diff --git a/CHANGELOG.md b/CHANGELOG.md index 19a180a66..76ff08a00 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ All notable changes to this project will be documented in this file. ### Changed - Berry fast_loop is now called every 5ms whatever the Sleep value - Reduce IRAM consumption of HDMI CEC to 1453 bytes +- `Sendmail` upgraded to ESP-Mail-Client v3.4.9 from v1.2.0, using BearSSL instead of MbedTLS ### Fixed - PCF8574 mode 1 with base relays exception 3/28 regression from v12.4.0.4 (#19408) diff --git a/lib/lib_ssl/bearssl-esp8266/src/t_bearssl_x509.h b/lib/lib_ssl/bearssl-esp8266/src/t_bearssl_x509.h index d5a6b6554..042b171f8 100644 --- a/lib/lib_ssl/bearssl-esp8266/src/t_bearssl_x509.h +++ b/lib/lib_ssl/bearssl-esp8266/src/t_bearssl_x509.h @@ -1032,7 +1032,7 @@ typedef struct { * \param append_in issuer DN receiver callback (or `0`). * \param append_in_ctx context for the issuer DN receiver callback. */ -void br_x509_decoder_init(br_x509_decoder_context *ctx, +void br_x509_decoder_init_esp8266(br_x509_decoder_context *ctx, void (*append_dn)(void *ctx, const void *buf, size_t len), void *append_dn_ctx, void (*append_in)(void *ctx, const void *buf, size_t len), @@ -1048,7 +1048,7 @@ void br_x509_decoder_init(br_x509_decoder_context *ctx, * \param data certificate data chunk. * \param len certificate data chunk length (in bytes). */ -void br_x509_decoder_push(br_x509_decoder_context *ctx, +void br_x509_decoder_push_tasmota(br_x509_decoder_context *ctx, const void *data, size_t len); /** diff --git a/lib/lib_ssl/bearssl-esp8266/src/x509/x509_decoder.c b/lib/lib_ssl/bearssl-esp8266/src/x509/x509_decoder.c index b738755f5..48d50aa00 100644 --- a/lib/lib_ssl/bearssl-esp8266/src/x509/x509_decoder.c +++ b/lib/lib_ssl/bearssl-esp8266/src/x509/x509_decoder.c @@ -62,9 +62,9 @@ t0_parse7E_signed(const unsigned char **p) /* static const unsigned char t0_datablock[]; */ -void br_x509_decoder_init_main(void *t0ctx); +void br_x509_decoder_init_main_tasmota(void *t0ctx); -void br_x509_decoder_run(void *t0ctx); +void br_x509_decoder_run_tasmota(void *t0ctx); @@ -81,7 +81,7 @@ void br_x509_decoder_run(void *t0ctx); /* see bearssl_x509.h */ void -br_x509_decoder_init(br_x509_decoder_context *ctx, +br_x509_decoder_init_esp8266(br_x509_decoder_context *ctx, void (*append_dn)(void *ctx, const void *buf, size_t len), void *append_dn_ctx, void (*append_in)(void *ctx, const void *buf, size_t len), @@ -99,18 +99,18 @@ br_x509_decoder_init(br_x509_decoder_context *ctx, ctx->append_in_ctx = append_in_ctx; ctx->cpu.dp = &ctx->dp_stack[0]; ctx->cpu.rp = &ctx->rp_stack[0]; - br_x509_decoder_init_main(&ctx->cpu); - br_x509_decoder_run(&ctx->cpu); + br_x509_decoder_init_main_tasmota(&ctx->cpu); + br_x509_decoder_run_tasmota(&ctx->cpu); } /* see bearssl_x509.h */ void -br_x509_decoder_push(br_x509_decoder_context *ctx, +br_x509_decoder_push_tasmota(br_x509_decoder_context *ctx, const void *data, size_t len) { ctx->hbuf = data; ctx->hlen = len; - br_x509_decoder_run(&ctx->cpu); + br_x509_decoder_run_tasmota(&ctx->cpu); } @@ -381,12 +381,12 @@ name(void *ctx) \ T0_ENTER(t0ctx->ip, t0ctx->rp, slot); \ } -T0_DEFENTRY(br_x509_decoder_init_main, 93) +T0_DEFENTRY(br_x509_decoder_init_main_tasmota, 93) #define T0_NEXT(t0ipp) (pgm_read_byte((*t0ipp)++)) void -br_x509_decoder_run(void *t0ctx) +br_x509_decoder_run_tasmota(void *t0ctx) { uint32_t *dp, *rp; const unsigned char *ip; diff --git a/lib/lib_ssl/tls_mini/src/WiFiClientSecureLightBearSSL.cpp b/lib/lib_ssl/tls_mini/src/WiFiClientSecureLightBearSSL.cpp index 6887ff594..1bd425ae4 100755 --- a/lib/lib_ssl/tls_mini/src/WiFiClientSecureLightBearSSL.cpp +++ b/lib/lib_ssl/tls_mini/src/WiFiClientSecureLightBearSSL.cpp @@ -731,7 +731,7 @@ extern "C" { br_x509_pubkeyfingerprint_context *xc = (br_x509_pubkeyfingerprint_context *)ctx; // Don't process anything but the first certificate in the chain if (!xc->done_cert) { - br_x509_decoder_init(&xc->ctx, nullptr, nullptr, nullptr, nullptr); + br_x509_decoder_init_esp8266(&xc->ctx, nullptr, nullptr, nullptr, nullptr); } (void)server_name; // ignore server name } @@ -748,7 +748,7 @@ extern "C" { br_x509_pubkeyfingerprint_context *xc = (br_x509_pubkeyfingerprint_context *)ctx; // Don't process anything but the first certificate in the chain if (!xc->done_cert) { - br_x509_decoder_push(&xc->ctx, (const void*)buf, len); + br_x509_decoder_push_tasmota(&xc->ctx, (const void*)buf, len); } } diff --git a/lib/libesp32/lib_mail/LICENSE b/lib/libesp32/ESP-Mail-Client/LICENSE similarity index 95% rename from lib/libesp32/lib_mail/LICENSE rename to lib/libesp32/ESP-Mail-Client/LICENSE index 4ba9966fd..c22fc2301 100644 --- a/lib/libesp32/lib_mail/LICENSE +++ b/lib/libesp32/ESP-Mail-Client/LICENSE @@ -1,21 +1,21 @@ -MIT License - -Copyright (c) 2021 mobizt - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +MIT License + +Copyright (c) 2023 mobizt + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/lib/libesp32/ESP-Mail-Client/README.md b/lib/libesp32/ESP-Mail-Client/README.md new file mode 100644 index 000000000..79d584f99 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/README.md @@ -0,0 +1,1127 @@ +![ESP Mail](https://raw.githubusercontent.com/mobizt/ESP-Mail-Client/master/media/images/esp-mail-client.svg) + + +![Compile](https://github.com/mobizt/ESP-Mail-Client/actions/workflows/compile_library.yml/badge.svg) ![Examples](https://github.com/mobizt/ESP-Mail-Client/actions/workflows/compile_examples.yml/badge.svg) [![Github Stars](https://img.shields.io/github/stars/mobizt/ESP-Mail-Client?logo=github)](https://github.com/mobizt/ESP-Mail-Client/stargazers) ![Github Issues](https://img.shields.io/github/issues/mobizt/ESP-Mail-Client?logo=github) + +![arduino-library-badge](https://www.ardu-badge.com/badge/ESP%20Mail%20Client.svg) ![PlatformIO](https://badges.registry.platformio.org/packages/mobizt/library/ESP%20Mail%20Client.svg) + + +The comprehensive Arduino Email Client Library to send and read Email for Arduino devices. + +This library was tested and works well with ESP32s, ESP8266s, SAMD21s and RP2040 Pico based modules. + +The library supported external networking devices hat work with Arduino Clients e.g. WiFiClient, EthernetClient, and GSMClient. + +Minimum 200k flash space device is recommended for library installation and user code. + +The minimum ram requirement is based on the applications (SMTP and IMAP). IMAP application may required up to 20k memory while SMTP application required much less memory. + + +## Contents + + +[1. Features](#features) + +[2. Supported Devices](#supported-devices) + +[3. Prerequisites](#prerequisites) +- [Gmail SMTP and IMAP required App Passwords to sign in](#gmail-smtp-and-imap-required-app-passwords-to-sign-in) + +- [PlatformIO IDE Compile Options](#platformio-ide-compile-options) + +- [Third party SD library must be removed](#third-party-sd-library-must-be-removed) + +- [SdFat conflicts in ESP8266 and must be removed](#sdfat-conflicts-in-esp8266-and-must-be-removed) + +- [ESP32 and ESP8266 SDKs](#esp32-and-esp8266-sdks) + +- [RP2040 Arduino SDK](#rp2040-arduino-sdk) + +[4. Library Instalation](#library-instalation) + +- [Using Library Manager](#using-library-manager) + +- [Manual installation](#manual-installation) + +[5. Memory Options](#memory-options) + +- [Memory Options for ESP8266](#memory-options-for-esp8266) + + - [Arduino IDE](#arduino-ide) + + - [PlatformIO IDE](#platformio-ide) + + - [ESP8266 and SRAM/PSRAM Chip connection](#esp8266-and-srampsram-chip-connection) + +- [Memory Options for ESP32](#memory-options-for-esp32) + + - [Arduino IDE](#arduino-ide-1) + + - [PlatformIO IDE](#platformio-ide-1) + + +[6. Library Build Options](#library-build-options) + + - [Predefined Options](#predefined-options) + + - [Optional Options](#optional-options) + + +[7. Usage](#usage) + +- [Send Email message](#send-email-message) + +- [Read Email message](#read-email-message) + +- [Get Incoming Message Notification and Reading](#get-incoming-message-notification-and-reading) + +- [Sending Custom IMAP commands](#sending-custom-imap-commands) + +- [Using TCP session KeepAlive in ESP8266 and ESP32](#using-tcp-session-keepalive-in-esp8266-and-esp32) + +- [Use external Arduino Clients interfaces](#use-external-arduino-clients-interfaces) + + - [TTGO T-A7670 LTE with TinyGSM](#ttgo-t-a7670-lte-with-tinygsm) + + - [ESP32 and W5500](#esp32-and-w5500) + +[8. License](#license) + + + +## Features + +* Supports sending Email with attachments. +* Supports reading the message and listening the mailbox changes. +* Supports custom SMTP and IMAP commands. +* Supports PLAIN, LOGIN and XOAUTH2 authentication mechanisms. +* Supports standard ports and user defined ports. +* Supports STARTTLS for both SMTP and IMAP. +* Supports TCP session reusage. +* Supports the content encodings e.g. quoted-printable and base64. +* Supports the content decodings e.g. base64, UTF-8, UTF-7, quoted-printable, ISO-8859-1 (latin1) and ISO-8859-11 (Thai). +* Supports embedded contents e.g. inline images, attachments, parallel media attachments and RFC822 message. +* Supports IMAP MIME data stream callback for external reader. +* supports IMAP custom character decoding callback based on the character set. +* Support full debuging. +* Support on-board or native networking (WiFi and Ethernet) and external networking (WiFi, Ethernet and GSM) via external basic WiFiClient, EthernetClient and GSMClient. +* Supports TinyGSM library integration. + + + + +## Supported Devices + +This following devices are supported. + + * ESP8266 MCUs based boards + * ESP32 MCUs based boards + * Arduino MKR WiFi 1010 + * Arduino MKR 1000 WIFI + * Arduino Nano 33 IoT + * Arduino MKR Vidor 4000 + * Raspberry Pi Pico (RP2040) + * Arduino UNO R4 WiFi (Renesas). + * LAN8720 Ethernet PHY + * TLK110 Ethernet PHY + * IP101 Ethernet PHY + * ENC28J60 SPI Ethernet module + * W5100 SPI Ethernet module + * W5500 SPI Ethernet module + * SIMCom Modules with TinyGSMClient + + + +## Prerequisites + + +### Gmail SMTP and IMAP required App Passwords to sign in + +From May 30, 2022, Google no longer supports the use of third-party apps or devices which ask you to sign in to your GoogleAccount using only your username and password. + +This means the Gmail account credentials i.e. account Email and account password can't be used to sign in with Google SMTP and IMAP servers. This prevents the third party apps hack to Gmail user account. + +To use Gmail with this library, you need to use App Passwords instead. + +For setting up the App Passwords, please read [here](https://support.google.com/accounts/answer/185833). + +After you created App Password, you can use Gmail Email address and App Password created to sign in as the following. + +```cpp +config.login.email = ""; +config.login.password = ""; +``` + + +### PlatformIO IDE Compile Options + +For Arduino Nano RP2040 Connect board, using PlatformIO IDE, to prevent the compile error due to wrong headers compilation, please set the lib_ldf_mode in platformio.ini as this. + +```ini +lib_ldf_mode = chain+ +``` + +### Third party SD library must be removed + +In Arduino IDE, all third party SD libraries installed in libraries folder must be reboved. + +The Core SD library was used instead of third party SD libraries. + +### SdFat conflicts in ESP8266 and must be removed + +The [SdFat](https://github.com/greiman/SdFat) is already implemented as wrapper class in ESP8266 core library. + +For Arduino IDE, the SdFat library should be removed from libraries folder when you compile this library for ESP8266 because of conclicts with core library SDFS.h. + + +### ESP32 and ESP8266 SDKs + +For Espressif's ESP32 and ESP8266 based boards, this library requires Arduino's ESP32 or ESP8266 Core SDK to be installed. + +The latest Core SDK is recommended. For ESP8266, the Core SDK version 3.x.x or later is recommended. + +The ESP8266 Core SDK version 2.5.x and earlier are not supported. + +For ESP32, the Core SDK version 2.0.4 or later is recommended. + +The ESP32 Core SDK version 1.0.4 and earlier are not supported. + + +### RP2040 Arduino SDK + +For Arduino IDE, the Arduino-Pico SDK can be installed from Boards Manager by searching pico and choose Raspberry Pi Pico/RP2040 to install. + +For PlatformIO, the Arduino-Pico SDK can be installed via platformio.ini + +```ini +[env:rpipicow] +platform = https://github.com/maxgerhardt/platform-raspberrypi.git +board = rpipicow +framework = arduino +board_build.core = earlephilhower +monitor_speed = 115200 +board_build.filesystem_size = 1m +``` + +See this Arduino-Pico SDK [documentation](https://arduino-pico.readthedocs.io/en/latest/) for more information. + + +## Library Instalation + + +### Using Library Manager + +At Arduino IDE, go to menu **Sketch** -> **Include Library** -> **Manage Libraries...** + +In Library Manager Window, search **"ESP Mail Client"** in the search form then select **"ESP Mail Client"**. + +Click **"Install"** button. + + + +For PlatformIO IDE. + +Go to **PIO Home** -> **Libraries** -> **Registry** then search **ESP Mail Client**. + + +If you ever installed this library in Global storage in PlatformIO version prior to v2.0.0 and you have updated the PlatformIO to v2.0.0 and later, the global library installation was not available, the sources files of old library version still be able to search by the library dependency finder (LDF), you needed to remove the library from folder **C:\Users\\\\.platformio\lib** to prevent unexpected behavior when compile and run. + + + +### Manual installation + + +Click on **Code** dropdown at the top of repository, select **Download ZIP** and save file on your computer. + +From Arduino IDE, goto menu **Sketch** -> **Include Library** -> **Add .ZIP Library...** and choose **ESP-Mail-Client-master.zip** that previously downloaded. + +Rename **ESP-Mail-Client-master** folder to **ESP_Mail_Client**. + +Go to menu **Files** -> **Examples** -> **ESP Mail Client** and choose one from examples + + + +## Memory Options + + +### Memory Options for ESP8266 + +This section is optional for memory settings in IDE. + +When you update the ESP8266 Arduino Core SDK to v3.0.0, the memory can be configurable from IDE. + +You can choose the Heap memory between internal and external memory chip from IDE e.g. Arduino IDE and PlatformIO on VSCode or Atom IDE. + +#### Arduino IDE + + +For ESP8266 devices that don't have external SRAM/PSRAM chip installed, choose the MMU **option 3**, 16KB cache + 48KB IRAM and 2nd Heap (shared). + +![Arduino IDE config](/media/images/ArduinoIDE.png) + +For ESP8266 devices that have external 23LC1024 SRAM chip installed, choose the MMU **option 5**, 128K External 23LC1024. + +![MMU VM 128K](/media/images/ESP8266_VM.png) + +For ESP8266 devices that have external ESP-PSRAM64 chip installed, choose the MMU **option 6**, 1M External 64 MBit PSRAM. + + +#### PlatformIO IDE + +The MMU options can be selected from build_flags in your project's platformio.ini file + +For ESP8266 devices that don't not have external SRAM/PSRAM chip installed, add build flag as below. + +```ini +[env:d1_mini] +platform = espressif8266 +build_flags = -D PIO_FRAMEWORK_ARDUINO_MMU_CACHE16_IRAM48_SECHEAP_SHARED +board = d1_mini +framework = arduino +monitor_speed = 115200 +``` + + +For ESP8266 devices that have external 23LC1024 SRAM chip installed, add build flag as below. + +```ini +[env:d1_mini] +platform = espressif8266 +;128K External 23LC1024 +build_flags = -D PIO_FRAMEWORK_ARDUINO_MMU_EXTERNAL_128K +board = d1_mini +framework = arduino +monitor_speed = 115200 +``` + + +For ESP8266 devices that have external ESP-PSRAM64 chip installed, add build flag as below. + +```ini +[env:d1_mini] +platform = espressif8266 +;1M External 64 MBit PSRAM +build_flags = -D PIO_FRAMEWORK_ARDUINO_MMU_EXTERNAL_1024K +board = d1_mini +framework = arduino +monitor_speed = 115200 +``` + + +#### ESP8266 and SRAM/PSRAM Chip connection + +Most ESP8266 modules don't have the built-in SRAM/PSRAM on board. External memory chip connection can be done via SPI port as below. + +``` +23LC1024/ESP-PSRAM64 ESP8266 + +CS (Pin 1) GPIO15 +SCK (Pin 6) GPIO14 +MOSI (Pin 5) GPIO13 +MISO (Pin 2) GPIO12 +/HOLD (Pin 7 on 23LC1024 only) 3V3 +Vcc (Pin 8) 3V3 +Vcc (Pin 4) GND +``` + +Once the external Heap memory was selected in IDE, to allow the library to use the external memory, you can set it in [**ESP_Mail_FS.h**](src/ESP_Mail_FS.h) by define this macro. + + +```cpp +#define ESP_MAIL_USE_PSRAM +``` + +This macro was defined by default when you installed or update the library. + + + +### Memory Options for ESP32 + +This section is optional for memory settings in IDE. + +In ESP32 module that has PSRAM installed, you can enable it and set the library to use this external memory instead. + +#### Arduino IDE + +To enable PSRAM in ESP32 module. + +![Enable PSRAM in ESP32](/media/images/ESP32-PSRAM.png) + + +#### PlatformIO IDE + + +In PlatformIO on VSCode or Atom IDE, add the following build_flags in your project's platformio.ini file. + +```ini +build_flags = -DBOARD_HAS_PSRAM -mfix-esp32-psram-cache-issue +``` + +As in ESP8266, once the external Heap memory was enabled in IDE, to allow the library to use the external memory, you can set it in [**ESP_Mail_FS.h**](src/ESP_Mail_FS.h) by define this macro. + +```cpp +#define ESP_MAIL_USE_PSRAM +``` + + + +## Library Build Options + +The library build options are defined as preprocessor macros (`#define name`). + +Some options can be disabled to reduce program space. + +### Predefined Options + +The predefined options that are already set in [**ESP_Mail_FS.h**](src/ESP_Mail_FS.h) are following. + +```cpp +ENABLE_IMAP // For IMAP class compilation +ENABLE_SMTP // For SMTP class compilation +ENABLE_NTP_TIME // For enabling the device or library time setup from NTP server +ENABLE_ERROR_STRING // For enabling the error string from error reason +ESP_MAIL_USE_PSRAM // For enabling PSRAM support +ESP_MAIL_DEFAULT_FLASH_FS // For enabling flash filesystem support +ESP_MAIL_DEFAULT_SD_FS // For enabling SD filesystem support +``` + +### Optional Options + +The following options are not yet defined in [**ESP_Mail_FS.h**](src/ESP_Mail_FS.h) and can be assigned by user. + +```cpp +SILENT_MODE // For silent operation (no debug printing and callback) +ENABLE_ESP8266_ENC28J60_ETH // For ENC28J60 Ethernet module support in ESP8266 +ENABLE_ESP8266_W5500_ETH // For W5500 Ethernet module support in ESP8266 +ENABLE_ESP8266_W5100_ETH // For W5100 Ethernet module support in ESP8266 +ESP_MAIL_DISABLE_ONBOARD_WIFI // For disabling on-board WiFI functionality in case external Client usage +ESP_MAIL_DISABLE_NATIVE_ETHERNET // For disabling native (sdk) Ethernet functionality in case external Client usage +ESP_MAIL_DISABLE_SSL // // For disabling SSL connection (also disabling TLS using STARTTLS) in MAP and SMTP application +ESP_MAIL_DEBUG_PORT // For debug port assignment if SILENT_MODE option was not set +``` + + +You can assign the optional build options using one of the following methods. + +- By creating user config file `Custom_ESP_Mail_FS.h` in library installed folder and define these optional options. + +- By adding compiler build flags with `-D name`. + +In PlatformIO IDE, using `build_flags` in PlatformIO IDE's platformio.ini is more convenient + +```ini +build_flags = -D ESP_MAIL_DEBUG_PORT=Serial + -D DISABLE_IMAP + -D ESP_MAIL_DISABLE_ONBOARD_WIFI +``` + +For disabling predefined options instead of editing the [**ESP_Mail_FS.h**](src/ESP_Mail_FS.h) or using `#undef` in `Custom_ESP_Mail_FS.h`, you can define these build flags with these names or macros in `Custom_ESP_Mail_FS.h`. + +```cpp +DISABLE_IMAP // For excluding the IMAP class compilation +DISABLE_SMTP // For excluding the SMTP class compilation +DISABLE_NTP_TIME // For disabling the NTP time setting +DISABLE_ERROR_STRING // For disabling the error string from error reason +DISABLE_PSRAM // For disabling PSRAM support +DISABLE_FLASH // For disabling flash filesystem support +DISABLE_SD // For disabling SD filesystem support + +DISABLE_ALL_OPTIONS // For disabling all predefined build options above +``` + +Note that, `Custom_ESP_Mail_FS.h` for user config should be placed in the library install folder inside src folder. + +This `Custom_ESP_Mail_FS.h` will not change or overwrite when update the library. + + + +## Usage + + +See [examples folder](/examples) for all usage examples. + +See [src/README.md](/src/README.md) for the functions descriptions. + +The usefull blogs that described how to send and read E-mail in detail can be found here. + +[ESP32 Send Emails using an SMTP Server: HTML, Text, and Attachments (Arduino IDE) by Rui and Sara from randomnerdtutorials.com](https://randomnerdtutorials.com/esp32-send-email-smtp-server-arduino-ide/) + +[Receiving Emails with ESP32 using IMAP Server by Alina Mybeth from theengineeringprojects.com](https://www.theengineeringprojects.com/2022/01/receiving-emails-with-esp32-using-imap-server.html) + + +The following code snippet showed the minimum usage of the library. + + +### Send Email message + +The following code will send email with image attachment. + +```C++ +// Include WiFi library +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +// Include ESP Mail Client library (this library) +#include + + +// Declare the global used SMTPSession object for SMTP transport +SMTPSession smtp; + +// Declare the global used Session_Config for user defined session credentials +Session_Config config; + +// Callback function to get the Email sending status +void smtpCallback(SMTP_Status status); + +void setup() +{ + + Serial.begin(115200); + + WiFi.begin("", ""); + Serial.print("Connecting to Wi-Fi"); + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + // Set the session config + config.server.host_name = "smtp.office365.com"; // for outlook.com + config.server.port = 587; // for TLS with STARTTLS or 25 (Plain/TLS with STARTTLS) or 465 (SSL) + config.login.email = "your Email address"; // set to empty for no SMTP Authentication + config.login.password = "your Email password"; // set to empty for no SMTP Authentication + + // For client identity, assign invalid string can cause server rejection + config.login.user_domain = "client domain or public ip"; + + /* + Set the NTP config time + For times east of the Prime Meridian use 0-12 + For times west of the Prime Meridian add 12 to the offset. + Ex. American/Denver GMT would be -6. 6 + 12 = 18 + See https://en.wikipedia.org/wiki/Time_zone for a list of the GMT/UTC timezone offsets + */ + config.time.ntp_server = "pool.ntp.org,time.nist.gov"; + config.time.gmt_offset = 3; + config.time.day_light_offset = 0; + + // Declare the SMTP_Message class variable to handle to message being transport + SMTP_Message message; + + // Set the message headers + message.sender.name = "My Mail"; + message.sender.email = "sender or your Email address"; + message.subject = "Test sending Email"; + message.addRecipient("name1", "email1"); + message.addRecipient("name2", "email2"); + + message.addCc("email3"); + message.addBcc("email4"); + + // Set the message content + message.text.content = "This is simple plain text message"; + + //Base64 data of image + const char *greenImg = "iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAAoUlEQVR42u" + "3RAQ0AMAgAoJviyWxtAtNYwzmoQGT/eqwRQoQgRAhChCBECEKECBGCECEI" + "EYIQIQgRghCECEGIEIQIQYgQhCBECEKEIEQIQoQgBCFCECIEIUIQIgQhCB" + "GCECEIEYIQIQhBiBCECEGIEIQIQQhChCBECEKEIEQIQhAiBCFCECIEIUIQ" + "ghAhCBGCECEIEYIQIUKEIEQIQoQg5LoBBaDPbQYiMoMAAAAASUVORK5CYII="; + + // Declare the attachment data + SMTP_Attachment att; + + // Set the attatchment info + att.descr.filename = "green.png"; + att.descr.mime = "image/png"; + att.blob.data = (uint8_t *)greenImg; + att.blob.size = strlen(greenImg); + // Set the transfer encoding to base64 + att.descr.transfer_encoding = Content_Transfer_Encoding::enc_base64; + // We set the content encoding to match the above greenImage data + att.descr.content_encoding = Content_Transfer_Encoding::enc_base64; + + // Add attachment to the message + message.addAttachment(att); + + // Set debug option + smtp.debug(1); + + // Set the callback function to get the sending results + smtp.callback(smtpCallback); + + // Connect to the server + smtp.connect(&config); + + // Start sending Email and close the session + if (!MailClient.sendMail(&smtp, &message)) + Serial.println("Error sending Email, " + smtp.errorReason()); + +} + +void smtpCallback(SMTP_Status status) +{ + + Serial.println(status.info()); + + if (status.success()) + { + // See example for how to get the sending result + } +} + + +``` + + +### Read Email message + +The following code will read the latest email message in the "INBOX" mailbox. + +```C++ +// Include WiFi library +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +// Include ESP Mail Client library (this library) +#include + +// Declare the global used IMAPSession object for IMAP transport +IMAPSession imap; + +// Declare the global used Session_Config for user defined session credentials +Session_Config config; + +// Callback function to get the Email reading status +void imapCallback(IMAP_Status status) + +void setup() +{ + + Serial.begin(115200); + + WiFi.begin("", ""); + Serial.print("Connecting to Wi-Fi"); + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + // Set the session config + config.server.host_name = "outlook.office365.com"; //for outlook.com + config.server.port = 993; // for SSL or 143 for Plain or TLS with STARTTLS + config.login.email = "your Email address"; + config.login.password = "your Email password"; + + // Declare the IMAP_Data object used for user defined IMAP operating options + // and contains the IMAP operating result + IMAP_Data imap_data; + + + // Set to enable the message content which will be stored in the IMAP_Data data + imap_data.enable.html = true; + imap_data.enable.text = true; + + + // Set the debug option + imap.debug(1); + + // Set the callback function to get message information + imap.callback(imapCallback); + + + // Connect to the server + imap.connect(&config, &imap_data); + + // Open or select the mailbox folder to read the message + imap.selectFolder("INBOX"); + + + // Define the message UID (number) which required to fetch or read the message + // In this case we will get the UID from the max message number (lastest message) + // then imap.getUID and imap.selectedFolder().msgCount() should be called after + // calling select or open the folder (mailbox). + imap_data.fetch.uid = imap.getUID(imap.selectedFolder().msgCount()); + + // Empty search criteria to disable the messsage search + imap_data.search.criteria.clear(); + + + // Read the Email and close the session + MailClient.readMail(&imap); + + +} + + +void imapCallback(IMAP_Status status) +{ + + Serial.println(status.info()); + + if (status.success()) + { + // See example for how to get the message info + } +} + +``` + + +### Get Mailbox Changes Notification + +See [Mailbox_Changes_Notification.ino](/examples/IMAP/Mailbox_Changes_Notification/Mailbox_Changes_Notification.ino) for the example. + + +### Sending Custom IMAP commands + +Can't find what you want from exising IMAP functions, sending custom command was supported. + +Please read the RFC 3501 and RFC 9051 documents for the details of IMAP protocol commands. + +See [Custom_Command examples](/examples/IMAP/Custom_Command) for how to use. + + +### Using TCP session KeepAlive in ESP8266 and ESP32 + +The server connection will be probed at some intervals to maintain connection. + +The TCP session KeepAlive can be enabled from executing `.keepAlive` or `.keepAlive` with providing TCP options as arguments, i.e., + +`tcpKeepIdleSeconds`, `tcpKeepIntervalSeconds` and `tcpKeepCount`. + +Ex. + +```cpp +smtp.keepAlive(5 /* tcp KeepAlive idle 5 seconds */, 5 /* tcp KeeAalive interval 5 seconds */, 1 /* tcp KeepAlive count 1 */); + +imap.keepAlive(5 /* tcp KeepAlive idle 5 seconds */, 5 /* tcp KeeAalive interval 5 seconds */, 1 /* tcp KeepAlive count 1 */); + +// If one of three arguments is zero, the KeepAlive will be disabled. +``` + +To check the KeepAlive status, use `.isKeepAlive` or `.isKeepAlive`. + + +For the TCP (KeepAlive) options, see [here](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/lwip.html#tcp-options). + +You can check the server connecting status, by executing `.connected()` or `.connected()` which will return true when connection to the server is still alive. + + +The TCP KeepAlive was currently available in ESP32 unless in ESP8266, [this ESP8266 PR #8940](https://github.com/esp8266/Arduino/pull/8940) should be merged in the [ESP8266 Arduino Core SDK](https://github.com/esp8266/Arduino/releases), i.e., it will be supported in the ESP8266 core version newer than v3.1.2. + + +In ESP8266 core v3.1.2 and older, the error can be occurred when executing `.keepAlive` or `.isKeepAlive` because of object slicing. + + +The Arduino Pico is currently not support TCP KeepAlive until it's implemented in WiFiClientSecure library as in ESP8266. + + +For External Client, this TCP KeepAlive option is not appliable and should be managed by external Client library. + + + + +### Use External Arduino Clients for External Networking Devices + +This library supports external netwoking devices e.g. WiFi modules, Ethernet modules and GSM modules that connected to the Arduino device via communication ports e.g. SPI and Serial, through the Arduino Clients (driver) for those networking devices e.g. WiFiClient, EthernetClient and GSMClient. + +Since v3.4.0, the Arduino Clients can be used with this library without additional external SSL Client required. + +No additional setup needed, only pass the Arduino Client to the function `setClient` or pass the TinyGSMClient and TinyGSM modem to the function `setGSMClient`. + +Two callback functions required (except for using `setGSMClient`) for network connection (with disconnection) and sending connecting status back to the Mail Client. + +If device has on-board WiFi and supports native (SDK) Ethernet, these two native networks will be auto detectd and used. + +If you don't want to let `ESP Mail Client` library to use the native networking and use external networking devices using Arduino Clients instead, the following build flags or macros should be defined in `Custom_ESP_Mail_FS.h`. + +```cpp +ESP_MAIL_DISABLE_ONBOARD_WIFI + +ESP_MAIL_DISABLE_NATIVE_ETHERNET +``` + +See [External Client Examples](/examples/SMTP/External_Client) for more external Client usage. + + +#### TTGO T-A7670 LTE with TinyGSM + +The following example showed how to use TTGO T-A7670 with `GSMClient` to connect to SMTP server. + +To allow TinyGSM library integration, the following build flag or macro should be defined in `Custom_ESP_Mail_FS.h`. + +```cpp +TINY_GSM_MODEM_SIM7600 +``` + +See the TinyGSM documentation and example for other SIMCom modules definition. + + +```cpp + +// For TTGO T-A7670 +#define TINY_GSM_MODEM_SIM7600 // SIMA7670 Compatible with SIM7600 AT instructions + +// Set serial for debug console (to the Serial Monitor, default speed 115200) +#define SerialMon Serial + +// Set serial for AT commands (to the module) +// Use Hardware Serial on Mega, Leonardo, Micro +#define SerialAT Serial1 + +// See all AT commands, if wanted +// #define DUMP_AT_COMMANDS + +// Define the serial console for debug prints, if needed +#define TINY_GSM_DEBUG SerialMon + +#define TINY_GSM_USE_GPRS true +#define TINY_GSM_USE_WIFI false + +// set GSM PIN, if any +#define GSM_PIN "" + +// Your GPRS credentials, if any +const char apn[] = "YourAPN"; +const char gprsUser[] = ""; +const char gprsPass[] = ""; + + +#define uS_TO_S_FACTOR 1000000ULL // Conversion factor for micro seconds to seconds +#define TIME_TO_SLEEP 600 // Time ESP32 will go to sleep (in seconds) + +#define UART_BAUD 115200 +#define PIN_DTR 25 +#define PIN_TX 26 +#define PIN_RX 27 +#define PWR_PIN 4 +#define BAT_ADC 35 +#define BAT_EN 12 +#define PIN_RI 33 +#define PIN_DTR 25 +#define RESET 5 + +#define SD_MISO 2 +#define SD_MOSI 15 +#define SD_SCLK 14 +#define SD_CS 13 + + +#include +#include + + +TinyGsm modem(SerialAT); + +TinyGsmClient gsm_client(modem); // basic non-secure client + +SMTPSession smtp; + +// Callback function to get the Email sending status +void smtpCallback(SMTP_Status status); + +void setup() +{ + + SerialMon.begin(115200); + + // Set debug option + smtp.debug(1); + + // Set the callback function to get the sending results + smtp.callback(smtpCallback); + + delay(10); + pinMode(BAT_EN, OUTPUT); + digitalWrite(BAT_EN, HIGH); + + // A7670 Reset + pinMode(RESET, OUTPUT); + digitalWrite(RESET, LOW); + delay(100); + digitalWrite(RESET, HIGH); + delay(3000); + digitalWrite(RESET, LOW); + + pinMode(PWR_PIN, OUTPUT); + digitalWrite(PWR_PIN, LOW); + delay(100); + digitalWrite(PWR_PIN, HIGH); + delay(1000); + digitalWrite(PWR_PIN, LOW); + + DBG("Wait..."); + + delay(3000); + + SerialAT.begin(UART_BAUD, SERIAL_8N1, PIN_RX, PIN_TX); + + // Restart takes quite some time + // To skip it, call init() instead of restart() + DBG("Initializing modem..."); + if (!modem.init()) + { + DBG("Failed to restart modem, delaying 10s and retrying"); + return; + } + + /* + 2 Automatic + 13 GSM Only + 14 WCDMA Only + 38 LTE Only + */ + modem.setNetworkMode(38); + if (modem.waitResponse(10000L) != 1) + { + DBG(" setNetworkMode faill"); + } + + String name = modem.getModemName(); + DBG("Modem Name:", name); + + String modemInfo = modem.getModemInfo(); + DBG("Modem Info:", modemInfo); + + Session_Config config; + + config.server.host_name = SMTP_HOST; + config.server.port = SMTP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + config.login.user_domain = F("127.0.0.1"); + + // Declare the SMTP_Message class variable to handle to message being transport + SMTP_Message message; + + // Set the message headers + message.sender.name = F("ESP Mail"); + message.sender.email = AUTHOR_EMAIL; + message.subject = F("Test sending plain text Email using GSM module"); + message.addRecipient(F("Someone"), RECIPIENT_EMAIL); + + // Set the message content + message.text.content = "This is simple plain text message"; + + // Set debug option + smtp.debug(1); + + // Set the callback function to get the sending results + smtp.callback(smtpCallback); + + smtp.setGSMClient(&gsm_client, &modem, GSM_PIN, apn, gprsUser, gprsPass); + + // Connect to the server with the defined session and options + smtp.connect(&config); + + // Start sending Email and close the session + if (!MailClient.sendMail(&smtp, &message)) + Serial.println("Error sending Email, " + smtp.errorReason()); +} + +void loop() +{ +} + +void smtpCallback(SMTP_Status status) +{ + + Serial.println(status.info()); + + if (status.success()) + { + // See example for how to get the sending result + } +} + +``` + +#### ESP32 and W5500 + +The below example will use ESP32 and W5500 and Ethernet client library to connect to SMTP server + + +```cpp + +#include + +#include + +#define WIZNET_RESET_PIN 26 // Connect W5500 Reset pin to GPIO 26 of ESP32 +#define WIZNET_CS_PIN 5 // Connect W5500 CS pin to GPIO 5 of ESP32 +#define WIZNET_MISO_PIN 19 // Connect W5500 MISO pin to GPIO 19 of ESP32 +#define WIZNET_MOSI_PIN 23 // Connect W5500 MOSI pin to GPIO 23 of ESP32 +#define WIZNET_SCLK_PIN 18 // Connect W5500 SCLK pin to GPIO 18 of ESP32 + + +EthernetClient eth_client; + +uint8_t Eth_MAC[] = {0x02, 0xF0, 0x0D, 0xBE, 0xEF, 0x01}; + +SMTPSession smtp; + +Session_Config config; + +// Callback function to get the Email sending status +void smtpCallback(SMTP_Status status); + +void ResetEthernet() +{ + Serial.println("Resetting WIZnet W5500 Ethernet Board... "); + pinMode(WIZNET_RESET_PIN, OUTPUT); + digitalWrite(WIZNET_RESET_PIN, HIGH); + delay(200); + digitalWrite(WIZNET_RESET_PIN, LOW); + delay(50); + digitalWrite(WIZNET_RESET_PIN, HIGH); + delay(200); +} + +void networkConnection() +{ + + Ethernet.init(WIZNET_CS_PIN); + + ResetEthernet(); + + Serial.println("Starting Ethernet connection..."); + Ethernet.begin(Eth_MAC); + + unsigned long to = millis(); + + while (Ethernet.linkStatus() == LinkOFF || millis() - to < 2000) + { + delay(100); + } + + if (Ethernet.linkStatus() == LinkON) + { + Serial.print("Connected with IP "); + Serial.println(Ethernet.localIP()); + } + else + { + Serial.println("Can't connect"); + } +} + +void networkStatusRequestCallback() +{ + smtp.setNetworkStatus(Ethernet.linkStatus() == LinkON); +} + +void setup() +{ + Serial.begin(115200); + + networkConnection(); + + config.server.host_name = "smtp.gmail.com"; //for gmail.com + config.server.port = 587; // requires connection upgrade via STARTTLS + config.login.email = "your Email address"; //set to empty for no SMTP Authentication + config.login.password = "your Email password"; //set to empty for no SMTP Authentication + config.login.user_domain = "client domain or ip e.g. mydomain.com"; + + // Declare the SMTP_Message class variable to handle to message being transport + SMTP_Message message; + + // Set the message headers + message.sender.name = "My Mail"; + message.sender.email = "sender or your Email address"; + message.subject = "Test sending Email"; + message.addRecipient("name1", "email1"); + message.addRecipient("name2", "email2"); + + message.addCc("email3"); + message.addBcc("email4"); + + // Set the message content + message.text.content = "This is simple plain text message"; + + // Set the callback function for connection upgrade + smtp.networkStatusRequestCallback(networkStatusRequestCallback); + + smtp.networkConnectionRequestCallback(networkConnection); + + smtp.setClient(ð_client); + + // Set debug option + smtp.debug(1); + + // Set the callback function to get the sending results + smtp.callback(smtpCallback); + + // Connect to the server with the defined session and options + smtp.connect(&config); + + // Start sending Email and close the session + if (!MailClient.sendMail(&smtp, &message)) + Serial.println("Error sending Email, " + smtp.errorReason()); + +} + +void smtpCallback(SMTP_Status status) +{ + + Serial.println(status.info()); + + if (status.success()) + { + // See example for how to get the sending result + } +} + +``` + + +## License + +The MIT License (MIT) + +Copyright (c) 2023 K. Suwatchai (Mobizt) + + +Permission is hereby granted, free of charge, to any person returning a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/lib/libesp32/lib_mail/_config.yml b/lib/libesp32/ESP-Mail-Client/_config.yml similarity index 100% rename from lib/libesp32/lib_mail/_config.yml rename to lib/libesp32/ESP-Mail-Client/_config.yml diff --git a/lib/libesp32/ESP-Mail-Client/examples/IMAP/ACL/ACL.ino b/lib/libesp32/ESP-Mail-Client/examples/IMAP/ACL/ACL.ino new file mode 100644 index 000000000..145e9815c --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/IMAP/ACL/ACL.ino @@ -0,0 +1,258 @@ +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt + */ + +// This example shows how to get, set the access control list. + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +/** For ESP8266, with BearSSL WiFi Client + * The memory reserved for completed valid SSL response from IMAP is 16 kbytes which + * may cause your device out of memory reset in case the memory + * allocation error. + */ + +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +#include + +// To use only IMAP functions, you can exclude the SMTP from compilation, see ESP_Mail_FS.h. + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +/** For Gmail, IMAP option should be enabled. https://support.google.com/mail/answer/7126229?hl=en + * and also https://accounts.google.com/b/0/DisplayUnlockCaptcha + * + * Some Gmail user still not able to sign in using account password even above options were set up, + * for this case, use "App Password" to sign in instead. + * About Gmail "App Password", go to https://support.google.com/accounts/answer/185833?hl=en + * + * For Yahoo mail, log in to your yahoo mail in web browser and generate app password by go to + * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc + * + * To use Gmai and Yahoo's App Password to sign in, define the AUTHOR_PASSWORD with your App Password + * and AUTHOR_EMAIL with your account email. + */ + +/* The imap host name e.g. imap.gmail.com for GMail or outlook.office365.com for Outlook */ +#define IMAP_HOST "" + +/** The imap port e.g. + * 143 or esp_mail_imap_port_143 + * 993 or esp_mail_imap_port_993 + */ +#define IMAP_PORT 993 + +/* The log in credentials */ +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" + +/* Declare the global used IMAPSession object for IMAP transport */ +IMAPSession imap; + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) +WiFiMulti multi; +#endif + +void setup() +{ + + Serial.begin(115200); + +#if defined(ARDUINO_ARCH_SAMD) + while (!Serial) + ; +#endif + + Serial.println(); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + multi.addAP(WIFI_SSID, WIFI_PASSWORD); + multi.run(); +#else + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Connecting to Wi-Fi"); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + unsigned long ms = millis(); +#endif + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + if (millis() - ms > 10000) + break; +#endif + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + /* Set the network reconnection option */ + MailClient.networkReconnect(true); + + // The WiFi credentials are required for Pico W + // due to it does not have reconnect feature. +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + MailClient.clearAP(); + MailClient.addAP(WIFI_SSID, WIFI_PASSWORD); +#endif + + /** Enable the debug via Serial port + * 0 for no debugging + * 1 for basic level debugging + * + * Debug port can be changed via ESP_MAIL_DEFAULT_DEBUG_PORT in ESP_Mail_FS.h + */ + imap.debug(1); + + /* Declare the Session_Config for user defined session credentials */ + Session_Config config; + + /* Set the session config */ + config.server.host_name = IMAP_HOST; + config.server.port = IMAP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + + /* Define the IMAP_Data object used for user defined IMAP operating options. */ + IMAP_Data imap_data; + + /* Connect to the server */ + if (!imap.connect(&config, &imap_data)) + return; + + if (imap.isAuthenticated()) + Serial.println("\nSuccessfully logged in."); + else + Serial.println("\nConnected with no Auth."); + + IMAP_Rights_List acl_list; + + Serial.println("\nGet ACLs..."); + + if (!imap.getACL("INBOX", &acl_list)) + { + Serial.println("Get ACLs failed"); + } + else + { + Serial.println("ACL..."); + + for (size_t i = 0; i < acl_list.size(); i++) + { + MailClient.printf("Identifier: %s, Rights: ", acl_list[i].identifier.c_str()); + String r; + for (int j = esp_mail_imap_rights_administer; j < esp_mail_imap_rights_maxType; j++) + { + if (acl_list[i].rights[j]) + r += (char)('a' + j); + } + + Serial.println(r); + } + } + + IMAP_Rights_Info acl; + acl.identifier = "Steve"; + acl.rights[esp_mail_imap_rights_administer] = true; + acl.rights[esp_mail_imap_rights_create] = true; + acl.rights[esp_mail_imap_rights_create_c] = true; + acl.rights[esp_mail_imap_rights_delete_message] = true; + acl.rights[esp_mail_imap_rights_delete_d] = true; + acl.rights[esp_mail_imap_rights_delete_mailbox] = true; + acl.rights[esp_mail_imap_rights_expunge] = true; + acl.rights[esp_mail_imap_rights_lookup] = true; + acl.rights[esp_mail_imap_rights_insert] = true; + acl.rights[esp_mail_imap_rights_post] = true; + acl.rights[esp_mail_imap_rights_read] = true; + acl.rights[esp_mail_imap_rights_write] = true; + acl.rights[esp_mail_imap_rights_seen] = true; + + Serial.println("\nSet ACLs..."); + + if (!imap.setACL("INBOX", &acl)) + { + Serial.println("Set ACLs failed"); + } + else + { + Serial.println("Set ACLs success"); + } + + Serial.println("\nGet my rights..."); + + if (!imap.myRights("INBOX", &acl)) + { + Serial.println("Set my rights failed"); + } + else + { + Serial.print("Rights: "); + + String r; + for (int i = esp_mail_imap_rights_administer; i < esp_mail_imap_rights_maxType; i++) + { + if (acl.rights[i]) + r += (char)('a' + i); + } + + Serial.println(r); + } + + Serial.println("\nDelete ACLs..."); + + if (!imap.deleteACL("INBOX", "Steve")) + { + Serial.println("Set ACLs failed"); + } + else + { + Serial.println("Delete ACLs success"); + } + + MailClient.printf("Free Heap: %d\n", MailClient.getFreeHeap()); +} + +void loop() +{ +} diff --git a/lib/libesp32/ESP-Mail-Client/examples/IMAP/Append_Message/Append_Message.ino b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Append_Message/Append_Message.ino new file mode 100644 index 000000000..d7bbea2c2 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Append_Message/Append_Message.ino @@ -0,0 +1,239 @@ +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt +*/ + +// This example shows how to append message to mailbox. + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +/** Assign SD card type and FS used in src/ESP_Mail_FS.h and + * change the config for that card interfaces in src/extras/SDHelper.h + */ + +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +#include + +#include + +// required IMAP and SMTP +#if defined(ENABLE_IMAP) && defined(ENABLE_SMTP) + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +/** For Gmail, IMAP option should be enabled. https://support.google.com/mail/answer/7126229?hl=en + * and also https://accounts.google.com/b/0/DisplayUnlockCaptcha + * + * Some Gmail user still not able to sign in using account password even above options were set up, + * for this case, use "App Password" to sign in instead. + * About Gmail "App Password", go to https://support.google.com/accounts/answer/185833?hl=en + * + * For Yahoo mail, log in to your yahoo mail in web browser and generate app password by go to + * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc + * + * To use Gmai and Yahoo's App Password to sign in, define the AUTHOR_PASSWORD with your App Password + * and AUTHOR_EMAIL with your account email. + */ + +/* The imap host name e.g. imap.gmail.com for GMail or outlook.office365.com for Outlook */ +#define IMAP_HOST "" + +/** The imap port e.g. + * 143 or esp_mail_imap_port_143 + * 993 or esp_mail_imap_port_993 + */ +#define IMAP_PORT 993 + +/* The log in credentials */ +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" + +/* Declare the global used IMAPSession object for IMAP transport */ +IMAPSession imap; + +/* Callback function to get the Email reading status */ +void imapCallback(IMAP_Status status) +{ + /* Print the current status */ + Serial.println(status.info()); +} + +#endif + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) +WiFiMulti multi; +#endif + +void setup() +{ + + Serial.begin(115200); + +// required IMAP and SMTP +#if defined(ENABLE_IMAP) && defined(ENABLE_SMTP) + +#if defined(ARDUINO_ARCH_SAMD) + while (!Serial) + ; +#endif + + Serial.println(); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + multi.addAP(WIFI_SSID, WIFI_PASSWORD); + multi.run(); +#else + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Connecting to Wi-Fi"); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + unsigned long ms = millis(); +#endif + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + if (millis() - ms > 10000) + break; +#endif + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + /* Set the network reconnection option */ + MailClient.networkReconnect(true); + + // The WiFi credentials are required for Pico W + // due to it does not have reconnect feature. +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + MailClient.clearAP(); + MailClient.addAP(WIFI_SSID, WIFI_PASSWORD); +#endif + + /** Enable the debug via Serial port + * 0 for no debugging + * 1 for basic level debugging + * + * Debug port can be changed via ESP_MAIL_DEFAULT_DEBUG_PORT in ESP_Mail_FS.h + */ + imap.debug(1); + + /* Set the callback function to get the reading results */ + imap.callback(imapCallback); + + /* Declare the Session_Config for user defined session credentials */ + Session_Config config; + + /* Set the session config */ + config.server.host_name = IMAP_HOST; + config.server.port = IMAP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + + /* Define the IMAP_Data object used for user defined IMAP operating options. */ + IMAP_Data imap_data; + + ESP_Mail_Message message[2]; // The same usage as SMTP_Message + + message[0].sender.name = "Fred Foobar"; + message[0].sender.email = "foobar@Blurdybloop.example.COM"; + message[0].subject = "afternoon meeting"; + message[0].addRecipient("Joe Mooch", "mooch@owatagu.example.net"); + message[0].text.content = "Hello Joe, do you think we can meet at 3:30 tomorrow?"; + message[0].text.charSet = "us-ascii"; + message[0].text.transfer_encoding = Content_Transfer_Encoding::enc_7bit; + + ESP_Mail_Attachment att[2]; // The same usage as SMTP_Attachment + + att[0].descr.filename = "shaun.png"; + att[0].descr.mime = "image/png"; + att[0].blob.data = shaun_png; + att[0].blob.size = sizeof(shaun_png); + att[0].descr.transfer_encoding = Content_Transfer_Encoding::enc_base64; + message[0].addAttachment(att[0]); + + message[1].sender.name = "Joe Mooch"; + message[1].sender.email = "mooch@OWaTaGu.example.net"; + message[1].subject = "Re: afternoon meeting"; + message[1].addRecipient("Fred Foobar", "foobar@blurdybloop.example.com"); + message[1].text.content = "3:30 is fine with me."; + message[1].text.charSet = "us-ascii"; + message[1].text.transfer_encoding = Content_Transfer_Encoding::enc_7bit; + + att[1].descr.filename = "mu_law.wav"; + att[1].descr.mime = "audio/basic"; + att[1].blob.data = mu_law_wave; + att[1].blob.size = sizeof(mu_law_wave); + att[1].descr.transfer_encoding = Content_Transfer_Encoding::enc_base64; + + message[1].addAttachment(att[1]); + + /* Connect to the server */ + if (!imap.connect(&config, &imap_data)) + return; + + if (imap.isAuthenticated()) + Serial.println("\nSuccessfully logged in."); + else + Serial.println("\nConnected with no Auth."); + + if (!imap.selectFolder(F("INBOX"))) + return; + + // If MULTIAPPEND extension is supported, the multiple messages will send by a single APPEND command. + // If not, one message can append for a APPEND command. + // Outlook.com does not accept flag and date/time arguments in APPEND command + if (!MailClient.appendMessage(&imap, &message[0], false /* if not last message to append */, "\\Flagged" /* flags or empty string for Outlook.com */, "Thu, 16 Jun 2022 12:30:25 -0800 (PST)" /* date/time or empty string for Outlook.com */)) + MailClient.printf("Message appending error, Error Code: %d, Reason: %s", imap.errorCode(), imap.errorReason().c_str()); + + if (!MailClient.appendMessage(&imap, &message[1], true /* last message to append */)) + MailClient.printf("Message appending error, Error Code: %d, Reason: %s", imap.errorCode(), imap.errorReason().c_str()); + + MailClient.printf("Free Heap: %d\n", MailClient.getFreeHeap()); + +#endif +} + +void loop() +{ +} diff --git a/lib/libesp32/lib_mail/examples/Send_Parallel_Attachment/data.h b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Append_Message/data.h similarity index 98% rename from lib/libesp32/lib_mail/examples/Send_Parallel_Attachment/data.h rename to lib/libesp32/ESP-Mail-Client/examples/IMAP/Append_Message/data.h index 0b73e9752..c7a88aeab 100644 --- a/lib/libesp32/lib_mail/examples/Send_Parallel_Attachment/data.h +++ b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Append_Message/data.h @@ -1,1957 +1,1957 @@ -#include - -static const uint8_t mu_law_wave[] PROGMEM = { -0x52, 0x49, 0x46, 0x46, 0x84, 0x5D, 0x00, 0x00, 0x57, 0x41, 0x56, 0x45, 0x66, 0x6D, 0x74, 0x20, -0x12, 0x00, 0x00, 0x00, 0x07, 0x00, 0x01, 0x00, 0x40, 0x1F, 0x00, 0x00, 0x40, 0x1F, 0x00, 0x00, -0x01, 0x00, 0x08, 0x00, 0x00, 0x00, 0x66, 0x61, 0x63, 0x74, 0x04, 0x00, 0x00, 0x00, 0x00, 0x5D, -0x00, 0x00, 0x64, 0x61, 0x74, 0x61, 0x00, 0x5D, 0x00, 0x00, 0xFB, 0xFD, 0xFF, 0xFE, 0xFF, 0x7F, -0x7F, 0x7E, 0x7E, 0x7D, 0x7C, 0x7D, 0x7D, 0x7C, 0x7D, 0x7D, 0x7E, 0x7E, 0x7E, 0x7E, 0x7C, 0x7D, -0x7C, 0x7C, 0x7D, 0x7F, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x7E, 0xFF, 0x7F, -0x7D, 0x7C, 0x7B, 0x7B, 0x7B, 0x7A, 0x79, 0x79, 0x7A, 0x7B, 0x7A, 0x79, 0x7A, 0x7C, 0x7C, 0x7B, -0x7B, 0x7B, 0x7A, 0x7A, 0x7B, 0x7A, 0x7A, 0x7B, 0x7A, 0x79, 0x7A, 0x7B, 0x7B, 0x7A, 0x7C, 0x7E, -0x7B, 0x7A, 0x7B, 0x7B, 0x7B, 0x79, 0x79, 0x7B, 0x7B, 0x7B, 0x7C, 0x7C, 0x7E, 0xFF, 0xFE, 0xFE, -0xFF, 0x7E, 0x7C, 0x7D, 0x7F, 0x7F, 0x7E, 0x7E, 0x7D, 0x7C, 0x7B, 0x7A, 0x79, 0x79, 0x78, 0x79, -0x7A, 0x79, 0x78, 0x78, 0x78, 0x77, 0x78, 0x78, 0x79, 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FF, 0xFF, 0xFF, -0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, -0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, -0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, -0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, -0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, -0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x4C, 0x49, 0x53, 0x54, 0x4A, 0x00, -0x00, 0x00, 0x49, 0x4E, 0x46, 0x4F, 0x49, 0x53, 0x46, 0x54, 0x3E, 0x00, 0x00, 0x00, 0x46, 0x69, -0x6C, 0x65, 0x20, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x20, 0x62, 0x79, 0x20, 0x47, 0x6F, -0x6C, 0x64, 0x57, 0x61, 0x76, 0x65, 0x2E, 0x20, 0x20, 0x47, 0x6F, 0x6C, 0x64, 0x57, 0x61, 0x76, -0x65, 0x20, 0x63, 0x6F, 0x70, 0x79, 0x72, 0x69, 0x67, 0x68, 0x74, 0x20, 0x28, 0x43, 0x29, 0x20, -0x43, 0x68, 0x72, 0x69, 0x73, 0x20, 0x43, 0x72, 0x61, 0x69, 0x67, 0x00 - -}; - -static const uint8_t shaun_png[] PROGMEM = { - 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00, 0x00, 0x00, 0x0D, 0x49, 0x48, 0x44, 0x52, - 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x57, 0x08, 0x06, 0x00, 0x00, 0x00, 0xF2, 0x0C, 0xE0, - 0x57, 0x00, 0x00, 0x00, 0x06, 0x62, 0x4B, 0x47, 0x44, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0xA0, - 0xBD, 0xA7, 0x93, 0x00, 0x00, 0x00, 0x09, 0x70, 0x48, 0x59, 0x73, 0x00, 0x00, 0x42, 0x8A, 0x00, - 0x00, 0x42, 0x8A, 0x01, 0x34, 0xA8, 0x6C, 0x25, 0x00, 0x00, 0x00, 0x09, 0x76, 0x70, 0x41, 0x67, - 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x57, 0x00, 0x73, 0x4D, 0x3B, 0xD6, 0x00, 0x00, 0x1B, - 0x47, 0x49, 0x44, 0x41, 0x54, 0x78, 0xDA, 0xED, 0x9D, 0x79, 0x74, 0x14, 0x55, 0xBE, 0xC7, 0x3F, - 0x55, 0xDD, 0x49, 0x67, 0x5F, 0x3A, 0x7B, 0x42, 0x82, 0x61, 0x49, 0x02, 0x81, 0xB0, 0x29, 0x32, - 0x22, 0x3C, 0x16, 0x41, 0x45, 0x10, 0x15, 0x7D, 0x13, 0x65, 0xD0, 0x81, 0xE3, 0x7B, 0xCC, 0xD3, - 0x51, 0x04, 0xF5, 0xE1, 0xB8, 0xCE, 0xE6, 0x28, 0x22, 0x23, 0x33, 0x2C, 0x2A, 0x22, 0xEE, 0x02, - 0x22, 0x0C, 0x2A, 0x83, 0x28, 0x7B, 0x20, 0xC8, 0x92, 0x10, 0xD9, 0x97, 0x40, 0x08, 0x81, 0x90, - 0x3D, 0x64, 0x21, 0xE9, 0x4E, 0x3A, 0x5D, 0xF7, 0xFD, 0x71, 0xBB, 0x93, 0x0E, 0x10, 0xD2, 0x59, - 0x3A,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5, 0x22, 0x09, 0x5D, 0x8C, 0xF4, 0xEA, 0x1D, 0x45, 0xA6, 0x1C, 0x67, 0x20, 0x23, 0x44, - 0x2A, 0x5B, 0x76, 0xDB, 0xCE, 0xC1, 0xFF, 0x01, 0xCE, 0x34, 0xF5, 0xEC, 0x2D, 0xA9, 0x9C, 0xA8, - 0x00, 0x00, 0x00, 0x25, 0x74, 0x45, 0x58, 0x74, 0x64, 0x61, 0x74, 0x65, 0x3A, 0x63, 0x72, 0x65, - 0x61, 0x74, 0x65, 0x00, 0x32, 0x30, 0x31, 0x32, 0x2D, 0x30, 0x31, 0x2D, 0x33, 0x31, 0x54, 0x31, - 0x33, 0x3A, 0x34, 0x31, 0x3A, 0x31, 0x38, 0x2D, 0x30, 0x38, 0x3A, 0x30, 0x30, 0xED, 0x4F, 0xCC, - 0x0D, 0x00, 0x00, 0x00, 0x25, 0x74, 0x45, 0x58, 0x74, 0x64, 0x61, 0x74, 0x65, 0x3A, 0x6D, 0x6F, - 0x64, 0x69, 0x66, 0x79, 0x00, 0x32, 0x30, 0x31, 0x32, 0x2D, 0x30, 0x31, 0x2D, 0x33, 0x31, 0x54, - 0x31, 0x33, 0x3A, 0x34, 0x31, 0x3A, 0x31, 0x38, 0x2D, 0x30, 0x38, 0x3A, 0x30, 0x30, 0x9C, 0x12, - 0x74, 0xB1, 0x00, 0x00, 0x00, 0x19, 0x74, 0x45, 0x58, 0x74, 0x53, 0x6F, 0x66, 0x74, 0x77, 0x61, - 0x72, 0x65, 0x00, 0x77, 0x77, 0x77, 0x2E, 0x69, 0x6E, 0x6B, 0x73, 0x63, 0x61, 0x70, 0x65, 0x2E, - 0x6F, 0x72, 0x67, 0x9B, 0xEE, 0x3C, 0x1A, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4E, 0x44, 0xAE, +#include + +static const uint8_t mu_law_wave[] PROGMEM = { +0x52, 0x49, 0x46, 0x46, 0x84, 0x5D, 0x00, 0x00, 0x57, 0x41, 0x56, 0x45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F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, +0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, +0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, +0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, +0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x4C, 0x49, 0x53, 0x54, 0x4A, 0x00, +0x00, 0x00, 0x49, 0x4E, 0x46, 0x4F, 0x49, 0x53, 0x46, 0x54, 0x3E, 0x00, 0x00, 0x00, 0x46, 0x69, +0x6C, 0x65, 0x20, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x20, 0x62, 0x79, 0x20, 0x47, 0x6F, +0x6C, 0x64, 0x57, 0x61, 0x76, 0x65, 0x2E, 0x20, 0x20, 0x47, 0x6F, 0x6C, 0x64, 0x57, 0x61, 0x76, +0x65, 0x20, 0x63, 0x6F, 0x70, 0x79, 0x72, 0x69, 0x67, 0x68, 0x74, 0x20, 0x28, 0x43, 0x29, 0x20, +0x43, 0x68, 0x72, 0x69, 0x73, 0x20, 0x43, 0x72, 0x61, 0x69, 0x67, 0x00 + +}; + +static const uint8_t shaun_png[] PROGMEM = { + 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00, 0x00, 0x00, 0x0D, 0x49, 0x48, 0x44, 0x52, + 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x57, 0x08, 0x06, 0x00, 0x00, 0x00, 0xF2, 0x0C, 0xE0, + 0x57, 0x00, 0x00, 0x00, 0x06, 0x62, 0x4B, 0x47, 0x44, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0xA0, + 0xBD, 0xA7, 0x93, 0x00, 0x00, 0x00, 0x09, 0x70, 0x48, 0x59, 0x73, 0x00, 0x00, 0x42, 0x8A, 0x00, + 0x00, 0x42, 0x8A, 0x01, 0x34, 0xA8, 0x6C, 0x25, 0x00, 0x00, 0x00, 0x09, 0x76, 0x70, 0x41, 0x67, + 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x57, 0x00, 0x73, 0x4D, 0x3B, 0xD6, 0x00, 0x00, 0x1B, + 0x47, 0x49, 0x44, 0x41, 0x54, 0x78, 0xDA, 0xED, 0x9D, 0x79, 0x74, 0x14, 0x55, 0xBE, 0xC7, 0x3F, + 0x55, 0xDD, 0x49, 0x67, 0x5F, 0x3A, 0x7B, 0x42, 0x82, 0x61, 0x49, 0x02, 0x81, 0xB0, 0x29, 0x32, + 0x22, 0x3C, 0x16, 0x41, 0x45, 0x10, 0x15, 0x7D, 0x13, 0x65, 0xD0, 0x81, 0xE3, 0x7B, 0xCC, 0xD3, + 0x51, 0x04, 0xF5, 0xE1, 0xB8, 0xCE, 0xE6, 0x28, 0x22, 0x23, 0x33, 0x2C, 0x2A, 0x22, 0xEE, 0x02, + 0x22, 0x0C, 0x2A, 0x83, 0x28, 0x7B, 0x20, 0xC8, 0x92, 0x10, 0xD9, 0x97, 0x40, 0x08, 0x81, 0x90, + 0x3D, 0x64, 0x21, 0xE9, 0x4E, 0x3A, 0x5D, 0xF7, 0xFD, 0x71, 0xBB, 0x93, 0x0E, 0x10, 0xD2, 0x59, + 0x3A, 0x01, 0xCF, 0xFB, 0x9E, 0xD3, 0xE7, 0xA4, 0x6E, 0xA5, 0x6E, 0xDD, 0xFA, 0xFD, 0xEA, 0xFE, + 0xEE, 0xEF, 0xFE, 0xB6, 0x52, 0xB8, 0xFE, 0xA1, 0x03, 0x7A, 0x01, 0x43, 0x81, 0x9B, 0x80, 0x6A, + 0x60, 0x3F, 0xA0, 0x02, 0x8F, 0x00, 0xB7, 0x03, 0xA1, 0x80, 0x00, 0x72, 0x81, 0xAD, 0xC0, 0xC7, + 0xC0, 0x6E, 0xA0, 0xAE, 0xB3, 0x07, 0xFF, 0x4B, 0x43, 0x30, 0xF0, 0x67, 0x20, 0x1B, 0xB0, 0x20, + 0x89, 0xAE, 0x01, 0x95, 0x40, 0xB9, 0xED, 0xF8, 0x6A, 0xBF, 0x3C, 0xDB, 0x75, 0x81, 0xCD, 0xF4, + 0xAF, 0x03, 0x8C, 0x40, 0x2C, 0xD0, 0x13, 0x88, 0x00, 0x0C, 0x9D, 0xF9, 0xC0, 0x4A, 0x27, 0xDD, + 0xD7, 0x13, 0x88, 0x07, 0xFA, 0x03, 0x51, 0x36, 0x22, 0xE4, 0x03, 0x87, 0x80, 0x83, 0x48, 0x62, + 0x1B, 0x81, 0x85, 0x40, 0x72, 0x2B, 0xC7, 0xA9, 0x01, 0x5F, 0x00, 0x2F, 0x03, 0x35, 0xB6, 0xE3, + 0x0A, 0xDB, 0xDF, 0xDE, 0xC0, 0x48, 0x60, 0x22, 0x30, 0x08, 0xC9, 0x78, 0x3D, 0x92, 0xD1, 0x99, + 0xC0, 0x0F, 0xC0, 0x5A, 0xE0, 0x5C, 0x47, 0x13, 0xA6, 0xA3, 0x19, 0xA2, 0x07, 0x46, 0x00, 0x4F, + 0x22, 0x45, 0x4D, 0xD0, 0x65, 0x63, 0xB8, 0x84, 0x14, 0x47, 0xEF, 0x03, 0x09, 0xC0, 0x4B, 0x48, + 0xD1, 0x44, 0x40, 0x40, 0x00, 0x31, 0x31, 0x31, 0x54, 0x56, 0x56, 0x92, 0x93, 0x93, 0x83, 0xD5, + 0x6A, 0x25, 0x3A, 0x3A, 0x9A, 0x89, 0x13, 0x27, 0x32, 0x60, 0xC0, 0x00, 0xAC, 0x56, 0x2B, 0xBB, + 0x77, 0xE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xF5, 0xEC, 0x2D, 0xA9, 0x9C, 0xA8, + 0x00, 0x00, 0x00, 0x25, 0x74, 0x45, 0x58, 0x74, 0x64, 0x61, 0x74, 0x65, 0x3A, 0x63, 0x72, 0x65, + 0x61, 0x74, 0x65, 0x00, 0x32, 0x30, 0x31, 0x32, 0x2D, 0x30, 0x31, 0x2D, 0x33, 0x31, 0x54, 0x31, + 0x33, 0x3A, 0x34, 0x31, 0x3A, 0x31, 0x38, 0x2D, 0x30, 0x38, 0x3A, 0x30, 0x30, 0xED, 0x4F, 0xCC, + 0x0D, 0x00, 0x00, 0x00, 0x25, 0x74, 0x45, 0x58, 0x74, 0x64, 0x61, 0x74, 0x65, 0x3A, 0x6D, 0x6F, + 0x64, 0x69, 0x66, 0x79, 0x00, 0x32, 0x30, 0x31, 0x32, 0x2D, 0x30, 0x31, 0x2D, 0x33, 0x31, 0x54, + 0x31, 0x33, 0x3A, 0x34, 0x31, 0x3A, 0x31, 0x38, 0x2D, 0x30, 0x38, 0x3A, 0x30, 0x30, 0x9C, 0x12, + 0x74, 0xB1, 0x00, 0x00, 0x00, 0x19, 0x74, 0x45, 0x58, 0x74, 0x53, 0x6F, 0x66, 0x74, 0x77, 0x61, + 0x72, 0x65, 0x00, 0x77, 0x77, 0x77, 0x2E, 0x69, 0x6E, 0x6B, 0x73, 0x63, 0x61, 0x70, 0x65, 0x2E, + 0x6F, 0x72, 0x67, 0x9B, 0xEE, 0x3C, 0x1A, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4E, 0x44, 0xAE, 0x42, 0x60, 0x82}; \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/examples/IMAP/Copy_Messages/Copy_Messages_List/Copy_Messages_List.ino b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Copy_Messages/Copy_Messages_List/Copy_Messages_List.ino new file mode 100644 index 000000000..3a1511777 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Copy_Messages/Copy_Messages_List/Copy_Messages_List.ino @@ -0,0 +1,220 @@ +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt +*/ + +// This example shows how to copy messages from the mailbox to other folder. + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +/** For ESP8266, with BearSSL WiFi Client + * The memory reserved for completed valid SSL response from IMAP is 16 kbytes which + * may cause your device out of memory reset in case the memory + * allocation error. + */ + +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +#include + +// To use only IMAP functions, you can exclude the SMTP from compilation, see ESP_Mail_FS.h. + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +/** For Gmail, IMAP option should be enabled. https://support.google.com/mail/answer/7126229?hl=en + * and also https://accounts.google.com/b/0/DisplayUnlockCaptcha + * + * Some Gmail user still not able to sign in using account password even above options were set up, + * for this case, use "App Password" to sign in instead. + * About Gmail "App Password", go to https://support.google.com/accounts/answer/185833?hl=en + * + * For Yahoo mail, log in to your yahoo mail in web browser and generate app password by go to + * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc + * + * To use Gmai and Yahoo's App Password to sign in, define the AUTHOR_PASSWORD with your App Password + * and AUTHOR_EMAIL with your account email. + */ + +/* The imap host name e.g. imap.gmail.com for GMail or outlook.office365.com for Outlook */ +#define IMAP_HOST "" + +/** The imap port e.g. + * 143 or esp_mail_imap_port_143 + * 993 or esp_mail_imap_port_993 + */ +#define IMAP_PORT 993 + +/* The log in credentials */ +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" + +/* Print the list of mailbox folders */ +void printAllMailboxesInfo(IMAPSession &imap); + +/* Declare the global used IMAPSession object for IMAP transport */ +IMAPSession imap; + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) +WiFiMulti multi; +#endif + +void setup() +{ + + Serial.begin(115200); + +#if defined(ARDUINO_ARCH_SAMD) + while (!Serial) + ; +#endif + + Serial.println(); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + multi.addAP(WIFI_SSID, WIFI_PASSWORD); + multi.run(); +#else + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Connecting to Wi-Fi"); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + unsigned long ms = millis(); +#endif + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + if (millis() - ms > 10000) + break; +#endif + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + /* Set the network reconnection option */ + MailClient.networkReconnect(true); + + // The WiFi credentials are required for Pico W + // due to it does not have reconnect feature. +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + MailClient.clearAP(); + MailClient.addAP(WIFI_SSID, WIFI_PASSWORD); +#endif + + /** Enable the debug via Serial port + * 0 for no debugging + * 1 for basic level debugging + * + * Debug port can be changed via ESP_MAIL_DEFAULT_DEBUG_PORT in ESP_Mail_FS.h + */ + imap.debug(1); + + /* Declare the Session_Config for user defined session credentials */ + Session_Config config; + + /* Set the session config */ + config.server.host_name = IMAP_HOST; + config.server.port = IMAP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + + /* Define the IMAP_Data object used for user defined IMAP operating options. */ + IMAP_Data imap_data; + + /* Connect to the server */ + if (!imap.connect(&config, &imap_data)) + return; + + if (imap.isAuthenticated()) + Serial.println("\nSuccessfully logged in."); + else + Serial.println("\nConnected with no Auth."); + + /* {Optional} */ + printAllMailboxesInfo(imap); + + /* Open or select the mailbox folder to read or search the message */ + if (!imap.selectFolder(F("INBOX"))) + return; + + /* Define the MessageList class to add the message to copy */ + MessageList toCopy; + + /* Add message uid to copy to the list */ + toCopy.add(3); + toCopy.add(4); + + // imap.createFolder("test"); + + /* Copy all messages in the list to the folder "test" */ + if (imap.copyMessages(&toCopy, F("test"))) + MailClient.printf("\nMessages copied\n"); + + /* Delete all messages in the list from the opened folder (move to trash) */ + // imap.deleteMessages(&toCopy); + + // imap.deleteolder("test"); + // imap.deleteolder("test2"); + + MailClient.printf("Free Heap: %d\n", MailClient.getFreeHeap()); +} + +void loop() +{ +} + +void printAllMailboxesInfo(IMAPSession &imap) +{ + /* Declare the folder collection class to get the list of mailbox folders */ + FoldersCollection folders; + + /* Get the mailbox folders */ + if (imap.getFolders(folders)) + { + for (size_t i = 0; i < folders.size(); i++) + { + /* Iterate each folder info using the folder info item data */ + FolderInfo folderInfo = folders.info(i); + MailClient.printf("%s%s%s", i == 0 ? "\nAvailable folders: " : ", ", folderInfo.name, i == folders.size() - 1 ? "\n" : ""); + } + } +} diff --git a/lib/libesp32/ESP-Mail-Client/examples/IMAP/Copy_Messages/Copy_Messages_Message_Numbers_Ranges/Copy_Messages_Message_Numbers_Ranges.ino b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Copy_Messages/Copy_Messages_Message_Numbers_Ranges/Copy_Messages_Message_Numbers_Ranges.ino new file mode 100644 index 000000000..958037525 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Copy_Messages/Copy_Messages_Message_Numbers_Ranges/Copy_Messages_Message_Numbers_Ranges.ino @@ -0,0 +1,214 @@ +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt +*/ + +// This example shows how to copy messages from the mailbox to other folder using message numbers ranges. + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +/** For ESP8266, with BearSSL WiFi Client + * The memory reserved for completed valid SSL response from IMAP is 16 kbytes which + * may cause your device out of memory reset in case the memory + * allocation error. + */ + +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +#include + +// To use only IMAP functions, you can exclude the SMTP from compilation, see ESP_Mail_FS.h. + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +/** For Gmail, IMAP option should be enabled. https://support.google.com/mail/answer/7126229?hl=en + * and also https://accounts.google.com/b/0/DisplayUnlockCaptcha + * + * Some Gmail user still not able to sign in using account password even above options were set up, + * for this case, use "App Password" to sign in instead. + * About Gmail "App Password", go to https://support.google.com/accounts/answer/185833?hl=en + * + * For Yahoo mail, log in to your yahoo mail in web browser and generate app password by go to + * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc + * + * To use Gmai and Yahoo's App Password to sign in, define the AUTHOR_PASSWORD with your App Password + * and AUTHOR_EMAIL with your account email. + */ + +/* The imap host name e.g. imap.gmail.com for GMail or outlook.office365.com for Outlook */ +#define IMAP_HOST "" + +/** The imap port e.g. + * 143 or esp_mail_imap_port_143 + * 993 or esp_mail_imap_port_993 + */ +#define IMAP_PORT 993 + +/* The log in credentials */ +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" + +/* Print the list of mailbox folders */ +void printAllMailboxesInfo(IMAPSession &imap); + +/* Declare the global used IMAPSession object for IMAP transport */ +IMAPSession imap; + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) +WiFiMulti multi; +#endif + +void setup() +{ + + Serial.begin(115200); + +#if defined(ARDUINO_ARCH_SAMD) + while (!Serial) + ; +#endif + + Serial.println(); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + multi.addAP(WIFI_SSID, WIFI_PASSWORD); + multi.run(); +#else + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Connecting to Wi-Fi"); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + unsigned long ms = millis(); +#endif + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + if (millis() - ms > 10000) + break; +#endif + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + /* Set the network reconnection option */ + MailClient.networkReconnect(true); + + // The WiFi credentials are required for Pico W + // due to it does not have reconnect feature. +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + MailClient.clearAP(); + MailClient.addAP(WIFI_SSID, WIFI_PASSWORD); +#endif + + /** Enable the debug via Serial port + * 0 for no debugging + * 1 for basic level debugging + * + * Debug port can be changed via ESP_MAIL_DEFAULT_DEBUG_PORT in ESP_Mail_FS.h + */ + imap.debug(1); + + /* Declare the Session_Config for user defined session credentials */ + Session_Config config; + + /* Set the session config */ + config.server.host_name = IMAP_HOST; + config.server.port = IMAP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + + /* Define the IMAP_Data object used for user defined IMAP operating options. */ + IMAP_Data imap_data; + + /* Connect to the server */ + if (!imap.connect(&config, &imap_data)) + return; + + if (imap.isAuthenticated()) + Serial.println("\nSuccessfully logged in."); + else + Serial.println("\nConnected with no Auth."); + + /* {Optional} */ + printAllMailboxesInfo(imap); + + /* Open or select the mailbox folder to read or search the message */ + if (!imap.selectFolder(F("INBOX"))) + return; + + /* Copy all messages using message sequence ranges (last 10 message numbers) to the folder "test"*/ + int msg_last = imap.selectedFolder().msgCount(); + int msg_begin = msg_last > 10 ? msg_last - 10 : msg_last; + + String sequence_set2 = String(msg_begin) + ":" + String(msg_last); + + if (imap.copyMessages(sequence_set2, false /* if sequence set are message numbers not UIDs */, F("test"))) + MailClient.printf("\nCopying messages using message numbers ranges success\n"); + else + MailClient.printf("\nError, copying messages using message numbers ranges\n"); + + // imap.deleteolder("test"); + + MailClient.printf("Free Heap: %d\n", MailClient.getFreeHeap()); +} + +void loop() +{ +} + +void printAllMailboxesInfo(IMAPSession &imap) +{ + /* Declare the folder collection class to get the list of mailbox folders */ + FoldersCollection folders; + + /* Get the mailbox folders */ + if (imap.getFolders(folders)) + { + for (size_t i = 0; i < folders.size(); i++) + { + /* Iterate each folder info using the folder info item data */ + FolderInfo folderInfo = folders.info(i); + MailClient.printf("%s%s%s", i == 0 ? "\nAvailable folders: " : ", ", folderInfo.name, i == folders.size() - 1 ? "\n" : ""); + } + } +} diff --git a/lib/libesp32/ESP-Mail-Client/examples/IMAP/Copy_Messages/Copy_Messages_UIDs_Ranges/Copy_Messages_UIDs_Ranges.ino b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Copy_Messages/Copy_Messages_UIDs_Ranges/Copy_Messages_UIDs_Ranges.ino new file mode 100644 index 000000000..1fdc5c6bf --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Copy_Messages/Copy_Messages_UIDs_Ranges/Copy_Messages_UIDs_Ranges.ino @@ -0,0 +1,214 @@ +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt +*/ + +// This example shows how to copy messages from the mailbox to other folder using UIDs ranges. + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +/** For ESP8266, with BearSSL WiFi Client + * The memory reserved for completed valid SSL response from IMAP is 16 kbytes which + * may cause your device out of memory reset in case the memory + * allocation error. + */ + +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +#include + +// To use only IMAP functions, you can exclude the SMTP from compilation, see ESP_Mail_FS.h. + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +/** For Gmail, IMAP option should be enabled. https://support.google.com/mail/answer/7126229?hl=en + * and also https://accounts.google.com/b/0/DisplayUnlockCaptcha + * + * Some Gmail user still not able to sign in using account password even above options were set up, + * for this case, use "App Password" to sign in instead. + * About Gmail "App Password", go to https://support.google.com/accounts/answer/185833?hl=en + * + * For Yahoo mail, log in to your yahoo mail in web browser and generate app password by go to + * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc + * + * To use Gmai and Yahoo's App Password to sign in, define the AUTHOR_PASSWORD with your App Password + * and AUTHOR_EMAIL with your account email. + */ + +/* The imap host name e.g. imap.gmail.com for GMail or outlook.office365.com for Outlook */ +#define IMAP_HOST "" + +/** The imap port e.g. + * 143 or esp_mail_imap_port_143 + * 993 or esp_mail_imap_port_993 + */ +#define IMAP_PORT 993 + +/* The log in credentials */ +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" + +/* Print the list of mailbox folders */ +void printAllMailboxesInfo(IMAPSession &imap); + +/* Declare the global used IMAPSession object for IMAP transport */ +IMAPSession imap; + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) +WiFiMulti multi; +#endif + +void setup() +{ + + Serial.begin(115200); + +#if defined(ARDUINO_ARCH_SAMD) + while (!Serial) + ; +#endif + + Serial.println(); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + multi.addAP(WIFI_SSID, WIFI_PASSWORD); + multi.run(); +#else + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Connecting to Wi-Fi"); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + unsigned long ms = millis(); +#endif + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + if (millis() - ms > 10000) + break; +#endif + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + /* Set the network reconnection option */ + MailClient.networkReconnect(true); + + // The WiFi credentials are required for Pico W + // due to it does not have reconnect feature. +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + MailClient.clearAP(); + MailClient.addAP(WIFI_SSID, WIFI_PASSWORD); +#endif + + /** Enable the debug via Serial port + * 0 for no debugging + * 1 for basic level debugging + * + * Debug port can be changed via ESP_MAIL_DEFAULT_DEBUG_PORT in ESP_Mail_FS.h + */ + imap.debug(1); + + /* Declare the Session_Config for user defined session credentials */ + Session_Config config; + + /* Set the session config */ + config.server.host_name = IMAP_HOST; + config.server.port = IMAP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + + /* Define the IMAP_Data object used for user defined IMAP operating options. */ + IMAP_Data imap_data; + + /* Connect to the server */ + if (!imap.connect(&config, &imap_data)) + return; + + if (imap.isAuthenticated()) + Serial.println("\nSuccessfully logged in."); + else + Serial.println("\nConnected with no Auth."); + + /* {Optional} */ + printAllMailboxesInfo(imap); + + /* Open or select the mailbox folder to read or search the message */ + if (!imap.selectFolder(F("INBOX"))) + return; + + /* Copy all messages using UIDs ranges (last 10 UIDs) to the folder "test" */ + int uid_last = imap.getUID(imap.selectedFolder().msgCount()); + int uid_begin = uid_last > 10 ? uid_last - 10 : uid_last; + + String sequence_set1 = String(uid_begin) + ":" + String(uid_last); + + if (imap.copyMessages(sequence_set1, true /* if sequence set are the UIDs */, F("test"))) + MailClient.printf("\nCopying messages using UIDs ranges success\n"); + else + MailClient.printf("\nError, copying messages using UIDs ranges\n"); + + // imap.deleteolder("test"); + + MailClient.printf("Free Heap: %d\n", MailClient.getFreeHeap()); +} + +void loop() +{ +} + +void printAllMailboxesInfo(IMAPSession &imap) +{ + /* Declare the folder collection class to get the list of mailbox folders */ + FoldersCollection folders; + + /* Get the mailbox folders */ + if (imap.getFolders(folders)) + { + for (size_t i = 0; i < folders.size(); i++) + { + /* Iterate each folder info using the folder info item data */ + FolderInfo folderInfo = folders.info(i); + MailClient.printf("%s%s%s", i == 0 ? "\nAvailable folders: " : ", ", folderInfo.name, i == folders.size() - 1 ? "\n" : ""); + } + } +} diff --git a/lib/libesp32/ESP-Mail-Client/examples/IMAP/Custom_Character_Decoding/Custom_Character_Decoding.ino b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Custom_Character_Decoding/Custom_Character_Decoding.ino new file mode 100644 index 000000000..f703bd316 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Custom_Character_Decoding/Custom_Character_Decoding.ino @@ -0,0 +1,498 @@ +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt + */ + +// This example shows how to read Email with custom character decoding for local language. + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +/** Assign SD card type and FS used in src/ESP_Mail_FS.h and + * change the config for that card interfaces in src/extras/SDHelper.h + */ + +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +#include + +// Provide the SD card interfaces setting and mounting +#include + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +/** For Gmail, IMAP option should be enabled. https://support.google.com/mail/answer/7126229?hl=en + * and also https://accounts.google.com/b/0/DisplayUnlockCaptcha + * + * Some Gmail user still not able to sign in using account password even above options were set up, + * for this case, use "App Password" to sign in instead. + * About Gmail "App Password", go to https://support.google.com/accounts/answer/185833?hl=en + * + * For Yahoo mail, log in to your yahoo mail in web browser and generate app password by go to + * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc + * + * To use Gmai and Yahoo's App Password to sign in, define the AUTHOR_PASSWORD with your App Password + * and AUTHOR_EMAIL with your account email. + */ + +/* The imap host name e.g. imap.gmail.com for GMail or outlook.office365.com for Outlook */ +#define IMAP_HOST "" + +/** The imap port e.g. + * 143 or esp_mail_imap_port_143 + * 993 or esp_mail_imap_port_993 + */ +#define IMAP_PORT 993 + +/* The log in credentials */ +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" + +/* Callback function to get the Email reading status */ +void imapCallback(IMAP_Status status); + +/* Callback function to decode the string based on character set of the content */ +void customCharacterDecodingCallback(IMAP_Decoding_Info *decoding); + +/* Print the list of mailbox folders */ +void printAllMailboxesInfo(IMAPSession &imap); + +/* Print the selected folder info */ +void printSelectedMailboxInfo(SelectedFolderInfo sFolder); + +/* Print all messages from the message list */ +void printMessages(std::vector &msgItems, bool headerOnly); + +/* Print all attachments info from the message */ +void printAttacements(std::vector &atts); + +/* Declare the global used IMAPSession object for IMAP transport */ +IMAPSession imap; + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) +WiFiMulti multi; +#endif + +void setup() +{ + + Serial.begin(115200); + +#if defined(ARDUINO_ARCH_SAMD) + while (!Serial) + ; +#endif + + Serial.println(); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + multi.addAP(WIFI_SSID, WIFI_PASSWORD); + multi.run(); +#else + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Connecting to Wi-Fi"); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + unsigned long ms = millis(); +#endif + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + if (millis() - ms > 10000) + break; +#endif + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + /* Set the network reconnection option */ + MailClient.networkReconnect(true); + + // The WiFi credentials are required for Pico W + // due to it does not have reconnect feature. +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + MailClient.clearAP(); + MailClient.addAP(WIFI_SSID, WIFI_PASSWORD); +#endif + +#if defined(ESP_MAIL_DEFAULT_SD_FS) // defined in src/ESP_Mail_FS.h + // Mount SD card. + SD_Card_Mounting(); // See src/extras/SDHelper.h +#endif + + /** Enable the debug via Serial port + * 0 for no debugging + * 1 for basic level debugging + * + * Debug port can be changed via ESP_MAIL_DEFAULT_DEBUG_PORT in ESP_Mail_FS.h + */ + imap.debug(1); + + /* Set the callback function to get the reading results */ + imap.callback(imapCallback); + + /* Set the callback function to decode the string based on the caracter set of string */ + imap.characterDecodingCallback(customCharacterDecodingCallback); + + /** In case the SD card/adapter was used for the file storagge, the SPI pins can be configure from + * MailClient.sdBegin function which may be different for ESP32 and ESP8266 + * For ESP32, assign all of SPI pins + * MailClient.sdBegin(14,2,15,13) + * Which SCK = 14, MISO = 2, MOSI = 15 and SS = 13 + * And for ESP8266, assign the CS pins of SPI port + * MailClient.sdBegin(15) + * Which pin 15 is the CS pin of SD card adapter + */ + + /* Declare the Session_Config for user defined session credentials */ + Session_Config config; + + /* Set the session config */ + config.server.host_name = IMAP_HOST; + config.server.port = IMAP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + + /* Define the IMAP_Data object used for user defined IMAP operating options. */ + IMAP_Data imap_data; + + /* Set the storage to save the downloaded files and attachments */ + imap_data.storage.saved_path = F("/email_data"); + + /** The file storage type e.g. + * esp_mail_file_storage_type_none, + * esp_mail_file_storage_type_flash, and + * esp_mail_file_storage_type_sd + */ + imap_data.storage.type = esp_mail_file_storage_type_sd; + + /** Set to download headers, text and html messaeges, + * attachments and inline images respectively. + */ + imap_data.download.header = true; + imap_data.download.text = true; + imap_data.download.html = true; + imap_data.download.attachment = true; + imap_data.download.inlineImg = true; + + /** Set to enable the results i.e. html and text messaeges + * which the content stored in the IMAPSession object is limited + * by the option imap_data.limit.msg_size. + * The whole message can be download through imap_data.download.text + * or imap_data.download.html which not depends on these enable options. + */ + imap_data.enable.html = true; + imap_data.enable.text = true; + + /* Set to enable the sort the result by message UID in the decending order */ + imap_data.enable.recent_sort = true; + + /* Set to report the download progress via the default serial port */ + imap_data.enable.download_status = true; + + /* Header fields parsing is case insensitive by default to avoid uppercase header in some server e.g. iCloud + , to allow case sensitive parse, uncomment below line*/ + // imap_data.enable.header_case_sensitive = true; + + /* Set the limit of number of messages in the search results */ + imap_data.limit.search = 5; + + /** Set the maximum size of message stored in + * IMAPSession object in byte + */ + imap_data.limit.msg_size = 512; + + /** Set the maximum attachments and inline images files size + * that can be downloaded in byte. + * The file which its size is largger than this limit may be saved + * as truncated file. + */ + imap_data.limit.attachment_size = 1024 * 1024 * 5; + + /* Connect to the server */ + if (!imap.connect(&config, &imap_data)) + return; + + if (imap.isAuthenticated()) + Serial.println("\nSuccessfully logged in."); + else + Serial.println("\nConnected with no Auth."); + + /* {Optional} */ + printAllMailboxesInfo(imap); + + /* Open or select the mailbox folder to read or search the message */ + if (!imap.selectFolder(F("INBOX"))) + return; + + /* {Optional} */ + printSelectedMailboxInfo(imap.selectedFolder()); + + /** Message UID to fetch or read e.g. 100. + * In this case we will get the UID from the max message number (lastest message) + */ + imap_data.fetch.uid = imap.getUID(imap.selectedFolder().msgCount()); + + // or fetch via the message sequence number + // imap_data.fetch.number = imap.selectedFolder().msgCount(); + + // if both imap_data.fetch.uid and imap_data.fetch.number were set, + // then total 2 messages will be fetched i.e. one using uid and other using number. + + /* Set seen flag */ + + // The message with "Seen" flagged means the message was already read or seen by user. + // The default value of this option is set to false. + // If you want to set the message flag as "Seen", set this option to true. + // If this option is false, the message flag was unchanged. + // To set or remove flag from message, see Set_Flags.ino example. + + // imap_data.fetch.set_seen = true; + + /* Read or search the Email and close the session */ + + // When message was fetched or read, the /Seen flag will not set or message remained in unseen or unread status, + // as this is the purpose of library (not UI application), user can set the message status as read by set \Seen flag + // to message, see the Set_Flags.ino example. + MailClient.readMail(&imap); + + /* Clear all stored data in IMAPSession object */ + imap.empty(); +} + +void loop() +{ +} + +void To_UTF8(IMAP_Decoding_Info *decoding) +{ + decoding->decodedString = "fake decoded string "; // return the decoded string +} + +void customCharacterDecodingCallback(IMAP_Decoding_Info *decoding) +{ + // Serial.println("***** Data Type *****"); + // 0 or IMAP_Decoding_Info::message_part_type_header or + // 1 or IMAP_Decoding_Info::message_part_type_text + // Serial.println(decoding->type); + + // Serial.println("***** Charset *****"); + // Serial.println(decoding->charset); + // Serial.println("***** String to Decode *****"); + // Serial.println(decoding->encoded); + + // The original or decoded string should be return to the process via + // decoding->decodedString + + // Then rturn the decoded string back to the process. + if (strlen(decoding->charset) == 0 || strcasecmp(decoding->charset, "utf-8") == 0 || strcasecmp(decoding->charset, "us-ascii") == 0) // return original + decoding->decodedString = decoding->data; + else // decode to UTF-8 or ASCII + To_UTF8(decoding); +} + +/* Callback function to get the Email reading status */ +void imapCallback(IMAP_Status status) +{ + /* Print the current status */ + MailClient.printf(status.info()); + + /* Show the result when reading finished */ + if (status.success()) + { + /* Print the result */ + /* Get the message list from the message list data */ + IMAP_MSG_List msgList = imap.data(); + printMessages(msgList.msgItems, imap.headerOnly()); + + /* Clear all stored data in IMAPSession object */ + imap.empty(); + } +} + +void printAllMailboxesInfo(IMAPSession &imap) +{ + /* Declare the folder collection class to get the list of mailbox folders */ + FoldersCollection folders; + + /* Get the mailbox folders */ + if (imap.getFolders(folders)) + { + for (size_t i = 0; i < folders.size(); i++) + { + /* Iterate each folder info using the folder info item data */ + FolderInfo folderInfo = folders.info(i); + MailClient.printf("%s%s%s", i == 0 ? "\nAvailable folders: " : ", ", folderInfo.name, i == folders.size() - 1 ? "\n" : ""); + } + } +} + +void printSelectedMailboxInfo(SelectedFolderInfo sFolder) +{ + /* Show the mailbox info */ + MailClient.printf("\nInfo of the selected folder\nTotal Messages: %d\n", sFolder.msgCount()); + MailClient.printf("UID Validity: %d\n", sFolder.uidValidity()); + MailClient.printf("Predicted next UID: %d\n", sFolder.nextUID()); + if (sFolder.unseenIndex() > 0) + MailClient.printf("First Unseen Message Number: %d\n", sFolder.unseenIndex()); + else + MailClient.printf("Unseen Messages: No\n"); + + if (sFolder.modSeqSupported()) + MailClient.printf("Highest Modification Sequence: %llu\n", sFolder.highestModSeq()); + for (size_t i = 0; i < sFolder.flagCount(); i++) + MailClient.printf("%s%s%s", i == 0 ? "Flags: " : ", ", sFolder.flag(i).c_str(), i == sFolder.flagCount() - 1 ? "\n" : ""); + + if (sFolder.flagCount(true)) + { + for (size_t i = 0; i < sFolder.flagCount(true); i++) + MailClient.printf("%s%s%s", i == 0 ? "Permanent Flags: " : ", ", sFolder.flag(i, true).c_str(), i == sFolder.flagCount(true) - 1 ? "\n" : ""); + } +} + +void printAttacements(std::vector &atts) +{ + MailClient.printf("Attachment: %d file(s)\n****************************\n", atts.size()); + for (size_t j = 0; j < atts.size(); j++) + { + IMAP_Attach_Item att = atts[j]; + /** att.type can be + * esp_mail_att_type_none or 0 + * esp_mail_att_type_attachment or 1 + * esp_mail_att_type_inline or 2 + */ + MailClient.printf("%d. Filename: %s, Name: %s, Size: %d, MIME: %s, Type: %s, Description: %s, Creation Date: %s\n", j + 1, att.filename, att.name, att.size, att.mime, att.type == esp_mail_att_type_attachment ? "attachment" : "inline", att.description, att.creationDate); + } + Serial.println(); +} + +void printMessages(std::vector &msgItems, bool headerOnly) +{ + + /** In devices other than ESP8266 and ESP32, if SD card was chosen as filestorage and + * the standard SD.h library included in ESP_Mail_FS.h, files will be renamed due to long filename + * (> 13 characters) is not support in the SD.h library. + * To show how its original file name, use imap.fileList(). + */ + // Serial.println(imap.fileList()); + + for (size_t i = 0; i < msgItems.size(); i++) + { + + /* Iterate to get each message data through the message item data */ + IMAP_MSG_Item msg = msgItems[i]; + + Serial.println("****************************"); + MailClient.printf("Number: %d\n", msg.msgNo); + MailClient.printf("UID: %d\n", msg.UID); + + // The attachment status in search may be true in case the "multipart/mixed" + // content type header was set with no real attachtment included. + MailClient.printf("Attachment: %s\n", msg.hasAttachment ? "yes" : "no"); + + MailClient.printf("Messsage-ID: %s\n", msg.ID); + + if (strlen(msg.flags)) + MailClient.printf("Flags: %s\n", msg.flags); + if (strlen(msg.acceptLang)) + MailClient.printf("Accept Language: %s\n", msg.acceptLang); + if (strlen(msg.contentLang)) + MailClient.printf("Content Language: %s\n", msg.contentLang); + if (strlen(msg.from)) + MailClient.printf("From: %s\n", msg.from); + if (strlen(msg.sender)) + MailClient.printf("Sender: %s\n", msg.sender); + if (strlen(msg.to)) + MailClient.printf("To: %s\n", msg.to); + if (strlen(msg.cc)) + MailClient.printf("CC: %s\n", msg.cc); + if (strlen(msg.bcc)) + MailClient.printf("BCC: %s\n", msg.bcc); + if (strlen(msg.date)) + { + MailClient.printf("Date: %s\n", msg.date); + MailClient.printf("Timestamp: %d\n", (int)MailClient.Time.getTimestamp(msg.date)); + } + if (strlen(msg.subject)) + MailClient.printf("Subject: %s\n", msg.subject); + if (strlen(msg.reply_to)) + MailClient.printf("Reply-To: %s\n", msg.reply_to); + if (strlen(msg.return_path)) + MailClient.printf("Return-Path: %s\n", msg.return_path); + if (strlen(msg.in_reply_to)) + MailClient.printf("In-Reply-To: %s\n", msg.in_reply_to); + if (strlen(msg.references)) + MailClient.printf("References: %s\n", msg.references); + if (strlen(msg.comments)) + MailClient.printf("Comments: %s\n", msg.comments); + if (strlen(msg.keywords)) + MailClient.printf("Keywords: %s\n", msg.keywords); + + /* If the result contains the message info (Fetch mode) */ + if (!headerOnly) + { + if (strlen(msg.text.content)) + MailClient.printf("Text Message: %s\n", msg.text.content); + if (strlen(msg.text.charSet)) + MailClient.printf("Text Message Charset: %s\n", msg.text.charSet); + if (strlen(msg.text.transfer_encoding)) + MailClient.printf("Text Message Transfer Encoding: %s\n", msg.text.transfer_encoding); + if (strlen(msg.html.content)) + MailClient.printf("HTML Message: %s\n", msg.html.content); + if (strlen(msg.html.charSet)) + MailClient.printf("HTML Message Charset: %s\n", msg.html.charSet); + if (strlen(msg.html.transfer_encoding)) + MailClient.printf("HTML Message Transfer Encoding: %s\n\n", msg.html.transfer_encoding); + + if (msg.rfc822.size() > 0) + { + MailClient.printf("\r\nRFC822 Messages: %d message(s)\n****************************\n", msg.rfc822.size()); + printMessages(msg.rfc822, headerOnly); + } + + if (msg.attachments.size() > 0) + printAttacements(msg.attachments); + } + + Serial.println(); + } +} \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/examples/IMAP/Custom_Command/Append_Message/Append_Message.ino b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Custom_Command/Append_Message/Append_Message.ino new file mode 100644 index 000000000..9ef89294e --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Custom_Command/Append_Message/Append_Message.ino @@ -0,0 +1,221 @@ +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt +*/ + +// This example shows how to append new message to mailbox using the custom IMAP command. + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +/** For ESP8266, with BearSSL WiFi Client + * The memory reserved for completed valid SSL response from IMAP is 16 kbytes which + * may cause your device out of memory reset in case the memory + * allocation error. + */ + +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +#include + +// To use only IMAP functions, you can exclude the SMTP from compilation, see ESP_Mail_FS.h. + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +/** For Gmail, IMAP option should be enabled. https://support.google.com/mail/answer/7126229?hl=en + * and also https://accounts.google.com/b/0/DisplayUnlockCaptcha + * + * Some Gmail user still not able to sign in using account password even above options were set up, + * for this case, use "App Password" to sign in instead. + * About Gmail "App Password", go to https://support.google.com/accounts/answer/185833?hl=en + * + * For Yahoo mail, log in to your yahoo mail in web browser and generate app password by go to + * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc + * + * To use Gmai and Yahoo's App Password to sign in, define the AUTHOR_PASSWORD with your App Password + * and AUTHOR_EMAIL with your account email. + */ + +/* The imap host name e.g. imap.gmail.com for GMail or outlook.office365.com for Outlook */ +#define IMAP_HOST "" + +/** The imap port e.g. + * 143 or esp_mail_imap_port_143 + * 993 or esp_mail_imap_port_993 + */ +#define IMAP_PORT 993 + +/* The log in credentials */ +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" + +/* Declare the global used IMAPSession object for IMAP transport */ +IMAPSession imap; + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) +WiFiMulti multi; +#endif + +void customCommandCallback(IMAP_Response res) +{ + // The server responses will included tagged and/or untagged data. + + // Tagged data is the status which begins with command identifier (tag) i.e. "A01" in this case. + // Tagged status responses included OK, NO, BAD, PREAUTH and BYE. + + // Untagged data is the information or result of the request which begins with * + + // When you send multiple commands with different tag simultaneously, + // tag will be used as command identifier. + + MailClient.printf("> C: TAG %s\n", res.tag.c_str()); + MailClient.printf("< S: %s\n", res.text.c_str()); + + if (res.completed) + { + MailClient.printf("> C: Response finished with status %s\n\n", res.status.c_str()); + } +} + +void setup() +{ + + Serial.begin(115200); + +#if defined(ARDUINO_ARCH_SAMD) + while (!Serial) + ; +#endif + + Serial.println(); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + multi.addAP(WIFI_SSID, WIFI_PASSWORD); + multi.run(); +#else + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Connecting to Wi-Fi"); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + unsigned long ms = millis(); +#endif + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + if (millis() - ms > 10000) + break; +#endif + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + /* Set the network reconnection option */ + MailClient.networkReconnect(true); + + // The WiFi credentials are required for Pico W + // due to it does not have reconnect feature. +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + MailClient.clearAP(); + MailClient.addAP(WIFI_SSID, WIFI_PASSWORD); +#endif + + /* Declare the Session_Config for user defined session credentials */ + Session_Config config; + + /* Set the session config */ + config.server.host_name = IMAP_HOST; + config.server.port = IMAP_PORT; + + /* Connect to the server */ + if (!imap.customConnect(&config, customCommandCallback, F("A01") /* tag */)) + return; + + String cmd = F("LOGIN "); + cmd += AUTHOR_EMAIL; + cmd += F(" "); + cmd += AUTHOR_PASSWORD; + + // You can also assign tag to the begining of the command e.g. "A01 FETCH 1 UID" + // Do not assign tag to command when you assign tag to the last parameter of function. + + imap.sendCustomCommand(cmd, customCommandCallback, F("A02") /* tag */); + + + if (imap.isAuthenticated()) + Serial.println("\nSuccessfully logged in.\n"); + else + Serial.println("\nConnected with no Auth.\n"); + + imap.sendCustomCommand(F("SELECT \"INBOX\""), customCommandCallback, F("A03") /* tag */); + + imap.sendCustomCommand(F("LIST \"\" *"), customCommandCallback, F("A04") /* tag */); + + String appendMsg = "Date: Thu, 16 Jun 2022 12:30:25 -0800 (PST)\r\n"; + + appendMsg += "From: Jack \r\n"; + + appendMsg += "Subject: Greeting from ESP Mail\r\n"; + + appendMsg += "To: joe@host.com\r\n"; + + appendMsg += "Message-Id: \r\n"; + + appendMsg += "MIME-Version: 1.0\r\n"; + + appendMsg += "Content-Type: text/plain; charset=\"us-ascii\"\r\n"; + + appendMsg += "Content-transfer-encoding: 7bit\r\n"; + + appendMsg += "\r\n"; + + appendMsg += "Hello Joe, this is the append message\r\n"; + + String appendMsgCmd = "APPEND INBOX {" + String(appendMsg.length()) + "}"; + + imap.sendCustomCommand(appendMsgCmd, customCommandCallback, F("A05") /* tag */); + + imap.sendCustomData(appendMsg, true /* flag states the last data to send */); +} + +void loop() +{ +} diff --git a/lib/libesp32/ESP-Mail-Client/examples/IMAP/Custom_Command/Basic_Auth/Basic_Auth.ino b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Custom_Command/Basic_Auth/Basic_Auth.ino new file mode 100644 index 000000000..9485ee7e6 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Custom_Command/Basic_Auth/Basic_Auth.ino @@ -0,0 +1,197 @@ +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt +*/ + +// This example shows how to send custom IMAP command and get the response. + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +/** For ESP8266, with BearSSL WiFi Client + * The memory reserved for completed valid SSL response from IMAP is 16 kbytes which + * may cause your device out of memory reset in case the memory + * allocation error. + */ + +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +#include + +// To use only IMAP functions, you can exclude the SMTP from compilation, see ESP_Mail_FS.h. + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +/** For Gmail, IMAP option should be enabled. https://support.google.com/mail/answer/7126229?hl=en + * and also https://accounts.google.com/b/0/DisplayUnlockCaptcha + * + * Some Gmail user still not able to sign in using account password even above options were set up, + * for this case, use "App Password" to sign in instead. + * About Gmail "App Password", go to https://support.google.com/accounts/answer/185833?hl=en + * + * For Yahoo mail, log in to your yahoo mail in web browser and generate app password by go to + * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc + * + * To use Gmai and Yahoo's App Password to sign in, define the AUTHOR_PASSWORD with your App Password + * and AUTHOR_EMAIL with your account email. + */ + +/* The imap host name e.g. imap.gmail.com for GMail or outlook.office365.com for Outlook */ +#define IMAP_HOST "" + +/** The imap port e.g. + * 143 or esp_mail_imap_port_143 + * 993 or esp_mail_imap_port_993 + */ +#define IMAP_PORT 993 + +/* The log in credentials */ +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" + +/* Declare the global used IMAPSession object for IMAP transport */ +IMAPSession imap; + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) +WiFiMulti multi; +#endif + +void customCommandCallback(IMAP_Response res) +{ + // The server responses will included tagged and/or untagged data. + + // Tagged data is the status which begins with command identifier (tag) i.e. "A01" in this case. + // Tagged status responses included OK, NO, BAD, PREAUTH and BYE. + + // Untagged data is the information or result of the request which begins with * + + // When you send multiple commands with different tag simultaneously, + // tag will be used as command identifier. + + MailClient.printf("> C: TAG %s\n", res.tag.c_str()); + MailClient.printf("< S: %s\n", res.text.c_str()); + + if (res.completed) + { + MailClient.printf("> C: Response finished with status %s\n\n", res.status.c_str()); + } +} + +void setup() +{ + + Serial.begin(115200); + +#if defined(ARDUINO_ARCH_SAMD) + while (!Serial) + ; +#endif + + Serial.println(); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + multi.addAP(WIFI_SSID, WIFI_PASSWORD); + multi.run(); +#else + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Connecting to Wi-Fi"); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + unsigned long ms = millis(); +#endif + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + if (millis() - ms > 10000) + break; +#endif + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + /* Set the network reconnection option */ + MailClient.networkReconnect(true); + + // The WiFi credentials are required for Pico W + // due to it does not have reconnect feature. +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + MailClient.clearAP(); + MailClient.addAP(WIFI_SSID, WIFI_PASSWORD); +#endif + + // This debug required for showing debug info from imap.connect + imap.debug(1); + + /* Define the IMAP_Data object used for user defined IMAP operating options. */ + IMAP_Data imap_data; + + /* Declare the Session_Config for user defined session credentials */ + Session_Config config; + + /* Set the session config */ + config.server.host_name = IMAP_HOST; + config.server.port = IMAP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + + /* Connect to the server */ + if (!imap.connect(&config, &imap_data)) + return; + + if (imap.isAuthenticated()) + Serial.println("\nSuccessfully logged in.\n"); + else + Serial.println("\nConnected with no Auth.\n"); + + // You can also assign tag to the begining of the command e.g. "A01 FETCH 1 UID" + // Do not assign tag to command when you assign tag to the last parameter of function. + + imap.sendCustomCommand(F("SELECT \"INBOX\""), customCommandCallback, F("A01") /* tag */); + + imap.sendCustomCommand(F("LIST \"\" *"), customCommandCallback, F("A02") /* tag */); + + imap.sendCustomCommand(F("FETCH 1 UID"), customCommandCallback, F("A03") /* tag */); +} + +void loop() +{ +} diff --git a/lib/libesp32/ESP-Mail-Client/examples/IMAP/Custom_Command/Custom_Auth/Custom_Auth.ino b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Custom_Command/Custom_Auth/Custom_Auth.ino new file mode 100644 index 000000000..afb3ef9c2 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Custom_Command/Custom_Auth/Custom_Auth.ino @@ -0,0 +1,197 @@ +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt +*/ + +// This example shows how to send custom IMAP command and get the response. + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +/** For ESP8266, with BearSSL WiFi Client + * The memory reserved for completed valid SSL response from IMAP is 16 kbytes which + * may cause your device out of memory reset in case the memory + * allocation error. + */ + +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +#include + +// To use only IMAP functions, you can exclude the SMTP from compilation, see ESP_Mail_FS.h. + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +/** For Gmail, IMAP option should be enabled. https://support.google.com/mail/answer/7126229?hl=en + * and also https://accounts.google.com/b/0/DisplayUnlockCaptcha + * + * Some Gmail user still not able to sign in using account password even above options were set up, + * for this case, use "App Password" to sign in instead. + * About Gmail "App Password", go to https://support.google.com/accounts/answer/185833?hl=en + * + * For Yahoo mail, log in to your yahoo mail in web browser and generate app password by go to + * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc + * + * To use Gmai and Yahoo's App Password to sign in, define the AUTHOR_PASSWORD with your App Password + * and AUTHOR_EMAIL with your account email. + */ + +/* The imap host name e.g. imap.gmail.com for GMail or outlook.office365.com for Outlook */ +#define IMAP_HOST "" + +/** The imap port e.g. + * 143 or esp_mail_imap_port_143 + * 993 or esp_mail_imap_port_993 + */ +#define IMAP_PORT 993 + +/* The log in credentials */ +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" + +/* Declare the global used IMAPSession object for IMAP transport */ +IMAPSession imap; + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) +WiFiMulti multi; +#endif + +void customCommandCallback(IMAP_Response res) +{ + // The server responses will included tagged and/or untagged data. + + // Tagged data is the status which begins with command identifier (tag) i.e. "A01" in this case. + // Tagged status responses included OK, NO, BAD, PREAUTH and BYE. + + // Untagged data is the information or result of the request which begins with * + + // When you send multiple commands with different tag simultaneously, + // tag will be used as command identifier. + + MailClient.printf("> C: TAG %s\n", res.tag.c_str()); + MailClient.printf("< S: %s\n", res.text.c_str()); + + if (res.completed) + { + MailClient.printf("> C: Response finished with status %s\n\n", res.status.c_str()); + } +} + +void setup() +{ + + Serial.begin(115200); + +#if defined(ARDUINO_ARCH_SAMD) + while (!Serial) + ; +#endif + + Serial.println(); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + multi.addAP(WIFI_SSID, WIFI_PASSWORD); + multi.run(); +#else + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Connecting to Wi-Fi"); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + unsigned long ms = millis(); +#endif + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + if (millis() - ms > 10000) + break; +#endif + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + /* Set the network reconnection option */ + MailClient.networkReconnect(true); + + // The WiFi credentials are required for Pico W + // due to it does not have reconnect feature. +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + MailClient.clearAP(); + MailClient.addAP(WIFI_SSID, WIFI_PASSWORD); +#endif + + /* Declare the Session_Config for user defined session credentials */ + Session_Config config; + + /* Set the session config */ + config.server.host_name = IMAP_HOST; + config.server.port = IMAP_PORT; + + /* Connect to the server */ + if (!imap.customConnect(&config, customCommandCallback, F("A01") /* tag */)) + return; + + String cmd = F("LOGIN "); + cmd += AUTHOR_EMAIL; + cmd += F(" "); + cmd += AUTHOR_PASSWORD; + + // You can also assign tag to the begining of the command e.g. "A01 FETCH 1 UID" + // Do not assign tag to command when you assign tag to the last parameter of function. + + imap.sendCustomCommand(cmd, customCommandCallback, F("A02") /* tag */); + + + if (imap.isAuthenticated()) + Serial.println("\nSuccessfully logged in.\n"); + else + Serial.println("\nConnected with no Auth.\n"); + + imap.sendCustomCommand(F("SELECT \"INBOX\""), customCommandCallback, F("A03") /* tag */); + + imap.sendCustomCommand(F("LIST \"\" *"), customCommandCallback, F("A04") /* tag */); + + imap.sendCustomCommand(F("FETCH 1 UID"), customCommandCallback, F("A05") /* tag */); +} + +void loop() +{ +} diff --git a/lib/libesp32/ESP-Mail-Client/examples/IMAP/Custom_Command/Idle/Idle.ino b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Custom_Command/Idle/Idle.ino new file mode 100644 index 000000000..5a704e6bc --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Custom_Command/Idle/Idle.ino @@ -0,0 +1,220 @@ +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt +*/ + +// This example shows how to receive mailbox updates by sending the custom IMAP command IDLE. + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +/** For ESP8266, with BearSSL WiFi Client + * The memory reserved for completed valid SSL response from IMAP is 16 kbytes which + * may cause your device out of memory reset in case the memory + * allocation error. + */ + +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +#include + +// To use only IMAP functions, you can exclude the SMTP from compilation, see ESP_Mail_FS.h. + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +/** For Gmail, IMAP option should be enabled. https://support.google.com/mail/answer/7126229?hl=en + * and also https://accounts.google.com/b/0/DisplayUnlockCaptcha + * + * Some Gmail user still not able to sign in using account password even above options were set up, + * for this case, use "App Password" to sign in instead. + * About Gmail "App Password", go to https://support.google.com/accounts/answer/185833?hl=en + * + * For Yahoo mail, log in to your yahoo mail in web browser and generate app password by go to + * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc + * + * To use Gmai and Yahoo's App Password to sign in, define the AUTHOR_PASSWORD with your App Password + * and AUTHOR_EMAIL with your account email. + */ + +/* The imap host name e.g. imap.gmail.com for GMail or outlook.office365.com for Outlook */ +#define IMAP_HOST "" + +/** The imap port e.g. + * 143 or esp_mail_imap_port_143 + * 993 or esp_mail_imap_port_993 + */ +#define IMAP_PORT 993 + +/* The log in credentials */ +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" + +/* Declare the global used IMAPSession object for IMAP transport */ +IMAPSession imap; + +unsigned long lastIdleTerminatedMillis = 0; + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) +WiFiMulti multi; +#endif + +void customCommandCallback(IMAP_Response res) +{ + // The server responses will included tagged and/or untagged data. + + // Tagged data is the status which begins with command identifier (tag) i.e. "A01" in this case. + // Tagged status responses included OK, NO, BAD, PREAUTH and BYE. + + // Untagged data is the information or result of the request which begins with * + + // When you send multiple commands with different tag simultaneously, + // tag will be used as command identifier. + + MailClient.printf("> C: TAG %s\n", res.tag.c_str()); + MailClient.printf("< S: %s\n", res.text.c_str()); + + if (res.completed) + { + MailClient.printf("> C: Response finished with status %s\n\n", res.status.c_str()); + } +} + +void setup() +{ + + Serial.begin(115200); + +#if defined(ARDUINO_ARCH_SAMD) + while (!Serial) + ; +#endif + + Serial.println(); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + multi.addAP(WIFI_SSID, WIFI_PASSWORD); + multi.run(); +#else + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Connecting to Wi-Fi"); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + unsigned long ms = millis(); +#endif + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + if (millis() - ms > 10000) + break; +#endif + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + /* Set the network reconnection option */ + MailClient.networkReconnect(true); + + // The WiFi credentials are required for Pico W + // due to it does not have reconnect feature. +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + MailClient.clearAP(); + MailClient.addAP(WIFI_SSID, WIFI_PASSWORD); +#endif + + /* Declare the Session_Config for user defined session credentials */ + Session_Config config; + + /* Set the session config */ + config.server.host_name = IMAP_HOST; + config.server.port = IMAP_PORT; + + /* Connect to the server */ + if (!imap.customConnect(&config, customCommandCallback, F("A01") /* tag */)) + return; + + if (imap.isAuthenticated()) + Serial.println("\nSuccessfully logged in.\n"); + else + Serial.println("\nConnected with no Auth.\n"); + + String cmd = F("LOGIN "); + cmd += AUTHOR_EMAIL; + cmd += F(" "); + cmd += AUTHOR_PASSWORD; + + // You can also assign tag to the begining of the command e.g. "A01 FETCH 1 UID" + // Do not assign tag to command when you assign tag to the last parameter of function. + + imap.sendCustomCommand(cmd, customCommandCallback, F("A02") /* tag */); + + imap.sendCustomCommand(F("SELECT \"INBOX\""), customCommandCallback, F("A03") /* tag */); + + imap.sendCustomCommand(F("LIST \"\" *"), customCommandCallback, F("A04") /* tag */); +} + +void loop() +{ + + if (imap.connected()) + { + if (!imap.sendCustomCommand(F("IDLE"), customCommandCallback, F("A05") /* tag */)) + { + // If error, need to re-connect if imap.connected() returns false and re-log in again + Serial.println("\nTCP connection closed!"); + return; + } + + if (millis() - lastIdleTerminatedMillis > 20 * 60 * 1000) // terminate the IDLE every 20 min. + { + lastIdleTerminatedMillis = millis(); + imap.sendCustomCommand(F("DONE"), customCommandCallback, "" /* don't include tag for DONE command */); + } + } +} + +/** + * The server MAY consider a client inactive if it has an IDLE command + * running, and if such a server has an inactivity timeout it MAY log + * the client off implicitly at the end of its timeout period. Because + * of that, clients using IDLE are advised to terminate the IDLE and + * re-issue it at least every 29 minutes to avoid being logged off. + */ \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/examples/IMAP/Custom_Ports/Custom_Ports.ino b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Custom_Ports/Custom_Ports.ino new file mode 100644 index 000000000..b870aa5ab --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Custom_Ports/Custom_Ports.ino @@ -0,0 +1,256 @@ +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt +*/ + +// This example shows how to assign the custom ports with protocols to access IMAP server. + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +/** For ESP8266, with BearSSL WiFi Client + * The memory reserved for completed valid SSL response from IMAP is 16 kbytes which + * may cause your device out of memory reset in case the memory + * allocation error. + */ + +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +#include + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +/** For Gmail, IMAP option should be enabled. https://support.google.com/mail/answer/7126229?hl=en + * and also https://accounts.google.com/b/0/DisplayUnlockCaptcha + * + * Some Gmail user still not able to sign in using account password even above options were set up, + * for this case, use "App Password" to sign in instead. + * About Gmail "App Password", go to https://support.google.com/accounts/answer/185833?hl=en + * + * For Yahoo mail, log in to your yahoo mail in web browser and generate app password by go to + * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc + * + * To use Gmai and Yahoo's App Password to sign in, define the AUTHOR_PASSWORD with your App Password + * and AUTHOR_EMAIL with your account email. + */ + +/* The imap host name e.g. imap.gmail.com for GMail or outlook.office365.com for Outlook */ +#define IMAP_HOST "" + +/** The imap port e.g. + * 143 or esp_mail_imap_port_143 // Plain or TLS with STARTTLS + * 993 or esp_mail_imap_port_993 + */ +#define IMAP_PORT esp_mail_imap_port_143 + +/* The log in credentials */ +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" + +/* Print the list of mailbox folders */ +void printAllMailboxesInfo(IMAPSession &imap); + +/* Print the selected folder info */ +void printSelectedMailboxInfo(SelectedFolderInfo sFolder); + +/* Declare the global used IMAPSession object for IMAP transport */ +IMAPSession imap; + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) +WiFiMulti multi; +#endif + +void setup() +{ + + Serial.begin(115200); + +#if defined(ARDUINO_ARCH_SAMD) + while (!Serial) + ; +#endif + + Serial.println(); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + multi.addAP(WIFI_SSID, WIFI_PASSWORD); + multi.run(); +#else + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Connecting to Wi-Fi"); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + unsigned long ms = millis(); +#endif + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + if (millis() - ms > 10000) + break; +#endif + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + /* Set the network reconnection option */ + MailClient.networkReconnect(true); + + // The WiFi credentials are required for Pico W + // due to it does not have reconnect feature. +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + MailClient.clearAP(); + MailClient.addAP(WIFI_SSID, WIFI_PASSWORD); +#endif + + /** Enable the debug via Serial port + * 0 for no debugging + * 1 for basic level debugging + * + * Debug port can be changed via ESP_MAIL_DEFAULT_DEBUG_PORT in ESP_Mail_FS.h + */ + imap.debug(1); + + /* Declare the Session_Config for user defined session credentials */ + Session_Config config; + + /** In case the SD card/adapter was used for the file storagge, the SPI pins can be configure from + * MailClient.sdBegin function which may be different for ESP32 and ESP8266 + * For ESP32, assign all of SPI pins + * MailClient.sdBegin(14,2,15,13) + * Which SCK = 14, MISO = 2, MOSI = 15 and SS = 13 + * And for ESP8266, assign the CS pins of SPI port + * MailClient.sdBegin(15) + * Which pin 15 is the CS pin of SD card adapter + */ + + /* Set the session config */ + config.server.host_name = IMAP_HOST; + config.server.port = IMAP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + + /** Set the ports and protocols + * The port that assigned with config.server.port will map with the + * protocol assigned here + */ + + config.ports_functions.list = new port_function[2]; + config.ports_functions.size = 2; + + config.ports_functions.list[0].port = 143; + config.ports_functions.list[0].protocol = esp_mail_protocol_tls; + + config.ports_functions.list[1].port = 993; + config.ports_functions.list[1].protocol = esp_mail_protocol_ssl; + + /* Define the IMAP_Data object used for user defined IMAP operating options. */ + IMAP_Data imap_data; + + /* Connect to the server */ + if (!imap.connect(&config, &imap_data)) + return; + + if (imap.isAuthenticated()) + Serial.println("\nSuccessfully logged in."); + else + Serial.println("\nConnected with no Auth."); + + /* {Optional} */ + printAllMailboxesInfo(imap); + + /* Open or select the mailbox folder to read or search the message */ + if (!imap.selectFolder(F("INBOX"))) + return; + + /* {Optional} */ + printSelectedMailboxInfo(imap.selectedFolder()); + + /* Close the seeion in case the session is still open */ + imap.closeSession(); + + /* Clear all stored data in IMAPSession object */ + imap.empty(); +} + +void loop() +{ +} + +void printAllMailboxesInfo(IMAPSession &imap) +{ + /* Declare the folder collection class to get the list of mailbox folders */ + FoldersCollection folders; + + /* Get the mailbox folders */ + if (imap.getFolders(folders)) + { + for (size_t i = 0; i < folders.size(); i++) + { + /* Iterate each folder info using the folder info item data */ + FolderInfo folderInfo = folders.info(i); + MailClient.printf("%s%s%s", i == 0 ? "\nAvailable folders: " : ", ", folderInfo.name, i == folders.size() - 1 ? "\n" : ""); + } + } +} + +void printSelectedMailboxInfo(SelectedFolderInfo sFolder) +{ + /* Show the mailbox info */ + MailClient.printf("\nInfo of the selected folder\nTotal Messages: %d\n", sFolder.msgCount()); + MailClient.printf("UID Validity: %d\n", sFolder.uidValidity()); + MailClient.printf("Predicted next UID: %d\n", sFolder.nextUID()); + if (sFolder.unseenIndex() > 0) + MailClient.printf("First Unseen Message Number: %d\n", sFolder.unseenIndex()); + else + MailClient.printf("Unseen Messages: No\n"); + + if (sFolder.modSeqSupported()) + MailClient.printf("Highest Modification Sequence: %llu\n", sFolder.highestModSeq()); + for (size_t i = 0; i < sFolder.flagCount(); i++) + MailClient.printf("%s%s%s", i == 0 ? "Flags: " : ", ", sFolder.flag(i).c_str(), i == sFolder.flagCount() - 1 ? "\n" : ""); + + if (sFolder.flagCount(true)) + { + for (size_t i = 0; i < sFolder.flagCount(true); i++) + MailClient.printf("%s%s%s", i == 0 ? "Permanent Flags: " : ", ", sFolder.flag(i, true).c_str(), i == sFolder.flagCount(true) - 1 ? "\n" : ""); + } +} \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/examples/IMAP/Data_Stream_Callback/Data_Stream_Callback.ino b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Data_Stream_Callback/Data_Stream_Callback.ino new file mode 100644 index 000000000..c06f4342e --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Data_Stream_Callback/Data_Stream_Callback.ino @@ -0,0 +1,368 @@ +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt +*/ + +// This example shows how to read Email and collect the stream data to print or store via the callback function. + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +/** Assign SD card type and FS used in src/ESP_Mail_FS.h and + * change the config for that card interfaces in src/extras/SDHelper.h + */ + +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +#include + +// Provide the SD card interfaces setting and mounting +#include + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +/** For Gmail, IMAP option should be enabled. https://support.google.com/mail/answer/7126229?hl=en + * and also https://accounts.google.com/b/0/DisplayUnlockCaptcha + * + * Some Gmail user still not able to sign in using account password even above options were set up, + * for this case, use "App Password" to sign in instead. + * About Gmail "App Password", go to https://support.google.com/accounts/answer/185833?hl=en + * + * For Yahoo mail, log in to your yahoo mail in web browser and generate app password by go to + * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc + * + * To use Gmai and Yahoo's App Password to sign in, define the AUTHOR_PASSWORD with your App Password + * and AUTHOR_EMAIL with your account email. + */ + +/* The imap host name e.g. imap.gmail.com for GMail or outlook.office365.com for Outlook */ +#define IMAP_HOST "" + +/** The imap port e.g. + * 143 or esp_mail_imap_port_143 + * 993 or esp_mail_imap_port_993 + */ +#define IMAP_PORT 993 + +/* The log in credentials */ +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" + +void mimeDataStreamCallback(MIME_Data_Stream_Info streaminfo); + +/* Declare the global used IMAPSession object for IMAP transport */ +IMAPSession imap; + +int progress = 0; +int lastProgress = -1; + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) +WiFiMulti multi; +#endif + +void setup() +{ + + Serial.begin(115200); + +#if defined(ARDUINO_ARCH_SAMD) + while (!Serial) + ; +#endif + + Serial.println(); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + multi.addAP(WIFI_SSID, WIFI_PASSWORD); + multi.run(); +#else + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Connecting to Wi-Fi"); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + unsigned long ms = millis(); +#endif + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + if (millis() - ms > 10000) + break; +#endif + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + /* Set the network reconnection option */ + MailClient.networkReconnect(true); + + // The WiFi credentials are required for Pico W + // due to it does not have reconnect feature. +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + MailClient.clearAP(); + MailClient.addAP(WIFI_SSID, WIFI_PASSWORD); +#endif + +#if defined(ESP_MAIL_DEFAULT_SD_FS) // defined in src/ESP_Mail_FS.h + // Mount SD card. + SD_Card_Mounting(); // See src/extras/SDHelper.h +#endif + + /* Set the callback function to get MIME Data stream */ + imap.mimeDataStreamCallback(mimeDataStreamCallback); + + /** In case the SD card/adapter was used for the file storagge, the SPI pins can be configure from + * MailClient.sdBegin function which may be different for ESP32 and ESP8266 + * For ESP32, assign all of SPI pins + * MailClient.sdBegin(14,2,15,13) + * Which SCK = 14, MISO = 2, MOSI = 15 and SS = 13 + * And for ESP8266, assign the CS pins of SPI port + * MailClient.sdBegin(15) + * Which pin 15 is the CS pin of SD card adapter + */ + + /* Declare the Session_Config for user defined session credentials */ + Session_Config config; + + /* Set the session config */ + config.server.host_name = IMAP_HOST; + config.server.port = IMAP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + + /* Define the IMAP_Data object used for user defined IMAP operating options. */ + IMAP_Data imap_data; + + /* Set the storage to save the downloaded files and attachments */ + imap_data.storage.saved_path = F("/email_data"); + + /** The file storage type e.g. + * esp_mail_file_storage_type_none, + * esp_mail_file_storage_type_flash, and + * esp_mail_file_storage_type_sd + */ + imap_data.storage.type = esp_mail_file_storage_type_sd; + + /** Set to download headers, text and html messaeges, + * attachments and inline images respectively. + */ + imap_data.download.header = true; + imap_data.download.text = true; + imap_data.download.html = true; + imap_data.download.attachment = true; + imap_data.download.inlineImg = true; + + /** Set to enable the results i.e. html and text messaeges + * which the content stored in the IMAPSession object is limited + * by the option imap_data.limit.msg_size. + * The whole message can be download through imap_data.download.text + * or imap_data.download.html which not depends on these enable options. + */ + imap_data.enable.html = true; + imap_data.enable.text = true; + + /* Set to enable the sort the result by message UID in the decending order */ + imap_data.enable.recent_sort = true; + + /* Set to report the download progress via the default serial port */ + imap_data.enable.download_status = true; + + /* Header fields parsing is case insensitive by default to avoid uppercase header in some server e.g. iCloud + , to allow case sensitive parse, uncomment below line*/ + // imap_data.enable.header_case_sensitive = true; + + /* Set the limit of number of messages in the search results */ + imap_data.limit.search = 5; + + /** Set the maximum size of message stored in + * IMAPSession object in byte + */ + imap_data.limit.msg_size = 512; + + /** Set the maximum attachments and inline images files size + * that can be downloaded in byte. + * The file which its size is largger than this limit may be saved + * as truncated file. + */ + imap_data.limit.attachment_size = 1024 * 1024 * 5; + + /* Connect to the server */ + if (!imap.connect(&config, &imap_data)) + return; + + if (imap.isAuthenticated()) + Serial.println("\nSuccessfully logged in."); + else + Serial.println("\nConnected with no Auth."); + + /* Open or select the mailbox folder to read or search the message */ + if (!imap.selectFolder(F("INBOX"))) + return; + + /** Message UID to fetch or read e.g. 100. + * In this case we will get the UID from the max message number (lastest message) + */ + imap_data.fetch.uid = imap.getUID(imap.selectedFolder().msgCount()); + + /* Set seen flag */ + + // The message with "Seen" flagged means the message was already read or seen by user. + // The default value of this option is set to false. + // If you want to set the message flag as "Seen", set this option to true. + // If this option is false, the message flag was unchanged. + // To set or remove flag from message, see Set_Flags.ino example. + + // imap_data.fetch.set_seen = true; + + /* Read or search the Email and close the session */ + + // When message was fetched or read, the /Seen flag will not set or message remained in unseen or unread status, + // as this is the purpose of library (not UI application), user can set the message status as read by set \Seen flag + // to message, see the Set_Flags.ino example. + MailClient.readMail(&imap); + + /* Clear all stored data in IMAPSession object */ + imap.empty(); +} + +void loop() +{ +} + +void mimeDataStreamCallback(MIME_Data_Stream_Info streaminfo) +{ + if (streaminfo.isFirstData) + { + progress = 0; + lastProgress = -1; + + Serial.print("Message UID: "); + Serial.println(streaminfo.uid); + + Serial.print("Content Type: "); + Serial.println(streaminfo.type); + + Serial.print("Content Disposition: "); + Serial.println(streaminfo.disposition); + + Serial.print("Text Character Set: "); + Serial.println(streaminfo.charSet); + + Serial.print("Content Transfer Encoding: "); + Serial.println(streaminfo.transfer_encoding); + + // The total octets of encoded or non-encoded MIME content. + // The size of decoded content may be different. + Serial.print("Total Octets: "); + Serial.println(streaminfo.octet_size); + + if (strcmp(streaminfo.disposition, "attachment") == 0 || strcmp(streaminfo.disposition, "inline") == 0) + { + + if (strcmp(streaminfo.disposition, "inline") == 0) + { + Serial.print("Content ID: "); + Serial.println(streaminfo.cid); + } + + Serial.print("Name: "); + Serial.println(streaminfo.name); + + Serial.print("File Name: "); + Serial.println(streaminfo.filename); + + Serial.print("Size: "); + Serial.println(streaminfo.size); + + Serial.print("Content Description: "); + Serial.println(streaminfo.description); + + Serial.print("Creation Date: "); + Serial.println(streaminfo.date); + } + + Serial.println("Content:"); + } + + progress = 100 * streaminfo.octet_count / streaminfo.octet_size; + + if (progress != lastProgress && (progress == 0 || progress == 100 || lastProgress + 5 <= progress)) + { + + lastProgress = progress; + + // The size of current decoded chunk data + Serial.print("Data Length: "); + Serial.print(streaminfo.data_size); + + Serial.print(", Reading %: "); + Serial.println(progress); + } + + // Decoded chunk data is available here + if (streaminfo.data) + { + + // If streaminfo.transfer_encoding is 'base64', + // to print or send null terminated string from stream data + + /** + char str[streaminfo.data_size + 1]; + memcpy(str, streaminfo.data, streaminfo.data_size); + str[streaminfo.data_size] = 0; + Serial.print(str); + */ + + // If streaminfo.transfer_encoding is not 'base64', the string can be + // taken directly from casting streaminfo.data as (const char*)streaminfo.data + + // To write data to file (if fs is File class object that open in appended mode) + // fs.write((uint8_t *)streaminfo.data, streaminfo.data_size); + + // streaminfo.data_size is not more than 512 + } + + if (streaminfo.isLastData) + { + Serial.println(); + Serial.println(); + } +} \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/examples/IMAP/Delete_Messages/Delete_Messages_List/Delete_Messages_List.ino b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Delete_Messages/Delete_Messages_List/Delete_Messages_List.ino new file mode 100644 index 000000000..42020a5c9 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Delete_Messages/Delete_Messages_List/Delete_Messages_List.ino @@ -0,0 +1,218 @@ +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt +*/ + +// This example shows how to delete messages from the mailbox. + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +/** For ESP8266, with BearSSL WiFi Client + * The memory reserved for completed valid SSL response from IMAP is 16 kbytes which + * may cause your device out of memory reset in case the memory + * allocation error. + */ + +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +#include + +// To use only IMAP functions, you can exclude the SMTP from compilation, see ESP_Mail_FS.h. + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +/** For Gmail, IMAP option should be enabled. https://support.google.com/mail/answer/7126229?hl=en + * and also https://accounts.google.com/b/0/DisplayUnlockCaptcha + * + * Some Gmail user still not able to sign in using account password even above options were set up, + * for this case, use "App Password" to sign in instead. + * About Gmail "App Password", go to https://support.google.com/accounts/answer/185833?hl=en + * + * For Yahoo mail, log in to your yahoo mail in web browser and generate app password by go to + * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc + * + * To use Gmai and Yahoo's App Password to sign in, define the AUTHOR_PASSWORD with your App Password + * and AUTHOR_EMAIL with your account email. + */ + +/* The imap host name e.g. imap.gmail.com for GMail or outlook.office365.com for Outlook */ +#define IMAP_HOST "" + +/** The imap port e.g. + * 143 or esp_mail_imap_port_143 + * 993 or esp_mail_imap_port_993 + */ +#define IMAP_PORT 993 + +/* The log in credentials */ +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" + +/* Print the list of mailbox folders */ +void printAllMailboxesInfo(IMAPSession &imap); + +/* Declare the global used IMAPSession object for IMAP transport */ +IMAPSession imap; + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) +WiFiMulti multi; +#endif + +void setup() +{ + + Serial.begin(115200); + +#if defined(ARDUINO_ARCH_SAMD) + while (!Serial) + ; +#endif + + Serial.println(); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + multi.addAP(WIFI_SSID, WIFI_PASSWORD); + multi.run(); +#else + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Connecting to Wi-Fi"); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + unsigned long ms = millis(); +#endif + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + if (millis() - ms > 10000) + break; +#endif + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + /* Set the network reconnection option */ + MailClient.networkReconnect(true); + + // The WiFi credentials are required for Pico W + // due to it does not have reconnect feature. +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + MailClient.clearAP(); + MailClient.addAP(WIFI_SSID, WIFI_PASSWORD); +#endif + + /** Enable the debug via Serial port + * 0 for no debugging + * 1 for basic level debugging + * + * Debug port can be changed via ESP_MAIL_DEFAULT_DEBUG_PORT in ESP_Mail_FS.h + */ + imap.debug(1); + + /* Declare the Session_Config for user defined session credentials */ + Session_Config config; + + /* Set the session config */ + config.server.host_name = IMAP_HOST; + config.server.port = IMAP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + + /* Define the IMAP_Data object used for user defined IMAP operating options. */ + IMAP_Data imap_data; + + /* Connect to the server */ + if (!imap.connect(&config, &imap_data)) + return; + + if (imap.isAuthenticated()) + Serial.println("\nSuccessfully logged in."); + else + Serial.println("\nConnected with no Auth."); + + /* {Optional} */ + printAllMailboxesInfo(imap); + + /* Open or select the mailbox folder to read or search the message */ + if (!imap.selectFolder(F("INBOX"))) + return; + + /* Define the MessageList class to add the message to delete */ + MessageList toDelete; + + /** Add message uid to delete to the list + * In this case we will delete last 10 messages by get the UID of these message + * and add it to the list + */ + for (int i = imap.selectedFolder().msgCount(); i > (int)imap.selectedFolder().msgCount() - 10 && i > 0; i--) + toDelete.add(imap.getUID(i)); + + /* Delete all messages in the list (move to trash) */ + if (imap.deleteMessages(&toDelete)) + Serial.println("\nMessages deleted"); + + /* Delete all messages permanently by assign the second param to true*/ + // imap.deleteMessages(&toDelete, true); + + MailClient.printf("Free Heap: %d\n", MailClient.getFreeHeap()); +} + +void loop() +{ +} + +void printAllMailboxesInfo(IMAPSession &imap) +{ + /* Declare the folder collection class to get the list of mailbox folders */ + FoldersCollection folders; + + /* Get the mailbox folders */ + if (imap.getFolders(folders)) + { + for (size_t i = 0; i < folders.size(); i++) + { + /* Iterate each folder info using the folder info item data */ + FolderInfo folderInfo = folders.info(i); + MailClient.printf("%s%s%s", i == 0 ? "\nAvailable folders: " : ", ", folderInfo.name, i == folders.size() - 1 ? "\n" : ""); + } + } +} diff --git a/lib/libesp32/ESP-Mail-Client/examples/IMAP/Delete_Messages/Delete_Messages_Message_Numbers_Ranges/Delete_Messages_Message_Numbers_Ranges.ino b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Delete_Messages/Delete_Messages_Message_Numbers_Ranges/Delete_Messages_Message_Numbers_Ranges.ino new file mode 100644 index 000000000..8d589e625 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Delete_Messages/Delete_Messages_Message_Numbers_Ranges/Delete_Messages_Message_Numbers_Ranges.ino @@ -0,0 +1,229 @@ +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt +*/ + +// This example shows how to delete messages from the mailbox using message numbers ranges. + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +/** For ESP8266, with BearSSL WiFi Client + * The memory reserved for completed valid SSL response from IMAP is 16 kbytes which + * may cause your device out of memory reset in case the memory + * allocation error. + */ + +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +#include + +// To use only IMAP functions, you can exclude the SMTP from compilation, see ESP_Mail_FS.h. + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +/** For Gmail, IMAP option should be enabled. https://support.google.com/mail/answer/7126229?hl=en + * and also https://accounts.google.com/b/0/DisplayUnlockCaptcha + * + * Some Gmail user still not able to sign in using account password even above options were set up, + * for this case, use "App Password" to sign in instead. + * About Gmail "App Password", go to https://support.google.com/accounts/answer/185833?hl=en + * + * For Yahoo mail, log in to your yahoo mail in web browser and generate app password by go to + * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc + * + * To use Gmai and Yahoo's App Password to sign in, define the AUTHOR_PASSWORD with your App Password + * and AUTHOR_EMAIL with your account email. + */ + +/* The imap host name e.g. imap.gmail.com for GMail or outlook.office365.com for Outlook */ +#define IMAP_HOST "" + +/** The imap port e.g. + * 143 or esp_mail_imap_port_143 + * 993 or esp_mail_imap_port_993 + */ +#define IMAP_PORT 993 + +/* The log in credentials */ +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" + +/* Print the list of mailbox folders */ +void printAllMailboxesInfo(IMAPSession &imap); + +/* Declare the global used IMAPSession object for IMAP transport */ +IMAPSession imap; + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) +WiFiMulti multi; +#endif + +void setup() +{ + + Serial.begin(115200); + +#if defined(ARDUINO_ARCH_SAMD) + while (!Serial) + ; +#endif + + Serial.println(); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + multi.addAP(WIFI_SSID, WIFI_PASSWORD); + multi.run(); +#else + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Connecting to Wi-Fi"); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + unsigned long ms = millis(); +#endif + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + if (millis() - ms > 10000) + break; +#endif + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + /* Set the network reconnection option */ + MailClient.networkReconnect(true); + + // The WiFi credentials are required for Pico W + // due to it does not have reconnect feature. +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + MailClient.clearAP(); + MailClient.addAP(WIFI_SSID, WIFI_PASSWORD); +#endif + + /** Enable the debug via Serial port + * 0 for no debugging + * 1 for basic level debugging + * + * Debug port can be changed via ESP_MAIL_DEFAULT_DEBUG_PORT in ESP_Mail_FS.h + */ + imap.debug(1); + + /* Declare the Session_Config for user defined session credentials */ + Session_Config config; + + /* Set the session config */ + config.server.host_name = IMAP_HOST; + config.server.port = IMAP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + + /* Define the IMAP_Data object used for user defined IMAP operating options. */ + IMAP_Data imap_data; + + /* Connect to the server */ + if (!imap.connect(&config, &imap_data)) + return; + + if (imap.isAuthenticated()) + Serial.println("\nSuccessfully logged in."); + else + Serial.println("\nConnected with no Auth."); + + /* {Optional} */ + printAllMailboxesInfo(imap); + + /* Open or select the mailbox folder to read or search the message */ + if (!imap.selectFolder(F("INBOX"))) + return; + + /* Copy all messages using UIDs ranges (last 10 message numbers) to the folder "test" */ + int msg_last = imap.selectedFolder().msgCount(); + int msg_begin = msg_last > 10 ? msg_last - 10 : msg_last; + + String sequence_set1 = String(msg_begin) + ":" + String(msg_last); + + if (imap.copyMessages(sequence_set1, true /* if sequence set are the UIDs */, F("test"))) + Serial.println("\nCopying messages using message numbers ranges success"); + else + Serial.println("\nError, copying messages using message numbers ranges"); + + /* Open or select the mailbox folder to read or search the message */ + if (!imap.selectFolder(F("test"))) + return; + + delay(10000); + + /* Delete all messages using UIDs ranges (last 10 message numbers) from the folder "test" */ + msg_last = imap.selectedFolder().msgCount(); + msg_begin = msg_last > 10 ? msg_last - 10 : msg_last; + + sequence_set1 = String(msg_begin) + ":" + String(msg_last); + + if (imap.deleteMessages(sequence_set1, true /* if sequence set are the UIDs */, false)) + Serial.println("\nDeleting messages using message numbers ranges success"); + else + Serial.println("\nError, Deleting messages using message numbers ranges"); + + MailClient.printf("Free Heap: %d\n", MailClient.getFreeHeap()); +} + +void loop() +{ +} + +void printAllMailboxesInfo(IMAPSession &imap) +{ + /* Declare the folder collection class to get the list of mailbox folders */ + FoldersCollection folders; + + /* Get the mailbox folders */ + if (imap.getFolders(folders)) + { + for (size_t i = 0; i < folders.size(); i++) + { + /* Iterate each folder info using the folder info item data */ + FolderInfo folderInfo = folders.info(i); + MailClient.printf("%s%s%s", i == 0 ? "\nAvailable folders: " : ", ", folderInfo.name, i == folders.size() - 1 ? "\n" : ""); + } + } +} diff --git a/lib/libesp32/ESP-Mail-Client/examples/IMAP/Delete_Messages/Delete_Messages_UIDs_Ranges/Delete_Messages_UIDs_Ranges.ino b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Delete_Messages/Delete_Messages_UIDs_Ranges/Delete_Messages_UIDs_Ranges.ino new file mode 100644 index 000000000..cb0c90d7f --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Delete_Messages/Delete_Messages_UIDs_Ranges/Delete_Messages_UIDs_Ranges.ino @@ -0,0 +1,229 @@ +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt +*/ + +// This example shows how to delete messages from the mailbox using UIDs ranges. + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +/** For ESP8266, with BearSSL WiFi Client + * The memory reserved for completed valid SSL response from IMAP is 16 kbytes which + * may cause your device out of memory reset in case the memory + * allocation error. + */ + +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +#include + +// To use only IMAP functions, you can exclude the SMTP from compilation, see ESP_Mail_FS.h. + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +/** For Gmail, IMAP option should be enabled. https://support.google.com/mail/answer/7126229?hl=en + * and also https://accounts.google.com/b/0/DisplayUnlockCaptcha + * + * Some Gmail user still not able to sign in using account password even above options were set up, + * for this case, use "App Password" to sign in instead. + * About Gmail "App Password", go to https://support.google.com/accounts/answer/185833?hl=en + * + * For Yahoo mail, log in to your yahoo mail in web browser and generate app password by go to + * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc + * + * To use Gmai and Yahoo's App Password to sign in, define the AUTHOR_PASSWORD with your App Password + * and AUTHOR_EMAIL with your account email. + */ + +/* The imap host name e.g. imap.gmail.com for GMail or outlook.office365.com for Outlook */ +#define IMAP_HOST "" + +/** The imap port e.g. + * 143 or esp_mail_imap_port_143 + * 993 or esp_mail_imap_port_993 + */ +#define IMAP_PORT 993 + +/* The log in credentials */ +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" + +/* Print the list of mailbox folders */ +void printAllMailboxesInfo(IMAPSession &imap); + +/* Declare the global used IMAPSession object for IMAP transport */ +IMAPSession imap; + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) +WiFiMulti multi; +#endif + +void setup() +{ + + Serial.begin(115200); + +#if defined(ARDUINO_ARCH_SAMD) + while (!Serial) + ; +#endif + + Serial.println(); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + multi.addAP(WIFI_SSID, WIFI_PASSWORD); + multi.run(); +#else + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Connecting to Wi-Fi"); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + unsigned long ms = millis(); +#endif + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + if (millis() - ms > 10000) + break; +#endif + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + /* Set the network reconnection option */ + MailClient.networkReconnect(true); + + // The WiFi credentials are required for Pico W + // due to it does not have reconnect feature. +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + MailClient.clearAP(); + MailClient.addAP(WIFI_SSID, WIFI_PASSWORD); +#endif + + /** Enable the debug via Serial port + * 0 for no debugging + * 1 for basic level debugging + * + * Debug port can be changed via ESP_MAIL_DEFAULT_DEBUG_PORT in ESP_Mail_FS.h + */ + imap.debug(1); + + /* Declare the Session_Config for user defined session credentials */ + Session_Config config; + + /* Set the session config */ + config.server.host_name = IMAP_HOST; + config.server.port = IMAP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + + /* Define the IMAP_Data object used for user defined IMAP operating options. */ + IMAP_Data imap_data; + + /* Connect to the server */ + if (!imap.connect(&config, &imap_data)) + return; + + if (imap.isAuthenticated()) + Serial.println("\nSuccessfully logged in."); + else + Serial.println("\nConnected with no Auth."); + + /* {Optional} */ + printAllMailboxesInfo(imap); + + /* Open or select the mailbox folder to read or search the message */ + if (!imap.selectFolder(F("INBOX"))) + return; + + /* Copy all messages using UIDs ranges (last 10 UIDs) to the folder "test" */ + int uid_last = imap.getUID(imap.selectedFolder().msgCount()); + int uid_begin = uid_last > 10 ? uid_last - 10 : uid_last; + + String sequence_set1 = String(uid_begin) + ":" + String(uid_last); + + if (imap.copyMessages(sequence_set1, true /* if sequence set are the UIDs */, F("test"))) + Serial.println("Copying messages using UIDs ranges success"); + else + Serial.println("Error, copying messages using UIDs ranges"); + + /* Open or select the mailbox folder to read or search the message */ + if (!imap.selectFolder(F("test"))) + return; + + delay(10000); + + /* Delete all messages using UIDs ranges (last 10 UIDs) from the folder "test" */ + uid_last = imap.getUID(imap.selectedFolder().msgCount()); + uid_begin = uid_last > 10 ? uid_last - 10 : uid_last; + + sequence_set1 = String(uid_begin) + ":" + String(uid_last); + + if (imap.deleteMessages(sequence_set1, true /* if sequence set are the UIDs */, false)) + Serial.println("Deleting messages using UIDs ranges success"); + else + Serial.println("Error, Deleting messages using UIDs ranges"); + + MailClient.printf("Free Heap: %d\n", MailClient.getFreeHeap()); +} + +void loop() +{ +} + +void printAllMailboxesInfo(IMAPSession &imap) +{ + /* Declare the folder collection class to get the list of mailbox folders */ + FoldersCollection folders; + + /* Get the mailbox folders */ + if (imap.getFolders(folders)) + { + for (size_t i = 0; i < folders.size(); i++) + { + /* Iterate each folder info using the folder info item data */ + FolderInfo folderInfo = folders.info(i); + MailClient.printf("%s%s%s", i == 0 ? "\nAvailable folders: " : ", ", folderInfo.name, i == folders.size() - 1 ? "\n" : ""); + } + } +} diff --git a/lib/libesp32/ESP-Mail-Client/examples/IMAP/External_Client/External_Client.ino b/lib/libesp32/ESP-Mail-Client/examples/IMAP/External_Client/External_Client.ino new file mode 100644 index 000000000..65e11b7b3 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/IMAP/External_Client/External_Client.ino @@ -0,0 +1,334 @@ +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt + */ + +/** + * This example shows how to send Email using EthernetClient. + * + * This example used ESP32 and WIZnet W5500 Ethernet module. + * + * Please see examples/SMTP/Ethernet and examples/SMTP/External_Client for more usage + */ + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +#include + +#include + +#include + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +#define IMAP_HOST "" +#define IMAP_PORT 993 + +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" + +void imapCallback(IMAP_Status status); + +void printAllMailboxesInfo(IMAPSession &imap); + +void printSelectedMailboxInfo(SelectedFolderInfo sFolder); + +void printMessages(std::vector &msgItems, bool headerOnly); + +void printAttacements(std::vector &atts); + +IMAPSession imap; + +EthernetClient eth_client; + +void networkConnection() +{ + // Reset the network connection + WiFi.disconnect(); + + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); + Serial.print("Connecting to Wi-Fi"); + unsigned long ms = millis(); + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); + if (millis() - ms >= 5000) + { + Serial.println(" failed!"); + return; + } + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); +} + +void networkStatusRequestCallback() +{ + imap.setNetworkStatus(WiFi.status() == WL_CONNECTED); +} + +void setup() +{ + + Serial.begin(115200); + + Serial.println(); + + MailClient.networkReconnect(true); + + // The WiFi credentials are required for SAMD21 + // due to it does not have reconnect feature. + MailClient.clearAP(); + MailClient.addAP(WIFI_SSID, WIFI_PASSWORD); + + networkConnection(); + + imap.debug(1); + + /* + For internal NTP client + For times east of the Prime Meridian use 0-12 + For times west of the Prime Meridian add 12 to the offset. + Ex. American/Denver GMT would be -6. 6 + 12 = 18 + See https://en.wikipedia.org/wiki/Time_zone for a list of the GMT/UTC timezone offsets + */ + MailClient.setUDPClient(&udp_client, 0 /* GMT offset */); + + MailClient.networkReconnect(true); + + imap.callback(imapCallback); + + Session_Config config; + + config.server.host_name = IMAP_HOST; + config.server.port = IMAP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + + IMAP_Data imap_data; + + imap_data.search.criteria.clear(); + + imap_data.search.unseen_msg = true; + + imap_data.storage.saved_path = F("/email_data"); + + imap_data.storage.type = esp_mail_file_storage_type_flash; + + imap_data.download.header = true; + imap_data.download.text = true; + imap_data.download.html = true; + imap_data.download.attachment = true; + imap_data.download.inlineImg = true; + + imap_data.enable.html = true; + imap_data.enable.text = true; + + imap_data.enable.recent_sort = true; + + imap_data.enable.download_status = true; + + imap_data.limit.search = 5; + + imap_data.limit.msg_size = 512; + + imap_data.limit.attachment_size = 1024 * 1024 * 5; + + imap.setClient(ð_client); + + imap.networkConnectionRequestCallback(networkConnection); + + imap.networkStatusRequestCallback(networkStatusRequestCallback); + + if (!imap.connect(&config, &imap_data)) + return; + + if (imap.isAuthenticated()) + Serial.println("\nSuccessfully logged in."); + else + Serial.println("\nConnected with no Auth."); + + printAllMailboxesInfo(imap); + + if (!imap.selectFolder(F("INBOX"))) + return; + + printSelectedMailboxInfo(imap.selectedFolder()); + + imap_data.fetch.uid = imap.getUID(imap.selectedFolder().msgCount()); + + MailClient.readMail(&imap); + + imap.empty(); +} + +void loop() +{ +} + +void imapCallback(IMAP_Status status) +{ + Serial.println(status.info()); + + if (status.success()) + { + IMAP_MSG_List msgList = imap.data(); + printMessages(msgList.msgItems, imap.headerOnly()); + imap.empty(); + } +} + +void printAllMailboxesInfo(IMAPSession &imap) +{ + FoldersCollection folders; + + if (imap.getFolders(folders)) + { + for (size_t i = 0; i < folders.size(); i++) + { + FolderInfo folderInfo = folders.info(i); + MailClient.printf("%s%s%s", i == 0 ? "\nAvailable folders: " : ", ", folderInfo.name, i == folders.size() - 1 ? "\n" : ""); + } + } +} + +void printSelectedMailboxInfo(SelectedFolderInfo sFolder) +{ + /* Show the mailbox info */ + MailClient.printf("\nInfo of the selected folder\nTotal Messages: %d\n", sFolder.msgCount()); + MailClient.printf("UID Validity: %d\n", sFolder.uidValidity()); + MailClient.printf("Predicted next UID: %d\n", sFolder.nextUID()); + if (sFolder.unseenIndex() > 0) + MailClient.printf("First Unseen Message Number: %d\n", sFolder.unseenIndex()); + else + MailClient.printf("Unseen Messages: No\n"); + + if (sFolder.modSeqSupported()) + MailClient.printf("Highest Modification Sequence: %llu\n", sFolder.highestModSeq()); + for (size_t i = 0; i < sFolder.flagCount(); i++) + MailClient.printf("%s%s%s", i == 0 ? "Flags: " : ", ", sFolder.flag(i).c_str(), i == sFolder.flagCount() - 1 ? "\n" : ""); + + if (sFolder.flagCount(true)) + { + for (size_t i = 0; i < sFolder.flagCount(true); i++) + MailClient.printf("%s%s%s", i == 0 ? "Permanent Flags: " : ", ", sFolder.flag(i, true).c_str(), i == sFolder.flagCount(true) - 1 ? "\n" : ""); + } +} + +void printAttacements(std::vector &atts) +{ + MailClient.printf("Attachment: %d file(s)\n****************************\n", atts.size()); + for (size_t j = 0; j < atts.size(); j++) + { + IMAP_Attach_Item att = atts[j]; + MailClient.printf("%d. Filename: %s, Name: %s, Size: %d, MIME: %s, Type: %s, Description: %s, Creation Date: %s\n", j + 1, att.filename, att.name, att.size, att.mime, att.type == esp_mail_att_type_attachment ? "attachment" : "inline", att.description, att.creationDate); + } + Serial.println(); +} + +void printMessages(std::vector &msgItems, bool headerOnly) +{ + + for (size_t i = 0; i < msgItems.size(); i++) + { + IMAP_MSG_Item msg = msgItems[i]; + + Serial.println("****************************"); + MailClient.printf("Number: %d\n", msg.msgNo); + MailClient.printf("UID: %d\n", msg.UID); + + // The attachment status in search may be true in case the "multipart/mixed" + // content type header was set with no real attachtment included. + MailClient.printf("Attachment: %s\n", msg.hasAttachment ? "yes" : "no"); + + MailClient.printf("Messsage-ID: %s\n", msg.ID); + + if (strlen(msg.flags)) + MailClient.printf("Flags: %s\n", msg.flags); + if (strlen(msg.acceptLang)) + MailClient.printf("Accept Language: %s\n", msg.acceptLang); + if (strlen(msg.contentLang)) + MailClient.printf("Content Language: %s\n", msg.contentLang); + if (strlen(msg.from)) + MailClient.printf("From: %s\n", msg.from); + if (strlen(msg.sender)) + MailClient.printf("Sender: %s\n", msg.sender); + if (strlen(msg.to)) + MailClient.printf("To: %s\n", msg.to); + if (strlen(msg.cc)) + MailClient.printf("CC: %s\n", msg.cc); + if (strlen(msg.bcc)) + MailClient.printf("BCC: %s\n", msg.bcc); + if (strlen(msg.date)) + { + MailClient.printf("Date: %s\n", msg.date); + MailClient.printf("Timestamp: %d\n", (int)MailClient.Time.getTimestamp(msg.date)); + } + if (strlen(msg.subject)) + MailClient.printf("Subject: %s\n", msg.subject); + if (strlen(msg.reply_to)) + MailClient.printf("Reply-To: %s\n", msg.reply_to); + if (strlen(msg.return_path)) + MailClient.printf("Return-Path: %s\n", msg.return_path); + if (strlen(msg.in_reply_to)) + MailClient.printf("In-Reply-To: %s\n", msg.in_reply_to); + if (strlen(msg.references)) + MailClient.printf("References: %s\n", msg.references); + if (strlen(msg.comments)) + MailClient.printf("Comments: %s\n", msg.comments); + if (strlen(msg.keywords)) + MailClient.printf("Keywords: %s\n", msg.keywords); + + if (!headerOnly) + { + if (strlen(msg.text.content)) + MailClient.printf("Text Message: %s\n", msg.text.content); + if (strlen(msg.text.charSet)) + MailClient.printf("Text Message Charset: %s\n", msg.text.charSet); + if (strlen(msg.text.transfer_encoding)) + MailClient.printf("Text Message Transfer Encoding: %s\n", msg.text.transfer_encoding); + if (strlen(msg.html.content)) + MailClient.printf("HTML Message: %s\n", msg.html.content); + if (strlen(msg.html.charSet)) + MailClient.printf("HTML Message Charset: %s\n", msg.html.charSet); + if (strlen(msg.html.transfer_encoding)) + MailClient.printf("HTML Message Transfer Encoding: %s\n\n", msg.html.transfer_encoding); + + if (msg.rfc822.size() > 0) + { + MailClient.printf("\r\nRFC822 Messages: %d message(s)\n****************************\n", msg.rfc822.size()); + printMessages(msg.rfc822, headerOnly); + } + + if (msg.attachments.size() > 0) + printAttacements(msg.attachments); + } + + Serial.println(); + } +} diff --git a/lib/libesp32/ESP-Mail-Client/examples/IMAP/Firmware_Update_Attachment/Firmware_Update_Attachment.ino b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Firmware_Update_Attachment/Firmware_Update_Attachment.ino new file mode 100644 index 000000000..15f706daa --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Firmware_Update_Attachment/Firmware_Update_Attachment.ino @@ -0,0 +1,464 @@ +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt +*/ + +// This example shows how to read Email and update firmware if firmware file name in attachments matches. + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +#include + +// Provide the SD card interfaces setting and mounting +#include + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +/** For Gmail, IMAP option should be enabled. https://support.google.com/mail/answer/7126229?hl=en + * and also https://accounts.google.com/b/0/DisplayUnlockCaptcha + * + * Some Gmail user still not able to sign in using account password even above options were set up, + * for this case, use "App Password" to sign in instead. + * About Gmail "App Password", go to https://support.google.com/accounts/answer/185833?hl=en + * + * For Yahoo mail, log in to your yahoo mail in web browser and generate app password by go to + * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc + * + * To use Gmai and Yahoo's App Password to sign in, define the AUTHOR_PASSWORD with your App Password + * and AUTHOR_EMAIL with your account email. + */ + +/* The imap host name e.g. imap.gmail.com for GMail or outlook.office365.com for Outlook */ +#define IMAP_HOST "" + +/** The imap port e.g. + * 143 or esp_mail_imap_port_143 + * 993 or esp_mail_imap_port_993 + */ +#define IMAP_PORT 993 + +/* The log in credentials */ +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" + +/* Callback function to get the Email reading status */ +void imapCallback(IMAP_Status status); + +/* Print the list of mailbox folders */ +void printAllMailboxesInfo(IMAPSession &imap); + +/* Print the selected folder info */ +void printSelectedMailboxInfo(SelectedFolderInfo sFolder); + +/* Print all messages from the message list */ +void printMessages(std::vector &msgItems, bool headerOnly); + +/* Print all attachments info from the message */ +void printAttacements(std::vector &atts); + +/* Declare the global used IMAPSession object for IMAP transport */ +IMAPSession imap; + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) +WiFiMulti multi; +#endif + +void setup() +{ + + Serial.begin(115200); + + Serial.println(); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + multi.addAP(WIFI_SSID, WIFI_PASSWORD); + multi.run(); +#else + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Connecting to Wi-Fi"); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + unsigned long ms = millis(); +#endif + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + if (millis() - ms > 10000) + break; +#endif + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + /* Set the network reconnection option */ + MailClient.networkReconnect(true); + + // The WiFi credentials are required for Pico W + // due to it does not have reconnect feature. +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + MailClient.clearAP(); + MailClient.addAP(WIFI_SSID, WIFI_PASSWORD); +#endif + +#if defined(ESP_MAIL_DEFAULT_SD_FS) // defined in src/ESP_Mail_FS.h + // Mount SD card. + SD_Card_Mounting(); // See src/extras/SDHelper.h +#endif + + /** Enable the debug via Serial port + * 0 for no debugging + * 1 for basic level debugging + * + * Debug port can be changed via ESP_MAIL_DEFAULT_DEBUG_PORT in ESP_Mail_FS.h + */ + imap.debug(1); + + /* Set the callback function to get the reading results */ + imap.callback(imapCallback); + + /** In case the SD card/adapter was used for the file storagge, the SPI pins can be configure from + * MailClient.sdBegin function which may be different for ESP32 and ESP8266 + * For ESP32, assign all of SPI pins + * MailClient.sdBegin(14,2,15,13) + * Which SCK = 14, MISO = 2, MOSI = 15 and SS = 13 + * And for ESP8266, assign the CS pins of SPI port + * MailClient.sdBegin(15) + * Which pin 15 is the CS pin of SD card adapter + */ + + /* Declare the Session_Config for user defined session credentials */ + Session_Config config; + + /* Set the session config */ + config.server.host_name = IMAP_HOST; + config.server.port = IMAP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + + /* Define the IMAP_Data object used for user defined IMAP operating options. */ + IMAP_Data imap_data; + + /* Set the storage to save the downloaded files and attachments */ + imap_data.storage.saved_path = F("/email_data"); + + /** Set to enable the results i.e. html and text messaeges + * which the content stored in the IMAPSession object is limited + * by the option imap_data.limit.msg_size. + * The whole message can be download through imap_data.download.text + * or imap_data.download.html which not depends on these enable options. + */ + imap_data.enable.html = true; + imap_data.enable.text = true; + + /* Assign the attachment filename to compare, update firmware if it matches */ + imap_data.firmware_update.attach_filename = "firmware.bin"; + /* save (download) firmware to file? */ + imap_data.firmware_update.save_to_file = false; + + /** + * Device will reboot in if imap.isFirmwareUpdated() returns true in imapCallback function. + * To disable firmware update, call imap_data.firmware_update.attach_filename.clear(); or + * imap_data.firmware_update.attach_filename = ""; + * + */ + + /* Set to enable the sort the result by message UID in the decending order */ + imap_data.enable.recent_sort = true; + + /* Set to report the download progress via the default serial port */ + imap_data.enable.download_status = true; + + /* Header fields parsing is case insensitive by default to avoid uppercase header in some server e.g. iCloud + , to allow case sensitive parse, uncomment below line*/ + // imap_data.enable.header_case_sensitive = true; + + /* Set the limit of number of messages in the search results */ + imap_data.limit.search = 5; + + /** Set the maximum size of message stored in + * IMAPSession object in byte + */ + imap_data.limit.msg_size = 512; + + /** Set the maximum attachments and inline images files size + * that can be downloaded in byte. + * The file which its size is largger than this limit may be saved + * as truncated file. + */ + imap_data.limit.attachment_size = 1024 * 1024 * 5; + + /* Connect to the server */ + if (!imap.connect(&config, &imap_data)) + return; + + if (imap.isAuthenticated()) + Serial.println("\nSuccessfully logged in."); + else + Serial.println("\nConnected with no Auth."); + + /* {Optional} */ + printAllMailboxesInfo(imap); + + /* Open or select the mailbox folder to read or search the message */ + if (!imap.selectFolder(F("INBOX"))) + return; + + /* {Optional} */ + printSelectedMailboxInfo(imap.selectedFolder()); + + /** Message UID to fetch or read e.g. 100. + * In this case we will get the UID from the max message number (lastest message) + */ + imap_data.fetch.uid = imap.getUID(imap.selectedFolder().msgCount()); + + // or fetch via the message sequence number + // imap_data.fetch.number = imap.selectedFolder().msgCount(); + + // if both imap_data.fetch.uid and imap_data.fetch.number were set, + // then total 2 messages will be fetched i.e. one using uid and other using number. + + /* Set seen flag */ + + // The message with "Seen" flagged means the message was already read or seen by user. + // The default value of this option is set to false. + // If you want to set the message flag as "Seen", set this option to true. + // If this option is false, the message flag was unchanged. + // To set or remove flag from message, see Set_Flags.ino example. + + // imap_data.fetch.set_seen = true; + + /* Read or search the Email and close the session */ + + // When message was fetched or read, the /Seen flag will not set or message remained in unseen or unread status, + // as this is the purpose of library (not UI application), user can set the message status as read by set \Seen flag + // to message, see the Set_Flags.ino example. + MailClient.readMail(&imap); + + /* Clear all stored data in IMAPSession object */ + imap.empty(); +} + +void loop() +{ +} + +/* Callback function to get the Email reading status */ +void imapCallback(IMAP_Status status) +{ + /* Print the current status */ + Serial.println(status.info()); + + /* Show the result when reading finished */ + if (status.success()) + { + /* Print the result */ + /* Get the message list from the message list data */ + IMAP_MSG_List msgList = imap.data(); + printMessages(msgList.msgItems, imap.headerOnly()); + + /* Clear all stored data in IMAPSession object */ + imap.empty(); + + if (imap.isFirmwareUpdateSuccess()) + { + Serial.println("****************************"); + Serial.println("Firmware is already updated, restarting device..."); + delay(2000); +#if defined(ESP32) || defined(ESP8266) + ESP.restart(); +#elif defined(ARDUINO_ARCH_RP2040) && !defined(ARDUINO_NANO_RP2040_CONNECT) + rp2040.restart(); +#endif + } + } +} + +void printAllMailboxesInfo(IMAPSession &imap) +{ + /* Declare the folder collection class to get the list of mailbox folders */ + FoldersCollection folders; + + /* Get the mailbox folders */ + if (imap.getFolders(folders)) + { + for (size_t i = 0; i < folders.size(); i++) + { + /* Iterate each folder info using the folder info item data */ + FolderInfo folderInfo = folders.info(i); + MailClient.printf("%s%s%s", i == 0 ? "\nAvailable folders: " : ", ", folderInfo.name, i == folders.size() - 1 ? "\n" : ""); + } + } +} + +void printSelectedMailboxInfo(SelectedFolderInfo sFolder) +{ + /* Show the mailbox info */ + MailClient.printf("\nInfo of the selected folder\nTotal Messages: %d\n", sFolder.msgCount()); + MailClient.printf("UID Validity: %d\n", sFolder.uidValidity()); + MailClient.printf("Predicted next UID: %d\n", sFolder.nextUID()); + if (sFolder.unseenIndex() > 0) + MailClient.printf("First Unseen Message Number: %d\n", sFolder.unseenIndex()); + else + MailClient.printf("Unseen Messages: No\n"); + + if (sFolder.modSeqSupported()) + MailClient.printf("Highest Modification Sequence: %llu\n", sFolder.highestModSeq()); + for (size_t i = 0; i < sFolder.flagCount(); i++) + MailClient.printf("%s%s%s", i == 0 ? "Flags: " : ", ", sFolder.flag(i).c_str(), i == sFolder.flagCount() - 1 ? "\n" : ""); + + if (sFolder.flagCount(true)) + { + for (size_t i = 0; i < sFolder.flagCount(true); i++) + MailClient.printf("%s%s%s", i == 0 ? "Permanent Flags: " : ", ", sFolder.flag(i, true).c_str(), i == sFolder.flagCount(true) - 1 ? "\n" : ""); + } +} + +void printAttacements(std::vector &atts) +{ + MailClient.printf("Attachment: %d file(s)\n****************************\n", atts.size()); + for (size_t j = 0; j < atts.size(); j++) + { + IMAP_Attach_Item att = atts[j]; + /** att.type can be + * esp_mail_att_type_none or 0 + * esp_mail_att_type_attachment or 1 + * esp_mail_att_type_inline or 2 + */ + MailClient.printf("%d. Filename: %s, Name: %s, Size: %d, MIME: %s, Type: %s, Description: %s, Creation Date: %s\n", j + 1, att.filename, att.name, att.size, att.mime, att.type == esp_mail_att_type_attachment ? "attachment" : "inline", att.description, att.creationDate); + } + Serial.println(); +} + +void printMessages(std::vector &msgItems, bool headerOnly) +{ + + /** In devices other than ESP8266 and ESP32, if SD card was chosen as filestorage and + * the standard SD.h library included in ESP_Mail_FS.h, files will be renamed due to long filename + * (> 13 characters) is not support in the SD.h library. + * To show how its original file name, use imap.fileList(). + */ + // Serial.println(imap.fileList()); + + for (size_t i = 0; i < msgItems.size(); i++) + { + + /* Iterate to get each message data through the message item data */ + IMAP_MSG_Item msg = msgItems[i]; + + Serial.println("****************************"); + MailClient.printf("Number: %d\n", msg.msgNo); + MailClient.printf("UID: %d\n", msg.UID); + + // The attachment status in search may be true in case the "multipart/mixed" + // content type header was set with no real attachtment included. + MailClient.printf("Attachment: %s\n", msg.hasAttachment ? "yes" : "no"); + + MailClient.printf("Messsage-ID: %s\n", msg.ID); + + if (strlen(msg.flags)) + MailClient.printf("Flags: %s\n", msg.flags); + if (strlen(msg.acceptLang)) + MailClient.printf("Accept Language: %s\n", msg.acceptLang); + if (strlen(msg.contentLang)) + MailClient.printf("Content Language: %s\n", msg.contentLang); + if (strlen(msg.from)) + MailClient.printf("From: %s\n", msg.from); + if (strlen(msg.sender)) + MailClient.printf("Sender: %s\n", msg.sender); + if (strlen(msg.to)) + MailClient.printf("To: %s\n", msg.to); + if (strlen(msg.cc)) + MailClient.printf("CC: %s\n", msg.cc); + if (strlen(msg.bcc)) + MailClient.printf("BCC: %s\n", msg.bcc); + if (strlen(msg.date)) + { + MailClient.printf("Date: %s\n", msg.date); + MailClient.printf("Timestamp: %d\n", (int)MailClient.Time.getTimestamp(msg.date)); + } + if (strlen(msg.subject)) + MailClient.printf("Subject: %s\n", msg.subject); + if (strlen(msg.reply_to)) + MailClient.printf("Reply-To: %s\n", msg.reply_to); + if (strlen(msg.return_path)) + MailClient.printf("Return-Path: %s\n", msg.return_path); + if (strlen(msg.in_reply_to)) + MailClient.printf("In-Reply-To: %s\n", msg.in_reply_to); + if (strlen(msg.references)) + MailClient.printf("References: %s\n", msg.references); + if (strlen(msg.comments)) + MailClient.printf("Comments: %s\n", msg.comments); + if (strlen(msg.keywords)) + MailClient.printf("Keywords: %s\n", msg.keywords); + + /* If the result contains the message info (Fetch mode) */ + if (!headerOnly) + { + if (strlen(msg.text.content)) + MailClient.printf("Text Message: %s\n", msg.text.content); + if (strlen(msg.text.charSet)) + MailClient.printf("Text Message Charset: %s\n", msg.text.charSet); + if (strlen(msg.text.transfer_encoding)) + MailClient.printf("Text Message Transfer Encoding: %s\n", msg.text.transfer_encoding); + if (strlen(msg.html.content)) + MailClient.printf("HTML Message: %s\n", msg.html.content); + if (strlen(msg.html.charSet)) + MailClient.printf("HTML Message Charset: %s\n", msg.html.charSet); + if (strlen(msg.html.transfer_encoding)) + MailClient.printf("HTML Message Transfer Encoding: %s\n\n", msg.html.transfer_encoding); + + if (msg.rfc822.size() > 0) + { + MailClient.printf("\r\nRFC822 Messages: %d message(s)\n****************************\n", msg.rfc822.size()); + printMessages(msg.rfc822, headerOnly); + } + + if (msg.attachments.size() > 0) + printAttacements(msg.attachments); + } + + Serial.println(); + } +} diff --git a/lib/libesp32/ESP-Mail-Client/examples/IMAP/Get_Quota/Get_Quota.ino b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Get_Quota/Get_Quota.ino new file mode 100644 index 000000000..aae7f050d --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Get_Quota/Get_Quota.ino @@ -0,0 +1,215 @@ +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt +*/ + +// This example shows how to get the quota root's resource usage and limits. + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +/** For ESP8266, with BearSSL WiFi Client + * The memory reserved for completed valid SSL response from IMAP is 16 kbytes which + * may cause your device out of memory reset in case the memory + * allocation error. + */ + +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +#include + +// To use only IMAP functions, you can exclude the SMTP from compilation, see ESP_Mail_FS.h. + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +/** For Gmail, IMAP option should be enabled. https://support.google.com/mail/answer/7126229?hl=en + * and also https://accounts.google.com/b/0/DisplayUnlockCaptcha + * + * Some Gmail user still not able to sign in using account password even above options were set up, + * for this case, use "App Password" to sign in instead. + * About Gmail "App Password", go to https://support.google.com/accounts/answer/185833?hl=en + * + * For Yahoo mail, log in to your yahoo mail in web browser and generate app password by go to + * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc + * + * To use Gmai and Yahoo's App Password to sign in, define the AUTHOR_PASSWORD with your App Password + * and AUTHOR_EMAIL with your account email. + */ + +/* The imap host name e.g. imap.gmail.com for GMail or outlook.office365.com for Outlook */ +#define IMAP_HOST "" + +/** The imap port e.g. + * 143 or esp_mail_imap_port_143 + * 993 or esp_mail_imap_port_993 + */ +#define IMAP_PORT 993 + +/* The log in credentials */ +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" + +/* Declare the global used IMAPSession object for IMAP transport */ +IMAPSession imap; + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) +WiFiMulti multi; +#endif + +void setup() +{ + + Serial.begin(115200); + +#if defined(ARDUINO_ARCH_SAMD) + while (!Serial) + ; +#endif + + Serial.println(); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + multi.addAP(WIFI_SSID, WIFI_PASSWORD); + multi.run(); +#else + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Connecting to Wi-Fi"); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + unsigned long ms = millis(); +#endif + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + if (millis() - ms > 10000) + break; +#endif + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + /* Set the network reconnection option */ + MailClient.networkReconnect(true); + + // The WiFi credentials are required for Pico W + // due to it does not have reconnect feature. +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + MailClient.clearAP(); + MailClient.addAP(WIFI_SSID, WIFI_PASSWORD); +#endif + + /** Enable the debug via Serial port + * 0 for no debugging + * 1 for basic level debugging + * + * Debug port can be changed via ESP_MAIL_DEFAULT_DEBUG_PORT in ESP_Mail_FS.h + */ + imap.debug(1); + + /* Declare the Session_Config for user defined session credentials */ + Session_Config config; + + /* Set the session config */ + config.server.host_name = IMAP_HOST; + config.server.port = IMAP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + + /* Define the IMAP_Data object used for user defined IMAP operating options. */ + IMAP_Data imap_data; + + /* Connect to the server */ + if (!imap.connect(&config, &imap_data)) + return; + + if (imap.isAuthenticated()) + Serial.println("\nSuccessfully logged in."); + else + Serial.println("\nConnected with no Auth."); + + IMAP_Quota_Root_Info info; + + Serial.println("\nGet quota root..."); + + if (!imap.getQuota("", &info)) + { + Serial.println("Get quota root failed"); + } + else + { + MailClient.printf("Quota root: %s, Resource name: %s, Usage (k): %d, Limit (k): %d\n", info.quota_root.c_str(), info.name.c_str(), (int)info.usage, (int)info.limit); + } + + IMAP_Quota_Roots_List quota_roots; + + Serial.println("\nGet quota roots list for INBOX folder..."); + + if (!imap.getQuotaRoot("INBOX", "a_roots)) + { + Serial.println("\nGet quota roots list failed"); + } + else + { + for (size_t i = 0; i < quota_roots.size(); i++) + MailClient.printf("%d, Quota root: %s, Resource name: %s, Usage (k): %d, Limit (k): %d\n", (int)i + 1, quota_roots[i].quota_root.c_str(), quota_roots[i].name.c_str(), (int)quota_roots[i].usage, (int)quota_roots[i].limit); + } + + Serial.println("\nSet quota root..."); + + info.name = "STORAGE"; + info.limit = 1024 * 1024; // 1048576 k or 1 G. + + if (!imap.setQuota("", &info)) + { + Serial.println("\nSet quota root failed"); + } + else + { + Serial.println("\nSet quota root success"); + } + + MailClient.printf("Free Heap: %d\n", MailClient.getFreeHeap()); +} + +void loop() +{ +} diff --git a/lib/libesp32/ESP-Mail-Client/examples/IMAP/Mailbox_Changes_Notification/Mailbox_Changes_Notification.ino b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Mailbox_Changes_Notification/Mailbox_Changes_Notification.ino new file mode 100644 index 000000000..271a9f53a --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Mailbox_Changes_Notification/Mailbox_Changes_Notification.ino @@ -0,0 +1,446 @@ +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt +*/ + +// This example shows how to get notification in realtime when incoming message arrived and other mailbox changes. + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +/** For ESP8266, with BearSSL WiFi Client + * The memory reserved for completed valid SSL response from IMAP is 16 kbytes which + * may cause your device out of memory reset in case the memory + * allocation error. + */ + +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +#include + +// To use only IMAP functions, you can exclude the SMTP from compilation, see ESP_Mail_FS.h. + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +/** For Gmail, IMAP option should be enabled. https://support.google.com/mail/answer/7126229?hl=en + * and also https://accounts.google.com/b/0/DisplayUnlockCaptcha + * + * Some Gmail user still not able to sign in using account password even above options were set up, + * for this case, use "App Password" to sign in instead. + * About Gmail "App Password", go to https://support.google.com/accounts/answer/185833?hl=en + * + * For Yahoo mail, log in to your yahoo mail in web browser and generate app password by go to + * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc + * + * To use Gmai and Yahoo's App Password to sign in, define the AUTHOR_PASSWORD with your App Password + * and AUTHOR_EMAIL with your account email. + */ + +/* The imap host name e.g. imap.gmail.com for GMail or outlook.office365.com for Outlook */ +#define IMAP_HOST "" + +/** The imap port e.g. + * 143 or esp_mail_imap_port_143 + * 993 or esp_mail_imap_port_993 + */ +#define IMAP_PORT 993 + +/* The log in credentials */ +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" + +/* Print the selected folder update info */ +void printPollingStatus(IMAPSession &imap); + +/* Callback function to get the Email reading status */ +void imapCallback(IMAP_Status status); + +/* Print the list of mailbox folders */ +void printAllMailboxesInfo(IMAPSession &imap); + +/* Print the selected folder info */ +void printSelectedMailboxInfo(SelectedFolderInfo sFolder); + +/* Print all messages from the message list */ +void printMessages(std::vector &msgItems, bool headerOnly); + +/* Print all attachments info from the message */ +void printAttacements(std::vector &atts); + +/* Declare the global used IMAPSession object for IMAP transport */ +IMAPSession imap; + +/* Declare the global used Session_Config for user defined session credentials */ +Session_Config config; + +/* Define the IMAP_Data object used for user defined IMAP operating options. */ +IMAP_Data imap_data; + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) +WiFiMulti multi; +#endif + +void connectWiFi() +{ + WiFi.disconnect(); + + Serial.println(); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + multi.addAP(WIFI_SSID, WIFI_PASSWORD); + multi.run(); +#else + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Connecting to Wi-Fi"); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + unsigned long ms = millis(); +#endif + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + if (millis() - ms > 10000) + break; +#endif + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); +} + +void setup() +{ + + Serial.begin(115200); + +#if defined(ARDUINO_ARCH_SAMD) + while (!Serial) + ; +#endif + + Serial.println(); + + /* Set the network reconnection option */ + MailClient.networkReconnect(true); + + // The WiFi credentials are required for Pico W + // due to it does not have reconnect feature. +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + MailClient.clearAP(); + MailClient.addAP(WIFI_SSID, WIFI_PASSWORD); +#endif + + connectWiFi(); + + /** Enable the debug via Serial port + * 0 for no debugging + * 1 for basic level debugging + * + * Debug port can be changed via ESP_MAIL_DEFAULT_DEBUG_PORT in ESP_Mail_FS.h + */ + imap.debug(1); + + /* Set the callback function to get the reading results */ + imap.callback(imapCallback); + + /** In case the SD card/adapter was used for the file storagge, the SPI pins can be configure from + * MailClient.sdBegin function which may be different for ESP32 and ESP8266 + * For ESP32, assign all of SPI pins + * MailClient.sdBegin(14,2,15,13) + * Which SCK = 14, MISO = 2, MOSI = 15 and SS = 13 + * And for ESP8266, assign the CS pins of SPI port + * MailClient.sdBegin(15) + * Which pin 15 is the CS pin of SD card adapter + */ + + /* Set the session config */ + config.server.host_name = IMAP_HOST; + config.server.port = IMAP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + + /* + Set the NTP config time + For times east of the Prime Meridian use 0-12 + For times west of the Prime Meridian add 12 to the offset. + Ex. American/Denver GMT would be -6. 6 + 12 = 18 + See https://en.wikipedia.org/wiki/Time_zone for a list of the GMT/UTC timezone offsets + */ + config.time.ntp_server = F("pool.ntp.org,time.nist.gov"); + config.time.gmt_offset = 3; + config.time.day_light_offset = 0; + + /** Assign internet connection handler function + * in case of lost internet connection for re-listening the mailbox. + */ + config.network_connection_handler = connectWiFi; + + // You can use TCP KeepAlive for more reliable of listen (idle) operation, please read this for detail. + // https://github.com/mobizt/ESP-Mail-Client#using-tcp-session-keepalive-in-esp8266-and-esp32 + // You can use keepAlive in ESP8266 core version newer than v3.1.2. + // Or you can use git version (v3.1.2) https://github.com/esp8266/Arduino +#if defined(ESP32) + imap.keepAlive(5, 5, 1); +#endif + + /* Set the TCP response read timeout in seconds */ + // smtp.setTCPTimeout(10); + + /* Connect to the server */ + if (!imap.connect(&config, &imap_data)) + return; + + if (imap.isAuthenticated()) + Serial.println("\nSuccessfully logged in."); + else + Serial.println("\nConnected with no Auth."); + + /* {Optional} */ + printAllMailboxesInfo(imap); + + /* Open or select the mailbox folder to read or search the message */ + if (!imap.selectFolder(F("INBOX"))) + return; + + /* {Optional} */ + printSelectedMailboxInfo(imap.selectedFolder()); +} + +void loop() +{ + /* imap.connect and imap.selectFolder or imap.openFolder nedded to be called once prior to listen */ + + // Listen for mailbox changes + if (!imap.listen()) + return; + + // Check the changes + if (imap.folderChanged()) + printPollingStatus(imap); + + // To stop listen, use imap.stopListen(); and to listen again, call imap.listen() +} + +void printPollingStatus(IMAPSession &imap) +{ + /* Declare the selected folder info class to get the info of selected mailbox folder */ + SelectedFolderInfo sFolder = imap.selectedFolder(); + + /* Show the mailbox info */ + MailClient.printf("\nMailbox status changed\n----------------------\nTotal Messages: %d\n", sFolder.msgCount()); + + if (sFolder.pollingStatus().type == imap_polling_status_type_new_message) + { + + MailClient.printf("New message %d, has been addedd, reading message...\n", (int)sFolder.pollingStatus().messageNum); + + // if (sFolder.recentCount() > 0) + // MailClient.printf("\nMesssage count which recent flag set: %d\n", sFolder.recentCount()); + + // we need to stop polling before do anything + imap.stopListen(); + + // Get the UID of new message and fetch + imap_data.fetch.uid = imap.getUID(sFolder.pollingStatus().messageNum); + MailClient.readMail(&imap, false); + } + else if (sFolder.pollingStatus().type == imap_polling_status_type_remove_message) + MailClient.printf("Message %d, has been removed\n\n", (int)sFolder.pollingStatus().messageNum); + else if (sFolder.pollingStatus().type == imap_polling_status_type_fetch_message) + MailClient.printf("Message %d, has been fetched with the argument %s\n\n", (int)sFolder.pollingStatus().messageNum, sFolder.pollingStatus().argument.c_str()); +} + +/* Callback function to get the Email reading status */ +void imapCallback(IMAP_Status status) +{ + /* Print the current status */ + Serial.println(status.info()); + + /* Show the result when reading finished */ + if (status.success()) + { + /* Print the result */ + /* Get the message list from the message list data */ + IMAP_MSG_List msgList = imap.data(); + printMessages(msgList.msgItems, imap.headerOnly()); + + /* Clear all stored data in IMAPSession object */ + imap.empty(); + } +} + +void printAllMailboxesInfo(IMAPSession &imap) +{ + /* Declare the folder collection class to get the list of mailbox folders */ + FoldersCollection folders; + + /* Get the mailbox folders */ + if (imap.getFolders(folders)) + { + for (size_t i = 0; i < folders.size(); i++) + { + /* Iterate each folder info using the folder info item data */ + FolderInfo folderInfo = folders.info(i); + MailClient.printf("%s%s%s", i == 0 ? "\nAvailable folders: " : ", ", folderInfo.name, i == folders.size() - 1 ? "\n" : ""); + } + } +} + +void printSelectedMailboxInfo(SelectedFolderInfo sFolder) +{ + /* Show the mailbox info */ + MailClient.printf("\nInfo of the selected folder\nTotal Messages: %d\n", sFolder.msgCount()); + MailClient.printf("UID Validity: %d\n", sFolder.uidValidity()); + MailClient.printf("Predicted next UID: %d\n", sFolder.nextUID()); + if (sFolder.unseenIndex() > 0) + MailClient.printf("First Unseen Message Number: %d\n", sFolder.unseenIndex()); + else + MailClient.printf("Unseen Messages: No\n"); + + if (sFolder.modSeqSupported()) + MailClient.printf("Highest Modification Sequence: %llu\n", sFolder.highestModSeq()); + for (size_t i = 0; i < sFolder.flagCount(); i++) + MailClient.printf("%s%s%s", i == 0 ? "Flags: " : ", ", sFolder.flag(i).c_str(), i == sFolder.flagCount() - 1 ? "\n" : ""); + + if (sFolder.flagCount(true)) + { + for (size_t i = 0; i < sFolder.flagCount(true); i++) + MailClient.printf("%s%s%s", i == 0 ? "Permanent Flags: " : ", ", sFolder.flag(i, true).c_str(), i == sFolder.flagCount(true) - 1 ? "\n" : ""); + } +} + +void printAttacements(std::vector &atts) +{ + MailClient.printf("Attachment: %d file(s)\n****************************\n", atts.size()); + for (size_t j = 0; j < atts.size(); j++) + { + IMAP_Attach_Item att = atts[j]; + /** att.type can be + * esp_mail_att_type_none or 0 + * esp_mail_att_type_attachment or 1 + * esp_mail_att_type_inline or 2 + */ + MailClient.printf("%d. Filename: %s, Name: %s, Size: %d, MIME: %s, Type: %s, Description: %s, Creation Date: %s\n", j + 1, att.filename, att.name, att.size, att.mime, att.type == esp_mail_att_type_attachment ? "attachment" : "inline", att.description, att.creationDate); + } + Serial.println(); +} + +void printMessages(std::vector &msgItems, bool headerOnly) +{ + + for (size_t i = 0; i < msgItems.size(); i++) + { + + /* Iterate to get each message data through the message item data */ + IMAP_MSG_Item msg = msgItems[i]; + + Serial.println("****************************"); + MailClient.printf("Number: %d\n", msg.msgNo); + MailClient.printf("UID: %d\n", msg.UID); + + // The attachment status in search may be true in case the "multipart/mixed" + // content type header was set with no real attachtment included. + MailClient.printf("Attachment: %s\n", msg.hasAttachment ? "yes" : "no"); + + MailClient.printf("Messsage-ID: %s\n", msg.ID); + + if (strlen(msg.flags)) + MailClient.printf("Flags: %s\n", msg.flags); + if (strlen(msg.acceptLang)) + MailClient.printf("Accept Language: %s\n", msg.acceptLang); + if (strlen(msg.contentLang)) + MailClient.printf("Content Language: %s\n", msg.contentLang); + if (strlen(msg.from)) + MailClient.printf("From: %s\n", msg.from); + if (strlen(msg.sender)) + MailClient.printf("Sender: %s\n", msg.sender); + if (strlen(msg.to)) + MailClient.printf("To: %s\n", msg.to); + if (strlen(msg.cc)) + MailClient.printf("CC: %s\n", msg.cc); + if (strlen(msg.bcc)) + MailClient.printf("BCC: %s\n", msg.bcc); + if (strlen(msg.date)) + { + MailClient.printf("Date: %s\n", msg.date); + MailClient.printf("Timestamp: %d\n", (int)MailClient.Time.getTimestamp(msg.date)); + } + if (strlen(msg.subject)) + MailClient.printf("Subject: %s\n", msg.subject); + if (strlen(msg.reply_to)) + MailClient.printf("Reply-To: %s\n", msg.reply_to); + if (strlen(msg.return_path)) + MailClient.printf("Return-Path: %s\n", msg.return_path); + if (strlen(msg.in_reply_to)) + MailClient.printf("In-Reply-To: %s\n", msg.in_reply_to); + if (strlen(msg.references)) + MailClient.printf("References: %s\n", msg.references); + if (strlen(msg.comments)) + MailClient.printf("Comments: %s\n", msg.comments); + if (strlen(msg.keywords)) + MailClient.printf("Keywords: %s\n", msg.keywords); + + /* If the result contains the message info (Fetch mode) */ + if (!headerOnly) + { + if (strlen(msg.text.content)) + MailClient.printf("Text Message: %s\n", msg.text.content); + if (strlen(msg.text.charSet)) + MailClient.printf("Text Message Charset: %s\n", msg.text.charSet); + if (strlen(msg.text.transfer_encoding)) + MailClient.printf("Text Message Transfer Encoding: %s\n", msg.text.transfer_encoding); + if (strlen(msg.html.content)) + MailClient.printf("HTML Message: %s\n", msg.html.content); + if (strlen(msg.html.charSet)) + MailClient.printf("HTML Message Charset: %s\n", msg.html.charSet); + if (strlen(msg.html.transfer_encoding)) + MailClient.printf("HTML Message Transfer Encoding: %s\n\n", msg.html.transfer_encoding); + + if (msg.rfc822.size() > 0) + { + MailClient.printf("RFC822 Messages: %d message(s)\n****************************\n", msg.rfc822.size()); + printMessages(msg.rfc822, headerOnly); + } + } + + Serial.println(); + } +} diff --git a/lib/libesp32/ESP-Mail-Client/examples/IMAP/Move_Messages/Move_Messages_List/Move_Messages_List.ino b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Move_Messages/Move_Messages_List/Move_Messages_List.ino new file mode 100644 index 000000000..bf95fcc20 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Move_Messages/Move_Messages_List/Move_Messages_List.ino @@ -0,0 +1,214 @@ +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt +*/ + +// This example shows how to move messages from the mailbox to other folder. + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +/** For ESP8266, with BearSSL WiFi Client + * The memory reserved for completed valid SSL response from IMAP is 16 kbytes which + * may cause your device out of memory reset in case the memory + * allocation error. + */ + +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +#include + +// To use only IMAP functions, you can exclude the SMTP from compilation, see ESP_Mail_FS.h. + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +/** For Gmail, IMAP option should be enabled. https://support.google.com/mail/answer/7126229?hl=en + * and also https://accounts.google.com/b/0/DisplayUnlockCaptcha + * + * Some Gmail user still not able to sign in using account password even above options were set up, + * for this case, use "App Password" to sign in instead. + * About Gmail "App Password", go to https://support.google.com/accounts/answer/185833?hl=en + * + * For Yahoo mail, log in to your yahoo mail in web browser and generate app password by go to + * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc + * + * To use Gmai and Yahoo's App Password to sign in, define the AUTHOR_PASSWORD with your App Password + * and AUTHOR_EMAIL with your account email. + */ + +/* The imap host name e.g. imap.gmail.com for GMail or outlook.office365.com for Outlook */ +#define IMAP_HOST "" + +/** The imap port e.g. + * 143 or esp_mail_imap_port_143 + * 993 or esp_mail_imap_port_993 + */ +#define IMAP_PORT 993 + +/* The log in credentials */ +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" + +/* Print the list of mailbox folders */ +void printAllMailboxesInfo(IMAPSession &imap); + +/* Declare the global used IMAPSession object for IMAP transport */ +IMAPSession imap; + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) +WiFiMulti multi; +#endif + +void setup() +{ + + Serial.begin(115200); + +#if defined(ARDUINO_ARCH_SAMD) + while (!Serial) + ; +#endif + + Serial.println(); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + multi.addAP(WIFI_SSID, WIFI_PASSWORD); + multi.run(); +#else + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Connecting to Wi-Fi"); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + unsigned long ms = millis(); +#endif + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + if (millis() - ms > 10000) + break; +#endif + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + /* Set the network reconnection option */ + MailClient.networkReconnect(true); + + // The WiFi credentials are required for Pico W + // due to it does not have reconnect feature. +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + MailClient.clearAP(); + MailClient.addAP(WIFI_SSID, WIFI_PASSWORD); +#endif + + /** Enable the debug via Serial port + * 0 for no debugging + * 1 for basic level debugging + * + * Debug port can be changed via ESP_MAIL_DEFAULT_DEBUG_PORT in ESP_Mail_FS.h + */ + imap.debug(1); + + /* Declare the Session_Config for user defined session credentials */ + Session_Config config; + + /* Set the session config */ + config.server.host_name = IMAP_HOST; + config.server.port = IMAP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + + /* Define the IMAP_Data object used for user defined IMAP operating options. */ + IMAP_Data imap_data; + + /* Connect to the server */ + if (!imap.connect(&config, &imap_data)) + return; + + if (imap.isAuthenticated()) + Serial.println("\nSuccessfully logged in."); + else + Serial.println("\nConnected with no Auth."); + + /* {Optional} */ + printAllMailboxesInfo(imap); + + /* Open or select the mailbox folder to read or search the message */ + if (!imap.selectFolder(F("INBOX"))) + return; + + /* Define the MessageList class to add the message to move */ + MessageList toMove; + + /* Add message uid to move to the list */ + toMove.add(3); + toMove.add(4); + + // imap.createFolder("test"); + + /* Move all messages in the list to the folder "test" */ + if (imap.moveMessages(&toMove, F("test"))) + Serial.println("\nMessages moved"); + + MailClient.printf("Free Heap: %d\n", MailClient.getFreeHeap()); +} + +void loop() +{ +} + +void printAllMailboxesInfo(IMAPSession &imap) +{ + /* Declare the folder collection class to get the list of mailbox folders */ + FoldersCollection folders; + + /* Get the mailbox folders */ + if (imap.getFolders(folders)) + { + for (size_t i = 0; i < folders.size(); i++) + { + /* Iterate each folder info using the folder info item data */ + FolderInfo folderInfo = folders.info(i); + MailClient.printf("%s%s%s", i == 0 ? "\nAvailable folders: " : ", ", folderInfo.name, i == folders.size() - 1 ? "\n" : ""); + } + } +} diff --git a/lib/libesp32/ESP-Mail-Client/examples/IMAP/Move_Messages/Move_Messages_Message_Numbers_Ranges/Move_Messages_Message_Numbers_Ranges.ino b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Move_Messages/Move_Messages_Message_Numbers_Ranges/Move_Messages_Message_Numbers_Ranges.ino new file mode 100644 index 000000000..329c9db99 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Move_Messages/Move_Messages_Message_Numbers_Ranges/Move_Messages_Message_Numbers_Ranges.ino @@ -0,0 +1,213 @@ +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt +*/ + +// This example shows how to move messages from the mailbox to other folder using message numbers ranges. + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +/** For ESP8266, with BearSSL WiFi Client + * The memory reserved for completed valid SSL response from IMAP is 16 kbytes which + * may cause your device out of memory reset in case the memory + * allocation error. + */ + +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +#include + +// To use only IMAP functions, you can exclude the SMTP from compilation, see ESP_Mail_FS.h. + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +/** For Gmail, IMAP option should be enabled. https://support.google.com/mail/answer/7126229?hl=en + * and also https://accounts.google.com/b/0/DisplayUnlockCaptcha + * + * Some Gmail user still not able to sign in using account password even above options were set up, + * for this case, use "App Password" to sign in instead. + * About Gmail "App Password", go to https://support.google.com/accounts/answer/185833?hl=en + * + * For Yahoo mail, log in to your yahoo mail in web browser and generate app password by go to + * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc + * + * To use Gmai and Yahoo's App Password to sign in, define the AUTHOR_PASSWORD with your App Password + * and AUTHOR_EMAIL with your account email. + */ + +/* The imap host name e.g. imap.gmail.com for GMail or outlook.office365.com for Outlook */ +#define IMAP_HOST "" + +/** The imap port e.g. + * 143 or esp_mail_imap_port_143 + * 993 or esp_mail_imap_port_993 + */ +#define IMAP_PORT 993 + +/* The log in credentials */ +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" + +/* Print the list of mailbox folders */ +void printAllMailboxesInfo(IMAPSession &imap); + +/* Declare the global used IMAPSession object for IMAP transport */ +IMAPSession imap; + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) +WiFiMulti multi; +#endif + +void setup() +{ + + Serial.begin(115200); + +#if defined(ARDUINO_ARCH_SAMD) + while (!Serial) + ; +#endif + Serial.println(); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + multi.addAP(WIFI_SSID, WIFI_PASSWORD); + multi.run(); +#else + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Connecting to Wi-Fi"); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + unsigned long ms = millis(); +#endif + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + if (millis() - ms > 10000) + break; +#endif + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + /* Set the network reconnection option */ + MailClient.networkReconnect(true); + + // The WiFi credentials are required for Pico W + // due to it does not have reconnect feature. +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + MailClient.clearAP(); + MailClient.addAP(WIFI_SSID, WIFI_PASSWORD); +#endif + + /** Enable the debug via Serial port + * 0 for no debugging + * 1 for basic level debugging + * + * Debug port can be changed via ESP_MAIL_DEFAULT_DEBUG_PORT in ESP_Mail_FS.h + */ + imap.debug(1); + + /* Declare the Session_Config for user defined session credentials */ + Session_Config config; + + /* Set the session config */ + config.server.host_name = IMAP_HOST; + config.server.port = IMAP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + + /* Define the IMAP_Data object used for user defined IMAP operating options. */ + IMAP_Data imap_data; + + /* Connect to the server */ + if (!imap.connect(&config, &imap_data)) + return; + + if (imap.isAuthenticated()) + Serial.println("\nSuccessfully logged in."); + else + Serial.println("\nConnected with no Auth."); + + /* {Optional} */ + printAllMailboxesInfo(imap); + + /* Open or select the mailbox folder to read or search the message */ + if (!imap.selectFolder(F("INBOX"))) + return; + + /* Move all messages using message sequence ranges (last 10 message numbers) to the folder "test"*/ + int msg_last = imap.selectedFolder().msgCount(); + int msg_begin = msg_last > 10 ? msg_last - 10 : msg_last; + + String sequence_set2 = String(msg_begin) + ":" + String(msg_last); + + if (imap.moveMessages(sequence_set2, false /* if sequence set are message numbers not UIDs */, F("test"))) + Serial.println("\nMoving messages using message numbers ranges success"); + else + Serial.println("\nError, moving messages using message numbers ranges"); + + // imap.deleteolder("test"); + + MailClient.printf("Free Heap: %d\n", MailClient.getFreeHeap()); +} + +void loop() +{ +} + +void printAllMailboxesInfo(IMAPSession &imap) +{ + /* Declare the folder collection class to get the list of mailbox folders */ + FoldersCollection folders; + + /* Get the mailbox folders */ + if (imap.getFolders(folders)) + { + for (size_t i = 0; i < folders.size(); i++) + { + /* Iterate each folder info using the folder info item data */ + FolderInfo folderInfo = folders.info(i); + MailClient.printf("%s%s%s", i == 0 ? "\nAvailable folders: " : ", ", folderInfo.name, i == folders.size() - 1 ? "\n" : ""); + } + } +} diff --git a/lib/libesp32/ESP-Mail-Client/examples/IMAP/Move_Messages/Move_Messages_UIDs_Ranges/Move_Messages_UIDs_Ranges.ino b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Move_Messages/Move_Messages_UIDs_Ranges/Move_Messages_UIDs_Ranges.ino new file mode 100644 index 000000000..3d75cc065 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Move_Messages/Move_Messages_UIDs_Ranges/Move_Messages_UIDs_Ranges.ino @@ -0,0 +1,214 @@ +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt +*/ + +// This example shows how to move messages from the mailbox to other folder using UIDs ranges. + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +/** For ESP8266, with BearSSL WiFi Client + * The memory reserved for completed valid SSL response from IMAP is 16 kbytes which + * may cause your device out of memory reset in case the memory + * allocation error. + */ + +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +#include + +// To use only IMAP functions, you can exclude the SMTP from compilation, see ESP_Mail_FS.h. + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +/** For Gmail, IMAP option should be enabled. https://support.google.com/mail/answer/7126229?hl=en + * and also https://accounts.google.com/b/0/DisplayUnlockCaptcha + * + * Some Gmail user still not able to sign in using account password even above options were set up, + * for this case, use "App Password" to sign in instead. + * About Gmail "App Password", go to https://support.google.com/accounts/answer/185833?hl=en + * + * For Yahoo mail, log in to your yahoo mail in web browser and generate app password by go to + * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc + * + * To use Gmai and Yahoo's App Password to sign in, define the AUTHOR_PASSWORD with your App Password + * and AUTHOR_EMAIL with your account email. + */ + +/* The imap host name e.g. imap.gmail.com for GMail or outlook.office365.com for Outlook */ +#define IMAP_HOST "" + +/** The imap port e.g. + * 143 or esp_mail_imap_port_143 + * 993 or esp_mail_imap_port_993 + */ +#define IMAP_PORT 993 + +/* The log in credentials */ +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" + +/* Print the list of mailbox folders */ +void printAllMailboxesInfo(IMAPSession &imap); + +/* Declare the global used IMAPSession object for IMAP transport */ +IMAPSession imap; + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) +WiFiMulti multi; +#endif + +void setup() +{ + + Serial.begin(115200); + +#if defined(ARDUINO_ARCH_SAMD) + while (!Serial) + ; +#endif + + Serial.println(); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + multi.addAP(WIFI_SSID, WIFI_PASSWORD); + multi.run(); +#else + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Connecting to Wi-Fi"); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + unsigned long ms = millis(); +#endif + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + if (millis() - ms > 10000) + break; +#endif + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + /* Set the network reconnection option */ + MailClient.networkReconnect(true); + + // The WiFi credentials are required for Pico W + // due to it does not have reconnect feature. +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + MailClient.clearAP(); + MailClient.addAP(WIFI_SSID, WIFI_PASSWORD); +#endif + + /** Enable the debug via Serial port + * 0 for no debugging + * 1 for basic level debugging + * + * Debug port can be changed via ESP_MAIL_DEFAULT_DEBUG_PORT in ESP_Mail_FS.h + */ + imap.debug(1); + + /* Declare the Session_Config for user defined session credentials */ + Session_Config config; + + /* Set the session config */ + config.server.host_name = IMAP_HOST; + config.server.port = IMAP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + + /* Define the IMAP_Data object used for user defined IMAP operating options. */ + IMAP_Data imap_data; + + /* Connect to the server */ + if (!imap.connect(&config, &imap_data)) + return; + + if (imap.isAuthenticated()) + Serial.println("\nSuccessfully logged in."); + else + Serial.println("\nConnected with no Auth."); + + /* {Optional} */ + printAllMailboxesInfo(imap); + + /* Open or select the mailbox folder to read or search the message */ + if (!imap.selectFolder(F("INBOX"))) + return; + + /* Move all messages using UIDs ranges (last 10 UIDs) to the folder "test" */ + int uid_last = imap.getUID(imap.selectedFolder().msgCount()); + int uid_begin = uid_last > 10 ? uid_last - 10 : uid_last; + + String sequence_set1 = String(uid_begin) + ":" + String(uid_last); + + if (imap.moveMessages(sequence_set1, true /* if sequence set are the UIDs */, F("test"))) + Serial.println("\nMoving messages using UIDs ranges success"); + else + Serial.println("\nError, moving messages using UIDs ranges"); + + // imap.deleteolder("test"); + + MailClient.printf("Free Heap: %d\n", MailClient.getFreeHeap()); +} + +void loop() +{ +} + +void printAllMailboxesInfo(IMAPSession &imap) +{ + /* Declare the folder collection class to get the list of mailbox folders */ + FoldersCollection folders; + + /* Get the mailbox folders */ + if (imap.getFolders(folders)) + { + for (size_t i = 0; i < folders.size(); i++) + { + /* Iterate each folder info using the folder info item data */ + FolderInfo folderInfo = folders.info(i); + MailClient.printf("%s%s%s", i == 0 ? "\nAvailable folders: " : ", ", folderInfo.name, i == folders.size() - 1 ? "\n" : ""); + } + } +} diff --git a/lib/libesp32/ESP-Mail-Client/examples/IMAP/Namespaces/Namespaces.ino b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Namespaces/Namespaces.ino new file mode 100644 index 000000000..533d90dcf --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Namespaces/Namespaces.ino @@ -0,0 +1,216 @@ +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt +*/ + +// This example shows how to get the namespaces. + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +/** For ESP8266, with BearSSL WiFi Client + * The memory reserved for completed valid SSL response from IMAP is 16 kbytes which + * may cause your device out of memory reset in case the memory + * allocation error. + */ + +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +#include + +// To use only IMAP functions, you can exclude the SMTP from compilation, see ESP_Mail_FS.h. + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +/** For Gmail, IMAP option should be enabled. https://support.google.com/mail/answer/7126229?hl=en + * and also https://accounts.google.com/b/0/DisplayUnlockCaptcha + * + * Some Gmail user still not able to sign in using account password even above options were set up, + * for this case, use "App Password" to sign in instead. + * About Gmail "App Password", go to https://support.google.com/accounts/answer/185833?hl=en + * + * For Yahoo mail, log in to your yahoo mail in web browser and generate app password by go to + * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc + * + * To use Gmai and Yahoo's App Password to sign in, define the AUTHOR_PASSWORD with your App Password + * and AUTHOR_EMAIL with your account email. + */ + +/* The imap host name e.g. imap.gmail.com for GMail or outlook.office365.com for Outlook */ +#define IMAP_HOST "" + +/** The imap port e.g. + * 143 or esp_mail_imap_port_143 + * 993 or esp_mail_imap_port_993 + */ +#define IMAP_PORT 993 + +/* The log in credentials */ +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" + +/* Declare the global used IMAPSession object for IMAP transport */ +IMAPSession imap; + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) +WiFiMulti multi; +#endif + +void setup() +{ + + Serial.begin(115200); + +#if defined(ARDUINO_ARCH_SAMD) + while (!Serial) + ; +#endif + + Serial.println(); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + multi.addAP(WIFI_SSID, WIFI_PASSWORD); + multi.run(); +#else + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Connecting to Wi-Fi"); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + unsigned long ms = millis(); +#endif + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + if (millis() - ms > 10000) + break; +#endif + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + /* Set the network reconnection option */ + MailClient.networkReconnect(true); + + // The WiFi credentials are required for Pico W + // due to it does not have reconnect feature. +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + MailClient.clearAP(); + MailClient.addAP(WIFI_SSID, WIFI_PASSWORD); +#endif + + /** Enable the debug via Serial port + * 0 for no debugging + * 1 for basic level debugging + * + * Debug port can be changed via ESP_MAIL_DEFAULT_DEBUG_PORT in ESP_Mail_FS.h + */ + imap.debug(1); + + /* Declare the Session_Config for user defined session credentials */ + Session_Config config; + + /* Set the session config */ + config.server.host_name = IMAP_HOST; + config.server.port = IMAP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + + /* Define the IMAP_Data object used for user defined IMAP operating options. */ + IMAP_Data imap_data; + + /* Connect to the server */ + if (!imap.connect(&config, &imap_data)) + return; + + if (imap.isAuthenticated()) + Serial.println("\nSuccessfully logged in."); + else + Serial.println("\nConnected with no Auth."); + + /* Open or select the mailbox folder to read or search the message */ + if (!imap.selectFolder(F("INBOX"))) + return; + + IMAP_Namespaces_List ns_list; + + Serial.println("\nGet namespaces..."); + + if (!imap.getNamespace(&ns_list)) + { + Serial.println("\nGet namespaces failed"); + } + else + { + if (ns_list.personal_namespaces.size() > 0) + { + Serial.println("\nPersonal Namespaces..."); + for (size_t i = 0; i < ns_list.personal_namespaces.size(); i++) + { + MailClient.printf("Prefix: %s, Delimiter: %s\n", ns_list.personal_namespaces[i].prefix.c_str(), ns_list.personal_namespaces[i].delimiter.c_str()); + } + } + + if (ns_list.other_users_namespaces.size() > 0) + { + Serial.println("\nOther Users Namespaces..."); + for (size_t i = 0; i < ns_list.other_users_namespaces.size(); i++) + { + MailClient.printf("Prefix: %s, Delimiter: %s\n", ns_list.other_users_namespaces[i].prefix.c_str(), ns_list.other_users_namespaces[i].delimiter.c_str()); + } + } + + if (ns_list.shared_namespaces.size() > 0) + { + Serial.println("\nShared Namespaces..."); + for (size_t i = 0; i < ns_list.shared_namespaces.size(); i++) + { + MailClient.printf("Prefix: %s, Delimiter: %s\n", ns_list.shared_namespaces[i].prefix.c_str(), ns_list.shared_namespaces[i].delimiter.c_str()); + } + } + } + + MailClient.printf("Free Heap: %d\n", MailClient.getFreeHeap()); +} + +void loop() +{ +} diff --git a/lib/libesp32/ESP-Mail-Client/examples/IMAP/Read_Email_Access_Token/Read_Email_Access_Token.ino b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Read_Email_Access_Token/Read_Email_Access_Token.ino new file mode 100644 index 000000000..26b32a91b --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Read_Email_Access_Token/Read_Email_Access_Token.ino @@ -0,0 +1,472 @@ +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt +*/ + +// This example will log in with the SASL XOAUTH2 mechanisme using OAuth2.0 access token. + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +/** For ESP8266, with BearSSL WiFi Client + * The memory reserved for completed valid SSL response from IMAP is 16 kbytes which + * may cause your device out of memory reset in case the memory + * allocation error. + */ + +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +#include + +// To use only IMAP functions, you can exclude the SMTP from compilation, see ESP_Mail_FS.h. + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +/** For Gmail, IMAP option should be enabled. https://support.google.com/mail/answer/7126229?hl=en + * and also https://accounts.google.com/b/0/DisplayUnlockCaptcha + * + * Some Gmail user still not able to sign in using account password even above options were set up, + * for this case, use "App Password" to sign in instead. + * About Gmail "App Password", go to https://support.google.com/accounts/answer/185833?hl=en + * + * For Yahoo mail, log in to your yahoo mail in web browser and generate app password by go to + * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc + * + * To use Gmai and Yahoo's App Password to sign in, define the AUTHOR_PASSWORD with your App Password + * and AUTHOR_EMAIL with your account email. + */ + +/* The imap host name e.g. imap.gmail.com for GMail or outlook.office365.com for Outlook */ +#define IMAP_HOST "" + +/** The imap port e.g. + * 143 or esp_mail_imap_port_143 + * 993 or esp_mail_imap_port_993 + */ +#define IMAP_PORT 993 + +/* The log in credentials */ +#define AUTHOR_EMAIL "" + +/** The OAuth2.0 access token + * The generation, exchange and refresh of the access token are not available + * in this library. + * + * To test this using GMail, get the OAuth2.0 access token from this web site + * https://developers.google.com/oauthplayground/ + * + * 1. Select the following scope (in Step 1) from Gmail API V1 + * https://mail.google.com/ + * https://mail.google.com/ + * + * 2. Click Authorize APIs button. + * 3. Cick Exchangeauthorization code for tokens. + * 4. From the response, look at access_token from the JSON payload node. + * 5. Copy that access token and paste to the AUTHOR_ACCESS_TOKEN value. + * + * The token will be expired in 3600 seconds (1 Hr). + * The AUTHOR_EMAIL above is the Email address that you granted to access the Gmail services. + */ +#define AUTHOR_ACCESS_TOKEN "" + +/* Callback function to get the Email reading status */ +void imapCallback(IMAP_Status status); + +/* Print the list of mailbox folders */ +void printAllMailboxesInfo(IMAPSession &imap); + +/* Print the selected folder info */ +void printSelectedMailboxInfo(SelectedFolderInfo sFolder); + +/* Print all messages from the message list */ +void printMessages(std::vector &msgItems, bool headerOnly); + +/* Print all attachments info from the message */ +void printAttacements(std::vector &atts); + +/* Declare the global used IMAPSession object for IMAP transport */ +IMAPSession imap; + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) +WiFiMulti multi; +#endif + +void setup() +{ + + Serial.begin(115200); + +#if defined(ARDUINO_ARCH_SAMD) + while (!Serial) + ; +#endif + + Serial.println(); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + multi.addAP(WIFI_SSID, WIFI_PASSWORD); + multi.run(); +#else + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Connecting to Wi-Fi"); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + unsigned long ms = millis(); +#endif + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + if (millis() - ms > 10000) + break; +#endif + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + /* Set the network reconnection option */ + MailClient.networkReconnect(true); + + // The WiFi credentials are required for Pico W + // due to it does not have reconnect feature. +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + MailClient.clearAP(); + MailClient.addAP(WIFI_SSID, WIFI_PASSWORD); +#endif + + /** Enable the debug via Serial port + * 0 for no debugging + * 1 for basic level debugging + * + * Debug port can be changed via ESP_MAIL_DEFAULT_DEBUG_PORT in ESP_Mail_FS.h + */ + imap.debug(1); + + /* Set the callback function to get the reading results */ + imap.callback(imapCallback); + + /** In case the SD card/adapter was used for the file storagge, the SPI pins can be configure from + * MailClient.sdBegin function which may be different for ESP32 and ESP8266 + * For ESP32, assign all of SPI pins + * MailClient.sdBegin(14,2,15,13) + * Which SCK = 14, MISO = 2, MOSI = 15 and SS = 13 + * And for ESP8266, assign the CS pins of SPI port + * MailClient.sdBegin(15) + * Which pin 15 is the CS pin of SD card adapter + */ + + /* Declare the Session_Config for user defined session credentials */ + Session_Config config; + + /* Set the session config */ + config.server.host_name = IMAP_HOST; + config.server.port = IMAP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.accessToken = AUTHOR_ACCESS_TOKEN; + + /* Define the IMAP_Data object used for user defined IMAP operating options. */ + IMAP_Data imap_data; + + /* Message UID to fetch or read e.g. 100 */ + imap_data.fetch.uid = imap.getUID(imap.selectedFolder().msgCount()); + + /* Set seen flag*/ + // imap_data.fetch.set_seen = true; + + /* Search criteria */ + imap_data.search.criteria.clear(); + + /* Also search the unseen message */ + imap_data.search.unseen_msg = true; + + /* Set the storage to save the downloaded files and attachments */ + imap_data.storage.saved_path = F("/email_data"); + + /** The file storage type e.g. + * esp_mail_file_storage_type_none, + * esp_mail_file_storage_type_flash, and + * esp_mail_file_storage_type_sd + */ + imap_data.storage.type = esp_mail_file_storage_type_flash; + + /** Set to download headers, text and html messaeges, + * attachments and inline images respectively. + */ + imap_data.download.header = true; + imap_data.download.text = true; + imap_data.download.html = true; + imap_data.download.attachment = true; + imap_data.download.inlineImg = true; + + /** Set to enable the results i.e. html and text messaeges + * which the content stored in the IMAPSession object is limited + * by the option imap_data.limit.msg_size. + * The whole message can be download through imap_data.download.text + * or imap_data.download.html which not depends on these enable options. + */ + imap_data.enable.html = true; + imap_data.enable.text = true; + + /* Set to enable the sort the result by message UID in the decending order */ + imap_data.enable.recent_sort = true; + + /* Set to report the download progress via the default serial port */ + imap_data.enable.download_status = true; + + /* Header fields parsing is case insensitive by default to avoid uppercase header in some server e.g. iCloud + , to allow case sensitive parse, uncomment below line*/ + // imap_data.enable.header_case_sensitive = true; + + /* Set the limit of number of messages in the search results */ + imap_data.limit.search = 5; + + /** Set the maximum size of message stored in + * IMAPSession object in byte + */ + imap_data.limit.msg_size = 512; + + /** Set the maximum attachments and inline images files size + * that can be downloaded in byte. + * The file which its size is largger than this limit may be saved + * as truncated file. + */ + imap_data.limit.attachment_size = 1024 * 1024 * 5; + + /* Connect to the server */ + if (!imap.connect(&config, &imap_data)) + return; + + if (imap.isAuthenticated()) + Serial.println("\nSuccessfully logged in."); + else + Serial.println("\nConnected with no Auth."); + + /* {Optional} */ + printAllMailboxesInfo(imap); + + /* Open or select the mailbox folder to read or search the message */ + if (!imap.selectFolder(F("INBOX"))) + return; + + /* {Optional} */ + printSelectedMailboxInfo(imap.selectedFolder()); + + /* Read or search the Email and close the session */ + + // When message was fetched or read, the /Seen flag will not set or message remained in unseen or unread status, + // as this is the purpose of library (not UI application), user can set the message status as read by set \Seen flag + // to message, see the Set_Flags.ino example. + MailClient.readMail(&imap); + + /* Clear all stored data in IMAPSession object */ + imap.empty(); +} + +void loop() +{ +} + +/* Callback function to get the Email reading status */ +void imapCallback(IMAP_Status status) +{ + /* Print the current status */ + Serial.println(status.info()); + + /* Show the result when reading finished */ + if (status.success()) + { + /* Print the result */ + /* Get the message list from the message list data */ + IMAP_MSG_List msgList = imap.data(); + printMessages(msgList.msgItems, imap.headerOnly()); + + /* Clear all stored data in IMAPSession object */ + imap.empty(); + } +} + +void printAllMailboxesInfo(IMAPSession &imap) +{ + /* Declare the folder collection class to get the list of mailbox folders */ + FoldersCollection folders; + + /* Get the mailbox folders */ + if (imap.getFolders(folders)) + { + for (size_t i = 0; i < folders.size(); i++) + { + /* Iterate each folder info using the folder info item data */ + FolderInfo folderInfo = folders.info(i); + MailClient.printf("%s%s%s", i == 0 ? "\nAvailable folders: " : ", ", folderInfo.name, i == folders.size() - 1 ? "\n" : ""); + } + } +} + +void printSelectedMailboxInfo(SelectedFolderInfo sFolder) +{ + /* Show the mailbox info */ + MailClient.printf("\nInfo of the selected folder\nTotal Messages: %d\n", sFolder.msgCount()); + MailClient.printf("UID Validity: %d\n", sFolder.uidValidity()); + MailClient.printf("Predicted next UID: %d\n", sFolder.nextUID()); + if (sFolder.unseenIndex() > 0) + MailClient.printf("First Unseen Message Number: %d\n", sFolder.unseenIndex()); + else + MailClient.printf("Unseen Messages: No\n"); + + if (sFolder.modSeqSupported()) + MailClient.printf("Highest Modification Sequence: %llu\n", sFolder.highestModSeq()); + for (size_t i = 0; i < sFolder.flagCount(); i++) + MailClient.printf("%s%s%s", i == 0 ? "Flags: " : ", ", sFolder.flag(i).c_str(), i == sFolder.flagCount() - 1 ? "\n" : ""); + + if (sFolder.flagCount(true)) + { + for (size_t i = 0; i < sFolder.flagCount(true); i++) + MailClient.printf("%s%s%s", i == 0 ? "Permanent Flags: " : ", ", sFolder.flag(i, true).c_str(), i == sFolder.flagCount(true) - 1 ? "\n" : ""); + } +} + +void printAttacements(std::vector &atts) +{ + MailClient.printf("Attachment: %d file(s)\n****************************\n", atts.size()); + for (size_t j = 0; j < atts.size(); j++) + { + IMAP_Attach_Item att = atts[j]; + /** att.type can be + * esp_mail_att_type_none or 0 + * esp_mail_att_type_attachment or 1 + * esp_mail_att_type_inline or 2 + */ + MailClient.printf("%d. Filename: %s, Name: %s, Size: %d, MIME: %s, Type: %s, Description: %s, Creation Date: %s\n", j + 1, att.filename, att.name, att.size, att.mime, att.type == esp_mail_att_type_attachment ? "attachment" : "inline", att.description, att.creationDate); + } + Serial.println(); +} + +void printMessages(std::vector &msgItems, bool headerOnly) +{ + + /** In devices other than ESP8266 and ESP32, if SD card was chosen as filestorage and + * the standard SD.h library included in ESP_Mail_FS.h, files will be renamed due to long filename + * (> 13 characters) is not support in the SD.h library. + * To show how its original file name, use imap.fileList(). + */ + // Serial.println(imap.fileList()); + + for (size_t i = 0; i < msgItems.size(); i++) + { + + /* Iterate to get each message data through the message item data */ + IMAP_MSG_Item msg = msgItems[i]; + + Serial.println("****************************"); + MailClient.printf("Number: %d\n", msg.msgNo); + MailClient.printf("UID: %d\n", msg.UID); + + // The attachment status in search may be true in case the "multipart/mixed" + // content type header was set with no real attachtment included. + MailClient.printf("Attachment: %s\n", msg.hasAttachment ? "yes" : "no"); + + MailClient.printf("Messsage-ID: %s\n", msg.ID); + + if (strlen(msg.flags)) + MailClient.printf("Flags: %s\n", msg.flags); + if (strlen(msg.acceptLang)) + MailClient.printf("Accept Language: %s\n", msg.acceptLang); + if (strlen(msg.contentLang)) + MailClient.printf("Content Language: %s\n", msg.contentLang); + if (strlen(msg.from)) + MailClient.printf("From: %s\n", msg.from); + if (strlen(msg.sender)) + MailClient.printf("Sender: %s\n", msg.sender); + if (strlen(msg.to)) + MailClient.printf("To: %s\n", msg.to); + if (strlen(msg.cc)) + MailClient.printf("CC: %s\n", msg.cc); + if (strlen(msg.bcc)) + MailClient.printf("BCC: %s\n", msg.bcc); + if (strlen(msg.date)) + { + MailClient.printf("Date: %s\n", msg.date); + MailClient.printf("Timestamp: %d\n", (int)MailClient.Time.getTimestamp(msg.date)); + } + if (strlen(msg.subject)) + MailClient.printf("Subject: %s\n", msg.subject); + if (strlen(msg.reply_to)) + MailClient.printf("Reply-To: %s\n", msg.reply_to); + if (strlen(msg.return_path)) + MailClient.printf("Return-Path: %s\n", msg.return_path); + if (strlen(msg.in_reply_to)) + MailClient.printf("In-Reply-To: %s\n", msg.in_reply_to); + if (strlen(msg.references)) + MailClient.printf("References: %s\n", msg.references); + if (strlen(msg.comments)) + MailClient.printf("Comments: %s\n", msg.comments); + if (strlen(msg.keywords)) + MailClient.printf("Keywords: %s\n", msg.keywords); + + /* If the result contains the message info (Fetch mode) */ + if (!headerOnly) + { + if (strlen(msg.text.content)) + MailClient.printf("Text Message: %s\n", msg.text.content); + if (strlen(msg.text.charSet)) + MailClient.printf("Text Message Charset: %s\n", msg.text.charSet); + if (strlen(msg.text.transfer_encoding)) + MailClient.printf("Text Message Transfer Encoding: %s\n", msg.text.transfer_encoding); + if (strlen(msg.html.content)) + MailClient.printf("HTML Message: %s\n", msg.html.content); + if (strlen(msg.html.charSet)) + MailClient.printf("HTML Message Charset: %s\n", msg.html.charSet); + if (strlen(msg.html.transfer_encoding)) + MailClient.printf("HTML Message Transfer Encoding: %s\n\n", msg.html.transfer_encoding); + + if (msg.rfc822.size() > 0) + { + MailClient.printf("\r\nRFC822 Messages: %d message(s)\n****************************\n", msg.rfc822.size()); + printMessages(msg.rfc822, headerOnly); + } + + if (msg.attachments.size() > 0) + printAttacements(msg.attachments); + } + + Serial.println(); + } +} diff --git a/lib/libesp32/ESP-Mail-Client/examples/IMAP/Read_Sequence_Set/Read_Sequence_Set.ino b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Read_Sequence_Set/Read_Sequence_Set.ino new file mode 100644 index 000000000..63ce16c97 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Read_Sequence_Set/Read_Sequence_Set.ino @@ -0,0 +1,477 @@ +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt +*/ + +// This example shows how to read Email using UIDs ranges or message numbers ranges. + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +/** Assign SD card type and FS used in src/ESP_Mail_FS.h and + * change the config for that card interfaces in src/extras/SDHelper.h + */ + +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +#include + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +/** For Gmail, IMAP option should be enabled. https://support.google.com/mail/answer/7126229?hl=en + * and also https://accounts.google.com/b/0/DisplayUnlockCaptcha + * + * Some Gmail user still not able to sign in using account password even above options were set up, + * for this case, use "App Password" to sign in instead. + * About Gmail "App Password", go to https://support.google.com/accounts/answer/185833?hl=en + * + * For Yahoo mail, log in to your yahoo mail in web browser and generate app password by go to + * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc + * + * To use Gmai and Yahoo's App Password to sign in, define the AUTHOR_PASSWORD with your App Password + * and AUTHOR_EMAIL with your account email. + */ + +/* The imap host name e.g. imap.gmail.com for GMail or outlook.office365.com for Outlook */ +#define IMAP_HOST "" + +/** The imap port e.g. + * 143 or esp_mail_imap_port_143 + * 993 or esp_mail_imap_port_993 + */ +#define IMAP_PORT 993 + +/* The log in credentials */ +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" + +/* Callback function to get the Email reading status */ +void imapCallback(IMAP_Status status); + +/* Print the list of mailbox folders */ +void printAllMailboxesInfo(IMAPSession &imap); + +/* Print the selected folder info */ +void printSelectedMailboxInfo(SelectedFolderInfo sFolder); + +/* Print all messages from the message list */ +void printMessages(std::vector &msgItems, bool headerOnly); + +/* Print all attachments info from the message */ +void printAttacements(std::vector &atts); + +/* Declare the Session_Config for user defined session credentials */ +Session_Config config; + +/* Declare the global used IMAPSession object for IMAP transport */ +IMAPSession imap; + +/* Define the IMAP_Data object used for user defined IMAP operating options. */ +IMAP_Data imap_data; + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) +WiFiMulti multi; +#endif + +void readEmailsUIDS() +{ + + int uid_last = imap.getUID(imap.selectedFolder().msgCount()); + int uid_begin = uid_last > 10 ? uid_last - 10 : uid_last; + + // Fetch last 10 UIDs + String sequence_set = String(uid_begin) + ":" + String(uid_last); + + imap_data.fetch.sequence_set.string = sequence_set; + + imap_data.fetch.sequence_set.UID = true; // The sequence set are UIDs ranges + + imap_data.fetch.sequence_set.headerOnly = true; // Do not fetch the content, header only + + MailClient.readMail(&imap, false /* do not close sessiopn */); + + imap_data.limit.fetch = 5; // Set the limit of number of messages in the fetch results +} + +void readEmailsNumbers() +{ + int msg_last = imap.selectedFolder().msgCount(); + int msg_begin = msg_last > 10 ? msg_last - 10 : msg_last; + + String sequence_set = String(msg_begin) + ":" + String(msg_last); + + imap_data.fetch.sequence_set.string = sequence_set; + + imap_data.fetch.sequence_set.UID = false; // The sequence set are not UIDs + + imap_data.fetch.sequence_set.headerOnly = true; // Do not fetch the content, header only + + imap_data.limit.fetch = 5; // Set the limit of number of messages in the fetch results + + // Read Email and close session + MailClient.readMail(&imap); + + /* Clear all stored data in IMAPSession object */ + imap.empty(); +} + +void setup() +{ + + Serial.begin(115200); + +#if defined(ARDUINO_ARCH_SAMD) + while (!Serial) + ; +#endif + + Serial.println(); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + multi.addAP(WIFI_SSID, WIFI_PASSWORD); + multi.run(); +#else + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Connecting to Wi-Fi"); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + unsigned long ms = millis(); +#endif + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + if (millis() - ms > 10000) + break; +#endif + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + /* Set the network reconnection option */ + MailClient.networkReconnect(true); + + // The WiFi credentials are required for Pico W + // due to it does not have reconnect feature. +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + MailClient.clearAP(); + MailClient.addAP(WIFI_SSID, WIFI_PASSWORD); +#endif + + /** Enable the debug via Serial port + * 0 for no debugging + * 1 for basic level debugging + * + * Debug port can be changed via ESP_MAIL_DEFAULT_DEBUG_PORT in ESP_Mail_FS.h + */ + imap.debug(1); + + /* Set the callback function to get the reading results */ + imap.callback(imapCallback); + + /** In case the SD card/adapter was used for the file storagge, the SPI pins can be configure from + * MailClient.sdBegin function which may be different for ESP32 and ESP8266 + * For ESP32, assign all of SPI pins + * MailClient.sdBegin(14,2,15,13) + * Which SCK = 14, MISO = 2, MOSI = 15 and SS = 13 + * And for ESP8266, assign the CS pins of SPI port + * MailClient.sdBegin(15) + * Which pin 15 is the CS pin of SD card adapter + */ + + /* Set the session config */ + config.server.host_name = IMAP_HOST; + config.server.port = IMAP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + + /* Set the storage to save the downloaded files and attachments */ + imap_data.storage.saved_path = F("/email_data"); + + /** Set to enable the results i.e. html and text messaeges + * which the content stored in the IMAPSession object is limited + * by the option imap_data.limit.msg_size. + * The whole message can be download through imap_data.download.text + * or imap_data.download.html which not depends on these enable options. + */ + imap_data.enable.html = true; + imap_data.enable.text = true; + + /* Set to enable the sort the result by message UID in the decending order */ + imap_data.enable.recent_sort = true; + + /* Set to report the download progress via the default serial port */ + imap_data.enable.download_status = true; + + /* Header fields parsing is case insensitive by default to avoid uppercase header in some server e.g. iCloud + , to allow case sensitive parse, uncomment below line*/ + // imap_data.enable.header_case_sensitive = true; + + /** Set the maximum size of message stored in + * IMAPSession object in byte + */ + imap_data.limit.msg_size = 512; + + /** Set the maximum attachments and inline images files size + * that can be downloaded in byte. + * The file which its size is largger than this limit may be saved + * as truncated file. + */ + imap_data.limit.attachment_size = 1024 * 1024 * 5; + + // If ID extension was supported by IMAP server, assign the client identification + // name, version, vendor, os, os_version, support_url, address, command, arguments, environment + // Server ID can be optained from imap.serverID() after calling imap.connect and imap.id. + + // imap_data.identification.name = "User"; + // imap_data.identification.version = "1.0"; + + /* Connect to the server */ + if (!imap.connect(&config, &imap_data)) + return; + + if (imap.isAuthenticated()) + Serial.println("\nSuccessfully logged in."); + else + Serial.println("\nConnected with no Auth."); + + // Client identification can be sent to server later with + /** + * IMAP_Identification iden; + * iden.name = "user"; + * iden.version = "1.0"; + * + * if (imap.id(&iden)) + * { + * Serial.println("\nSend Identification success"); + * Serial.println(imap.serverID()); + * } + * else + * MailClient.printf("nIdentification sending error, Error Code: %d, Reason: %s", imap.errorCode(), imap.errorReason().c_str()); + */ + + /* {Optional} */ + printAllMailboxesInfo(imap); + + /* Open or select the mailbox folder to read or search the message */ + if (!imap.selectFolder(F("INBOX"))) + return; + + /* {Optional} */ + printSelectedMailboxInfo(imap.selectedFolder()); + + Serial.println("::::::::::::::::: Reading Emails using the UIDs ranges ::::::::::::::::"); + readEmailsUIDS(); + + Serial.println("::::::::::: Reading Emails using the message numbers ranges :::::::::::"); + readEmailsNumbers(); +} + +void loop() +{ +} + +/* Callback function to get the Email reading status */ +void imapCallback(IMAP_Status status) +{ + /* Print the current status */ + Serial.println(status.info()); + + /* Show the result when reading finished */ + if (status.success()) + { + /* Print the result */ + /* Get the message list from the message list data */ + IMAP_MSG_List msgList = imap.data(); + printMessages(msgList.msgItems, imap.headerOnly()); + + /* Clear all stored data in IMAPSession object */ + imap.empty(); + } +} + +void printAllMailboxesInfo(IMAPSession &imap) +{ + /* Declare the folder collection class to get the list of mailbox folders */ + FoldersCollection folders; + + /* Get the mailbox folders */ + if (imap.getFolders(folders)) + { + for (size_t i = 0; i < folders.size(); i++) + { + /* Iterate each folder info using the folder info item data */ + FolderInfo folderInfo = folders.info(i); + MailClient.printf("%s%s%s", i == 0 ? "\nAvailable folders: " : ", ", folderInfo.name, i == folders.size() - 1 ? "\n" : ""); + } + } +} + +void printSelectedMailboxInfo(SelectedFolderInfo sFolder) +{ + /* Show the mailbox info */ + MailClient.printf("\nInfo of the selected folder\nTotal Messages: %d\n", sFolder.msgCount()); + MailClient.printf("UID Validity: %d\n", sFolder.uidValidity()); + MailClient.printf("Predicted next UID: %d\n", sFolder.nextUID()); + if (sFolder.unseenIndex() > 0) + MailClient.printf("First Unseen Message Number: %d\n", sFolder.unseenIndex()); + else + MailClient.printf("Unseen Messages: No\n"); + + if (sFolder.modSeqSupported()) + MailClient.printf("Highest Modification Sequence: %llu\n", sFolder.highestModSeq()); + for (size_t i = 0; i < sFolder.flagCount(); i++) + MailClient.printf("%s%s%s", i == 0 ? "Flags: " : ", ", sFolder.flag(i).c_str(), i == sFolder.flagCount() - 1 ? "\n" : ""); + + if (sFolder.flagCount(true)) + { + for (size_t i = 0; i < sFolder.flagCount(true); i++) + MailClient.printf("%s%s%s", i == 0 ? "Permanent Flags: " : ", ", sFolder.flag(i, true).c_str(), i == sFolder.flagCount(true) - 1 ? "\n" : ""); + } +} + +void printAttacements(std::vector &atts) +{ + MailClient.printf("Attachment: %d file(s)\n****************************\n", atts.size()); + for (size_t j = 0; j < atts.size(); j++) + { + IMAP_Attach_Item att = atts[j]; + /** att.type can be + * esp_mail_att_type_none or 0 + * esp_mail_att_type_attachment or 1 + * esp_mail_att_type_inline or 2 + */ + MailClient.printf("%d. Filename: %s, Name: %s, Size: %d, MIME: %s, Type: %s, Description: %s, Creation Date: %s\n", j + 1, att.filename, att.name, att.size, att.mime, att.type == esp_mail_att_type_attachment ? "attachment" : "inline", att.description, att.creationDate); + } + Serial.println(); +} + +void printMessages(std::vector &msgItems, bool headerOnly) +{ + + /** In devices other than ESP8266 and ESP32, if SD card was chosen as filestorage and + * the standard SD.h library included in ESP_Mail_FS.h, files will be renamed due to long filename + * (> 13 characters) is not support in the SD.h library. + * To show how its original file name, use imap.fileList(). + */ + // Serial.println(imap.fileList()); + + for (size_t i = 0; i < msgItems.size(); i++) + { + + /* Iterate to get each message data through the message item data */ + IMAP_MSG_Item msg = msgItems[i]; + + Serial.println("****************************"); + MailClient.printf("Number: %d\n", msg.msgNo); + MailClient.printf("UID: %d\n", msg.UID); + + // The attachment status in search may be true in case the "multipart/mixed" + // content type header was set with no real attachtment included. + MailClient.printf("Attachment: %s\n", msg.hasAttachment ? "yes" : "no"); + + MailClient.printf("Messsage-ID: %s\n", msg.ID); + + if (strlen(msg.flags)) + MailClient.printf("Flags: %s\n", msg.flags); + if (strlen(msg.acceptLang)) + MailClient.printf("Accept Language: %s\n", msg.acceptLang); + if (strlen(msg.contentLang)) + MailClient.printf("Content Language: %s\n", msg.contentLang); + if (strlen(msg.from)) + MailClient.printf("From: %s\n", msg.from); + if (strlen(msg.sender)) + MailClient.printf("Sender: %s\n", msg.sender); + if (strlen(msg.to)) + MailClient.printf("To: %s\n", msg.to); + if (strlen(msg.cc)) + MailClient.printf("CC: %s\n", msg.cc); + if (strlen(msg.bcc)) + MailClient.printf("BCC: %s\n", msg.bcc); + if (strlen(msg.date)) + { + MailClient.printf("Date: %s\n", msg.date); + MailClient.printf("Timestamp: %d\n", (int)MailClient.Time.getTimestamp(msg.date)); + } + if (strlen(msg.subject)) + MailClient.printf("Subject: %s\n", msg.subject); + if (strlen(msg.reply_to)) + MailClient.printf("Reply-To: %s\n", msg.reply_to); + if (strlen(msg.return_path)) + MailClient.printf("Return-Path: %s\n", msg.return_path); + if (strlen(msg.in_reply_to)) + MailClient.printf("In-Reply-To: %s\n", msg.in_reply_to); + if (strlen(msg.references)) + MailClient.printf("References: %s\n", msg.references); + if (strlen(msg.comments)) + MailClient.printf("Comments: %s\n", msg.comments); + if (strlen(msg.keywords)) + MailClient.printf("Keywords: %s\n", msg.keywords); + + /* If the result contains the message info (Fetch mode) */ + if (!headerOnly) + { + if (strlen(msg.text.content)) + MailClient.printf("Text Message: %s\n", msg.text.content); + if (strlen(msg.text.charSet)) + MailClient.printf("Text Message Charset: %s\n", msg.text.charSet); + if (strlen(msg.text.transfer_encoding)) + MailClient.printf("Text Message Transfer Encoding: %s\n", msg.text.transfer_encoding); + if (strlen(msg.html.content)) + MailClient.printf("HTML Message: %s\n", msg.html.content); + if (strlen(msg.html.charSet)) + MailClient.printf("HTML Message Charset: %s\n", msg.html.charSet); + if (strlen(msg.html.transfer_encoding)) + MailClient.printf("HTML Message Transfer Encoding: %s\n\n", msg.html.transfer_encoding); + + if (msg.rfc822.size() > 0) + { + MailClient.printf("\r\nRFC822 Messages: %d message(s)\n****************************\n", msg.rfc822.size()); + printMessages(msg.rfc822, headerOnly); + } + + if (msg.attachments.size() > 0) + printAttacements(msg.attachments); + } + + Serial.println(); + } +} diff --git a/lib/libesp32/ESP-Mail-Client/examples/IMAP/Read_Single_Email/Read_Single_Email.ino b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Read_Single_Email/Read_Single_Email.ino new file mode 100644 index 000000000..c8533ed92 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Read_Single_Email/Read_Single_Email.ino @@ -0,0 +1,516 @@ +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt +*/ + +// This example shows how to read Email and store the message in SD card. + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +/** Assign SD card type and FS used in src/ESP_Mail_FS.h and + * change the config for that card interfaces in src/extras/SDHelper.h + */ + +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +#include + +// Provide the SD card interfaces setting and mounting +#include + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +/** For Gmail, IMAP option should be enabled. https://support.google.com/mail/answer/7126229?hl=en + * and also https://accounts.google.com/b/0/DisplayUnlockCaptcha + * + * Some Gmail user still not able to sign in using account password even above options were set up, + * for this case, use "App Password" to sign in instead. + * About Gmail "App Password", go to https://support.google.com/accounts/answer/185833?hl=en + * + * For Yahoo mail, log in to your yahoo mail in web browser and generate app password by go to + * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc + * + * To use Gmai and Yahoo's App Password to sign in, define the AUTHOR_PASSWORD with your App Password + * and AUTHOR_EMAIL with your account email. + */ + +/* The imap host name e.g. imap.gmail.com for GMail or outlook.office365.com for Outlook */ +#define IMAP_HOST "" + +/** The imap port e.g. + * 143 or esp_mail_imap_port_143 + * 993 or esp_mail_imap_port_993 + */ +#define IMAP_PORT 993 + +/* The log in credentials */ +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" + +/* Callback function to get the Email reading status */ +void imapCallback(IMAP_Status status); + +/* Print the list of mailbox folders */ +void printAllMailboxesInfo(IMAPSession &imap); + +/* Print the selected folder info */ +void printSelectedMailboxInfo(SelectedFolderInfo sFolder); + +/* Print all messages from the message list */ +void printMessages(std::vector &msgItems, bool headerOnly); + +/* Print all attachments info from the message */ +void printAttacements(std::vector &atts); + +/* Declare the global used IMAPSession object for IMAP transport */ +IMAPSession imap; + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) +WiFiMulti multi; +#endif + +void setup() +{ + + Serial.begin(115200); + +#if defined(ARDUINO_ARCH_SAMD) + while (!Serial) + ; +#endif + + Serial.println(); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + multi.addAP(WIFI_SSID, WIFI_PASSWORD); + multi.run(); +#else + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Connecting to Wi-Fi"); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + unsigned long ms = millis(); +#endif + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + if (millis() - ms > 10000) + break; +#endif + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + /* Set the network reconnection option */ + MailClient.networkReconnect(true); + + // The WiFi credentials are required for Pico W + // due to it does not have reconnect feature. +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + MailClient.clearAP(); + MailClient.addAP(WIFI_SSID, WIFI_PASSWORD); +#endif + +#if defined(ESP_MAIL_DEFAULT_SD_FS) // defined in src/ESP_Mail_FS.h + // Mount SD card. + SD_Card_Mounting(); // See src/extras/SDHelper.h +#endif + + /** Enable the debug via Serial port + * 0 for no debugging + * 1 for basic level debugging + * + * Debug port can be changed via ESP_MAIL_DEFAULT_DEBUG_PORT in ESP_Mail_FS.h + */ + imap.debug(1); + + /* Set the callback function to get the reading results */ + imap.callback(imapCallback); + + /** In case the SD card/adapter was used for the file storagge, the SPI pins can be configure from + * MailClient.sdBegin function which may be different for ESP32 and ESP8266 + * For ESP32, assign all of SPI pins + * MailClient.sdBegin(14,2,15,13) + * Which SCK = 14, MISO = 2, MOSI = 15 and SS = 13 + * And for ESP8266, assign the CS pins of SPI port + * MailClient.sdBegin(15) + * Which pin 15 is the CS pin of SD card adapter + */ + + /* Declare the Session_Config for user defined session credentials */ + Session_Config config; + + /* Set the session config */ + config.server.host_name = IMAP_HOST; + config.server.port = IMAP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + + /* Define the IMAP_Data object used for user defined IMAP operating options. */ + IMAP_Data imap_data; + + /* Set the storage to save the downloaded files and attachments */ + imap_data.storage.saved_path = F("/email_data"); + + /** The file storage type e.g. + * esp_mail_file_storage_type_none, + * esp_mail_file_storage_type_flash, and + * esp_mail_file_storage_type_sd + */ + imap_data.storage.type = esp_mail_file_storage_type_sd; + + /** Set to download headers, text and html messaeges, + * attachments and inline images respectively. + */ + imap_data.download.header = true; + imap_data.download.text = true; + imap_data.download.html = true; + imap_data.download.attachment = true; + imap_data.download.inlineImg = true; + + /** Set to enable the results i.e. html and text messaeges + * which the content stored in the IMAPSession object is limited + * by the option imap_data.limit.msg_size. + * The whole message can be download through imap_data.download.text + * or imap_data.download.html which not depends on these enable options. + */ + imap_data.enable.html = true; + imap_data.enable.text = true; + + /* Set to enable the sort the result by message UID in the decending order */ + imap_data.enable.recent_sort = true; + + /* Set to report the download progress via the default serial port */ + imap_data.enable.download_status = true; + + /* Header fields parsing is case insensitive by default to avoid uppercase header in some server e.g. iCloud + , to allow case sensitive parse, uncomment below line*/ + // imap_data.enable.header_case_sensitive = true; + + /* Set the limit of number of messages in the search results */ + imap_data.limit.search = 5; + + /** Set the maximum size of message stored in + * IMAPSession object in byte + */ + imap_data.limit.msg_size = 512; + + /** Set the maximum attachments and inline images files size + * that can be downloaded in byte. + * The file which its size is largger than this limit may be saved + * as truncated file. + */ + imap_data.limit.attachment_size = 1024 * 1024 * 5; + + // If ID extension was supported by IMAP server, assign the client identification + // name, version, vendor, os, os_version, support_url, address, command, arguments, environment + // Server ID can be optained from imap.serverID() after calling imap.connect and imap.id. + + // imap_data.identification.name = "User"; + // imap_data.identification.version = "1.0"; + + /* Set the TCP response read timeout in seconds */ + // imap.setTCPTimeout(10); + + /* Connect to the server */ + if (!imap.connect(&config, &imap_data)) + return; + + /** Or connect without log in and log in later + + if (!imap.connect(&config, &imap_data, false)) + return; + + if (!imap.loginWithPassword(AUTHOR_EMAIL, AUTHOR_PASSWORD)) + return; + */ + + // Client identification can be sent to server later with + /** + * IMAP_Identification iden; + * iden.name = "user"; + * iden.version = "1.0"; + * + * if (imap.id(&iden)) + * { + * Serial.println("\nSend Identification success"); + * Serial.println(imap.serverID()); + * } + * else + * MailClient.printf("nIdentification sending error, Error Code: %d, Reason: %s", imap.errorCode(), imap.errorReason().c_str()); + */ + + if (!imap.isLoggedIn()) + { + Serial.println("\nNot yet logged in."); + } + else + { + if (imap.isAuthenticated()) + Serial.println("\nSuccessfully logged in."); + else + Serial.println("\nConnected with no Auth."); + } + + /* {Optional} */ + printAllMailboxesInfo(imap); + + /* Open or select the mailbox folder to read or search the message */ + if (!imap.selectFolder(F("INBOX"))) + return; + + /* {Optional} */ + printSelectedMailboxInfo(imap.selectedFolder()); + + /** Message UID to fetch or read e.g. 100. + * In this case we will get the UID from the max message number (lastest message) + */ + imap_data.fetch.uid = imap.getUID(imap.selectedFolder().msgCount()); + + // if IMAP server supports CONDSTORE extension, the modification sequence can be assign to fetch command + // Note that modsequence value supports in this library is 32-bit integer + imap_data.fetch.modsequence = 123; + + // To fetch only header part + // imap_data.fetch.headerOnly = true; + + // or fetch via the message sequence number + // imap_data.fetch.number = imap.selectedFolder().msgCount(); + + // if both imap_data.fetch.uid and imap_data.fetch.number were set, + // then total 2 messages will be fetched i.e. one using uid and other using number. + + /* Set seen flag */ + + // The message with "Seen" flagged means the message was already read or seen by user. + // The default value of this option is set to false. + // If you want to set the message flag as "Seen", set this option to true. + // If this option is false, the message flag was unchanged. + // To set or remove flag from message, see Set_Flags.ino example. + + // imap_data.fetch.set_seen = true; + + /* Fetch or read only message header */ + // imap_data.fetch.headerOnly = true; + + /* Read or search the Email and close the session */ + + // When message was fetched or read, the /Seen flag will not set or message remained in unseen or unread status, + // as this is the purpose of library (not UI application), user can set the message status as read by set \Seen flag + // to message, see the Set_Flags.ino example. + MailClient.readMail(&imap); + + /* Clear all stored data in IMAPSession object */ + imap.empty(); +} + +void loop() +{ +} + +/* Callback function to get the Email reading status */ +void imapCallback(IMAP_Status status) +{ + /* Print the current status */ + Serial.println(status.info()); + + /* Show the result when reading finished */ + if (status.success()) + { + /* Print the result */ + /* Get the message list from the message list data */ + IMAP_MSG_List msgList = imap.data(); + printMessages(msgList.msgItems, imap.headerOnly()); + + /* Clear all stored data in IMAPSession object */ + imap.empty(); + } +} + +void printAllMailboxesInfo(IMAPSession &imap) +{ + /* Declare the folder collection class to get the list of mailbox folders */ + FoldersCollection folders; + + /* Get the mailbox folders */ + if (imap.getFolders(folders)) + { + for (size_t i = 0; i < folders.size(); i++) + { + /* Iterate each folder info using the folder info item data */ + FolderInfo folderInfo = folders.info(i); + MailClient.printf("%s%s%s", i == 0 ? "\nAvailable folders: " : ", ", folderInfo.name, i == folders.size() - 1 ? "\n" : ""); + } + } +} + +void printSelectedMailboxInfo(SelectedFolderInfo sFolder) +{ + /* Show the mailbox info */ + MailClient.printf("\nInfo of the selected folder\nTotal Messages: %d\n", sFolder.msgCount()); + MailClient.printf("UID Validity: %d\n", sFolder.uidValidity()); + MailClient.printf("Predicted next UID: %d\n", sFolder.nextUID()); + if (sFolder.unseenIndex() > 0) + MailClient.printf("First Unseen Message Number: %d\n", sFolder.unseenIndex()); + else + MailClient.printf("Unseen Messages: No\n"); + + if (sFolder.modSeqSupported()) + MailClient.printf("Highest Modification Sequence: %llu\n", sFolder.highestModSeq()); + for (size_t i = 0; i < sFolder.flagCount(); i++) + MailClient.printf("%s%s%s", i == 0 ? "Flags: " : ", ", sFolder.flag(i).c_str(), i == sFolder.flagCount() - 1 ? "\n" : ""); + + if (sFolder.flagCount(true)) + { + for (size_t i = 0; i < sFolder.flagCount(true); i++) + MailClient.printf("%s%s%s", i == 0 ? "Permanent Flags: " : ", ", sFolder.flag(i, true).c_str(), i == sFolder.flagCount(true) - 1 ? "\n" : ""); + } +} + +void printAttacements(std::vector &atts) +{ + MailClient.printf("Attachment: %d file(s)\n****************************\n", atts.size()); + for (size_t j = 0; j < atts.size(); j++) + { + IMAP_Attach_Item att = atts[j]; + /** att.type can be + * esp_mail_att_type_none or 0 + * esp_mail_att_type_attachment or 1 + * esp_mail_att_type_inline or 2 + */ + MailClient.printf("%d. Filename: %s, Name: %s, Size: %d, MIME: %s, Type: %s, Description: %s, Creation Date: %s\n", j + 1, att.filename, att.name, att.size, att.mime, att.type == esp_mail_att_type_attachment ? "attachment" : "inline", att.description, att.creationDate); + } + Serial.println(); +} + +void printMessages(std::vector &msgItems, bool headerOnly) +{ + + /** In devices other than ESP8266 and ESP32, if SD card was chosen as filestorage and + * the standard SD.h library included in ESP_Mail_FS.h, files will be renamed due to long filename + * (> 13 characters) is not support in the SD.h library. + * To show how its original file name, use imap.fileList(). + */ + // Serial.println(imap.fileList()); + + for (size_t i = 0; i < msgItems.size(); i++) + { + + /* Iterate to get each message data through the message item data */ + IMAP_MSG_Item msg = msgItems[i]; + + Serial.println("****************************"); + MailClient.printf("Number: %d\n", msg.msgNo); + MailClient.printf("UID: %d\n", msg.UID); + + // The attachment status in search may be true in case the "multipart/mixed" + // content type header was set with no real attachtment included. + MailClient.printf("Attachment: %s\n", msg.hasAttachment ? "yes" : "no"); + + MailClient.printf("Messsage-ID: %s\n", msg.ID); + + if (strlen(msg.flags)) + MailClient.printf("Flags: %s\n", msg.flags); + if (strlen(msg.acceptLang)) + MailClient.printf("Accept Language: %s\n", msg.acceptLang); + if (strlen(msg.contentLang)) + MailClient.printf("Content Language: %s\n", msg.contentLang); + if (strlen(msg.from)) + MailClient.printf("From: %s\n", msg.from); + if (strlen(msg.sender)) + MailClient.printf("Sender: %s\n", msg.sender); + if (strlen(msg.to)) + MailClient.printf("To: %s\n", msg.to); + if (strlen(msg.cc)) + MailClient.printf("CC: %s\n", msg.cc); + if (strlen(msg.bcc)) + MailClient.printf("BCC: %s\n", msg.bcc); + if (strlen(msg.date)) + { + MailClient.printf("Date: %s\n", msg.date); + MailClient.printf("Timestamp: %d\n", (int)MailClient.Time.getTimestamp(msg.date)); + } + if (strlen(msg.subject)) + MailClient.printf("Subject: %s\n", msg.subject); + if (strlen(msg.reply_to)) + MailClient.printf("Reply-To: %s\n", msg.reply_to); + if (strlen(msg.return_path)) + MailClient.printf("Return-Path: %s\n", msg.return_path); + if (strlen(msg.in_reply_to)) + MailClient.printf("In-Reply-To: %s\n", msg.in_reply_to); + if (strlen(msg.references)) + MailClient.printf("References: %s\n", msg.references); + if (strlen(msg.comments)) + MailClient.printf("Comments: %s\n", msg.comments); + if (strlen(msg.keywords)) + MailClient.printf("Keywords: %s\n", msg.keywords); + + /* If the result contains the message info (Fetch mode) */ + if (!headerOnly) + { + if (strlen(msg.text.content)) + MailClient.printf("Text Message: %s\n", msg.text.content); + if (strlen(msg.text.charSet)) + MailClient.printf("Text Message Charset: %s\n", msg.text.charSet); + if (strlen(msg.text.transfer_encoding)) + MailClient.printf("Text Message Transfer Encoding: %s\n", msg.text.transfer_encoding); + if (strlen(msg.html.content)) + MailClient.printf("HTML Message: %s\n", msg.html.content); + if (strlen(msg.html.charSet)) + MailClient.printf("HTML Message Charset: %s\n", msg.html.charSet); + if (strlen(msg.html.transfer_encoding)) + MailClient.printf("HTML Message Transfer Encoding: %s\n\n", msg.html.transfer_encoding); + + if (msg.rfc822.size() > 0) + { + MailClient.printf("\r\nRFC822 Messages: %d message(s)\n****************************\n", msg.rfc822.size()); + printMessages(msg.rfc822, headerOnly); + } + + if (msg.attachments.size() > 0) + printAttacements(msg.attachments); + } + + Serial.println(); + } +} diff --git a/lib/libesp32/ESP-Mail-Client/examples/IMAP/Read_Single_Email_Loop/Read_Single_Email_Loop.ino b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Read_Single_Email_Loop/Read_Single_Email_Loop.ino new file mode 100644 index 000000000..96d1d5568 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Read_Single_Email_Loop/Read_Single_Email_Loop.ino @@ -0,0 +1,561 @@ +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt +*/ + +// This example shows how to read Email repeatedly. + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +/** For ESP8266, with BearSSL WiFi Client + * The memory reserved for completed valid SSL response from IMAP is 16 kbytes which + * may cause your device out of memory reset in case the memory + * allocation error. + */ + +/** Assign SD card type and FS used in src/ESP_Mail_FS.h and + * change the config for that card interfaces in src/extras/SDHelper.h + */ + +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +#include + +// Provide the SD card interfaces setting and mounting +#include + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +/** For Gmail, IMAP option should be enabled. https://support.google.com/mail/answer/7126229?hl=en + * and also https://accounts.google.com/b/0/DisplayUnlockCaptcha + * + * Some Gmail user still not able to sign in using account password even above options were set up, + * for this case, use "App Password" to sign in instead. + * About Gmail "App Password", go to https://support.google.com/accounts/answer/185833?hl=en + * + * For Yahoo mail, log in to your yahoo mail in web browser and generate app password by go to + * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc + * + * To use Gmai and Yahoo's App Password to sign in, define the AUTHOR_PASSWORD with your App Password + * and AUTHOR_EMAIL with your account email. + */ + +/* The imap host name e.g. imap.gmail.com for GMail or outlook.office365.com for Outlook */ +#define IMAP_HOST "" + +/** The imap port e.g. + * 143 or esp_mail_imap_port_143 + * 993 or esp_mail_imap_port_993 + */ +#define IMAP_PORT 993 + +/* The log in credentials */ +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" + +/* Callback function to get the Email reading status */ +void imapCallback(IMAP_Status status); + +/* Print the list of mailbox folders */ +void printAllMailboxesInfo(IMAPSession &imap); + +/* Print the selected folder info */ +void printSelectedMailboxInfo(SelectedFolderInfo sFolder); + +/* Print all messages from the message list */ +void printMessages(std::vector &msgItems, bool headerOnly); + +/* Print all attachments info from the message */ +void printAttacements(std::vector &atts); + +/* Declare the global used IMAPSession object for IMAP transport */ +IMAPSession imap; + +unsigned long readMillis = 0; +int totalMessage = 0; +int msgNum = 0; +int sign = -1; + +/* Declare the global used Session_Config for user defined session credentials */ +Session_Config config; + +/* Define the IMAP_Data object used for user defined IMAP operating options. */ +IMAP_Data imap_data; + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) +WiFiMulti multi; +#endif + +// For Free Heap checking +#include "HeapStat.h" +HeapStat heapInfo; + +void setup() +{ + + Serial.begin(115200); + +#if defined(ARDUINO_ARCH_SAMD) + while (!Serial) + ; +#endif + + Serial.println(); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + multi.addAP(WIFI_SSID, WIFI_PASSWORD); + multi.run(); +#else + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Connecting to Wi-Fi"); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + unsigned long ms = millis(); +#endif + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + if (millis() - ms > 10000) + break; +#endif + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + /* Set the network reconnection option */ + MailClient.networkReconnect(true); + + // The WiFi credentials are required for Pico W + // due to it does not have reconnect feature. +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + MailClient.clearAP(); + MailClient.addAP(WIFI_SSID, WIFI_PASSWORD); +#endif + +#if defined(ESP_MAIL_DEFAULT_SD_FS) // defined in src/ESP_Mail_FS.h + // Mount SD card. + SD_Card_Mounting(); // See src/extras/SDHelper.h +#endif + + /** Enable the debug via Serial port + * 0 for no debugging + * 1 for basic level debugging + * + * Debug port can be changed via ESP_MAIL_DEFAULT_DEBUG_PORT in ESP_Mail_FS.h + */ + imap.debug(1); + + /* Set the callback function to get the reading results */ + imap.callback(imapCallback); + + /** In case the SD card/adapter was used for the file storagge, the SPI pins can be configure from + * MailClient.sdBegin function which may be different for ESP32 and ESP8266 + * For ESP32, assign all of SPI pins + * MailClient.sdBegin(14,2,15,13) + * Which SCK = 14, MISO = 2, MOSI = 15 and SS = 13 + * And for ESP8266, assign the CS pins of SPI port + * MailClient.sdBegin(15) + * Which pin 15 is the CS pin of SD card adapter + */ + + /* Set the session config */ + config.server.host_name = IMAP_HOST; + config.server.port = IMAP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + + /* Message UID to fetch or read */ + imap_data.fetch.uid.clear(); + + /* Search criteria */ + imap_data.search.criteria.clear(); + + /* Also search the unseen message */ + imap_data.search.unseen_msg = true; + + /* Set the storage to save the downloaded files and attachments */ + imap_data.storage.saved_path = F("/email_data"); + + /** The file storage type e.g. + * esp_mail_file_storage_type_none, + * esp_mail_file_storage_type_flash, and + * esp_mail_file_storage_type_sd + */ + imap_data.storage.type = esp_mail_file_storage_type_sd; + + /** Set to download headers, text and html messaeges, + * attachments and inline images respectively. + */ + imap_data.download.header = false; + imap_data.download.text = false; + imap_data.download.html = false; + imap_data.download.attachment = false; + imap_data.download.inlineImg = false; + + /** Set to enable the results i.e. html and text messaeges + * which the content stored in the IMAPSession object is limited + * by the option imap_data.limit.msg_size. + * The whole message can be download through imap_data.download.text + * or imap_data.download.html which not depends on these enable options. + */ + imap_data.enable.html = true; + imap_data.enable.text = true; + + /* Set to enable the sort the result by message UID in the decending order */ + imap_data.enable.recent_sort = true; + + /* Set to report the download progress via the default serial port */ + imap_data.enable.download_status = true; + + /* Header fields parsing is case insensitive by default to avoid uppercase header in some server e.g. iCloud + , to allow case sensitive parse, uncomment below line*/ + // imap_data.enable.header_case_sensitive = true; + + /* Set the limit of number of messages in the search results */ + imap_data.limit.search = 5; + + /** Set the maximum size of message stored in + * IMAPSession object in byte + */ + imap_data.limit.msg_size = 512; + + /** Set the maximum attachments and inline images files size + * that can be downloaded in byte. + * The file which its size is largger than this limit may be saved + * as truncated file. + */ + imap_data.limit.attachment_size = 1024 * 1024 * 5; + + // If ID extension was supported by IMAP server, assign the client identification + // name, version, vendor, os, os_version, support_url, address, command, arguments, environment + // Server ID can be optained from imap.serverID() after calling imap.connect and imap.id. + + // imap_data.identification.name = "User"; + // imap_data.identification.version = "1.0"; + + /* Set the TCP response read timeout in seconds */ + // imap.setTCPTimeout(10); + + /* Connect to the server */ + if (!imap.connect(&config, &imap_data)) + return; + + // Client identification can be sent to server later with + /** + * IMAP_Identification iden; + * iden.name = "user"; + * iden.version = "1.0"; + * + * if (imap.id(&iden)) + * { + * Serial.println("\nSend Identification success"); + * Serial.println(imap.serverID()); + * } + * else + * MailClient.printf("nIdentification sending error, Error Code: %d, Reason: %s", imap.errorCode(), imap.errorReason().c_str()); + */ + + if (!imap.isLoggedIn()) + { + Serial.println("\nNot yet logged in."); + } + else + { + if (imap.isAuthenticated()) + Serial.println("\nSuccessfully logged in."); + else + Serial.println("\nConnected with no Auth."); + } + + /* {Optional} */ + printAllMailboxesInfo(imap); + + /* Open or select the mailbox folder to read or search the message */ + if (!imap.selectFolder(F("INBOX"))) + return; + + /* {Optional} */ + printSelectedMailboxInfo(imap.selectedFolder()); + + totalMessage = imap.selectedFolder().msgCount(); + + /* Start fetch from last message */ + msgNum = totalMessage; + sign = -1; // count down + + /* To start fetch from first message */ + // msgNum = 1; + // sign = 1;// count up +} + +void loop() +{ + if (millis() - readMillis > 10000 || readMillis == 0) + { + readMillis = millis(); + + // If session was closed, reconnect and re-select the mailbox + if (!imap.connected()) + { + if (!imap.connect(&config, &imap_data)) + return; + + if (!imap.selectFolder(F("INBOX"))) + return; + + if (totalMessage == 0) + { + totalMessage = imap.selectedFolder().msgCount(); + msgNum = totalMessage; + sign = -1; + } + } + + if (msgNum <= 0) + { + msgNum = 1; + sign = 1; + } + else if (msgNum >= totalMessage) + { + msgNum = totalMessage; + sign = -1; + } + + /* Message number to fetch or read */ + imap_data.fetch.number = msgNum; + + /* Set seen flag */ + // imap_data.fetch.set_seen = true; + + /* Fetch or read only message header */ + // imap_data.fetch.headerOnly = true; + + /** Read or search the Email and keep the TCP session to open + * The second parameter is for close the session. + */ + + // When message was fetched or read, the /Seen flag will not set or message remained in unseen or unread status, + // as this is the purpose of library (not UI application), user can set the message status as read by set \Seen flag + // to message, see the Set_Flags.ino example. + if (MailClient.readMail(&imap, false)) + msgNum += sign; + + /* Clear all stored data in IMAPSession object */ + imap.empty(); + + msgNum += sign; + } +} + +/* Callback function to get the Email reading status */ +void imapCallback(IMAP_Status status) +{ + /* Print the current status */ + Serial.println(status.info()); + + /* Show the result when reading finished */ + if (status.success()) + { + /* Print the result */ + /* Get the message list from the message list data */ + IMAP_MSG_List msgList = imap.data(); + printMessages(msgList.msgItems, imap.headerOnly()); + + /* Clear all stored data in IMAPSession object */ + imap.empty(); + + // Collect memory info + heapInfo.collect(); + + // Print memory info + heapInfo.print(); + } +} + +void printAllMailboxesInfo(IMAPSession &imap) +{ + /* Declare the folder collection class to get the list of mailbox folders */ + FoldersCollection folders; + + /* Get the mailbox folders */ + if (imap.getFolders(folders)) + { + for (size_t i = 0; i < folders.size(); i++) + { + /* Iterate each folder info using the folder info item data */ + FolderInfo folderInfo = folders.info(i); + MailClient.printf("%s%s%s", i == 0 ? "\nAvailable folders: " : ", ", folderInfo.name, i == folders.size() - 1 ? "\n" : ""); + } + } +} + +void printSelectedMailboxInfo(SelectedFolderInfo sFolder) +{ + /* Show the mailbox info */ + MailClient.printf("\nInfo of the selected folder\nTotal Messages: %d\n", sFolder.msgCount()); + MailClient.printf("UID Validity: %d\n", sFolder.uidValidity()); + MailClient.printf("Predicted next UID: %d\n", sFolder.nextUID()); + if (sFolder.unseenIndex() > 0) + MailClient.printf("First Unseen Message Number: %d\n", sFolder.unseenIndex()); + else + MailClient.printf("Unseen Messages: No\n"); + + if (sFolder.modSeqSupported()) + MailClient.printf("Highest Modification Sequence: %llu\n", sFolder.highestModSeq()); + for (size_t i = 0; i < sFolder.flagCount(); i++) + MailClient.printf("%s%s%s", i == 0 ? "Flags: " : ", ", sFolder.flag(i).c_str(), i == sFolder.flagCount() - 1 ? "\n" : ""); + + if (sFolder.flagCount(true)) + { + for (size_t i = 0; i < sFolder.flagCount(true); i++) + MailClient.printf("%s%s%s", i == 0 ? "Permanent Flags: " : ", ", sFolder.flag(i, true).c_str(), i == sFolder.flagCount(true) - 1 ? "\n" : ""); + } +} + +void printAttacements(std::vector &atts) +{ + MailClient.printf("Attachment: %d file(s)\n****************************\n", atts.size()); + for (size_t j = 0; j < atts.size(); j++) + { + IMAP_Attach_Item att = atts[j]; + /** att.type can be + * esp_mail_att_type_none or 0 + * esp_mail_att_type_attachment or 1 + * esp_mail_att_type_inline or 2 + */ + MailClient.printf("%d. Filename: %s, Name: %s, Size: %d, MIME: %s, Type: %s, Description: %s, Creation Date: %s\n", j + 1, att.filename, att.name, att.size, att.mime, att.type == esp_mail_att_type_attachment ? "attachment" : "inline", att.description, att.creationDate); + } + Serial.println(); +} + +void printMessages(std::vector &msgItems, bool headerOnly) +{ + /** In devices other than ESP8266 and ESP32, if SD card was chosen as filestorage and + * the standard SD.h library included in ESP_Mail_FS.h, files will be renamed due to long filename + * (> 13 characters) is not support in the SD.h library. + * To show how its original file name, use imap.fileList(). + */ + // Serial.println(imap.fileList()); + + for (size_t i = 0; i < msgItems.size(); i++) + { + + /* Iterate to get each message data through the message item data */ + IMAP_MSG_Item msg = msgItems[i]; + + Serial.println("****************************"); + MailClient.printf("Number: %d\n", msg.msgNo); + MailClient.printf("UID: %d\n", msg.UID); + + // The attachment status in search may be true in case the "multipart/mixed" + // content type header was set with no real attachtment included. + MailClient.printf("Attachment: %s\n", msg.hasAttachment ? "yes" : "no"); + + MailClient.printf("Messsage-ID: %s\n", msg.ID); + + if (strlen(msg.flags)) + MailClient.printf("Flags: %s\n", msg.flags); + if (strlen(msg.acceptLang)) + MailClient.printf("Accept Language: %s\n", msg.acceptLang); + if (strlen(msg.contentLang)) + MailClient.printf("Content Language: %s\n", msg.contentLang); + if (strlen(msg.from)) + MailClient.printf("From: %s\n", msg.from); + if (strlen(msg.sender)) + MailClient.printf("Sender: %s\n", msg.sender); + if (strlen(msg.to)) + MailClient.printf("To: %s\n", msg.to); + if (strlen(msg.cc)) + MailClient.printf("CC: %s\n", msg.cc); + if (strlen(msg.bcc)) + MailClient.printf("BCC: %s\n", msg.bcc); + if (strlen(msg.date)) + { + MailClient.printf("Date: %s\n", msg.date); + MailClient.printf("Timestamp: %d\n", (int)MailClient.Time.getTimestamp(msg.date)); + } + if (strlen(msg.subject)) + MailClient.printf("Subject: %s\n", msg.subject); + if (strlen(msg.reply_to)) + MailClient.printf("Reply-To: %s\n", msg.reply_to); + if (strlen(msg.return_path)) + MailClient.printf("Return-Path: %s\n", msg.return_path); + if (strlen(msg.in_reply_to)) + MailClient.printf("In-Reply-To: %s\n", msg.in_reply_to); + if (strlen(msg.references)) + MailClient.printf("References: %s\n", msg.references); + if (strlen(msg.comments)) + MailClient.printf("Comments: %s\n", msg.comments); + if (strlen(msg.keywords)) + MailClient.printf("Keywords: %s\n", msg.keywords); + + /* If the result contains the message info (Fetch mode) */ + if (!headerOnly) + { + if (strlen(msg.text.content)) + MailClient.printf("Text Message: %s\n", msg.text.content); + if (strlen(msg.text.charSet)) + MailClient.printf("Text Message Charset: %s\n", msg.text.charSet); + if (strlen(msg.text.transfer_encoding)) + MailClient.printf("Text Message Transfer Encoding: %s\n", msg.text.transfer_encoding); + if (strlen(msg.html.content)) + MailClient.printf("HTML Message: %s\n", msg.html.content); + if (strlen(msg.html.charSet)) + MailClient.printf("HTML Message Charset: %s\n", msg.html.charSet); + if (strlen(msg.html.transfer_encoding)) + MailClient.printf("HTML Message Transfer Encoding: %s\n\n", msg.html.transfer_encoding); + + if (msg.rfc822.size() > 0) + { + MailClient.printf("\r\nRFC822 Messages: %d message(s)\n****************************\n", msg.rfc822.size()); + printMessages(msg.rfc822, headerOnly); + } + + if (msg.attachments.size() > 0) + printAttacements(msg.attachments); + } + + Serial.println(); + } +} diff --git a/lib/libesp32/ESP-Mail-Client/examples/IMAP/Read_Single_Email_Loop_Silent_Mode/Read_Single_Email_Loop_Silent_Mode.ino b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Read_Single_Email_Loop_Silent_Mode/Read_Single_Email_Loop_Silent_Mode.ino new file mode 100644 index 000000000..94183bbd7 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Read_Single_Email_Loop_Silent_Mode/Read_Single_Email_Loop_Silent_Mode.ino @@ -0,0 +1,402 @@ +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt +*/ + +// This example shows how to read Email repeatedly. + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +/** + * To use library in silent mode (no debug printing and callback), please define this macro in src/ESP_Mail_FS.h. + * #define SILENT_MODE + */ + +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +#include + +#include + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +#define IMAP_HOST "" + +#define IMAP_PORT 993 + +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" + +void printImapData(IMAP_Status status); + +void printAllMailboxesInfo(IMAPSession &imap); + +void printSelectedMailboxInfo(SelectedFolderInfo sFolder); + +void printMessages(std::vector &msgItems, bool headerOnly); + +void printAttacements(std::vector &atts); + +IMAPSession imap; + +unsigned long readMillis = 0; +int totalMessage = 0; +int msgNum = 0; +int sign = -1; + +Session_Config config; + +IMAP_Data imap_data; + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) +WiFiMulti multi; +#endif + +// For Free Heap checking +#include "HeapStat.h" +HeapStat heapInfo; + +void setup() +{ + + Serial.begin(115200); + +#if defined(ARDUINO_ARCH_SAMD) + while (!Serial) + ; +#endif + + Serial.println(); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + multi.addAP(WIFI_SSID, WIFI_PASSWORD); + multi.run(); +#else + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Connecting to Wi-Fi"); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + unsigned long ms = millis(); +#endif + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + if (millis() - ms > 10000) + break; +#endif + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + MailClient.networkReconnect(true); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + MailClient.clearAP(); + MailClient.addAP(WIFI_SSID, WIFI_PASSWORD); +#endif + +#if defined(ESP_MAIL_DEFAULT_SD_FS) // defined in src/ESP_Mail_FS.h + // Mount SD card. + SD_Card_Mounting(); // See src/extras/SDHelper.h +#endif + + config.server.host_name = IMAP_HOST; + config.server.port = IMAP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + + imap_data.fetch.uid.clear(); + + imap_data.search.criteria.clear(); + + imap_data.search.unseen_msg = true; + + imap_data.storage.saved_path = F("/email_data"); + + imap_data.storage.type = esp_mail_file_storage_type_sd; + + imap_data.download.header = false; + imap_data.download.text = false; + imap_data.download.html = false; + imap_data.download.attachment = false; + imap_data.download.inlineImg = false; + + imap_data.enable.html = true; + imap_data.enable.text = true; + + imap_data.enable.recent_sort = true; + + imap_data.enable.download_status = true; + + imap_data.limit.search = 5; + + imap_data.limit.msg_size = 512; + + imap_data.limit.attachment_size = 1024 * 1024 * 5; + + if (!imap.connect(&config, &imap_data)) + { + MailClient.printf("Connection error, Error Code: %d, Reason: %s", imap.errorCode(), imap.errorReason().c_str()); + return; + } + + if (imap.isAuthenticated()) + Serial.println("\nSuccessfully logged in."); + else + Serial.println("\nConnected with no Auth."); + + printAllMailboxesInfo(imap); + + if (!imap.selectFolder(F("INBOX"))) + { + MailClient.printf("Folder selection error, Error Code: %d, Reason: %s", imap.errorCode(), imap.errorReason().c_str()); + return; + } + + printSelectedMailboxInfo(imap.selectedFolder()); + + totalMessage = imap.selectedFolder().msgCount(); + + msgNum = totalMessage; + sign = -1; // count down +} + +void loop() +{ + if (millis() - readMillis > 10000 || readMillis == 0) + { + readMillis = millis(); + + if (!imap.connected()) + { + if (!imap.connect(&config, &imap_data)) + return; + + if (!imap.selectFolder(F("INBOX"))) + return; + + if (totalMessage == 0) + { + totalMessage = imap.selectedFolder().msgCount(); + msgNum = totalMessage; + sign = -1; + } + } + + if (msgNum <= 0) + { + msgNum = 1; + sign = 1; + } + else if (msgNum >= totalMessage) + { + msgNum = totalMessage; + sign = -1; + } + + imap_data.fetch.number = msgNum; + + if (MailClient.readMail(&imap, false)) + { + printImapData(imap.status()); + } + else + { + MailClient.printf("Message reading error, Error Code: %d, Reason: %s", imap.errorCode(), imap.errorReason().c_str()); + } + + imap.empty(); + + msgNum += sign; + } +} + +void printImapData(IMAP_Status status) +{ + + if (status.success()) + { + IMAP_MSG_List msgList = imap.data(); + printMessages(msgList.msgItems, imap.headerOnly()); + + imap.empty(); + + heapInfo.collect(); + + heapInfo.print(); + + Serial.println(); + } +} + +void printAllMailboxesInfo(IMAPSession &imap) +{ + + FoldersCollection folders; + + if (imap.getFolders(folders)) + { + for (size_t i = 0; i < folders.size(); i++) + { + FolderInfo folderInfo = folders.info(i); + MailClient.printf("%s%s%s", i == 0 ? "\nAvailable folders: " : ", ", folderInfo.name, i == folders.size() - 1 ? "\n" : ""); + } + } +} + +void printSelectedMailboxInfo(SelectedFolderInfo sFolder) +{ + /* Show the mailbox info */ + MailClient.printf("\nInfo of the selected folder\nTotal Messages: %d\n", sFolder.msgCount()); + MailClient.printf("UID Validity: %d\n", sFolder.uidValidity()); + MailClient.printf("Predicted next UID: %d\n", sFolder.nextUID()); + if (sFolder.unseenIndex() > 0) + MailClient.printf("First Unseen Message Number: %d\n", sFolder.unseenIndex()); + else + MailClient.printf("Unseen Messages: No\n"); + + if (sFolder.modSeqSupported()) + MailClient.printf("Highest Modification Sequence: %llu\n", sFolder.highestModSeq()); + for (size_t i = 0; i < sFolder.flagCount(); i++) + MailClient.printf("%s%s%s", i == 0 ? "Flags: " : ", ", sFolder.flag(i).c_str(), i == sFolder.flagCount() - 1 ? "\n" : ""); + + if (sFolder.flagCount(true)) + { + for (size_t i = 0; i < sFolder.flagCount(true); i++) + MailClient.printf("%s%s%s", i == 0 ? "Permanent Flags: " : ", ", sFolder.flag(i, true).c_str(), i == sFolder.flagCount(true) - 1 ? "\n" : ""); + } +} + +void printAttacements(std::vector &atts) +{ + MailClient.printf("Attachment: %d file(s)\n****************************\n", atts.size()); + for (size_t j = 0; j < atts.size(); j++) + { + IMAP_Attach_Item att = atts[j]; + MailClient.printf("%d. Filename: %s, Name: %s, Size: %d, MIME: %s, Type: %s, Description: %s, Creation Date: %s\n", j + 1, att.filename, att.name, att.size, att.mime, att.type == esp_mail_att_type_attachment ? "attachment" : "inline", att.description, att.creationDate); + } + Serial.println(); +} + +void printMessages(std::vector &msgItems, bool headerOnly) +{ + + for (size_t i = 0; i < msgItems.size(); i++) + { + + IMAP_MSG_Item msg = msgItems[i]; + + Serial.println("****************************"); + MailClient.printf("Number: %d\n", msg.msgNo); + MailClient.printf("UID: %d\n", msg.UID); + + // The attachment status in search may be true in case the "multipart/mixed" + // content type header was set with no real attachtment included. + MailClient.printf("Attachment: %s\n", msg.hasAttachment ? "yes" : "no"); + + MailClient.printf("Messsage-ID: %s\n", msg.ID); + + if (strlen(msg.flags)) + MailClient.printf("Flags: %s\n", msg.flags); + if (strlen(msg.acceptLang)) + MailClient.printf("Accept Language: %s\n", msg.acceptLang); + if (strlen(msg.contentLang)) + MailClient.printf("Content Language: %s\n", msg.contentLang); + if (strlen(msg.from)) + MailClient.printf("From: %s\n", msg.from); + if (strlen(msg.sender)) + MailClient.printf("Sender: %s\n", msg.sender); + if (strlen(msg.to)) + MailClient.printf("To: %s\n", msg.to); + if (strlen(msg.cc)) + MailClient.printf("CC: %s\n", msg.cc); + if (strlen(msg.bcc)) + MailClient.printf("BCC: %s\n", msg.bcc); + if (strlen(msg.date)) + { + MailClient.printf("Date: %s\n", msg.date); + MailClient.printf("Timestamp: %d\n", (int)MailClient.Time.getTimestamp(msg.date)); + } + if (strlen(msg.subject)) + MailClient.printf("Subject: %s\n", msg.subject); + if (strlen(msg.reply_to)) + MailClient.printf("Reply-To: %s\n", msg.reply_to); + if (strlen(msg.return_path)) + MailClient.printf("Return-Path: %s\n", msg.return_path); + if (strlen(msg.in_reply_to)) + MailClient.printf("In-Reply-To: %s\n", msg.in_reply_to); + if (strlen(msg.references)) + MailClient.printf("References: %s\n", msg.references); + if (strlen(msg.comments)) + MailClient.printf("Comments: %s\n", msg.comments); + if (strlen(msg.keywords)) + MailClient.printf("Keywords: %s\n", msg.keywords); + + if (!headerOnly) + { + if (strlen(msg.text.content)) + MailClient.printf("Text Message: %s\n", msg.text.content); + if (strlen(msg.text.charSet)) + MailClient.printf("Text Message Charset: %s\n", msg.text.charSet); + if (strlen(msg.text.transfer_encoding)) + MailClient.printf("Text Message Transfer Encoding: %s\n", msg.text.transfer_encoding); + if (strlen(msg.html.content)) + MailClient.printf("HTML Message: %s\n", msg.html.content); + if (strlen(msg.html.charSet)) + MailClient.printf("HTML Message Charset: %s\n", msg.html.charSet); + if (strlen(msg.html.transfer_encoding)) + MailClient.printf("HTML Message Transfer Encoding: %s\n\n", msg.html.transfer_encoding); + + if (msg.rfc822.size() > 0) + { + MailClient.printf("\r\nRFC822 Messages: %d message(s)\n****************************\n", msg.rfc822.size()); + printMessages(msg.rfc822, headerOnly); + } + + if (msg.attachments.size() > 0) + printAttacements(msg.attachments); + } + + Serial.println(); + } +} diff --git a/lib/libesp32/ESP-Mail-Client/examples/IMAP/Search_And_Read/Search_And_Read.ino b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Search_And_Read/Search_And_Read.ino new file mode 100644 index 000000000..7ad828a1e --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Search_And_Read/Search_And_Read.ino @@ -0,0 +1,352 @@ +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt +*/ + +// This example shows how to search the unread messages and read them. + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +/** + * To use library in silent mode (no debug printing and callback), please define this macro in src/ESP_Mail_FS.h. + * #define SILENT_MODE + */ + +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +#include + +#include + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +#define IMAP_HOST "" + +#define IMAP_PORT 993 + +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" + +void imapCallback(IMAP_Status status); + +void printAllMailboxesInfo(IMAPSession &imap); + +void printSelectedMailboxInfo(SelectedFolderInfo sFolder); + +void printMessageData(); + +IMAPSession imap; + +Session_Config config; + +IMAP_Data imap_data; + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) +WiFiMulti multi; +#endif + +// Max messages in the search result +int max_result = 5; + +// Array to store the UID of messages in search result +int msg_uid[5]; + +void setup() +{ + + Serial.begin(115200); + +#if defined(ARDUINO_ARCH_SAMD) + while (!Serial) + ; +#endif + + Serial.println(); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + multi.addAP(WIFI_SSID, WIFI_PASSWORD); + multi.run(); +#else + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Connecting to Wi-Fi"); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + unsigned long ms = millis(); +#endif + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + if (millis() - ms > 10000) + break; +#endif + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + MailClient.networkReconnect(true); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + MailClient.clearAP(); + MailClient.addAP(WIFI_SSID, WIFI_PASSWORD); +#endif + + /** Enable the debug via Serial port + * 0 for no debugging + * 1 for basic level debugging + * + * Debug port can be changed via ESP_MAIL_DEFAULT_DEBUG_PORT in ESP_Mail_FS.h + */ + imap.debug(1); + + /* Set the callback function to get the reading results */ + imap.callback(imapCallback); + + config.server.host_name = IMAP_HOST; + config.server.port = IMAP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + + // Clear all these fetch options to perform search + imap_data.fetch.uid.clear(); + imap_data.fetch.number.clear(); + imap_data.fetch.sequence_set.string.clear(); + + imap_data.search.unseen_msg = true; + + // Don't download all to filesystem + imap_data.download.header = false; + imap_data.download.text = false; + imap_data.download.html = false; + imap_data.download.attachment = false; + imap_data.download.inlineImg = false; + + // Store html/text message body in IMAPSession object + imap_data.enable.html = true; + imap_data.enable.text = true; + + imap_data.enable.recent_sort = true; + + // Max messages in the search result + imap_data.limit.search = max_result; + + imap_data.limit.msg_size = 128; + + if (!imap.connect(&config, &imap_data)) + { + MailClient.printf("Connection error, Error Code: %d, Reason: %s", imap.errorCode(), imap.errorReason().c_str()); + return; + } + + if (imap.isAuthenticated()) + Serial.println("\nSuccessfully logged in."); + else + Serial.println("\nConnected with no Auth."); + + printAllMailboxesInfo(imap); + + if (!imap.selectFolder(F("INBOX"))) + { + MailClient.printf("Folder selection error, Error Code: %d, Reason: %s", imap.errorCode(), imap.errorReason().c_str()); + return; + } + + printSelectedMailboxInfo(imap.selectedFolder()); + + // We search the unseen messages first to get its UID and stored in msg_uid. + imap_data.search.criteria = F("SEARCH UNSEEN"); + + MailClient.readMail(&imap, false /* keep session open for fetching message in opened mailbox later */); + + // We already get the search result message, fetch it + + // Fetch the messages using UID stored in msg_uid one by one + for (int i = 0; i < max_result; i++) + { + imap_data.search.criteria.clear(); + + // Mark this message as read + MailClient.addFlag(&imap, msg_uid[i], F("\\Seen"), false /* Close session */, false /* Ignore response */); + + // Now Fech message by UID stored in msg_uid + imap_data.fetch.uid = msg_uid[i]; + + MailClient.readMail(&imap, false /* keep session open for fetching message in opened mailbox later */); + } + + imap.closeSession(); + imap.empty(); +} + +void loop() +{ +} + +void imapCallback(IMAP_Status status) +{ + Serial.println(status.info()); + + if (status.success()) + { + // If this is the search result (imap contains only header info), + // store the message UID that we can fetch for its body later. + if (imap.headerOnly()) + { + max_result = imap.data().msgItems.size(); + for (size_t i = 0; i < imap.data().msgItems.size(); i++) + msg_uid[i] = imap.data().msgItems[i].UID; + } + else + { + // This is the fetch result, print the whole message (header + body) + printMessageData(); + } + + imap.empty(); + } +} + +void printAllMailboxesInfo(IMAPSession &imap) +{ + + FoldersCollection folders; + + if (imap.getFolders(folders)) + { + for (size_t i = 0; i < folders.size(); i++) + { + FolderInfo folderInfo = folders.info(i); + MailClient.printf("%s%s%s", i == 0 ? "\nAvailable folders: " : ", ", folderInfo.name, i == folders.size() - 1 ? "\n" : ""); + } + } +} + +void printSelectedMailboxInfo(SelectedFolderInfo sFolder) +{ + /* Show the mailbox info */ + MailClient.printf("\nInfo of the selected folder\nTotal Messages: %d\n", sFolder.msgCount()); + MailClient.printf("UID Validity: %d\n", sFolder.uidValidity()); + MailClient.printf("Predicted next UID: %d\n", sFolder.nextUID()); + if (sFolder.unseenIndex() > 0) + MailClient.printf("First Unseen Message Number: %d\n", sFolder.unseenIndex()); + else + MailClient.printf("Unseen Messages: No\n"); + + if (sFolder.modSeqSupported()) + MailClient.printf("Highest Modification Sequence: %llu\n", sFolder.highestModSeq()); + for (size_t i = 0; i < sFolder.flagCount(); i++) + MailClient.printf("%s%s%s", i == 0 ? "Flags: " : ", ", sFolder.flag(i).c_str(), i == sFolder.flagCount() - 1 ? "\n" : ""); + + if (sFolder.flagCount(true)) + { + for (size_t i = 0; i < sFolder.flagCount(true); i++) + MailClient.printf("%s%s%s", i == 0 ? "Permanent Flags: " : ", ", sFolder.flag(i, true).c_str(), i == sFolder.flagCount(true) - 1 ? "\n" : ""); + } +} + +void printMessageData() +{ + + IMAP_MSG_Item msg = imap.data().msgItems[0]; // msgItems contains only one message from fetch + + Serial.println("****************************"); + + MailClient.printf("Number: %d\n", msg.msgNo); + MailClient.printf("UID: %d\n", msg.UID); + + // The attachment status in search may be true in case the "multipart/mixed" + // content type header was set with no real attachtment included. + MailClient.printf("Attachment: %s\n", msg.hasAttachment ? "yes" : "no"); + + MailClient.printf("Messsage-ID: %s\n", msg.ID); + + if (strlen(msg.flags)) + MailClient.printf("Flags: %s\n", msg.flags); + if (strlen(msg.acceptLang)) + MailClient.printf("Accept Language: %s\n", msg.acceptLang); + if (strlen(msg.contentLang)) + MailClient.printf("Content Language: %s\n", msg.contentLang); + if (strlen(msg.from)) + MailClient.printf("From: %s\n", msg.from); + if (strlen(msg.sender)) + MailClient.printf("Sender: %s\n", msg.sender); + if (strlen(msg.to)) + MailClient.printf("To: %s\n", msg.to); + if (strlen(msg.cc)) + MailClient.printf("CC: %s\n", msg.cc); + if (strlen(msg.bcc)) + MailClient.printf("BCC: %s\n", msg.bcc); + if (strlen(msg.date)) + { + MailClient.printf("Date: %s\n", msg.date); + MailClient.printf("Timestamp: %d\n", (int)MailClient.Time.getTimestamp(msg.date)); + } + if (strlen(msg.subject)) + MailClient.printf("Subject: %s\n", msg.subject); + if (strlen(msg.reply_to)) + MailClient.printf("Reply-To: %s\n", msg.reply_to); + if (strlen(msg.return_path)) + MailClient.printf("Return-Path: %s\n", msg.return_path); + if (strlen(msg.in_reply_to)) + MailClient.printf("In-Reply-To: %s\n", msg.in_reply_to); + if (strlen(msg.references)) + MailClient.printf("References: %s\n", msg.references); + if (strlen(msg.comments)) + MailClient.printf("Comments: %s\n", msg.comments); + if (strlen(msg.keywords)) + MailClient.printf("Keywords: %s\n", msg.keywords); + + if (strlen(msg.text.content)) + MailClient.printf("Text Message: %s\n", msg.text.content); + if (strlen(msg.text.charSet)) + MailClient.printf("Text Message Charset: %s\n", msg.text.charSet); + if (strlen(msg.text.transfer_encoding)) + MailClient.printf("Text Message Transfer Encoding: %s\n", msg.text.transfer_encoding); + if (strlen(msg.html.content)) + MailClient.printf("HTML Message: %s\n", msg.html.content); + if (strlen(msg.html.charSet)) + MailClient.printf("HTML Message Charset: %s\n", msg.html.charSet); + if (strlen(msg.html.transfer_encoding)) + MailClient.printf("HTML Message Transfer Encoding: %s\n\n", msg.html.transfer_encoding); + + Serial.println(); +} \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/examples/IMAP/Search_Emails/Search_Emails.ino b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Search_Emails/Search_Emails.ino new file mode 100644 index 000000000..597b25652 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Search_Emails/Search_Emails.ino @@ -0,0 +1,533 @@ +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt + */ + +// This example shows how to search all messages with the keywords in the opened mailbox folder. + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +/** For ESP8266, with BearSSL WiFi Client + * The memory reserved for completed valid SSL response from IMAP is 16 kbytes which + * may cause your device out of memory reset in case the memory + * allocation error. + */ + +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +#include + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +/** For Gmail, IMAP option should be enabled. https://support.google.com/mail/answer/7126229?hl=en + * and also https://accounts.google.com/b/0/DisplayUnlockCaptcha + * + * Some Gmail user still not able to sign in using account password even above options were set up, + * for this case, use "App Password" to sign in instead. + * About Gmail "App Password", go to https://support.google.com/accounts/answer/185833?hl=en + * + * For Yahoo mail, log in to your yahoo mail in web browser and generate app password by go to + * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc + * + * To use Gmai and Yahoo's App Password to sign in, define the AUTHOR_PASSWORD with your App Password + * and AUTHOR_EMAIL with your account email. + */ + +/* The imap host name e.g. imap.gmail.com for GMail or outlook.office365.com for Outlook */ +#define IMAP_HOST "" + +/** The imap port e.g. + * 143 or esp_mail_imap_port_143 // Plain or TLS with STARTTLS + * 993 or esp_mail_imap_port_993 + */ +#define IMAP_PORT esp_mail_imap_port_143 + +/* The log in credentials */ +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" + +/* Callback function to get the Email reading status */ +void imapCallback(IMAP_Status status); + +/* Print the list of mailbox folders */ +void printAllMailboxesInfo(IMAPSession &imap); + +/* Print the selected folder info */ +void printSelectedMailboxInfo(SelectedFolderInfo sFolder); + +/* Print all messages from the message list */ +void printMessages(std::vector &msgItems, bool headerOnly); + +/* Print all attachments info from the message */ +void printAttacements(std::vector &atts); + +/* Declare the global used IMAPSession object for IMAP transport */ +IMAPSession imap; + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) +WiFiMulti multi; +#endif + +void setup() +{ + + Serial.begin(115200); + +#if defined(ARDUINO_ARCH_SAMD) + while (!Serial) + ; +#endif + + Serial.println(); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + multi.addAP(WIFI_SSID, WIFI_PASSWORD); + multi.run(); +#else + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Connecting to Wi-Fi"); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + unsigned long ms = millis(); +#endif + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + if (millis() - ms > 10000) + break; +#endif + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + /* Set the network reconnection option */ + MailClient.networkReconnect(true); + + // The WiFi credentials are required for Pico W + // due to it does not have reconnect feature. +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + MailClient.clearAP(); + MailClient.addAP(WIFI_SSID, WIFI_PASSWORD); +#endif + + /** Enable the debug via Serial port + * 0 for no debugging + * 1 for basic level debugging + * + * Debug port can be changed via ESP_MAIL_DEFAULT_DEBUG_PORT in ESP_Mail_FS.h + */ + imap.debug(1); + + /* Set the callback function to get the reading results */ + imap.callback(imapCallback); + + /* Declare the Session_Config for user defined session credentials */ + Session_Config config; + + /** In case the SD card/adapter was used for the file storagge, the SPI pins can be configure from + * MailClient.sdBegin function which may be different for ESP32 and ESP8266 + * For ESP32, assign all of SPI pins + * MailClient.sdBegin(14,2,15,13) + * Which SCK = 14, MISO = 2, MOSI = 15 and SS = 13 + * And for ESP8266, assign the CS pins of SPI port + * MailClient.sdBegin(15) + * Which pin 15 is the CS pin of SD card adapter + */ + + /* Set the session config */ + config.server.host_name = IMAP_HOST; + config.server.port = IMAP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + + /** Declare the IMAP_Data object used for user defined IMAP operating options + * and contains the IMAP operating result + */ + IMAP_Data imap_data; + + /* We will clear fetching message UID as it used to determine the reading mode i.e., search and fetch */ + imap_data.fetch.uid.clear(); + + /** Search criteria + * + * A search key can also be a parenthesized list of one or more search keys + * (e.g., for use with the OR and NOT keys). + * + * Since IMAP protocol uses Polish notation, the search criteria which in the polish notation form can be. + * + * To search the message from "someone@email.com" with the subject "my subject" since 1 Jan 2021, your search criteria can be + * UID SEARCH (OR SUBJECT "my subject" FROM "someone@email.com") SINCE "Fri, 1 Jan 2021 21:52:25 -0800" + * + * To search the message from "mail1@domain.com" or from "mail2@domain.com", the search criteria will be + * UID SEARCH OR FROM mail1@domain.com FROM mail2@domain.com + * + * For more details on using parentheses, AND, OR and NOT search keys in search criteria. + * https://www.limilabs.com/blog/imap-search-requires-parentheses + * + *For keywords used in search criteria, see + * https://github.com/mobizt/ESP-Mail-Client/tree/master/src#search-criteria + * + * Use "SEARCH UNSEEN" for unread messages search + * Use "SEARCH RECENT" for messages with the \\RECENT flag set + * Use "ON _date_" for messages with Date header matching _date_ + * Use "BEFORE _date_" for messages with Date header before _date_ + */ + imap_data.search.criteria = F("SEARCH RECENT"); + + /* Also search the unseen message */ + imap_data.search.unseen_msg = true; + + /* Set the storage to save the downloaded files and attachments */ + imap_data.storage.saved_path = F("/email_data"); + + /** The file storage type e.g. + * esp_mail_file_storage_type_none, + * esp_mail_file_storage_type_flash, and + * esp_mail_file_storage_type_sd + */ + imap_data.storage.type = esp_mail_file_storage_type_flash; + + /** Set to download headers, text and html messaeges, + * attachments and inline images respectively. + */ + imap_data.download.header = true; + imap_data.download.text = true; + imap_data.download.html = true; + imap_data.download.attachment = true; + imap_data.download.inlineImg = true; + + /** Set to enable the results i.e. html and text messaeges + * which the content stored in the IMAPSession object is limited + * by the option imap_data.limit.msg_size. + * The whole message can be download through imap_data.download.text + * or imap_data.download.html which not depends on these enable options. + */ + imap_data.enable.html = true; + imap_data.enable.text = true; + + /* Set to enable the sort the result by message UID in the decending order */ + imap_data.enable.recent_sort = true; + + /* Set to report the download progress via the default serial port */ + imap_data.enable.download_status = true; + + /* Header fields parsing is case insensitive by default to avoid uppercase header in some server e.g. iCloud + , to allow case sensitive parse, uncomment below line*/ + // imap_data.enable.header_case_sensitive = true; + + /* Set the limit of number of messages in the search results */ + imap_data.limit.search = 5; + + /** Set the maximum size of message stored in + * IMAPSession object in byte + */ + imap_data.limit.msg_size = 512; + + /** Set the maximum attachments and inline images files size + * that can be downloaded in byte. + * The file which its size is largger than this limit may be saved + * as truncated file. + */ + imap_data.limit.attachment_size = 1024 * 1024 * 5; + + // If ID extension was supported by IMAP server, assign the client identification + // name, version, vendor, os, os_version, support_url, address, command, arguments, environment + // Server ID can be optained from imap.serverID() after calling imap.connect and imap.id. + + // imap_data.identification.name = "User"; + // imap_data.identification.version = "1.0"; + + /* Set the TCP response read timeout in seconds */ + // imap.setTCPTimeout(10); + + /* Connect to the server */ + if (!imap.connect(&config, &imap_data)) + return; + + /** Or connect without log in and log in later + + if (!imap.connect(&config, &imap_data, false)) + return; + + if (!imap.loginWithPassword(AUTHOR_EMAIL, AUTHOR_PASSWORD)) + return; + */ + + // Client identification can be sent to server later with + /** + * IMAP_Identification iden; + * iden.name = "user"; + * iden.version = "1.0"; + * + * if (imap.id(&iden)) + * { + * Serial.println("\nSend Identification success"); + * Serial.println(imap.serverID()); + * } + * else + * MailClient.printf("nIdentification sending error, Error Code: %d, Reason: %s", imap.errorCode(), imap.errorReason().c_str()); + */ + + if (!imap.isLoggedIn()) + { + Serial.println("\nNot yet logged in."); + } + else + { + if (imap.isAuthenticated()) + Serial.println("\nSuccessfully logged in."); + else + Serial.println("\nConnected with no Auth."); + } + + /* {Optional} */ + printAllMailboxesInfo(imap); + + /* Open or select the mailbox folder to read or search the message */ + if (!imap.selectFolder(F("INBOX"))) + return; + + /* {Optional} */ + printSelectedMailboxInfo(imap.selectedFolder()); + + /** Read or search the Email and keep the TCP session to open + * The second parameter is for close the session. + */ + MailClient.readMail(&imap, false); + + /* Clear all stored data in IMAPSession object */ + imap.empty(); + + /** Open or select other mailbox folder + * The folder that previousely opened will be closed + */ + if (imap.selectFolder(F("Junk"))) + { + /* {Optional} */ + printSelectedMailboxInfo(imap.selectedFolder()); + + /** Config to search all messages in the opened mailboax (Search mode) + * For keywords used in search criteria, see + * https://github.com/mobizt/ESP-Mail-Client/tree/master/src#search-criteria + */ + imap_data.search.criteria = F("SEARCH ALL"); // or "SEARCH NEW" for recent received messages + + /* We will clear fetching message UID as it used to determine the reading mode i.e., search and fetch */ + imap_data.fetch.uid.clear(); + + /* Search the Email and close the session */ + MailClient.readMail(&imap); + } + + /* Close the seeion in case the session is still open */ + imap.closeSession(); + + /* Clear all stored data in IMAPSession object */ + imap.empty(); +} + +void loop() +{ +} + +/* Callback function to get the Email reading status */ +void imapCallback(IMAP_Status status) +{ + /* Print the current status */ + Serial.println(status.info()); + + /* Show the result when reading finished */ + if (status.success()) + { + /* Print the result */ + /* Get the message list from the message list data */ + IMAP_MSG_List msgList = imap.data(); + printMessages(msgList.msgItems, imap.headerOnly()); + + /* Clear all stored data in IMAPSession object */ + imap.empty(); + } +} + +void printAllMailboxesInfo(IMAPSession &imap) +{ + /* Declare the folder collection class to get the list of mailbox folders */ + FoldersCollection folders; + + /* Get the mailbox folders */ + if (imap.getFolders(folders)) + { + for (size_t i = 0; i < folders.size(); i++) + { + /* Iterate each folder info using the folder info item data */ + FolderInfo folderInfo = folders.info(i); + MailClient.printf("%s%s%s", i == 0 ? "\nAvailable folders: " : ", ", folderInfo.name, i == folders.size() - 1 ? "\n" : ""); + } + } +} + +void printSelectedMailboxInfo(SelectedFolderInfo sFolder) +{ + /* Show the mailbox info */ + MailClient.printf("\nInfo of the selected folder\nTotal Messages: %d\n", sFolder.msgCount()); + MailClient.printf("UID Validity: %d\n", sFolder.uidValidity()); + MailClient.printf("Predicted next UID: %d\n", sFolder.nextUID()); + if (sFolder.unseenIndex() > 0) + MailClient.printf("First Unseen Message Number: %d\n", sFolder.unseenIndex()); + else + MailClient.printf("Unseen Messages: No\n"); + + if (sFolder.modSeqSupported()) + MailClient.printf("Highest Modification Sequence: %llu\n", sFolder.highestModSeq()); + for (size_t i = 0; i < sFolder.flagCount(); i++) + MailClient.printf("%s%s%s", i == 0 ? "Flags: " : ", ", sFolder.flag(i).c_str(), i == sFolder.flagCount() - 1 ? "\n" : ""); + + if (sFolder.flagCount(true)) + { + for (size_t i = 0; i < sFolder.flagCount(true); i++) + MailClient.printf("%s%s%s", i == 0 ? "Permanent Flags: " : ", ", sFolder.flag(i, true).c_str(), i == sFolder.flagCount(true) - 1 ? "\n" : ""); + } +} + +void printAttacements(std::vector &atts) +{ + MailClient.printf("Attachment: %d file(s)\n****************************\n", atts.size()); + for (size_t j = 0; j < atts.size(); j++) + { + IMAP_Attach_Item att = atts[j]; + /** att.type can be + * esp_mail_att_type_none or 0 + * esp_mail_att_type_attachment or 1 + * esp_mail_att_type_inline or 2 + */ + MailClient.printf("%d. Filename: %s, Name: %s, Size: %d, MIME: %s, Type: %s, Description: %s, Creation Date: %s\n", j + 1, att.filename, att.name, att.size, att.mime, att.type == esp_mail_att_type_attachment ? "attachment" : "inline", att.description, att.creationDate); + } + Serial.println(); +} + +void printMessages(std::vector &msgItems, bool headerOnly) +{ + + for (size_t i = 0; i < msgItems.size(); i++) + { + + /* Iterate to get each message data through the message item data */ + IMAP_MSG_Item msg = msgItems[i]; + + Serial.println("****************************"); + // Message sequence number + MailClient.printf("Number: %d\n", msg.msgNo); + // Message UID + MailClient.printf("UID: %d\n", msg.UID); + + // The attachment status in search may be true in case the "multipart/mixed" + // content type header was set with no real attachtment included. + MailClient.printf("Attachment: %s\n", msg.hasAttachment ? "yes" : "no"); + + MailClient.printf("Messsage-ID: %s\n", msg.ID); + + if (strlen(msg.flags)) + MailClient.printf("Flags: %s\n", msg.flags); + if (strlen(msg.acceptLang)) + MailClient.printf("Accept Language: %s\n", msg.acceptLang); + if (strlen(msg.contentLang)) + MailClient.printf("Content Language: %s\n", msg.contentLang); + if (strlen(msg.from)) + MailClient.printf("From: %s\n", msg.from); + if (strlen(msg.sender)) + MailClient.printf("Sender: %s\n", msg.sender); + if (strlen(msg.to)) + MailClient.printf("To: %s\n", msg.to); + if (strlen(msg.cc)) + MailClient.printf("CC: %s\n", msg.cc); + if (strlen(msg.bcc)) + MailClient.printf("BCC: %s\n", msg.bcc); + if (strlen(msg.date)) + { + MailClient.printf("Date: %s\n", msg.date); + MailClient.printf("Timestamp: %d\n", (int)MailClient.Time.getTimestamp(msg.date)); + } + if (strlen(msg.subject)) + MailClient.printf("Subject: %s\n", msg.subject); + if (strlen(msg.reply_to)) + MailClient.printf("Reply-To: %s\n", msg.reply_to); + if (strlen(msg.return_path)) + MailClient.printf("Return-Path: %s\n", msg.return_path); + if (strlen(msg.in_reply_to)) + MailClient.printf("In-Reply-To: %s\n", msg.in_reply_to); + if (strlen(msg.references)) + MailClient.printf("References: %s\n", msg.references); + if (strlen(msg.comments)) + MailClient.printf("Comments: %s\n", msg.comments); + if (strlen(msg.keywords)) + MailClient.printf("Keywords: %s\n", msg.keywords); + + /* If the result contains the message info (Fetch mode) */ + if (!headerOnly) + { + if (strlen(msg.text.content)) + MailClient.printf("Text Message: %s\n", msg.text.content); + if (strlen(msg.text.charSet)) + MailClient.printf("Text Message Charset: %s\n", msg.text.charSet); + if (strlen(msg.text.transfer_encoding)) + MailClient.printf("Text Message Transfer Encoding: %s\n", msg.text.transfer_encoding); + if (strlen(msg.html.content)) + MailClient.printf("HTML Message: %s\n", msg.html.content); + if (strlen(msg.html.charSet)) + MailClient.printf("HTML Message Charset: %s\n", msg.html.charSet); + if (strlen(msg.html.transfer_encoding)) + MailClient.printf("HTML Message Transfer Encoding: %s\n\n", msg.html.transfer_encoding); + + if (msg.rfc822.size() > 0) + { + MailClient.printf("\r\nRFC822 Messages: %d message(s)\n****************************\n", msg.rfc822.size()); + printMessages(msg.rfc822, headerOnly); + } + + if (msg.attachments.size() > 0) + printAttacements(msg.attachments); + } + + Serial.println(); + } +} diff --git a/lib/libesp32/ESP-Mail-Client/examples/IMAP/Search_Emails_Silent_Mode/Search_Emails_Silent_Mode.ino b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Search_Emails_Silent_Mode/Search_Emails_Silent_Mode.ino new file mode 100644 index 000000000..5f6367ef8 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Search_Emails_Silent_Mode/Search_Emails_Silent_Mode.ino @@ -0,0 +1,327 @@ +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt +*/ + +// This example shows how to search all messages with the keywords in the opened mailbox folder. + +/** + * To use library in silent mode (no debug printing and callback), please define this macro in src/ESP_Mail_FS.h. + * #define SILENT_MODE + */ + +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +#include + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +#define IMAP_HOST "" + +#define IMAP_PORT esp_mail_imap_port_143 + +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" + +void printImapData(IMAP_Status status); + +void printAllMailboxesInfo(IMAPSession &imap); + +void printSelectedMailboxInfo(SelectedFolderInfo sFolder); + +void printMessages(std::vector &msgItems, bool headerOnly); + +void printAttacements(std::vector &atts); + +IMAPSession imap; + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) +WiFiMulti multi; +#endif + +void setup() +{ + + Serial.begin(115200); + +#if defined(ARDUINO_ARCH_SAMD) + while (!Serial) + ; +#endif + + Serial.println(); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + multi.addAP(WIFI_SSID, WIFI_PASSWORD); + multi.run(); +#else + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Connecting to Wi-Fi"); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + unsigned long ms = millis(); +#endif + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + if (millis() - ms > 10000) + break; +#endif + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + MailClient.networkReconnect(true); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + MailClient.clearAP(); + MailClient.addAP(WIFI_SSID, WIFI_PASSWORD); +#endif + + Session_Config config; + + config.server.host_name = IMAP_HOST; + config.server.port = IMAP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + + IMAP_Data imap_data; + + imap_data.fetch.uid.clear(); + + imap_data.search.criteria = F("SEARCH RECENT"); + + imap_data.search.unseen_msg = true; + + imap_data.storage.saved_path = F("/email_data"); + + imap_data.storage.type = esp_mail_file_storage_type_flash; + + imap_data.download.header = true; + imap_data.download.text = true; + imap_data.download.html = true; + imap_data.download.attachment = true; + imap_data.download.inlineImg = true; + + imap_data.enable.html = true; + imap_data.enable.text = true; + + imap_data.enable.recent_sort = true; + + imap_data.enable.download_status = true; + + imap_data.limit.search = 5; + + imap_data.limit.msg_size = 512; + + imap_data.limit.attachment_size = 1024 * 1024 * 5; + + imap.setTCPTimeout(10); + + if (!imap.connect(&config, &imap_data)) + { + MailClient.printf("Connection error, Error Code: %d, Reason: %s", imap.errorCode(), imap.errorReason().c_str()); + return; + } + + if (imap.isAuthenticated()) + Serial.println("\nSuccessfully logged in."); + else + Serial.println("\nConnected with no Auth."); + + printAllMailboxesInfo(imap); + + if (!imap.selectFolder(F("INBOX"))) + { + MailClient.printf("Folder selection error, Error Code: %d, Reason: %s", imap.errorCode(), imap.errorReason().c_str()); + return; + } + + printSelectedMailboxInfo(imap.selectedFolder()); + + if (MailClient.readMail(&imap, false)) + { + printImapData(imap.status()); + } + else + { + MailClient.printf("Message searching error, Error Code: %d, Reason: %s", imap.errorCode(), imap.errorReason().c_str()); + } + + imap.closeSession(); + + imap.empty(); +} + +void loop() +{ +} + +void printImapData(IMAP_Status status) +{ + + if (status.success()) + { + MailClient.printf("\nFound %d messages\n\n", imap.selectedFolder().searchCount()); + + IMAP_MSG_List msgList = imap.data(); + printMessages(msgList.msgItems, imap.headerOnly()); + + imap.empty(); + } +} + +void printAllMailboxesInfo(IMAPSession &imap) +{ + FoldersCollection folders; + + if (imap.getFolders(folders)) + { + for (size_t i = 0; i < folders.size(); i++) + { + FolderInfo folderInfo = folders.info(i); + MailClient.printf("%s%s%s", i == 0 ? "\nAvailable folders: " : ", ", folderInfo.name, i == folders.size() - 1 ? "\n" : ""); + } + } +} + +void printSelectedMailboxInfo(SelectedFolderInfo sFolder) +{ + /* Show the mailbox info */ + MailClient.printf("\nInfo of the selected folder\nTotal Messages: %d\n", sFolder.msgCount()); + MailClient.printf("UID Validity: %d\n", sFolder.uidValidity()); + MailClient.printf("Predicted next UID: %d\n", sFolder.nextUID()); + if (sFolder.unseenIndex() > 0) + MailClient.printf("First Unseen Message Number: %d\n", sFolder.unseenIndex()); + else + MailClient.printf("Unseen Messages: No\n"); + + if (sFolder.modSeqSupported()) + MailClient.printf("Highest Modification Sequence: %llu\n", sFolder.highestModSeq()); + for (size_t i = 0; i < sFolder.flagCount(); i++) + MailClient.printf("%s%s%s", i == 0 ? "Flags: " : ", ", sFolder.flag(i).c_str(), i == sFolder.flagCount() - 1 ? "\n" : ""); + + if (sFolder.flagCount(true)) + { + for (size_t i = 0; i < sFolder.flagCount(true); i++) + MailClient.printf("%s%s%s", i == 0 ? "Permanent Flags: " : ", ", sFolder.flag(i, true).c_str(), i == sFolder.flagCount(true) - 1 ? "\n" : ""); + } +} + +void printAttacements(std::vector &atts) +{ + MailClient.printf("Attachment: %d file(s)\n****************************\n", atts.size()); + for (size_t j = 0; j < atts.size(); j++) + { + IMAP_Attach_Item att = atts[j]; + MailClient.printf("%d. Filename: %s, Name: %s, Size: %d, MIME: %s, Type: %s, Description: %s, Creation Date: %s\n", j + 1, att.filename, att.name, att.size, att.mime, att.type == esp_mail_att_type_attachment ? "attachment" : "inline", att.description, att.creationDate); + } + Serial.println(); +} + +void printMessages(std::vector &msgItems, bool headerOnly) +{ + + for (size_t i = 0; i < msgItems.size(); i++) + { + IMAP_MSG_Item msg = msgItems[i]; + + Serial.println("****************************"); + + MailClient.printf("Number: %d\n", msg.msgNo); + MailClient.printf("UID: %d\n", msg.UID); + + // The attachment status in search may be true in case the "multipart/mixed" + // content type header was set with no real attachtment included. + MailClient.printf("Attachment: %s\n", msg.hasAttachment ? "yes" : "no"); + + MailClient.printf("Messsage-ID: %s\n", msg.ID); + + if (strlen(msg.flags)) + MailClient.printf("Flags: %s\n", msg.flags); + if (strlen(msg.acceptLang)) + MailClient.printf("Accept Language: %s\n", msg.acceptLang); + if (strlen(msg.contentLang)) + MailClient.printf("Content Language: %s\n", msg.contentLang); + if (strlen(msg.from)) + MailClient.printf("From: %s\n", msg.from); + if (strlen(msg.sender)) + MailClient.printf("Sender: %s\n", msg.sender); + if (strlen(msg.to)) + MailClient.printf("To: %s\n", msg.to); + if (strlen(msg.cc)) + MailClient.printf("CC: %s\n", msg.cc); + if (strlen(msg.bcc)) + MailClient.printf("BCC: %s\n", msg.bcc); + if (strlen(msg.date)) + { + MailClient.printf("Date: %s\n", msg.date); + MailClient.printf("Timestamp: %d\n", (int)MailClient.Time.getTimestamp(msg.date)); + } + if (strlen(msg.subject)) + MailClient.printf("Subject: %s\n", msg.subject); + if (strlen(msg.reply_to)) + MailClient.printf("Reply-To: %s\n", msg.reply_to); + if (strlen(msg.return_path)) + MailClient.printf("Return-Path: %s\n", msg.return_path); + if (strlen(msg.in_reply_to)) + MailClient.printf("In-Reply-To: %s\n", msg.in_reply_to); + if (strlen(msg.references)) + MailClient.printf("References: %s\n", msg.references); + if (strlen(msg.comments)) + MailClient.printf("Comments: %s\n", msg.comments); + if (strlen(msg.keywords)) + MailClient.printf("Keywords: %s\n", msg.keywords); + + if (!headerOnly) + { + if (strlen(msg.text.content)) + MailClient.printf("Text Message: %s\n", msg.text.content); + if (strlen(msg.text.charSet)) + MailClient.printf("Text Message Charset: %s\n", msg.text.charSet); + if (strlen(msg.text.transfer_encoding)) + MailClient.printf("Text Message Transfer Encoding: %s\n", msg.text.transfer_encoding); + if (strlen(msg.html.content)) + MailClient.printf("HTML Message: %s\n", msg.html.content); + if (strlen(msg.html.charSet)) + MailClient.printf("HTML Message Charset: %s\n", msg.html.charSet); + if (strlen(msg.html.transfer_encoding)) + MailClient.printf("HTML Message Transfer Encoding: %s\n\n", msg.html.transfer_encoding); + + if (msg.rfc822.size() > 0) + { + MailClient.printf("\r\nRFC822 Messages: %d message(s)\n****************************\n", msg.rfc822.size()); + printMessages(msg.rfc822, headerOnly); + } + + if (msg.attachments.size() > 0) + printAttacements(msg.attachments); + } + + Serial.println(); + } +} diff --git a/lib/libesp32/ESP-Mail-Client/examples/IMAP/Set_Flags/Set_Flags_List/Set_Flags_List.ino b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Set_Flags/Set_Flags_List/Set_Flags_List.ino new file mode 100644 index 000000000..3aedc9021 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Set_Flags/Set_Flags_List/Set_Flags_List.ino @@ -0,0 +1,339 @@ +/** + * This example shows how to set messages flags. + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt + * + */ + +// This example shows how to set messages flags. + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +/** For ESP8266, with BearSSL WiFi Client + * The memory reserved for completed valid SSL response from IMAP is 16 kbytes which + * may cause your device out of memory reset in case the memory + * allocation error. + */ + +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +#include + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +/** For Gmail, IMAP option should be enabled. https://support.google.com/mail/answer/7126229?hl=en + * and also https://accounts.google.com/b/0/DisplayUnlockCaptcha + * + * Some Gmail user still not able to sign in using account password even above options were set up, + * for this case, use "App Password" to sign in instead. + * About Gmail "App Password", go to https://support.google.com/accounts/answer/185833?hl=en + * + * For Yahoo mail, log in to your yahoo mail in web browser and generate app password by go to + * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc + * + * To use Gmai and Yahoo's App Password to sign in, define the AUTHOR_PASSWORD with your App Password + * and AUTHOR_EMAIL with your account email. + */ + +/* The imap host name e.g. imap.gmail.com for GMail or outlook.office365.com for Outlook */ +#define IMAP_HOST "" + +/** The imap port e.g. + * 143 or esp_mail_imap_port_143 + * 993 or esp_mail_imap_port_993 + */ +#define IMAP_PORT 993 + +/* The log in credentials */ +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" + +/* Print the list of mailbox folders */ +void printAllMailboxesInfo(IMAPSession &imap); + +/* Print the selected folder info */ +void printSelectedMailboxInfo(SelectedFolderInfo sFolder); + +/* Declare the global used IMAPSession object for IMAP transport */ +IMAPSession imap; + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) +WiFiMulti multi; +#endif + +void setup() +{ + + Serial.begin(115200); + +#if defined(ARDUINO_ARCH_SAMD) + while (!Serial) + ; +#endif + + Serial.println(); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + multi.addAP(WIFI_SSID, WIFI_PASSWORD); + multi.run(); +#else + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Connecting to Wi-Fi"); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + unsigned long ms = millis(); +#endif + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + if (millis() - ms > 10000) + break; +#endif + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + /* Set the network reconnection option */ + MailClient.networkReconnect(true); + + // The WiFi credentials are required for Pico W + // due to it does not have reconnect feature. +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + MailClient.clearAP(); + MailClient.addAP(WIFI_SSID, WIFI_PASSWORD); +#endif + + /** Enable the debug via Serial port + * 0 for no debugging + * 1 for basic level debugging + * + * Debug port can be changed via ESP_MAIL_DEFAULT_DEBUG_PORT in ESP_Mail_FS.h + */ + imap.debug(1); + + /** In case the SD card/adapter was used for the file storagge, the SPI pins can be configure from + * MailClient.sdBegin function which may be different for ESP32 and ESP8266 + * For ESP32, assign all of SPI pins + * MailClient.sdBegin(14,2,15,13) + * Which SCK = 14, MISO = 2, MOSI = 15 and SS = 13 + * And for ESP8266, assign the CS pins of SPI port + * MailClient.sdBegin(15) + * Which pin 15 is the CS pin of SD card adapter + */ + + /* Declare the Session_Config for user defined session credentials */ + Session_Config config; + + /* Set the session config */ + config.server.host_name = IMAP_HOST; + config.server.port = IMAP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + + /* Define the IMAP_Data object used for user defined IMAP operating options. */ + IMAP_Data imap_data; + + /* Set seen flag */ + // imap_data.fetch.set_seen = true; + + /* Search criteria */ + imap_data.search.criteria.clear(); + + /* Also search the unseen message */ + imap_data.search.unseen_msg = true; + + /* Set the storage to save the downloaded files and attachments */ + imap_data.storage.saved_path = F("/email_data"); + + /** The file storage type e.g. + * esp_mail_file_storage_type_none, + * esp_mail_file_storage_type_flash, and + * esp_mail_file_storage_type_sd + */ + imap_data.storage.type = esp_mail_file_storage_type_flash; + + /** Set to download headers, text and html messaeges, + * attachments and inline images respectively. + */ + imap_data.download.header = true; + imap_data.download.text = true; + imap_data.download.html = true; + imap_data.download.attachment = true; + imap_data.download.inlineImg = true; + + /** Set to enable the results i.e. html and text messaeges + * which the content stored in the IMAPSession object is limited + * by the option imap_data.limit.msg_size. + * The whole message can be download through imap_data.download.text + * or imap_data.download.html which not depends on these enable options. + */ + imap_data.enable.html = true; + imap_data.enable.text = true; + + /* Set to enable the sort the result by message UID in the decending order */ + imap_data.enable.recent_sort = true; + + /* Set to report the download progress via the default serial port */ + imap_data.enable.download_status = true; + + /* Set the limit of number of messages in the search results */ + imap_data.limit.search = 5; + + /** Set the maximum size of message stored in + * IMAPSession object in byte + */ + imap_data.limit.msg_size = 512; + + /** Set the maximum attachments and inline images files size + * that can be downloaded in byte. + * The file which its size is largger than this limit may be saved + * as truncated file. + */ + imap_data.limit.attachment_size = 1024 * 1024 * 5; + + /* Connect to the server */ + if (!imap.connect(&config, &imap_data)) + return; + + /* {Optional} */ + printAllMailboxesInfo(imap); + + /* Open or select the mailbox folder to read or search the message */ + if (!imap.selectFolder(F("INBOX"))) + return; + + /* {Optional} */ + printSelectedMailboxInfo(imap.selectedFolder()); + + /* Message UID to fetch or read e.g. 100 */ + int uid = imap.getUID(imap.selectedFolder().msgCount()); + + /** Set \Seen and \Answered to flags for message with UID + * The seesion will keep open. + */ + if (MailClient.setFlag(&imap, uid, F("\\Seen \\Answered"), false)) + Serial.println("\nSetting FLAG success"); + else + Serial.println("\nError, setting FLAG"); + + /* Add \Seen and \Answered to flags for message with UID 100 */ + // MailClient.addFlag(imap, 100, "\\Seen \\Answered", false); + + /* Remove \Seen and \Answered from flags for message with UID 100 */ + // MailClient.removeFlag(imap, 100, "\\Seen \\Answered", false); + + /* Remove Seen and Answered flags from messages using UID ranges (last 10 UIDs) */ + int uid_last = imap.getUID(imap.selectedFolder().msgCount()); + int uid_begin = uid_last > 10 ? uid_last - 10 : uid_last; + + String sequence_set1 = String(uid_begin) + ":" + String(uid_last); + + if (MailClient.removeFlag(&imap, sequence_set1, true /* if sequence set are the UIDs */, F("\\Seen \\Answered"), false /* Close session */, false /* Ignore response */)) + Serial.println("\nRemoving FLAG with UIDs ranges success"); + else + Serial.println("\nError, removing FLAG with UIDs ranges"); + + /* Remove Seen and Answered flags from messages using message sequence ranges (last 10 message numbers) */ + int msg_last = imap.selectedFolder().msgCount(); + int msg_begin = msg_last > 10 ? msg_last - 10 : msg_last; + + String sequence_set2 = String(msg_begin) + ":" + String(msg_last); + + if (MailClient.removeFlag(&imap, sequence_set2, false /* if sequence set are message numbers not UIDs */, F("\\Seen \\Answered"), false /* Close session */, false /* Ignore response */)) + Serial.println("\nRemoving FLAG with message numbers ranges success"); + else + Serial.println("\nError, removing FLAG with message numbers ranges"); + + imap_data.fetch.uid = uid; + + /* Read or search the Email and close the session */ + MailClient.readMail(&imap); + + /* Clear all stored data in IMAPSession object */ + imap.empty(); + + MailClient.printf("Free Heap: %d\n", MailClient.getFreeHeap()); +} + +void loop() +{ +} + +void printAllMailboxesInfo(IMAPSession &imap) +{ + /* Declare the folder collection class to get the list of mailbox folders */ + FoldersCollection folders; + + /* Get the mailbox folders */ + if (imap.getFolders(folders)) + { + for (size_t i = 0; i < folders.size(); i++) + { + /* Iterate each folder info using the folder info item data */ + FolderInfo folderInfo = folders.info(i); + MailClient.printf("%s%s%s", i == 0 ? "\nAvailable folders: " : ", ", folderInfo.name, i == folders.size() - 1 ? "\n" : ""); + } + } +} + +void printSelectedMailboxInfo(SelectedFolderInfo sFolder) +{ + /* Show the mailbox info */ + MailClient.printf("\nInfo of the selected folder\nTotal Messages: %d\n", sFolder.msgCount()); + MailClient.printf("UID Validity: %d\n", sFolder.uidValidity()); + MailClient.printf("Predicted next UID: %d\n", sFolder.nextUID()); + if (sFolder.unseenIndex() > 0) + MailClient.printf("First Unseen Message Number: %d\n", sFolder.unseenIndex()); + else + MailClient.printf("Unseen Messages: No\n"); + + if (sFolder.modSeqSupported()) + MailClient.printf("Highest Modification Sequence: %llu\n", sFolder.highestModSeq()); + for (size_t i = 0; i < sFolder.flagCount(); i++) + MailClient.printf("%s%s%s", i == 0 ? "Flags: " : ", ", sFolder.flag(i).c_str(), i == sFolder.flagCount() - 1 ? "\n" : ""); + + if (sFolder.flagCount(true)) + { + for (size_t i = 0; i < sFolder.flagCount(true); i++) + MailClient.printf("%s%s%s", i == 0 ? "Permanent Flags: " : ", ", sFolder.flag(i, true).c_str(), i == sFolder.flagCount(true) - 1 ? "\n" : ""); + } +} diff --git a/lib/libesp32/ESP-Mail-Client/examples/IMAP/Set_Flags/Set_Flags_Message_Numbers_Ranges/Set_Flags_Message_Numbers_Ranges.ino b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Set_Flags/Set_Flags_Message_Numbers_Ranges/Set_Flags_Message_Numbers_Ranges.ino new file mode 100644 index 000000000..0e2645f25 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Set_Flags/Set_Flags_Message_Numbers_Ranges/Set_Flags_Message_Numbers_Ranges.ino @@ -0,0 +1,309 @@ +/** + * This example shows how to set messages flags. + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt + * + */ + +// This example shows how to set messages flags using message numbers ranges. + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +/** For ESP8266, with BearSSL WiFi Client + * The memory reserved for completed valid SSL response from IMAP is 16 kbytes which + * may cause your device out of memory reset in case the memory + * allocation error. + */ + +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +#include + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +/** For Gmail, IMAP option should be enabled. https://support.google.com/mail/answer/7126229?hl=en + * and also https://accounts.google.com/b/0/DisplayUnlockCaptcha + * + * Some Gmail user still not able to sign in using account password even above options were set up, + * for this case, use "App Password" to sign in instead. + * About Gmail "App Password", go to https://support.google.com/accounts/answer/185833?hl=en + * + * For Yahoo mail, log in to your yahoo mail in web browser and generate app password by go to + * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc + * + * To use Gmai and Yahoo's App Password to sign in, define the AUTHOR_PASSWORD with your App Password + * and AUTHOR_EMAIL with your account email. + */ + +/* The imap host name e.g. imap.gmail.com for GMail or outlook.office365.com for Outlook */ +#define IMAP_HOST "" + +/** The imap port e.g. + * 143 or esp_mail_imap_port_143 + * 993 or esp_mail_imap_port_993 + */ +#define IMAP_PORT 993 + +/* The log in credentials */ +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" + +/* Print the list of mailbox folders */ +void printAllMailboxesInfo(IMAPSession &imap); + +/* Print the selected folder info */ +void printSelectedMailboxInfo(SelectedFolderInfo sFolder); + +/* Declare the global used IMAPSession object for IMAP transport */ +IMAPSession imap; + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) +WiFiMulti multi; +#endif + +void setup() +{ + + Serial.begin(115200); + +#if defined(ARDUINO_ARCH_SAMD) + while (!Serial) + ; +#endif + + Serial.println(); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + multi.addAP(WIFI_SSID, WIFI_PASSWORD); + multi.run(); +#else + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Connecting to Wi-Fi"); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + unsigned long ms = millis(); +#endif + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + if (millis() - ms > 10000) + break; +#endif + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + /* Set the network reconnection option */ + MailClient.networkReconnect(true); + + // The WiFi credentials are required for Pico W + // due to it does not have reconnect feature. +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + MailClient.clearAP(); + MailClient.addAP(WIFI_SSID, WIFI_PASSWORD); +#endif + + /** Enable the debug via Serial port + * 0 for no debugging + * 1 for basic level debugging + * + * Debug port can be changed via ESP_MAIL_DEFAULT_DEBUG_PORT in ESP_Mail_FS.h + */ + imap.debug(1); + + /** In case the SD card/adapter was used for the file storagge, the SPI pins can be configure from + * MailClient.sdBegin function which may be different for ESP32 and ESP8266 + * For ESP32, assign all of SPI pins + * MailClient.sdBegin(14,2,15,13) + * Which SCK = 14, MISO = 2, MOSI = 15 and SS = 13 + * And for ESP8266, assign the CS pins of SPI port + * MailClient.sdBegin(15) + * Which pin 15 is the CS pin of SD card adapter + */ + + /* Declare the Session_Config for user defined session credentials */ + Session_Config config; + + /* Set the session config */ + config.server.host_name = IMAP_HOST; + config.server.port = IMAP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + + /* Define the IMAP_Data object used for user defined IMAP operating options. */ + IMAP_Data imap_data; + + /* Set seen flag */ + // imap_data.fetch.set_seen = true; + + /* Search criteria */ + imap_data.search.criteria.clear(); + + /* Also search the unseen message */ + imap_data.search.unseen_msg = true; + + /* Set the storage to save the downloaded files and attachments */ + imap_data.storage.saved_path = F("/email_data"); + + /** The file storage type e.g. + * esp_mail_file_storage_type_none, + * esp_mail_file_storage_type_flash, and + * esp_mail_file_storage_type_sd + */ + imap_data.storage.type = esp_mail_file_storage_type_flash; + + /** Set to download headers, text and html messaeges, + * attachments and inline images respectively. + */ + imap_data.download.header = true; + imap_data.download.text = true; + imap_data.download.html = true; + imap_data.download.attachment = true; + imap_data.download.inlineImg = true; + + /** Set to enable the results i.e. html and text messaeges + * which the content stored in the IMAPSession object is limited + * by the option imap_data.limit.msg_size. + * The whole message can be download through imap_data.download.text + * or imap_data.download.html which not depends on these enable options. + */ + imap_data.enable.html = true; + imap_data.enable.text = true; + + /* Set to enable the sort the result by message UID in the decending order */ + imap_data.enable.recent_sort = true; + + /* Set to report the download progress via the default serial port */ + imap_data.enable.download_status = true; + + /* Set the limit of number of messages in the search results */ + imap_data.limit.search = 5; + + /** Set the maximum size of message stored in + * IMAPSession object in byte + */ + imap_data.limit.msg_size = 512; + + /** Set the maximum attachments and inline images files size + * that can be downloaded in byte. + * The file which its size is largger than this limit may be saved + * as truncated file. + */ + imap_data.limit.attachment_size = 1024 * 1024 * 5; + + /* Connect to the server */ + if (!imap.connect(&config, &imap_data)) + return; + + /* {Optional} */ + printAllMailboxesInfo(imap); + + /* Open or select the mailbox folder to read or search the message */ + if (!imap.selectFolder(F("INBOX"))) + return; + + /* {Optional} */ + printSelectedMailboxInfo(imap.selectedFolder()); + + /* Add Seen and Answered flags from messages using message numbers ranges (last 10 message numbers) */ + int msg_last = imap.selectedFolder().msgCount(); + int msg_begin = msg_last > 10 ? msg_last - 10 : msg_last; + + String sequence_set1 = String(msg_begin) + ":" + String(msg_last); + + if (MailClient.addFlag(&imap, sequence_set1, false /* if sequence set are message numbers not UIDs */, F("\\Seen \\Answered"), false /* Close session */, false /* Ignore response */)) + Serial.println("\nAdding FLAG with message numbers ranges success"); + else + Serial.println("\nError, adding FLAG with message numbers ranges"); + + /* Remove Seen and Answered flags from messages using message numbers ranges (last 10 message numbers) */ + if (MailClient.removeFlag(&imap, sequence_set1, false /* if sequence set are message numbers not UIDs */, F("\\Seen \\Answered"), false /* Close session */, false /* Ignore response */)) + Serial.println("\nRemoving FLAG with message numbers ranges success"); + else + Serial.println("\nError, removing FLAG with message numbers ranges"); + + MailClient.printf("Free Heap: %d\n", MailClient.getFreeHeap()); +} + +void loop() +{ +} + +void printAllMailboxesInfo(IMAPSession &imap) +{ + /* Declare the folder collection class to get the list of mailbox folders */ + FoldersCollection folders; + + /* Get the mailbox folders */ + if (imap.getFolders(folders)) + { + for (size_t i = 0; i < folders.size(); i++) + { + /* Iterate each folder info using the folder info item data */ + FolderInfo folderInfo = folders.info(i); + MailClient.printf("%s%s%s", i == 0 ? "\nAvailable folders: " : ", ", folderInfo.name, i == folders.size() - 1 ? "\n" : ""); + } + } +} + +void printSelectedMailboxInfo(SelectedFolderInfo sFolder) +{ + /* Show the mailbox info */ + MailClient.printf("\nInfo of the selected folder\nTotal Messages: %d\n", sFolder.msgCount()); + MailClient.printf("UID Validity: %d\n", sFolder.uidValidity()); + MailClient.printf("Predicted next UID: %d\n", sFolder.nextUID()); + if (sFolder.unseenIndex() > 0) + MailClient.printf("First Unseen Message Number: %d\n", sFolder.unseenIndex()); + else + MailClient.printf("Unseen Messages: No\n"); + + if (sFolder.modSeqSupported()) + MailClient.printf("Highest Modification Sequence: %llu\n", sFolder.highestModSeq()); + for (size_t i = 0; i < sFolder.flagCount(); i++) + MailClient.printf("%s%s%s", i == 0 ? "Flags: " : ", ", sFolder.flag(i).c_str(), i == sFolder.flagCount() - 1 ? "\n" : ""); + + if (sFolder.flagCount(true)) + { + for (size_t i = 0; i < sFolder.flagCount(true); i++) + MailClient.printf("%s%s%s", i == 0 ? "Permanent Flags: " : ", ", sFolder.flag(i, true).c_str(), i == sFolder.flagCount(true) - 1 ? "\n" : ""); + } +} diff --git a/lib/libesp32/ESP-Mail-Client/examples/IMAP/Set_Flags/Set_Flags_UIDs_Ranges/Set_Flags_UIDs_Ranges.ino b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Set_Flags/Set_Flags_UIDs_Ranges/Set_Flags_UIDs_Ranges.ino new file mode 100644 index 000000000..4e3ccc2ad --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/IMAP/Set_Flags/Set_Flags_UIDs_Ranges/Set_Flags_UIDs_Ranges.ino @@ -0,0 +1,310 @@ +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt +*/ + +// This example shows how to set messages flags. + +// This example shows how to set messages flags using UIDs ranges. + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +/** For ESP8266, with BearSSL WiFi Client + * The memory reserved for completed valid SSL response from IMAP is 16 kbytes which + * may cause your device out of memory reset in case the memory + * allocation error. + */ + +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +#include + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +/** For Gmail, IMAP option should be enabled. https://support.google.com/mail/answer/7126229?hl=en + * and also https://accounts.google.com/b/0/DisplayUnlockCaptcha + * + * Some Gmail user still not able to sign in using account password even above options were set up, + * for this case, use "App Password" to sign in instead. + * About Gmail "App Password", go to https://support.google.com/accounts/answer/185833?hl=en + * + * For Yahoo mail, log in to your yahoo mail in web browser and generate app password by go to + * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc + * + * To use Gmai and Yahoo's App Password to sign in, define the AUTHOR_PASSWORD with your App Password + * and AUTHOR_EMAIL with your account email. + */ + +/* The imap host name e.g. imap.gmail.com for GMail or outlook.office365.com for Outlook */ +#define IMAP_HOST "" + +/** The imap port e.g. + * 143 or esp_mail_imap_port_143 + * 993 or esp_mail_imap_port_993 + */ +#define IMAP_PORT 993 + +/* The log in credentials */ +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" + +/* Print the list of mailbox folders */ +void printAllMailboxesInfo(IMAPSession &imap); + +/* Print the selected folder info */ +void printSelectedMailboxInfo(SelectedFolderInfo sFolder); + +/* Declare the global used IMAPSession object for IMAP transport */ +IMAPSession imap; + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) +WiFiMulti multi; +#endif + +void setup() +{ + + Serial.begin(115200); + +#if defined(ARDUINO_ARCH_SAMD) + while (!Serial) + ; +#endif + + Serial.println(); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + multi.addAP(WIFI_SSID, WIFI_PASSWORD); + multi.run(); +#else + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Connecting to Wi-Fi"); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + unsigned long ms = millis(); +#endif + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + if (millis() - ms > 10000) + break; +#endif + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + /* Set the network reconnection option */ + MailClient.networkReconnect(true); + + // The WiFi credentials are required for Pico W + // due to it does not have reconnect feature. +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + MailClient.clearAP(); + MailClient.addAP(WIFI_SSID, WIFI_PASSWORD); +#endif + + /** Enable the debug via Serial port + * 0 for no debugging + * 1 for basic level debugging + * + * Debug port can be changed via ESP_MAIL_DEFAULT_DEBUG_PORT in ESP_Mail_FS.h + */ + imap.debug(1); + + /** In case the SD card/adapter was used for the file storagge, the SPI pins can be configure from + * MailClient.sdBegin function which may be different for ESP32 and ESP8266 + * For ESP32, assign all of SPI pins + * MailClient.sdBegin(14,2,15,13) + * Which SCK = 14, MISO = 2, MOSI = 15 and SS = 13 + * And for ESP8266, assign the CS pins of SPI port + * MailClient.sdBegin(15) + * Which pin 15 is the CS pin of SD card adapter + */ + + /* Declare the Session_Config for user defined session credentials */ + Session_Config config; + + /* Set the session config */ + config.server.host_name = IMAP_HOST; + config.server.port = IMAP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + + /* Define the IMAP_Data object used for user defined IMAP operating options. */ + IMAP_Data imap_data; + + /* Set seen flag */ + // imap_data.fetch.set_seen = true; + + /* Search criteria */ + imap_data.search.criteria.clear(); + + /* Also search the unseen message */ + imap_data.search.unseen_msg = true; + + /* Set the storage to save the downloaded files and attachments */ + imap_data.storage.saved_path = F("/email_data"); + + /** The file storage type e.g. + * esp_mail_file_storage_type_none, + * esp_mail_file_storage_type_flash, and + * esp_mail_file_storage_type_sd + */ + imap_data.storage.type = esp_mail_file_storage_type_flash; + + /** Set to download headers, text and html messaeges, + * attachments and inline images respectively. + */ + imap_data.download.header = true; + imap_data.download.text = true; + imap_data.download.html = true; + imap_data.download.attachment = true; + imap_data.download.inlineImg = true; + + /** Set to enable the results i.e. html and text messaeges + * which the content stored in the IMAPSession object is limited + * by the option imap_data.limit.msg_size. + * The whole message can be download through imap_data.download.text + * or imap_data.download.html which not depends on these enable options. + */ + imap_data.enable.html = true; + imap_data.enable.text = true; + + /* Set to enable the sort the result by message UID in the decending order */ + imap_data.enable.recent_sort = true; + + /* Set to report the download progress via the default serial port */ + imap_data.enable.download_status = true; + + /* Set the limit of number of messages in the search results */ + imap_data.limit.search = 5; + + /** Set the maximum size of message stored in + * IMAPSession object in byte + */ + imap_data.limit.msg_size = 512; + + /** Set the maximum attachments and inline images files size + * that can be downloaded in byte. + * The file which its size is largger than this limit may be saved + * as truncated file. + */ + imap_data.limit.attachment_size = 1024 * 1024 * 5; + + /* Connect to the server */ + if (!imap.connect(&config, &imap_data)) + return; + + /* {Optional} */ + printAllMailboxesInfo(imap); + + /* Open or select the mailbox folder to read or search the message */ + if (!imap.selectFolder(F("INBOX"))) + return; + + /* {Optional} */ + printSelectedMailboxInfo(imap.selectedFolder()); + + /* Add Seen and Answered flags from messages using UID ranges (last 10 UIDs) */ + int uid_last = imap.getUID(imap.selectedFolder().msgCount()); + int uid_begin = uid_last > 10 ? uid_last - 10 : uid_last; + + String sequence_set1 = String(uid_begin) + ":" + String(uid_last); + + if (MailClient.addFlag(&imap, sequence_set1, true /* if sequence set are the UIDs */, F("\\Seen \\Answered"), false /* Close session */, false /* Ignore response */)) + Serial.println("\nAdding FLAG with UIDs ranges success"); + else + Serial.println("\nError, adding FLAG with UIDs ranges"); + + /* Remove Seen and Answered flags from messages using UID ranges (last 10 UIDs) */ + if (MailClient.removeFlag(&imap, sequence_set1, true /* if sequence set are the UIDs */, F("\\Seen \\Answered"), false /* Close session */, false /* Ignore response */)) + Serial.println("\nRemoving FLAG with UIDs ranges success"); + else + Serial.println("\nError, removing FLAG with UIDs ranges"); + + MailClient.printf("Free Heap: %d\n", MailClient.getFreeHeap()); +} + +void loop() +{ +} + +void printAllMailboxesInfo(IMAPSession &imap) +{ + /* Declare the folder collection class to get the list of mailbox folders */ + FoldersCollection folders; + + /* Get the mailbox folders */ + if (imap.getFolders(folders)) + { + for (size_t i = 0; i < folders.size(); i++) + { + /* Iterate each folder info using the folder info item data */ + FolderInfo folderInfo = folders.info(i); + MailClient.printf("%s%s%s", i == 0 ? "\nAvailable folders: " : ", ", folderInfo.name, i == folders.size() - 1 ? "\n" : ""); + } + } +} + +void printSelectedMailboxInfo(SelectedFolderInfo sFolder) +{ + /* Show the mailbox info */ + MailClient.printf("\nInfo of the selected folder\nTotal Messages: %d\n", sFolder.msgCount()); + MailClient.printf("UID Validity: %d\n", sFolder.uidValidity()); + MailClient.printf("Predicted next UID: %d\n", sFolder.nextUID()); + if (sFolder.unseenIndex() > 0) + MailClient.printf("First Unseen Message Number: %d\n", sFolder.unseenIndex()); + else + MailClient.printf("Unseen Messages: No\n"); + + if (sFolder.modSeqSupported()) + MailClient.printf("Highest Modification Sequence: %llu\n", sFolder.highestModSeq()); + for (size_t i = 0; i < sFolder.flagCount(); i++) + MailClient.printf("%s%s%s", i == 0 ? "Flags: " : ", ", sFolder.flag(i).c_str(), i == sFolder.flagCount() - 1 ? "\n" : ""); + + if (sFolder.flagCount(true)) + { + for (size_t i = 0; i < sFolder.flagCount(true); i++) + MailClient.printf("%s%s%s", i == 0 ? "Permanent Flags: " : ", ", sFolder.flag(i, true).c_str(), i == sFolder.flagCount(true) - 1 ? "\n" : ""); + } +} diff --git a/lib/libesp32/ESP-Mail-Client/examples/SMTP/Custom_Command/Basic_Auth/Basic_Auth.ino b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Custom_Command/Basic_Auth/Basic_Auth.ino new file mode 100644 index 000000000..c43a149eb --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Custom_Command/Basic_Auth/Basic_Auth.ino @@ -0,0 +1,219 @@ + +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt +*/ + +// This example showes how to send Email using custom commands. + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +#include + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +/** For Gmail, the app password will be used for log in + * Check out https://github.com/mobizt/ESP-Mail-Client#gmail-smtp-and-imap-required-app-passwords-to-sign-in + * + * For Yahoo mail, log in to your yahoo mail in web browser and generate app password by go to + * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc + * + * To use Gmai and Yahoo's App Password to sign in, define the AUTHOR_PASSWORD with your App Password + * and AUTHOR_EMAIL with your account email. + */ + +/** The smtp host name e.g. smtp.gmail.com for GMail or smtp.office365.com for Outlook or smtp.mail.yahoo.com */ +#define SMTP_HOST "" + +/** The smtp port e.g. + * 25 or esp_mail_smtp_port_25 + * 465 or esp_mail_smtp_port_465 + * 587 or esp_mail_smtp_port_587 // See STARTTLS.ino example + */ +#define SMTP_PORT esp_mail_smtp_port_465 // port 465 is not available for Outlook.com + +/* The log in credentials */ +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" + +/* Declare the global used SMTPSession object for SMTP transport */ +SMTPSession smtp; + +const char rootCACert[] PROGMEM = "-----BEGIN CERTIFICATE-----\n" + "-----END CERTIFICATE-----\n"; + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) +WiFiMulti multi; +#endif + +void customCommandCallback(SMTP_Response res) +{ + + // The res.id is the command identifier number that use to identify the source of command. + + // The command identifier number can be set via the last parameter of customConnect and sendCustomCommand functions. + + // If command identifier number was not set in those functions, the res.id received will be auto increased and begins with 0 + + MailClient.printf("> C: Command ID %d\n", res.id); + MailClient.printf("< S: %s\n", res.text.c_str()); + + if (res.statusCode > 0) + { + MailClient.printf("> C: Response finished with status code %d\n\n", res.statusCode); + } +} + +void setup() +{ + + Serial.begin(115200); + +#if defined(ARDUINO_ARCH_SAMD) + while (!Serial) + ; +#endif + + Serial.println(); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + multi.addAP(WIFI_SSID, WIFI_PASSWORD); + multi.run(); +#else + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Connecting to Wi-Fi"); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + unsigned long ms = millis(); +#endif + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + if (millis() - ms > 10000) + break; +#endif + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + /* Set the network reconnection option */ + MailClient.networkReconnect(true); + + // The WiFi credentials are required for Pico W + // due to it does not have reconnect feature. +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + MailClient.clearAP(); + MailClient.addAP(WIFI_SSID, WIFI_PASSWORD); +#endif + + /* Declare the Session_Config for user defined session credentials */ + Session_Config config; + + /* Set the session config */ + config.server.host_name = SMTP_HOST; + config.server.port = SMTP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + + /** Assign your host name or you public IPv4 or IPv6 only + * as this is the part of EHLO/HELO command to identify the client system + * to prevent connection rejection. + * If host name or public IP is not available, ignore this or + * use loopback address "127.0.0.1". + * + * Assign any text to this option may cause the connection rejection. + */ + config.login.user_domain = F("127.0.0.1"); + + /* Connect to the server */ + if (!smtp.connect(&config)) + return; + + if (smtp.isAuthenticated()) + Serial.println("\nSuccessfully logged in."); + else + Serial.println("\nConnected with no Auth."); + + // Please don't forget to change sender@xxxxxx.com to your email + if (smtp.sendCustomCommand(F("MAIL FROM:"), customCommandCallback) != 250) + { + smtp.closeSession(); + return; + } + + // Please don't forget to change recipient@xxxxx.com with your recipient email + if (smtp.sendCustomCommand(F("RCPT TO:"), customCommandCallback) != 250) + { + smtp.closeSession(); + return; + } + + if (smtp.sendCustomCommand(F("DATA"), customCommandCallback) != 354) + { + smtp.closeSession(); + return; + } + + // Send data with command which terminated with dot '.' + if (smtp.sendCustomCommand(F("Subject: Test sending Email\r\nHello World!\r\n."), customCommandCallback) != 250) + { + smtp.closeSession(); + return; + } + + // Do not use this command in ESP8266 due to memory leaks in ESP8266 core BearSSL. + // smtp.sendCustomCommand(F("QUIT"), customCommandCallback); + + smtp.closeSession(); + + // to clear sending result log + // smtp.sendingResult.clear(); + + MailClient.printf("Free Heap: %d\n", MailClient.getFreeHeap()); +} + +void loop() +{ +} diff --git a/lib/libesp32/ESP-Mail-Client/examples/SMTP/Custom_Command/Custom_Auth/Custom_Auth.ino b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Custom_Command/Custom_Auth/Custom_Auth.ino new file mode 100644 index 000000000..13f50920c --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Custom_Command/Custom_Auth/Custom_Auth.ino @@ -0,0 +1,248 @@ + +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt +*/ + +// This example showes how to send Email using custom commands. + + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +#include + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +/** For Gmail, the app password will be used for log in + * Check out https://github.com/mobizt/ESP-Mail-Client#gmail-smtp-and-imap-required-app-passwords-to-sign-in + * + * For Yahoo mail, log in to your yahoo mail in web browser and generate app password by go to + * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc + * + * To use Gmai and Yahoo's App Password to sign in, define the AUTHOR_PASSWORD with your App Password + * and AUTHOR_EMAIL with your account email. + */ + +/** The smtp host name e.g. smtp.gmail.com for GMail or smtp.office365.com for Outlook or smtp.mail.yahoo.com */ +#define SMTP_HOST "" + +/** The smtp port e.g. + * 25 or esp_mail_smtp_port_25 + * 465 or esp_mail_smtp_port_465 + * 587 or esp_mail_smtp_port_587 // See STARTTLS.ino example + */ +#define SMTP_PORT esp_mail_smtp_port_465 // port 465 is not available for Outlook.com + +/* The log in credentials */ +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" + +/* Declare the global used SMTPSession object for SMTP transport */ +SMTPSession smtp; + +const char rootCACert[] PROGMEM = "-----BEGIN CERTIFICATE-----\n" + "-----END CERTIFICATE-----\n"; + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) +WiFiMulti multi; +#endif + +void customCommandCallback(SMTP_Response res) +{ + + // The res.id is the command identifier number that use to identify the source of command. + + // The command identifier number can be set via the last parameter of customConnect and sendCustomCommand functions. + + // If command identifier number was not set in those functions, the res.id received will be auto increased and begins with 0 + + MailClient.printf("> C: Command ID %d\n", res.id); + MailClient.printf("< S: %s\n", res.text.c_str()); + + if (res.statusCode > 0) + { + MailClient.printf("> C: Response finished with status code %d\n\n", res.statusCode); + } +} + +void setup() +{ + + Serial.begin(115200); + +#if defined(ARDUINO_ARCH_SAMD) + while (!Serial) + ; +#endif + + Serial.println(); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + multi.addAP(WIFI_SSID, WIFI_PASSWORD); + multi.run(); +#else + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Connecting to Wi-Fi"); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + unsigned long ms = millis(); +#endif + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + if (millis() - ms > 10000) + break; +#endif + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + /* Set the network reconnection option */ + MailClient.networkReconnect(true); + + // The WiFi credentials are required for Pico W + // due to it does not have reconnect feature. +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + MailClient.clearAP(); + MailClient.addAP(WIFI_SSID, WIFI_PASSWORD); +#endif + + /* Declare the Session_Config for user defined session credentials */ + Session_Config config; + + /* Set the session config */ + config.server.host_name = SMTP_HOST; + config.server.port = SMTP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + + /* Connect to the server */ + if (smtp.customConnect(&config /* session credentials */, customCommandCallback) != 220) + { + Serial.println("! E: Unable to connect to server"); + return; + } + + if (smtp.sendCustomCommand(F("EHLO 127.0.0.1"), customCommandCallback) != 250) + { + smtp.closeSession(); + return; + } + + if (smtp.sendCustomCommand(F("AUTH LOGIN"), customCommandCallback) != 334) + { + smtp.closeSession(); + return; + } + + if (smtp.sendCustomCommand(MailClient.toBase64(config.login.email), customCommandCallback) != 334) + { + smtp.closeSession(); + return; + } + + if (smtp.sendCustomCommand(MailClient.toBase64(config.login.password), customCommandCallback) != 235) + { + smtp.closeSession(); + return; + } + + if (smtp.isAuthenticated()) + Serial.println("Successfully logged in.\n"); + else + Serial.println("Connected with no Auth.\n"); + + // Please don't forget to change sender@xxxxxx.com to your email + if (smtp.sendCustomCommand(F("MAIL FROM:"), customCommandCallback) != 250) + { + smtp.closeSession(); + return; + } + + // Please don't forget to change recipient@xxxxx.com with your recipient email + if (smtp.sendCustomCommand(F("RCPT TO:"), customCommandCallback) != 250) + { + smtp.closeSession(); + return; + } + + if (smtp.sendCustomCommand(F("DATA"), customCommandCallback) != 354) + { + smtp.closeSession(); + return; + } + + if (!smtp.sendCustomData(F("Subject: Test sending Email\r\n"))) + { + smtp.closeSession(); + return; + } + + if (!smtp.sendCustomData(F("Hello World!\r\n"))) + { + smtp.closeSession(); + return; + } + + if (smtp.sendCustomCommand(F("."), customCommandCallback) != 250) + { + smtp.closeSession(); + return; + } + + // Do not use this command in ESP8266 due to memory leaks in ESP8266 core BearSSL. + // smtp.sendCustomCommand(F("QUIT"), customCommandCallback); + + smtp.closeSession(); + + // to clear sending result log + // smtp.sendingResult.clear(); + + MailClient.printf("Free Heap: %d\n", MailClient.getFreeHeap()); +} + +void loop() +{ +} diff --git a/lib/libesp32/ESP-Mail-Client/examples/SMTP/Custom_Command/STARTTLS/STARTTLS.ino b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Custom_Command/STARTTLS/STARTTLS.ino new file mode 100644 index 000000000..64788c799 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Custom_Command/STARTTLS/STARTTLS.ino @@ -0,0 +1,268 @@ + + +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt +*/ + +// This example showes how to send Email using custom commands. + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +#include + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +/** For Gmail, the app password will be used for log in + * Check out https://github.com/mobizt/ESP-Mail-Client#gmail-smtp-and-imap-required-app-passwords-to-sign-in + * + * For Yahoo mail, log in to your yahoo mail in web browser and generate app password by go to + * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc + * + * To use Gmai and Yahoo's App Password to sign in, define the AUTHOR_PASSWORD with your App Password + * and AUTHOR_EMAIL with your account email. + */ + +/** The smtp host name e.g. smtp.gmail.com for GMail or smtp.office365.com for Outlook or smtp.mail.yahoo.com */ +#define SMTP_HOST "" + +/** The smtp port e.g. + * 25 or esp_mail_smtp_port_25 + * 465 or esp_mail_smtp_port_465 // port 465 is not available for Outlook.com + * 587 or esp_mail_smtp_port_587 + */ +#define SMTP_PORT esp_mail_smtp_port_587 // for STARTTLS + +/* The log in credentials */ +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" + +/* Declare the global used SMTPSession object for SMTP transport */ +SMTPSession smtp; + +const char rootCACert[] PROGMEM = "-----BEGIN CERTIFICATE-----\n" + "-----END CERTIFICATE-----\n"; + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) +WiFiMulti multi; +#endif + +void customCommandCallback(SMTP_Response res) +{ + + // The res.id is the command identifier number that use to identify the source of command. + + // The command identifier number can be set via the last parameter of customConnect and sendCustomCommand functions. + + // If command identifier number was not set in those functions, the res.id received will be auto increased and begins with 0 + + MailClient.printf("> C: Command ID %d\n", res.id); + MailClient.printf("< S: %s\n", res.text.c_str()); + + if (res.statusCode > 0) + { + MailClient.printf("> C: Response finished with status code %d\n\n", res.statusCode); + } +} + +void setup() +{ + + Serial.begin(115200); + +#if defined(ARDUINO_ARCH_SAMD) + while (!Serial) + ; +#endif + + Serial.println(); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + multi.addAP(WIFI_SSID, WIFI_PASSWORD); + multi.run(); +#else + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Connecting to Wi-Fi"); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + unsigned long ms = millis(); +#endif + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + if (millis() - ms > 10000) + break; +#endif + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + /* Set the network reconnection option */ + MailClient.networkReconnect(true); + + // The WiFi credentials are required for Pico W + // due to it does not have reconnect feature. +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + MailClient.clearAP(); + MailClient.addAP(WIFI_SSID, WIFI_PASSWORD); +#endif + + /* Declare the Session_Config for user defined session credentials */ + Session_Config config; + + /* Set the session config */ + config.server.host_name = SMTP_HOST; + config.server.port = SMTP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + + bool tls = false; + + /* Connect to the server */ + if (smtp.customConnect(&config /* session credentials */, customCommandCallback) != 220) + { + Serial.println("! E: Unable to connect to server"); + return; + } + +init: + + if (smtp.sendCustomCommand(F("EHLO 127.0.0.1"), customCommandCallback) != 250) + { + smtp.closeSession(); + return; + } + + // Only for SMTP port 587 in supported server that accepts STARTTLS + + if (!tls) + { + if (smtp.sendCustomCommand(F("STARTTLS"), customCommandCallback) != 220) + { + smtp.closeSession(); + return; + } + + tls = true; + + // Send greeting again + goto init; + } + + if (smtp.sendCustomCommand(F("AUTH LOGIN"), customCommandCallback) != 334) + { + smtp.closeSession(); + return; + } + + if (smtp.sendCustomCommand(MailClient.toBase64(config.login.email), customCommandCallback) != 334) + { + smtp.closeSession(); + return; + } + + if (smtp.sendCustomCommand(MailClient.toBase64(config.login.password), customCommandCallback) != 235) + { + smtp.closeSession(); + return; + } + + if (smtp.isAuthenticated()) + Serial.println("Successfully logged in.\n"); + else + Serial.println("Connected with no Auth.\n"); + + // Please don't forget to change sender@xxxxxx.com to your email + if (smtp.sendCustomCommand(F("MAIL FROM:"), customCommandCallback) != 250) + { + smtp.closeSession(); + return; + } + + // Please don't forget to change recipient@xxxxx.com with your recipient email + if (smtp.sendCustomCommand(F("RCPT TO:"), customCommandCallback) != 250) + { + smtp.closeSession(); + return; + } + + if (smtp.sendCustomCommand(F("DATA"), customCommandCallback) != 354) + { + smtp.closeSession(); + return; + } + + if (!smtp.sendCustomData(F("Subject: Test sending Email\r\n"))) + { + smtp.closeSession(); + return; + } + + if (!smtp.sendCustomData(F("Hello World!\r\n"))) + { + smtp.closeSession(); + return; + } + + if (smtp.sendCustomCommand(F("."), customCommandCallback) != 250) + { + smtp.closeSession(); + return; + } + + // Do not use this command in ESP8266 due to memory leaks in ESP8266 core BearSSL. + // smtp.sendCustomCommand(F("QUIT"), customCommandCallback); + + smtp.closeSession(); + + // to clear sending result log + // smtp.sendingResult.clear(); + + MailClient.printf("Free Heap: %d\n", MailClient.getFreeHeap()); +} + +void loop() +{ +} diff --git a/lib/libesp32/ESP-Mail-Client/examples/SMTP/Custom_Ports/Custom_Ports.ino b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Custom_Ports/Custom_Ports.ino new file mode 100644 index 000000000..95b1b0330 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Custom_Ports/Custom_Ports.ino @@ -0,0 +1,376 @@ + +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt +*/ + +// This example showes how to send text Email via the custom port. + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +#include + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +/** For Gmail, the app password will be used for log in + * Check out https://github.com/mobizt/ESP-Mail-Client#gmail-smtp-and-imap-required-app-passwords-to-sign-in + * + * For Yahoo mail, log in to your yahoo mail in web browser and generate app password by go to + * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc + * + * To use Gmai and Yahoo's App Password to sign in, define the AUTHOR_PASSWORD with your App Password + * and AUTHOR_EMAIL with your account email. + */ + +/** The smtp host name e.g. smtp.gmail.com for GMail or smtp.office365.com for Outlook or smtp.mail.yahoo.com */ +#define SMTP_HOST "" + +/** The smtp port e.g. + * 25 or esp_mail_smtp_port_25 + * 465 or esp_mail_smtp_port_465 + * 587 or esp_mail_smtp_port_587 + */ +#define SMTP_PORT 2525 // non-standard port (TLS) + +/* The log in credentials */ +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" + +/* Recipient email address */ +#define RECIPIENT_EMAIL "" + +/* Declare the global used SMTPSession object for SMTP transport */ +SMTPSession smtp; + +/* Callback function to get the Email sending status */ +void smtpCallback(SMTP_Status status); + +const char rootCACert[] PROGMEM = "-----BEGIN CERTIFICATE-----\n" + "-----END CERTIFICATE-----\n"; + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) +WiFiMulti multi; +#endif + +void setup() +{ + + Serial.begin(115200); + +#if defined(ARDUINO_ARCH_SAMD) + while (!Serial) + ; +#endif + + Serial.println(); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + multi.addAP(WIFI_SSID, WIFI_PASSWORD); + multi.run(); +#else + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Connecting to Wi-Fi"); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + unsigned long ms = millis(); +#endif + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + if (millis() - ms > 10000) + break; +#endif + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + /* Set the network reconnection option */ + MailClient.networkReconnect(true); + + // The WiFi credentials are required for Pico W + // due to it does not have reconnect feature. +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + MailClient.clearAP(); + MailClient.addAP(WIFI_SSID, WIFI_PASSWORD); +#endif + + /** Enable the debug via Serial port + * 0 for no debugging + * 1 for basic level debugging + * + * Debug port can be changed via ESP_MAIL_DEFAULT_DEBUG_PORT in ESP_Mail_FS.h + */ + smtp.debug(1); + + /* Set the callback function to get the sending results */ + smtp.callback(smtpCallback); + + /* Declare the Session_Config for user defined session credentials */ + Session_Config config; + + /* Set the session config */ + config.server.host_name = SMTP_HOST; + config.server.port = SMTP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + + /** Assign your host name or you public IPv4 or IPv6 only + * as this is the part of EHLO/HELO command to identify the client system + * to prevent connection rejection. + * If host name or public IP is not available, ignore this or + * use loopback address "127.0.0.1". + * + * Assign any text to this option may cause the connection rejection. + */ + config.login.user_domain = F("127.0.0.1"); + + /* + Set the NTP config time + For times east of the Prime Meridian use 0-12 + For times west of the Prime Meridian add 12 to the offset. + Ex. American/Denver GMT would be -6. 6 + 12 = 18 + See https://en.wikipedia.org/wiki/Time_zone for a list of the GMT/UTC timezone offsets + */ + config.time.ntp_server = F("pool.ntp.org,time.nist.gov"); + config.time.gmt_offset = 3; + config.time.day_light_offset = 0; + + /** Set the ports and protocols + * This allows non-standard port to work with this library + * The port that assigned with config.server.port will map with the + * protocol assigned here + */ + + config.ports_functions.list = new port_function[4]; + config.ports_functions.size = 4; + + config.ports_functions.list[0].port = 25; + config.ports_functions.list[0].protocol = esp_mail_protocol_plain_text; + + config.ports_functions.list[1].port = 465; + config.ports_functions.list[1].protocol = esp_mail_protocol_ssl; + + config.ports_functions.list[2].port = 587; + config.ports_functions.list[2].protocol = esp_mail_protocol_tls; + + config.ports_functions.list[3].port = 2525; + config.ports_functions.list[3].protocol = esp_mail_protocol_tls; + + /** In ESP32, timezone environment will not keep after wake up boot from sleep. + * The local time will equal to GMT time. + * + * To sync or set time with NTP server with the valid local time after wake up boot, + * set both gmt and day light offsets to 0 and assign the timezone environment string e.g. + + config.time.ntp_server = F("pool.ntp.org,time.nist.gov"); + config.time.gmt_offset = 0; + config.time.day_light_offset = 0; + config.time.timezone_env_string = "JST-9"; // for Tokyo + + * The library will get (sync) the time from NTP server without GMT time offset adjustment + * and set the timezone environment variable later. + * + * This timezone environment string will be stored to flash or SD file named "/tz_env.txt" + * which set via config.time.timezone_file. + * + * See the timezone environment string list from + * https://github.com/nayarsystems/posix_tz_db/blob/master/zones.csv + * + */ + + /* Declare the message class */ + SMTP_Message message; + + /* Set the message headers */ + message.sender.name = F("ESP Mail"); // This witll be used with 'MAIL FROM' command and 'From' header field. + message.sender.email = AUTHOR_EMAIL; // This witll be used with 'From' header field. + message.subject = F("Test sending plain text Email"); + message.addRecipient(F("Someone"), RECIPIENT_EMAIL); // This will be used with RCPT TO command and 'To' header field. + + String textMsg = "This is simple plain text message"; + message.text.content = textMsg; + + /** If the message to send is a large string, to reduce the memory used from internal copying while sending, + * you can assign string to message.text.blob by cast your string to uint8_t array like this + * + * String myBigString = "..... ......"; + * message.text.blob.data = (uint8_t *)myBigString.c_str(); + * message.text.blob.size = myBigString.length(); + * + * or assign string to message.text.nonCopyContent, like this + * + * message.text.nonCopyContent = myBigString.c_str(); + * + * Only base64 encoding is supported for content transfer encoding in this case. + */ + + /** The Plain text message character set e.g. + * us-ascii + * utf-8 + * utf-7 + * The default value is utf-8 + */ + message.text.charSet = F("us-ascii"); + + /** The content transfer encoding e.g. + * enc_7bit or "7bit" (not encoded) + * enc_qp or "quoted-printable" (encoded) + * enc_base64 or "base64" (encoded) + * enc_binary or "binary" (not encoded) + * enc_8bit or "8bit" (not encoded) + * The default value is "7bit" + */ + message.text.transfer_encoding = Content_Transfer_Encoding::enc_7bit; + + // If this is a reply message + // message.in_reply_to = ""; + // message.references = " "; + + /** The message priority + * esp_mail_smtp_priority_high or 1 + * esp_mail_smtp_priority_normal or 3 + * esp_mail_smtp_priority_low or 5 + * The default value is esp_mail_smtp_priority_low + */ + message.priority = esp_mail_smtp_priority::esp_mail_smtp_priority_low; + + // message.response.reply_to = "someone@somemail.com"; + // message.response.return_path = "someone@somemail.com"; + + /** The Delivery Status Notifications e.g. + * esp_mail_smtp_notify_never + * esp_mail_smtp_notify_success + * esp_mail_smtp_notify_failure + * esp_mail_smtp_notify_delay + * The default value is esp_mail_smtp_notify_never + */ + // message.response.notify = esp_mail_smtp_notify_success | esp_mail_smtp_notify_failure | esp_mail_smtp_notify_delay; + + /* Set the custom message header */ + message.addHeader(F("Message-ID: ")); + + // For Root CA certificate verification (ESP8266 and ESP32 only) + // config.certificate.cert_data = rootCACert; + // or + // config.certificate.cert_file = "/path/to/der/file"; + // config.certificate.cert_file_storage_type = esp_mail_file_storage_type_flash; // esp_mail_file_storage_type_sd + // config.certificate.verify = true; + + // The WiFiNINA firmware the Root CA certification can be added via the option in Firmware update tool in Arduino IDE + + /* Connect to server with the session config */ + + // Library will be trying to sync the time with NTP server if time is never sync or set. + // This is 10 seconds blocking process. + // If time reading was timed out, the error "NTP server time reading timed out" will show via debug and callback function. + // You can manually sync time by yourself with NTP library or calling configTime in ESP32 and ESP8266. + // Time can be set manually with provided timestamp to function smtp.setSystemTime. + + /* Connect to the server */ + if (!smtp.connect(&config)) + { + MailClient.printf("Connection error, Status Code: %d, Error Code: %d, Reason: %s", smtp.statusCode(), smtp.errorCode(), smtp.errorReason().c_str()); + return; + } + + if (smtp.isAuthenticated()) + Serial.println("\nSuccessfully logged in."); + else + Serial.println("\nConnected with no Auth."); + + /* Start sending Email and close the session */ + if (!MailClient.sendMail(&smtp, &message)) + MailClient.printf("Error, Status Code: %d, Error Code: %d, Reason: %s", smtp.statusCode(), smtp.errorCode(), smtp.errorReason().c_str()); + + // to clear sending result log + // smtp.sendingResult.clear(); + + MailClient.printf("Free Heap: %d\n", MailClient.getFreeHeap()); +} + +void loop() +{ +} + +/* Callback function to get the Email sending status */ +void smtpCallback(SMTP_Status status) +{ + /* Print the current status */ + Serial.println(status.info()); + + /* Print the sending result */ + if (status.success()) + { + // MailClient.printf used in the examples is for format printing via debug Serial port + // that works for all supported Arduino platform SDKs e.g. SAMD, ESP32 and ESP8266. + // In ESP8266 and ESP32, you can use Serial.printf directly. + + Serial.println("----------------"); + MailClient.printf("Message sent success: %d\n", status.completedCount()); + MailClient.printf("Message sent failed: %d\n", status.failedCount()); + Serial.println("----------------\n"); + + for (size_t i = 0; i < smtp.sendingResult.size(); i++) + { + /* Get the result item */ + SMTP_Result result = smtp.sendingResult.getItem(i); + + // In case, ESP32, ESP8266 and SAMD device, the timestamp get from result.timestamp should be valid if + // your device time was synched with NTP server. + // Other devices may show invalid timestamp as the device time was not set i.e. it will show Jan 1, 1970. + // You can call smtp.setSystemTime(xxx) to set device time manually. Where xxx is timestamp (seconds since Jan 1, 1970) + + MailClient.printf("Message No: %d\n", i + 1); + MailClient.printf("Status: %s\n", result.completed ? "success" : "failed"); + MailClient.printf("Date/Time: %s\n", MailClient.Time.getDateTimeString(result.timestamp, "%B %d, %Y %H:%M:%S").c_str()); + MailClient.printf("Recipient: %s\n", result.recipients.c_str()); + MailClient.printf("Subject: %s\n", result.subject.c_str()); + } + Serial.println("----------------\n"); + + // You need to clear sending result as the memory usage will grow up. + smtp.sendingResult.clear(); + } +} diff --git a/lib/libesp32/ESP-Mail-Client/examples/SMTP/Ethernet/ESP32/Send_Text/Send_Text.ino b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Ethernet/ESP32/Send_Text/Send_Text.ino new file mode 100644 index 000000000..60a05519e --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Ethernet/ESP32/Send_Text/Send_Text.ino @@ -0,0 +1,287 @@ + +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt +*/ + +// This example shows how to send Email using ESP32 and LAN8720 Ethernet module. + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +/** + * There are many sources for LAN8720 and ESP32 interconnection on the internet which may + * work for your LAN8720 board. + * + * Some methods worked unless no IP is available. + * + * This modification and interconnection provided in this example are mostly worked as + * the 50 MHz clock was created internally in ESP32 which GPIO 17 is set to be output of this clock + * and feeds to the LAN8720 chip XTAL input. + * + * The on-board LAN8720 50 MHz XTAL chip will be disabled by connect its enable pin or pin 1 to GND. + * + * Please see the images in the folder "modified_LAN8720_board_images" for how to modify the LAN8720 board. + * + * The LAN8720 Ethernet modified board and ESP32 board wiring connection. + * + * ESP32 LAN8720 + * + * GPIO17 - EMAC_CLK_OUT_180 nINT/REFCLK - LAN8720 XTAL1/CLKIN 4k7 Pulldown + * GPIO22 - EMAC_TXD1 TX1 + * GPIO19 - EMAC_TXD0 TX0 + * GPIO21 - EMAC_TX_EN TX_EN + * GPIO26 - EMAC_RXD1 RX1 + * GPIO25 - EMAC_RXD0 RX0 + * GPIO27 - EMAC_RX_DV CRS + * GPIO23 - MDC MDC + * GPIO18 - MDIO MDIO + * GND GND + * 3V3 VCC + * + * + * ESP32 Arduino SDK native Ethernet using ETH.h is currently support Ethernet PHY chips + * + * LAN8720, TLK101, RTL8201, DP83848, DM9051, KSZ8041 and KSZ8081. + * + * For ESP32 and other SPI MAC Ethernet modules, the external Client was used, + * see examples/SMTP/External_Client/EthernetClient/EthernetClient.ino + * + */ + +#include + +#ifdef ETH_CLK_MODE +#undef ETH_CLK_MODE +#endif +#define ETH_CLK_MODE ETH_CLOCK_GPIO17_OUT // RMII clock output from GPIO17 + +// Pin# of the enable signal for the external crystal oscillator (-1 to disable) +#define ETH_POWER_PIN -1 + +// Type of the Ethernet PHY (LAN8720 or TLK110) +#define ETH_TYPE ETH_PHY_LAN8720 + +// I²C-address of Ethernet PHY (0 or 1 for LAN8720, 31 for TLK110) +#define ETH_ADDR 1 + +// Pin# of the I²C clock signal for the Ethernet PHY +#define ETH_MDC_PIN 23 + +// Pin# of the I²C IO signal for the Ethernet PHY +#define ETH_MDIO_PIN 18 + +static bool eth_connected = false; + +#define SMTP_HOST "" +#define SMTP_PORT 25 + +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" +#define RECIPIENT_EMAIL "" + +SMTPSession smtp; + +void smtpCallback(SMTP_Status status); + +unsigned long sendMillis = 0; + +void WiFiEvent(WiFiEvent_t event) +{ + // Do not run any function here to prevent stack overflow or nested interrupt + +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 4, 0) + + switch (event) + { + case ARDUINO_EVENT_ETH_START: + Serial.println("ETH Started"); + // set eth hostname here + ETH.setHostname("esp32-ethernet"); + break; + case ARDUINO_EVENT_ETH_CONNECTED: + Serial.println("ETH Connected"); + break; + case ARDUINO_EVENT_ETH_GOT_IP: + Serial.print("ETH MAC: "); + Serial.print(ETH.macAddress()); + Serial.print(", IPv4: "); + Serial.print(ETH.localIP()); + if (ETH.fullDuplex()) + { + Serial.print(", FULL_DUPLEX"); + } + Serial.print(", "); + Serial.print(ETH.linkSpeed()); + Serial.println("Mbps"); + eth_connected = true; + break; + case ARDUINO_EVENT_ETH_DISCONNECTED: + Serial.println("ETH Disconnected"); + eth_connected = false; + break; + case ARDUINO_EVENT_ETH_STOP: + Serial.println("ETH Stopped"); + eth_connected = false; + break; + default: + break; + } + +#else + switch (event) + { + case SYSTEM_EVENT_ETH_START: + Serial.println("ETH Started"); + // set eth hostname here + ETH.setHostname("esp32-ethernet"); + break; + case SYSTEM_EVENT_ETH_CONNECTED: + Serial.println("ETH Connected"); + break; + case SYSTEM_EVENT_ETH_GOT_IP: + Serial.print("ETH MAC: "); + Serial.print(ETH.macAddress()); + Serial.print(", IPv4: "); + Serial.print(ETH.localIP()); + if (ETH.fullDuplex()) + { + Serial.print(", FULL_DUPLEX"); + } + Serial.print(", "); + Serial.print(ETH.linkSpeed()); + Serial.println("Mbps"); + eth_connected = true; + break; + case SYSTEM_EVENT_ETH_DISCONNECTED: + Serial.println("ETH Disconnected"); + eth_connected = false; + break; + case SYSTEM_EVENT_ETH_STOP: + Serial.println("ETH Stopped"); + eth_connected = false; + break; + default: + break; + } +#endif +} + +void sendMail() +{ + + smtp.debug(1); + + smtp.callback(smtpCallback); + + Session_Config config; + + config.server.host_name = SMTP_HOST; + config.server.port = SMTP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + + config.login.user_domain = F("127.0.0.1"); + + /* + Set the NTP config time + For times east of the Prime Meridian use 0-12 + For times west of the Prime Meridian add 12 to the offset. + Ex. American/Denver GMT would be -6. 6 + 12 = 18 + See https://en.wikipedia.org/wiki/Time_zone for a list of the GMT/UTC timezone offsets + */ + config.time.ntp_server = F("pool.ntp.org,time.nist.gov"); + config.time.gmt_offset = 3; + config.time.day_light_offset = 0; + + SMTP_Message message; + + message.sender.name = F("ESP Mail"); + message.sender.email = AUTHOR_EMAIL; + message.subject = F("Test sending plain text Email"); + message.addRecipient(F("Someone"), RECIPIENT_EMAIL); + + String textMsg = "This is simple plain text message"; + message.text.content = textMsg; + + if (!smtp.connect(&config)) + { + MailClient.printf("Connection error, Status Code: %d, Error Code: %d, Reason: %s", smtp.statusCode(), smtp.errorCode(), smtp.errorReason().c_str()); + return; + } + + if (smtp.isAuthenticated()) + Serial.println("\nSuccessfully logged in."); + else + Serial.println("\nConnected with no Auth."); + + if (!MailClient.sendMail(&smtp, &message)) + MailClient.printf("Error, Status Code: %d, Error Code: %d, Reason: %s", smtp.statusCode(), smtp.errorCode(), smtp.errorReason().c_str()); +} + +void setup() +{ + Serial.begin(115200); + Serial.println(); + + WiFi.onEvent(WiFiEvent); + + ETH.begin(ETH_ADDR, ETH_POWER_PIN, ETH_MDC_PIN, ETH_MDIO_PIN, ETH_TYPE, ETH_CLK_MODE); +} + +void loop() +{ + if (eth_connected && (millis() - sendMillis > 300000 || sendMillis == 0)) + { + sendMillis = millis(); + sendMail(); + } +} + +void smtpCallback(SMTP_Status status) +{ + Serial.println(status.info()); + + if (status.success()) + { + + Serial.println("----------------"); + MailClient.printf("Message sent success: %d\n", status.completedCount()); + MailClient.printf("Message sent failed: %d\n", status.failedCount()); + Serial.println("----------------\n"); + + for (size_t i = 0; i < smtp.sendingResult.size(); i++) + { + + SMTP_Result result = smtp.sendingResult.getItem(i); + + MailClient.printf("Message No: %d\n", i + 1); + MailClient.printf("Status: %s\n", result.completed ? "success" : "failed"); + MailClient.printf("Date/Time: %s\n", MailClient.Time.getDateTimeString(result.timestamp, "%B %d, %Y %H:%M:%S").c_str()); + MailClient.printf("Recipient: %s\n", result.recipients.c_str()); + MailClient.printf("Subject: %s\n", result.subject.c_str()); + } + Serial.println("----------------\n"); + smtp.sendingResult.clear(); + } +} diff --git a/lib/libesp32/lib_mail/examples/ESP32_Ethernet_Send_Text/modified_LAN8720_board_images/lan8720_modified_board.png b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Ethernet/ESP32/Send_Text/modified_LAN8720_board_images/lan8720_modified_board.png similarity index 100% rename from lib/libesp32/lib_mail/examples/ESP32_Ethernet_Send_Text/modified_LAN8720_board_images/lan8720_modified_board.png rename to lib/libesp32/ESP-Mail-Client/examples/SMTP/Ethernet/ESP32/Send_Text/modified_LAN8720_board_images/lan8720_modified_board.png diff --git a/lib/libesp32/lib_mail/examples/ESP32_Ethernet_Send_Text/modified_LAN8720_board_images/lan8720_modified_schematic.png b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Ethernet/ESP32/Send_Text/modified_LAN8720_board_images/lan8720_modified_schematic.png similarity index 100% rename from lib/libesp32/lib_mail/examples/ESP32_Ethernet_Send_Text/modified_LAN8720_board_images/lan8720_modified_schematic.png rename to lib/libesp32/ESP-Mail-Client/examples/SMTP/Ethernet/ESP32/Send_Text/modified_LAN8720_board_images/lan8720_modified_schematic.png diff --git a/lib/libesp32/ESP-Mail-Client/examples/SMTP/Ethernet/ESP8266/Send_Text/Send_Text.ino b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Ethernet/ESP8266/Send_Text/Send_Text.ino new file mode 100644 index 000000000..4f677fa88 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Ethernet/ESP8266/Send_Text/Send_Text.ino @@ -0,0 +1,230 @@ + +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt +*/ + +// This example shows how to send Email using ESP8266 and ENC28J60 Ethernet module. + +// This example requires ESP8266 Arduino Core SDK v3.x.x + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +/** + * + * The ENC28J60 Ethernet module and ESP8266 board, SPI port wiring connection. + * + * ESP8266 (Wemos D1 Mini or NodeMCU) ENC28J60 + * + * GPIO12 (D6) - MISO SO + * GPIO13 (D7) - MOSI SI + * GPIO14 (D5) - SCK SCK + * GPIO16 (D0) - CS CS + * GND GND + * 3V3 VCC + * + */ + +#if defined(ESP8266) +#include +#endif + +#include +// #include +// #include + +/** + * For ENC28J60 ethernet module, uncomment this line in ESP_Mail_FS.h + #define ENABLE_ESP8266_ENC28J60_ETH + + * For W5500 ethernet module, uncomment this line in ESP_Mail_FS.h + #define ENABLE_ESP8266_W5500_ETH + + * For W5100 ethernet module, uncomment this line in ESP_Mail_FS.h + #define ENABLE_ESP8266_W5100_ETH +*/ + +#include + +#define SMTP_HOST "" +#define SMTP_PORT 25 + +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" +#define RECIPIENT_EMAIL "" + +SMTPSession smtp; + +void smtpCallback(SMTP_Status status); + +unsigned long sendMillis = 0; + +#ifdef ESP8266_CORE_SDK_V3_X_X + +#define ETH_CS_PIN 16 // D0 +ENC28J60lwIP eth(ETH_CS_PIN); +// Wiznet5100lwIP eth(ETH_CS_PIN); +// Wiznet5500lwIP eth(ETH_CS_PIN); + +#endif + +void sendMail() +{ + + smtp.debug(1); + + smtp.callback(smtpCallback); + + Session_Config config; + + /* Assign the pointer to Ethernet module lwip interface */ +#ifdef ESP8266_CORE_SDK_V3_X_X +#if defined(ENABLE_ESP8266_ENC28J60_ETH) + config.spi_ethernet_module.enc28j60 = ð +#elif defined(ENABLE_ESP8266_W5100_ETH) + config.spi_ethernet_module.w5100 = ð +#elif defined(ENABLE_ESP8266_W5500_ETH) + config.spi_ethernet_module.w5500 = ð +#endif +#endif + + config.server.host_name = SMTP_HOST; + config.server.port = SMTP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + + config.login.user_domain = F("127.0.0.1"); + + /* + Set the NTP config time + For times east of the Prime Meridian use 0-12 + For times west of the Prime Meridian add 12 to the offset. + Ex. American/Denver GMT would be -6. 6 + 12 = 18 + See https://en.wikipedia.org/wiki/Time_zone for a list of the GMT/UTC timezone offsets + */ + config.time.ntp_server = F("pool.ntp.org,time.nist.gov"); + config.time.gmt_offset = 3; + config.time.day_light_offset = 0; + + SMTP_Message message; + + message.sender.name = F("ESP Mail"); + message.sender.email = AUTHOR_EMAIL; + message.subject = F("Test sending plain text Email"); + message.addRecipient(F("Someone"), RECIPIENT_EMAIL); + + String textMsg = "This is simple plain text message"; + message.text.content = textMsg; + + if (!smtp.connect(&config)) + { + MailClient.printf("Connection error, Status Code: %d, Error Code: %d, Reason: %s", smtp.statusCode(), smtp.errorCode(), smtp.errorReason().c_str()); + return; + } + + if (smtp.isAuthenticated()) + Serial.println("\nSuccessfully logged in."); + else + Serial.println("\nConnected with no Auth."); + + if (!MailClient.sendMail(&smtp, &message)) + MailClient.printf("Error, Status Code: %d, Error Code: %d, Reason: %s", smtp.statusCode(), smtp.errorCode(), smtp.errorReason().c_str()); +} + +void setup() +{ + Serial.begin(115200); + Serial.println(); + +#ifdef ESP8266_CORE_SDK_V3_X_X + + SPI.begin(); + SPI.setClockDivider(SPI_CLOCK_DIV4); // 4 MHz? + SPI.setBitOrder(MSBFIRST); + SPI.setDataMode(SPI_MODE0); + eth.setDefault(); // use ethernet for default route + if (!eth.begin()) + { + Serial.println("ethernet hardware not found ... sleeping"); + while (1) + { + delay(1000); + } + } + else + { + Serial.print("connecting ethernet"); + while (!eth.connected()) + { + Serial.print("."); + delay(1000); + } + } + Serial.println(); + Serial.print("ethernet IP address: "); + Serial.println(eth.localIP()); + +#else + Serial.println("This example requires ESP8266 Arduino Core SDK v3.x.x, please update."); +#endif +} + +void loop() +{ +#ifdef ESP8266_CORE_SDK_V3_X_X + if (millis() - sendMillis > 300000 || sendMillis == 0) + { + sendMillis = millis(); + sendMail(); + } +#endif +} + +void smtpCallback(SMTP_Status status) +{ + Serial.println(status.info()); + + if (status.success()) + { + + Serial.println("----------------"); + MailClient.printf("Message sent success: %d\n", status.completedCount()); + MailClient.printf("Message sent failed: %d\n", status.failedCount()); + Serial.println("----------------\n"); + + for (size_t i = 0; i < smtp.sendingResult.size(); i++) + { + + SMTP_Result result = smtp.sendingResult.getItem(i); + + MailClient.printf("Message No: %d\n", i + 1); + MailClient.printf("Status: %s\n", result.completed ? "success" : "failed"); + MailClient.printf("Date/Time: %s\n", MailClient.Time.getDateTimeString(result.timestamp, "%B %d, %Y %H:%M:%S").c_str()); + MailClient.printf("Recipient: %s\n", result.recipients.c_str()); + MailClient.printf("Subject: %s\n", result.subject.c_str()); + } + Serial.println("----------------\n"); + smtp.sendingResult.clear(); + } +} \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/examples/SMTP/External_Client/EthernetClient/EthernetClient.ino b/lib/libesp32/ESP-Mail-Client/examples/SMTP/External_Client/EthernetClient/EthernetClient.ino new file mode 100644 index 000000000..ec9fd07ef --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/SMTP/External_Client/EthernetClient/EthernetClient.ino @@ -0,0 +1,224 @@ +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt +*/ + +/** + * This example shows how to send Email using EthernetClient. + * + * This example used ESP32 and WIZnet W5500 Ethernet module. + * + * For ESP32 and LAN8720 see examples/SMTP/Ethernet/ESP32/Send_Text.ino + * + * ESP32 Arduino SDK native Ethernet using ETH.h is currently support Ethernet PHY chips + * + * LAN8720, TLK101, RTL8201, DP83848, DM9051, KSZ8041 and KSZ8081. + * + * For ESP8266, the native Ethernet is currently supported ENC28J60, W5100 and W5500. + * + * You do not need to set external Client with native Ethernet support PHY/MAC chips. + * + * + */ + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +#include + +#include + +#include + +#define SMTP_HOST "smtp.gmail.com" +#define SMTP_PORT 587 + +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" +#define RECIPIENT_EMAIL "" + +#define WIZNET_RESET_PIN 26 // Connect W5500 Reset pin to GPIO 26 of ESP32 +#define WIZNET_CS_PIN 5 // Connect W5500 CS pin to GPIO 5 of ESP32 +#define WIZNET_MISO_PIN 19 // Connect W5500 MISO pin to GPIO 19 of ESP32 +#define WIZNET_MOSI_PIN 23 // Connect W5500 MOSI pin to GPIO 23 of ESP32 +#define WIZNET_SCLK_PIN 18 // Connect W5500 SCLK pin to GPIO 18 of ESP32 + +unsigned long sentMillis = 0; + +const int analog_pin = 34; + +uint8_t Eth_MAC[] = {0x02, 0xF0, 0x0D, 0xBE, 0xEF, 0x01}; + +SMTPSession smtp; + +EthernetClient eth_client; + +void smtpCallback(SMTP_Status status); + +void ResetEthernet() +{ + Serial.println("Resetting WIZnet W5500 Ethernet Board... "); + pinMode(WIZNET_RESET_PIN, OUTPUT); + digitalWrite(WIZNET_RESET_PIN, HIGH); + delay(200); + digitalWrite(WIZNET_RESET_PIN, LOW); + delay(50); + digitalWrite(WIZNET_RESET_PIN, HIGH); + delay(200); +} + +void networkConnection() +{ + + Ethernet.init(WIZNET_CS_PIN); + + ResetEthernet(); + + Serial.println("Starting Ethernet connection..."); + Ethernet.begin(Eth_MAC); + + unsigned long to = millis(); + + while (Ethernet.linkStatus() == LinkOFF || millis() - to < 2000) + { + delay(100); + } + + if (Ethernet.linkStatus() == LinkON) + { + Serial.print("Connected with IP "); + Serial.println(Ethernet.localIP()); + } + else + { + Serial.println("Can't connect"); + } +} + +void networkStatusRequestCallback() +{ + smtp.setNetworkStatus(Ethernet.linkStatus() == LinkON); +} + +void sendEmail() +{ + + Session_Config config; + + config.server.host_name = SMTP_HOST; + config.server.port = SMTP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + + config.login.user_domain = F("127.0.0.1"); + + SMTP_Message message; + + message.sender.name = F("ESP Mail"); + message.sender.email = AUTHOR_EMAIL; + message.subject = F("Test sending plain text Email"); + + message.addRecipient(F("Someone"), RECIPIENT_EMAIL); + + message.text.content = "This is simple plain text message"; + + smtp.setClient(ð_client); + + smtp.networkConnectionRequestCallback(networkConnection); + + smtp.networkStatusRequestCallback(networkStatusRequestCallback); + + if (!smtp.connect(&config)) + { + MailClient.printf("Connection error, Status Code: %d, Error Code: %d, Reason: %s", smtp.statusCode(), smtp.errorCode(), smtp.errorReason().c_str()); + return; + } + + if (smtp.isAuthenticated()) + Serial.println("\nSuccessfully logged in."); + else + Serial.println("\nConnected with no Auth."); + + if (!MailClient.sendMail(&smtp, &message)) + MailClient.printf("Error, Status Code: %d, Error Code: %d, Reason: %s", smtp.statusCode(), smtp.errorCode(), smtp.errorReason().c_str()); + + MailClient.printf("Free Heap: %d\n", MailClient.getFreeHeap()); +} + +void setup() +{ + + Serial.begin(115200); + + Serial.println(); + + networkConnection(); + + /* + For internal NTP client + For times east of the Prime Meridian use 0-12 + For times west of the Prime Meridian add 12 to the offset. + Ex. American/Denver GMT would be -6. 6 + 12 = 18 + See https://en.wikipedia.org/wiki/Time_zone for a list of the GMT/UTC timezone offsets + */ + MailClient.setUDPClient(&udp_client, 0 /* GMT offset */); + + smtp.debug(1); + + smtp.callback(smtpCallback); +} + +void loop() +{ + if (millis() - sentMillis > 120000 || sentMillis == 0) + { + sentMillis = millis(); + sendEmail(); + } +} + +void smtpCallback(SMTP_Status status) +{ + Serial.println(status.info()); + + if (status.success()) + { + Serial.println("----------------"); + MailClient.printf("Message sent success: %d\n", status.completedCount()); + MailClient.printf("Message sent failed: %d\n", status.failedCount()); + Serial.println("----------------\n"); + + for (size_t i = 0; i < smtp.sendingResult.size(); i++) + { + SMTP_Result result = smtp.sendingResult.getItem(i); + + MailClient.printf("Message No: %d\n", i + 1); + MailClient.printf("Status: %s\n", result.completed ? "success" : "failed"); + MailClient.printf("Date/Time: %s\n", MailClient.Time.getDateTimeString(result.timestamp, "%B %d, %Y %H:%M:%S").c_str()); + MailClient.printf("Recipient: %s\n", result.recipients.c_str()); + MailClient.printf("Subject: %s\n", result.subject.c_str()); + } + Serial.println("----------------\n"); + smtp.sendingResult.clear(); + } +} \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/examples/SMTP/External_Client/GSMClient/GSMClient.ino b/lib/libesp32/ESP-Mail-Client/examples/SMTP/External_Client/GSMClient/GSMClient.ino new file mode 100644 index 000000000..9d1026d4e --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/SMTP/External_Client/GSMClient/GSMClient.ino @@ -0,0 +1,213 @@ + +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt + */ + +// This example used TTGO T-A7670 (ESP32 with SIMCom SIMA7670) and TinyGSMClient. + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +// To allow TinyGSM library integration, the following macro should be defined in src/ESP_Mail_FS.h or +// your custom config file src/Custom_ESP_Mail_FS.h. +// #define TINY_GSM_MODEM_SIM7600 + +#define TINY_GSM_MODEM_SIM7600 // SIMA7670 Compatible with SIM7600 AT instructions + +// Set serial for debug console (to the Serial Monitor, default speed 115200) +#define SerialMon Serial + +// Set serial for AT commands (to the module) +// Use Hardware Serial on Mega, Leonardo, Micro +#define SerialAT Serial1 + +// See all AT commands, if wanted +// #define DUMP_AT_COMMANDS + +// Define the serial console for debug prints, if needed +#define TINY_GSM_DEBUG SerialMon + +#define TINY_GSM_USE_GPRS true +#define TINY_GSM_USE_WIFI false + +// set GSM PIN, if any +#define GSM_PIN "" + +// Your GPRS credentials, if any +const char apn[] = "YourAPN"; +const char gprsUser[] = ""; +const char gprsPass[] = ""; + +#define uS_TO_S_FACTOR 1000000ULL // Conversion factor for micro seconds to seconds +#define TIME_TO_SLEEP 600 // Time ESP32 will go to sleep (in seconds) + +#define UART_BAUD 115200 +#define PIN_DTR 25 +#define PIN_TX 26 +#define PIN_RX 27 +#define PWR_PIN 4 +#define BAT_ADC 35 +#define BAT_EN 12 +#define PIN_RI 33 +#define PIN_DTR 25 +#define RESET 5 + +#define SD_MISO 2 +#define SD_MOSI 15 +#define SD_SCLK 14 +#define SD_CS 13 + +#include +#include + +TinyGsm modem(SerialAT); + +TinyGsmClient gsm_client(modem); + +#define SMTP_HOST "" +#define SMTP_PORT esp_mail_smtp_port_587 +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" +#define RECIPIENT_EMAIL "" + +SMTPSession smtp; + +void smtpCallback(SMTP_Status status); + +void setup() +{ + + SerialMon.begin(115200); + + smtp.debug(1); + + smtp.callback(smtpCallback); + + delay(10); + pinMode(BAT_EN, OUTPUT); + digitalWrite(BAT_EN, HIGH); + + // A7670 Reset + pinMode(RESET, OUTPUT); + digitalWrite(RESET, LOW); + delay(100); + digitalWrite(RESET, HIGH); + delay(3000); + digitalWrite(RESET, LOW); + + pinMode(PWR_PIN, OUTPUT); + digitalWrite(PWR_PIN, LOW); + delay(100); + digitalWrite(PWR_PIN, HIGH); + delay(1000); + digitalWrite(PWR_PIN, LOW); + + DBG("Wait..."); + + delay(3000); + + SerialAT.begin(UART_BAUD, SERIAL_8N1, PIN_RX, PIN_TX); + + // Restart takes quite some time + // To skip it, call init() instead of restart() + DBG("Initializing modem..."); + if (!modem.init()) + { + DBG("Failed to restart modem, delaying 10s and retrying"); + return; + } + + /* + 2 Automatic + 13 GSM Only + 14 WCDMA Only + 38 LTE Only + */ + modem.setNetworkMode(38); + if (modem.waitResponse(10000L) != 1) + { + DBG(" setNetworkMode faill"); + } + + String name = modem.getModemName(); + DBG("Modem Name:", name); + + String modemInfo = modem.getModemInfo(); + DBG("Modem Info:", modemInfo); + + Session_Config config; + + config.server.host_name = SMTP_HOST; + config.server.port = SMTP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + config.login.user_domain = F("127.0.0.1"); + + SMTP_Message message; + + message.sender.name = F("ESP Mail"); + message.sender.email = AUTHOR_EMAIL; + message.subject = F("Test sending plain text Email using GSM module"); + message.addRecipient(F("Someone"), RECIPIENT_EMAIL); + + message.text.content = "This is simple plain text message"; + + smtp.setGSMClient(&gsm_client, &modem, GSM_PIN, apn, gprsUser, gprsPass); + + smtp.connect(&config); + + if (!MailClient.sendMail(&smtp, &message)) + Serial.println("Error sending Email, " + smtp.errorReason()); +} + +void loop() +{ +} + +void smtpCallback(SMTP_Status status) +{ + Serial.println(status.info()); + + if (status.success()) + { + Serial.println("----------------"); + MailClient.printf("Message sent success: %d\n", status.completedCount()); + MailClient.printf("Message sent failed: %d\n", status.failedCount()); + Serial.println("----------------\n"); + + for (size_t i = 0; i < smtp.sendingResult.size(); i++) + { + SMTP_Result result = smtp.sendingResult.getItem(i); + + MailClient.printf("Message No: %d\n", i + 1); + MailClient.printf("Status: %s\n", result.completed ? "success" : "failed"); + MailClient.printf("Date/Time: %s\n", MailClient.Time.getDateTimeString(result.timestamp, "%B %d, %Y %H:%M:%S").c_str()); + MailClient.printf("Recipient: %s\n", result.recipients.c_str()); + MailClient.printf("Subject: %s\n", result.subject.c_str()); + } + Serial.println("----------------\n"); + + smtp.sendingResult.clear(); + } +} \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/examples/SMTP/External_Client/WiFiClient/WiFiClient.ino b/lib/libesp32/ESP-Mail-Client/examples/SMTP/External_Client/WiFiClient/WiFiClient.ino new file mode 100644 index 000000000..6e80e1101 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/SMTP/External_Client/WiFiClient/WiFiClient.ino @@ -0,0 +1,187 @@ + +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt +*/ + +// This example shows how to send Email using external WiFiClient. + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +#include + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +#define SMTP_HOST "" +#define SMTP_PORT esp_mail_smtp_port_587 +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" +#define RECIPIENT_EMAIL "" + +SMTPSession smtp; + +WiFiClient wifi_client; + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) +WiFiMulti multi; +#endif + +void smtpCallback(SMTP_Status status); + +void networkStatusRequestCallback() +{ + smtp.setNetworkStatus(WiFi.status() == WL_CONNECTED); +} + +void networkConnectionRequestCallback() +{ + Serial.println(); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + multi.addAP(WIFI_SSID, WIFI_PASSWORD); + multi.run(); +#else + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Connecting to Wi-Fi"); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + unsigned long ms = millis(); +#endif + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + if (millis() - ms > 10000) + break; +#endif + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); +} + +void setup() +{ + + Serial.begin(115200); + + networkConnectionRequestCallback(); + + MailClient.networkReconnect(true); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + MailClient.clearAP(); + MailClient.addAP(WIFI_SSID, WIFI_PASSWORD); +#endif + + smtp.debug(1); + + smtp.callback(smtpCallback); + + Session_Config config; + + config.server.host_name = SMTP_HOST; + config.server.port = SMTP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + config.login.user_domain = F("127.0.0.1"); + + config.time.ntp_server = F("pool.ntp.org,time.nist.gov"); + + smtp.setClient(&wifi_client); + + smtp.networkStatusRequestCallback(networkStatusRequestCallback); + + smtp.networkConnectionRequestCallback(networkConnectionRequestCallback); + + smtp.connect(&config); + + if (smtp.isAuthenticated()) + Serial.println("\nSuccessfully logged in."); + else + Serial.println("\nConnected with no Auth."); + + SMTP_Message message; + + message.sender.name = F("ESP Mail"); + message.sender.email = AUTHOR_EMAIL; + message.subject = F("Test sending plain text Email"); + message.addRecipient(F("Someone"), RECIPIENT_EMAIL); + + message.text.content = "This is simple plain text message"; + + if (!MailClient.sendMail(&smtp, &message)) + Serial.println("Error sending Email, " + smtp.errorReason()); + + MailClient.printf("Free Heap: %d\n", MailClient.getFreeHeap()); +} + +void loop() +{ +} + +void smtpCallback(SMTP_Status status) +{ + Serial.println(status.info()); + + if (status.success()) + { + Serial.println("----------------"); + MailClient.printf("Message sent success: %d\n", status.completedCount()); + MailClient.printf("Message sent failed: %d\n", status.failedCount()); + Serial.println("----------------\n"); + + for (size_t i = 0; i < smtp.sendingResult.size(); i++) + { + SMTP_Result result = smtp.sendingResult.getItem(i); + + MailClient.printf("Message No: %d\n", i + 1); + MailClient.printf("Status: %s\n", result.completed ? "success" : "failed"); + MailClient.printf("Date/Time: %s\n", MailClient.Time.getDateTimeString(result.timestamp, "%B %d, %Y %H:%M:%S").c_str()); + MailClient.printf("Recipient: %s\n", result.recipients.c_str()); + MailClient.printf("Subject: %s\n", result.subject.c_str()); + } + Serial.println("----------------\n"); + smtp.sendingResult.clear(); + } +} diff --git a/lib/libesp32/ESP-Mail-Client/examples/SMTP/Reply_Text/Reply_Text.ino b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Reply_Text/Reply_Text.ino new file mode 100644 index 000000000..76ce8091b --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Reply_Text/Reply_Text.ino @@ -0,0 +1,497 @@ + +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt +*/ + +// This example showes how to send a reply message when specific email was received. + +// The account 2 will send Hello message to account 1. + +// The account 1 will poll the mailbox for incoming message, when new message received with matched subject +// and sent from account 2, the account 1 will send a reply messsage to account 2. + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +#include + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +/** For Gmail, the app password will be used for log in + * Check out https://github.com/mobizt/ESP-Mail-Client#gmail-smtp-and-imap-required-app-passwords-to-sign-in + * + * For Yahoo mail, log in to your yahoo mail in web browser and generate app password by go to + * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc + * + * To use Gmai and Yahoo's App Password to sign in, define the AUTHOR_PASSWORD with your App Password + * and AUTHOR_EMAIL with your account email. + */ + +/* The imap host name e.g. imap.gmail.com for GMail or outlook.office365.com for Outlook */ +#define IMAP_HOST "" +#define IMAP_PORT 993 + +#define IMAP_AUTHOR_EMAIL "" +#define IMAP_AUTHOR_PASSWORD "" + +#define REPLY_SMTP_AUTHOR_EMAIL "" +#define REPLY_SMTP_AUTHOR_PASSWORD "" + +/** The smtp port e.g. + * 25 or esp_mail_smtp_port_25 + * 465 or esp_mail_smtp_port_465 + * 587 or esp_mail_smtp_port_587 + */ +#define REPLY_SMTP_PORT 587 +#define REPLY_SMTP_HOST "" + +#define HELLO_SMTP_AUTHOR_EMAIL "" +#define HELLO_SMTP_AUTHOR_PASSWORD "" + +#define HELLO_SMTP_PORT 587 +#define HELLO_SMTP_HOST "" + +void setupIMAP(); + +bool setupHelloSMTP(); + +bool setupReplySMTP(); + +void sendHelloMessage(); + +void sendReplyMessage(const char *subject, const char *reply_email, const char *msgID, const char *references); + +/* Print the selected folder update info */ +void printPollingStatus(IMAPSession &imap); + +/* Callback function to get the Email reading status */ +void imapCallback(IMAP_Status status); + +/* Callback function to get the Email sending status */ +void helloSMTPCallback(SMTP_Status status); + +void replySMTPCallback(SMTP_Status status); + +/* Declare the global used IMAPSession object for IMAP transport */ +IMAPSession imap; + +/* Declare the global used Session_Config for user defined IMAP session credentials */ +Session_Config imap_config; + +/** Define the IMAP_Data object used for user defined IMAP operating options + * and contains the IMAP operating result + */ +IMAP_Data imap_data; + +/* Declare the global used SMTPSession object for SMTP transport */ +SMTPSession hello_smtp; +SMTPSession reply_smtp; + +/* Declare the global used Session_Config for user defined SMTP session credentials */ +Session_Config hello_smtp_config; +Session_Config reply_smtp_config; + +bool imapSetupOk = false; + +unsigned long helloSendingMillis = 0; + +String sendingSubject = "ESP Mail Hello Test!"; + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) +WiFiMulti multi; +#endif + +void setup() +{ + + Serial.begin(115200); + +#if defined(ARDUINO_ARCH_SAMD) + while (!Serial) + ; +#endif + + Serial.println(); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + multi.addAP(WIFI_SSID, WIFI_PASSWORD); + multi.run(); +#else + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Connecting to Wi-Fi"); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + unsigned long ms = millis(); +#endif + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + if (millis() - ms > 10000) + break; +#endif + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + /* Set the network reconnection option */ + MailClient.networkReconnect(true); + + // The WiFi credentials are required for Pico W + // due to it does not have reconnect feature. +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + MailClient.clearAP(); + MailClient.addAP(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Setup and connect to IMAP server... "); + + setupIMAP(); + + if (!imapSetupOk) + return; +} + +void loop() +{ + + /* imap.connect and imap.selectFolder or imap.openFolder nedded to be called once prior to listen */ + + // Listen for mailbox changes + if (!imap.listen()) + return; + + // Check the changes + if (imap.folderChanged()) + printPollingStatus(imap); + + // To stop listen, use imap.stopListen(); and to listen again, call imap.listen() + + if (millis() - helloSendingMillis > 5 * 60 * 1000 || helloSendingMillis == 0) + { + helloSendingMillis = millis(); + Serial.print("Sending Hello message... "); + sendHelloMessage(); + } +} + +void setupIMAP() +{ + imap.debug(1); + + /* Set the callback function to get the reading results */ + imap.callback(imapCallback); + + /* Set the imap app config */ + imap_config.server.host_name = IMAP_HOST; + imap_config.server.port = IMAP_PORT; + imap_config.login.email = IMAP_AUTHOR_EMAIL; + imap_config.login.password = IMAP_AUTHOR_PASSWORD; + + /* Connect to the server */ + if (!imap.connect(&imap_config, &imap_data)) + return; + + if (imap.isAuthenticated()) + Serial.println("\nIMAP client, successfully logged in."); + else + Serial.println("\nIMAP client, connected with no Auth."); + + /* Open or select the mailbox folder to read or search the message */ + if (!imap.selectFolder(F("INBOX"))) + return; + + imapSetupOk = true; +} + +bool setupHelloSMTP() +{ + hello_smtp.debug(1); + + /* Set the callback function to get the sending results */ + hello_smtp.callback(helloSMTPCallback); + + /* Set the session config */ + hello_smtp_config.server.host_name = HELLO_SMTP_HOST; + hello_smtp_config.server.port = HELLO_SMTP_PORT; + hello_smtp_config.login.email = HELLO_SMTP_AUTHOR_EMAIL; + hello_smtp_config.login.password = HELLO_SMTP_AUTHOR_PASSWORD; + + /** Assign your host name or you public IPv4 or IPv6 only + * as this is the part of EHLO/HELO command to identify the client system + * to prevent connection rejection. + * If host name or public IP is not available, ignore this or + * use loopback address "127.0.0.1". + * + * Assign any text to this option may cause the connection rejection. + */ + hello_smtp_config.login.user_domain = F("127.0.0.1"); + + /* + Set the NTP config time + For times east of the Prime Meridian use 0-12 + For times west of the Prime Meridian add 12 to the offset. + Ex. American/Denver GMT would be -6. 6 + 12 = 18 + See https://en.wikipedia.org/wiki/Time_zone for a list of the GMT/UTC timezone offsets + */ + hello_smtp_config.time.ntp_server = F("pool.ntp.org,time.nist.gov"); + hello_smtp_config.time.gmt_offset = 3; + hello_smtp_config.time.day_light_offset = 0; + + /* Connect to the server */ + if (!hello_smtp.connect(&hello_smtp_config)) + { + MailClient.printf("Connection error, Status Code: %d, Error Code: %d, Reason: %s", hello_smtp.statusCode(), hello_smtp.errorCode(), hello_smtp.errorReason().c_str()); + return false; + } + + if (imap.isAuthenticated()) + Serial.println("\nHello SMTP client, successfully logged in."); + else + Serial.println("\nHello SMTP client, connected with no Auth."); + + return true; +} + +bool setupReplySMTP() +{ + reply_smtp.debug(1); + + /* Set the callback function to get the sending results */ + reply_smtp.callback(replySMTPCallback); + + /* Set the session config */ + reply_smtp_config.server.host_name = REPLY_SMTP_HOST; + reply_smtp_config.server.port = REPLY_SMTP_PORT; + reply_smtp_config.login.email = REPLY_SMTP_AUTHOR_EMAIL; + reply_smtp_config.login.password = REPLY_SMTP_AUTHOR_PASSWORD; + reply_smtp_config.login.user_domain = F("127.0.0.1"); + + /* Connect to the server */ + if (!reply_smtp.connect(&reply_smtp_config)) + { + MailClient.printf("Connection error, Status Code: %d, Error Code: %d, Reason: %s", reply_smtp.statusCode(), reply_smtp.errorCode(), reply_smtp.errorReason().c_str()); + return false; + } + + if (imap.isAuthenticated()) + Serial.println("\nReply SMTP client, successfully logged in."); + else + Serial.println("\nReply SMTP client, connected with no Auth."); + + return true; +} + +void sendHelloMessage() +{ + + if (!setupHelloSMTP()) + return; + + /* Declare the message class */ + SMTP_Message message; + + /* Set the message headers */ + message.sender.name = F("ESP Mail"); + message.sender.email = HELLO_SMTP_AUTHOR_EMAIL; + message.subject = sendingSubject.c_str(); + message.addRecipient(F("Me"), IMAP_AUTHOR_EMAIL); + message.response.reply_to = HELLO_SMTP_AUTHOR_EMAIL; // only email address, excluded < and > + message.text.content = F("Hello Me!"); + + /* Start sending Email and close the session */ + if (!MailClient.sendMail(&hello_smtp, &message)) + MailClient.printf("Error, Status Code: %d, Error Code: %d, Reason: %s", hello_smtp.statusCode(), hello_smtp.errorCode(), hello_smtp.errorReason().c_str()); +} + +void sendReplyMessage(const char *subject, const char *reply_email, const char *msgID, const char *references) +{ + + if (!setupReplySMTP()) + return; + + /* Declare the message class */ + SMTP_Message message; + + /* Set the message headers */ + message.sender.name = F("ESP Mail"); + message.sender.email = REPLY_SMTP_AUTHOR_EMAIL; + String reSubject = "RE: "; + reSubject += subject; + message.subject = reSubject; + message.addRecipient(F("Me"), reply_email); + + message.in_reply_to = msgID; + + String ref = references; + if (strlen(references) > 0) + ref += " "; + ref += msgID; + + message.references = ref; + message.text.content = F("Yeah!, it works."); + + /* Start sending Email and close the session */ + if (!MailClient.sendMail(&reply_smtp, &message)) + MailClient.printf("Error, Status Code: %d, Error Code: %d, Reason: %s", reply_smtp.statusCode(), reply_smtp.errorCode(), reply_smtp.errorReason().c_str()); +} + +void printPollingStatus(IMAPSession &imap) +{ + /* Declare the selected folder info class to get the info of selected mailbox folder */ + SelectedFolderInfo sFolder = imap.selectedFolder(); + + if (sFolder.pollingStatus().type == imap_polling_status_type_new_message) + { + /* Show the mailbox info */ + MailClient.printf("\nMailbox status changed\n----------------------\nTotal Messages: %d\n", sFolder.msgCount()); + + MailClient.printf("New message %d, has been addedd, reading message...\n", (int)sFolder.pollingStatus().messageNum); + + // we need to stop polling before do anything + imap.stopListen(); + + // Get the UID of new message and fetch + imap_data.fetch.uid = imap.getUID(sFolder.pollingStatus().messageNum); + + // When message was fetched or read, the /Seen flag will not set or message remained in unseen or unread status, + // as this is the purpose of library (not UI application), user can set the message status as read by set \Seen flag + // to message, see the Set_Flags.ino example. + MailClient.readMail(&imap, false); + } +} + +/* Callback function to get the Email reading status */ +void imapCallback(IMAP_Status status) +{ + /* Print the current status */ + Serial.println(status.info()); + + /* Show the result when reading finished */ + if (status.success()) + { + + /* Get the message list from the message list data */ + IMAP_MSG_List msgList = imap.data(); + + if (strcmp(msgList.msgItems[0].subject, sendingSubject.c_str()) == 0) + { + Serial.print("Sending Reply message... "); + std::string replyEmail = msgList.msgItems[0].reply_to; + + // remove < at the beginning and > at the end. + replyEmail.erase(0, 1); + replyEmail.pop_back(); + + sendReplyMessage(msgList.msgItems[0].subject, replyEmail.c_str(), msgList.msgItems[0].ID, msgList.msgItems[0].references); + } + + /* Clear all stored data in IMAPSession object */ + imap.empty(); + } +} + +/* Callback function to get the Email sending status */ +void helloSMTPCallback(SMTP_Status status) +{ + /* Print the current status */ + Serial.println(status.info()); + + /* Print the sending result */ + if (status.success()) + { + Serial.println("----------------"); + MailClient.printf("Message sent success: %d\n", status.completedCount()); + MailClient.printf("Message sent failed: %d\n", status.failedCount()); + Serial.println("----------------\n"); + struct tm dt; + + for (size_t i = 0; i < hello_smtp.sendingResult.size(); i++) + { + /* Get the result item */ + SMTP_Result result = hello_smtp.sendingResult.getItem(i); + + MailClient.printf("Message No: %d\n", i + 1); + MailClient.printf("Status: %s\n", result.completed ? "success" : "failed"); + MailClient.printf("Date/Time: %s\n", MailClient.Time.getDateTimeString(result.timestamp, "%B %d, %Y %H:%M:%S").c_str()); + MailClient.printf("Recipient: %s\n", result.recipients.c_str()); + MailClient.printf("Subject: %s\n", result.subject.c_str()); + } + Serial.println("----------------\n"); + + // You need to clear sending result as the memory usage will grow up + hello_smtp.sendingResult.clear(); + } +} + +void replySMTPCallback(SMTP_Status status) +{ + /* Print the current status */ + Serial.println(status.info()); + + /* Print the sending result */ + if (status.success()) + { + Serial.println("----------------"); + MailClient.printf("Message sent success: %d\n", status.completedCount()); + MailClient.printf("Message sent failed: %d\n", status.failedCount()); + Serial.println("----------------\n"); + struct tm dt; + + for (size_t i = 0; i < reply_smtp.sendingResult.size(); i++) + { + /* Get the result item */ + SMTP_Result result = reply_smtp.sendingResult.getItem(i); + + MailClient.printf("Message No: %d\n", i + 1); + MailClient.printf("Status: %s\n", result.completed ? "success" : "failed"); + MailClient.printf("Date/Time: %s\n", MailClient.Time.getDateTimeString(result.timestamp, "%B %d, %Y %H:%M:%S").c_str()); + MailClient.printf("Recipient: %s\n", result.recipients.c_str()); + MailClient.printf("Subject: %s\n", result.subject.c_str()); + } + Serial.println("----------------\n"); + + reply_smtp.sendingResult.clear(); + } +} diff --git a/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_Access_Token/Send_Access_Token.ino b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_Access_Token/Send_Access_Token.ino new file mode 100644 index 000000000..cb0cdb6bf --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_Access_Token/Send_Access_Token.ino @@ -0,0 +1,304 @@ +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt +*/ + +// This example shows how to log in with the SASL XOAUTH2 mechanisme using OAuth2.0 access token and send Email. + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +/** For Gmail, to send the Email via port 465 (SSL), less secure app option + * should be enabled in the account settings. https://myaccount.google.com/lesssecureapps?pli=1 + */ + +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +#include + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +#define SMTP_HOST "" + +/** The smtp port e.g. + * 25 or esp_mail_smtp_port_25 + * 465 or esp_mail_smtp_port_465 + * 587 or esp_mail_smtp_port_587 + */ +#define SMTP_PORT 25 + +/* The user Email for OAuth2.0 access token */ +#define AUTHOR_EMAIL "" + +/* Recipient email address */ +#define RECIPIENT_EMAIL "" + +/** The OAuth2.0 access token + * The generation, exchange and refresh of the access token are not available + * in this library. + * + * To test this using GMail, get the OAuth2.0 access token from this web site + * https://developers.google.com/oauthplayground/ + * + * + * 1. Select the following scope (in Step 1) from Gmail API V1 + * https://mail.google.com/ + * https://mail.google.com/ + * + * 2. Click Authorize APIs button. + * 3. Cick Exchangeauthorization code for tokens. + * 4. From the response, look at access_token from the JSON payload node. + * 5. Copy that access token and paste to the AUTHOR_ACCESS_TOKEN value. + * + * The token will be expired in 3600 seconds (1 Hr). + * The AUTHOR_EMAIL above is the Email address that you granted to access the Gmail services. + */ +#define AUTHOR_ACCESS_TOKEN "" + +/* Declare the global used SMTPSession object for SMTP transport */ +SMTPSession smtp; + +/* Callback function to get the Email sending status */ +void smtpCallback(SMTP_Status status); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) +WiFiMulti multi; +#endif + +void setup() +{ + + Serial.begin(115200); + +#if defined(ARDUINO_ARCH_SAMD) + while (!Serial) + ; +#endif + + Serial.println(); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + multi.addAP(WIFI_SSID, WIFI_PASSWORD); + multi.run(); +#else + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Connecting to Wi-Fi"); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + unsigned long ms = millis(); +#endif + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + if (millis() - ms > 10000) + break; +#endif + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + /* Set the network reconnection option */ + MailClient.networkReconnect(true); + + // The WiFi credentials are required for Pico W + // due to it does not have reconnect feature. +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + MailClient.clearAP(); + MailClient.addAP(WIFI_SSID, WIFI_PASSWORD); +#endif + + /** Enable the debug via Serial port + * 0 for no debugging + * 1 for basic level debugging + * + * Debug port can be changed via ESP_MAIL_DEFAULT_DEBUG_PORT in ESP_Mail_FS.h + */ + smtp.debug(1); + + /* Set the callback function to get the sending results */ + smtp.callback(smtpCallback); + + /* Declare the Session_Config for user defined session credentials */ + Session_Config config; + + /* Set the session config */ + config.server.host_name = SMTP_HOST; + config.server.port = SMTP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.accessToken = AUTHOR_ACCESS_TOKEN; + + /** Assign your host name or you public IPv4 or IPv6 only + * as this is the part of EHLO/HELO command to identify the client system + * to prevent connection rejection. + * If host name or public IP is not available, ignore this or + * use loopback address "127.0.0.1". + * + * Assign any text to this option may cause the connection rejection. + */ + config.login.user_domain = F("127.0.0.1"); + + /* + Set the NTP config time + For times east of the Prime Meridian use 0-12 + For times west of the Prime Meridian add 12 to the offset. + Ex. American/Denver GMT would be -6. 6 + 12 = 18 + See https://en.wikipedia.org/wiki/Time_zone for a list of the GMT/UTC timezone offsets + */ + config.time.ntp_server = F("pool.ntp.org,time.nist.gov"); + config.time.gmt_offset = 3; + config.time.day_light_offset = 0; + + /* Declare the message class */ + SMTP_Message message; + + /* Set the message headers */ + message.sender.name = F("ESP Mail"); + message.sender.email = AUTHOR_EMAIL; + message.subject = F("Test sending Email using Access token"); + message.addRecipient(F("Admin"), RECIPIENT_EMAIL); + + message.text.content = F("This is simple plain text message"); + + /** The Plain text message character set e.g. + * us-ascii + * utf-8 + * utf-7 + * The default value is utf-8 + */ + message.text.charSet = F("us-ascii"); + + /** The content transfer encoding e.g. + * enc_7bit or "7bit" (not encoded) + * enc_qp or "quoted-printable" (encoded) + * enc_base64 or "base64" (encoded) + * enc_binary or "binary" (not encoded) + * enc_8bit or "8bit" (not encoded) + * The default value is "7bit" + */ + message.text.transfer_encoding = Content_Transfer_Encoding::enc_7bit; + + /** The message priority + * esp_mail_smtp_priority_high or 1 + * esp_mail_smtp_priority_normal or 3 + * esp_mail_smtp_priority_low or 5 + * The default value is esp_mail_smtp_priority_low + */ + message.priority = esp_mail_smtp_priority::esp_mail_smtp_priority_low; + + /** The Delivery Status Notifications e.g. + * esp_mail_smtp_notify_never + * esp_mail_smtp_notify_success + * esp_mail_smtp_notify_failure + * esp_mail_smtp_notify_delay + * The default value is esp_mail_smtp_notify_never + */ + // message.response.notify = esp_mail_smtp_notify_success | esp_mail_smtp_notify_failure | esp_mail_smtp_notify_delay; + + /* Connect to the server */ + if (!smtp.connect(&config)) + { + MailClient.printf("Connection error, Status Code: %d, Error Code: %d, Reason: %s", smtp.statusCode(), smtp.errorCode(), smtp.errorReason().c_str()); + return; + } + + if (smtp.isAuthenticated()) + Serial.println("\nSuccessfully logged in."); + else + Serial.println("\nConnected with no Auth."); + + /* Set the custom message header */ + message.addHeader(F("Message-ID: ")); + + /* Start sending Email and close the session */ + if (!MailClient.sendMail(&smtp, &message)) + MailClient.printf("Error, Status Code: %d, Error Code: %d, Reason: %s", smtp.statusCode(), smtp.errorCode(), smtp.errorReason().c_str()); + + // to clear sending result log + // smtp.sendingResult.clear(); + + MailClient.printf("Free Heap: %d\n", MailClient.getFreeHeap()); +} + +void loop() +{ +} + +/* Callback function to get the Email sending status */ +void smtpCallback(SMTP_Status status) +{ + /* Print the current status */ + Serial.println(status.info()); + + /* Print the sending result */ + if (status.success()) + { + // MailClient.printf used in the examples is for format printing via debug Serial port + // that works for all supported Arduino platform SDKs e.g. SAMD, ESP32 and ESP8266. + // In ESP8266 and ESP32, you can use Serial.printf directly. + + Serial.println("----------------"); + MailClient.printf("Message sent success: %d\n", status.completedCount()); + MailClient.printf("Message sent failed: %d\n", status.failedCount()); + Serial.println("----------------\n"); + + for (size_t i = 0; i < smtp.sendingResult.size(); i++) + { + /* Get the result item */ + SMTP_Result result = smtp.sendingResult.getItem(i); + + // In case, ESP32, ESP8266 and SAMD device, the timestamp get from result.timestamp should be valid if + // your device time was synched with NTP server. + // Other devices may show invalid timestamp as the device time was not set i.e. it will show Jan 1, 1970. + // You can call smtp.setSystemTime(xxx) to set device time manually. Where xxx is timestamp (seconds since Jan 1, 1970) + + MailClient.printf("Message No: %d\n", i + 1); + MailClient.printf("Status: %s\n", result.completed ? "success" : "failed"); + MailClient.printf("Date/Time: %s\n", MailClient.Time.getDateTimeString(result.timestamp, "%B %d, %Y %H:%M:%S").c_str()); + MailClient.printf("Recipient: %s\n", result.recipients.c_str()); + MailClient.printf("Subject: %s\n", result.subject.c_str()); + } + Serial.println("----------------\n"); + + // You need to clear sending result as the memory usage will grow up. + smtp.sendingResult.clear(); + } +} \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_Attachment_Blob/Send_Attachment_Blob.ino b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_Attachment_Blob/Send_Attachment_Blob.ino new file mode 100644 index 000000000..b408c8f81 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_Attachment_Blob/Send_Attachment_Blob.ino @@ -0,0 +1,369 @@ + +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt +*/ + +// This example shows how to send Email with attachments and inline images. + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +#include + +/* This is for attachment data */ +#include "blob_data.h" + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +/** For Gmail, the app password will be used for log in + * Check out https://github.com/mobizt/ESP-Mail-Client#gmail-smtp-and-imap-required-app-passwords-to-sign-in + * + * For Yahoo mail, log in to your yahoo mail in web browser and generate app password by go to + * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc + * + * To use Gmai and Yahoo's App Password to sign in, define the AUTHOR_PASSWORD with your App Password + * and AUTHOR_EMAIL with your account email. + */ + +/** The smtp host name e.g. smtp.gmail.com for GMail or smtp.office365.com for Outlook or smtp.mail.yahoo.com */ +#define SMTP_HOST "" + +/** The smtp port e.g. + * 25 or esp_mail_smtp_port_25 + * 465 or esp_mail_smtp_port_465 + * 587 or esp_mail_smtp_port_587 + */ +#define SMTP_PORT esp_mail_smtp_port_587 + +/* The log in credentials */ +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" + +/* Recipient email address */ +#define RECIPIENT_EMAIL "" + +/* Declare the global used SMTPSession object for SMTP transport */ +SMTPSession smtp; + +/* Callback function to get the Email sending status */ +void smtpCallback(SMTP_Status status); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) +WiFiMulti multi; +#endif + +void setup() +{ + + Serial.begin(115200); + +#if defined(ARDUINO_ARCH_SAMD) + while (!Serial) + ; +#endif + + Serial.println(); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + multi.addAP(WIFI_SSID, WIFI_PASSWORD); + multi.run(); +#else + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Connecting to Wi-Fi"); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + unsigned long ms = millis(); +#endif + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + if (millis() - ms > 10000) + break; +#endif + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + /* Set the network reconnection option */ + MailClient.networkReconnect(true); + + // The WiFi credentials are required for Pico W + // due to it does not have reconnect feature. +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + MailClient.clearAP(); + MailClient.addAP(WIFI_SSID, WIFI_PASSWORD); +#endif + + /** Enable the debug via Serial port + * 0 for no debugging + * 1 for basic level debugging + * + * Debug port can be changed via ESP_MAIL_DEFAULT_DEBUG_PORT in ESP_Mail_FS.h + */ + smtp.debug(1); + + /* Set the callback function to get the sending results */ + smtp.callback(smtpCallback); + + /* Declare the Session_Config for user defined session credentials */ + Session_Config config; + + /* Set the session config */ + config.server.host_name = SMTP_HOST; + config.server.port = SMTP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + + /** Assign your host name or you public IPv4 or IPv6 only + * as this is the part of EHLO/HELO command to identify the client system + * to prevent connection rejection. + * If host name or public IP is not available, ignore this or + * use loopback address "127.0.0.1". + * + * Assign any text to this option may cause the connection rejection. + */ + config.login.user_domain = F("127.0.0.1"); + + /* + Set the NTP config time + For times east of the Prime Meridian use 0-12 + For times west of the Prime Meridian add 12 to the offset. + Ex. American/Denver GMT would be -6. 6 + 12 = 18 + See https://en.wikipedia.org/wiki/Time_zone for a list of the GMT/UTC timezone offsets + */ + config.time.ntp_server = F("pool.ntp.org,time.nist.gov"); + config.time.gmt_offset = 3; + config.time.day_light_offset = 0; + + /* Declare the message class */ + SMTP_Message message; + + /* Enable the chunked data transfer with pipelining for large message if server supported */ + message.enable.chunking = true; + + /* Set the message headers */ + message.sender.name = F("ESP Mail"); + message.sender.email = AUTHOR_EMAIL; + + message.subject = F("Test sending Email with attachments and inline images"); + message.addRecipient(F("user1"), RECIPIENT_EMAIL); + + message.html.content = F("This message contains 3 inline images and 1 attachment file.

"); + + /** The HTML text message character set e.g. + * us-ascii + * utf-8 + * utf-7 + * The default value is utf-8 + */ + message.html.charSet = F("utf-8"); + + /** The content transfer encoding e.g. + * enc_7bit or "7bit" (not encoded) + * enc_qp or "quoted-printable" (encoded) + * enc_base64 or "base64" (encoded) + * enc_binary or "binary" (not encoded) + * enc_8bit or "8bit" (not encoded) + * The default value is "7bit" + */ + message.html.transfer_encoding = Content_Transfer_Encoding::enc_qp; + + message.text.content = F("This message contains 3 inline images and 1 attachment file.\r\nThe inline images were not shown in the plain text message."); + message.text.charSet = F("utf-8"); + message.text.transfer_encoding = Content_Transfer_Encoding::enc_base64; + + /** The message priority + * esp_mail_smtp_priority_high or 1 + * esp_mail_smtp_priority_normal or 3 + * esp_mail_smtp_priority_low or 5 + * The default value is esp_mail_smtp_priority_low + */ + message.priority = esp_mail_smtp_priority::esp_mail_smtp_priority_normal; + + /** The Delivery Status Notifications e.g. + * esp_mail_smtp_notify_never + * esp_mail_smtp_notify_success + * esp_mail_smtp_notify_failure + * esp_mail_smtp_notify_delay + * The default value is esp_mail_smtp_notify_never + */ + // message.response.notify = esp_mail_smtp_notify_success | esp_mail_smtp_notify_failure | esp_mail_smtp_notify_delay; + + /* Set the custom message header */ + message.addHeader(F("Message-ID: ")); + + /* The attachment data item */ + SMTP_Attachment att[4]; + int attIndex = 0; + + /** Set the inline image info e.g. + * file name, MIME type, BLOB data, BLOB data size, + * transfer encoding (should be base64 for inline image) + */ + att[attIndex].descr.filename = F("firebase_logo.png"); + att[attIndex].descr.mime = F("image/png"); + att[attIndex].blob.data = firebase_logo_png; + att[attIndex].blob.size = sizeof(firebase_logo_png); + att[attIndex].descr.transfer_encoding = Content_Transfer_Encoding::enc_base64; + + /* Add inline image to the message */ + message.addInlineImage(att[attIndex]); + + /** Set the inline image info e.g. + * file name, MIME type, BLOB data, BLOB data size. + * The default transfer encoding is base64. + */ + attIndex++; + att[attIndex].descr.filename = F("tree.gif"); + att[attIndex].descr.mime = F("image/gif"); + att[attIndex].blob.data = tree_img_gif; + att[attIndex].blob.size = sizeof(tree_img_gif); + att[attIndex].descr.transfer_encoding = Content_Transfer_Encoding::enc_base64; + + /* Add inline image to the message */ + message.addInlineImage(att[attIndex]); + + /** Set the inline image info e.g. + * file name, MIME type, BLOB data, BLOB data size. + * The default transfer encoding is base64. + */ + attIndex++; + att[attIndex].descr.filename = F("bird.gif"); + att[attIndex].descr.mime = F("image/gif"); + att[attIndex].blob.data = bird_img_gif; + att[attIndex].blob.size = sizeof(bird_img_gif); + att[attIndex].descr.transfer_encoding = Content_Transfer_Encoding::enc_base64; + + /* Add inline image to the message */ + message.addInlineImage(att[attIndex]); + + /* Prepare the attachment data (from ram) */ + uint8_t *a = new uint8_t[512]; + int j = 0; + + for (int i = 0; i < 512; i++) + { + a[i] = j; + j++; + if (j > 255) + j = 0; + } + + /** Set the attachment info e.g. + * file name, MIME type, BLOB data, BLOB data size. + * The default transfer encoding is base64. + */ + attIndex++; + att[attIndex].descr.filename = F("test.dat"); + att[attIndex].descr.mime = F("application/octet-stream"); + att[attIndex].blob.data = a; + att[attIndex].blob.size = 512; + att[attIndex].descr.transfer_encoding = Content_Transfer_Encoding::enc_base64; + /* Add attachment to the message */ + message.addAttachment(att[attIndex]); + + /* Connect to the server */ + if (!smtp.connect(&config)) + return; + + if (smtp.isAuthenticated()) + Serial.println("\nSuccessfully logged in."); + else + Serial.println("\nConnected with no Auth."); + + /* Start sending the Email and close the session */ + if (!MailClient.sendMail(&smtp, &message, true)) + MailClient.printf("Error, Status Code: %d, Error Code: %d, Reason: %s", smtp.statusCode(), smtp.errorCode(), smtp.errorReason().c_str()); + + // to clear sending result log + // smtp.sendingResult.clear(); + + MailClient.printf("Free Heap: %d\n", MailClient.getFreeHeap()); +} + +void loop() +{ +} + +/* Callback function to get the Email sending status */ +void smtpCallback(SMTP_Status status) +{ + /* Print the current status */ + Serial.println(status.info()); + + /* Print the sending result */ + if (status.success()) + { + // MailClient.printf used in the examples is for format printing via debug Serial port + // that works for all supported Arduino platform SDKs e.g. SAMD, ESP32 and ESP8266. + // In ESP8266 and ESP32, you can use Serial.printf directly. + + Serial.println("----------------"); + MailClient.printf("Message sent success: %d\n", status.completedCount()); + MailClient.printf("Message sent failed: %d\n", status.failedCount()); + Serial.println("----------------\n"); + + for (size_t i = 0; i < smtp.sendingResult.size(); i++) + { + /* Get the result item */ + SMTP_Result result = smtp.sendingResult.getItem(i); + + // In case, ESP32, ESP8266 and SAMD device, the timestamp get from result.timestamp should be valid if + // your device time was synched with NTP server. + // Other devices may show invalid timestamp as the device time was not set i.e. it will show Jan 1, 1970. + // You can call smtp.setSystemTime(xxx) to set device time manually. Where xxx is timestamp (seconds since Jan 1, 1970) + + MailClient.printf("Message No: %d\n", i + 1); + MailClient.printf("Status: %s\n", result.completed ? "success" : "failed"); + MailClient.printf("Date/Time: %s\n", MailClient.Time.getDateTimeString(result.timestamp, "%B %d, %Y %H:%M:%S").c_str()); + MailClient.printf("Recipient: %s\n", result.recipients.c_str()); + MailClient.printf("Subject: %s\n", result.subject.c_str()); + } + Serial.println("----------------\n"); + + // You need to clear sending result as the memory usage will grow up. + smtp.sendingResult.clear(); + } +} \ No newline at end of file diff --git a/lib/libesp32/lib_mail/examples/Send_RFC822_Attachment/image.h b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_Attachment_Blob/blob_data.h similarity index 98% rename from lib/libesp32/lib_mail/examples/Send_RFC822_Attachment/image.h rename to lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_Attachment_Blob/blob_data.h index 80ce0a0e7..c853cded3 100644 --- a/lib/libesp32/lib_mail/examples/Send_RFC822_Attachment/image.h +++ b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_Attachment_Blob/blob_data.h @@ -1,1851 +1,1851 @@ -#include - -static const uint8_t firebase_png[] PROGMEM = { - 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00, 0x00, 0x00, 0x0D, 0x49, 0x48, 0x44, 0x52, - 0x00, 0x00, 0x03, 0x20, 0x00, 0x00, 0x02, 0x58, 0x08, 0x06, 0x00, 0x00, 0x00, 0x9A, 0x76, 0x82, - 0x70, 0x00, 0x00, 0x00, 0x01, 0x73, 0x52, 0x47, 0x42, 0x00, 0xAE, 0xCE, 0x1C, 0xE9, 0x00, 0x00, - 0x00, 0x04, 0x67, 0x41, 0x4D, 0x41, 0x00, 0x00, 0xB1, 0x8F, 0x0B, 0xFC, 0x61, 0x05, 0x00, 0x00, - 0x00, 0x09, 0x70, 0x48, 0x59, 0x73, 0x00, 0x00, 0x0E, 0xC3, 0x00, 0x00, 0x0E, 0xC3, 0x01, 0xC7, - 0x6F, 0xA8, 0x64, 0x00, 0x00, 0x55, 0x14, 0x49, 0x44, 0x41, 0x54, 0x78, 0x5E, 0xED, 0xDD, 0x59, - 0x90, 0x1D, 0xF5, 0x81, 0xE7, 0x7B, 0x3F, 0xF4, 0xC3, 0x84, 0x91, 0x40, 0x6E, 0xEF, 0xC6, 0x8B, - 0x30, 0x92, 0x4A, 0x1B, 0x58, 0x98, 0xCD, 0xA0, 0xA5, 0x4A, 0x12, 0x20, 0x6C, 0x9A, 0xB6, 0xBA, - 0x01, 0x63, 0x4F, 0x3F, 0x8C, 0x1E, 0x26, 0xC2, 0xF7, 0xE5, 0xC6, 0x25, 0xE2, 0xDE, 0x97, 0x3B, - 0x7D, 0x67, 0xAC, 0x6E, 0x63, 0x63, 0x83, 0x8D, 0xBC, 0xB1, 0x99, 0xA5, 0x10, 0x08, 0xED, 0x52, - 0x69, 0xAD, 0x92, 0xA0, 0xBB, 0xAB, 0xA7, 0xED, 0x6E, 0x77, 0xB7, 0x81, 0x42, 0x9B, 0x99, 0x89, - 0x89, 0xDB, 0x9A, 0xB9, 0x0E, 0x2F, 0x2C, 0x76, 0x61, 0x16, 0x49, 0x85, 0xA4, 0xFC, 0xDF, 0xFF, - 0x3F, 0x4F, 0xE6, 0xA9, 0x3C, 0x79, 0x7E, 0xE7, 0x9C, 0xCC, 0x3C, 0x99, 0x75, 0xCE, 0xC9, 0xFA, - 0x7E, 0x22, 0x7E, 0xA1, 0x6E, 0x2F, 0x42, 0xC2, 0x94, 0xE2, 0xFF, 0x8D, 0x7F, 0x65, 0x9E, 0xF7, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x28, 0x82, 0x79, 0x6E, 0xCD, 0x80, 0xBF, 0xC3, 0x5F, 0x58, 0x12, 0xFC, - 0x4B, 0x00, 0x00, 0x00, 0x00, 0x90, 0x1F, 0x73, 0x78, 0xCD, 0x3A, 0xEF, 0xB9, 0x35, 0x63, 0xE6, - 0xB9, 0x9B, 0x4D, 0x75, 0xCF, 0xAE, 0xF1, 0xE7, 0x3D, 0x7B, 0xD3, 0xA0, 0x0B, 0x92, 0xE0, 0x3F, - 0x0A, 0x00, 0x00, 0x00, 0x00, 0xD9, 0x98, 0x91, 0x35, 0xB3, 0xEB, 0xC2, 0x23, 0x12, 0x1F, 0xD1, - 0x79, 0x87, 0xD7, 0x6C, 0x08, 0xFE, 0x6B, 0x00, 0x00, 0x00, 0x00, 0x90, 0x8E, 0xFB, 0x16, 0x2B, - 0xEF, 0xD9, 0x35, 0xE3, 0x95, 0xE0, 0xB8, 0xD1, 0x98, 0x03, 0x57, 0x19, 0xB3, 0x7B, 0xAE, 0x31, - 0x3B, 0x3E, 0x65, 0xCC, 0xB6, 0x8F, 0x1A, 0xB3, 0xF3, 0xD3, 0xC6, 0x0C, 0x2D, 0x34, 0x66, 0x78, - 0xD9, 0x64, 0x84, 0x3C, 0x7B, 0xD3, 0x60, 0xF0, 0x5F, 0x07, 0x00, 0x00, 0x00, 0x80, 0xE4, 0xAA, - 0x37, 0x1F, 0x2E, 0x3C, 0x76, 0x7C, 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, 0x66, 0x76, 0xF0, 0x97, 0x07, 0x00, 0x00, - 0x00, 0x30, 0x9D, 0x98, 0x03, 0x57, 0xDB, 0x40, 0x50, 0x91, 0xD1, 0x68, 0x22, 0x2E, 0x5A, 0xCD, - 0xC5, 0x47, 0x38, 0x6E, 0x41, 0x00, 0x00, 0x00, 0x80, 0xE9, 0xC9, 0xDD, 0x44, 0x98, 0x7D, 0x9F, - 0xB1, 0x91, 0xA0, 0x42, 0x43, 0x4D, 0xC4, 0x45, 0xAB, 0x45, 0xE3, 0xC3, 0x6D, 0xF7, 0xDC, 0xCA, - 0x2D, 0xC8, 0x73, 0xAB, 0x07, 0x82, 0x5F, 0x06, 0x00, 0x00, 0x00, 0x80, 0xE9, 0xC0, 0x3C, 0xB7, - 0x66, 0xC0, 0xEC, 0x9E, 0x67, 0x43, 0x41, 0xC5, 0x46, 0x7C, 0x22, 0x2E, 0x5A, 0x2D, 0x1E, 0x1F, - 0xE1, 0x86, 0xAF, 0x73, 0x0F, 0xA4, 0x8F, 0x06, 0xBF, 0x0C, 0x00, 0x00, 0x00, 0x00, 0xD3, 0x81, - 0xF7, 0xEC, 0x4D, 0x77, 0x99, 0x9D, 0x97, 0xD8, 0x58, 0x50, 0xC1, 0x11, 0x9D, 0x88, 0x8B, 0x56, - 0x53, 0xE1, 0x11, 0x6E, 0xD7, 0xA7, 0xB9, 0x05, 0x01, 0x00, 0x00, 0x00, 0xA6, 0x1B, 0xEF, 0xF0, - 0x8D, 0x1B, 0x74, 0x70, 0x44, 0x27, 0xE2, 0xA2, 0xD5, 0x54, 0x74, 0xC4, 0xC7, 0x2D, 0x08, 0x00, - 0x00, 0x00, 0x30, 0xBD, 0x78, 0x07, 0xAF, 0x6F, 0xF1, 0x06, 0x2C, 0x11, 0x17, 0xAD, 0xA6, 0x62, - 0x43, 0xCD, 0x7D, 0xF6, 0x88, 0xBB, 0x05, 0x39, 0x7C, 0xE3, 0xBA, 0xE0, 0x97, 0x03, 0x00, 0x00, - 0x00,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 0x00, 0x00, 0x50, 0x16, 0x66, 0xFF, 0x67, 0x75, 0x5C, - 0xB4, 0x9A, 0x0C, 0x8B, 0x24, 0x13, 0xD1, 0x11, 0xDF, 0xC8, 0x0A, 0xE3, 0x1D, 0x5A, 0x3D, 0x18, - 0xFC, 0x12, 0x01, 0x00, 0x00, 0x00, 0x94, 0x81, 0xBB, 0x65, 0x30, 0xFB, 0x2E, 0xD7, 0x81, 0xD1, - 0x6C, 0x32, 0x2C, 0x92, 0x4C, 0xC4, 0x86, 0x1A, 0xB7, 0x20, 0x00, 0x00, 0x00, 0x40, 0xF9, 0x98, - 0xE7, 0x56, 0x0F, 0x98, 0x5D, 0x97, 0xEA, 0xC8, 0x68, 0x34, 0x19, 0x16, 0x49, 0x26, 0x42, 0xA3, - 0xD9, 0x0E, 0x7E, 0xCE, 0x78, 0x87, 0x6F, 0x18, 0x0D, 0x7E, 0xA9, 0x00, 0x00, 0x00, 0x00, 0x7A, - 0x9D, 0xFF, 0x06, 0xAC, 0x1D, 0x9F, 0xD0, 0xA1, 0xA1, 0x26, 0xC3, 0x22, 0xC9, 0x44, 0x60, 0xB4, - 0xDA, 0xCE, 0x4B, 0x82, 0x5B, 0x90, 0xD5, 0x03, 0xC1, 0x2F, 0x17, 0x00, 0x00, 0x00, 0x40, 0x2F, - 0xF3, 0x9E, 0xBD, 0x61, 0x50, 0x86, 0x86, 0x9A, 0x0C, 0x8B, 0x24, 0x13, 0x71, 0x91, 0x74, 0x07, - 0xAF, 0x35, 0xDE, 0xE1, 0x55, 0xDC, 0x82, 0x00, 0x00, 0x00, 0x00, 0x65, 0xE0, 0x1D, 0xBC, 0x6E, - 0x54, 0xC6, 0x46, 0x7C, 0x32, 0x2C, 0x92, 0x4C, 0x44, 0x45, 0xD2, 0x6D, 0xF9, 0x80, 0x31, 0x3B, - 0x67, 0xBB, 0x0F, 0x26, 0x34, 0xE6, 0xD0, 0xAA, 0xB5, 0xC1, 0x2F, 0x19, 0x00, 0x00, 0x00, 0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, 0xFD, 0xD7, 0x57, 0x55, 0xFE, 0x7D, 0x22, 0x04, 0x00, 0x00, 0xA0, 0x38, 0xFE, - 0x2B, 0x78, 0x55, 0x74, 0x84, 0x93, 0x71, 0xD1, 0x6A, 0x2A, 0x28, 0xD2, 0x4C, 0xC4, 0x45, 0xAB, - 0xA9, 0xA8, 0x48, 0xBC, 0x59, 0x95, 0x07, 0xC7, 0xDD, 0xB7, 0x50, 0x65, 0xB8, 0x05, 0xF1, 0x86, - 0x57, 0x64, 0xBF, 0xFD, 0x90, 0x21, 0x91, 0x65, 0x91, 0xF8, 0x08, 0xC7, 0x2D, 0x48, 0x6D, 0x7C, - 0x1C, 0xB9, 0xB1, 0x36, 0x3A, 0xD4, 0x5C, 0x98, 0x1C, 0xFD, 0x42, 0x25, 0x42, 0x4E, 0x7C, 0x85, - 0x1B, 0x24, 0x00, 0x00, 0x80, 0xBC, 0x79, 0x07, 0x97, 0x35, 0x7E, 0x03, 0x96, 0x8C, 0x8B, 0x56, - 0x53, 0x41, 0x91, 0x66, 0x22, 0x2E, 0x5A, 0x4D, 0x46, 0x45, 0xD2, 0x85, 0x1F, 0x16, 0x68, 0xE7, - 0x6E, 0x41, 0x46, 0x06, 0x86, 0x82, 0xBF, 0x35, 0x89, 0xB4, 0x75, 0xFB, 0x21, 0x43, 0x22, 0xCB, - 0x44, 0x7C, 0xB8, 0x6D, 0xFD, 0xD0, 0xB4, 0xBE, 0x05, 0xA9, 0x89, 0x0F, 0x77, 0xEB, 0xA1, 0x82, - 0xA3, 0xD1, 0x5C, 0xAC, 0xF8, 0x37, 0x26, 0x5F, 0x29, 0xE4, 0xD3, 0xF2, 0x01, 0x00, 0x00, 0xA6, - 0x2D, 0x6F, 0xFF, 0x35, 0x63, 0xC4, 0x47, 0xB0, 0xED, 0x1F, 0xB7, 0x87, 0x75, 0xFF, 0x16, 0x24, - 0xF1, 0x81, 0xDD, 0x1B, 0x59, 0x31, 0xE6, 0x3F, 0xC4, 0xAF, 0x02, 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, 0x7E, 0x66, 0x68, 0xBE, 0x8D, 0x02, 0x15, 0x18, 0xCD, 0x26, 0xA2, 0x22, - 0xE9, 0x54, 0x78, 0x44, 0x96, 0xE8, 0xF6, 0x23, 0x88, 0x8F, 0x76, 0x6F, 0x3F, 0x74, 0x48, 0x64, - 0x99, 0x08, 0x89, 0x2C, 0x23, 0x3E, 0x72, 0x98, 0x0A, 0x87, 0x3C, 0x26, 0xE2, 0x21, 0x8F, 0xBD, - 0x78, 0x1D, 0x6F, 0xC2, 0x02, 0x00, 0x00, 0xD3, 0x87, 0xFF, 0x06, 0xAC, 0x5D, 0x9F, 0xB6, 0x61, - 0xA0, 0x22, 0xA3, 0xD1, 0x44, 0x54, 0x24, 0x9D, 0x08, 0x8E, 0xEA, 0x92, 0xDE, 0x7E, 0x3C, 0x6E, - 0x03, 0x24, 0x8C, 0x8F, 0x68, 0x80, 0xFC, 0x80, 0xF8, 0x20, 0x3E, 0x54, 0x38, 0xE4, 0x31, 0x11, - 0x0E, 0x79, 0xED, 0x85, 0xAB, 0x78, 0x13, 0x16, 0x00, 0x00, 0x98, 0x3E, 0xCC, 0xA1, 0xFE, 0xB5, - 0x66, 0xC7, 0xC7, 0x6D, 0x1C, 0xA8, 0xD0, 0x50, 0x13, 0x51, 0x91, 0x74, 0x2A, 0x3A, 0x62, 0x53, - 0xB7, 0x1F, 0xD1, 0x00, 0xF1, 0xE3, 0xA3, 0xD1, 0xED, 0xC7, 0x37, 0x75, 0x68, 0xA8, 0xE9, 0x90, - 0xC8, 0x32, 0x11, 0x12, 0x59, 0x46, 0x7C, 0xE4, 0x30, 0x15, 0x0E, 0x79, 0x4C, 0x44, 0x43, 0xCE, - 0xE3, 0x4D, 0x58, 0x00, 0x00, 0x60, 0xDA, 0xF0, 0xDF, 0x80, 0xB5, 0xE5, 0xFD, 0x36, 0x10, 0x54, - 0x6C, 0xC4, 0x27, 0xA2, 0x22, 0xE9, 0x44, 0x6C, 0xD4, 0x2C, 0xC1, 0xED, 0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F, 0x51, 0x00, 0x00, 0x80, 0x72, 0xF1, 0x0E, 0x5C, - 0x33, 0x2A, 0xE3, 0xA2, 0xD5, 0x54, 0x58, 0x24, 0x99, 0x8D, 0x0E, 0xF7, 0xE3, 0x64, 0x80, 0x04, - 0xF1, 0x11, 0xBD, 0xFD, 0x88, 0xC5, 0x47, 0xDD, 0xED, 0xC7, 0xB7, 0x6A, 0x6F, 0x3F, 0x74, 0x48, - 0x64, 0x99, 0x08, 0x89, 0x2C, 0x13, 0xE1, 0xE1, 0x56, 0x17, 0x1F, 0xEA, 0x8D, 0x57, 0xC4, 0x47, - 0x30, 0x15, 0x0E, 0x79, 0x4C, 0x45, 0x42, 0x51, 0xD3, 0x71, 0x91, 0x68, 0x47, 0x56, 0xF3, 0x26, - 0x2C, 0x00, 0x00, 0x50, 0x4E, 0xDE, 0xDE, 0x25, 0x63, 0x32, 0x30, 0x9A, 0x2D, 0x1E, 0x15, 0x69, - 0x16, 0x86, 0x47, 0x18, 0x1F, 0x69, 0x6F, 0x3F, 0x7E, 0x68, 0x57, 0xB6, 0xF8, 0x70, 0x37, 0x1F, - 0x2E, 0x3E, 0xDC, 0x43, 0xE7, 0xC4, 0x87, 0x9D, 0x0A, 0x87, 0x3C, 0xA6, 0x22, 0xA1, 0xA8, 0x89, - 0xA8, 0x48, 0xB3, 0x97, 0x56, 0xF0, 0x26, 0x2C, 0x00, 0x00, 0x50, 0x4E, 0x66, 0xCF, 0x42, 0x1D, - 0x19, 0x8D, 0xA6, 0xA2, 0x22, 0xE5, 0x2A, 0x01, 0x32, 0xB3, 0xED, 0xDB, 0x0F, 0x1D, 0x12, 0x59, - 0x26, 0x42, 0x22, 0xCB, 0x44, 0x78, 0xB8, 0xB5, 0x8C, 0x8F, 0xBF, 0x9C, 0xFC, 0xAC, 0x8F, 0x3F, - 0xDC, 0x4B, 0x7C, 0x14, 0x33, 0x15, 0x09, 0x45, 0x4D, 0x04, 0x45, 0xDA, 0xBD, 0x78, 0x8D, 0x0D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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xD0, 0x15, 0xDE, 0xF3, 0x9E, 0xFF, 0x1F, 0x5B, 0xE2, 0x94, 0x1D, 0x86, - 0x86, 0x23, 0x09, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4E, 0x44, 0xAE, 0x42, 0x60, 0x82}; - -static const uint8_t tree_gif[] PROGMEM = { - - 0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x28, 0x00, 0x3C, 0x00, 0x83, 0x0B, 0x00, 0x00, 0xFF, 0xFF, - 0x00, 0x21, 0x00, 0x00, 0x4A, 0x00, 0x00, 0x6B, 0x00, 0x00, 0x94, 0x00, 0x00, 0xB5, 0x00, 0x00, - 0xDE, 0x00, 0x00, 0xFF, 0x00, 0x6B, 0x00, 0x00, 0xFF, 0x33, 0x33, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, - 0xFF, 0xFF, 0xCC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x99, 0x00, 0xCC, 0x00, 0x00, 0x21, 0xFF, 0x0B, - 0x4E, 0x45, 0x54, 0x53, 0x43, 0x41, 0x50, 0x45, 0x32, 0x2E, 0x30, 0x03, 0x01, 0xA0, 0x0F, 0x00, - 0x21, 0xF9, 0x04, 0x09, 0x14, 0x00, 0x0B, 0x00, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x28, 0x00, 0x3C, - 0x00, 0x03, 0x04, 0xFB, 0x70, 0xC9, 0x49, 0x6B, 0x75, 0x36, 0xEB, 0xBD, 0x31, 0xFF, 0xA0, 0xE4, - 0x8C, 0xCA, 0xE8, 0x85, 0xE8, 0xA5, 0xAC, 0x67, 0xEA, 0x8A, 0xE5, 0x2B, 0x2F, 0xE3, 0x31, 0xCE, - 0xAF, 0x41, 0x1C, 0xB8, 0x1B, 0x24, 0x80, 0x04, 0xAF, 0x87, 0x02, 0x26, 0x88, 0xA1, 0x07, 0x60, - 0xB9, 0x44, 0x82, 0x04, 0x02, 0x80, 0x61, 0x30, 0x70, 0x6E, 0x0C, 0x86, 0x03, 0x60, 0x20, 0xB0, - 0x6A, 0xA8, 0xD3, 0x03, 0x21, 0xEC, 0xAD, 0x18, 0x12, 0xE8, 0xF4, 0xB1, 0x4C, 0x51, 0xA0, 0x07, - 0xEA, 0x07, 0x5B, 0xF2, 0x70, 0x13, 0x76, 0xD4, 0xA8, 0xBC, 0xBC, 0xEA, 0x1F, 0x06, 0x77, 0x51, - 0x73, 0x50, 0x0A, 0x80, 0x7F, 0x04, 0x4C, 0x4D, 0x65, 0x06, 0x0A, 0x3B, 0x3B, 0x62, 0x5A, 0x53, - 0x65, 0x05, 0x02, 0x04, 0x68, 0x0C, 0x6A, 0x00, 0x5D, 0x5E, 0x0F, 0x0F, 0x6A, 0x98, 0x6A, 0x09, - 0x7B, 0x56, 0x9D, 0x09, 0x0C, 0xA7, 0xA7, 0x7F, 0x06, 0x9D, 0xA3, 0x44, 0x02, 0x01, 0x03, 0x90, - 0x0C, 0x87, 0x03, 0x06, 0x02, 0x05, 0x56, 0x06, 0x01, 0x02, 0x53, 0xB1, 0xB3, 0x04, 0x79, 0xAF, - 0x55, 0x48, 0x51, 0xB0, 0x87, 0xC0, 0x7F, 0x07, 0x95, 0x05, 0x85, 0x44, 0xB6, 0x00, 0x05, 0x53, - 0x96, 0x6A, 0x60, 0x02, 0x0A, 0x48, 0x89, 0x00, 0x07, 0xA1, 0x69, 0x7D, 0x2B, 0x3D, 0x9D, 0x41, - 0xA1, 0x04, 0xA0, 0xDD, 0x9D, 0x38, 0x02, 0xE1, 0x6A, 0x07, 0x62, 0x0C, 0x77, 0xE6, 0xAD, 0x2F, - 0x05, 0x01, 0xB6, 0x90, 0x07, 0xA8, 0xA7, 0x54, 0xB5, 0xBC, 0x06, 0x33, 0x50, 0x53, 0x3A, 0x00, - 0x39, 0x62, 0x10, 0x6B, 0xDF, 0xBE, 0x19, 0x03, 0x18, 0x40, 0xA9, 0x15, 0x4B, 0xCC, 0x0E, 0x77, - 0x3B, 0x04, 0xC4, 0x02, 0x38, 0x43, 0x21, 0x96, 0x2C, 0xD3, 0xD6, 0x81, 0x01, 0x26, 0x2A, 0xFB, - 0xDE, 0x07, 0x7C, 0x0A, 0xB7, 0x71, 0x1B, 0x79, 0xEE, 0xC5, 0x83, 0x72, 0xDD, 0x84, 0xBC, 0x4B, - 0x13, 0xA4, 0x13, 0x15, 0x17, 0xAB, 0x18, 0x78, 0x4A, 0x43, 0x40, 0x81, 0x43, 0x76, 0x8E, 0xB6, - 0x04, 0x7C, 0x19, 0x02, 0x98, 0xC4, 0x86, 0x35, 0xBD, 0xE1, 0x1C, 0x90, 0x4D, 0x62, 0xBF, 0x14, - 0xFC, 0x7E, 0x02, 0x1A, 0x60, 0xD3, 0xD1, 0x9D, 0x3B, 0x3A, 0x09, 0xFC, 0x44, 0xB1, 0xD0, 0x96, - 0x8E, 0x43, 0x8D, 0x9E, 0xDA, 0xDB, 0x22, 0x11, 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xB7, - 0x90, 0x68, 0x72, 0xD1, 0x7C, 0xD9, 0x3D, 0xA3, 0x94, 0x35, 0xDE, 0x54, 0x06, 0x92, 0x51, 0x50, - 0x68, 0xC2, 0xC5, 0x44, 0xB7, 0x30, 0x70, 0xDE, 0x6A, 0x49, 0x69, 0x86, 0xC5, 0x2D, 0xA3, 0x29, - 0x04, 0x05, 0x2F, 0xD9, 0xC4, 0x02, 0x0C, 0x6C, 0x0C, 0x48, 0xB0, 0x94, 0x01, 0xDA, 0x3C, 0xF2, - 0x56, 0x21, 0xFA, 0xE8, 0xA3, 0xA1, 0x55, 0x12, 0xE9, 0xF4, 0x56, 0x42, 0xF8, 0x50, 0x00, 0x40, - 0x08, 0x08, 0xD4, 0x88, 0x80, 0x05, 0x33, 0x66, 0x10, 0xA2, 0x0C, 0xDC, 0xA0, 0xB0, 0xA3, 0x0B, - 0x71, 0xCD, 0xB1, 0x80, 0x75, 0x69, 0x20, 0x41, 0xE4, 0x91, 0x6B, 0x64, 0x10, 0x01, 0x00, 0x21, - 0xF9, 0x04, 0x09, 0x14, 0x00, 0x0B, 0x00, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x28, 0x00, 0x3C, 0x00, - 0x03, 0x04, 0xFB, 0x70, 0xC9, 0x49, 0x6B, 0x75, 0x36, 0xEB, 0xBD, 0x31, 0xFF, 0xA0, 0xE4, 0x8C, - 0xA4, 0x17, 0x9E, 0x57, 0x89, 0xAE, 0xA9, 0xC9, 0xAE, 0xE3, 0x31, 0xBE, 0xAF, 0x31, 0x1C, 0x34, - 0x1B, 0x24, 0x4C, 0x82, 0xE7, 0x28, 0x5E, 0x02, 0x78, 0x7A, 0x30, 0x8E, 0x47, 0x62, 0x48, 0x20, - 0x60, 0xD8, 0x06, 0x4A, 0x8E, 0xC1, 0x70, 0x60, 0x0C, 0x04, 0xD1, 0xCD, 0x60, 0x60, 0x3B, 0x10, - 0xBA, 0x59, 0x8B, 0x21, 0x41, 0x2E, 0x0F, 0xC3, 0x16, 0xF2, 0xC0, 0xAC, 0x40, 0x4F, 0x1E, 0x80, - 0x04, 0x81, 0x70, 0xD8, 0x0A, 0x14, 0x0F, 0xF7, 0x42, 0x00, 0xA0, 0xD6, 0x09, 0x0A, 0x81, 0x81, - 0x68, 0x00, 0x85, 0x85, 0x7F, 0x07, 0x07, 0x0A, 0x06, 0x7A, 0x06, 0x00, 0x74, 0x74, 0x5E, 0x8A, - 0x36, 0x68, 0x05, 0x7C, 0x66, 0x3D, 0x64, 0x58, 0x61, 0x0F, 0x0F, 0x66, 0x64, 0x99, 0x64, 0x79, - 0x9C, 0x9E, 0xA0, 0x48, 0x4E, 0x9D, 0xA3, 0x4A, 0x02, 0x01, 0x37, 0x90, 0x55, 0x04, 0x5C, 0x02, - 0x05, 0x59, 0x06, 0x01, 0x02, 0x4F, 0x89, 0x55, 0x76, 0xAC, 0x50, 0xAB, 0x0A, 0xAD, 0x7F, 0xB1, - 0x75, 0x07, 0x02, 0x04, 0x05, 0x00, 0xBE, 0x39, 0x06, 0x77, 0x05, 0x36, 0x04, 0x9F, 0x5B, 0xCC, - 0x00, 0x4A, 0x82, 0x81, 0x07, 0x9F, 0x65, 0x86, 0x85, 0x40, 0x9D, 0x0A, 0x9F, 0x0C, 0xD0, 0x9F, - 0x00, 0x9D, 0x39, 0x02, 0xDE, 0x66, 0xB0, 0x73, 0xE2, 0x09, 0xE4, 0xAA, 0x2F, 0x05, 0x01, 0xCC, - 0x5E, 0xA7, 0x56, 0x75, 0xD2, 0xB8, 0x8C, 0x2F, 0x4C, 0x36, 0x06, 0xB1, 0x73, 0xE1, 0x88, 0xC9, - 0x92, 0x45, 0x43, 0x96, 0x00, 0x2E, 0x37, 0xE8, 0x79, 0x99, 0x53, 0xEC, 0x86, 0x0D, 0x06, 0x05, - 0xF3, 0x51, 0x61, 0x57, 0xE6, 0x9E, 0xBF, 0x35, 0x0C, 0xDE, 0x81, 0xE8, 0x64, 0x10, 0xFB, 0x5B, - 0xB6, 0x6C, 0xF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x85, 0x47, 0x8D, 0xD8, 0xC8, 0xD9, - 0xE2, 0xF0, 0x55, 0x99, 0x4A, 0xE3, 0x82, 0x07, 0x41, 0x3F, 0x25, 0x92, 0xAE, 0xD7, 0x4C, 0x3C, - 0xE7, 0xAC, 0x02, 0x04, 0x58, 0xC4, 0xC4, 0xAD, 0x9C, 0x1B, 0xB1, 0x3F, 0xE1, 0x42, 0x3D, 0x4B, - 0x9E, 0x85, 0xCB, 0x57, 0xA6, 0x30, 0x4B, 0x97, 0x88, 0x26, 0xA2, 0x03, 0x7F, 0x8B, 0x72, 0x2D, - 0x90, 0x79, 0x02, 0xFD, 0x59, 0x36, 0xB2, 0xF3, 0x41, 0x2A, 0x65, 0xAD, 0x75, 0x64, 0x3A, 0x0C, - 0x48, 0xB4, 0x15, 0x35, 0x13, 0xE0, 0xC2, 0xC0, 0x2D, 0xB1, 0x15, 0x95, 0x0C, 0x13, 0x97, 0x59, - 0x73, 0x90, 0x01, 0xF5, 0xAC, 0x36, 0x8D, 0x79, 0x12, 0x40, 0xB8, 0x45, 0x22, 0xB8, 0xF8, 0xC4, - 0x0C, 0x7D, 0xB3, 0x31, 0x96, 0xCF, 0x00, 0x01, 0x76, 0x41, 0x80, 0x4F, 0x0B, 0x80, 0x78, 0x4A, - 0x24, 0x5B, 0x8C, 0x18, 0xDB, 0x8A, 0x0A, 0xF0, 0xC3, 0x15, 0x88, 0x08, 0xF1, 0xC5, 0xC7, 0x3C, - 0x13, 0x40, 0x94, 0x01, 0x81, 0x13, 0x20, 0xA0, 0x23, 0x02, 0x27, 0xE0, 0x58, 0x63, 0x08, 0xD9, - 0xE8, 0x41, 0x81, 0x5B, 0x42, 0x7A, 0x57, 0x86, 0x12, 0x46, 0x26, 0x79, 0x46, 0x06, 0x11, 0x00, - 0x00, 0x21, 0xF9, 0x04, 0x09, 0x14, 0x00, 0x0B, 0x00, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x28, 0x00, - 0x3C, 0x00, 0x03, 0x04, 0xFB, 0x70, 0xC9, 0x49, 0x6B, 0x75, 0x36, 0xEB, 0xBD, 0x31, 0xFF, 0xA0, - 0xE4, 0x8C, 0xA4, 0x17, 0x9E, 0x57, 0x89, 0xAE, 0xA9, 0xC9, 0xAE, 0xE3, 0x31, 0xBE, 0xAF, 0xA1, - 0x1C, 0x34, 0x1B, 0x24, 0x4A, 0x82, 0xE7, 0x27, 0x85, 0x50, 0x08, 0x0C, 0x3D, 0x12, 0xBC, 0xC4, - 0xA3, 0x18, 0x12, 0x08, 0x14, 0x86, 0xC1, 0x80, 0xC9, 0x31, 0x18, 0x0E, 0x84, 0x81, 0x80, 0xBA, - 0x91, 0x46, 0xB1, 0x51, 0x06, 0xD7, 0x62, 0x40, 0x9A, 0x91, 0xE2, 0x71, 0xA5, 0x37, 0x40, 0x33, - 0xDE, 0xE9, 0xF1, 0xE3, 0xA1, 0x20, 0x10, 0x0E, 0x52, 0x01, 0x63, 0xA9, 0x5E, 0x0C, 0x85, 0x03, - 0x76, 0x7A, 0x7D, 0x0B, 0x4E, 0x03, 0x75, 0x78, 0x77, 0x78, 0x06, 0x84, 0x51, 0x37, 0x8A, 0x77, - 0x02, 0x51, 0x6A, 0x05, 0x02, 0x04, 0x67, 0x67, 0x5B, 0x72, 0x47, 0x98, 0x98, 0x7C, 0x5C, 0x73, - 0x66, 0x58, 0x07, 0x8B, 0x0F, 0x00, 0x9F, 0x45, 0x02, 0x01, 0x03, 0xA3, 0x0C, 0x89, 0x03, 0x06, - 0x02, 0x00, 0x5C, 0x06, 0x01, 0x92, 0x52, 0x07, 0xAE, 0x59, 0x03, 0x00, 0xBD, 0xBD, 0x4C, 0x02, - 0x05, 0xAB, 0xB9, 0x70, 0x0C, 0xAC, 0x96, 0x00, 0x52, 0x45, 0x36, 0xC1, 0x51, 0x97, 0x0C, 0x66, - 0x5E, 0x00, 0x8C, 0x4C, 0x0A, 0x05, 0x5F, 0x68, 0x98, 0x4E, 0x56, 0x40, 0x7F, 0x3D, 0x67, 0x97, - 0x9D, 0x73, 0x39, 0x02, 0x74, 0x9C, 0x48, 0xA4, 0x76, 0x76, 0x66, 0x73, 0xA8, 0x2C, 0x05, 0x50, - 0x02, 0xA3, 0xA3, 0x59, 0x78, 0x5E, 0x92, 0xD4, 0x2C, 0xDB, 0xB0, 0x59, 0x76, 0x07, 0x00, 0x78, - 0x16, 0x09, 0x80, 0xF5, 0xE4, 0x05, 0xC1, 0x81, 0x5F, 0xB0, 0x10, 0x00, 0xA0, 0xEE, 0xC0, 0xC0, - 0x03, 0x8E, 0x68, 0x68, 0xB1, 0x72, 0xE5, 0x92, 0xAF, 0x5E, 0xF6, 0x0C, 0x10, 0xF0, 0x86, 0x62, - 0xFB, 0xCE, 0xC1, 0x03, 0x98, 0x00, 0x74, 0x42, 0x42, 0xE7, 0xC5, 0xB9, 0x4E, 0xFF, 0xC2, 0x9D, - 0x99, 0xA3, 0x60, 0x0A, 0x0A, 0x03, 0xED, 0xC0, 0xDD, 0xF1, 0x47, 0xCF, 0xCB, 0x2E, 0x97, 0x20, - 0x92, 0x0D, 0x64, 0x85, 0xA5, 0x65, 0x43, 0x2C, 0x3C, 0x19, 0x10, 0x30, 0x94, 0x2F, 0x27, 0xBE, - 0x9D, 0x87, 0x78, 0xCE, 0x54, 0x47, 0xC0, 0x98, 0xC6, 0x9D, 0x39, 0x2F, 0xC6, 0xB2, 0xF1, 0x87, - 0x29, 0x96, 0x62, 0xC6, 0xB6, 0x69, 0xE2, 0xC0, 0x2B, 0x4A, 0x2C, 0x58, 0x49, 0x47, 0xDA, 0x11, - 0x6A, 0x69, 0xC0, 0xB8, 0x10, 0x22, 0x1F, 0xDC, 0x0A, 0xF4, 0x6D, 0x64, 0x02, 0x06, 0xB1, 0x04, - 0x28, 0x39, 0xBB, 0xA1, 0xDD, 0x49, 0x4C, 0xE9, 0xD4, 0xB9, 0x4D, 0x0A, 0xA2, 0x40, 0x81, 0x91, - 0x81, 0x68, 0x2E, 0x35, 0x43, 0xA0, 0xC0,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, 0xF8, - 0xF1, 0xC7, 0x3C, 0x00, 0xAA, 0xC6, 0xCB, 0x45, 0xFC, 0x21, 0xD5, 0x52, 0x72, 0x17, 0x95, 0x88, - 0xD8, 0x09, 0x08, 0x00, 0x80, 0x00, 0x02, 0x28, 0x94, 0x28, 0xC1, 0x8C, 0x20, 0x20, 0xD1, 0x5D, - 0x02, 0x27, 0xE8, 0x88, 0x82, 0x5B, 0x84, 0x2C, 0xE0, 0xD6, 0x19, 0x4C, 0x1C, 0xA9, 0xA4, 0x19, - 0x1B, 0x44, 0x00, 0x00, 0x21, 0xFE, 0x19, 0x42, 0x6F, 0x79, 0x27, 0x73, 0x20, 0x48, 0x61, 0x70, - 0x70, 0x79, 0x20, 0x48, 0x6F, 0x6C, 0x69, 0x64, 0x61, 0x79, 0x73, 0x20, 0x50, 0x61, 0x67, 0x65, - 0x00, 0x3B - -}; - -static const uint8_t bird_gif[] PROGMEM = { - 0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x74, 0x00, 0x4E, 0x00, 0xCC, 0x13, 0x00, 0xFF, 0xFF, 0xFF, - 0xEF, 0xFF, 0xFF, 0xBD, 0xE7, 0xE7, 0xD6, 0xEF, 0xEF, 0x63, 0x63, 0x63, 0xAD, 0xAD, 0xAD, 0xCE, - 0xCE, 0xCE, 0xD6, 0xDE, 0xDE, 0x4A, 0x4A, 0x4A, 0x7B, 0x84, 0x84, 0x94, 0x9C, 0x9C, 0xE7, 0xE7, - 0xE7, 0x84, 0x94, 0x94, 0xB5, 0xC6, 0xC6, 0x73, 0x7B, 0x7B, 0x31, 0x31, 0x31, 0xF7, 0xF7, 0xF7, - 0x18, 0x10, 0x10, 0xCE, 0x63, 0x39, 0x6B, 0x39, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0xFF, 0x0B, - 0x4E, 0x45, 0x54, 0x53, 0x43, 0x41, 0x50, 0x45, 0x32, 0x2E, 0x30, 0x03, 0x01, 0x00, 0x00, 0x00, - 0x21, 0xF9, 0x04, 0x09, 0x0A, 0x00, 0x00, 0x00, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x74, 0x00, 0x4B, - 0x00, 0x00, 0x05, 0xFF, 0x20, 0x20, 0x8E, 0x64, 0x69, 0x9E, 0x68, 0xAA, 0xAE, 0xEC, 0x68, 0x2C, - 0x6D, 0x2C, 0xCF, 0x74, 0x6D, 0x03, 0x46, 0x84, 0x40, 0x77, 0xEF, 0xFF, 0x40, 0x51, 0x42, 0x41, - 0x0C, 0x1A, 0x8F, 0x48, 0x13, 0xC1, 0xD0, 0x20, 0x00, 0x0E, 0x8E, 0x42, 0x72, 0x4A, 0xAD, 0x21, - 0x0E, 0xCD, 0x05, 0xE1, 0x80, 0xA8, 0x7A, 0xBF, 0x29, 0xC2, 0xA0, 0x91, 0x28, 0x34, 0x02, 0x5D, - 0xB0, 0x5A, 0xFD, 0x08, 0x34, 0x14, 0x84, 0x00, 0x7A, 0x4D, 0xF7, 0x22, 0xDC, 0x89, 0xB8, 0xC1, - 0xB9, 0x80, 0xD5, 0xFF, 0x40, 0x0B, 0x77, 0x0C, 0x0F, 0x05, 0x01, 0x0C, 0x0A, 0x0B, 0x0F, 0x08, - 0x06, 0x80, 0x8E, 0x37, 0x7B, 0x01, 0x09, 0x11, 0x03, 0x68, 0x5C, 0x4C, 0x0A, 0x8F, 0x9A, 0x33, - 0x06, 0x09, 0x01, 0x0E, 0x71, 0x68, 0x88, 0x92, 0x07, 0x9B, 0xA6, 0x2C, 0x0A, 0x86, 0x07, 0x95, - 0x05, 0x04, 0xA1, 0x5D, 0x8D, 0xA7, 0xB2, 0x26, 0x09, 0x06, 0x72, 0x72, 0x0E, 0x94, 0x01, 0xA9, - 0x04, 0x08, 0x52, 0xB3, 0xC0, 0x00, 0x09, 0x95, 0xB7, 0x0D, 0x86, 0x01, 0x04, 0x0A, 0xC3, 0x09, - 0x34, 0x43, 0xC1, 0x54, 0x0E, 0xB7, 0xD2, 0x87, 0xAE, 0xBB, 0x99, 0x32, 0x7B, 0x0E, 0xCF, 0x49, - 0x0B, 0xD1, 0xD3, 0x72, 0x0C, 0xDE, 0x57, 0x33, 0xBE, 0xCC, 0xDB, 0x47, 0x05, 0x0C, 0xDF, 0xD3, - 0x05, 0xD7, 0x31, 0x0C, 0xE1, 0xA5, 0xE7, 0x46, 0xBE, 0xEB, 0xD2, 0x04, 0x05, 0xBF, 0x2C, 0x5C, - 0x4D, 0xF3, 0x46, 0x0B, 0x11, 0x56, 0xD9, 0x3B, 0x14, 0x01, 0x14, 0x0F, 0x16, 0x04, 0x1A, 0x30, - 0x28, 0x00, 0x81, 0xA1, 0x3F, 0x1F, 0xAD, 0x02, 0x10, 0x5B, 0x87, 0x6F, 0x0E, 0x8B, 0x02, 0x0E, - 0x04, 0x5C, 0x41, 0x10, 0xF0, 0x61, 0x8F, 0x25, 0x03, 0x26, 0xDA, 0x43, 0xC4, 0x42, 0x8B, 0x00, - 0x05, 0x0E, 0x7C, 0xFF, 0xED, 0xF0, 0x68, 0x83, 0x8B, 0x44, 0x91, 0xDF, 0x06, 0xAC, 0x54, 0x01, - 0x21, 0xA1, 0x80, 0x07, 0x0F, 0x1A, 0x38, 0x70, 0xC7, 0x72, 0x46, 0xC2, 0x97, 0x03, 0x3F, 0xC5, - 0x52, 0xE1, 0x80, 0x81, 0x00, 0x01, 0x19, 0x1B, 0x3C, 0x38, 0xD8, 0x53, 0xC6, 0x81, 0x38, 0x21, - 0x61, 0x4A, 0xEB, 0xB7, 0x42, 0x01, 0x82, 0xA3, 0x58, 0x7D, 0xC9, 0x6B, 0x1A, 0x63, 0x0B, 0xD0, - 0x81, 0x11, 0x08, 0x74, 0x44, 0x61, 0xE0, 0x01, 0xD6, 0xA3, 0x05, 0x16, 0x2D, 0xE5, 0xDA, 0xC2, - 0x80, 0xB7, 0x90, 0x41, 0xCB, 0xA4, 0x39, 0xC1, 0xEF, 0x2C, 0x56, 0xAA, 0x6C, 0x57, 0x38, 0xA8, - 0x14, 0x35, 0xA8, 0x35, 0x14, 0x10, 0x10, 0x34, 0xB0, 0x9B, 0xD5, 0x4F, 0xDE, 0x14, 0x06, 0x8E, - 0xF5, 0x1D, 0xC8, 0x25, 0x85, 0x83, 0xC1, 0x84, 0x05, 0x20, 0x32, 0x30, 0xF4, 0x30, 0x2D, 0x39, - 0x8B, 0x07, 0x32, 0x42, 0xA1, 0x00, 0x72, 0xE4, 0x45, 0x08, 0x7C, 0x59, 0x36, 0x91, 0x18, 0x73, - 0xE6, 0x6F, 0x79, 0x38, 0x2B, 0x88, 0x7C, 0x54, 0xE7, 0xE0, 0x2D, 0xA3, 0x4B, 0x78, 0x7A, 0x79, - 0x7A, 0x1A, 0xCE, 0x04, 0x4C, 0x85, 0xAC, 0x66, 0x7D, 0x96, 0x80, 0xB9, 0xD8, 0x22, 0x4A, 0x4B, - 0x14, 0x00, 0x97, 0xF1, 0xD3, 0x12, 0x3B, 0x79, 0x9F, 0x45, 0xC0, 0x13, 0xB8, 0xB7, 0xE1, 0xC5, - 0x19, 0x33, 0xEB, 0x53, 0xD3, 0xA8, 0x72, 0x01, 0x0D, 0x44, 0x97, 0x5C, 0x90, 0x7B, 0x9B, 0x01, - 0x05, 0xA6, 0x89, 0xFB, 0x3D, 0x54, 0x20, 0x81, 0xDA, 0x8C, 0xD7, 0x91, 0x16, 0x22, 0x91, 0xF8, - 0x80, 0x9F, 0x86, 0x08, 0x1E, 0xF4, 0xF2, 0xD5, 0x7D, 0x96, 0x18, 0xCC, 0x47, 0xA3, 0xDB, 0x7B, - 0xCA, 0x60, 0x40, 0xCA, 0xF4, 0x58, 0x81, 0xE2, 0x42, 0x04, 0x11, 0x4C, 0x80, 0x53, 0x7C, 0x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, 0x64, 0x9D, 0x72, 0x70, 0x54, 0x29, 0x03, 0x04, 0xDF, 0xE5, - 0xE1, 0x4A, 0x19, 0x06, 0xB0, 0xD9, 0xC4, 0x66, 0x48, 0x7C, 0x27, 0xCD, 0x88, 0x98, 0x92, 0x89, - 0xE2, 0x75, 0x69, 0x2D, 0x69, 0xC3, 0x02, 0x07, 0xA4, 0x03, 0x8A, 0x2B, 0x8E, 0xC2, 0x04, 0x05, - 0x03, 0x48, 0x3C, 0x17, 0x5E, 0xAB, 0x7E, 0x61, 0x04, 0x20, 0x03, 0x33, 0x21, 0x01, 0xC1, 0x02, - 0xDF, 0x81, 0x52, 0x8B, 0x34, 0xAD, 0xC8, 0x6A, 0x43, 0x3E, 0x48, 0x9E, 0xF5, 0x24, 0x45, 0xAF, - 0xF2, 0x96, 0x9D, 0xFF, 0x03, 0xF5, 0x51, 0xD1, 0xA2, 0x03, 0x90, 0xCA, 0xF1, 0x94, 0x3E, 0x37, - 0x68, 0x81, 0xA4, 0x98, 0xC0, 0x9A, 0xF8, 0xC0, 0x8F, 0xCA, 0x39, 0xA0, 0xCD, 0x1F, 0x0B, 0x10, - 0x21, 0x0D, 0x03, 0xB8, 0x7D, 0x74, 0x64, 0x98, 0xD2, 0x16, 0x8A, 0x0C, 0xBA, 0xCA, 0x29, 0xF5, - 0x48, 0x8B, 0x53, 0xA1, 0x19, 0x03, 0xA8, 0x18, 0x85, 0xB2, 0x2A, 0xB9, 0x63, 0x06, 0x45, 0x06, - 0x80, 0x48, 0x05, 0xC9, 0x6E, 0x9C, 0x4F, 0xE1, 0xA3, 0xC2, 0x77, 0xF0, 0x16, 0x95, 0x4B, 0xB7, - 0xF4, 0x12, 0xEA, 0x57, 0x59, 0x14, 0xB2, 0x46, 0x08, 0xB8, 0x8E, 0x08, 0x72, 0x06, 0xB3, 0x3E, - 0xA6, 0xF2, 0x28, 0x46, 0x8B, 0x2C, 0xEB, 0xED, 0x03, 0xF3, 0x56, 0x5C, 0xF0, 0x40,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D, 0x80, 0x37, 0xDE, 0x0A, 0x8E, 0xFB, 0x06, 0x1C, 0x00, 0x4D, 0xE0, 0x1E, - 0x80, 0x0C, 0x73, 0xFB, 0x47, 0x00, 0xE8, 0x2C, 0x89, 0x6E, 0xCF, 0x0C, 0x66, 0x87, 0x64, 0x55, - 0x73, 0x87, 0xB5, 0xD2, 0x39, 0xF2, 0x54, 0xA3, 0xAD, 0x24, 0xEF, 0x09, 0xC4, 0x2E, 0x47, 0x0C, - 0x83, 0x4F, 0x44, 0x6E, 0x25, 0xA9, 0x0C, 0x8F, 0x43, 0xE0, 0xD3, 0xB4, 0x30, 0x50, 0x54, 0xF9, - 0x41, 0x57, 0xC9, 0x63, 0xE6, 0x03, 0x00, 0xC1, 0xED, 0xE9, 0xAB, 0x60, 0x4F, 0x62, 0x94, 0x41, - 0x2A, 0xFE, 0x01, 0x56, 0x11, 0x10, 0xB3, 0x65, 0x4F, 0x11, 0xCC, 0x37, 0x4A, 0x10, 0x2C, 0x8E, - 0x3C, 0x80, 0x40, 0x3A, 0x30, 0x20, 0x02, 0x96, 0x10, 0x3F, 0x13, 0x64, 0xA7, 0x1E, 0x17, 0x53, - 0x90, 0x02, 0x28, 0x87, 0x00, 0xB2, 0xC1, 0xE0, 0x29, 0x08, 0x24, 0x50, 0xC9, 0xFE, 0x37, 0x3C, - 0x28, 0x30, 0x67, 0x75, 0x01, 0x9C, 0x20, 0x4E, 0x0A, 0xE0, 0xAC, 0xAF, 0x21, 0x90, 0x3E, 0x0D, - 0x4C, 0x41, 0xBB, 0x42, 0x13, 0x05, 0x63, 0xA4, 0x64, 0x81, 0x43, 0x28, 0x40, 0xED, 0x44, 0x00, - 0x01, 0x2C, 0x78, 0x29, 0x85, 0x2C, 0x38, 0x56, 0x62, 0x1A, 0xC0, 0x1D, 0x35, 0x84, 0x00, 0x00, - 0x21, 0xF9, 0x04, 0x09, 0x0A, 0x00, 0x00, 0x00, 0x2C, 0x00, 0x00, 0x17, 0x00, 0x6A, 0x00, 0x32, - 0x00, 0x00, 0x05, 0xFF, 0x20, 0x20, 0x8E, 0x64, 0x69, 0x9E, 0x68, 0xAA, 0x8A, 0x85, 0x02, 0xAD, - 0x70, 0x2C, 0xCF, 0x74, 0x5D, 0x26, 0x0C, 0x63, 0xD8, 0x7C, 0xEF, 0xFF, 0xA2, 0x05, 0x21, 0x80, - 0x58, 0x2C, 0x70, 0x0B, 0xA0, 0x72, 0xC9, 0x64, 0x34, 0x0C, 0x89, 0x86, 0x42, 0xC8, 0xAC, 0x5A, - 0x6B, 0x54, 0x46, 0x81, 0x11, 0x70, 0x5E, 0xBF, 0x60, 0x94, 0xA2, 0xB0, 0x40, 0x10, 0x00, 0x86, - 0x73, 0x23, 0x71, 0x08, 0xBB, 0xAF, 0x90, 0x73, 0xE2, 0x11, 0x28, 0x97, 0x1B, 0xBA, 0xB7, 0x7E, - 0xA9, 0x68, 0x04, 0x0A, 0x01, 0x01, 0x04, 0x39, 0x01, 0x50, 0x7B, 0x87, 0x3E, 0x0B, 0x5C, 0x81, - 0x5D, 0x0F, 0x03, 0x01, 0x78, 0x69, 0x05, 0x88, 0x94, 0x33, 0x0C, 0x8F, 0x8C, 0x0B, 0x81, 0x5A, - 0x08, 0x06, 0x2D, 0x3F, 0x0A, 0x0A, 0x33, 0x0B, 0x63, 0x0D, 0x49, 0x95, 0x26, 0x2D, 0x8C, 0xAB, - 0x05, 0x04, 0x7E, 0x0D, 0x67, 0x3C, 0x10, 0x09, 0x0A, 0x0C, 0x26, 0x10, 0x0E, 0x83, 0x05, 0x07, - 0x0B, 0x69, 0x0F, 0xB4, 0x0E, 0x0F, 0x9D, 0xA8, 0x24, 0x06, 0x08, 0xAB, 0xC8, 0x81, 0xA1, 0x3C, - 0x07, 0x0E, 0x6B, 0x6D, 0x25, 0x06, 0x11, 0x11, 0x12, 0x13, 0x13, 0x0F, 0x11, 0x80, 0xAC, 0xC2, - 0xD0, 0xA8, 0x65, 0x01, 0x98, 0xC9, 0x10, 0x66, 0x0E, 0x93, 0x32, 0x07, 0x38, 0x02, 0x0C, 0xB4, - 0xA2, 0x25, 0x07, 0x08, 0x13, 0x12, 0xF2, 0x13, 0x06, 0x7F, 0x07, 0xDB, 0xED, 0x95, 0xDF, 0xE1, - 0xC9, 0x63, 0x71, 0xDD, 0x29, 0x8E, 0xB8, 0x12, 0xA0, 0x2E, 0x94, 0x03, 0x14, 0xB0, 0xE4, 0x55, - 0x53, 0x80, 0x40, 0x01, 0xB2, 0x01, 0xB9, 0x4E, 0x21, 0x3A, 0x30, 0x64, 0x00, 0xBF, 0x64, 0x0B, - 0x1E, 0x48, 0x3C, 0x41, 0x2A, 0x0A, 0xC1, 0x8F, 0x05, 0x8A, 0x04, 0x74, 0x10, 0x4F, 0x42, 0x84, - 0x07, 0x0E, 0x93, 0xFF, 0x35, 0x40, 0x60, 0xEE, 0x90, 0x14, 0x70, 0x17, 0x91, 0x29, 0x48, 0x80, - 0x62, 0xC1, 0x16, 0x05, 0x1F, 0x73, 0x12, 0x9C, 0xB9, 0xA2, 0x40, 0x04, 0x04, 0x09, 0x82, 0x6A, - 0x4B, 0xC6, 0x80, 0x80, 0x81, 0x17, 0x7A, 0x0A, 0xD4, 0xB3, 0x18, 0x33, 0x10, 0x84, 0x5F, 0x6C, - 0x48, 0xB4, 0x1A, 0xA8, 0x53, 0x67, 0x82, 0x1D, 0x2B, 0x84, 0x2C, 0x4A, 0xB6, 0xEA, 0xC0, 0x4C, - 0x1C, 0xA6, 0x20, 0x20, 0xB5, 0x32, 0x05, 0x66, 0xD3, 0x40, 0x07, 0xA0, 0xD8, 0x12, 0xD1, 0xE0, - 0x41, 0x83, 0xAA, 0x55, 0x61, 0x31, 0xC8, 0xA7, 0x82, 0xA1, 0x83, 0x7A, 0x5C, 0x19, 0x41, 0x48, - 0xDB, 0x22, 0x47, 0xD0, 0xA3, 0x4C, 0x52, 0x32, 0x3D, 0x0B, 0x0E, 0x01, 0x34, 0x03, 0x6E, 0xE1, - 0xC2, 0xC5, 0x43, 0x57, 0x05, 0x04, 0x28, 0x04, 0x1C, 0x38, 0xB9, 0x97, 0x17, 0xD9, 0x81, 0x02, - 0x7F, 0xC7, 0xF6, 0x48, 0x10, 0x68, 0x80, 0x00, 0x8B, 0x95, 0x73, 0x8D, 0x38, 0xB0, 0xEE, 0xAD, - 0xE2, 0x8F, 0x0A, 0x08, 0x00, 0x94, 0x01, 0xA1, 0x17, 0x66, 0x02, 0xB0, 0x71, 0x84, 0x52, 0x9A, - 0x97, 0xB4, 0xEA, 0x1F, 0x07, 0xC1, 0x11, 0x24, 0xDC, 0xC0, 0xC1, 0x18, 0x00, 0xA4, 0x10, 0x30, - 0x38, 0x8D, 0xDA, 0xF0, 0x92, 0x05, 0x69, 0x0F, 0xA4, 0x55, 0xE0, 0x40, 0x32, 0xDE, 0xAE, 0xE5, - 0x7A, 0xE0, 0x02, 0xD0, 0x79, 0x77, 0x65, 0x70, 0xB0, 0x09, 0x14, 0x20, 0xFE, 0x51, 0xFB, 0xC6, - 0x2F, 0x8F, 0x85, 0x42, 0x40, 0x86, 0xF9, 0x7B, 0x0C, 0x5C, 0x8C, 0x3C, 0x7F, 0x26, 0xDC, 0x85, - 0xC0, 0x83, 0x41, 0xA6, 0x4F, 0x6B, 0x41, 0x04, 0xA1, 0xD5, 0x73, 0xB4, 0xDA, 0x35, 0xAB, 0xB8, - 0x8C, 0x23, 0xBD, 0xF5, 0xEB, 0x30, 0x41, 0xD0, 0xD6, 0x69, 0x6B, 0x34, 0x80, 0x0A, 0x04, 0xEB, - 0xA8, 0x14, 0x85, 0xFF, 0x7E, 0x41, 0x60, 0xE6, 0x40, 0x02, 0x05, 0x48, 0xE1, 0x47, 0x75, 0xBB, - 0xB1, 0xC7, 0xC8, 0x4A, 0xC4, 0xCD, 0x47, 0x0C, 0x2C, 0x31, 0x85, 0x64, 0x46, 0x64, 0x09, 0x20, - 0xF0, 0xC0, 0x2F, 0xF7, 0x39, 0xA0, 0x89, 0x7F, 0xEB, 0x01, 0x18, 0x88, 0x5A, 0xF1, 0xE5, 0xC4, - 0x40, 0x74, 0xC4, 0x00, 0xD0, 0x8C, 0x85, 0x03, 0x18, 0xD0, 0x21, 0x02, 0xD4, 0xA1, 0x98, 0xA2, - 0x8A, 0x10, 0x28, 0xF0, 0x00, 0x5C, 0x08, 0x30, 0xA8, 0x8F, 0x33, 0x2A, 0x5A, 0x46, 0x40, 0x02, - 0x27, 0xEA, 0xF8, 0x99, 0x8A, 0x88, 0x39, 0xA3, 0x13, 0x66, 0x34, 0xC5, 0x48, 0xC2, 0x2C, 0x29, - 0x15, 0x79, 0x9D, 0x7A, 0x15, 0xAA, 0xB8, 0x80, 0x6F, 0x39, 0xA1, 0x64, 0x9E, 0x94, 0x00, 0xF4, - 0x67, 0x65, 0x5E, 0x4C, 0x65, 0x79, 0x9D, 0x4D, 0x0E, 0x20, 0x20, 0xE2, 0x16, 0xCD, 0x09, 0x09, - 0x26, 0x00, 0x84, 0x8C, 0xC9, 0xD5, 0x60, 0xA0, 0x9D, 0x89, 0xC0, 0x84, 0x88, 0xDD, 0xF6, 0x66, - 0x0A, 0xCC, 0xC9, 0x79, 0x25, 0x7B, 0xE8, 0x34, 0xB4, 0x4A, 0x30, 0x06, 0xEE, 0x29, 0xC6, 0x03, - 0xF7, 0xF9, 0x69, 0xE5, 0x63, 0x04, 0xC4, 0x84, 0x98, 0x48, 0x86, 0x9A, 0x40, 0xD1, 0x56, 0x8A, - 0x56, 0x66, 0x40, 0x03, 0x52, 0xB0, 0x94, 0xE8, 0xA0, 0x1A, 0x45, 0x7A, 0x42, 0x01, 0xBE, 0x51, - 0x56, 0x29, 0x57, 0x97, 0x1A, 0x20, 0x6A, 0x65, 0x2B, 0x61, 0xE5, 0xA9, 0x3B, 0x09, 0x10, 0x50, - 0xE5, 0xA8, 0xA3, 0x0E, 0xA0, 0xDD, 0xAA, 0x27, 0x20, 0xA8, 0x1A, 0xAC, 0xB8, 0x0E, 0x42, 0xEB, - 0x09, 0x14, 0xBD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x52, 0x8B, 0x3C, 0xF8, - 0x42, 0x01, 0x5A, 0x1C, 0x62, 0x44, 0x86, 0x6B, 0x69, 0x46, 0x40, 0x87, 0x1E, 0x06, 0x02, 0x84, - 0x88, 0x33, 0x14, 0xF3, 0x57, 0x00, 0x6D, 0x09, 0x10, 0xC0, 0x09, 0x29, 0x2E, 0xE1, 0x80, 0x6B, - 0x6A, 0xC4, 0x80, 0x90, 0x66, 0x80, 0x69, 0xA6, 0xC0, 0x03, 0x0E, 0xD6, 0x28, 0x02, 0x04, 0x0C, - 0x28, 0xC2, 0xE2, 0x0A, 0x1C, 0xF9, 0xE0, 0xCE, 0x3E, 0x05, 0x94, 0xE6, 0x00, 0x02, 0x11, 0x68, - 0x21, 0xA4, 0x0C, 0x35, 0xB1, 0x11, 0x94, 0x49, 0x09, 0x35, 0xF0, 0x24, 0x0E, 0x48, 0x35, 0x61, - 0x4A, 0x93, 0x29, 0x4C, 0x69, 0xC4, 0x01, 0x42, 0x30, 0x70, 0x25, 0x1E, 0x20, 0x26, 0x44, 0x40, - 0x94, 0x0C, 0x38, 0xC4, 0x44, 0x13, 0x99, 0x1C, 0x10, 0x9B, 0x98, 0x34, 0x98, 0xC0, 0x4E, 0x9B, - 0x56, 0x74, 0x54, 0x08, 0x3B, 0x99, 0xB8, 0xF0, 0x48, 0x13, 0x4D, 0x88, 0x45, 0x27, 0x12, 0x0A, - 0x99, 0x83, 0x8A, 0x40, 0x73, 0xBE, 0x60, 0x57, 0x13, 0xA1, 0x0D, 0xFA, 0xD2, 0x6C, 0x93, 0x91, - 0x10, 0x02, 0x00, 0x21, 0xF9, 0x04, 0x09, 0x0A, 0x00, 0x00, 0x00, 0x2C, 0x00, 0x00, 0x20, 0x00, - 0x6A, 0x00, 0x2E, 0x00, 0x00, 0x05, 0xFF, 0x20, 0x00, 0x40, 0x62, 0xB9, 0x28, 0x08, 0x41, 0x28, - 0x4B, 0xE9, 0xBE, 0x70, 0x2C, 0xCF, 0x74, 0x6D, 0xDF, 0xE5, 0xF1, 0x3C, 0x69, 0x52, 0x24, 0x0F, - 0x82, 0xE1, 0x60, 0x00, 0x26, 0x5A, 0xB8, 0xA4, 0x72, 0xC9, 0x94, 0xE9, 0x22, 0x12, 0xC9, 0x64, - 0xF2, 0x18, 0x04, 0xAE, 0xD7, 0x01, 0xB0, 0xD0, 0xEC, 0x7A, 0xBF, 0x31, 0x48, 0x61, 0x12, 0x95, - 0x32, 0x02, 0x8E, 0x06, 0x36, 0x70, 0x50, 0x21, 0xC1, 0xF0, 0x78, 0x72, 0x91, 0x20, 0x4B, 0x55, - 0x85, 0xF5, 0xB5, 0x81, 0xE0, 0xCA, 0xFF, 0x80, 0x32, 0x0D, 0x0F, 0x53, 0x11, 0x11, 0x04, 0x07, - 0x7A, 0x57, 0x0E, 0x04, 0x6F, 0x81, 0x8F, 0x7F, 0x0B, 0x2A, 0x06, 0x94, 0x6A, 0x8A, 0x01, 0x06, - 0x04, 0x05, 0x07, 0x0B, 0x0B, 0x44, 0x94, 0xA0, 0x43, 0x24, 0x90, 0xA4, 0x37, 0x05, 0x04, 0x96, - 0x97, 0x58, 0x45, 0x09, 0x0A, 0x0C, 0x0C, 0x0A, 0x05, 0x0D, 0xB3, 0x05, 0x0A, 0x09, 0x0C, 0x05, - 0x06, 0xA3, 0x4D, 0x9F, 0xA0, 0x0B, 0xBB, 0xA5, 0x33, 0x6D, 0x08, 0x0C, 0x89, 0xAA, 0xC7, 0x8A, - 0x07, 0xAE, 0x3E, 0xC0, 0x32, 0x10, 0x07, 0x3F, 0x2A, 0x0E, 0x8C, 0x2A, 0x08, 0xD6, 0x29, 0x0E, - 0xB9, 0xCD, 0xC1, 0x22, 0x10, 0x45, 0xD2, 0xB8, 0x07, 0x56, 0x97, 0x22, 0xC8, 0x01, 0x0D, 0x0C, - 0x3E, 0x9C, 0x25, 0xCF, 0xA7, 0x04, 0xD9, 0xE2, 0xC8, 0x03, 0xD0, 0x09, 0x04, 0xD6, 0x09, 0xBA, - 0xDC, 0x30, 0x10, 0x0B, 0x06, 0xB6, 0x2A, 0x04, 0x12, 0xDC, 0x52, 0x40, 0x90, 0x60, 0x81, 0x5C, - 0x07, 0x20, 0xA8, 0x1A, 0xD0, 0x20, 0x01, 0x35, 0x07, 0x3C, 0x1C, 0x18, 0x30, 0x87, 0xCC, 0x00, - 0x03, 0x02, 0x0F, 0x12, 0x34, 0xD8, 0xA6, 0xCF, 0x44, 0xA7, 0x8F, 0x9D, 0x0E, 0x88, 0xAC, 0x75, - 0x6B, 0x22, 0xC5, 0x4B, 0x44, 0x4E, 0xFF, 0x26, 0x63, 0x80, 0x20, 0xE3, 0x81, 0x8E, 0x5D, 0x0E, - 0xA4, 0x33, 0xA6, 0x92, 0x8D, 0x03, 0x04, 0x35, 0x2F, 0x35, 0xC0, 0x98, 0xE0, 0x25, 0x4C, 0x26, - 0x07, 0x7C, 0xE4, 0xBC, 0x82, 0x40, 0xE1, 0x50, 0x3D, 0xCA, 0x52, 0x38, 0xFA, 0x89, 0xE3, 0x47, - 0xCE, 0x1F, 0x00, 0x8E, 0xAA, 0x02, 0xC2, 0x80, 0xE9, 0x92, 0x86, 0x2A, 0x0D, 0x3C, 0xA0, 0x29, - 0x55, 0xD1, 0x00, 0x8C, 0x06, 0xAC, 0x26, 0x31, 0x80, 0xC0, 0x24, 0x32, 0x04, 0x09, 0xBA, 0x9A, - 0x1B, 0x94, 0x80, 0xA3, 0x58, 0x18, 0x5A, 0xCF, 0x1C, 0x13, 0x78, 0x69, 0x9C, 0xDA, 0x2C, 0x04, - 0x22, 0x34, 0x78, 0x6B, 0x03, 0x82, 0x02, 0x44, 0x97, 0x5E, 0xD5, 0x1D, 0x60, 0xF7, 0xEE, 0xB9, - 0x07, 0x61, 0xF9, 0xD6, 0x58, 0xC0, 0x20, 0xDB, 0x1A, 0x82, 0x0B, 0x09, 0x17, 0xBE, 0xFB, 0x55, - 0x81, 0xE2, 0x1B, 0x99, 0x10, 0x39, 0xF6, 0x2A, 0x99, 0xB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x11, - 0xF4, 0x11, 0x0B, 0x42, 0x62, 0x41, 0x70, 0xCB, 0x73, 0x1E, 0x0E, 0xE5, 0x20, 0x70, 0x7B, 0x10, - 0x40, 0x58, 0x5E, 0xC4, 0xE4, 0x23, 0x42, 0x02, 0x86, 0x34, 0xA2, 0x98, 0x24, 0x0A, 0x00, 0x19, - 0x63, 0x4E, 0xFD, 0x10, 0x43, 0x93, 0x32, 0x79, 0xF1, 0x90, 0x42, 0x88, 0x2E, 0x2C, 0xF0, 0x80, - 0x21, 0x0F, 0x30, 0x00, 0x5F, 0x30, 0x62, 0xF4, 0xB1, 0x61, 0x90, 0x47, 0x39, 0x18, 0xCB, 0x3F, - 0xEF, 0xF8, 0x60, 0xC0, 0x2F, 0x36, 0x3C, 0xB1, 0x22, 0x53, 0x99, 0x20, 0x90, 0x08, 0x9A, 0x5D, - 0x79, 0xD9, 0x80, 0x00, 0x29, 0xB4, 0xD6, 0x04, 0x59, 0x2C, 0xFC, 0x24, 0x13, 0x2A, 0x78, 0x76, - 0xF5, 0x95, 0x03, 0x0C, 0xA0, 0xA6, 0xA3, 0x17, 0x6E, 0x3D, 0xB2, 0xC0, 0x0F, 0x0A, 0x10, 0xB9, - 0xDA, 0x39, 0x08, 0x08, 0x90, 0x86, 0x00, 0x4E, 0x2E, 0x17, 0x86, 0x3B, 0xA5, 0x4D, 0xAA, 0x87, - 0x42, 0xAF, 0x0C, 0xE2, 0x00, 0xA6, 0x63, 0x8A, 0xF6, 0xA8, 0x0A, 0x91, 0x06, 0xF0, 0x4B, 0x9E, - 0xCE, 0x29, 0xF2, 0x17, 0x4B, 0x96, 0x16, 0x50, 0xA9, 0x9F, 0x9A, 0x02, 0x50, 0x00, 0x23, 0x81, - 0x9E, 0x1A, 0x41, 0x94, 0x47, 0x31, 0x10, 0xE6, 0x01, 0xD3, 0x98, 0xA5, 0x10, 0x2A, 0x2D, 0xF1, - 0x21, 0x46, 0x40, 0xB5, 0xDA, 0x8A, 0xD8, 0x02, 0x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6B, 0x50, 0xE0, - 0x5E, 0x2E, 0x05, 0x29, 0x36, 0x05, 0x0E, 0x65, 0xE3, 0x66, 0x4A, 0x7D, 0x73, 0xA3, 0x2D, 0x60, - 0x90, 0xE5, 0x44, 0x0A, 0x66, 0xA4, 0xAB, 0x3D, 0x78, 0xB0, 0xC8, 0xCA, 0xDE, 0x94, 0x14, 0x7F, - 0x07, 0x28, 0x07, 0x79, 0x23, 0x52, 0xA5, 0xB0, 0xE8, 0x35, 0x03, 0x06, 0x04, 0x05, 0x30, 0x4A, - 0x2A, 0x68, 0x4E, 0xE2, 0x5D, 0x0B, 0x2D, 0x9A, 0x66, 0x0F, 0xEA, 0x35, 0x43, 0x53, 0x20, 0xC1, - 0x56, 0x93, 0x61, 0x78, 0xF6, 0xAC, 0xD9, 0xCF, 0x40, 0xE9, 0x3D, 0x20, 0x23, 0x10, 0x03, 0x80, - 0x54, 0x23, 0x00, 0x4C, 0x2A, 0x14, 0xE5, 0x25, 0xC1, 0xCC, 0x01, 0xBD, 0xE2, 0x26, 0x0F, 0x28, - 0xA2, 0xCC, 0x0C, 0x45, 0xEC, 0x30, 0x0D, 0x98, 0x97, 0xDD, 0x24, 0x04, 0x49, 0xC6, 0x0A, 0x02, - 0xC8, 0xB1, 0x50, 0xD4, 0xAA, 0x5A, 0xEE, 0x24, 0x48, 0x19, 0x00, 0xE4, 0xF4, 0xA0, 0xC0, 0x28, - 0x0A, 0xB0, 0xE2, 0x1B, 0x0D, 0x33, 0xA9, 0x25, 0x00, 0x52, 0x8B, 0x3C, 0xF8, 0x42, 0x01, 0x5A, - 0x1C, 0x62, 0x44, 0x86, 0x6B, 0x69, 0x46, 0x40, 0x87, 0x1E, 0x06, 0x02, 0x84, 0x88, 0x33, 0x14, - 0xF3, 0x57, 0x00, 0x6D, 0x09, 0x10, 0xC0, 0x09, 0x29, 0x2E, 0xE1, 0x80, 0x6B, 0x6A, 0xC4, 0x80, - 0x90, 0x66, 0x80, 0x69, 0xA6, 0xC0, 0x03, 0x0E, 0xD6, 0x28, 0x02, 0x04, 0x0C, 0x28, 0xC2, 0xE2, - 0x0A, 0x1C, 0xF9, 0xE0, 0xCE, 0x3E, 0x05, 0x94, 0xE6, 0x00, 0x02, 0x11, 0x68, 0x21, 0xA4, 0x0C, - 0x35, 0xB1, 0x11, 0x94, 0x49, 0x09, 0x35, 0xF0, 0x24, 0x0E, 0x48, 0x35, 0x61, 0x4A, 0x93, 0x29, - 0x4C, 0x69, 0xC4, 0x01, 0x42, 0x30, 0x70, 0x25, 0x1E, 0x20, 0x26, 0x44, 0x40, 0x94, 0x0C, 0x38, - 0xC4, 0x44, 0x13, 0x99, 0x1C, 0x10, 0x9B, 0x98, 0x34, 0x98, 0xC0, 0x4E, 0x9B, 0x56, 0x74, 0x54, - 0x08, 0x3B, 0x99, 0xB8, 0xF0, 0x48, 0x13, 0x4D, 0x88, 0x45, 0x27, 0x12, 0x0A, 0x99, 0x83, 0x8A, - 0x40, 0x73, 0xBE, 0x60, 0x57, 0x13, 0xA1, 0x0D, 0xFA, 0xD2, 0x6C, 0x93, 0x91, 0x10, 0x02, 0x00, - 0x21, 0xF9, 0x04, 0x09, 0x0A, 0x00, 0x00, 0x00, 0x2C, 0x00, 0x00, 0x17, 0x00, 0x6A, 0x00, 0x32, - 0x00, 0x00, 0x05, 0xFF, 0x20, 0x20, 0x8E, 0x64, 0x69, 0x9E, 0x68, 0xAA, 0x8A, 0x85, 0x02, 0xAD, - 0x70, 0x2C, 0xCF, 0x74, 0x5D, 0x26, 0x0C, 0x63, 0xD8, 0x7C, 0xEF, 0xFF, 0xA2, 0x05, 0x21, 0x80, - 0x58, 0x2C, 0x70, 0x0B, 0xA0, 0x72, 0xC9, 0x64, 0x34, 0x0C, 0x89, 0x86, 0x42, 0xC8, 0xAC, 0x5A, - 0x6B, 0x54, 0x46, 0x81, 0x11, 0x70, 0x5E, 0xBF, 0x60, 0x94, 0xA2, 0xB0, 0x40, 0x10, 0x00, 0x86, - 0x73, 0x23, 0x71, 0x08, 0xBB, 0xAF, 0x90, 0x73, 0xE2, 0x11, 0x28, 0x97, 0x1B, 0xBA, 0xB7, 0x7E, - 0xA9, 0x68, 0x04, 0x0A, 0x01, 0x01, 0x04, 0x39, 0x01, 0x50, 0x7B, 0x87, 0x3E, 0x0B, 0x5C, 0x81, - 0x5D, 0x0F, 0x03, 0x01, 0x78, 0x69, 0x05, 0x88, 0x94, 0x33, 0x0C, 0x8F, 0x8C, 0x0B, 0x81, 0x5A, - 0x08, 0x06, 0x2D, 0x3F, 0x0A, 0x0A, 0x33, 0x0B, 0x63, 0x0D, 0x49, 0x95, 0x26, 0x2D, 0x8C, 0xAB, - 0x05, 0x04, 0x7E, 0x0D, 0x67, 0x3C, 0x10, 0x09, 0x0A, 0x0C, 0x26, 0x10, 0x0E, 0x83, 0x05, 0x07, - 0x0B, 0x69, 0x0F, 0xB4, 0x0E, 0x0F, 0x9D, 0xA8, 0x24, 0x06, 0x08, 0xAB, 0xC8, 0x81, 0xA1, 0x3C, - 0x07, 0x0E, 0x6B, 0x6D, 0x25, 0x06, 0x11, 0x11, 0x12, 0x13, 0x13, 0x0F, 0x11, 0x80, 0xAC, 0xC2, - 0xD0, 0xA8, 0x65, 0x01, 0x98, 0xC9, 0x10, 0x66, 0x0E, 0x93, 0x32, 0x07, 0x38, 0x02, 0x0C, 0xB4, - 0xA2, 0x25, 0x07, 0x08, 0x13, 0x12, 0xF2, 0x13, 0x06, 0x7F, 0x07, 0xDB, 0xED, 0x95, 0xDF, 0xE1, - 0xC9, 0x63, 0x71, 0xDD, 0x29, 0x8E, 0xB8, 0x12, 0xA0, 0x2E, 0x94, 0x03, 0x14, 0xB0, 0xE4, 0x55, - 0x53, 0x80, 0x40, 0x01, 0xB2, 0x01, 0xB9, 0x4E, 0x21, 0x3A, 0x30, 0x64, 0x00, 0xBF, 0x64, 0x0B, - 0x1E, 0x48, 0x3C, 0x41, 0x2A, 0x0A, 0xC1, 0x8F, 0x05, 0x8A, 0x04, 0x74, 0x10, 0x4F, 0x42, 0x84, - 0x07, 0x0E, 0x93, 0xFF, 0x35, 0x40, 0x60, 0xEE, 0x90, 0x14, 0x70, 0x17, 0x91, 0x29, 0x48, 0x80, - 0x62, 0xC1, 0x16, 0x05, 0x1F, 0x73, 0x12, 0x9C, 0xB9, 0xA2, 0x40, 0x04, 0x04, 0x09, 0x82, 0x6A, - 0x4B, 0xC6, 0x80, 0x80, 0x81, 0x17, 0x7A, 0x0A, 0xD4, 0xB3, 0x18, 0x33, 0x10, 0x84, 0x5F, 0x6C, - 0x48, 0xB4, 0x1A, 0xA8, 0x53, 0x67, 0x82, 0x1D, 0x2B, 0x84, 0x2C, 0x4A, 0xB6, 0xEA, 0xC0, 0x4C, - 0x1C, 0xA6, 0x20, 0x20, 0xB5, 0x32, 0x05, 0x66, 0xD3, 0x40, 0x07, 0xA0, 0xD8, 0x12, 0xD1, 0xE0, - 0x41, 0x83, 0xAA, 0x55, 0x61, 0x31, 0xC8, 0xA7, 0x82, 0xA1, 0x83, 0x7A, 0x5C, 0x19, 0x41, 0x48, - 0xDB, 0x22, 0x47, 0xD0, 0xA3, 0x4C, 0x52, 0x32, 0x3D, 0x0B, 0x0E, 0x01, 0x34, 0x03, 0x6E, 0xE1, - 0xC2, 0xC5, 0x43, 0x57, 0x05, 0x04, 0x28, 0x04, 0x1C, 0x38, 0xB9, 0x97, 0x17, 0xD9, 0x81, 0x02, - 0x7F, 0xC7, 0xF6, 0x48, 0x10, 0x68, 0x80, 0x00, 0x8B, 0x95, 0x73, 0x8D, 0x38, 0xB0, 0xEE, 0xAD, - 0xE2, 0x8F, 0x0A, 0x08, 0x00, 0x94, 0x01, 0xA1, 0x17, 0x66, 0x02, 0xB0, 0x71, 0x84, 0x52, 0x9A, - 0x97, 0xB4, 0xEA, 0x1F, 0x07, 0xC1, 0x11, 0x24, 0xDC, 0xC0, 0xC1, 0x18, 0x00, 0xA4, 0x10, 0x30, - 0x38, 0x8D, 0xDA, 0xF0, 0x92, 0x05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, 0x8A, 0xD0, 0xE3, 0x25, 0xC8, 0x20, 0x4B, 0xE6, 0x23, 0x59, 0xAE, 0xF7, - 0x8E, 0xAA, 0xF1, 0x92, 0x30, 0xA9, 0xB1, 0x29, 0xA0, 0x9A, 0x80, 0x6F, 0x7D, 0x98, 0x9A, 0x56, - 0xA6, 0x0F, 0xC0, 0xDB, 0x2F, 0x09, 0x3E, 0x3A, 0x60, 0x6C, 0x00, 0x23, 0x5C, 0xD9, 0x9B, 0x9A, - 0x0E, 0x4C, 0x33, 0x8D, 0x30, 0x47, 0x16, 0x30, 0xEC, 0xC2, 0xC0, 0xF9, 0x68, 0xD4, 0x75, 0xA4, - 0x6D, 0xA2, 0xE6, 0x91, 0x06, 0x9C, 0xF2, 0x8E, 0xC5, 0x51, 0x2C, 0xCB, 0x71, 0x09, 0x8C, 0x0E, - 0x92, 0xA8, 0x57, 0x27, 0xA9, 0xF9, 0xCB, 0x97, 0x19, 0xC5, 0xCC, 0xD2, 0xCA, 0x33, 0x78, 0x35, - 0xF0, 0x8B, 0xB9, 0xE8, 0x52, 0xF2, 0x02, 0x1B, 0x93, 0xA2, 0x32, 0xCE, 0x30, 0xB4, 0x36, 0xB4, - 0x0D, 0x21, 0x00, 0x00, 0x3B}; +#include + +static const uint8_t firebase_logo_png[] PROGMEM = { + 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00, 0x00, 0x00, 0x0D, 0x49, 0x48, 0x44, 0x52, + 0x00, 0x00, 0x03, 0x20, 0x00, 0x00, 0x02, 0x58, 0x08, 0x06, 0x00, 0x00, 0x00, 0x9A, 0x76, 0x82, + 0x70, 0x00, 0x00, 0x00, 0x01, 0x73, 0x52, 0x47, 0x42, 0x00, 0xAE, 0xCE, 0x1C, 0xE9, 0x00, 0x00, + 0x00, 0x04, 0x67, 0x41, 0x4D, 0x41, 0x00, 0x00, 0xB1, 0x8F, 0x0B, 0xFC, 0x61, 0x05, 0x00, 0x00, + 0x00, 0x09, 0x70, 0x48, 0x59, 0x73, 0x00, 0x00, 0x0E, 0xC3, 0x00, 0x00, 0x0E, 0xC3, 0x01, 0xC7, + 0x6F, 0xA8, 0x64, 0x00, 0x00, 0x55, 0x14, 0x49, 0x44, 0x41, 0x54, 0x78, 0x5E, 0xED, 0xDD, 0x59, + 0x90, 0x1D, 0xF5, 0x81, 0xE7, 0x7B, 0x3F, 0xF4, 0xC3, 0x84, 0x91, 0x40, 0x6E, 0xEF, 0xC6, 0x8B, + 0x30, 0x92, 0x4A, 0x1B, 0x58, 0x98, 0xCD, 0xA0, 0xA5, 0x4A, 0x12, 0x20, 0x6C, 0x9A, 0xB6, 0xBA, + 0x01, 0x63, 0x4F, 0x3F, 0x8C, 0x1E, 0x26, 0xC2, 0xF7, 0xE5, 0xC6, 0x25, 0xE2, 0xDE, 0x97, 0x3B, + 0x7D, 0x67, 0xAC, 0x6E, 0x63, 0x63, 0x83, 0x8D, 0xBC, 0xB1, 0x99, 0xA5, 0x10, 0x08, 0xED, 0x52, + 0x69, 0xAD, 0x92, 0xA0, 0xBB, 0xAB, 0xA7, 0xED, 0x6E, 0x77, 0xB7, 0x81, 0x42, 0x9B, 0x99, 0x89, + 0x89, 0xDB, 0x9A, 0xB9, 0x0E, 0x2F, 0x2C, 0x76, 0x61, 0x16, 0x49, 0x85, 0xA4, 0xFC, 0xDF, 0xFF, + 0x3F, 0x4F, 0xE6, 0xA9, 0x3C, 0x79, 0x7E, 0xE7, 0x9C, 0xCC, 0x3C, 0x99, 0x75, 0xCE, 0xC9, 0xFA, + 0x7E, 0x22, 0x7E, 0xA1, 0x6E, 0x2F, 0x42, 0xC2, 0x94, 0xE2, 0xFF, 0x8D, 0x7F, 0x65, 0x9E, 0xF7, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x28, 0x82, 0x79, 0x6E, 0xCD, 0x80, 0xBF, 0xC3, 0x5F, 0x58, 0x12, 0xFC, + 0x4B, 0x00, 0x00, 0x00, 0x00, 0x90, 0x1F, 0x73, 0x78, 0xCD, 0x3A, 0xEF, 0xB9, 0x35, 0x63, 0xE6, + 0xB9, 0x9B, 0x4D, 0x75, 0xCF, 0xAE, 0xF1, 0xE7, 0x3D, 0x7B, 0xD3, 0xA0, 0x0B, 0x92, 0xE0, 0x3F, + 0x0A, 0x00, 0x00, 0x00, 0x00, 0xD9, 0x98, 0x91, 0x35, 0xB3, 0xEB, 0xC2, 0x23, 0x12, 0x1F, 0xD1, + 0x79, 0x87, 0xD7, 0x6C, 0x08, 0xFE, 0x6B, 0x00, 0x00, 0x00, 0x00, 0x90, 0x8E, 0xFB, 0x16, 0x2B, + 0xEF, 0xD9, 0x35, 0xE3, 0x95, 0xE0, 0xB8, 0xD1, 0x98, 0x03, 0x57, 0x19, 0xB3, 0x7B, 0xAE, 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35, 0x11, 0x19, 0xAD, 0x76, 0xA8, 0xDF, 0x3D, 0x90, 0x3E, 0x18, 0xFC, 0xA5, 0x01, 0x00, 0x00, + 0x00, 0x4C, 0x37, 0xDE, 0x81, 0x6B, 0x46, 0x75, 0x60, 0x34, 0x9B, 0x88, 0x8B, 0x56, 0xDB, 0xFA, + 0x21, 0x63, 0x86, 0xE6, 0x57, 0x5E, 0xCB, 0x3B, 0xB2, 0x66, 0x76, 0xF0, 0x97, 0x07, 0x00, 0x00, + 0x00, 0x30, 0x9D, 0x98, 0x03, 0x57, 0xDB, 0x40, 0x50, 0x91, 0xD1, 0x68, 0x22, 0x2E, 0x5A, 0xCD, + 0xC5, 0x47, 0x38, 0x6E, 0x41, 0x00, 0x00, 0x00, 0x80, 0xE9, 0xC9, 0xDD, 0x44, 0x98, 0x7D, 0x9F, + 0xB1, 0x91, 0xA0, 0x42, 0x43, 0x4D, 0xC4, 0x45, 0xAB, 0x45, 0xE3, 0xC3, 0x6D, 0xF7, 0xDC, 0xCA, + 0x2D, 0xC8, 0x73, 0xAB, 0x07, 0x82, 0x5F, 0x06, 0x00, 0x00, 0x00, 0x80, 0xE9, 0xC0, 0x3C, 0xB7, + 0x66, 0xC0, 0xEC, 0x9E, 0x67, 0x43, 0x41, 0xC5, 0x46, 0x7C, 0x22, 0x2E, 0x5A, 0x2D, 0x1E, 0x1F, + 0xE1, 0x86, 0xAF, 0x73, 0x0F, 0xA4, 0x8F, 0x06, 0xBF, 0x0C, 0x00, 0x00, 0x00, 0x00, 0xD3, 0x81, + 0xF7, 0xEC, 0x4D, 0x77, 0x99, 0x9D, 0x97, 0xD8, 0x58, 0x50, 0xC1, 0x11, 0x9D, 0x88, 0x8B, 0x56, + 0x53, 0xE1, 0x11, 0x6E, 0xD7, 0xA7, 0xB9, 0x05, 0x01, 0x00, 0x00, 0x00, 0xA6, 0x1B, 0xEF, 0xF0, + 0x8D, 0x1B, 0x74, 0x70, 0x44, 0x27, 0xE2, 0xA2, 0xD5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x76, 0x91, 0x39, 0xFD, 0xA8, + 0x0D, 0x8E, 0x36, 0x6F, 0x3F, 0x74, 0x48, 0x64, 0x99, 0x08, 0x89, 0x2C, 0x23, 0x3E, 0x72, 0x98, + 0x0A, 0x87, 0x3C, 0x26, 0x02, 0xA2, 0xDD, 0xB9, 0x37, 0x61, 0x1D, 0xBF, 0x63, 0x49, 0xF0, 0xE5, + 0x08, 0x00, 0x00, 0x50, 0x7E, 0x66, 0x68, 0xBE, 0x8D, 0x02, 0x15, 0x18, 0xCD, 0x26, 0xA2, 0x22, + 0xE9, 0x54, 0x78, 0x44, 0x96, 0xE8, 0xF6, 0x23, 0x88, 0x8F, 0x76, 0x6F, 0x3F, 0x74, 0x48, 0x64, + 0x99, 0x08, 0x89, 0x2C, 0x23, 0x3E, 0x72, 0x98, 0x0A, 0x87, 0x3C, 0x26, 0xE2, 0x21, 0x8F, 0xBD, + 0x78, 0x1D, 0x6F, 0xC2, 0x02, 0x00, 0x00, 0xD3, 0x87, 0xFF, 0x06, 0xAC, 0x5D, 0x9F, 0xB6, 0x61, + 0xA0, 0x22, 0xA3, 0xD1, 0x44, 0x54, 0x24, 0x9D, 0x08, 0x8E, 0xEA, 0x92, 0xDE, 0x7E, 0x3C, 0x6E, + 0x03, 0x24, 0x8C, 0x8F, 0x68, 0x80, 0xFC, 0x80, 0xF8, 0x20, 0x3E, 0x54, 0x38, 0xE4, 0x31, 0x11, + 0x0E, 0x79, 0xED, 0x85, 0xAB, 0x78, 0x13, 0x16, 0x00, 0x00, 0x98, 0x3E, 0xCC, 0xA1, 0xFE, 0xB5, + 0x66, 0xC7, 0xC7, 0x6D, 0x1C, 0xA8, 0xD0, 0x50, 0x13, 0x51, 0x91, 0x74, 0x2A, 0x3A, 0x62, 0x53, + 0xB7, 0x1F, 0xD1, 0x00, 0xF1, 0xE3, 0xA3, 0xD1, 0xED, 0xC7, 0x37, 0x75, 0x68, 0xA8, 0xE9, 0x90, + 0xC8, 0x32, 0x11, 0x12, 0x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, 0x01, 0x00, 0x00, 0x00, 0x40, 0x3A, 0xEE, 0x35, + 0xB9, 0xFE, 0x07, 0x1B, 0xEE, 0xE8, 0x1B, 0x88, 0xEF, 0xDF, 0x36, 0xCC, 0xEE, 0x0B, 0xFE, 0x63, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xD0, 0x15, 0xDE, 0xF3, 0x9E, 0xFF, 0x1F, 0x5B, 0xE2, 0x94, 0x1D, 0x86, + 0x86, 0x23, 0x09, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4E, 0x44, 0xAE, 0x42, 0x60, 0x82}; + +static const uint8_t tree_img_gif[] PROGMEM = { + + 0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x28, 0x00, 0x3C, 0x00, 0x83, 0x0B, 0x00, 0x00, 0xFF, 0xFF, + 0x00, 0x21, 0x00, 0x00, 0x4A, 0x00, 0x00, 0x6B, 0x00, 0x00, 0x94, 0x00, 0x00, 0xB5, 0x00, 0x00, + 0xDE, 0x00, 0x00, 0xFF, 0x00, 0x6B, 0x00, 0x00, 0xFF, 0x33, 0x33, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, + 0xFF, 0xFF, 0xCC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x99, 0x00, 0xCC, 0x00, 0x00, 0x21, 0xFF, 0x0B, + 0x4E, 0x45, 0x54, 0x53, 0x43, 0x41, 0x50, 0x45, 0x32, 0x2E, 0x30, 0x03, 0x01, 0xA0, 0x0F, 0x00, + 0x21, 0xF9, 0x04, 0x09, 0x14, 0x00, 0x0B, 0x00, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x28, 0x00, 0x3C, + 0x00, 0x03, 0x04, 0xFB, 0x70, 0xC9, 0x49, 0x6B, 0x75, 0x36, 0xEB, 0xBD, 0x31, 0xFF, 0xA0, 0xE4, + 0x8C, 0xCA, 0xE8, 0x85, 0xE8, 0xA5, 0xAC, 0x67, 0xEA, 0x8A, 0xE5, 0x2B, 0x2F, 0xE3, 0x31, 0xCE, + 0xAF, 0x41, 0x1C, 0xB8, 0x1B, 0x24, 0x80, 0x04, 0xAF, 0x87, 0x02, 0x26, 0x88, 0xA1, 0x07, 0x60, + 0xB9, 0x44, 0x82, 0x04, 0x02, 0x80, 0x61, 0x30, 0x70, 0x6E, 0x0C, 0x86, 0x03, 0x60, 0x20, 0xB0, + 0x6A, 0xA8, 0xD3, 0x03, 0x21, 0xEC, 0xAD, 0x18, 0x12, 0xE8, 0xF4, 0xB1, 0x4C, 0x51, 0xA0, 0x07, + 0xEA, 0x07, 0x5B, 0xF2, 0x70, 0x13, 0x76, 0xD4, 0xA8, 0xBC, 0xBC, 0xEA, 0x1F, 0x06, 0x77, 0x51, + 0x73, 0x50, 0x0A, 0x80, 0x7F, 0x04, 0x4C, 0x4D, 0x65, 0x06, 0x0A, 0x3B, 0x3B, 0x62, 0x5A, 0x53, + 0x65, 0x05, 0x02, 0x04, 0x68, 0x0C, 0x6A, 0x00, 0x5D, 0x5E, 0x0F, 0x0F, 0x6A, 0x98, 0x6A, 0x09, + 0x7B, 0x56, 0x9D, 0x09, 0x0C, 0xA7, 0xA7, 0x7F, 0x06, 0x9D, 0xA3, 0x44, 0x02, 0x01, 0x03, 0x90, + 0x0C, 0x87, 0x03, 0x06, 0x02, 0x05, 0x56, 0x06, 0x01, 0x02, 0x53, 0xB1, 0xB3, 0x04, 0x79, 0xAF, + 0x55, 0x48, 0x51, 0xB0, 0x87, 0xC0, 0x7F, 0x07, 0x95, 0x05, 0x85, 0x44, 0xB6, 0x00, 0x05, 0x53, + 0x96, 0x6A, 0x60, 0x02, 0x0A, 0x48, 0x89, 0x00, 0x07, 0xA1, 0x69, 0x7D, 0x2B, 0x3D, 0x9D, 0x41, + 0xA1, 0x04, 0xA0, 0xDD, 0x9D, 0x38, 0x02, 0xE1, 0x6A, 0x07, 0x62, 0x0C, 0x77, 0xE6, 0xAD, 0x2F, + 0x05, 0x01, 0xB6, 0x90, 0x07, 0xA8, 0xA7, 0x54, 0xB5, 0xBC, 0x06, 0x33, 0x50, 0x53, 0x3A, 0x00, + 0x39, 0x62, 0x10, 0x6B, 0xDF, 0xBE, 0x19, 0x03, 0x18, 0x40, 0xA9, 0x15, 0x4B, 0xCC, 0x0E, 0x77, + 0x3B, 0x04, 0xC4, 0x02, 0x38, 0x43, 0x21, 0x96, 0x2C, 0xD3, 0xD6, 0x81, 0x01, 0x26, 0x2A, 0xFB, + 0xDE, 0x07, 0x7C, 0x0A, 0xB7, 0x71, 0x1B, 0x79, 0xEE, 0xC5, 0x83, 0x72, 0xDD, 0x84, 0xBC, 0x4B, + 0x13, 0xA4, 0x13, 0x15, 0x17, 0xAB, 0x18, 0x78, 0x4A, 0x43, 0x40, 0x81, 0x43, 0x76, 0x8E, 0xB6, + 0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, 0x8A, 0x75, 0x64, 0xFA, 0x42, 0xF1, 0x12, 0xAD, + 0x60, 0xDE, 0x51, 0x0A, 0x94, 0xBA, 0x5E, 0x2C, 0x8C, 0x86, 0xDD, 0x3D, 0xDE, 0x8F, 0x0A, 0x70, + 0x51, 0x5F, 0xFE, 0xF2, 0x84, 0xD1, 0xD0, 0xA6, 0x68, 0xB7, 0x96, 0x62, 0x14, 0x0C, 0xC1, 0xB7, + 0x90, 0x68, 0x72, 0xD1, 0x7C, 0xD9, 0x3D, 0xA3, 0x94, 0x35, 0xDE, 0x54, 0x06, 0x92, 0x51, 0x50, + 0x68, 0xC2, 0xC5, 0x44, 0xB7, 0x30, 0x70, 0xDE, 0x6A, 0x49, 0x69, 0x86, 0xC5, 0x2D, 0xA3, 0x29, + 0x04, 0x05, 0x2F, 0xD9, 0xC4, 0x02, 0x0C, 0x6C, 0x0C, 0x48, 0xB0, 0x94, 0x01, 0xDA, 0x3C, 0xF2, + 0x56, 0x21, 0xFA, 0xE8, 0xA3, 0xA1, 0x55, 0x12, 0xE9, 0xF4, 0x56, 0x42, 0xF8, 0x50, 0x00, 0x40, + 0x08, 0x08, 0xD4, 0x88, 0x80, 0x05, 0x33, 0x66, 0x10, 0xA2, 0x0C, 0xDC, 0xA0, 0xB0, 0xA3, 0x0B, + 0x71, 0xCD, 0xB1, 0x80, 0x75, 0x69, 0x20, 0x41, 0xE4, 0x91, 0x6B, 0x64, 0x10, 0x01, 0x00, 0x21, + 0xF9, 0x04, 0x09, 0x14, 0x00, 0x0B, 0x00, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x28, 0x00, 0x3C, 0x00, + 0x03, 0x04, 0xFB, 0x70, 0xC9, 0x49, 0x6B, 0x75, 0x36, 0xEB, 0xBD, 0x31, 0xFF, 0xA0, 0xE4, 0x8C, + 0xA4, 0x17, 0x9E, 0x57, 0x89, 0xAE, 0xA9, 0xC9, 0xAE, 0xE3, 0x31, 0xBE, 0xAF, 0x31, 0x1C, 0x34, + 0x1B, 0x24, 0x4C, 0x82, 0xE7, 0x28, 0x5E, 0x02, 0x78, 0x7A, 0x30, 0x8E, 0x47, 0x62, 0x48, 0x20, + 0x60, 0xD8, 0x06, 0x4A, 0x8E, 0xC1, 0x70, 0x60, 0x0C, 0x04, 0xD1, 0xCD, 0x60, 0x60, 0x3B, 0x10, + 0xBA, 0x59, 0x8B, 0x21, 0x41, 0x2E, 0x0F, 0xC3, 0x16, 0xF2, 0xC0, 0xAC, 0x40, 0x4F, 0x1E, 0x80, + 0x04, 0x81, 0x70, 0xD8, 0x0A, 0x14, 0x0F, 0xF7, 0x42, 0x00, 0xA0, 0xD6, 0x09, 0x0A, 0x81, 0x81, + 0x68, 0x00, 0x85, 0x85, 0x7F, 0x07, 0x07, 0x0A, 0x06, 0x7A, 0x06, 0x00, 0x74, 0x74, 0x5E, 0x8A, + 0x36, 0x68, 0x05, 0x7C, 0x66, 0x3D, 0x64, 0x58, 0x61, 0x0F, 0x0F, 0x66, 0x64, 0x99, 0x64, 0x79, + 0x9C, 0x9E, 0xA0, 0x48, 0x4E, 0x9D, 0xA3, 0x4A, 0x02, 0x01, 0x37, 0x90, 0x55, 0x04, 0x5C, 0x02, + 0x05, 0x59, 0x06, 0x01, 0x02, 0x4F, 0x89, 0x55, 0x76, 0xAC, 0x50, 0xAB, 0x0A, 0xAD, 0x7F, 0xB1, + 0x75, 0x07, 0x02, 0x04, 0x05, 0x00, 0xBE, 0x39, 0x06, 0x77, 0x05, 0x36, 0x04, 0x9F, 0x5B, 0xCC, + 0x00, 0x4A, 0x82, 0x81, 0x07, 0x9F, 0x65, 0x86, 0x85, 0x40, 0x9D, 0x0A, 0x9F, 0x0C, 0xD0, 0x9F, + 0x00, 0x9D, 0x39, 0x02, 0xDE, 0x66, 0xB0, 0x73, 0xE2, 0x09, 0xE4, 0xAA, 0x2F, 0x05, 0x01, 0xCC, + 0x5E, 0xA7, 0x56, 0x75, 0xD2, 0xB8, 0x8C, 0x2F, 0x4C, 0x36, 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, 0xEB, 0x7E, 0x72, 0x31, 0x10, 0x54, 0x9F, 0x85, 0x00, 0xF1, 0xA6, 0x1C, 0x94, 0x2C, + 0x34, 0xB2, 0x17, 0x9F, 0x5B, 0xB8, 0x14, 0x80, 0xFC, 0x41, 0x28, 0x63, 0xC7, 0x03, 0x9A, 0x4A, + 0x32, 0x9C, 0x2C, 0x2B, 0x2E, 0x40, 0x72, 0x63, 0x59, 0x48, 0x85, 0x47, 0x8D, 0xD8, 0xC8, 0xD9, + 0xE2, 0xF0, 0x55, 0x99, 0x4A, 0xE3, 0x82, 0x07, 0x41, 0x3F, 0x25, 0x92, 0xAE, 0xD7, 0x4C, 0x3C, + 0xE7, 0xAC, 0x02, 0x04, 0x58, 0xC4, 0xC4, 0xAD, 0x9C, 0x1B, 0xB1, 0x3F, 0xE1, 0x42, 0x3D, 0x4B, + 0x9E, 0x85, 0xCB, 0x57, 0xA6, 0x30, 0x4B, 0x97, 0x88, 0x26, 0xA2, 0x03, 0x7F, 0x8B, 0x72, 0x2D, + 0x90, 0x79, 0x02, 0xFD, 0x59, 0x36, 0xB2, 0xF3, 0x41, 0x2A, 0x65, 0xAD, 0x75, 0x64, 0x3A, 0x0C, + 0x48, 0xB4, 0x15, 0x35, 0x13, 0xE0, 0xC2, 0xC0, 0x2D, 0xB1, 0x15, 0x95, 0x0C, 0x13, 0x97, 0x59, + 0x73, 0x90, 0x01, 0xF5, 0xAC, 0x36, 0x8D, 0x79, 0x12, 0x40, 0xB8, 0x45, 0x22, 0xB8, 0xF8, 0xC4, + 0x0C, 0x7D, 0xB3, 0x31, 0x96, 0xCF, 0x00, 0x01, 0x76, 0x41, 0x80, 0x4F, 0x0B, 0x80, 0x78, 0x4A, + 0x24, 0x5B, 0x8C, 0x18, 0xDB, 0x8A, 0x0A, 0xF0, 0xC3, 0x15, 0x88, 0x08, 0xF1, 0xC5, 0xC7, 0x3C, + 0x13, 0x40, 0x94, 0x01, 0x81, 0x13, 0x20, 0xA0, 0x23, 0x02, 0x27, 0xE0, 0x58, 0x63, 0x08, 0xD9, + 0xE8, 0x41, 0x81, 0x5B, 0x42, 0x7A, 0x57, 0x86, 0x12, 0x46, 0x26, 0x79, 0x46, 0x06, 0x11, 0x00, + 0x00, 0x21, 0xF9, 0x04, 0x09, 0x14, 0x00, 0x0B, 0x00, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x28, 0x00, + 0x3C, 0x00, 0x03, 0x04, 0xFB, 0x70, 0xC9, 0x49, 0x6B, 0x75, 0x36, 0xEB, 0xBD, 0x31, 0xFF, 0xA0, + 0xE4, 0x8C, 0xA4, 0x17, 0x9E, 0x57, 0x89, 0xAE, 0xA9, 0xC9, 0xAE, 0xE3, 0x31, 0xBE, 0xAF, 0xA1, + 0x1C, 0x34, 0x1B, 0x24, 0x4A, 0x82, 0xE7, 0x27, 0x85, 0x50, 0x08, 0x0C, 0x3D, 0x12, 0xBC, 0xC4, + 0xA3, 0x18, 0x12, 0x08, 0x14, 0x86, 0xC1, 0x80, 0xC9, 0x31, 0x18, 0x0E, 0x84, 0x81, 0x80, 0xBA, + 0x91, 0x46, 0xB1, 0x51, 0x06, 0xD7, 0x62, 0x40, 0x9A, 0x91, 0xE2, 0x71, 0xA5, 0x37, 0x40, 0x33, + 0xDE, 0xE9, 0xF1, 0xE3, 0xA1, 0x20, 0x10, 0x0E, 0x52, 0x01, 0x63, 0xA9, 0x5E, 0x0C, 0x85, 0x03, + 0x76, 0x7A, 0x7D, 0x0B, 0x4E, 0x03, 0x75, 0x78, 0x77, 0x78, 0x06, 0x84, 0x51, 0x37, 0x8A, 0x77, + 0x02, 0x51, 0x6A, 0x05, 0x02, 0x04, 0x67, 0x67, 0x5B, 0x72, 0x47, 0x98, 0x98, 0x7C, 0x5C, 0x73, + 0x66, 0x58, 0x07, 0x8B, 0x0F, 0x00, 0x9F, 0x45, 0x02, 0x01, 0x03, 0xA3, 0x0C, 0x89, 0x03, 0x06, + 0x02, 0x00, 0x5C, 0x06, 0x01, 0x92, 0x52, 0x07, 0xAE, 0x59, 0x03, 0x00, 0xBD, 0xBD, 0x4C, 0x02, + 0x05, 0xAB, 0xB9, 0x70, 0x0C, 0xAC, 0x96, 0x00, 0x52, 0x45, 0x36, 0xC1, 0x51, 0x97, 0x0C, 0x66, + 0x5E, 0x00, 0x8C, 0x4C, 0x0A, 0x05, 0x5F, 0x68, 0x98, 0x4E, 0x56, 0x40, 0x7F, 0x3D, 0x67, 0x97, + 0x9D, 0x73, 0x39, 0x02, 0x74, 0x9C, 0x48, 0xA4, 0x76, 0x76, 0x66, 0x73, 0xA8, 0x2C, 0x05, 0x50, + 0x02, 0xA3, 0xA3, 0x59, 0x78, 0x5E, 0x92, 0xD4, 0x2C, 0xDB, 0xB0, 0x59, 0x76, 0x07, 0x00, 0x78, + 0x16, 0x09, 0x80, 0xF5, 0xE4, 0x05, 0xC1, 0x81, 0x5F, 0xB0, 0x10, 0x00, 0xA0, 0xEE, 0xC0, 0xC0, + 0x03, 0x8E, 0x68, 0x68, 0xB1, 0x72, 0xE5, 0x92, 0xAF, 0x5E, 0xF6, 0x0C, 0x10, 0xF0, 0x86, 0x62, + 0xFB, 0xCE, 0xC1, 0x03, 0x98, 0x00, 0x74, 0x42, 0x42, 0xE7, 0xC5, 0xB9, 0x4E, 0xFF, 0xC2, 0x9D, + 0x99, 0xA3, 0x60, 0x0A, 0x0A, 0x03, 0xED, 0xC0, 0xDD, 0xF1, 0x47, 0xCF, 0xCB, 0x2E, 0x97, 0x20, + 0x92, 0x0D, 0x64, 0x85, 0xA5, 0x65, 0x43, 0x2C, 0x3C, 0x19, 0x10, 0x30, 0x94, 0x2F, 0x27, 0xBE, + 0x9D, 0x87, 0x78, 0xCE, 0x54, 0x47, 0xC0, 0x98, 0xC6, 0x9D, 0x39, 0x2F, 0xC6, 0xB2, 0xF1, 0x87, + 0x29, 0x96, 0x62, 0xC6, 0xB6, 0x69, 0xE2, 0xC0, 0x2B, 0x4A, 0x2C, 0x58, 0x49, 0x47, 0xDA, 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0x5B, 0x49, 0xF0, 0x84, 0x2A, 0x48, 0x19, 0x92, 0x47, 0x30, + 0x4E, 0x00, 0x60, 0xC9, 0x57, 0x71, 0x79, 0x03, 0x51, 0x30, 0xD3, 0x4C, 0xA0, 0xC0, 0x4E, 0xA4, + 0x1C, 0x45, 0x51, 0x2C, 0x7E, 0x39, 0xB8, 0x18, 0x3E, 0x04, 0xB5, 0x04, 0x14, 0x6C, 0xB3, 0xF8, + 0xF1, 0xC7, 0x3C, 0x00, 0xAA, 0xC6, 0xCB, 0x45, 0xFC, 0x21, 0xD5, 0x52, 0x72, 0x17, 0x95, 0x88, + 0xD8, 0x09, 0x08, 0x00, 0x80, 0x00, 0x02, 0x28, 0x94, 0x28, 0xC1, 0x8C, 0x20, 0x20, 0xD1, 0x5D, + 0x02, 0x27, 0xE8, 0x88, 0x82, 0x5B, 0x84, 0x2C, 0xE0, 0xD6, 0x19, 0x4C, 0x1C, 0xA9, 0xA4, 0x19, + 0x1B, 0x44, 0x00, 0x00, 0x21, 0xFE, 0x19, 0x42, 0x6F, 0x79, 0x27, 0x73, 0x20, 0x48, 0x61, 0x70, + 0x70, 0x79, 0x20, 0x48, 0x6F, 0x6C, 0x69, 0x64, 0x61, 0x79, 0x73, 0x20, 0x50, 0x61, 0x67, 0x65, + 0x00, 0x3B + +}; + +static const uint8_t bird_img_gif[] PROGMEM = { + 0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x74, 0x00, 0x4E, 0x00, 0xCC, 0x13, 0x00, 0xFF, 0xFF, 0xFF, + 0xEF, 0xFF, 0xFF, 0xBD, 0xE7, 0xE7, 0xD6, 0xEF, 0xEF, 0x63, 0x63, 0x63, 0xAD, 0xAD, 0xAD, 0xCE, + 0xCE, 0xCE, 0xD6, 0xDE, 0xDE, 0x4A, 0x4A, 0x4A, 0x7B, 0x84, 0x84, 0x94, 0x9C, 0x9C, 0xE7, 0xE7, + 0xE7, 0x84, 0x94, 0x94, 0xB5, 0xC6, 0xC6, 0x73, 0x7B, 0x7B, 0x31, 0x31, 0x31, 0xF7, 0xF7, 0xF7, + 0x18, 0x10, 0x10, 0xCE, 0x63, 0x39, 0x6B, 0x39, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0xFF, 0x0B, + 0x4E, 0x45, 0x54, 0x53, 0x43, 0x41, 0x50, 0x45, 0x32, 0x2E, 0x30, 0x03, 0x01, 0x00, 0x00, 0x00, + 0x21, 0xF9, 0x04, 0x09, 0x0A, 0x00, 0x00, 0x00, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x74, 0x00, 0x4B, + 0x00, 0x00, 0x05, 0xFF, 0x20, 0x20, 0x8E, 0x64, 0x69, 0x9E, 0x68, 0xAA, 0xAE, 0xEC, 0x68, 0x2C, + 0x6D, 0x2C, 0xCF, 0x74, 0x6D, 0x03, 0x46, 0x84, 0x40, 0x77, 0xEF, 0xFF, 0x40, 0x51, 0x42, 0x41, + 0x0C, 0x1A, 0x8F, 0x48, 0x13, 0xC1, 0xD0, 0x20, 0x00, 0x0E, 0x8E, 0x42, 0x72, 0x4A, 0xAD, 0x21, + 0x0E, 0xCD, 0x05, 0xE1, 0x80, 0xA8, 0x7A, 0xBF, 0x29, 0xC2, 0xA0, 0x91, 0x28, 0x34, 0x02, 0x5D, + 0xB0, 0x5A, 0xFD, 0x08, 0x34, 0x14, 0x84, 0x00, 0x7A, 0x4D, 0xF7, 0x22, 0xDC, 0x89, 0xB8, 0xC1, + 0xB9, 0x80, 0xD5, 0xFF, 0x40, 0x0B, 0x77, 0x0C, 0x0F, 0x05, 0x01, 0x0C, 0x0A, 0x0B, 0x0F, 0x08, + 0x06, 0x80, 0x8E, 0x37, 0x7B, 0x01, 0x09, 0x11, 0x03, 0x68, 0x5C, 0x4C, 0x0A, 0x8F, 0x9A, 0x33, + 0x06, 0x09, 0x01, 0x0E, 0x71, 0x68, 0x88, 0x92, 0x07, 0x9B, 0xA6, 0x2C, 0x0A, 0x86, 0x07, 0x95, + 0x05, 0x04, 0xA1, 0x5D, 0x8D, 0xA7, 0xB2, 0x26, 0x09, 0x06, 0x72, 0x72, 0x0E, 0x94, 0x01, 0xA9, + 0x04, 0x08, 0x52, 0xB3, 0xC0, 0x00, 0x09, 0x95, 0xB7, 0x0D, 0x86, 0x01, 0x04, 0x0A, 0xC3, 0x09, + 0x34, 0x43, 0xC1, 0x54, 0x0E, 0xB7, 0xD2, 0x87, 0xAE, 0xBB, 0x99, 0x32, 0x7B, 0x0E, 0xCF, 0x49, + 0x0B, 0xD1, 0xD3, 0x72, 0x0C, 0xDE, 0x57, 0x33, 0xBE, 0xCC, 0xDB, 0x47, 0x05, 0x0C, 0xDF, 0xD3, + 0x05, 0xD7, 0x31, 0x0C, 0xE1, 0xA5, 0xE7, 0x46, 0xBE, 0xEB, 0xD2, 0x04, 0x05, 0xBF, 0x2C, 0x5C, + 0x4D, 0xF3, 0x46, 0x0B, 0x11, 0x56, 0xD9, 0x3B, 0x14, 0x01, 0x14, 0x0F, 0x16, 0x04, 0x1A, 0x30, + 0x28, 0x00, 0x81, 0xA1, 0x3F, 0x1F, 0xAD, 0x02, 0x10, 0x5B, 0x87, 0x6F, 0x0E, 0x8B, 0x02, 0x0E, + 0x04, 0x5C, 0x41, 0x10, 0xF0, 0x61, 0x8F, 0x25, 0x03, 0x26, 0xDA, 0x43, 0xC4, 0x42, 0x8B, 0x00, + 0x05, 0x0E, 0x7C, 0xFF, 0xED, 0xF0, 0x68, 0x83, 0x8B, 0x44, 0x91, 0xDF, 0x06, 0xAC, 0x54, 0x01, + 0x21, 0xA1, 0x80, 0x07, 0x0F, 0x1A, 0x38, 0x70, 0xC7, 0x72, 0x46, 0xC2, 0x97, 0x03, 0x3F, 0xC5, + 0x52, 0xE1, 0x80, 0x81, 0x00, 0x01, 0x19, 0x1B, 0x3C, 0x38, 0xD8, 0x53, 0xC6, 0x81, 0x38, 0x21, + 0x61, 0x4A, 0xEB, 0xB7, 0x42, 0x01, 0x82, 0xA3, 0x58, 0x7D, 0xC9, 0x6B, 0x1A, 0x63, 0x0B, 0xD0, + 0x81, 0x11, 0x08, 0x74, 0x44, 0x61, 0xE0, 0x01, 0xD6, 0xA3, 0x05, 0x16, 0x2D, 0xE5, 0xDA, 0xC2, + 0x80, 0xB7, 0x90, 0x41, 0xCB, 0xA4, 0x39, 0xC1, 0xEF, 0x2C, 0x56, 0xAA, 0x6C, 0x57, 0x38, 0xA8, + 0x14, 0x35, 0xA8, 0x35, 0x14, 0x10, 0x10, 0x34, 0xB0, 0x9B, 0xD5, 0x4F, 0xDE, 0x14, 0x06, 0x8E, + 0xF5, 0x1D, 0xC8, 0x25, 0x85, 0x83, 0xC1, 0x84, 0x05, 0x20, 0x32, 0x30, 0xF4, 0x30, 0x2D, 0x39, + 0x8B, 0x07, 0x32, 0x42, 0xA1, 0x00, 0x72, 0xE4, 0x45, 0x08, 0x7C, 0x59, 0x36, 0x91, 0x18, 0x73, + 0xE6, 0x6F, 0x79, 0x38, 0x2B, 0x88, 0x7C, 0x54, 0xE7, 0xE0, 0x2D, 0xA3, 0x4B, 0x78, 0x7A, 0x79, + 0x7A, 0x1A, 0xCE, 0x04, 0x4C, 0x85, 0xAC, 0x66, 0x7D, 0x96, 0x80, 0xB9, 0xD8, 0x22, 0x4A, 0x4B, + 0x14, 0x00, 0x97, 0xF1, 0xD3, 0x12, 0x3B, 0x79, 0x9F, 0x45, 0xC0, 0x13, 0xB8, 0xB7, 0xE1, 0xC5, + 0x19, 0x33, 0xEB, 0x53, 0xD3, 0xA8, 0x72, 0x01, 0x0D, 0x44, 0x97, 0x5C, 0x90, 0x7B, 0x9B, 0x01, + 0x05, 0xA6, 0x89, 0xFB, 0x3D, 0x54, 0x20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, 0x73, 0x89, 0x93, 0xE5, 0xFE, + 0x74, 0x13, 0xB7, 0xCB, 0xE6, 0xA4, 0x4B, 0x63, 0x90, 0x65, 0xED, 0x16, 0x25, 0x77, 0xE9, 0x54, + 0x67, 0x11, 0xDB, 0x89, 0x44, 0xB3, 0x6E, 0xF6, 0x89, 0x7E, 0x37, 0x05, 0x47, 0xE7, 0xB2, 0xFB, + 0xF5, 0x2D, 0x70, 0xDD, 0x80, 0x37, 0xDE, 0x0A, 0x8E, 0xFB, 0x06, 0x1C, 0x00, 0x4D, 0xE0, 0x1E, + 0x80, 0x0C, 0x73, 0xFB, 0x47, 0x00, 0xE8, 0x2C, 0x89, 0x6E, 0xCF, 0x0C, 0x66, 0x87, 0x64, 0x55, + 0x73, 0x87, 0xB5, 0xD2, 0x39, 0xF2, 0x54, 0xA3, 0xAD, 0x24, 0xEF, 0x09, 0xC4, 0x2E, 0x47, 0x0C, + 0x83, 0x4F, 0x44, 0x6E, 0x25, 0xA9, 0x0C, 0x8F, 0x43, 0xE0, 0xD3, 0xB4, 0x30, 0x50, 0x54, 0xF9, + 0x41, 0x57, 0xC9, 0x63, 0xE6, 0x03, 0x00, 0xC1, 0xED, 0xE9, 0xAB, 0x60, 0x4F, 0x62, 0x94, 0x41, + 0x2A, 0xFE, 0x01, 0x56, 0x11, 0x10, 0xB3, 0x65, 0x4F, 0x11, 0xCC, 0x37, 0x4A, 0x10, 0x2C, 0x8E, + 0x3C, 0x80, 0x40, 0x3A, 0x30, 0x20, 0x02, 0x96, 0x10, 0x3F, 0x13, 0x64, 0xA7, 0x1E, 0x17, 0x53, + 0x90, 0x02, 0x28, 0x87, 0x00, 0xB2, 0xC1, 0xE0, 0x29, 0x08, 0x24, 0x50, 0xC9, 0xFE, 0x37, 0x3C, + 0x28, 0x30, 0x67, 0x75, 0x01, 0x9C, 0x20, 0x4E, 0x0A, 0xE0, 0xAC, 0xAF, 0x21, 0x90, 0x3E, 0x0D, + 0x4C, 0x41, 0xBB, 0x42, 0x13, 0x05, 0x63, 0xA4, 0x64, 0x81, 0x43, 0x28, 0x40, 0xED, 0x44, 0x00, + 0x01, 0x2C, 0x78, 0x29, 0x85, 0x2C, 0x38, 0x56, 0x62, 0x1A, 0xC0, 0x1D, 0x35, 0x84, 0x00, 0x00, + 0x21, 0xF9, 0x04, 0x09, 0x0A, 0x00, 0x00, 0x00, 0x2C, 0x00, 0x00, 0x17, 0x00, 0x6A, 0x00, 0x32, + 0x00, 0x00, 0x05, 0xFF, 0x20, 0x20, 0x8E, 0x64, 0x69, 0x9E, 0x68, 0xAA, 0x8A, 0x85, 0x02, 0xAD, + 0x70, 0x2C, 0xCF, 0x74, 0x5D, 0x26, 0x0C, 0x63, 0xD8, 0x7C, 0xEF, 0xFF, 0xA2, 0x05, 0x21, 0x80, + 0x58, 0x2C, 0x70, 0x0B, 0xA0, 0x72, 0xC9, 0x64, 0x34, 0x0C, 0x89, 0x86, 0x42, 0xC8, 0xAC, 0x5A, + 0x6B, 0x54, 0x46, 0x81, 0x11, 0x70, 0x5E, 0xBF, 0x60, 0x94, 0xA2, 0xB0, 0x40, 0x10, 0x00, 0x86, + 0x73, 0x23, 0x71, 0x08, 0xBB, 0xAF, 0x90, 0x73, 0xE2, 0x11, 0x28, 0x97, 0x1B, 0xBA, 0xB7, 0x7E, + 0xA9, 0x68, 0x04, 0x0A, 0x01, 0x01, 0x04, 0x39, 0x01, 0x50, 0x7B, 0x87, 0x3E, 0x0B, 0x5C, 0x81, + 0x5D, 0x0F, 0x03, 0x01, 0x78, 0x69, 0x05, 0x88, 0x94, 0x33, 0x0C, 0x8F, 0x8C, 0x0B, 0x81, 0x5A, + 0x08, 0x06, 0x2D, 0x3F, 0x0A, 0x0A, 0x33, 0x0B, 0x63, 0x0D, 0x49, 0x95, 0x26, 0x2D, 0x8C, 0xAB, + 0x05, 0x04, 0x7E, 0x0D, 0x67, 0x3C, 0x10, 0x09, 0x0A, 0x0C, 0x26, 0x10, 0x0E, 0x83, 0x05, 0x07, + 0x0B, 0x69, 0x0F, 0xB4, 0x0E, 0x0F, 0x9D, 0xA8, 0x24, 0x06, 0x08, 0xAB, 0xC8, 0x81, 0xA1, 0x3C, + 0x07, 0x0E, 0x6B, 0x6D, 0x25, 0x06, 0x11, 0x11, 0x12, 0x13, 0x13, 0x0F, 0x11, 0x80, 0xAC, 0xC2, + 0xD0, 0xA8, 0x65, 0x01, 0x98, 0xC9, 0x10, 0x66, 0x0E, 0x93, 0x32, 0x07, 0x38, 0x02, 0x0C, 0xB4, + 0xA2, 0x25, 0x07, 0x08, 0x13, 0x12, 0xF2, 0x13, 0x06, 0x7F, 0x07, 0xDB, 0xED, 0x95, 0xDF, 0xE1, + 0xC9, 0x63, 0x71, 0xDD, 0x29, 0x8E, 0xB8, 0x12, 0xA0, 0x2E, 0x94, 0x03, 0x14, 0xB0, 0xE4, 0x55, + 0x53, 0x80, 0x40, 0x01, 0xB2, 0x01, 0xB9, 0x4E, 0x21, 0x3A, 0x30, 0x64, 0x00, 0xBF, 0x64, 0x0B, + 0x1E, 0x48, 0x3C, 0x41, 0x2A, 0x0A, 0xC1, 0x8F, 0x05, 0x8A, 0x04, 0x74, 0x10, 0x4F, 0x42, 0x84, + 0x07, 0x0E, 0x93, 0xFF, 0x35, 0x40, 0x60, 0xEE, 0x90, 0x14, 0x70, 0x17, 0x91, 0x29, 0x48, 0x80, + 0x62, 0xC1, 0x16, 0x05, 0x1F, 0x73, 0x12, 0x9C, 0xB9, 0xA2, 0x40, 0x04, 0x04, 0x09, 0x82, 0x6A, + 0x4B, 0xC6, 0x80, 0x80, 0x81, 0x17, 0x7A, 0x0A, 0xD4, 0xB3, 0x18, 0x33, 0x10, 0x84, 0x5F, 0x6C, + 0x48, 0xB4, 0x1A, 0xA8, 0x53, 0x67, 0x82, 0x1D, 0x2B, 0x84, 0x2C, 0x4A, 0xB6, 0xEA, 0xC0, 0x4C, + 0x1C, 0xA6, 0x20, 0x20, 0xB5, 0x32, 0x05, 0x66, 0xD3, 0x40, 0x07, 0xA0, 0xD8, 0x12, 0xD1, 0xE0, + 0x41, 0x83, 0xAA, 0x55, 0x61, 0x31, 0xC8, 0xA7, 0x82, 0xA1, 0x83, 0x7A, 0x5C, 0x19, 0x41, 0x48, + 0xDB, 0x22, 0x47, 0xD0, 0xA3, 0x4C, 0x52, 0x32, 0x3D, 0x0B, 0x0E, 0x01, 0x34, 0x03, 0x6E, 0xE1, + 0xC2, 0xC5, 0x43, 0x57, 0x05, 0x04, 0x28, 0x04, 0x1C, 0x38, 0xB9, 0x97, 0x17, 0xD9, 0x81, 0x02, + 0x7F, 0xC7, 0xF6, 0x48, 0x10, 0x68, 0x80, 0x00, 0x8B, 0x95, 0x73, 0x8D, 0x38, 0xB0, 0xEE, 0xAD, + 0xE2, 0x8F, 0x0A, 0x08, 0x00, 0x94, 0x01, 0xA1, 0x17, 0x66, 0x02, 0xB0, 0x71, 0x84, 0x52, 0x9A, + 0x97, 0xB4, 0xEA, 0x1F, 0x07, 0xC1, 0x11, 0x24, 0xDC, 0xC0, 0xC1, 0x18, 0x00, 0xA4, 0x10, 0x30, + 0x38, 0x8D, 0xDA, 0xF0, 0x92, 0x05, 0x69, 0x0F, 0xA4, 0x55, 0xE0, 0x40, 0x32, 0xDE, 0xAE, 0xE5, + 0x7A, 0xE0, 0x02, 0xD0, 0x79, 0x77, 0x65, 0x70, 0xB0, 0x09, 0x14, 0x20, 0xFE, 0x51, 0xFB, 0xC6, + 0x2F, 0x8F, 0x85, 0x42, 0x40, 0x86, 0xF9, 0x7B, 0x0C, 0x5C, 0x8C, 0x3C, 0x7F, 0x26, 0xDC, 0x85, + 0xC0, 0x83, 0x41, 0xA6, 0x4F, 0x6B, 0x41, 0x04, 0xA1, 0xD5, 0x73, 0xB4, 0xDA, 0x35, 0xAB, 0xB8, + 0x8C, 0x23, 0xBD, 0xF5, 0xEB, 0x30, 0x41, 0xD0, 0xD6, 0x69, 0x6B, 0x34, 0x80, 0x0A, 0x04, 0xEB, + 0xA8, 0x14, 0x85, 0xFF, 0x7E, 0x41, 0x60, 0xE6, 0x40, 0x02, 0x05, 0x48, 0xE1, 0x47, 0x75, 0xBB, + 0xB1, 0xC7, 0xC8, 0x4A, 0xC4, 0xCD, 0x47, 0x0C, 0x2C, 0x31, 0x85, 0x64, 0x46, 0x64, 0x09, 0x20, + 0xF0, 0xC0, 0x2F, 0xF7, 0x39, 0xA0, 0x89, 0x7F, 0xEB, 0x01, 0x18, 0x88, 0x5A, 0xF1, 0xE5, 0xC4, + 0x40, 0x74, 0xC4, 0x00, 0xD0, 0x8C, 0x85, 0x03, 0x18, 0xD0, 0x21, 0x02, 0xD4, 0xA1, 0x98, 0xA2, + 0x8A, 0x10, 0x28, 0xF0, 0x00, 0x5C, 0x08, 0x30, 0xA8, 0x8F, 0x33, 0x2A, 0x5A, 0x46, 0x40, 0x02, + 0x27, 0xEA, 0xF8, 0x99, 0x8A, 0x88, 0x39, 0xA3, 0x13, 0x66, 0x34, 0xC5, 0x48, 0xC2, 0x2C, 0x29, + 0x15, 0x79, 0x9D, 0x7A, 0x15, 0xAA, 0xB8, 0x80, 0x6F, 0x39, 0xA1, 0x64, 0x9E, 0x94, 0x00, 0xF4, + 0x67, 0x65, 0x5E, 0x4C, 0x65, 0x79, 0x9D, 0x4D, 0x0E, 0x20, 0x20, 0xE2, 0x16, 0xCD, 0x09, 0x09, + 0x26, 0x00, 0x84, 0x8C, 0xC9, 0xD5, 0x60, 0xA0, 0x9D, 0x89, 0xC0, 0x84, 0x88, 0xDD, 0xF6, 0x66, + 0x0A, 0xCC, 0xC9, 0x79, 0x25, 0x7B, 0xE8, 0x34, 0xB4, 0x4A, 0x30, 0x06, 0xEE, 0x29, 0xC6, 0x03, + 0xF7, 0xF9, 0x69, 0xE5, 0x63, 0x04, 0xC4, 0x84, 0x98, 0x48, 0x86, 0x9A, 0x40, 0xD1, 0x56, 0x8A, + 0x56, 0x66, 0x40, 0x03, 0x52, 0xB0, 0x94, 0xE8, 0xA0, 0x1A, 0x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C, 0x0E, + 0x92, 0xA8, 0x57, 0x27, 0xA9, 0xF9, 0xCB, 0x97, 0x19, 0xC5, 0xCC, 0xD2, 0xCA, 0x33, 0x78, 0x35, + 0xF0, 0x8B, 0xB9, 0xE8, 0x52, 0xF2, 0x02, 0x1B, 0x93, 0xA2, 0x32, 0xCE, 0x30, 0xB4, 0x36, 0xB4, + 0x0D, 0x21, 0x00, 0x00, 0x21, 0xF9, 0x04, 0x09, 0x0A, 0x00, 0x00, 0x00, 0x2C, 0x00, 0x00, 0x20, + 0x00, 0x6A, 0x00, 0x25, 0x00, 0x00, 0x05, 0xFF, 0x20, 0x20, 0x8E, 0xE3, 0xA2, 0x14, 0xC6, 0x42, + 0xAE, 0x6C, 0xEB, 0xBE, 0x70, 0x2C, 0xCF, 0x2D, 0x94, 0x10, 0x4C, 0x71, 0x2C, 0x06, 0xF1, 0x24, + 0x0A, 0xC7, 0x03, 0x61, 0xA0, 0x19, 0x8F, 0xC8, 0x24, 0xCC, 0x10, 0x89, 0x48, 0x26, 0x93, 0x47, + 0xA4, 0x10, 0xA8, 0x56, 0x0B, 0x0F, 0xC2, 0x41, 0xC9, 0xED, 0x7A, 0x5B, 0x06, 0xC4, 0x44, 0x42, + 0x9E, 0x18, 0x02, 0x3A, 0x2B, 0xFA, 0xA1, 0xF8, 0xBA, 0xDF, 0xC9, 0xC6, 0xB8, 0xAC, 0x40, 0x30, + 0xD4, 0x81, 0x01, 0x81, 0xA0, 0x82, 0xFB, 0xFF, 0x2D, 0x0B, 0x0E, 0x73, 0x11, 0x6C, 0x78, 0x55, + 0x0D, 0x08, 0x05, 0x80, 0x8C, 0x8D, 0x05, 0x11, 0x08, 0x09, 0x09, 0x0E, 0x54, 0x87, 0x01, 0x0C, + 0x04, 0x06, 0x10, 0x8D, 0x9C, 0x6F, 0x0B, 0x38, 0x96, 0x78, 0x07, 0x05, 0x0A, 0x0C, 0x93, 0x0E, + 0x93, 0x09, 0x0C, 0x0A, 0x0D, 0x7D, 0x9D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0xCC, 0x0C, 0x45, 0xEC, 0x30, 0x0D, 0x98, 0x97, 0xDD, 0x24, 0x04, 0x49, + 0xC6, 0x0A, 0x02, 0xC8, 0xB1, 0x50, 0xD4, 0xAA, 0x5A, 0xEE, 0x24, 0x48, 0x19, 0x00, 0xE4, 0xF4, + 0xA0, 0xC0, 0x28, 0x0A, 0xB0, 0xE2, 0x1B, 0x0D, 0x33, 0xA9, 0x25, 0x00, 0x52, 0x8B, 0x3C, 0xF8, + 0x42, 0x01, 0x5A, 0x1C, 0x62, 0x44, 0x86, 0x6B, 0x69, 0x46, 0x40, 0x87, 0x1E, 0x06, 0x02, 0x84, + 0x88, 0x33, 0x14, 0xF3, 0x57, 0x00, 0x6D, 0x09, 0x10, 0xC0, 0x09, 0x29, 0x2E, 0xE1, 0x80, 0x6B, + 0x6A, 0xC4, 0x80, 0x90, 0x66, 0x80, 0x69, 0xA6, 0xC0, 0x03, 0x0E, 0xD6, 0x28, 0x02, 0x04, 0x0C, + 0x28, 0xC2, 0xE2, 0x0A, 0x1C, 0xF9, 0xE0, 0xCE, 0x3E, 0x05, 0x94, 0xE6, 0x00, 0x02, 0x11, 0x68, + 0x21, 0xA4, 0x0C, 0x35, 0xB1, 0x11, 0x94, 0x49, 0x09, 0x35, 0xF0, 0x24, 0x0E, 0x48, 0x35, 0x61, + 0x4A, 0x93, 0x29, 0x4C, 0x69, 0xC4, 0x01, 0x42, 0x30, 0x70, 0x25, 0x1E, 0x20, 0x26, 0x44, 0x40, + 0x94, 0x0C, 0x38, 0xC4, 0x44, 0x13, 0x99, 0x1C, 0x10, 0x9B, 0x98, 0x34, 0x98, 0xC0, 0x4E, 0x9B, + 0x56, 0x74, 0x54, 0x08, 0x3B, 0x99, 0xB8, 0xF0, 0x48, 0x13, 0x4D, 0x88, 0x45, 0x27, 0x12, 0x0A, + 0x99, 0x83, 0x8A, 0x40, 0x73, 0xBE, 0x60, 0x57, 0x13, 0xA1, 0x0D, 0xFA, 0xD2, 0x6C, 0x93, 0x91, + 0x10, 0x02, 0x00, 0x21, 0xF9, 0x04, 0x09, 0x0A, 0x00, 0x00, 0x00, 0x2C, 0x00, 0x00, 0x20, 0x00, + 0x6A, 0x00, 0x2E, 0x00, 0x00, 0x05, 0xFF, 0x20, 0x00, 0x40, 0x62, 0xB9, 0x28, 0x08, 0x41, 0x28, + 0x4B, 0xE9, 0xBE, 0x70, 0x2C, 0xCF, 0x74, 0x6D, 0xDF, 0xE5, 0xF1, 0x3C, 0x69, 0x52, 0x24, 0x0F, + 0x82, 0xE1, 0x60, 0x00, 0x26, 0x5A, 0xB8, 0xA4, 0x72, 0xC9, 0x94, 0xE9, 0x22, 0x12, 0xC9, 0x64, + 0xF2, 0x18, 0x04, 0xAE, 0xD7, 0x01, 0xB0, 0xD0, 0xEC, 0x7A, 0xBF, 0x31, 0x48, 0x61, 0x12, 0x95, + 0x32, 0x02, 0x8E, 0x06, 0x36, 0x70, 0x50, 0x21, 0xC1, 0xF0, 0x78, 0x72, 0x91, 0x20, 0x4B, 0x55, + 0x85, 0xF5, 0xB5, 0x81, 0xE0, 0xCA, 0xFF, 0x80, 0x32, 0x0D, 0x0F, 0x53, 0x11, 0x11, 0x04, 0x07, + 0x7A, 0x57, 0x0E, 0x04, 0x6F, 0x81, 0x8F, 0x7F, 0x0B, 0x2A, 0x06, 0x94, 0x6A, 0x8A, 0x01, 0x06, + 0x04, 0x05, 0x07, 0x0B, 0x0B, 0x44, 0x94, 0xA0, 0x43, 0x24, 0x90, 0xA4, 0x37, 0x05, 0x04, 0x96, + 0x97, 0x58, 0x45, 0x09, 0x0A, 0x0C, 0x0C, 0x0A, 0x05, 0x0D, 0xB3, 0x05, 0x0A, 0x09, 0x0C, 0x05, + 0x06, 0xA3, 0x4D, 0x9F, 0xA0, 0x0B, 0xBB, 0xA5, 0x33, 0x6D, 0x08, 0x0C, 0x89, 0xAA, 0xC7, 0x8A, + 0x07, 0xAE, 0x3E, 0xC0, 0x32, 0x10, 0x07, 0x3F, 0x2A, 0x0E, 0x8C, 0x2A, 0x08, 0xD6, 0x29, 0x0E, + 0xB9, 0xCD, 0xC1, 0x22, 0x10, 0x45, 0xD2, 0xB8, 0x07, 0x56, 0x97, 0x22, 0xC8, 0x01, 0x0D, 0x0C, + 0x3E, 0x9C, 0x25, 0xCF, 0xA7, 0x04, 0xD9, 0xE2, 0xC8, 0x03, 0xD0, 0x09, 0x04, 0xD6, 0x09, 0xBA, + 0xDC, 0x30, 0x10, 0x0B, 0x06, 0xB6, 0x2A, 0x04, 0x12, 0xDC, 0x52, 0x40, 0x90, 0x60, 0x81, 0x5C, + 0x07, 0x20, 0xA8, 0x1A, 0xD0, 0x20, 0x01, 0x35, 0x07, 0x3C, 0x1C, 0x18, 0x30, 0x87, 0xCC, 0x00, + 0x03, 0x02, 0x0F, 0x12, 0x34, 0xD8, 0xA6, 0xCF, 0x44, 0xA7, 0x8F, 0x9D, 0x0E, 0x88, 0xAC, 0x75, + 0x6B, 0x22, 0xC5, 0x4B, 0x44, 0x4E, 0xFF, 0x26, 0x63, 0x80, 0x20, 0xE3, 0x81, 0x8E, 0x5D, 0x0E, + 0xA4, 0x33, 0xA6, 0x92, 0x8D, 0x03, 0x04, 0x35, 0x2F, 0x35, 0xC0, 0x98, 0xE0, 0x25, 0x4C, 0x26, + 0x07, 0x7C, 0xE4, 0xBC, 0x82, 0x40, 0xE1, 0x50, 0x3D, 0xCA, 0x52, 0x38, 0xFA, 0x89, 0xE3, 0x47, + 0xCE, 0x1F, 0x00, 0x8E, 0xAA, 0x02, 0xC2, 0x80, 0xE9, 0x92, 0x86, 0x2A, 0x0D, 0x3C, 0xA0, 0x29, + 0x55, 0xD1, 0x00, 0x8C, 0x06, 0xAC, 0x26, 0x31, 0x80, 0xC0, 0x24, 0x32, 0x04, 0x09, 0xBA, 0x9A, + 0x1B, 0x94, 0x80, 0xA3, 0x58, 0x18, 0x5A, 0xCF, 0x1C, 0x13, 0x78, 0x69, 0x9C, 0xDA, 0x2C, 0x04, + 0x22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 0x4C, 0x05, 0xC8, 0xA5, 0x9E, 0x70, 0xA7, 0x31, 0x78, 0x92, + 0x24, 0x89, 0xB9, 0x70, 0x4C, 0x26, 0x41, 0x04, 0xA4, 0x40, 0x03, 0x19, 0x32, 0x72, 0xC8, 0x85, + 0x1D, 0xB9, 0x92, 0x20, 0x7F, 0xEE, 0x9D, 0x94, 0xE1, 0x49, 0x0C, 0xDD, 0x84, 0x16, 0x79, 0x11, + 0xF4, 0x11, 0x0B, 0x42, 0x62, 0x41, 0x70, 0xCB, 0x73, 0x1E, 0x0E, 0xE5, 0x20, 0x70, 0x7B, 0x10, + 0x40, 0x58, 0x5E, 0xC4, 0xE4, 0x23, 0x42, 0x02, 0x86, 0x34, 0xA2, 0x98, 0x24, 0x0A, 0x00, 0x19, + 0x63, 0x4E, 0xFD, 0x10, 0x43, 0x93, 0x32, 0x79, 0xF1, 0x90, 0x42, 0x88, 0x2E, 0x2C, 0xF0, 0x80, + 0x21, 0x0F, 0x30, 0x00, 0x5F, 0x30, 0x62, 0xF4, 0xB1, 0x61, 0x90, 0x47, 0x39, 0x18, 0xCB, 0x3F, + 0xEF, 0xF8, 0x60, 0xC0, 0x2F, 0x36, 0x3C, 0xB1, 0x22, 0x53, 0x99, 0x20, 0x90, 0x08, 0x9A, 0x5D, + 0x79, 0xD9, 0x80, 0x00, 0x29, 0xB4, 0xD6, 0x04, 0x59, 0x2C, 0xFC, 0x24, 0x13, 0x2A, 0x78, 0x76, + 0xF5, 0x95, 0x03, 0x0C, 0xA0, 0xA6, 0xA3, 0x17, 0x6E, 0x3D, 0xB2, 0xC0, 0x0F, 0x0A, 0x10, 0xB9, + 0xDA, 0x39, 0x08, 0x08, 0x90, 0x86, 0x00, 0x4E, 0x2E, 0x17, 0x86, 0x3B, 0xA5, 0x4D, 0xAA, 0x87, + 0x42, 0xAF, 0x0C, 0xE2, 0x00, 0xA6, 0x63, 0x8A, 0xF6, 0xA8, 0x0A, 0x91, 0x06, 0xF0, 0x4B, 0x9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F8, 0x42, 0x01, 0x5A, + 0x1C, 0x62, 0x44, 0x86, 0x6B, 0x69, 0x46, 0x40, 0x87, 0x1E, 0x06, 0x02, 0x84, 0x88, 0x33, 0x14, + 0xF3, 0x57, 0x00, 0x6D, 0x09, 0x10, 0xC0, 0x09, 0x29, 0x2E, 0xE1, 0x80, 0x6B, 0x6A, 0xC4, 0x80, + 0x90, 0x66, 0x80, 0x69, 0xA6, 0xC0, 0x03, 0x0E, 0xD6, 0x28, 0x02, 0x04, 0x0C, 0x28, 0xC2, 0xE2, + 0x0A, 0x1C, 0xF9, 0xE0, 0xCE, 0x3E, 0x05, 0x94, 0xE6, 0x00, 0x02, 0x11, 0x68, 0x21, 0xA4, 0x0C, + 0x35, 0xB1, 0x11, 0x94, 0x49, 0x09, 0x35, 0xF0, 0x24, 0x0E, 0x48, 0x35, 0x61, 0x4A, 0x93, 0x29, + 0x4C, 0x69, 0xC4, 0x01, 0x42, 0x30, 0x70, 0x25, 0x1E, 0x20, 0x26, 0x44, 0x40, 0x94, 0x0C, 0x38, + 0xC4, 0x44, 0x13, 0x99, 0x1C, 0x10, 0x9B, 0x98, 0x34, 0x98, 0xC0, 0x4E, 0x9B, 0x56, 0x74, 0x54, + 0x08, 0x3B, 0x99, 0xB8, 0xF0, 0x48, 0x13, 0x4D, 0x88, 0x45, 0x27, 0x12, 0x0A, 0x99, 0x83, 0x8A, + 0x40, 0x73, 0xBE, 0x60, 0x57, 0x13, 0xA1, 0x0D, 0xFA, 0xD2, 0x6C, 0x93, 0x91, 0x10, 0x02, 0x00, + 0x21, 0xF9, 0x04, 0x09, 0x0A, 0x00, 0x00, 0x00, 0x2C, 0x00, 0x00, 0x17, 0x00, 0x6A, 0x00, 0x32, + 0x00, 0x00, 0x05, 0xFF, 0x20, 0x20, 0x8E, 0x64, 0x69, 0x9E, 0x68, 0xAA, 0x8A, 0x85, 0x02, 0xAD, + 0x70, 0x2C, 0xCF, 0x74, 0x5D, 0x26, 0x0C, 0x63, 0xD8, 0x7C, 0xEF, 0xFF, 0xA2, 0x05, 0x21, 0x80, + 0x58, 0x2C, 0x70, 0x0B, 0xA0, 0x72, 0xC9, 0x64, 0x34, 0x0C, 0x89, 0x86, 0x42, 0xC8, 0xAC, 0x5A, + 0x6B, 0x54, 0x46, 0x81, 0x11, 0x70, 0x5E, 0xBF, 0x60, 0x94, 0xA2, 0xB0, 0x40, 0x10, 0x00, 0x86, + 0x73, 0x23, 0x71, 0x08, 0xBB, 0xAF, 0x90, 0x73, 0xE2, 0x11, 0x28, 0x97, 0x1B, 0xBA, 0xB7, 0x7E, + 0xA9, 0x68, 0x04, 0x0A, 0x01, 0x01, 0x04, 0x39, 0x01, 0x50, 0x7B, 0x87, 0x3E, 0x0B, 0x5C, 0x81, + 0x5D, 0x0F, 0x03, 0x01, 0x78, 0x69, 0x05, 0x88, 0x94, 0x33, 0x0C, 0x8F, 0x8C, 0x0B, 0x81, 0x5A, + 0x08, 0x06, 0x2D, 0x3F, 0x0A, 0x0A, 0x33, 0x0B, 0x63, 0x0D, 0x49, 0x95, 0x26, 0x2D, 0x8C, 0xAB, + 0x05, 0x04, 0x7E, 0x0D, 0x67, 0x3C, 0x10, 0x09, 0x0A, 0x0C, 0x26, 0x10, 0x0E, 0x83, 0x05, 0x07, + 0x0B, 0x69, 0x0F, 0xB4, 0x0E, 0x0F, 0x9D, 0xA8, 0x24, 0x06, 0x08, 0xAB, 0xC8, 0x81, 0xA1, 0x3C, + 0x07, 0x0E, 0x6B, 0x6D, 0x25, 0x06, 0x11, 0x11, 0x12, 0x13, 0x13, 0x0F, 0x11, 0x80, 0xAC, 0xC2, + 0xD0, 0xA8, 0x65, 0x01, 0x98, 0xC9, 0x10, 0x66, 0x0E, 0x93, 0x32, 0x07, 0x38, 0x02, 0x0C, 0xB4, + 0xA2, 0x25, 0x07, 0x08, 0x13, 0x12, 0xF2, 0x13, 0x06, 0x7F, 0x07, 0xDB, 0xED, 0x95, 0xDF, 0xE1, + 0xC9, 0x63, 0x71, 0xDD, 0x29, 0x8E, 0xB8, 0x12, 0xA0, 0x2E, 0x94, 0x03, 0x14, 0xB0, 0xE4, 0x55, + 0x53, 0x80, 0x40, 0x01, 0xB2, 0x01, 0xB9, 0x4E, 0x21, 0x3A, 0x30, 0x64, 0x00, 0xBF, 0x64, 0x0B, + 0x1E, 0x48, 0x3C, 0x41, 0x2A, 0x0A, 0xC1, 0x8F, 0x05, 0x8A, 0x04, 0x74, 0x10, 0x4F, 0x42, 0x84, + 0x07, 0x0E, 0x93, 0xFF, 0x35, 0x40, 0x60, 0xEE, 0x90, 0x14, 0x70, 0x17, 0x91, 0x29, 0x48, 0x80, + 0x62, 0xC1, 0x16, 0x05, 0x1F, 0x73, 0x12, 0x9C, 0xB9, 0xA2, 0x40, 0x04, 0x04, 0x09, 0x82, 0x6A, + 0x4B, 0xC6, 0x80, 0x80, 0x81, 0x17, 0x7A, 0x0A, 0xD4, 0xB3, 0x18, 0x33, 0x10, 0x84, 0x5F, 0x6C, + 0x48, 0xB4, 0x1A, 0xA8, 0x53, 0x67, 0x82, 0x1D, 0x2B, 0x84, 0x2C, 0x4A, 0xB6, 0xEA, 0xC0, 0x4C, + 0x1C, 0xA6, 0x20, 0x20, 0xB5, 0x32, 0x05, 0x66, 0xD3, 0x40, 0x07, 0xA0, 0xD8, 0x12, 0xD1, 0xE0, + 0x41, 0x83, 0xAA, 0x55, 0x61, 0x31, 0xC8, 0xA7, 0x82, 0xA1, 0x83, 0x7A, 0x5C, 0x19, 0x41, 0x48, + 0xDB, 0x22, 0x47, 0xD0, 0xA3, 0x4C, 0x52, 0x32, 0x3D, 0x0B, 0x0E, 0x01, 0x34, 0x03, 0x6E, 0xE1, + 0xC2, 0xC5, 0x43, 0x57, 0x05, 0x04, 0x28, 0x04, 0x1C, 0x38, 0xB9, 0x97, 0x17, 0xD9, 0x81, 0x02, + 0x7F, 0xC7, 0xF6, 0x48, 0x10, 0x68, 0x80, 0x00, 0x8B, 0x95, 0x73, 0x8D, 0x38, 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, 0xD0, 0x56, 0x4B, 0xBB, + 0x4A, 0x75, 0x6B, 0x8F, 0x32, 0x34, 0x44, 0x2B, 0x00, 0x6C, 0xAB, 0x55, 0xAB, 0xD5, 0xB1, 0x32, + 0xC8, 0xC9, 0x14, 0x24, 0xC3, 0x54, 0x5B, 0x02, 0x2C, 0x9B, 0x86, 0xFB, 0x27, 0x26, 0x1F, 0x3D, + 0x52, 0x00, 0xB5, 0xE6, 0x8A, 0xD0, 0xE3, 0x25, 0xC8, 0x20, 0x4B, 0xE6, 0x23, 0x59, 0xAE, 0xF7, + 0x8E, 0xAA, 0xF1, 0x92, 0x30, 0xA9, 0xB1, 0x29, 0xA0, 0x9A, 0x80, 0x6F, 0x7D, 0x98, 0x9A, 0x56, + 0xA6, 0x0F, 0xC0, 0xDB, 0x2F, 0x09, 0x3E, 0x3A, 0x60, 0x6C, 0x00, 0x23, 0x5C, 0xD9, 0x9B, 0x9A, + 0x0E, 0x4C, 0x33, 0x8D, 0x30, 0x47, 0x16, 0x30, 0xEC, 0xC2, 0xC0, 0xF9, 0x68, 0xD4, 0x75, 0xA4, + 0x6D, 0xA2, 0xE6, 0x91, 0x06, 0x9C, 0xF2, 0x8E, 0xC5, 0x51, 0x2C, 0xCB, 0x71, 0x09, 0x8C, 0x0E, + 0x92, 0xA8, 0x57, 0x27, 0xA9, 0xF9, 0xCB, 0x97, 0x19, 0xC5, 0xCC, 0xD2, 0xCA, 0x33, 0x78, 0x35, + 0xF0, 0x8B, 0xB9, 0xE8, 0x52, 0xF2, 0x02, 0x1B, 0x93, 0xA2, 0x32, 0xCE, 0x30, 0xB4, 0x36, 0xB4, + 0x0D, 0x21, 0x00, 0x00, 0x3B}; diff --git a/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_Attachment_File/Send_Attachment_File.ino b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_Attachment_File/Send_Attachment_File.ino new file mode 100644 index 000000000..d615e9f3a --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_Attachment_File/Send_Attachment_File.ino @@ -0,0 +1,443 @@ + + +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt +*/ + +// This example shows how to send Email with attachments and inline images stored in SD card. + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +/** Assign SD card type and FS used in src/ESP_Mail_FS.h and + * change the config for that card interfaces in src/extras/SDHelper.h + */ + +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +#include + +// Provide the SD card interfaces setting and mounting +#include + +// To use only SMTP functions, you can exclude the IMAP from compilation, see ESP_Mail_FS.h. + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +/** For Gmail, the app password will be used for log in + * Check out https://github.com/mobizt/ESP-Mail-Client#gmail-smtp-and-imap-required-app-passwords-to-sign-in + * + * For Yahoo mail, log in to your yahoo mail in web browser and generate app password by go to + * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc + * + * To use Gmai and Yahoo's App Password to sign in, define the AUTHOR_PASSWORD with your App Password + * and AUTHOR_EMAIL with your account email. + */ + +/** The smtp host name e.g. smtp.gmail.com for GMail or smtp.office365.com for Outlook or smtp.mail.yahoo.com */ +#define SMTP_HOST "" + +/** The smtp port e.g. + * 25 or esp_mail_smtp_port_25 + * 465 or esp_mail_smtp_port_465 + * 587 or esp_mail_smtp_port_587 + */ +#define SMTP_PORT esp_mail_smtp_port_587 + +/* The log in credentials */ +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" + +/* Recipient email address */ +#define RECIPIENT_EMAIL "" + +/* Declare the global used SMTPSession object for SMTP transport */ +SMTPSession smtp; + +/* Callback function to get the Email sending status */ +void smtpCallback(SMTP_Status status); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) +WiFiMulti multi; +#endif + +void setup() +{ + + Serial.begin(115200); + +#if defined(ARDUINO_ARCH_SAMD) + while (!Serial) + ; +#endif + + Serial.println(); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + multi.addAP(WIFI_SSID, WIFI_PASSWORD); + multi.run(); +#else + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Connecting to Wi-Fi"); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + unsigned long ms = millis(); +#endif + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + if (millis() - ms > 10000) + break; +#endif + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); + +#if defined(ESP_MAIL_DEFAULT_SD_FS) // defined in src/ESP_Mail_FS.h + + // Mount SD card. + SD_Card_Mounting(); // See src/extras/SDHelper.h + + Serial.println("Preparing SD file attachments..."); + + const char *orangeImg = "iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAAoUlEQVR42u3RMQ0AMAgAsCFgftHLiQpsENJaaFT+fqwRQoQgRAhChCBECEKECBGCECEIEYIQIQgRghCECEGIEIQIQYgQhCBECEKEIEQIQoQgBCFCECIEIUIQIgQhCBGCECEIEYIQIQhBiBCECEGIEIQIQQhChCBECEKEIEQIQhAiBCFCECIEIUIQghAhCBGCECEIEYIQIUKEIEQIQoQg5LoBGi/oCaOpTXoAAAAASUVORK5CYII="; + + // Write demo data to file + + static uint8_t buf[512]; + +// SDFat? +#if defined(ESP_MAIL_USE_SDFAT) // ESP_MAIL_USE_SDFAT is auto defined when you set to use SdFat in src/ESP_Mail_FS.h + SdFile file; + file.open("/orange.png", O_RDWR | O_CREAT); + file.print(orangeImg); + file.close(); + + file.open("/bin1.dat", O_RDWR | O_CREAT); + buf[0] = 'H'; + buf[1] = 'E'; + buf[2] = 'A'; + buf[3] = 'D'; + file.write(buf, 4); + + size_t i; + + for (i = 0; i < 4; i++) + { + memset(buf, i + 1, 512); + file.write(buf, 512); + } + + buf[0] = 'T'; + buf[1] = 'A'; + buf[2] = 'I'; + buf[3] = 'L'; + file.write(buf, 4); + file.close(); + +#else + +#if defined(ESP32) + File file = ESP_MAIL_DEFAULT_SD_FS.open("/orange.png", FILE_WRITE); +#else + File file = ESP_MAIL_DEFAULT_SD_FS.open("/orange.png", "w"); +#endif + file.print(orangeImg); + file.close(); + +#if defined(ESP32) + file = ESP_MAIL_DEFAULT_SD_FS.open("/bin1.dat", FILE_WRITE); +#else + file = ESP_MAIL_DEFAULT_SD_FS.open("/bin1.dat", "w"); +#endif + + buf[0] = 'H'; + buf[1] = 'E'; + buf[2] = 'A'; + buf[3] = 'D'; + file.write(buf, 4); + + size_t i; + + for (i = 0; i < 4; i++) + { + memset(buf, i + 1, 512); + file.write(buf, 512); + } + + buf[0] = 'T'; + buf[1] = 'A'; + buf[2] = 'I'; + buf[3] = 'L'; + file.write(buf, 4); + file.close(); +#endif + +#endif + + /* Set the network reconnection option */ + MailClient.networkReconnect(true); + + // The WiFi credentials are required for Pico W + // due to it does not have reconnect feature. +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + MailClient.clearAP(); + MailClient.addAP(WIFI_SSID, WIFI_PASSWORD); +#endif + + /** Enable the debug via Serial port + * 0 for no debugging + * 1 for basic level debugging + * + * Debug port can be changed via ESP_MAIL_DEFAULT_DEBUG_PORT in ESP_Mail_FS.h + */ + smtp.debug(1); + + /* Set the callback function to get the sending results */ + smtp.callback(smtpCallback); + + /* Declare the Session_Config for user defined session credentials */ + Session_Config config; + + /* Set the session config */ + config.server.host_name = SMTP_HOST; + config.server.port = SMTP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + + /** Assign your host name or you public IPv4 or IPv6 only + * as this is the part of EHLO/HELO command to identify the client system + * to prevent connection rejection. + * If host name or public IP is not available, ignore this or + * use loopback address "127.0.0.1". + * + * Assign any text to this option may cause the connection rejection. + */ + config.login.user_domain = F("127.0.0.1"); + + /* + Set the NTP config time + For times east of the Prime Meridian use 0-12 + For times west of the Prime Meridian add 12 to the offset. + Ex. American/Denver GMT would be -6. 6 + 12 = 18 + See https://en.wikipedia.org/wiki/Time_zone for a list of the GMT/UTC timezone offsets + */ + config.time.ntp_server = F("pool.ntp.org,time.nist.gov"); + config.time.gmt_offset = 3; + config.time.day_light_offset = 0; + + /* Declare the message class */ + SMTP_Message message; + + /* Enable the chunked data transfer with pipelining for large message if server supported */ + message.enable.chunking = true; + + /* Set the message headers */ + message.sender.name = F("ESP Mail"); + message.sender.email = AUTHOR_EMAIL; + + message.subject = F("Test sending Email with attachments and inline images from SD card and Flash"); + + message.addRecipient(F("user1"), RECIPIENT_EMAIL); + + /** Two alternative content versions are sending in this example e.g. plain text and html */ + String htmlMsg = "This message contains 1 inline image and 1 attachment file.

"; + + message.html.content = htmlMsg; + + /** The HTML text message character set e.g. + * us-ascii + * utf-8 + * utf-7 + * The default value is utf-8 + */ + message.html.charSet = F("utf-8"); + + /** The content transfer encoding e.g. + * enc_7bit or "7bit" (not encoded) + * enc_qp or "quoted-printable" (encoded) + * enc_base64 or "base64" (encoded) + * enc_binary or "binary" (not encoded) + * enc_8bit or "8bit" (not encoded) + * The default value is "7bit" + */ + message.html.transfer_encoding = Content_Transfer_Encoding::enc_qp; + + message.text.content = F("This message contains 1 inline image and 1 attachment file.\r\nThe inline image will not show in the plain text message."); + + message.text.charSet = F("utf-8"); + message.text.transfer_encoding = Content_Transfer_Encoding::enc_base64; + + /** The message priority + * esp_mail_smtp_priority_high or 1 + * esp_mail_smtp_priority_normal or 3 + * esp_mail_smtp_priority_low or 5 + * The default value is esp_mail_smtp_priority_low + */ + message.priority = esp_mail_smtp_priority::esp_mail_smtp_priority_normal; + + /** The Delivery Status Notifications e.g. + * esp_mail_smtp_notify_never + * esp_mail_smtp_notify_success + * esp_mail_smtp_notify_failure + * esp_mail_smtp_notify_delay + * The default value is esp_mail_smtp_notify_never + */ + // message.response.notify = esp_mail_smtp_notify_success | esp_mail_smtp_notify_failure | esp_mail_smtp_notify_delay; + + /* Set the custom message header */ + message.addHeader(F("Message-ID: ")); + + /* The attachment data item */ + SMTP_Attachment att[2]; + int attIndex = 0; + + /** Set the inline image info e.g. + * file name, MIME type, file path, file storage type, + * transfer encoding and content encoding + */ + att[attIndex].descr.filename = F("orange.png"); + att[attIndex].descr.mime = F("image/png"); + att[attIndex].file.path = F("/orange.png"); + + /** The file storage type e.g. + * esp_mail_file_storage_type_none, + * esp_mail_file_storage_type_flash, and + * esp_mail_file_storage_type_sd + */ + att[attIndex].file.storage_type = esp_mail_file_storage_type_sd; + + /* Need to be base64 transfer encoding for inline image */ + att[attIndex].descr.transfer_encoding = Content_Transfer_Encoding::enc_base64; + + /** The orange.png file is already base64 encoded file. + * Then set the content encoding to match the transfer encoding + * which no encoding was taken place prior to sending. + */ + att[attIndex].descr.content_encoding = Content_Transfer_Encoding::enc_base64; + + /* Add inline image to the message */ + message.addInlineImage(att[attIndex]); + + /** Set the attachment info e.g. + * file name, MIME type, file path, file storage type, + * transfer encoding and content encoding + */ + + attIndex++; + att[attIndex].descr.filename = F("bin1.dat"); + att[attIndex].descr.mime = F("application/octet-stream"); // binary data + att[attIndex].descr.description = F("This is binary data"); + att[attIndex].file.path = F("/bin1.dat"); + att[attIndex].file.storage_type = esp_mail_file_storage_type_sd; + att[attIndex].descr.transfer_encoding = Content_Transfer_Encoding::enc_base64; + + /* Add attachment to the message */ + message.addAttachment(att[attIndex]); + + /* Connect to the server */ + if (!smtp.connect(&config)) + { + MailClient.printf("Connection error, Status Code: %d, Error Code: %d, Reason: %s", smtp.statusCode(), smtp.errorCode(), smtp.errorReason().c_str()); + return; + } + + if (smtp.isAuthenticated()) + Serial.println("\nSuccessfully logged in."); + else + Serial.println("\nConnected with no Auth."); + + /* Start sending the Email and close the session */ + if (!MailClient.sendMail(&smtp, &message, true)) + MailClient.printf("Error, Status Code: %d, Error Code: %d, Reason: %s", smtp.statusCode(), smtp.errorCode(), smtp.errorReason().c_str()); + + // to clear sending result log + // smtp.sendingResult.clear(); + + MailClient.printf("Free Heap: %d\n", MailClient.getFreeHeap()); +} + +void loop() +{ +} + +/* Callback function to get the Email sending status */ +void smtpCallback(SMTP_Status status) +{ + /* Print the current status */ + Serial.println(status.info()); + + /* Print the sending result */ + if (status.success()) + { + // MailClient.printf used in the examples is for format printing via debug Serial port + // that works for all supported Arduino platform SDKs e.g. SAMD, ESP32 and ESP8266. + // In ESP8266 and ESP32, you can use Serial.printf directly. + + Serial.println("----------------"); + MailClient.printf("Message sent success: %d\n", status.completedCount()); + MailClient.printf("Message sent failed: %d\n", status.failedCount()); + Serial.println("----------------\n"); + + for (size_t i = 0; i < smtp.sendingResult.size(); i++) + { + /* Get the result item */ + SMTP_Result result = smtp.sendingResult.getItem(i); + + // In case, ESP32, ESP8266 and SAMD device, the timestamp get from result.timestamp should be valid if + // your device time was synched with NTP server. + // Other devices may show invalid timestamp as the device time was not set i.e. it will show Jan 1, 1970. + // You can call smtp.setSystemTime(xxx) to set device time manually. Where xxx is timestamp (seconds since Jan 1, 1970) + + MailClient.printf("Message No: %d\n", i + 1); + MailClient.printf("Status: %s\n", result.completed ? "success" : "failed"); + MailClient.printf("Date/Time: %s\n", MailClient.Time.getDateTimeString(result.timestamp, "%B %d, %Y %H:%M:%S").c_str()); + MailClient.printf("Recipient: %s\n", result.recipients.c_str()); + MailClient.printf("Subject: %s\n", result.subject.c_str()); + } + Serial.println("----------------\n"); + + // You need to clear sending result as the memory usage will grow up. + smtp.sendingResult.clear(); + } +} \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_Attachment_Flash/Send_Attachment_Flash.ino b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_Attachment_Flash/Send_Attachment_Flash.ino new file mode 100644 index 000000000..49ef4f54f --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_Attachment_Flash/Send_Attachment_Flash.ino @@ -0,0 +1,411 @@ + +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt +*/ + +// This example shows how to send Email with attachments and inline images stored in SPIFFS/LittleFS filesystem. + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +/** Assign SD card type and FS used in src/ESP_Mail_FS.h and + * change the config for that card interfaces in src/extras/SDHelper.h + */ + +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +#include + +// To use only SMTP functions, you can exclude the IMAP from compilation, see ESP_Mail_FS.h. + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +/** For Gmail, the app password will be used for log in + * Check out https://github.com/mobizt/ESP-Mail-Client#gmail-smtp-and-imap-required-app-passwords-to-sign-in + * + * For Yahoo mail, log in to your yahoo mail in web browser and generate app password by go to + * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc + * + * To use Gmai and Yahoo's App Password to sign in, define the AUTHOR_PASSWORD with your App Password + * and AUTHOR_EMAIL with your account email. + */ + +/** The smtp host name e.g. smtp.gmail.com for GMail or smtp.office365.com for Outlook or smtp.mail.yahoo.com */ +#define SMTP_HOST "" + +/** The smtp port e.g. + * 25 or esp_mail_smtp_port_25 + * 465 or esp_mail_smtp_port_465 + * 587 or esp_mail_smtp_port_587 + */ +#define SMTP_PORT esp_mail_smtp_port_587 + +/* The log in credentials */ +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" + +/* Recipient email address */ +#define RECIPIENT_EMAIL "" + +/* Declare the global used SMTPSession object for SMTP transport */ +SMTPSession smtp; + +/* Callback function to get the Email sending status */ +void smtpCallback(SMTP_Status status); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) +WiFiMulti multi; +#endif + +void setup() +{ + + Serial.begin(115200); + +#if defined(ARDUINO_ARCH_SAMD) + while (!Serial) + ; +#endif + + Serial.println(); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + multi.addAP(WIFI_SSID, WIFI_PASSWORD); + multi.run(); +#else + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Connecting to Wi-Fi"); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + unsigned long ms = millis(); +#endif + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + if (millis() - ms > 10000) + break; +#endif + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + /* Set the network reconnection option */ + MailClient.networkReconnect(true); + + // The WiFi credentials are required for Pico W + // due to it does not have reconnect feature. +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + MailClient.clearAP(); + MailClient.addAP(WIFI_SSID, WIFI_PASSWORD); +#endif + +#if defined(ESP_MAIL_DEFAULT_FLASH_FS) // defined in src/ESP_Mail_FS.h + + // Mount SPIFFS/LittleFS filesystem. + ESP_MAIL_DEFAULT_FLASH_FS.begin(); + + Serial.println("Preparing flash file attachments..."); + + const char *orangeImg = "iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAAoUlEQVR42u3RMQ0AMAgAsCFgftHLiQpsENJaaFT+fqwRQoQgRAhChCBECEKECBGCECEIEYIQIQgRghCECEGIEIQIQYgQhCBECEKEIEQIQoQgBCFCECIEIUIQIgQhCBGCECEIEYIQIQhBiBCECEGIEIQIQQhChCBECEKEIEQIQhAiBCFCECIEIUIQghAhCBGCECEIEYIQIUKEIEQIQoQg5LoBGi/oCaOpTXoAAAAASUVORK5CYII="; + + // Write demo data to file + + static uint8_t buf[512]; + +#if defined(ESP32) + File file = ESP_MAIL_DEFAULT_FLASH_FS.open("/orange.png", FILE_WRITE); +#else + File file = ESP_MAIL_DEFAULT_FLASH_FS.open("/orange.png", "w"); +#endif + + file.print(orangeImg); + file.close(); + +#if defined(ESP32) + file = ESP_MAIL_DEFAULT_FLASH_FS.open("/bin1.dat", FILE_WRITE); +#else + file = ESP_MAIL_DEFAULT_FLASH_FS.open("/bin1.dat", "w"); +#endif + + buf[0] = 'H'; + buf[1] = 'E'; + buf[2] = 'A'; + buf[3] = 'D'; + file.write(buf, 4); + + size_t i; + + for (i = 0; i < 4; i++) + { + memset(buf, i + 1, 512); + file.write(buf, 512); + } + + buf[0] = 'T'; + buf[1] = 'A'; + buf[2] = 'I'; + buf[3] = 'L'; + file.write(buf, 4); + file.close(); + +#endif + + /* Set the network reconnection option */ + MailClient.networkReconnect(true); + + /** Enable the debug via Serial port + * 0 for no debugging + * 1 for basic level debugging + * + * Debug port can be changed via ESP_MAIL_DEFAULT_DEBUG_PORT in ESP_Mail_FS.h + */ + smtp.debug(1); + + /* Set the callback function to get the sending results */ + smtp.callback(smtpCallback); + + /* Declare the Session_Config for user defined session credentials */ + Session_Config config; + + /* Set the session config */ + config.server.host_name = SMTP_HOST; + config.server.port = SMTP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + + /** Assign your host name or you public IPv4 or IPv6 only + * as this is the part of EHLO/HELO command to identify the client system + * to prevent connection rejection. + * If host name or public IP is not available, ignore this or + * use loopback address "127.0.0.1". + * + * Assign any text to this option may cause the connection rejection. + */ + config.login.user_domain = F("127.0.0.1"); + + /* + Set the NTP config time + For times east of the Prime Meridian use 0-12 + For times west of the Prime Meridian add 12 to the offset. + Ex. American/Denver GMT would be -6. 6 + 12 = 18 + See https://en.wikipedia.org/wiki/Time_zone for a list of the GMT/UTC timezone offsets + */ + config.time.ntp_server = F("pool.ntp.org,time.nist.gov"); + config.time.gmt_offset = 3; + config.time.day_light_offset = 0; + + /* Declare the message class */ + SMTP_Message message; + + /* Enable the chunked data transfer with pipelining for large message if server supported */ + message.enable.chunking = true; + + /* Set the message headers */ + message.sender.name = F("ESP Mail"); + message.sender.email = AUTHOR_EMAIL; + + message.subject = F("Test sending Email with attachments and inline images from flash filesystem"); + + message.addRecipient(F("user1"), RECIPIENT_EMAIL); + + /** Two alternative content versions are sending in this example e.g. plain text and html */ + String htmlMsg = "This message contains 1 inline image and 1 attachment file.

"; + + message.html.content = htmlMsg; + + /** The HTML text message character set e.g. + * us-ascii + * utf-8 + * utf-7 + * The default value is utf-8 + */ + message.html.charSet = F("utf-8"); + + /** The content transfer encoding e.g. + * enc_7bit or "7bit" (not encoded) + * enc_qp or "quoted-printable" (encoded) + * enc_base64 or "base64" (encoded) + * enc_binary or "binary" (not encoded) + * enc_8bit or "8bit" (not encoded) + * The default value is "7bit" + */ + message.html.transfer_encoding = Content_Transfer_Encoding::enc_qp; + + message.text.content = F("This message contains 1 inline image and 1 attachment file.\r\nThe inline image will not show in the plain text message."); + + message.text.charSet = F("utf-8"); + message.text.transfer_encoding = Content_Transfer_Encoding::enc_base64; + + /** The message priority + * esp_mail_smtp_priority_high or 1 + * esp_mail_smtp_priority_normal or 3 + * esp_mail_smtp_priority_low or 5 + * The default value is esp_mail_smtp_priority_low + */ + message.priority = esp_mail_smtp_priority::esp_mail_smtp_priority_normal; + + /** The Delivery Status Notifications e.g. + * esp_mail_smtp_notify_never + * esp_mail_smtp_notify_success + * esp_mail_smtp_notify_failure + * esp_mail_smtp_notify_delay + * The default value is esp_mail_smtp_notify_never + */ + // message.response.notify = esp_mail_smtp_notify_success | esp_mail_smtp_notify_failure | esp_mail_smtp_notify_delay; + + /* Set the custom message header */ + message.addHeader(F("Message-ID: ")); + + /* The attachment data item */ + SMTP_Attachment att[2]; + int attIndex = 0; + + /** Set the inline image info e.g. + * file name, MIME type, file path, file storage type, + * transfer encoding and content encoding + */ + att[attIndex].descr.filename = F("orange.png"); + att[attIndex].descr.mime = F("image/png"); + att[attIndex].file.path = F("/orange.png"); + + /** The file storage type e.g. + * esp_mail_file_storage_type_none, + * esp_mail_file_storage_type_flash, and + * esp_mail_file_storage_type_sd + */ + att[attIndex].file.storage_type = esp_mail_file_storage_type_flash; + + /* Need to be base64 transfer encoding for inline image */ + att[attIndex].descr.transfer_encoding = Content_Transfer_Encoding::enc_base64; + + /** The orange.png file is already base64 encoded file. + * Then set the content encoding to match the transfer encoding + * which no encoding was taken place prior to sending. + */ + att[attIndex].descr.content_encoding = Content_Transfer_Encoding::enc_base64; + + /* Add inline image to the message */ + message.addInlineImage(att[attIndex]); + + /** Set the attachment info e.g. + * file name, MIME type, file path, file storage type, + * transfer encoding and content encoding + */ + + attIndex++; + att[attIndex].descr.filename = F("bin1.dat"); + att[attIndex].descr.mime = F("application/octet-stream"); // binary data + att[attIndex].descr.description = F("This is binary data"); + att[attIndex].file.path = F("/bin1.dat"); + att[attIndex].file.storage_type = esp_mail_file_storage_type_flash; + att[attIndex].descr.transfer_encoding = Content_Transfer_Encoding::enc_base64; + + /* Add attachment to the message */ + message.addAttachment(att[attIndex]); + + /* Connect to the server */ + if (!smtp.connect(&config)) + { + MailClient.printf("Connection error, Status Code: %d, Error Code: %d, Reason: %s", smtp.statusCode(), smtp.errorCode(), smtp.errorReason().c_str()); + return; + } + + if (smtp.isAuthenticated()) + Serial.println("\nSuccessfully logged in."); + else + Serial.println("\nConnected with no Auth."); + + /* Start sending the Email and close the session */ + if (!MailClient.sendMail(&smtp, &message, true)) + MailClient.printf("Error, Status Code: %d, Error Code: %d, Reason: %s", smtp.statusCode(), smtp.errorCode(), smtp.errorReason().c_str()); + + // to clear sending result log + // smtp.sendingResult.clear(); + + MailClient.printf("Free Heap: %d\n", MailClient.getFreeHeap()); +} + +void loop() +{ +} + +/* Callback function to get the Email sending status */ +void smtpCallback(SMTP_Status status) +{ + /* Print the current status */ + Serial.println(status.info()); + + /* Print the sending result */ + if (status.success()) + { + // MailClient.printf used in the examples is for format printing via debug Serial port + // that works for all supported Arduino platform SDKs e.g. SAMD, ESP32 and ESP8266. + // In ESP8266 and ESP32, you can use Serial.printf directly. + + Serial.println("----------------"); + MailClient.printf("Message sent success: %d\n", status.completedCount()); + MailClient.printf("Message sent failed: %d\n", status.failedCount()); + Serial.println("----------------\n"); + + for (size_t i = 0; i < smtp.sendingResult.size(); i++) + { + /* Get the result item */ + SMTP_Result result = smtp.sendingResult.getItem(i); + + // In case, ESP32, ESP8266 and SAMD device, the timestamp get from result.timestamp should be valid if + // your device time was synched with NTP server. + // Other devices may show invalid timestamp as the device time was not set i.e. it will show Jan 1, 1970. + // You can call smtp.setSystemTime(xxx) to set device time manually. Where xxx is timestamp (seconds since Jan 1, 1970) + + MailClient.printf("Message No: %d\n", i + 1); + MailClient.printf("Status: %s\n", result.completed ? "success" : "failed"); + MailClient.printf("Date/Time: %s\n", MailClient.Time.getDateTimeString(result.timestamp, "%B %d, %Y %H:%M:%S").c_str()); + MailClient.printf("Recipient: %s\n", result.recipients.c_str()); + MailClient.printf("Subject: %s\n", result.subject.c_str()); + } + Serial.println("----------------\n"); + + // You need to clear sending result as the memory usage will grow up. + smtp.sendingResult.clear(); + } +} \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_Attachment_PSRAM/Send_Attachment_PSRAM.ino b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_Attachment_PSRAM/Send_Attachment_PSRAM.ino new file mode 100644 index 000000000..2cd102ea6 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_Attachment_PSRAM/Send_Attachment_PSRAM.ino @@ -0,0 +1,318 @@ + + +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt +*/ + +// This example shows how to send Email with attachment stored in PSRAM (ESP32 only). + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +#include +#if defined(ESP32) +#include +#elif defined(ESP8266) +#include +#endif + +#include + +// To use only SMTP functions, you can exclude the IMAP from compilation, see ESP_Mail_FS.h. + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +/** For Gmail, the app password will be used for log in + * Check out https://github.com/mobizt/ESP-Mail-Client#gmail-smtp-and-imap-required-app-passwords-to-sign-in + * + * For Yahoo mail, log in to your yahoo mail in web browser and generate app password by go to + * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc + * + * To use Gmai and Yahoo's App Password to sign in, define the AUTHOR_PASSWORD with your App Password + * and AUTHOR_EMAIL with your account email. + */ + +/** The smtp host name e.g. smtp.gmail.com for GMail or smtp.office365.com for Outlook or smtp.mail.yahoo.com */ +#define SMTP_HOST "" + +/** The smtp port e.g. + * 25 or esp_mail_smtp_port_25 + * 465 or esp_mail_smtp_port_465 + * 587 or esp_mail_smtp_port_587 + */ +#define SMTP_PORT esp_mail_smtp_port_587 + +/* The log in credentials */ +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" + +/* Recipient email address */ +#define RECIPIENT_EMAIL "" + +/* Declare the global used SMTPSession object for SMTP transport */ +SMTPSession smtp; + +/* Callback function to get the Email sending status */ +void smtpCallback(SMTP_Status status); + +const char rootCACert[] PROGMEM = "-----BEGIN CERTIFICATE-----\n" + "-----END CERTIFICATE-----\n"; + +void setup() +{ + + Serial.begin(115200); + + Serial.println(); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + multi.addAP(WIFI_SSID, WIFI_PASSWORD); + multi.run(); +#else + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Connecting to Wi-Fi"); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + unsigned long ms = millis(); +#endif + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + if (millis() - ms > 10000) + break; +#endif + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + /* Set the network reconnection option */ + MailClient.networkReconnect(true); + + /** Enable the debug via Serial port + * 0 for no debugging + * 1 for basic level debugging + * + * Debug port can be changed via ESP_MAIL_DEFAULT_DEBUG_PORT in ESP_Mail_FS.h + */ + smtp.debug(1); + + /* Set the callback function to get the sending results */ + smtp.callback(smtpCallback); + + /* Declare the Session_Config for user defined session credentials */ + Session_Config config; + + /* Set the session config */ + config.server.host_name = SMTP_HOST; + config.server.port = SMTP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + + /** Assign your host name or you public IPv4 or IPv6 only + * as this is the part of EHLO/HELO command to identify the client system + * to prevent connection rejection. + * If host name or public IP is not available, ignore this or + * use loopback address "127.0.0.1". + * + * Assign any text to this option may cause the connection rejection. + */ + config.login.user_domain = F("127.0.0.1"); + + /* + Set the NTP config time + For times east of the Prime Meridian use 0-12 + For times west of the Prime Meridian add 12 to the offset. + Ex. American/Denver GMT would be -6. 6 + 12 = 18 + See https://en.wikipedia.org/wiki/Time_zone for a list of the GMT/UTC timezone offsets + */ + config.time.ntp_server = F("pool.ntp.org,time.nist.gov"); + config.time.gmt_offset = 3; + config.time.day_light_offset = 0; + + /* Declare the message class */ + SMTP_Message message; + + /* Set the message headers */ + message.sender.name = F("ESP Mail"); + message.sender.email = AUTHOR_EMAIL; + message.subject = F("Test sending plain text Email with PSRAM attachment"); + message.addRecipient(F("Someone"), RECIPIENT_EMAIL); + + String textMsg = "This is simple plain text message with PSRAM attachment"; + message.text.content = textMsg; + + /** The Plain text message character set e.g. + * us-ascii + * utf-8 + * utf-7 + * The default value is utf-8 + */ + message.text.charSet = F("us-ascii"); + + /** The content transfer encoding e.g. + * enc_7bit or "7bit" (not encoded) + * enc_qp or "quoted-printable" (encoded) + * enc_base64 or "base64" (encoded) + * enc_binary or "binary" (not encoded) + * enc_8bit or "8bit" (not encoded) + * The default value is "7bit" + */ + message.text.transfer_encoding = Content_Transfer_Encoding::enc_7bit; + + // If this is a reply message + // message.in_reply_to = ""; + // message.references = " "; + + /** The message priority + * esp_mail_smtp_priority_high or 1 + * esp_mail_smtp_priority_normal or 3 + * esp_mail_smtp_priority_low or 5 + * The default value is esp_mail_smtp_priority_low + */ + message.priority = esp_mail_smtp_priority::esp_mail_smtp_priority_low; + + // message.response.reply_to = "someone@somemail.com"; + // message.response.return_path = "someone@somemail.com"; + + /** The Delivery Status Notifications e.g. + * esp_mail_smtp_notify_never + * esp_mail_smtp_notify_success + * esp_mail_smtp_notify_failure + * esp_mail_smtp_notify_delay + * The default value is esp_mail_smtp_notify_never + */ + // message.response.notify = esp_mail_smtp_notify_success | esp_mail_smtp_notify_failure | esp_mail_smtp_notify_delay; + + /* Set the custom message header */ + message.addHeader(F("Message-ID: ")); + + // For Root CA certificate verification (ESP8266 and ESP32 only) + // config.certificate.cert_data = rootCACert; + // or + // config.certificate.cert_file = "/path/to/der/file"; + // config.certificate.cert_file_storage_type = esp_mail_file_storage_type_flash; // esp_mail_file_storage_type_sd + // config.certificate.verify = true; + + // The WiFiNINA firmware the Root CA certification can be added via the option in Firmware update tool in Arduino IDE + + /* The attachment data item */ + SMTP_Attachment att[1]; + int attIndex = 0; + +#if defined(ESP32) + + int dlen = 3 * 1024 * 1024 + 512 * 1024; + uint8_t *data = (uint8_t *)ps_malloc(dlen); + + if (psramFound()) + { + memset(data, 0xff, dlen); + + att[attIndex].descr.filename = F("data.dat"); + att[attIndex].descr.mime = F("application/octet-stream"); + att[attIndex].descr.description = F("This is binary data"); + att[attIndex].blob.data = data; + att[attIndex].blob.size = dlen; + att[attIndex].descr.transfer_encoding = Content_Transfer_Encoding::enc_base64; + + /* Add inline image to the message */ + message.addInlineImage(att[attIndex]); + } + +#endif + + /* Connect to the server */ + if (!smtp.connect(&config)) + { + MailClient.printf("Connection error, Status Code: %d, Error Code: %d, Reason: %s", smtp.statusCode(), smtp.errorCode(), smtp.errorReason().c_str()); + return; + } + + if (smtp.isAuthenticated()) + Serial.println("\nSuccessfully logged in."); + else + Serial.println("\nConnected with no Auth."); + + /* Start sending Email and close the session */ + if (!MailClient.sendMail(&smtp, &message)) + MailClient.printf("Error, Status Code: %d, Error Code: %d, Reason: %s", smtp.statusCode(), smtp.errorCode(), smtp.errorReason().c_str()); + + // to clear sending result log + // smtp.sendingResult.clear(); + + MailClient.printf("Free Heap: %d\n", MailClient.getFreeHeap()); +} + +void loop() +{ +} + +/* Callback function to get the Email sending status */ +void smtpCallback(SMTP_Status status) +{ + /* Print the current status */ + Serial.println(status.info()); + + /* Print the sending result */ + if (status.success()) + { + // MailClient.printf used in the examples is for format printing via debug Serial port + // that works for all supported Arduino platform SDKs e.g. SAMD, ESP32 and ESP8266. + // In ESP8266 and ESP32, you can use Serial.printf directly. + + Serial.println("----------------"); + MailClient.printf("Message sent success: %d\n", status.completedCount()); + MailClient.printf("Message sent failed: %d\n", status.failedCount()); + Serial.println("----------------\n"); + + for (size_t i = 0; i < smtp.sendingResult.size(); i++) + { + /* Get the result item */ + SMTP_Result result = smtp.sendingResult.getItem(i); + + // In case, ESP32, ESP8266 and SAMD device, the timestamp get from result.timestamp should be valid if + // your device time was synched with NTP server. + // Other devices may show invalid timestamp as the device time was not set i.e. it will show Jan 1, 1970. + // You can call smtp.setSystemTime(xxx) to set device time manually. Where xxx is timestamp (seconds since Jan 1, 1970) + + MailClient.printf("Message No: %d\n", i + 1); + MailClient.printf("Status: %s\n", result.completed ? "success" : "failed"); + MailClient.printf("Date/Time: %s\n", MailClient.Time.getDateTimeString(result.timestamp, "%B %d, %Y %H:%M:%S").c_str()); + MailClient.printf("Recipient: %s\n", result.recipients.c_str()); + MailClient.printf("Subject: %s\n", result.subject.c_str()); + } + Serial.println("----------------\n"); + + // You need to clear sending result as the memory usage will grow up. + smtp.sendingResult.clear(); + } +} diff --git a/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_Camera_Image/ESP_Camera/ESP_Camera.ino b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_Camera_Image/ESP_Camera/ESP_Camera.ino new file mode 100644 index 000000000..ca1d27850 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_Camera_Image/ESP_Camera/ESP_Camera.ino @@ -0,0 +1,325 @@ + +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt +*/ + +/** + * This example shows how to send Email with inline image from ESP32 camera module. + * + * The ESP32 board used in this example is ESP32 PSRAM Timer Camera X (OV3660). + */ + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +#include +#if defined(ESP32) +#include +#endif + +#include + +#include "esp_camera.h" + +// =================== +// Select camera model +// =================== +//#define CAMERA_MODEL_WROVER_KIT // Has PSRAM +#define CAMERA_MODEL_ESP_EYE // Has PSRAM +//#define CAMERA_MODEL_ESP32S3_EYE // Has PSRAM +//#define CAMERA_MODEL_M5STACK_PSRAM // Has PSRAM +//#define CAMERA_MODEL_M5STACK_V2_PSRAM // M5Camera version B Has PSRAM +//#define CAMERA_MODEL_M5STACK_WIDE // Has PSRAM +//#define CAMERA_MODEL_M5STACK_ESP32CAM // No PSRAM +//#define CAMERA_MODEL_M5STACK_UNITCAM // No PSRAM +//#define CAMERA_MODEL_AI_THINKER // Has PSRAM +//#define CAMERA_MODEL_TTGO_T_JOURNAL // No PSRAM +//#define CAMERA_MODEL_XIAO_ESP32S3 // Has PSRAM +// ** Espressif Internal Boards ** +//#define CAMERA_MODEL_ESP32_CAM_BOARD +//#define CAMERA_MODEL_ESP32S2_CAM_BOARD +//#define CAMERA_MODEL_ESP32S3_CAM_LCD +//#define CAMERA_MODEL_DFRobot_FireBeetle2_ESP32S3 // Has PSRAM +//#define CAMERA_MODEL_DFRobot_Romeo_ESP32S3 // Has PSRAM +#include "camera_pins.h" + +// The camera_pins.h was taken from +//https://github.com/espressif/arduino-esp32/blob/master/libraries/ESP32/examples/Camera/CameraWebServer + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +/** For Gmail, the app password will be used for log in + * Check out https://github.com/mobizt/ESP-Mail-Client#gmail-smtp-and-imap-required-app-passwords-to-sign-in + * + * For Yahoo mail, log in to your yahoo mail in web browser and generate app password by go to + * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc + * + * To use Gmai and Yahoo's App Password to sign in, define the AUTHOR_PASSWORD with your App Password + * and AUTHOR_EMAIL with your account email. + */ + +/** The smtp host name e.g. smtp.gmail.com for GMail or smtp.office365.com for Outlook or smtp.mail.yahoo.com */ +#define SMTP_HOST "" + +/** The smtp port e.g. + * 25 or esp_mail_smtp_port_25 + * 465 or esp_mail_smtp_port_465 + * 587 or esp_mail_smtp_port_587 + */ +#define SMTP_PORT esp_mail_smtp_port_587 + +/* The log in credentials */ +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" + +/* Recipient email address */ +#define RECIPIENT_EMAIL "" + +/* Declare the global used SMTPSession object for SMTP transport */ +SMTPSession smtp; + +/* Callback function to get the Email sending status */ +void smtpCallback(SMTP_Status status); + +void setup() +{ + + Serial.begin(115200); + + Serial.println(); + + camera_config_t camCfg; + camCfg.ledc_channel = LEDC_CHANNEL_0; + camCfg.ledc_timer = LEDC_TIMER_0; + camCfg.pin_d0 = Y2_GPIO_NUM; + camCfg.pin_d1 = Y3_GPIO_NUM; + camCfg.pin_d2 = Y4_GPIO_NUM; + camCfg.pin_d3 = Y5_GPIO_NUM; + camCfg.pin_d4 = Y6_GPIO_NUM; + camCfg.pin_d5 = Y7_GPIO_NUM; + camCfg.pin_d6 = Y8_GPIO_NUM; + camCfg.pin_d7 = Y9_GPIO_NUM; + camCfg.pin_xclk = XCLK_GPIO_NUM; + camCfg.pin_pclk = PCLK_GPIO_NUM; + camCfg.pin_vsync = VSYNC_GPIO_NUM; + camCfg.pin_href = HREF_GPIO_NUM; + camCfg.pin_sscb_sda = SIOD_GPIO_NUM; + camCfg.pin_sscb_scl = SIOC_GPIO_NUM; + camCfg.pin_pwdn = PWDN_GPIO_NUM; + camCfg.pin_reset = RESET_GPIO_NUM; + camCfg.xclk_freq_hz = 20000000; + camCfg.pixel_format = PIXFORMAT_JPEG; + camCfg.frame_size = FRAMESIZE_QXGA; + camCfg.jpeg_quality = 10; + camCfg.fb_count = 2; + + // camera init + esp_err_t err = esp_camera_init(&camCfg); + if (err != ESP_OK) + { + Serial.printf("Camera init failed with error 0x%x", err); + return; + } + + Serial.print("Connecting to AP"); + + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(200); + } + + Serial.println(""); + Serial.println("WiFi connected."); + Serial.println("IP address: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + /* Set the network reconnection option */ + MailClient.networkReconnect(true); + + /** Enable the debug via Serial port + * 0 for no debugging + * 1 for basic level debugging + * + * Debug port can be changed via ESP_MAIL_DEFAULT_DEBUG_PORT in ESP_Mail_FS.h + */ + smtp.debug(1); + + /* Set the callback function to get the sending results */ + smtp.callback(smtpCallback); + + /* Declare the Session_Config for user defined session credentials */ + Session_Config config; + + /* Set the session config */ + config.server.host_name = SMTP_HOST; + config.server.port = SMTP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + + /** Assign your host name or you public IPv4 or IPv6 only + * as this is the part of EHLO/HELO command to identify the client system + * to prevent connection rejection. + * If host name or public IP is not available, ignore this or + * use loopback address "127.0.0.1". + * + * Assign any text to this option may cause the connection rejection. + */ + config.login.user_domain = F("127.0.0.1"); + + /* + Set the NTP config time + For times east of the Prime Meridian use 0-12 + For times west of the Prime Meridian add 12 to the offset. + Ex. American/Denver GMT would be -6. 6 + 12 = 18 + See https://en.wikipedia.org/wiki/Time_zone for a list of the GMT/UTC timezone offsets + */ + config.time.ntp_server = F("pool.ntp.org,time.nist.gov"); + config.time.gmt_offset = 3; + config.time.day_light_offset = 0; + + /* Declare the message class */ + SMTP_Message message; + + /* Enable the chunked data transfer with pipelining for large message if server supported */ + message.enable.chunking = true; + + /* Set the message headers */ + message.sender.name = F("ESP Mail"); + message.sender.email = AUTHOR_EMAIL; + + message.subject = F("Test sending camera image"); + message.addRecipient(F("user1"), RECIPIENT_EMAIL); + + message.html.content = F("The camera image.

\"esp32"); + + /** The content transfer encoding e.g. + * enc_7bit or "7bit" (not encoded) + * enc_qp or "quoted-printable" (encoded) <- not supported for message from blob and file + * enc_base64 or "base64" (encoded) + * enc_binary or "binary" (not encoded) + * enc_8bit or "8bit" (not encoded) + * The default value is "7bit" + */ + message.html.transfer_encoding = Content_Transfer_Encoding::enc_7bit; + + /** The HTML text message character set e.g. + * us-ascii + * utf-8 + * utf-7 + * The default value is utf-8 + */ + message.html.charSet = F("utf-8"); + + camera_fb_t *fb = esp_camera_fb_get(); + + SMTP_Attachment att; + + /** Set the inline image info e.g. + * file name, MIME type, file path, file storage type, + * transfer encoding and content encoding + */ + att.descr.filename = F("camera.jpg"); + att.descr.mime = F("image/jpg"); + + att.blob.data = fb->buf; + att.blob.size = fb->len; + + att.descr.content_id = F("image-001"); // The content id (cid) of camera.jpg image in the src tag + + /* Need to be base64 transfer encoding for inline image */ + att.descr.transfer_encoding = Content_Transfer_Encoding::enc_base64; + + /* Add inline image to the message */ + message.addInlineImage(att); + + /* Connect to the server */ + if (!smtp.connect(&config)) + { + MailClient.printf("Connection error, Status Code: %d, Error Code: %d, Reason: %s", smtp.statusCode(), smtp.errorCode(), smtp.errorReason().c_str()); + return; + } + + if (smtp.isAuthenticated()) + Serial.println("\nSuccessfully logged in."); + else + Serial.println("\nConnected with no Auth."); + + /* Start sending the Email and close the session */ + if (!MailClient.sendMail(&smtp, &message, true)) + MailClient.printf("Error, Status Code: %d, Error Code: %d, Reason: %s", smtp.statusCode(), smtp.errorCode(), smtp.errorReason().c_str()); + + // to clear sending result log + // smtp.sendingResult.clear(); + + MailClient.printf("Free Heap: %d\n", MailClient.getFreeHeap()); +} + +void loop() +{ +} + +/* Callback function to get the Email sending status */ +void smtpCallback(SMTP_Status status) +{ + /* Print the current status */ + Serial.println(status.info()); + + /* Print the sending result */ + if (status.success()) + { + // MailClient.printf used in the examples is for format printing via debug Serial port + // that works for all supported Arduino platform SDKs e.g. SAMD, ESP32 and ESP8266. + // In ESP8266 and ESP32, you can use Serial.printf directly. + + Serial.println("----------------"); + MailClient.printf("Message sent success: %d\n", status.completedCount()); + MailClient.printf("Message sent failed: %d\n", status.failedCount()); + Serial.println("----------------\n"); + + for (size_t i = 0; i < smtp.sendingResult.size(); i++) + { + /* Get the result item */ + SMTP_Result result = smtp.sendingResult.getItem(i); + + // In case, ESP32, ESP8266 and SAMD device, the timestamp get from result.timestamp should be valid if + // your device time was synched with NTP server. + // Other devices may show invalid timestamp as the device time was not set i.e. it will show Jan 1, 1970. + // You can call smtp.setSystemTime(xxx) to set device time manually. Where xxx is timestamp (seconds since Jan 1, 1970) + + MailClient.printf("Message No: %d\n", i + 1); + MailClient.printf("Status: %s\n", result.completed ? "success" : "failed"); + MailClient.printf("Date/Time: %s\n", MailClient.Time.getDateTimeString(result.timestamp, "%B %d, %Y %H:%M:%S").c_str()); + MailClient.printf("Recipient: %s\n", result.recipients.c_str()); + MailClient.printf("Subject: %s\n", result.subject.c_str()); + } + Serial.println("----------------\n"); + + // You need to clear sending result as the memory usage will grow up. + smtp.sendingResult.clear(); + } +} \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_Camera_Image/ESP_Camera/camera_pins.h b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_Camera_Image/ESP_Camera/camera_pins.h new file mode 100644 index 000000000..fdbdd1a31 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_Camera_Image/ESP_Camera/camera_pins.h @@ -0,0 +1,317 @@ + +#if defined(CAMERA_MODEL_WROVER_KIT) +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM -1 +#define XCLK_GPIO_NUM 21 +#define SIOD_GPIO_NUM 26 +#define SIOC_GPIO_NUM 27 + +#define Y9_GPIO_NUM 35 +#define Y8_GPIO_NUM 34 +#define Y7_GPIO_NUM 39 +#define Y6_GPIO_NUM 36 +#define Y5_GPIO_NUM 19 +#define Y4_GPIO_NUM 18 +#define Y3_GPIO_NUM 5 +#define Y2_GPIO_NUM 4 +#define VSYNC_GPIO_NUM 25 +#define HREF_GPIO_NUM 23 +#define PCLK_GPIO_NUM 22 + +#elif defined(CAMERA_MODEL_ESP_EYE) +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM -1 +#define XCLK_GPIO_NUM 4 +#define SIOD_GPIO_NUM 18 +#define SIOC_GPIO_NUM 23 + +#define Y9_GPIO_NUM 36 +#define Y8_GPIO_NUM 37 +#define Y7_GPIO_NUM 38 +#define Y6_GPIO_NUM 39 +#define Y5_GPIO_NUM 35 +#define Y4_GPIO_NUM 14 +#define Y3_GPIO_NUM 13 +#define Y2_GPIO_NUM 34 +#define VSYNC_GPIO_NUM 5 +#define HREF_GPIO_NUM 27 +#define PCLK_GPIO_NUM 25 + +#define LED_GPIO_NUM 22 + +#elif defined(CAMERA_MODEL_M5STACK_PSRAM) +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM 15 +#define XCLK_GPIO_NUM 27 +#define SIOD_GPIO_NUM 25 +#define SIOC_GPIO_NUM 23 + +#define Y9_GPIO_NUM 19 +#define Y8_GPIO_NUM 36 +#define Y7_GPIO_NUM 18 +#define Y6_GPIO_NUM 39 +#define Y5_GPIO_NUM 5 +#define Y4_GPIO_NUM 34 +#define Y3_GPIO_NUM 35 +#define Y2_GPIO_NUM 32 +#define VSYNC_GPIO_NUM 22 +#define HREF_GPIO_NUM 26 +#define PCLK_GPIO_NUM 21 + +#elif defined(CAMERA_MODEL_M5STACK_V2_PSRAM) +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM 15 +#define XCLK_GPIO_NUM 27 +#define SIOD_GPIO_NUM 22 +#define SIOC_GPIO_NUM 23 + +#define Y9_GPIO_NUM 19 +#define Y8_GPIO_NUM 36 +#define Y7_GPIO_NUM 18 +#define Y6_GPIO_NUM 39 +#define Y5_GPIO_NUM 5 +#define Y4_GPIO_NUM 34 +#define Y3_GPIO_NUM 35 +#define Y2_GPIO_NUM 32 +#define VSYNC_GPIO_NUM 25 +#define HREF_GPIO_NUM 26 +#define PCLK_GPIO_NUM 21 + +#elif defined(CAMERA_MODEL_M5STACK_WIDE) +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM 15 +#define XCLK_GPIO_NUM 27 +#define SIOD_GPIO_NUM 22 +#define SIOC_GPIO_NUM 23 + +#define Y9_GPIO_NUM 19 +#define Y8_GPIO_NUM 36 +#define Y7_GPIO_NUM 18 +#define Y6_GPIO_NUM 39 +#define Y5_GPIO_NUM 5 +#define Y4_GPIO_NUM 34 +#define Y3_GPIO_NUM 35 +#define Y2_GPIO_NUM 32 +#define VSYNC_GPIO_NUM 25 +#define HREF_GPIO_NUM 26 +#define PCLK_GPIO_NUM 21 + +#define LED_GPIO_NUM 2 + +#elif defined(CAMERA_MODEL_M5STACK_ESP32CAM) +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM 15 +#define XCLK_GPIO_NUM 27 +#define SIOD_GPIO_NUM 25 +#define SIOC_GPIO_NUM 23 + +#define Y9_GPIO_NUM 19 +#define Y8_GPIO_NUM 36 +#define Y7_GPIO_NUM 18 +#define Y6_GPIO_NUM 39 +#define Y5_GPIO_NUM 5 +#define Y4_GPIO_NUM 34 +#define Y3_GPIO_NUM 35 +#define Y2_GPIO_NUM 17 +#define VSYNC_GPIO_NUM 22 +#define HREF_GPIO_NUM 26 +#define PCLK_GPIO_NUM 21 + +#elif defined(CAMERA_MODEL_M5STACK_UNITCAM) +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM 15 +#define XCLK_GPIO_NUM 27 +#define SIOD_GPIO_NUM 25 +#define SIOC_GPIO_NUM 23 + +#define Y9_GPIO_NUM 19 +#define Y8_GPIO_NUM 36 +#define Y7_GPIO_NUM 18 +#define Y6_GPIO_NUM 39 +#define Y5_GPIO_NUM 5 +#define Y4_GPIO_NUM 34 +#define Y3_GPIO_NUM 35 +#define Y2_GPIO_NUM 32 +#define VSYNC_GPIO_NUM 22 +#define HREF_GPIO_NUM 26 +#define PCLK_GPIO_NUM 21 + +#elif defined(CAMERA_MODEL_AI_THINKER) +#define PWDN_GPIO_NUM 32 +#define RESET_GPIO_NUM -1 +#define XCLK_GPIO_NUM 0 +#define SIOD_GPIO_NUM 26 +#define SIOC_GPIO_NUM 27 + +#define Y9_GPIO_NUM 35 +#define Y8_GPIO_NUM 34 +#define Y7_GPIO_NUM 39 +#define Y6_GPIO_NUM 36 +#define Y5_GPIO_NUM 21 +#define Y4_GPIO_NUM 19 +#define Y3_GPIO_NUM 18 +#define Y2_GPIO_NUM 5 +#define VSYNC_GPIO_NUM 25 +#define HREF_GPIO_NUM 23 +#define PCLK_GPIO_NUM 22 + +// 4 for flash led or 33 for normal led +#define LED_GPIO_NUM 4 + +#elif defined(CAMERA_MODEL_TTGO_T_JOURNAL) +#define PWDN_GPIO_NUM 0 +#define RESET_GPIO_NUM 15 +#define XCLK_GPIO_NUM 27 +#define SIOD_GPIO_NUM 25 +#define SIOC_GPIO_NUM 23 + +#define Y9_GPIO_NUM 19 +#define Y8_GPIO_NUM 36 +#define Y7_GPIO_NUM 18 +#define Y6_GPIO_NUM 39 +#define Y5_GPIO_NUM 5 +#define Y4_GPIO_NUM 34 +#define Y3_GPIO_NUM 35 +#define Y2_GPIO_NUM 17 +#define VSYNC_GPIO_NUM 22 +#define HREF_GPIO_NUM 26 +#define PCLK_GPIO_NUM 21 + +#elif defined(CAMERA_MODEL_XIAO_ESP32S3) +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM -1 +#define XCLK_GPIO_NUM 10 +#define SIOD_GPIO_NUM 40 +#define SIOC_GPIO_NUM 39 + +#define Y9_GPIO_NUM 48 +#define Y8_GPIO_NUM 11 +#define Y7_GPIO_NUM 12 +#define Y6_GPIO_NUM 14 +#define Y5_GPIO_NUM 16 +#define Y4_GPIO_NUM 18 +#define Y3_GPIO_NUM 17 +#define Y2_GPIO_NUM 15 +#define VSYNC_GPIO_NUM 38 +#define HREF_GPIO_NUM 47 +#define PCLK_GPIO_NUM 13 + +#elif defined(CAMERA_MODEL_ESP32_CAM_BOARD) +// The 18 pin header on the board has Y5 and Y3 swapped +#define USE_BOARD_HEADER 0 +#define PWDN_GPIO_NUM 32 +#define RESET_GPIO_NUM 33 +#define XCLK_GPIO_NUM 4 +#define SIOD_GPIO_NUM 18 +#define SIOC_GPIO_NUM 23 + +#define Y9_GPIO_NUM 36 +#define Y8_GPIO_NUM 19 +#define Y7_GPIO_NUM 21 +#define Y6_GPIO_NUM 39 +#if USE_BOARD_HEADER +#define Y5_GPIO_NUM 13 +#else +#define Y5_GPIO_NUM 35 +#endif +#define Y4_GPIO_NUM 14 +#if USE_BOARD_HEADER +#define Y3_GPIO_NUM 35 +#else +#define Y3_GPIO_NUM 13 +#endif +#define Y2_GPIO_NUM 34 +#define VSYNC_GPIO_NUM 5 +#define HREF_GPIO_NUM 27 +#define PCLK_GPIO_NUM 25 + +#elif defined(CAMERA_MODEL_ESP32S3_CAM_LCD) +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM -1 +#define XCLK_GPIO_NUM 40 +#define SIOD_GPIO_NUM 17 +#define SIOC_GPIO_NUM 18 + +#define Y9_GPIO_NUM 39 +#define Y8_GPIO_NUM 41 +#define Y7_GPIO_NUM 42 +#define Y6_GPIO_NUM 12 +#define Y5_GPIO_NUM 3 +#define Y4_GPIO_NUM 14 +#define Y3_GPIO_NUM 47 +#define Y2_GPIO_NUM 13 +#define VSYNC_GPIO_NUM 21 +#define HREF_GPIO_NUM 38 +#define PCLK_GPIO_NUM 11 + +#elif defined(CAMERA_MODEL_ESP32S2_CAM_BOARD) +// The 18 pin header on the board has Y5 and Y3 swapped +#define USE_BOARD_HEADER 0 +#define PWDN_GPIO_NUM 1 +#define RESET_GPIO_NUM 2 +#define XCLK_GPIO_NUM 42 +#define SIOD_GPIO_NUM 41 +#define SIOC_GPIO_NUM 18 + +#define Y9_GPIO_NUM 16 +#define Y8_GPIO_NUM 39 +#define Y7_GPIO_NUM 40 +#define Y6_GPIO_NUM 15 +#if USE_BOARD_HEADER +#define Y5_GPIO_NUM 12 +#else +#define Y5_GPIO_NUM 13 +#endif +#define Y4_GPIO_NUM 5 +#if USE_BOARD_HEADER +#define Y3_GPIO_NUM 13 +#else +#define Y3_GPIO_NUM 12 +#endif +#define Y2_GPIO_NUM 14 +#define VSYNC_GPIO_NUM 38 +#define HREF_GPIO_NUM 4 +#define PCLK_GPIO_NUM 3 + +#elif defined(CAMERA_MODEL_ESP32S3_EYE) +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM -1 +#define XCLK_GPIO_NUM 15 +#define SIOD_GPIO_NUM 4 +#define SIOC_GPIO_NUM 5 + +#define Y2_GPIO_NUM 11 +#define Y3_GPIO_NUM 9 +#define Y4_GPIO_NUM 8 +#define Y5_GPIO_NUM 10 +#define Y6_GPIO_NUM 12 +#define Y7_GPIO_NUM 18 +#define Y8_GPIO_NUM 17 +#define Y9_GPIO_NUM 16 + +#define VSYNC_GPIO_NUM 6 +#define HREF_GPIO_NUM 7 +#define PCLK_GPIO_NUM 13 + +#elif defined(CAMERA_MODEL_DFRobot_FireBeetle2_ESP32S3) || defined(CAMERA_MODEL_DFRobot_Romeo_ESP32S3) +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM -1 +#define XCLK_GPIO_NUM 45 +#define SIOD_GPIO_NUM 1 +#define SIOC_GPIO_NUM 2 + +#define Y9_GPIO_NUM 48 +#define Y8_GPIO_NUM 46 +#define Y7_GPIO_NUM 8 +#define Y6_GPIO_NUM 7 +#define Y5_GPIO_NUM 4 +#define Y4_GPIO_NUM 41 +#define Y3_GPIO_NUM 40 +#define Y2_GPIO_NUM 39 +#define VSYNC_GPIO_NUM 6 +#define HREF_GPIO_NUM 42 +#define PCLK_GPIO_NUM 5 + +#else +#error "Camera model not selected" +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_Embedded_Message/Send_Embedded_Message.ino b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_Embedded_Message/Send_Embedded_Message.ino new file mode 100644 index 000000000..2f4da480e --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_Embedded_Message/Send_Embedded_Message.ino @@ -0,0 +1,303 @@ + +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt +*/ + +// This example shows how to send Email which the html and text message will be embedded as attachment or inline content. + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +#include + +// To use only SMTP functions, you can exclude the IMAP from compilation, see ESP_Mail_FS.h. + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +/* Recipient email address */ +#define RECIPIENT_EMAIL "" + +/** For Gmail, the app password will be used for log in + * Check out https://github.com/mobizt/ESP-Mail-Client#gmail-smtp-and-imap-required-app-passwords-to-sign-in + * + * For Yahoo mail, log in to your yahoo mail in web browser and generate app password by go to + * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc + * + * To use Gmai and Yahoo's App Password to sign in, define the AUTHOR_PASSWORD with your App Password + * and AUTHOR_EMAIL with your account email. + */ + +/** The smtp host name e.g. smtp.gmail.com for GMail or smtp.office365.com for Outlook or smtp.mail.yahoo.com */ +#define SMTP_HOST "" + +/** The smtp port e.g. + * 25 or esp_mail_smtp_port_25 + * 465 or esp_mail_smtp_port_465 + * 587 or esp_mail_smtp_port_587 + */ +#define SMTP_PORT esp_mail_smtp_port_587 + +/* The log in credentials */ +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" + +/* Declare the global used SMTPSession object for SMTP transport */ +SMTPSession smtp; + +/* Callback function to get the Email sending status */ +void smtpCallback(SMTP_Status status); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) +WiFiMulti multi; +#endif + +void setup() +{ + + Serial.begin(115200); + +#if defined(ARDUINO_ARCH_SAMD) + while (!Serial) + ; +#endif + + Serial.println(); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + multi.addAP(WIFI_SSID, WIFI_PASSWORD); + multi.run(); +#else + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Connecting to Wi-Fi"); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + unsigned long ms = millis(); +#endif + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + if (millis() - ms > 10000) + break; +#endif + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + /* Set the network reconnection option */ + MailClient.networkReconnect(true); + + // The WiFi credentials are required for Pico W + // due to it does not have reconnect feature. +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + MailClient.clearAP(); + MailClient.addAP(WIFI_SSID, WIFI_PASSWORD); +#endif + + /** Enable the debug via Serial port + * 0 for no debugging + * 1 for basic level debugging + * + * Debug port can be changed via ESP_MAIL_DEFAULT_DEBUG_PORT in ESP_Mail_FS.h + */ + smtp.debug(1); + + /* Set the callback function to get the sending results */ + smtp.callback(smtpCallback); + + /* Declare the Session_Config for user defined session credentials */ + Session_Config config; + + /* Set the session config */ + config.server.host_name = SMTP_HOST; + config.server.port = SMTP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + + /** Assign your host name or you public IPv4 or IPv6 only + * as this is the part of EHLO/HELO command to identify the client system + * to prevent connection rejection. + * If host name or public IP is not available, ignore this or + * use loopback address "127.0.0.1". + * + * Assign any text to this option may cause the connection rejection. + */ + config.login.user_domain = F("127.0.0.1"); + + /* + Set the NTP config time + For times east of the Prime Meridian use 0-12 + For times west of the Prime Meridian add 12 to the offset. + Ex. American/Denver GMT would be -6. 6 + 12 = 18 + See https://en.wikipedia.org/wiki/Time_zone for a list of the GMT/UTC timezone offsets + */ + config.time.ntp_server = F("pool.ntp.org,time.nist.gov"); + config.time.gmt_offset = 3; + config.time.day_light_offset = 0; + + /* Declare the message class */ + SMTP_Message message; + + /* Set the message headers */ + message.sender.name = F("ESP Mail"); + message.sender.email = AUTHOR_EMAIL; + message.subject = F("Test sending message as embedded files"); + message.addRecipient(F("Admin"), RECIPIENT_EMAIL); + + message.html.content = F("This is html message"); + + /** The Plain text message character set e.g. + * us-ascii + * utf-8 + * utf-7 + * The default value is utf-8 + */ + message.html.charSet = F("utf-8"); + + /** The content transfer encoding e.g. + * enc_7bit or "7bit" (not encoded) + * enc_qp or "quoted-printable" (encoded) + * enc_base64 or "base64" (encoded) + * enc_binary or "binary" (not encoded) + * enc_8bit or "8bit" (not encoded) + * The default value is "7bit" + */ + message.html.transfer_encoding = Content_Transfer_Encoding::enc_qp; + + /* Enable to send this message body as file */ + message.html.embed.enable = true; + + /* The name of embedded file */ + message.html.embed.filename = F("test.html"); + + /** The embedded type + * esp_mail_smtp_embed_message_type_attachment or 0 + * esp_mail_smtp_embed_message_type_inline or 1 + */ + message.html.embed.type = esp_mail_smtp_embed_message_type_attachment; + + message.text.content = F("This is simple plain text message"); + message.text.charSet = F("utf-8"); + message.text.transfer_encoding = Content_Transfer_Encoding::enc_base64; + message.text.embed.enable = true; + message.text.embed.filename = F("test.txt"); + message.text.embed.type = esp_mail_smtp_embed_message_type_inline; + + /** The message priority + * esp_mail_smtp_priority_high or 1 + * esp_mail_smtp_priority_normal or 3 + * esp_mail_smtp_priority_low or 5 + * The default value is esp_mail_smtp_priority_low + */ + message.priority = esp_mail_smtp_priority::esp_mail_smtp_priority_low; + + /* Set the custom message header */ + message.addHeader(F("Message-ID: ")); + + /* Connect to the server */ + if (!smtp.connect(&config)) + { + MailClient.printf("Connection error, Status Code: %d, Error Code: %d, Reason: %s", smtp.statusCode(), smtp.errorCode(), smtp.errorReason().c_str()); + return; + } + + if (smtp.isAuthenticated()) + Serial.println("\nSuccessfully logged in."); + else + Serial.println("\nConnected with no Auth."); + + /* Start sending Email and close the session */ + if (!MailClient.sendMail(&smtp, &message)) + MailClient.printf("Error, Status Code: %d, Error Code: %d, Reason: %s", smtp.statusCode(), smtp.errorCode(), smtp.errorReason().c_str()); + + // to clear sending result log + // smtp.sendingResult.clear(); + + MailClient.printf("Free Heap: %d\n", MailClient.getFreeHeap()); +} + +void loop() +{ +} + +/* Callback function to get the Email sending status */ +void smtpCallback(SMTP_Status status) +{ + /* Print the current status */ + Serial.println(status.info()); + + /* Print the sending result */ + if (status.success()) + { + // MailClient.printf used in the examples is for format printing via debug Serial port + // that works for all supported Arduino platform SDKs e.g. SAMD, ESP32 and ESP8266. + // In ESP8266 and ESP32, you can use Serial.printf directly. + + Serial.println("----------------"); + MailClient.printf("Message sent success: %d\n", status.completedCount()); + MailClient.printf("Message sent failed: %d\n", status.failedCount()); + Serial.println("----------------\n"); + + for (size_t i = 0; i < smtp.sendingResult.size(); i++) + { + /* Get the result item */ + SMTP_Result result = smtp.sendingResult.getItem(i); + + // In case, ESP32, ESP8266 and SAMD device, the timestamp get from result.timestamp should be valid if + // your device time was synched with NTP server. + // Other devices may show invalid timestamp as the device time was not set i.e. it will show Jan 1, 1970. + // You can call smtp.setSystemTime(xxx) to set device time manually. Where xxx is timestamp (seconds since Jan 1, 1970) + + MailClient.printf("Message No: %d\n", i + 1); + MailClient.printf("Status: %s\n", result.completed ? "success" : "failed"); + MailClient.printf("Date/Time: %s\n", MailClient.Time.getDateTimeString(result.timestamp, "%B %d, %Y %H:%M:%S").c_str()); + MailClient.printf("Recipient: %s\n", result.recipients.c_str()); + MailClient.printf("Subject: %s\n", result.subject.c_str()); + } + Serial.println("----------------\n"); + + // You need to clear sending result as the memory usage will grow up. + smtp.sendingResult.clear(); + } +} \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_Enriched_Text/Send_Enriched_Text.ino b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_Enriched_Text/Send_Enriched_Text.ino new file mode 100644 index 000000000..99c162a6b --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_Enriched_Text/Send_Enriched_Text.ino @@ -0,0 +1,293 @@ + +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt +*/ + +// This example shows how to send Email in enriched text version. + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +#include + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +/** For Gmail, the app password will be used for log in + * Check out https://github.com/mobizt/ESP-Mail-Client#gmail-smtp-and-imap-required-app-passwords-to-sign-in + * + * For Yahoo mail, log in to your yahoo mail in web browser and generate app password by go to + * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc + * + * To use Gmai and Yahoo's App Password to sign in, define the AUTHOR_PASSWORD with your App Password + * and AUTHOR_EMAIL with your account email. + */ + +/** The smtp host name e.g. smtp.gmail.com for GMail or smtp.office365.com for Outlook or smtp.mail.yahoo.com */ +#define SMTP_HOST "" + +/** The smtp port e.g. + * 25 or esp_mail_smtp_port_25 + * 465 or esp_mail_smtp_port_465 + * 587 or esp_mail_smtp_port_587 + */ +#define SMTP_PORT esp_mail_smtp_port_587 + +/* The log in credentials */ +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" + +/* Recipient email address */ +#define RECIPIENT_EMAIL "" + +/* Declare the global used SMTPSession object for SMTP transport */ +SMTPSession smtp; + +/* Callback function to get the Email sending status */ +void smtpCallback(SMTP_Status status); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) +WiFiMulti multi; +#endif + +void setup() +{ + + Serial.begin(115200); + +#if defined(ARDUINO_ARCH_SAMD) + while (!Serial) + ; +#endif + + Serial.println(); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + multi.addAP(WIFI_SSID, WIFI_PASSWORD); + multi.run(); +#else + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Connecting to Wi-Fi"); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + unsigned long ms = millis(); +#endif + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + if (millis() - ms > 10000) + break; +#endif + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + /* Set the network reconnection option */ + MailClient.networkReconnect(true); + + // The WiFi credentials are required for Pico W + // due to it does not have reconnect feature. +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + MailClient.clearAP(); + MailClient.addAP(WIFI_SSID, WIFI_PASSWORD); +#endif + + /** Enable the debug via Serial port + * 0 for no debugging + * 1 for basic level debugging + * + * Debug port can be changed via ESP_MAIL_DEFAULT_DEBUG_PORT in ESP_Mail_FS.h + */ + smtp.debug(1); + + /* Set the callback function to get the sending results */ + smtp.callback(smtpCallback); + + /* Declare the Session_Config for user defined session credentials */ + Session_Config config; + + /* Set the session config */ + config.server.host_name = SMTP_HOST; + config.server.port = SMTP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + + /** Assign your host name or you public IPv4 or IPv6 only + * as this is the part of EHLO/HELO command to identify the client system + * to prevent connection rejection. + * If host name or public IP is not available, ignore this or + * use loopback address "127.0.0.1". + * + * Assign any text to this option may cause the connection rejection. + */ + config.login.user_domain = F("127.0.0.1"); + + /* + Set the NTP config time + For times east of the Prime Meridian use 0-12 + For times west of the Prime Meridian add 12 to the offset. + Ex. American/Denver GMT would be -6. 6 + 12 = 18 + See https://en.wikipedia.org/wiki/Time_zone for a list of the GMT/UTC timezone offsets + */ + config.time.ntp_server = F("pool.ntp.org,time.nist.gov"); + config.time.gmt_offset = 3; + config.time.day_light_offset = 0; + + /* Declare the message class */ + SMTP_Message message; + + /* Set the message headers */ + message.sender.name = F("ESP Mail"); + message.sender.email = AUTHOR_EMAIL; + message.subject = F("Test sending enriched text Email"); + message.addRecipient(F("Someone"), RECIPIENT_EMAIL); + + message.text.content = F("This is enriched as defined in RFC 1896\r\n\r\nIsn't it cool?"); + + message.text.content_type = F("text/enriched"); + + /** The Plain text message character set e.g. + * us-ascii + * utf-8 + * utf-7 + * The default value is utf-8 + */ + message.text.charSet = F("us-ascii"); + + /** The content transfer encoding e.g. + * enc_7bit or "7bit" (not encoded) + * enc_qp or "quoted-printable" (encoded) + * enc_base64 or "base64" (encoded) + * enc_binary or "binary" (not encoded) + * enc_8bit or "8bit" (not encoded) + * The default value is "7bit" + */ + message.text.transfer_encoding = Content_Transfer_Encoding::enc_7bit; + + /** The message priority + * esp_mail_smtp_priority_high or 1 + * esp_mail_smtp_priority_normal or 3 + * esp_mail_smtp_priority_low or 5 + * The default value is esp_mail_smtp_priority_low + */ + message.priority = esp_mail_smtp_priority::esp_mail_smtp_priority_low; + + /** The Delivery Status Notifications e.g. + * esp_mail_smtp_notify_never + * esp_mail_smtp_notify_success + * esp_mail_smtp_notify_failure + * esp_mail_smtp_notify_delay + * The default value is esp_mail_smtp_notify_never + */ + // message.response.notify = esp_mail_smtp_notify_success | esp_mail_smtp_notify_failure | esp_mail_smtp_notify_delay; + + /* Set the custom message header */ + message.addHeader(F("Message-ID: ")); + + /* Connect to the server */ + if (!smtp.connect(&config)) + { + MailClient.printf("Connection error, Status Code: %d, Error Code: %d, Reason: %s", smtp.statusCode(), smtp.errorCode(), smtp.errorReason().c_str()); + return; + } + + if (smtp.isAuthenticated()) + Serial.println("\nSuccessfully logged in."); + else + Serial.println("\nConnected with no Auth."); + + /* Start sending Email and close the session */ + if (!MailClient.sendMail(&smtp, &message)) + MailClient.printf("Error, Status Code: %d, Error Code: %d, Reason: %s", smtp.statusCode(), smtp.errorCode(), smtp.errorReason().c_str()); + + // to clear sending result log + // smtp.sendingResult.clear(); + + MailClient.printf("Free Heap: %d\n", MailClient.getFreeHeap()); +} + +void loop() +{ +} + +/* Callback function to get the Email sending status */ +void smtpCallback(SMTP_Status status) +{ + /* Print the current status */ + Serial.println(status.info()); + + /* Print the sending result */ + if (status.success()) + { + // MailClient.printf used in the examples is for format printing via debug Serial port + // that works for all supported Arduino platform SDKs e.g. SAMD, ESP32 and ESP8266. + // In ESP8266 and ESP32, you can use Serial.printf directly. + + Serial.println("----------------"); + MailClient.printf("Message sent success: %d\n", status.completedCount()); + MailClient.printf("Message sent failed: %d\n", status.failedCount()); + Serial.println("----------------\n"); + + for (size_t i = 0; i < smtp.sendingResult.size(); i++) + { + /* Get the result item */ + SMTP_Result result = smtp.sendingResult.getItem(i); + + // In case, ESP32, ESP8266 and SAMD device, the timestamp get from result.timestamp should be valid if + // your device time was synched with NTP server. + // Other devices may show invalid timestamp as the device time was not set i.e. it will show Jan 1, 1970. + // You can call smtp.setSystemTime(xxx) to set device time manually. Where xxx is timestamp (seconds since Jan 1, 1970) + + MailClient.printf("Message No: %d\n", i + 1); + MailClient.printf("Status: %s\n", result.completed ? "success" : "failed"); + MailClient.printf("Date/Time: %s\n", MailClient.Time.getDateTimeString(result.timestamp, "%B %d, %Y %H:%M:%S").c_str()); + MailClient.printf("Recipient: %s\n", result.recipients.c_str()); + MailClient.printf("Subject: %s\n", result.subject.c_str()); + } + Serial.println("----------------\n"); + + // You need to clear sending result as the memory usage will grow up. + smtp.sendingResult.clear(); + } +} \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_Flash_Message_with_Inline_Image/Send_Flash_Message_with_Inline_Image.ino b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_Flash_Message_with_Inline_Image/Send_Flash_Message_with_Inline_Image.ino new file mode 100644 index 000000000..dacf96434 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_Flash_Message_with_Inline_Image/Send_Flash_Message_with_Inline_Image.ino @@ -0,0 +1,370 @@ + +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt +*/ + +// This example shows how to send Email with inline images stored in flash memory. + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +// The file systems for flash and sd memory can be changed in ESP_Mail_FS.h. + +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +#include + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +/** For Gmail, the app password will be used for log in + * Check out https://github.com/mobizt/ESP-Mail-Client#gmail-smtp-and-imap-required-app-passwords-to-sign-in + * + * For Yahoo mail, log in to your yahoo mail in web browser and generate app password by go to + * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc + * + * To use Gmai and Yahoo's App Password to sign in, define the AUTHOR_PASSWORD with your App Password + * and AUTHOR_EMAIL with your account email. + */ + +/** The smtp host name e.g. smtp.gmail.com for GMail or smtp.office365.com for Outlook or smtp.mail.yahoo.com */ +#define SMTP_HOST "" + +/** The smtp port e.g. + * 25 or esp_mail_smtp_port_25 + * 465 or esp_mail_smtp_port_465 + * 587 or esp_mail_smtp_port_587 + */ +#define SMTP_PORT esp_mail_smtp_port_587 + +/* The log in credentials */ +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" + +/* Recipient email address */ +#define RECIPIENT_EMAIL "" + +/* Declare the global used SMTPSession object for SMTP transport */ +SMTPSession smtp; + +/* Callback function to get the Email sending status */ +void smtpCallback(SMTP_Status status); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) +WiFiMulti multi; +#endif + +void setup() +{ + + Serial.begin(115200); + +#if defined(ARDUINO_ARCH_SAMD) + while (!Serial) + ; +#endif + + Serial.println(); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + multi.addAP(WIFI_SSID, WIFI_PASSWORD); + multi.run(); +#else + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Connecting to Wi-Fi"); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + unsigned long ms = millis(); +#endif + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + if (millis() - ms > 10000) + break; +#endif + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + Serial.println("Mounting flash..."); + + const char *html = "This message contains inline image.

\"orange"; + const char *base64Img = "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAkGBggGBQkIBwgKCQkKDRYODQwMDRoTFBAWHxwhIB8cHh4jJzIqIyUvJR4eKzssLzM1ODg4ISo9QTw2QTI3ODX/2wBDAQkKCg0LDRkODhk1JB4kNTU1NTU1NTU1NTU1NTU1NTU1NTU1NTU1NTU1NTU1NTU1NTU1NTU1NTU1NTU1NTU1NTX/wgARCAFoAoADAREAAhEBAxEB/8QAGwABAQEBAQEBAQAAAAAAAAAAAAECAwUGBAf/xAAbAQEBAQADAQEAAAAAAAAAAAAAAQIDBAUGB//aAAwDAQACEAMQAAAAn5/+igVVBAAAFIWJQsAAAgAAAAAAAoIAAAAgKFBAAUIWAAAAAAASUIoKFCwAAAAAAAACUQAAAAACAAoICgAgKFCAAAAFECUAAAACCWgoAsAAAAAAAACoBCgAQACACghSAAUBCkCgAAAAAAAoIAACDN0BSFECkKAAAAAACpCgEKBABAKQAAAAUIAAoEAABSFACiUAAEgAloALQgARQAAAAEAAABBRAAAoBCkAFCAAABYCVSFAChAUAAIAEAKACgCgskKAAAAEAAABBRAAAoIAABUAABAFEoAAUKIAAAAARAFtEAoAAoACABFCQFAACAAAUAAQFAQAAAgAM7fIe10tRuXcu866YvXG95v6uLf7+rsKEABSAAIUUgUCiAAAQAUCQAAUIAABQACAFIAAAAQCoTkz/Gvtvi4zpdTW869Tqet+7rd39fDz+10ez7HR0AAAIUgAQtCgAAAAWJZRABBSFhRECgAAFABCkAAAAIACUG5/F/t/h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R6S5F5ey59IRH2oI9TKLkXl5c/SwR1n7skl6MwuZL9ZBH0pJ13IvMxl7JI9ZP2pM1GYy6ol+zn7EaF9+fYr3Ek/nknUvRr1n//2Q=="; + +#if defined(ESP32) || defined(ESP8266) +#if defined(ESP32) + if (ESP_MAIL_DEFAULT_FLASH_FS.begin(true)) +#elif defined(ESP8266) + if (ESP_MAIL_DEFAULT_FLASH_FS.begin()) +#endif + { + + // ESP_MAIL_DEFAULT_FLASH_FS.format(); + + if (ESP_MAIL_DEFAULT_FLASH_FS.exists("/base64Img.jpg")) + ESP_MAIL_DEFAULT_FLASH_FS.remove("/base64Img.jpg"); + + Serial.println("Preparing flash file attachments..."); + +#if defined(ESP32) + File file = ESP_MAIL_DEFAULT_FLASH_FS.open("/base64Img.jpg", FILE_WRITE); +#elif defined(ESP8266) + File file = ESP_MAIL_DEFAULT_FLASH_FS.open("/base64Img.jpg", "w"); +#endif + file.print(base64Img); + file.close(); + +#if defined(ESP32) + file = ESP_MAIL_DEFAULT_FLASH_FS.open("/msg.html", FILE_WRITE); +#elif defined(ESP8266) + file = ESP_MAIL_DEFAULT_FLASH_FS.open("/msg.html", "w"); +#endif + file.print(html); + file.close(); + } + else + { + Serial.println("Flash filesystem monting Failed"); + } +#endif + + /* Set the network reconnection option */ + MailClient.networkReconnect(true); + + // The WiFi credentials are required for Pico W + // due to it does not have reconnect feature. +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + MailClient.clearAP(); + MailClient.addAP(WIFI_SSID, WIFI_PASSWORD); +#endif + + /** Enable the debug via Serial port + * 0 for no debugging + * 1 for basic level debugging + * + * Debug port can be changed via ESP_MAIL_DEFAULT_DEBUG_PORT in ESP_Mail_FS.h + */ + smtp.debug(1); + + /* Set the callback function to get the sending results */ + smtp.callback(smtpCallback); + + /* Declare the Session_Config for user defined session credentials */ + Session_Config config; + + /* Set the session config */ + config.server.host_name = SMTP_HOST; + config.server.port = SMTP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + + /** Assign your host name or you public IPv4 or IPv6 only + * as this is the part of EHLO/HELO command to identify the client system + * to prevent connection rejection. + * If host name or public IP is not available, ignore this or + * use loopback address "127.0.0.1". + * + * Assign any text to this option may cause the connection rejection. + */ + config.login.user_domain = F("127.0.0.1"); + + /* + Set the NTP config time + For times east of the Prime Meridian use 0-12 + For times west of the Prime Meridian add 12 to the offset. + Ex. American/Denver GMT would be -6. 6 + 12 = 18 + See https://en.wikipedia.org/wiki/Time_zone for a list of the GMT/UTC timezone offsets + */ + config.time.ntp_server = F("pool.ntp.org,time.nist.gov"); + config.time.gmt_offset = 3; + config.time.day_light_offset = 0; + + /* Declare the message class */ + SMTP_Message message; + + /* Enable the chunked data transfer with pipelining for large message if server supported */ + message.enable.chunking = true; + + /* Set the message headers */ + message.sender.name = F("ESP Mail"); + message.sender.email = AUTHOR_EMAIL; + + message.subject = F("Test sending base64 inline image stored in flash memory"); + message.addRecipient(F("user1"), RECIPIENT_EMAIL); + + /* Two alternative content versions are sending in this example e.g. plain text and html */ + + /* Assign blob data (in flash or ram) as HTML message */ + message.html.blob.data = (const uint8_t *)html; + message.html.blob.size = strlen(html); + + // Or get the content from file + // message.html.file.name = "/msg.html"; + // message.html.file.type = esp_mail_file_storage_type_flash; + + /** The content transfer encoding e.g. + * enc_7bit or "7bit" (not encoded) + * enc_qp or "quoted-printable" (encoded) <- not supported for message from blob and file + * enc_base64 or "base64" (encoded) + * enc_binary or "binary" (not encoded) + * enc_8bit or "8bit" (not encoded) + * The default value is "7bit" + */ + message.html.transfer_encoding = Content_Transfer_Encoding::enc_7bit; + + /** The HTML text message character set e.g. + * us-ascii + * utf-8 + * utf-7 + * The default value is utf-8 + */ + message.html.charSet = F("utf-8"); + + message.text.content = F("This message contains inline image.\r\nThe inline image was not shown in the plain text message."); + message.text.charSet = F("utf-8"); + message.text.transfer_encoding = Content_Transfer_Encoding::enc_base64; + + /* Set the custom message header */ + message.addHeader(F("Message-ID: ")); + + /* The attachment data item */ + SMTP_Attachment att; + /** Set the inline image info e.g. + * file name, MIME type, file path, file storage type, + * transfer encoding and content encoding + */ + att.descr.filename = F("base64Img.jpg"); + att.descr.mime = F("image/jpg"); + +#if defined(ESP32) || defined(ESP8266) + att.file.path = F("/base64Img.jpg"); + /** The file storage type e.g. + * esp_mail_file_storage_type_none, + * esp_mail_file_storage_type_flash, and + * esp_mail_file_storage_type_sd + */ + att.file.storage_type = esp_mail_file_storage_type_flash; +#elif defined(ARDUINO_ARCH_SAMD) + att.blob.data = (const uint8_t *)base64Img; + att.blob.size = sizeof(base64Img); +#endif + + att.descr.content_id = F("image-001"); // The content id (cid) of orange image in the src tag + + /* Need to be base64 transfer encoding for inline image */ + att.descr.transfer_encoding = Content_Transfer_Encoding::enc_base64; + + /** The attach image file is already base64 encoded file. + * Then set the content encoding to match the transfer encoding + * which no encoding was taken place prior to sending. + */ + att.descr.content_encoding = Content_Transfer_Encoding::enc_base64; + + /* Add inline image to the message */ + message.addInlineImage(att); + + /* Connect to the server */ + if (!smtp.connect(&config)) + { + MailClient.printf("Connection error, Status Code: %d, Error Code: %d, Reason: %s", smtp.statusCode(), smtp.errorCode(), smtp.errorReason().c_str()); + return; + } + + if (smtp.isAuthenticated()) + Serial.println("\nSuccessfully logged in."); + else + Serial.println("\nConnected with no Auth."); + + /* Start sending the Email and close the session */ + if (!MailClient.sendMail(&smtp, &message, true)) + MailClient.printf("Error, Status Code: %d, Error Code: %d, Reason: %s", smtp.statusCode(), smtp.errorCode(), smtp.errorReason().c_str()); + + // to clear sending result log + // smtp.sendingResult.clear(); + + MailClient.printf("Free Heap: %d\n", MailClient.getFreeHeap()); +} + +void loop() +{ +} + +/* Callback function to get the Email sending status */ +void smtpCallback(SMTP_Status status) +{ + /* Print the current status */ + Serial.println(status.info()); + + /* Print the sending result */ + if (status.success()) + { + // MailClient.printf used in the examples is for format printing via debug Serial port + // that works for all supported Arduino platform SDKs e.g. SAMD, ESP32 and ESP8266. + // In ESP8266 and ESP32, you can use Serial.printf directly. + + Serial.println("----------------"); + MailClient.printf("Message sent success: %d\n", status.completedCount()); + MailClient.printf("Message sent failed: %d\n", status.failedCount()); + Serial.println("----------------\n"); + + for (size_t i = 0; i < smtp.sendingResult.size(); i++) + { + /* Get the result item */ + SMTP_Result result = smtp.sendingResult.getItem(i); + + // In case, ESP32, ESP8266 and SAMD device, the timestamp get from result.timestamp should be valid if + // your device time was synched with NTP server. + // Other devices may show invalid timestamp as the device time was not set i.e. it will show Jan 1, 1970. + // You can call smtp.setSystemTime(xxx) to set device time manually. Where xxx is timestamp (seconds since Jan 1, 1970) + + MailClient.printf("Message No: %d\n", i + 1); + MailClient.printf("Status: %s\n", result.completed ? "success" : "failed"); + MailClient.printf("Date/Time: %s\n", MailClient.Time.getDateTimeString(result.timestamp, "%B %d, %Y %H:%M:%S").c_str()); + MailClient.printf("Recipient: %s\n", result.recipients.c_str()); + MailClient.printf("Subject: %s\n", result.subject.c_str()); + } + Serial.println("----------------\n"); + + // You need to clear sending result as the memory usage will grow up. + smtp.sendingResult.clear(); + } +} \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_HTML/Send_HTML.ino b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_HTML/Send_HTML.ino new file mode 100644 index 000000000..1a4af3860 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_HTML/Send_HTML.ino @@ -0,0 +1,301 @@ + + +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt +*/ + +// This example shows how to send html message. + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +#include + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +/** For Gmail, the app password will be used for log in + * Check out https://github.com/mobizt/ESP-Mail-Client#gmail-smtp-and-imap-required-app-passwords-to-sign-in + * + * For Yahoo mail, log in to your yahoo mail in web browser and generate app password by go to + * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc + * + * To use Gmai and Yahoo's App Password to sign in, define the AUTHOR_PASSWORD with your App Password + * and AUTHOR_EMAIL with your account email. + */ + +/** The smtp host name e.g. smtp.gmail.com for GMail or smtp.office365.com for Outlook or smtp.mail.yahoo.com */ +#define SMTP_HOST "" + +/** The smtp port e.g. + * 25 or esp_mail_smtp_port_25 + * 465 or esp_mail_smtp_port_465 + * 587 or esp_mail_smtp_port_587 + */ +#define SMTP_PORT esp_mail_smtp_port_587 + +/* The log in credentials */ +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" + +/* Recipient email address */ +#define RECIPIENT_EMAIL "" + +/* Declare the global used SMTPSession object for SMTP transport */ +SMTPSession smtp; + +/* Callback function to get the Email sending status */ +void smtpCallback(SMTP_Status status); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) +WiFiMulti multi; +#endif + +void setup() +{ + + Serial.begin(115200); + +#if defined(ARDUINO_ARCH_SAMD) + while (!Serial) + ; +#endif + + Serial.println(); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + multi.addAP(WIFI_SSID, WIFI_PASSWORD); + multi.run(); +#else + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Connecting to Wi-Fi"); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + unsigned long ms = millis(); +#endif + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + if (millis() - ms > 10000) + break; +#endif + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + /* Set the network reconnection option */ + MailClient.networkReconnect(true); + + // The WiFi credentials are required for Pico W + // due to it does not have reconnect feature. +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + MailClient.clearAP(); + MailClient.addAP(WIFI_SSID, WIFI_PASSWORD); +#endif + + /** Enable the debug via Serial port + * 0 for no debugging + * 1 for basic level debugging + * + * Debug port can be changed via ESP_MAIL_DEFAULT_DEBUG_PORT in ESP_Mail_FS.h + */ + smtp.debug(1); + + /* Set the callback function to get the sending results */ + smtp.callback(smtpCallback); + + /* Declare the Session_Config for user defined session credentials */ + Session_Config config; + + /* Set the session config */ + config.server.host_name = SMTP_HOST; + config.server.port = SMTP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + + /** Assign your host name or you public IPv4 or IPv6 only + * as this is the part of EHLO/HELO command to identify the client system + * to prevent connection rejection. + * If host name or public IP is not available, ignore this or + * use loopback address "127.0.0.1". + * + * Assign any text to this option may cause the connection rejection. + */ + config.login.user_domain = F("127.0.0.1"); + + /* + Set the NTP config time + For times east of the Prime Meridian use 0-12 + For times west of the Prime Meridian add 12 to the offset. + Ex. American/Denver GMT would be -6. 6 + 12 = 18 + See https://en.wikipedia.org/wiki/Time_zone for a list of the GMT/UTC timezone offsets + */ + config.time.ntp_server = F("pool.ntp.org,time.nist.gov"); + config.time.gmt_offset = 3; + config.time.day_light_offset = 0; + + /* The full message sending logs can now save to file */ + /* Since v3.0.4, the sent logs stored in smtp.sendingResult will store only the latest message logs */ + // config.sentLogs.filename = "/path/to/log/file"; + // config.sentLogs.storage_type = esp_mail_file_storage_type_flash; + + /* Declare the message class */ + SMTP_Message message; + + /* Set the message headers */ + message.sender.name = F("ESP Mail"); + message.sender.email = AUTHOR_EMAIL; + message.subject = F("Test sending html Email"); + message.addRecipient(F("Admin"), RECIPIENT_EMAIL); + + String htmlMsg = "

This is the html text message.

The message was sent via ESP device.

"; + message.html.content = htmlMsg; + + /** The html text message character set e.g. + * us-ascii + * utf-8 + * utf-7 + * The default value is utf-8 + */ + message.html.charSet = F("us-ascii"); + + /** The content transfer encoding e.g. + * enc_7bit or "7bit" (not encoded) + * enc_qp or "quoted-printable" (encoded) + * enc_base64 or "base64" (encoded) + * enc_binary or "binary" (not encoded) + * enc_8bit or "8bit" (not encoded) + * The default value is "7bit" + */ + message.html.transfer_encoding = Content_Transfer_Encoding::enc_7bit; + + /** The message priority + * esp_mail_smtp_priority_high or 1 + * esp_mail_smtp_priority_normal or 3 + * esp_mail_smtp_priority_low or 5 + * The default value is esp_mail_smtp_priority_low + */ + message.priority = esp_mail_smtp_priority::esp_mail_smtp_priority_low; + + /** The Delivery Status Notifications e.g. + * esp_mail_smtp_notify_never + * esp_mail_smtp_notify_success + * esp_mail_smtp_notify_failure + * esp_mail_smtp_notify_delay + * The default value is esp_mail_smtp_notify_never + */ + // message.response.notify = esp_mail_smtp_notify_success | esp_mail_smtp_notify_failure | esp_mail_smtp_notify_delay; + + /* Set the custom message header */ + message.addHeader(F("Message-ID: ")); + + /* Set the TCP response read timeout in seconds */ + // smtp.setTCPTimeout(10); + + /* Connect to the server */ + if (!smtp.connect(&config)) + { + MailClient.printf("Connection error, Status Code: %d, Error Code: %d, Reason: %s", smtp.statusCode(), smtp.errorCode(), smtp.errorReason().c_str()); + return; + } + + if (smtp.isAuthenticated()) + Serial.println("\nSuccessfully logged in."); + else + Serial.println("\nConnected with no Auth."); + + /* Start sending Email and close the session */ + if (!MailClient.sendMail(&smtp, &message)) + MailClient.printf("Error, Status Code: %d, Error Code: %d, Reason: %s", smtp.statusCode(), smtp.errorCode(), smtp.errorReason().c_str()); + + // to clear sending result log + // smtp.sendingResult.clear(); + + MailClient.printf("Free Heap: %d\n", MailClient.getFreeHeap()); +} + +void loop() +{ +} + +/* Callback function to get the Email sending status */ +void smtpCallback(SMTP_Status status) +{ + /* Print the current status */ + Serial.println(status.info()); + + /* Print the sending result */ + if (status.success()) + { + // MailClient.printf used in the examples is for format printing via debug Serial port + // that works for all supported Arduino platform SDKs e.g. SAMD, ESP32 and ESP8266. + // In ESP8266 and ESP32, you can use Serial.printf directly. + + Serial.println("----------------"); + MailClient.printf("Message sent success: %d\n", status.completedCount()); + MailClient.printf("Message sent failed: %d\n", status.failedCount()); + Serial.println("----------------\n"); + + for (size_t i = 0; i < smtp.sendingResult.size(); i++) + { + /* Get the result item */ + SMTP_Result result = smtp.sendingResult.getItem(i); + + // In case, ESP32, ESP8266 and SAMD device, the timestamp get from result.timestamp should be valid if + // your device time was synched with NTP server. + // Other devices may show invalid timestamp as the device time was not set i.e. it will show Jan 1, 1970. + // You can call smtp.setSystemTime(xxx) to set device time manually. Where xxx is timestamp (seconds since Jan 1, 1970) + + MailClient.printf("Message No: %d\n", i + 1); + MailClient.printf("Status: %s\n", result.completed ? "success" : "failed"); + MailClient.printf("Date/Time: %s\n", MailClient.Time.getDateTimeString(result.timestamp, "%B %d, %Y %H:%M:%S").c_str()); + MailClient.printf("Recipient: %s\n", result.recipients.c_str()); + MailClient.printf("Subject: %s\n", result.subject.c_str()); + } + Serial.println("----------------\n"); + + // You need to clear sending result as the memory usage will grow up. + smtp.sendingResult.clear(); + } +} \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_Parallel_Attachment/Send_Parallel_Attachment.ino b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_Parallel_Attachment/Send_Parallel_Attachment.ino new file mode 100644 index 000000000..bb7221272 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_Parallel_Attachment/Send_Parallel_Attachment.ino @@ -0,0 +1,334 @@ + +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt + * +*/ + + +/** + * This example shows how to send Email with media e.g. audio and images as parallen attachments, + * and play or display them simultaneously on the Email client (depends on the Mail client supports). + */ + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +#include + +/* This is for attachment data */ +#include "data.h" + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +/** For Gmail, the app password will be used for log in + * Check out https://github.com/mobizt/ESP-Mail-Client#gmail-smtp-and-imap-required-app-passwords-to-sign-in + * + * For Yahoo mail, log in to your yahoo mail in web browser and generate app password by go to + * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc + * + * To use Gmai and Yahoo's App Password to sign in, define the AUTHOR_PASSWORD with your App Password + * and AUTHOR_EMAIL with your account email. + */ + +/** The smtp host name e.g. smtp.gmail.com for GMail or smtp.office365.com for Outlook or smtp.mail.yahoo.com */ +#define SMTP_HOST "" + +/** The smtp port e.g. + * 25 or esp_mail_smtp_port_25 + * 465 or esp_mail_smtp_port_465 + * 587 or esp_mail_smtp_port_587 + */ +#define SMTP_PORT esp_mail_smtp_port_587 + +/* The log in credentials */ +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" + +/* Recipient email address */ +#define RECIPIENT_EMAIL "" + +/* Declare the global used SMTPSession object for SMTP transport */ +SMTPSession smtp; + +/* Callback function to get the Email sending status */ +void smtpCallback(SMTP_Status status); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) +WiFiMulti multi; +#endif + +void setup() +{ + + Serial.begin(115200); + +#if defined(ARDUINO_ARCH_SAMD) + while (!Serial) + ; +#endif + + Serial.println(); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + multi.addAP(WIFI_SSID, WIFI_PASSWORD); + multi.run(); +#else + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Connecting to Wi-Fi"); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + unsigned long ms = millis(); +#endif + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + if (millis() - ms > 10000) + break; +#endif + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + /* Set the network reconnection option */ + MailClient.networkReconnect(true); + + // The WiFi credentials are required for Pico W + // due to it does not have reconnect feature. +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + MailClient.clearAP(); + MailClient.addAP(WIFI_SSID, WIFI_PASSWORD); +#endif + + /** Enable the debug via Serial port + * 0 for no debugging + * 1 for basic level debugging + * + * Debug port can be changed via ESP_MAIL_DEFAULT_DEBUG_PORT in ESP_Mail_FS.h + */ + smtp.debug(1); + + /* Set the callback function to get the sending results */ + smtp.callback(smtpCallback); + + /* Declare the Session_Config for user defined session credentials */ + Session_Config config; + + /* Set the session config */ + config.server.host_name = SMTP_HOST; + config.server.port = SMTP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + + /** Assign your host name or you public IPv4 or IPv6 only + * as this is the part of EHLO/HELO command to identify the client system + * to prevent connection rejection. + * If host name or public IP is not available, ignore this or + * use loopback address "127.0.0.1". + * + * Assign any text to this option may cause the connection rejection. + */ + config.login.user_domain = F("127.0.0.1"); + + /* + Set the NTP config time + For times east of the Prime Meridian use 0-12 + For times west of the Prime Meridian add 12 to the offset. + Ex. American/Denver GMT would be -6. 6 + 12 = 18 + See https://en.wikipedia.org/wiki/Time_zone for a list of the GMT/UTC timezone offsets + */ + config.time.ntp_server = F("pool.ntp.org,time.nist.gov"); + config.time.gmt_offset = 3; + config.time.day_light_offset = 0; + + /* Declare the message class */ + SMTP_Message message; + + /* Enable the chunked data transfer with pipelining for large message if server supported */ + message.enable.chunking = true; + + /* Set the message headers */ + message.sender.name = F("ESP Mail"); + message.sender.email = AUTHOR_EMAIL; + + message.subject = F("Test sending Email with parallel attachments"); + message.addRecipient(F("user1"), RECIPIENT_EMAIL); + + message.html.content = F("This message contains image and audio file which will play on the Mail client in parallel or simultaneously (depends on the client supports)."); + + /** The HTML text message character set e.g. + * us-ascii + * utf-8 + * utf-7 + * The default value is utf-8 + */ + message.html.charSet = F("utf-8"); + + /** The content transfer encoding e.g. + * enc_7bit or "7bit" (not encoded) + * enc_qp or "quoted-printable" (encoded) + * enc_base64 or "base64" (encoded) + * enc_binary or "binary" (not encoded) + * enc_8bit or "8bit" (not encoded) + * The default value is "7bit" + */ + message.html.transfer_encoding = Content_Transfer_Encoding::enc_qp; + + message.text.content = F("This message contains image and audio file which will play on the Mail client in parallel or simultaneously (depends on the client supports)."); + message.text.charSet = F("us-ascii"); + message.text.transfer_encoding = Content_Transfer_Encoding::enc_base64; + + /** The message priority + * esp_mail_smtp_priority_high or 1 + * esp_mail_smtp_priority_normal or 3 + * esp_mail_smtp_priority_low or 5 + * The default value is esp_mail_smtp_priority_low + */ + message.priority = esp_mail_smtp_priority::esp_mail_smtp_priority_normal; + + /** The Delivery Status Notifications e.g. + * esp_mail_smtp_notify_never + * esp_mail_smtp_notify_success + * esp_mail_smtp_notify_failure + * esp_mail_smtp_notify_delay + * The default value is esp_mail_smtp_notify_never + */ + // message.response.notify = esp_mail_smtp_notify_success | esp_mail_smtp_notify_failure | esp_mail_smtp_notify_delay; + + /* Set the custom message header */ + message.addHeader(F("Message-ID: ")); + + /* The attachment data item */ + SMTP_Attachment att; + + /** Set the attachment info e.g. + * file name, MIME type, file path, file storage type, + * transfer encoding and content encoding + */ + att.descr.filename = F("haun.png"); + att.descr.mime = F("image/png"); + att.blob.data = shaun_png; + att.blob.size = sizeof(shaun_png); + att.descr.transfer_encoding = Content_Transfer_Encoding::enc_base64; + message.addParallelAttachment(att); + + /** Set the attachment info e.g. + * file name, MIME type, file path, file storage type, + * transfer encoding and content encoding + */ + message.resetAttachItem(att); // Clear the attach item data to reuse + att.descr.filename = F("mu_law.wav"); + att.descr.mime = F("audio/basic"); + att.blob.data = mu_law_wave; + att.blob.size = sizeof(mu_law_wave); + att.descr.transfer_encoding = Content_Transfer_Encoding::enc_base64; + + message.addParallelAttachment(att); + + /* Connect to the server */ + if (!smtp.connect(&config)) + { + MailClient.printf("Connection error, Status Code: %d, Error Code: %d, Reason: %s", smtp.statusCode(), smtp.errorCode(), smtp.errorReason().c_str()); + return; + } + + if (smtp.isAuthenticated()) + Serial.println("\nSuccessfully logged in."); + else + Serial.println("\nConnected with no Auth."); + + /* Start sending the Email and close the session */ + if (!MailClient.sendMail(&smtp, &message, true)) + MailClient.printf("Error, Status Code: %d, Error Code: %d, Reason: %s", smtp.statusCode(), smtp.errorCode(), smtp.errorReason().c_str()); + + // to clear sending result log + // smtp.sendingResult.clear(); + + MailClient.printf("Free Heap: %d\n", MailClient.getFreeHeap()); +} + +void loop() +{ +} + +/* Callback function to get the Email sending status */ +void smtpCallback(SMTP_Status status) +{ + /* Print the current status */ + Serial.println(status.info()); + + /* Print the sending result */ + if (status.success()) + { + // MailClient.printf used in the examples is for format printing via debug Serial port + // that works for all supported Arduino platform SDKs e.g. SAMD, ESP32 and ESP8266. + // In ESP8266 and ESP32, you can use Serial.printf directly. + + Serial.println("----------------"); + MailClient.printf("Message sent success: %d\n", status.completedCount()); + MailClient.printf("Message sent failed: %d\n", status.failedCount()); + Serial.println("----------------\n"); + + for (size_t i = 0; i < smtp.sendingResult.size(); i++) + { + /* Get the result item */ + SMTP_Result result = smtp.sendingResult.getItem(i); + + // In case, ESP32, ESP8266 and SAMD device, the timestamp get from result.timestamp should be valid if + // your device time was synched with NTP server. + // Other devices may show invalid timestamp as the device time was not set i.e. it will show Jan 1, 1970. + // You can call smtp.setSystemTime(xxx) to set device time manually. Where xxx is timestamp (seconds since Jan 1, 1970) + + MailClient.printf("Message No: %d\n", i + 1); + MailClient.printf("Status: %s\n", result.completed ? "success" : "failed"); + MailClient.printf("Date/Time: %s\n", MailClient.Time.getDateTimeString(result.timestamp, "%B %d, %Y %H:%M:%S").c_str()); + MailClient.printf("Recipient: %s\n", result.recipients.c_str()); + MailClient.printf("Subject: %s\n", result.subject.c_str()); + } + Serial.println("----------------\n"); + + // You need to clear sending result as the memory usage will grow up. + smtp.sendingResult.clear(); + } +} diff --git a/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_Parallel_Attachment/data.h b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_Parallel_Attachment/data.h new file mode 100644 index 000000000..c7a88aeab --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_Parallel_Attachment/data.h @@ -0,0 +1,1957 @@ +#include + +static const uint8_t mu_law_wave[] PROGMEM = { +0x52, 0x49, 0x46, 0x46, 0x84, 0x5D, 0x00, 0x00, 0x57, 0x41, 0x56, 0x45, 0x66, 0x6D, 0x74, 0x20, +0x12, 0x00, 0x00, 0x00, 0x07, 0x00, 0x01, 0x00, 0x40, 0x1F, 0x00, 0x00, 0x40, 0x1F, 0x00, 0x00, +0x01, 0x00, 0x08, 0x00, 0x00, 0x00, 0x66, 0x61, 0x63, 0x74, 0x04, 0x00, 0x00, 0x00, 0x00, 0x5D, +0x00, 0x00, 0x64, 0x61, 0x74, 0x61, 0x00, 0x5D, 0x00, 0x00, 0xFB, 0xFD, 0xFF, 0xFE, 0xFF, 0x7F, +0x7F, 0x7E, 0x7E, 0x7D, 0x7C, 0x7D, 0x7D, 0x7C, 0x7D, 0x7D, 0x7E, 0x7E, 0x7E, 0x7E, 0x7C, 0x7D, +0x7C, 0x7C, 0x7D, 0x7F, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x7E, 0xFF, 0x7F, +0x7D, 0x7C, 0x7B, 0x7B, 0x7B, 0x7A, 0x79, 0x79, 0x7A, 0x7B,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0x46, 0x69, +0x6C, 0x65, 0x20, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x20, 0x62, 0x79, 0x20, 0x47, 0x6F, +0x6C, 0x64, 0x57, 0x61, 0x76, 0x65, 0x2E, 0x20, 0x20, 0x47, 0x6F, 0x6C, 0x64, 0x57, 0x61, 0x76, +0x65, 0x20, 0x63, 0x6F, 0x70, 0x79, 0x72, 0x69, 0x67, 0x68, 0x74, 0x20, 0x28, 0x43, 0x29, 0x20, +0x43, 0x68, 0x72, 0x69, 0x73, 0x20, 0x43, 0x72, 0x61, 0x69, 0x67, 0x00 + +}; + +static const uint8_t shaun_png[] PROGMEM = { + 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00, 0x00, 0x00, 0x0D, 0x49, 0x48, 0x44, 0x52, + 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x57, 0x08, 0x06, 0x00, 0x00, 0x00, 0xF2, 0x0C, 0xE0, + 0x57, 0x00, 0x00, 0x00, 0x06, 0x62, 0x4B, 0x47, 0x44, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0xA0, + 0xBD, 0xA7, 0x93, 0x00, 0x00, 0x00, 0x09, 0x70, 0x48, 0x59, 0x73, 0x00, 0x00, 0x42, 0x8A, 0x00, + 0x00, 0x42, 0x8A, 0x01, 0x34, 0xA8, 0x6C, 0x25, 0x00, 0x00, 0x00, 0x09, 0x76, 0x70, 0x41, 0x67, + 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x57, 0x00, 0x73, 0x4D, 0x3B, 0xD6, 0x00, 0x00, 0x1B, + 0x47, 0x49, 0x44, 0x41, 0x54, 0x78, 0xDA, 0xED, 0x9D, 0x79, 0x74, 0x14, 0x55, 0xBE, 0xC7, 0x3F, + 0x55, 0xDD, 0x49, 0x67, 0x5F, 0x3A, 0x7B, 0x42, 0x82, 0x61, 0x49, 0x02, 0x81, 0xB0, 0x29, 0x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 0x7E, 0x40, 0x32, 0x3D, 0xB4, 0xB3, 0x1F, 0xB6, 0x29, 0x02, 0x5C, 0xAF, 0x08, 0x45, 0xD6, 0x06, + 0xBE, 0x0B, 0xF8, 0x15, 0x72, 0xEF, 0xE2, 0x6C, 0x32, 0x91, 0x1D, 0x16, 0xA4, 0x23, 0xE9, 0x38, + 0x32, 0xA1, 0x68, 0x13, 0x72, 0x66, 0x54, 0x75, 0xF6, 0xC3, 0x35, 0x85, 0xEB, 0x99, 0x21, 0x76, + 0xE8, 0x90, 0x16, 0xE3, 0x3E, 0x48, 0xAB, 0x71, 0x5F, 0xA0, 0x07, 0x92, 0x61, 0x01, 0x34, 0xE4, + 0xF5, 0xD5, 0x22, 0x09, 0x5D, 0x8C, 0xF4, 0xEA, 0x1D, 0x45, 0xA6, 0x1C, 0x67, 0x20, 0x23, 0x44, + 0x2A, 0x5B, 0x76, 0xDB, 0xCE, 0xC1, 0xFF, 0x01, 0xCE, 0x34, 0xF5, 0xEC, 0x2D, 0xA9, 0x9C, 0xA8, + 0x00, 0x00, 0x00, 0x25, 0x74, 0x45, 0x58, 0x74, 0x64, 0x61, 0x74, 0x65, 0x3A, 0x63, 0x72, 0x65, + 0x61, 0x74, 0x65, 0x00, 0x32, 0x30, 0x31, 0x32, 0x2D, 0x30, 0x31, 0x2D, 0x33, 0x31, 0x54, 0x31, + 0x33, 0x3A, 0x34, 0x31, 0x3A, 0x31, 0x38, 0x2D, 0x30, 0x38, 0x3A, 0x30, 0x30, 0xED, 0x4F, 0xCC, + 0x0D, 0x00, 0x00, 0x00, 0x25, 0x74, 0x45, 0x58, 0x74, 0x64, 0x61, 0x74, 0x65, 0x3A, 0x6D, 0x6F, + 0x64, 0x69, 0x66, 0x79, 0x00, 0x32, 0x30, 0x31, 0x32, 0x2D, 0x30, 0x31, 0x2D, 0x33, 0x31, 0x54, + 0x31, 0x33, 0x3A, 0x34, 0x31, 0x3A, 0x31, 0x38, 0x2D, 0x30, 0x38, 0x3A, 0x30, 0x30, 0x9C, 0x12, + 0x74, 0xB1, 0x00, 0x00, 0x00, 0x19, 0x74, 0x45, 0x58, 0x74, 0x53, 0x6F, 0x66, 0x74, 0x77, 0x61, + 0x72, 0x65, 0x00, 0x77, 0x77, 0x77, 0x2E, 0x69, 0x6E, 0x6B, 0x73, 0x63, 0x61, 0x70, 0x65, 0x2E, + 0x6F, 0x72, 0x67, 0x9B, 0xEE, 0x3C, 0x1A, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4E, 0x44, 0xAE, + 0x42, 0x60, 0x82}; \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_RFC822_Attachment/Send_RFC822_Attachment.ino b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_RFC822_Attachment/Send_RFC822_Attachment.ino new file mode 100644 index 000000000..49a98ed09 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_RFC822_Attachment/Send_RFC822_Attachment.ino @@ -0,0 +1,360 @@ + +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt +*/ + +// This example shows how to send Email message with attachment + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +#include + +/* This is for attachment data */ +#include "image.h" + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +/** For Gmail, the app password will be used for log in + * Check out https://github.com/mobizt/ESP-Mail-Client#gmail-smtp-and-imap-required-app-passwords-to-sign-in + * + * For Yahoo mail, log in to your yahoo mail in web browser and generate app password by go to + * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc + * + * To use Gmai and Yahoo's App Password to sign in, define the AUTHOR_PASSWORD with your App Password + * and AUTHOR_EMAIL with your account email. + */ + +/** The smtp host name e.g. smtp.gmail.com for GMail or smtp.office365.com for Outlook or smtp.mail.yahoo.com */ +#define SMTP_HOST "" + +/** The smtp port e.g. + * 25 or esp_mail_smtp_port_25 + * 465 or esp_mail_smtp_port_465 + * 587 or esp_mail_smtp_port_587 + */ +#define SMTP_PORT esp_mail_smtp_port_587 + +/* The log in credentials */ +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" + +/* Recipient email address */ +#define RECIPIENT_EMAIL "" + +/* Declare the global used SMTPSession object for SMTP transport */ +SMTPSession smtp; + +/* Callback function to get the Email sending status */ +void smtpCallback(SMTP_Status status); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) +WiFiMulti multi; +#endif + +void setup() +{ + + Serial.begin(115200); + +#if defined(ARDUINO_ARCH_SAMD) + while (!Serial) + ; +#endif + + Serial.println(); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + multi.addAP(WIFI_SSID, WIFI_PASSWORD); + multi.run(); +#else + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Connecting to Wi-Fi"); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + unsigned long ms = millis(); +#endif + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + if (millis() - ms > 10000) + break; +#endif + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + /* Set the network reconnection option */ + MailClient.networkReconnect(true); + + // The WiFi credentials are required for Pico W + // due to it does not have reconnect feature. +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + MailClient.clearAP(); + MailClient.addAP(WIFI_SSID, WIFI_PASSWORD); +#endif + + /** Enable the debug via Serial port + * 0 for no debugging + * 1 for basic level debugging + * + * Debug port can be changed via ESP_MAIL_DEFAULT_DEBUG_PORT in ESP_Mail_FS.h + */ + smtp.debug(1); + + /* Set the callback function to get the sending results */ + smtp.callback(smtpCallback); + + /* Declare the Session_Config for user defined session credentials */ + Session_Config config; + + /* Set the session config */ + config.server.host_name = SMTP_HOST; + config.server.port = SMTP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + + /** Assign your host name or you public IPv4 or IPv6 only + * as this is the part of EHLO/HELO command to identify the client system + * to prevent connection rejection. + * If host name or public IP is not available, ignore this or + * use loopback address "127.0.0.1". + * + * Assign any text to this option may cause the connection rejection. + */ + config.login.user_domain = F("127.0.0.1"); + + /* + Set the NTP config time + For times east of the Prime Meridian use 0-12 + For times west of the Prime Meridian add 12 to the offset. + Ex. American/Denver GMT would be -6. 6 + 12 = 18 + See https://en.wikipedia.org/wiki/Time_zone for a list of the GMT/UTC timezone offsets + */ + config.time.ntp_server = F("pool.ntp.org,time.nist.gov"); + config.time.gmt_offset = 3; + config.time.day_light_offset = 0; + + /* Declare the message class */ + SMTP_Message message; + + /* Set the message headers */ + message.sender.name = F("ESP Mail"); + message.sender.email = AUTHOR_EMAIL; + message.subject = F("Test sending Email with rfc822 attachment"); + message.addRecipient(F("Someone"), RECIPIENT_EMAIL); + + message.text.content = F("This is simple plain text message with rfc822 attachment"); + + /** The Plain text message character set e.g. + * us-ascii + * utf-8 + * utf-7 + * The default value is utf-8 + */ + message.text.charSet = F("us-ascii"); + + /** The content transfer encoding e.g. + * enc_7bit or "7bit" (not encoded) + * enc_qp or "quoted-printable" (encoded) + * enc_base64 or "base64" (encoded) + * enc_binary or "binary" (not encoded) + * enc_8bit or "8bit" (not encoded) + * The default value is "7bit" + */ + message.text.transfer_encoding = Content_Transfer_Encoding::enc_7bit; + + /** The message priority + * esp_mail_smtp_priority_high or 1 + * esp_mail_smtp_priority_normal or 3 + * esp_mail_smtp_priority_low or 5 + * The default value is esp_mail_smtp_priority_low + */ + message.priority = esp_mail_smtp_priority::esp_mail_smtp_priority_low; + + /* Set the custom message header */ + message.addHeader(F("Message-ID: ")); + + SMTP_Message rfc822; + rfc822.messageID = F("1234@local.machine.example"); + rfc822.from.name = F("rob"); + rfc822.from.email = F("rob@example.com"); + rfc822.sender.name = F("steve"); + rfc822.sender.email = F("steve@example.com"); + + // This date field will set by default if the device time was already set or set date field manually + rfc822.date = MailClient.Time.getDateTimeString(); + + rfc822.subject = F("Test rfc822 message"); + rfc822.comments = F("This is comment"); + rfc822.addRecipient(F("joe"), F("joe@example.com")); + rfc822.response.reply_to = F("rob@example.com"); + rfc822.text.charSet = F("utf-8"); + rfc822.text.content = F("This is rfc822 text message"); + rfc822.text.transfer_encoding = Content_Transfer_Encoding::enc_qp; + + rfc822.html.charSet = F("utf-8"); + rfc822.html.content = F("This is rfc822 html message"); + rfc822.html.transfer_encoding = Content_Transfer_Encoding::enc_base64; + + /* The attachment data item */ + SMTP_Attachment att[2]; + int attIndex = 0; + + /** Set the attachment info e.g. + * file name, MIME type, BLOB data, BLOB data size, + * and transfer encoding + */ + att[attIndex].descr.filename = F("firebase_logo.png"); + att[attIndex].descr.mime = F("image/png"); + att[attIndex].blob.data = firebase_png; + att[attIndex].blob.size = sizeof(firebase_png); + att[attIndex].descr.transfer_encoding = Content_Transfer_Encoding::enc_base64; + + /* Add the attachment to the rfc822 message */ +#if defined(ESP32) || defined(ESP8266) + rfc822.addAttachment(att[attIndex]); // Required more stack and may fail on SAMD +#endif + /* Prepare other attachment data */ + uint8_t *a = new uint8_t[512]; + int j = 0; + + for (int i = 0; i < 512; i++) + { + a[i] = j; + j++; + if (j > 255) + j = 0; + } + + /** Set the attachment info e.g. + * file name, MIME type, BLOB data, BLOB data size. + * The default transfer encoding is base64. + */ + attIndex++; + att[attIndex].descr.filename = F("test.dat"); + att[attIndex].descr.mime = F("application/octet-stream"); + att[attIndex].blob.data = a; + att[attIndex].blob.size = 512; + + /* Add this attachment to the message */ + message.addAttachment(att[attIndex]); + + /* Add rfc822 message in the message */ + message.addMessage(rfc822); + + /* Connect to the server */ + if (!smtp.connect(&config)) + { + MailClient.printf("Connection error, Status Code: %d, Error Code: %d, Reason: %s", smtp.statusCode(), smtp.errorCode(), smtp.errorReason().c_str()); + return; + } + + if (!smtp.isLoggedIn()) + { + Serial.println("\nNot yet logged in."); + } + else + { + if (smtp.isAuthenticated()) + Serial.println("\nSuccessfully logged in."); + else + Serial.println("\nConnected with no Auth."); + } + + /* Start sending Email and close the session */ + if (!MailClient.sendMail(&smtp, &message)) + MailClient.printf("Error, Status Code: %d, Error Code: %d, Reason: %s", smtp.statusCode(), smtp.errorCode(), smtp.errorReason().c_str()); + + // to clear sending result log + // smtp.sendingResult.clear(); + + MailClient.printf("Free Heap: %d\n", MailClient.getFreeHeap()); +} + +void loop() +{ +} + +/* Callback function to get the Email sending status */ +void smtpCallback(SMTP_Status status) +{ + /* Print the current status */ + Serial.println(status.info()); + + /* Print the sending result */ + if (status.success()) + { + // MailClient.printf used in the examples is for format printing via debug Serial port + // that works for all supported Arduino platform SDKs e.g. SAMD, ESP32 and ESP8266. + // In ESP8266 and ESP32, you can use Serial.printf directly. + + Serial.println("----------------"); + MailClient.printf("Message sent success: %d\n", status.completedCount()); + MailClient.printf("Message sent failed: %d\n", status.failedCount()); + Serial.println("----------------\n"); + + for (size_t i = 0; i < smtp.sendingResult.size(); i++) + { + /* Get the result item */ + SMTP_Result result = smtp.sendingResult.getItem(i); + + // In case, ESP32, ESP8266 and SAMD device, the timestamp get from result.timestamp should be valid if + // your device time was synched with NTP server. + // Other devices may show invalid timestamp as the device time was not set i.e. it will show Jan 1, 1970. + // You can call smtp.setSystemTime(xxx) to set device time manually. Where xxx is timestamp (seconds since Jan 1, 1970) + + MailClient.printf("Message No: %d\n", i + 1); + MailClient.printf("Status: %s\n", result.completed ? "success" : "failed"); + MailClient.printf("Date/Time: %s\n", MailClient.Time.getDateTimeString(result.timestamp, "%B %d, %Y %H:%M:%S").c_str()); + MailClient.printf("Recipient: %s\n", result.recipients.c_str()); + MailClient.printf("Subject: %s\n", result.subject.c_str()); + } + Serial.println("----------------\n"); + + // You need to clear sending result as the memory usage will grow up. + smtp.sendingResult.clear(); + } +} diff --git a/lib/libesp32/lib_mail/examples/Send_Attachment_Blob/image.h b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_RFC822_Attachment/image.h similarity index 99% rename from lib/libesp32/lib_mail/examples/Send_Attachment_Blob/image.h rename to lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_RFC822_Attachment/image.h index 80ce0a0e7..5ddd6829b 100644 --- a/lib/libesp32/lib_mail/examples/Send_Attachment_Blob/image.h +++ b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_RFC822_Attachment/image.h @@ -1,1851 +1,1851 @@ -#include - -static const uint8_t firebase_png[] PROGMEM = { - 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00, 0x00, 0x00, 0x0D, 0x49, 0x48, 0x44, 0x52, - 0x00, 0x00, 0x03, 0x20, 0x00, 0x00, 0x02, 0x58, 0x08, 0x06, 0x00, 0x00, 0x00, 0x9A, 0x76, 0x82, - 0x70, 0x00, 0x00, 0x00, 0x01, 0x73, 0x52, 0x47, 0x42, 0x00, 0xAE, 0xCE, 0x1C, 0xE9, 0x00, 0x00, - 0x00, 0x04, 0x67, 0x41, 0x4D, 0x41, 0x00, 0x00, 0xB1, 0x8F, 0x0B, 0xFC, 0x61, 0x05, 0x00, 0x00, - 0x00, 0x09, 0x70, 0x48, 0x59, 0x73, 0x00, 0x00, 0x0E, 0xC3, 0x00, 0x00, 0x0E, 0xC3, 0x01, 0xC7, - 0x6F, 0xA8, 0x64, 0x00, 0x00, 0x55, 0x14, 0x49, 0x44, 0x41, 0x54, 0x78, 0x5E, 0xED, 0xDD, 0x59, - 0x90, 0x1D, 0xF5, 0x81, 0xE7, 0x7B, 0x3F, 0xF4, 0xC3, 0x84, 0x91, 0x40, 0x6E, 0xEF, 0xC6, 0x8B, - 0x30, 0x92, 0x4A, 0x1B, 0x58, 0x98, 0xCD, 0xA0, 0xA5, 0x4A, 0x12, 0x20, 0x6C, 0x9A, 0xB6, 0xBA, - 0x01, 0x63, 0x4F, 0x3F, 0x8C, 0x1E, 0x26, 0xC2, 0xF7, 0xE5, 0xC6, 0x25, 0xE2, 0xDE, 0x97, 0x3B, - 0x7D, 0x67, 0xAC, 0x6E, 0x63, 0x63, 0x83, 0x8D, 0xBC, 0xB1, 0x99, 0xA5, 0x10, 0x08, 0xED, 0x52, - 0x69, 0xAD, 0x92, 0xA0, 0xBB, 0xAB, 0xA7, 0xED, 0x6E, 0x77, 0xB7, 0x81, 0x42, 0x9B, 0x99, 0x89, - 0x89, 0xDB, 0x9A, 0xB9, 0x0E, 0x2F, 0x2C, 0x76, 0x61, 0x16, 0x49, 0x85, 0xA4, 0xFC, 0xDF, 0xFF, - 0x3F, 0x4F, 0xE6, 0xA9, 0x3C, 0x79, 0x7E, 0xE7, 0x9C, 0xCC, 0x3C, 0x99, 0x75, 0xCE, 0xC9, 0xFA, - 0x7E, 0x22, 0x7E, 0xA1, 0x6E, 0x2F, 0x42, 0xC2, 0x94, 0xE2, 0xFF, 0x8D, 0x7F, 0x65, 0x9E, 0xF7, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x28, 0x82, 0x79, 0x6E, 0xCD, 0x80, 0xBF, 0xC3, 0x5F, 0x58, 0x12, 0xFC, - 0x4B, 0x00, 0x00, 0x00, 0x00, 0x90, 0x1F, 0x73, 0x78, 0xCD, 0x3A, 0xEF, 0xB9, 0x35, 0x63, 0xE6, - 0xB9, 0x9B, 0x4D, 0x75, 0xCF, 0xAE, 0xF1, 0xE7, 0x3D, 0x7B, 0xD3, 0xA0, 0x0B, 0x92, 0xE0, 0x3F, - 0x0A, 0x00, 0x00, 0x00, 0x00, 0xD9, 0x98, 0x91, 0x35, 0xB3, 0xEB, 0xC2, 0x23, 0x12, 0x1F, 0xD1, - 0x79, 0x87, 0xD7, 0x6C, 0x08, 0xFE, 0x6B, 0x00, 0x00, 0x00, 0x00, 0x90, 0x8E, 0xFB, 0x16, 0x2B, - 0xEF, 0xD9, 0x35, 0xE3, 0x95, 0xE0, 0xB8, 0xD1, 0x98, 0x03, 0x57, 0x19, 0xB3, 0x7B, 0xAE, 0x31, - 0x3B, 0x3E, 0x65, 0xCC, 0xB6, 0x8F, 0x1A, 0xB3, 0xF3, 0xD3, 0xC6, 0x0C, 0x2D, 0x34, 0x66, 0x78, - 0xD9, 0x64, 0x84, 0x3C, 0x7B, 0xD3, 0x60, 0xF0, 0x5F, 0x07, 0x00, 0x00, 0x00, 0x80, 0xE4, 0xAA, - 0x37, 0x1F, 0x2E, 0x3C,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B, 0x04, 0x00, 0x00, 0x00, 0x50, 0x16, 0x66, 0xFF, 0x67, 0x75, 0x5C, - 0xB4, 0x9A, 0x0C, 0x8B, 0x24, 0x13, 0xD1, 0x11, 0xDF, 0xC8, 0x0A, 0xE3, 0x1D, 0x5A, 0x3D, 0x18, - 0xFC, 0x12, 0x01, 0x00, 0x00, 0x00, 0x94, 0x81, 0xBB, 0x65, 0x30, 0xFB, 0x2E, 0xD7, 0x81, 0xD1, - 0x6C, 0x32, 0x2C, 0x92, 0x4C, 0xC4, 0x86, 0x1A, 0xB7, 0x20, 0x00, 0x00, 0x00, 0x40, 0xF9, 0x98, - 0xE7, 0x56, 0x0F, 0x98, 0x5D, 0x97, 0xEA, 0xC8, 0x68, 0x34, 0x19, 0x16, 0x49, 0x26, 0x42, 0xA3, - 0xD9, 0x0E, 0x7E, 0xCE, 0x78, 0x87, 0x6F, 0x18, 0x0D, 0x7E, 0xA9, 0x00, 0x00, 0x00, 0x00, 0x7A, - 0x9D, 0xFF, 0x06, 0xAC, 0x1D, 0x9F, 0xD0, 0xA1, 0xA1, 0x26, 0xC3, 0x22, 0xC9, 0x44, 0x60, 0xB4, - 0xDA, 0xCE, 0x4B, 0x82, 0x5B, 0x90, 0xD5, 0x03, 0xC1, 0x2F, 0x17, 0x00, 0x00, 0x00, 0x40, 0x2F, - 0xF3, 0x9E, 0xBD, 0x61, 0x50, 0x86, 0x86, 0x9A, 0x0C, 0x8B, 0x24, 0x13, 0x71, 0x91, 0x74, 0x07, - 0xAF, 0x35, 0xDE, 0xE1, 0x55, 0xDC, 0x82, 0x00, 0x00, 0x00, 0x00, 0x65, 0xE0, 0x1D, 0xBC, 0x6E, - 0x54, 0xC6, 0x46, 0x7C, 0x32, 0x2C, 0x92, 0x4C, 0x44, 0x45, 0xD2, 0x6D, 0xF9, 0x80, 0x31, 0x3B, - 0x67, 0xBB, 0x0F, 0x26, 0x34, 0xE6, 0xD0, 0xAA, 0xB5, 0xC1, 0x2F, 0x19, 0x00,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D, 0x70, 0xB5, 0xFD, 0xD7, 0x57, 0x55, 0xFE, 0x7D, 0x22, 0x04, 0x00, 0x00, 0xA0, 0x38, 0xFE, - 0x2B, 0x78, 0x55, 0x74, 0x84, 0x93, 0x71, 0xD1, 0x6A, 0x2A, 0x28, 0xD2, 0x4C, 0xC4, 0x45, 0xAB, - 0xA9, 0xA8, 0x48, 0xBC, 0x59, 0x95, 0x07, 0xC7, 0xDD, 0xB7, 0x50, 0x65, 0xB8, 0x05, 0xF1, 0x86, - 0x57, 0x64, 0xBF, 0xFD, 0x90, 0x21, 0x91, 0x65, 0x91, 0xF8, 0x08, 0xC7, 0x2D, 0x48, 0x6D, 0x7C, - 0x1C, 0xB9, 0xB1, 0x36, 0x3A, 0xD4, 0x5C, 0x98, 0x1C, 0xFD, 0x42, 0x25, 0x42, 0x4E, 0x7C, 0x85, - 0x1B, 0x24, 0x00, 0x00, 0x80, 0xBC, 0x79, 0x07, 0x97, 0x35, 0x7E, 0x03, 0x96, 0x8C, 0x8B, 0x56, - 0x53, 0x41, 0x91, 0x66, 0x22, 0x2E, 0x5A, 0x4D, 0x46, 0x45, 0xD2, 0x85, 0x1F, 0x16, 0x68, 0xE7, - 0x6E, 0x41, 0x46, 0x06, 0x86, 0x82, 0xBF, 0x35, 0x89, 0xB4, 0x75, 0xFB, 0x21, 0x43, 0x22, 0xCB, - 0x44, 0x7C, 0xB8, 0x6D, 0xFD, 0xD0, 0xB4, 0xBE, 0x05, 0xA9, 0x89, 0x0F, 0x77, 0xEB, 0xA1, 0x82, - 0xA3, 0xD1, 0x5C, 0xAC, 0xF8, 0x37, 0x26, 0x5F, 0x29, 0xE4, 0xD3, 0xF2, 0x01, 0x00, 0x00, 0xA6, - 0x2D, 0x6F, 0xFF, 0x35, 0x63, 0xC4, 0x47, 0xB0, 0xED, 0x1F, 0xB7, 0x87, 0x75, 0xFF, 0x16, 0x24, - 0xF1, 0x81, 0xDD, 0x1B, 0x59, 0x31, 0xE6, 0x3F, 0xC4,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x00, 0x00, 0x50, 0x7E, 0x66, 0x68, 0xBE, 0x8D, 0x02, 0x15, 0x18, 0xCD, 0x26, 0xA2, 0x22, - 0xE9, 0x54, 0x78, 0x44, 0x96, 0xE8, 0xF6, 0x23, 0x88, 0x8F, 0x76, 0x6F, 0x3F, 0x74, 0x48, 0x64, - 0x99, 0x08, 0x89, 0x2C, 0x23, 0x3E, 0x72, 0x98, 0x0A, 0x87, 0x3C, 0x26, 0xE2, 0x21, 0x8F, 0xBD, - 0x78, 0x1D, 0x6F, 0xC2, 0x02, 0x00, 0x00, 0xD3, 0x87, 0xFF, 0x06, 0xAC, 0x5D, 0x9F, 0xB6, 0x61, - 0xA0, 0x22, 0xA3, 0xD1, 0x44, 0x54, 0x24, 0x9D, 0x08, 0x8E, 0xEA, 0x92, 0xDE, 0x7E, 0x3C, 0x6E, - 0x03, 0x24, 0x8C, 0x8F, 0x68, 0x80, 0xFC, 0x80, 0xF8, 0x20, 0x3E, 0x54, 0x38, 0xE4, 0x31, 0x11, - 0x0E, 0x79, 0xED, 0x85, 0xAB, 0x78, 0x13, 0x16, 0x00, 0x00, 0x98, 0x3E, 0xCC, 0xA1, 0xFE, 0xB5, - 0x66, 0xC7, 0xC7, 0x6D, 0x1C, 0xA8, 0xD0, 0x50, 0x13, 0x51, 0x91, 0x74, 0x2A, 0x3A, 0x62, 0x53, - 0xB7, 0x1F, 0xD1, 0x00, 0xF1, 0xE3, 0xA3, 0xD1, 0xED, 0xC7, 0x37, 0x75, 0x68, 0xA8, 0xE9, 0x90, - 0xC8, 0x32, 0x11, 0x12, 0x59, 0x46, 0x7C, 0xE4, 0x30, 0x15, 0x0E, 0x79, 0x4C, 0x44, 0x43, 0xCE, - 0xE3, 0x4D, 0x58, 0x00, 0x00, 0x60, 0xDA, 0xF0, 0xDF, 0x80, 0xB5, 0xE5, 0xFD, 0x36, 0x10, 0x54, - 0x6C, 0xC4, 0x27, 0xA2, 0x22, 0xE9, 0x44, 0x6C, 0xD4, 0x2C, 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C6, 0x83, 0x2F, 0x51, 0x00, 0x00, 0x80, 0x72, 0xF1, 0x0E, 0x5C, - 0x33, 0x2A, 0xE3, 0xA2, 0xD5, 0x54, 0x58, 0x24, 0x99, 0x8D, 0x0E, 0xF7, 0xE3, 0x64, 0x80, 0x04, - 0xF1, 0x11, 0xBD, 0xFD, 0x88, 0xC5, 0x47, 0xDD, 0xED, 0xC7, 0xB7, 0x6A, 0x6F, 0x3F, 0x74, 0x48, - 0x64, 0x99, 0x08, 0x89, 0x2C, 0x13, 0xE1, 0xE1, 0x56, 0x17, 0x1F, 0xEA, 0x8D, 0x57, 0xC4, 0x47, - 0x30, 0x15, 0x0E, 0x79, 0x4C, 0x45, 0x42, 0x51, 0xD3, 0x71, 0x91, 0x68, 0x47, 0x56, 0xF3, 0x26, - 0x2C, 0x00, 0x00, 0x50, 0x4E, 0xDE, 0xDE, 0x25, 0x63, 0x32, 0x30, 0x9A, 0x2D, 0x1E, 0x15, 0x69, - 0x16, 0x86, 0x47, 0x18, 0x1F, 0x69, 0x6F, 0x3F, 0x7E, 0x68, 0x57, 0xB6, 0xF8, 0x70, 0x37, 0x1F, - 0x2E, 0x3E, 0xDC, 0x43, 0xE7, 0xC4, 0x87, 0x9D, 0x0A, 0x87, 0x3C, 0xA6, 0x22, 0xA1, 0xA8, 0x89, - 0xA8, 0x48, 0xB3, 0x97, 0x56, 0xF0, 0x26, 0x2C, 0x00, 0x00, 0x50, 0x4E, 0x66, 0xCF, 0x42, 0x1D, - 0x19, 0x8D, 0xA6, 0xA2, 0x22, 0xE5, 0x2A, 0x01, 0x32, 0xB3, 0xED, 0xDB, 0x0F, 0x1D, 0x12, 0x59, - 0x26, 0x42, 0x22, 0xCB, 0x44, 0x78, 0xB8, 0xB5, 0x8C, 0x8F, 0xBF, 0x9C, 0xFC, 0xAC, 0x8F, 0x3F, - 0xDC, 0x4B, 0x7C, 0x14, 0x33, 0x15, 0x09, 0x45, 0x4D, 0x04, 0x45, 0xDA, 0xBD, 0x78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00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xD0, 0x15, 0xDE, 0xF3, 0x9E, 0xFF, 0x1F, 0x5B, 0xE2, 0x94, 0x1D, 0x86, - 0x86, 0x23, 0x09, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4E, 0x44, 0xAE, 0x42, 0x60, 0x82}; - -static const uint8_t tree_gif[] PROGMEM = { - - 0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x28, 0x00, 0x3C, 0x00, 0x83, 0x0B, 0x00, 0x00, 0xFF, 0xFF, - 0x00, 0x21, 0x00, 0x00, 0x4A, 0x00, 0x00, 0x6B, 0x00, 0x00, 0x94, 0x00, 0x00, 0xB5, 0x00, 0x00, - 0xDE, 0x00, 0x00, 0xFF, 0x00, 0x6B, 0x00, 0x00, 0xFF, 0x33, 0x33, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, - 0xFF, 0xFF, 0xCC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x99, 0x00, 0xCC, 0x00, 0x00, 0x21, 0xFF, 0x0B, - 0x4E, 0x45, 0x54, 0x53, 0x43, 0x41, 0x50, 0x45, 0x32, 0x2E, 0x30, 0x03, 0x01, 0xA0, 0x0F, 0x00, - 0x21, 0xF9, 0x04, 0x09, 0x14, 0x00, 0x0B, 0x00, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x28, 0x00, 0x3C, - 0x00, 0x03, 0x04, 0xFB, 0x70, 0xC9, 0x49, 0x6B, 0x75, 0x36, 0xEB, 0xBD, 0x31, 0xFF, 0xA0, 0xE4, - 0x8C, 0xCA, 0xE8, 0x85, 0xE8, 0xA5, 0xAC, 0x67, 0xEA, 0x8A, 0xE5, 0x2B, 0x2F, 0xE3, 0x31, 0xCE, - 0xAF, 0x41, 0x1C, 0xB8, 0x1B, 0x24, 0x80, 0x04, 0xAF, 0x87, 0x02, 0x26, 0x88, 0xA1, 0x07, 0x60, - 0xB9, 0x44, 0x82, 0x04, 0x02, 0x80, 0x61, 0x30, 0x70, 0x6E, 0x0C, 0x86, 0x03, 0x60, 0x20, 0xB0, - 0x6A, 0xA8, 0xD3, 0x03, 0x21, 0xEC, 0xAD, 0x18, 0x12, 0xE8, 0xF4, 0xB1, 0x4C, 0x51, 0xA0, 0x07, - 0xEA, 0x07, 0x5B, 0xF2, 0x70, 0x13, 0x76, 0xD4, 0xA8, 0xBC, 0xBC, 0xEA, 0x1F, 0x06, 0x77, 0x51, - 0x73, 0x50, 0x0A, 0x80, 0x7F, 0x04, 0x4C, 0x4D, 0x65, 0x06, 0x0A, 0x3B, 0x3B, 0x62, 0x5A, 0x53, - 0x65, 0x05, 0x02, 0x04, 0x68, 0x0C, 0x6A, 0x00, 0x5D, 0x5E, 0x0F, 0x0F, 0x6A, 0x98, 0x6A, 0x09, - 0x7B, 0x56, 0x9D, 0x09, 0x0C, 0xA7, 0xA7, 0x7F, 0x06, 0x9D, 0xA3, 0x44, 0x02, 0x01, 0x03, 0x90, - 0x0C, 0x87, 0x03, 0x06, 0x02, 0x05, 0x56, 0x06, 0x01, 0x02, 0x53, 0xB1, 0xB3, 0x04, 0x79, 0xAF, - 0x55, 0x48, 0x51, 0xB0, 0x87, 0xC0, 0x7F, 0x07, 0x95, 0x05, 0x85, 0x44, 0xB6, 0x00, 0x05, 0x53, - 0x96, 0x6A, 0x60, 0x02, 0x0A, 0x48, 0x89, 0x00, 0x07, 0xA1, 0x69, 0x7D, 0x2B, 0x3D, 0x9D, 0x41, - 0xA1, 0x04, 0xA0, 0xDD, 0x9D, 0x38, 0x02, 0xE1, 0x6A, 0x07, 0x62, 0x0C, 0x77, 0xE6, 0xAD, 0x2F, - 0x05, 0x01, 0xB6, 0x90, 0x07, 0xA8, 0xA7, 0x54, 0xB5, 0xBC, 0x06, 0x33, 0x50, 0x53, 0x3A, 0x00, - 0x39, 0x62, 0x10, 0x6B, 0xDF, 0xBE, 0x19, 0x03, 0x18, 0x40, 0xA9, 0x15, 0x4B, 0xCC, 0x0E, 0x77, - 0x3B, 0x04, 0xC4, 0x02, 0x38, 0x43, 0x21, 0x96, 0x2C, 0xD3, 0xD6, 0x81, 0x01, 0x26, 0x2A, 0xFB, - 0xDE, 0x07, 0x7C, 0x0A, 0xB7, 0x71, 0x1B, 0x79, 0xEE, 0xC5, 0x83, 0x72, 0xDD, 0x84, 0xBC, 0x4B, - 0x13, 0xA4, 0x13, 0x15, 0x17, 0xAB, 0x18, 0x78, 0x4A, 0x43, 0x40, 0x81, 0x43, 0x76, 0x8E, 0xB6, - 0x04, 0x7C, 0x19, 0x02, 0x98, 0xC4, 0x86, 0x35, 0xBD, 0xE1, 0x1C, 0x90, 0x4D, 0x62, 0xBF, 0x14, - 0xFC, 0x7E, 0x02, 0x1A, 0x60, 0xD3, 0xD1, 0x9D, 0x3B, 0x3A, 0x09, 0xFC, 0x44, 0xB1, 0xD0, 0x96, - 0x8E, 0x43, 0x8D, 0x9E, 0xDA, 0xDB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x0C, 0xC1, 0xB7, - 0x90, 0x68, 0x72, 0xD1, 0x7C, 0xD9, 0x3D, 0xA3, 0x94, 0x35, 0xDE, 0x54, 0x06, 0x92, 0x51, 0x50, - 0x68, 0xC2, 0xC5, 0x44, 0xB7, 0x30, 0x70, 0xDE, 0x6A, 0x49, 0x69, 0x86, 0xC5, 0x2D, 0xA3, 0x29, - 0x04, 0x05, 0x2F, 0xD9, 0xC4, 0x02, 0x0C, 0x6C, 0x0C, 0x48, 0xB0, 0x94, 0x01, 0xDA, 0x3C, 0xF2, - 0x56, 0x21, 0xFA, 0xE8, 0xA3, 0xA1, 0x55, 0x12, 0xE9, 0xF4, 0x56, 0x42, 0xF8, 0x50, 0x00, 0x40, - 0x08, 0x08, 0xD4, 0x88, 0x80, 0x05, 0x33, 0x66, 0x10, 0xA2, 0x0C, 0xDC, 0xA0, 0xB0, 0xA3, 0x0B, - 0x71, 0xCD, 0xB1, 0x80, 0x75, 0x69, 0x20, 0x41, 0xE4, 0x91, 0x6B, 0x64, 0x10, 0x01, 0x00, 0x21, - 0xF9, 0x04, 0x09, 0x14, 0x00, 0x0B, 0x00, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x28, 0x00, 0x3C, 0x00, - 0x03, 0x04, 0xFB, 0x70, 0xC9, 0x49, 0x6B, 0x75, 0x36, 0xEB, 0xBD, 0x31, 0xFF, 0xA0, 0xE4, 0x8C, - 0xA4, 0x17, 0x9E, 0x57, 0x89, 0xAE, 0xA9, 0xC9, 0xAE, 0xE3, 0x31, 0xBE, 0xAF, 0x31, 0x1C, 0x34, - 0x1B, 0x24, 0x4C, 0x82, 0xE7, 0x28, 0x5E, 0x02, 0x78, 0x7A, 0x30, 0x8E, 0x47, 0x62, 0x48, 0x20, - 0x60, 0xD8, 0x06, 0x4A, 0x8E, 0xC1, 0x70, 0x60, 0x0C, 0x04, 0xD1, 0xCD, 0x60, 0x60, 0x3B, 0x10, - 0xBA, 0x59, 0x8B, 0x21, 0x41, 0x2E, 0x0F, 0xC3, 0x16, 0xF2, 0xC0, 0xAC, 0x40, 0x4F, 0x1E, 0x80, - 0x04, 0x81, 0x70, 0xD8, 0x0A, 0x14, 0x0F, 0xF7, 0x42, 0x00, 0xA0, 0xD6, 0x09, 0x0A, 0x81, 0x81, - 0x68, 0x00, 0x85, 0x85, 0x7F, 0x07, 0x07, 0x0A, 0x06, 0x7A, 0x06, 0x00, 0x74, 0x74, 0x5E, 0x8A, - 0x36, 0x68, 0x05, 0x7C, 0x66, 0x3D, 0x64, 0x58, 0x61, 0x0F, 0x0F, 0x66, 0x64, 0x99, 0x64, 0x79, - 0x9C, 0x9E, 0xA0, 0x48, 0x4E, 0x9D, 0xA3, 0x4A, 0x02, 0x01, 0x37, 0x90, 0x55, 0x04, 0x5C, 0x02, - 0x05, 0x59, 0x06, 0x01, 0x02, 0x4F, 0x89, 0x55, 0x76, 0xAC, 0x50, 0xAB, 0x0A, 0xAD, 0x7F, 0xB1, - 0x75, 0x07, 0x02, 0x04, 0x05, 0x00, 0xBE, 0x39, 0x06, 0x77, 0x05, 0x36, 0x04, 0x9F, 0x5B, 0xCC, - 0x00, 0x4A, 0x82, 0x81, 0x07, 0x9F, 0x65, 0x86, 0x85, 0x40, 0x9D, 0x0A, 0x9F, 0x0C, 0xD0, 0x9F, - 0x00, 0x9D, 0x39, 0x02, 0xDE, 0x66, 0xB0, 0x73, 0xE2, 0x09, 0xE4, 0xAA, 0x2F, 0x05, 0x01, 0xCC, - 0x5E, 0xA7, 0x56, 0x75, 0xD2, 0xB8, 0x8C, 0x2F, 0x4C, 0x36, 0x06, 0xB1, 0x73, 0xE1, 0x88, 0xC9, - 0x92, 0x45, 0x43, 0x96, 0x00, 0x2E, 0x37, 0xE8, 0x79, 0x99, 0x53, 0xEC, 0x86, 0x0D, 0x06, 0x05, - 0xF3, 0x51, 0x61, 0x57, 0xE6, 0x9E, 0xBF, 0x35, 0x0C, 0xDE, 0x81, 0xE8, 0x64, 0x10, 0xFB, 0x5B, - 0xB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 0x59, 0x48, 0x85, 0x47, 0x8D, 0xD8, 0xC8, 0xD9, - 0xE2, 0xF0, 0x55, 0x99, 0x4A, 0xE3, 0x82, 0x07, 0x41, 0x3F, 0x25, 0x92, 0xAE, 0xD7, 0x4C, 0x3C, - 0xE7, 0xAC, 0x02, 0x04, 0x58, 0xC4, 0xC4, 0xAD, 0x9C, 0x1B, 0xB1, 0x3F, 0xE1, 0x42, 0x3D, 0x4B, - 0x9E, 0x85, 0xCB, 0x57, 0xA6, 0x30, 0x4B, 0x97, 0x88, 0x26, 0xA2, 0x03, 0x7F, 0x8B, 0x72, 0x2D, - 0x90, 0x79, 0x02, 0xFD, 0x59, 0x36, 0xB2, 0xF3, 0x41, 0x2A, 0x65, 0xAD, 0x75, 0x64, 0x3A, 0x0C, - 0x48, 0xB4, 0x15, 0x35, 0x13, 0xE0, 0xC2, 0xC0, 0x2D, 0xB1, 0x15, 0x95, 0x0C, 0x13, 0x97, 0x59, - 0x73, 0x90, 0x01, 0xF5, 0xAC, 0x36, 0x8D, 0x79, 0x12, 0x40, 0xB8, 0x45, 0x22, 0xB8, 0xF8, 0xC4, - 0x0C, 0x7D, 0xB3, 0x31, 0x96, 0xCF, 0x00, 0x01, 0x76, 0x41, 0x80, 0x4F, 0x0B, 0x80, 0x78, 0x4A, - 0x24, 0x5B, 0x8C, 0x18, 0xDB, 0x8A, 0x0A, 0xF0, 0xC3, 0x15, 0x88, 0x08, 0xF1, 0xC5, 0xC7, 0x3C, - 0x13, 0x40, 0x94, 0x01, 0x81, 0x13, 0x20, 0xA0, 0x23, 0x02, 0x27, 0xE0, 0x58, 0x63, 0x08, 0xD9, - 0xE8, 0x41, 0x81, 0x5B, 0x42, 0x7A, 0x57, 0x86, 0x12, 0x46, 0x26, 0x79, 0x46, 0x06, 0x11, 0x00, - 0x00, 0x21, 0xF9, 0x04, 0x09, 0x14, 0x00, 0x0B, 0x00, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x28, 0x00, - 0x3C, 0x00, 0x03, 0x04, 0xFB, 0x70, 0xC9, 0x49, 0x6B, 0x75, 0x36, 0xEB, 0xBD, 0x31, 0xFF, 0xA0, - 0xE4, 0x8C, 0xA4, 0x17, 0x9E, 0x57, 0x89, 0xAE, 0xA9, 0xC9, 0xAE, 0xE3, 0x31, 0xBE, 0xAF, 0xA1, - 0x1C, 0x34, 0x1B, 0x24, 0x4A, 0x82, 0xE7, 0x27, 0x85, 0x50, 0x08, 0x0C, 0x3D, 0x12, 0xBC, 0xC4, - 0xA3, 0x18, 0x12, 0x08, 0x14, 0x86, 0xC1, 0x80, 0xC9, 0x31, 0x18, 0x0E, 0x84, 0x81, 0x80, 0xBA, - 0x91, 0x46, 0xB1, 0x51, 0x06, 0xD7, 0x62, 0x40, 0x9A, 0x91, 0xE2, 0x71, 0xA5, 0x37, 0x40, 0x33, - 0xDE, 0xE9, 0xF1, 0xE3, 0xA1, 0x20, 0x10, 0x0E, 0x52, 0x01, 0x63, 0xA9, 0x5E, 0x0C, 0x85, 0x03, - 0x76, 0x7A, 0x7D, 0x0B, 0x4E, 0x03, 0x75, 0x78, 0x77, 0x78, 0x06, 0x84, 0x51, 0x37, 0x8A, 0x77, - 0x02, 0x51, 0x6A, 0x05, 0x02, 0x04, 0x67, 0x67, 0x5B, 0x72, 0x47, 0x98, 0x98, 0x7C, 0x5C, 0x73, - 0x66, 0x58, 0x07, 0x8B, 0x0F, 0x00, 0x9F, 0x45, 0x02, 0x01, 0x03, 0xA3, 0x0C, 0x89, 0x03, 0x06, - 0x02, 0x00, 0x5C, 0x06, 0x01, 0x92, 0x52, 0x07, 0xAE, 0x59, 0x03, 0x00, 0xBD, 0xBD, 0x4C, 0x02, - 0x05, 0xAB, 0xB9, 0x70, 0x0C, 0xAC, 0x96, 0x00, 0x52, 0x45, 0x36, 0xC1, 0x51, 0x97, 0x0C, 0x66, - 0x5E, 0x00, 0x8C, 0x4C, 0x0A, 0x05, 0x5F, 0x68, 0x98, 0x4E, 0x56, 0x40, 0x7F, 0x3D, 0x67, 0x97, - 0x9D, 0x73, 0x39, 0x02, 0x74, 0x9C, 0x48, 0xA4, 0x76, 0x76, 0x66, 0x73, 0xA8, 0x2C, 0x05, 0x50, - 0x02, 0xA3, 0xA3, 0x59, 0x78, 0x5E, 0x92, 0xD4, 0x2C, 0xDB, 0xB0, 0x59, 0x76, 0x07, 0x00, 0x78, - 0x16, 0x09, 0x80, 0xF5, 0xE4, 0x05, 0xC1, 0x81, 0x5F, 0xB0, 0x10, 0x00, 0xA0, 0xEE, 0xC0, 0xC0, - 0x03, 0x8E, 0x68, 0x68, 0xB1, 0x72, 0xE5, 0x92, 0xAF, 0x5E, 0xF6, 0x0C, 0x10, 0xF0, 0x86, 0x62, - 0xFB, 0xCE, 0xC1, 0x03, 0x98, 0x00, 0x74, 0x42, 0x42, 0xE7, 0xC5, 0xB9, 0x4E, 0xFF, 0xC2, 0x9D, - 0x99, 0xA3, 0x60, 0x0A, 0x0A, 0x03, 0xED, 0xC0, 0xDD, 0xF1, 0x47, 0xCF, 0xCB, 0x2E, 0x97, 0x20, - 0x92, 0x0D, 0x64, 0x85, 0xA5, 0x65, 0x43, 0x2C, 0x3C, 0x19, 0x10, 0x30, 0x94, 0x2F, 0x27, 0xBE, - 0x9D, 0x87, 0x78, 0xCE, 0x54, 0x47, 0xC0, 0x98, 0xC6, 0x9D, 0x39, 0x2F, 0xC6, 0xB2, 0xF1, 0x87, - 0x29, 0x96, 0x62, 0xC6, 0xB6, 0x69, 0xE2, 0xC0, 0x2B, 0x4A, 0x2C, 0x58, 0x49, 0x47, 0xDA, 0x11, - 0x6A, 0x69, 0xC0, 0xB8, 0x10, 0x22, 0x1F, 0xDC, 0x0A, 0xF4, 0x6D, 0x64, 0x02, 0x06, 0xB1, 0x04, - 0x28, 0x39, 0xBB, 0xA1, 0xDD, 0x49, 0x4C, 0xE9, 0xD4, 0xB9, 0x4D, 0x0A, 0xA2, 0x40, 0x81, 0x91, - 0x81, 0x68, 0x2E, 0x35, 0x43,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, 0x6C, 0xB3, 0xF8, - 0xF1, 0xC7, 0x3C, 0x00, 0xAA, 0xC6, 0xCB, 0x45, 0xFC, 0x21, 0xD5, 0x52, 0x72, 0x17, 0x95, 0x88, - 0xD8, 0x09, 0x08, 0x00, 0x80, 0x00, 0x02, 0x28, 0x94, 0x28, 0xC1, 0x8C, 0x20, 0x20, 0xD1, 0x5D, - 0x02, 0x27, 0xE8, 0x88, 0x82, 0x5B, 0x84, 0x2C, 0xE0, 0xD6, 0x19, 0x4C, 0x1C, 0xA9, 0xA4, 0x19, - 0x1B, 0x44, 0x00, 0x00, 0x21, 0xFE, 0x19, 0x42, 0x6F, 0x79, 0x27, 0x73, 0x20, 0x48, 0x61, 0x70, - 0x70, 0x79, 0x20, 0x48, 0x6F, 0x6C, 0x69, 0x64, 0x61, 0x79, 0x73, 0x20, 0x50, 0x61, 0x67, 0x65, - 0x00, 0x3B - -}; - -static const uint8_t bird_gif[] PROGMEM = { - 0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x74, 0x00, 0x4E, 0x00, 0xCC, 0x13, 0x00, 0xFF, 0xFF, 0xFF, - 0xEF, 0xFF, 0xFF, 0xBD, 0xE7, 0xE7, 0xD6, 0xEF, 0xEF, 0x63, 0x63, 0x63, 0xAD, 0xAD, 0xAD, 0xCE, - 0xCE, 0xCE, 0xD6, 0xDE, 0xDE, 0x4A, 0x4A, 0x4A, 0x7B, 0x84, 0x84, 0x94, 0x9C, 0x9C, 0xE7, 0xE7, - 0xE7, 0x84, 0x94, 0x94, 0xB5, 0xC6, 0xC6, 0x73, 0x7B, 0x7B, 0x31, 0x31, 0x31, 0xF7, 0xF7, 0xF7, - 0x18, 0x10, 0x10, 0xCE, 0x63, 0x39, 0x6B, 0x39, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0xFF, 0x0B, - 0x4E, 0x45, 0x54, 0x53, 0x43, 0x41, 0x50, 0x45, 0x32, 0x2E, 0x30, 0x03, 0x01, 0x00, 0x00, 0x00, - 0x21, 0xF9, 0x04, 0x09, 0x0A, 0x00, 0x00, 0x00, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x74, 0x00, 0x4B, - 0x00, 0x00, 0x05, 0xFF, 0x20, 0x20, 0x8E, 0x64, 0x69, 0x9E, 0x68, 0xAA, 0xAE, 0xEC, 0x68, 0x2C, - 0x6D, 0x2C, 0xCF, 0x74, 0x6D, 0x03, 0x46, 0x84, 0x40, 0x77, 0xEF, 0xFF, 0x40, 0x51, 0x42, 0x41, - 0x0C, 0x1A, 0x8F, 0x48, 0x13, 0xC1, 0xD0, 0x20, 0x00, 0x0E, 0x8E, 0x42, 0x72, 0x4A, 0xAD, 0x21, - 0x0E, 0xCD, 0x05, 0xE1, 0x80, 0xA8, 0x7A, 0xBF, 0x29, 0xC2, 0xA0, 0x91, 0x28, 0x34, 0x02, 0x5D, - 0xB0, 0x5A, 0xFD, 0x08, 0x34, 0x14, 0x84, 0x00, 0x7A, 0x4D, 0xF7, 0x22, 0xDC, 0x89, 0xB8, 0xC1, - 0xB9, 0x80, 0xD5, 0xFF, 0x40, 0x0B, 0x77, 0x0C, 0x0F, 0x05, 0x01, 0x0C, 0x0A, 0x0B, 0x0F, 0x08, - 0x06, 0x80, 0x8E, 0x37, 0x7B, 0x01, 0x09, 0x11, 0x03, 0x68, 0x5C, 0x4C, 0x0A, 0x8F, 0x9A, 0x33, - 0x06, 0x09, 0x01, 0x0E, 0x71, 0x68, 0x88, 0x92, 0x07, 0x9B, 0xA6, 0x2C, 0x0A, 0x86, 0x07, 0x95, - 0x05, 0x04, 0xA1, 0x5D, 0x8D, 0xA7, 0xB2, 0x26, 0x09, 0x06, 0x72, 0x72, 0x0E, 0x94, 0x01, 0xA9, - 0x04, 0x08, 0x52, 0xB3, 0xC0, 0x00, 0x09, 0x95, 0xB7, 0x0D, 0x86, 0x01, 0x04, 0x0A, 0xC3, 0x09, - 0x34, 0x43, 0xC1, 0x54, 0x0E, 0xB7, 0xD2, 0x87, 0xAE, 0xBB, 0x99, 0x32, 0x7B, 0x0E, 0xCF, 0x49, - 0x0B, 0xD1, 0xD3, 0x72, 0x0C, 0xDE, 0x57, 0x33, 0xBE, 0xCC, 0xDB, 0x47, 0x05, 0x0C, 0xDF, 0xD3, - 0x05, 0xD7, 0x31, 0x0C, 0xE1, 0xA5, 0xE7, 0x46, 0xBE, 0xEB, 0xD2, 0x04, 0x05, 0xBF, 0x2C, 0x5C, - 0x4D, 0xF3, 0x46, 0x0B, 0x11, 0x56, 0xD9, 0x3B, 0x14, 0x01, 0x14, 0x0F, 0x16, 0x04, 0x1A, 0x30, - 0x28, 0x00, 0x81, 0xA1, 0x3F, 0x1F, 0xAD, 0x02, 0x10, 0x5B, 0x87, 0x6F, 0x0E, 0x8B, 0x02, 0x0E, - 0x04, 0x5C, 0x41, 0x10, 0xF0, 0x61, 0x8F, 0x25, 0x03, 0x26, 0xDA, 0x43, 0xC4, 0x42, 0x8B, 0x00, - 0x05, 0x0E, 0x7C, 0xFF, 0xED, 0xF0, 0x68, 0x83, 0x8B, 0x44, 0x91, 0xDF, 0x06, 0xAC, 0x54, 0x01, - 0x21, 0xA1, 0x80, 0x07, 0x0F, 0x1A, 0x38, 0x70, 0xC7, 0x72, 0x46, 0xC2, 0x97, 0x03, 0x3F, 0xC5, - 0x52, 0xE1, 0x80, 0x81, 0x00, 0x01, 0x19, 0x1B, 0x3C, 0x38, 0xD8, 0x53, 0xC6, 0x81, 0x38, 0x21, - 0x61, 0x4A, 0xEB, 0xB7, 0x42, 0x01, 0x82, 0xA3, 0x58, 0x7D, 0xC9, 0x6B, 0x1A, 0x63, 0x0B, 0xD0, - 0x81, 0x11, 0x08, 0x74, 0x44, 0x61, 0xE0, 0x01, 0xD6, 0xA3, 0x05, 0x16, 0x2D, 0xE5, 0xDA, 0xC2, - 0x80, 0xB7, 0x90, 0x41, 0xCB, 0xA4, 0x39, 0xC1, 0xEF, 0x2C, 0x56, 0xAA, 0x6C, 0x57, 0x38, 0xA8, - 0x14, 0x35, 0xA8, 0x35, 0x14, 0x10, 0x10, 0x34, 0xB0, 0x9B, 0xD5, 0x4F, 0xDE, 0x14, 0x06, 0x8E, - 0xF5, 0x1D, 0xC8, 0x25, 0x85, 0x83, 0xC1, 0x84, 0x05, 0x20, 0x32, 0x30, 0xF4, 0x30, 0x2D, 0x39, - 0x8B, 0x07, 0x32, 0x42, 0xA1, 0x00, 0x72, 0xE4, 0x45, 0x08, 0x7C, 0x59, 0x36, 0x91, 0x18, 0x73, - 0xE6, 0x6F, 0x79, 0x38, 0x2B, 0x88, 0x7C, 0x54, 0xE7, 0xE0, 0x2D, 0xA3, 0x4B, 0x78, 0x7A, 0x79, - 0x7A, 0x1A, 0xCE, 0x04, 0x4C, 0x85, 0xAC, 0x66, 0x7D, 0x96, 0x80, 0xB9, 0xD8, 0x22, 0x4A, 0x4B, - 0x14, 0x00, 0x97, 0xF1, 0xD3, 0x12, 0x3B, 0x79, 0x9F, 0x45, 0xC0, 0x13, 0xB8, 0xB7, 0xE1, 0xC5, - 0x19, 0x33, 0xEB, 0x53, 0xD3, 0xA8, 0x72, 0x01, 0x0D, 0x44, 0x97, 0x5C, 0x90, 0x7B, 0x9B, 0x01, - 0x05, 0xA6, 0x89, 0xFB, 0x3D, 0x54, 0x20, 0x81, 0xDA, 0x8C, 0xD7, 0x91, 0x16, 0x22, 0x91, 0xF8, - 0x80, 0x9F, 0x86, 0x08, 0x1E, 0xF4, 0xF2, 0xD5, 0x7D, 0x96, 0x18, 0xCC, 0x47, 0xA3, 0xDB, 0x7B, - 0xCA, 0x60, 0x40, 0xCA, 0xF4, 0x58, 0x81, 0xE2, 0x42, 0x04, 0x11, 0x4C, 0x80, 0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2D, 0x70, 0xDD, 0x80, 0x37, 0xDE, 0x0A, 0x8E, 0xFB, 0x06, 0x1C, 0x00, 0x4D, 0xE0, 0x1E, - 0x80, 0x0C, 0x73, 0xFB, 0x47, 0x00, 0xE8, 0x2C, 0x89, 0x6E, 0xCF, 0x0C, 0x66, 0x87, 0x64, 0x55, - 0x73, 0x87, 0xB5, 0xD2, 0x39, 0xF2, 0x54, 0xA3, 0xAD, 0x24, 0xEF, 0x09, 0xC4, 0x2E, 0x47, 0x0C, - 0x83, 0x4F, 0x44, 0x6E, 0x25, 0xA9, 0x0C, 0x8F, 0x43, 0xE0, 0xD3, 0xB4, 0x30, 0x50, 0x54, 0xF9, - 0x41, 0x57, 0xC9, 0x63, 0xE6, 0x03, 0x00, 0xC1, 0xED, 0xE9, 0xAB, 0x60, 0x4F, 0x62, 0x94, 0x41, - 0x2A, 0xFE, 0x01, 0x56, 0x11, 0x10, 0xB3, 0x65, 0x4F, 0x11, 0xCC, 0x37, 0x4A, 0x10, 0x2C, 0x8E, - 0x3C, 0x80, 0x40, 0x3A, 0x30, 0x20, 0x02, 0x96, 0x10, 0x3F, 0x13, 0x64, 0xA7, 0x1E, 0x17, 0x53, - 0x90, 0x02, 0x28, 0x87, 0x00, 0xB2, 0xC1, 0xE0, 0x29, 0x08, 0x24, 0x50, 0xC9, 0xFE, 0x37, 0x3C, - 0x28, 0x30, 0x67, 0x75, 0x01, 0x9C, 0x20, 0x4E, 0x0A, 0xE0, 0xAC, 0xAF, 0x21, 0x90, 0x3E, 0x0D, - 0x4C, 0x41, 0xBB, 0x42, 0x13, 0x05, 0x63, 0xA4, 0x64, 0x81, 0x43, 0x28, 0x40, 0xED, 0x44, 0x00, - 0x01, 0x2C, 0x78, 0x29, 0x85, 0x2C, 0x38, 0x56, 0x62, 0x1A, 0xC0, 0x1D, 0x35, 0x84, 0x00, 0x00, - 0x21, 0xF9, 0x04, 0x09, 0x0A, 0x00, 0x00, 0x00, 0x2C, 0x00, 0x00, 0x17, 0x00, 0x6A, 0x00, 0x32, - 0x00, 0x00, 0x05, 0xFF, 0x20, 0x20, 0x8E, 0x64, 0x69, 0x9E, 0x68, 0xAA, 0x8A, 0x85, 0x02, 0xAD, - 0x70, 0x2C, 0xCF, 0x74, 0x5D, 0x26, 0x0C, 0x63, 0xD8, 0x7C, 0xEF, 0xFF, 0xA2, 0x05, 0x21, 0x80, - 0x58, 0x2C, 0x70, 0x0B, 0xA0, 0x72, 0xC9, 0x64, 0x34, 0x0C, 0x89, 0x86, 0x42, 0xC8, 0xAC, 0x5A, - 0x6B, 0x54, 0x46, 0x81, 0x11, 0x70, 0x5E, 0xBF, 0x60, 0x94, 0xA2, 0xB0, 0x40, 0x10, 0x00, 0x86, - 0x73, 0x23, 0x71, 0x08, 0xBB, 0xAF, 0x90, 0x73, 0xE2, 0x11, 0x28, 0x97, 0x1B, 0xBA, 0xB7, 0x7E, - 0xA9, 0x68, 0x04, 0x0A, 0x01, 0x01, 0x04, 0x39, 0x01, 0x50, 0x7B, 0x87, 0x3E, 0x0B, 0x5C, 0x81, - 0x5D, 0x0F, 0x03, 0x01, 0x78, 0x69, 0x05, 0x88, 0x94, 0x33, 0x0C, 0x8F, 0x8C, 0x0B, 0x81, 0x5A, - 0x08, 0x06, 0x2D, 0x3F, 0x0A, 0x0A, 0x33, 0x0B, 0x63, 0x0D, 0x49, 0x95, 0x26, 0x2D, 0x8C, 0xAB, - 0x05, 0x04, 0x7E, 0x0D, 0x67, 0x3C, 0x10, 0x09, 0x0A, 0x0C, 0x26, 0x10, 0x0E, 0x83, 0x05, 0x07, - 0x0B, 0x69, 0x0F, 0xB4, 0x0E, 0x0F, 0x9D, 0xA8, 0x24, 0x06, 0x08, 0xAB, 0xC8, 0x81, 0xA1, 0x3C, - 0x07, 0x0E, 0x6B, 0x6D, 0x25, 0x06, 0x11, 0x11, 0x12, 0x13, 0x13, 0x0F, 0x11, 0x80, 0xAC, 0xC2, - 0xD0, 0xA8, 0x65, 0x01, 0x98, 0xC9, 0x10, 0x66, 0x0E, 0x93, 0x32, 0x07, 0x38, 0x02, 0x0C, 0xB4, - 0xA2, 0x25, 0x07, 0x08, 0x13, 0x12, 0xF2, 0x13, 0x06, 0x7F, 0x07, 0xDB, 0xED, 0x95, 0xDF, 0xE1, - 0xC9, 0x63, 0x71, 0xDD, 0x29, 0x8E, 0xB8, 0x12, 0xA0, 0x2E, 0x94, 0x03, 0x14, 0xB0, 0xE4, 0x55, - 0x53, 0x80, 0x40, 0x01, 0xB2, 0x01, 0xB9, 0x4E, 0x21, 0x3A, 0x30, 0x64, 0x00, 0xBF, 0x64, 0x0B, - 0x1E, 0x48, 0x3C, 0x41, 0x2A, 0x0A, 0xC1, 0x8F, 0x05, 0x8A, 0x04, 0x74, 0x10, 0x4F, 0x42, 0x84, - 0x07, 0x0E, 0x93, 0xFF, 0x35, 0x40, 0x60, 0xEE, 0x90, 0x14, 0x70, 0x17, 0x91, 0x29, 0x48, 0x80, - 0x62, 0xC1, 0x16, 0x05, 0x1F, 0x73, 0x12, 0x9C, 0xB9, 0xA2, 0x40, 0x04, 0x04, 0x09, 0x82, 0x6A, - 0x4B, 0xC6, 0x80, 0x80, 0x81, 0x17, 0x7A, 0x0A, 0xD4, 0xB3, 0x18, 0x33, 0x10, 0x84, 0x5F, 0x6C, - 0x48, 0xB4, 0x1A, 0xA8, 0x53, 0x67, 0x82, 0x1D, 0x2B, 0x84, 0x2C, 0x4A, 0xB6, 0xEA, 0xC0, 0x4C, - 0x1C, 0xA6, 0x20, 0x20, 0xB5, 0x32, 0x05, 0x66, 0xD3, 0x40, 0x07, 0xA0, 0xD8, 0x12, 0xD1, 0xE0, - 0x41, 0x83, 0xAA, 0x55, 0x61, 0x31, 0xC8, 0xA7, 0x82, 0xA1, 0x83, 0x7A, 0x5C, 0x19, 0x41, 0x48, - 0xDB, 0x22, 0x47, 0xD0, 0xA3, 0x4C, 0x52, 0x32, 0x3D, 0x0B, 0x0E, 0x01, 0x34, 0x03, 0x6E, 0xE1, - 0xC2, 0xC5, 0x43, 0x57, 0x05, 0x04, 0x28, 0x04, 0x1C, 0x38, 0xB9, 0x97, 0x17, 0xD9, 0x81, 0x02, - 0x7F, 0xC7, 0xF6, 0x48, 0x10, 0x68, 0x80, 0x00, 0x8B, 0x95, 0x73, 0x8D, 0x38, 0xB0, 0xEE, 0xAD, - 0xE2, 0x8F, 0x0A, 0x08, 0x00, 0x94, 0x01, 0xA1, 0x17, 0x66, 0x02, 0xB0, 0x71, 0x84, 0x52, 0x9A, - 0x97, 0xB4, 0xEA, 0x1F, 0x07, 0xC1, 0x11, 0x24, 0xDC, 0xC0, 0xC1, 0x18, 0x00, 0xA4, 0x10, 0x30, - 0x38, 0x8D, 0xDA, 0xF0, 0x92, 0x05, 0x69, 0x0F, 0xA4, 0x55, 0xE0, 0x40, 0x32, 0xDE, 0xAE, 0xE5, - 0x7A, 0xE0, 0x02, 0xD0, 0x79, 0x77, 0x65, 0x70, 0xB0, 0x09, 0x14, 0x20, 0xFE, 0x51, 0xFB, 0xC6, - 0x2F, 0x8F, 0x85, 0x42, 0x40, 0x86, 0xF9, 0x7B, 0x0C, 0x5C, 0x8C, 0x3C, 0x7F, 0x26, 0xDC, 0x85, - 0xC0, 0x83, 0x41, 0xA6, 0x4F, 0x6B, 0x41, 0x04, 0xA1, 0xD5, 0x73, 0xB4, 0xDA, 0x35, 0xAB, 0xB8, - 0x8C, 0x23, 0xBD, 0xF5, 0xEB, 0x30, 0x41, 0xD0, 0xD6, 0x69, 0x6B, 0x34, 0x80, 0x0A, 0x04, 0xEB, - 0xA8, 0x14, 0x85, 0xFF, 0x7E, 0x41, 0x60, 0xE6, 0x40, 0x02, 0x05, 0x48, 0xE1, 0x47, 0x75, 0xBB, - 0xB1, 0xC7, 0xC8, 0x4A, 0xC4, 0xCD, 0x47, 0x0C, 0x2C, 0x31, 0x85, 0x64, 0x46, 0x64, 0x09, 0x20, - 0xF0, 0xC0, 0x2F, 0xF7, 0x39, 0xA0, 0x89, 0x7F, 0xEB, 0x01, 0x18, 0x88, 0x5A, 0xF1, 0xE5, 0xC4, - 0x40, 0x74, 0xC4, 0x00, 0xD0, 0x8C, 0x85, 0x03, 0x18, 0xD0, 0x21, 0x02, 0xD4, 0xA1, 0x98, 0xA2, - 0x8A, 0x10, 0x28, 0xF0, 0x00, 0x5C, 0x08, 0x30, 0xA8, 0x8F, 0x33, 0x2A, 0x5A, 0x46, 0x40, 0x02, - 0x27, 0xEA, 0xF8, 0x99, 0x8A, 0x88, 0x39, 0xA3, 0x13, 0x66, 0x34, 0xC5, 0x48, 0xC2, 0x2C, 0x29, - 0x15, 0x79, 0x9D, 0x7A, 0x15, 0xAA, 0xB8, 0x80, 0x6F, 0x39, 0xA1, 0x64, 0x9E, 0x94, 0x00, 0xF4, - 0x67, 0x65, 0x5E, 0x4C, 0x65, 0x79, 0x9D, 0x4D, 0x0E, 0x20, 0x20, 0xE2, 0x16, 0xCD, 0x09, 0x09, - 0x26, 0x00, 0x84, 0x8C, 0xC9, 0xD5, 0x60, 0xA0, 0x9D, 0x89, 0xC0, 0x84, 0x88, 0xDD, 0xF6, 0x66, - 0x0A, 0xCC, 0xC9, 0x79, 0x25, 0x7B, 0xE8, 0x34, 0xB4, 0x4A, 0x30, 0x06, 0xEE, 0x29, 0xC6, 0x03, - 0xF7, 0xF9, 0x69, 0xE5, 0x63, 0x04, 0xC4, 0x84, 0x98, 0x48, 0x86, 0x9A, 0x40, 0xD1, 0x56, 0x8A, - 0x56, 0x66, 0x40, 0x03, 0x52, 0xB0, 0x94, 0xE8, 0xA0, 0x1A, 0x45, 0x7A, 0x42, 0x01, 0xBE, 0x51, - 0x56, 0x29, 0x57, 0x97, 0x1A, 0x20, 0x6A, 0x65, 0x2B, 0x61, 0xE5, 0xA9, 0x3B, 0x09, 0x10, 0x50, - 0xE5, 0xA8, 0xA3, 0x0E, 0xA0, 0xDD, 0xAA, 0x27, 0x20, 0xA8, 0x1A, 0xAC, 0xB8, 0x0E, 0x42, 0xEB, - 0x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 0x25, 0x00, 0x52, 0x8B, 0x3C, 0xF8, - 0x42, 0x01, 0x5A, 0x1C, 0x62, 0x44, 0x86, 0x6B, 0x69, 0x46, 0x40, 0x87, 0x1E, 0x06, 0x02, 0x84, - 0x88, 0x33, 0x14, 0xF3, 0x57, 0x00, 0x6D, 0x09, 0x10, 0xC0, 0x09, 0x29, 0x2E, 0xE1, 0x80, 0x6B, - 0x6A, 0xC4, 0x80, 0x90, 0x66, 0x80, 0x69, 0xA6, 0xC0, 0x03, 0x0E, 0xD6, 0x28, 0x02, 0x04, 0x0C, - 0x28, 0xC2, 0xE2, 0x0A, 0x1C, 0xF9, 0xE0, 0xCE, 0x3E, 0x05, 0x94, 0xE6, 0x00, 0x02, 0x11, 0x68, - 0x21, 0xA4, 0x0C, 0x35, 0xB1, 0x11, 0x94, 0x49, 0x09, 0x35, 0xF0, 0x24, 0x0E, 0x48, 0x35, 0x61, - 0x4A, 0x93, 0x29, 0x4C, 0x69, 0xC4, 0x01, 0x42, 0x30, 0x70, 0x25, 0x1E, 0x20, 0x26, 0x44, 0x40, - 0x94, 0x0C, 0x38, 0xC4, 0x44, 0x13, 0x99, 0x1C, 0x10, 0x9B, 0x98, 0x34, 0x98, 0xC0, 0x4E, 0x9B, - 0x56, 0x74, 0x54, 0x08, 0x3B, 0x99, 0xB8, 0xF0, 0x48, 0x13, 0x4D, 0x88, 0x45, 0x27, 0x12, 0x0A, - 0x99, 0x83, 0x8A, 0x40, 0x73, 0xBE, 0x60, 0x57, 0x13, 0xA1, 0x0D, 0xFA, 0xD2, 0x6C, 0x93, 0x91, - 0x10, 0x02, 0x00, 0x21, 0xF9, 0x04, 0x09, 0x0A, 0x00, 0x00, 0x00, 0x2C, 0x00, 0x00, 0x20, 0x00, - 0x6A, 0x00, 0x2E, 0x00, 0x00, 0x05, 0xFF, 0x20, 0x00, 0x40, 0x62, 0xB9, 0x28, 0x08, 0x41, 0x28, - 0x4B, 0xE9, 0xBE, 0x70, 0x2C, 0xCF, 0x74, 0x6D, 0xDF, 0xE5, 0xF1, 0x3C, 0x69, 0x52, 0x24, 0x0F, - 0x82, 0xE1, 0x60, 0x00, 0x26, 0x5A, 0xB8, 0xA4, 0x72, 0xC9, 0x94, 0xE9, 0x22, 0x12, 0xC9, 0x64, - 0xF2, 0x18, 0x04, 0xAE, 0xD7, 0x01, 0xB0, 0xD0, 0xEC, 0x7A, 0xBF, 0x31, 0x48, 0x61, 0x12, 0x95, - 0x32, 0x02, 0x8E, 0x06, 0x36, 0x70, 0x50, 0x21, 0xC1, 0xF0, 0x78, 0x72, 0x91, 0x20, 0x4B, 0x55, - 0x85, 0xF5, 0xB5, 0x81, 0xE0, 0xCA, 0xFF, 0x80, 0x32, 0x0D, 0x0F, 0x53, 0x11, 0x11, 0x04, 0x07, - 0x7A, 0x57, 0x0E, 0x04, 0x6F, 0x81, 0x8F, 0x7F, 0x0B, 0x2A, 0x06, 0x94, 0x6A, 0x8A, 0x01, 0x06, - 0x04, 0x05, 0x07, 0x0B, 0x0B, 0x44, 0x94, 0xA0, 0x43, 0x24, 0x90, 0xA4, 0x37, 0x05, 0x04, 0x96, - 0x97, 0x58, 0x45, 0x09, 0x0A, 0x0C, 0x0C, 0x0A, 0x05, 0x0D, 0xB3, 0x05, 0x0A, 0x09, 0x0C, 0x05, - 0x06, 0xA3, 0x4D, 0x9F, 0xA0, 0x0B, 0xBB, 0xA5, 0x33, 0x6D, 0x08, 0x0C, 0x89, 0xAA, 0xC7, 0x8A, - 0x07, 0xAE, 0x3E, 0xC0, 0x32, 0x10, 0x07, 0x3F, 0x2A, 0x0E, 0x8C, 0x2A, 0x08, 0xD6, 0x29, 0x0E, - 0xB9, 0xCD, 0xC1, 0x22, 0x10, 0x45, 0xD2, 0xB8, 0x07, 0x56, 0x97, 0x22, 0xC8, 0x01, 0x0D, 0x0C, - 0x3E, 0x9C, 0x25, 0xCF, 0xA7, 0x04, 0xD9, 0xE2, 0xC8, 0x03, 0xD0, 0x09, 0x04, 0xD6, 0x09, 0xBA, - 0xDC, 0x30, 0x10, 0x0B, 0x06, 0xB6, 0x2A, 0x04, 0x12, 0xDC, 0x52, 0x40, 0x90, 0x60, 0x81, 0x5C, - 0x07, 0x20, 0xA8, 0x1A, 0xD0, 0x20, 0x01, 0x35, 0x07, 0x3C, 0x1C, 0x18, 0x30, 0x87, 0xCC, 0x00, - 0x03, 0x02, 0x0F, 0x12, 0x34, 0xD8, 0xA6, 0xCF, 0x44, 0xA7, 0x8F, 0x9D, 0x0E, 0x88, 0xAC, 0x75, - 0x6B, 0x22, 0xC5, 0x4B, 0x44, 0x4E, 0xFF, 0x26, 0x63, 0x80, 0x20, 0xE3, 0x81, 0x8E, 0x5D, 0x0E, - 0xA4, 0x33, 0xA6, 0x92, 0x8D, 0x03, 0x04, 0x35, 0x2F, 0x35, 0xC0, 0x98, 0xE0, 0x25, 0x4C, 0x26, - 0x07, 0x7C, 0xE4, 0xBC, 0x82, 0x40, 0xE1, 0x50, 0x3D, 0xCA, 0x52, 0x38, 0xFA, 0x89, 0xE3, 0x47, - 0xCE, 0x1F, 0x00, 0x8E, 0xAA, 0x02, 0xC2, 0x80, 0xE9, 0x92, 0x86, 0x2A, 0x0D, 0x3C, 0xA0, 0x29, - 0x55, 0xD1, 0x00, 0x8C, 0x06, 0xAC, 0x26, 0x31, 0x80, 0xC0, 0x24, 0x32, 0x04, 0x09, 0xBA, 0x9A, - 0x1B, 0x94, 0x80, 0xA3, 0x58, 0x18, 0x5A, 0xCF, 0x1C, 0x13, 0x78, 0x69, 0x9C, 0xDA, 0x2C, 0x04, - 0x22, 0x34, 0x78, 0x6B, 0x03, 0x82, 0x02, 0x44, 0x97, 0x5E, 0xD5, 0x1D, 0x60, 0xF7, 0xEE, 0xB9, - 0x07, 0x61, 0xF9, 0xD6, 0x58, 0xC0, 0x20, 0xDB, 0x1A, 0x82, 0x0B, 0x09, 0x17, 0xBE, 0xFB, 0x55, - 0x81, 0xE2, 0x1B, 0x99, 0x10, 0x39, 0xF6, 0x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 0x16, 0x79, 0x11, - 0xF4, 0x11, 0x0B, 0x42, 0x62, 0x41, 0x70, 0xCB, 0x73, 0x1E, 0x0E, 0xE5, 0x20, 0x70, 0x7B, 0x10, - 0x40, 0x58, 0x5E, 0xC4, 0xE4, 0x23, 0x42, 0x02, 0x86, 0x34, 0xA2, 0x98, 0x24, 0x0A, 0x00, 0x19, - 0x63, 0x4E, 0xFD, 0x10, 0x43, 0x93, 0x32, 0x79, 0xF1, 0x90, 0x42, 0x88, 0x2E, 0x2C, 0xF0, 0x80, - 0x21, 0x0F, 0x30, 0x00, 0x5F, 0x30, 0x62, 0xF4, 0xB1, 0x61, 0x90, 0x47, 0x39, 0x18, 0xCB, 0x3F, - 0xEF, 0xF8, 0x60, 0xC0, 0x2F, 0x36, 0x3C, 0xB1, 0x22, 0x53, 0x99, 0x20, 0x90, 0x08, 0x9A, 0x5D, - 0x79, 0xD9, 0x80, 0x00, 0x29, 0xB4, 0xD6, 0x04, 0x59, 0x2C, 0xFC, 0x24, 0x13, 0x2A, 0x78, 0x76, - 0xF5, 0x95, 0x03, 0x0C, 0xA0, 0xA6, 0xA3, 0x17, 0x6E, 0x3D, 0xB2, 0xC0, 0x0F, 0x0A, 0x10, 0xB9, - 0xDA, 0x39, 0x08, 0x08, 0x90, 0x86, 0x00, 0x4E, 0x2E, 0x17, 0x86, 0x3B, 0xA5, 0x4D, 0xAA, 0x87, - 0x42, 0xAF, 0x0C, 0xE2, 0x00, 0xA6, 0x63, 0x8A, 0xF6, 0xA8, 0x0A, 0x91, 0x06, 0xF0, 0x4B, 0x9E, - 0xCE, 0x29, 0xF2, 0x17, 0x4B, 0x96, 0x16, 0x50, 0xA9, 0x9F, 0x9A, 0x02, 0x50, 0x00, 0x23, 0x81, - 0x9E, 0x1A, 0x41, 0x94, 0x47, 0x31, 0x10, 0xE6, 0x01, 0xD3, 0x98, 0xA5, 0x10, 0x2A, 0x2D, 0xF1, - 0x21, 0x46, 0x40, 0xB5, 0xDA, 0x8A, 0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x96, 0xD2, 0x6B, 0x50, 0xE0, - 0x5E, 0x2E, 0x05, 0x29, 0x36, 0x05, 0x0E, 0x65, 0xE3, 0x66, 0x4A, 0x7D, 0x73, 0xA3, 0x2D, 0x60, - 0x90, 0xE5, 0x44, 0x0A, 0x66, 0xA4, 0xAB, 0x3D, 0x78, 0xB0, 0xC8, 0xCA, 0xDE, 0x94, 0x14, 0x7F, - 0x07, 0x28, 0x07, 0x79, 0x23, 0x52, 0xA5, 0xB0, 0xE8, 0x35, 0x03, 0x06, 0x04, 0x05, 0x30, 0x4A, - 0x2A, 0x68, 0x4E, 0xE2, 0x5D, 0x0B, 0x2D, 0x9A, 0x66, 0x0F, 0xEA, 0x35, 0x43, 0x53, 0x20, 0xC1, - 0x56, 0x93, 0x61, 0x78, 0xF6, 0xAC, 0xD9, 0xCF, 0x40, 0xE9, 0x3D, 0x20, 0x23, 0x10, 0x03, 0x80, - 0x54, 0x23, 0x00, 0x4C, 0x2A, 0x14, 0xE5, 0x25, 0xC1, 0xCC, 0x01, 0xBD, 0xE2, 0x26, 0x0F, 0x28, - 0xA2, 0xCC, 0x0C, 0x45, 0xEC, 0x30, 0x0D, 0x98, 0x97, 0xDD, 0x24, 0x04, 0x49, 0xC6, 0x0A, 0x02, - 0xC8, 0xB1, 0x50, 0xD4, 0xAA, 0x5A, 0xEE, 0x24, 0x48, 0x19, 0x00, 0xE4, 0xF4, 0xA0, 0xC0, 0x28, - 0x0A, 0xB0, 0xE2, 0x1B, 0x0D, 0x33, 0xA9, 0x25, 0x00, 0x52, 0x8B, 0x3C, 0xF8, 0x42, 0x01, 0x5A, - 0x1C, 0x62, 0x44, 0x86, 0x6B, 0x69, 0x46, 0x40, 0x87, 0x1E, 0x06, 0x02, 0x84, 0x88, 0x33, 0x14, - 0xF3, 0x57, 0x00, 0x6D, 0x09, 0x10, 0xC0, 0x09, 0x29, 0x2E, 0xE1, 0x80, 0x6B, 0x6A, 0xC4, 0x80, - 0x90, 0x66, 0x80, 0x69, 0xA6, 0xC0, 0x03, 0x0E, 0xD6, 0x28, 0x02, 0x04, 0x0C, 0x28, 0xC2, 0xE2, - 0x0A, 0x1C, 0xF9, 0xE0, 0xCE, 0x3E, 0x05, 0x94, 0xE6, 0x00, 0x02, 0x11, 0x68, 0x21, 0xA4, 0x0C, - 0x35, 0xB1, 0x11, 0x94, 0x49, 0x09, 0x35, 0xF0, 0x24, 0x0E, 0x48, 0x35, 0x61, 0x4A, 0x93, 0x29, - 0x4C, 0x69, 0xC4, 0x01, 0x42, 0x30, 0x70, 0x25, 0x1E, 0x20, 0x26, 0x44, 0x40, 0x94, 0x0C, 0x38, - 0xC4, 0x44, 0x13, 0x99, 0x1C, 0x10, 0x9B, 0x98, 0x34, 0x98, 0xC0, 0x4E, 0x9B, 0x56, 0x74, 0x54, - 0x08, 0x3B, 0x99, 0xB8, 0xF0, 0x48, 0x13, 0x4D, 0x88, 0x45, 0x27, 0x12, 0x0A, 0x99, 0x83, 0x8A, - 0x40, 0x73, 0xBE, 0x60, 0x57, 0x13, 0xA1, 0x0D, 0xFA, 0xD2, 0x6C, 0x93, 0x91, 0x10, 0x02, 0x00, - 0x21, 0xF9, 0x04, 0x09, 0x0A, 0x00, 0x00, 0x00, 0x2C, 0x00, 0x00, 0x17, 0x00, 0x6A, 0x00, 0x32, - 0x00, 0x00, 0x05, 0xFF, 0x20, 0x20, 0x8E, 0x64, 0x69, 0x9E, 0x68, 0xAA, 0x8A, 0x85, 0x02, 0xAD, - 0x70, 0x2C, 0xCF, 0x74, 0x5D, 0x26, 0x0C, 0x63, 0xD8, 0x7C, 0xEF, 0xFF, 0xA2, 0x05, 0x21, 0x80, - 0x58, 0x2C, 0x70, 0x0B, 0xA0, 0x72, 0xC9, 0x64, 0x34, 0x0C, 0x89, 0x86, 0x42, 0xC8, 0xAC, 0x5A, - 0x6B, 0x54, 0x46, 0x81, 0x11, 0x70, 0x5E, 0xBF, 0x60, 0x94, 0xA2, 0xB0, 0x40, 0x10, 0x00, 0x86, - 0x73, 0x23, 0x71, 0x08, 0xBB, 0xAF, 0x90, 0x73, 0xE2, 0x11, 0x28, 0x97, 0x1B, 0xBA, 0xB7, 0x7E, - 0xA9, 0x68, 0x04, 0x0A, 0x01, 0x01, 0x04, 0x39, 0x01, 0x50, 0x7B, 0x87, 0x3E, 0x0B, 0x5C, 0x81, - 0x5D, 0x0F, 0x03, 0x01, 0x78, 0x69, 0x05, 0x88, 0x94, 0x33, 0x0C, 0x8F, 0x8C, 0x0B, 0x81, 0x5A, - 0x08, 0x06, 0x2D, 0x3F, 0x0A, 0x0A, 0x33, 0x0B, 0x63, 0x0D, 0x49, 0x95, 0x26, 0x2D, 0x8C, 0xAB, - 0x05, 0x04, 0x7E, 0x0D, 0x67, 0x3C, 0x10, 0x09, 0x0A, 0x0C, 0x26, 0x10, 0x0E, 0x83, 0x05, 0x07, - 0x0B, 0x69, 0x0F, 0xB4, 0x0E, 0x0F, 0x9D, 0xA8, 0x24, 0x06, 0x08, 0xAB, 0xC8, 0x81, 0xA1, 0x3C, - 0x07, 0x0E, 0x6B, 0x6D, 0x25, 0x06, 0x11, 0x11, 0x12, 0x13, 0x13, 0x0F, 0x11, 0x80, 0xAC, 0xC2, - 0xD0, 0xA8, 0x65, 0x01, 0x98, 0xC9, 0x10, 0x66, 0x0E, 0x93, 0x32, 0x07, 0x38, 0x02, 0x0C, 0xB4, - 0xA2, 0x25, 0x07, 0x08, 0x13, 0x12, 0xF2, 0x13, 0x06, 0x7F, 0x07, 0xDB, 0xED, 0x95, 0xDF, 0xE1, - 0xC9, 0x63, 0x71, 0xDD, 0x29, 0x8E, 0xB8, 0x12, 0xA0, 0x2E, 0x94, 0x03, 0x14, 0xB0, 0xE4, 0x55, - 0x53, 0x80, 0x40, 0x01, 0xB2, 0x01, 0xB9, 0x4E, 0x21, 0x3A, 0x30, 0x64, 0x00, 0xBF, 0x64, 0x0B, - 0x1E, 0x48, 0x3C, 0x41, 0x2A, 0x0A, 0xC1, 0x8F, 0x05, 0x8A, 0x04, 0x74, 0x10, 0x4F, 0x42, 0x84, - 0x07, 0x0E, 0x93, 0xFF, 0x35, 0x40, 0x60, 0xEE, 0x90, 0x14, 0x70, 0x17, 0x91, 0x29, 0x48, 0x80, - 0x62, 0xC1, 0x16, 0x05, 0x1F, 0x73, 0x12, 0x9C, 0xB9, 0xA2, 0x40, 0x04, 0x04, 0x09, 0x82, 0x6A, - 0x4B, 0xC6, 0x80, 0x80, 0x81, 0x17, 0x7A, 0x0A, 0xD4, 0xB3, 0x18, 0x33, 0x10, 0x84, 0x5F, 0x6C, - 0x48, 0xB4, 0x1A, 0xA8, 0x53, 0x67, 0x82, 0x1D, 0x2B, 0x84, 0x2C, 0x4A, 0xB6, 0xEA, 0xC0, 0x4C, - 0x1C, 0xA6, 0x20, 0x20, 0xB5, 0x32, 0x05, 0x66, 0xD3, 0x40, 0x07, 0xA0, 0xD8, 0x12, 0xD1, 0xE0, - 0x41, 0x83, 0xAA, 0x55, 0x61, 0x31, 0xC8, 0xA7, 0x82, 0xA1, 0x83, 0x7A, 0x5C, 0x19, 0x41, 0x48, - 0xDB, 0x22, 0x47, 0xD0, 0xA3, 0x4C, 0x52, 0x32, 0x3D, 0x0B, 0x0E, 0x01, 0x34, 0x03, 0x6E, 0xE1, - 0xC2, 0xC5, 0x43, 0x57, 0x05, 0x04, 0x28, 0x04, 0x1C, 0x38, 0xB9, 0x97, 0x17, 0xD9, 0x81, 0x02, - 0x7F, 0xC7, 0xF6, 0x48, 0x10, 0x68, 0x80, 0x00, 0x8B, 0x95, 0x73, 0x8D, 0x38, 0xB0, 0xEE, 0xAD, - 0xE2, 0x8F, 0x0A, 0x08, 0x00, 0x94, 0x01, 0xA1, 0x17, 0x66, 0x02, 0xB0, 0x71, 0x84, 0x52, 0x9A, - 0x97, 0xB4, 0xEA, 0x1F, 0x07, 0xC1, 0x11, 0x24, 0xDC, 0xC0, 0xC1, 0x18, 0x00, 0xA4, 0x10, 0x30, - 0x38, 0x8D, 0xDA, 0x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, 0xB5, 0xE6, 0x8A, 0xD0, 0xE3, 0x25, 0xC8, 0x20, 0x4B, 0xE6, 0x23, 0x59, 0xAE, 0xF7, - 0x8E, 0xAA, 0xF1, 0x92, 0x30, 0xA9, 0xB1, 0x29, 0xA0, 0x9A, 0x80, 0x6F, 0x7D, 0x98, 0x9A, 0x56, - 0xA6, 0x0F, 0xC0, 0xDB, 0x2F, 0x09, 0x3E, 0x3A, 0x60, 0x6C, 0x00, 0x23, 0x5C, 0xD9, 0x9B, 0x9A, - 0x0E, 0x4C, 0x33, 0x8D, 0x30, 0x47, 0x16, 0x30, 0xEC, 0xC2, 0xC0, 0xF9, 0x68, 0xD4, 0x75, 0xA4, - 0x6D, 0xA2, 0xE6, 0x91, 0x06, 0x9C, 0xF2, 0x8E, 0xC5, 0x51, 0x2C, 0xCB, 0x71, 0x09, 0x8C, 0x0E, - 0x92, 0xA8, 0x57, 0x27, 0xA9, 0xF9, 0xCB, 0x97, 0x19, 0xC5, 0xCC, 0xD2, 0xCA, 0x33, 0x78, 0x35, - 0xF0, 0x8B, 0xB9, 0xE8, 0x52, 0xF2, 0x02, 0x1B, 0x93, 0xA2, 0x32, 0xCE, 0x30, 0xB4, 0x36, 0xB4, - 0x0D, 0x21, 0x00, 0x00, 0x3B}; +#include + +static const uint8_t firebase_png[] PROGMEM = { + 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00, 0x00, 0x00, 0x0D, 0x49, 0x48, 0x44, 0x52, + 0x00, 0x00, 0x03, 0x20, 0x00, 0x00, 0x02, 0x58, 0x08, 0x06, 0x00, 0x00, 0x00, 0x9A, 0x76, 0x82, + 0x70, 0x00, 0x00, 0x00, 0x01, 0x73, 0x52, 0x47, 0x42, 0x00, 0xAE, 0xCE, 0x1C, 0xE9, 0x00, 0x00, + 0x00, 0x04, 0x67, 0x41, 0x4D, 0x41, 0x00, 0x00, 0xB1, 0x8F, 0x0B, 0xFC, 0x61, 0x05, 0x00, 0x00, + 0x00, 0x09, 0x70, 0x48, 0x59, 0x73, 0x00, 0x00, 0x0E, 0xC3, 0x00, 0x00, 0x0E, 0xC3, 0x01, 0xC7, + 0x6F, 0xA8, 0x64, 0x00, 0x00, 0x55, 0x14, 0x49, 0x44, 0x41, 0x54, 0x78, 0x5E, 0xED, 0xDD, 0x59, + 0x90, 0x1D, 0xF5, 0x81, 0xE7, 0x7B, 0x3F, 0xF4, 0xC3, 0x84, 0x91, 0x40, 0x6E, 0xEF, 0xC6, 0x8B, + 0x30, 0x92, 0x4A, 0x1B, 0x58, 0x98, 0xCD, 0xA0, 0xA5, 0x4A, 0x12, 0x20, 0x6C, 0x9A, 0xB6, 0xBA, + 0x01, 0x63, 0x4F, 0x3F, 0x8C, 0x1E, 0x26, 0xC2, 0xF7, 0xE5, 0xC6, 0x25, 0xE2, 0xDE, 0x97, 0x3B, + 0x7D, 0x67, 0xAC, 0x6E, 0x63, 0x63, 0x83, 0x8D, 0xBC, 0xB1, 0x99, 0xA5, 0x10, 0x08, 0xED, 0x52, + 0x69, 0xAD, 0x92, 0xA0, 0xBB, 0xAB, 0xA7, 0xED, 0x6E, 0x77, 0xB7, 0x81, 0x42, 0x9B, 0x99, 0x89, + 0x89, 0xDB, 0x9A, 0xB9, 0x0E, 0x2F, 0x2C, 0x76, 0x61, 0x16, 0x49, 0x85, 0xA4, 0xFC, 0xDF, 0xFF, + 0x3F, 0x4F, 0xE6, 0xA9, 0x3C, 0x79, 0x7E, 0xE7, 0x9C, 0xCC, 0x3C, 0x99, 0x75, 0xCE, 0xC9, 0xFA, + 0x7E, 0x22, 0x7E, 0xA1, 0x6E, 0x2F, 0x42, 0xC2, 0x94, 0xE2, 0xFF, 0x8D, 0x7F, 0x65, 0x9E, 0xF7, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x28, 0x82, 0x79, 0x6E, 0xCD, 0x80, 0xBF, 0xC3, 0x5F, 0x58, 0x12, 0xFC, + 0x4B, 0x00, 0x00, 0x00, 0x00, 0x90, 0x1F, 0x73, 0x78, 0xCD, 0x3A, 0xEF, 0xB9, 0x35, 0x63, 0xE6, + 0xB9, 0x9B, 0x4D, 0x75, 0xCF, 0xAE, 0xF1, 0xE7, 0x3D, 0x7B, 0xD3, 0xA0, 0x0B, 0x92, 0xE0, 0x3F, + 0x0A, 0x00, 0x00, 0x00, 0x00, 0xD9, 0x98, 0x91, 0x35, 0xB3, 0xEB, 0xC2, 0x23, 0x12, 0x1F, 0xD1, + 0x79, 0x87, 0xD7, 0x6C, 0x08, 0xFE, 0x6B, 0x00, 0x00, 0x00, 0x00, 0x90, 0x8E, 0xFB, 0x16, 0x2B, + 0xEF, 0xD9, 0x35, 0xE3, 0x95, 0xE0, 0xB8, 0xD1, 0x98, 0x03, 0x57, 0x19, 0xB3, 0x7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 0x68, + 0x35, 0x11, 0x19, 0xAD, 0x76, 0xA8, 0xDF, 0x3D, 0x90, 0x3E, 0x18, 0xFC, 0xA5, 0x01, 0x00, 0x00, + 0x00, 0x4C, 0x37, 0xDE, 0x81, 0x6B, 0x46, 0x75, 0x60, 0x34, 0x9B, 0x88, 0x8B, 0x56, 0xDB, 0xFA, + 0x21, 0x63, 0x86, 0xE6, 0x57, 0x5E, 0xCB, 0x3B, 0xB2, 0x66, 0x76, 0xF0, 0x97, 0x07, 0x00, 0x00, + 0x00, 0x30, 0x9D, 0x98, 0x03, 0x57, 0xDB, 0x40, 0x50, 0x91, 0xD1, 0x68, 0x22, 0x2E, 0x5A, 0xCD, + 0xC5, 0x47, 0x38, 0x6E, 0x41, 0x00, 0x00, 0x00, 0x80, 0xE9, 0xC9, 0xDD, 0x44, 0x98, 0x7D, 0x9F, + 0xB1, 0x91, 0xA0, 0x42, 0x43, 0x4D, 0xC4, 0x45, 0xAB, 0x45, 0xE3, 0xC3, 0x6D, 0xF7, 0xDC, 0xCA, + 0x2D, 0xC8, 0x73, 0xAB, 0x07, 0x82, 0x5F, 0x06, 0x00, 0x00, 0x00, 0x80, 0xE9, 0xC0, 0x3C, 0xB7, + 0x66, 0xC0, 0xEC, 0x9E, 0x67, 0x43, 0x41, 0xC5, 0x46, 0x7C, 0x22, 0x2E, 0x5A, 0x2D, 0x1E, 0x1F, + 0xE1, 0x86, 0xAF, 0x73, 0x0F, 0xA4, 0x8F, 0x06, 0xBF, 0x0C, 0x00, 0x00, 0x00, 0x00, 0xD3, 0x81, + 0xF7, 0xEC, 0x4D, 0x77, 0x99, 0x9D, 0x97, 0xD8, 0x58, 0x50, 0xC1, 0x11, 0x9D, 0x88, 0x8B, 0x56, + 0x53, 0xE1, 0x11, 0x6E, 0xD7, 0xA7, 0xB9, 0x05, 0x01, 0x00, 0x00, 0x00, 0xA6, 0x1B, 0xEF, 0xF0, + 0x8D, 0x1B, 0x74, 0x70, 0x44, 0x27, 0xE2, 0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, 0x3C, 0x76, 0x91, 0x39, 0xFD, 0xA8, + 0x0D, 0x8E, 0x36, 0x6F, 0x3F, 0x74, 0x48, 0x64, 0x99, 0x08, 0x89, 0x2C, 0x23, 0x3E, 0x72, 0x98, + 0x0A, 0x87, 0x3C, 0x26, 0x02, 0xA2, 0xDD, 0xB9, 0x37, 0x61, 0x1D, 0xBF, 0x63, 0x49, 0xF0, 0xE5, + 0x08, 0x00, 0x00, 0x50, 0x7E, 0x66, 0x68, 0xBE, 0x8D, 0x02, 0x15, 0x18, 0xCD, 0x26, 0xA2, 0x22, + 0xE9, 0x54, 0x78, 0x44, 0x96, 0xE8, 0xF6, 0x23, 0x88, 0x8F, 0x76, 0x6F, 0x3F, 0x74, 0x48, 0x64, + 0x99, 0x08, 0x89, 0x2C, 0x23, 0x3E, 0x72, 0x98, 0x0A, 0x87, 0x3C, 0x26, 0xE2, 0x21, 0x8F, 0xBD, + 0x78, 0x1D, 0x6F, 0xC2, 0x02, 0x00, 0x00, 0xD3, 0x87, 0xFF, 0x06, 0xAC, 0x5D, 0x9F, 0xB6, 0x61, + 0xA0, 0x22, 0xA3, 0xD1, 0x44, 0x54, 0x24, 0x9D, 0x08, 0x8E, 0xEA, 0x92, 0xDE, 0x7E, 0x3C, 0x6E, + 0x03, 0x24, 0x8C, 0x8F, 0x68, 0x80, 0xFC, 0x80, 0xF8, 0x20, 0x3E, 0x54, 0x38, 0xE4, 0x31, 0x11, + 0x0E, 0x79, 0xED, 0x85, 0xAB, 0x78, 0x13, 0x16, 0x00, 0x00, 0x98, 0x3E, 0xCC, 0xA1, 0xFE, 0xB5, + 0x66, 0xC7, 0xC7, 0x6D, 0x1C, 0xA8, 0xD0, 0x50, 0x13, 0x51, 0x91, 0x74, 0x2A, 0x3A, 0x62, 0x53, + 0xB7, 0x1F, 0xD1, 0x00, 0xF1, 0xE3, 0xA3, 0xD1, 0xED, 0xC7, 0x37, 0x75, 0x68, 0xA8, 0xE9, 0x90, + 0xC8, 0x32, 0x11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0xF0, 0x53, 0x01, 0x00, 0x00, 0x00, 0x40, 0x3A, 0xEE, 0x35, + 0xB9, 0xFE, 0x07, 0x1B, 0xEE, 0xE8, 0x1B, 0x88, 0xEF, 0xDF, 0x36, 0xCC, 0xEE, 0x0B, 0xFE, 0x63, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xD0, 0x15, 0xDE, 0xF3, 0x9E, 0xFF, 0x1F, 0x5B, 0xE2, 0x94, 0x1D, 0x86, + 0x86, 0x23, 0x09, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4E, 0x44, 0xAE, 0x42, 0x60, 0x82}; + +static const uint8_t tree_gif[] PROGMEM = { + + 0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x28, 0x00, 0x3C, 0x00, 0x83, 0x0B, 0x00, 0x00, 0xFF, 0xFF, + 0x00, 0x21, 0x00, 0x00, 0x4A, 0x00, 0x00, 0x6B, 0x00, 0x00, 0x94, 0x00, 0x00, 0xB5, 0x00, 0x00, + 0xDE, 0x00, 0x00, 0xFF, 0x00, 0x6B, 0x00, 0x00, 0xFF, 0x33, 0x33, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, + 0xFF, 0xFF, 0xCC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x99, 0x00, 0xCC, 0x00, 0x00, 0x21, 0xFF, 0x0B, + 0x4E, 0x45, 0x54, 0x53, 0x43, 0x41, 0x50, 0x45, 0x32, 0x2E, 0x30, 0x03, 0x01, 0xA0, 0x0F, 0x00, + 0x21, 0xF9, 0x04, 0x09, 0x14, 0x00, 0x0B, 0x00, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x28, 0x00, 0x3C, + 0x00, 0x03, 0x04, 0xFB, 0x70, 0xC9, 0x49, 0x6B, 0x75, 0x36, 0xEB, 0xBD, 0x31, 0xFF, 0xA0, 0xE4, + 0x8C, 0xCA, 0xE8, 0x85, 0xE8, 0xA5, 0xAC, 0x67, 0xEA, 0x8A, 0xE5, 0x2B, 0x2F, 0xE3, 0x31, 0xCE, + 0xAF, 0x41, 0x1C, 0xB8, 0x1B, 0x24, 0x80, 0x04, 0xAF, 0x87, 0x02, 0x26, 0x88, 0xA1, 0x07, 0x60, + 0xB9, 0x44, 0x82, 0x04, 0x02, 0x80, 0x61, 0x30, 0x70, 0x6E, 0x0C, 0x86, 0x03, 0x60, 0x20, 0xB0, + 0x6A, 0xA8, 0xD3, 0x03, 0x21, 0xEC, 0xAD, 0x18, 0x12, 0xE8, 0xF4, 0xB1, 0x4C, 0x51, 0xA0, 0x07, + 0xEA, 0x07, 0x5B, 0xF2, 0x70, 0x13, 0x76, 0xD4, 0xA8, 0xBC, 0xBC, 0xEA, 0x1F, 0x06, 0x77, 0x51, + 0x73, 0x50, 0x0A, 0x80, 0x7F, 0x04, 0x4C, 0x4D, 0x65, 0x06, 0x0A, 0x3B, 0x3B, 0x62, 0x5A, 0x53, + 0x65, 0x05, 0x02, 0x04, 0x68, 0x0C, 0x6A, 0x00, 0x5D, 0x5E, 0x0F, 0x0F, 0x6A, 0x98, 0x6A, 0x09, + 0x7B, 0x56, 0x9D, 0x09, 0x0C, 0xA7, 0xA7, 0x7F, 0x06, 0x9D, 0xA3, 0x44, 0x02, 0x01, 0x03, 0x90, + 0x0C, 0x87, 0x03, 0x06, 0x02, 0x05, 0x56, 0x06, 0x01, 0x02, 0x53, 0xB1, 0xB3, 0x04, 0x79, 0xAF, + 0x55, 0x48, 0x51, 0xB0, 0x87, 0xC0, 0x7F, 0x07, 0x95, 0x05, 0x85, 0x44, 0xB6, 0x00, 0x05, 0x53, + 0x96, 0x6A, 0x60, 0x02, 0x0A, 0x48, 0x89, 0x00, 0x07, 0xA1, 0x69, 0x7D, 0x2B, 0x3D, 0x9D, 0x41, + 0xA1, 0x04, 0xA0, 0xDD, 0x9D, 0x38, 0x02, 0xE1, 0x6A, 0x07, 0x62, 0x0C, 0x77, 0xE6, 0xAD, 0x2F, + 0x05, 0x01, 0xB6, 0x90, 0x07, 0xA8, 0xA7, 0x54, 0xB5, 0xBC, 0x06, 0x33, 0x50, 0x53, 0x3A, 0x00, + 0x39, 0x62, 0x10, 0x6B, 0xDF, 0xBE, 0x19, 0x03, 0x18, 0x40, 0xA9, 0x15, 0x4B, 0xCC, 0x0E, 0x77, + 0x3B, 0x04, 0xC4, 0x02, 0x38, 0x43, 0x21, 0x96, 0x2C, 0xD3, 0xD6, 0x81, 0x01, 0x26, 0x2A, 0xFB, + 0xDE, 0x07, 0x7C, 0x0A, 0xB7, 0x71, 0x1B, 0x79, 0xEE, 0xC5, 0x83, 0x72, 0xDD, 0x84, 0xBC, 0x4B, + 0x13, 0xA4, 0x13, 0x15, 0x17, 0xAB, 0x18, 0x78, 0x4A, 0x43, 0x40, 0x81, 0x43, 0x76, 0x8E, 0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x30, 0x06, 0x8A, 0x75, 0x64, 0xFA, 0x42, 0xF1, 0x12, 0xAD, + 0x60, 0xDE, 0x51, 0x0A, 0x94, 0xBA, 0x5E, 0x2C, 0x8C, 0x86, 0xDD, 0x3D, 0xDE, 0x8F, 0x0A, 0x70, + 0x51, 0x5F, 0xFE, 0xF2, 0x84, 0xD1, 0xD0, 0xA6, 0x68, 0xB7, 0x96, 0x62, 0x14, 0x0C, 0xC1, 0xB7, + 0x90, 0x68, 0x72, 0xD1, 0x7C, 0xD9, 0x3D, 0xA3, 0x94, 0x35, 0xDE, 0x54, 0x06, 0x92, 0x51, 0x50, + 0x68, 0xC2, 0xC5, 0x44, 0xB7, 0x30, 0x70, 0xDE, 0x6A, 0x49, 0x69, 0x86, 0xC5, 0x2D, 0xA3, 0x29, + 0x04, 0x05, 0x2F, 0xD9, 0xC4, 0x02, 0x0C, 0x6C, 0x0C, 0x48, 0xB0, 0x94, 0x01, 0xDA, 0x3C, 0xF2, + 0x56, 0x21, 0xFA, 0xE8, 0xA3, 0xA1, 0x55, 0x12, 0xE9, 0xF4, 0x56, 0x42, 0xF8, 0x50, 0x00, 0x40, + 0x08, 0x08, 0xD4, 0x88, 0x80, 0x05, 0x33, 0x66, 0x10, 0xA2, 0x0C, 0xDC, 0xA0, 0xB0, 0xA3, 0x0B, + 0x71, 0xCD, 0xB1, 0x80, 0x75, 0x69, 0x20, 0x41, 0xE4, 0x91, 0x6B, 0x64, 0x10, 0x01, 0x00, 0x21, + 0xF9, 0x04, 0x09, 0x14, 0x00, 0x0B, 0x00, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x28, 0x00, 0x3C, 0x00, + 0x03, 0x04, 0xFB, 0x70, 0xC9, 0x49, 0x6B, 0x75, 0x36, 0xEB, 0xBD, 0x31, 0xFF, 0xA0, 0xE4, 0x8C, + 0xA4, 0x17, 0x9E, 0x57, 0x89, 0xAE, 0xA9, 0xC9, 0xAE, 0xE3, 0x31, 0xBE, 0xAF, 0x31, 0x1C, 0x34, + 0x1B, 0x24, 0x4C, 0x82, 0xE7, 0x28, 0x5E, 0x02, 0x78, 0x7A, 0x30, 0x8E, 0x47, 0x62, 0x48, 0x20, + 0x60, 0xD8, 0x06, 0x4A, 0x8E, 0xC1, 0x70, 0x60, 0x0C, 0x04, 0xD1, 0xCD, 0x60, 0x60, 0x3B, 0x10, + 0xBA, 0x59, 0x8B, 0x21, 0x41, 0x2E, 0x0F, 0xC3, 0x16, 0xF2, 0xC0, 0xAC, 0x40, 0x4F, 0x1E, 0x80, + 0x04, 0x81, 0x70, 0xD8, 0x0A, 0x14, 0x0F, 0xF7, 0x42, 0x00, 0xA0, 0xD6, 0x09, 0x0A, 0x81, 0x81, + 0x68, 0x00, 0x85, 0x85, 0x7F, 0x07, 0x07, 0x0A, 0x06, 0x7A, 0x06, 0x00, 0x74, 0x74, 0x5E, 0x8A, + 0x36, 0x68, 0x05, 0x7C, 0x66, 0x3D, 0x64, 0x58, 0x61, 0x0F, 0x0F, 0x66, 0x64, 0x99, 0x64, 0x79, + 0x9C, 0x9E, 0xA0, 0x48, 0x4E, 0x9D, 0xA3, 0x4A, 0x02, 0x01, 0x37, 0x90, 0x55, 0x04, 0x5C, 0x02, + 0x05, 0x59, 0x06, 0x01, 0x02, 0x4F, 0x89, 0x55, 0x76, 0xAC, 0x50, 0xAB, 0x0A, 0xAD, 0x7F, 0xB1, + 0x75, 0x07, 0x02, 0x04, 0x05, 0x00, 0xBE, 0x39, 0x06, 0x77, 0x05, 0x36, 0x04, 0x9F, 0x5B, 0xCC, + 0x00, 0x4A, 0x82, 0x81, 0x07, 0x9F, 0x65, 0x86, 0x85, 0x40, 0x9D, 0x0A, 0x9F, 0x0C, 0xD0, 0x9F, + 0x00, 0x9D, 0x39, 0x02, 0xDE, 0x66, 0xB0, 0x73, 0xE2, 0x09, 0xE4, 0xAA, 0x2F, 0x05, 0x01, 0xCC, + 0x5E, 0xA7, 0x56, 0x75, 0xD2, 0xB8, 0x8C, 0x2F, 0x4C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23, 0x02, 0x27, 0xE0, 0x58, 0x63, 0x08, 0xD9, + 0xE8, 0x41, 0x81, 0x5B, 0x42, 0x7A, 0x57, 0x86, 0x12, 0x46, 0x26, 0x79, 0x46, 0x06, 0x11, 0x00, + 0x00, 0x21, 0xF9, 0x04, 0x09, 0x14, 0x00, 0x0B, 0x00, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x28, 0x00, + 0x3C, 0x00, 0x03, 0x04, 0xFB, 0x70, 0xC9, 0x49, 0x6B, 0x75, 0x36, 0xEB, 0xBD, 0x31, 0xFF, 0xA0, + 0xE4, 0x8C, 0xA4, 0x17, 0x9E, 0x57, 0x89, 0xAE, 0xA9, 0xC9, 0xAE, 0xE3, 0x31, 0xBE, 0xAF, 0xA1, + 0x1C, 0x34, 0x1B, 0x24, 0x4A, 0x82, 0xE7, 0x27, 0x85, 0x50, 0x08, 0x0C, 0x3D, 0x12, 0xBC, 0xC4, + 0xA3, 0x18, 0x12, 0x08, 0x14, 0x86, 0xC1, 0x80, 0xC9, 0x31, 0x18, 0x0E, 0x84, 0x81, 0x80, 0xBA, + 0x91, 0x46, 0xB1, 0x51, 0x06, 0xD7, 0x62, 0x40, 0x9A, 0x91, 0xE2, 0x71, 0xA5, 0x37, 0x40, 0x33, + 0xDE, 0xE9, 0xF1, 0xE3, 0xA1, 0x20, 0x10, 0x0E, 0x52, 0x01, 0x63, 0xA9, 0x5E, 0x0C, 0x85, 0x03, + 0x76, 0x7A, 0x7D, 0x0B, 0x4E, 0x03, 0x75, 0x78, 0x77, 0x78, 0x06, 0x84, 0x51, 0x37, 0x8A, 0x77, + 0x02, 0x51, 0x6A, 0x05, 0x02, 0x04, 0x67, 0x67, 0x5B, 0x72, 0x47, 0x98, 0x98, 0x7C, 0x5C, 0x73, + 0x66, 0x58, 0x07, 0x8B, 0x0F, 0x00, 0x9F, 0x45, 0x02, 0x01, 0x03, 0xA3, 0x0C, 0x89, 0x03, 0x06, + 0x02, 0x00, 0x5C, 0x06, 0x01, 0x92, 0x52, 0x07, 0xAE, 0x59, 0x03, 0x00, 0xBD, 0xBD, 0x4C, 0x02, + 0x05, 0xAB, 0xB9, 0x70, 0x0C, 0xAC, 0x96, 0x00, 0x52, 0x45, 0x36, 0xC1, 0x51, 0x97, 0x0C, 0x66, + 0x5E, 0x00, 0x8C, 0x4C, 0x0A, 0x05, 0x5F, 0x68, 0x98, 0x4E, 0x56, 0x40, 0x7F, 0x3D, 0x67, 0x97, + 0x9D, 0x73, 0x39, 0x02, 0x74, 0x9C, 0x48, 0xA4, 0x76, 0x76, 0x66, 0x73, 0xA8, 0x2C, 0x05, 0x50, + 0x02, 0xA3, 0xA3, 0x59, 0x78, 0x5E, 0x92, 0xD4, 0x2C, 0xDB, 0xB0, 0x59, 0x76, 0x07, 0x00, 0x78, + 0x16, 0x09, 0x80, 0xF5, 0xE4, 0x05, 0xC1, 0x81, 0x5F, 0xB0, 0x10, 0x00, 0xA0, 0xEE, 0xC0, 0xC0, + 0x03, 0x8E, 0x68, 0x68, 0xB1, 0x72, 0xE5, 0x92, 0xAF, 0x5E, 0xF6, 0x0C, 0x10, 0xF0, 0x86, 0x62, + 0xFB, 0xCE, 0xC1, 0x03, 0x98, 0x00, 0x74, 0x42, 0x42, 0xE7, 0xC5, 0xB9, 0x4E, 0xFF, 0xC2, 0x9D, + 0x99, 0xA3, 0x60, 0x0A, 0x0A, 0x03, 0xED, 0xC0, 0xDD, 0xF1, 0x47, 0xCF, 0xCB, 0x2E, 0x97, 0x20, + 0x92, 0x0D, 0x64, 0x85, 0xA5, 0x65, 0x43, 0x2C, 0x3C, 0x19, 0x10, 0x30, 0x94, 0x2F, 0x27, 0xBE, + 0x9D, 0x87, 0x78, 0xCE, 0x54, 0x47, 0xC0, 0x98, 0xC6, 0x9D, 0x39, 0x2F, 0xC6, 0xB2, 0xF1, 0x87, + 0x29, 0x96, 0x62, 0xC6, 0xB6, 0x69, 0xE2, 0xC0, 0x2B, 0x4A, 0x2C, 0x58, 0x49, 0x47,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, 0x16, 0x5B, 0x49, 0xF0, 0x84, 0x2A, 0x48, 0x19, 0x92, 0x47, 0x30, + 0x4E, 0x00, 0x60, 0xC9, 0x57, 0x71, 0x79, 0x03, 0x51, 0x30, 0xD3, 0x4C, 0xA0, 0xC0, 0x4E, 0xA4, + 0x1C, 0x45, 0x51, 0x2C, 0x7E, 0x39, 0xB8, 0x18, 0x3E, 0x04, 0xB5, 0x04, 0x14, 0x6C, 0xB3, 0xF8, + 0xF1, 0xC7, 0x3C, 0x00, 0xAA, 0xC6, 0xCB, 0x45, 0xFC, 0x21, 0xD5, 0x52, 0x72, 0x17, 0x95, 0x88, + 0xD8, 0x09, 0x08, 0x00, 0x80, 0x00, 0x02, 0x28, 0x94, 0x28, 0xC1, 0x8C, 0x20, 0x20, 0xD1, 0x5D, + 0x02, 0x27, 0xE8, 0x88, 0x82, 0x5B, 0x84, 0x2C, 0xE0, 0xD6, 0x19, 0x4C, 0x1C, 0xA9, 0xA4, 0x19, + 0x1B, 0x44, 0x00, 0x00, 0x21, 0xFE, 0x19, 0x42, 0x6F, 0x79, 0x27, 0x73, 0x20, 0x48, 0x61, 0x70, + 0x70, 0x79, 0x20, 0x48, 0x6F, 0x6C, 0x69, 0x64, 0x61, 0x79, 0x73, 0x20, 0x50, 0x61, 0x67, 0x65, + 0x00, 0x3B + +}; + +static const uint8_t bird_gif[] PROGMEM = { + 0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x74, 0x00, 0x4E, 0x00, 0xCC, 0x13, 0x00, 0xFF, 0xFF, 0xFF, + 0xEF, 0xFF, 0xFF, 0xBD, 0xE7, 0xE7, 0xD6, 0xEF, 0xEF, 0x63, 0x63, 0x63, 0xAD, 0xAD, 0xAD, 0xCE, + 0xCE, 0xCE, 0xD6, 0xDE, 0xDE, 0x4A, 0x4A, 0x4A, 0x7B, 0x84, 0x84, 0x94, 0x9C, 0x9C, 0xE7, 0xE7, + 0xE7, 0x84, 0x94, 0x94, 0xB5, 0xC6, 0xC6, 0x73, 0x7B, 0x7B, 0x31, 0x31, 0x31, 0xF7, 0xF7, 0xF7, + 0x18, 0x10, 0x10, 0xCE, 0x63, 0x39, 0x6B, 0x39, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0xFF, 0x0B, + 0x4E, 0x45, 0x54, 0x53, 0x43, 0x41, 0x50, 0x45, 0x32, 0x2E, 0x30, 0x03, 0x01, 0x00, 0x00, 0x00, + 0x21, 0xF9, 0x04, 0x09, 0x0A, 0x00, 0x00, 0x00, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x74, 0x00, 0x4B, + 0x00, 0x00, 0x05, 0xFF, 0x20, 0x20, 0x8E, 0x64, 0x69, 0x9E, 0x68, 0xAA, 0xAE, 0xEC, 0x68, 0x2C, + 0x6D, 0x2C, 0xCF, 0x74, 0x6D, 0x03, 0x46, 0x84, 0x40, 0x77, 0xEF, 0xFF, 0x40, 0x51, 0x42, 0x41, + 0x0C, 0x1A, 0x8F, 0x48, 0x13, 0xC1, 0xD0, 0x20, 0x00, 0x0E, 0x8E, 0x42, 0x72, 0x4A, 0xAD, 0x21, + 0x0E, 0xCD, 0x05, 0xE1, 0x80, 0xA8, 0x7A, 0xBF, 0x29, 0xC2, 0xA0, 0x91, 0x28, 0x34, 0x02, 0x5D, + 0xB0, 0x5A, 0xFD, 0x08, 0x34, 0x14, 0x84, 0x00, 0x7A, 0x4D, 0xF7, 0x22, 0xDC, 0x89, 0xB8, 0xC1, + 0xB9, 0x80, 0xD5, 0xFF, 0x40, 0x0B, 0x77, 0x0C, 0x0F, 0x05, 0x01, 0x0C, 0x0A, 0x0B, 0x0F, 0x08, + 0x06, 0x80, 0x8E, 0x37, 0x7B, 0x01, 0x09, 0x11, 0x03, 0x68, 0x5C, 0x4C, 0x0A, 0x8F, 0x9A, 0x33, + 0x06, 0x09, 0x01, 0x0E, 0x71, 0x68, 0x88, 0x92, 0x07, 0x9B, 0xA6, 0x2C, 0x0A, 0x86, 0x07, 0x95, + 0x05, 0x04, 0xA1, 0x5D, 0x8D, 0xA7, 0xB2, 0x26, 0x09, 0x06, 0x72, 0x72, 0x0E, 0x94, 0x01, 0xA9, + 0x04, 0x08, 0x52, 0xB3, 0xC0, 0x00, 0x09, 0x95, 0xB7, 0x0D, 0x86, 0x01, 0x04, 0x0A, 0xC3, 0x09, + 0x34, 0x43, 0xC1, 0x54, 0x0E, 0xB7, 0xD2, 0x87, 0xAE, 0xBB, 0x99, 0x32, 0x7B, 0x0E, 0xCF, 0x49, + 0x0B, 0xD1, 0xD3, 0x72, 0x0C, 0xDE, 0x57, 0x33, 0xBE, 0xCC, 0xDB, 0x47, 0x05, 0x0C, 0xDF, 0xD3, + 0x05, 0xD7, 0x31, 0x0C, 0xE1, 0xA5, 0xE7, 0x46, 0xBE, 0xEB, 0xD2, 0x04, 0x05, 0xBF, 0x2C, 0x5C, + 0x4D, 0xF3, 0x46, 0x0B, 0x11, 0x56, 0xD9, 0x3B, 0x14, 0x01, 0x14, 0x0F, 0x16, 0x04, 0x1A, 0x30, + 0x28, 0x00, 0x81, 0xA1, 0x3F, 0x1F, 0xAD, 0x02, 0x10, 0x5B, 0x87, 0x6F, 0x0E, 0x8B, 0x02, 0x0E, + 0x04, 0x5C, 0x41, 0x10, 0xF0, 0x61, 0x8F, 0x25, 0x03, 0x26, 0xDA, 0x43, 0xC4, 0x42, 0x8B, 0x00, + 0x05, 0x0E, 0x7C, 0xFF, 0xED, 0xF0, 0x68, 0x83, 0x8B, 0x44, 0x91, 0xDF, 0x06, 0xAC, 0x54, 0x01, + 0x21, 0xA1, 0x80, 0x07, 0x0F, 0x1A, 0x38, 0x70, 0xC7, 0x72, 0x46, 0xC2, 0x97, 0x03, 0x3F, 0xC5, + 0x52, 0xE1, 0x80, 0x81, 0x00, 0x01, 0x19, 0x1B, 0x3C, 0x38, 0xD8, 0x53, 0xC6, 0x81, 0x38, 0x21, + 0x61, 0x4A, 0xEB, 0xB7, 0x42, 0x01, 0x82, 0xA3, 0x58, 0x7D, 0xC9, 0x6B, 0x1A, 0x63, 0x0B, 0xD0, + 0x81, 0x11, 0x08, 0x74, 0x44, 0x61, 0xE0, 0x01, 0xD6, 0xA3, 0x05, 0x16, 0x2D, 0xE5, 0xDA, 0xC2, + 0x80, 0xB7, 0x90, 0x41, 0xCB, 0xA4, 0x39, 0xC1, 0xEF, 0x2C, 0x56, 0xAA, 0x6C, 0x57, 0x38, 0xA8, + 0x14, 0x35, 0xA8, 0x35, 0x14, 0x10, 0x10, 0x34, 0xB0, 0x9B, 0xD5, 0x4F, 0xDE, 0x14, 0x06, 0x8E, + 0xF5, 0x1D, 0xC8, 0x25, 0x85, 0x83, 0xC1, 0x84, 0x05, 0x20, 0x32, 0x30, 0xF4, 0x30, 0x2D, 0x39, + 0x8B, 0x07, 0x32, 0x42, 0xA1, 0x00, 0x72, 0xE4, 0x45, 0x08, 0x7C, 0x59, 0x36, 0x91, 0x18, 0x73, + 0xE6, 0x6F, 0x79, 0x38, 0x2B, 0x88, 0x7C, 0x54, 0xE7, 0xE0, 0x2D, 0xA3, 0x4B, 0x78, 0x7A, 0x79, + 0x7A, 0x1A, 0xCE, 0x04, 0x4C, 0x85, 0xAC, 0x66, 0x7D, 0x96, 0x80, 0xB9, 0xD8, 0x22, 0x4A, 0x4B, + 0x14, 0x00, 0x97, 0xF1, 0xD3, 0x12, 0x3B, 0x79, 0x9F, 0x45, 0xC0, 0x13, 0xB8, 0xB7, 0xE1, 0xC5, + 0x19, 0x33, 0xEB, 0x53, 0xD3, 0xA8, 0x72, 0x01, 0x0D, 0x44, 0x97, 0x5C, 0x90, 0x7B, 0x9B, 0x01, + 0x05, 0xA6, 0x89, 0xFB, 0x3D, 0x54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, 0x99, 0x73, 0x89, 0x93, 0xE5, 0xFE, + 0x74, 0x13, 0xB7, 0xCB, 0xE6, 0xA4, 0x4B, 0x63, 0x90, 0x65, 0xED, 0x16, 0x25, 0x77, 0xE9, 0x54, + 0x67, 0x11, 0xDB, 0x89, 0x44, 0xB3, 0x6E, 0xF6, 0x89, 0x7E, 0x37, 0x05, 0x47, 0xE7, 0xB2, 0xFB, + 0xF5, 0x2D, 0x70, 0xDD, 0x80, 0x37, 0xDE, 0x0A, 0x8E, 0xFB, 0x06, 0x1C, 0x00, 0x4D, 0xE0, 0x1E, + 0x80, 0x0C, 0x73, 0xFB, 0x47, 0x00, 0xE8, 0x2C, 0x89, 0x6E, 0xCF, 0x0C, 0x66, 0x87, 0x64, 0x55, + 0x73, 0x87, 0xB5, 0xD2, 0x39, 0xF2, 0x54, 0xA3, 0xAD, 0x24, 0xEF, 0x09, 0xC4, 0x2E, 0x47, 0x0C, + 0x83, 0x4F, 0x44, 0x6E, 0x25, 0xA9, 0x0C, 0x8F, 0x43, 0xE0, 0xD3, 0xB4, 0x30, 0x50, 0x54, 0xF9, + 0x41, 0x57, 0xC9, 0x63, 0xE6, 0x03, 0x00, 0xC1, 0xED, 0xE9, 0xAB, 0x60, 0x4F, 0x62, 0x94, 0x41, + 0x2A, 0xFE, 0x01, 0x56, 0x11, 0x10, 0xB3, 0x65, 0x4F, 0x11, 0xCC, 0x37, 0x4A, 0x10, 0x2C, 0x8E, + 0x3C, 0x80, 0x40, 0x3A, 0x30, 0x20, 0x02, 0x96, 0x10, 0x3F, 0x13, 0x64, 0xA7, 0x1E, 0x17, 0x53, + 0x90, 0x02, 0x28, 0x87, 0x00, 0xB2, 0xC1, 0xE0, 0x29, 0x08, 0x24, 0x50, 0xC9, 0xFE, 0x37, 0x3C, + 0x28, 0x30, 0x67, 0x75, 0x01, 0x9C, 0x20, 0x4E, 0x0A, 0xE0, 0xAC, 0xAF, 0x21, 0x90, 0x3E, 0x0D, + 0x4C, 0x41, 0xBB, 0x42, 0x13, 0x05, 0x63, 0xA4, 0x64, 0x81, 0x43, 0x28, 0x40, 0xED, 0x44, 0x00, + 0x01, 0x2C, 0x78, 0x29, 0x85, 0x2C, 0x38, 0x56, 0x62, 0x1A, 0xC0, 0x1D, 0x35, 0x84, 0x00, 0x00, + 0x21, 0xF9, 0x04, 0x09, 0x0A, 0x00, 0x00, 0x00, 0x2C, 0x00, 0x00, 0x17, 0x00, 0x6A, 0x00, 0x32, + 0x00, 0x00, 0x05, 0xFF, 0x20, 0x20, 0x8E, 0x64, 0x69, 0x9E, 0x68, 0xAA, 0x8A, 0x85, 0x02, 0xAD, + 0x70, 0x2C, 0xCF, 0x74, 0x5D, 0x26, 0x0C, 0x63, 0xD8, 0x7C, 0xEF, 0xFF, 0xA2, 0x05, 0x21, 0x80, + 0x58, 0x2C, 0x70, 0x0B, 0xA0, 0x72, 0xC9, 0x64, 0x34, 0x0C, 0x89, 0x86, 0x42, 0xC8, 0xAC, 0x5A, + 0x6B, 0x54, 0x46, 0x81, 0x11, 0x70, 0x5E, 0xBF, 0x60, 0x94, 0xA2, 0xB0, 0x40, 0x10, 0x00, 0x86, + 0x73, 0x23, 0x71, 0x08, 0xBB, 0xAF, 0x90, 0x73, 0xE2, 0x11, 0x28, 0x97, 0x1B, 0xBA, 0xB7, 0x7E, + 0xA9, 0x68, 0x04, 0x0A, 0x01, 0x01, 0x04, 0x39, 0x01, 0x50, 0x7B, 0x87, 0x3E, 0x0B, 0x5C, 0x81, + 0x5D, 0x0F, 0x03, 0x01, 0x78, 0x69, 0x05, 0x88, 0x94, 0x33, 0x0C, 0x8F, 0x8C, 0x0B, 0x81, 0x5A, + 0x08, 0x06, 0x2D, 0x3F, 0x0A, 0x0A, 0x33, 0x0B, 0x63, 0x0D, 0x49, 0x95, 0x26, 0x2D, 0x8C, 0xAB, + 0x05, 0x04, 0x7E, 0x0D, 0x67, 0x3C, 0x10, 0x09, 0x0A, 0x0C, 0x26, 0x10, 0x0E, 0x83, 0x05, 0x07, + 0x0B, 0x69, 0x0F, 0xB4, 0x0E, 0x0F, 0x9D, 0xA8, 0x24, 0x06, 0x08, 0xAB, 0xC8, 0x81, 0xA1, 0x3C, + 0x07, 0x0E, 0x6B, 0x6D, 0x25, 0x06, 0x11, 0x11, 0x12, 0x13, 0x13, 0x0F, 0x11, 0x80, 0xAC, 0xC2, + 0xD0, 0xA8, 0x65, 0x01, 0x98, 0xC9, 0x10, 0x66, 0x0E, 0x93, 0x32, 0x07, 0x38, 0x02, 0x0C, 0xB4, + 0xA2, 0x25, 0x07, 0x08, 0x13, 0x12, 0xF2, 0x13, 0x06, 0x7F, 0x07, 0xDB, 0xED, 0x95, 0xDF, 0xE1, + 0xC9, 0x63, 0x71, 0xDD, 0x29, 0x8E, 0xB8, 0x12, 0xA0, 0x2E, 0x94, 0x03, 0x14, 0xB0, 0xE4, 0x55, + 0x53, 0x80, 0x40, 0x01, 0xB2, 0x01, 0xB9, 0x4E, 0x21, 0x3A, 0x30, 0x64, 0x00, 0xBF, 0x64, 0x0B, + 0x1E, 0x48, 0x3C, 0x41, 0x2A, 0x0A, 0xC1, 0x8F, 0x05, 0x8A, 0x04, 0x74, 0x10, 0x4F, 0x42, 0x84, + 0x07, 0x0E, 0x93, 0xFF, 0x35, 0x40, 0x60, 0xEE, 0x90, 0x14, 0x70, 0x17, 0x91, 0x29, 0x48, 0x80, + 0x62, 0xC1, 0x16, 0x05, 0x1F, 0x73, 0x12, 0x9C, 0xB9, 0xA2, 0x40, 0x04, 0x04, 0x09, 0x82, 0x6A, + 0x4B, 0xC6, 0x80, 0x80, 0x81, 0x17, 0x7A, 0x0A, 0xD4, 0xB3, 0x18, 0x33, 0x10, 0x84, 0x5F, 0x6C, + 0x48, 0xB4, 0x1A, 0xA8, 0x53, 0x67, 0x82, 0x1D, 0x2B, 0x84, 0x2C, 0x4A, 0xB6, 0xEA, 0xC0, 0x4C, + 0x1C, 0xA6, 0x20, 0x20, 0xB5, 0x32, 0x05, 0x66, 0xD3, 0x40, 0x07, 0xA0, 0xD8, 0x12, 0xD1, 0xE0, + 0x41, 0x83, 0xAA, 0x55, 0x61, 0x31, 0xC8, 0xA7, 0x82, 0xA1, 0x83, 0x7A, 0x5C, 0x19, 0x41, 0x48, + 0xDB, 0x22, 0x47, 0xD0, 0xA3, 0x4C, 0x52, 0x32, 0x3D, 0x0B, 0x0E, 0x01, 0x34, 0x03, 0x6E, 0xE1, + 0xC2, 0xC5, 0x43, 0x57, 0x05, 0x04, 0x28, 0x04, 0x1C, 0x38, 0xB9, 0x97, 0x17, 0xD9, 0x81, 0x02, + 0x7F, 0xC7, 0xF6, 0x48, 0x10, 0x68, 0x80, 0x00, 0x8B, 0x95, 0x73, 0x8D, 0x38, 0xB0, 0xEE, 0xAD, + 0xE2, 0x8F, 0x0A, 0x08, 0x00, 0x94, 0x01, 0xA1, 0x17, 0x66, 0x02, 0xB0, 0x71, 0x84, 0x52, 0x9A, + 0x97, 0xB4, 0xEA, 0x1F, 0x07, 0xC1, 0x11, 0x24, 0xDC, 0xC0, 0xC1, 0x18, 0x00, 0xA4, 0x10, 0x30, + 0x38, 0x8D, 0xDA, 0xF0, 0x92, 0x05, 0x69, 0x0F, 0xA4, 0x55, 0xE0, 0x40, 0x32, 0xDE, 0xAE, 0xE5, + 0x7A, 0xE0, 0x02, 0xD0, 0x79, 0x77, 0x65, 0x70, 0xB0, 0x09, 0x14, 0x20, 0xFE, 0x51, 0xFB, 0xC6, + 0x2F, 0x8F, 0x85, 0x42, 0x40, 0x86, 0xF9, 0x7B, 0x0C, 0x5C, 0x8C, 0x3C, 0x7F, 0x26, 0xDC, 0x85, + 0xC0, 0x83, 0x41, 0xA6, 0x4F, 0x6B, 0x41, 0x04, 0xA1, 0xD5, 0x73, 0xB4, 0xDA, 0x35, 0xAB, 0xB8, + 0x8C, 0x23, 0xBD, 0xF5, 0xEB, 0x30, 0x41, 0xD0, 0xD6, 0x69, 0x6B, 0x34, 0x80, 0x0A, 0x04, 0xEB, + 0xA8, 0x14, 0x85, 0xFF, 0x7E, 0x41, 0x60, 0xE6, 0x40, 0x02, 0x05, 0x48, 0xE1, 0x47, 0x75, 0xBB, + 0xB1, 0xC7, 0xC8, 0x4A, 0xC4, 0xCD, 0x47, 0x0C, 0x2C, 0x31, 0x85, 0x64, 0x46, 0x64, 0x09, 0x20, + 0xF0, 0xC0, 0x2F, 0xF7, 0x39, 0xA0, 0x89, 0x7F, 0xEB, 0x01, 0x18, 0x88, 0x5A, 0xF1, 0xE5, 0xC4, + 0x40, 0x74, 0xC4, 0x00, 0xD0, 0x8C, 0x85, 0x03, 0x18, 0xD0, 0x21, 0x02, 0xD4, 0xA1, 0x98, 0xA2, + 0x8A, 0x10, 0x28, 0xF0, 0x00, 0x5C, 0x08, 0x30, 0xA8, 0x8F, 0x33, 0x2A, 0x5A, 0x46, 0x40, 0x02, + 0x27, 0xEA, 0xF8, 0x99, 0x8A, 0x88, 0x39, 0xA3, 0x13, 0x66, 0x34, 0xC5, 0x48, 0xC2, 0x2C, 0x29, + 0x15, 0x79, 0x9D, 0x7A, 0x15, 0xAA, 0xB8, 0x80, 0x6F, 0x39, 0xA1, 0x64, 0x9E, 0x94, 0x00, 0xF4, + 0x67, 0x65, 0x5E, 0x4C, 0x65, 0x79, 0x9D, 0x4D, 0x0E, 0x20, 0x20, 0xE2, 0x16, 0xCD, 0x09, 0x09, + 0x26, 0x00, 0x84, 0x8C, 0xC9, 0xD5, 0x60, 0xA0, 0x9D, 0x89, 0xC0, 0x84, 0x88, 0xDD, 0xF6, 0x66, + 0x0A, 0xCC, 0xC9, 0x79, 0x25, 0x7B, 0xE8, 0x34, 0xB4, 0x4A, 0x30, 0x06, 0xEE, 0x29, 0xC6, 0x03, + 0xF7, 0xF9, 0x69, 0xE5, 0x63, 0x04, 0xC4, 0x84, 0x98, 0x48, 0x86, 0x9A, 0x40, 0xD1, 0x56, 0x8A, + 0x56, 0x66, 0x40, 0x03, 0x52, 0xB0, 0x94, 0xE8, 0xA0, 0x1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, 0x8C, 0x0E, + 0x92, 0xA8, 0x57, 0x27, 0xA9, 0xF9, 0xCB, 0x97, 0x19, 0xC5, 0xCC, 0xD2, 0xCA, 0x33, 0x78, 0x35, + 0xF0, 0x8B, 0xB9, 0xE8, 0x52, 0xF2, 0x02, 0x1B, 0x93, 0xA2, 0x32, 0xCE, 0x30, 0xB4, 0x36, 0xB4, + 0x0D, 0x21, 0x00, 0x00, 0x21, 0xF9, 0x04, 0x09, 0x0A, 0x00, 0x00, 0x00, 0x2C, 0x00, 0x00, 0x20, + 0x00, 0x6A, 0x00, 0x25, 0x00, 0x00, 0x05, 0xFF, 0x20, 0x20, 0x8E, 0xE3, 0xA2, 0x14, 0xC6, 0x42, + 0xAE, 0x6C, 0xEB, 0xBE, 0x70, 0x2C, 0xCF, 0x2D, 0x94, 0x10, 0x4C, 0x71, 0x2C, 0x06, 0xF1, 0x24, + 0x0A, 0xC7, 0x03, 0x61, 0xA0, 0x19, 0x8F, 0xC8, 0x24, 0xCC, 0x10, 0x89, 0x48, 0x26, 0x93, 0x47, + 0xA4, 0x10, 0xA8, 0x56, 0x0B, 0x0F, 0xC2, 0x41, 0xC9, 0xED, 0x7A, 0x5B, 0x06, 0xC4, 0x44, 0x42, + 0x9E, 0x18, 0x02, 0x3A, 0x2B, 0xFA, 0xA1, 0xF8, 0xBA, 0xDF, 0xC9, 0xC6, 0xB8, 0xAC, 0x40, 0x30, + 0xD4, 0x81, 0x01, 0x81, 0xA0, 0x82, 0xFB, 0xFF, 0x2D, 0x0B, 0x0E, 0x73, 0x11, 0x6C, 0x78, 0x55, + 0x0D, 0x08, 0x05, 0x80, 0x8C, 0x8D, 0x05, 0x11, 0x08, 0x09, 0x09, 0x0E, 0x54, 0x87, 0x01, 0x0C, + 0x04, 0x06, 0x10, 0x8D, 0x9C, 0x6F, 0x0B, 0x38, 0x96, 0x78, 0x07, 0x05, 0x0A, 0x0C, 0x93, 0x0E, + 0x93, 0x09, 0x0C, 0x0A, 0x0D, 0x7D,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xA2, 0xCC, 0x0C, 0x45, 0xEC, 0x30, 0x0D, 0x98, 0x97, 0xDD, 0x24, 0x04, 0x49, + 0xC6, 0x0A, 0x02, 0xC8, 0xB1, 0x50, 0xD4, 0xAA, 0x5A, 0xEE, 0x24, 0x48, 0x19, 0x00, 0xE4, 0xF4, + 0xA0, 0xC0, 0x28, 0x0A, 0xB0, 0xE2, 0x1B, 0x0D, 0x33, 0xA9, 0x25, 0x00, 0x52, 0x8B, 0x3C, 0xF8, + 0x42, 0x01, 0x5A, 0x1C, 0x62, 0x44, 0x86, 0x6B, 0x69, 0x46, 0x40, 0x87, 0x1E, 0x06, 0x02, 0x84, + 0x88, 0x33, 0x14, 0xF3, 0x57, 0x00, 0x6D, 0x09, 0x10, 0xC0, 0x09, 0x29, 0x2E, 0xE1, 0x80, 0x6B, + 0x6A, 0xC4, 0x80, 0x90, 0x66, 0x80, 0x69, 0xA6, 0xC0, 0x03, 0x0E, 0xD6, 0x28, 0x02, 0x04, 0x0C, + 0x28, 0xC2, 0xE2, 0x0A, 0x1C, 0xF9, 0xE0, 0xCE, 0x3E, 0x05, 0x94, 0xE6, 0x00, 0x02, 0x11, 0x68, + 0x21, 0xA4, 0x0C, 0x35, 0xB1, 0x11, 0x94, 0x49, 0x09, 0x35, 0xF0, 0x24, 0x0E, 0x48, 0x35, 0x61, + 0x4A, 0x93, 0x29, 0x4C, 0x69, 0xC4, 0x01, 0x42, 0x30, 0x70, 0x25, 0x1E, 0x20, 0x26, 0x44, 0x40, + 0x94, 0x0C, 0x38, 0xC4, 0x44, 0x13, 0x99, 0x1C, 0x10, 0x9B, 0x98, 0x34, 0x98, 0xC0, 0x4E, 0x9B, + 0x56, 0x74, 0x54, 0x08, 0x3B, 0x99, 0xB8, 0xF0, 0x48, 0x13, 0x4D, 0x88, 0x45, 0x27, 0x12, 0x0A, + 0x99, 0x83, 0x8A, 0x40, 0x73, 0xBE, 0x60, 0x57, 0x13, 0xA1, 0x0D, 0xFA, 0xD2, 0x6C, 0x93, 0x91, + 0x10, 0x02, 0x00, 0x21, 0xF9, 0x04, 0x09, 0x0A, 0x00, 0x00, 0x00, 0x2C, 0x00, 0x00, 0x20, 0x00, + 0x6A, 0x00, 0x2E, 0x00, 0x00, 0x05, 0xFF, 0x20, 0x00, 0x40, 0x62, 0xB9, 0x28, 0x08, 0x41, 0x28, + 0x4B, 0xE9, 0xBE, 0x70, 0x2C, 0xCF, 0x74, 0x6D, 0xDF, 0xE5, 0xF1, 0x3C, 0x69, 0x52, 0x24, 0x0F, + 0x82, 0xE1, 0x60, 0x00, 0x26, 0x5A, 0xB8, 0xA4, 0x72, 0xC9, 0x94, 0xE9, 0x22, 0x12, 0xC9, 0x64, + 0xF2, 0x18, 0x04, 0xAE, 0xD7, 0x01, 0xB0, 0xD0, 0xEC, 0x7A, 0xBF, 0x31, 0x48, 0x61, 0x12, 0x95, + 0x32, 0x02, 0x8E, 0x06, 0x36, 0x70, 0x50, 0x21, 0xC1, 0xF0, 0x78, 0x72, 0x91, 0x20, 0x4B, 0x55, + 0x85, 0xF5, 0xB5, 0x81, 0xE0, 0xCA, 0xFF, 0x80, 0x32, 0x0D, 0x0F, 0x53, 0x11, 0x11, 0x04, 0x07, + 0x7A, 0x57, 0x0E, 0x04, 0x6F, 0x81, 0x8F, 0x7F, 0x0B, 0x2A, 0x06, 0x94, 0x6A, 0x8A, 0x01, 0x06, + 0x04, 0x05, 0x07, 0x0B, 0x0B, 0x44, 0x94, 0xA0, 0x43, 0x24, 0x90, 0xA4, 0x37, 0x05, 0x04, 0x96, + 0x97, 0x58, 0x45, 0x09, 0x0A, 0x0C, 0x0C, 0x0A, 0x05, 0x0D, 0xB3, 0x05, 0x0A, 0x09, 0x0C, 0x05, + 0x06, 0xA3, 0x4D, 0x9F, 0xA0, 0x0B, 0xBB, 0xA5, 0x33, 0x6D, 0x08, 0x0C, 0x89, 0xAA, 0xC7, 0x8A, + 0x07, 0xAE, 0x3E, 0xC0, 0x32, 0x10, 0x07, 0x3F,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 0x20, 0x4C, 0x05, 0xC8, 0xA5, 0x9E, 0x70, 0xA7, 0x31, 0x78, 0x92, + 0x24, 0x89, 0xB9, 0x70, 0x4C, 0x26, 0x41, 0x04, 0xA4, 0x40, 0x03, 0x19, 0x32, 0x72, 0xC8, 0x85, + 0x1D, 0xB9, 0x92, 0x20, 0x7F, 0xEE, 0x9D, 0x94, 0xE1, 0x49, 0x0C, 0xDD, 0x84, 0x16, 0x79, 0x11, + 0xF4, 0x11, 0x0B, 0x42, 0x62, 0x41, 0x70, 0xCB, 0x73, 0x1E, 0x0E, 0xE5, 0x20, 0x70, 0x7B, 0x10, + 0x40, 0x58, 0x5E, 0xC4, 0xE4, 0x23, 0x42, 0x02, 0x86, 0x34, 0xA2, 0x98, 0x24, 0x0A, 0x00, 0x19, + 0x63, 0x4E, 0xFD, 0x10, 0x43, 0x93, 0x32, 0x79, 0xF1, 0x90, 0x42, 0x88, 0x2E, 0x2C, 0xF0, 0x80, + 0x21, 0x0F, 0x30, 0x00, 0x5F, 0x30, 0x62, 0xF4, 0xB1, 0x61, 0x90, 0x47, 0x39, 0x18, 0xCB, 0x3F, + 0xEF, 0xF8, 0x60, 0xC0, 0x2F, 0x36, 0x3C, 0xB1, 0x22, 0x53, 0x99, 0x20, 0x90, 0x08, 0x9A, 0x5D, + 0x79, 0xD9, 0x80, 0x00, 0x29, 0xB4, 0xD6, 0x04, 0x59, 0x2C, 0xFC, 0x24, 0x13, 0x2A, 0x78, 0x76, + 0xF5, 0x95, 0x03, 0x0C, 0xA0, 0xA6, 0xA3, 0x17, 0x6E, 0x3D, 0xB2, 0xC0, 0x0F, 0x0A, 0x10, 0xB9, + 0xDA, 0x39, 0x08, 0x08, 0x90, 0x86, 0x00, 0x4E, 0x2E, 0x17, 0x86, 0x3B, 0xA5, 0x4D, 0xAA, 0x87, + 0x42, 0xAF, 0x0C, 0xE2, 0x00, 0xA6, 0x63, 0x8A, 0xF6, 0xA8, 0x0A, 0x91, 0x06, 0xF0, 0x4B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C, 0xF8, 0x42, 0x01, 0x5A, + 0x1C, 0x62, 0x44, 0x86, 0x6B, 0x69, 0x46, 0x40, 0x87, 0x1E, 0x06, 0x02, 0x84, 0x88, 0x33, 0x14, + 0xF3, 0x57, 0x00, 0x6D, 0x09, 0x10, 0xC0, 0x09, 0x29, 0x2E, 0xE1, 0x80, 0x6B, 0x6A, 0xC4, 0x80, + 0x90, 0x66, 0x80, 0x69, 0xA6, 0xC0, 0x03, 0x0E, 0xD6, 0x28, 0x02, 0x04, 0x0C, 0x28, 0xC2, 0xE2, + 0x0A, 0x1C, 0xF9, 0xE0, 0xCE, 0x3E, 0x05, 0x94, 0xE6, 0x00, 0x02, 0x11, 0x68, 0x21, 0xA4, 0x0C, + 0x35, 0xB1, 0x11, 0x94, 0x49, 0x09, 0x35, 0xF0, 0x24, 0x0E, 0x48, 0x35, 0x61, 0x4A, 0x93, 0x29, + 0x4C, 0x69, 0xC4, 0x01, 0x42, 0x30, 0x70, 0x25, 0x1E, 0x20, 0x26, 0x44, 0x40, 0x94, 0x0C, 0x38, + 0xC4, 0x44, 0x13, 0x99, 0x1C, 0x10, 0x9B, 0x98, 0x34, 0x98, 0xC0, 0x4E, 0x9B, 0x56, 0x74, 0x54, + 0x08, 0x3B, 0x99, 0xB8, 0xF0, 0x48, 0x13, 0x4D, 0x88, 0x45, 0x27, 0x12, 0x0A, 0x99, 0x83, 0x8A, + 0x40, 0x73, 0xBE, 0x60, 0x57, 0x13, 0xA1, 0x0D, 0xFA, 0xD2, 0x6C, 0x93, 0x91, 0x10, 0x02, 0x00, + 0x21, 0xF9, 0x04, 0x09, 0x0A, 0x00, 0x00, 0x00, 0x2C, 0x00, 0x00, 0x17, 0x00, 0x6A, 0x00, 0x32, + 0x00, 0x00, 0x05, 0xFF, 0x20, 0x20, 0x8E, 0x64, 0x69, 0x9E, 0x68, 0xAA, 0x8A, 0x85, 0x02, 0xAD, + 0x70, 0x2C, 0xCF, 0x74, 0x5D, 0x26, 0x0C, 0x63, 0xD8, 0x7C, 0xEF, 0xFF, 0xA2, 0x05, 0x21, 0x80, + 0x58, 0x2C, 0x70, 0x0B, 0xA0, 0x72, 0xC9, 0x64, 0x34, 0x0C, 0x89, 0x86, 0x42, 0xC8, 0xAC, 0x5A, + 0x6B, 0x54, 0x46, 0x81, 0x11, 0x70, 0x5E, 0xBF, 0x60, 0x94, 0xA2, 0xB0, 0x40, 0x10, 0x00, 0x86, + 0x73, 0x23, 0x71, 0x08, 0xBB, 0xAF, 0x90, 0x73, 0xE2, 0x11, 0x28, 0x97, 0x1B, 0xBA, 0xB7, 0x7E, + 0xA9, 0x68, 0x04, 0x0A, 0x01, 0x01, 0x04, 0x39, 0x01, 0x50, 0x7B, 0x87, 0x3E, 0x0B, 0x5C, 0x81, + 0x5D, 0x0F, 0x03, 0x01, 0x78, 0x69, 0x05, 0x88, 0x94, 0x33, 0x0C, 0x8F, 0x8C, 0x0B, 0x81, 0x5A, + 0x08, 0x06, 0x2D, 0x3F, 0x0A, 0x0A, 0x33, 0x0B, 0x63, 0x0D, 0x49, 0x95, 0x26, 0x2D, 0x8C, 0xAB, + 0x05, 0x04, 0x7E, 0x0D, 0x67, 0x3C, 0x10, 0x09, 0x0A, 0x0C, 0x26, 0x10, 0x0E, 0x83, 0x05, 0x07, + 0x0B, 0x69, 0x0F, 0xB4, 0x0E, 0x0F, 0x9D, 0xA8, 0x24, 0x06, 0x08, 0xAB, 0xC8, 0x81, 0xA1, 0x3C, + 0x07, 0x0E, 0x6B, 0x6D, 0x25, 0x06, 0x11, 0x11, 0x12, 0x13, 0x13, 0x0F, 0x11, 0x80, 0xAC, 0xC2, + 0xD0, 0xA8, 0x65, 0x01, 0x98, 0xC9, 0x10, 0x66, 0x0E, 0x93, 0x32, 0x07, 0x38, 0x02, 0x0C, 0xB4, + 0xA2, 0x25, 0x07, 0x08, 0x13, 0x12, 0xF2, 0x13, 0x06, 0x7F, 0x07, 0xDB, 0xED, 0x95, 0xDF, 0xE1, + 0xC9, 0x63, 0x71, 0xDD, 0x29, 0x8E, 0xB8, 0x12, 0xA0, 0x2E, 0x94, 0x03, 0x14, 0xB0, 0xE4, 0x55, + 0x53, 0x80, 0x40, 0x01, 0xB2, 0x01, 0xB9, 0x4E, 0x21, 0x3A, 0x30, 0x64, 0x00, 0xBF, 0x64, 0x0B, + 0x1E, 0x48, 0x3C, 0x41, 0x2A, 0x0A, 0xC1, 0x8F, 0x05, 0x8A, 0x04, 0x74, 0x10, 0x4F, 0x42, 0x84, + 0x07, 0x0E, 0x93, 0xFF, 0x35, 0x40, 0x60, 0xEE, 0x90, 0x14, 0x70, 0x17, 0x91, 0x29, 0x48, 0x80, + 0x62, 0xC1, 0x16, 0x05, 0x1F, 0x73, 0x12, 0x9C, 0xB9, 0xA2, 0x40, 0x04, 0x04, 0x09, 0x82, 0x6A, + 0x4B, 0xC6, 0x80, 0x80, 0x81, 0x17, 0x7A, 0x0A, 0xD4, 0xB3, 0x18, 0x33, 0x10, 0x84, 0x5F, 0x6C, + 0x48, 0xB4, 0x1A, 0xA8, 0x53, 0x67, 0x82, 0x1D, 0x2B, 0x84, 0x2C, 0x4A, 0xB6, 0xEA, 0xC0, 0x4C, + 0x1C, 0xA6, 0x20, 0x20, 0xB5, 0x32, 0x05, 0x66, 0xD3, 0x40, 0x07, 0xA0, 0xD8, 0x12, 0xD1, 0xE0, + 0x41, 0x83, 0xAA, 0x55, 0x61, 0x31, 0xC8, 0xA7, 0x82, 0xA1, 0x83, 0x7A, 0x5C, 0x19, 0x41, 0x48, + 0xDB, 0x22, 0x47, 0xD0, 0xA3, 0x4C, 0x52, 0x32, 0x3D, 0x0B, 0x0E, 0x01, 0x34, 0x03, 0x6E, 0xE1, + 0xC2, 0xC5, 0x43, 0x57, 0x05, 0x04, 0x28, 0x04, 0x1C, 0x38, 0xB9, 0x97, 0x17, 0xD9, 0x81, 0x02, + 0x7F, 0xC7, 0xF6, 0x48, 0x10, 0x68, 0x80, 0x00, 0x8B, 0x95, 0x73, 0x8D, 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 0x0E, 0xD0, 0x56, 0x4B, 0xBB, + 0x4A, 0x75, 0x6B, 0x8F, 0x32, 0x34, 0x44, 0x2B, 0x00, 0x6C, 0xAB, 0x55, 0xAB, 0xD5, 0xB1, 0x32, + 0xC8, 0xC9, 0x14, 0x24, 0xC3, 0x54, 0x5B, 0x02, 0x2C, 0x9B, 0x86, 0xFB, 0x27, 0x26, 0x1F, 0x3D, + 0x52, 0x00, 0xB5, 0xE6, 0x8A, 0xD0, 0xE3, 0x25, 0xC8, 0x20, 0x4B, 0xE6, 0x23, 0x59, 0xAE, 0xF7, + 0x8E, 0xAA, 0xF1, 0x92, 0x30, 0xA9, 0xB1, 0x29, 0xA0, 0x9A, 0x80, 0x6F, 0x7D, 0x98, 0x9A, 0x56, + 0xA6, 0x0F, 0xC0, 0xDB, 0x2F, 0x09, 0x3E, 0x3A, 0x60, 0x6C, 0x00, 0x23, 0x5C, 0xD9, 0x9B, 0x9A, + 0x0E, 0x4C, 0x33, 0x8D, 0x30, 0x47, 0x16, 0x30, 0xEC, 0xC2, 0xC0, 0xF9, 0x68, 0xD4, 0x75, 0xA4, + 0x6D, 0xA2, 0xE6, 0x91, 0x06, 0x9C, 0xF2, 0x8E, 0xC5, 0x51, 0x2C, 0xCB, 0x71, 0x09, 0x8C, 0x0E, + 0x92, 0xA8, 0x57, 0x27, 0xA9, 0xF9, 0xCB, 0x97, 0x19, 0xC5, 0xCC, 0xD2, 0xCA, 0x33, 0x78, 0x35, + 0xF0, 0x8B, 0xB9, 0xE8, 0x52, 0xF2, 0x02, 0x1B, 0x93, 0xA2, 0x32, 0xCE, 0x30, 0xB4, 0x36, 0xB4, + 0x0D, 0x21, 0x00, 0x00, 0x3B}; diff --git a/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_Reuse_Session/Send_Reuse_Session.ino b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_Reuse_Session/Send_Reuse_Session.ino new file mode 100644 index 000000000..ed7d61396 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_Reuse_Session/Send_Reuse_Session.ino @@ -0,0 +1,242 @@ +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt +*/ + +// This example show how to login once for sending multiple messages. + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +#include + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +/** For Gmail, the app password will be used for log in + * Check out https://github.com/mobizt/ESP-Mail-Client#gmail-smtp-and-imap-required-app-passwords-to-sign-in + * + * For Yahoo mail, log in to your yahoo mail in web browser and generate app password by go to + * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc + * + * To use Gmai and Yahoo's App Password to sign in, define the AUTHOR_PASSWORD with your App Password + * and AUTHOR_EMAIL with your account email. + */ + +/** The smtp host name e.g. smtp.gmail.com for GMail or smtp.office365.com for Outlook or smtp.mail.yahoo.com */ +#define SMTP_HOST "" + +/** The smtp port e.g. + * 25 or esp_mail_smtp_port_25 + * 465 or esp_mail_smtp_port_465 + * 587 or esp_mail_smtp_port_587 + */ +#define SMTP_PORT esp_mail_smtp_port_587 + +/* The log in credentials */ +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" + +/* Recipient email address */ +#define RECIPIENT_EMAIL "" + +SMTPSession smtp; + +Session_Config config; + +void smtpCallback(SMTP_Status status); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) +WiFiMulti multi; +#endif + +#include "HeapStat.h" +HeapStat heapInfo; + +unsigned long sentMillis = 0; + +void setup() +{ + + Serial.begin(115200); + +#if defined(ARDUINO_ARCH_SAMD) + while (!Serial) + ; +#endif + + Serial.println(); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + multi.addAP(WIFI_SSID, WIFI_PASSWORD); + multi.run(); +#else + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Connecting to Wi-Fi"); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + unsigned long ms = millis(); +#endif + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + if (millis() - ms > 10000) + break; +#endif + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + MailClient.networkReconnect(true); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + MailClient.clearAP(); + MailClient.addAP(WIFI_SSID, WIFI_PASSWORD); +#endif + + smtp.debug(1); + + smtp.callback(smtpCallback); + + config.server.host_name = SMTP_HOST; + config.server.port = SMTP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + + config.login.user_domain = F("127.0.0.1"); + + /* + Set the NTP config time + For times east of the Prime Meridian use 0-12 + For times west of the Prime Meridian add 12 to the offset. + Ex. American/Denver GMT would be -6. 6 + 12 = 18 + See https://en.wikipedia.org/wiki/Time_zone for a list of the GMT/UTC timezone offsets + */ + config.time.ntp_server = F("pool.ntp.org,time.nist.gov"); + config.time.gmt_offset = 3; + config.time.day_light_offset = 0; +} + +void loop() +{ + if (millis() - sentMillis > 3 * 60 * 1000 || sentMillis == 0) + { + sentMillis = millis(); + + SMTP_Message message; + + message.sender.name = F("ESP Mail"); + message.sender.email = AUTHOR_EMAIL; + message.subject = F("Send Email with session reusage"); + message.addRecipient(F("user"), RECIPIENT_EMAIL); + + message.html.content = F("

This is the HTML message.

"); + message.text.content = F("This is the text message"); + + Serial.println(); + Serial.println("Sending Email..."); + + if (!smtp.isLoggedIn()) + { + /* Set the TCP response read timeout in seconds */ + // smtp.setTCPTimeout(10); + + if (!smtp.connect(&config)) + { + MailClient.printf("Connection error, Status Code: %d, Error Code: %d, Reason: %s", smtp.statusCode(), smtp.errorCode(), smtp.errorReason().c_str()); + goto exit; + } + + if (!smtp.isLoggedIn()) + { + Serial.println("\nError, Not yet logged in."); + goto exit; + } + else + { + if (smtp.isAuthenticated()) + Serial.println("\nSuccessfully logged in."); + else + Serial.println("\nConnected with no Auth."); + } + } + + if (!MailClient.sendMail(&smtp, &message, false)) + MailClient.printf("Error, Status Code: %d, Error Code: %d, Reason: %s", smtp.statusCode(), smtp.errorCode(), smtp.errorReason().c_str()); + + exit: + + heapInfo.collect(); + heapInfo.print(); + } +} + +/* Callback function to get the Email sending status */ +void smtpCallback(SMTP_Status status) +{ + + Serial.println(status.info()); + + if (status.success()) + { + + Serial.println("----------------"); + MailClient.printf("Message sent success: %d\n", status.completedCount()); + MailClient.printf("Message sent failed: %d\n", status.failedCount()); + Serial.println("----------------\n"); + + for (size_t i = 0; i < smtp.sendingResult.size(); i++) + { + SMTP_Result result = smtp.sendingResult.getItem(i); + + MailClient.printf("Message No: %d\n", i + 1); + MailClient.printf("Status: %s\n", result.completed ? "success" : "failed"); + MailClient.printf("Date/Time: %s\n", MailClient.Time.getDateTimeString(result.timestamp, "%B %d, %Y %H:%M:%S").c_str()); + MailClient.printf("Recipient: %s\n", result.recipients.c_str()); + MailClient.printf("Subject: %s\n", result.subject.c_str()); + } + Serial.println("----------------\n"); + + smtp.sendingResult.clear(); + } +} \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_Text _Silent_Mode/Send_Text_Silent_Mode.ino b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_Text _Silent_Mode/Send_Text_Silent_Mode.ino new file mode 100644 index 000000000..2fa30a753 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_Text _Silent_Mode/Send_Text_Silent_Mode.ino @@ -0,0 +1,197 @@ + +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt +*/ + +// This example showes how to send text message without callback and debug. + +/** + * To use library in silent mode (no debug printing and callback), please define this macro in src/ESP_Mail_FS.h. + * #define SILENT_MODE + */ + +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +#include + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +#define SMTP_HOST "" + +#define SMTP_PORT esp_mail_smtp_port_587 + +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" +#define RECIPIENT_EMAIL "" + +SMTPSession smtp; + +void printSmtpData(SMTP_Status status); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) +WiFiMulti multi; +#endif + +void setup() +{ + + Serial.begin(115200); + +#if defined(ARDUINO_ARCH_SAMD) + while (!Serial) + ; +#endif + + Serial.println(); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + multi.addAP(WIFI_SSID, WIFI_PASSWORD); + multi.run(); +#else + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Connecting to Wi-Fi"); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + unsigned long ms = millis(); +#endif + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + if (millis() - ms > 10000) + break; +#endif + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + MailClient.networkReconnect(true); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + MailClient.clearAP(); + MailClient.addAP(WIFI_SSID, WIFI_PASSWORD); +#endif + + Session_Config config; + + config.server.host_name = SMTP_HOST; + config.server.port = SMTP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + + config.login.user_domain = F("127.0.0.1"); + + /* + Set the NTP config time + For times east of the Prime Meridian use 0-12 + For times west of the Prime Meridian add 12 to the offset. + Ex. American/Denver GMT would be -6. 6 + 12 = 18 + See https://en.wikipedia.org/wiki/Time_zone for a list of the GMT/UTC timezone offsets + */ + config.time.ntp_server = F("pool.ntp.org,time.nist.gov"); + config.time.gmt_offset = 3; + config.time.day_light_offset = 0; + + SMTP_Message message; + + message.sender.name = F("ESP Mail"); + message.sender.email = AUTHOR_EMAIL; + message.subject = F("Test sending plain text Email"); + message.addRecipient(F("Someone"), RECIPIENT_EMAIL); + + String textMsg = "This is simple plain text message"; + message.text.content = textMsg; + + message.text.charSet = F("us-ascii"); + + message.text.transfer_encoding = Content_Transfer_Encoding::enc_7bit; + + message.priority = esp_mail_smtp_priority::esp_mail_smtp_priority_low; + + message.addHeader(F("Message-ID: ")); + + if (!smtp.connect(&config)) + { + MailClient.printf("Connection error, Status Code: %d, Error Code: %d, Reason: %s", smtp.statusCode(), smtp.errorCode(), smtp.errorReason().c_str()); + return; + } + + if (!smtp.isLoggedIn()) + { + Serial.println("Not yet logged in."); + } + else + { + if (smtp.isAuthenticated()) + Serial.println("Successfully logged in."); + else + Serial.println("Connected with no Auth."); + } + + if (MailClient.sendMail(&smtp, &message)) + { + printSmtpData(smtp.status()); + } + else + { + MailClient.printf("Error, Status Code: %d, Error Code: %d, Reason: %s", smtp.statusCode(), smtp.errorCode(), smtp.errorReason().c_str()); + } + + smtp.sendingResult.clear(); +} + +void loop() +{ +} + +void printSmtpData(SMTP_Status status) +{ + + if (status.success()) + { + + Serial.println("\n----------------"); + MailClient.printf("Message sent success: %d\n", status.completedCount()); + MailClient.printf("Message sent failed: %d\n", status.failedCount()); + Serial.println("----------------"); + + for (size_t i = 0; i < smtp.sendingResult.size(); i++) + { + + SMTP_Result result = smtp.sendingResult.getItem(i); + + MailClient.printf("Message No: %d\n", i + 1); + MailClient.printf("Status: %s\n", result.completed ? "success" : "failed"); + MailClient.printf("Date/Time: %s\n", MailClient.Time.getDateTimeString(result.timestamp, "%B %d, %Y %H:%M:%S").c_str()); + MailClient.printf("Recipient: %s\n", result.recipients.c_str()); + MailClient.printf("Subject: %s\n", result.subject.c_str()); + } + Serial.println("----------------\n"); + + smtp.sendingResult.clear(); + } +} diff --git a/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_Text/Send_Text.ino b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_Text/Send_Text.ino new file mode 100644 index 000000000..ea9beee08 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_Text/Send_Text.ino @@ -0,0 +1,396 @@ + +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt + */ + +// This example showes how to send text message. + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +#include + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +/** For Gmail, the app password will be used for log in + * Check out https://github.com/mobizt/ESP-Mail-Client#gmail-smtp-and-imap-required-app-passwords-to-sign-in + * + * For Yahoo mail, log in to your yahoo mail in web browser and generate app password by go to + * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc + * + * To use Gmai and Yahoo's App Password to sign in, define the AUTHOR_PASSWORD with your App Password + * and AUTHOR_EMAIL with your account email. + */ + +/** The smtp host name e.g. smtp.gmail.com for GMail or smtp.office365.com for Outlook or smtp.mail.yahoo.com */ +#define SMTP_HOST "" + +/** The smtp port e.g. + * 25 or esp_mail_smtp_port_25 + * 465 or esp_mail_smtp_port_465 + * 587 or esp_mail_smtp_port_587 + */ +#define SMTP_PORT esp_mail_smtp_port_587 // port 465 is not available for Outlook.com + +/* The log in credentials */ +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" + +/* Recipient email address */ +#define RECIPIENT_EMAIL "" + +/* Declare the global used SMTPSession object for SMTP transport */ +SMTPSession smtp; + +/* Callback function to get the Email sending status */ +void smtpCallback(SMTP_Status status); + +// const char rootCACert[] PROGMEM = "-----BEGIN CERTIFICATE-----\n" +// "-----END CERTIFICATE-----\n"; + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) +WiFiMulti multi; +#endif + +void setup() +{ + + Serial.begin(115200); + +#if defined(ARDUINO_ARCH_SAMD) + while (!Serial) + ; +#endif + + Serial.println(); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + multi.addAP(WIFI_SSID, WIFI_PASSWORD); + multi.run(); +#else + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Connecting to Wi-Fi"); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + unsigned long ms = millis(); +#endif + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + if (millis() - ms > 10000) + break; +#endif + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + /* Set the network reconnection option */ + MailClient.networkReconnect(true); + + // The WiFi credentials are required for Pico W + // due to it does not have reconnect feature. +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + MailClient.clearAP(); + MailClient.addAP(WIFI_SSID, WIFI_PASSWORD); +#endif + + /** Enable the debug via Serial port + * 0 for no debugging + * 1 for basic level debugging + * + * Debug port can be changed via ESP_MAIL_DEFAULT_DEBUG_PORT in ESP_Mail_FS.h + */ + smtp.debug(1); + + /* Set the callback function to get the sending results */ + smtp.callback(smtpCallback); + + /* Declare the Session_Config for user defined session credentials */ + Session_Config config; + + /* Set the session config */ + config.server.host_name = SMTP_HOST; + config.server.port = SMTP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + + /** Assign your host name or you public IPv4 or IPv6 only + * as this is the part of EHLO/HELO command to identify the client system + * to prevent connection rejection. + * If host name or public IP is not available, ignore this or + * use loopback address "127.0.0.1". + * + * Assign any text to this option may cause the connection rejection. + */ + config.login.user_domain = F("127.0.0.1"); + + /** If non-secure port is prefered (not allow SSL and TLS connection), use + * config.secure.mode = esp_mail_secure_mode_nonsecure; + * + * If SSL and TLS are always required, use + * config.secure.mode = esp_mail_secure_mode_ssl_tls; + * + * To disable SSL permanently (use less program space), define ESP_MAIL_DISABLE_SSL in ESP_Mail_FS.h + * or Custom_ESP_Mail_FS.h + */ + // config.secure.mode = esp_mail_secure_mode_nonsecure; + + /* + Set the NTP config time + For times east of the Prime Meridian use 0-12 + For times west of the Prime Meridian add 12 to the offset. + Ex. American/Denver GMT would be -6. 6 + 12 = 18 + See https://en.wikipedia.org/wiki/Time_zone for a list of the GMT/UTC timezone offsets + */ + config.time.ntp_server = F("pool.ntp.org,time.nist.gov"); + config.time.gmt_offset = 3; + config.time.day_light_offset = 0; + + /* The full message sending logs can now save to file */ + /* Since v3.0.4, the sent logs stored in smtp.sendingResult will store only the latest message logs */ + // config.sentLogs.filename = "/path/to/log/file"; + // config.sentLogs.storage_type = esp_mail_file_storage_type_flash; + + /** In ESP32, timezone environment will not keep after wake up boot from sleep. + * The local time will equal to GMT time. + * + * To sync or set time with NTP server with the valid local time after wake up boot, + * set both gmt and day light offsets to 0 and assign the timezone environment string e.g. + + config.time.ntp_server = F("pool.ntp.org,time.nist.gov"); + config.time.gmt_offset = 0; + config.time.day_light_offset = 0; + config.time.timezone_env_string = "JST-9"; // for Tokyo + + * The library will get (sync) the time from NTP server without GMT time offset adjustment + * and set the timezone environment variable later. + * + * This timezone environment string will be stored to flash or SD file named "/tze.txt" + * which set via config.time.timezone_file. + * + * See the timezone environment string list from + * https://github.com/nayarsystems/posix_tz_db/blob/master/zones.csv + * + */ + + /* Declare the message class */ + SMTP_Message message; + + /* Set the message headers */ + message.sender.name = F("ESP Mail"); + message.sender.email = AUTHOR_EMAIL; + + /** If author and sender are not identical + message.sender.name = F("Sender"); + message.sender.email = "sender@mail.com"; + message.author.name = F("ESP Mail"); + message.author.email = AUTHOR_EMAIL; // should be the same email as config.login.email + */ + + message.subject = F("Test sending plain text Email"); + message.addRecipient(F("Someone"), RECIPIENT_EMAIL); + + String textMsg = "This is simple plain text message"; + message.text.content = textMsg; + + /** If the message to send is a large string, to reduce the memory used from internal copying while sending, + * you can assign string to message.text.blob by cast your string to uint8_t array like this + * + * String myBigString = "..... ......"; + * message.text.blob.data = (uint8_t *)myBigString.c_str(); + * message.text.blob.size = myBigString.length(); + * + * or assign string to message.text.nonCopyContent, like this + * + * message.text.nonCopyContent = myBigString.c_str(); + * + * Only base64 encoding is supported for content transfer encoding in this case. + */ + + /** The Plain text message character set e.g. + * us-ascii + * utf-8 + * utf-7 + * The default value is utf-8 + */ + message.text.charSet = F("us-ascii"); + + /** The content transfer encoding e.g. + * enc_7bit or "7bit" (not encoded) + * enc_qp or "quoted-printable" (encoded) + * enc_base64 or "base64" (encoded) + * enc_binary or "binary" (not encoded) + * enc_8bit or "8bit" (not encoded) + * The default value is "7bit" + */ + message.text.transfer_encoding = Content_Transfer_Encoding::enc_7bit; + + // If this is a reply message + // message.in_reply_to = ""; + // message.references = " "; + + /** The message priority + * esp_mail_smtp_priority_high or 1 + * esp_mail_smtp_priority_normal or 3 + * esp_mail_smtp_priority_low or 5 + * The default value is esp_mail_smtp_priority_low + */ + message.priority = esp_mail_smtp_priority::esp_mail_smtp_priority_low; + + // message.response.reply_to = "someone@somemail.com"; + // message.response.return_path = "someone@somemail.com"; + + /** The Delivery Status Notifications e.g. + * esp_mail_smtp_notify_never + * esp_mail_smtp_notify_success + * esp_mail_smtp_notify_failure + * esp_mail_smtp_notify_delay + * The default value is esp_mail_smtp_notify_never + */ + // message.response.notify = esp_mail_smtp_notify_success | esp_mail_smtp_notify_failure | esp_mail_smtp_notify_delay; + + /* Set the custom message header */ + message.addHeader(F("Message-ID: ")); + + // For Root CA certificate verification (ESP8266 and ESP32 only) + // config.certificate.cert_data = rootCACert; + // or + // config.certificate.cert_file = "/path/to/der/file"; + // config.certificate.cert_file_storage_type = esp_mail_file_storage_type_flash; // esp_mail_file_storage_type_sd + // config.certificate.verify = true; + + // The WiFiNINA firmware the Root CA certification can be added via the option in Firmware update tool in Arduino IDE + + /* Connect to server with the session config */ + + // Library will be trying to sync the time with NTP server if time is never sync or set. + // This is 10 seconds blocking process. + // If time reading was timed out, the error "NTP server time reading timed out" will show via debug and callback function. + // You can manually sync time by yourself with NTP library or calling configTime in ESP32 and ESP8266. + // Time can be set manually with provided timestamp to function smtp.setSystemTime. + + /* Set the TCP response read timeout in seconds */ + // smtp.setTCPTimeout(10); + + /* Connect to the server */ + if (!smtp.connect(&config)) + { + MailClient.printf("Connection error, Status Code: %d, Error Code: %d, Reason: %s", smtp.statusCode(), smtp.errorCode(), smtp.errorReason().c_str()); + return; + } + + /** Or connect without log in and log in later + + if (!smtp.connect(&config, false)) + return; + + if (!smtp.loginWithPassword(AUTHOR_EMAIL, AUTHOR_PASSWORD)) + return; + */ + + if (!smtp.isLoggedIn()) + { + Serial.println("\nNot yet logged in."); + } + else + { + if (smtp.isAuthenticated()) + Serial.println("\nSuccessfully logged in."); + else + Serial.println("\nConnected with no Auth."); + } + + /* Start sending Email and close the session */ + if (!MailClient.sendMail(&smtp, &message)) + MailClient.printf("Error, Status Code: %d, Error Code: %d, Reason: %s", smtp.statusCode(), smtp.errorCode(), smtp.errorReason().c_str()); + + // to clear sending result log + // smtp.sendingResult.clear(); +} + +void loop() +{ +} + +/* Callback function to get the Email sending status */ +void smtpCallback(SMTP_Status status) +{ + /* Print the current status */ + Serial.println(status.info()); + + /* Print the sending result */ + if (status.success()) + { + // MailClient.printf used in the examples is for format printing via debug Serial port + // that works for all supported Arduino platform SDKs e.g. SAMD, ESP32 and ESP8266. + // In ESP8266 and ESP32, you can use Serial.printf directly. + + Serial.println("----------------"); + MailClient.printf("Message sent success: %d\n", status.completedCount()); + MailClient.printf("Message sent failed: %d\n", status.failedCount()); + Serial.println("----------------\n"); + + for (size_t i = 0; i < smtp.sendingResult.size(); i++) + { + /* Get the result item */ + SMTP_Result result = smtp.sendingResult.getItem(i); + + // In case, ESP32, ESP8266 and SAMD device, the timestamp get from result.timestamp should be valid if + // your device time was synched with NTP server. + // Other devices may show invalid timestamp as the device time was not set i.e. it will show Jan 1, 1970. + // You can call smtp.setSystemTime(xxx) to set device time manually. Where xxx is timestamp (seconds since Jan 1, 1970) + + MailClient.printf("Message No: %d\n", i + 1); + MailClient.printf("Status: %s\n", result.completed ? "success" : "failed"); + MailClient.printf("Date/Time: %s\n", MailClient.Time.getDateTimeString(result.timestamp, "%B %d, %Y %H:%M:%S").c_str()); + MailClient.printf("Recipient: %s\n", result.recipients.c_str()); + MailClient.printf("Subject: %s\n", result.subject.c_str()); + } + Serial.println("----------------\n"); + + // You need to clear sending result as the memory usage will grow up. + smtp.sendingResult.clear(); + } +} diff --git a/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_Text_Flowed/Send_Text_Flowed.ino b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_Text_Flowed/Send_Text_Flowed.ino new file mode 100644 index 000000000..badb2b5a6 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Send_Text_Flowed/Send_Text_Flowed.ino @@ -0,0 +1,308 @@ + +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt +*/ + +// This example shows how to send text message with text wrapping. + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +#include + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +/** For Gmail, the app password will be used for log in + * Check out https://github.com/mobizt/ESP-Mail-Client#gmail-smtp-and-imap-required-app-passwords-to-sign-in + * + * For Yahoo mail, log in to your yahoo mail in web browser and generate app password by go to + * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc + * + * To use Gmai and Yahoo's App Password to sign in, define the AUTHOR_PASSWORD with your App Password + * and AUTHOR_EMAIL with your account email. + */ + +/** The smtp host name e.g. smtp.gmail.com for GMail or smtp.office365.com for Outlook or smtp.mail.yahoo.com */ +#define SMTP_HOST "" + +/** The smtp port e.g. + * 25 or esp_mail_smtp_port_25 + * 465 or esp_mail_smtp_port_465 + * 587 or esp_mail_smtp_port_587 + */ +#define SMTP_PORT esp_mail_smtp_port_587 + +/* The log in credentials */ +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" + +/* Recipient email address */ +#define RECIPIENT_EMAIL "" + +/* Declare the global used SMTPSession object for SMTP transport */ +SMTPSession smtp; + +/* Callback function to get the Email sending status */ +void smtpCallback(SMTP_Status status); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) +WiFiMulti multi; +#endif + +void setup() +{ + + Serial.begin(115200); + +#if defined(ARDUINO_ARCH_SAMD) + while (!Serial) + ; +#endif + + Serial.println(); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + multi.addAP(WIFI_SSID, WIFI_PASSWORD); + multi.run(); +#else + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Connecting to Wi-Fi"); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + unsigned long ms = millis(); +#endif + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + if (millis() - ms > 10000) + break; +#endif + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + /* Set the network reconnection option */ + MailClient.networkReconnect(true); + + // The WiFi credentials are required for Pico W + // due to it does not have reconnect feature. +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + MailClient.clearAP(); + MailClient.addAP(WIFI_SSID, WIFI_PASSWORD); +#endif + + /** Enable the debug via Serial port + * 0 for no debugging + * 1 for basic level debugging + * + * Debug port can be changed via ESP_MAIL_DEFAULT_DEBUG_PORT in ESP_Mail_FS.h + */ + smtp.debug(1); + + /* Set the callback function to get the sending results */ + smtp.callback(smtpCallback); + + /* Declare the Session_Config for user defined session credentials */ + Session_Config config; + + /* Set the session config */ + config.server.host_name = SMTP_HOST; + config.server.port = SMTP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + + /** Assign your host name or you public IPv4 or IPv6 only + * as this is the part of EHLO/HELO command to identify the client system + * to prevent connection rejection. + * If host name or public IP is not available, ignore this or + * use loopback address "127.0.0.1". + * + * Assign any text to this option may cause the connection rejection. + */ + config.login.user_domain = F("127.0.0.1"); + + /* + Set the NTP config time + For times east of the Prime Meridian use 0-12 + For times west of the Prime Meridian add 12 to the offset. + Ex. American/Denver GMT would be -6. 6 + 12 = 18 + See https://en.wikipedia.org/wiki/Time_zone for a list of the GMT/UTC timezone offsets + */ + config.time.ntp_server = F("pool.ntp.org,time.nist.gov"); + config.time.gmt_offset = 3; + config.time.day_light_offset = 0; + + /* Declare the message class */ + SMTP_Message message; + + /* Set the message headers */ + /* Set the message headers */ + message.sender.name = F("ESP Mail"); + message.sender.email = AUTHOR_EMAIL; + message.subject = F("Test sending plain text Email"); + message.addRecipient(F("Someone"), RECIPIENT_EMAIL); + + /** The option to add soft line break to to the message for + * the long text message > 78 characters (rfc 3676) + * Some Servers may not compliant with this standard. + */ + message.text.flowed = true; + + /** if the option message.text.flowed is true, + * the following plain text message will be wrapped. + */ + message.text.content = F("The text below is the long quoted text which breaks into several lines.\r\n\r\n>> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.\r\n\r\nThis is the normal short text.\r\n\r\nAnother long text, abcdefg hijklmnop qrstuv wxyz abcdefg hijklmnop qrstuv wxyz abcdefg hijklmnop qrstuv wxyz."); + + /** The Plain text message character set e.g. + * us-ascii + * utf-8 + * utf-7 + * The default value is utf-8 + */ + message.text.charSet = F("us-ascii"); + + /** The content transfer encoding e.g. + * enc_7bit or "7bit" (not encoded) + * enc_qp or "quoted-printable" (encoded) + * enc_base64 or "base64" (encoded) + * enc_binary or "binary" (not encoded) + * enc_8bit or "8bit" (not encoded) + * The default value is "7bit" + */ + message.text.transfer_encoding = Content_Transfer_Encoding::enc_7bit; + + /** The message priority + * esp_mail_smtp_priority_high or 1 + * esp_mail_smtp_priority_normal or 3 + * esp_mail_smtp_priority_low or 5 + * The default value is esp_mail_smtp_priority_low + */ + message.priority = esp_mail_smtp_priority::esp_mail_smtp_priority_low; + + /** The Delivery Status Notifications e.g. + * esp_mail_smtp_notify_never + * esp_mail_smtp_notify_success + * esp_mail_smtp_notify_failure + * esp_mail_smtp_notify_delay + * The default value is esp_mail_smtp_notify_never + */ + // message.response.notify = esp_mail_smtp_notify_success | esp_mail_smtp_notify_failure | esp_mail_smtp_notify_delay; + + /* Set the custom message header */ + message.addHeader(F("Message-ID: ")); + + /* Connect to the server */ + if (!smtp.connect(&config)) + { + MailClient.printf("Connection error, Status Code: %d, Error Code: %d, Reason: %s", smtp.statusCode(), smtp.errorCode(), smtp.errorReason().c_str()); + return; + } + + if (!smtp.isLoggedIn()) + { + Serial.println("\nNot yet logged in."); + } + else + { + if (smtp.isAuthenticated()) + Serial.println("\nSuccessfully logged in."); + else + Serial.println("\nConnected with no Auth."); + } + + /* Start sending Email and close the session */ + if (!MailClient.sendMail(&smtp, &message)) + MailClient.printf("Error, Status Code: %d, Error Code: %d, Reason: %s", smtp.statusCode(), smtp.errorCode(), smtp.errorReason().c_str()); + + // to clear sending result log + // smtp.sendingResult.clear(); + + MailClient.printf("Free Heap: %d\n", MailClient.getFreeHeap()); +} + +void loop() +{ +} + +/* Callback function to get the Email sending status */ +void smtpCallback(SMTP_Status status) +{ + /* Print the current status */ + Serial.println(status.info()); + + /* Print the sending result */ + if (status.success()) + { + // MailClient.printf used in the examples is for format printing via debug Serial port + // that works for all supported Arduino platform SDKs e.g. SAMD, ESP32 and ESP8266. + // In ESP8266 and ESP32, you can use Serial.printf directly. + + Serial.println("----------------"); + MailClient.printf("Message sent success: %d\n", status.completedCount()); + MailClient.printf("Message sent failed: %d\n", status.failedCount()); + Serial.println("----------------\n"); + + for (size_t i = 0; i < smtp.sendingResult.size(); i++) + { + /* Get the result item */ + SMTP_Result result = smtp.sendingResult.getItem(i); + + // In case, ESP32, ESP8266 and SAMD device, the timestamp get from result.timestamp should be valid if + // your device time was synched with NTP server. + // Other devices may show invalid timestamp as the device time was not set i.e. it will show Jan 1, 1970. + // You can call smtp.setSystemTime(xxx) to set device time manually. Where xxx is timestamp (seconds since Jan 1, 1970) + + MailClient.printf("Message No: %d\n", i + 1); + MailClient.printf("Status: %s\n", result.completed ? "success" : "failed"); + MailClient.printf("Date/Time: %s\n", MailClient.Time.getDateTimeString(result.timestamp, "%B %d, %Y %H:%M:%S").c_str()); + MailClient.printf("Recipient: %s\n", result.recipients.c_str()); + MailClient.printf("Subject: %s\n", result.subject.c_str()); + } + Serial.println("----------------\n"); + + // You need to clear sending result as the memory usage will grow up. + smtp.sendingResult.clear(); + } +} diff --git a/lib/libesp32/ESP-Mail-Client/examples/SMTP/Set_Time/Set_Time.ino b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Set_Time/Set_Time.ino new file mode 100644 index 000000000..fcf96414f --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Set_Time/Set_Time.ino @@ -0,0 +1,253 @@ + +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt + */ + +// This example showes how to set the library and/or device time manually. + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +#include +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#include "RTC.h" +#endif + +#include + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +#define SMTP_HOST "" +#define SMTP_PORT esp_mail_smtp_port_587 + +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" +#define RECIPIENT_EMAIL "" + +SMTPSession smtp; + +void smtpCallback(SMTP_Status status); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) +WiFiMulti multi; +#endif + +void setup() +{ + + Serial.begin(115200); + + Serial.println(); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + multi.addAP(WIFI_SSID, WIFI_PASSWORD); + multi.run(); +#else + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); +#endif + + Serial.print("Connecting to Wi-Fi"); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + unsigned long ms = millis(); +#endif + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(300); +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + if (millis() - ms > 10000) + break; +#endif + } + Serial.println(); + Serial.print("Connected with IP: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + Serial.print("Waiting for NTP server time reading"); + +#if defined(ESP8266) || defined(ESP32) && !defined(ARDUINO_NANO_RP2040_CONNECT) + + configTime(0, 0, "pool.ntp.org", "time.nist.gov"); + while (time(nullptr) < ESP_MAIL_CLIENT_VALID_TS) + { + delay(100); + } + +#elif defined(ARDUINO_RASPBERRY_PI_PICO_W) + + configTime(10000, 0, "pool.ntp.org", "time.nist.gov"); + while (time(nullptr) < ESP_MAIL_CLIENT_VALID_TS) + { + delay(100); + } + +#elif __has_include() || __has_include() + time_t ts = 0; + do + { + ts = WiFi.getTime(); + delay(100); + } while (ts < ESP_MAIL_CLIENT_VALID_TS); + + float gmtOffset = 3.0; // GMT offset in hour + + smtp.setSystemTime(ts, gmtOffset); + +#elif __has_include() + + // see https://docs.arduino.cc/tutorials/uno-r4-wifi/rtc + + RTC.begin(); + + // RTCTime startTime(30, Month::JUNE, 2023, 13, 37, 00, DayOfWeek::WEDNESDAY, SaveLight::SAVING_TIME_ACTIVE); + // RTC.setTime(startTime); + + RTCTime currentTime; + + // Get current time from RTC + RTC.getTime(currentTime); + + float gmtOffset = 3.0; // GMT offset in hour + smtp.setSystemTime(currentTime.getUnixTime(), gmtOffset); + +#endif + + // To disable library internal NTP time reading, please comment or remove the following macro defined in src/ESP_Mail_FS.h + // #define ENABLE_NTP_TIME + + MailClient.networkReconnect(true); + +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + MailClient.clearAP(); + MailClient.addAP(WIFI_SSID, WIFI_PASSWORD); +#endif + + smtp.debug(1); + + smtp.callback(smtpCallback); + + Session_Config config; + + config.server.host_name = SMTP_HOST; + config.server.port = SMTP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + + config.login.user_domain = F("127.0.0.1"); + + /** + * Once the system time (using smtp.setSystemTime) or device time was set before calling smtp.connect, the following config will + * not take effect when NTP time is enabled. + * + * config.time.ntp_server + * config.time.gmt_offset + * config.time.day_light_offset + * + * To reset the reference time and use config.time instead, call smtp.setSystemTime(0) whenever you want. + */ + + SMTP_Message message; + + /* Set the message headers */ + message.sender.name = F("ESP Mail"); + message.sender.email = AUTHOR_EMAIL; + message.addRecipient(F("Someone"), RECIPIENT_EMAIL); + + /* The time format of timestamp to inject into subject or content as using in strftime C++ function */ + message.timestamp.tag = "#esp_mail_current_time"; + + /* The tag that will be replaced with current timestamp */ + message.timestamp.format = "%B %d, %Y %H:%M:%S"; + + message.subject = F("Test sending plain text Email (#esp_mail_current_time)"); + + message.text.content = "This is simple plain text message\n\nSent #esp_mail_current_time"; + + if (!smtp.connect(&config)) + { + MailClient.printf("Connection error, Status Code: %d, Error Code: %d, Reason: %s", smtp.statusCode(), smtp.errorCode(), smtp.errorReason().c_str()); + return; + } + + if (!smtp.isLoggedIn()) + { + Serial.println("\nNot yet logged in."); + } + else + { + if (smtp.isAuthenticated()) + Serial.println("\nSuccessfully logged in."); + else + Serial.println("\nConnected with no Auth."); + } + + if (!MailClient.sendMail(&smtp, &message)) + MailClient.printf("Error, Status Code: %d, Error Code: %d, Reason: %s", smtp.statusCode(), smtp.errorCode(), smtp.errorReason().c_str()); +} + +void loop() +{ +} + +void smtpCallback(SMTP_Status status) +{ + Serial.println(status.info()); + + if (status.success()) + { + + Serial.println("----------------"); + MailClient.printf("Message sent success: %d\n", status.completedCount()); + MailClient.printf("Message sent failed: %d\n", status.failedCount()); + Serial.println("----------------\n"); + + for (size_t i = 0; i < smtp.sendingResult.size(); i++) + { + + SMTP_Result result = smtp.sendingResult.getItem(i); + + MailClient.printf("Message No: %d\n", i + 1); + MailClient.printf("Status: %s\n", result.completed ? "success" : "failed"); + MailClient.printf("Date/Time: %s\n", MailClient.Time.getDateTimeString(result.timestamp, "%B %d, %Y %H:%M:%S").c_str()); + MailClient.printf("Recipient: %s\n", result.recipients.c_str()); + MailClient.printf("Subject: %s\n", result.subject.c_str()); + } + Serial.println("----------------\n"); + + smtp.sendingResult.clear(); + } +} diff --git a/lib/libesp32/ESP-Mail-Client/examples/SMTP/Sleep/Sleep.ino b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Sleep/Sleep.ino new file mode 100644 index 000000000..2902423aa --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/examples/SMTP/Sleep/Sleep.ino @@ -0,0 +1,310 @@ +/** + * Created by K. Suwatchai (Mobizt) + * + * Email: suwatchai@outlook.com + * + * Github: https://github.com/mobizt/ESP-Mail-Client + * + * Copyright (c) 2023 mobizt + */ + +// This example showes how the device time was resume after device woke up from sleep. + +/** Note for library update from v2.x.x to v3.x.x. + * + * Struct data names changed + * + * "ESP_Mail_Session" changes to "Session_Config" + * "IMAP_Config" changes to "IMAP_Data" + * + * Changes in the examples + * + * ESP_Mail_Session session; + * to + * Session_Config config; + * + * IMAP_Config config; + * to + * IMAP_Data imap_data; + */ + +#include +#if defined(ESP32) +#include +#else + +// Other Client defined here +// To use custom Client, define ENABLE_CUSTOM_CLIENT in src/ESP_Mail_FS.h. +// See the example Custom_Client.ino for how to use. + +#endif + +#include + +#define WIFI_SSID "" +#define WIFI_PASSWORD "" + +/** For Gmail, to send Email via port 465 (SSL), less secure app option + * should be enabled in the account settings. https://myaccount.google.com/lesssecureapps?pli=1 + * + * Some Gmail user still not able to sign in using account password even above option was set up, + * for this case, use "App Password" to sign in instead. + * About Gmail "App Password", go to https://support.google.com/accounts/answer/185833?hl=en + * + * For Yahoo mail, log in to your yahoo mail in web browser and generate app password by go to + * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc + * + * To use Gmai and Yahoo's App Password to sign in, define the AUTHOR_PASSWORD with your App Password + * and AUTHOR_EMAIL with your account email. + */ + +/** The smtp host name e.g. smtp.gmail.com for GMail or smtp.office365.com for Outlook or smtp.mail.yahoo.com */ +#define SMTP_HOST "" + +/** The smtp port e.g. + * 25 or esp_mail_smtp_port_25 + * 465 or esp_mail_smtp_port_465 + * 587 or esp_mail_smtp_port_587 + */ +#define SMTP_PORT esp_mail_smtp_port_587 // port 465 is not available for Outlook.com + +/* The log in credentials */ +#define AUTHOR_EMAIL "" +#define AUTHOR_PASSWORD "" + +/* Recipient email address */ +#define RECIPIENT_EMAIL "" + +/* Declare the global used SMTPSession object for SMTP transport */ +SMTPSession smtp; + +/* Callback function to get the Email sending status */ +void smtpCallback(SMTP_Status status); + +const char rootCACert[] PROGMEM = "-----BEGIN CERTIFICATE-----\n" + "-----END CERTIFICATE-----\n"; + +void sendEmail() +{ + /* Declare the Session_Config for user defined session credentials */ + Session_Config config; + + /* Set the session config */ + config.server.host_name = SMTP_HOST; + config.server.port = SMTP_PORT; + config.login.email = AUTHOR_EMAIL; + config.login.password = AUTHOR_PASSWORD; + config.login.user_domain = F("127.0.0.1"); + + /* + Set the NTP config time + For times east of the Prime Meridian use 0-12 + For times west of the Prime Meridian add 12 to the offset. + Ex. American/Denver GMT would be -6. 6 + 12 = 18 + See https://en.wikipedia.org/wiki/Time_zone for a list of the GMT/UTC timezone offsets + */ + config.time.ntp_server = F("pool.ntp.org,time.nist.gov"); + config.time.gmt_offset = 0; + config.time.day_light_offset = 0; + config.time.timezone_env_string = "JST-9"; // for Tokyo + + // See the timezone environment string list from https://github.com/nayarsystems/posix_tz_db/blob/master/zones.csv + + /* Declare the message class */ + SMTP_Message message; + + /* Set the message headers */ + message.sender.name = F("ESP Mail"); // This witll be used with 'MAIL FROM' command and 'From' header field. + message.sender.email = AUTHOR_EMAIL; // This witll be used with 'From' header field. + message.subject = F("Test sending plain text Email"); + message.addRecipient(F("Someone"), RECIPIENT_EMAIL); // This will be used with RCPT TO command and 'To' header field. + + String textMsg = "This is simple plain text message"; + message.text.content = textMsg; + + /** If the message to send is a large string, to reduce the memory used from internal copying while sending, + * you can assign string to message.text.blob by cast your string to uint8_t array like this + * + * String myBigString = "..... ......"; + * message.text.blob.data = (uint8_t *)myBigString.c_str(); + * message.text.blob.size = myBigString.length(); + * + * or assign string to message.text.nonCopyContent, like this + * + * message.text.nonCopyContent = myBigString.c_str(); + * + * Only base64 encoding is supported for content transfer encoding in this case. + */ + + /** The Plain text message character set e.g. + * us-ascii + * utf-8 + * utf-7 + * The default value is utf-8 + */ + message.text.charSet = F("us-ascii"); + + /** The content transfer encoding e.g. + * enc_7bit or "7bit" (not encoded) + * enc_qp or "quoted-printable" (encoded) + * enc_base64 or "base64" (encoded) + * enc_binary or "binary" (not encoded) + * enc_8bit or "8bit" (not encoded) + * The default value is "7bit" + */ + message.text.transfer_encoding = Content_Transfer_Encoding::enc_7bit; + + // If this is a reply message + // message.in_reply_to = ""; + // message.references = " "; + + /** The message priority + * esp_mail_smtp_priority_high or 1 + * esp_mail_smtp_priority_normal or 3 + * esp_mail_smtp_priority_low or 5 + * The default value is esp_mail_smtp_priority_low + */ + message.priority = esp_mail_smtp_priority::esp_mail_smtp_priority_low; + + // message.response.reply_to = "someone@somemail.com"; + // message.response.return_path = "someone@somemail.com"; + + /** The Delivery Status Notifications e.g. + * esp_mail_smtp_notify_never + * esp_mail_smtp_notify_success + * esp_mail_smtp_notify_failure + * esp_mail_smtp_notify_delay + * The default value is esp_mail_smtp_notify_never + */ + // message.response.notify = esp_mail_smtp_notify_success | esp_mail_smtp_notify_failure | esp_mail_smtp_notify_delay; + + /* Set the custom message header */ + message.addHeader(F("Message-ID: ")); + + // For Root CA certificate verification (ESP8266 and ESP32 only) + // config.certificate.cert_data = rootCACert; + // or + // config.certificate.cert_file = "/path/to/der/file"; + // config.certificate.cert_file_storage_type = esp_mail_file_storage_type_flash; // esp_mail_file_storage_type_sd + // config.certificate.verify = true; + + // The WiFiNINA firmware the Root CA certification can be added via the option in Firmware update tool in Arduino IDE + + /* Connect to server with the session config */ + + // Library will be trying to sync the time with NTP server if time is never sync or set. + // This is 10 seconds blocking process. + // If time reading was timed out, the error "NTP server time reading timed out" will show via debug and callback function. + // You can manually sync time by yourself with NTP library or calling configTime in ESP32 and ESP8266. + // Time can be set manually with provided timestamp to function smtp.setSystemTime. + + /* Connect to the server */ + if (!smtp.connect(&config)) + { + MailClient.printf("Connection error, Status Code: %d, Error Code: %d, Reason: %s", smtp.statusCode(), smtp.errorCode(), smtp.errorReason().c_str()); + return; + } + + /* Start sending Email and close the session */ + if (!MailClient.sendMail(&smtp, &message)) + MailClient.printf("Error, Status Code: %d, Error Code: %d, Reason: %s", smtp.statusCode(), smtp.errorCode(), smtp.errorReason().c_str()); + + // to clear sending result log + // smtp.sendingResult.clear(); + + MailClient.printf("Free Heap: %d\n", MailClient.getFreeHeap()); +} + +void setup() +{ + + Serial.begin(115200); + + Serial.println(); + + Serial.print("Connecting to AP"); + + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + delay(200); + } + + Serial.println(""); + Serial.println("WiFi connected."); + Serial.println("IP address: "); + Serial.println(WiFi.localIP()); + Serial.println(); + + /** Enable the debug via Serial port + * 0 for no debugging + * 1 for basic level debugging + * + * Debug port can be changed via ESP_MAIL_DEFAULT_DEBUG_PORT in ESP_Mail_FS.h + */ + smtp.debug(1); + + /* Set the callback function to get the sending results */ + smtp.callback(smtpCallback); + + sendEmail(); + + // Sleep for 60 seconds + + Serial.println("Going to sleep for 60 seconds..."); + +#if defined(ESP32) + + esp_sleep_enable_timer_wakeup(60 * 1000000); + + esp_deep_sleep_start(); + +#endif +} + +void loop() +{ +} + +/* Callback function to get the Email sending status */ +void smtpCallback(SMTP_Status status) +{ + /* Print the current status */ + Serial.println(status.info()); + + /* Print the sending result */ + if (status.success()) + { + // MailClient.printf used in the examples is for format printing via debug Serial port + // that works for all supported Arduino platform SDKs e.g. AVR, SAMD, ESP32 and ESP8266. + // In ESP8266 and ESP32, you can use Serial.printf directly. + + Serial.println("----------------"); + MailClient.printf("Message sent success: %d\n", status.completedCount()); + MailClient.printf("Message sent failed: %d\n", status.failedCount()); + Serial.println("----------------\n"); + struct tm dt; + + for (size_t i = 0; i < smtp.sendingResult.size(); i++) + { + /* Get the result item */ + SMTP_Result result = smtp.sendingResult.getItem(i); + + // In case, ESP32, ESP8266 and SAMD device, the timestamp get from result.timestamp should be valid if + // your device time was synched with NTP server. + // Other devices may show invalid timestamp as the device time was not set i.e. it will show Jan 1, 1970. + // You can call smtp.setSystemTime(xxx) to set device time manually. Where xxx is timestamp (seconds since Jan 1, 1970) + + MailClient.printf("Message No: %d\n", i + 1); + MailClient.printf("Status: %s\n", result.completed ? "success" : "failed"); + MailClient.printf("Date/Time: %s\n", MailClient.Time.getDateTimeString(result.timestamp, "%B %d, %Y %H:%M:%S").c_str()); + MailClient.printf("Recipient: %s\n", result.recipients.c_str()); + MailClient.printf("Subject: %s\n", result.subject.c_str()); + } + Serial.println("----------------\n"); + + // You need to clear sending result as the memory usage will grow up. + smtp.sendingResult.clear(); + } +} diff --git a/lib/libesp32/lib_mail/keywords.txt b/lib/libesp32/ESP-Mail-Client/keywords.txt similarity index 62% rename from lib/libesp32/lib_mail/keywords.txt rename to lib/libesp32/ESP-Mail-Client/keywords.txt index 8e669d92c..86c058045 100644 --- a/lib/libesp32/lib_mail/keywords.txt +++ b/lib/libesp32/ESP-Mail-Client/keywords.txt @@ -1,127 +1,194 @@ -###################################### -# Syntax Coloring Map ESP Mail Client -###################################### - -####################################### -# Classes and Structured Type (KEYWORD1) -####################################### - -MailClient KEYWORD1 -IMAPSession KEYWORD1 -SMTPSession KEYWORD1 -SMTP_Message KEYWORD1 -IMAP_Config KEYWORD1 -FoldersCollection KEYWORD1 -imapStatusCallback KEYWORD1 -IMAP_MSG_List KEYWORD1 -SelectedFolderInfo KEYWORD1 -ESP_Mail_Session KEYWORD1 -smtpStatusCallback KEYWORD1 -SMTP_Attachment KEYWORD1 -SMTP_Result KEYWORD1 -IMAP_MSG_Item KEYWORD1 -Content_Transfer_Encoding KEYWORD1 -MessageList KEYWORD1 - -############################################### -# Methods and Functions (KEYWORD2) -############################################### - -sendMail KEYWORD2 -readMail KEYWORD2 -setFlag KEYWORD2 -addFlag KEYWORD2 -removeFlag KEYWORD2 -sdBegin KEYWORD2 -sdMMCBegin KEYWORD2 -connect KEYWORD2 -closeSession KEYWORD2 -debug KEYWORD2 -getFolders KEYWORD2 -selectFolder KEYWORD2 -openFolder KEYWORD2 -closeFolder KEYWORD2 -callback KEYWORD2 -headerOnly KEYWORD2 -data KEYWORD2 -selectedFolder KEYWORD2 -errorReason KEYWORD2 -empty KEYWORD2 -resetAttachItem KEYWORD2 -clear KEYWORD2 -clearInlineimages KEYWORD2 -clearAttachments KEYWORD2 -clearRFC822Messages KEYWORD2 -clearRecipients KEYWORD2 -clearCc KEYWORD2 -clearBcc KEYWORD2 -clearHeader KEYWORD2 -addAttachment KEYWORD2 -addParallelAttachment KEYWORD2 -addInlineImage KEYWORD2 -addMessage KEYWORD2 -addRecipient KEYWORD2 -addCc KEYWORD2 -addBcc KEYWORD2 -addHeader KEYWORD2 -info KEYWORD2 -successs KEYWORD2 -completedCount KEYWORD2 -failedCount KEYWORD2 -getItem KEYWORD2 -size KEYWORD2 -flagCount KEYWORD2 -msgCount KEYWORD2 -nextUID KEYWORD2 -searchCount KEYWORD2 -availableMessages KEYWORD2 -flag KEYWORD2 -setClock KEYWORD2 -getUnixTime KEYWORD2 -getTimestamp KEYWORD2 -getYear KEYWORD2 -getMonth KEYWORD2 -getDay KEYWORD2 -getDayOfWeek KEYWORD2 -getDayOfWeekString KEYWORD2 -getHour KEYWORD2 -getMin KEYWORD2 -getSecond KEYWORD2 -getNumberOfDayThisYear KEYWORD2 -getTotalDays KEYWORD2 -dayofWeek KEYWORD2 -getCurrentSecond KEYWORD2 -getCurrentTimestamp KEYWORD2 -getTimeFromSec KEYWORD2 -getDateTimeString KEYWORD2 -copyMessages KEYWORD2 -deleteMessages KEYWORD2 -createFolder KEYWORD2 -deleteFolder KEYWORD2 - - -####################################### -# Struct (KEYWORD3) -####################################### - -esp_mail_email_info_t KEYWORD3 -esp_mail_plain_body_t KEYWORD3 -esp_mail_html_body_t KEYWORD3 -esp_mail_smtp_msg_response_t KEYWORD3 -esp_mail_smtp_enable_option_t KEYWORD3 -esp_mail_email_info_t KEYWORD3 -esp_mail_folder_info_item_t KEYWORD3 -esp_mail_sesson_sever_config_t KEYWORD3 -esp_mail_sesson_login_config_t KEYWORD3 -esp_mail_sesson_secure_config_t KEYWORD3 -esp_mail_sesson_cert_config_t KEYWORD3 -esp_mail_imap_fetch_config_t KEYWORD3 -esp_mail_imap_search_config_t KEYWORD3 -esp_mail_imap_limit_config_t KEYWORD3 -esp_mail_imap_enable_config_t KEYWORD3 -esp_mail_imap_download_config_t KEYWORD3 -esp_mail_imap_storage_config_t KEYWORD3 - -esp_mail_file_storage_type_none KEYWORD3 -esp_mail_file_storage_type_flash KEYWORD3 -esp_mail_file_storage_type_sd KEYWORD3 \ No newline at end of file +###################################### +# Syntax Coloring Map ESP Mail Client +###################################### + +####################################### +# Classes and Structured Type (KEYWORD1) +####################################### + +MailClient KEYWORD1 +IMAPSession KEYWORD1 +SMTPSession KEYWORD1 +SMTP_Message KEYWORD1 +IMAP_Config KEYWORD1 +IMAP_Data KEYWORD2 +FoldersCollection KEYWORD1 +imapStatusCallback KEYWORD1 +IMAP_MSG_List KEYWORD1 +SelectedFolderInfo KEYWORD1 +ESP_Mail_Session KEYWORD1 +Session_Config KEYWORD1 +smtpStatusCallback KEYWORD1 +imapResponseCallback KEYWORD1 +SMTP_Attachment KEYWORD1 +SMTP_Result KEYWORD1 +IMAP_MSG_Item KEYWORD1 +Content_Transfer_Encoding KEYWORD1 +MessageList KEYWORD1 + +############################################### +# Methods and Functions (KEYWORD2) +############################################### + +sendMail KEYWORD2 +appendMessage KEYWORD2 +readMail KEYWORD2 +setFlag KEYWORD2 +addFlag KEYWORD2 +removeFlag KEYWORD2 +networkReconnect KEYWORD2 +sdBegin KEYWORD2 +sdMMCBegin KEYWORD2 +getFreeHeap KEYWORD2 +connect KEYWORD2 +loginWithPassword KEYWORD2 +loginWithAccessToken KEYWORD2 +isAuthenticated KEYWORD2 +isLoggedIn KEYWORD2 +connected KEYWORD2 +keepAlive KEYWORD2 +isKeepAlive KEYWORD2 +customConnect KEYWORD2 +closeSession KEYWORD2 +debug KEYWORD2 +getFolders KEYWORD2 +selectFolder KEYWORD2 +openFolder KEYWORD2 +closeFolder KEYWORD2 +callback KEYWORD2 +headerOnly KEYWORD2 +data KEYWORD2 +selectedFolder KEYWORD2 +errorReason KEYWORD2 +statusCode KEYWORD2 +statusMessage KEYWORD2 +errorCode KEYWORD2 +empty KEYWORD2 +resetAttachItem KEYWORD2 +clear KEYWORD2 +clearInlineimages KEYWORD2 +clearAttachments KEYWORD2 +clearRFC822Messages KEYWORD2 +clearRecipients KEYWORD2 +clearCc KEYWORD2 +clearBcc KEYWORD2 +clearHeader KEYWORD2 +addAttachment KEYWORD2 +addParallelAttachment KEYWORD2 +addInlineImage KEYWORD2 +addMessage KEYWORD2 +addRecipient KEYWORD2 +addCc KEYWORD2 +addBcc KEYWORD2 +addHeader KEYWORD2 +info KEYWORD2 +successs KEYWORD2 +completedCount KEYWORD2 +failedCount KEYWORD2 +getItem KEYWORD2 +size KEYWORD2 +flagCount KEYWORD2 +msgCount KEYWORD2 +recentCount KEYWORD2 +nextUID KEYWORD2 +pollingStatus KEYWORD2 +searchCount KEYWORD2 +availableMessages KEYWORD2 +flag KEYWORD2 +setClock KEYWORD2 +getUnixTime KEYWORD2 +getTimestamp KEYWORD2 +getYear KEYWORD2 +getMonth KEYWORD2 +getDay KEYWORD2 +getDayOfWeek KEYWORD2 +getDayOfWeekString KEYWORD2 +getHour KEYWORD2 +getMin KEYWORD2 +getSecond KEYWORD2 +getNumberOfDayThisYear KEYWORD2 +getTotalDays KEYWORD2 +dayofWeek KEYWORD2 +getCurrentSecond KEYWORD2 +getCurrentTimestamp KEYWORD2 +getTimeFromSec KEYWORD2 +getDateTimeString KEYWORD2 +copyMessages KEYWORD2 +moveMessages KEYWORD2 +deleteMessages KEYWORD2 +getQuota KEYWORD2 +setQuota KEYWORD2 +getQuotaRoot KEYWORD2 +getACL KEYWORD2 +setACL KEYWORD2 +deleteACL KEYWORD2 +myRights KEYWORD2 +enable KEYWORD2 +getNamespace KEYWORD2 +createFolder KEYWORD2 +renameFolder KEYWORD2 +getSubscribesMailboxes KEYWORD2 +subscribe KEYWORD2 +unSubscribe KEYWORD2 +deleteFolder KEYWORD2 +listen KEYWORD2 +stopListen KEYWORD2 +folderChanged KEYWORD2 +sendCustomCommand KEYWORD2 +sendCustomData KEYWORD2 +toBase64 KEYWORD2 +getFlags KEYWORD2 +getUID KEYWORD2 +setTCPTimeout KEYWORD2 +setClient KEYWORD2 +setGSMClient KEYWORD2 +connectionRequestCallback KEYWORD2 +connectionUpgradeRequestCallback KEYWORD2 +networkConnectionRequestCallback KEYWORD2 +networkDisconnectionRequestCallback KEYWORD2 +networkStatusRequestCallback KEYWORD2 +setSystemTime KEYWORD2 +mimeDataStreamCallback KEYWORD2 +characterDecodingCallback KEYWORD2 +clearAP KEYWORD2 +addAP KEYWORD2 +isFirmwareUpdated KEYWORD2 +id KEYWORD2 +serverID KEYWORD2 +fileList KEYWORD2 +status KEYWORD2 + +####################################### +# Struct (KEYWORD3) +####################################### + +esp_mail_email_info_t KEYWORD3 +esp_mail_plain_body_t KEYWORD3 +esp_mail_html_body_t KEYWORD3 +esp_mail_smtp_msg_response_t KEYWORD3 +esp_mail_smtp_enable_option_t KEYWORD3 +esp_mail_email_info_t KEYWORD3 +esp_mail_folder_info_item_t KEYWORD3 +esp_mail_sesson_sever_config_t KEYWORD3 +esp_mail_sesson_login_config_t KEYWORD3 +esp_mail_sesson_secure_config_t KEYWORD3 +esp_mail_sesson_cert_config_t KEYWORD3 +esp_mail_imap_fetch_config_t KEYWORD3 +esp_mail_imap_search_config_t KEYWORD3 +esp_mail_imap_limit_config_t KEYWORD3 +esp_mail_imap_enable_config_t KEYWORD3 +esp_mail_imap_download_config_t KEYWORD3 +esp_mail_imap_storage_config_t KEYWORD3 +esp_mail_imap_polling_status_t KEYWORD3 +IMAP_Polling_Status KEYWORD3 +IMAP_Identification KEYWORD3 + +esp_mail_file_storage_type_none KEYWORD3 +esp_mail_file_storage_type_flash KEYWORD3 +esp_mail_file_storage_type_sd KEYWORD3 + +###################################### +# Constants (LITERAL1) +####################################### + +ESP_MAIL_PRINTF LITERAL1 \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/library.json b/lib/libesp32/ESP-Mail-Client/library.json new file mode 100644 index 000000000..6f1953984 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/library.json @@ -0,0 +1,16 @@ +{ + "name": "ESP Mail Client", + "version": "3.4.9", + "keywords": "communication, email, imap, smtp, esp32, esp8266, samd, arduino", + "description": "Arduino E-Mail Client Library to send, read and get incoming email notification for ESP32, ESP8266 and SAMD21 devices. The library also supported other Arduino Devices using Clients interfaces e.g. WiFiClient, EthernetClient, and GSMClient.", + "repository": { + "type": "git", + "url": "https://github.com/mobizt/ESP-Mail-Client.git" + }, + "authors": [{ + "name": "Mobizt", + "email": "suwatchai@outlook.com" + }], + "frameworks": "arduino", + "platforms": "espressif32, espressif8266, atmelsam, atmelavr, atmelmegaavr, ststm32, teensy, rp2040" +} diff --git a/lib/libesp32/ESP-Mail-Client/library.properties b/lib/libesp32/ESP-Mail-Client/library.properties new file mode 100644 index 000000000..80b2d2c7e --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/library.properties @@ -0,0 +1,17 @@ +name=ESP Mail Client + +version=3.4.9 + +author=Mobizt + +maintainer=Mobizt + +sentence=Arduino E-Mail Client Library to send, read and get incoming email notification for ESP32, ESP8266 and SAMD21 devices. + +paragraph=The library also supported other Arduino devices using Clients interfaces e.g. WiFiClient, EthernetClient, and GSMClient. + +category=Communication + +url=https://github.com/mobizt/ESP-Mail-Client + +architectures=esp8266,esp32,sam,samd,stm32,STM32F1,STM32F4,teensy,avr,megaavr,mbed_nano,mbed_rp2040,rp2040 diff --git a/lib/libesp32/lib_mail/media/images/ArduinoIDE.png b/lib/libesp32/ESP-Mail-Client/media/images/ArduinoIDE.png similarity index 100% rename from lib/libesp32/lib_mail/media/images/ArduinoIDE.png rename to lib/libesp32/ESP-Mail-Client/media/images/ArduinoIDE.png diff --git a/lib/libesp32/ESP-Mail-Client/media/images/ESP32-PSRAM.png b/lib/libesp32/ESP-Mail-Client/media/images/ESP32-PSRAM.png new file mode 100644 index 000000000..4e5ece8f1 Binary files /dev/null and b/lib/libesp32/ESP-Mail-Client/media/images/ESP32-PSRAM.png differ diff --git a/lib/libesp32/ESP-Mail-Client/media/images/ESP8266_VM.png b/lib/libesp32/ESP-Mail-Client/media/images/ESP8266_VM.png new file mode 100644 index 000000000..abf0090ee Binary files /dev/null and b/lib/libesp32/ESP-Mail-Client/media/images/ESP8266_VM.png differ diff --git a/lib/libesp32/ESP-Mail-Client/media/images/SerialNINAPassthrough.png b/lib/libesp32/ESP-Mail-Client/media/images/SerialNINAPassthrough.png new file mode 100644 index 000000000..130e78fce Binary files /dev/null and b/lib/libesp32/ESP-Mail-Client/media/images/SerialNINAPassthrough.png differ diff --git a/lib/libesp32/lib_mail/media/images/esp-mail-client.png b/lib/libesp32/ESP-Mail-Client/media/images/esp-mail-client.png similarity index 100% rename from lib/libesp32/lib_mail/media/images/esp-mail-client.png rename to lib/libesp32/ESP-Mail-Client/media/images/esp-mail-client.png diff --git a/lib/libesp32/lib_mail/media/images/esp-mail-client.svg b/lib/libesp32/ESP-Mail-Client/media/images/esp-mail-client.svg similarity index 100% rename from lib/libesp32/lib_mail/media/images/esp-mail-client.svg rename to lib/libesp32/ESP-Mail-Client/media/images/esp-mail-client.svg diff --git a/lib/libesp32/ESP-Mail-Client/media/images/esptool.png b/lib/libesp32/ESP-Mail-Client/media/images/esptool.png new file mode 100644 index 000000000..17c9c143d Binary files /dev/null and b/lib/libesp32/ESP-Mail-Client/media/images/esptool.png differ diff --git a/lib/libesp32/ESP-Mail-Client/src/ESP_Mail_Client.cpp b/lib/libesp32/ESP-Mail-Client/src/ESP_Mail_Client.cpp new file mode 100644 index 000000000..4c58543a2 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/ESP_Mail_Client.cpp @@ -0,0 +1,1933 @@ +#ifndef ESP_MAIL_CLIENT_CPP +#define ESP_MAIL_CLIENT_CPP + +#pragma GCC diagnostic ignored "-Wunused-but-set-variable" + +#include "ESP_Mail_Client_Version.h" +#if !VALID_VERSION_CHECK(30409) +#error "Mixed versions compilation." +#endif + +/** + * Mail Client Arduino Library for Arduino devices. + * + * Created August 28, 2023 + * + * This library allows Espressif's ESP32, ESP8266, SAMD and RP2040 Pico devices to send and read Email through the SMTP and IMAP servers. + * + * The MIT License (MIT) + * Copyright (c) 2023 K. Suwatchai (Mobizt) + * + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include "ESP_Mail_Client.h" +#include "ESP_Mail_Client_Version.h" + +#include "ESP_Mail_IMAP.h" +#include "ESP_Mail_SMTP.h" + +void ESP_Mail_Client::networkReconnect(bool reconnect) +{ +#if defined(ESP_MAIL_WIFI_IS_AVAILABLE) && (defined(ESP32) || defined(ESP8266)) + WiFi.setAutoReconnect(reconnect); +#endif + networkAutoReconnect = reconnect; +} + +void ESP_Mail_Client::printf(const char *format, ...) +{ + int size = 2048; + char s[size]; + va_list va; + va_start(va, format); + vsnprintf(s, size, format, va); + va_end(va); + ESP_MAIL_DEFAULT_DEBUG_PORT.print(s); +} + +void ESP_Mail_Client::addAP(const String &ssid, const String &password) +{ + wifi.addAP(ssid, password); +} + +void ESP_Mail_Client::clearAP() +{ + wifi.clearAP(); +} + +#if defined(MBFS_SD_FS) && defined(MBFS_CARD_TYPE_SD) + +bool ESP_Mail_Client::sdBegin(int8_t ss, int8_t sck, int8_t miso, int8_t mosi, uint32_t frequency) +{ + return mbfs->sdBegin(ss, sck, miso, mosi, frequency); +} + +#if defined(ESP8266) || defined(MB_ARDUINO_PICO) +bool ESP_Mail_Client::sdBegin(SDFSConfig *sdFSConfig) +{ + return mbfs->sdFatBegin(sdFSConfig); +} +#endif + +#if defined(ESP32) +bool ESP_Mail_Client::sdBegin(int8_t ss, SPIClass *spiConfig, uint32_t frequency) +{ + return mbfs->sdSPIBegin(ss, spiConfig, frequency); +} +#endif + +#if defined(MBFS_ESP32_SDFAT_ENABLED) || defined(MBFS_SDFAT_ENABLED) +bool ESP_Mail_Client::sdBegin(SdSpiConfig *sdFatSPIConfig, int8_t ss, int8_t sck, int8_t miso, int8_t mosi) +{ + return mbfs->sdFatBegin(sdFatSPIConfig, ss, sck, miso, mosi); +} + +bool ESP_Mail_Client::sdBegin(SdioConfig *sdFatSDIOConfig) +{ + return mbfs->sdFatBegin(sdFatSDIOConfig); +} +#endif + +#endif + +#if defined(ESP32) && defined(MBFS_SD_FS) && defined(MBFS_CARD_TYPE_SD_MMC) + +bool ESP_Mail_Client::sdMMCBegin(const char *mountpoint, bool mode1bit, bool format_if_mount_failed) +{ + return mbfs->sdMMCBegin(mountpoint, mode1bit, format_if_mount_failed); +} + +#endif + +int ESP_Mail_Client::getFreeHeap() +{ +#if defined(MB_ARDUINO_ESP) + return ESP.getFreeHeap(); +#elif defined(MB_ARDUINO_PICO) + return rp2040.getFreeHeap(); +#else + return 0; +#endif +} + +// All following functions are for IMAP or SMTP only +#if defined(ENABLE_SMTP) || defined(ENABLE_IMAP) + +void ESP_Mail_Client::resumeNetwork(ESP_Mail_TCPClient *client) +{ + client->networkReconnect(); +} + +template +bool ESP_Mail_Client::sessionExisted(T sessionPtr) +{ + +#if defined(ENABLE_SMTP) || defined(ENABLE_IMAP) + + Session_Config *config = sessionPtr->_session_cfg; + _vectorImpl *configPtrList = &(sessionPtr->_configPtrList); + + if (config) + { + int ptr = toAddr(*config); + for (size_t i = 0; i < configPtrList->size(); i++) + { + if ((*configPtrList)[i] == ptr) + return true; + } + + sessionPtr->closeSession(); + sessionPtr->_responseStatus.errorCode = MAIL_CLIENT_ERROR_SESSION_CONFIG_WAS_NOT_ASSIGNED; + sessionPtr->_responseStatus.text.clear(); + } + +#endif + return false; +} + +void ESP_Mail_Client::debugPrintNewLine() +{ +#if !defined(SILENT_MODE) + esp_mail_debug_print("", true); +#endif +} + +template +void ESP_Mail_Client::callBackSendNewLine(T sessionPtr, bool success) +{ +#if defined(SESSION_DEBUG_ENABLED) + sendCallback(sessionPtr, "", false, success); +#endif +} + +void ESP_Mail_Client::appendTagSpace(MB_String &buf, PGM_P tag) +{ + buf += (tag == NULL) ? esp_mail_imap_tag_str : tag; + appendSpace(buf); +} + +template +void ESP_Mail_Client::appendList(MB_String &buf, _vectorImpl &list) +{ + for (size_t i = 0; i < list.size(); i++) + { + if (i > 0) + buf += esp_mail_str_8; /* "," */ + buf += list[i]; + } +} + +void ESP_Mail_Client::appendSpace(MB_String &buf) +{ + buf += esp_mail_str_2 /* " " */; +} + +void ESP_Mail_Client::appendSpace(MB_String &buf, bool withTag, PGM_P value) +{ + if (withTag) + appendTagSpace(buf); + buf += value; + appendSpace(buf); +} + +void ESP_Mail_Client::appendSpace(MB_String &buf, bool withTag, int nunArgs, ...) +{ + if (withTag) + appendTagSpace(buf); + + va_list ap; + va_start(ap, nunArgs); + PGM_P p = va_arg(ap, PGM_P); + if (p) + buf += p; + for (int i = 2; i <= nunArgs; i++) + { + appendSpace(buf); + p = va_arg(ap, PGM_P); + if (p) + buf += p; + } + va_end(ap); + appendSpace(buf); +} + +void ESP_Mail_Client::prependSpace(MB_String &buf, PGM_P value) +{ + appendSpace(buf); + buf += value; +} + +void ESP_Mail_Client::appendDot(MB_String &buf) +{ + buf += esp_mail_str_27; /* "." */ +} + +void ESP_Mail_Client::prependDot(MB_String &buf, PGM_P value) +{ + buf += esp_mail_str_27; /* "." */ + buf += value; +} + +void ESP_Mail_Client::joinStringSpace(MB_String &buf, bool withTag, int nunArgs, ...) +{ + if (withTag) + appendTagSpace(buf); + + va_list ap; + va_start(ap, nunArgs); + PGM_P p = va_arg(ap, PGM_P); + if (p) + buf += p; + for (int i = 2; i <= nunArgs; i++) + { + appendSpace(buf); + p = va_arg(ap, PGM_P); + if (p) + buf += p; + } + va_end(ap); +} + +void ESP_Mail_Client::appendImap4KeyValue(MB_String &buf, PGM_P key, PGM_P value) +{ + buf += esp_mail_str_11; /* "\"" */ + buf += key; + buf += esp_mail_str_11; /* "\"" */ + appendSpace(buf); + buf += esp_mail_str_11; /* "\"" */ + buf += value; + buf += esp_mail_str_11; /* "\"" */ +} + +void ESP_Mail_Client::joinStringDot(MB_String &buf, int nunArgs, ...) +{ + va_list ap; + va_start(ap, nunArgs); + PGM_P p = va_arg(ap, PGM_P); + if (p) + buf += p; + for (int i = 2; i <= nunArgs; i++) + { + buf += esp_mail_str_27; /* "." */ + p = va_arg(ap, PGM_P); + if (p) + buf += p; + } + va_end(ap); +} + +template +void ESP_Mail_Client::sendCallback(T sessionPtr, PGM_P info, bool prependCRLF, bool success) +{ + +#if defined(SESSION_DEBUG_ENABLED) + + sessionPtr->_cbData._info.clear(); + + if (prependCRLF) + appendNewline(sessionPtr->_cbData._info); + if (strlen_P(info) > 0) + { + sessionPtr->_cbData._info += esp_mail_str_33; /* "#### " */ + sessionPtr->_cbData._info += info; + } + sessionPtr->_cbData._success = success; + if (sessionPtr->_statusCallback && !sessionPtr->_customCmdResCallback) + sessionPtr->_statusCallback(sessionPtr->_cbData); + +#endif +} + +template +void ESP_Mail_Client::printDebug(T sessionPtr, PGM_P cbMsg, PGM_P dbMsg, esp_mail_debug_tag_type type, bool prependCRLF, bool success) +{ +#if defined(SESSION_DEBUG_ENABLED) + + if (sessionPtr->_statusCallback != NULL && !isResponseCB(sessionPtr)) + sendCallback(sessionPtr, cbMsg, prependCRLF, success); + else if (sessionPtr->_debug) + debugPrintNewLine(); + + if (sessionPtr->_debug) + esp_mail_debug_print_tag(dbMsg, type, true); + +#endif +} + +void ESP_Mail_Client::printProgress(int progress, int &lastProgress) +{ +#if !defined(SILENT_MODE) + if (progress > 100) + progress = 100; + + if (lastProgress != progress && (progress == 0 || progress == 100 || lastProgress + ESP_MAIL_PROGRESS_REPORT_STEP <= progress)) + { + int len = 16; + int curTick = progress * len / 100; + int lastTick = lastProgress * len / 100; + + if (curTick > lastTick || progress == 0 || progress == 100) + { + MB_String s; + for (int i = 0; i < len; i++) + { + if (i == 0) + s = '['; + s += i < progress * len / 100 ? '#' : ' '; + if (i == len - 1) + s += ']'; + } + appendSpace(s); + s += progress; + appendSpace(s); + s += esp_mail_str_24; /* "%" */ + esp_mail_debug_print_tag(s.c_str(), esp_mail_debug_tag_type_client, true); + } + + lastProgress = progress; + } +#endif +} + +void ESP_Mail_Client::setTimezone(const char *TZ_Var, const char *TZ_file) +{ + + if (!TZ_Var) + return; + +#if defined(ESP32) || defined(ESP8266) || defined(MB_ARDUINO_PICO) + if (strlen(TZ_Var) > 0) + { + +#if defined(ESP32) + + mb_fs_mem_storage_type type = mb_fs_mem_storage_type_undefined; + +#if defined(MBFS_FLASH_FS) + type = mb_fs_mem_storage_type_flash; +#elif defined(MBFS_SD_FS) + type = mb_fs_mem_storage_type_sd; +#endif + + if (type != mb_fs_mem_storage_type_undefined) + { + MB_String filename = TZ_file; + if (mbfs->open(filename, type, mb_fs_open_mode_write) > -1) + { + mbfs->print(type, TZ_Var); + mbfs->close(type); + } + } + +#endif + + setenv("TZ", TZ_Var, 1); + tzset(); + timezoneEnvSet = true; + } +#endif +} + +void ESP_Mail_Client::preparePortFunction(Session_Config *session_config, bool isSMTP, bool &secure, bool &secureMode, bool &ssl) +{ + + if (session_config->ports_functions.list) + { + if (session_config->ports_functions.use_internal_list) + { + session_config->ports_functions.use_internal_list = false; + delete[] session_config->ports_functions.list; + session_config->ports_functions.list = nullptr; + } + } + + if (!session_config->ports_functions.list) + { + if (isSMTP) + { +#if defined(ENABLE_SMTP) + session_config->ports_functions.use_internal_list = true; + session_config->ports_functions.list = new port_function[3]; + session_config->ports_functions.size = 3; + + for (int i = 0; i < 3; i++) + session_config->ports_functions.list[i] = smtp_ports[i]; +#endif + } + else + { +#if defined(ENABLE_IMAP) + session_config->ports_functions.use_internal_list = true; + session_config->ports_functions.list = new port_function[2]; + session_config->ports_functions.size = 2; + + for (int i = 0; i < 2; i++) + session_config->ports_functions.list[i] = imap_ports[i]; +#endif + } + } + + getPortFunction(session_config->server.port, session_config->ports_functions, secure, secureMode, ssl, session_config->secure.startTLS); +} + +void ESP_Mail_Client::getPortFunction(uint16_t port, struct esp_mail_ports_functions &ports_functions, bool &secure, bool &secureMode, bool &ssl, bool &starttls) +{ + for (size_t i = 0; i < ports_functions.size; i++) + { + if (ports_functions.list[i].port == port) + { + if (ports_functions.list[i].protocol == esp_mail_protocol_plain_text) + { + secure = false; + secureMode = false; + } + else + { + if (ports_functions.list[i].protocol == esp_mail_protocol_tls) + starttls = true; + + secureMode = !starttls; + + if (ports_functions.list[i].protocol == esp_mail_protocol_ssl) + ssl = true; + } + return; + } + } +} + +void ESP_Mail_Client::getTimezone(const char *TZ_file, MB_String &out) +{ + +#if defined(ESP32) + + mb_fs_mem_storage_type type = mb_fs_mem_storage_type_undefined; + +#if defined(MBFS_FLASH_FS) + type = mb_fs_mem_storage_type_flash; +#elif defined(MBFS_SD_FS) + type = mb_fs_mem_storage_type_sd; +#endif + + if (type != mb_fs_mem_storage_type_undefined) + { + MB_String filename = TZ_file; + + if (mbfs->open(filename, type, mb_fs_open_mode_read) > 0) + { + out.clear(); + while (mbfs->available(type)) + { + out += (char)mbfs->read(type); + } + mbfs->close(type); + } + } +#endif +} + +void ESP_Mail_Client::setTime(const char *TZ_Var, const char *TZ_file, bool wait, bool debugProgress) +{ + + timeStatus = Time.timeReady(); + + if (!timeStatus) + { + +#if defined(ENABLE_IMAP) || defined(ENABLE_SMTP) + +#if defined(ENABLE_NTP_TIME) + + if (WiFI_CONNECTED) + { + Time.readNTPTime(wait ? 10000 : 0, debugProgress); + } + else + { +#if !defined(SILENT_MODE) + esp_mail_debug_print_tag(esp_mail_error_client_str_4 /* "NTP server time reading cannot begin when valid time is required because of no WiFi capability/activity detected." */, esp_mail_debug_tag_type_warning, true); + esp_mail_debug_print_tag(esp_mail_error_client_str_5 /* "Please set the library reference time manually using smtp.setSystemTime or imap.setSystemTime." */, esp_mail_debug_tag_type_warning, true); +#endif + } + + getSetTimezoneEnv(TZ_file, TZ_Var); + +#elif !defined(SILENT_MODE) + esp_mail_debug_print_tag(esp_mail_error_client_str_5 /* "Please set the library reference time manually using smtp.setSystemTime or imap.setSystemTime." */, esp_mail_debug_tag_type_warning, true); +#endif + +#endif + } + + timeStatus = Time.timeReady(); +} + +void ESP_Mail_Client::getSetTimezoneEnv(const char *TZ_file, const char *TZ_Var) +{ + // set and get TZ environment variable + + MB_String timezone; + + // only ESP32 only + getTimezone(TZ_file, timezone); + + if (timezone.length() == 0) + timezone = TZ_Var; + + // if timezone string assign + setTimezone(timezone.c_str(), TZ_file); +} + +bool ESP_Mail_Client::validEmail(const char *s) +{ + MB_String str(s); + size_t at = str.find('@'); + size_t dot = str.find('.', at); + return (at != MB_String::npos) && (dot != MB_String::npos); +} + +#if defined(ENABLE_SMTP) && defined(ENABLE_IMAP) + +bool ESP_Mail_Client::mAppendMessage(IMAPSession *imap, SMTP_Message *msg, bool lastAppend, MB_StringPtr flags, MB_StringPtr dateTime) +{ + this->imap = imap; + calDataLen = true; + dataLen = 0; + imap_ts = 0; + + if (!sessionExisted(imap)) + return false; + + MB_String _flags = flags; + _flags.trim(); + + MB_String _dt = dateTime; + _dt.trim(); + + bool rfc822MSG = false; + + sendContent(nullptr, msg, false, rfc822MSG); + + MB_String cmd; + + if (!imap->_feature_capability[esp_mail_imap_read_capability_multiappend]) + { + lastAppend = true; + imap->_prev_imap_cmd = esp_mail_imap_cmd_sasl_login; + } + + if (imap->_prev_imap_cmd != esp_mail_imap_cmd_append) + joinStringSpace(cmd, true, 2, imap_commands[esp_mail_imap_command_append].text, imap->_currentFolder.c_str()); + + appendSpace(cmd); + + if (_flags.length() > 0) + { + appendString(cmd, _flags.c_str(), false, false, esp_mail_string_mark_type_round_bracket); + appendSpace(cmd); + } + + if (_dt.length() > 0) + { + appendString(cmd, _dt.c_str(), false, false, esp_mail_string_mark_type_double_quote); + appendSpace(cmd); + } + + appendString(cmd, MB_String((int)dataLen).c_str(), false, false, esp_mail_string_mark_type_curly_bracket); + + if (imapSend(imap, cmd.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + { + imap->_prev_imap_cmd = esp_mail_imap_cmd_sasl_login; + return false; + } + + imap->_imap_cmd = esp_mail_imap_command::esp_mail_imap_cmd_append; + + if (!handleIMAPResponse(imap, IMAP_STATUS_BAD_COMMAND, false)) + { + imap->_prev_imap_cmd = esp_mail_imap_cmd_sasl_login; + return false; + } + + calDataLen = false; + + rfc822MSG = false; + + if (!sendContent(nullptr, msg, false, rfc822MSG)) + { + imap->_prev_imap_cmd = esp_mail_imap_cmd_sasl_login; + return false; + } + + if (lastAppend) + { + if (imapSend(imap, esp_mail_str_18 /* "\r\n" */, false) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + { + imap->_prev_imap_cmd = esp_mail_imap_cmd_sasl_login; + return false; + } + + imap->_imap_cmd = esp_mail_imap_command::esp_mail_imap_cmd_append_last; + + if (!handleIMAPResponse(imap, IMAP_STATUS_BAD_COMMAND, false)) + { + imap->_prev_imap_cmd = esp_mail_imap_cmd_sasl_login; + return false; + } + + imap->_prev_imap_cmd = esp_mail_imap_cmd_sasl_login; + } + + if (!lastAppend) + imap->_prev_imap_cmd = esp_mail_imap_cmd_append; + else + { +#if !defined(SILENT_MODE) + altSendCallback(nullptr, esp_mail_cb_str_45 /* "Message append successfully" */, esp_mail_dbg_str_73 /* "message append successfully" */, esp_mail_debug_tag_type_client, true, false); +#endif + } + return true; +} + +#endif + +char *ESP_Mail_Client::getRandomUID() +{ + char *tmp = allocMem(36); + sprintf(tmp, "%d", (int)random(2000, 4000)); + return tmp; +} + +void ESP_Mail_Client::splitToken(const char *str, _vectorImpl &tk, const char *delim) +{ + char *p = allocMem(strlen(str)); + strcpy(p, str); + char *pp = p; + char *end = p; + MB_String tmp; + while (pp != NULL) + { + // See RFC2047.h + ESP_MAIL_STRSEP(&end, delim); + if (strlen(pp) > 0) + { + tmp = pp; + tk.push_back(tmp); + } + pp = end; + } + // release memory + freeMem(&p); +} + +int ESP_Mail_Client::strpos(const char *haystack, const char *needle, int offset, bool caseSensitive) +{ + if (!haystack || !needle) + return -1; + + int hlen = strlen(haystack); + int nlen = strlen(needle); + + if (hlen == 0 || nlen == 0) + return -1; + + int hidx = offset, nidx = 0; + while ((*(haystack + hidx) != '\0') && (*(needle + nidx) != '\0') && hidx < hlen) + { + + bool nm = caseSensitive ? *(needle + nidx) != *(haystack + hidx) : tolower(*(needle + nidx)) != tolower(*(haystack + hidx)); + + if (nm) + { + hidx++; + nidx = 0; + } + else + { + nidx++; + hidx++; + if (nidx == nlen) + return hidx - nidx; + } + } + + return -1; +} + +char *ESP_Mail_Client::subStr(const char *buf, PGM_P beginToken, PGM_P endToken, int beginPos, int endPos, bool caseSensitive) +{ + char *tmp = nullptr; + if (beginToken) + { + int p1 = strposP(buf, beginToken, beginPos, caseSensitive); + if (p1 != -1) + { + while (buf[p1 + strlen_P(beginToken)] == ' ' || buf[p1 + strlen_P(beginToken)] == '\r' || buf[p1 + strlen_P(beginToken)] == '\n') + { + p1++; + if (strlen(buf) <= p1 + strlen_P(beginToken)) + { + p1--; + break; + } + } + + int p2 = -1; + if (endPos == 0) + p2 = strposP(buf, endToken, p1 + strlen_P(beginToken), caseSensitive); + + if (p2 == -1) + p2 = strlen(buf); + + int len = p2 - p1 - strlen_P(beginToken); + int ofs = endToken ? strlen_P(endToken) : 1; + tmp = allocMem(len + ofs); + memcpy(tmp, &buf[p1 + strlen_P(beginToken)], len); + } + } + else + { + int p1 = strposP(buf, endToken, beginPos); + if (p1 != -1) + { + tmp = allocMem(p1); + memcpy(tmp, &buf[2], p1 - 1); + } + } + + return tmp; +} + +bool ESP_Mail_Client::getHeader(const char *buf, PGM_P beginToken, MB_String &out, bool caseSensitive) +{ + if (strcmpP(buf, 0, beginToken, caseSensitive)) + { + char *tmp = subStr(buf, beginToken, NULL, 0, -1, caseSensitive); + if (tmp) + { + out = tmp; + // release memory + freeMem(&tmp); + return true; + } + } + + return false; +} + +void ESP_Mail_Client::appendHeaderField(MB_String &buf, const char *name, PGM_P value, bool comma, bool newLine, esp_mail_string_mark_type type) +{ + appendHeaderName(buf, name); + appendString(buf, value, comma, newLine, type); +} + +void ESP_Mail_Client::appendAddressHeaderField(MB_String &buf, esp_mail_address_info_t &source, esp_mail_rfc822_header_field_types type, bool header, bool comma, bool newLine) +{ + // Construct header field. + if (header) + appendHeaderName(buf, rfc822_headers[type].text); + + if (type != esp_mail_rfc822_header_field_cc && type != esp_mail_rfc822_header_field_bcc && + source.name.length() > 0) + { + appendString(buf, source.name.c_str(), false, false, esp_mail_string_mark_type_double_quote); + // Add white space after name for SMTP to fix iCloud Mail Service IMAP search compatibility issue #278 + // This is not restricted by rfc2822. + appendSpace(buf); + } + + appendString(buf, source.email.c_str(), comma, newLine, esp_mail_string_mark_type_angle_bracket); +} + +void ESP_Mail_Client::appendHeaderName(MB_String &buf, const char *name, bool clear, bool lowercase, bool space) +{ + if (clear) + buf.clear(); + + if (lowercase) + appendLowerCaseString(buf, name); + else + buf += name; + buf += esp_mail_str_34; /* ":" */ + if (space) + appendSpace(buf); +} + +void ESP_Mail_Client::appendLowerCaseString(MB_String &buf, PGM_P value, bool clear) +{ + if (clear) + buf.clear(); + char *tmp = strP2Lower(value); + buf += tmp; + freeMem(&tmp); +} + +void ESP_Mail_Client::appendHeaderProp(MB_String &buf, PGM_P prop, const char *value, bool &firstProp, bool lowerCase, bool isString, bool newLine) +{ + if (firstProp) + buf += esp_mail_str_35; /* ";" */ + appendSpace(buf); + if (lowerCase) + appendLowerCaseString(buf, prop); + else + buf += prop; + buf += esp_mail_str_7; /* "=" */ + if (isString) + buf += esp_mail_str_11; /* "\"" */ + buf += value; + if (isString) + buf += esp_mail_str_11; /* "\"" */ + buf += esp_mail_str_35; /* ";" */ + if (newLine) + appendNewline(buf); + + firstProp = false; +} + +void ESP_Mail_Client::appendString(MB_String &buf, PGM_P value, bool comma, bool newLine, esp_mail_string_mark_type type) +{ + if (comma) + buf += esp_mail_str_8; /* "," */ + + switch (type) + { + case esp_mail_string_mark_type_double_quote: + buf += esp_mail_str_11; /* "\"" */ + break; + case esp_mail_string_mark_type_angle_bracket: + buf += esp_mail_str_19; /* "<" */ + break; + case esp_mail_string_mark_type_round_bracket: + buf += esp_mail_str_38; /* "(" */ + break; + case esp_mail_string_mark_type_curly_bracket: + buf += esp_mail_str_36; /* "{" */ + break; + case esp_mail_string_mark_type_square_bracket: + buf += esp_mail_str_40; /* "[" */ + break; + default: + break; + } + + if (value) + buf += value; + + switch (type) + { + case esp_mail_string_mark_type_double_quote: + buf += esp_mail_str_11; /* "\"" */ + break; + case esp_mail_string_mark_type_angle_bracket: + buf += esp_mail_str_20; /* ">" */ + break; + case esp_mail_string_mark_type_round_bracket: + buf += esp_mail_str_39; /* ")" */ + break; + case esp_mail_string_mark_type_curly_bracket: + buf += esp_mail_str_37; /* "}" */ + break; + case esp_mail_string_mark_type_square_bracket: + buf += esp_mail_str_41; /* "]" */ + break; + default: + break; + } + + if (newLine) + appendNewline(buf); +} + +void ESP_Mail_Client::maskString(MB_String &buf, int len) +{ + for (int i = 0; i < len; i++) + buf += esp_mail_str_3; /* "*" */ +} + +void ESP_Mail_Client::appendDomain(MB_String &buf, const char *domain) +{ + buf += strlen(domain) > 0 ? domain : pgm2Str(esp_mail_str_1 /* "127.0.0.1" */); +} + +void ESP_Mail_Client::appendEmbedMessage(MB_String &buf, esp_mail_message_body_t &body, bool isHtml) +{ + appendHeaderName(buf, message_headers[esp_mail_message_header_field_content_disposition].text); + appendString(buf, body.embed.type == esp_mail_smtp_embed_message_type_inline ? esp_mail_content_disposition_type_t::inline_ : esp_mail_content_disposition_type_t::attachment, false, false); + + PGM_P pgm = isHtml ? esp_mail_str_14 /* "msg.html" */ : esp_mail_str_13; /* "msg.txt" */ + MB_String filename; + if (body.embed.filename.length() > 0) + filename = body.embed.filename; + else + filename = pgm; + + bool firstProp = true; + appendHeaderProp(buf, message_headers[esp_mail_message_header_field_filename].text, filename.c_str(), firstProp, true, true, true); + + if (body.embed.type == esp_mail_smtp_embed_message_type_inline) + { + appendHeaderName(buf, message_headers[esp_mail_message_header_field_content_location].text); + body.embed.filename.length() > 0 ? appendString(buf, body.embed.filename.c_str(), false, true) : appendString(buf, pgm, false, true); + appendHeaderField(buf, message_headers[esp_mail_message_header_field_content_id].text, body._int.cid.c_str(), false, true, esp_mail_string_mark_type_angle_bracket); + } +} + +void ESP_Mail_Client::appendNewline(MB_String &buf) +{ + buf += esp_mail_str_18; /* "\r\n" */ +} + +void ESP_Mail_Client::getExtfromMIME(const char *mime, MB_String &ext) +{ + ext.clear(); + for (int i = 0; i < esp_mail_file_extension_maxType; i++) + { + if (strcmp_P(mime, mimeinfo[i].mimeType) == 0) + { + ext = mimeinfo[i].endsWith; + break; + } + } + + if (ext.length() == 0) + ext = esp_mail_str_42; /* ".dat" */ +} + +MB_String ESP_Mail_Client::mGetBase64(MB_StringPtr str) +{ + MB_String data = str; + return encodeBase64Str((uint8_t *)(data.c_str()), data.length()); +} + +int ESP_Mail_Client::readLine(ESP_Mail_TCPClient *client, char *buf, int bufLen, bool withLineBreak, int &count, bool &ovf, unsigned long timeoutSec, bool &isTimeout) +{ + int ret = -1; + char c = 0; + char _c = 0; + int idx = 0; + ovf = idx >= bufLen; + bool lineBreak = false; + isTimeout = false; + + unsigned long ms = millis(); + + // Instead of relying on data available, we looks for line break until timed out or disconnected or overflown occurred. + while (idx < bufLen && client->connected() && (!lineBreak || client->available() /* data may not available sometimes */)) + { + if (millis() - ms >= timeoutSec * 1000) + { + isTimeout = true; + break; + } + + yield_impl(); + + ret = client->read(); + if (ret > -1) + { + c = (char)ret; + buf[idx++] = c; + count++; + if (_c == '\r' && c == '\n') + { + lineBreak = true; + if (!withLineBreak) + { + buf[idx - 2] = 0; + idx -= 2; + } + return idx; + } + _c = c; + + if (idx >= bufLen - 1) + { + ovf = true; + return idx; + } + } + } + return idx; +} + +template +bool ESP_Mail_Client::readResponse(T sessionPtr, char *buf, int bufLen, int &readLen, bool withLineBreak, int &count, MB_String &ovfBuf) +{ + bool ovf = false, isTimeout = false; + unsigned long timeoutSec = TCP_CLIENT_DEFAULT_TCP_TIMEOUT_SEC; + + do + { + timeoutSec = sessionPtr->client.tcpTimeout(); + int len = readLine(&(sessionPtr->client), buf, bufLen, withLineBreak, count, ovf, timeoutSec, isTimeout); + readLen += len; + if (len > 0 && (ovf || ovfBuf.length() > 0)) + ovfBuf += buf; + + } while (ovf); + + if (isTimeout) + return false; + + if (ovfBuf.length() > 0) + { + +#if defined(SESSION_DEBUG_ENABLED) + sessionPtr->_responseStatus.errorCode = MAIL_CLIENT_ERROR_BUFFER_OVERFLOW; + sessionPtr->_responseStatus.text.clear(); + if (sessionPtr->_debug) + esp_mail_debug_print_tag(sessionPtr->errorReason().c_str(), esp_mail_debug_tag_type_warning, true); +#endif + } + + return true; +} + +template +bool ESP_Mail_Client::reconnect(T sessionPtr, unsigned long dataTime, bool downloadRequest) +{ + if (!sessionPtr) + return false; + + sessionPtr->client.setSession(sessionPtr->_session_cfg); + networkStatus = sessionPtr->client.networkReady(); + + if (dataTime > 0) + { + if (millis() - dataTime > (unsigned long)sessionPtr->client.tcpTimeout()) + { + closeTCPSession(sessionPtr); + + if (sessionPtr->_sessionType == esp_mail_session_type_imap) + { +#if defined(ENABLE_IMAP) + IMAPSession *ss = (IMAPSession *)sessionPtr; + if (ss->_headers.size() > 0) + { + if (downloadRequest) + { + errorStatusCB(ss, nullptr, IMAP_STATUS_ERROR_DOWNLAD_TIMEOUT, true); + if (cPart(ss) && cHeader(ss)->part_headers.size() > 0) + cPart(ss)->download_error = ss->errorReason().c_str(); + } + else + { + errorStatusCB(ss, nullptr, MAIL_CLIENT_ERROR_READ_TIMEOUT, true); + if (cHeader(ss)) + cHeader(ss)->error_msg = ss->errorReason().c_str(); + } + } + else + { +#if !defined(SILENT_MODE) + if (sessionPtr->_debug) + esp_mail_debug_print_tag(esp_mail_error_network_str_9 /* "response read timed out" */, esp_mail_debug_tag_type_error, true); +#endif + } +#endif + } + else + { +#if defined(ENABLE_SMTP) + SMTPSession *ss = (SMTPSession *)sessionPtr; + errorStatusCB(ss, this->imap, MAIL_CLIENT_ERROR_READ_TIMEOUT, false); +#endif + } + return false; + } + } + + if (!networkStatus) + { + closeTCPSession(sessionPtr); + + if (sessionPtr->_sessionType == esp_mail_session_type_imap) + { +#if defined(ENABLE_IMAP) + IMAPSession *ss = (IMAPSession *)sessionPtr; + if (ss->_mbif._idleTimeMs > 0 || ss->_imap_cmd == esp_mail_imap_cmd_idle || ss->_imap_cmd == esp_mail_imap_cmd_done) + { + // defer the polling error report + if (millis() - ss->_last_polling_error_ms > 10000 && !sessionPtr->connected()) + { + ss->_last_polling_error_ms = millis(); + errorStatusCB(ss, nullptr, MAIL_CLIENT_ERROR_CONNECTION_CLOSED, true); + } + } + else if (millis() - ss->_last_network_error_ms > 1000) + { + ss->_last_network_error_ms = millis(); + errorStatusCB(ss, nullptr, MAIL_CLIENT_ERROR_CONNECTION_CLOSED, true); + } + + if (ss->_headers.size() > 0) + { + if (cPart(ss) && downloadRequest) + cPart(ss)->download_error = ss->errorReason().c_str(); + else if (cHeader(ss)) + cHeader(ss)->error_msg = ss->errorReason().c_str(); + } + +#endif + } + else + { +#if defined(ENABLE_SMTP) + SMTPSession *ss = (SMTPSession *)sessionPtr; + errorStatusCB(ss, nullptr, MAIL_CLIENT_ERROR_CONNECTION_CLOSED, false); +#endif + } + + if (millis() - _lastReconnectMillis > _reconnectTimeout && !sessionPtr->connected()) + { + if (sessionPtr->_session_cfg->network_connection_handler) + { + // dummy + sessionPtr->client.disconnect(); + sessionPtr->_session_cfg->network_connection_handler(); + } + else + { + if (MailClient.networkAutoReconnect) + MailClient.resumeNetwork(&(sessionPtr->client)); + } + + _lastReconnectMillis = millis(); + } + + networkStatus = sessionPtr->client.networkReady(); + } + + return networkStatus; +} + +template +void ESP_Mail_Client::sendCB(T sessionPtr, PGM_P info, bool prependCRLF, bool success) +{ + if (sessionPtr) + { + sessionPtr->_cbData._info.clear(); + + if (prependCRLF) + appendNewline(sessionPtr->_cbData._info); + if (strlen_P(info) > 0) + { + sessionPtr->_cbData._info += esp_mail_str_33; /* "#### " */ + sessionPtr->_cbData._info += info; + } + sessionPtr->_cbData._success = success; + if (sessionPtr->_statusCallback) + sessionPtr->_statusCallback(sessionPtr->_cbData); + } +} + +template +void ESP_Mail_Client::sendErrorCB(T sessionPtr, PGM_P info, bool prependCRLF, bool success) +{ +#if !defined(SILENT_MODE) + MB_String e = esp_mail_str_12; /* "Error, " */ + e += info; + sendCB(sessionPtr, e.c_str(), prependCRLF, success); +#endif +} + +template +void ESP_Mail_Client::errorStatusCB(T1 sessionPtr, T2 sessionPtr2, int error, bool clearLastStatus) +{ + + if (sessionPtr) + { + sessionPtr->_responseStatus.errorCode = error; + + if (clearLastStatus) + sessionPtr->_responseStatus.text.clear(); + +#if !defined(SILENT_MODE) + if (sessionPtr->_statusCallback && !sessionPtr->_customCmdResCallback) + sendErrorCB(sessionPtr, sessionPtr->errorReason().c_str(), false, false); + + if (sessionPtr->_debug && !sessionPtr->_customCmdResCallback) + esp_mail_debug_print_tag(sessionPtr->errorReason().c_str(), esp_mail_debug_tag_type_error, true); +#endif + } + else if (sessionPtr2 && !calDataLen) + errorStatusCB(sessionPtr2, nullptr, error, clearLastStatus); +} + +template +bool ESP_Mail_Client::isResponseCB(T sessionPtr) +{ +#if defined(ENABLE_SMTP) || defined(ENABLE_IMAP) + return sessionPtr->_customCmdResCallback != NULL; +#endif + return false; +} + +template +void ESP_Mail_Client::printLibInfo(T sessionPtr) +{ +#if defined(SESSION_DEBUG_ENABLED) + + if (sessionPtr->_statusCallback != NULL && !isResponseCB(sessionPtr)) + sendCallback(sessionPtr, + sessionPtr->_sessionType == esp_mail_session_type_smtp ? esp_mail_cb_str_1 /* "Connecting to SMTP server..." */ + : esp_mail_cb_str_15 /* "Connecting to IMAP server..." */, + false, false); + + if (sessionPtr->_debug && !isResponseCB(sessionPtr)) + { + MB_String dbMsg = esp_mail_version_str; /* "ESP Mail Client v" */ + dbMsg += ESP_MAIL_VERSION; + esp_mail_debug_print_tag(dbMsg.c_str(), esp_mail_debug_tag_type_client, true); + +#if defined(BOARD_HAS_PSRAM) && defined(MB_STRING_USE_PSRAM) + if (ESP.getPsramSize() == 0 && !isResponseCB(sessionPtr)) + esp_mail_debug_print_tag(esp_mail_error_mem_str_4 /* "PSRAM was enabled but not detected." */, esp_mail_debug_tag_type_warning, true); +#endif + } + +#endif +} + +template +bool ESP_Mail_Client::beginConnection(Session_Config *session_config, T sessionPtr, bool secureMode) +{ + + sessionPtr->client.setWiFi(&wifi); + sessionPtr->client.setSession(session_config); + + if (!reconnect(sessionPtr)) + return false; + +#if defined(SESSION_DEBUG_ENABLED) + if (sessionPtr->_debug && !isResponseCB(sessionPtr)) + { + esp_mail_debug_print_tag(sessionPtr->_sessionType == esp_mail_session_type_smtp + ? esp_mail_dbg_str_2 /* "connecting to SMTP server" */ + : esp_mail_dbg_str_18 /* "connecting to IMAP server" */, + esp_mail_debug_tag_type_client, true); + + MB_String dbMsg = esp_mail_dbg_str_19; /* "Host > " */ + dbMsg += session_config->server.host_name; + esp_mail_debug_print_tag(dbMsg.c_str(), esp_mail_debug_tag_type_client, true); + + dbMsg = esp_mail_dbg_str_20; /* "Port > " */ + dbMsg += session_config->server.port; + esp_mail_debug_print_tag(dbMsg.c_str(), esp_mail_debug_tag_type_client, true); + } +#endif + + sessionPtr->client.begin(session_config->server.host_name.c_str(), session_config->server.port); + + sessionPtr->client.ethDNSWorkAround(); + + if (!sessionPtr->client.connect(secureMode, session_config->certificate.verify)) + { + if (sessionPtr->_sessionType == esp_mail_session_type_smtp) + { +#if defined(ENABLE_SMTP) + return handleSMTPError((SMTPSession *)sessionPtr, SMTP_STATUS_SERVER_CONNECT_FAILED, false); +#endif + } + else + { +#if defined(ENABLE_IMAP) + return handleIMAPError((IMAPSession *)sessionPtr, IMAP_STATUS_SERVER_CONNECT_FAILED, false); +#endif + } + } + + return true; +} + +template +bool ESP_Mail_Client::prepareTime(Session_Config *session_config, T sessionPtr) +{ + bool timeShouldBeValid = false; + + if (sessionPtr->_sessionType == esp_mail_session_type_smtp) + timeShouldBeValid = true; +#if !defined(ESP_MAIL_DISABLE_SSL) + else + timeShouldBeValid = session_config->certificate.cert_file.length() > 0 || session_config->cert_ptr != 0; +#endif + +#if defined(ENABLE_NTP_TIME) && defined(ESP_MAIL_WIFI_IS_AVAILABLE) + bool ntpEnabled = true; +#else + bool ntpEnabled = false; +#endif + +#if defined(ESP_MAIL_WIFI_IS_AVAILABLE) + + if (session_config->time.ntp_server.length() > 0 || timeShouldBeValid) + { + + Time.begin(session_config->time.gmt_offset, session_config->time.day_light_offset, session_config->time.ntp_server.c_str()); + + if (!Time.timeReady()) + { + if (sessionPtr->client.type() == esp_mail_client_type_external_gsm_client) + { + int year = 0; + int month = 0; + int day = 0; + int hour = 0; + int min = 0; + int sec = 0; + float timezone = 0; + if (sessionPtr->client.gprsGetTime(year, month, day, hour, min, sec, timezone)) + Time.setTimestamp(Time.getTimestamp(year, month, day, hour, min, sec), timezone); + } + else if (session_config->time.ntp_server.length()) + { +#if defined(ENABLE_NTP_TIME) +#if !defined(SILENT_MODE) + if (sessionPtr->_debug && !isResponseCB(sessionPtr)) + esp_mail_debug_print_tag(esp_mail_dbg_str_21 /* "Reading time from NTP server" */, esp_mail_debug_tag_type_client, false); +#endif + + setTime(session_config->time.timezone_env_string.c_str(), session_config->time.timezone_file.c_str(), true, sessionPtr->_debug && !isResponseCB(sessionPtr)); +#endif + } + } + } + +#endif + +#if defined(ESP32) + if (Time.timeReady() && !timezoneEnvSet) + getSetTimezoneEnv(session_config->time.timezone_file.c_str(), session_config->time.timezone_env_string.c_str()); +#endif + + if (Time.timeReady()) + return true; + else if (WiFI_CONNECTED && timeShouldBeValid) + { + errorStatusCB(sessionPtr, nullptr, ntpEnabled && session_config->time.ntp_server.length() ? MAIL_CLIENT_ERROR_NTP_TIME_SYNC_TIMED_OUT : MAIL_CLIENT_ERROR_TIME_WAS_NOT_SET, false); + return false; + } + + return true; +} + +template +bool ESP_Mail_Client::sessionReady(T sessionPtr) +{ + // If network connection failure or tcp session closed, close session to clear resources. + if (!reconnect(sessionPtr) || !connected(sessionPtr)) + { + closeTCPSession(sessionPtr); + +#if defined(ENABLE_IMAP) + if (sessionPtr->_sessionType == esp_mail_session_type_imap && !connected(sessionPtr)) + errorStatusCB(sessionPtr, nullptr, MAIL_CLIENT_ERROR_CONNECTION_CLOSED, false); +#endif + + return false; + } + + return true; +} + +void ESP_Mail_Client::setCert(Session_Config *session_config, const char *ca) +{ + int ptr = reinterpret_cast(ca); + if (ptr != session_config->cert_ptr) + { + session_config->cert_updated = true; + session_config->cert_ptr = ptr; + } +} + +void ESP_Mail_Client::setSecure(ESP_Mail_TCPClient &client, Session_Config *session_config) +{ + + client.setMBFS(mbfs); + + client.setSession(session_config); + +#if !defined(ESP_MAIL_DISABLE_SSL) + + if (client.getCertType() == esp_mail_cert_type_undefined || session_config->cert_updated) + { + if (session_config->certificate.cert_file.length() > 0 || session_config->certificate.cert_data != NULL || session_config->cert_ptr > 0) + { + client.setClockReady(timeStatus); + } + + if (session_config->certificate.cert_file.length() == 0) + { + if (session_config->cert_ptr > 0) + client.setCACert(reinterpret_cast(session_config->cert_ptr)); + else if (session_config->certificate.cert_data != NULL) + client.setCACert(session_config->certificate.cert_data); + else + client.setCACert(NULL); + } + else + { + if (!client.setCertFile(session_config->certificate.cert_file.c_str(), mbfs_type session_config->certificate.cert_file_storage_type)) + client.setCACert(NULL); + } + session_config->cert_updated = false; + } +#endif +} + +void ESP_Mail_Client::appendMultipartContentType(MB_String &buf, esp_mail_multipart_types type, const char *boundary) +{ + bool firstProp = true; + appendHeaderField(buf, message_headers[esp_mail_message_header_field_content_type].text, multipart_types[type].text, false, false); + appendHeaderProp(buf, esp_mail_str_90 /* "boundary" */, boundary, firstProp, false, true, true); + appendNewline(buf); +} + +String ESP_Mail_Client::errorReason(bool isSMTP, int errorCode, const char *msg) +{ + MB_String ret; + +#if defined(ENABLE_ERROR_STRING) && !defined(SILENT_MODE) + + // If there is server meanningful response (msg) is available, return it instead + if (strlen(msg) > 0) + return msg; + + // The error code enums were defined in ESP_Mail_Error.h and MB_FS.h. + switch (errorCode) + { + + case TCP_CLIENT_ERROR_CONNECTION_REFUSED: + ret = esp_mail_error_network_str_7; /* "connection refused" */ + break; + case TCP_CLIENT_ERROR_SEND_DATA_FAILED: + ret = esp_mail_error_network_str_8; /* "data sending failed" */ + break; + case TCP_CLIENT_ERROR_NOT_INITIALIZED: + ret = esp_mail_error_client_str_1; /* "client and/or necessary callback functions are not yet assigned" */ + break; + case TCP_CLIENT_ERROR_NOT_CONNECTED: + ret = esp_mail_error_network_str_4; /* "not connected" */ + break; + + case MAIL_CLIENT_ERROR_CONNECTION_CLOSED: + ret = esp_mail_error_network_str_6; /* "connection closed" */ + break; + case MAIL_CLIENT_ERROR_READ_TIMEOUT: + ret = esp_mail_error_network_str_3; /* "response read timed out" */ + break; + case MAIL_CLIENT_ERROR_SSL_TLS_STRUCTURE_SETUP: + ret = esp_mail_error_ssl_str_1; /* "fail to set up the SSL/TLS structure" */ + break; + case MAIL_CLIENT_ERROR_OUT_OF_MEMORY: + ret = esp_mail_error_mem_str_8; /* "out of memory" */ + break; + case MAIL_CLIENT_ERROR_NTP_TIME_SYNC_TIMED_OUT: + ret = esp_mail_error_network_str_2; /* "NTP server time reading timed out" */ + break; + case MAIL_CLIENT_ERROR_SESSION_CONFIG_WAS_NOT_ASSIGNED: + ret = esp_mail_error_session_str_1; /* "the Session_Config object was not assigned" */ + break; + case MAIL_CLIENT_ERROR_TIME_WAS_NOT_SET: + ret = esp_mail_error_time_str_1; /* "library or device time was not set" */ + break; + case MAIL_CLIENT_ERROR_NOT_YET_LOGIN: + ret = esp_mail_error_auth_str_3; /* "not yet log in" */ + break; + case MAIL_CLIENT_ERROR_BUFFER_OVERFLOW: + ret = esp_mail_error_mem_str_9; /* "buffer overflow" */ + break; + +#if defined(ENABLE_SMTP) + case SMTP_STATUS_SERVER_CONNECT_FAILED: + ret = esp_mail_error_network_str_1; /* "unable to connect to server" */ + break; + case SMTP_STATUS_SMTP_GREETING_GET_RESPONSE_FAILED: + ret = esp_mail_error_smtp_str_1; /* "SMTP server greeting failed" */ + break; + case SMTP_STATUS_SMTP_GREETING_SEND_ACK_FAILED: + ret = esp_mail_error_smtp_str_1; /* "SMTP server greeting failed" */ + break; + case SMTP_STATUS_AUTHEN_NOT_SUPPORT: + ret = esp_mail_error_auth_str_1; /* "the provided SASL authentication mechanism is not support" */ + break; + case SMTP_STATUS_AUTHEN_FAILED: + ret = esp_mail_error_smtp_str_2; /* "authentication failed" */ + break; + case SMTP_STATUS_USER_LOGIN_FAILED: + ret = esp_mail_error_smtp_str_2; /* "authentication failed" */ + break; + case SMTP_STATUS_PASSWORD_LOGIN_FAILED: + ret = esp_mail_error_smtp_str_3; /* "login password is not valid" */ + break; + case SMTP_STATUS_SEND_HEADER_SENDER_FAILED: + ret = esp_mail_error_smtp_str_4; /* "send header failed" */ + break; + case SMTP_STATUS_SEND_HEADER_RECIPIENT_FAILED: + ret = esp_mail_error_smtp_str_9; /* "set recipient failed" */ + break; + case SMTP_STATUS_SEND_BODY_FAILED: + ret = esp_mail_error_smtp_str_5; /* "send body failed" */ + break; + case SMTP_STATUS_SERVER_OAUTH2_LOGIN_DISABLED: + ret = esp_mail_error_auth_str_2; /* "OAuth2.0 log in was disabled for this server" */ + break; + case SMTP_STATUS_NO_VALID_RECIPIENTS_EXISTED: + ret = esp_mail_error_smtp_str_8; /* "some of the recipient Email address is not valid" */ + break; + case SMTP_STATUS_NO_VALID_SENDER_EXISTED: + ret = esp_mail_error_smtp_str_7; /* "sender Email address is not valid" */ + break; + case SMTP_STATUS_NO_SUPPORTED_AUTH: + ret = esp_mail_error_auth_str_1; /* "the provided SASL authentication mechanism is not support" */ + break; + case SMTP_STATUS_SEND_CUSTOM_COMMAND_FAILED: + ret = esp_mail_error_smtp_str_10; /* "send custom command failed" */ + break; + case SMTP_STATUS_XOAUTH2_AUTH_FAILED: + ret = esp_mail_error_smtp_str_11; /* "XOAuth2 authenticate failed" */ + break; + case SMTP_STATUS_UNDEFINED: + ret = esp_mail_error_smtp_str_12; /* "undefined error" */ + break; +#endif + +#if defined(ENABLE_IMAP) + case IMAP_STATUS_SERVER_CONNECT_FAILED: + ret = esp_mail_error_network_str_1; /* "unable to connect to server" */ + break; + case IMAP_STATUS_IMAP_RESPONSE_FAILED: + ret = esp_mail_error_imap_str_18; /* "server replied NO or BAD response" */ + break; + case IMAP_STATUS_AUTHENTICATE_FAILED: + ret = esp_mail_error_imap_str_19; /* "authenticate failed" */ + break; + case IMAP_STATUS_BAD_COMMAND: + ret = esp_mail_error_imap_str_17; /* "could not parse command" */ + break; + case IMAP_STATUS_STORE_FAILED: + ret = esp_mail_error_imap_str_20; /* "flags or keywords store failed" */ + break; + case IMAP_STATUS_SERVER_OAUTH2_LOGIN_DISABLED: + ret = esp_mail_error_imap_str_21; /* "server is not support OAuth2 login" */ + break; + case IMAP_STATUS_NO_MESSAGE: + ret = esp_mail_error_imap_str_5; /* "some of the requested messages no longer exist" */ + break; + case IMAP_STATUS_ERROR_DOWNLAD_TIMEOUT: + ret = esp_mail_error_network_str_5; /* "connection timeout" */ + break; + case IMAP_STATUS_CLOSE_MAILBOX_FAILED: + ret = esp_mail_error_imap_str_3; /* "fail to close the mailbox" */ + break; + case IMAP_STATUS_OPEN_MAILBOX_FAILED: + ret = esp_mail_error_imap_str_4; /* "fail to open the mailbox" */ + break; + case IMAP_STATUS_LIST_MAILBOXS_FAILED: + ret = esp_mail_error_imap_str_1; /* "fail to list the mailboxes" */ + break; + case IMAP_STATUS_CHECK_CAPABILITIES_FAILED: + ret = esp_mail_error_imap_str_2; /* "fail to check the capabilities" */ + break; + case IMAP_STATUS_NO_SUPPORTED_AUTH: + ret = esp_mail_error_auth_str_1; /* "the provided SASL authentication mechanism is not support" */ + break; + case IMAP_STATUS_NO_MAILBOX_FOLDER_OPENED: + ret = esp_mail_error_imap_str_5; /* "no mailbox opened" */ + break; + case IMAP_STATUS_FIRMWARE_UPDATE_INIT_FAILED: + ret = esp_mail_error_imap_str_6; /* "firmware update initialization failed" */ + break; + case IMAP_STATUS_FIRMWARE_UPDATE_WRITE_FAILED: + ret = esp_mail_error_imap_str_7; /* "firmware update write failed" */ + break; + case IMAP_STATUS_FIRMWARE_UPDATE_END_FAILED: + ret = esp_mail_error_imap_str_8; /* "firmware update finalize failed" */ + break; + case IMAP_STATUS_CHANGEDSINC_MODSEQ_TEST_FAILED: + ret = esp_mail_error_imap_str_14; /* "no message changed since (assigned) modsec" */ + break; + case IMAP_STATUS_MODSEQ_WAS_NOT_SUPPORTED: + ret = esp_mail_error_imap_str_15; /* "CONDSTORE was not supported or modsec was not supported for selected mailbox" */ + break; + +#endif + +#if defined(MBFS_FLASH_FS) || defined(MBFS_SD_FS) + + case MB_FS_ERROR_FILE_IO_ERROR: + ret = esp_mail_error_mem_str_7; /* "file I/O error" */ + break; + case MB_FS_ERROR_FILE_NOT_FOUND: + ret = esp_mail_error_mem_str_6; /* "file not found." */ + break; + case MB_FS_ERROR_FLASH_STORAGE_IS_NOT_READY: + ret = esp_mail_error_mem_str_1; /* "flash Storage is not ready." */ + break; + case MB_FS_ERROR_SD_STORAGE_IS_NOT_READY: + ret = esp_mail_error_mem_str_2; /* "SD Storage is not ready." */ + break; + case MB_FS_ERROR_FILE_STILL_OPENED: + ret = esp_mail_error_mem_str_5; /* "file is still opened." */ + break; + +#endif + default: + break; + } + +#endif + + return ret.c_str(); +} + +template +void ESP_Mail_Client::closeTCPSession(T sessionPtr) +{ + if (!sessionPtr) + return; + + sessionPtr->client.stop(); + + _lastReconnectMillis = millis(); + + memset(sessionPtr->_auth_capability, 0, esp_mail_auth_capability_maxType); + memset(sessionPtr->_feature_capability, 0, + sessionPtr->_sessionType == esp_mail_session_type_smtp +#if defined(ENABLE_SMTP) + ? (int)esp_mail_smtp_send_capability_maxType +#else + ? 0 +#endif + : (int)esp_mail_imap_read_capability_maxType); + + sessionPtr->_authenticated = false; + sessionPtr->_loginStatus = false; +} + +template +bool ESP_Mail_Client::connected(T sessionPtr) +{ + return sessionPtr->client.connected(); +} + +size_t ESP_Mail_Client::getReservedLen(size_t len) +{ + return mbfs->getReservedLen(len); +} + +template +T ESP_Mail_Client::allocMem(size_t size, bool clear) +{ + return reinterpret_cast(mbfs->newP(size, clear)); +} + +void ESP_Mail_Client::freeMem(void *ptr) +{ + mbfs->delP(ptr); +} + +bool ESP_Mail_Client::strcmpP(const char *buf, int ofs, PGM_P beginToken, bool caseSensitive) +{ + if (ofs < 0) + { + int p = strposP(buf, beginToken, 0, caseSensitive); + if (p == -1) + return false; + ofs = p; + } + + char *tmp2 = allocMem(strlen_P(beginToken) + 1); + memcpy(tmp2, &buf[ofs], strlen_P(beginToken)); + tmp2[strlen_P(beginToken)] = 0; + MB_String s = beginToken; + bool ret = (strcasecmp(s.c_str(), tmp2) == 0); + // release memory + freeMem(&tmp2); + return ret; +} + +int ESP_Mail_Client::strposP(const char *buf, PGM_P beginToken, int ofs, bool caseSensitive) +{ + MB_String s = beginToken; + return strpos(buf, s.c_str(), ofs, caseSensitive); +} + +char *ESP_Mail_Client::strP(PGM_P pgm) +{ + size_t len = strlen_P(pgm) + 1; + char *buf = allocMem(len); + strcpy_P(buf, pgm); + buf[len - 1] = 0; + return buf; +} + +char *ESP_Mail_Client::strP2Lower(PGM_P pgm) +{ + size_t len = strlen_P(pgm) + 1; + char *buf = allocMem(len); + strcpy_P(buf, pgm); + + for (char *p = buf; *p; p++) + { + *p = tolower(*p); + } + + buf[len - 1] = 0; + return buf; +} + +void ESP_Mail_Client::strReplaceP(MB_String &buf, PGM_P name, PGM_P value) +{ + char *n = strP(name); + char *v = strP(value); + + buf.replaceAll(n, v); + + freeMem(&n); + freeMem(&v); +} + +bool ESP_Mail_Client::isOAuthError(char *buf, int bufLen, int &chunkIdx, int ofs) +{ + bool ret = false; + if (chunkIdx == 0) + { + size_t olen; + unsigned char *decoded = decodeBase64((const unsigned char *)(buf + ofs), bufLen - ofs, &olen); + if (decoded) + { + ret = strposP((char *)decoded, esp_mail_str_44 /* "{\"status\":" */, 0) > -1; + freeMem(&decoded); + } + chunkIdx++; + } + return ret; +} + +MB_String ESP_Mail_Client::getXOAUTH2String(const MB_String &email, const MB_String &accessToken) +{ + MB_String raw = esp_mail_str_45; /* "user=" */ + raw += email; + raw += esp_mail_str_46; /* "\1auth=Bearer " */ + raw += accessToken; + raw += esp_mail_str_43; /* "\1\1" */ + return encodeBase64Str((const unsigned char *)raw.c_str(), raw.length()); +} + +unsigned char *ESP_Mail_Client::decodeBase64(const unsigned char *src, size_t len, size_t *out_len) +{ + unsigned char *out, *pos, block[4], tmp; + size_t i, count, olen; + int pad = 0; + size_t extra_pad; + + unsigned char *dtable = allocMem(256); + + memset(dtable, 0x80, 256); + + for (i = 0; i < sizeof(b64_index_table) - 1; i++) + dtable[b64_index_table[i]] = (unsigned char)i; + dtable['='] = 0; + + count = 0; + for (i = 0; i < len; i++) + { + if (dtable[src[i]] != 0x80) + count++; + } + + if (count == 0) + goto exit; + + extra_pad = (4 - count % 4) % 4; + + olen = (count + extra_pad) / 4 * 3; + + pos = out = allocMem(olen); + + if (out == NULL) + goto exit; + + count = 0; + + for (i = 0; i < len + extra_pad; i++) + { + unsigned char val; + + if (i >= len) + val = '='; + else + val = src[i]; + tmp = dtable[val]; + if (tmp == 0x80) + continue; + + if (val == '=') + pad++; + block[count] = tmp; + count++; + if (count == 4) + { + *pos++ = (block[0] << 2) | (block[1] >> 4); + *pos++ = (block[1] << 4) | (block[2] >> 2); + *pos++ = (block[2] << 6) | block[3]; + count = 0; + if (pad) + { + if (pad == 1) + pos--; + else if (pad == 2) + pos -= 2; + else + { + // release memory + free(out); + goto exit; + } + break; + } + } + } + + *out_len = pos - out; + // release memory + freeMem(&dtable); + return out; +exit: + // release memory + freeMem(&dtable); + return nullptr; +} + +MB_String ESP_Mail_Client::encodeBase64Str(const unsigned char *src, size_t len) +{ + return encodeBase64Str((uint8_t *)src, len); +} + +MB_String ESP_Mail_Client::encodeBase64Str(uint8_t *src, size_t len) +{ + MB_String outStr; + unsigned char *out, *pos; + const unsigned char *end, *in; + size_t olen = 4 * ((len + 2) / 3); + if (olen < len) + return outStr; + + outStr.resize(olen); + out = (unsigned char *)&outStr[0]; + + end = src + len; + in = src; + pos = out; + + while (end - in >= 3) + { + *pos++ = b64_index_table[in[0] >> 2]; + *pos++ = b64_index_table[((in[0] & 0x03) << 4) | (in[1] >> 4)]; + *pos++ = b64_index_table[((in[1] & 0x0f) << 2) | (in[2] >> 6)]; + *pos++ = b64_index_table[in[2] & 0x3f]; + in += 3; + } + + if (end - in) + { + *pos++ = b64_index_table[in[0] >> 2]; + if (end - in == 1) + { + *pos++ = b64_index_table[(in[0] & 0x03) << 4]; + *pos++ = '='; + } + else + { + *pos++ = b64_index_table[((in[0] & 0x03) << 4) | (in[1] >> 4)]; + *pos++ = b64_index_table[(in[1] & 0x0f) << 2]; + } + *pos++ = '='; + } + + return outStr; +} + +#endif + +ESP_Mail_Client MailClient = ESP_Mail_Client(); + +#endif /* ESP_MAIL_CLIENT_CPP */ diff --git a/lib/libesp32/ESP-Mail-Client/src/ESP_Mail_Client.h b/lib/libesp32/ESP-Mail-Client/src/ESP_Mail_Client.h new file mode 100644 index 000000000..69099a497 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/ESP_Mail_Client.h @@ -0,0 +1,2862 @@ +#ifndef ESP_MAIL_CLIENT_H +#define ESP_MAIL_CLIENT_H + +#include "ESP_Mail_Client_Version.h" +#if !VALID_VERSION_CHECK(30409) +#error "Mixed versions compilation." +#endif + +/** + * Mail Client Arduino Library for Arduino devices. + * + * Created August 28, 2023 + * + * This library allows Espressif's ESP32, ESP8266, SAMD and RP2040 Pico devices to send and read Email through the SMTP and IMAP servers. + * + * The MIT License (MIT) + * Copyright (c) 2023 K. Suwatchai (Mobizt) + * + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include +#include "extras/RFC2047.h" +#include +#include + +#include +#include +#include + +#if __has_include() +#include +#endif + +#if __has_include() +#include +#endif + +#include "ESP_Mail_FS.h" +#include "ESP_Mail_Const.h" +#include "extras/MB_Time.h" + +#if defined(MB_ARDUINO_ESP) || defined(MB_ARDUINO_PICO) +#define ESP_MAIL_PRINTF ESP_MAIL_DEFAULT_DEBUG_PORT.printf +#else +#define ESP_MAIL_PRINTF MailClient.printf +#endif + +#if defined(ESP32) || defined(ESP8266) || defined(MB_ARDUINO_PICO) + +#define UPLOAD_CHUNKS_NUM 12 + +#if defined(ESP32) + +#define ESP_MAIL_MIN_MEM 70000 + +#elif defined(ESP8266) + +#define SD_CS_PIN 15 +#define ESP_MAIL_MIN_MEM 8000 + +#elif defined(MB_ARDUINO_PICO) + +#define ESP_MAIL_MIN_MEM 70000 +#define SD_CS_PIN PIN_SPI1_SS + +#endif + +#else + +#undef min +#undef max +#define ESP_MAIL_MIN_MEM 3000 +#define UPLOAD_CHUNKS_NUM 5 + +#ifdef __arm__ +// should use uinstd.h to define sbrk but Due causes a conflict +extern "C" char *sbrk(int incr); +#else // __ARM__ +extern char *__brkval; +#endif // __arm__ + +#endif + +#include "ESP_Mail_TCPClient.h" + +using namespace mb_string; + +class IMAPSession; +class SMTPSession; +class SMTP_Status; +class DownloadProgress; +class MessageData; + +#if defined(ENABLE_IMAP) + +class MessageList +{ +public: + friend class IMAPSession; + MessageList(){}; + ~MessageList() { clear(); }; + void add(int uid) + { + if (uid > 0) + _list.push_back(uid); + } + + void clear() { _list.clear(); } + +private: + _vectorImpl _list; +}; + +/* The class that provides the info of selected or opened mailbox folder */ +class SelectedFolderInfo +{ +public: + friend class ESP_Mail_Client; + friend class IMAPSession; + SelectedFolderInfo(){}; + ~SelectedFolderInfo() { clear(); }; + + /* Get the flags count for this mailbox */ + size_t flagCount(bool permanent = false) { return permanent ? _permanent_flags.size() : _flags.size(); }; + + /* Get the numbers of messages in this mailbox */ + size_t msgCount() { return _msgCount; }; + + /* Get the numbers of messages in this mailbox that recent flag was set */ + size_t recentCount() { return _recentCount; }; + + /* Get the order of message in number of message in this mailbox that reoved */ + /** + * The IMAP_Polling_Status has the properties e.g. type, messageNum, and argument. + * + * The type property is the type of status e.g.imap_polling_status_type_undefined, imap_polling_status_type_new_message, + * imap_polling_status_type_remove_message, and imap_polling_status_type_fetch_message. + * + * The messageNum property is message number or order from the total number of message that added, fetched or deleted. + * + * The argument property is the argument of commands e.g. FETCH + */ + IMAP_Polling_Status pollingStatus() { return _polling_status; }; + + /* Get the The unique identifier (UID) validity value */ + size_t uidValidity() { return _uidValidity; }; + + /* Get the predict next message UID */ + size_t nextUID() { return _nextUID; }; + + /* Get the index of first unseen message */ + size_t unseenIndex() { return _unseenMsgIndex; }; + + /* Get the highest modification sequence */ + uint64_t highestModSeq() { return strtoull(_highestModSeq.c_str(), NULL, 10); }; + + /* Check for the modification sequence supports */ + bool modSeqSupported() { return _highestModSeq.length() > 0 && !_nomodsec; }; + + /* Get the numbers of messages from search result based on the search criteria + */ + size_t searchCount() { return _searchCount; }; + + /* Get the numbers of messages to be stored in the ressult */ + size_t availableMessages() { return _availableItems; }; + + /* Get the flag argument at the specified index */ + String flag(size_t index, bool permanent = false) + { + size_t size = permanent ? _permanent_flags.size() : _flags.size(); + if (index < size) + return permanent ? _permanent_flags[index].c_str() : _flags[index].c_str(); + return ""; + } + +private: + void addFlag(const char *flag, bool permanent) + { + MB_String s = flag; + if (permanent) + _permanent_flags.push_back(s); + else + _flags.push_back(s); + }; + void clear() + { + for (size_t i = 0; i < _flags.size(); i++) + _flags[i].clear(); + _flags.clear(); + + for (size_t i = 0; i < _permanent_flags.size(); i++) + _permanent_flags[i].clear(); + _permanent_flags.clear(); + + _msgCount = 0; + _polling_status.argument.clear(); + _polling_status.messageNum = 0; + _polling_status.type = imap_polling_status_type_undefined; + _idleTimeMs = 0; + _searchCount = 0; + } + + size_t _msgCount = 0; + size_t _recentCount = 0; + size_t _uidValidity = 0; + size_t _nextUID = 0; + size_t _unseenMsgIndex = 0; + MB_String _highestModSeq; + size_t _searchCount = 0; + size_t _availableItems = 0; + unsigned long _idleTimeMs = 0; + bool _folderChanged = false; + bool _floderChangedState = false; + bool _nomodsec = false; + IMAP_Polling_Status _polling_status; + _vectorImpl _flags; + _vectorImpl _permanent_flags; +}; + +/* The class that provides the list of FolderInfo e.g. name, attributes and + * delimiter */ +class FoldersCollection +{ +public: + friend class ESP_Mail_Client; + friend class IMAPSession; + FoldersCollection(){}; + ~FoldersCollection() { clear(); }; + size_t size() { return _folders.size(); }; + + struct esp_mail_folder_info_item_t info(size_t index) + { + struct esp_mail_folder_info_item_t fd; + if (index < _folders.size()) + { + fd.name = _folders[index].name.c_str(); + fd.attributes = _folders[index].attributes.c_str(); + fd.delimiter = _folders[index].delimiter.c_str(); + } + return fd; + } + + esp_mail_folder_info_t operator[](size_t index) + { + if (index < _folders.size()) + return _folders[index]; + + return esp_mail_folder_info_t(); + } + +private: + void add(struct esp_mail_folder_info_t fd) { _folders.push_back(fd); }; + void clear() + { + for (size_t i = 0; i < _folders.size(); i++) + { + _folders[i].name.clear(); + _folders[i].attributes.clear(); + _folders[i].delimiter.clear(); + } + _folders.clear(); + } + _vectorImpl _folders; +}; + +/* The class that provides the list of IMAP_Quota_Root_Info e.g. resource name, used and limit */ +class IMAP_Quota_Roots_List +{ + friend class IMAPSession; + +public: + IMAP_Quota_Roots_List(){}; + ~IMAP_Quota_Roots_List() { clear(); }; + + size_t size() { return _quota_roots.size(); }; + + IMAP_Quota_Root_Info operator[](size_t index) + { + if (index < _quota_roots.size()) + return _quota_roots[index]; + + return IMAP_Quota_Root_Info(); + } + +private: + _vectorImpl _quota_roots; + + void add(IMAP_Quota_Root_Info v) + { + _quota_roots.push_back(v); + } + void clear() + { + _quota_roots.clear(); + } +}; + +/* The class that provides the list of IMAP_Namespaces */ +class IMAP_Namespaces +{ + friend class IMAPSession; + +public: + IMAP_Namespaces(){}; + ~IMAP_Namespaces() { clear(); }; + + size_t size() { return _ns_list.size(); }; + + IMAP_Namespace_Info operator[](size_t index) + { + if (index < _ns_list.size()) + return _ns_list[index]; + + return IMAP_Namespace_Info(); + } + +private: + _vectorImpl _ns_list; + + void add(IMAP_Namespace_Info v) + { + _ns_list.push_back(v); + } + void clear() + { + _ns_list.clear(); + } +}; + +/* The class that provides the list of IMAP_Namespaces */ +class IMAP_Rights_List +{ + friend class IMAPSession; + +public: + IMAP_Rights_List(){}; + ~IMAP_Rights_List() { clear(); }; + + size_t size() { return _rights_list.size(); }; + + IMAP_Rights_Info operator[](size_t index) + { + if (index < _rights_list.size()) + return _rights_list[index]; + + return IMAP_Rights_Info(); + } + +private: + _vectorImpl _rights_list; + + void add(IMAP_Rights_Info v) + { + _rights_list.push_back(v); + } + void clear() + { + _rights_list.clear(); + } +}; + +typedef struct esp_mail_imap_nanespace_list_t +{ + IMAP_Namespaces personal_namespaces; + IMAP_Namespaces other_users_namespaces; + IMAP_Namespaces shared_namespaces; +} IMAP_Namespaces_List; + +/* The class that provides the status of message feching and searching */ +class IMAP_Status +{ +public: + IMAP_Status(); + ~IMAP_Status(); + const char *info(); + bool success(); + void empty(); + friend class IMAPSession; + + MB_String _info; + bool _success = false; +}; + +typedef void (*imapStatusCallback)(IMAP_Status); +typedef void (*imapResponseCallback)(IMAP_Response); +typedef void (*MIMEDataStreamCallback)(MIME_Data_Stream_Info); +typedef void (*imapCharacterDecodingCallback)(IMAP_Decoding_Info *); + +#else + +enum esp_mail_imap_read_capability_types +{ + esp_mail_imap_read_capability_maxType +}; + +// Dummy class used in template functions (errorStatusCB). +class IMAPSession +{ +public: + struct IMAP_Status + { + public: + const char *info() { return ""; }; + bool success() { return false; }; + void empty(); + MB_String _info; + bool _success = false; + }; + + typedef void (*imapStatusCallback)(IMAP_Status); + MB_String errorReason() { return ""; } + bool _debug; + imapStatusCallback _statusCallback = nullptr; + void *_customCmdResCallback = nullptr; + esp_mail_session_type _sessionType = esp_mail_session_type_imap; + + struct esp_mail_imap_response_status_t + { + int errorCode = 0; + MB_String tag; + MB_String text; + MB_String status; + bool completed = false; + }; + + esp_mail_imap_response_status_t _responseStatus; + IMAP_Status _cbData; +}; +#endif + +#if defined(ENABLE_SMTP) + +/* The SMTP message class */ +class SMTP_Message +{ +public: + SMTP_Message() + { + text.content_type = "text/plain"; + html.content_type = "text/html"; + }; + + ~SMTP_Message() { clear(); }; + + void resetAttachItem(SMTP_Attachment &att) + { + att.blob.size = 0; + att.blob.data = nullptr; + att.file.path.clear(); + att.file.storage_type = esp_mail_file_storage_type_none; + att.descr.name.clear(); + att.descr.filename.clear(); + att.descr.transfer_encoding.clear(); + att.descr.content_encoding.clear(); + att.descr.mime.clear(); + att.descr.content_id.clear(); + att._int.att_type = esp_mail_att_type_none; + att._int.index = 0; + att._int.msg_uid = 0; + att._int.flash_blob = false; + att._int.xencoding = esp_mail_msg_xencoding_none; + att._int.parallel = false; + att._int.cid.clear(); + } + + void clear() + { + sender.name.clear(); + sender.email.clear(); + subject.clear(); + text.charSet.clear(); + text.content.clear(); + text.content_type.clear(); + text.embed.enable = false; + html.charSet.clear(); + html.content.clear(); + html.content_type.clear(); + html.embed.enable = false; + response.reply_to.clear(); + response.notify = esp_mail_smtp_notify::esp_mail_smtp_notify_never; + priority = esp_mail_smtp_priority::esp_mail_smtp_priority_normal; + + for (size_t i = 0; i < _rcp.size(); i++) + { + _rcp[i].name.clear(); + _rcp[i].email.clear(); + } + + for (size_t i = 0; i < _cc.size(); i++) + _cc[i].email.clear(); + + for (size_t i = 0; i < _bcc.size(); i++) + _bcc[i].email.clear(); + + for (size_t i = 0; i < _hdr.size(); i++) + _hdr[i].clear(); + + for (size_t i = 0; i < _att.size(); i++) + { + _att[i].descr.filename.clear(); + _att[i].blob.data = nullptr; + _att[i].descr.mime.clear(); + _att[i].descr.name.clear(); + _att[i].blob.size = 0; + _att[i].descr.transfer_encoding.clear(); + _att[i].file.path.clear(); + _att[i].file.storage_type = esp_mail_file_storage_type_none; + } + + for (size_t i = 0; i < _parallel.size(); i++) + { + _parallel[i].descr.filename.clear(); + _parallel[i].blob.data = nullptr; + _parallel[i].descr.mime.clear(); + _parallel[i].descr.name.clear(); + _parallel[i].blob.size = 0; + _parallel[i].descr.transfer_encoding.clear(); + _parallel[i].file.path.clear(); + _parallel[i].file.storage_type = esp_mail_file_storage_type_none; + } + + _rcp.clear(); + _cc.clear(); + _bcc.clear(); + _hdr.clear(); + _att.clear(); + _parallel.clear(); + } + + /** Clear all the inline images + */ + void clearInlineimages() + { + for (int i = (int)_att.size() - 1; i >= 0; i--) + { + if (_att[i]._int.att_type == esp_mail_att_type_inline) + _att.erase(_att.begin() + i); + } + }; + + /* Clear all the attachments */ + void clearAttachments() + { + for (int i = (int)_att.size() - 1; i >= 0; i--) + { + if (_att[i]._int.att_type == esp_mail_att_type_attachment) + _att.erase(_att.begin() + i); + } + + for (int i = (int)_parallel.size() - 1; i >= 0; i--) + _parallel.erase(_parallel.begin() + i); + }; + + /** Clear all rfc822 message attachment + */ + void clearRFC822Messages() + { + for (int i = (int)_rfc822.size() - 1; i >= 0; i--) + { + _rfc822[i].clear(); + _rfc822.erase(_rfc822.begin() + i); + } + }; + + /** Clear the primary recipient mailboxes + */ + void clearRecipients() { _rcp.clear(); }; + + /** Clear the Carbon-copy recipient mailboxes + */ + void clearCc() { _cc.clear(); }; + + /** Clear the Blind-carbon-copy recipient mailboxes + */ + void clearBcc() { _bcc.clear(); }; + + /** Clear the custom message headers + */ + void clearHeader() { _hdr.clear(); }; + + /** Add attachment to the message + * + * @param att The SMTP_Attachment data item + */ + void addAttachment(SMTP_Attachment &att) + { + att._int.att_type = esp_mail_att_type_attachment; + att._int.parallel = false; + att._int.flash_blob = true; + _att.push_back(att); + }; + + /** Add parallel attachment to the message + * + * @param att The SMTP_Attachment data item + */ + void addParallelAttachment(SMTP_Attachment &att) + { + att._int.att_type = esp_mail_att_type_attachment; + att._int.parallel = true; + att._int.flash_blob = true; + _parallel.push_back(att); + }; + + /** Add inline image to the message + * + * @param att The SMTP_Attachment data item + */ + void addInlineImage(SMTP_Attachment &att) + { + att._int.flash_blob = true; + att._int.parallel = false; + att._int.att_type = esp_mail_att_type_inline; + att._int.cid = random(2000, 4000); + _att.push_back(att); + }; + + /** Add rfc822 message to the message + * + * @param msg The RFC822_Message class object + */ + void addMessage(SMTP_Message &msg) { _rfc822.push_back(msg); } + + /** Add the primary recipient mailbox to the message + * + * @param name The name of primary recipient + * @param email The Email address of primary recipient + */ + template + void addRecipient(T1 name, T2 email) + { + struct esp_mail_address_info_t rcp; + rcp.name = toStringPtr(name); + rcp.email = toStringPtr(email); + _rcp.push_back(rcp); + }; + + /** Add Carbon-copy recipient mailbox + * + * @param email The Email address of the secondary recipient + */ + template + void addCc(T email) + { + struct esp_mail_address_info_t cc; + cc.email = toStringPtr(email); + _cc.push_back(cc); + }; + + /** Add Blind-carbon-copy recipient mailbox + * + * @param email The Email address of the tertiary recipient + */ + template + void addBcc(T email) + { + struct esp_mail_address_info_t bcc; + bcc.email = toStringPtr(email); + _bcc.push_back(bcc); + }; + + /** Add the custom header to the message + * + * @param hdr The header name and value + */ + template + void addHeader(T hdr) + { + _hdr.push_back(MB_String().setPtr(toStringPtr(hdr))); + }; + + /* The message author config */ + struct esp_mail_address_info_t author; + + /* The message sender (agent or teansmitter) config */ + struct esp_mail_address_info_t sender; + + /* The topic of message */ + MB_String subject; + + /* The message type */ + byte type = esp_mail_msg_type_none; + + /* The PLAIN text message */ + esp_mail_plain_body_t text; + + /* The HTML text message */ + esp_mail_html_body_t html; + + /* The response config */ + struct esp_mail_smtp_msg_response_t response; + + /* The priority of the message */ + esp_mail_smtp_priority priority = esp_mail_smtp_priority::esp_mail_smtp_priority_normal; + + /* The enable options */ + struct esp_mail_smtp_enable_option_t enable; + + /* The message from config */ + struct esp_mail_address_info_t from; + + /* The message identifier */ + MB_String messageID; + + /* The keywords or phrases, separated by commas */ + MB_String keywords; + + /* The comments about message */ + MB_String comments; + + /* The date of message */ + MB_String date; + + /* The field that contains the parent's message ID of the message to which this one is a reply */ + MB_String in_reply_to; + + /* The field that contains the parent's references (if any) and followed by the parent's message ID (if any) of the message to which this one is a reply */ + MB_String references; + + /* The timestamp value to replace in text */ + esp_mail_timestamp_value_t timestamp; + +private: + friend class ESP_Mail_Client; + _vectorImpl _rcp; + _vectorImpl _cc; + _vectorImpl _bcc; + _vectorImpl _hdr; + _vectorImpl _att; + _vectorImpl _parallel; + _vectorImpl _rfc822; +}; + +class SMTP_Status +{ +public: + friend class SMTPSession; + friend class ESP_Mail_Client; + + SMTP_Status(); + ~SMTP_Status(); + const char *info(); + bool success(); + void empty(); + size_t completedCount(); + size_t failedCount(); + +private: + MB_String _info; + bool _success = false; + size_t _sentSuccess = 0; + size_t _sentFailed = 0; +}; + +typedef void (*smtpStatusCallback)(SMTP_Status); +typedef void (*smtpResponseCallback)(SMTP_Response); + +#endif + +class ESP_Mail_Client +{ + +public: + ESP_Mail_Client() + { + mbfs = new MB_FS(); + }; + + ~ESP_Mail_Client() + { + if (mbfs) + delete mbfs; + mbfs = nullptr; + + wifi.clearAP(); + }; + +#if defined(ENABLE_SMTP) + /** Sending Email through the SMTP server + * + * @param smtp The pointer to SMTP session object which holds the data and the + * TCP client. + * @param msg The pointer to SMTP_Message class which contains the header, + * body, and attachments. + * @param closeSession The option to Close the SMTP session after sent. + * @return The boolean value indicates the success of operation. + */ + bool sendMail(SMTPSession *smtp, SMTP_Message *msg, bool closeSession = true); +#endif + +#if defined(ENABLE_SMTP) && defined(ENABLE_IMAP) + /** Append message to the mailbox + * + * @param imap The pointer to IMAP session object which holds the data and the + * TCP client. + * @param msg The pointer to SMTP_Message class which contains the header, + * body, and attachments. + * @param lastAppend The last message to append (optional). In case of MULTIAPPEND extension + * is supported, set this to false will append messages in single APPEND command. + * @param flags The flags to set to this message (optional). + * @param dateTime The date/time to set to this message (optional). + * @return The boolean value indicates the success of operation. + */ + template + bool appendMessage(IMAPSession *imap, SMTP_Message *msg, bool lastAppend = true, T1 flags = "", T2 dateTime = "") { return mAppendMessage(imap, msg, lastAppend, toStringPtr(flags), toStringPtr(dateTime)); } +#endif + +#if defined(ENABLE_IMAP) + /** Reading Email through IMAP server. + * + * @param imap The pointer to IMAP session object which holds the data and + the TCP client. + + * @param closeSession The option to close the IMAP session after fetching or + searching the Email. + * @return The boolean value indicates the success of operation. + */ + bool readMail(IMAPSession *imap, bool closeSession = true); + + /** Set the argument to the Flags for the specified message. + * + * @param imap The pointer to IMAP session object which holds the data and the + * TCP client. + * @param msgUID The UID of the message. + * @param flags The flag list to set. + * @param closeSession The option to close the IMAP session after set flag. + * @param silent The option to ignore the response. + * @param modsequence The int32_t option for UNCHANGESINCE conditional test. + * @return The boolean value indicates the success of operation. + * + * The modsequence value can be used only if IMAP server supports Conditional STORE extension + * and the selected mailbox supports modsequences. + */ + template + bool setFlag(IMAPSession *imap, int msgUID, T flags, bool closeSession, bool silent = false, int32_t modsequence = -1) { return mSetFlag(imap, toStringPtr(msgUID), toStringPtr(flags), esp_mail_imap_store_flag_type_set, closeSession, silent, true, modsequence); } + + /** Set the argument to the Flags for the specified message. + * + * @param imap The pointer to IMAP session object which holds the data and the + * TCP client. + * @param sequenceSet The sequence set string i.g., unique identifier (UID) or message sequence number or ranges of UID or sequence number. + * @param UID The option for sequenceSet whether it is UID or message sequence number. + * @param flags The flag list to set. + * @param closeSession The option to close the IMAP session after set flag. + * @param silent The option to ignore the response. + * @param modsequence The int32_t option for UNCHANGESINCE conditional test. + * @return The boolean value indicates the success of operation. + * + * The modsequence value can be used only if IMAP server supports Conditional STORE extension + * and the selected mailbox supports modsequences. + */ + template + bool setFlag(IMAPSession *imap, T1 sequenceSet, bool UID, T2 flags, bool closeSession, bool silent = false, int32_t modsequence = -1) { return mSetFlag(imap, toStringPtr(sequenceSet), toStringPtr(flags), esp_mail_imap_store_flag_type_set, closeSession, silent, UID, modsequence); } + + /** Add the argument to the Flags for the specified message. + * + * @param imap The pointer to IMAP session object which holds the data and the + * TCP client. + * @param msgUID The UID of the message. + * @param flags The flag list to add. + * @param closeSession The option to close the IMAP session after add flag. + * @param silent The option to ignore the response. + * @param modsequence The int32_t option for UNCHANGESINCE conditional test. + * @return The boolean value indicates the success of operation. + * + * The modsequence value can be used only if IMAP server supports Conditional STORE extension + * and the selected mailbox supports modsequences. + */ + template + bool addFlag(IMAPSession *imap, int msgUID, T flags, bool closeSession, bool silent = false, int32_t modsequence = -1) { return mSetFlag(imap, toStringPtr(msgUID), toStringPtr(flags), esp_mail_imap_store_flag_type_add, closeSession, silent, true, modsequence); } + + /** Add the argument to the Flags for the specified message. + * + * @param imap The pointer to IMAP session object which holds the data and the + * TCP client. + * @param sequenceSet The sequence set string i.g., unique identifier (UID) or message sequence number or ranges of UID or sequence number. + * @param UID The option for sequenceSet whether it is UID or message sequence number. + * @param flags The flag list to add. + * @param closeSession The option to close the IMAP session after set flag. + * @param silent The option to ignore the response. + * @param modsequence The int32_t option for UNCHANGESINCE conditional test. + * @return The boolean value indicates the success of operation. + * + * The modsequence value can be used only if IMAP server supports Conditional STORE extension + * and the selected mailbox supports modsequences. + */ + template + bool addFlag(IMAPSession *imap, T1 sequenceSet, bool UID, T2 flags, bool closeSession, bool silent = false, int32_t modsequence = -1) { return mSetFlag(imap, toStringPtr(sequenceSet), toStringPtr(flags), esp_mail_imap_store_flag_type_add, closeSession, silent, UID, modsequence); } + + /** Remove the argument from the Flags for the specified message. + * + * @param imap The pointer to IMAP session object which holds the data and the + * TCP client. + * @param msgUID The UID of the message that flags to be removed. + * @param flags The flag list to remove. + * @param closeSession The option to close the IMAP session after remove flag. + * @param silent The option to ignore the response. + * @param modsequence The int32_t option for UNCHANGESINCE conditional test. + * @return The boolean value indicates the success of operation. + * + * The modsequence value can be used only if IMAP server supports Conditional STORE extension + * and the selected mailbox supports modsequences. + */ + template + bool removeFlag(IMAPSession *imap, int msgUID, T flags, bool closeSession, bool silent = false, int32_t modsequence = -1) { return mSetFlag(imap, toStringPtr(msgUID), toStringPtr(flags), esp_mail_imap_store_flag_type_remove, closeSession, silent, true, modsequence); } + + /** Remove the argument from the Flags for the specified message. + * + * @param imap The pointer to IMAP session object which holds the data and the + * TCP client. + * @param sequenceSet The sequence set string i.g., unique identifier (UID) or message sequence number or ranges of UID or sequence number. + * @param UID The option for sequenceSet whether it is UID or message sequence number. + * @param flags The flag list to remove. + * @param closeSession The option to close the IMAP session after set flag. + * @param silent The option to ignore the response. + * @param modsequence The int32_t option for UNCHANGESINCE conditional test. + * @return The boolean value indicates the success of operation. + * + * The modsequence value can be used only if IMAP server supports Conditional STORE extension + * and the selected mailbox supports modsequences. + */ + template + bool removeFlag(IMAPSession *imap, T1 sequenceSet, bool UID, T2 flags, bool closeSession, bool silent = false, int32_t modsequence = -1) { return mSetFlag(imap, toStringPtr(sequenceSet), toStringPtr(flags), esp_mail_imap_store_flag_type_remove, closeSession, silent, UID, modsequence); } + +#endif + + /** Reconnect WiFi or network if lost connection. + * + * @param reconnect The boolean to set/unset WiFi AP reconnection. + */ + void networkReconnect(bool reconnect); + + /* Obsoleted */ + void setUDPClient(void *client, float gmtOffset) {} + + /** Clear all WiFi access points assigned. + * + */ + void clearAP(); + + /** Add WiFi access point for non-ESP device to resume WiFi connection. + * + * @param ssid The WiFi SSID. + * @param password The WiFi password. + */ + void addAP(const String &ssid, const String &password); + + /** + * Formatted printing on debug port. + * + */ + void printf(const char *format, ...); + +#if defined(MBFS_SD_FS) && defined(MBFS_CARD_TYPE_SD) + + /** Initiate SD card with SPI port configuration. + * + * @param ss SPI Chip/Slave Select pin. + * @param sck SPI Clock pin. + * @param miso SPI MISO pin. + * @param mosi SPI MOSI pin. + * @param frequency The SPI frequency + * @return Boolean type status indicates the success of the operation. + */ + bool sdBegin(int8_t ss = -1, int8_t sck = -1, int8_t miso = -1, int8_t mosi = -1, uint32_t frequency = 4000000); + +#if defined(ESP8266) || defined(MB_ARDUINO_PICO) + + /** Initiate SD card with SD FS configurations (ESP8266 only). + * + * @param ss SPI Chip/Slave Select pin. + * @param sdFSConfig The pointer to SDFSConfig object (ESP8266 only). + * @return Boolean type status indicates the success of the operation. + */ + bool sdBegin(SDFSConfig *sdFSConfig); + +#endif + +#if defined(ESP32) + /** Initiate SD card with chip select and SPI configuration (ESP32 only). + * + * @param ss SPI Chip/Slave Select pin. + * @param spiConfig The pointer to SPIClass object for SPI configuartion. + * @param frequency The SPI frequency. + * @return Boolean type status indicates the success of the operation. + */ + bool sdBegin(int8_t ss, SPIClass *spiConfig = nullptr, uint32_t frequency = 4000000); +#endif + +#if defined(MBFS_ESP32_SDFAT_ENABLED) || defined(MBFS_SDFAT_ENABLED) + /** Initiate SD card with SdFat SPI and pins configurations (with SdFat included only). + * + * @param sdFatSPIConfig The pointer to SdSpiConfig object for SdFat SPI configuration. + * @param ss SPI Chip/Slave Select pin. + * @param sck SPI Clock pin. + * @param miso SPI MISO pin. + * @param mosi SPI MOSI pin. + * @return Boolean type status indicates the success of the operation. + */ + bool sdBegin(SdSpiConfig *sdFatSPIConfig, int8_t ss = -1, int8_t sck = -1, int8_t miso = -1, int8_t mosi = -1); + + /** Initiate SD card with SdFat SDIO configuration (with SdFat included only). + * + * @param sdFatSDIOConfig The pointer to SdioConfig object for SdFat SDIO configuration. + * @return Boolean type status indicates the success of the operation. + */ + bool sdBegin(SdioConfig *sdFatSDIOConfig); + +#endif + +#endif + +#if defined(ESP32) && defined(MBFS_SD_FS) && defined(MBFS_CARD_TYPE_SD_MMC) + /** Initialize the SD_MMC card (ESP32 only). + * + * @param mountpoint The mounting point. + * @param mode1bit Allow 1 bit data line (SPI mode). + * @param format_if_mount_failed Format SD_MMC card if mount failed. + * @return The boolean value indicates the success of operation. + */ + bool sdMMCBegin(const char *mountpoint = "/sdcard", bool mode1bit = false, bool format_if_mount_failed = false); +#endif + + /** Get free Heap memory. + * + * @return Free memory amount in byte. + */ + int getFreeHeap(); + + /** Get base64 encode string. + * + * @return String of base64 encoded string. + */ + template + String toBase64(T str) { return mGetBase64(toStringPtr(str)).c_str(); } + + MB_Time Time; + +#if defined(ENABLE_IMAP) + + // Get encoding type from character set string + esp_mail_char_decoding_scheme getEncodingFromCharset(const char *enc); + + // Decode Latin1 to UTF-8 + int decodeLatin1_UTF8(unsigned char *out, int *outlen, const unsigned char *in, int *inlen); + + // Decode TIS620 to UTF-8 + void decodeTIS620_UTF8(char *out, const char *in, size_t len); + + // handle rfc2047 Q (quoted printable) and B (base64) decodings + RFC2047_Decoder RFC2047Decoder; + +#endif + +private: + friend class SMTPSession; + friend class IMAPSession; + + MB_FS *mbfs = nullptr; + bool timeStatus = false; + time_t ts = 0; + bool networkAutoReconnect = true; + volatile bool networkStatus = false; + esp_mail_wifi_credentials_t wifi; + bool timezoneEnvSet = false; + + IMAPSession *imap = nullptr; + bool calDataLen = false; + uint32_t dataLen = 0; + uint32_t imap_ts = 0; + +#if defined(ENABLE_SMTP) || defined(ENABLE_IMAP) + + unsigned long _lastReconnectMillis = 0; + uint16_t _reconnectTimeout = ESP_MAIL_NETWORK_RECONNECT_TIMEOUT; + + // Resume network connection + void resumeNetwork(ESP_Mail_TCPClient *client); + + // Get the CRLF ending string w/wo CRLF included. Return the size of string read and the current octet read. + int readLine(ESP_Mail_TCPClient *client, char *buf, int bufLen, bool withLineBreak, int &count, bool &ovf, unsigned long timeoutSec, bool &isTimeout); + + // readLine with overflow handling. + template + bool readResponse(T sessionPtr, char *buf, int bufLen, int &readLen, bool withLineBreak, int &count, MB_String &ovfBuf); + + // Network reconnection and return the connection status + template + bool reconnect(T sessionPtr, unsigned long dataTime = 0, bool downloadRequest = false); + + // Send callback + template + void sendCB(T sessionPtr, PGM_P info = "", bool prependCRLF = false, bool success = false); + + // PGM string replacement + void strReplaceP(MB_String &buf, PGM_P key, PGM_P value); + + // Check for OAuth log in error response + bool isOAuthError(char *buf, int bufLen, int &chunkIdx, int ofs); + + // Get SASL XOAUTH2 string + MB_String getXOAUTH2String(const MB_String &email, const MB_String &accessToken); + + // Send error callback + template + void sendErrorCB(T sessionPtr, PGM_P info, bool prependCRLF = false, bool success = false); + + // Send the error status callback + template + void errorStatusCB(T1 sessionPtr, T2 sessionPtr2, int error, bool clearLastStatus); + + // Check response callback was assigned? + template + bool isResponseCB(T sessionPtr); + + // Print library info + template + void printLibInfo(T sessionPtr); + + // Begin server connection + template + bool beginConnection(Session_Config *session_config, T sessionPtr, bool secureMode); + + // Prepare system time + template + bool prepareTime(Session_Config *session_config, T sessionPtr); + + // Check for session. Close session If not ready. + template + bool sessionReady(T sessionPtr); + + // Set cert data + void setCert(Session_Config *session_cfg, const char *ca); + // Set secure data + void setSecure(ESP_Mail_TCPClient &client, Session_Config *session_config); + + void appendMultipartContentType(MB_String &buf, esp_mail_multipart_types type, const char *boundary); + + String errorReason(bool isSMTP, int errorCode, const char *msg); + + // Close TCP session and clear auth_capability, read/send_capability, connected and authenticate statuses + template + void closeTCPSession(T sessionPtr); + + // Get and set timezone + void getSetTimezoneEnv(const char *TZ_file, const char *TZ_Var); + + // Get TCP connected status + template + bool connected(T sessionPtr); + + // Get the memory allocation block size of multiple of 4 + size_t getReservedLen(size_t len); + + // Check Email for valid format + bool validEmail(const char *s); + + // Get random UID for SMTP content ID and IMAP attachment default file name + char *getRandomUID(); + + // Spit the string into token strings + void splitToken(const char *str, _vectorImpl &tk, const char *delim); + + // Decode base64 encoded string + unsigned char *decodeBase64(const unsigned char *src, size_t len, size_t *out_len); + + // Decode base64 encoded string + MB_String encodeBase64Str(const unsigned char *src, size_t len); + + // Decode base64 encoded string + MB_String encodeBase64Str(uint8_t *src, size_t len); + + // Decode base64 encoded string + MB_String mGetBase64(MB_StringPtr str); + + // Sub string + char *subStr(const char *buf, PGM_P beginToken, PGM_P endToken, int beginPos, int endPos = 0, bool caseSensitive = true); + + // Find string + int strpos(const char *haystack, const char *needle, int offset, bool caseSensitive = true); + + // Memory allocation + template + T allocMem(size_t size, bool clear = true); + + // Memory deallocation + void freeMem(void *ptr); + + // PGM string compare + bool strcmpP(const char *buf, int ofs, PGM_P beginToken, bool caseSensitive = true); + + // Find PGM string + int strposP(const char *buf, PGM_P beginToken, int ofs, bool caseSensitive = true); + + // Memory allocation for PGM string + char *strP(PGM_P pgm); + + // Memory allocation for PGM lower case string + char *strP2Lower(PGM_P pgm); + + // Set or sync device system time with NTP server + // Do not modify or remove + void setTime(const char *TZ_Var, const char *TZ_file, bool wait, bool debugProgress); + + // Set the device time zone via TZ environment variable + void setTimezone(const char *TZ_Var, const char *TZ_file); + + // Get TZ environment variable from file + // Do not modify or remove + void getTimezone(const char *TZ_file, MB_String &out); + + // Check the session existent + template + bool sessionExisted(T sessionPtr); + + // Send SMTP/IMAP callback + template + void sendCallback(T sessionPtr, PGM_P info, bool prependCRLF, bool success); + + // Send IMAP/SMTP response callback and print debug message + template + void printDebug(T sessionPtr, PGM_P cbMsg, PGM_P dbMsg, esp_mail_debug_tag_type type, bool prependCRLF, bool success); + + // Get header content from response based on the field name + bool getHeader(const char *buf, PGM_P beginToken, MB_String &out, bool caseSensitive); + + // Append header field to buffer + void appendHeaderField(MB_String &buf, const char *name, PGM_P value, bool comma, bool newLine, esp_mail_string_mark_type type = esp_mail_string_mark_type_none); + + // Append SMTP address header field + void appendAddressHeaderField(MB_String &buf, esp_mail_address_info_t &source, esp_mail_rfc822_header_field_types type, bool header, bool comma, bool newLine); + + // Append header field name to buffer + void appendHeaderName(MB_String &buf, const char *name, bool clear = false, bool lowercase = false, bool space = true); + + // Append lowercase string to buffer + void appendLowerCaseString(MB_String &buf, PGM_P value, bool clear = false); + + // Append header field property to buffer + void appendHeaderProp(MB_String &buf, PGM_P prop, const char *value, bool &firstProp, bool lowerCase, bool isString, bool newLine); + + // Append quote string to buffer + void appendString(MB_String &buf, PGM_P value, bool comma, bool newLine, esp_mail_string_mark_type type = esp_mail_string_mark_type_none); + + // Append list to buffer + template + void appendList(MB_String &buf, _vectorImpl &list); + + // Append space to buffer + void appendSpace(MB_String &buf); + + // Append space to buffer after value + void appendSpace(MB_String &buf, bool withTag, PGM_P value); + + // Append space to buffer after values + void appendSpace(MB_String &buf, bool withTag, int nunArgs, ...); + + // Append space to buffer before value + void prependSpace(MB_String &buf, PGM_P value); + + // Append dot to buffer + void appendDot(MB_String &buf); + + // Append IMAP string key value list + void appendImap4KeyValue(MB_String &buf, PGM_P key, PGM_P value); + + // Append dot to buffer before value + void prependDot(MB_String &buf, PGM_P value); + + // Join 2 strings to buffer with space + void joinStringSpace(MB_String &buf, bool withTag, int nunArgs, ...); + + // Join 2 strings to buffer with dot + void joinStringDot(MB_String &buf, int nunArgs, ...); + + // Append mask(*) string to buffer + void maskString(MB_String &buf, int len); + + // Append domain to buffer + void appendDomain(MB_String &buf, const char *domain); + + // Append embedded message header to buffer + void appendEmbedMessage(MB_String &buf, esp_mail_message_body_t &body, bool isHtml); + + // Append crlf to buffer + void appendNewline(MB_String &buf); + + // Append tag to the buffer + void appendTagSpace(MB_String &buf, PGM_P tag = NULL); + + // Print newline + void debugPrintNewLine(); + + // Send newline to callback + template + void callBackSendNewLine(T sessionPtr, bool success); + + // Print progress bar + void printProgress(int progress, int &lastProgress); + + // Get file extension with dot from MIME string + void getExtfromMIME(const char *mime, MB_String &ext); + + // Prepare ports + void preparePortFunction(Session_Config *session_config, bool isSMTP, bool &secure, bool &secureMode, bool &ssl); + + // Get operation config based on port and its protocol + void getPortFunction(uint16_t port, struct esp_mail_ports_functions &ports_functions, bool &secure, bool &secureMode, bool &ssl, bool &starttls); + +#endif + +#if defined(ENABLE_SMTP) + + // Encode Quoted Printable string + void encodeQP(const char *buf, char *out); + + // Add the soft line break to the long text line rfc 3676 + void formatFlowedText(MB_String &content); + + // Insert soft break + void softBreak(MB_String &content, const char *quoteMarks); + + // Get content type (MIME) from file extension + void getMIME(const char *ext, MB_String &mime); + + // Get content type (MIME) from file name + void mimeFromFile(const char *name, MB_String &mime); + + // Get MIME boundary string + MB_String getMIMEBoundary(size_t len); + + // Send Email function + bool mSendMail(SMTPSession *smtp, SMTP_Message *msg, bool closeSession = true); + + // SMTP send data + size_t smtpSend(SMTPSession *smtp, PGM_P data, bool newline = false); + + // SMTP send data + size_t smtpSend(SMTPSession *smtp, int data, bool newline = false); + + // SMTP send data + size_t smtpSend(SMTPSession *smtp, uint8_t *data, size_t size); + + // Handle the error by sending callback and close session + bool handleSMTPError(SMTPSession *smtp, int err, bool ret = false); + + // Send parallel attachment RFC1521 + bool sendParallelAttachments(SMTPSession *smtp, SMTP_Message *msg, const MB_String &boundary); + + // Send attachment + bool sendAttachments(SMTPSession *smtp, SMTP_Message *msg, const MB_String &boundary, bool parallel = false); + + // Send message content + bool sendContent(SMTPSession *smtp, SMTP_Message *msg, bool closeSession, bool rfc822MSG); + + // Send imap or smtp callback + void altSendCallback(SMTPSession *smtp, PGM_P cbMsg, PGM_P dbMsg, esp_mail_debug_tag_type type, bool prependCRLF, bool success); + + // Send message data + bool sendMSGData(SMTPSession *smtp, SMTP_Message *msg, bool closeSession, bool rfc822MSG); + + // Send RFC 822 message + bool sendRFC822Msg(SMTPSession *smtp, SMTP_Message *msg, const MB_String &boundary, bool closeSession, bool rfc822MSG); + + // Get RFC 822 message envelope + void getRFC822MsgEnvelope(SMTPSession *smtp, SMTP_Message *msg, MB_String &buf); + + // Append boundary string to buffer + void appendBoundaryString(MB_String &buf, const char *value, bool endMark, bool newLine); + + // Send BDAT command RFC 3030 + bool sendBDAT(SMTPSession *smtp, SMTP_Message *msg, int len, bool last); + + // Get transfer encoding + void getXEncoding(esp_mail_msg_xencoding &xencoding, const char *enc); + + // Set the unencoded xencoding enum for html, text and attachment from its xencoding string + void checkUnencodedData(SMTPSession *smtp, SMTP_Message *msg); + + // Check imap or smtp has callback set + bool altIsCB(SMTPSession *smtp); + + // Check imap or smtp has debug set + bool altIsDebug(SMTPSession *smtp); + + // Send BLOB attachment + bool sendBlobAttachment(SMTPSession *smtp, SMTP_Message *msg, SMTP_Attachment *att); + + // Send file content + bool sendFile(SMTPSession *smtp, SMTP_Message *msg, SMTP_Attachment *att); + + // Send imap or smtp storage error callback + void altSendStorageErrorCB(SMTPSession *smtp, int err); + + // Open file to send an attachment + bool openFileRead(SMTPSession *smtp, SMTP_Message *msg, SMTP_Attachment *att, MB_String &buf, const MB_String &boundary, bool inlined); + + // Open text file or html file for to send message + bool openFileRead2(SMTPSession *smtp, SMTP_Message *msg, const char *path, esp_mail_file_storage_type storageType); + + // Send inline attachments + bool sendInline(SMTPSession *smtp, SMTP_Message *msg, const MB_String &boundary, byte type); + + // Send storage error callback + void sendStorageNotReadyError(SMTPSession *smtp, esp_mail_file_storage_type storageType); + + // Append message + bool mAppendMessage(IMAPSession *imap, SMTP_Message *msg, bool lastAppend, MB_StringPtr flags, MB_StringPtr dateTime); + + // Get numbers of attachment based on type + size_t numAtt(SMTPSession *smtp, esp_mail_attach_type type, SMTP_Message *msg); + + // Check for valid recipient Email + bool checkEmail(SMTPSession *smtp, SMTP_Message *msg); + + // Send text parts MIME message + bool sendPartText(SMTPSession *smtp, SMTP_Message *msg, byte type, const char *boundary); + + // Alternative string data sending to send imap APPEND data or smtp data + bool altSendData(MB_String &s, bool newLine, SMTPSession *smtp, SMTP_Message *msg, bool addSendResult, bool getResponse, esp_mail_smtp_command cmd, esp_mail_smtp_status_code statusCode, int errCode); + + // Alternative bytes data sending to send imap APPEND data or smtp data + bool altSendData(uint8_t *data, size_t size, SMTPSession *smtp, SMTP_Message *msg, bool addSendResult, bool getResponse, esp_mail_smtp_command cmd, esp_mail_smtp_status_code statusCode, int errCode); + + // Send MIME message + bool sendMSG(SMTPSession *smtp, SMTP_Message *msg, const MB_String &boundary); + + // Get an attachment part header string + void getAttachHeader(MB_String &header, const MB_String &boundary, SMTP_Attachment *attach, size_t size, bool isInline); + + // Get RFC 8222 part header string + void getRFC822PartHeader(SMTPSession *smtp, MB_String &header, const MB_String &boundary); + + // Send BLOB type text part or html part MIME message + bool sendBlobBody(SMTPSession *smtp, SMTP_Message *msg, uint8_t type); + + // Send file type text part or html part MIME message + bool sendFileBody(SMTPSession *smtp, SMTP_Message *msg, uint8_t type); + + // Base64 and QP encodings for text and html messages and replace embeded attachment file name with content ID + void encodingText(SMTPSession *smtp, SMTP_Message *msg, uint8_t type, MB_String &content); + + // Blob or Stream available + int chunkAvailable(SMTPSession *smtp, esp_mail_smtp_send_base64_data_info_t &data_info); + + // Read chunk data of blob or file + int getChunk(SMTPSession *smtp, esp_mail_smtp_send_base64_data_info_t &data_info, unsigned char *rawChunk, bool base64); + + // Terminate chunk reading + void closeChunk(esp_mail_smtp_send_base64_data_info_t &data_info); + + // Get base64 encoded buffer or raw buffer + void getBuffer(bool base64, uint8_t *out, uint8_t *in, int &encodedCount, int &bufIndex, bool &dataReady, int &size, size_t chunkSize); + + // Send blob or file as base64 encoded chunk + bool sendBase64(SMTPSession *smtp, SMTP_Message *msg, esp_mail_smtp_send_base64_data_info_t &data_info, bool base64, bool report); + + // Save sending logs to file + void saveSendingLogs(SMTPSession *smtp, SMTP_Message *msg, bool result); + + // Get imap or smtp report progress var pointer + uint32_t altProgressPtr(SMTPSession *smtp); + + // Get SMTP response status (statusCode and text) + void getResponseStatus(const char *buf, esp_mail_smtp_status_code statusCode, int beginPos, struct esp_mail_smtp_response_status_t &status); + + // Parse SMTP authentication capability + void parseAuthCapability(SMTPSession *smtp, char *buf); + + // Add the sending result + bool addSendingResult(SMTPSession *smtp, SMTP_Message *msg, bool result, bool showResult); + + // Handle SMTP server authentication + bool smtpAuth(SMTPSession *smtp, bool &ssl); + + // Handle SMTP response + bool handleSMTPResponse(SMTPSession *smtp, esp_mail_smtp_command cmd, esp_mail_smtp_status_code statusCode, int errCode); + + // Print the upload status to the debug port + void uploadReport(const char *filename, uint32_t pgAddr, int progress); + + // Get MB_FS object pointer + MB_FS *getMBFS(); + + // Set device system time + int setTimestamp(time_t ts); +#endif + +#if defined(ENABLE_IMAP) + + // Check if child part (part number string) is a member of the parent part (part number string) + // part number string format: .. + bool multipartMember(const MB_String &parent, const MB_String &child); + + // Decode string + int decodeChar(const char *s); + + // Decode Quoted Printable string + void decodeQP_UTF8(const char *buf, char *out); + + // Actually not decode because 7bit string is enencode string unless prepare valid 7bit string and do qp decoding + char *decode7Bit_UTF8(char *buf); + + // Actually not decode because 8bit string is enencode string unless prepare valid 8bit string + char *decode8Bit_UTF8(char *buf); + + // Decode string base on encoding + void decodeString(IMAPSession *imap, MB_String &string, const char *enc = ""); + + /** + * Encode a code point using UTF-8 + * + * @author Ondřej Hruška + * https://gist.github.com/MightyPork/52eda3e5677b4b03524e40c9f0ab1da5 + * + * @license MIT + * + * @param out - output buffer (min 5 characters), will be 0-terminated + * @param utf - code point 0-0x10FFFF + * @return number of bytes on success, 0 on failure (also produces U+FFFD, which uses 3 bytes) + */ + int encodeUnicode_UTF8(char *out, uint32_t utf); + + // Append headers fetch command + void appendHeadersFetchCommand(IMAPSession *imap, MB_String &cmd, int index, bool debug); + + // Append rfc822 headers fetch command + void appendRFC822HeadersFetchCommand(MB_String &cmd); + + // Get multipart MIME fetch command + bool getMultipartFechCmd(IMAPSession *imap, int msgIdx, MB_String &partText); + + // Fetch multipart MIME body header + bool fetchMultipartBodyHeader(IMAPSession *imap, int msgIdx); + + // Print body part fetching debug + void printBodyPartFechingDubug(IMAPSession *imap, const char *partNum, bool multiLevel); + + // Handle IMAP server authentication + bool imapAuth(IMAPSession *imap, bool &ssl); + + // Send IMAP command + bool sendFetchCommand(IMAPSession *imap, int msgIndex, esp_mail_imap_command cmdCase); + + // Send data + size_t imapSend(IMAPSession *imap, PGM_P data, bool newline = false); + + // Send data + size_t imapSend(IMAPSession *imap, int data, bool newline = false); + + // Send data + size_t imapSend(IMAPSession *imap, uint8_t *data, size_t size); + + // Log out + bool imapLogout(IMAPSession *imap); + + // Send storage error callback + void sendStorageNotReadyError(IMAPSession *imap, esp_mail_file_storage_type storageType); + + // Parse search response + int parseSearchResponse(IMAPSession *imap, esp_mail_imap_response_data &res, PGM_P tag, const char *key); + + // Parse header state + bool parseHeaderField(IMAPSession *imap, const char *buf, PGM_P beginToken, bool caseSensitive, struct esp_mail_message_header_t &header, int &headerState, int state); + + // Parse header response + void parseHeaderResponse(IMAPSession *imap, esp_mail_imap_response_data &res, bool caseSensitive = true); + + // Set the header based on state parsed + void collectHeaderField(IMAPSession *imap, char *buf, struct esp_mail_message_header_t &header, int state); + + // Get decoded header + bool getDecodedHeader(IMAPSession *imap, const char *buf, PGM_P beginToken, MB_String &out, bool caseSensitive); + + // Check attachment for firmware file + void checkFirmwareFile(IMAPSession *imap, const char *filename, struct esp_mail_message_part_info_t &part, bool defaultSize = false); + + // Parse part header response + void parsePartHeaderResponse(IMAPSession *imap, esp_mail_imap_response_data &res, bool caseSensitive = true); + + // Count char in string + int countChar(const char *buf, char find); + + // Store the value to string via its the pointer + bool storeStringPtr(IMAPSession *imap, uint32_t addr, MB_String &value, const char *buf); + + // Get part header properties + bool getPartHeaderProperties(IMAPSession *imap, const char *buf, PGM_P p, PGM_P e, bool num, MB_String &value, MB_String &old_value, esp_mail_char_decoding_scheme &scheme, bool caseSensitive); + + // Url decode for UTF-8 encoded header text + char *urlDecode(const char *str); + + // Reset the pointer to multiline response keeping string + void resetStringPtr(struct esp_mail_message_part_info_t &part); + + // Get current part + struct esp_mail_message_part_info_t *cPart(IMAPSession *imap); + + // Get current header + struct esp_mail_message_header_t *cHeader(IMAPSession *imap); + +#if !defined(MB_USE_STD_VECTOR) + // Decending sort + void numDecSort(_vectorImpl &arr); +#endif + + // Handle IMAP response + bool handleIMAPResponse(IMAPSession *imap, int errCode, bool closeSession); + + // Print the file download status via debug port + void downloadReport(IMAPSession *imap, int progress); + + // Print the message fetch status via debug port + void fetchReport(IMAPSession *imap, int progress, bool html); + + // Print the message search status via debug port + void searchReport(IMAPSession *imap, int progress); + + // Get current message num item + struct esp_mail_imap_msg_num_t cMSG(IMAPSession *imap); + + // Get current message Index + int cIdx(IMAPSession *imap); + + // Get IMAP response status e.g. OK, NO and Bad status enum value + esp_mail_imap_response_status imapResponseStatus(IMAPSession *imap, char *response, PGM_P tag); + + // Add header item to string buffer + void addHeaderItem(MB_String &str, esp_mail_message_header_t *header, bool json); + + // Get RFC822 header string pointer by index + int getRFC822HeaderPtr(int index, esp_mail_imap_rfc822_msg_header_item_t *header); + + // Add RFC822 headers to string buffer + void addRFC822Headers(MB_String &s, esp_mail_imap_rfc822_msg_header_item_t *header, bool json); + + // Add RFC822 header item to string buffer + void addRFC822HeaderItem(MB_String &s, esp_mail_imap_rfc822_msg_header_item_t *header, int index, bool json); + + // Add header string by name and value to string buffer + void addHeader(MB_String &s, const char *name, const char *s_value, int num_value, bool trim, bool isJson); + + // Save header string buffer to file + void saveHeader(IMAPSession *imap, bool json); + + // Send MIME stream to callback + void sendStreamCB(IMAPSession *imap, void *buf, size_t len, int chunkIndex, bool hrdBrk); + + // Prepare file path for saving + void prepareFilePath(IMAPSession *imap, MB_String &filePath, bool header); + + // Decode text and store it to buffer or file + void decodeText(IMAPSession *imap, esp_mail_imap_response_data &res); + + // Handle atachment parsing and download + bool parseAttachmentResponse(IMAPSession *imap, char *buf, esp_mail_imap_response_data &res); + + // Get List + char *getList(char *buf, bool &isList); + + // Parse mailbox folder open response + void parseFoldersResponse(IMAPSession *imap, char *buf, bool list); + + // Prepare alias (short name) file list for unsupported long file name filesystem + void prepareFileList(IMAPSession *imap, MB_String &filePath); + + // Parse capability response + bool parseCapabilityResponse(IMAPSession *imap, const char *buf, int &chunkIdx); + + // Parse Idle response + bool parseIdleResponse(IMAPSession *imap); + + // Append Fetch UID/Flags string to buffer + void appendFetchString(MB_String &buf, bool uid); + + // Parse command response + void parseCmdResponse(IMAPSession *imap, char *buf, PGM_P find); + + // Get flags + bool getFlags(IMAPSession *imap, char *buf, esp_mail_imap_response_types type); + + // Parse examine response + void parseExamineResponse(IMAPSession *imap, char *buf); + + // Handle the error by sending callback and close session + bool handleIMAPError(IMAPSession *imap, int err, bool ret); + + // Set Flag + bool mSetFlag(IMAPSession *imap, MB_StringPtr sequenceSet, MB_StringPtr flags, esp_mail_imap_store_flag_type type, bool closeSession, bool silent = false, bool UID = true, int32_t modsequence = -1); + +#endif +}; + +#if defined(ENABLE_IMAP) + +class IMAPSession +{ +public: + IMAPSession(Client *client); + IMAPSession(); + ~IMAPSession(); + + /** Set the tcp timeout. + * + * @param timeoutSec The tcp timeout in seconds. + */ + void setTCPTimeout(unsigned long timeoutSec); + + /** Assign custom Client from Arduino Clients. + * + * @param client The pointer to Arduino Client derived class e.g. WiFiClient, EthernetClient or GSMClient. + */ + void setClient(Client *client); + + /** Assign TinyGsm Clients. + * + * @param client The pointer to TinyGsmClient. + * @param modem The pointer to TinyGsm modem object. Modem should be initialized and/or set mode before transfering data. + * @param pin The SIM pin. + * @param apn The GPRS APN (Access Point Name). + * @param user The GPRS user. + * @param password The GPRS password. + */ + void setGSMClient(Client *client, void *modem, const char *pin, const char *apn, const char *user, const char *password); + + /** Assign the callback function to handle the network connection for custom Client. + * + * @param networkConnectionCB The function that handles the network connection. + */ + void networkConnectionRequestCallback(NetworkConnectionRequestCallback networkConnectionCB); + + /** Assign the callback function to handle the network connection status acknowledgement. + * + * @param networkStatusCB The function that handle the network connection status acknowledgement. + */ + void networkStatusRequestCallback(NetworkStatusRequestCallback networkStatusCB); + + /** Set the network status acknowledgement. + * + * @param status The network status. + */ + void setNetworkStatus(bool status); + + /** Set the BearSSL IO buffer size. + * + * @param rx The BearSSL receive buffer size in bytes. + * @param tx The BearSSL trasmit buffer size in bytes. + */ + void setSSLBufferSize(int rx = -1, int tx = -1); + + /** Begin the IMAP server connection. + * + * @param session_config The pointer to Session_Config structured data that keeps + * the server and log in details. + * @param imap_data The pointer to IMAP_Data structured data that keeps the + * operation options. + * @param login The bool option for login after server connection. + * @return The boolean value which indicates the success of operation. + */ + bool connect(Session_Config *session_config, IMAP_Data *imap_data, bool login = true); + + /** Log in to IMAP server using Email and password. + * + * @param email The IMAP server account email. + * @param password The IMAP server account password. + * @return The boolean value which indicates the success of operation. + */ + template + bool loginWithPassword(T1 email, T2 password) { return mLogin(toStringPtr(email), toStringPtr(password), false); }; + + /** Log in to IMAP server using Email and access token. + * + * @param email The IMAP server account email. + * @param token The Access token to log in. + * @return The boolean value which indicates the success of operation. + */ + template + bool loginWithAccessToken(T1 email, T2 token) { return mLogin(toStringPtr(email), toStringPtr(token), true); }; + + /** Send the client identification to the server + * + * @param identification The pointer to IMAP_Identification structured data that keeps + * the key properties e.g., name, version, os, os_version, vendor, support_url, address, + * date, command, arguments, and environment. + */ + bool id(IMAP_Identification *identification); + + /** Return the server ID returns from ID command. + * @return The server ID string. + */ + String serverID(); + + /** Return the SASL authentication status. + * @return The boolean value indicates SASL authentication status. + */ + bool isAuthenticated(); + + /** Return the log status. + * @return The boolean value log in status. + */ + bool isLoggedIn(); + + /** Return firmware update result when attachment filename matches. + * @return The boolean value indicates the firmware update status. + */ + bool isFirmwareUpdateSuccess(); + + /** Begin the IMAP server connection without authentication. + * + * @param session_config The pointer to Session_Config structured data that keeps + * the server and log in details. + * @param callback The callback function that accepts IMAP_Response as parameter. + * @param tag The tag that pass to the callback function. + * @return The boolean value indicates the success of operation. + */ + template + bool customConnect(Session_Config *session_config, imapResponseCallback callback, T tag = "") { return mCustomConnect(session_config, callback, toStringPtr(tag)); }; + + /** Close the IMAP session. + * + * @return The boolean value which indicates the success of operation. + */ + bool closeSession(); + + /** Get TCP connection status. + * + * @return The boolean value indicates the connection status. + */ + bool connected(); + + /** Set to enable the debug. + * + * @param level The level to enable the debug message + * level = 0, no debugging + * level = 1, basic level debugging + */ + void debug(int level); + + /** Get the list of all the mailbox folders since the TCP session was opened + * and user was authenticated. + * + * @param folders The FoldersCollection class that contains the collection of + * the + * FolderInfo structured data. + * @return The boolean value which indicates the success of operation. + */ + bool getFolders(FoldersCollection &folders); + + /** Select or open the mailbox folder to search or fetch the message inside. + * + * @param folderName The known mailbox folder name. The default name is INBOX. + * @param readOnly The option to open the mailbox for read only. Set this + * option to false when you wish + * to modify the Flags using the setFlag, addFlag and removeFlag functions. + * @return The boolean value which indicates the success of operation. + * + * @note: the function will exit immediately and return true if the time since previous success folder selection (open) + * with the same readOnly mode, is less than 5 seconds. + */ + template + bool selectFolder(T folderName, bool readOnly = true) { return mSelectFolder(toStringPtr(folderName), readOnly); } + + /** Open the mailbox folder to read or search the mesages. + * + * @param folderName The name of known mailbox folder to be opened. + * @param readOnly The option to open the mailbox for reading only. Set this + * option to false when you wish + * to modify the flags using the setFlag, addFlag and removeFlag functions. + * @return The boolean value which indicates the success of operation. + * + * @note: the function will exit immediately and return true if the time since previous success folder selection (open) + * with the same readOnly mode, is less than 5 seconds. + */ + template + bool openFolder(T folderName, bool readOnly = true) { return mOpenFolder(toStringPtr(folderName), readOnly); } + + /** Close the mailbox folder that was opened. + * + * @param expunge The option to allow emty the deleted flag set messages in case folder was open with editable mode. + * @return The boolean value which indicates the success of operation. + */ + bool closeFolder(bool expunge = false) { return mCloseFolder(expunge); } + + /** Create folder. + * + * @param folderName The name of folder to create. + * @return The boolean value which indicates the success of operation. + */ + template + bool createFolder(T folderName) { return mCreateFolder(toStringPtr(folderName)); } + + /** Rename folder. + * + * @param currentFolderName The name of folder to rename. + * @param newFolderName The new name of folder to rename. + * @return The boolean value which indicates the success of operation. + */ + template + bool renameFolder(T1 currentFolderName, T2 newFolderName) { return mRenameFolder(toStringPtr(currentFolderName), toStringPtr(newFolderName)); } + + /** Delete folder. + * + * @param folderName The name of folder to delete. + * @return The boolean value which indicates the success of operation. + */ + template + bool deleteFolder(T folderName) { return mDeleteFolder(toStringPtr(folderName)); } + + /** Get subscribes mailboxes. + * + * @param reference The reference name. + * @param mailbox The mailbox name with possible wildcards. + * @param folders The return FoldersCollection that contains the folder info e.g., name, attribute and delimiter. + * @return The boolean value which indicates the success of operation. + */ + template + bool getSubscribesMailboxes(T1 reference, T2 mailbox, FoldersCollection &folders) { return mGetSubscribesMailboxes(toStringPtr(reference), toStringPtr(mailbox), folders); } + + /** Subscribe mailbox. + * + * @param folderName The name of folder to subscribe. + * @return The boolean value which indicates the success of operation. + */ + template + bool subscribe(T folderName) { return mSubscribe(toStringPtr(folderName)); } + + /** Unsubscribe mailbox. + * + * @param folderName The name of folder to unsubscribe. + * @return The boolean value which indicates the success of operation. + */ + template + bool unSubscribe(T folderName) { return mUnSubscribe(toStringPtr(folderName)); } + + /** Get UID number in selected or opened mailbox. + * + * @param msgNum The message number or order in the total message numbers. + * @return UID number in selected or opened mailbox. + * + * @note Returns 0 when fail to get UID. + */ + int getUID(int msgNum); + + /** Get message flags in selected or opened mailbox. + * + * @param msgNum The message number or order in the total message numbers. + * @return Message flags in selected or opened mailbox. + * + * @note Returns empty string when fail to get flags. + */ + const char *getFlags(int msgNum); + + /** Send the custom IMAP command and get the result via callback. + * + * @param cmd The command string. + * @param callback The callback function that accepts IMAP_Response as parameter. + * @param tag The tag string to pass to the callback function. + * @return The boolean value which indicates the success of operation. + * + * @note imap.connect and imap.selectFolder or imap.openFolder are needed to call once prior to call this function. + */ + template + bool sendCustomCommand(T1 cmd, imapResponseCallback callback, T2 tag = "") { return mSendCustomCommand(toStringPtr(cmd), callback, toStringPtr(tag)); } + + /** Send the custom IMAP command data string. + * + * @param data The string data. + * @param last The flag represents the last data to send (optional). + * @return The boolean value which indicates the success of operation. + * + * @note Should be used after calling sendCustomCommand("APPEND xxxxxx"); + */ + template + bool sendCustomData(T data, bool lastData = false) { return mSendData(toStringPtr(data), lastData, esp_mail_imap_cmd_custom); } + + /** Send the custom IMAP command data. + * + * @param data The byte data. + * @param size The data size. + * @param lastData The flag represents the last data to send (optional). + * @return The boolean value which indicates the success of operation. + * + * @note Should be used after calling ssendCustomCommand("APPEND xxxxxx"); + */ + bool sendCustomData(uint8_t *data, size_t size, bool lastData = false) { return mSendData(data, size, lastData, esp_mail_imap_cmd_custom); } + + /** Copy the messages to the defined mailbox folder. + * + * @param toCopy The pointer to the MessageList class that contains the + * list of messages to copy. + * @param dest The destination folder that the messages to copy to. + * @return The boolean value which indicates the success of operation. + */ + template + bool copyMessages(MessageList *toCopy, T dest) { return mCopyMessages(toCopy, toStringPtr(dest)); } + + /** Copy the messages to the defined mailbox folder. + * + * @param sequenceSet The sequence set string i.g., unique identifier (UID) or message sequence number or ranges of UID or sequence number. + * @param UID The option for sequenceSet whether it is UID or message sequence number. + * @param dest The destination folder that the messages to copy to. + * @return The boolean value indicates the success of operation. + */ + template + bool copyMessages(T1 sequenceSet, bool UID, T2 dest) { return mCopyMessagesSet(toStringPtr(sequenceSet), UID, toStringPtr(dest)); } + + /** Move the messages to the defined mailbox folder. + * + * @param toMove The pointer to the MessageList class that contains the + * list of messages to move. + * @param dest The destination folder that the messages to move to. + * @return The boolean value which indicates the success of operation. + */ + template + bool moveMessages(MessageList *toCopy, T dest) { return mMoveMessages(toCopy, toStringPtr(dest)); } + + /** Move the messages to the defined mailbox folder. + * + * @param sequenceSet The sequence set string i.g., unique identifier (UID) or message sequence number or ranges of UID or sequence number. + * @param UID The option for sequenceSet whether it is UID or message sequence number. + * @param dest The destination folder that the messages to move to. + * @return The boolean value indicates the success of operation. + */ + template + bool moveMessages(T1 sequenceSet, bool UID, T2 dest) { return mMoveMessagesSet(toStringPtr(sequenceSet), UID, toStringPtr(dest)); } + + /** Delete the messages in the opened mailbox folder. + * + * @param toDelete The pointer to the MessageList class that contains the + * list of messages to delete. + * @param expunge The boolean option to expunge all messages. + * @param modsequence The int32_t option for UNCHANGESINCE conditional test. + * @return The boolean value which indicates the success of operation. + * + * The modsequence value can be used only if IMAP server supports Conditional STORE extension + * and the selected mailbox supports modsequences. + */ + bool deleteMessages(MessageList *toDelete, bool expunge = false, int32_t modsequence = -1) { return mDeleteMessages(toDelete, expunge, modsequence); } + + /** Delete the messages in the opened mailbox folder. + * + * @param sequenceSet The sequence set string i.g., unique identifier (UID) or message sequence number or ranges of UID or sequence number. + * @param UID The option for sequenceSet whether it is UID or message sequence number. + * @param expunge The boolean option to expunge all messages. + * @param modsequence The int32_t option for UNCHANGESINCE conditional test. + * @return The boolean value which indicates the success of operation. + * + * The modsequence value can be used only if IMAP server supports Conditional STORE extension + * and the selected mailbox supports modsequences. + */ + template + bool deleteMessages(T sequenceSet, bool UID, bool expunge = false, int32_t modsequence = -1) { return mDeleteMessagesSet(toStringPtr(sequenceSet), UID, expunge, modsequence); } + + /** Get the quota root's resource usage and limits. + * + * @param quotaRoot The quota root to get. + * @param info The pointer to IMAP_Quota_Root_Info that contains quota root's resource name, usage and limit. + * @return The boolean value which indicates the success of operation. + */ + template + bool getQuota(T quotaRoot, IMAP_Quota_Root_Info *info) { return mGetSetQuota(toStringPtr(quotaRoot), info, true); } + + /** Set the quota root's resource usage and limits. + * + * @param quotaRoot The quota root to set. + * @param data The pointer to IMAP_Quota_Root_Info that contains quota root's resource name, usage and limit. + * @return The boolean value which indicates the success of operation. + */ + template + bool setQuota(T quotaRoot, IMAP_Quota_Root_Info *data) { return mGetSetQuota(toStringPtr(quotaRoot), data, false); } + + /** Get the list of quota roots for the named mailbox. + * + * @param mailbox The mailbox name. + * @param quotaRootsList The pointer to IMAP_Quota_Roots_List that contains the list of IMAP_Quota_Root_Info. + * @return The boolean value which indicates the success of operation. + */ + template + bool getQuotaRoot(T mailbox, IMAP_Quota_Roots_List *quotaRootsList) { return mGetQuotaRoots(toStringPtr(mailbox), quotaRootsList); } + + /** Get the ACLs for a mailbox. + * + * @param mailbox The mailbox name. + * @param aclList The pointer to the returning IMAP_Rights_List object. + * @return The boolean value which indicates the success of operation. + */ + template + bool getACL(T mailbox, IMAP_Rights_List *aclList) { return mManageACL(toStringPtr(mailbox), aclList, nullptr, toStringPtr(""), esp_mail_imap_cmd_get_acl); }; + + /** Get the ACLs for a mailbox. + * + * @param mailbox The mailbox name. + * @param acl The pointer to the acl IMAP_Rights_Info to set. + * @return The boolean value which indicates the success of operation. + */ + template + bool setACL(T mailbox, IMAP_Rights_Info *acl) { return mManageACL(toStringPtr(mailbox), nullptr, acl, toStringPtr(""), esp_mail_imap_cmd_set_acl); }; + + /** Delete the ACLs set for identifier on mailbox. + * + * @param mailbox The mailbox name. + * @param identifier The identifier (user) to remove the rights. + * @return The boolean value which indicates the success of operation. + */ + template + bool deleteACL(T1 mailbox, T2 identifier) { return mManageACL(toStringPtr(mailbox), nullptr, nullptr, toStringPtr(identifier), esp_mail_imap_cmd_delete_acl); }; + + /** Show my ACLs for a mailbox. + * + * @param mailbox The mailbox name. + * @param acl The pointer to the returning IMAP_Rights_Info object. + * @return The boolean value which indicates the success of operation. + */ + template + bool myRights(T mailbox, IMAP_Rights_Info *acl) { return mManageACL(toStringPtr(mailbox), nullptr, acl, toStringPtr(""), esp_mail_imap_cmd_my_rights); }; + + /** Returns IMAP namespaces. + * + * @param mailbox The mailbox name. + * @param ns The pointer to the returning IMAP_Namespaces_List object. + * @return The boolean value which indicates the success of operation. + */ + bool getNamespace(IMAP_Namespaces_List *ns) { return mNamespace(ns); }; + + /** Enable IMAP capability. + * + * @param capability The mailbox name. + * @return The boolean value which indicates the success of operation. + */ + template + bool enable(T capability) { return mEnable(toStringPtr(capability)); }; + + /** Listen for the selected or open mailbox for updates. + * @return The boolean value which indicates the success of operation. + */ + bool listen() { return mListen(false); }; + + /** Stop listen for the mailbox for updates. + * @return The boolean value which indicates the success of operation. + */ + bool stopListen() { return mStopListen(false); }; + + /** Check for the selected or open mailbox updates. + * @return The boolean value which indicates the changes status of mailbox. + */ + bool folderChanged(); + + /** Send NOOP command to IMAP server. + * @return The boolean value which indicates the success of operation. + */ + bool noop(); + + /** Assign the callback function that returns the operating status when + * fetching or reading the Email. + * + * @param imapCallback The function that accepts the imapStatusCallback as + * parameter. + */ + void callback(imapStatusCallback imapCallback); + + /** Assign the callback function to decode the string based on the character set. + * + * @param callback The function that accepts the pointer to IMAP_Decoding_Info as parameter. + */ + void characterDecodingCallback(imapCharacterDecodingCallback callback); + + /** Assign the callback function that returns the MIME data stream from + * fetching or reading the Email. + * + * @param mimeDataStreamCallback The function that accepts the MIME_Stream_Info as + * parameter. + */ + void mimeDataStreamCallback(MIMEDataStreamCallback mimeDataStreamCallback); + + /** Determine if no message body contained in the search result and only the + * message header is available. + */ + bool headerOnly(); + + /** Get the message list from search or fetch the Emails + * + * @return The IMAP_MSG_List structured data which contains text and html + * contents, + * attachments, inline images, embedded rfc822 messages details for each + * message. + */ + IMAP_MSG_List data(); + + /** Get the details of the selected or opned mailbox folder + * + * @return The SelectedFolderInfo class which contains the info about flags, + * total messages, next UID, + * search count and the available messages count. + */ + SelectedFolderInfo selectedFolder(); + + /** Get the error details when readingg the Emails + * + * @return The string of error details. + */ + String errorReason(); + + /** Get the operating status error code. + * + * @return The int value of operating status error code. + * + * The negative value indicated error. + * See src/ESP_Mail_Error.h and extras/MB_FS.h + */ + int errorCode(); + + /** Clear all the cache data stored in the IMAP session object. + */ + void empty(); + + /** Get the status of message fetching and searching. + * + * @return The IMAP_Status object contains the fetching and searching statuses. + */ + IMAP_Status status(); + + /** Get the JSON string of file name list of files that stored in SD card. + * + * @return The JSON string of filenames. + * @note This will available only when standard SD library was used and file storage is SD. + */ + String fileList(); + + /** Set the current timestamp. + * + * @param ts The current timestamp. + * @param gmtOffset The GMT offset. + */ + void setSystemTime(time_t ts, float gmtOffset = 0); + + /** Setup TCP KeepAlive for internal TCP client. + * + * @param tcpKeepIdleSeconds lwIP TCP Keepalive idle in seconds. + * @param tcpKeepIntervalSeconds lwIP TCP Keepalive interval in seconds. + * @param tcpKeepCount lwIP TCP Keepalive count. + * + * For the TCP (KeepAlive) options, see https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/lwip.html#tcp-options. + * + * If value of one of these parameters is zero, the TCP KeepAlive will be disabled. + * + * You can check the server connecting status, by exexuting .connected() which will return true when connection to the server is still alive. + */ + void keepAlive(int tcpKeepIdleSeconds, int tcpKeepIntervalSeconds, int tcpKeepCount); + + /** Get TCP KeepAlive status. + * + * @return Boolean status of TCP KeepAlive. + */ + bool isKeepAlive(); + + friend class ESP_Mail_Client; + friend class foldderList; + +private: + // Log in to IMAP server + bool mLogin(MB_StringPtr email, MB_StringPtr password, bool isToken); + + // Clear message data + void clearMessageData(); + + // Check for valid UID or set wildcard * as UID + void checkUID(); + + // Check for valid saving file path or prepend / + void checkPath(); + + // Get message item by index + void getMessages(uint16_t messageIndex, struct esp_mail_imap_msg_item_t &msg); + + // Get RFC822 message item by index + void getRFC822Messages(uint16_t messageIndex, struct esp_mail_imap_msg_item_t &msg); + + // Close mailbox + bool closeMailbox(bool expunge = false); + + // Open mailbox + bool openMailbox(MB_StringPtr folder, esp_mail_imap_auth_mode mode, bool waitResponse, bool unselect); + + // Get folders list + bool getMailboxes(FoldersCollection &folders); + + // Get subscribes mailboxes + bool mGetSubscribesMailboxes(MB_StringPtr reference, MB_StringPtr mailbox, FoldersCollection &folders); + + // Subscribe the mailbox + bool mSubscribe(MB_StringPtr folder); + + // Unsubscribe the mailbox + bool mUnSubscribe(MB_StringPtr folder); + + // Get UID + int mGetUID(int msgNum); + + // Fetch by sequence set + bool mFetchSequenceSet(); + + // Return string from TAG prepended command + MB_String prependTag(PGM_P cmd, PGM_P tag = NULL); + + // Check capabilities + bool checkCapabilities(); + + // Listen mailbox changes + bool mListen(bool recon); + + // Stop listen mailbox + bool mStopListen(bool recon); + + // Send custom command + bool mSendCustomCommand(MB_StringPtr cmd, imapResponseCallback callback, MB_StringPtr tag); + + // Send data after sending APPEND command + bool mSendData(MB_StringPtr data, bool lastData, esp_mail_imap_command cmd); + + // Send data after sending APPEND command + bool mSendData(uint8_t *data, size_t size, bool lastData, esp_mail_imap_command cmd); + + // Delete folder + bool mDeleteFolder(MB_StringPtr folderName); + + // Create folder + bool mCreateFolder(MB_StringPtr folderName); + + // Rename folder + bool mRenameFolder(MB_StringPtr currentFolderName, MB_StringPtr newFolderName); + + // Copy message + bool copyMsg(MessageList *toCopy, const char *sequenceSet, bool UID, MB_StringPtr dest); + + // Copy message + bool mCopyMessages(MessageList *toCopy, MB_StringPtr dest); + + // Copy message using sequence set + bool mCopyMessagesSet(MB_StringPtr sequenceSet, bool UID, MB_StringPtr dest); + + // Move message + bool moveMsg(MessageList *toMove, const char *sequenceSet, bool UID, MB_StringPtr dest); + + // Move message + bool mMoveMessages(MessageList *toMove, MB_StringPtr dest); + + // Move message using sequence set + bool mMoveMessagesSet(MB_StringPtr sequenceSet, bool UID, MB_StringPtr dest); + + // Check for conditional STORE extention support + bool isCondStoreSupported(); + + // Check for mailbox mod-sequence support + bool isModseqSupported(); + + // add UNCHANGEDSINCE STORE modifier and CHANGEDSINCE FETCH modifier to command + void addModifier(MB_String &cmd, esp_mail_imap_command_types type, int32_t modsequence); + + // Delete message + bool deleteMsg(MessageList *toDelete, const char *sequenceSet, bool UID, bool expunge, int32_t modsequence = -1); + + // Delete messages + bool mDeleteMessages(MessageList *toDelete, bool expunge = false, int32_t modsequence = -1); + + // Delete messages + bool mDeleteMessagesSet(MB_StringPtr sequenceSet, bool UID, bool expunge = false, int32_t modsequence = -1); + + // Get or set the quota root's resource usage and limits. + bool mGetSetQuota(MB_StringPtr quotaRoot, IMAP_Quota_Root_Info *data, bool getMode); + + // Parse the IMAP_Quota_Root_info + void mParseQuota(const char *quota, IMAP_Quota_Root_Info *data); + + // Get the list of quota roots for the named mailbox. + bool mGetQuotaRoots(MB_StringPtr mailbox, IMAP_Quota_Roots_List *quotaRootsList); + + // Get or set ACL. + bool mManageACL(MB_StringPtr mailbox, IMAP_Rights_List *acl_list, IMAP_Rights_Info *acl, MB_StringPtr identifier, esp_mail_imap_command type); + + // Parse ACL + void parseACL(MB_String &acl_str, IMAP_Rights_List *right_list); + + // parse Rights + void parseRights(MB_String &righs_str, IMAP_Rights_Info *info); + + // Get Rights from IMAP_Rights_Info + void getRights(MB_String &righs_str, IMAP_Rights_Info *info); + + // Get namespace + bool mNamespace(IMAP_Namespaces_List *ns); + + // Enable the IMAP capability + bool mEnable(MB_StringPtr capability); + + // Parse namespaces + void parseNamespaces(MB_String &ns_str, IMAP_Namespaces *ns); + + // Close folder + bool mCloseFolder(bool expunge = false); + + // Open folder + bool mOpenFolder(MB_StringPtr folderName, bool readOnly); + + // Select folder + bool mSelectFolder(MB_StringPtr folderName, bool readOnly); + + // Custom TCP connection + bool mCustomConnect(Session_Config *session_config, imapResponseCallback callback, MB_StringPtr tag); + + // Append ID list to buffer + void appendIdList(MB_String &list, IMAP_Identification *identification); + + // Handle connection + bool handleConnection(Session_Config *session_config, IMAP_Data *imap_data, bool &ssl); + + // Start TCP connection + bool connect(bool &ssl); + + // Print features not supported debug error message + void printDebugNotSupported(); + + bool _sessionSSL = false; + bool _sessionLogin = false; + bool _loginStatus = false; + unsigned long _last_polling_error_ms = 0; + unsigned long _last_host_check_ms = 0; + unsigned long _last_server_connect_ms = 0; + unsigned long _last_network_error_ms = 0; + unsigned long tcpTimeout = TCP_CLIENT_DEFAULT_TCP_TIMEOUT_SEC; + struct esp_mail_imap_response_status_t _responseStatus; + int _cMsgIdx = 0; + int _cPartIdx = 0; + int _totalRead = 0; + _vectorImpl _headers; + + esp_mail_imap_command _imap_cmd = esp_mail_imap_command::esp_mail_imap_cmd_sasl_login; + esp_mail_imap_command _prev_imap_cmd = esp_mail_imap_command::esp_mail_imap_cmd_sasl_login; + esp_mail_imap_command _imap_custom_cmd = esp_mail_imap_cmd_custom; + esp_mail_imap_command _prev_imap_custom_cmd = esp_mail_imap_cmd_custom; + bool _idle = false; + MB_String _cmd; + _vectorImpl _multipart_levels; + int _rfc822_part_count = 0; + bool _unseen = false; + bool _readOnlyMode = true; + bool _msgDownload = false; + bool _attDownload = false; + bool _storageReady = false; + bool _storageChecked = false; + + bool _auth_capability[esp_mail_auth_capability_maxType]; + bool _feature_capability[esp_mail_imap_read_capability_maxType]; + Session_Config *_session_cfg; + _vectorImpl _configPtrList; + MB_String _currentFolder; + bool _mailboxOpened = false; + unsigned long _lastSameFolderOpenMillis = 0; + MB_String _nextUID; + MB_String _unseenMsgIndex; + MB_String _flags_tmp; + MB_String _quota_tmp; + MB_String _quota_root_tmp; + MB_String _acl_tmp; + MB_String _ns_tmp; + MB_String _server_id_tmp; + MB_String _sdFileList; + + struct esp_mail_imap_data_config_t *_imap_data = nullptr; + + int _userHeaderOnly = -1; + bool _headerOnly = true; + bool _uidSearch = false; + bool _headerSaved = false; + bool _debug = false; + int _debugLevel = 0; + bool _secure = false; + bool _authenticated = false; + bool _isFirmwareUpdated = false; + imapStatusCallback _statusCallback = NULL; + imapResponseCallback _customCmdResCallback = NULL; + MIMEDataStreamCallback _mimeDataStreamCallback = NULL; + imapCharacterDecodingCallback _charDecCallback = NULL; + + _vectorImpl _imap_msg_num; + esp_mail_session_type _sessionType = esp_mail_session_type_imap; + + FoldersCollection _folders; + SelectedFolderInfo _mbif; + int _uid_tmp = 0; + int _lastProgress = -1; + + ESP_Mail_TCPClient client; + + IMAP_Status _cbData; +}; + +#endif + +#if defined(ENABLE_SMTP) + +class SendingResult +{ +private: + _vectorImpl _result; + + void add(SMTP_Result *r) + { + _result.push_back(*r); + } + +public: + friend class SMTPSession; + friend class ESP_Mail_Client; + SendingResult(){}; + ~SendingResult() { clear(); }; + + void clear() + { + for (size_t i = 0; i < _result.size(); i++) + { + _result[i].recipients.clear(); + _result[i].subject.clear(); + _result[i].timestamp = 0; + _result[i].completed = false; + } + _result.clear(); + } + + SMTP_Result getItem(size_t index) + { + SMTP_Result r; + if (index < _result.size()) + return _result[index]; + return r; + } + size_t size() { return _result.size(); }; +}; + +class SMTPSession +{ +public: + SMTPSession(Client *client); + SMTPSession(); + ~SMTPSession(); + + /** Set the tcp timeout. + * + * @param timeoutSec The tcp timeout in seconds. + */ + void setTCPTimeout(unsigned long timeoutSec); + + /** Assign custom Client from Arduino Clients. + * + * @param client The pointer to Arduino Client derived class e.g. WiFiClient, EthernetClient or GSMClient. + */ + void setClient(Client *client); + + /** Assign TinyGsm Clients. + * + * @param client The pointer to TinyGsmClient. + * @param modem The pointer to TinyGsm modem object. Modem should be initialized and/or set mode before transfering data. + * @param pin The SIM pin. + * @param apn The GPRS APN (Access Point Name). + * @param user The GPRS user. + * @param password The GPRS password. + */ + void setGSMClient(Client *client, void *modem, const char *pin, const char *apn, const char *user, const char *password); + + /** Assign the callback function to handle the network connection for custom Client. + * + * @param networkConnectionCB The function that handles the network connection. + */ + void networkConnectionRequestCallback(NetworkConnectionRequestCallback networkConnectionCB); + + /** Assign the callback function to handle the network connection status acknowledgement. + * + * @param networkStatusCB The function that handle the network connection status acknowledgement. + */ + void networkStatusRequestCallback(NetworkStatusRequestCallback networkStatusCB); + + /** Set the network status acknowledgement. + * + * @param status The network status. + */ + void setNetworkStatus(bool status); + + /** Set the BearSSL IO buffer size. + * + * @param rx The BearSSL receive buffer size in bytes. + * @param tx The BearSSL trasmit buffer size in bytes. + */ + void setSSLBufferSize(int rx = -1, int tx = -1); + + /** Begin the SMTP server connection. + * + * @param session_config The pointer to Session_Config structured data that keeps + * the server and log in details. + * @param login The bool option for login after server connection. + * @return The boolean value indicates the success of operation. + */ + bool connect(Session_Config *session_config, bool login = true); + + /** Log in to SMTP server using Email and password. + * + * @param email The SMTP server account email. + * @param password The SMTP server account password. + * @return The boolean value which indicates the success of operation. + */ + template + bool loginWithPassword(T1 email, T2 password) { return mLogin(toStringPtr(email), toStringPtr(password), false); }; + + /** Log in to SMTP server using Email and access token. + * + * @param email The SMTP server account email. + * @param token The Access token to log in. + * @return The boolean value which indicates the success of operation. + */ + template + bool loginWithAccessToken(T1 email, T2 token) { return mLogin(toStringPtr(email), toStringPtr(token), true); }; + + /** Return the SASL authentication status. + * @return The boolean value indicates SASL authentication status. + */ + bool isAuthenticated(); + + /** Return the log status. + * @return The boolean value indicates log in status. + */ + bool isLoggedIn(); + + /** Begin the SMTP server connection without authentication. + * + * @param session_config The pointer to Session_Config structured data that keeps + * the server and log in details. + * @param callback The callback function that accepts the SMTP_Response as parameter. + * @param commandID The command identifier number that will pass to the callback. + * @return The int value of status code. + * + * @note If commandID was not set or set to -1, the command identifier will be auto increased started from zero. + */ + int customConnect(Session_Config *session_config, smtpResponseCallback callback, int commandID = -1); + + /** Close the SMTP session. + * + */ + bool closeSession(); + + /** Get TCP connection status. + * + * @return The boolean value indicates the connection status. + */ + bool connected(); + + /** Send the custom SMTP command and get the result via callback. + * + * @param cmd The command string. + * @param callback The function that accepts the SMTP_Response as parameter. + * @param commandID The command identifier number that will pass to the callback. + * @return The integer value of response code. + * + * @note smtp.connect or smtp.customConnect is needed to call once prior to call this function. + * + * If commandID was not set or set to -1, the command identifier will be auto increased started from zero. + */ + template + int sendCustomCommand(T cmd, smtpResponseCallback callback, int commandID = -1) { return mSendCustomCommand(toStringPtr(cmd), callback, commandID); } + + /** Send the custom SMTP command data string. + * + * @param data The string data. + * @return The boolean value which indicates the success of operation. + * + * @note Should be used after calling sendCustomCommand("DATA"); + */ + template + bool sendCustomData(T data) { return mSendData(toStringPtr(data)); } + + /** Send the custom SMTP command data. + * + * @param data The byte data. + * @param size The data size. + * @return The boolean value which indicates the success of operation. + * + * @note Should be used after calling sendCustomCommand("DATA"); + */ + bool sendCustomData(uint8_t *data, size_t size) { return mSendData(data, size); } + + /** Set to enable the debug. + * + * @param level The level to enable the debug message + * level = 0, no debugging + * level = 1, basic level debugging + */ + void debug(int level); + + /** Get the error details when sending the Email + * + * @return The string of error details. + */ + String errorReason(); + + /** Get the SMTP server response status code. + * + * @return The int value of SMTP server response status code. + * + * See RFC 5321 standard's documentation. + */ + int statusCode(); + + /** Get the SMTP server response status message. + * + * @return The int value of SMTP server response status message. + * + */ + String statusMessage(); + + /** Get the operating status error code. + * + * @return The int value of operating status error code. + * + * The negative value indicated error. + * See src/ESP_Mail_Error.h and extras/MB_FS.h + */ + int errorCode(); + + /** Set the Email sending status callback function. + * + * @param smtpCallback The callback function that accept the + * smtpStatusCallback param. + */ + void callback(smtpStatusCallback smtpCallback); + + /** Get the status of message fetching and searching. + * + * @return The SMTP_Status object contains the sending status. + */ + SMTP_Status status(); + + /** Set the current timestamp. + * + * @param ts The current timestamp. + * @param gmtOffset The GMT offset. + */ + void setSystemTime(time_t ts, float gmtOffset = 0); + + /** Setup TCP KeepAlive for internal TCP client. + * + * @param tcpKeepIdleSeconds lwIP TCP Keepalive idle in seconds. + * @param tcpKeepIntervalSeconds lwIP TCP Keepalive interval in seconds. + * @param tcpKeepCount lwIP TCP Keepalive count. + * + * For the TCP (KeepAlive) options, see https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/lwip.html#tcp-options. + * + * If value of one of these parameters is zero, the TCP KeepAlive will be disabled. + * + * You can check the server connecting status, by exexuting .connected() which will return true when connection to the server is still alive. + */ + void keepAlive(int tcpKeepIdleSeconds, int tcpKeepIntervalSeconds, int tcpKeepCount); + + /** Get TCP KeepAlive status. + * + * @return Boolean status of TCP KeepAlive. + */ + bool isKeepAlive(); + + SendingResult sendingResult; + + friend class ESP_Mail_Client; + +private: + bool _sessionSSL = false; + bool _sessionLogin = false; + struct esp_mail_smtp_response_status_t _responseStatus; + int _sentSuccessCount = 0; + int _sentFailedCount = 0; + bool _chunkedEnable = false; + int _chunkCount = 0; + uint32_t ts = 0; + unsigned long tcpTimeout = TCP_CLIENT_DEFAULT_TCP_TIMEOUT_SEC; + + esp_mail_smtp_command _smtp_cmd = esp_mail_smtp_command::esp_mail_smtp_cmd_greeting; + + bool _auth_capability[esp_mail_auth_capability_maxType]; + bool _feature_capability[esp_mail_smtp_send_capability_maxType]; + + Session_Config *_session_cfg = NULL; + _vectorImpl _configPtrList; + + bool _debug = false; + int _debugLevel = 0; + bool _secure = false; + bool _authenticated = false; + bool _loginStatus = false; + bool _waitForAuthenticate = false; + bool _canForward = false; + smtpStatusCallback _statusCallback = NULL; + smtpResponseCallback _customCmdResCallback = NULL; + int _commandID = -1; + bool _sdStorageReady = false; + bool _flashStorageReady = false; + bool _sdStorageChecked = false; + bool _flashStorageChecked = false; + + esp_mail_session_type _sessionType = esp_mail_session_type_smtp; + SMTP_Status _cbData; + struct esp_mail_smtp_msg_type_t _msgType; + int _lastProgress = -1; + + ESP_Mail_TCPClient client; + + // Start TCP connection + bool connect(bool &ssl); + + // Log in to SMTP server + bool mLogin(MB_StringPtr email, MB_StringPtr password, bool isToken); + + // Handle TCP connection + bool handleConnection(Session_Config *session_config, bool &ssl); + + // Send custom command + int mSendCustomCommand(MB_StringPtr cmd, smtpResponseCallback callback, int commandID = -1); + + // Send data after sending DATA command + bool mSendData(MB_StringPtr data); + + // Send data after sending DATA command + bool mSendData(uint8_t *data, size_t size); +}; + +#endif + +#if defined(ENABLE_SMTP) && defined(ENABLE_IMAP) + +class ESP_Mail_Message : public SMTP_Message +{ +public: + ESP_Mail_Message(){}; + ~ESP_Mail_Message(){}; +}; + +#endif + +extern ESP_Mail_Client MailClient; + +#endif /* ESP_MAIL_CLIENT_H */ diff --git a/lib/libesp32/ESP-Mail-Client/src/ESP_Mail_Client_Version.h b/lib/libesp32/ESP-Mail-Client/src/ESP_Mail_Client_Version.h new file mode 100644 index 000000000..21cd038f6 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/ESP_Mail_Client_Version.h @@ -0,0 +1,12 @@ + +#pragma once + +#ifndef ESP_MAIL_VERSION + +#define ESP_MAIL_VERSION "3.4.9" +#define ESP_MAIL_VERSION_NUM 30409 + +/* The inconsistent file version checking to prevent mixed versions compilation. */ +#define VALID_VERSION_CHECK(ver) (ver == ESP_MAIL_VERSION_NUM) + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/ESP_Mail_Const.h b/lib/libesp32/ESP-Mail-Client/src/ESP_Mail_Const.h new file mode 100644 index 000000000..195ab0b11 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/ESP_Mail_Const.h @@ -0,0 +1,3492 @@ +// Created August 20, 2023 + +#pragma once + +#ifndef ESP_MAIL_CONST_H +#define ESP_MAIL_CONST_H + +#include "ESP_Mail_Client_Version.h" +#if !VALID_VERSION_CHECK(30409) +#error "Mixed versions compilation." +#endif + +#include +#include "ESP_Mail_FS.h" +#include "ESP_Mail_Error.h" +#include "extras/MB_FS.h" +#include "extras/RFC2047.h" +#include +#include + +#if defined(ESP_MAIL_DEBUG_PORT) +#define ESP_MAIL_DEFAULT_DEBUG_PORT ESP_MAIL_DEBUG_PORT +#else +#define ESP_MAIL_DEFAULT_DEBUG_PORT Serial +#endif + +#include +#include + +#define _vectorImpl std::vector +#define MB_VECTOR std::vector + +#if !defined(FPSTR) +#define FPSTR +#endif + +#include "extras/Networks_Provider.h" +#include "extras/ESP8266_Supports.h" + +#if defined(ESP8266) +#if __has_include() +#include +#endif +#endif + +#if defined(ENABLE_IMAP) && (defined(ESP32) || defined(ESP8266) || defined(MB_ARDUINO_PICO)) +#if defined(ESP32) +#include +#elif defined(ESP8266) || defined(MB_ARDUINO_PICO) +#include +#endif +#define ESP_MAIL_OTA_UPDATE_ENABLED +#endif + +#if !defined(SILENT_MODE) && (defined(ENABLE_SMTP) || defined(ENABLE_IMAP)) +#define SESSION_DEBUG_ENABLED +#endif + +#define TCP_CLIENT_DEFAULT_TCP_TIMEOUT_SEC 30 + +#if defined(ENABLE_SMTP) || defined(ENABLE_IMAP) + +#define MAX_EMAIL_SEARCH_LIMIT 1000 +#define BASE64_CHUNKED_LEN 76 +#define FLOWED_TEXT_LEN 78 +#define QP_ENC_MSG_LEN 76 +#define ESP_MAIL_NETWORK_RECONNECT_TIMEOUT 10000 +#define ESP_MAIL_PROGRESS_REPORT_STEP 5 +#define ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED 0 +#define ESP_MAIL_CLIENT_STREAM_CHUNK_SIZE 256 +#define ESP_MAIL_CLIENT_RESPONSE_BUFFER_SIZE 1024 // should be 1 k or more to prevent buffer overflow +#define ESP_MAIL_CLIENT_VALID_TS 1577836800 + +#endif + +typedef enum +{ + esp_mail_cert_type_undefined = -1, + esp_mail_cert_type_none = 0, + esp_mail_cert_type_data, + esp_mail_cert_type_file, + esp_mail_cert_type_bundle + +} esp_mail_cert_type; + +typedef enum +{ + esp_mail_client_type_undefined, + esp_mail_client_type_internal_basic_client, + esp_mail_client_type_external_basic_client, + esp_mail_client_type_external_gsm_client + +} esp_mail_client_type; + +/* The filesystem types enum */ +enum esp_mail_file_storage_type +{ + esp_mail_file_storage_type_none, + esp_mail_file_storage_type_flash, + esp_mail_file_storage_type_sd +}; + +/* The session types enum */ +enum esp_mail_session_type +{ + esp_mail_session_type_smtp, + esp_mail_session_type_imap +}; + +/* The secure connection mode preference */ +typedef enum +{ + // No preferences + esp_mail_secure_mode_undefined = 0, + // Always use SSL and TLS via STARTTLS rfc2595 section 3 and rfc3207 + esp_mail_secure_mode_ssl_tls, + // Plain text mode only (non SSL/TLS) + // To disable SSL/TLS permanently, define ESP_MAIL_DISABLE_SSL in ESP_Mail_FS.h + esp_mail_secure_mode_nonsecure + +} esp_mail_secure_mode; + +using namespace mb_string; + +#if defined(ENABLE_SMTP) || defined(ENABLE_IMAP) + +typedef void (*NetworkConnectionHandler)(void); + +/* The file types enum */ +enum esp_mail_file_extension +{ + /** The arrangement is related to mimeinfo struct. + * Do not modify or remove. + */ + esp_mail_file_extension_html, + esp_mail_file_extension_htm, + esp_mail_file_extension_css, + esp_mail_file_extension_txt, + esp_mail_file_extension_js, + esp_mail_file_extension_json, + esp_mail_file_extension_png, + esp_mail_file_extension_gif, + esp_mail_file_extension_jpg, + esp_mail_file_extension_ico, + esp_mail_file_extension_svg, + esp_mail_file_extension_ttf, + esp_mail_file_extension_otf, + esp_mail_file_extension_woff, + esp_mail_file_extension_woff2, + esp_mail_file_extension_eot, + esp_mail_file_extension_sfnt, + esp_mail_file_extension_xml, + esp_mail_file_extension_pdf, + esp_mail_file_extension_zip, + esp_mail_file_extension_gz, + esp_mail_file_extension_appcache, + esp_mail_file_extension_dat, + esp_mail_file_extension_binary, + esp_mail_file_extension_maxType +}; + +struct esp_mail_mime_prop_t +{ + char endsWith[10]; + char mimeType[30]; +}; + +const struct esp_mail_mime_prop_t mimeinfo[esp_mail_file_extension_maxType] PROGMEM = { + /** The arrangement is related to esp_mail_file_extension enum. + * Do not modify or remove. + */ + {".html", "text/html"}, + {".htm", "text/html"}, + {".css", "text/css"}, + {".txt", "text/plain"}, + {".js", "application/javascript"}, + {".json", "application/json"}, + {".png", "image/png"}, + {".gif", "image/gif"}, + {".jpg", "image/jpeg"}, + {".ico", "image/x-icon"}, + {".svg", "image/svg+xml"}, + {".ttf", "application/x-font-ttf"}, + {".otf", "application/x-font-opentype"}, + {".woff", "application/font-woff"}, + {".woff2", "application/font-woff2"}, + {".eot", "application/vnd.ms-fontobject"}, + {".sfnt", "application/font-sfnt"}, + {".xml", "text/xml"}, + {".pdf", "application/pdf"}, + {".zip", "application/zip"}, + {".gz", "application/x-gzip"}, + {".appcache", "text/cache-manifest"}, + {".dat", "application/dat"}, + {"", "application/octet-stream"}}; + +#if defined(ENABLE_SMTP) + +/* The SMTP commands types enum */ +enum esp_mail_smtp_command_types +{ + /** The SMTP commands per stansards. + * The arrangement is related to smtp_commands struct. + * Do not modify or remove. + */ + esp_mail_smtp_command_auth, + esp_mail_smtp_command_login, + esp_mail_smtp_command_helo, + esp_mail_smtp_command_ehlo, + esp_mail_smtp_command_quit, + esp_mail_smtp_command_mail, + esp_mail_smtp_command_rcpt, + esp_mail_smtp_command_data, + esp_mail_smtp_command_bdat, + esp_mail_smtp_command_last, + esp_mail_smtp_command_plain, + esp_mail_smtp_command_from, + esp_mail_smtp_command_to, + esp_mail_smtp_command_notify, + esp_mail_smtp_command_success, + esp_mail_smtp_command_failure, + esp_mail_smtp_command_delay, + esp_mail_smtp_command_body, + esp_mail_smtp_command_terminate, + esp_mail_smtp_command_starttls, + esp_mail_smtp_command_maxType +}; + +/* The SMTP server capability types enum (except for SASL) */ +enum esp_mail_smtp_send_capability_types +{ + /** The server capability keywords per standard. + * The arrangement is related to smtp_send_capabilities struct. + * Do not modify or remove. + */ + esp_mail_smtp_send_capability_binary_mime, + esp_mail_smtp_send_capability_8bit_mime, + esp_mail_smtp_send_capability_chunking, + esp_mail_smtp_send_capability_utf8, + esp_mail_smtp_send_capability_pipelining, + esp_mail_smtp_send_capability_dsn, + esp_mail_smtp_send_capability_esmtp, + esp_mail_smtp_send_capability_maxType +}; + +#endif + +#if defined(ENABLE_IMAP) + +/* The IMAP server response types enum */ +enum esp_mail_imap_response_types +{ + /** The IMAP response. + * The arrangement is related to imap_responses struct. + * Do not modify or remove. + */ + esp_mail_imap_response_ok, + esp_mail_imap_response_no, + esp_mail_imap_response_bad, + esp_mail_imap_response_list, + esp_mail_imap_response_flags, + esp_mail_imap_response_search, + esp_mail_imap_response_fetch, + esp_mail_imap_response_nil, + esp_mail_imap_response_uid, + esp_mail_imap_response_capability_untagged, + esp_mail_imap_response_capability, + esp_mail_imap_response_lsub, + esp_mail_imap_response_quota, + esp_mail_imap_response_quotaroot, + esp_mail_imap_response_acl, + esp_mail_imap_response_myrights, + esp_mail_imap_response_namespace, + esp_mail_imap_response_untagged, + esp_mail_imap_response_exists, + esp_mail_imap_response_expunge, + esp_mail_imap_response_recent, + esp_mail_imap_response_uidnext, + esp_mail_imap_response_unseen, + esp_mail_imap_response_id, + esp_mail_imap_response_highest_modsec, + esp_mail_imap_response_nomodsec, + esp_mail_imap_response_permanent_flags, + esp_mail_imap_response_uidvalidity, + esp_mail_imap_response_maxType +}; + +/* The IMAP commands types enum */ +enum esp_mail_imap_command_types +{ + /** The IMAP commands per standards. + * The arrangement is related to imap_commands struct. + * Do not modify or remove. + */ + esp_mail_imap_command_starttls, + esp_mail_imap_command_append, + esp_mail_imap_command_capability, + esp_mail_imap_command_authenticate, + esp_mail_imap_command_plain, + esp_mail_imap_command_uid, + esp_mail_imap_command_fetch, + esp_mail_imap_command_flags, + esp_mail_imap_command_login, + esp_mail_imap_command_list, + esp_mail_imap_command_examine, + esp_mail_imap_command_search, + esp_mail_imap_command_logout, + esp_mail_imap_command_body, + esp_mail_imap_command_mime, + esp_mail_imap_command_close, + esp_mail_imap_command_exists, + esp_mail_imap_command_peek, + esp_mail_imap_command_text, + esp_mail_imap_command_fields, + esp_mail_imap_command_header, + esp_mail_imap_command_new, + esp_mail_imap_command_all, + esp_mail_imap_command_select, + esp_mail_imap_command_expunge, + esp_mail_imap_command_create, + esp_mail_imap_command_delete, + esp_mail_imap_command_idle, + esp_mail_imap_command_done, + esp_mail_imap_command_recent, + esp_mail_imap_command_unseen, + esp_mail_imap_command_rename, + esp_mail_imap_command_lsub, + esp_mail_imap_command_subscribe, + esp_mail_imap_command_unsubscribe, + esp_mail_imap_command_silent, + esp_mail_imap_command_move, + esp_mail_imap_command_getquota, + esp_mail_imap_command_setquota, + esp_mail_imap_command_root, + esp_mail_imap_command_get_acl, + esp_mail_imap_command_set_acl, + esp_mail_imap_command_delete_acl, + esp_mail_imap_command_myrights, + esp_mail_imap_command_namespace, + esp_mail_imap_command_enable, + esp_mail_imap_command_xoauth2, + esp_mail_imap_command_store, + esp_mail_imap_command_plus_flags, + esp_mail_imap_command_minus_flags, + esp_mail_imap_command_copy, + esp_mail_imap_command_id, + esp_mail_imap_command_unselect, + esp_mail_imap_command_condstore, + esp_mail_imap_command_noop, + esp_mail_imap_command_unchangedsince, + esp_mail_imap_command_changedsince, + esp_mail_imap_command_modsec, + esp_mail_imap_command_maxType +}; + +/* The IMAP server capability types enum (except for SASL) */ +enum esp_mail_imap_read_capability_types +{ + /** The server capability keywords per standard. + * The arrangement is related imap_read_capabilities struct. + * Do not modify or remove. + */ + + esp_mail_imap_read_capability_imap4, + esp_mail_imap_read_capability_imap4rev1, + // rfc2177 + esp_mail_imap_read_capability_idle, + esp_mail_imap_read_capability_literal_plus, + esp_mail_imap_read_capability_literal_minus, + esp_mail_imap_read_capability_multiappend, + esp_mail_imap_read_capability_uidplus, + // rfc4314 + esp_mail_imap_read_capability_acl, + esp_mail_imap_read_capability_binary, + esp_mail_imap_read_capability_logindisable, + // rfc6851 + esp_mail_imap_read_capability_move, + // rfc2087 + esp_mail_imap_read_capability_quota, + // rfc2342 + esp_mail_imap_read_capability_namespace, + // rfc5161 + esp_mail_imap_read_capability_enable, + // rfc2971 + esp_mail_imap_read_capability_id, + esp_mail_imap_read_capability_unselect, + esp_mail_imap_read_capability_children, + // rfc7162 (rfc4551 obsoleted) + esp_mail_imap_read_capability_condstore, + esp_mail_imap_read_capability_auto_caps, + esp_mail_imap_read_capability_maxType +}; + +/* The Identification keys enum used for IMAP ID command */ +enum esp_mail_imap_identification_keys +{ + /** The identification keys per standard. + * The arrangement is related imap_identification_keys struct. + * Do not modify or remove. + */ + + esp_mail_imap_identification_key_name, + esp_mail_imap_identification_key_version, + esp_mail_imap_identification_key_os, + esp_mail_imap_identification_key_os_version, + esp_mail_imap_identification_key_vendor, + esp_mail_imap_identification_key_support_url, + esp_mail_imap_identification_key_address, + esp_mail_imap_identification_key_date, + esp_mail_imap_identification_key_command, + esp_mail_imap_identification_key_arguments, + esp_mail_imap_identification_key_environment, + esp_mail_imap_identification_key_maxType +}; + +#endif + +/* The character encoding types enum used for decoding */ +enum esp_mail_char_decoding_types +{ + /** Supported charactor encodings. + * The arrangement is related to char_decodings struct. + * Do not modify or remove. + */ + esp_mail_char_decoding_utf8, + esp_mail_char_decoding_iso_8859_1, + esp_mail_char_decoding_iso_8859_11, + esp_mail_char_decoding_tis_620, + esp_mail_char_decoding_windows_874, + esp_mail_char_decoding_maxType +}; + +/* The MIME multipart message types */ +enum esp_mail_multipart_types +{ + /** MultiPart MIME. + * The arrangement is related to multipart_types struct. + * Do not modify or remove. + */ + esp_mail_multipart_type_mixed, + esp_mail_multipart_type_related, + esp_mail_multipart_type_parallel, + esp_mail_multipart_type_alternative, + esp_mail_multipart_maxType +}; + +/* The rfc822 message header fileds types enum */ +enum esp_mail_rfc822_header_field_types +{ + /** The rfc822 message header fields. + * The arrangement is related to rfc822_headers struct. + * Do not modify or remove. + */ + esp_mail_rfc822_header_field_from, + esp_mail_rfc822_header_field_sender, + esp_mail_rfc822_header_field_to, + esp_mail_rfc822_header_field_cc, + esp_mail_rfc822_header_field_subject, + esp_mail_rfc822_header_field_date, + esp_mail_rfc822_header_field_msg_id, + esp_mail_rfc822_header_field_return_path, + esp_mail_rfc822_header_field_reply_to, + esp_mail_rfc822_header_field_in_reply_to, + esp_mail_rfc822_header_field_references, + esp_mail_rfc822_header_field_comments, + esp_mail_rfc822_header_field_keywords, + esp_mail_rfc822_header_field_bcc, + esp_mail_rfc822_header_field_flags, + esp_mail_rfc822_header_field_maxType +}; + +/* The message header fileds types enum and its subproperties enum */ +enum esp_mail_message_header_field_types +{ + /** Additional fields and props. + * Some are used for the library information data field name. + * The arrangement is related to message_headers struct. + * Do not modify or remove. + */ + esp_mail_message_header_field_number, + esp_mail_message_header_field_uid, + esp_mail_message_header_field_accept_language, + esp_mail_message_header_field_content_language, + esp_mail_message_header_field_filename, + esp_mail_message_header_field_name, + esp_mail_message_header_field_size, + esp_mail_message_header_field_mime, + esp_mail_message_header_field_type, + esp_mail_message_header_field_description, + esp_mail_message_header_field_creation_date, + esp_mail_message_header_field_x_priority, + esp_mail_message_header_field_x_msmail_priority, + esp_mail_message_header_field_importance, + esp_mail_message_header_field_content_type, + esp_mail_message_header_field_content_transfer_encoding, + esp_mail_message_header_field_content_disposition, + esp_mail_message_header_field_content_location, + esp_mail_message_header_field_content_id, + esp_mail_message_header_field_content_description, + esp_mail_message_header_field_mime_version, + esp_mail_message_header_field_charset, + esp_mail_message_header_field_format, + esp_mail_message_header_field_delsp, + esp_mail_message_header_field_modification_date, + esp_mail_message_header_field_maxType +}; + +/* The auth capability types enum which shared usage between SMTP and IMAP */ +enum esp_mail_auth_capability_types +{ + /** The server capability keywords per standard. + * The arrangement is related to smtp_auth_capabilities and imap_auth_capabilities structs. + * Do not modify or remove. + */ + + esp_mail_auth_capability_plain, + esp_mail_auth_capability_xoauth2, + esp_mail_auth_capability_cram_md5, + esp_mail_auth_capability_digest_md5, + esp_mail_auth_capability_login, + esp_mail_auth_capability_starttls, + // imap rfc4959 + esp_mail_auth_capability_sasl_ir, + + esp_mail_auth_capability_maxType, +}; + +/* The smessage types enum */ +enum esp_mail_message_type +{ + esp_mail_msg_type_none = 0, + esp_mail_msg_type_plain = 1, + esp_mail_msg_type_html = 2, + esp_mail_msg_type_enriched = 1 +}; + +/* The string mark types enum used in joinStringx functions */ +enum esp_mail_string_mark_type +{ + esp_mail_string_mark_type_none, + esp_mail_string_mark_type_double_quote, + esp_mail_string_mark_type_angle_bracket, + esp_mail_string_mark_type_round_bracket, + esp_mail_string_mark_type_curly_bracket, + esp_mail_string_mark_type_square_bracket +}; + +/* The debug TAG types enum */ +enum esp_mail_debug_tag_type +{ + esp_mail_debug_tag_type_client, + esp_mail_debug_tag_type_server, + esp_mail_debug_tag_type_error, + esp_mail_debug_tag_type_info, + esp_mail_debug_tag_type_warning +}; + +/* The embed attachment types enum */ +enum esp_mail_smtp_embed_message_type +{ + esp_mail_smtp_embed_message_type_attachment = 0, + esp_mail_smtp_embed_message_type_inline +}; + +/* The attachment types enum */ +enum esp_mail_attach_type +{ + esp_mail_att_type_none, + esp_mail_att_type_attachment, + esp_mail_att_type_inline +}; + +/* The debug levels for printing the debug information via Serial port */ +enum esp_mail_debug_level +{ + esp_mail_debug_level_none = 0, + esp_mail_debug_level_basic, + esp_mail_debug_level_maintainer = 0xfff, + esp_mail_debug_level_developer = esp_mail_debug_level_maintainer + 1 +}; + +/* The content transfer encoding enum */ +enum esp_mail_msg_xencoding +{ + esp_mail_msg_xencoding_none, + /* rfc2045 section 2.7 */ + esp_mail_msg_xencoding_7bit, + esp_mail_msg_xencoding_qp, + esp_mail_msg_xencoding_base64, + /* rfc2045 section 2.8 */ + esp_mail_msg_xencoding_8bit, + /* rfc2045 section 2.9 */ + esp_mail_msg_xencoding_binary +}; + +/* The port protocols enum */ +enum esp_mail_protocol +{ + esp_mail_protocol_plain_text, + esp_mail_protocol_ssl, + esp_mail_protocol_tls +}; + +/* The internal use strct */ +struct esp_mail_internal_use_t +{ + esp_mail_msg_xencoding xencoding = esp_mail_msg_xencoding_none; + MB_String cid; +}; + +/* The struct contains port number and its protocol */ +struct port_function +{ + uint16_t port; + esp_mail_protocol protocol; +}; + +/* The struct that contains the list of port_function and its size */ +struct esp_mail_ports_functions +{ + friend class IMAPSession; + friend class SMTPSession; + friend class esp_mail_session_config_t; + + uint16_t size = 0; + port_function *list = nullptr; + bool use_internal_list = false; +}; + +/* The content transfer encoding type struct */ +struct esp_mail_transfer_encoding_t +{ + /* The default 7-bit transfer encoding for US-ACII characters*/ + static constexpr const char *enc_7bit = "7bit"; + + /* The quoted printable transfer encoding for non-US-ASCII characters*/ + static constexpr const char *enc_qp = "quoted-printable"; + + /* The base64 encoded transfer encoding */ + static constexpr const char *enc_base64 = "base64"; + + /* The 8-bit transfer encoding for extended-US-ASCII characters*/ + static constexpr const char *enc_8bit = "8bit"; + + /* The binary transfer encoding for extended-US-ASCII characters with no line + * length limit*/ + static constexpr const char *enc_binary = "binary"; +}; + +/* The content disposition types strucr (rfc 2183) */ +struct esp_mail_content_disposition_type_t +{ + /** if it is intended to be displayed automatically + * upon display of the message. + */ + static constexpr const char *inline_ = "inline"; + + /** to indicate that they are separate from the main body + * of the mail message, and that their display should not + * be automatic, but contingent upon some further action of the user. + */ + static constexpr const char *attachment = "attachment"; +}; + +/* The file (SD/flash) message content struct used for providing SMTP message content from file */ +struct esp_mail_file_message_content_t +{ + /* The file path include its name */ + MB_String name; + + /** The type of file storages e.g. + * esp_mail_file_storage_type_none, + * esp_mail_file_storage_type_flash, and + * esp_mail_file_storage_type_sd + */ + esp_mail_file_storage_type type = esp_mail_file_storage_type_flash; +}; + +/* The blob or flash string message content struct used for providing SMTP message content from blob or flash string */ +struct esp_mail_blob_message_content_t +{ + /* The array of content in flash memory */ + const uint8_t *data = nullptr; + + /* The array size in bytes */ + size_t size = 0; +}; + +/* The option to embed this message content as a file */ +struct esp_mail_smtp_embed_message_body_t +{ + /* Enable to send this message body as file */ + bool enable = false; + + /* The name of embedded file */ + MB_String filename; + + /** The embedded type + * esp_mail_smtp_embed_message_type_attachment or 0 + * esp_mail_smtp_embed_message_type_inline or 1 + */ + esp_mail_smtp_embed_message_type type = esp_mail_smtp_embed_message_type_attachment; +}; + +/** This is the base struct for SMTP message. + * This is for input and later used as esp_mail_plain_body_t + * and esp_mail_html_body_t. + * Its members are similar to esp_mail_imap_plain_body_t + * and esp_mail_imap_html_body_t unless it contains + * MB_String object to hold the string. + */ +struct esp_mail_message_body_t +{ + /* The option to embed this message content as a file */ + struct esp_mail_smtp_embed_message_body_t embed; + + /* The PLAIN/HTML content of the message */ + MB_String content; + + const char *nonCopyContent = ""; + + /* The blob that contins PLAIN/HTML content of the message */ + struct esp_mail_blob_message_content_t blob; + + /* The file that contins PLAIN/HTML content of the message */ + struct esp_mail_file_message_content_t file; + + /* The charset of the PLAIN/HTML content of the message */ + MB_String charSet = "UTF-8"; + + /* The content type of message */ + MB_String content_type = mimeinfo[esp_mail_file_extension_txt].mimeType; + + /* The option to encode the content for data transfer */ + MB_String transfer_encoding = "7bit"; + + /* The option to send the PLAIN text with wrapping */ + bool flowed = false; + + /* The internal usage data */ + struct esp_mail_internal_use_t _int; +}; + +/** The PLAIN text body details of the fetching message. + * This is for output and its members are similar to + * esp_mail_message_body_t unless there is no string object + * to hold string data unless the pointer to the const strings + * in IMAPSession object. + */ +struct esp_mail_imap_plain_body_t +{ + /* The option to embed this message content as a file */ + struct esp_mail_smtp_embed_message_body_t embed; + + /* The PLAIN text content of the message */ + const char *content = ""; + + /* The blob that contins PLAIN text content of the message */ + struct esp_mail_blob_message_content_t blob; + + /* The file that contins PLAIN text content of the message */ + struct esp_mail_file_message_content_t file; + + /* The charset of the PLAIN text content of the message */ + const char *charSet = "UTF-8"; + + /* The content type of message */ + const char *content_type = mimeinfo[esp_mail_file_extension_txt].mimeType; + + /* The option to encode the content for data transfer */ + const char *transfer_encoding = "7bit"; + + /* The option to send the PLAIN text with wrapping */ + bool flowed = false; + + /* The internal usage data */ + struct esp_mail_internal_use_t _int; +}; + +/** The HTML body details of the fetching message. + * This is for output and its members are similar to + * esp_mail_message_body_t unless there is no string object + * to hold string data unless the pointer to the const strings + * in IMAPSession object. + */ +struct esp_mail_imap_html_body_t +{ + /* The option to embedded the content as a file */ + struct esp_mail_smtp_embed_message_body_t embed; + + /* The HTML content of the message */ + const char *content = ""; + + /* The blob that contins HTML content of the message */ + struct esp_mail_blob_message_content_t blob; + + /* The file that contins HTML content of the message */ + struct esp_mail_file_message_content_t file; + + /* The charset of the HTML content of the message */ + const char *charSet = "UTF-8"; + + /* The content type of message */ + const char *content_type = mimeinfo[esp_mail_file_extension_html].mimeType; + + /* The option to encode the content for data transfer */ + const char *transfer_encoding = "7bit"; + + /* The internal usage data */ + struct esp_mail_internal_use_t _int; +}; + +/* The PLAIN text body details of the message */ +typedef struct esp_mail_message_body_t esp_mail_plain_body_t; + +/* The HTML text body details of the message */ +typedef struct esp_mail_message_body_t esp_mail_html_body_t; + +/* The attachment info struct used for output */ +struct esp_mail_attachment_info_t +{ + const char *filename = ""; + const char *name = ""; + const char *creationDate = ""; + const char *mime = ""; + const char *description = ""; + esp_mail_attach_type type = esp_mail_att_type_none; + size_t size; +}; + +#if defined(ENABLE_SMTP) + +struct esp_mail_smtp_command_t +{ + char text[9]; +}; + +struct esp_mail_timestamp_value_t +{ + /* The time format of timestamp to inject into subject or content as using in strftime C++ function */ + MB_String format; + /* The tag that will be replaced with current timestamp */ + MB_String tag; +}; + +/** The SMTP commands per stansards. + * The arrangement is related to esp_mail_smtp_command_types enum. + * Do not modify or remove. + */ +const struct esp_mail_smtp_command_t smtp_commands[esp_mail_smtp_command_maxType] PROGMEM = { + "AUTH", + "LOGIN", + "HELO", + "EHLO", + "QUIT", + "MAIL", + "RCPT", + "DATA", + "BDAT", + "LAST", + "PLAIN", + "FROM:", + "TO:", + "NOTIFY", + "SUCCESS", + "FAILURE", + "DELAY", + "BODY", + "\r\n.\r\n", + "STARTTLS"}; + +struct esp_mail_smtp_commands_tokens +{ +public: + esp_mail_smtp_commands_tokens(bool pre) + { + preToken = pre; + } + MB_String operator[](size_t index) + { + MB_String s = preToken ? " " : smtp_commands[index].text; + s += !preToken ? " " : smtp_commands[index].text; + return s; + } + +private: + bool preToken = false; +}; + +// The smtp commands with leading space. +static esp_mail_smtp_commands_tokens smtp_cmd_pre_tokens(true); + +// The smtp commands with trailing space. +static esp_mail_smtp_commands_tokens smtp_cmd_post_tokens(false); + +#endif + +#if defined(ENABLE_IMAP) + +struct esp_mail_imap_command_t +{ + char text[15]; +}; + +/** The IMAP commands per standards. + * The arrangement is related to esp_mail_imap_command_types enum. + * Do not modify or remove. + */ +const struct esp_mail_imap_command_t imap_commands[esp_mail_imap_command_maxType] PROGMEM = { + "STARTTLS", + "APPEND", + "CAPABILITY", + "AUTHENTICATE", + "PLAIN", + "UID", + "FETCH", + "FLAGS", + "LOGIN", + "LIST", + "EXAMINE", + "SEARCH", + "LOGOUT", + "BODY", + "MIME", + "CLOSE", + "EXISTS", + "PEEK", + "TEXT", + "FIELDS", + "HEADER", + "NEW", + "ALL", + "SELECT", + "EXPUNGE", + "CREATE", + "DELETE", + "IDLE", + "DONE", + "RECENT", + "UNSEEN", + "RENAME", + "LSUB", + "SUBSCRIBE", + "UNSUBSCRIBE", + "SILENT", + "MOVE", + "GETQUOTA", + "SETQUOTA", + "ROOT", + "GETACL", + "SETACL", + "DELETEACL", + "MYRIGHTS", + "NAMESPACE", + "ENABLE", + "XOAUTH2", + "STORE", + "+FLAGS", + "-FLAGS", + "COPY", + "ID", + "UNSELECT", + "CONDSTORE", + "NOOP", + "UNCHANGEDSINCE", + "CHANGEDSINCE", + "MODSEC"}; + +struct esp_mail_imap_commands_tokens +{ +public: + esp_mail_imap_commands_tokens(bool pre) + { + preToken = pre; + } + MB_String operator[](size_t index) + { + MB_String s = preToken ? " " : imap_commands[index].text; + s += !preToken ? " " : imap_commands[index].text; + return s; + } + +private: + bool preToken = false; +}; + +// The imap commands with leading space. +static esp_mail_imap_commands_tokens imap_cmd_pre_tokens(true); + +// The imap commands with trailing space. +static esp_mail_imap_commands_tokens imap_cmd_post_tokens(false); + +struct esp_mail_imap_response_t +{ + char text[18]; +}; + +/** The IMAP response. + * The arrangement is related to esp_mail_imap_response_types enum. + * Do not modify or remove. + */ +const struct esp_mail_imap_response_t imap_responses[esp_mail_imap_response_maxType] PROGMEM = { + // Tagged + "OK ", + "NO ", + "BAD ", + // Untagged + "* LIST ", + "* FLAGS ", + "* SEARCH ", + " FETCH ", + " NIL ", + " UID ", + "* CAPABILITY ", + "CAPABILITY ", + "* LSUB ", + "* QUOTA ", + "* QUOTAROOT ", + "* ACL ", + "* MYRIGHTS ", + "* NAMESPACE ", + "* ", + " EXISTS", + " EXPUNGE", + " RECENT", + " [UIDNEXT ", + " [UNSEEN ", + "* ID ", + " [HIGHESTMODSEQ ", + " [NOMODSEQ]", + " [PERMANENTFLAGS ", + " [UIDVALIDITY "}; + +#endif + +struct esp_mail_char_decoding_t +{ + char text[12]; +}; + +/** Supported charactor encodings. + * The arrangement is related to esp_mail_char_decoding_types enum. + * Do not modify or remove. + */ +const struct esp_mail_char_decoding_t char_decodings[esp_mail_char_decoding_maxType] PROGMEM = { + "utf-8", + "iso-8859-1", + "iso-8859-11", + "tis-620", + "windows-874"}; + +struct esp_mail_multipart_t +{ + char text[22]; +}; + +/** MultiPart MIME. + * The arrangement is related to esp_mail_multipart_types enum. + * Do not modify or remove. + */ +const struct esp_mail_multipart_t multipart_types[esp_mail_multipart_maxType] PROGMEM = { + "multipart/mixed", + "multipart/related", + "multipart/parallel", + "multipart/alternative"}; + +struct esp_mail_rfc822_header_field_t +{ + char text[20]; + bool isNum; + bool trim; +}; + +/** The rfc822 message header fields. + * The arrangement is related to esp_mail_rfc822_header_field_types enum. + * Do not modify or remove. + */ +const struct esp_mail_rfc822_header_field_t rfc822_headers[esp_mail_rfc822_header_field_maxType] PROGMEM = { + {"From", false, true}, + {"Sender", false, true}, + {"To", false, true}, + {"Cc", false, true}, + {"Subject", false, false}, + {"Date", false, false}, + {"Message-ID", false, false}, + {"Return-Path", false, true}, + {"Reply-To", false, true}, + {"In-Reply-To", false, true}, + {"References", false, true}, + {"Comments", false, false}, + {"Keywords", false, false}, + {"Bcc", false, true}, + {"Flags", false, false}}; + +struct esp_mail_message_header_field_t +{ + char text[26]; +}; + +/** Additional fields and props. + * The arrangement is related to esp_mail_message_header_field_types enum. + * Do not modify or remove. + */ +const struct esp_mail_message_header_field_t message_headers[esp_mail_message_header_field_maxType] PROGMEM = { + "Number", + "UID", + "Accept-Language", + "Content-Language", + "Filename", + "Name", + "Size", + "MIME", + "Type", + "Description", + "Creation-Date", + "X-Priority", + "X-MSMail-Priority", + "Importance", + "Content-Type", + "Content-transfer-encoding", + "Content-Disposition", + "Content-Location", + "Content-ID", + "Content-Description", + "Mime-Version", + "Charset", + "format", + "delsp", + "Modification-Date"}; + +struct esp_mail_auth_capability_t +{ + char text[20]; +}; + +#if defined(ENABLE_SMTP) + +/** The server capability keywords per standard. + * The arrangement is related to esp_mail_auth_capability_types enum. + * Do not modify or remove. + */ +const struct esp_mail_auth_capability_t smtp_auth_capabilities[esp_mail_auth_capability_maxType] PROGMEM = { + "PLAIN", + "XOAUTH2", + "CRAM-MD5", + "DIGEST-MD5", + "LOGIN", + "STARTTLS", + "DUMMY_AUTH" /* SASL-IR */}; + +struct esp_mail_smtp_auth_tokens +{ +public: + esp_mail_smtp_auth_tokens(bool pre) + { + preToken = pre; + } + MB_String operator[](size_t index) + { + MB_String s = preToken ? " " : smtp_auth_capabilities[index].text; + s += !preToken ? " " : smtp_auth_capabilities[index].text; + return s; + } + +private: + bool preToken = false; +}; + +// The smtp auth capability with leading space. +static esp_mail_smtp_auth_tokens smtp_auth_cap_pre_tokens(true); +// The smtp auth capability with trailing space. +static esp_mail_smtp_auth_tokens smtp_auth_cap_post_tokens(false); + +struct esp_mail_smtp_send_capability_t +{ + char text[15]; +}; + +/** The server capability keywords per standard. + * The arrangement is related esp_mail_smtp_send_capability_types enum. + * Do not modify or remove. + */ +const struct esp_mail_smtp_send_capability_t smtp_send_capabilities[esp_mail_smtp_send_capability_maxType] PROGMEM = { + "BINARYMIME", + "8BITMIME", + "CHUNKING", + "SMTPUTF8", + "PIPELINING", + "DSN", + "" /* ESMTP */}; + +struct esp_mail_smtp_send_tokens +{ +public: + esp_mail_smtp_send_tokens(bool pre) + { + preToken = pre; + } + MB_String operator[](size_t index) + { + MB_String s = preToken ? " " : smtp_send_capabilities[index].text; + s += !preToken ? " " : smtp_send_capabilities[index].text; + return s; + } + +private: + bool preToken = false; +}; + +static esp_mail_smtp_send_tokens smtp_send_cap_pre_tokens(true); + +#endif + +#if defined(ENABLE_IMAP) + +/** The server capability keywords per standard. + * The arrangement is related esp_mail_auth_capability_types enum. + * Do not modify or remove. + */ +const struct esp_mail_auth_capability_t imap_auth_capabilities[esp_mail_auth_capability_maxType] PROGMEM = { + "AUTH=PLAIN", + "AUTH=XOAUTH2", + "CRAM-MD5", + "DIGEST-MD5", + "DUMMY_AUTH", /* Log in */ + "STARTTLS", + "SASL-IR"}; + +struct esp_mail_imap_auth_tokens +{ +public: + esp_mail_imap_auth_tokens(bool pre) + { + preToken = pre; + } + MB_String operator[](size_t index) + { + MB_String s = preToken ? " " : imap_auth_capabilities[index].text; + s += !preToken ? " " : imap_auth_capabilities[index].text; + return s; + } + +private: + bool preToken = false; +}; + +// The imap auth capability with leading space. +static esp_mail_imap_auth_tokens imap_auth_cap_pre_tokens(true); + +struct esp_mail_imap_read_capability_t +{ + char text[15]; +}; + +/** The server capability keywords per standard. + * The arrangement is related esp_mail_imap_read_capability_types enum. + * Do not modify or remove. + */ +const struct esp_mail_imap_read_capability_t imap_read_capabilities[esp_mail_imap_read_capability_maxType] PROGMEM = { + "IMAP4", + "IMAP4rev1", + "IDLE", + "LITERAL+", + "LITERAL-", + "MULTIAPPEND", + "UIDPLUS", + "ACL", + "BINARY", + "LOGINDISABLED", + "MOVE", + "QUOTA", + "NAMESPACE", + "ENABLE", + "ID", + "UNSELECT", + "CHILDREN", + "CONDSTORE" + "" /* Auto cap */}; + +struct esp_mail_imap_read_tokens +{ +public: + esp_mail_imap_read_tokens(bool pre) + { + preToken = pre; + } + MB_String operator[](size_t index) + { + MB_String s = preToken ? " " : imap_read_capabilities[index].text; + s += !preToken ? " " : imap_read_capabilities[index].text; + return s; + } + +private: + bool preToken = false; +}; + +// The imap auth capability with leading space. +static esp_mail_imap_read_tokens imap_read_cap_pre_tokens(true); + +// The imap auth capability with trailing space. +static esp_mail_imap_read_tokens imap_read_cap_post_tokens(false); + +struct esp_mail_imap_identification_key_t +{ + char text[15]; +}; + +/** The identification keys per standard. + * The arrangement is related esp_mail_imap_identification_key_types enum. + * Do not modify or remove. + */ +const struct esp_mail_imap_identification_key_t imap_identification_keys[esp_mail_imap_identification_key_maxType] PROGMEM = { + "name", + "version", + "os", + "os-version", + "vendor", + "support-url", + "address", + "date", + "command", + "arguments", + "environment"}; + +/* The IMAP ID data struct */ +typedef struct esp_mail_imap_identity_t +{ + MB_String name; + MB_String version; + MB_String os; + MB_String os_version; + MB_String vendor; + MB_String support_url; + MB_String address; + MB_String date; + MB_String command; + MB_String arguments; + MB_String environment; + +} IMAP_Identification; + +#endif + +#endif + +#if defined(ENABLE_SMTP) || defined(ENABLE_IMAP) +/* The email address info [SMTP_Message]*/ +struct esp_mail_address_info_t +{ + /* The name of Email author/sender */ + MB_String name; + + /* The Email address */ + MB_String email; +}; +#endif + +#if defined(ENABLE_SMTP) + +/* The SMTP message notification types enum */ +enum esp_mail_smtp_notify +{ + esp_mail_smtp_notify_never = 0, + esp_mail_smtp_notify_success = 1, + esp_mail_smtp_notify_failure = 2, + esp_mail_smtp_notify_delay = 4 +}; + +/* The SMTP status codes enum */ +enum esp_mail_smtp_status_code +{ + esp_mail_smtp_status_code_0, // default + + /* Positive Completion */ + esp_mail_smtp_status_code_211 = 221, // System status, or system help reply + esp_mail_smtp_status_code_214 = 214, // Help message(A response to the HELP command) + esp_mail_smtp_status_code_220 = 220, // Service ready + esp_mail_smtp_status_code_221 = 221, // Service closing transmission channel [RFC 2034] + esp_mail_smtp_status_code_235 = 235, // 2.7.0 Authentication succeeded[RFC 4954] + esp_mail_smtp_status_code_250 = 250, // Requested mail action okay, completed + esp_mail_smtp_status_code_251 = 251, // User not local; will forward + esp_mail_smtp_status_code_252 = 252, // Cannot verify the user, but it will + // try to deliver the message anyway + + /* Positive Intermediate */ + esp_mail_smtp_status_code_334 = 334, //(Server challenge - the text part + // contains the Base64 - encoded + // challenge)[RFC 4954] + esp_mail_smtp_status_code_354 = 354, // Start mail input + + /* Transient Negative Completion */ + /* "Transient Negative" means the error condition is temporary, and the action + may be requested again.*/ + esp_mail_smtp_status_code_421 = 421, // Service is unavailable because the server is shutting down. + esp_mail_smtp_status_code_432 = 432, // 4.7.12 A password transition is needed [RFC 4954] + esp_mail_smtp_status_code_450 = 450, // Requested mail action not taken: mailbox unavailable (e.g., + // mailbox busy or temporarily blocked for policy reasons) + esp_mail_smtp_status_code_451 = 451, // Requested action aborted : local error in processing + // e.g.IMAP server unavailable[RFC 4468] + esp_mail_smtp_status_code_452 = 452, // Requested action not taken : insufficient system storage + esp_mail_smtp_status_code_454 = 454, // 4.7.0 Temporary authentication failure[RFC 4954] + esp_mail_smtp_status_code_455 = 455, // Server unable to accommodate parameters + + /* Permanent Negative Completion */ + esp_mail_smtp_status_code_500 = 500, // Syntax error, command unrecognized + // (This may include errors such as + // command line too long) + // e.g. Authentication Exchange line is too long [RFC 4954] + esp_mail_smtp_status_code_501 = 501, // Syntax error in parameters or arguments + // e.g. 5.5.2 Cannot Base64-decode Client responses [RFC 4954] + // 5.7.0 Client initiated Authentication Exchange (only when the SASL + // mechanism specified that client does not begin the authentication exchange) + // [RFC 4954] + esp_mail_smtp_status_code_502 = 502, // Command not implemented + esp_mail_smtp_status_code_503 = 503, // Bad sequence of commands + esp_mail_smtp_status_code_504 = 504, // Command parameter is not implemented + // e.g. 5.5.4 Unrecognized authentication type [RFC 4954] + esp_mail_smtp_status_code_521 = 521, // Server does not accept mail [RFC 7504] + esp_mail_smtp_status_code_523 = 523, // Encryption Needed [RFC 5248] + esp_mail_smtp_status_code_530 = 530, // 5.7.0 Authentication required [RFC 4954] + esp_mail_smtp_status_code_534 = 534, // 5.7.9 Authentication mechanism is too weak [RFC 4954] + esp_mail_smtp_status_code_535 = 535, // 5.7.8 Authentication credentials invalid [RFC 4954] + esp_mail_smtp_status_code_538 = 538, // 5.7.11 Encryption required for + // requested authentication mechanism[RFC + // 4954] + esp_mail_smtp_status_code_550 = 550, // Requested action not taken: mailbox unavailable (e.g., mailbox not + // found, no access, or command rejected for policy reasons) + esp_mail_smtp_status_code_551 = 551, // User not local; please try + esp_mail_smtp_status_code_552 = 552, // Requested mail action aborted: exceeded storage allocation + esp_mail_smtp_status_code_553 = 553, // Requested action not taken: mailbox name not allowed + esp_mail_smtp_status_code_554 = 554, // Transaction has failed (Or, in the + // case of a connection-opening response, + // "No SMTP service here") + // e.g. 5.3.4 Message too big for system [RFC 4468] + esp_mail_smtp_status_code_556 = 556, // Domain does not accept mail[RFC 7504] +}; + +/* The SMTP ports enum */ +enum esp_mail_smtp_port +{ + esp_mail_smtp_port_25 = 25, // PLAIN/TLS with STARTTLS + esp_mail_smtp_port_465 = 465, // SSL + esp_mail_smtp_port_587 = 587, // TLS with STARTTLS +}; + +const struct port_function smtp_ports[3] = { + {esp_mail_smtp_port_25, esp_mail_protocol_plain_text}, + {esp_mail_smtp_port_465, esp_mail_protocol_ssl}, + {esp_mail_smtp_port_587, esp_mail_protocol_tls}}; + +/* The SMTP message response [SMTP_Message] */ +struct esp_mail_smtp_msg_response_t +{ + /* The author Email address to reply */ + MB_String reply_to; + + /* The sender Email address to return the message */ + MB_String return_path; + + /** The Delivery Status Notifications e.g. esp_mail_smtp_notify_never, + * esp_mail_smtp_notify_success, + * esp_mail_smtp_notify_failure, and + * esp_mail_smtp_notify_delay + */ + int notify = esp_mail_smtp_notify::esp_mail_smtp_notify_never; +}; + +/* The SMTP enable option [SMTP_Message] */ +struct esp_mail_smtp_enable_option_t +{ + /* Enable chunk data sending for large message */ + bool chunking = false; +}; + +/* The SMTP blob data attachment data [Session_Config] */ +struct esp_mail_attach_blob_t +{ + /* BLOB data (flash or ram) */ + const uint8_t *data = nullptr; + + /* BLOB data size in byte */ + size_t size = 0; +}; + +/* The SMTP file attachment data [Session_Config] */ +struct esp_mail_attach_file_t +{ + MB_String path; + /** The file storage type e.g. esp_mail_file_storage_type_none, + * esp_mail_file_storage_type_flash, and + * esp_mail_file_storage_type_sd + */ + esp_mail_file_storage_type storage_type = esp_mail_file_storage_type_none; +}; + +/* The SMTP attachment decription [Session_Config] */ +struct esp_mail_attach_descr_t +{ + /* The name of attachment */ + MB_String name; + + /* The attachment file name */ + MB_String filename; + + /* The MIME type of attachment */ + MB_String mime; + + /* The transfer encoding of attachment e.g. base64 */ + MB_String transfer_encoding = "base64"; + + /* The content encoding of attachment e.g. base64 */ + MB_String content_encoding; + + /* The content id of attachment file */ + MB_String content_id; + + /* The description of attachment file */ + MB_String description; +}; + +/* Used internally in esp_mail_attachment_t */ +struct esp_mail_attach_internal_t +{ + esp_mail_attach_type att_type = esp_mail_att_type_attachment; + int index = 0; + int msg_uid = 0; + bool flash_blob = false; + esp_mail_msg_xencoding xencoding = esp_mail_msg_xencoding_none; + bool parallel = false; + MB_String cid; +}; + +/* The struct used as SMTP_Attachment for SMTP and ESP_Mail_Attachment for IMAP */ +struct esp_mail_attachment_t +{ + /* The attachment description */ + struct esp_mail_attach_descr_t descr; + + /* The BLOB data config */ + struct esp_mail_attach_blob_t blob; + + /* The file data config */ + struct esp_mail_attach_file_t file; + + /* reserved for internal usage */ + struct esp_mail_attach_internal_t _int; +}; + +/* The struct used as SMTP_Result */ +struct esp_mail_smtp_send_status_t +{ + /* The status of the message */ + bool completed = false; + + /* The primary recipient mailbox of the message */ + MB_String recipients; + + /* The topic of the message */ + MB_String subject; + + /* The timestamp of the message */ + uint32_t timestamp = 0; +}; + +/* Used internally for SMTPSession */ +struct esp_mail_smtp_msg_type_t +{ + bool rfc822 = false; + int rfc822Idx = 0; +}; + +/* Used internally for holding base64 data sources */ +struct esp_mail_smtp_send_base64_data_info_t +{ + esp_mail_file_storage_type storageType = esp_mail_file_storage_type_none; + const char *filename = ""; + const uint8_t *rawPtr = nullptr; + bool flashMem = false; + size_t size = 0; + size_t dataIndex = 0; +}; + +/* SMTP commands types enum */ +enum esp_mail_smtp_command +{ + esp_mail_smtp_cmd_undefined, + esp_mail_smtp_cmd_initial_state, + esp_mail_smtp_cmd_greeting, + esp_mail_smtp_cmd_start_tls, + esp_mail_smtp_cmd_login_user, + esp_mail_smtp_cmd_auth_plain, + esp_mail_smtp_cmd_auth_login, + esp_mail_smtp_cmd_auth_xoauth2, + esp_mail_smtp_cmd_login_psw, + esp_mail_smtp_cmd_send_header_sender, + esp_mail_smtp_cmd_send_header_recipient, + esp_mail_smtp_cmd_send_body, + esp_mail_smtp_cmd_chunk_termination, + esp_mail_smtp_cmd_logout, + esp_mail_smtp_cmd_custom +}; + +/* SMTP message priority level enum */ +enum esp_mail_smtp_priority +{ + esp_mail_smtp_priority_high = 1, + esp_mail_smtp_priority_normal = 3, + esp_mail_smtp_priority_low = 5, +}; + +/* SMTP response data */ +typedef struct esp_mail_smtp_response_status_t +{ + /* The SMTP server response status code */ + int statusCode = 0; + + /* error code */ + int errorCode = 0; + int id = -1; + MB_String text; +} SMTP_Response; + +#endif + +#if defined(ENABLE_IMAP) + +enum esp_mail_imap_msg_num_type +{ + esp_mail_imap_msg_num_type_undefined, + esp_mail_imap_msg_num_type_uid, + esp_mail_imap_msg_num_type_number +}; + +enum esp_mail_imap_store_flag_type +{ + esp_mail_imap_store_flag_type_set, + esp_mail_imap_store_flag_type_add, + esp_mail_imap_store_flag_type_remove +}; + +enum esp_mail_char_decoding_scheme +{ + esp_mail_char_decoding_scheme_default = -1, + esp_mail_char_decoding_scheme_utf_8, + esp_mail_char_decoding_scheme_iso8859_1, + esp_mail_char_decoding_scheme_iso8859_11, + esp_mail_char_decoding_scheme_tis_620, + esp_mail_char_decoding_scheme_windows_874 +}; + +enum esp_mail_imap_rights_type_t +{ + /* a - administer (perform SETACL/DELETEACL/GETACL/LISTRIGHTS) */ + esp_mail_imap_rights_administer = 'a' - 'a', + /* c - RFC2086 (obsoleted) create (CREATE new sub-mailboxes in any implementation-defined hierarchy) */ + esp_mail_imap_rights_create_c = 'c' - 'a', + /* d - RFC2086 (obsoleted) delete (STORE DELETED flag, perform EXPUNGE) */ + esp_mail_imap_rights_delete_d = 'd' - 'a', + /* e - perform EXPUNGE and expunge as a part of CLOSE */ + esp_mail_imap_rights_expunge = 'e' - 'a', + /* i - insert (perform APPEND, COPY into mailbox) */ + esp_mail_imap_rights_insert = 'i' - 'a', + /* k - RFC4314 create mailboxes (CREATE new sub-mailboxes in any implementation-defined hierarchy, parent mailbox for the new mailbox name in RENAME)*/ + esp_mail_imap_rights_create = 'k' - 'a', + /* l - lookup (mailbox is visible to LIST/LSUB commands, SUBSCRIBE mailbox) */ + esp_mail_imap_rights_lookup = 'l' - 'a', + /* p - post (send mail to submission address for mailbox, not enforced by IMAP4 itself) */ + esp_mail_imap_rights_post = 'p' - 'a', + /* r - read (SELECT the mailbox, perform STATUS) */ + esp_mail_imap_rights_read = 'r' - 'a', + /* s - keep seen/unseen information across sessions (set or clear \SEEN flag via STORE, also set \SEEN during APPEND/COPY/ FETCH BODY[...]) */ + esp_mail_imap_rights_seen = 's' - 'a', + /* t - RFC4314 delete messages (set or clear \DELETED flag via STORE, set \DELETED flag during APPEND/COPY) */ + esp_mail_imap_rights_delete_message = 't' - 'a', + /* w - write (set or clear flags other than \SEEN and \DELETED via STORE, also set them during APPEND/COPY) */ + esp_mail_imap_rights_write = 'w' - 'a', + /* x - RFC4314 delete mailbox (DELETE mailbox, old mailbox name in RENAME) */ + esp_mail_imap_rights_delete_mailbox = 'x' - 'a', + + esp_mail_imap_rights_maxType = esp_mail_imap_rights_delete_mailbox + 1 +}; + +enum esp_mail_imap_port +{ + esp_mail_imap_port_143 = 143, // PLAIN/TLS with STARTTLS + esp_mail_imap_port_993 = 993, // SSL +}; + +const struct port_function imap_ports[2] = { + {esp_mail_imap_port_143, esp_mail_protocol_plain_text}, + {esp_mail_imap_port_993, esp_mail_protocol_ssl}}; + +enum esp_mail_imap_auth_mode +{ + esp_mail_imap_mode_examine, + esp_mail_imap_mode_select +}; + +enum esp_mail_imap_response_status +{ + esp_mail_imap_resp_unknown, + esp_mail_imap_resp_ok, + esp_mail_imap_resp_no, + esp_mail_imap_resp_bad +}; + +enum esp_mail_imap_polling_status_type +{ + imap_polling_status_type_undefined, + imap_polling_status_type_new_message, + imap_polling_status_type_remove_message, + imap_polling_status_type_fetch_message +}; + +enum esp_mail_imap_header_state +{ + esp_mail_imap_state_content_type = esp_mail_rfc822_header_field_maxType, + esp_mail_imap_state_content_transfer_encoding, + esp_mail_imap_state_accept_language, + esp_mail_imap_state_content_language, + esp_mail_imap_state_char_set, + esp_mail_imap_state_boundary +}; + +enum esp_mail_imap_command +{ + esp_mail_imap_cmd_capability, + esp_mail_imap_cmd_starttls, + esp_mail_imap_cmd_sasl_login, + esp_mail_imap_cmd_sasl_auth_plain, + esp_mail_imap_cmd_sasl_auth_oauth, + esp_mail_imap_cmd_list, + esp_mail_imap_cmd_lsub, + esp_mail_imap_cmd_subscribe, + esp_mail_imap_cmd_unsubscribe, + esp_mail_imap_cmd_select, + esp_mail_imap_cmd_examine, + esp_mail_imap_cmd_close, + esp_mail_imap_cmd_status, + esp_mail_imap_cmd_search, + esp_mail_imap_cmd_fetch_body_header, + esp_mail_imap_cmd_fetch_body_mime, + esp_mail_imap_cmd_fetch_body_text, + esp_mail_imap_cmd_fetch_body_attachment, + esp_mail_imap_cmd_fetch_body_inline, + esp_mail_imap_cmd_fetch_sequence_set, + esp_mail_imap_cmd_logout, + esp_mail_imap_cmd_store, + esp_mail_imap_cmd_move, + esp_mail_imap_cmd_get_quota, + esp_mail_imap_cmd_set_quota, + esp_mail_imap_cmd_get_quota_root, + esp_mail_imap_cmd_get_acl, + esp_mail_imap_cmd_set_acl, + esp_mail_imap_cmd_delete_acl, + esp_mail_imap_cmd_my_rights, + esp_mail_imap_cmd_namespace, + esp_mail_imap_cmd_expunge, + esp_mail_imap_cmd_create, + esp_mail_imap_cmd_rename, + esp_mail_imap_cmd_delete, + esp_mail_imap_cmd_idle, + esp_mail_imap_cmd_done, + esp_mail_imap_cmd_get_uid, + esp_mail_imap_cmd_get_flags, + esp_mail_imap_cmd_append, + esp_mail_imap_cmd_append_last, + esp_mail_imap_cmd_enable, + esp_mail_imap_cmd_id, + esp_mail_imap_cmd_unselect, + esp_mail_imap_cmd_noop, + esp_mail_imap_cmd_copy, + esp_mail_imap_cmd_custom +}; + +enum esp_mail_imap_mime_fetch_type +{ + esp_mail_imap_mime_fetch_type_part, + esp_mail_imap_mime_fetch_type_sub_part1, + esp_mail_imap_mime_fetch_type_sub_part2 +}; + +enum esp_mail_imap_header_type +{ + esp_mail_imap_header_from, + esp_mail_imap_header_to, + esp_mail_imap_header_cc, + esp_mail_imap_header_subject, + esp_mail_imap_header_date, + esp_mail_imap_header_msg_id, + esp_mail_imap_header_cont_lang, + esp_mail_imap_header_accept_lang +}; + +enum esp_mail_imap_multipart_sub_type +{ + esp_mail_imap_multipart_sub_type_none = 0, + esp_mail_imap_multipart_sub_type_mixed, + esp_mail_imap_multipart_sub_type_alternative, + esp_mail_imap_multipart_sub_type_parallel, + esp_mail_imap_multipart_sub_type_digest, + esp_mail_imap_multipart_sub_type_related, + esp_mail_imap_multipart_sub_type_report, +}; + +enum esp_mail_imap_message_sub_type +{ + esp_mail_imap_message_sub_type_none = 0, + esp_mail_imap_message_sub_type_rfc822, + esp_mail_imap_message_sub_type_delivery_status, + esp_mail_imap_message_sub_type_partial, + esp_mail_imap_message_sub_type_external_body, +}; + +typedef struct esp_mail_imap_response_status_t +{ + // No IMAP server response status code (statusCode), server returns OK, NO and BAD response instead + + /* error code */ + int errorCode = 0; + MB_String tag; + MB_String text; + MB_String status; + bool completed = false; + +public: + void clear(bool clearTag = true) + { + if (clearTag) + tag.clear(); + status.clear(); + text.clear(); + completed = false; + } +} IMAP_Response; + +struct esp_mail_imap_msg_num_t +{ + esp_mail_imap_msg_num_type type = esp_mail_imap_msg_num_type_undefined; + uint32_t value = 0; +}; + +__attribute__((used)) struct +{ + bool operator()(struct esp_mail_imap_msg_num_t a, struct esp_mail_imap_msg_num_t b) const { return a.value > b.value; } +} compareMore; + +struct esp_mail_imap_rfc822_msg_header_item_t +{ + MB_String header_items[esp_mail_rfc822_header_field_maxType]; +}; + +/* IMAP quota root info */ +typedef struct esp_mail_imap_quota_root_info_t +{ + /* The quota root */ + MB_String quota_root; + + /* The resource name e.g. STORAGE and MESSAGE */ + MB_String name; + + /* The resource usage in kilo octets */ + size_t usage = 0; + + /* The resource limit in kilo octets */ + size_t limit = 0; + +} IMAP_Quota_Root_Info; + +/* IMAP namespace info */ +typedef struct esp_mail_imap_namespace_info_t +{ + /* The leading prefix */ + MB_String prefix; + + /* The hierarchy delimiter */ + MB_String delimiter; + +} IMAP_Namespace_Info; + +typedef struct esp_mail_imap_rights_info_t +{ + MB_String identifier; + bool rights[esp_mail_imap_rights_maxType]; + +} IMAP_Rights_Info; + +/* descrete media types (rfc 2046) */ +struct esp_mail_imap_descrete_media_type_t +{ + /** textual information with subtypes + * "plain" + * "enriched" (rfc 1896 revised from richtext in rfc 1341) + * + * unrecognized subtypes and charset should be interpreted as + * application/octet-stream + * + * parameters: + * "charset" (rfc 2045) default is us-ascii + * for character set includes 8-bit characters + * and such characters are used in the body, Content-Transfer-Encoding + * header field and a corresponding encoding on the data are required + * + * ISO-8859-X where "X" is to be replaced, as + * necessary, for the parts of ISO-8859 [ISO-8859]. + */ + static constexpr const char *text = "text"; + + /** image data with subtypes (rfc 2048) + * "jpeg" + * "gif" + * + * unrecognized subtypes should be interpreted as application/octet-stream + */ + static constexpr const char *image = "image"; + + /** audio data with initial subtype + * "baic" -- for single channel audio encoded using 8bit ISDN mu-law [PCM] + * at a sample rate of 8000 Hz. + * + * Unrecognized subtypes of "audio" should at a miniumum be treated as + * "application/octet-stream" + */ + static constexpr const char *audio = "audio"; + + /** video data with initial subtype + * "mpeg" + * + * Unrecognized subtypes of "video" should at a minumum be treated as + * "application/octet-stream" + */ + static constexpr const char *video = "video"; + + /** some other kind of data, typically either + * uninterpreted binary data or information to be + * processed by an application with subtypes + * + * "octet-stream" -- uninterpreted binary data + * "PostScript" -- for the transport of PostScript material + * + * Other expected uses include spreadsheets, data for mail-based + * scheduling systems, and languages for "active" (computational) + * messaging, and word processing formats that are not directly readable. + * + * The octet-stream subtype parameters: + * TYPE, PADDING, NAME + */ + static constexpr const char *application = "application"; +}; + +/** composite media types (rfc 2046) + * + * As stated in the definition of the Content-Transfer-Encoding field + * [RFC 2045], no encoding other than "7bit", "8bit", or "binary" is + * permitted for entities of type "multipart". The "multipart" boundary + * delimiters and header fields are always represented as 7bit US-ASCII + * in any case (though the header fields may encode non-US-ASCII header + * text as per RFC 2047) and data within the body parts can be encoded + * on a part-by-part basis, with Content-Transfer-Encoding fields for + * each appropriate body part. + */ +struct esp_mail_imap_composite_media_type_t +{ + /** data consisting of multiple entities of independent data types + * The Content-Type field for multipart entities requires one parameter, + * "boundary". + * The boundary delimiter line is then defined as a line + * consisting entirely of two hyphen characters ("-", decimal value 45) + * followed by the boundary parameter value from the Content-Type header + * field, optional linear whitespace, and a terminating CRLF. + * + * NOTE: The CRLF preceding the boundary delimiter line is conceptually + * attached to the boundary so that it is possible to have a part that + * does not end with a CRLF (line break). Body parts that must be + * considered to end with line breaks, therefore, must have two CRLFs + * preceding the boundary delimiter line, the first of which is part of + * the preceding body part, and the second of which is part of the + * encapsulation boundary. + * + * Boundary delimiters must not appear within the encapsulated material, + * and must be no longer than 70 characters, not counting the two + * leading hyphens. + * + * The boundary delimiter line following the last body part is a + * distinguished delimiter that indicates that no further body parts + * will follow. Such a delimiter line is identical to the previous + * delimiter lines, with the addition of two more hyphens after the + * boundary parameter value. + * + * See rfc2049 Appendix A for a Complex Multipart Example + */ + static constexpr const char *multipart = "multipart"; + + /* an encapsulated message */ + static constexpr const char *message = "message"; +}; + +typedef struct esp_mail_imap_mime_data_stream_info_t +{ + /* message UID */ + uint32_t uid = 0; + + /* content type */ + const char *type = ""; + + /* disposition */ + const char *disposition = ""; + + /* content character set */ + const char *charSet = ""; + + /* text content flowed format parameter */ + bool flowed = false; + + /* text content format DelSp parameter */ + bool delsp = false; + + /* content transfer encoding */ + const char *transfer_encoding = ""; + + /* content ID */ + const char *cid = ""; + + /* content description */ + const char *description = ""; + + /* content file name */ + const char *filename = ""; + + /* content name */ + const char *name = ""; + + /* creation date */ + const char *date = ""; + + /* content size */ + size_t size = 0; + + /* octet size */ + size_t octet_size = 0; + + /* current octet count */ + int octet_count = 0; + + /* data size */ + size_t data_size = 0; + + /* data buffer */ + void *data = NULL; + + bool isFirstData = false; + + bool isLastData = false; + +} MIME_Data_Stream_Info; + +typedef struct esp_mail_imap_decoding_info +{ + enum message_part_type + { + message_part_type_header, + message_part_type_text + }; + + /* The character set of the string to decode */ + const char *charset = ""; + + /* The string to decode */ + const char *data = ""; + + /* The decoded string to be processed */ + MB_String decodedString; + + /** The type of data that currently processed + * 0 or IMAP_Decoding_Info::message_part_type_header + * 1 or IMAP_Decoding_Info::message_part_type_text + */ + message_part_type type = message_part_type_header; + +} IMAP_Decoding_Info; + +struct esp_mail_imap_media_text_sub_type_t +{ + static constexpr const char *plain = "plain"; + static constexpr const char *enriched = "enriched"; + static constexpr const char *html = "html"; +}; + +/* multipart sub types */ +struct esp_mail_imap_multipart_sub_type_t +{ + /* a generic mixed set of parts */ + static constexpr const char *mixed = "mixed"; + + /* the same data in multiple formats */ + static constexpr const char *alternative = "alternative"; + + /* parts intended to be viewed simultaneously */ + static constexpr const char *parallel = "parallel"; + + /* multipart entities in which each part has a default type of + * "message/rfc822" */ + static constexpr const char *digest = "digest"; + + /* for compound objects consisting of several inter-related body parts (rfc + * 2387) */ + static constexpr const char *related = "related"; + + /* rfc 3462 */ + static constexpr const char *report = "report"; +}; + +/* message body sub types */ +struct esp_mail_imap_message_sub_type_t +{ + /* body contains an encapsulated message, with the syntax of an RFC 822 + * message. */ + static constexpr const char *rfc822 = "rfc822"; + + /* to allow large objects to be delivered as several separate pieces of mail + */ + static constexpr const char *Partial = "Partial"; + + /* the actual body data are not included, but merely referenced */ + static constexpr const char *External_Body = "External-Body"; + + static constexpr const char *delivery_status = "delivery-status"; +}; + +/* IMAP polling status */ +typedef struct esp_mail_imap_polling_status_t +{ + /** The type of status e.g. imap_polling_status_type_undefined, imap_polling_status_type_new_message, + * imap_polling_status_type_fetch_message and imap_polling_status_type_remove_message. + */ + esp_mail_imap_polling_status_type type = imap_polling_status_type_undefined; + + /** Message number or order from the total number of message that added, fetched or deleted. + */ + size_t messageNum = 0; + + /** Argument of commands e.g. FETCH + */ + MB_String argument; +} IMAP_Polling_Status; + +struct esp_mail_message_part_info_t +{ + enum content_header_field + { + content_header_field_none, + content_header_field_type, + content_header_field_description, + content_header_field_id, + content_header_field_disposition, + content_header_field_transfer_enc, + content_header_field_ext + + }; + + int octetLen = 0; + int octetCount = 0; + int attach_data_size = 0; + int textLen = 0; + bool sizeProp = false; + int nestedLevel = 0; + + // pointer to the MB_String for storing multi-line header field content. + uint32_t stringPtr = 0; + esp_mail_char_decoding_scheme stringEnc = esp_mail_char_decoding_scheme_default; + + content_header_field cur_content_hdr = content_header_field_none; + + MB_String partNumStr; + MB_String partNumFetchStr; + MB_String text; + MB_String filename; + MB_String CID; + MB_String type; + MB_String save_path; + MB_String name; + MB_String content_disposition; + MB_String content_description; + MB_String content_type; + MB_String descr; + MB_String content_transfer_encoding; + MB_String creation_date; + MB_String modification_date; + MB_String charset; + MB_String download_error; + esp_mail_attach_type attach_type = esp_mail_att_type_none; + esp_mail_message_type msg_type = esp_mail_msg_type_none; + bool file_open_write = false; + bool multipart = false; + bool is_firmware_file = false; + bool save_to_file = true; + size_t firmware_downloaded_byte = 0; + esp_mail_imap_multipart_sub_type multipart_sub_type = esp_mail_imap_multipart_sub_type_none; + esp_mail_imap_message_sub_type message_sub_type = esp_mail_imap_message_sub_type_none; + bool rfc822_part = false; + int rfc822_msg_Idx = 0; + struct esp_mail_imap_rfc822_msg_header_item_t rfc822_header; + bool error = false; + bool plain_flowed = false; + bool plain_delsp = false; + esp_mail_msg_xencoding xencoding = esp_mail_msg_xencoding_none; +}; + +struct esp_mail_message_header_t +{ + int header_data_len = 0; + + struct esp_mail_imap_rfc822_msg_header_item_t header_fields; + + MB_String content_type; + MB_String content_transfer_encoding; + uint32_t message_uid = 0; + uint32_t message_no = 0; + MB_String boundary; + MB_String accept_language; + MB_String content_language; + MB_String char_set; + bool multipart = false; + bool rfc822_part = false; + bool hasAttachment = false; + int rfc822Idx = 0; + MB_String partNumStr; + + esp_mail_imap_multipart_sub_type multipart_sub_type = esp_mail_imap_multipart_sub_type_none; + esp_mail_imap_message_sub_type message_sub_type = esp_mail_imap_message_sub_type_none; + MB_String msgID; + MB_String flags; + MB_String error_msg; + bool error = false; + _vectorImpl part_headers; + int attachment_count = 0; + int sd_alias_file_count = 0; + int total_download_size = 0; + int downloaded_size = 0; + int total_attach_data_size = 0; + int downloaded_bytes = 0; + int message_data_count = 0; +}; + +/* Internal use */ +struct esp_mail_folder_info_t +{ + MB_String name; + MB_String attributes; + MB_String delimiter; +}; + +struct esp_mail_folder_info_item_t +{ + /* The name of folder */ + const char *name = ""; + + /* The attributes of folder */ + const char *attributes = ""; + + /* The delimeter of folder */ + const char *delimiter = ""; +}; + +struct esp_mail_imap_download_config_t +{ + /* To download the PLAIN text content of the message */ + bool text = false; + + /* To download the HTML content of the message */ + bool html = false; + + /* To download the attachments of the message */ + bool attachment = false; + + /* To download the inline image of the message */ + bool inlineImg = false; + + /* To download the rfc822 mesages in the message */ + bool rfc822 = false; + + /* To download the message header */ + bool header = false; +}; + +struct esp_mail_imap_enable_config_t +{ + /* To store the PLAIN text of the message in the IMAPSession */ + bool text = false; + + /* To store the HTML of the message in the IMAPSession */ + bool html = false; + + /* To store the rfc822 messages in the IMAPSession */ + bool rfc822 = false; + + /* To enable the download status via the serial port */ + bool download_status = false; + + /* To sort the message UID of the search result in descending order */ + bool recent_sort = false; + + /* To allow case sesitive in header parsing */ + bool header_case_sensitive = false; +}; + +struct esp_mail_imap_limit_config_t +{ + /* The maximum messages from the search result */ + size_t search = 10; + + /* The maximum messages from the sequence set fetching result */ + size_t fetch = 30; + + /** The maximum size of the memory buffer to store the message content. + * This is only limit for data to be stored in the IMAPSession. + */ + size_t msg_size = 1024; + + /* The maximum size of each attachment to download */ + size_t attachment_size = 1024 * 1024 * 5; + + /* The IMAP idle timeout in ms (1 min to 29 min). Default is 8 min */ + size_t imap_idle_timeout = 8 * 60 * 1000; + + /** The IMAP idle host check interval in ms (30 sec to imap_idle_timeout) + * for internet availability checking to ensure the connection is active. + * Default is 1 min. + */ + size_t imap_idle_host_check_interval = 60 * 1000; +}; + +struct esp_mail_imap_storage_config_t +{ + /* The path to save the downloaded file */ + MB_String saved_path; + + /** The type of file storages e.g. + * esp_mail_file_storage_type_none, + * esp_mail_file_storage_type_flash, and + * esp_mail_file_storage_type_sd + */ + esp_mail_file_storage_type type = esp_mail_file_storage_type_flash; +}; + +struct esp_mail_imap_search_config_t +{ + /* The search criteria */ + MB_String criteria; + + /* The option to search the unseen message */ + bool unseen_msg = false; +}; + +struct esp_mail_imap_sequence_set_t +{ + /* The sequence set string i.g., unique identifier (UID) or message sequence number or ranges of UID or sequence number */ + MB_String string; + + /* The option for sequenceSet whether it is UID or message sequence number */ + bool UID = false; + + /* The option for header only fetching */ + bool headerOnly = false; +}; + +struct esp_mail_imap_fetch_config_t +{ + /* The UID of message to fetch */ + MB_String uid; + + /* The message sequence number to fetch */ + MB_String number; + + /* The sequence set options */ + esp_mail_imap_sequence_set_t sequence_set; + + /* Set the message flag as seen */ + bool set_seen = false; + + /* The int32_t option for CHANGESINCE conditional test. */ + int32_t modsequence = 0; + + /* The config to fetch only the header */ + bool headerOnly = false; +}; + +struct esp_mail_imap_firmware_config_t +{ + /* Update firmware using message attachments if one of its filename matches. */ + MB_String attach_filename; + + /* Save firmware file */ + bool save_to_file = false; +}; + +struct esp_mail_imap_data_config_t +{ + /* The config for fetching */ + struct esp_mail_imap_fetch_config_t fetch; + + /* The config for search */ + struct esp_mail_imap_search_config_t search; + + /* The config about the limits */ + struct esp_mail_imap_limit_config_t limit; + + /* The config to enable the features */ + struct esp_mail_imap_enable_config_t enable; + + /* The config about downloads */ + struct esp_mail_imap_download_config_t download; + + /* The config about the storage and path to save the downloaded file */ + struct esp_mail_imap_storage_config_t storage; + + /* The config about firmware updates and downloads for ESP32, ESP8266 and Raspberry Pi Pico */ + struct esp_mail_imap_firmware_config_t firmware_update; + + IMAP_Identification identification; +}; + +/* Mail and MIME Header Fields */ +struct esp_mail_imap_msg_item_t +{ + friend class IMAPSession; + +public: + esp_mail_imap_msg_item_t() + { + text.content_type = mimeinfo[esp_mail_file_extension_txt].mimeType; + html.content_type = mimeinfo[esp_mail_file_extension_html].mimeType; + }; + + /* The message number */ + int msgNo = 0; + + /* The message UID */ + int UID = 0; + + /* The message identifier (RFC 4021) */ + const char *ID = ""; + + /* The language(s) for auto-responses (RFC 4021) */ + const char *acceptLang = ""; + + /* The language of message content (RFC 4021) */ + const char *contentLang = ""; + + /* The mailbox of message author (RFC 4021) */ + const char *from = ""; + + /* The charset of the mailbox of message author */ + // deprecated + const char *fromCharset = ""; + + /* The primary recipient mailbox (RFC 4021) */ + const char *to = ""; + + /* The charset of the primary recipient mailbox */ + // deprecated + const char *toCharset = ""; + + /* The Carbon-copy recipient mailboxes (RFC 4021) */ + const char *cc = ""; + + /* The charset of the Carbon-copy recipient mailbox header */ + // deprecated + const char *ccCharset = ""; + + /* The Blind-carbon-copy recipient mailboxes (RFC 4021) */ + const char *bcc = ""; + + /* The charset of the Blind-carbon-copy recipient mailbox header */ + // deprecated + const char *bccCharset = ""; + + /* The message date and time (RFC 4021) */ + const char *date = ""; + + /* The topic of message (RFC 4021) */ + const char *subject = ""; + + /* The topic of message charset */ + // deprecated + const char *subjectCharset = ""; + + /* The message flags */ + const char *flags = ""; + + /* The PLAIN text content of the message */ + esp_mail_imap_plain_body_t text; + + /* The HTML content of the message */ + esp_mail_imap_html_body_t html; + + /* rfc822 related */ + + /* The sender Email */ + const char *sender; + + /* The charset of the sender Email */ + // deprecated + const char *senderCharset = ""; + + /* The keywords or phrases, separated by commas */ + const char *keywords = ""; + + /* The comments about message */ + const char *comments = ""; + + /* The field that contains the parent's message ID of the message to which this one is a reply */ + const char *in_reply_to = ""; + + /* The field that contains the parent's references (if any) and followed by the parent's message ID (if any) of the message to which this one is a reply */ + const char *references = ""; + + /* The return recipient of the message */ + const char *return_path = ""; + + /* The Email address to reply */ + const char *reply_to; + + /* The error description from fetching the message */ + const char *fetchError = ""; + + /* The info about the attachments in the message */ + _vectorImpl attachments; + + /* The info about the rfc822 messages included in the message */ + _vectorImpl rfc822; + + /* The status for message that contains attachment */ + bool hasAttachment = false; + +private: + void setRFC822Headers(struct esp_mail_imap_rfc822_msg_header_item_t *rfc822_header) + { + from = rfc822_header->header_items[esp_mail_rfc822_header_field_from].c_str(); + sender = rfc822_header->header_items[esp_mail_rfc822_header_field_sender].c_str(); + to = rfc822_header->header_items[esp_mail_rfc822_header_field_to].c_str(); + cc = rfc822_header->header_items[esp_mail_rfc822_header_field_cc].c_str(); + subject = rfc822_header->header_items[esp_mail_rfc822_header_field_subject].c_str(); + date = rfc822_header->header_items[esp_mail_rfc822_header_field_date].c_str(); + ID = rfc822_header->header_items[esp_mail_rfc822_header_field_msg_id].c_str(); + return_path = rfc822_header->header_items[esp_mail_rfc822_header_field_return_path].c_str(); + reply_to = rfc822_header->header_items[esp_mail_rfc822_header_field_reply_to].c_str(); + in_reply_to = rfc822_header->header_items[esp_mail_rfc822_header_field_in_reply_to].c_str(); + references = rfc822_header->header_items[esp_mail_rfc822_header_field_references].c_str(); + comments = rfc822_header->header_items[esp_mail_rfc822_header_field_comments].c_str(); + keywords = rfc822_header->header_items[esp_mail_rfc822_header_field_keywords].c_str(); + bcc = rfc822_header->header_items[esp_mail_rfc822_header_field_bcc].c_str(); + flags = rfc822_header->header_items[esp_mail_rfc822_header_field_flags].c_str(); + text.charSet = ""; + text.content_type = ""; + text.transfer_encoding = ""; + html.charSet = ""; + html.content_type = ""; + html.transfer_encoding = ""; + } +}; + +struct esp_mail_imap_msg_list_t +{ + /* The info of a message */ + _vectorImpl msgItems; +}; + +struct esp_mail_imap_multipart_level_t +{ + uint8_t level = 0; + bool fetch_rfc822_header = false; + bool append_body_text = false; +}; + +struct esp_mail_imap_response_data +{ +public: + esp_mail_imap_response_status imapResp = esp_mail_imap_resp_unknown; + char *response = nullptr; + int readLen = 0; + long dataTime = millis(); + int chunkBufSize = 512; + int chunkIdx = 0; + bool isUntaggedResponse = false; + bool untaggedRespCompleted = false; + bool completedResponse = false; + bool endSearch = false; + struct esp_mail_message_header_t header; + struct esp_mail_message_part_info_t part; + MB_String filePath; + bool downloadRequest = false; + int octetCount = 0; + int octetLength = 0; + bool tmo = false; + int headerState = 0; + int searchCount = 0; + char *lastBuf = nullptr; + char *buf = nullptr; + + esp_mail_imap_response_data(int bufLen) { chunkBufSize = bufLen; }; + ~esp_mail_imap_response_data() { clear(); } + void clear() + { + if (response) + free(response); + if (lastBuf) + free(lastBuf); + if (buf) + free(buf); + + response = nullptr; + lastBuf = nullptr; + buf = nullptr; + } +}; + +#endif + +#if defined(ENABLE_SMTP) || defined(ENABLE_IMAP) + +struct esp_mail_link_internal_t +{ + MB_String cid; +}; + +struct esp_mail_sesson_cert_config_t +{ + /* The certificate data (base64 data) */ + const char *cert_data = NULL; + + /* The certificate file (DER format) */ + MB_String cert_file; + + /* The storage type */ + esp_mail_file_storage_type cert_file_storage_type; + + /* The cerificate verification option */ + bool verify = false; +}; + +struct esp_mail_smtp_logs_config_t +{ + + /* The log file path */ + MB_String filename; + + /* The storage type */ + esp_mail_file_storage_type storage_type; +}; + +struct esp_mail_sesson_sever_config_t +{ + /* The hostName of the server */ + MB_String host_name; + /* The port on the server to connect to */ + uint16_t port = 0; +}; + +/* The log in credentials */ +struct esp_mail_sesson_login_config_t +{ + /* The user Email address to log in */ + MB_String email; + + /* The user password to log in */ + MB_String password; + + /* The OAuth2.0 access token to log in */ + MB_String accessToken; + + /* The host name or public IP of client system */ + MB_String user_domain; +}; + +/* The device time config */ +struct esp_mail_sesson_time_config_t +{ + /* set the NTP servers (use comma to separate the servers) to let the library to set the time from NTP server */ + MB_String ntp_server; + + /* the GMT offset or time zone */ + float gmt_offset = 0; + + /* the day light saving offset */ + float day_light_offset = 0; + + /** TZ environment variable for local time setting + * See https://github.com/nayarsystems/posix_tz_db/blob/master/zones.csv + */ + MB_String timezone_env_string; + + /* the file path to store TZ environment variable */ + MB_String timezone_file = "/tze.txt"; +}; + +struct esp_mail_sesson_secure_config_t +{ + /** The option (obsoleted) to send the SMTP and IMAP commands to start the TLS connection rfc2595 section 3 and rfc3207 */ + bool startTLS = false; + + /* The secure connection mode preference */ + esp_mail_secure_mode mode = esp_mail_secure_mode_undefined; +}; + +struct esp_mail_spi_ethernet_module_t +{ +#if defined(ESP8266) && defined(ESP8266_CORE_SDK_V3_X_X) +#ifdef INC_ENC28J60_LWIP + ENC28J60lwIP *enc28j60 = nullptr; +#endif +#ifdef INC_W5100_LWIP + Wiznet5100lwIP *w5100 = nullptr; +#endif +#ifdef INC_W5500_LWIP + Wiznet5500lwIP *w5500 = nullptr; +#endif +#elif defined(MB_ARDUINO_PICO) + +#endif +}; + +struct esp_mail_session_config_t +{ + friend class IMAPSession; + friend class SMTPSession; + friend class ESP_Mail_Client; + + /* The server config */ + struct esp_mail_sesson_sever_config_t server; + + /* The log in config */ + struct esp_mail_sesson_login_config_t login; + + /* The device time config */ + struct esp_mail_sesson_time_config_t time; + + /* The secure config */ + struct esp_mail_sesson_secure_config_t secure; + + /* The certificate config */ + struct esp_mail_sesson_cert_config_t certificate; + + /* SPI Ethernet Module config for ESP8266 */ + struct esp_mail_spi_ethernet_module_t spi_ethernet_module; + + /* The callback function for WiFi connection */ + NetworkConnectionHandler network_connection_handler = NULL; + + /* specific ports and its protocols */ + struct esp_mail_ports_functions ports_functions; + + /* The mail sending logs config */ + struct esp_mail_smtp_logs_config_t sentLogs; + +public: + esp_mail_session_config_t(){}; + + ~esp_mail_session_config_t() + { + clear(); + aremovePtr(); + } + + void addPtr(_vectorImpl *listPtr, int ptr) + { + if (listPtr) + { + this->listPtr = listPtr; + bool existed = false; + + for (size_t i = 0; i < this->listPtr->size(); i++) + { + if ((*this->listPtr)[i] == ptr) + existed = true; + } + + if (!existed) + this->listPtr->push_back(ptr); + } + } + + void aremovePtr() + { + if (listPtr) + { + int ptr = toAddr(*this); + for (size_t i = 0; i < listPtr->size(); i++) + { + if ((*listPtr)[i] == ptr) + { + listPtr->erase(listPtr->begin() + i, listPtr->begin() + i + 1); + break; + } + } + } + } + + void clear() + { + server.host_name.clear(); + server.port = 0; + + secure.startTLS = false; + secure.mode = esp_mail_secure_mode_undefined; + + login.email.clear(); + login.password.clear(); + login.user_domain.clear(); + login.accessToken.clear(); + + time.day_light_offset = 0; + time.gmt_offset = 0; + time.ntp_server.clear(); + time.timezone_env_string.clear(); + + certificate.cert_data = ""; + certificate.cert_file = ""; + certificate.cert_file_storage_type = esp_mail_file_storage_type_none; + certificate.verify = false; + + clearPorts(); + } + +private: + int cert_ptr = 0; + bool cert_updated = false; + _vectorImpl *listPtr = nullptr; + + // Internal flags use to keep user sercure.startTLS and secure.mode. + bool int_start_tls = false; + esp_mail_secure_mode int_mode = esp_mail_secure_mode_undefined; + + void clearPorts() + { + if (ports_functions.list) + { + if (ports_functions.use_internal_list) + { + ports_functions.size = 0; + ports_functions.use_internal_list = false; + delete[] ports_functions.list; + ports_functions.list = nullptr; + } + } + } +}; + +/** The content transfer encoding + * enc_7bit or "7bit" + * enc_qp or "quoted-printable" + * enc_base64 or "base64" + * enc_binary or "binary" + * enc_8bit or "8bit" + */ +typedef struct esp_mail_transfer_encoding_t Content_Transfer_Encoding; + +/* The session configuations */ +typedef struct esp_mail_session_config_t ESP_Mail_Session; // obsoleted +typedef struct esp_mail_session_config_t Session_Config; + +#endif + +#if defined(ENABLE_SMTP) +/* The result from sending the Email */ +typedef struct esp_mail_smtp_send_status_t SMTP_Result; + +/* The attachment details for sending the Email */ +typedef struct esp_mail_attachment_t SMTP_Attachment; +#endif + +#if defined(ENABLE_SMTP) && defined(ENABLE_IMAP) + +typedef struct esp_mail_attachment_t ESP_Mail_Attachment; + +#endif + +#if defined(ENABLE_IMAP) +/* The info of the selected or open mailbox folder e.g. name, attributes and + * delimiter */ +typedef struct esp_mail_folder_info_item_t FolderInfo; +/* The attachment item details for a message which returned from fetching the + * Email */ +typedef struct esp_mail_attachment_info_t IMAP_Attach_Item; + +/** The IMAP operation configuations */ +typedef struct esp_mail_imap_data_config_t IMAP_Config; // obsoleted + +typedef struct esp_mail_imap_data_config_t IMAP_Data; + +/* The message item data of the IMAP_MSG_List which contains header, body and + * attachments info for eacch message*/ +typedef struct esp_mail_imap_msg_item_t IMAP_MSG_Item; + +/* The list that contains the message items from searching or fetching the Email + */ +typedef struct esp_mail_imap_msg_list_t IMAP_MSG_List; + +#endif + +struct esp_mail_wifi_credential_t +{ + MB_String ssid; + MB_String password; +}; + +struct esp_mail_wifi_credentials_t +{ + friend class ESP_Mail_Client; + friend class ESP_Mail_TCPClient; + +public: + esp_mail_wifi_credentials_t(){}; + ~esp_mail_wifi_credentials_t() + { + clearAP(); + clearMulti(); + }; + void addAP(const String &ssid, const String &password) + { + esp_mail_wifi_credential_t cred; + cred.ssid = ssid; + cred.password = password; + credentials.push_back(cred); + } + void clearAP() + { + credentials.clear(); + } + +private: + _vectorImpl credentials; +#if defined(ESP_MAIL_HAS_WIFIMULTI) + WiFiMulti *multi = nullptr; +#endif + + void reconnect() + { + if (credentials.size()) + { + disconnect(); + connect(); + } + } + + void connect() + { +#if defined(ESP_MAIL_HAS_WIFIMULTI) + + clearMulti(); + multi = new WiFiMulti(); + for (size_t i = 0; i < credentials.size(); i++) + multi->addAP(credentials[i].ssid.c_str(), credentials[i].password.c_str()); + + if (credentials.size() > 0) + multi->run(); + +#elif defined(ESP_MAIL_WIFI_IS_AVAILABLE) + WiFi.begin((CONST_STRING_CAST)credentials[0].ssid.c_str(), credentials[0].password.c_str()); +#endif + } + + void disconnect() + { +#if defined(ESP_MAIL_WIFI_IS_AVAILABLE) + WiFi.disconnect(); +#endif + } + + void clearMulti() + { +#if defined(ESP_MAIL_HAS_WIFIMULTI) + if (multi) + delete multi; + multi = nullptr; +#endif + } +}; + +static const char esp_mail_imap_tag_str[] PROGMEM = "xmail"; + +#if !defined(SILENT_MODE) +static const char esp_mail_version_str[] PROGMEM = "ESP Mail Client v"; + +///////////////////////// +// SMTP debug string + +static const char esp_mail_dbg_str_1[] PROGMEM = "send command, STARTTLS"; +static const char esp_mail_dbg_str_2[] PROGMEM = "connecting to SMTP server"; + +#if defined(ENABLE_SMTP) +static const char esp_mail_dbg_str_3[] PROGMEM = "send Email"; +static const char esp_mail_dbg_str_4[] PROGMEM = "SMTP server connected"; +static const char esp_mail_dbg_str_5[] PROGMEM = "send SMTP command, EHLO"; +static const char esp_mail_dbg_str_6[] PROGMEM = "send SMTP command, AUTH LOGIN"; +static const char esp_mail_dbg_str_7[] PROGMEM = "send SMTP command, AUTH PLAIN"; +static const char esp_mail_dbg_str_8[] PROGMEM = "send message header"; +static const char esp_mail_dbg_str_9[] PROGMEM = "send message body"; +static const char esp_mail_dbg_str_10[] PROGMEM = "send attachments"; +static const char esp_mail_dbg_str_11[] PROGMEM = "terminate the SMTP session"; +static const char esp_mail_dbg_str_12[] PROGMEM = "message sent successfully"; +static const char esp_mail_dbg_str_13[] PROGMEM = "send next Email"; +static const char esp_mail_dbg_str_14[] PROGMEM = "send inline data"; +static const char esp_mail_dbg_str_15[] PROGMEM = "send smtp command, AUTH XOAUTH2"; +static const char esp_mail_dbg_str_16[] PROGMEM = "finishing the message sending"; +static const char esp_mail_dbg_str_17[] PROGMEM = "No ESMTP supported, send SMTP command, HELO"; +#endif + +///////////////////////// +// IMAP debug string +static const char esp_mail_dbg_str_18[] PROGMEM = "connecting to IMAP server"; +static const char esp_mail_dbg_str_19[] PROGMEM = "Host > "; +static const char esp_mail_dbg_str_20[] PROGMEM = "Port > "; +static const char esp_mail_dbg_str_21[] PROGMEM = "Reading time from NTP server"; +static const char esp_mail_dbg_str_22[] PROGMEM = "perform SSL/TLS handshake"; + +#if defined(ENABLE_IMAP) +static const char esp_mail_dbg_str_23[] PROGMEM = "get my ACL"; +static const char esp_mail_dbg_str_24[] PROGMEM = "checking the capability"; +static const char esp_mail_dbg_str_25[] PROGMEM = "fetching message "; +static const char esp_mail_dbg_str_26[] PROGMEM = "fetch message header"; +static const char esp_mail_dbg_str_27[] PROGMEM = "fetch body part header, "; +static const char esp_mail_dbg_str_28[] PROGMEM = "fetch body sub part header, "; +static const char esp_mail_dbg_str_29[] PROGMEM = "finished reading Email"; +static const char esp_mail_dbg_str_30[] PROGMEM = "UID is "; +static const char esp_mail_dbg_str_31[] PROGMEM = "log out completed"; +static const char esp_mail_dbg_str_32[] PROGMEM = "closing the "; +static const char esp_mail_dbg_str_33[] PROGMEM = "IMAP server connected"; +static const char esp_mail_dbg_str_34[] PROGMEM = "send IMAP command, LOGIN"; +static const char esp_mail_dbg_str_35[] PROGMEM = "send IMAP command, LIST"; +static const char esp_mail_dbg_str_36[] PROGMEM = "searching messages"; +static const char esp_mail_dbg_str_37[] PROGMEM = "send IMAP command, FETCH"; +static const char esp_mail_dbg_str_38[] PROGMEM = "send IMAP command, LOGOUT"; +static const char esp_mail_dbg_str_39[] PROGMEM = "message fetching completed"; +static const char esp_mail_dbg_str_40[] PROGMEM = "opening the mailbox folder"; +static const char esp_mail_dbg_str_41[] PROGMEM = "setting FLAG"; +static const char esp_mail_dbg_str_42[] PROGMEM = "adding FLAG"; +static const char esp_mail_dbg_str_43[] PROGMEM = "removing FLAG"; +static const char esp_mail_dbg_str_44[] PROGMEM = "send IMAP command, AUTHENTICATE PLAIN"; +static const char esp_mail_dbg_str_45[] PROGMEM = "send IMAP command, AUTH XOAUTH2"; +static const char esp_mail_dbg_str_46[] PROGMEM = "reading plain TEXT message"; +static const char esp_mail_dbg_str_47[] PROGMEM = "reading HTML message"; +static const char esp_mail_dbg_str_48[] PROGMEM = "copying message(s) to "; +static const char esp_mail_dbg_str_49[] PROGMEM = "creating folder"; +static const char esp_mail_dbg_str_50[] PROGMEM = "deleting folder"; +static const char esp_mail_dbg_str_51[] PROGMEM = "listening to "; +static const char esp_mail_dbg_str_52[] PROGMEM = " folder changes"; +static const char esp_mail_dbg_str_53[] PROGMEM = "polling established"; +static const char esp_mail_dbg_str_54[] PROGMEM = "Mailbox listening stopped"; +static const char esp_mail_dbg_str_55[] PROGMEM = "renaming folder"; +static const char esp_mail_dbg_str_56[] PROGMEM = "send IMAP command, LSUB"; +static const char esp_mail_dbg_str_57[] PROGMEM = "send IMAP command, SUBSCRIBE"; +static const char esp_mail_dbg_str_58[] PROGMEM = "send IMAP command, UNSUBSCRIBE"; +static const char esp_mail_dbg_str_59[] PROGMEM = "moving message(s) to "; +static const char esp_mail_dbg_str_60[] PROGMEM = "send IMAP command, GETQUOTA"; +static const char esp_mail_dbg_str_61[] PROGMEM = "send IMAP command, SETQUOTA"; +static const char esp_mail_dbg_str_62[] PROGMEM = "send IMAP command, GETQUOTAROOT"; +static const char esp_mail_dbg_str_63[] PROGMEM = "send IMAP command, GETACL"; +static const char esp_mail_dbg_str_64[] PROGMEM = "send IMAP command, SETACL"; +static const char esp_mail_dbg_str_65[] PROGMEM = "send IMAP command, DELETEACL"; +static const char esp_mail_dbg_str_66[] PROGMEM = "send IMAP command, MYRIGHTS"; +static const char esp_mail_dbg_str_67[] PROGMEM = "send IMAP command, NAMESPACE"; +static const char esp_mail_dbg_str_68[] PROGMEM = "selecting the "; +static const char esp_mail_dbg_str_69[] PROGMEM = "appending message"; +static const char esp_mail_dbg_str_70[] PROGMEM = "download attachment %d of %d"; +static const char esp_mail_dbg_str_71[] PROGMEM = "download HTML message"; +static const char esp_mail_dbg_str_72[] PROGMEM = "deleting the ACL"; +static const char esp_mail_dbg_str_73[] PROGMEM = "message append successfully"; +static const char esp_mail_dbg_str_74[] PROGMEM = "download plain TEXT message"; +static const char esp_mail_dbg_str_75[] PROGMEM = "deleting message(s)"; +static const char esp_mail_dbg_str_76[] PROGMEM = "check the capability"; +static const char esp_mail_dbg_str_77[] PROGMEM = "get the ACL"; +static const char esp_mail_dbg_str_78[] PROGMEM = "set the ACL"; +static const char esp_mail_dbg_str_79[] PROGMEM = "get UID"; +static const char esp_mail_dbg_str_80[] PROGMEM = "get Flags"; +static const char esp_mail_dbg_str_81[] PROGMEM = "delete folder"; +static const char esp_mail_dbg_str_82[] PROGMEM = "send IMAP command, ID"; +static const char esp_mail_dbg_str_83[] PROGMEM = "send IMAP command, NOOP"; +#endif + +///////////////////////// +// SMTP callback string + +static const char esp_mail_cb_str_1[] PROGMEM = "Connecting to SMTP server..."; +static const char esp_mail_cb_str_2[] PROGMEM = "Sending STARTTLS command..."; + +#if defined(ENABLE_SMTP) +static const char esp_mail_cb_str_3[] PROGMEM = "Sending greeting response..."; +static const char esp_mail_cb_str_4[] PROGMEM = "Sending message header..."; +static const char esp_mail_cb_str_5[] PROGMEM = "Sending message body..."; +static const char esp_mail_cb_str_6[] PROGMEM = "Sending attachments..."; +static const char esp_mail_cb_str_7[] PROGMEM = "Closing the session..."; +static const char esp_mail_cb_str_8[] PROGMEM = "Sending inline data..."; +static const char esp_mail_cb_str_9[] PROGMEM = "Sending Email..."; +static const char esp_mail_cb_str_10[] PROGMEM = "Sending next Email..."; +static const char esp_mail_cb_str_11[] PROGMEM = "Finishing the message sending..."; +static const char esp_mail_cb_str_12[] PROGMEM = "SMTP server connected, wait for greeting..."; +static const char esp_mail_cb_str_13[] PROGMEM = "Message sent successfully"; +#endif + +///////////////////////// +// IMAP callback string + +static const char esp_mail_cb_str_14[] PROGMEM = "Logging in..."; // shared with SMTP +static const char esp_mail_cb_str_15[] PROGMEM = "Connecting to IMAP server..."; + +#if defined(ENABLE_IMAP) + +static const char esp_mail_cb_str_16[] PROGMEM = "Reading the list of mailboxes..."; +static const char esp_mail_cb_str_17[] PROGMEM = "Checking the capability..."; +static const char esp_mail_cb_str_18[] PROGMEM = "Searching messages..."; +static const char esp_mail_cb_str_19[] PROGMEM = "Downloading attachments..."; +static const char esp_mail_cb_str_20[] PROGMEM = "Logging out..."; +static const char esp_mail_cb_str_21[] PROGMEM = "Saving message header to file..."; +static const char esp_mail_cb_str_22[] PROGMEM = "Get FLAG..."; +static const char esp_mail_cb_str_23[] PROGMEM = "Removing FLAG..."; +static const char esp_mail_cb_str_24[] PROGMEM = "Adding FLAG..."; +static const char esp_mail_cb_str_25[] PROGMEM = "Get UID..."; +static const char esp_mail_cb_str_26[] PROGMEM = "Setting FLAG..."; +static const char esp_mail_cb_str_27[] PROGMEM = "Closing the mailbox folder..."; +static const char esp_mail_cb_str_28[] PROGMEM = "Reading messages..."; +static const char esp_mail_cb_str_29[] PROGMEM = "Listening to mailbox changes..."; +static const char esp_mail_cb_str_30[] PROGMEM = "Listing the subscribed mailboxes..."; +static const char esp_mail_cb_str_31[] PROGMEM = "Subscribe mailbox..."; +static const char esp_mail_cb_str_32[] PROGMEM = "Unsubscribe mailbox..."; +static const char esp_mail_cb_str_33[] PROGMEM = "Get quota root resource usage and limit..."; +static const char esp_mail_cb_str_34[] PROGMEM = "Set quota root resource usage and limit..."; +static const char esp_mail_cb_str_35[] PROGMEM = "Get the list of quota roots..."; +static const char esp_mail_cb_str_36[] PROGMEM = "Get the ACL..."; +static const char esp_mail_cb_str_37[] PROGMEM = "Setting the ACL..."; +static const char esp_mail_cb_str_38[] PROGMEM = "Deleting the ACL..."; +static const char esp_mail_cb_str_39[] PROGMEM = "Get my ACL..."; +static const char esp_mail_cb_str_40[] PROGMEM = "Get namespace..."; +static const char esp_mail_cb_str_41[] PROGMEM = "Enable capability..."; +static const char esp_mail_cb_str_42[] PROGMEM = "Updating firmware..."; +static const char esp_mail_cb_str_43[] PROGMEM = "Downloading messages..."; +static const char esp_mail_cb_str_44[] PROGMEM = "Appending message..."; +static const char esp_mail_cb_str_45[] PROGMEM = "Message append successfully"; +static const char esp_mail_cb_str_46[] PROGMEM = "Finished reading Email"; +static const char esp_mail_cb_str_47[] PROGMEM = "Log out completed"; +static const char esp_mail_cb_str_48[] PROGMEM = "IMAP server connected"; +static const char esp_mail_cb_str_49[] PROGMEM = "Polling established"; +static const char esp_mail_cb_str_50[] PROGMEM = "Mailbox listening stopped"; +static const char esp_mail_cb_str_51[] PROGMEM = "Open the mailbox folder..."; +static const char esp_mail_cb_str_52[] PROGMEM = "Checking the capability..."; +static const char esp_mail_cb_str_53[] PROGMEM = "Renaming folder..."; +static const char esp_mail_cb_str_54[] PROGMEM = "UID is "; +static const char esp_mail_cb_str_55[] PROGMEM = "Get Flags..."; +static const char esp_mail_cb_str_56[] PROGMEM = "Deleting folder..."; +static const char esp_mail_cb_str_57[] PROGMEM = "Deleting message(s)..."; +static const char esp_mail_cb_str_58[] PROGMEM = "Copying message(s)..."; +static const char esp_mail_cb_str_59[] PROGMEM = "Creating folder..."; +static const char esp_mail_cb_str_60[] PROGMEM = "Moving message(s)..."; +static const char esp_mail_cb_str_61[] PROGMEM = "Send client identification..."; +static const char esp_mail_cb_str_62[] PROGMEM = "Send noop..."; +#endif + +#endif + +///////////////////////// +// Mem error string + +#if defined(ENABLE_ERROR_STRING) || !defined(SILENT_MODE) +#if defined(MBFS_FLASH_FS) || defined(MBFS_SD_FS) +static const char esp_mail_error_mem_str_1[] PROGMEM = "flash Storage is not ready."; +static const char esp_mail_error_mem_str_2[] PROGMEM = "SD Storage is not ready."; +static const char esp_mail_error_mem_str_3[] PROGMEM = "file does not exist or can't access"; +#endif +static const char esp_mail_error_mem_str_4[] PROGMEM = "PSRAM was enabled but not detected."; +#endif + +#if defined(ENABLE_ERROR_STRING) + +#if defined(MBFS_FLASH_FS) || defined(MBFS_SD_FS) +static const char esp_mail_error_mem_str_5[] PROGMEM = "file is still opened."; +static const char esp_mail_error_mem_str_6[] PROGMEM = "file not found."; +static const char esp_mail_error_mem_str_7[] PROGMEM = "file I/O error"; +#endif + +static const char esp_mail_error_mem_str_8[] PROGMEM = "out of memory"; +static const char esp_mail_error_mem_str_9[] PROGMEM = "buffer overflow"; + +#endif + +#if defined(MB_ARDUINO_PICO) +#if defined(ENABLE_ERROR_STRING) || !defined(SILENT_MODE) +static const char esp_mail_error_mem_str_10[] PROGMEM = "please make sure that the size of flash filesystem is not 0 in Pico."; +#endif +#endif + +///////////////////////// +// Client error string + +#if !defined(SILENT_MODE) +static const char esp_mail_error_client_str_1[] PROGMEM = "client and/or necessary callback functions are not yet assigned"; +static const char esp_mail_error_client_str_2[] PROGMEM = "network connection callback is required"; +static const char esp_mail_error_client_str_3[] PROGMEM = "network connection status callback is required"; +static const char esp_mail_error_client_str_4[] PROGMEM = "NTP server time reading cannot begin when valid time is required because of no WiFi capability/activity detected."; +static const char esp_mail_error_client_str_5[] PROGMEM = "Please set the library reference time manually using smtp.setSystemTime or imap.setSystemTime."; +#endif + +///////////////////////// +// Network error string + +#if !defined(SILENT_MODE) +static const char esp_mail_error_network_str_1[] PROGMEM = "unable to connect to server"; +#if defined(ENABLE_ERROR_STRING) +static const char esp_mail_error_network_str_2[] PROGMEM = "NTP server time reading timed out"; +static const char esp_mail_error_network_str_3[] PROGMEM = "response read timed out"; +static const char esp_mail_error_network_str_4[] PROGMEM = "not connected"; +static const char esp_mail_error_network_str_5[] PROGMEM = "connection timeout"; +static const char esp_mail_error_network_str_6[] PROGMEM = "connection closed"; +static const char esp_mail_error_network_str_7[] PROGMEM = "connection refused"; +static const char esp_mail_error_network_str_8[] PROGMEM = "data sending failed"; +#endif +#endif + +#if defined(ENABLE_ERROR_STRING) || !defined(SILENT_MODE) +static const char esp_mail_error_network_str_9[] PROGMEM = "response read timed out"; +#endif + +///////////////////////// +// SSL error string + +#if defined(ENABLE_ERROR_STRING) +static const char esp_mail_error_ssl_str_1[] PROGMEM = "fail to set up the SSL/TLS structure"; +#endif +#if defined(ENABLE_ERROR_STRING) || !defined(SILENT_MODE) +static const char esp_mail_error_ssl_str_2[] PROGMEM = "the alert SSL record received"; +static const char esp_mail_error_ssl_str_3[] PROGMEM = "make sure the SSL/TLS handshake was done before sending the data"; +#endif + +///////////////////////// +// Auth error string + +#if defined(ENABLE_ERROR_STRING) +static const char esp_mail_error_auth_str_1[] PROGMEM = "the provided SASL authentication mechanism is not support"; +static const char esp_mail_error_auth_str_2[] PROGMEM = "OAuth2.0 log in was disabled for this server"; +static const char esp_mail_error_auth_str_3[] PROGMEM = "not yet log in"; +#endif + +///////////////////////// +// Session error string + +#if defined(ENABLE_ERROR_STRING) +static const char esp_mail_error_session_str_1[] PROGMEM = "the Session_Config object was not assigned"; +#endif + +///////////////////////// +// Time error string +#if defined(ENABLE_ERROR_STRING) +static const char esp_mail_error_time_str_1[] PROGMEM = "library or device time was not set, see examples/SMTP/Set_Time.ino for manually time setting"; +#endif + +///////////////////////// +// SMTP error string +#if defined(ENABLE_SMTP) +#if defined(ENABLE_ERROR_STRING) +static const char esp_mail_error_smtp_str_1[] PROGMEM = "SMTP server greeting failed"; +static const char esp_mail_error_smtp_str_2[] PROGMEM = "authentication failed"; +static const char esp_mail_error_smtp_str_3[] PROGMEM = "login password is not valid"; +static const char esp_mail_error_smtp_str_4[] PROGMEM = "send header failed"; +static const char esp_mail_error_smtp_str_5[] PROGMEM = "send body failed"; +static const char esp_mail_error_smtp_str_7[] PROGMEM = "sender Email address is not valid"; +static const char esp_mail_error_smtp_str_8[] PROGMEM = "some of the recipient Email address is not valid"; +static const char esp_mail_error_smtp_str_9[] PROGMEM = "set recipient failed"; +static const char esp_mail_error_smtp_str_10[] PROGMEM = "send custom command failed"; +static const char esp_mail_error_smtp_str_11[] PROGMEM = "XOAuth2 authenticate failed"; +static const char esp_mail_error_smtp_str_12[] PROGMEM = "undefined error"; +#endif +#endif + +///////////////////////// +// IMAP error string +#if defined(ENABLE_IMAP) +#if defined(ENABLE_ERROR_STRING) +static const char esp_mail_error_imap_str_1[] PROGMEM = "fail to list the mailboxes"; +static const char esp_mail_error_imap_str_2[] PROGMEM = "fail to check the capabilities"; + +static const char esp_mail_error_imap_str_3[] PROGMEM = "fail to close the mailbox"; + +static const char esp_mail_error_imap_str_4[] PROGMEM = "fail to open the mailbox"; +static const char esp_mail_error_imap_str_5[] PROGMEM = "some of the requested messages no longer exist"; +static const char esp_mail_error_imap_str_6[] PROGMEM = "firmware update initialization failed"; +static const char esp_mail_error_imap_str_7[] PROGMEM = "firmware update write failed"; +static const char esp_mail_error_imap_str_8[] PROGMEM = "firmware update finalize failed"; + +#endif +#if defined(ENABLE_ERROR_STRING) || !defined(SILENT_MODE) +static const char esp_mail_error_imap_str_9[] PROGMEM = "no messages found for the specified search criteria"; +static const char esp_mail_error_imap_str_10[] PROGMEM = "no search criteria provided, then fetching the latest message"; +static const char esp_mail_error_imap_str_11[] PROGMEM = "no mailbox opened"; +static const char esp_mail_error_imap_str_12[] PROGMEM = "no content"; +static const char esp_mail_error_imap_str_13[] PROGMEM = "this feature was not supported"; +static const char esp_mail_error_imap_str_14[] PROGMEM = "no message changed since (assigned) modsec"; +static const char esp_mail_error_imap_str_15[] PROGMEM = "CONDSTORE was not supported or modsec was not supported for selected mailbox"; +static const char esp_mail_error_imap_str_17[] PROGMEM = "could not parse command"; +static const char esp_mail_error_imap_str_18[] PROGMEM = "server disconnected or returned error"; +static const char esp_mail_error_imap_str_19[] PROGMEM = "authenticate failed"; +static const char esp_mail_error_imap_str_20[] PROGMEM = "flags or keywords store failed"; +static const char esp_mail_error_imap_str_21[] PROGMEM = "server is not support OAuth2 login"; +#endif +#endif + +///////////////////////// +// General use string +static const char esp_mail_str_1[] PROGMEM = "127.0.0.1"; +static const char esp_mail_str_2[] PROGMEM = " "; +static const char esp_mail_str_3[] PROGMEM = "*"; +static const char esp_mail_str_4[] PROGMEM = "High"; +static const char esp_mail_str_5[] PROGMEM = "Normal"; +static const char esp_mail_str_6[] PROGMEM = "Low"; +static const char esp_mail_str_7[] PROGMEM = "="; +static const char esp_mail_str_8[] PROGMEM = ","; +static const char esp_mail_str_9[] PROGMEM = "--"; +static const char esp_mail_str_10[] PROGMEM = "/"; +static const char esp_mail_str_11[] PROGMEM = "\""; +static const char esp_mail_str_12[] PROGMEM = "Error, "; +static const char esp_mail_str_13[] PROGMEM = "msg.txt"; +static const char esp_mail_str_14[] PROGMEM = "msg.html"; +static const char esp_mail_str_15[] PROGMEM = "flash content message"; +static const char esp_mail_str_16[] PROGMEM = "file content message"; +static const char esp_mail_str_17[] PROGMEM = "cid:"; +static const char esp_mail_str_18[] PROGMEM = "\r\n"; +static const char esp_mail_str_19[] PROGMEM = "<"; +static const char esp_mail_str_20[] PROGMEM = ">"; +static const char esp_mail_str_21[] PROGMEM = "(\"name\" \"ESP Mail Client\" \"version\" \"%s\")"; +static const char esp_mail_str_22[] PROGMEM = "message/rfc822"; +static const char esp_mail_str_23[] PROGMEM = "upload"; +static const char esp_mail_str_24[] PROGMEM = "%"; +static const char esp_mail_str_25[] PROGMEM = "status code: "; +static const char esp_mail_str_26[] PROGMEM = ", text: "; +static const char esp_mail_str_27[] PROGMEM = "."; +static const char esp_mail_str_28[] PROGMEM = "> C: "; +static const char esp_mail_str_29[] PROGMEM = "< S: "; +static const char esp_mail_str_30[] PROGMEM = "! E: "; +static const char esp_mail_str_31[] PROGMEM = "! I: "; +static const char esp_mail_str_32[] PROGMEM = "! W: "; +static const char esp_mail_str_33[] PROGMEM = "#### "; +static const char esp_mail_str_34[] PROGMEM = ":"; +static const char esp_mail_str_35[] PROGMEM = ";"; +static const char esp_mail_str_36[] PROGMEM = "{"; +static const char esp_mail_str_37[] PROGMEM = "}"; +static const char esp_mail_str_38[] PROGMEM = "("; +static const char esp_mail_str_39[] PROGMEM = ")"; +static const char esp_mail_str_40[] PROGMEM = "["; +static const char esp_mail_str_41[] PROGMEM = "]"; +static const char esp_mail_str_42[] PROGMEM = "\r\n"; +static const char esp_mail_str_43[] PROGMEM = "\1\1"; +static const char esp_mail_str_44[] PROGMEM = "{\"status\":"; +static const char esp_mail_str_45[] PROGMEM = "user="; +static const char esp_mail_str_46[] PROGMEM = "\1auth=Bearer "; +static const char esp_mail_str_47[] PROGMEM = "0123456789ABCDEF"; +static const char esp_mail_str_48[] PROGMEM = "<0.0>"; +static const char esp_mail_str_49[] PROGMEM = "<0."; +static const char esp_mail_str_50[] PROGMEM = "Search limit: %d\nFound %d messages\nShow %d messages"; +static const char esp_mail_str_51[] PROGMEM = "1.0"; +static const char esp_mail_str_52[] PROGMEM = "Fetch message %d, UID: %d"; +static const char esp_mail_str_53[] PROGMEM = "Fetch message %d, Number: %d"; +static const char esp_mail_str_54[] PROGMEM = "Attachments (%d)"; +static const char esp_mail_str_55[] PROGMEM = "Free Heap: "; +static const char esp_mail_str_56[] PROGMEM = "content-"; +static const char esp_mail_str_58[] PROGMEM = "format=\"flowed\""; +static const char esp_mail_str_59[] PROGMEM = "format=flowed"; +static const char esp_mail_str_60[] PROGMEM = "delsp=\"yes\""; +static const char esp_mail_str_61[] PROGMEM = "delsp=yes"; +static const char esp_mail_str_62[] PROGMEM = "name"; +static const char esp_mail_str_63[] PROGMEM = "+ "; +static const char esp_mail_str_64[] PROGMEM = "boundary=\""; +static const char esp_mail_str_65[] PROGMEM = "/header.json"; +static const char esp_mail_str_66[] PROGMEM = "/header.txt"; +static const char esp_mail_str_67[] PROGMEM = "{\"Filename\":\""; +static const char esp_mail_str_68[] PROGMEM = "Index: "; +static const char esp_mail_str_69[] PROGMEM = ",\"RFC822\":"; +static const char esp_mail_str_70[] PROGMEM = "\r\n\r\nRFC822:\r\n"; +static const char esp_mail_str_71[] PROGMEM = ",\"Attachments\":{\"Count\":"; +static const char esp_mail_str_72[] PROGMEM = ",\"Files\":["; +static const char esp_mail_str_73[] PROGMEM = "\r\n\r\nAttachments ("; +static const char esp_mail_str_74[] PROGMEM = ")\r\n"; +static const char esp_mail_str_75[] PROGMEM = "]}"; +static const char esp_mail_str_76[] PROGMEM = "{\"Messages\":["; +static const char esp_mail_str_77[] PROGMEM = ",\""; +static const char esp_mail_str_78[] PROGMEM = "{\""; +static const char esp_mail_str_79[] PROGMEM = "\":\""; +static const char esp_mail_str_80[] PROGMEM = "{\"Renamed\":\""; +static const char esp_mail_str_81[] PROGMEM = "\",\"Original\":\""; +static const char esp_mail_str_82[] PROGMEM = "\"}]"; +static const char esp_mail_str_83[] PROGMEM = "_"; +static const char esp_mail_str_84[] PROGMEM = "message"; +static const char esp_mail_str_85[] PROGMEM = "rfc822"; +static const char esp_mail_str_86[] PROGMEM = "/msg"; +static const char esp_mail_str_87[] PROGMEM = "/rfc822_msg"; +static const char esp_mail_str_88[] PROGMEM = "polling established on "; +static const char esp_mail_str_89[] PROGMEM = " folder..."; +static const char esp_mail_str_90[] PROGMEM = "boundary"; +static const char esp_mail_str_91[] PROGMEM = "\\Deleted"; +static const char esp_mail_str_92[] PROGMEM = "Subject: %s"; +static const char esp_mail_str_93[] PROGMEM = "Message sent success: %d"; +static const char esp_mail_str_94[] PROGMEM = "Message sent failed: %d"; +static const char esp_mail_str_95[] PROGMEM = "Status: %s"; +static const char esp_mail_str_96[] PROGMEM = "Date/Time: %s"; +static const char esp_mail_str_97[] PROGMEM = "Recipient: %s"; +static const char esp_mail_str_98[] PROGMEM = "success"; +static const char esp_mail_str_99[] PROGMEM = "failed"; + +#if defined(ENABLE_SMTP) +static const char boundary_table[] PROGMEM = "=_abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; +#endif + +#if defined(ENABLE_SMTP) || defined(ENABLE_IMAP) + +static const unsigned char b64_index_table[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + +static void __attribute__((used)) +appendDebugTag(MB_String &buf, esp_mail_debug_tag_type type, bool clear, PGM_P text = NULL) +{ + if (clear) + buf.clear(); + + switch (type) + { + case esp_mail_debug_tag_type_client: + buf += esp_mail_str_28; /* "> C: "*/ + break; + case esp_mail_debug_tag_type_server: + buf += esp_mail_str_29; /* "< S: " */ + break; + case esp_mail_debug_tag_type_error: + buf += esp_mail_str_30; /* "! E: "*/ + break; + case esp_mail_debug_tag_type_info: + buf += esp_mail_str_31; /* "! I: "*/ + break; + case esp_mail_debug_tag_type_warning: + buf += esp_mail_str_32; /* "! W: "*/ + break; + default: + break; + } + + if (text != NULL) + buf += text; +} + +static void __attribute__((used)) +yield_impl() +{ +#if defined(ARDUINO_ESP8266_MAJOR) && defined(ARDUINO_ESP8266_MINOR) && defined(ARDUINO_ESP8266_REVISION) && ((ARDUINO_ESP8266_MAJOR == 3 && ARDUINO_ESP8266_MINOR >= 1) || ARDUINO_ESP8266_MAJOR > 3) + esp_yield(); +#else + delay(0); +#endif +} + +// Print debug message w/wo new line to debug port +static void __attribute__((used)) +esp_mail_debug_print(PGM_P msg = "", bool newLine = true) +{ + yield_impl(); + if (newLine) + ESP_MAIL_DEFAULT_DEBUG_PORT.println(msg); + else + ESP_MAIL_DEFAULT_DEBUG_PORT.print(msg); +} + +static void __attribute__((used)) +esp_mail_debug_print_tag(PGM_P msg, esp_mail_debug_tag_type type, bool newLine = true, bool showTag = true) +{ + yield_impl(); + + MB_String s; + if (showTag) + appendDebugTag(s, type, false, msg); + else + s = msg; + + if (newLine) + ESP_MAIL_DEFAULT_DEBUG_PORT.println(s.c_str()); + else + ESP_MAIL_DEFAULT_DEBUG_PORT.print(s.c_str()); +} + +#endif + +typedef void (*ConnectionUpgradeRequestCallback)(void); +typedef void (*NetworkConnectionRequestCallback)(void); +typedef void (*NetworkDisconnectionRequestCallback)(void); +typedef void (*NetworkStatusRequestCallback)(void); +// Optional +typedef void (*ConnectionRequestCallback)(const char *, int); +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/ESP_Mail_Error.h b/lib/libesp32/ESP-Mail-Client/src/ESP_Mail_Error.h new file mode 100644 index 000000000..172e7f8d4 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/ESP_Mail_Error.h @@ -0,0 +1,86 @@ +/** + * Created August 6, 2023 + */ +#pragma once + +#ifndef ESP_MAIL_ERROR_H +#define ESP_MAIL_ERROR_H + +#include "ESP_Mail_Client_Version.h" +#if !VALID_VERSION_CHECK(30409) +#error "Mixed versions compilation." +#endif + +#define TCP_CLIENT_ERROR_CONNECTION_REFUSED -1 +#define TCP_CLIENT_ERROR_SEND_DATA_FAILED -2 +#define TCP_CLIENT_ERROR_NOT_INITIALIZED -3 +#define TCP_CLIENT_ERROR_NOT_CONNECTED -4 + +#if defined(ENABLE_SMTP) + +#define SMTP_STATUS_SERVER_CONNECT_FAILED -100 +#define SMTP_STATUS_SMTP_GREETING_GET_RESPONSE_FAILED -101 +#define SMTP_STATUS_SMTP_GREETING_SEND_ACK_FAILED -102 +#define SMTP_STATUS_AUTHEN_NOT_SUPPORT -103 +#define SMTP_STATUS_AUTHEN_FAILED -104 +#define SMTP_STATUS_USER_LOGIN_FAILED -105 +#define SMTP_STATUS_PASSWORD_LOGIN_FAILED -106 +#define SMTP_STATUS_SEND_HEADER_SENDER_FAILED -107 +#define SMTP_STATUS_SEND_HEADER_RECIPIENT_FAILED -108 +#define SMTP_STATUS_SEND_BODY_FAILED -109 +#define SMTP_STATUS_SERVER_OAUTH2_LOGIN_DISABLED -110 +#define SMTP_STATUS_NO_VALID_RECIPIENTS_EXISTED -111 +#define SMTP_STATUS_NO_VALID_SENDER_EXISTED -112 +#define SMTP_STATUS_NO_SUPPORTED_AUTH -113 +#define SMTP_STATUS_SEND_CUSTOM_COMMAND_FAILED -114 +#define SMTP_STATUS_XOAUTH2_AUTH_FAILED -115 +#define SMTP_STATUS_UNDEFINED -116 +#endif + +#if defined(ENABLE_IMAP) + +#define IMAP_STATUS_SERVER_CONNECT_FAILED -200 +#define IMAP_STATUS_IMAP_RESPONSE_FAILED -201 +#define IMAP_STATUS_AUTHENTICATE_FAILED -202 +#define IMAP_STATUS_BAD_COMMAND -203 +#define IMAP_STATUS_STORE_FAILED -204 +#define IMAP_STATUS_SERVER_OAUTH2_LOGIN_DISABLED -205 +#define IMAP_STATUS_NO_MESSAGE -206 +#define IMAP_STATUS_ERROR_DOWNLAD_TIMEOUT -207 +#define IMAP_STATUS_CLOSE_MAILBOX_FAILED -208 +#define IMAP_STATUS_OPEN_MAILBOX_FAILED -209 +#define IMAP_STATUS_LIST_MAILBOXS_FAILED -210 +#define IMAP_STATUS_CHECK_CAPABILITIES_FAILED -211 +#define IMAP_STATUS_NO_SUPPORTED_AUTH -212 +#define IMAP_STATUS_NO_MAILBOX_FOLDER_OPENED -213 +#define IMAP_STATUS_FIRMWARE_UPDATE_INIT_FAILED -214 +#define IMAP_STATUS_FIRMWARE_UPDATE_WRITE_FAILED -215 +#define IMAP_STATUS_FIRMWARE_UPDATE_END_FAILED -216 +#define IMAP_STATUS_CHANGEDSINC_MODSEQ_TEST_FAILED -217 +#define IMAP_STATUS_MODSEQ_WAS_NOT_SUPPORTED -218 +#endif + +/** + * MB_FS.h + #define MB_FS_ERROR_FILE_IO_ERROR -300 + #define MB_FS_ERROR_FILE_NOT_FOUND -301 + #define MB_FS_ERROR_FLASH_STORAGE_IS_NOT_READY -302 + #define MB_FS_ERROR_SD_STORAGE_IS_NOT_READY -303 + #define MB_FS_ERROR_FILE_STILL_OPENED -304 +*/ + +#if defined(ENABLE_SMTP) || defined(ENABLE_IMAP) + +#define MAIL_CLIENT_ERROR_CONNECTION_CLOSED -400 +#define MAIL_CLIENT_ERROR_READ_TIMEOUT -401 +#define MAIL_CLIENT_ERROR_SSL_TLS_STRUCTURE_SETUP -402 +#define MAIL_CLIENT_ERROR_OUT_OF_MEMORY -403 +#define MAIL_CLIENT_ERROR_NTP_TIME_SYNC_TIMED_OUT -404 +#define MAIL_CLIENT_ERROR_SESSION_CONFIG_WAS_NOT_ASSIGNED -405 +#define MAIL_CLIENT_ERROR_TIME_WAS_NOT_SET -406 +#define MAIL_CLIENT_ERROR_NOT_YET_LOGIN -407 +#define MAIL_CLIENT_ERROR_BUFFER_OVERFLOW -408 + +#endif + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/ESP_Mail_FS.h b/lib/libesp32/ESP-Mail-Client/src/ESP_Mail_FS.h new file mode 100644 index 000000000..b9c9755d5 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/ESP_Mail_FS.h @@ -0,0 +1,170 @@ + + +#pragma once + +#ifndef ESP_MAIL_CONFIG_H +#define ESP_MAIL_CONFIG_H + +#include "ESP_Mail_Client_Version.h" +#if !VALID_VERSION_CHECK(30409) +#error "Mixed versions compilation." +#endif + +#include +#include "extras/MB_MCU.h" + +/** 📌 Predefined Build Options + * ⛔ Use following build flag to disable all predefined options. + * -D DISABLE_ALL_OPTIONS + */ + +/**📍 For enabling the device or library time setup from NTP server + * ⛔ Use following build flag to disable. + * -D DISABLE_NTP_TIME + */ +#define ENABLE_NTP_TIME + +/**📍 For enabling the error string from error reason + * ⛔ Use following build flag to disable. + * -D DISABLE_ERROR_STRING + */ +#define ENABLE_ERROR_STRING + +/**📍 For IMAP class compilation + * ⛔ Use following build flag to disable. + * -D DISABLE_IMAP + */ +#define ENABLE_IMAP + +/**📍 For SMTP class compilation + * ⛔ Use following build flag to disable. + * -D DISABLE_SMTP + */ +#define ENABLE_SMTP + +/**📍 For enabling PSRAM support + * ⛔ Use following build flag to disable. + * -D DISABLE_PSRAM + */ +#define ESP_MAIL_USE_PSRAM + +/**📌 For enabling flash filesystem support + * + * 📍 For SPIFFS + * #define ESP_MAIL_DEFAULT_FLASH_FS SPIFFS + * + * + * 📍 For LittleFS Filesystem + * #include + * #define ESP_MAIL_DEFAULT_FLASH_FS LittleFS + * + * + * 📍 For SPIFFS Filesystem + * #if defined(ESP32) + * #include + * #endif + * #define ESP_MAIL_DEFAULT_FLASH_FS SPIFFS + * + * + * 📍 For FAT Filesystem + * #include + * #define ESP_MAIL_DEFAULT_FLASH_FS FFat //For ESP32 FAT + * + * 🚫 Use following build flags to disable. + * -D DISABLE_FLASH or -DDISABLE_FLASH in PlatformIO + */ + +#if defined(ESP32) || defined(ESP8266) || defined(MB_ARDUINO_PICO) + +#if defined(ESP8266) || defined(MB_ARDUINO_PICO) + +#include +#define ESP_MAIL_DEFAULT_FLASH_FS LittleFS + +#elif defined(ESP_ARDUINO_VERSION) /* ESP32 core >= v2.0.x */ /* ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(2, 0, 0) */ + +#include +#define ESP_MAIL_DEFAULT_FLASH_FS LittleFS + +#else + +#include +#define ESP_MAIL_DEFAULT_FLASH_FS SPIFFS + +#endif + +#endif + +// For ESP32, format SPIFFS or FFat if mounting failed +#define ESP_MAIL_FORMAT_FLASH_IF_MOUNT_FAILED 1 + +/**📌 For enabling SD filesystem support + * + * 📍 For SD + * #include + * #define ESP_MAIL_DEFAULT_SD_FS SD + * #define ESP_MAIL_CARD_TYPE_SD 1 + * + * 📍 For SD MMC (ESP32) + * #include + * #define ESP_MAIL_DEFAULT_SD_FS SD_MMC //For ESP32 SDMMC + * #define ESP_MAIL_CARD_TYPE_SD_MMC 1 + * + * 📍 For SdFat on ESP32 and other devices except for ESP8266 + * #include //https://github.com/greiman/SdFat + * static SdFat sd_fat_fs; //should declare as static here + * #define ESP_MAIL_DEFAULT_SD_FS sd_fat_fs + * #define ESP_MAIL_CARD_TYPE_SD 1 + * #define ESP_MAIL_SD_FS_FILE SdFile + * + * + * ⛔ Use following build flags to disable. + * -D DISABLE_SD or -DDISABLE_SD in PlatformIO + */ +#if defined(ESP32) || defined(ESP8266) +#include +#define ESP_MAIL_DEFAULT_SD_FS SD +#define ESP_MAIL_CARD_TYPE_SD 1 +#elif defined(MB_ARDUINO_PICO) +// Use SDFS (ESP8266SdFat) instead of SD +#include +#define ESP_MAIL_DEFAULT_SD_FS SDFS +#define ESP_MAIL_CARD_TYPE_SD 1 +#endif + +/** 🔖 Optional Build Options + * + * 🏷️ For silent operation (no debug printing and callback) + * #define SILENT_MODE + * + * 🏷️ For ENC28J60 Ethernet module support in ESP8266 + * #define ENABLE_ESP8266_ENC28J60_ETH + * + * 🏷️ For W5500 Ethernet module support in ESP8266 + * #define ENABLE_ESP8266_W5500_ETH + * + * 🏷️ For W5100 Ethernet module support in ESP8266 + * #define ENABLE_ESP8266_W5100_ETH + * + * 🏷️ For disabling on-board WiFI functionality in case external Client usage + * #define ESP_MAIL_DISABLE_ONBOARD_WIFI + * + * 🏷️ For disabling native (sdk) Ethernet functionality in case external Client usage + * #define ESP_MAIL_DISABLE_NATIVE_ETHERNET + * + * 🏷️ For disabling SSL connection (also disabling TLS using STARTTLS) in MAP and SMTP application + * #define ESP_MAIL_DISABLE_SSL + * + * 🏷️ For debug port assignment if SILENT_MODE option was not set + * #define ESP_MAIL_DEBUG_PORT Serial + */ + +#define ENABLE_ESP8266_ENC28J60_ETH + +#if __has_include("Custom_ESP_Mail_FS.h") +#include "Custom_ESP_Mail_FS.h" +#endif + +#include "extras/Build_Options.h" + +#endif diff --git a/lib/libesp32/ESP-Mail-Client/src/ESP_Mail_IMAP.h b/lib/libesp32/ESP-Mail-Client/src/ESP_Mail_IMAP.h new file mode 100644 index 000000000..ddfdbed08 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/ESP_Mail_IMAP.h @@ -0,0 +1,6783 @@ + +#ifndef ESP_MAIL_IMAP_H +#define ESP_MAIL_IMAP_H + +#include "ESP_Mail_Client_Version.h" +#if !VALID_VERSION_CHECK(30409) +#error "Mixed versions compilation." +#endif + +/** + * Mail Client Arduino Library for Espressif's ESP32 and ESP8266, Raspberry Pi RP2040 Pico, and SAMD21 with u-blox NINA-W102 WiFi/Bluetooth module + * + * Created August 28, 2023 + * + * This library allows Espressif's ESP32, ESP8266, SAMD and RP2040 Pico devices to send and read Email through the SMTP and IMAP servers. + * + * The MIT License (MIT) + * Copyright (c) 2023 K. Suwatchai (Mobizt) + * + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include "ESP_Mail_Client_Version.h" +#include "ESP_Mail_Client.h" + +#if defined(ENABLE_IMAP) + +#if defined(MB_ARDUINO_PICO) +extern uint8_t _FS_start; +extern uint8_t _FS_end; +#endif + +int ESP_Mail_Client::decodeChar(const char *s) +{ + return 16 * hexval(*(s + 1)) + hexval(*(s + 2)); +} + +void ESP_Mail_Client::decodeQP_UTF8(const char *buf, char *out) +{ + char *tmp = strP(esp_mail_str_47 /* "0123456789ABCDEF" */); + int idx = 0; + while (*buf) + { + if (*buf != '=') + out[idx++] = *buf++; + else if (*(buf + 1) == '\r' && *(buf + 2) == '\n') + buf += 3; + else if (*(buf + 1) == '\n') + buf += 2; + else if (!strchr(tmp, *(buf + 1))) + out[idx++] = *buf++; + else if (!strchr(tmp, *(buf + 2))) + out[idx++] = *buf++; + else + { + out[idx++] = decodeChar(buf); + buf += 3; + } + } + + // release memory + freeMem(&tmp); +} + +char *ESP_Mail_Client::decode7Bit_UTF8(char *buf) +{ + MB_String s; + + // only non NULL and 7-bit ASCII are allowed + + // rfc2045 section 2.7 + + size_t len = buf ? strlen(buf) : 0; + + for (size_t i = 0; i < len; i++) + { + if (buf[i] > 0 && buf[i] < 128 && i < 998) + s.append(1, buf[i]); + } + + // some special chars can't send in 7bit unless encoded as queoted printable string + char *decoded = allocMem(s.length() + 10); + decodeQP_UTF8(s.c_str(), decoded); + s.clear(); + return decoded; +} + +char *ESP_Mail_Client::decode8Bit_UTF8(char *buf) +{ + MB_String s; + + // only non NULL and less than 998 octet length are allowed + + // rfc2045 section 2.8 + + size_t len = buf ? strlen(buf) : 0; + + for (size_t i = 0; i < len; i++) + { + if (buf[i] > 0 && i < 998) + s.append(1, buf[i]); + } + + char *decoded = allocMem(s.length() + 1); + strcpy(decoded, s.c_str()); + s.clear(); + return decoded; +} + +void ESP_Mail_Client::decodeString(IMAPSession *imap, MB_String &str, const char *enc) +{ + + size_t p1 = 0, p2 = 0; + MB_String headerEnc; + + if (strlen(enc) == 0) + { + while (str[p1] == ' ' && p1 < str.length() - 1) + p1++; + + if (str[p1] == '=' && str[p1 + 1] == '?') + { + p2 = str.find('?', p1 + 2); + if (p2 != MB_String::npos) + headerEnc = str.substr(p1 + 2, p2 - p1 - 2); + } + } + else + headerEnc = enc; + + int bufSize = str.length() + 10; + char *buf = allocMem(bufSize); + + // Content Q and B decodings + RFC2047Decoder.decode(mbfs, buf, str.c_str(), bufSize); + + // Char set decoding + esp_mail_char_decoding_scheme scheme = getEncodingFromCharset(headerEnc.c_str()); + if (imap->_charDecCallback) + { + IMAP_Decoding_Info decoding; + decoding.charset = headerEnc.c_str(); + decoding.data = buf; + decoding.type = IMAP_Decoding_Info::message_part_type_header; + + imap->_charDecCallback(&decoding); + + if (decoding.decodedString.length() > 0) + { + char *buf2 = allocMem(decoding.decodedString.length() + 1); + strcpy(buf2, decoding.decodedString.c_str()); + // release memory and point to new buffer + freeMem(&buf); + buf = buf2; + } + } + else if (scheme == esp_mail_char_decoding_scheme_iso8859_1) + { + int len = strlen(buf); + int olen = (len + 1) * 2; + unsigned char *out = allocMem(olen); + decodeLatin1_UTF8(out, &olen, (unsigned char *)buf, &len); + // release memory and point to new buffer + freeMem(&buf); + buf = (char *)out; + } + else if (scheme == esp_mail_char_decoding_scheme_tis_620 || scheme == esp_mail_char_decoding_scheme_iso8859_11 || scheme == esp_mail_char_decoding_scheme_windows_874) + { + size_t len2 = strlen(buf); + char *tmp = allocMem((len2 + 1) * 3); + decodeTIS620_UTF8(tmp, buf, len2); + // release memory and point to new buffer + freeMem(&buf); + buf = tmp; + } + + str = buf; + // release memory + freeMem(&buf); +} + +esp_mail_char_decoding_scheme ESP_Mail_Client::getEncodingFromCharset(const char *enc) +{ + esp_mail_char_decoding_scheme scheme = esp_mail_char_decoding_scheme_default; + + for (int i = esp_mail_char_decoding_utf8; i < esp_mail_char_decoding_maxType; i++) + { + if (strpos(enc, char_decodings[i].text, 0, false) > -1) + scheme = (esp_mail_char_decoding_scheme)i; + } + + return scheme; +} + +int ESP_Mail_Client::encodeUnicode_UTF8(char *out, uint32_t utf) +{ + if (utf <= 0x7F) + { + // Plain ASCII + out[0] = (char)utf; + out[1] = 0; + return 1; + } + else if (utf <= 0x07FF) + { + // 2-byte unicode + out[0] = (char)(((utf >> 6) & 0x1F) | 0xC0); + out[1] = (char)(((utf >> 0) & 0x3F) | 0x80); + out[2] = 0; + return 2; + } + else if (utf <= 0xFFFF) + { + // 3-byte unicode + out[0] = (char)(((utf >> 12) & 0x0F) | 0xE0); + out[1] = (char)(((utf >> 6) & 0x3F) | 0x80); + out[2] = (char)(((utf >> 0) & 0x3F) | 0x80); + out[3] = 0; + return 3; + } + else if (utf <= 0x10FFFF) + { + // 4-byte unicode + out[0] = (char)(((utf >> 18) & 0x07) | 0xF0); + out[1] = (char)(((utf >> 12) & 0x3F) | 0x80); + out[2] = (char)(((utf >> 6) & 0x3F) | 0x80); + out[3] = (char)(((utf >> 0) & 0x3F) | 0x80); + out[4] = 0; + return 4; + } + else + { + // error - use replacement character + out[0] = (char)0xEF; + out[1] = (char)0xBF; + out[2] = (char)0xBD; + out[3] = 0; + return 0; + } +} + +void ESP_Mail_Client::decodeTIS620_UTF8(char *out, const char *in, size_t len) +{ + // output is the 3-byte value UTF-8 + int j = 0; + for (size_t i = 0; i < len; i++) + { + if (in[i] < 0x80) + out[j++] = in[i]; + else if ((in[i] >= 0xa0 && in[i] < 0xdb) || (in[i] > 0xde && in[i] < 0xfc)) + { + int unicode = 0x0e00 + in[i] - 0xa0; + char o[5]; + memset(o, 0, 5); + int r = encodeUnicode_UTF8(o, unicode); + for (int x = 0; x < r; x++) + out[j++] = o[x]; + } + } +} + +int ESP_Mail_Client::decodeLatin1_UTF8(unsigned char *out, int *outlen, const unsigned char *in, int *inlen) +{ + unsigned char *outstart = out; + const unsigned char *base = in; + const unsigned char *processed = in; + unsigned char *outend = out + *outlen; + const unsigned char *inend; + unsigned int c; + int bits; + + inend = in + (*inlen); + while ((in < inend) && (out - outstart + 5 < *outlen)) + { + c = *in++; + + /* assertion: c is a single UTF-4 value */ + if (out >= outend) + break; + if (c < 0x80) + { + *out++ = c; + bits = -6; + } + else + { + *out++ = ((c >> 6) & 0x1F) | 0xC0; + bits = 0; + } + + for (; bits >= 0; bits -= 6) + { + if (out >= outend) + break; + *out++ = ((c >> bits) & 0x3F) | 0x80; + } + processed = (const unsigned char *)in; + } + *outlen = out - outstart; + *inlen = processed - base; + return (0); +} + +bool ESP_Mail_Client::sendFetchCommand(IMAPSession *imap, int msgIndex, esp_mail_imap_command cmdCase) +{ + + MB_String cmd, cmd2, cmd3; + appendHeadersFetchCommand(imap, cmd, msgIndex, false); + + if (cmdCase == esp_mail_imap_cmd_fetch_body_mime) + { + joinStringDot(cmd2, 2, imap_commands[esp_mail_imap_command_header].text, imap_commands[esp_mail_imap_command_fields].text); + appendSpace(cmd2); + joinStringSpace(cmd3, false, 2, message_headers[esp_mail_message_header_field_content_type].text, message_headers[esp_mail_message_header_field_content_transfer_encoding].text); + appendString(cmd2, cmd3.c_str(), false, false, esp_mail_string_mark_type_round_bracket); + } + else if (cmdCase == esp_mail_imap_cmd_fetch_body_text) + cmd2 = cPart(imap)->partNumFetchStr.length() > 0 ? cPart(imap)->partNumFetchStr.c_str() : imap_commands[esp_mail_imap_command_text].text; + else if (cmdCase == esp_mail_imap_cmd_fetch_body_attachment) + cmd2 = cPart(imap)->partNumFetchStr; + + if (cmd2.length() > 0) + appendString(cmd, cmd2.c_str(), false, false, esp_mail_string_mark_type_square_bracket); + + bool allowPartialFetch = (cmdCase == esp_mail_imap_cmd_fetch_body_attachment && cPart(imap)->is_firmware_file) ? false : true; + + if (imap->_mimeDataStreamCallback) + allowPartialFetch = false; + + if (allowPartialFetch) + { + // Apply partial fetch in case download was disabled. + if (!imap->_storageReady && imap->_attDownload && cmdCase == esp_mail_imap_cmd_fetch_body_attachment) + cmd += esp_mail_str_48; /* "<0.0>" */ // This case should not happen because the memory storage was previousely checked. + else if ((!imap->_msgDownload && cmdCase == esp_mail_imap_cmd_fetch_body_text) || (imap->_msgDownload && !imap->_storageReady)) + { + cmd += esp_mail_str_49; /* "<0." */ + cmd += imap->_imap_data->limit.msg_size; + cmd += esp_mail_str_20; /* ">" */ + } + } + + if (imapSend(imap, cmd.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return false; + + return true; +} + +bool ESP_Mail_Client::readMail(IMAPSession *imap, bool closeSession) +{ + if (!imap || !sessionExisted(imap)) + return false; + + imap->checkUID(); + imap->checkPath(); + imap->_cbData._success = false; + + if (!imap->connected()) + imap->_mailboxOpened = false; + + imap->_isFirmwareUpdated = false; + + MB_String buf, command, _uid; + + size_t readCount = 0; + imap->_multipart_levels.clear(); + + if (!reconnect(imap)) + return false; + + imap->_msgDownload = imap->_imap_data->download.text || imap->_imap_data->download.html; + imap->_attDownload = imap->_imap_data->download.attachment || imap->_imap_data->download.inlineImg; + + if (!imap->_storageChecked) + { + imap->_storageChecked = true; + imap->_storageReady = imap->_imap_data->download.header || (!imap->_imap_data->fetch.headerOnly && (imap->_msgDownload || imap->_attDownload)) ? mbfs->checkStorageReady(mbfs_type imap->_imap_data->storage.type) : true; + } + + bool readyToDownload = (imap->_msgDownload || imap->_attDownload) && imap->_storageReady; + + if (!imap->_storageReady) + sendStorageNotReadyError(imap, imap->_imap_data->storage.type); + +#if defined(MB_ARDUINO_ESP) || defined(MB_ARDUINO_PICO) + + int cmem = MailClient.getFreeHeap(); + + if (cmem < ESP_MAIL_MIN_MEM) + { +#if !defined(SILENT_MODE) + if (imap->_debug && imap->_statusCallback && !imap->_customCmdResCallback) + { + esp_mail_debug_print(); + errorStatusCB(imap, nullptr, MAIL_CLIENT_ERROR_OUT_OF_MEMORY, true); + } +#endif + + goto out; + } +#endif + + if (!imap->connected() && !imap->_loginStatus) + { +#if !defined(SILENT_MODE) + if (imap->_debug && imap->_statusCallback && !imap->_customCmdResCallback) + { + esp_mail_debug_print(); + errorStatusCB(imap, nullptr, MAIL_CLIENT_ERROR_NOT_YET_LOGIN, true); + } +#endif + return false; + } + + // new session + if (!imap->connected()) + { + // authenticate new + + bool ssl = false; + + if (!imap->connect(ssl)) + { + closeTCPSession(imap); + return false; + } + + if (!imapAuth(imap, ssl)) + { + closeTCPSession(imap); + return false; + } + } + else + { + // If time config changed, we will update time + MailClient.prepareTime(imap->_session_cfg, imap); + + // reuse session + for (size_t i = 0; i < imap->_headers.size(); i++) + imap->_headers[i].part_headers.clear(); + imap->_headers.clear(); + + if (imap->_imap_data->fetch.sequence_set.string.length() > 0 || imap->_imap_data->fetch.uid.length() > 0 || imap->_imap_data->fetch.number.length() > 0) + imap->_headerOnly = false; + else + imap->_headerOnly = true; + } + + imap->_rfc822_part_count = 0; + imap->_mbif._availableItems = 0; + imap->_imap_msg_num.clear(); + imap->_uidSearch = false; + imap->_mbif._searchCount = 0; + + if (imap->_currentFolder.length() == 0) + return handleIMAPError(imap, IMAP_STATUS_NO_MAILBOX_FOLDER_OPENED, false); + + if (!imap->_mailboxOpened || (imap->_imap_data->fetch.set_seen && !imap->_headerOnly && imap->_readOnlyMode)) + { + if (!imap->openFolder(imap->_currentFolder.c_str(), imap->_readOnlyMode && !imap->_imap_data->fetch.set_seen)) + return handleIMAPError(imap, IMAP_STATUS_OPEN_MAILBOX_FAILED, false); + } + + if (imap->_headerOnly) + { + if (imap->_imap_data->search.criteria.length() > 0) + { + command = esp_mail_imap_tag_str; + +#if !defined(SILENT_MODE) + printDebug(imap, + esp_mail_cb_str_18 /* "Searching messages..." */, + esp_mail_dbg_str_36 /* "searching messages" */, + esp_mail_debug_tag_type_client, + true, + false); + +#endif + + if (strposP(imap->_imap_data->search.criteria.c_str(), imap_cmd_post_tokens[esp_mail_imap_command_uid].c_str(), 0) != -1) + { + imap->_uidSearch = true; + command += imap_cmd_pre_tokens[esp_mail_imap_command_uid]; + } + + command += imap_cmd_pre_tokens[esp_mail_imap_command_search]; + + imap->_imap_data->search.criteria.trim(); + + MB_String tag; + appendTagSpace(tag); + + // Remove internal used reserved tag + if (strpos(imap->_imap_data->search.criteria.c_str(), tag.c_str(), 0, true) == 0) + imap->_imap_data->search.criteria.erase(0, tag.length()); + + for (size_t i = 0; i < imap->_imap_data->search.criteria.length(); i++) + { + if (imap->_imap_data->search.criteria[i] != ' ' && imap->_imap_data->search.criteria[i] != '\r' && imap->_imap_data->search.criteria[i] != '\n') + buf.append(1, imap->_imap_data->search.criteria[i]); + + if (imap->_imap_data->search.criteria[i] == ' ') + { + + if ((imap->_uidSearch && strcmp(buf.c_str(), imap_commands[esp_mail_imap_command_uid].text) == 0) || (imap->_unseen && buf.find(imap_commands[esp_mail_imap_command_all].text) != MB_String::npos)) + buf.clear(); + + if (strcmp(buf.c_str(), imap_commands[esp_mail_imap_command_search].text) != 0 && buf.length() > 0) + prependSpace(command, buf.c_str()); + + buf.clear(); + } + } + + if (imap->_unseen && strpos(imap->_imap_data->search.criteria.c_str(), imap_cmd_pre_tokens[esp_mail_imap_command_new].c_str(), 0) == -1) + command += imap_cmd_pre_tokens[esp_mail_imap_command_new]; + + if (buf.length() > 0) + prependSpace(command, buf.c_str()); + + if (!imap->isModseqSupported() && strpos(imap->_imap_data->search.criteria.c_str(), imap_cmd_pre_tokens[esp_mail_imap_command_modsec].c_str(), 0, false) != -1) + { + imap->_responseStatus.errorCode = IMAP_STATUS_MODSEQ_WAS_NOT_SUPPORTED; +#if !defined(SILENT_MODE) + + if (imap->_statusCallback) + sendErrorCB(imap, imap->errorReason().c_str(), false, false); + + if (imap->_debug) + esp_mail_debug_print_tag(imap->errorReason().c_str(), esp_mail_debug_tag_type_error, true); + +#endif + return false; + } + + if (imapSend(imap, command.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return false; + + command.clear(); + + imap->_imap_cmd = esp_mail_imap_cmd_search; + + if (!handleIMAPResponse(imap, IMAP_STATUS_BAD_COMMAND, closeSession)) + return false; + +#if !defined(SILENT_MODE) + if (imap->_statusCallback) + { + callBackSendNewLine(imap, false); + if (imap->_imap_msg_num.size() > 0) + { + int bufLen = 100; + char *buf = allocMem(bufLen); + snprintf(buf, bufLen, pgm2Str(esp_mail_str_50 /* "Search limit: %d\nFound %d messages\nShow %d messages\n" */), (int)imap->_imap_data->limit.search, imap->_mbif._searchCount, (int)imap->_imap_msg_num.size()); + sendCallback(imap, buf, false, false); + // release memory + freeMem(&buf); + } + else + sendCallback(imap, esp_mail_error_imap_str_9 /* "no messages found for the specified search criteria" */, false, false); + } +#endif + } + else + { +#if !defined(SILENT_MODE) + if (imap->_statusCallback) + sendCallback(imap, esp_mail_error_imap_str_10 /* "no search criteria provided, then fetching the latest message" */, false, false); +#endif + imap->_mbif._availableItems++; + + esp_mail_imap_msg_num_t msg_num; + msg_num.type = esp_mail_imap_msg_num_type_number; + msg_num.value = (uint32_t)imap->_mbif._msgCount; + + imap->_imap_msg_num.push_back(msg_num); + imap->_headerOnly = false; + imap->_imap_data->fetch.number = imap->_mbif._msgCount; + } + } + else + { + + if (imap->_imap_data->fetch.sequence_set.string.length() > 0) + { + imap->_headerOnly = imap->_imap_data->fetch.sequence_set.headerOnly; + imap->mFetchSequenceSet(); + + imap->_mbif._availableItems = imap->_imap_msg_num.size(); + } + else + { + if (imap->_imap_data->fetch.uid.length() > 0) + { + imap->_mbif._availableItems++; + + esp_mail_imap_msg_num_t msg_num; + msg_num.type = esp_mail_imap_msg_num_type_uid; + msg_num.value = (uint32_t)atoi(imap->_imap_data->fetch.uid.c_str()); + + imap->_imap_msg_num.push_back(msg_num); + } + + if (imap->_imap_data->fetch.number.length() > 0) + { + imap->_mbif._availableItems++; + + esp_mail_imap_msg_num_t msg_num; + msg_num.type = esp_mail_imap_msg_num_type_number; + msg_num.value = (uint32_t)atoi(imap->_imap_data->fetch.number.c_str()); + + imap->_imap_msg_num.push_back(msg_num); + } + } + } + + if (imap->_imap_data->fetch.headerOnly) + imap->_headerOnly = true; + + for (size_t i = 0; i < imap->_imap_msg_num.size(); i++) + { + imap->_cMsgIdx = i; + imap->_totalRead++; + +#if defined(MB_ARDUINO_ESP) || defined(MB_ARDUINO_PICO) + if (MailClient.getFreeHeap() - (imap->_imap_data->limit.msg_size * (i + 1)) < ESP_MAIL_MIN_MEM) + { + errorStatusCB(imap, nullptr, MAIL_CLIENT_ERROR_OUT_OF_MEMORY, true); + goto out; + } +#endif + +#if !defined(SILENT_MODE) + if (imap->_statusCallback) + { + readCount++; + int bufLen = 100; + PGM_P p = imap->_uidSearch || imap->_imap_msg_num[i].type == esp_mail_imap_msg_num_type_uid ? esp_mail_str_52 /* "Fetch message %d, UID: %d" */ : esp_mail_str_53 /* "Fetch message %d, Number: %d" */; + char *buf = allocMem(bufLen); + snprintf(buf, bufLen, pgm2Str(p), imap->_totalRead, (int)imap->_imap_msg_num[i].value); + sendCallback(imap, buf, true, false); + // release memory + freeMem(&buf); + } + + if (imap->_debug) + esp_mail_debug_print_tag(esp_mail_dbg_str_37 /* "send IMAP command, FETCH" */, esp_mail_debug_tag_type_client, true); +#endif + MB_String cmd; + appendHeadersFetchCommand(imap, cmd, i, true); + + // We fetch only known RFC822 headers because + // using Fetch RFC822.HEADER reurns all included unused headers + // which required more memory and network bandwidth. + MB_String cmd2; + appendRFC822HeadersFetchCommand(cmd2); + + appendString(cmd, cmd2.c_str(), false, false, esp_mail_string_mark_type_square_bracket); + + imap->addModifier(cmd, esp_mail_imap_command_changedsince, imap->_imap_data->fetch.modsequence); + + if (imapSend(imap, cmd.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + { + if (i < imap->_imap_msg_num.size() - 1) + continue; + return false; + } + + imap->_imap_cmd = esp_mail_imap_cmd_fetch_body_header; + + int err = imap->_headerOnly ? IMAP_STATUS_IMAP_RESPONSE_FAILED : IMAP_STATUS_BAD_COMMAND; + + if (!handleIMAPResponse(imap, err, closeSession)) + { + if (i < imap->_imap_msg_num.size() - 1) + continue; + return false; + } + + if (!cHeader(imap)) + continue; + + if (imap->_imap_msg_num[i].type == esp_mail_imap_msg_num_type_number) + cHeader(imap)->message_uid = imap->mGetUID(cHeader(imap)->message_no); + + cHeader(imap)->flags = imap->getFlags(cHeader(imap)->message_no); + + if (!imap->_headerOnly) + { + imap->_cPartIdx = 0; + + // Reset attachment state if it was set by "multipart/mixed" content type header + cHeader(imap)->hasAttachment = false; + +#if !defined(SILENT_MODE) + if (imap->_debug) + debugPrintNewLine(); +#endif + + // multipart + if (cHeader(imap)->multipart) + { + struct esp_mail_imap_multipart_level_t mlevel; + mlevel.level = 1; + mlevel.fetch_rfc822_header = false; + mlevel.append_body_text = false; + imap->_multipart_levels.push_back(mlevel); + + if (!fetchMultipartBodyHeader(imap, i)) + return false; + } + else + { + // single part + if (imap->_debug) + printBodyPartFechingDubug(imap, "1", false); + + cHeader(imap)->partNumStr.clear(); + if (!sendFetchCommand(imap, i, esp_mail_imap_cmd_fetch_body_mime)) + return false; + + imap->_imap_cmd = esp_mail_imap_cmd_fetch_body_mime; + if (!handleIMAPResponse(imap, IMAP_STATUS_BAD_COMMAND, closeSession)) + return false; + } + + if (readyToDownload && imap->_imap_data->storage.saved_path.length() == 0) + imap->_imap_data->storage.saved_path = esp_mail_str_10; /* "/" */ + + if (cHeader(imap)->part_headers.size() > 0) + { + + cHeader(imap)->sd_alias_file_count = 0; + + imap->_sdFileList.clear(); + if (!mbfs->longNameSupported()) + imap->_sdFileList = esp_mail_str_40; /* "[" */ + +#if !defined(SILENT_MODE) + + if (cHeader(imap)->attachment_count > 0 && imap->_statusCallback) + { + int bufLen = 100; + char *buf = allocMem(bufLen); + snprintf(buf, bufLen, pgm2Str(esp_mail_str_54 /* "Attachments (%d)" */), cHeader(imap)->attachment_count); + callBackSendNewLine(imap, false); + sendCallback(imap, buf, false, false); + // release memory + freeMem(&buf); + + int count = 0; + + for (size_t j = 0; j < cHeader(imap)->part_headers.size(); j++) + { + imap->_cPartIdx = j; + if (!cPart(imap)->rfc822_part && cPart(imap)->attach_type != esp_mail_att_type_none) + { + count++; + MB_String str = count; + appendDot(str); + prependSpace(str, cPart(imap)->filename.c_str()); + sendCallback(imap, str.c_str(), false, false); + } + } + } + +#endif + + MB_String s1, s2; + int _idx1 = 0; + for (size_t j = 0; j < cHeader(imap)->part_headers.size(); j++) + { + imap->_cPartIdx = j; + if (cPart(imap)->rfc822_part) + { + s1 = cPart(imap)->partNumStr; + _idx1 = cPart(imap)->rfc822_msg_Idx; + } + else if (s1.length() > 0) + { + if (multipartMember(s1, cPart(imap)->partNumStr)) + { + cPart(imap)->message_sub_type = esp_mail_imap_message_sub_type_rfc822; + cPart(imap)->rfc822_msg_Idx = _idx1; + } + } + + if (cPart(imap)->multipart_sub_type == esp_mail_imap_multipart_sub_type_parallel) + s2 = cPart(imap)->partNumStr; + else if (s2.length() > 0) + { + if (multipartMember(s2, cPart(imap)->partNumStr)) + { + cPart(imap)->attach_type = esp_mail_att_type_attachment; + if (cPart(imap)->filename.length() == 0) + { + if (cPart(imap)->name.length() > 0) + cPart(imap)->filename = cPart(imap)->name; + else + { + char *uid = getRandomUID(); + cPart(imap)->filename = uid; + cPart(imap)->filename += mimeinfo[esp_mail_file_extension_dat].endsWith; + freeMem(&uid); + } + } + } + } + + checkFirmwareFile(imap, cPart(imap)->filename.c_str(), *cPart(imap), true); + } + + int attach_count = 0; + int ccnt = 0; + + for (size_t j = 0; j < cHeader(imap)->part_headers.size(); j++) + { + imap->_cPartIdx = j; + + if (cPart(imap)->rfc822_part || cPart(imap)->multipart_sub_type != esp_mail_imap_multipart_sub_type_none) + continue; + + bool rfc822_body_subtype = cPart(imap)->message_sub_type == esp_mail_imap_message_sub_type_rfc822 && cPart(imap)->attach_type != esp_mail_att_type_attachment; + + if (cPart(imap)->attach_type == esp_mail_att_type_none && (cPart(imap)->msg_type == esp_mail_msg_type_html || cPart(imap)->msg_type == esp_mail_msg_type_plain || cPart(imap)->msg_type == esp_mail_msg_type_enriched)) + { + + bool ret = ((imap->_imap_data->enable.rfc822 || imap->_imap_data->download.rfc822) && rfc822_body_subtype) || (!rfc822_body_subtype && ((imap->_imap_data->enable.text && (cPart(imap)->msg_type == esp_mail_msg_type_plain || cPart(imap)->msg_type == esp_mail_msg_type_enriched)) || (imap->_imap_data->enable.html && cPart(imap)->msg_type == esp_mail_msg_type_html) || (cPart(imap)->msg_type == esp_mail_msg_type_html && imap->_imap_data->download.html) || ((cPart(imap)->msg_type == esp_mail_msg_type_plain || cPart(imap)->msg_type == esp_mail_msg_type_enriched) && imap->_imap_data->download.text))); + if (!ret) + continue; + +#if !defined(SILENT_MODE) + + if ((imap->_imap_data->download.rfc822 && rfc822_body_subtype) || (!rfc822_body_subtype && ((cPart(imap)->msg_type == esp_mail_msg_type_html && imap->_imap_data->download.html) || ((cPart(imap)->msg_type == esp_mail_msg_type_plain || cPart(imap)->msg_type == esp_mail_msg_type_enriched) && imap->_imap_data->download.text)))) + { + + if (ccnt == 0 && imap->_statusCallback) + sendCallback(imap, esp_mail_cb_str_43 /* "Downloading messages..." */, true, false); + + if (imap->_debug) + { + debugPrintNewLine(); + if (cPart(imap)->msg_type == esp_mail_msg_type_plain || cPart(imap)->msg_type == esp_mail_msg_type_enriched) + esp_mail_debug_print_tag(esp_mail_dbg_str_74 /* "download plain TEXT message" */, esp_mail_debug_tag_type_client, true); + else if (cPart(imap)->msg_type == esp_mail_msg_type_html) + esp_mail_debug_print_tag(esp_mail_dbg_str_71 /* "download HTML message" */, esp_mail_debug_tag_type_client, true); + } + } + else + { + if (ccnt == 0) + sendCallback(imap, esp_mail_cb_str_28 /* "Reading messages..." */, true, false); + + if (imap->_debug) + { + debugPrintNewLine(); + if (cPart(imap)->msg_type == esp_mail_msg_type_plain || cPart(imap)->msg_type == esp_mail_msg_type_enriched) + esp_mail_debug_print_tag(esp_mail_dbg_str_46 /* "reading plain TEXT message" */, esp_mail_debug_tag_type_client, true); + else if (cPart(imap)->msg_type == esp_mail_msg_type_html) + esp_mail_debug_print_tag(esp_mail_dbg_str_47 /* "reading HTML message" */, esp_mail_debug_tag_type_client, true); + } + } + +#endif + + ccnt++; + + if (!sendFetchCommand(imap, i, esp_mail_imap_cmd_fetch_body_text)) + return false; + + imap->_imap_cmd = esp_mail_imap_cmd_fetch_body_text; + if (!handleIMAPResponse(imap, IMAP_STATUS_IMAP_RESPONSE_FAILED, closeSession)) + return false; + } + else if (cPart(imap)->attach_type != esp_mail_att_type_none && (imap->_storageReady || cPart(imap)->is_firmware_file)) + { + + if (cPart(imap)->is_firmware_file || (imap->_imap_data->download.attachment && cPart(imap)->attach_type == esp_mail_att_type_attachment) || (imap->_imap_data->download.inlineImg && cPart(imap)->attach_type == esp_mail_att_type_inline)) + { +#if !defined(SILENT_MODE) + if (cPart(imap)->save_to_file) + { + + if (attach_count == 0 && imap->_statusCallback) + sendCallback(imap, esp_mail_cb_str_19 /* "Downloading attachments..." */, true, false); + + if (imap->_debug) + { + debugPrintNewLine(); + int bufLen = 100; + char *buf = allocMem(bufLen); + snprintf(buf, bufLen, pgm2Str(esp_mail_dbg_str_70 /* "download attachment %d of %d" */), attach_count + 1, (int)cHeader(imap)->attachment_count); + esp_mail_debug_print_tag(buf, esp_mail_debug_tag_type_client, true); + // release memory + freeMem(&buf); + + MB_String filePath = imap->_imap_data->storage.saved_path; + filePath += esp_mail_str_10; /* "/" */ + filePath += cHeader(imap)->message_uid; + filePath += esp_mail_str_10; /* "/" */ + filePath += cPart(imap)->filename; + + esp_mail_debug_print_tag(filePath.c_str(), esp_mail_debug_tag_type_client, true); + } + } +#endif + + attach_count++; + + if (cPart(imap)->octetLen <= (int)imap->_imap_data->limit.attachment_size) + { + + if (imap->_storageReady || cPart(imap)->is_firmware_file) + { + + if ((int)j < (int)cHeader(imap)->part_headers.size() - 1) + if (cHeader(imap)->part_headers[j + 1].octetLen > (int)imap->_imap_data->limit.attachment_size) + cHeader(imap)->downloaded_bytes += cHeader(imap)->part_headers[j + 1].octetLen; + + if (!sendFetchCommand(imap, i, esp_mail_imap_cmd_fetch_body_attachment)) + return false; + + imap->_imap_cmd = esp_mail_imap_cmd_fetch_body_attachment; + if (!handleIMAPResponse(imap, IMAP_STATUS_IMAP_RESPONSE_FAILED, closeSession)) + return false; + + yield_impl(); + } + } + else + { + if ((int)j == (int)cHeader(imap)->part_headers.size() - 1) + cHeader(imap)->downloaded_bytes += cPart(imap)->octetLen; + } + } + } + } + } + + if (imap->_storageReady && imap->_imap_data->download.header && !imap->_headerSaved) + { +#if !defined(SILENT_MODE) + if (imap->_statusCallback) + sendCallback(imap, esp_mail_cb_str_21 /* "Saving message header to file..." */, true, false); + else if (imap->_debug) + debugPrintNewLine(); +#endif + + saveHeader(imap, false); + saveHeader(imap, true); + } + + // save files list to file + if (imap->_storageReady && imap->_sdFileList.length() > 0) + { + MB_String filepath = cHeader(imap)->message_uid; + filepath += mimeinfo[esp_mail_file_extension_txt].endsWith; + if (mbfs->open(filepath, mbfs_type imap->_imap_data->storage.type, mb_fs_open_mode_write) > -1) + { + mbfs->print(mbfs_type imap->_imap_data->storage.type, imap->_sdFileList.c_str()); + mbfs->close(mbfs_type imap->_imap_data->storage.type); + } + } + + imap->_cMsgIdx++; + } +#if !defined(SILENT_MODE) + if (imap->_debug) + { + MB_String str = esp_mail_str_55; /* "Free Heap: " */ + str += MailClient.getFreeHeap(); + esp_mail_debug_print_tag(str.c_str(), esp_mail_debug_tag_type_client, true); + } +#endif + } +#if defined(MB_ARDUINO_ESP) || defined(MB_ARDUINO_PICO) +out: +#endif + if (readCount < imap->_imap_msg_num.size()) + { + imap->_mbif._availableItems = readCount; + imap->_imap_msg_num.erase(imap->_imap_msg_num.begin() + readCount, imap->_imap_msg_num.end()); + } + + if (closeSession) + { + if (!imap->closeSession()) + return false; + } + else + { +#if !defined(SILENT_MODE) + printDebug(imap, + esp_mail_cb_str_46 /* "Finished reading Email" */, + esp_mail_dbg_str_29 /* "finished reading Email" */, + esp_mail_debug_tag_type_client, + true, + false); +#endif + } + + imap->_cbData._success = true; + +#if !defined(SILENT_MODE) + if (imap->_statusCallback) + callBackSendNewLine(imap, true); +#endif + + return true; +} + +void ESP_Mail_Client::appendHeadersFetchCommand(IMAPSession *imap, MB_String &cmd, int index, bool debug) +{ + if (imap->_uidSearch || imap->_imap_msg_num[index].type == esp_mail_imap_msg_num_type_uid) + appendSpace(cmd, true, 2, imap_commands[esp_mail_imap_command_uid].text, imap_commands[esp_mail_imap_command_fetch].text); + else + appendSpace(cmd, true, imap_commands[esp_mail_imap_command_fetch].text); +#if !defined(SILENT_MODE) + if (debug && imap->_debug) + esp_mail_debug_print_tag(esp_mail_dbg_str_26 /* "fetch message header" */, esp_mail_debug_tag_type_client, true); +#endif + joinStringSpace(cmd, false, 2, MB_String((int)imap->_imap_msg_num[index].value).c_str(), imap_commands[esp_mail_imap_command_body].text); + + if (!imap->_imap_data->fetch.set_seen) + prependDot(cmd, imap_commands[esp_mail_imap_command_peek].text); +} + +void ESP_Mail_Client::appendRFC822HeadersFetchCommand(MB_String &cmd) +{ + joinStringDot(cmd, 2, imap_commands[esp_mail_imap_command_header].text, imap_commands[esp_mail_imap_command_fields].text); + appendSpace(cmd); + + MB_String cmd2; + + for (int i = 0; i < esp_mail_rfc822_header_field_maxType; i++) + appendSpace(cmd2, false, rfc822_headers[i].text); + + joinStringSpace(cmd2, false, 4, message_headers[esp_mail_message_header_field_content_type].text, + message_headers[esp_mail_message_header_field_content_transfer_encoding].text, + message_headers[esp_mail_message_header_field_content_language].text, + message_headers[esp_mail_message_header_field_accept_language].text); + + appendString(cmd, cmd2.c_str(), false, false, esp_mail_string_mark_type_round_bracket); +} + +bool ESP_Mail_Client::getMultipartFechCmd(IMAPSession *imap, int msgIdx, MB_String &partText) +{ + if (imap->_multipart_levels.size() == 0) + return false; + + int cLevel = imap->_multipart_levels.size() - 1; + + cHeader(imap)->partNumStr.clear(); + + appendHeadersFetchCommand(imap, partText, msgIdx, false); + + MB_String cmd1; + for (size_t i = 0; i < imap->_multipart_levels.size(); i++) + { + if (i > 0) + { + cmd1 += esp_mail_str_27; /* "." */ + cHeader(imap)->partNumStr += esp_mail_str_27; /* "." */ + } + + cmd1 += imap->_multipart_levels[i].level; + cHeader(imap)->partNumStr += imap->_multipart_levels[i].level; + } + + if (imap->_multipart_levels[cLevel].fetch_rfc822_header) + { + MB_String cmd2; + appendRFC822HeadersFetchCommand(cmd2); + prependDot(cmd1, cmd2.c_str()); + imap->_multipart_levels[cLevel].append_body_text = true; + } + else + prependDot(cmd1, imap_commands[esp_mail_imap_command_mime].text); + + appendString(partText, cmd1.c_str(), false, false, esp_mail_string_mark_type_square_bracket); + + imap->_multipart_levels[cLevel].fetch_rfc822_header = false; + + return true; +} + +bool ESP_Mail_Client::multipartMember(const MB_String &parent, const MB_String &child) +{ + if (parent.length() > child.length()) + return false; + + for (size_t i = 0; i < parent.length(); i++) + if (parent[i] != child[i]) + return false; + + return true; +} + +bool ESP_Mail_Client::fetchMultipartBodyHeader(IMAPSession *imap, int msgIdx) +{ + bool ret = true; + + if (!connected(imap)) + { + closeTCPSession(imap); + return false; + } + int cLevel = 0; + + // slower than BODYSTRUCTURE parsing but sure + do + { + +#if defined(MB_ARDUINO_ESP) || defined(MB_ARDUINO_PICO) + // Prevent stack overflow + if (MailClient.getFreeHeap() < ESP_MAIL_MIN_MEM) + { + errorStatusCB(imap, nullptr, MAIL_CLIENT_ERROR_OUT_OF_MEMORY, true); + break; + } +#endif + + struct esp_mail_message_part_info_t *_cpart = &cHeader(imap)->part_headers[cHeader(imap)->message_data_count - 1]; + bool rfc822_body_subtype = _cpart->message_sub_type == esp_mail_imap_message_sub_type_rfc822 && _cpart->attach_type != esp_mail_att_type_attachment; + + MB_String cmd; + if (!getMultipartFechCmd(imap, msgIdx, cmd)) + return true; + + if (imap->_debug) + printBodyPartFechingDubug(imap, cHeader(imap)->partNumStr.c_str(), imap->_multipart_levels.size() > 1); + + // Try fetching the part and its sub parts hierarchically + // Some sub part may not exist at the current multipart level + if (imapSend(imap, cmd.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return false; + + imap->_imap_cmd = esp_mail_imap_cmd_fetch_body_mime; + ret = handleIMAPResponse(imap, IMAP_STATUS_IMAP_RESPONSE_FAILED, false); + + _cpart = &cHeader(imap)->part_headers[cHeader(imap)->message_data_count - 1]; + rfc822_body_subtype = _cpart->message_sub_type == esp_mail_imap_message_sub_type_rfc822 && _cpart->attach_type != esp_mail_att_type_attachment; + cLevel = imap->_multipart_levels.size() - 1; + + if (ret) + { + if (_cpart->multipart) + { + if (_cpart->multipart_sub_type == esp_mail_imap_multipart_sub_type_parallel || _cpart->multipart_sub_type == esp_mail_imap_multipart_sub_type_alternative || _cpart->multipart_sub_type == esp_mail_imap_multipart_sub_type_related || _cpart->multipart_sub_type == esp_mail_imap_multipart_sub_type_mixed) + { + struct esp_mail_imap_multipart_level_t mlevel; + mlevel.level = 1; + mlevel.fetch_rfc822_header = false; + mlevel.append_body_text = false; + imap->_multipart_levels.push_back(mlevel); + fetchMultipartBodyHeader(imap, msgIdx); + } + else + imap->_multipart_levels[cLevel].level++; + } + else + { + if (rfc822_body_subtype) + { + // Get additional rfc822 message header + imap->_multipart_levels[cLevel].fetch_rfc822_header = true; + fetchMultipartBodyHeader(imap, msgIdx); + } + else + { + if (imap->_multipart_levels[cLevel].append_body_text) + { + // single part rfc822 message body, append TEXT to the body fetch command + prependDot(_cpart->partNumFetchStr, imap_commands[esp_mail_imap_command_text].text); + imap->_multipart_levels[cLevel].append_body_text = false; + } + imap->_multipart_levels[cLevel].level++; + } + } + } + + } while (ret); + + imap->_multipart_levels.pop_back(); + + if (imap->_multipart_levels.size() > 0) + { + cLevel = imap->_multipart_levels.size() - 1; + imap->_multipart_levels[cLevel].level++; + } + + return true; +} + +void ESP_Mail_Client::printBodyPartFechingDubug(IMAPSession *imap, const char *partNum, bool multiLevel) +{ +#if !defined(SILENT_MODE) + MB_String str = multiLevel ? esp_mail_dbg_str_28 /* "fetch body sub part header, " */ : esp_mail_dbg_str_27; /* "fetch body part header, " */ + str += partNum; + esp_mail_debug_print_tag(str.c_str(), esp_mail_debug_tag_type_client, true); +#endif +} + +bool ESP_Mail_Client::imapAuth(IMAPSession *imap, bool &ssl) +{ + + if (!sessionExisted(imap)) + return false; + + imap->_auth_capability[esp_mail_auth_capability_login] = false; + + imap->_session_cfg->int_start_tls = imap->_session_cfg->secure.startTLS; + imap->_session_cfg->int_mode = imap->_session_cfg->secure.mode; + +#if !defined(ESP_MAIL_DISABLE_SSL) +unauthenticate: +#endif + + // capabilities may change after TLS negotiation + if (!imap->checkCapabilities()) + return false; + +#if !defined(ESP_MAIL_DISABLE_SSL) + + if (imap->_session_cfg->int_mode != esp_mail_secure_mode_nonsecure) + { + // start TLS when needed or the server issues + if ((imap->_auth_capability[esp_mail_auth_capability_starttls] || imap->_session_cfg->int_start_tls || imap->_session_cfg->int_mode == esp_mail_secure_mode_ssl_tls) && !ssl) + { +#if !defined(SILENT_MODE) + printDebug(imap, + esp_mail_cb_str_2 /* "Sending STARTTLS command..." */, + esp_mail_dbg_str_1 /* "send command, STARTTLS" */, + esp_mail_debug_tag_type_client, + true, + false); +#endif + + imapSend(imap, imap->prependTag(imap_commands[esp_mail_imap_command_starttls].text).c_str(), true); + + // rfc2595 section 3.1 + imap->_imap_cmd = esp_mail_imap_cmd_starttls; + if (!handleIMAPResponse(imap, IMAP_STATUS_BAD_COMMAND, false)) + return false; + +#if !defined(SILENT_MODE) + if (imap->_debug) + esp_mail_debug_print_tag(esp_mail_dbg_str_22 /* "perform SSL/TLS handshake" */, esp_mail_debug_tag_type_client, true); +#endif + + // connect in secure mode + // do TLS handshake + + if (!imap->client.connectSSL(imap->_session_cfg->certificate.verify)) + return handleIMAPError(imap, MAIL_CLIENT_ERROR_SSL_TLS_STRUCTURE_SETUP, false); + + // set the secure mode + imap->_session_cfg->int_start_tls = false; + imap->_session_cfg->int_mode = esp_mail_secure_mode_undefined; + ssl = true; + imap->_secure = true; + + // check the capabilitiy again to prevent the man in the middle attack + goto unauthenticate; + } + } + +#endif + + imap->clearMessageData(); + imap->_mailboxOpened = false; + + bool creds = imap->_session_cfg->login.email.length() > 0 && imap->_session_cfg->login.password.length() > 0; + bool sasl_auth_oauth = imap->_session_cfg->login.accessToken.length() > 0 && imap->_auth_capability[esp_mail_auth_capability_xoauth2]; + bool sasl_login = creds; + bool sasl_auth_plain = imap->_auth_capability[esp_mail_auth_capability_plain] && creds; + + bool supported_sasl = sasl_auth_oauth || sasl_login || sasl_auth_plain; + + if (!supported_sasl) + return handleIMAPError(imap, IMAP_STATUS_NO_SUPPORTED_AUTH, false); + + // rfc4959 + if (supported_sasl) + { +#if !defined(SILENT_MODE) + if (imap->_statusCallback) + sendCallback(imap, esp_mail_cb_str_14 /* "Logging in..." */, true, false); + else if (imap->_debug) + debugPrintNewLine(); +#endif + } + + if (sasl_auth_oauth) + { + + if (!imap->_auth_capability[esp_mail_auth_capability_xoauth2]) + { + handleIMAPError(imap, IMAP_STATUS_SERVER_OAUTH2_LOGIN_DISABLED, false); + return false; + } + +#if !defined(SILENT_MODE) + if (imap->_debug) + esp_mail_debug_print_tag(esp_mail_dbg_str_45 /* "send IMAP command, AUTH XOAUTH2" */, esp_mail_debug_tag_type_client, true); +#endif + + MB_String cmd; + joinStringSpace(cmd, true, 2, imap_commands[esp_mail_imap_command_authenticate].text, imap_commands[esp_mail_imap_command_xoauth2].text); + + if (imap->_auth_capability[esp_mail_auth_capability_sasl_ir]) + { + prependSpace(cmd, getXOAUTH2String(imap->_session_cfg->login.email, imap->_session_cfg->login.accessToken).c_str()); + if (imapSend(imap, cmd.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return false; + } + else + { + if (imapSend(imap, cmd.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return false; + + imap->_imap_cmd = esp_mail_imap_cmd_sasl_auth_oauth; + if (!handleIMAPResponse(imap, IMAP_STATUS_AUTHENTICATE_FAILED, true)) + return false; + + cmd = getXOAUTH2String(imap->_session_cfg->login.email, imap->_session_cfg->login.accessToken); + + if (imapSend(imap, cmd.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return false; + } + + imap->_imap_cmd = esp_mail_imap_cmd_sasl_auth_oauth; + if (!handleIMAPResponse(imap, IMAP_STATUS_AUTHENTICATE_FAILED, false)) + return false; + } + else if (sasl_auth_plain) + { + +#if !defined(SILENT_MODE) + if (imap->_debug) + esp_mail_debug_print_tag(esp_mail_dbg_str_44 /* "send IMAP command, AUTHENTICATE PLAIN" */, esp_mail_debug_tag_type_client, true); +#endif + + int len = imap->_session_cfg->login.email.length() + imap->_session_cfg->login.password.length() + 2; + uint8_t *tmp = allocMem(len); + memset(tmp, 0, len); + int p = 1; + memcpy(tmp + p, imap->_session_cfg->login.email.c_str(), imap->_session_cfg->login.email.length()); + p += imap->_session_cfg->login.email.length() + 1; + memcpy(tmp + p, imap->_session_cfg->login.password.c_str(), imap->_session_cfg->login.password.length()); + p += imap->_session_cfg->login.password.length(); + + MB_String cmd; + joinStringSpace(cmd, true, 2, imap_commands[esp_mail_imap_command_authenticate].text, imap_commands[esp_mail_imap_command_plain].text); + + if (imap->_auth_capability[esp_mail_auth_capability_sasl_ir]) + { + prependSpace(cmd, encodeBase64Str(tmp, p).c_str()); + // release memory + freeMem(&tmp); + + if (imapSend(imap, cmd.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return false; + } + else + { + + if (imapSend(imap, cmd.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return false; + + imap->_imap_cmd = esp_mail_imap_cmd_sasl_auth_plain; + + if (!handleIMAPResponse(imap, IMAP_STATUS_AUTHENTICATE_FAILED, true)) + return false; + + cmd = encodeBase64Str(tmp, p); + // release memory + freeMem(&tmp); + + if (imapSend(imap, cmd.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return false; + } + + imap->_imap_cmd = esp_mail_imap_cmd_sasl_auth_plain; + if (!handleIMAPResponse(imap, IMAP_STATUS_AUTHENTICATE_FAILED, true)) + return false; + } + else if (sasl_login) + { + +#if !defined(SILENT_MODE) + if (imap->_debug) + esp_mail_debug_print_tag(esp_mail_dbg_str_34 /* "send IMAP command, LOGIN" */, esp_mail_debug_tag_type_client, true); +#endif + MB_String cmd; + joinStringSpace(cmd, true, 3, imap_commands[esp_mail_imap_command_login].text, imap->_session_cfg->login.email.c_str(), imap->_session_cfg->login.password.c_str()); + + if (imapSend(imap, cmd.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return false; + + imap->_imap_cmd = esp_mail_imap_cmd_sasl_login; + if (!handleIMAPResponse(imap, IMAP_STATUS_AUTHENTICATE_FAILED, true)) + return false; + } + + // auto capabilities after login? + if (!imap->_feature_capability[esp_mail_imap_read_capability_auto_caps]) + { + if (!imap->checkCapabilities()) + return false; + } + + if (imap->_feature_capability[esp_mail_imap_read_capability_id]) + { + if (!imap->id(&imap->_imap_data->identification)) + return false; + } + + if (supported_sasl) + imap->_authenticated = true; + + return true; +} + +bool ESP_Mail_Client::imapLogout(IMAPSession *imap) +{ + +#if defined(ESP8266) + return false; +#endif + + if (!sessionExisted(imap)) + return false; + +#if !defined(SILENT_MODE) + printDebug(imap, + esp_mail_cb_str_20 /* "Logging out..." */, + esp_mail_dbg_str_38 /* "send IMAP command, LOGOUT" */, + esp_mail_debug_tag_type_client, + true, + false); +#endif + + if (imapSend(imap, imap->prependTag(imap_commands[esp_mail_imap_command_logout].text).c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return false; + + imap->_imap_cmd = esp_mail_imap_cmd_logout; + if (!handleIMAPResponse(imap, IMAP_STATUS_BAD_COMMAND, false)) + return false; + + imap->_authenticated = false; + +#if !defined(SILENT_MODE) + printDebug(imap, + esp_mail_cb_str_47 /* "Log out completed" */, + esp_mail_dbg_str_31 /* "log out completed" */, + esp_mail_debug_tag_type_client, + true, + false); +#endif + return true; +} + +size_t ESP_Mail_Client::imapSend(IMAPSession *imap, PGM_P data, bool newline) +{ + if (!imap || !sessionReady(imap)) + return 0; + + int sent = 0; + + MB_String s = data; + + int toSend = newline ? s.length() + 2 : s.length(); + + if (imap->_debug && imap->_debugLevel > esp_mail_debug_level_maintainer && !imap->_customCmdResCallback) + esp_mail_debug_print(s.c_str(), newline); + + sent = newline ? imap->client.println(s.c_str()) : imap->client.print(s.c_str()); + + if (sent != toSend) + { + errorStatusCB(imap, nullptr, sent, true); + sent = 0; + } + + return sent; +} + +size_t ESP_Mail_Client::imapSend(IMAPSession *imap, int data, bool newline) +{ + MB_String s = data; + return imapSend(imap, s.c_str(), newline); +} + +size_t ESP_Mail_Client::imapSend(IMAPSession *imap, uint8_t *data, size_t size) +{ + if (!imap || !sessionReady(imap)) + return 0; + + int sent = 0; + + sent = imap->client.write(data, size); + + if (sent != (int)size) + { + errorStatusCB(imap, nullptr, sent, true); + sent = 0; + } + + return sent; +} + +bool ESP_Mail_Client::mSetFlag(IMAPSession *imap, MB_StringPtr sequenceSet, MB_StringPtr flag, esp_mail_imap_store_flag_type type, bool closeSession, bool silent, bool UID, int32_t modsequence) +{ + if (!reconnect(imap)) + return false; + + if (!imap->connected()) + { + imap->_mailboxOpened = false; + return false; + } + + if (imap->_currentFolder.length() == 0) + { +#if !defined(SILENT_MODE) + printDebug(imap, + esp_mail_error_imap_str_11 /* "no mailbox opened" */, + esp_mail_error_imap_str_11 /* "no mailbox opened" */, + esp_mail_debug_tag_type_client, + true, + false); +#endif + } + else + { + if (imap->_readOnlyMode || !imap->_mailboxOpened) + { + if (!imap->selectFolder(imap->_currentFolder.c_str(), false)) + return false; + } + } + +#if !defined(SILENT_MODE) + PGM_P p1 = NULL; + PGM_P p2 = NULL; + if (type == esp_mail_imap_store_flag_type_set) + { + p1 = esp_mail_cb_str_26; /* "Setting FLAG..." */ + p2 = esp_mail_dbg_str_41; /* "setting FLAG" */ + } + else if (type == esp_mail_imap_store_flag_type_add) + { + p1 = esp_mail_cb_str_24; /* "Adding FLAG..." */ + p2 = esp_mail_dbg_str_42; /* "adding FLAG" */ + } + else + { + p1 = esp_mail_cb_str_23; /* "Removing FLAG..." */ + p2 = esp_mail_dbg_str_43; /* "removing FLAG" */ + } + + printDebug(imap, + p1, + p2, + esp_mail_debug_tag_type_client, + true, + false); +#endif + + if (!sessionExisted(imap)) + return false; + + MB_String cmd; + if (UID) + appendSpace(cmd, true, 2, imap_commands[esp_mail_imap_command_uid].text, imap_commands[esp_mail_imap_command_store].text); + else + appendSpace(cmd, true, imap_commands[esp_mail_imap_command_store].text); + + cmd += sequenceSet; + + imap->addModifier(cmd, esp_mail_imap_command_unchangedsince, modsequence); + + if (type == esp_mail_imap_store_flag_type_set) + cmd += imap_cmd_pre_tokens[esp_mail_imap_command_flags]; + else if (type == esp_mail_imap_store_flag_type_add) + cmd += imap_cmd_pre_tokens[esp_mail_imap_command_plus_flags]; + else + cmd += imap_cmd_pre_tokens[esp_mail_imap_command_minus_flags]; + + if (silent) + prependDot(cmd, imap_commands[esp_mail_imap_command_silent].text); + + appendSpace(cmd); + appendString(cmd, MB_String(flag).c_str(), false, false, esp_mail_string_mark_type_round_bracket); + + if (imapSend(imap, cmd.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return false; + + imap->_imap_cmd = esp_mail_imap_cmd_store; + + if (!handleIMAPResponse(imap, IMAP_STATUS_STORE_FAILED, false)) + return false; + + if (closeSession) + imap->closeSession(); + + return true; +} + +int ESP_Mail_Client::parseSearchResponse(IMAPSession *imap, esp_mail_imap_response_data &res, PGM_P tag, const char *key) +{ + int bufLen = res.chunkBufSize; + int ret = -1; + char c = 0; + int idx = 0; + int num = 0; + + size_t tagLen = strlen_P(tag); + MB_String _tag = tag; + + while (imap->client.available() > 0 && idx < bufLen) + { + yield_impl(); + + ret = imap->client.read(); + + if (ret > -1) + { + + if (idx >= bufLen - 1) + return idx; + + c = (char)ret; + + if (c == '\n') + c = ' '; + + res.response[idx++] = c; + + if (res.chunkIdx == 0) + { + // Search response parsing + if (strcmp(res.response, key) == 0) + { + res.chunkIdx++; + return 0; + } + else + { + // Status response parsing + res.imapResp = imapResponseStatus(imap, res.response, esp_mail_imap_tag_str); + + // Exit if error or complete (no messages found) + if (res.imapResp != esp_mail_imap_resp_unknown) + goto end_search; + } + } + else + { + if (c == ' ') + { + imap->_mbif._searchCount++; + if (imap->_imap_data->enable.recent_sort) + { + esp_mail_imap_msg_num_t msg_num; + msg_num.type = imap->_uidSearch ? esp_mail_imap_msg_num_type_uid : esp_mail_imap_msg_num_type_number; + msg_num.value = (uint32_t)atoi(res.response); + + imap->_imap_msg_num.push_back(msg_num); + + if (imap->_imap_msg_num.size() > imap->_imap_data->limit.search) + imap->_imap_msg_num.erase(imap->_imap_msg_num.begin()); + } + else + { + if (imap->_imap_msg_num.size() < imap->_imap_data->limit.search) + { + esp_mail_imap_msg_num_t msg_num; + msg_num.type = imap->_uidSearch ? esp_mail_imap_msg_num_type_uid : esp_mail_imap_msg_num_type_number; + msg_num.value = (uint32_t)atoi(res.response); + + imap->_imap_msg_num.push_back(msg_num); + } + } + + if (imap->_debug) + { + num = (float)(100.0f * imap->_mbif._searchCount / imap->_mbif._msgCount); + if (res.searchCount != num) + { + res.searchCount = num; + searchReport(imap, num); + } + } + + res.chunkIdx++; + return idx; + } + else if (idx >= (int)tagLen) + { + if (strpos(res.response, _tag.c_str(), 0, false) > -1) + { +#if defined(MB_USE_STD_VECTOR) + if (imap->_imap_data->enable.recent_sort) + std::sort(imap->_imap_msg_num.begin(), imap->_imap_msg_num.end(), compareMore); +#else + if (imap->_imap_data->enable.recent_sort) + numDecSort(imap->_imap_msg_num); +#endif + goto end_search; + } + } + } + } + } + + return idx; + +end_search: + + res.endSearch = true; + int read = imap->client.available(); + read = imap->client.readBytes(res.response + idx, read); + return idx + read; +} + +#if !defined(MB_USE_STD_VECTOR) +void ESP_Mail_Client::numDecSort(_vectorImpl &arr) +{ + + struct esp_mail_imap_msg_num_t tmp; + + for (size_t i = 0; i < arr.size(); ++i) + { + for (size_t j = i + 1; j < arr.size(); ++j) + { + if (arr[i].value < arr[j].value) + { + tmp = arr[i]; + arr[i] = arr[j]; + arr[j] = tmp; + } + } + } +} +#endif + +struct esp_mail_message_part_info_t *ESP_Mail_Client::cPart(IMAPSession *imap) +{ + if (cHeader(imap) && imap->_cPartIdx < (int)cHeader(imap)->part_headers.size()) + return &cHeader(imap)->part_headers[imap->_cPartIdx]; + return nullptr; +} + +struct esp_mail_message_header_t *ESP_Mail_Client::cHeader(IMAPSession *imap) +{ + if (cIdx(imap) < (int)imap->_headers.size()) + return &imap->_headers[cIdx(imap)]; + return nullptr; +} + +bool ESP_Mail_Client::parseHeaderField(IMAPSession *imap, const char *buf, PGM_P beginToken, bool caseSensitive, struct esp_mail_message_header_t &header, int &headerState, int state) +{ + if (strcmpP(buf, 0, beginToken, caseSensitive)) + { + headerState = state; + char *tmp = subStr(buf, beginToken, NULL, 0, -1, caseSensitive); + if (tmp) + { + collectHeaderField(imap, tmp, header, headerState); + // release memory + freeMem(&tmp); + return true; + } + } + + return false; +} + +void ESP_Mail_Client::parseHeaderResponse(IMAPSession *imap, esp_mail_imap_response_data &res, bool caseSensitive) +{ + char *tmp = nullptr; + if (res.chunkIdx == 0) + { + MB_String str; + joinStringDot(str, 2, imap_commands[esp_mail_imap_command_header].text, imap_commands[esp_mail_imap_command_fields].text); + + if (!res.isUntaggedResponse && strposP(res.response, str.c_str(), 0, caseSensitive) != -1 && res.response[0] == '*') + res.isUntaggedResponse = true; + + if (res.isUntaggedResponse && res.response[strlen(res.response) - 1] == '}') + res.untaggedRespCompleted = true; + + if (res.isUntaggedResponse && res.header.message_no == 0) + { + tmp = subStr(res.response, imap_responses[esp_mail_imap_response_untagged].text, imap_responses[esp_mail_imap_response_fetch].text, 0); + if (tmp) + { + res.header.message_no = atoi(tmp); + // release memory + freeMem(&tmp); + } + } + + if (res.isUntaggedResponse && res.untaggedRespCompleted) + { + tmp = subStr(res.response, esp_mail_str_36 /* "{" */, esp_mail_str_37 /* "}" */, 0, 0, caseSensitive); + if (tmp) + { + res.octetCount = 2; + res.header.header_data_len = atoi(tmp); + // release memory + freeMem(&tmp); + res.chunkIdx++; + } + } + } + else + { + if (res.octetCount > res.header.header_data_len + 2) + return; + + res.chunkIdx++; + + MB_String field; + + for (int i = esp_mail_rfc822_header_field_from; i < esp_mail_rfc822_header_field_maxType; i++) + { + appendHeaderName(field, rfc822_headers[i].text, true, false, false); + if (parseHeaderField(imap, res.response, field.c_str(), caseSensitive, res.header, res.headerState, i)) + return; + } + + appendHeaderName(field, message_headers[esp_mail_message_header_field_content_transfer_encoding].text, true, true, false); + + if (parseHeaderField(imap, res.response, field.c_str(), caseSensitive, res.header, res.headerState, esp_mail_imap_state_content_transfer_encoding)) + return; + + appendHeaderName(field, message_headers[esp_mail_message_header_field_accept_language].text, true, true, false); + + if (parseHeaderField(imap, res.response, field.c_str(), caseSensitive, res.header, res.headerState, esp_mail_imap_state_accept_language)) + return; + + appendHeaderName(field, message_headers[esp_mail_message_header_field_content_language].text, true, true, false); + + if (parseHeaderField(imap, res.response, field.c_str(), caseSensitive, res.header, res.headerState, esp_mail_imap_state_content_language)) + return; + + MB_String contentTypeName; + appendHeaderName(contentTypeName, message_headers[esp_mail_message_header_field_content_type].text, false, false, false); + if (strcmpP(res.response, 0, contentTypeName.c_str(), caseSensitive)) + { + res.headerState = esp_mail_imap_state_content_type; + tmp = subStr(res.response, contentTypeName.c_str(), esp_mail_str_35 /* ";" */, 0, 0, caseSensitive); + if (tmp) + { + // We set attachment status here as attachment should be included in multipart/mixed message, + // unless no real attachments included which we don't know until fetching the sub part. + if (strpos(tmp, esp_mail_imap_multipart_sub_type_t::mixed, 0, caseSensitive) != -1) + res.header.hasAttachment = true; + + collectHeaderField(imap, res.response, res.header, res.headerState); + // release memory + freeMem(&tmp); + } + } + } +} + +void ESP_Mail_Client::collectHeaderField(IMAPSession *imap, char *buf, struct esp_mail_message_header_t &header, int state) +{ + size_t i = 0; + while (buf[i] == ' ') + { + i++; + if (strlen(buf) <= i) + return; + } + + if (state < esp_mail_rfc822_header_field_maxType) + { + int ptr = getRFC822HeaderPtr(state, &header.header_fields); + if (ptr > 0) + { + *(addrTo(ptr)) += &buf[i]; + } + return; + } + + switch (state) + { + case esp_mail_imap_state_content_type: + header.content_type += &buf[i]; + break; + case esp_mail_imap_state_content_transfer_encoding: + header.content_transfer_encoding += &buf[i]; + break; + case esp_mail_imap_state_accept_language: + header.accept_language += &buf[i]; + break; + case esp_mail_imap_state_content_language: + header.content_language += &buf[i]; + break; + case esp_mail_imap_state_char_set: + header.char_set += &buf[i]; + break; + case esp_mail_imap_state_boundary: + header.boundary += &buf[i]; + break; + default: + break; + } +} + +bool ESP_Mail_Client::getDecodedHeader(IMAPSession *imap, const char *buf, PGM_P beginToken, MB_String &out, bool caseSensitive) +{ + if (getHeader(buf, beginToken, out, caseSensitive)) + { + // decode header text + decodeString(imap, out); + return true; + } + return false; +} + +void ESP_Mail_Client::checkFirmwareFile(IMAPSession *imap, const char *filename, struct esp_mail_message_part_info_t &part, bool defaultSize) +{ + if (strcmp(filename, imap->_imap_data->firmware_update.attach_filename.c_str()) == 0 && part.attach_type == esp_mail_att_type_attachment) + { + part.is_firmware_file = true; + // If no file size prop from Content-Disposition header + if (part.attach_data_size == 0 && defaultSize) + { +#if defined(ESP32) || defined(ESP8266) + int sketchFreeSpace = ESP.getFreeSketchSpace(); + part.attach_data_size = sketchFreeSpace ? sketchFreeSpace : 1024000; +#elif defined(MB_ARDUINO_PICO) + size_t spiffsSize = ((size_t)&_FS_end - (size_t)&_FS_start); + part.attach_data_size = spiffsSize ? spiffsSize / 2 : 1024000; +#endif + } + + if (!imap->_imap_data->firmware_update.save_to_file) + part.save_to_file = false; + } +} + +void ESP_Mail_Client::parsePartHeaderResponse(IMAPSession *imap, esp_mail_imap_response_data &res, bool caseSensitive) +{ + char *tmp = nullptr; + if (res.chunkIdx == 0) + { + tmp = subStr(res.response, imap_responses[esp_mail_imap_response_fetch].text, NULL, 0, -1); + if (tmp) + { + // release memory + freeMem(&tmp); + tmp = subStr(res.response, esp_mail_str_36 /* "{" */, esp_mail_str_37 /* "}" */, 0); + if (tmp) + { + res.chunkIdx++; + res.part.octetLen = atoi(tmp); + res.octetCount = 2; + // release memory + freeMem(&tmp); + } + } + } + else + { + MB_String value, old_value; + bool valueStored = false; + res.chunkIdx++; + + // if all octets read + + if (res.octetCount > res.part.octetLen) + { + + // Is inline attachment without content id or name or filename? + // It is supposed to be the inline message txt content, reset attach type to none + + if (res.part.attach_type == esp_mail_att_type_inline && res.part.CID.length() == 0) + res.part.attach_type = esp_mail_att_type_none; + + // Is attachment file extension missing? + // append extension + + if (res.part.attach_type == esp_mail_att_type_inline || res.part.attach_type == esp_mail_att_type_attachment) + { + if (res.part.filename.length() > 0 && res.part.filename.find('.') == MB_String::npos) + { + MB_String ext; + getExtfromMIME(res.part.content_type.c_str(), ext); + res.part.filename += ext; + } + + checkFirmwareFile(imap, res.part.filename.c_str(), res.part); + } + + return; + } + + // Content header field parse + if (strcmpP(res.response, 0, esp_mail_str_56 /* "content-" */, caseSensitive)) + { + // Content-Type + MB_String contentTypeName; + appendHeaderName(contentTypeName, message_headers[esp_mail_message_header_field_content_type].text, false, false, false); + if (strcmpP(res.response, 0, contentTypeName.c_str(), caseSensitive)) + { + + res.part.cur_content_hdr = esp_mail_message_part_info_t::content_header_field_type; + resetStringPtr(res.part); + + tmp = subStr(res.response, contentTypeName.c_str(), esp_mail_str_35 /* ";" */, 0, 0, caseSensitive); + if (tmp) + { + res.part.content_type = tmp; + // release memory + freeMem(&tmp); + int p1 = strposP(res.part.content_type.c_str(), esp_mail_imap_composite_media_type_t::multipart, 0, caseSensitive); + if (p1 != -1) + { + p1 += strlen(esp_mail_imap_composite_media_type_t::multipart) + 1; + res.part.multipart = true; + // inline or embedded images + if (strpos(res.part.content_type.c_str(), esp_mail_imap_multipart_sub_type_t::related, p1, caseSensitive) != -1) + res.part.multipart_sub_type = esp_mail_imap_multipart_sub_type_related; + // multiple text formats e.g. plain, html, enriched + else if (strpos(res.part.content_type.c_str(), esp_mail_imap_multipart_sub_type_t::alternative, p1, caseSensitive) != -1) + res.part.multipart_sub_type = esp_mail_imap_multipart_sub_type_alternative; + // medias + else if (strpos(res.part.content_type.c_str(), esp_mail_imap_multipart_sub_type_t::parallel, p1, caseSensitive) != -1) + res.part.multipart_sub_type = esp_mail_imap_multipart_sub_type_parallel; + // rfc822 encapsulated + else if (strpos(res.part.content_type.c_str(), esp_mail_imap_multipart_sub_type_t::digest, p1, caseSensitive) != -1) + res.part.multipart_sub_type = esp_mail_imap_multipart_sub_type_digest; + else if (strpos(res.part.content_type.c_str(), esp_mail_imap_multipart_sub_type_t::report, p1, caseSensitive) != -1) + res.part.multipart_sub_type = esp_mail_imap_multipart_sub_type_report; + // others can be attachments + else if (strpos(res.part.content_type.c_str(), esp_mail_imap_multipart_sub_type_t::mixed, p1, caseSensitive) != -1) + res.part.multipart_sub_type = esp_mail_imap_multipart_sub_type_mixed; + } + + p1 = strposP(res.part.content_type.c_str(), esp_mail_imap_composite_media_type_t::message, 0, caseSensitive); + if (p1 != -1) + { + p1 += strlen(esp_mail_imap_composite_media_type_t::message) + 1; + if (strpos(res.part.content_type.c_str(), esp_mail_imap_message_sub_type_t::rfc822, p1, caseSensitive) != -1) + res.part.message_sub_type = esp_mail_imap_message_sub_type_rfc822; + else if (strpos(res.part.content_type.c_str(), esp_mail_imap_message_sub_type_t::Partial, p1, caseSensitive) != -1) + res.part.message_sub_type = esp_mail_imap_message_sub_type_partial; + else if (strpos(res.part.content_type.c_str(), esp_mail_imap_message_sub_type_t::External_Body, p1, caseSensitive) != -1) + res.part.message_sub_type = esp_mail_imap_message_sub_type_external_body; + else if (strpos(res.part.content_type.c_str(), esp_mail_imap_message_sub_type_t::delivery_status, p1, caseSensitive) != -1) + res.part.message_sub_type = esp_mail_imap_message_sub_type_delivery_status; + } + + p1 = strpos(res.part.content_type.c_str(), esp_mail_imap_descrete_media_type_t::text, 0, caseSensitive); + if (p1 != -1) + { + p1 += strlen(esp_mail_imap_descrete_media_type_t::text) + 1; + if (strpos(res.part.content_type.c_str(), esp_mail_imap_media_text_sub_type_t::plain, p1, caseSensitive) != -1) + res.part.msg_type = esp_mail_msg_type_plain; + else if (strpos(res.part.content_type.c_str(), esp_mail_imap_media_text_sub_type_t::enriched, p1, caseSensitive) != -1) + res.part.msg_type = esp_mail_msg_type_enriched; + else if (strpos(res.part.content_type.c_str(), esp_mail_imap_media_text_sub_type_t::html, p1, caseSensitive) != -1) + res.part.msg_type = esp_mail_msg_type_html; + else + res.part.msg_type = esp_mail_msg_type_plain; + } + } + } + + // Content-Description + MB_String contentDescrName; + appendHeaderName(contentDescrName, message_headers[esp_mail_message_header_field_content_description].text, false, true, false); + if (getDecodedHeader(imap, res.response, contentDescrName.c_str(), res.part.descr, caseSensitive)) + { + res.part.cur_content_hdr = esp_mail_message_part_info_t::content_header_field_description; + + tmp = subStr(res.response, contentDescrName.c_str(), NULL, 0, -1, caseSensitive); + if (tmp) + { + value = tmp; + // release memory + freeMem(&tmp); + + res.part.stringPtr = toAddr(res.part.content_description); + value.trim(); + if (value.length() == 0) + return; + } + } + + // Content-ID + MB_String contentIdName; + appendHeaderName(contentIdName, message_headers[esp_mail_message_header_field_content_id].text, false, true, false); + if (strcmpP(res.response, 0, contentIdName.c_str(), caseSensitive)) + { + tmp = subStr(res.response, contentIdName.c_str(), NULL, 0, -1, caseSensitive); + if (tmp) + { + res.part.CID = tmp; + // release memory + freeMem(&tmp); + res.part.CID.trim(); + + if (res.part.CID[0] == '<') + res.part.CID.erase(0, 1); + + if (res.part.CID[res.part.CID.length() - 1] == '>') + res.part.CID.erase(res.part.CID.length() - 1, 1); + + // if inline attachment file name was not assigned + if (res.part.attach_type == esp_mail_att_type_inline && res.part.filename.length() == 0) + { + // set filename from content id and append extension later + res.part.filename = res.part.CID; + res.part.name = res.part.filename; + } + } + + res.part.cur_content_hdr = esp_mail_message_part_info_t::content_header_field_id; + resetStringPtr(res.part); + } + + // Content-Disposition + MB_String contentDispositionName; + appendHeaderName(contentDispositionName, message_headers[esp_mail_message_header_field_content_disposition].text, false, true, false); + if (strcmpP(res.response, 0, contentDispositionName.c_str(), caseSensitive)) + { + + res.part.cur_content_hdr = esp_mail_message_part_info_t::content_header_field_disposition; + resetStringPtr(res.part); + + tmp = subStr(res.response, contentDispositionName.c_str(), esp_mail_str_35 /* ";" */, 0, 0, caseSensitive); + if (tmp) + { + // don't count altenative part text and html as embedded contents + if (cHeader(imap)->multipart_sub_type != esp_mail_imap_multipart_sub_type_alternative) + { + res.part.content_disposition = tmp; + if (caseSensitive) + { + if (strcmp(tmp, esp_mail_content_disposition_type_t::attachment) == 0) + res.part.attach_type = esp_mail_att_type_attachment; + else if (strcmp(tmp, esp_mail_content_disposition_type_t::inline_) == 0) + res.part.attach_type = esp_mail_att_type_inline; + } + else + { + if (strcasecmp(tmp, esp_mail_content_disposition_type_t::attachment) == 0) + res.part.attach_type = esp_mail_att_type_attachment; + else if (strcasecmp(tmp, esp_mail_content_disposition_type_t::inline_) == 0) + res.part.attach_type = esp_mail_att_type_inline; + } + } + // release memory + freeMem(&tmp); + } + } + + // Content-Transfer-Encoding + MB_String contentTEName; + appendHeaderName(contentTEName, message_headers[esp_mail_message_header_field_content_transfer_encoding].text, false, true, false); + if (strcmpP(res.response, 0, contentTEName.c_str(), caseSensitive)) + { + // store last text field + + res.part.cur_content_hdr = esp_mail_message_part_info_t::content_header_field_transfer_enc; + resetStringPtr(res.part); + + tmp = subStr(res.response, contentTEName.c_str(), NULL, 0, -1, caseSensitive); + if (tmp) + { + res.part.content_transfer_encoding = tmp; + + if (strcmpP(tmp, 0, esp_mail_transfer_encoding_t::enc_base64)) + res.part.xencoding = esp_mail_msg_xencoding_base64; + else if (strcmpP(tmp, 0, esp_mail_transfer_encoding_t::enc_qp)) + res.part.xencoding = esp_mail_msg_xencoding_qp; + else if (strcmpP(tmp, 0, esp_mail_transfer_encoding_t::enc_7bit)) + res.part.xencoding = esp_mail_msg_xencoding_7bit; + else if (strcmpP(tmp, 0, esp_mail_transfer_encoding_t::enc_8bit)) + res.part.xencoding = esp_mail_msg_xencoding_8bit; + else if (strcmpP(tmp, 0, esp_mail_transfer_encoding_t::enc_binary)) + res.part.xencoding = esp_mail_msg_xencoding_binary; + // release memory + freeMem(&tmp); + } + } + } + else + { + + if (res.part.cur_content_hdr == esp_mail_message_part_info_t::content_header_field_none) + { + + resetStringPtr(res.part); + + MB_String field; + for (int i = esp_mail_rfc822_header_field_from; i < esp_mail_rfc822_header_field_maxType; i++) + { + field = rfc822_headers[i].text; + field += esp_mail_str_34; /* ":" */ + ; + + int ptr = getRFC822HeaderPtr(i, &res.part.rfc822_header); + if (ptr > 0) + { + if (getDecodedHeader(imap, res.response, field.c_str(), *(addrTo(ptr)), caseSensitive)) + return; + } + } + } + } + + // parse content type header sub type properties + if (res.part.cur_content_hdr == esp_mail_message_part_info_t::content_header_field_type) + { + + if (res.part.msg_type == esp_mail_msg_type_plain || res.part.msg_type == esp_mail_msg_type_enriched) + { + MB_String charset; + appendLowerCaseString(charset, message_headers[esp_mail_message_header_field_charset].text, false); + // We have to check for both quotes string or non quote string + if (getPartHeaderProperties(imap, res.response, charset.c_str(), esp_mail_str_11 /* "\"" */, false, value, old_value, res.part.stringEnc, caseSensitive)) + { + res.part.charset = value; + resetStringPtr(res.part); + } + else if (getPartHeaderProperties(imap, res.response, charset.c_str(), esp_mail_str_35 /* ";" */, true, value, old_value, res.part.stringEnc, caseSensitive)) + { + res.part.charset = value; + resetStringPtr(res.part); + } + + if (strposP(res.response, esp_mail_str_59 /* "format=flowed" */, 0, caseSensitive) > -1 || strposP(res.response, esp_mail_str_58 /* "format=\"flowed\"" */, 0, caseSensitive) > -1) + { + res.part.plain_flowed = true; + resetStringPtr(res.part); + } + + if (strposP(res.response, esp_mail_str_61 /* "delsp=yes" */, 0, caseSensitive) > -1 || strposP(res.response, esp_mail_str_60 /* "delsp=\"yes\"" */, 0, caseSensitive) > -1) + { + res.part.plain_delsp = true; + resetStringPtr(res.part); + } + } + + if (res.part.charset.length() == 0) + { + MB_String charset; + appendLowerCaseString(charset, message_headers[esp_mail_message_header_field_charset].text, false); + // We have to check for both quotes string or non quote string + if (getPartHeaderProperties(imap, res.response, charset.c_str(), esp_mail_str_11 /* "\"" */, false, value, old_value, res.part.stringEnc, caseSensitive)) + { + res.part.charset = value; + resetStringPtr(res.part); + } + else if (getPartHeaderProperties(imap, res.response, charset.c_str(), esp_mail_str_35 /* ";" */, true, value, old_value, res.part.stringEnc, caseSensitive)) + { + res.part.charset = value; + resetStringPtr(res.part); + } + } + + MB_String name; + appendLowerCaseString(name, message_headers[esp_mail_message_header_field_name].text, false); + // We have to check for both quotes string or non quote string + if (getPartHeaderProperties(imap, res.response, name.c_str(), esp_mail_str_11 /* "\"" */, false, value, old_value, res.part.stringEnc, caseSensitive)) + { + res.part.stringPtr = toAddr(res.part.name); + value.trim(); + if (value.length() == 0) + return; + } + else if (getPartHeaderProperties(imap, res.response, name.c_str(), esp_mail_str_35 /* ";" */, true, value, old_value, res.part.stringEnc, caseSensitive)) + { + res.part.stringPtr = toAddr(res.part.name); + value.trim(); + if (value.length() == 0) + return; + } + } + + // parse content disposition header sub type properties + if (res.part.cur_content_hdr == esp_mail_message_part_info_t::content_header_field_disposition && res.part.content_disposition.length() > 0) + { + // filename prop + MB_String filename; + appendLowerCaseString(filename, message_headers[esp_mail_message_header_field_filename].text, false); + // We have to check for both quotes string or non quote string + if (getPartHeaderProperties(imap, res.response, filename.c_str(), esp_mail_str_11 /* "\"" */, false, value, old_value, res.part.stringEnc, caseSensitive)) + { + res.part.stringPtr = toAddr(res.part.filename); + value.trim(); + if (value.length() == 0) + return; + } + else if (getPartHeaderProperties(imap, res.response, filename.c_str(), esp_mail_str_35 /* ";" */, true, value, old_value, res.part.stringEnc, caseSensitive)) + { + res.part.stringPtr = toAddr(res.part.filename); + value.trim(); + if (value.length() == 0) + return; + } + + // size prop + MB_String size; + appendLowerCaseString(size, message_headers[esp_mail_message_header_field_size].text, false); + + if (getPartHeaderProperties(imap, res.response, size.c_str(), esp_mail_str_35 /* ";" */, true, value, old_value, res.part.stringEnc, caseSensitive)) + { + res.part.attach_data_size = atoi(value.c_str()); + cHeader(imap)->total_attach_data_size += res.part.attach_data_size; + res.part.sizeProp = true; + + if (!valueStored && old_value.length() > 0) + valueStored = storeStringPtr(imap, res.part.stringPtr, old_value, res.response); + resetStringPtr(res.part); + } + + // creation date prop + MB_String creationDate; + appendLowerCaseString(creationDate, message_headers[esp_mail_message_header_field_creation_date].text, false); + + if (getPartHeaderProperties(imap, res.response, creationDate.c_str(), esp_mail_str_11 /* "\"" */, false, value, old_value, res.part.stringEnc, caseSensitive)) + { + res.part.creation_date = value; + if (!valueStored && old_value.length() > 0) + valueStored = storeStringPtr(imap, res.part.stringPtr, old_value, res.response); + resetStringPtr(res.part); + } + + // mod date prop + MB_String modDate; + appendLowerCaseString(modDate, message_headers[esp_mail_message_header_field_modification_date].text, false); + + if (getPartHeaderProperties(imap, res.response, modDate.c_str(), esp_mail_str_11 /* "\"" */, false, value, old_value, res.part.stringEnc, caseSensitive)) + { + res.part.modification_date = value; + if (!valueStored && old_value.length() > 0) + valueStored = storeStringPtr(imap, res.part.stringPtr, old_value, res.response); + resetStringPtr(res.part); + } + } + + if (!valueStored && (res.part.cur_content_hdr == esp_mail_message_part_info_t::content_header_field_description || res.part.cur_content_hdr == esp_mail_message_part_info_t::content_header_field_type || res.part.cur_content_hdr == esp_mail_message_part_info_t::content_header_field_disposition)) + storeStringPtr(imap, res.part.stringPtr, value, res.response); + } +} + +void ESP_Mail_Client::resetStringPtr(struct esp_mail_message_part_info_t &part) +{ + part.stringPtr = 0; + part.stringEnc = esp_mail_char_decoding_scheme_default; +} + +int ESP_Mail_Client::countChar(const char *buf, char find) +{ + if (!buf) + return 0; + + int count = 0; + + for (size_t i = 0; i < strlen(buf); i++) + { + if (buf[i] == find) + count++; + } + + return count; +} + +bool ESP_Mail_Client::storeStringPtr(IMAPSession *imap, uint32_t addr, MB_String &value, const char *buf) +{ + if (addr) + { + MB_String *a = addrTo(addr); + MB_String s = value.length() > 0 ? value : buf; + + // is value string contains double quotes? + // trim it + if (countChar(s.c_str(), '"') == 2) + s.trim(); + + if (s[0] == '"') + s.erase(0, 1); + + if (s[s.length() - 1] == '"') + s.erase(s.length() - 1, 1); + + decodeString(imap, s); + + *a += s; + + return true; + } + + return false; +} + +bool ESP_Mail_Client::getPartHeaderProperties(IMAPSession *imap, const char *buf, PGM_P p, PGM_P e, bool num, MB_String &value, MB_String &old_value, esp_mail_char_decoding_scheme &scheme, bool caseSensitive) +{ + + MB_String str = p; + str += esp_mail_str_7; /* "=" */ + if (!num) + str += esp_mail_str_11; /* "\"" */ + + char *tmp = subStr(buf, str.c_str(), e, 0, 0, caseSensitive); + if (!tmp) + { + str = p; + str += esp_mail_str_7; /* "=" */ + tmp = subStr(buf, str.c_str(), e, 0, 0, caseSensitive); + if (tmp) + { + // other sub headers found? + int p2 = strposP(tmp, esp_mail_str_35 /* ";" */, 0, caseSensitive); + if (p2 > -1) + { + // release memory + freeMem(&tmp); + tmp = subStr(buf, str.c_str(), esp_mail_str_35 /* ";" */, 0, 0, caseSensitive); + } + // release memory in case above condition does not match + freeMem(&tmp); + } + else + { + // Extended notation rfc5987 + str = p; + str += esp_mail_str_3; /* "*" */ + int p2 = strpos(buf, str.c_str(), 0, caseSensitive); + if (p2 > -1) + { + int p3 = strposP(buf, esp_mail_str_3 /* "*" */, p2 + str.length() + 1, caseSensitive); + if (p3 > -1 && p3 < (int)strlen(buf)) + { + MB_String charset; + + p3 += 2; + + int p4 = strpos(buf, "'", p3, caseSensitive); + if (p4 > -1) + { + + scheme = getEncodingFromCharset(buf); + int c1 = p4 + 1; + p4 = strpos(buf, "'", p4 + 1, caseSensitive); + int c2 = p4; + if (c2 > -1) + { + charset.append(buf + c1, c2 - c1); + } + p3 = p4 + 1; + } + + int len = strlen(buf) - p3; + tmp = allocMem(len + 1); + + if (buf[strlen(buf) - 1] == ';') + len--; + + memcpy(tmp, &buf[p3], len); + + if (scheme == esp_mail_char_decoding_scheme_utf_8) + { + char *buf2 = urlDecode(tmp); + // release memory and point to new buffer + freeMem(&tmp); + tmp = buf2; + } + else if (imap->_charDecCallback) + { + IMAP_Decoding_Info decoding; + decoding.charset = charset.c_str(); + decoding.data = tmp; + decoding.type = IMAP_Decoding_Info::message_part_type_header; + + imap->_charDecCallback(&decoding); + + if (decoding.decodedString.length() > 0) + { + char *buf2 = allocMem(decoding.decodedString.length() + 1); + strcpy(buf2, decoding.decodedString.c_str()); + // release memory and point to new buffer + freeMem(&tmp); + tmp = buf2; + } + } + else if (scheme == esp_mail_char_decoding_scheme_iso8859_1) + { + int ilen = strlen(tmp); + int olen = (ilen + 1) * 2; + char *buf2 = allocMem(olen); + decodeLatin1_UTF8((unsigned char *)buf2, &olen, (unsigned char *)tmp, &ilen); + // release memory and point to new buffer + freeMem(&tmp); + tmp = buf2; + } + else if (scheme == esp_mail_char_decoding_scheme_tis_620 || scheme == esp_mail_char_decoding_scheme_iso8859_11 || scheme == esp_mail_char_decoding_scheme_windows_874) + { + int ilen = strlen(tmp); + char *buf2 = allocMem((ilen + 1) * 3); + decodeTIS620_UTF8(buf2, tmp, ilen); + // release memory and point to new buffer + freeMem(&tmp); + tmp = buf2; + } + } + } + } + } + + if (tmp) + { + old_value = value; + value = tmp; + // release memory + freeMem(&tmp); + return true; + } + + return false; +} + +char *ESP_Mail_Client::urlDecode(const char *str) +{ + int d = 0; /* whether or not the string is decoded */ + char *dStr = allocMem(strlen(str) + 1); + char eStr[] = "00"; /* for a hex code */ + + strcpy(dStr, str); + + while (!d) + { + d = 1; + size_t i; /* the counter for the string */ + + for (i = 0; i < strlen(dStr); ++i) + { + + if (dStr[i] == '%') + { + if (dStr[i + 1] == 0) + return dStr; + + if (isxdigit(dStr[i + 1]) && isxdigit(dStr[i + 2])) + { + d = 0; + + /* combine the next to numbers into one */ + eStr[0] = dStr[i + 1]; + eStr[1] = dStr[i + 2]; + + /* convert it to decimal */ + long int x = strtol(eStr, NULL, 16); + + /* remove the hex */ + memmove(&dStr[i + 1], &dStr[i + 3], strlen(&dStr[i + 3]) + 1); + + dStr[i] = x; + } + } + } + } + + return dStr; +} + +bool ESP_Mail_Client::handleIMAPResponse(IMAPSession *imap, int errCode, bool closeSession) +{ + + if (!reconnect(imap)) + return false; + + esp_mail_imap_response_data res(imap->client.available()); + imap->_lastProgress = -1; + + // Flag used for CRLF inclusion in response reading in case 8bit/binary attachment and base64 encoded and binary messages + bool withLineBreak = imap->_imap_cmd == esp_mail_imap_cmd_fetch_body_text && (cPart(imap)->xencoding == esp_mail_msg_xencoding_base64 || cPart(imap)->xencoding == esp_mail_msg_xencoding_binary); + withLineBreak |= imap->_imap_cmd == esp_mail_imap_cmd_fetch_body_attachment && cPart(imap)->xencoding != esp_mail_msg_xencoding_base64; + + // custom cmd IDLE?, waiting incoming server response + if (res.chunkBufSize == 0 && imap->_prev_imap_custom_cmd == imap->_imap_custom_cmd && imap->_imap_custom_cmd == esp_mail_imap_cmd_idle) + { + if (!reconnect(imap)) + return false; + + return true; + } + + while (imap->connected() && res.chunkBufSize <= 0) + { + + if (!reconnect(imap, res.dataTime)) + return false; + + if (!connected(imap)) + { +#if defined(ESP32) + if (imap->_imap_cmd == esp_mail_imap_cmd_logout) // suppress the error due to server closes the connection immediately in ESP32 core v2.0.4 + return true; +#endif + if (millis() - imap->_last_network_error_ms > 1000) + { + imap->_last_network_error_ms = millis(); + errorStatusCB(imap, nullptr, MAIL_CLIENT_ERROR_CONNECTION_CLOSED, true); + } + + return false; + } + res.chunkBufSize = imap->client.available(); + yield_impl(); + } + + res.dataTime = millis(); + + if (res.chunkBufSize > 0) + { + if (imap->_imap_cmd == esp_mail_imap_cmd_examine) + { + imap->_mbif.clear(); + imap->_nextUID.clear(); + imap->_unseenMsgIndex.clear(); + } + + if (imap->_imap_cmd == esp_mail_imap_cmd_search) + { + imap->_mbif._searchCount = 0; + imap->_imap_msg_num.clear(); + } + + // response buffer + res.chunkBufSize = ESP_MAIL_CLIENT_RESPONSE_BUFFER_SIZE; + res.response = allocMem(res.chunkBufSize + 1); + + if (imap->_imap_cmd == esp_mail_imap_cmd_fetch_body_attachment || imap->_imap_cmd == esp_mail_imap_cmd_fetch_body_inline) + res.lastBuf = allocMem(BASE64_CHUNKED_LEN + 1); + + while (!res.completedResponse) // looking for operation finishing + { + yield_impl(); + + if (imap->_imap_cmd == esp_mail_imap_cmd_append || (imap->_imap_custom_cmd == esp_mail_imap_cmd_append && imap->_imap_cmd == esp_mail_imap_cmd_custom && imap->_customCmdResCallback)) + { + // No waiting time out for APPEND + res.dataTime = millis(); + } + + if (!reconnect(imap, res.dataTime) || !connected(imap)) + { + + if (!connected(imap)) + { + + if (cPart(imap) && cPart(imap)->file_open_write) + mbfs->close(mbfs_type imap->_imap_data->storage.type); + +#if defined(ESP32) + if (imap->_imap_cmd == esp_mail_imap_cmd_logout) // suppress the error due to server closes the connection immediately in ESP32 core v2.0.4 + return true; +#endif + + if (millis() - imap->_last_network_error_ms > 1000) + { + imap->_last_network_error_ms = millis(); + errorStatusCB(imap, nullptr, MAIL_CLIENT_ERROR_CONNECTION_CLOSED, true); + } + + return false; + } + return false; + } + + res.chunkBufSize = imap->client.available(); + + if (res.chunkBufSize > 0) + { + res.chunkBufSize = ESP_MAIL_CLIENT_RESPONSE_BUFFER_SIZE; + + if (imap->_imap_cmd == esp_mail_imap_cmd_search) + { + + res.readLen = parseSearchResponse(imap, res, esp_mail_imap_tag_str, imap_responses[esp_mail_imap_response_search].text); + imap->_mbif._availableItems = imap->_imap_msg_num.size(); + + if (imap->_mbif._availableItems == 0) + { + res.imapResp = imapResponseStatus(imap, res.response, esp_mail_imap_tag_str); + + if (res.imapResp != esp_mail_imap_resp_unknown) + res.endSearch = true; + + if (res.imapResp == esp_mail_imap_resp_bad) + { + errorStatusCB(imap, nullptr, IMAP_STATUS_BAD_COMMAND, false); + return false; + } + } + } + else + { + // response read as chunk ended with CRLF or complete buffer size + int o = res.octetCount; + res.readLen = 0; + MB_String ovfBuf; + if (!readResponse(imap, res.response, res.chunkBufSize, res.readLen, withLineBreak, res.octetCount, ovfBuf)) + { + errorStatusCB(imap, nullptr, MAIL_CLIENT_ERROR_READ_TIMEOUT, true); + return false; + } + + // If buffer overflown, copy from overflow buffer + if (ovfBuf.length() > 0) + { + // release memory + freeMem(&res.response); + res.response = allocMem(ovfBuf.length() + 1); + strcpy(res.response, ovfBuf.c_str()); + ovfBuf.clear(); + } + + if (res.readLen == 0 && o != res.octetCount && res.octetCount <= res.octetLength && cPart(imap)->xencoding != esp_mail_msg_xencoding_base64 && cPart(imap)->xencoding != esp_mail_msg_xencoding_binary && cPart(imap)->xencoding != esp_mail_msg_xencoding_qp) + { + strcpy_P(res.response, esp_mail_str_42 /* "\r\n" */); + res.readLen = 2; + } + } + + if (res.readLen) + { + if (imap->_debug && imap->_debugLevel > esp_mail_debug_level_basic && !imap->_customCmdResCallback) + { + if (imap->_imap_cmd != esp_mail_imap_cmd_search && imap->_imap_cmd != esp_mail_imap_cmd_fetch_body_text && imap->_imap_cmd != esp_mail_imap_cmd_fetch_body_attachment && imap->_imap_cmd != esp_mail_imap_cmd_fetch_body_inline) + esp_mail_debug_print((const char *)res.response, true); + } + + if (imap->_imap_cmd != esp_mail_imap_cmd_search || (imap->_imap_cmd == esp_mail_imap_cmd_search && res.endSearch)) + res.imapResp = imapResponseStatus(imap, res.response, esp_mail_imap_tag_str); + + if (res.imapResp != esp_mail_imap_resp_unknown) + { + + // We've got the right response, + // prepare to exit + + res.completedResponse = true; + + if (imap->_debug && imap->_debugLevel > esp_mail_debug_level_basic && !imap->_customCmdResCallback) + { + if (imap->_imap_cmd == esp_mail_imap_cmd_fetch_body_text || imap->_imap_cmd == esp_mail_imap_cmd_fetch_body_attachment || imap->_imap_cmd == esp_mail_imap_cmd_fetch_body_inline) + esp_mail_debug_print((const char *)res.response, true); + } + + MB_String ovfBuf; + + while (imap->client.available()) + { + + if (!readResponse(imap, res.response, res.chunkBufSize, res.readLen, true, res.octetCount, ovfBuf)) + { + errorStatusCB(imap, nullptr, MAIL_CLIENT_ERROR_READ_TIMEOUT, true); + return false; + } + // If buffer overflown, copy from overflow buffer + if (ovfBuf.length() > 0) + { + // release memory + freeMem(&res.response); + res.response = allocMem(ovfBuf.length() + 1); + strcpy(res.response, ovfBuf.c_str()); + ovfBuf.clear(); + } + + if (res.readLen) + { + if (imap->_debug && imap->_debugLevel > esp_mail_debug_level_basic && !imap->_customCmdResCallback) + { + if (imap->_imap_cmd == esp_mail_imap_cmd_fetch_body_text || imap->_imap_cmd == esp_mail_imap_cmd_fetch_body_attachment || imap->_imap_cmd == esp_mail_imap_cmd_fetch_body_inline) + esp_mail_debug_print((const char *)res.response, true); + } + } + } + } + else + { + + // No response ever parsed + + if (imap->_imap_cmd == esp_mail_imap_cmd_sasl_auth_plain || imap->_imap_cmd == esp_mail_imap_cmd_sasl_auth_oauth) + { + if (imap->_imap_cmd == esp_mail_imap_cmd_sasl_auth_oauth) + { + if (isOAuthError(res.response, res.readLen, res.chunkIdx, 2)) + res.completedResponse = true; + } + + // In case SASL-IR extension does not support, check for initial zero-length server challenge first "+ " + if (!imap->_auth_capability[esp_mail_auth_capability_sasl_ir] && strcmp(res.response, pgm2Str(esp_mail_str_63 /* "+ " */)) == 0) + { + res.imapResp = esp_mail_imap_resp_ok; + res.completedResponse = true; + } + } + + if (imap->_imap_cmd == esp_mail_imap_cmd_sasl_login || imap->_imap_cmd == esp_mail_imap_cmd_sasl_auth_oauth || imap->_imap_cmd == esp_mail_imap_cmd_sasl_auth_plain) + { + int i = 0; + if (parseCapabilityResponse(imap, res.response, i)) + imap->_feature_capability[esp_mail_imap_read_capability_auto_caps] = true; + } + else if (imap->_imap_cmd == esp_mail_imap_cmd_custom && imap->_customCmdResCallback) + { + + res.imapResp = imapResponseStatus(imap, res.response, imap->_responseStatus.tag.c_str()); + + // get response or custom cmd APPEND or custom cmd IDLE? + if (res.imapResp > esp_mail_imap_resp_unknown || strposP(imap->_cmd.c_str(), imap_commands[esp_mail_imap_command_append].text, 0, false) > -1 || imap->_imap_custom_cmd == esp_mail_imap_cmd_idle) + res.completedResponse = true; + + imap->_responseStatus.text = res.response; + + imap->_customCmdResCallback(imap->_responseStatus); + + if (res.completedResponse) + return true; + } + else if (imap->_imap_cmd == esp_mail_imap_cmd_append) + { + res.imapResp = esp_mail_imap_resp_ok; + res.completedResponse = true; + } + else if (imap->_imap_cmd == esp_mail_imap_cmd_capability) + parseCapabilityResponse(imap, res.response, res.chunkIdx); + else if (imap->_imap_cmd == esp_mail_imap_cmd_list) + parseFoldersResponse(imap, res.response, true); + else if (imap->_imap_cmd == esp_mail_imap_cmd_lsub) + parseFoldersResponse(imap, res.response, false); + else if (imap->_imap_cmd == esp_mail_imap_cmd_select || imap->_imap_cmd == esp_mail_imap_cmd_examine) + parseExamineResponse(imap, res.response); + else if (imap->_imap_cmd == esp_mail_imap_cmd_get_uid) + { + MB_String str; + appendFetchString(str, true); + parseCmdResponse(imap, res.response, str.c_str()); + } + else if (imap->_imap_cmd == esp_mail_imap_cmd_get_flags) + { + MB_String str; + appendFetchString(str, false); + parseCmdResponse(imap, res.response, str.c_str()); + } + else if (imap->_imap_cmd == esp_mail_imap_cmd_get_quota) + parseCmdResponse(imap, res.response, imap_responses[esp_mail_imap_response_quota].text); + else if (imap->_imap_cmd == esp_mail_imap_cmd_id) + parseCmdResponse(imap, res.response, imap_responses[esp_mail_imap_response_id].text); + else if (imap->_imap_cmd == esp_mail_imap_cmd_get_quota_root) + { + parseCmdResponse(imap, res.response, imap_responses[esp_mail_imap_response_quotaroot].text); + imap->_quota_tmp.clear(); + parseCmdResponse(imap, res.response, imap_responses[esp_mail_imap_response_quota].text); + if (imap->_quota_tmp.length() > 0) + { + imap->_quota_root_tmp += (char)':'; + imap->_quota_root_tmp += imap->_quota_tmp; + } + } + else if (imap->_imap_cmd == esp_mail_imap_cmd_get_acl || imap->_imap_cmd == esp_mail_imap_cmd_my_rights) + parseCmdResponse(imap, res.response, imap->_imap_cmd == esp_mail_imap_cmd_get_acl ? imap_responses[esp_mail_imap_response_acl].text : imap_responses[esp_mail_imap_response_myrights].text); + else if (imap->_imap_cmd == esp_mail_imap_cmd_namespace) + parseCmdResponse(imap, res.response, imap_responses[esp_mail_imap_response_namespace].text); + else if (imap->_imap_cmd == esp_mail_imap_cmd_idle) + { + res.completedResponse = res.response[0] == '+'; + res.imapResp = esp_mail_imap_resp_ok; + + imap->_last_host_check_ms = millis(); + } + else if (imap->_imap_cmd == esp_mail_imap_cmd_fetch_sequence_set) + { + MB_String str; + appendFetchString(str, true); + parseCmdResponse(imap, res.response, str.c_str()); + } + else if (imap->_imap_cmd == esp_mail_imap_cmd_fetch_body_header) + { + + if (res.headerState == 0 && cMSG(imap).type == esp_mail_imap_msg_num_type_uid) + res.header.message_uid = cMSG(imap).value; + + int _st = res.headerState; + parseHeaderResponse(imap, res, imap->_imap_data->enable.header_case_sensitive); + if (_st == res.headerState && res.headerState > 0 && res.octetCount <= res.header.header_data_len) + collectHeaderField(imap, res.response, res.header, res.headerState); + } + else if (imap->_imap_cmd == esp_mail_imap_cmd_fetch_body_mime) + parsePartHeaderResponse(imap, res, imap->_imap_data->enable.header_case_sensitive); + else if (imap->_imap_cmd == esp_mail_imap_cmd_fetch_body_text) + decodeText(imap, res); + else if (imap->_imap_cmd == esp_mail_imap_cmd_fetch_body_attachment || imap->_imap_cmd == esp_mail_imap_cmd_fetch_body_inline) + { + + if (cPart(imap)->xencoding == esp_mail_msg_xencoding_base64) + { + // Multi-line chunked base64 string attachment handle + if (res.octetCount < res.octetLength && res.readLen < BASE64_CHUNKED_LEN) + { + if (strlen(res.lastBuf) > 0) + { + res.buf = allocMem(res.readLen + strlen(res.lastBuf) + 2); + strcpy(res.buf, res.lastBuf); + strcat(res.buf, res.response); + res.readLen = strlen(res.buf); + res.tmo = parseAttachmentResponse(imap, res.buf, res); + // release memory + freeMem(&res.buf); + memset(res.lastBuf, 0, BASE64_CHUNKED_LEN + 1); + if (!res.tmo) + break; + } + else if (res.readLen < BASE64_CHUNKED_LEN + 1) + strcpy(res.lastBuf, res.response); + } + else + { + res.tmo = parseAttachmentResponse(imap, res.response, res); + if (!res.tmo) + break; + } + } + else + res.tmo = parseAttachmentResponse(imap, res.response, res); + } + + res.dataTime = millis(); + } + } + memset(res.response, 0, res.chunkBufSize); + } + } + + if (imap->_imap_cmd == esp_mail_imap_cmd_search) + { + if (imap->_debug && res.searchCount > 0 && res.searchCount < 100) + { + searchReport(imap, 100); + } + } + } + + if ((res.imapResp != esp_mail_imap_resp_ok && imap->_imap_cmd == esp_mail_imap_cmd_fetch_body_header && res.header.header_data_len == 0) || res.imapResp == esp_mail_imap_resp_no) + { + // We don't get any response + + if (res.imapResp == esp_mail_imap_resp_no) + imap->_responseStatus.errorCode = IMAP_STATUS_IMAP_RESPONSE_FAILED; + else if (imap->_imap_data->fetch.modsequence > -1 && imap->isModseqSupported() && res.imapResp == esp_mail_imap_resp_ok && res.header.header_data_len == 0) + imap->_responseStatus.errorCode = IMAP_STATUS_CHANGEDSINC_MODSEQ_TEST_FAILED; + else + imap->_responseStatus.errorCode = IMAP_STATUS_NO_MESSAGE; + +#if !defined(SILENT_MODE) + + if (imap->_statusCallback && imap->_imap_cmd != esp_mail_imap_cmd_fetch_body_mime) + sendErrorCB(imap, imap->errorReason().c_str(), false, false); + + if (imap->_debug && imap->_imap_cmd != esp_mail_imap_cmd_fetch_body_mime) + esp_mail_debug_print_tag(imap->errorReason().c_str(), esp_mail_debug_tag_type_error, true); + +#endif + + return false; + } + + // We've got OK or NO responses + + if (res.imapResp == esp_mail_imap_resp_ok) + { + // Response OK + + if (imap->_imap_cmd == esp_mail_imap_cmd_fetch_body_header) + { + // Headers management + + char *buf = allocMem(res.header.content_type.length() + 1); + strcpy(buf, res.header.content_type.c_str()); + res.header.content_type.clear(); + + MB_String contentTypeName; + appendHeaderName(contentTypeName, message_headers[esp_mail_message_header_field_content_type].text, false, false, false); + + res.buf = subStr(buf, contentTypeName.c_str(), esp_mail_str_35 /* ";" */, 0, 0, false); + if (res.buf) + { + res.headerState = esp_mail_imap_state_content_type; + collectHeaderField(imap, res.buf, res.header, res.headerState); + // release memory + freeMem(&res.buf); + + if (res.header.content_type.length() > 0) + { + int p1 = strposP(res.header.content_type.c_str(), esp_mail_imap_composite_media_type_t::multipart, 0); + if (p1 != -1) + { + p1 += strlen(esp_mail_imap_composite_media_type_t::multipart) + 1; + res.header.multipart = true; + // inline or embedded images + if (strpos(res.header.content_type.c_str(), esp_mail_imap_multipart_sub_type_t::related, p1) != -1) + res.header.multipart_sub_type = esp_mail_imap_multipart_sub_type_related; + // multiple text formats e.g. plain, html, enriched + else if (strpos(res.header.content_type.c_str(), esp_mail_imap_multipart_sub_type_t::alternative, p1) != -1) + res.header.multipart_sub_type = esp_mail_imap_multipart_sub_type_alternative; + // medias + else if (strpos(res.header.content_type.c_str(), esp_mail_imap_multipart_sub_type_t::parallel, p1) != -1) + res.header.multipart_sub_type = esp_mail_imap_multipart_sub_type_parallel; + // rfc822 encapsulated + else if (strpos(res.header.content_type.c_str(), esp_mail_imap_multipart_sub_type_t::digest, p1) != -1) + res.header.multipart_sub_type = esp_mail_imap_multipart_sub_type_digest; + else if (strpos(res.header.content_type.c_str(), esp_mail_imap_multipart_sub_type_t::report, p1) != -1) + res.header.multipart_sub_type = esp_mail_imap_multipart_sub_type_report; + // others can be attachments + else if (strpos(res.header.content_type.c_str(), esp_mail_imap_multipart_sub_type_t::mixed, p1) != -1) + res.header.multipart_sub_type = esp_mail_imap_multipart_sub_type_mixed; + } + + p1 = strposP(res.header.content_type.c_str(), esp_mail_imap_composite_media_type_t::message, 0); + if (p1 != -1) + { + p1 += strlen(esp_mail_imap_composite_media_type_t::message) + 1; + if (strpos(res.part.content_type.c_str(), esp_mail_imap_message_sub_type_t::rfc822, p1) != -1) + { + res.header.rfc822_part = true; + res.header.message_sub_type = esp_mail_imap_message_sub_type_rfc822; + } + else if (strpos(res.part.content_type.c_str(), esp_mail_imap_message_sub_type_t::Partial, p1) != -1) + res.header.message_sub_type = esp_mail_imap_message_sub_type_partial; + else if (strpos(res.part.content_type.c_str(), esp_mail_imap_message_sub_type_t::External_Body, p1) != -1) + res.header.message_sub_type = esp_mail_imap_message_sub_type_external_body; + else if (strpos(res.part.content_type.c_str(), esp_mail_imap_message_sub_type_t::delivery_status, p1) != -1) + res.header.message_sub_type = esp_mail_imap_message_sub_type_delivery_status; + } + } + + MB_String charset; + appendLowerCaseString(charset, message_headers[esp_mail_message_header_field_charset].text, false); + charset += esp_mail_str_7; /* "=" */ + + res.buf = subStr(buf, charset.c_str(), NULL, 0, -1, false); + if (res.buf) + { + res.headerState = esp_mail_imap_state_char_set; + collectHeaderField(imap, res.buf, res.header, res.headerState); + // release memory + freeMem(&res.buf); + } + + if (res.header.multipart) + { + if (strcmpP(buf, 0, esp_mail_str_64 /* "boundary=\"" */)) + { + res.buf = subStr(buf, esp_mail_str_64 /* "boundary=\"" */, esp_mail_str_11 /* "\"" */, 0, 0, false); + if (res.buf) + { + res.headerState = esp_mail_imap_state_boundary; + collectHeaderField(imap, res.buf, res.header, res.headerState); + // release memory + freeMem(&res.buf); + } + } + } + } + + // release memory + freeMem(&buf); + + // Decode the headers fields + + for (int i = esp_mail_rfc822_header_field_from; i < esp_mail_rfc822_header_field_maxType; i++) + { + if (i != esp_mail_rfc822_header_field_msg_id && i != esp_mail_rfc822_header_field_flags) + decodeString(imap, res.header.header_fields.header_items[i]); + } + + imap->_headers.push_back(res.header); + } + + if (imap->_imap_cmd == esp_mail_imap_cmd_fetch_body_mime) + { + // Expect the octet length in the response for the existent part + if (res.part.octetLen > 0) + { + + res.part.partNumStr = cHeader(imap)->partNumStr; + res.part.partNumFetchStr = cHeader(imap)->partNumStr; + if (cHeader(imap)->part_headers.size() > 0) + { + + struct esp_mail_message_part_info_t *_part = &cHeader(imap)->part_headers[cHeader(imap)->part_headers.size() - 1]; + bool rfc822_body_subtype = _part->message_sub_type == esp_mail_imap_message_sub_type_rfc822; + + if (rfc822_body_subtype) + { + if (!_part->rfc822_part) + { + // additional rfc822 message header, store it to the rfc822 part header + _part->rfc822_part = true; + _part->rfc822_header = res.part.rfc822_header; + imap->_rfc822_part_count++; + _part->rfc822_msg_Idx = imap->_rfc822_part_count; + } + } + } + + cHeader(imap)->part_headers.push_back(res.part); + cHeader(imap)->message_data_count = cHeader(imap)->part_headers.size(); + + if (res.part.msg_type != esp_mail_msg_type_none || + res.part.attach_type != esp_mail_att_type_none) + { + if (res.part.attach_type == esp_mail_att_type_attachment || + res.part.message_sub_type != esp_mail_imap_message_sub_type_rfc822) + { + if (res.part.attach_type != esp_mail_att_type_none && + cHeader(imap)->multipart_sub_type != esp_mail_imap_multipart_sub_type_alternative) + { + cHeader(imap)->hasAttachment = true; + cHeader(imap)->attachment_count++; + } + } + } + } + else + { + // nonexistent part + // return false to exit the loop without closing the connection + if (closeSession) + imap->closeSession(); + return false; + } + } + + if (imap->_imap_cmd == esp_mail_imap_cmd_fetch_body_attachment || imap->_imap_cmd == esp_mail_imap_cmd_fetch_body_text || imap->_imap_cmd == esp_mail_imap_cmd_fetch_body_inline) + { + if (cPart(imap) && cPart(imap)->file_open_write) + mbfs->close(mbfs_type imap->_imap_data->storage.type); + } + + if (cPart(imap) && imap->_imap_cmd == esp_mail_imap_cmd_fetch_body_text) + cPart(imap)->text[cPart(imap)->textLen] = 0; + } + else + { + + // Response NO + + // Some server responses NO and should exit (false) from MIME feching loop without + // closing the session + if (imap->_imap_cmd != esp_mail_imap_cmd_fetch_body_mime) + return handleIMAPError(imap, errCode, false); + + if (closeSession) + imap->closeSession(); + return false; + } + + return true; +} + +void ESP_Mail_Client::addHeader(MB_String &s, PGM_P name, const char *s_value, int num_value, bool trim, bool isJson) +{ + if (isJson) + { + s += (s.length() > 0) ? esp_mail_str_77 /* ",\"" */ : esp_mail_str_78 /* "{\"" */; + s += name; + + if (strlen(s_value) > 0) + { + s += esp_mail_str_79; /* "\":\"" */ + ; + if (trim) + { + MB_String t = s_value; + t.replaceAll("\"", ""); + s += t; + } + else + s += s_value; + s += esp_mail_str_11; /* "\"" */ + } + else + { + s += esp_mail_str_34 /* ":" */; + appendSpace(s); + s += num_value; + } + } + else + { + if (s.length() > 0) + appendNewline(s); + s += name; + s += esp_mail_str_34 /* ":" */; + appendSpace(s); + if (strlen(s_value) > 0) + s += s_value; + else + s += num_value; + } +} + +void ESP_Mail_Client::saveHeader(IMAPSession *imap, bool json) +{ + if (!imap->_storageReady) + return; + + MB_String headerFilePath; + + prepareFilePath(imap, headerFilePath, true); + + headerFilePath += json ? esp_mail_str_65 /* "/header.json" */ : esp_mail_str_66 /* "/header.txt" */; + + prepareFileList(imap, headerFilePath); + + int sz = mbfs->open(headerFilePath, mbfs_type imap->_imap_data->storage.type, mb_fs_open_mode_write); + if (sz < 0) + { + imap->_responseStatus.errorCode = sz; + imap->_responseStatus.text.clear(); +#if !defined(SILENT_MODE) + if (imap->_debug) + { + esp_mail_debug_print_tag(imap->errorReason().c_str(), esp_mail_debug_tag_type_error, true); + } +#endif + return; + } + + MB_String s; + for (size_t i = 0; i < imap->_headers.size(); i++) + addHeaderItem(s, &imap->_headers[i], json); + + if (json) + s += esp_mail_str_75; /* "]}" */ + + mbfs->print(mbfs_type imap->_imap_data->storage.type, s.c_str()); + + mbfs->close(mbfs_type imap->_imap_data->storage.type); + + imap->_headerSaved = true; +} + +void ESP_Mail_Client::addHeaderItem(MB_String &str, esp_mail_message_header_t *header, bool json) +{ + MB_String s; + if (json) + { + if (str.length() > 0) + str += esp_mail_str_8; /* "," */ + else + str = esp_mail_str_76; /* "{\"Messages\":[" */ + } + + addHeader(s, message_headers[esp_mail_message_header_field_number].text, "", header->message_no, false, json); + addHeader(s, message_headers[esp_mail_message_header_field_uid].text, "", header->message_uid, false, json); + + if (header->accept_language.length() > 0) + addHeader(s, message_headers[esp_mail_message_header_field_accept_language].text, header->accept_language.c_str(), 0, false, json); + + if (header->content_language.length() > 0) + addHeader(s, message_headers[esp_mail_message_header_field_content_language].text, header->content_language.c_str(), 0, false, json); + + addRFC822Headers(s, &header->header_fields, json); + + for (size_t j = 0; j < header->part_headers.size(); j++) + { + if (header->part_headers[j].rfc822_part) + { + MB_String s1; + addRFC822Headers(s1, &header->part_headers[j].rfc822_header, json); + + if (json) + { + s += esp_mail_str_69; /* ",\"RFC822\":" */ + s += s1; + s += esp_mail_str_36; /* "}" */ + } + else + { + s += esp_mail_str_70; /* "\r\n\r\nRFC822:\r\n" */ + s += s1; + } + } + } + + if (header->attachment_count > 0) + { + if (json) + { + s += esp_mail_str_71 /* ",\"Attachments\":{\"Count\":" */; + s += header->attachment_count; + s += esp_mail_str_72; /* ",\"Files\":[" */ + } + else + { + s += esp_mail_str_73; /* "\r\n\r\nAttachments (" */ + s += header->attachment_count; + s += esp_mail_str_74; /* ")\r\n" */ + } + + int index = 0; + for (size_t j = 0; j < header->part_headers.size(); j++) + { + + if (header->part_headers[j].attach_type == esp_mail_att_type_none || header->part_headers[j].rfc822_part) + continue; + + if (json) + { + if (index > 0) + s += esp_mail_str_8; /* "," */ + s += esp_mail_str_67; /* /"{\"Filename\":\"" */ + s += header->part_headers[j].filename; + s += esp_mail_str_11; /* "\"" */ + } + else + { + if (index > 0) + appendNewline(s); + appendNewline(s); + s += esp_mail_str_68; /* /"Index: " */ + s += index + 1; + addHeader(s, message_headers[esp_mail_message_header_field_filename].text, header->part_headers[j].filename.c_str(), 0, false, json); + } + + addHeader(s, message_headers[esp_mail_message_header_field_name].text, header->part_headers[j].name.c_str(), 0, false, json); + addHeader(s, message_headers[esp_mail_message_header_field_size].text, "", header->part_headers[j].attach_data_size, false, json); + addHeader(s, message_headers[esp_mail_message_header_field_mime].text, header->part_headers[j].content_type.c_str(), 0, false, json); + addHeader(s, message_headers[esp_mail_message_header_field_type].text, header->part_headers[j].attach_type == esp_mail_att_type_attachment ? esp_mail_content_disposition_type_t::attachment : esp_mail_content_disposition_type_t::inline_, 0, false, json); + addHeader(s, message_headers[esp_mail_message_header_field_description].text, header->part_headers[j].content_description.c_str(), 0, false, json); + addHeader(s, message_headers[esp_mail_message_header_field_creation_date].text, header->part_headers[j].creation_date.c_str(), 0, false, json); + + if (json) + s += esp_mail_str_36; /* "}" */ + + index++; + } + + if (json) + s += esp_mail_str_75; /* "]}" */ + } + + if (json) + { + s += esp_mail_str_36; /* "}" */ + } + + str += s; +} + +int ESP_Mail_Client::getRFC822HeaderPtr(int index, esp_mail_imap_rfc822_msg_header_item_t *header) +{ + if (index > esp_mail_rfc822_header_field_from && index < esp_mail_rfc822_header_field_maxType) + return toAddr(header->header_items[index]); + return 0; +} + +void ESP_Mail_Client::addRFC822Headers(MB_String &s, esp_mail_imap_rfc822_msg_header_item_t *header, bool json) +{ + for (int i = esp_mail_rfc822_header_field_from; i < esp_mail_rfc822_header_field_maxType; i++) + addRFC822HeaderItem(s, header, i, json); +} + +void ESP_Mail_Client::addRFC822HeaderItem(MB_String &s, esp_mail_imap_rfc822_msg_header_item_t *header, int index, bool json) +{ + int ptr = getRFC822HeaderPtr(index, header); + if (ptr > 0) + addHeader(s, rfc822_headers[index].text, addrTo(ptr)->c_str(), 0, rfc822_headers[index].trim, json); +} + +esp_mail_imap_response_status ESP_Mail_Client::imapResponseStatus(IMAPSession *imap, char *response, PGM_P tag) +{ + imap->_responseStatus.clear(false); + MB_String test; + esp_mail_imap_response_status status = esp_mail_imap_resp_unknown; + esp_mail_imap_response_types type = esp_mail_imap_response_maxType; + + if (strpos(response, imap->prependTag(imap_responses[esp_mail_imap_response_ok].text, tag).c_str(), 0) > -1) + { + status = esp_mail_imap_resp_ok; + type = esp_mail_imap_response_ok; + } + else if (strpos(response, imap->prependTag(imap_responses[esp_mail_imap_response_no].text, tag).c_str(), 0) > -1) + { + status = esp_mail_imap_resp_no; + type = esp_mail_imap_response_no; + } + else if (strpos(response, imap->prependTag(imap_responses[esp_mail_imap_response_bad].text, tag).c_str(), 0) > -1) + { + status = esp_mail_imap_resp_bad; + type = esp_mail_imap_response_bad; + } + + if (status != esp_mail_imap_resp_unknown) + { + test = imap->prependTag(imap_responses[type].text, tag); + + imap->_responseStatus.text = &response[test.length()]; + if (imap->_responseStatus.text[imap->_responseStatus.text.length() - 2] == '\r') + imap->_responseStatus.text[imap->_responseStatus.text.length() - 2] = 0; + + test = imap_responses[type].text; + test.trim(); + imap->_responseStatus.status = test; + imap->_responseStatus.completed = true; + } + return status; +} + +bool ESP_Mail_Client::parseCapabilityResponse(IMAPSession *imap, const char *buf, int &chunkIdx) +{ + if (chunkIdx == 0) + { + MB_String res; + // We add white space to make post token checking to work in all capabilities. + // This will allow us to check "IDLE " and "ID " correctly. + appendSpace(res, false, buf); + + if (strposP(res.c_str(), imap_responses[esp_mail_imap_response_capability_untagged].text, 0) > -1 || strposP(res.c_str(), imap_responses[esp_mail_imap_response_capability].text, 0) > -1) + { + for (int i = esp_mail_auth_capability_plain; i < esp_mail_auth_capability_maxType; i++) + { + if (strposP(res.c_str(), imap_auth_cap_pre_tokens[i].c_str(), 0) > -1) + imap->_auth_capability[i] = true; + } + + for (int i = esp_mail_imap_read_capability_imap4; i < esp_mail_imap_read_capability_maxType; i++) + { + if (strposP(res.c_str(), imap_read_cap_post_tokens[i].c_str(), 0) > -1) + { + imap->_feature_capability[i] = true; + if (i == esp_mail_imap_read_capability_logindisable) + imap->_auth_capability[esp_mail_auth_capability_login] = false; + } + } + + return true; + } + } + + return false; +} + +char *ESP_Mail_Client::getList(char *buf, bool &isList) +{ + if (buf[0] == '(' && buf[1] != ')') + { + if (buf[strlen(buf) - 1] == ')') + buf[strlen(buf) - 1] = 0; + else + isList = true; + + return &buf[1]; + } + else if (isList) + { + if (buf[strlen(buf) - 1] == ')') + { + buf[strlen(buf) - 1] = 0; + isList = false; + } + } + + return buf; +} + +void ESP_Mail_Client::parseFoldersResponse(IMAPSession *imap, char *buf, bool list) +{ + struct esp_mail_folder_info_t fd; + int pos = list ? strposP(buf, imap_responses[esp_mail_imap_response_list].text, 0) : strposP(buf, imap_responses[esp_mail_imap_response_lsub].text, 0); + bool isList = false, delimOk = false; + if (pos != -1) + { + char *p = allocMem(strlen(buf)); + strcpy(p, buf); + char *pp = p; + char *end = p; + int count = 0; + int tkPos = 3; + + while (pp != NULL) + { + // See RFC2047.h + ESP_MAIL_STRSEP(&end, " "); + count++; + + if (count >= tkPos && strlen(pp) > 0) + { + if (count == tkPos && pp[0] == '(' && pp[1] != ')') + fd.attributes = getList(pp, isList); + else if (isList) + { + fd.attributes += ' '; + fd.attributes += getList(pp, isList); + } + else + { + if (pp[strlen(pp) - 1] == '"') + pp[strlen(pp) - 1] = 0; + + const char *ptr = pp[0] == '"' ? &pp[1] : &pp[0]; + + if (!delimOk) + { + delimOk = true; + fd.delimiter = ptr; + } + else + { + if (fd.name.length() > 0) + fd.name += ' '; + fd.name += ptr; + } + } + } + pp = end; + } + + // release memory + freeMem(&p); + + imap->_folders.add(fd); + } +} + +bool ESP_Mail_Client::parseIdleResponse(IMAPSession *imap) +{ + + int chunkBufSize = 0; + + if (!reconnect(imap)) + return false; + + if (imap->client.connected()) + chunkBufSize = imap->client.available(); + else + return false; + + if (chunkBufSize > 0) + { + chunkBufSize = ESP_MAIL_CLIENT_RESPONSE_BUFFER_SIZE; + + char *buf = allocMem(chunkBufSize + 1); + + int octetCount = 0; + + int readLen = 0; + + MB_String ovfBuf; + readResponse(imap, buf, chunkBufSize, readLen, false, octetCount, ovfBuf); + + // If buffer overflown, copy from overflow buffer + if (ovfBuf.length() > 0) + { + // release memory + freeMem(&buf); + buf = allocMem(ovfBuf.length() + 1); + strcpy(buf, ovfBuf.c_str()); + ovfBuf.clear(); + } + + if (readLen > 0) + { + + if (imap->_debug && imap->_debugLevel > esp_mail_debug_level_basic) + esp_mail_debug_print((const char *)buf, true); + + char *tmp = nullptr; + int p1 = -1; + bool exists = false; + + tmp = subStr(buf, NULL, imap_responses[esp_mail_imap_response_exists].text, 0); + if (tmp) + { + int numMsg = imap->_mbif._msgCount; + imap->_mbif._msgCount = atoi(tmp); + // release memory + freeMem(&tmp); + exists = true; + imap->_mbif._folderChanged |= (int)imap->_mbif._msgCount != numMsg; + if ((int)imap->_mbif._msgCount > numMsg) + { + imap->_mbif._polling_status.type = imap_polling_status_type_new_message; + imap->_mbif._polling_status.messageNum = imap->_mbif._msgCount; + } + goto ex; + } + + tmp = subStr(buf, NULL, imap_responses[esp_mail_imap_response_expunge].text, 0); + if (tmp) + { + imap->_mbif._polling_status.type = imap_polling_status_type_remove_message; + imap->_mbif._polling_status.messageNum = atoi(tmp); + + if (imap->_mbif._polling_status.messageNum == imap->_mbif._msgCount && imap->_mbif._nextUID > 0) + imap->_mbif._nextUID--; + + // release memory + freeMem(&tmp); + imap->_mbif._folderChanged = true; + goto ex; + } + + tmp = subStr(buf, NULL, imap_responses[esp_mail_imap_response_recent].text, 0); + if (tmp) + { + imap->_mbif._recentCount = atoi(tmp); + // release memory + freeMem(&tmp); + goto ex; + } + + tmp = subStr(buf, NULL, imap_responses[esp_mail_imap_response_fetch].text, 0); + if (tmp) + { + imap->_mbif._polling_status.messageNum = atoi(tmp); + // release memory + freeMem(&tmp); + + imap->_mbif._polling_status.argument = buf; + imap->_mbif._polling_status.argument.erase(0, p1 + 8); + imap->_mbif._polling_status.argument.pop_back(); + imap->_mbif._folderChanged = true; + imap->_mbif._polling_status.type = imap_polling_status_type_fetch_message; + goto ex; + } + + ex: + + imap->_mbif._floderChangedState = (imap->_mbif._folderChanged && exists) || imap->_mbif._polling_status.type == imap_polling_status_type_fetch_message; + } + + // release memory + freeMem(&buf); + } + + size_t imap_idle_tmo = imap->_imap_data->limit.imap_idle_timeout; + + if (imap_idle_tmo < 60 * 1000 || imap_idle_tmo > 29 * 60 * 1000) + imap_idle_tmo = 10 * 60 * 1000; + + if (millis() - imap->_mbif._idleTimeMs > imap_idle_tmo) + { + if (imap->mStopListen(true)) + return imap->mListen(true); + return false; + } + + return true; +} + +void ESP_Mail_Client::appendFetchString(MB_String &buf, bool uid) +{ + if (uid) + buf += imap_cmd_post_tokens[esp_mail_imap_command_uid]; + else + joinStringSpace(buf, false, 2, imap_commands[esp_mail_imap_command_flags].text, esp_mail_str_38 /* "(" */); +} + +void ESP_Mail_Client::parseCmdResponse(IMAPSession *imap, char *buf, PGM_P find) +{ + if (imap->_imap_cmd == esp_mail_imap_cmd_get_uid) + imap->_uid_tmp = 0; + + char *tmp = nullptr; + int p1 = strposP(buf, find, 0); + if (p1 != -1) + { + if (imap->_imap_cmd == esp_mail_imap_cmd_get_quota_root || + imap->_imap_cmd == esp_mail_imap_cmd_get_acl || + imap->_imap_cmd == esp_mail_imap_cmd_my_rights) + { + int ofs = imap->_imap_cmd == esp_mail_imap_cmd_get_quota_root ? 0 : 1; + int p2 = strposP(buf, esp_mail_str_2 /* " " */, p1 + strlen_P(find) + ofs); + if (p2 != -1) + { + int len = strlen(buf) - p2 - 1; + tmp = allocMem(len); + strncpy(tmp, buf + p2 + 1, strlen(buf) - p2 - 1); + if (imap->_imap_cmd == esp_mail_imap_cmd_get_quota_root) + { + if (imap->_quota_root_tmp.length() > 0) + imap->_quota_root_tmp += esp_mail_str_8; /* ";" */ + imap->_quota_root_tmp += tmp; + } + else + { + imap->_acl_tmp = tmp; + } + + // release memory + freeMem(&tmp); + } + } + else + { + int len = imap->_imap_cmd == esp_mail_imap_cmd_get_uid ? 20 : strlen(buf) - p1 - strlen_P(find); + int ofs = imap->_imap_cmd == esp_mail_imap_cmd_get_uid || + imap->_imap_cmd == esp_mail_imap_cmd_fetch_sequence_set + ? 1 + : imap->_imap_cmd == esp_mail_imap_cmd_namespace || imap->_imap_cmd == esp_mail_imap_cmd_id ? 0 + : 2; + tmp = allocMem(len); + + strncpy(tmp, buf + p1 + strlen_P(find), strlen(buf) - p1 - strlen_P(find) - ofs); + + esp_mail_imap_msg_num_t msg_num; + + switch ((int)imap->_imap_cmd) + { + case esp_mail_imap_cmd_get_uid: + imap->_uid_tmp = atoi(tmp); + break; + case esp_mail_imap_cmd_get_flags: + imap->_flags_tmp = tmp; + break; + case esp_mail_imap_cmd_get_quota: + imap->_quota_tmp = tmp; + break; + case esp_mail_imap_cmd_id: + imap->_server_id_tmp = tmp; + break; + case esp_mail_imap_cmd_namespace: + imap->_ns_tmp += tmp; + break; + case esp_mail_imap_cmd_fetch_sequence_set: + + msg_num.type = esp_mail_imap_msg_num_type_uid; + msg_num.value = (uint32_t)atoi(tmp); + imap->_imap_msg_num.push_back(msg_num); + + if (imap->_imap_msg_num.size() > imap->_imap_data->limit.fetch) + imap->_imap_msg_num.erase(imap->_imap_msg_num.begin()); + + break; + default: + break; + } + } + + // release memory + freeMem(&tmp); + } +} + +bool ESP_Mail_Client::getFlags(IMAPSession *imap, char *buf, esp_mail_imap_response_types type) +{ + if (strposP(buf, imap_responses[type].text, 0) != -1) + { + char *p = allocMem(strlen(buf)); + strcpy(p, buf); + char *pp = p; + char *end = p; + int count = 0; + bool isList = false; + int tkPos = (type == esp_mail_imap_response_permanent_flags) ? 4 : 3; + + while (pp != NULL) + { + // See RFC2047.h + ESP_MAIL_STRSEP(&end, " "); + count++; + if (count >= tkPos && strlen(pp) > 0) + { + if (type == esp_mail_imap_response_permanent_flags && pp[strlen(pp) - 1] == ']') + pp[strlen(pp) - 1] = 0; + + if (count == tkPos && pp[0] == '(' && pp[1] != ')') + imap->_mbif.addFlag(getList(pp, isList), type == esp_mail_imap_response_permanent_flags); + else if (isList) + imap->_mbif.addFlag(getList(pp, isList), type == esp_mail_imap_response_permanent_flags); + } + pp = end; + } + + // release memory + freeMem(&p); + + return true; + } + + return false; +} + +void ESP_Mail_Client::parseExamineResponse(IMAPSession *imap, char *buf) +{ + char *tmp = NULL; + + tmp = subStr(buf, NULL, imap_responses[esp_mail_imap_response_exists].text, 0); + if (tmp) + { + imap->_mbif._msgCount = atoi(tmp); + // release memory + freeMem(&tmp); + return; + } + + tmp = subStr(buf, NULL, imap_responses[esp_mail_imap_response_recent].text, 0); + if (tmp) + { + imap->_mbif._recentCount = atoi(tmp); + // release memory + freeMem(&tmp); + return; + } + + if (imap->_mbif._flags.size() == 0 && getFlags(imap, buf, esp_mail_imap_response_flags)) + return; + + if (imap->_mbif._permanent_flags.size() == 0 && getFlags(imap, buf, esp_mail_imap_response_permanent_flags)) + return; + + if (imap->_mbif._uidValidity == 0) + { + tmp = subStr(buf, imap_responses[esp_mail_imap_response_uidvalidity].text, esp_mail_str_41 /* "]" */, 0, 0); + if (tmp) + { + imap->_mbif._uidValidity = atoi(tmp); + // release memory + freeMem(&tmp); + return; + } + } + + if (imap->_nextUID.length() == 0) + { + tmp = subStr(buf, imap_responses[esp_mail_imap_response_uidnext].text, esp_mail_str_41 /* "]" */, 0, 0); + if (tmp) + { + imap->_nextUID = tmp; + imap->_mbif._nextUID = atoi(tmp); + // release memory + freeMem(&tmp); + return; + } + } + + if (imap->_unseenMsgIndex.length() == 0) + { + tmp = subStr(buf, imap_responses[esp_mail_imap_response_unseen].text, esp_mail_str_41 /* "]" */, 0, 0); + if (tmp) + { + imap->_unseenMsgIndex = tmp; + imap->_mbif._unseenMsgIndex = atoi(tmp); + // release memory + freeMem(&tmp); + return; + } + } + + if (imap->isCondStoreSupported()) + { + tmp = subStr(buf, imap_responses[esp_mail_imap_response_highest_modsec].text, esp_mail_str_41 /* "]" */, 0, 0); + if (tmp) + { + imap->_mbif._highestModSeq = tmp; + // release memory + freeMem(&tmp); + return; + } + + tmp = subStr(buf, imap_responses[esp_mail_imap_response_nomodsec].text, nullptr, 0, 0); + if (tmp) + { + imap->_mbif._nomodsec = true; + // release memory + freeMem(&tmp); + return; + } + } +} + +bool ESP_Mail_Client::handleIMAPError(IMAPSession *imap, int err, bool ret) +{ + if (err < 0) + { + errorStatusCB(imap, nullptr, err, true); + + if (imap->_headers.size() > 0 && cHeader(imap)) + { + if ((imap->_imap_cmd == esp_mail_imap_cmd_fetch_body_attachment || imap->_imap_cmd == esp_mail_imap_cmd_fetch_body_inline) && (imap->_imap_data->download.attachment || imap->_imap_data->download.inlineImg)) + { + if (cPart(imap) && cHeader(imap)->part_headers.size() > 0) + cPart(imap)->download_error = imap->errorReason().c_str(); + } + else if (cHeader(imap)) + cHeader(imap)->error_msg = imap->errorReason().c_str(); + + cHeader(imap)->error = true; + } + } + + closeTCPSession(imap); + + imap->_cbData.empty(); + + return ret; +} + +void ESP_Mail_Client::prepareFileList(IMAPSession *imap, MB_String &filePath) +{ +#if defined(MBFS_SD_FS) + if (!mbfs->longNameSupported()) + { + cHeader(imap)->sd_alias_file_count++; + MB_String alias = cHeader(imap)->message_uid; + alias += esp_mail_str_83; /* "_" */ + alias += cHeader(imap)->sd_alias_file_count; + + if (imap->_sdFileList.length() > 0) + { + if (imap->_sdFileList[imap->_sdFileList.length() - 1] == ']') + { + imap->_sdFileList[imap->_sdFileList.length() - 1] = 0; + imap->_sdFileList += esp_mail_str_8; /* "," */ + } + } + imap->_sdFileList += esp_mail_str_80; /* "{\"Renamed\":\"" */ + imap->_sdFileList += alias; + imap->_sdFileList += esp_mail_str_81; /* "\",\"Original\":\"" */ + imap->_sdFileList += filePath; + imap->_sdFileList += esp_mail_str_82; /* "\"}]" */ + // rename the original file + filePath = alias; + } +#endif +} + +bool ESP_Mail_Client::parseAttachmentResponse(IMAPSession *imap, char *buf, esp_mail_imap_response_data &res) +{ + int bufLen = res.readLen; + + if (res.chunkIdx == 0) + { + char *tmp = subStr(buf, esp_mail_str_36 /* "{" */, esp_mail_str_37 /* "}" */, 0); + if (tmp) + { + res.chunkIdx++; + res.octetCount = 0; // CRLF counted from first line + res.octetLength = atoi(tmp); + // release memory + freeMem(&tmp); + cPart(imap)->octetLen = res.octetLength; + cPart(imap)->octetCount = 0; + cHeader(imap)->total_download_size += res.octetLength; + imap->_lastProgress = -1; + +#if defined(ESP_MAIL_OTA_UPDATE_ENABLED) + if (cPart(imap)->is_firmware_file) + { + cPart(imap)->is_firmware_file = Update.begin(cPart(imap)->attach_data_size); + + if (!cPart(imap)->is_firmware_file) + { + imap->_responseStatus.errorCode = IMAP_STATUS_FIRMWARE_UPDATE_INIT_FAILED; + imap->_responseStatus.text.clear(); + } + +#if !defined(SILENT_MODE) + + sendCallback(imap, esp_mail_cb_str_42 /* "Updating firmware..." */, true, false); + + if (!cPart(imap)->is_firmware_file) + { + printDebug(imap, + imap->errorReason().c_str(), + imap->errorReason().c_str(), + esp_mail_debug_tag_type_error, + true, + false); + } + +#endif + } +#endif + + if (!cPart(imap)->file_open_write) + { + + if (imap->_storageReady && cPart(imap)->save_to_file) + { + res.downloadRequest = true; + + res.filePath.clear(); + + res.filePath += imap->_imap_data->storage.saved_path; + res.filePath += esp_mail_str_10; /* "/" */ + res.filePath += cHeader(imap)->message_uid; + res.filePath += esp_mail_str_10; /* "/" */ + res.filePath += cPart(imap)->filename; + + prepareFileList(imap, res.filePath); + + int sz = mbfs->open(res.filePath, mbfs_type imap->_imap_data->storage.type, mb_fs_open_mode_write); + + if (sz < 0) + { + imap->_responseStatus.errorCode = sz; + imap->_responseStatus.text.clear(); +#if !defined(SILENT_MODE) + printDebug(imap, + imap->errorReason().c_str(), + imap->errorReason().c_str(), + esp_mail_debug_tag_type_error, + true, + false); +#endif + } + + cPart(imap)->file_open_write = true; + } + } + } + return true; + } + + yield_impl(); + + if (res.octetLength == 0) + return true; + + if (cPart(imap)->octetCount <= res.octetLength) + { + if (cPart(imap)->octetCount + bufLen > res.octetLength) + { + bufLen = res.octetLength - cPart(imap)->octetCount; + buf[bufLen] = 0; + cPart(imap)->octetCount += bufLen; + } + else + cPart(imap)->octetCount = res.octetCount; + + if (imap->_imap_data->enable.download_status) + { + if (imap->_debug) + downloadReport(imap, 100 * cPart(imap)->octetCount / res.octetLength); + } + + if (cPart(imap)->octetCount > res.octetLength) + return true; + + bool write_error = false, fw_write_error = false; + + if (cPart(imap)->xencoding == esp_mail_msg_xencoding_base64) + { + + size_t olen = 0; + unsigned char *decoded = decodeBase64((const unsigned char *)buf, bufLen, &olen); + + if (decoded) + { + + if (!cPart(imap)->sizeProp) + { + cPart(imap)->attach_data_size += olen; + cHeader(imap)->total_attach_data_size += cPart(imap)->attach_data_size; + } + + sendStreamCB(imap, (void *)decoded, olen, res.chunkIdx, false); + + size_t write = olen; + + if (cPart(imap)->is_firmware_file) + { +#if defined(ESP_MAIL_OTA_UPDATE_ENABLED) + size_t fw_write = Update.write((uint8_t *)decoded, olen); + cPart(imap)->firmware_downloaded_byte += fw_write == olen ? olen : 0; + fw_write_error = fw_write != olen; +#endif + } + + if (cPart(imap)->save_to_file) + { + if (mbfs->ready(mbfs_type imap->_imap_data->storage.type)) + write = mbfs->write(mbfs_type imap->_imap_data->storage.type, (uint8_t *)decoded, olen); + } + + yield_impl(); + // release memory + freeMem(&decoded); + + write_error = write != olen; + } + + if (!reconnect(imap)) + return false; + } + else + { + // binary content + if (!cPart(imap)->sizeProp) + { + cPart(imap)->attach_data_size += bufLen; + cHeader(imap)->total_attach_data_size += cPart(imap)->attach_data_size; + } + + sendStreamCB(imap, (void *)buf, bufLen, res.chunkIdx, false); + + int write = bufLen; + + if (cPart(imap)->is_firmware_file) + { +#if defined(ESP_MAIL_OTA_UPDATE_ENABLED) + int fw_write = Update.write((uint8_t *)buf, bufLen); + cPart(imap)->firmware_downloaded_byte += fw_write == bufLen ? (size_t)bufLen : 0; + fw_write_error = fw_write != bufLen; +#endif + } + + if (cPart(imap)->save_to_file) + { + if (mbfs->ready(mbfs_type imap->_imap_data->storage.type)) + write = mbfs->write(mbfs_type imap->_imap_data->storage.type, (uint8_t *)buf, bufLen); + } + + yield_impl(); + + write_error = write != bufLen; + + if (!reconnect(imap)) + return false; + } + +#if defined(ESP_MAIL_OTA_UPDATE_ENABLED) + if (cPart(imap)->is_firmware_file) + { + bool update_result_ok = !fw_write_error; + + if (!imap->_isFirmwareUpdated && update_result_ok && + (cPart(imap)->firmware_downloaded_byte == (size_t)cPart(imap)->attach_data_size || cPart(imap)->octetCount >= res.octetLength)) + { + update_result_ok = Update.end(cPart(imap)->octetCount >= res.octetLength); + if (update_result_ok) + imap->_isFirmwareUpdated = true; + } + + if (!update_result_ok) + { + cPart(imap)->is_firmware_file = false; + + imap->_responseStatus.errorCode = fw_write_error ? IMAP_STATUS_FIRMWARE_UPDATE_WRITE_FAILED : IMAP_STATUS_FIRMWARE_UPDATE_END_FAILED; + imap->_responseStatus.text.clear(); + +#if !defined(SILENT_MODE) + printDebug(imap, + imap->_responseStatus.text.c_str(), + imap->errorReason().c_str(), + esp_mail_debug_tag_type_error, + !imap->_debug, + false); +#endif + } + } +#endif + + if (write_error || fw_write_error) + return false; + } + + res.chunkIdx++; + return true; +} + +void ESP_Mail_Client::downloadReport(IMAPSession *imap, int progress) +{ + printProgress(progress, imap->_lastProgress); +} + +void ESP_Mail_Client::fetchReport(IMAPSession *imap, int progress, bool download) +{ +#if !defined(SILENT_MODE) + if (imap->_debug && imap->_lastProgress == -1 && strcmp_P(cPart(imap)->filename.c_str(), esp_mail_str_84 /* "message" */) != 0) + esp_mail_debug_print_tag(cPart(imap)->filename.c_str(), esp_mail_debug_tag_type_client, true); + printProgress(progress, imap->_lastProgress); +#endif +} + +void ESP_Mail_Client::searchReport(IMAPSession *imap, int progress) +{ + printProgress(progress, imap->_lastProgress); +} + +struct esp_mail_imap_msg_num_t ESP_Mail_Client::cMSG(IMAPSession *imap) +{ + return imap->_imap_msg_num[cIdx(imap)]; +} + +int ESP_Mail_Client::cIdx(IMAPSession *imap) +{ + return imap->_cMsgIdx; +} + +void ESP_Mail_Client::decodeText(IMAPSession *imap, esp_mail_imap_response_data &res) +{ + int bufLen = res.readLen; + bool rfc822_body_subtype = cPart(imap)->message_sub_type == esp_mail_imap_message_sub_type_rfc822; + if (res.chunkIdx == 0) + { + + imap->_lastProgress = -1; + char *tmp = subStr(res.response, esp_mail_str_36 /* "{" */, esp_mail_str_37 /* "}" */, 0); + if (tmp) + { + res.chunkIdx++; + res.octetCount = 0; + res.octetLength = atoi(tmp); + // release memory + freeMem(&tmp); + cPart(imap)->octetLen = res.octetLength; + cPart(imap)->octetCount = 0; + + bool dlMsg = (rfc822_body_subtype && imap->_imap_data->download.rfc822) || (!rfc822_body_subtype && ((cPart(imap)->msg_type == esp_mail_msg_type_html && imap->_imap_data->download.html) || ((cPart(imap)->msg_type == esp_mail_msg_type_plain || cPart(imap)->msg_type == esp_mail_msg_type_enriched) && imap->_imap_data->download.text))); + if (dlMsg) + prepareFilePath(imap, res.filePath, false); + + if (res.filePath.length() == 0) + { + if (!rfc822_body_subtype) + res.filePath += esp_mail_str_84; /* "message" */ + else + joinStringSpace(res.filePath, false, 2, esp_mail_str_85 /* "rfc822" */, esp_mail_str_84 /* "message" */); + } + cPart(imap)->filename = res.filePath; + + if (imap->_storageReady && !cPart(imap)->file_open_write && dlMsg) + { + + prepareFileList(imap, res.filePath); + + int sz = mbfs->open(res.filePath, mbfs_type imap->_imap_data->storage.type, mb_fs_open_mode_write); + if (sz > -1) + { + res.downloadRequest = true; + cPart(imap)->file_open_write = true; + } + else + { + imap->_responseStatus.errorCode = sz; + imap->_responseStatus.text.clear(); +#if !defined(SILENT_MODE) + if (imap->_debug) + esp_mail_debug_print_tag(imap->errorReason().c_str(), esp_mail_debug_tag_type_error, true); +#endif + } + } + + return; + } + else + { +#if !defined(SILENT_MODE) + if (imap->_debug) + esp_mail_debug_print_tag(esp_mail_error_imap_str_12 /* "no centent" */, esp_mail_debug_tag_type_client, false); +#endif + } + } + + yield_impl(); + + if (res.octetLength == 0) + return; + + bool enableDownloads = (imap->_imap_data->download.rfc822 && rfc822_body_subtype) || (!rfc822_body_subtype && ((cPart(imap)->msg_type == esp_mail_msg_type_html && imap->_imap_data->download.html) || ((cPart(imap)->msg_type == esp_mail_msg_type_plain || cPart(imap)->msg_type == esp_mail_msg_type_enriched) && imap->_imap_data->download.text))); + + if (imap->_imap_data->download.rfc822 || imap->_imap_data->download.html || imap->_imap_data->download.text || (rfc822_body_subtype && imap->_imap_data->enable.rfc822) || (!rfc822_body_subtype && ((cPart(imap)->msg_type == esp_mail_msg_type_html && imap->_imap_data->enable.html) || ((cPart(imap)->msg_type == esp_mail_msg_type_plain || cPart(imap)->msg_type == esp_mail_msg_type_enriched) && imap->_imap_data->enable.text)))) + { + + if (cPart(imap)->octetCount + bufLen >= res.octetLength) + { + bufLen = res.octetLength - cPart(imap)->octetCount; + cPart(imap)->octetCount += bufLen; + + if (res.octetLength <= res.octetCount && cPart(imap)->xencoding != esp_mail_msg_xencoding_base64 && cPart(imap)->xencoding != esp_mail_msg_xencoding_qp) + bufLen = 0; + + res.response[bufLen] = 0; + } + else + cPart(imap)->octetCount = res.octetCount; + + if (imap->_debug) + fetchReport(imap, 100 * cPart(imap)->octetCount / res.octetLength, enableDownloads); + + if (cPart(imap)->octetCount <= res.octetLength) + { + bool hrdBrk = cPart(imap)->xencoding == esp_mail_msg_xencoding_qp; + hrdBrk &= cPart(imap)->octetCount < res.octetLength; + hrdBrk &= bufLen == 2 && res.response[bufLen - 2] != '\r' && res.response[bufLen - 1] != '\n'; + + // remove soft break for QP + if (bufLen <= QP_ENC_MSG_LEN && res.response[bufLen - 1] == '=' && cPart(imap)->xencoding == esp_mail_msg_xencoding_qp) + { + hrdBrk = false; + res.response[bufLen - 1] = 0; + bufLen--; + } + + size_t olen = 0; + char *decoded = nullptr; + MB_String str; + bool dontDeleteOrModify = false; + + // decode the content based on the transfer decoding + if (cPart(imap)->xencoding == esp_mail_msg_xencoding_base64) + { + decoded = (char *)decodeBase64((const unsigned char *)res.response, bufLen, &olen); + } + else if (cPart(imap)->xencoding == esp_mail_msg_xencoding_qp) + { + decoded = allocMem(bufLen + 10); + decodeQP_UTF8(res.response, decoded); + olen = strlen(decoded); + } + else if (cPart(imap)->xencoding == esp_mail_msg_xencoding_7bit) + { + decoded = decode7Bit_UTF8(res.response); + olen = strlen(decoded); + } + else if (cPart(imap)->xencoding == esp_mail_msg_xencoding_8bit) + { + decoded = decode8Bit_UTF8(res.response); + olen = strlen(decoded); + } + else + { + // binary + dontDeleteOrModify = true; + decoded = res.response; + olen = bufLen; + } + + if (decoded) + { + // charset? apply character decoding to the decoded or nonencoded content + if ((rfc822_body_subtype && imap->_imap_data->enable.rfc822) || (!rfc822_body_subtype && ((cPart(imap)->msg_type == esp_mail_msg_type_html && imap->_imap_data->enable.html) || ((cPart(imap)->msg_type == esp_mail_msg_type_plain || cPart(imap)->msg_type == esp_mail_msg_type_enriched) && imap->_imap_data->enable.text)))) + { + if (imap->_charDecCallback) + { + IMAP_Decoding_Info decoding; + decoding.charset = cPart(imap)->charset.c_str(); + decoding.data = decoded; + decoding.type = IMAP_Decoding_Info::message_part_type_text; + + imap->_charDecCallback(&decoding); + + if (decoding.decodedString.length() > 0) + { + char *buf2 = allocMem(decoding.decodedString.length() + 1); + strcpy(buf2, decoding.decodedString.c_str()); + + if (decoded && !dontDeleteOrModify) + // release memory + freeMem(&decoded); + + decoded = buf2; + olen = strlen(buf2); + } + } + else + { + esp_mail_char_decoding_scheme scheme = getEncodingFromCharset(cPart(imap)->charset.c_str()); + + if (scheme == esp_mail_char_decoding_scheme_iso8859_1) + { + int ilen = olen; + int olen2 = (ilen + 1) * 2; + unsigned char *tmp = allocMem(olen2); + decodeLatin1_UTF8(tmp, &olen2, (unsigned char *)decoded, &ilen); + + if (decoded && !dontDeleteOrModify) + // release memory + freeMem(&decoded); + + olen = olen2; + decoded = (char *)tmp; + } + else if (scheme == esp_mail_char_decoding_scheme_tis_620 || scheme == esp_mail_char_decoding_scheme_iso8859_11 || scheme == esp_mail_char_decoding_scheme_windows_874) + { + char *out = allocMem((olen + 1) * 3); + decodeTIS620_UTF8(out, decoded, olen); + olen = strlen(out); + if (decoded && !dontDeleteOrModify) + // release memory + freeMem(&decoded); + decoded = out; + } + } + + if (cPart(imap)->text.length() < imap->_imap_data->limit.msg_size) + { + + if (cPart(imap)->text.length() + olen < imap->_imap_data->limit.msg_size) + { + cPart(imap)->textLen += olen; + cPart(imap)->text.append(decoded, olen); + if (hrdBrk) + { + appendNewline(cPart(imap)->text); + cPart(imap)->textLen += 2; + } + } + else + { + int d = imap->_imap_data->limit.msg_size - cPart(imap)->text.length(); + cPart(imap)->textLen += d; + if (d > 0) + cPart(imap)->text.append(decoded, d); + + if (hrdBrk) + { + appendNewline(cPart(imap)->text); + cPart(imap)->textLen += 2; + } + } + } + } + + if (res.filePath.length() > 0 && res.downloadRequest) + { + if (mbfs->ready(mbfs_type imap->_imap_data->storage.type)) + { + if (olen > 0) + mbfs->write(mbfs_type imap->_imap_data->storage.type, (uint8_t *)decoded, olen); + if (hrdBrk) + mbfs->write(mbfs_type imap->_imap_data->storage.type, (uint8_t *)"\r\n", 2); + } + } + + sendStreamCB(imap, (void *)decoded, olen, res.chunkIdx, hrdBrk); + + if (decoded && !dontDeleteOrModify) + // release memory + freeMem(&decoded); + } + } + } + + res.chunkIdx++; +} + +void ESP_Mail_Client::sendStreamCB(IMAPSession *imap, void *buf, size_t len, int chunkIndex, bool hrdBrk) +{ + if (imap->_mimeDataStreamCallback && len > 0) + { + MIME_Data_Stream_Info streaminfo; + streaminfo.uid = cHeader(imap)->message_uid; + streaminfo.disposition = cPart(imap)->content_disposition.c_str(); + streaminfo.type = cPart(imap)->content_type.c_str(); + streaminfo.charSet = cPart(imap)->charset.c_str(); + streaminfo.transfer_encoding = cPart(imap)->content_transfer_encoding.c_str(); + streaminfo.cid = cPart(imap)->CID.c_str(); + streaminfo.description = cPart(imap)->content_description.c_str(); + streaminfo.date = cPart(imap)->creation_date.c_str(); + streaminfo.filename = cPart(imap)->filename.c_str(); + streaminfo.size = (cPart(imap)->sizeProp) ? cPart(imap)->attach_data_size : cPart(imap)->octetLen; + streaminfo.name = cPart(imap)->name.c_str(); + streaminfo.octet_size = cPart(imap)->octetLen; + streaminfo.octet_count = cPart(imap)->octetCount; + streaminfo.isFirstData = chunkIndex == 1; + streaminfo.isLastData = !hrdBrk ? cPart(imap)->octetLen == cPart(imap)->octetCount : false; + streaminfo.data_size = len; + streaminfo.data = buf; + streaminfo.flowed = cPart(imap)->plain_flowed; + streaminfo.delsp = cPart(imap)->plain_delsp; + + imap->_mimeDataStreamCallback(streaminfo); + + if (hrdBrk) + { + streaminfo.isFirstData = false; + streaminfo.isLastData = cPart(imap)->octetLen == cPart(imap)->octetCount; + streaminfo.data_size = 2; + streaminfo.data = (void *)"\r\n"; + imap->_mimeDataStreamCallback(streaminfo); + } + } +} + +void ESP_Mail_Client::prepareFilePath(IMAPSession *imap, MB_String &filePath, bool header) +{ + bool rfc822_body_subtype = cPart(imap)->message_sub_type == esp_mail_imap_message_sub_type_rfc822; + MB_String fpath = imap->_imap_data->storage.saved_path; + fpath += esp_mail_str_10; /* "/" */ + fpath += cHeader(imap)->message_uid; + + if (!header) + { + if (!rfc822_body_subtype) + { + fpath += esp_mail_str_86; /* "/msg" */ + if (cPart(imap)->msg_type == esp_mail_msg_type_plain || cPart(imap)->msg_type == esp_mail_msg_type_enriched) + fpath += mimeinfo[esp_mail_file_extension_txt].endsWith; + else if (cPart(imap)->msg_type == esp_mail_msg_type_html) + fpath += mimeinfo[esp_mail_file_extension_htm].endsWith; + } + else + { + fpath += esp_mail_str_87; /* "/rfc822_msg" */ + + if (cPart(imap)->rfc822_msg_Idx > 0) + fpath += cPart(imap)->rfc822_msg_Idx; + + if (cPart(imap)->msg_type == esp_mail_msg_type_plain || cPart(imap)->msg_type == esp_mail_msg_type_enriched) + fpath += mimeinfo[esp_mail_file_extension_txt].endsWith; + else if (cPart(imap)->msg_type == esp_mail_msg_type_html) + fpath += mimeinfo[esp_mail_file_extension_htm].endsWith; + else + // possible rfc822 encapsulated message which cannot fetch its header + fpath += mimeinfo[esp_mail_file_extension_dat].endsWith; + } + } + + filePath = fpath; +} + +void ESP_Mail_Client::sendStorageNotReadyError(IMAPSession *imap, esp_mail_file_storage_type storageType) +{ + +#if defined(MBFS_FLASH_FS) || defined(MBFS_SD_FS) +#if !defined(SILENT_MODE) + if (imap->_debug && (storageType == esp_mail_file_storage_type_flash || storageType == esp_mail_file_storage_type_sd)) + { + if (storageType == esp_mail_file_storage_type_flash) + { + esp_mail_debug_print_tag(esp_mail_error_mem_str_1 /* "flash Storage is not ready." */, esp_mail_debug_tag_type_error, true); +#if defined(MB_ARDUINO_PICO) + esp_mail_debug_print_tag(esp_mail_error_mem_str_10 /* "please make sure that the size of flash filesystem is not 0 in Pico." */, esp_mail_debug_tag_type_error, true); +#endif + } + else if (storageType == esp_mail_file_storage_type_sd) + esp_mail_debug_print_tag(esp_mail_error_mem_str_2 /* "SD Storage is not ready." */, esp_mail_debug_tag_type_error, true); + } +#endif +#endif +} + +IMAPSession::IMAPSession(Client *client) +{ + setClient(client); +} + +IMAPSession::IMAPSession() +{ +} + +IMAPSession::~IMAPSession() +{ + empty(); +} + +bool IMAPSession::closeSession() +{ + _prev_imap_cmd = esp_mail_imap_cmd_sasl_login; + _prev_imap_custom_cmd = esp_mail_imap_cmd_custom; + + if (!connected()) + return false; + + if (_mbif._idleTimeMs > 0) + mStopListen(false); + + if (_loginStatus) + { +#if !defined(ESP8266) + /** + * The strange behavior in ESP8266 SSL client, BearSSLWiFiClientSecure + * The client disposed without memory released after the server close + * the connection due to LOGOUT command, which caused the memory leaks. + */ + if (!MailClient.imapLogout(this)) + return false; +#endif + } + + return MailClient.handleIMAPError(this, 0, true); +} + +bool IMAPSession::connected() +{ + return client.connected(); +} + +bool IMAPSession::connect(Session_Config *session_config, IMAP_Data *imap_data, bool login) +{ + _sessionSSL = false; + _sessionLogin = login; + + if (session_config) + session_config->clearPorts(); + + this->_customCmdResCallback = NULL; + + int ptr = toAddr(*session_config); + session_config->addPtr(&_configPtrList, ptr); + + if (!handleConnection(session_config, imap_data, _sessionSSL)) + return false; + + if (!_sessionLogin) + return true; + + _loginStatus = MailClient.imapAuth(this, _sessionSSL); + + return _loginStatus; +} + +bool IMAPSession::mLogin(MB_StringPtr email, MB_StringPtr password, bool isToken) +{ + if (_loginStatus) + return true; + + if (!MailClient.sessionExisted(this)) + return false; + + _session_cfg->login.email = email; + + _session_cfg->login.accessToken.clear(); + _session_cfg->login.password.clear(); + + if (isToken) + _session_cfg->login.accessToken = password; + else + _session_cfg->login.password = password; + + _loginStatus = MailClient.imapAuth(this, _sessionSSL); + + return _loginStatus; +} + +void IMAPSession::appendIdList(MB_String &list, IMAP_Identification *identification) +{ + + if (identification->name.length() > 0 && identification->name.length() <= 1024) + MailClient.appendImap4KeyValue(list, imap_identification_keys[esp_mail_imap_identification_key_name].text, identification->name.c_str()); + + if (identification->version.length() > 0 && identification->version.length() <= 1024) + { + if (list.length() > 0) + MailClient.appendSpace(list); + MailClient.appendImap4KeyValue(list, imap_identification_keys[esp_mail_imap_identification_key_version].text, identification->version.c_str()); + } + + if (identification->os.length() > 0 && identification->os.length() <= 1024) + { + if (list.length() > 0) + MailClient.appendSpace(list); + MailClient.appendImap4KeyValue(list, imap_identification_keys[esp_mail_imap_identification_key_os].text, identification->os.c_str()); + } + + if (identification->vendor.length() > 0 && identification->vendor.length() <= 1024) + { + if (list.length() > 0) + MailClient.appendSpace(list); + MailClient.appendImap4KeyValue(list, imap_identification_keys[esp_mail_imap_identification_key_vendor].text, identification->vendor.c_str()); + } + + if (identification->support_url.length() > 0 && identification->support_url.length() <= 1024) + { + if (list.length() > 0) + MailClient.appendSpace(list); + MailClient.appendImap4KeyValue(list, imap_identification_keys[esp_mail_imap_identification_key_support_url].text, identification->support_url.c_str()); + } + + if (identification->address.length() > 0 && identification->address.length() <= 1024) + { + if (list.length() > 0) + MailClient.appendSpace(list); + MailClient.appendImap4KeyValue(list, imap_identification_keys[esp_mail_imap_identification_key_address].text, identification->address.c_str()); + } + + if (identification->date.length() > 0 && identification->date.length() <= 1024) + { + if (list.length() > 0) + MailClient.appendSpace(list); + MailClient.appendImap4KeyValue(list, imap_identification_keys[esp_mail_imap_identification_key_date].text, identification->date.c_str()); + } + + if (identification->command.length() > 0 && identification->command.length() <= 1024) + { + if (list.length() > 0) + MailClient.appendSpace(list); + MailClient.appendImap4KeyValue(list, imap_identification_keys[esp_mail_imap_identification_key_command].text, identification->command.c_str()); + } + + if (identification->arguments.length() > 0 && identification->arguments.length() <= 1024) + { + if (list.length() > 0) + MailClient.appendSpace(list); + MailClient.appendImap4KeyValue(list, imap_identification_keys[esp_mail_imap_identification_key_arguments].text, identification->arguments.c_str()); + } + + if (identification->environment.length() > 0 && identification->environment.length() <= 1024) + { + if (list.length() > 0) + MailClient.appendSpace(list); + MailClient.appendImap4KeyValue(list, imap_identification_keys[esp_mail_imap_identification_key_environment].text, identification->environment.c_str()); + } +} + +bool IMAPSession::id(IMAP_Identification *identification) +{ +#if !defined(SILENT_MODE) + MailClient.printDebug(this, + esp_mail_cb_str_61 /* "Send client identification..." */, + esp_mail_dbg_str_82 /* "send IMAP command, ID" */, + esp_mail_debug_tag_type_client, + true, + false); +#endif + if (!_feature_capability[esp_mail_imap_read_capability_id]) + { +#if !defined(SILENT_MODE) + printDebugNotSupported(); +#endif + return false; + } + + if (!MailClient.reconnect(this)) + return false; + + MB_String cmd, idList; + + appendIdList(idList, identification); + + MailClient.appendSpace(cmd, true, imap_commands[esp_mail_imap_command_id].text); + + if (idList.length() > 0) + MailClient.appendString(cmd, idList.c_str(), false, false, esp_mail_string_mark_type_round_bracket); + else + { + int bufLen = 50; + char *buf = MailClient.allocMem(bufLen); + snprintf(buf, bufLen, pgm2Str(esp_mail_str_21 /* "(\"name\" \"ESP Mail Client\" \"version\" \"%s\")" */), ESP_MAIL_VERSION); + cmd += buf; + // release memory + MailClient.freeMem(&buf); + } + + if (MailClient.imapSend(this, cmd.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return false; + + _imap_cmd = esp_mail_imap_cmd_id; + if (!MailClient.handleIMAPResponse(this, IMAP_STATUS_BAD_COMMAND, false)) + return false; + + return true; +} + +String IMAPSession::serverID() +{ + return _server_id_tmp.c_str(); +} + +bool IMAPSession::isAuthenticated() +{ + return _authenticated; +} + +bool IMAPSession::isLoggedIn() +{ + return _loginStatus; +} + +bool IMAPSession::isFirmwareUpdateSuccess() +{ + return _isFirmwareUpdated; +} + +bool IMAPSession::mCustomConnect(Session_Config *session_config, imapResponseCallback callback, MB_StringPtr tag) +{ + this->_customCmdResCallback = callback; + this->_responseStatus.tag = tag; + + bool ssl = false; + if (!handleConnection(session_config, NULL, ssl)) + return false; + + return true; +} + +bool IMAPSession::handleConnection(Session_Config *session_config, IMAP_Data *imap_data, bool &ssl) +{ + + _session_cfg = session_config; + + if (!client.isInitialized()) + return MailClient.handleIMAPError(this, TCP_CLIENT_ERROR_NOT_INITIALIZED, false); + + // Resources are also released if network disconnected. + if (!MailClient.reconnect(this)) + return false; + + // Need to close previous connection first to free resources. + MailClient.closeTCPSession(this); + + _session_cfg = session_config; + _imap_data = imap_data; + + MailClient.setCert(_session_cfg, _session_cfg->certificate.cert_data); + + ssl = false; + if (!connect(ssl)) + { + MailClient.closeTCPSession(this); + return false; + } + + return true; +} + +bool IMAPSession::connect(bool &ssl) +{ + ssl = false; + MB_String buf; + + if (_imap_data) + { + if (_imap_data->fetch.sequence_set.string.length() > 0 || _imap_data->fetch.uid.length() > 0 || _imap_data->fetch.number.length() > 0) + _headerOnly = false; + else + _headerOnly = true; + } + + _totalRead = 0; + _secure = true; + bool secureMode = true; + + client.txBufDivider = 16; // minimum, tx buffer size for ssl data and request command data + client.rxBufDivider = 1; + if (_imap_data) + { + if (!_headerOnly && !_imap_data->firmware_update.attach_filename.length() == 0 && !_imap_data->enable.html && !_imap_data->enable.text && !_imap_data->download.attachment && !_imap_data->download.inlineImg && !_imap_data->download.html && !_imap_data->download.text) + client.rxBufDivider = 16; // minimum rx buffer size for only message header + } + + MailClient.preparePortFunction(_session_cfg, false, _secure, secureMode, ssl); + +#if !defined(SILENT_MODE) + MailClient.printLibInfo(this); +#endif + + MailClient.prepareTime(_session_cfg, this); + + MailClient.setSecure(client, _session_cfg); + + if (!MailClient.beginConnection(_session_cfg, this, secureMode)) + return false; + + // server connected + + client.setTimeout(tcpTimeout); + + // wait for greeting + unsigned long dataMs = millis(); + while (client.connected() && client.available() == 0 && millis() - dataMs < 2000) + { + yield_impl(); + } + + int chunkBufSize = client.available(); + + if (chunkBufSize > 0) + { + char *buf = MailClient.allocMem(chunkBufSize + 1); + client.readBytes(buf, chunkBufSize); + if (_debug && _debugLevel > esp_mail_debug_level_basic && !_customCmdResCallback) + esp_mail_debug_print((const char *)buf, true); + + if (_customCmdResCallback) + { + MailClient.imapResponseStatus(this, buf, esp_mail_str_3 /* "*" */); + _responseStatus.text = buf; + + if (_responseStatus.text[_responseStatus.text.length() - 2] == '\r' && _responseStatus.text[_responseStatus.text.length() - 1] == '\n') + _responseStatus.text[_responseStatus.text.length() - 2] = 0; + + if (_responseStatus.tag.length() == 0) + this->_responseStatus.tag = esp_mail_imap_tag_str; + + _customCmdResCallback(_responseStatus); + } + + // release memory + MailClient.freeMem(&buf); + } + + if (!_customCmdResCallback) + { +#if !defined(SILENT_MODE) + MailClient.printDebug(this, + esp_mail_cb_str_48 /* "IMAP server connected" */, + esp_mail_dbg_str_33 /* "IMAP server connected" */, + esp_mail_debug_tag_type_client, + true, + false); +#endif + } + + return true; +} + +void IMAPSession::debug(int level) +{ + if (level > esp_mail_debug_level_none) + { + if (level > esp_mail_debug_level_basic && level < esp_mail_debug_level_maintainer) + level = esp_mail_debug_level_basic; + _debugLevel = level; + _debug = true; + client.setDebugLevel(level); + } + else + { + _debugLevel = esp_mail_debug_level_none; + _debug = false; + client.setDebugLevel(0); + } +} + +String IMAPSession::errorReason() +{ + return MailClient.errorReason(false, _responseStatus.errorCode, _responseStatus.text.c_str()); +} + +int IMAPSession::errorCode() +{ + return _responseStatus.errorCode; +} + +bool IMAPSession::mSelectFolder(MB_StringPtr folderName, bool readOnly) +{ + if (connected()) + { + if (!openFolder(folderName, readOnly)) + return false; + } + else + { + _currentFolder = folderName; + } + + if (!connected()) + { + _responseStatus.errorCode = IMAP_STATUS_OPEN_MAILBOX_FAILED; + _responseStatus.clear(); + } + + return connected(); +} + +void IMAPSession::setTCPTimeout(unsigned long timeoutSec) +{ + tcpTimeout = timeoutSec; +} + +void IMAPSession::setClient(Client *client) +{ + this->client.setClient(client); +} + +void IMAPSession::setGSMClient(Client *client, void *modem, const char *pin, const char *apn, const char *user, const char *password) +{ + this->client.setGSMClient(client, modem, pin, apn, user, password); +} + +void IMAPSession::networkConnectionRequestCallback(NetworkConnectionRequestCallback networkConnectionCB) +{ + this->client.networkConnectionRequestCallback(networkConnectionCB); +} + +void IMAPSession::networkStatusRequestCallback(NetworkStatusRequestCallback networkStatusCB) +{ + this->client.networkStatusRequestCallback(networkStatusCB); +} + +void IMAPSession::setNetworkStatus(bool status) +{ + this->client.setNetworkStatus(status); + MailClient.networkStatus = status; +} + +void IMAPSession::setSSLBufferSize(int rx, int tx) +{ + this->client.setIOBufferSize(rx, tx); +} + +bool IMAPSession::mOpenFolder(MB_StringPtr folderName, bool readOnly) +{ + if (!connected()) + { + _responseStatus.errorCode = IMAP_STATUS_OPEN_MAILBOX_FAILED; + _responseStatus.clear(); + return false; + } + + if (readOnly) + return openMailbox(folderName, esp_mail_imap_auth_mode::esp_mail_imap_mode_examine, true, false); + else + return openMailbox(folderName, esp_mail_imap_auth_mode::esp_mail_imap_mode_select, true, false); +} + +bool IMAPSession::getFolders(FoldersCollection &folders) +{ + if (!connected()) + return false; + return getMailboxes(folders); +} + +bool IMAPSession::mCloseFolder(bool expunge) +{ + + // no folder opened + if (_currentFolder.length() == 0) + { +#if !defined(SILENT_MODE) + MailClient.printDebug(this, + esp_mail_error_imap_str_11 /* "no mailbox opened" */, + esp_mail_error_imap_str_11 /* "no mailbox opened" */, + esp_mail_debug_tag_type_client, + true, + false); +#endif + return false; + } + + return closeMailbox(expunge); +} + +bool IMAPSession::mListen(bool recon) +{ + if (!MailClient.sessionExisted(this)) + return false; + + if (_currentFolder.length() == 0) + { + _mbif._floderChangedState = false; + _mbif._folderChanged = false; + return false; + } + + if (!MailClient.reconnect(this)) + return false; + + if (!connected()) + { + if (!_imap_data || (millis() - _last_server_connect_ms < 2000 && _last_server_connect_ms > 0)) + return false; + + _last_server_connect_ms = millis(); + + bool ssl = false; + + if (!connect(ssl)) + { + MailClient.closeTCPSession(this); + return false; + } + + // re-authenticate after session closed + if (!MailClient.imapAuth(this, ssl)) + { + MailClient.closeTCPSession(this); + return false; + } + + // re-open folder + if (!selectFolder(_currentFolder.c_str())) + return false; + } + + // no IDLE was not supported (should be checked after imapAuth) + if (!_feature_capability[esp_mail_imap_read_capability_idle]) + { +#if !defined(SILENT_MODE) + printDebugNotSupported(); +#endif + } + + if (_mbif._idleTimeMs == 0) + { + _mbif._polling_status.messageNum = 0; + _mbif._polling_status.type = imap_polling_status_type_undefined; + _mbif._polling_status.argument.clear(); + _mbif._recentCount = 0; + _mbif._folderChanged = false; + +#if !defined(SILENT_MODE) + MB_String dbMsg; + + if (!recon) + { + + dbMsg = esp_mail_dbg_str_51; /* "listening to " */ + dbMsg += _currentFolder; + dbMsg += esp_mail_dbg_str_52; /* " folder changes" */ + MailClient.printDebug(this, + esp_mail_cb_str_29 /* "Listening to mailbox changes..." */, + dbMsg.c_str(), + esp_mail_debug_tag_type_client, + true, + false); + } + +#endif + + if (MailClient.imapSend(this, prependTag(imap_commands[esp_mail_imap_command_idle].text).c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return false; + + _imap_cmd = esp_mail_imap_cmd_idle; + if (!MailClient.handleIMAPResponse(this, IMAP_STATUS_BAD_COMMAND, false)) + return false; + +#if !defined(SILENT_MODE) + if (!recon) + { + + dbMsg = esp_mail_str_88 /* "polling established on " */; + dbMsg += MailClient.Time.getDateTimeString(MailClient.Time.getCurrentTimestamp(), "%B %d, %Y %H:%M:%S"); + MailClient.printDebug(this, + esp_mail_cb_str_49 /* "Polling established" */, + dbMsg.c_str(), + esp_mail_debug_tag_type_client, + true, + false); + } + +#endif + + _mbif._idleTimeMs = millis(); + } + else + { + if (_mbif._floderChangedState) + { + _mbif._floderChangedState = false; + _mbif._folderChanged = false; + _mbif._polling_status.messageNum = 0; + _mbif._polling_status.type = imap_polling_status_type_undefined; + _mbif._polling_status.argument.clear(); + _mbif._recentCount = 0; + } + + size_t imap_idle_tmo = _imap_data->limit.imap_idle_timeout; + + if (imap_idle_tmo < 60 * 1000 || imap_idle_tmo > 29 * 60 * 1000) + imap_idle_tmo = 10 * 60 * 1000; + + size_t host_check_interval = _imap_data->limit.imap_idle_host_check_interval; + + if (host_check_interval < 30 * 1000 || host_check_interval > imap_idle_tmo) + host_check_interval = 60 * 1000; + + if (millis() - _last_host_check_ms > host_check_interval && connected()) + { + _last_host_check_ms = millis(); + + IPAddress ip; + + if (client.hostByName(_session_cfg->server.host_name.c_str(), ip) != 1) + { + closeSession(); + _mbif._idleTimeMs = millis(); + return false; + } + } + + return MailClient.parseIdleResponse(this); + } + + return true; +} + +bool IMAPSession::mStopListen(bool recon) +{ + _mbif._idleTimeMs = 0; + _mbif._floderChangedState = false; + _mbif._folderChanged = false; + _mbif._polling_status.messageNum = 0; + _mbif._polling_status.type = imap_polling_status_type_undefined; + _mbif._polling_status.argument.clear(); + _mbif._recentCount = 0; + + if (!connected() || _currentFolder.length() == 0 || !_feature_capability[esp_mail_imap_read_capability_idle]) + return false; + + if (MailClient.imapSend(this, imap_commands[esp_mail_imap_command_done].text, true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return false; + + _imap_cmd = esp_mail_imap_cmd_done; + if (!MailClient.handleIMAPResponse(this, IMAP_STATUS_BAD_COMMAND, false)) + return false; + +#if !defined(SILENT_MODE) + if (!recon) + { + MailClient.printDebug(this, + esp_mail_cb_str_50 /* "Mailbox listening stopped" */, + esp_mail_dbg_str_54 /* "Mailbox listening stopped" */, + esp_mail_debug_tag_type_client, + true, + false); + } +#endif + + return true; +} + +bool IMAPSession::folderChanged() +{ + return _mbif._floderChangedState; +} + +bool IMAPSession::noop() +{ + +#if !defined(SILENT_MODE) + MailClient.printDebug(this, + esp_mail_cb_str_62 /* "Sending noop..." */, + esp_mail_dbg_str_83 /* "send IMAP command, NOOP" */, + esp_mail_debug_tag_type_client, + true, + false); +#endif + + if (MailClient.imapSend(this, prependTag(imap_commands[esp_mail_imap_command_noop].text).c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return false; + + _imap_cmd = esp_mail_imap_cmd_noop; + if (!MailClient.handleIMAPResponse(this, IMAP_STATUS_BAD_COMMAND, false)) + return false; + + return true; +} + +void IMAPSession::checkUID() +{ + if (MailClient.strcmpP(_imap_data->fetch.uid.c_str(), 0, imap_commands[esp_mail_imap_command_uid].text) || MailClient.strcmpP(_imap_data->fetch.uid.c_str(), 0, imap_commands[esp_mail_imap_command_flags].text) || + MailClient.strcmpP(_imap_data->fetch.uid.c_str(), 0, imap_commands[esp_mail_imap_command_body].text) || MailClient.strcmpP(_imap_data->fetch.uid.c_str(), 0, imap_commands[esp_mail_imap_command_peek].text) || MailClient.strcmpP(_imap_data->fetch.uid.c_str(), 0, imap_commands[esp_mail_imap_command_text].text) || + MailClient.strcmpP(_imap_data->fetch.uid.c_str(), 0, imap_commands[esp_mail_imap_command_header].text) || MailClient.strcmpP(_imap_data->fetch.uid.c_str(), 0, imap_commands[esp_mail_imap_command_fields].text) || MailClient.strcmpP(_imap_data->fetch.uid.c_str(), 0, esp_mail_str_40 /* "[" */) || + MailClient.strcmpP(_imap_data->fetch.uid.c_str(), 0, esp_mail_str_41 /* "]" */) || MailClient.strcmpP(_imap_data->fetch.uid.c_str(), 0, imap_commands[esp_mail_imap_command_mime].text)) + _imap_data->fetch.uid = esp_mail_str_3; /* "*" */ +} + +void IMAPSession::checkPath() +{ + MB_String path = _imap_data->storage.saved_path; + if (path[0] != '/') + { + path = '/'; + path += _imap_data->storage.saved_path; + path = path.c_str(); + } +} + +bool IMAPSession::headerOnly() +{ + return _headerOnly; +} + +struct esp_mail_imap_msg_list_t IMAPSession::data() +{ + struct esp_mail_imap_msg_list_t ret; + + for (size_t i = 0; i < _headers.size(); i++) + { + +#if defined(MB_ARDUINO_ESP) || defined(MB_ARDUINO_PICO) + if (MailClient.getFreeHeap() < ESP_MAIL_MIN_MEM) + continue; +#endif + struct esp_mail_imap_msg_item_t itm; + itm.setRFC822Headers(&_headers[i].header_fields); + itm.UID = _headers[i].message_uid; + itm.msgNo = _headers[i].message_no; + itm.flags = _headers[i].flags.c_str(); + itm.acceptLang = _headers[i].accept_language.c_str(); + itm.contentLang = _headers[i].content_language.c_str(); + itm.hasAttachment = _headers[i].hasAttachment; + itm.fetchError = _headers[i].error_msg.c_str(); + + getMessages(i, itm); + + getRFC822Messages(i, itm); + + ret.msgItems.push_back(itm); + } + + return ret; +} + +SelectedFolderInfo IMAPSession::selectedFolder() +{ + return _mbif; +} + +void IMAPSession::callback(imapStatusCallback imapCallback) +{ + _statusCallback = imapCallback; +} + +void IMAPSession::characterDecodingCallback(imapCharacterDecodingCallback callback) +{ + _charDecCallback = callback; +} + +void IMAPSession::mimeDataStreamCallback(MIMEDataStreamCallback mimeDataStreamCallback) +{ + _mimeDataStreamCallback = mimeDataStreamCallback; +} + +void IMAPSession::setSystemTime(time_t ts, float gmtOffset) +{ + MailClient.Time.setTimestamp(ts, gmtOffset); +} + +void IMAPSession::keepAlive(int tcpKeepIdleSeconds, int tcpKeepIntervalSeconds, int tcpKeepCount) +{ + this->client.keepAlive(tcpKeepIdleSeconds, tcpKeepIntervalSeconds, tcpKeepCount); +} + +bool IMAPSession::isKeepAlive() +{ + return this->client.isKeepAlive(); +} + +void IMAPSession::getMessages(uint16_t messageIndex, struct esp_mail_imap_msg_item_t &msg) +{ + msg.text.content = ""; + msg.text.charSet = ""; + msg.text.content_type = ""; + msg.text.transfer_encoding = ""; + msg.html.content = ""; + msg.html.charSet = ""; + msg.html.content_type = ""; + msg.html.transfer_encoding = ""; + + if (messageIndex < _headers.size()) + { + int sz = _headers[messageIndex].part_headers.size(); + if (sz > 0) + { + for (int i = 0; i < sz; i++) + { + if (_headers[messageIndex].part_headers[i].attach_type == esp_mail_att_type_attachment || (!_headers[messageIndex].part_headers[i].rfc822_part && _headers[messageIndex].part_headers[i].message_sub_type != esp_mail_imap_message_sub_type_rfc822)) + { + if (_headers[messageIndex].part_headers[i].attach_type == esp_mail_att_type_none) + { + if (_headers[messageIndex].part_headers[i].msg_type == esp_mail_msg_type_plain || _headers[messageIndex].part_headers[i].msg_type == esp_mail_msg_type_enriched) + { + msg.text.content = _headers[messageIndex].part_headers[i].text.c_str(); + msg.text.charSet = _headers[messageIndex].part_headers[i].charset.c_str(); + msg.text.content_type = _headers[messageIndex].part_headers[i].content_type.c_str(); + msg.text.transfer_encoding = _headers[messageIndex].part_headers[i].content_transfer_encoding.c_str(); + } + + if (_headers[messageIndex].part_headers[i].msg_type == esp_mail_msg_type_html) + { + msg.html.content = _headers[messageIndex].part_headers[i].text.c_str(); + msg.html.charSet = _headers[messageIndex].part_headers[i].charset.c_str(); + msg.html.content_type = _headers[messageIndex].part_headers[i].content_type.c_str(); + msg.html.transfer_encoding = _headers[messageIndex].part_headers[i].content_transfer_encoding.c_str(); + } + } + else + { + struct esp_mail_attachment_info_t att; + att.filename = _headers[messageIndex].part_headers[i].filename.c_str(); + att.mime = _headers[messageIndex].part_headers[i].content_type.c_str(); + att.name = _headers[messageIndex].part_headers[i].name.c_str(); + att.size = _headers[messageIndex].part_headers[i].attach_data_size; + att.description = _headers[messageIndex].part_headers[i].content_description.c_str(); + att.creationDate = _headers[messageIndex].part_headers[i].creation_date.c_str(); + att.type = _headers[messageIndex].part_headers[i].attach_type; + msg.attachments.push_back(att); + } + } + } + } + } +} + +void IMAPSession::getRFC822Messages(uint16_t messageIndex, struct esp_mail_imap_msg_item_t &msg) +{ + if (messageIndex < _headers.size()) + { + int size = _headers[messageIndex].part_headers.size(); + int partIdx = 0; + int cIdx = 0; + IMAP_MSG_Item *_rfc822 = nullptr; + if (size > 0) + { + for (int i = 0; i < size; i++) + { + if (_headers[messageIndex].part_headers[i].message_sub_type == esp_mail_imap_message_sub_type_rfc822 && _headers[messageIndex].part_headers[i].attach_type != esp_mail_att_type_attachment) + { + if (_headers[messageIndex].part_headers[i].rfc822_part) + { + if (partIdx > 0) + msg.rfc822.push_back(*_rfc822); + cIdx = i; + partIdx++; + _rfc822 = new IMAP_MSG_Item(); + _rfc822->setRFC822Headers(&_headers[messageIndex].part_headers[i].rfc822_header); + } + else + { + if (MailClient.multipartMember(_headers[messageIndex].part_headers[cIdx].partNumStr, _headers[messageIndex].part_headers[i].partNumStr)) + { + if (_headers[messageIndex].part_headers[i].attach_type == esp_mail_att_type_none) + { + if (_headers[messageIndex].part_headers[i].msg_type == esp_mail_msg_type_plain || _headers[messageIndex].part_headers[i].msg_type == esp_mail_msg_type_enriched) + { + _rfc822->text.charSet = _headers[messageIndex].part_headers[i].charset.c_str(); + _rfc822->text.content_type = _headers[messageIndex].part_headers[i].content_type.c_str(); + _rfc822->text.content = _headers[messageIndex].part_headers[i].text.c_str(); + _rfc822->text.transfer_encoding = _headers[messageIndex].part_headers[i].content_transfer_encoding.c_str(); + } + if (_headers[messageIndex].part_headers[i].msg_type == esp_mail_msg_type_html) + { + _rfc822->html.charSet = _headers[messageIndex].part_headers[i].charset.c_str(); + _rfc822->html.content_type = _headers[messageIndex].part_headers[i].content_type.c_str(); + _rfc822->html.content = _headers[messageIndex].part_headers[i].text.c_str(); + _rfc822->html.transfer_encoding = _headers[messageIndex].part_headers[i].content_transfer_encoding.c_str(); + } + } + else + { + struct esp_mail_attachment_info_t att; + att.filename = _headers[messageIndex].part_headers[i].filename.c_str(); + att.mime = _headers[messageIndex].part_headers[i].content_type.c_str(); + att.name = _headers[messageIndex].part_headers[i].name.c_str(); + att.size = _headers[messageIndex].part_headers[i].attach_data_size; + att.description = _headers[messageIndex].part_headers[i].content_description.c_str(); + att.creationDate = _headers[messageIndex].part_headers[i].creation_date.c_str(); + att.type = _headers[messageIndex].part_headers[i].attach_type; + _rfc822->attachments.push_back(att); + } + } + } + } + } + + if ((int)msg.rfc822.size() < partIdx && _rfc822 != nullptr) + msg.rfc822.push_back(*_rfc822); + } + } +} + +bool IMAPSession::closeMailbox(bool expunge) +{ +#if !defined(SILENT_MODE) + MB_String dbMsg = esp_mail_dbg_str_32; /* "closing the " */ + dbMsg += _currentFolder; + dbMsg += esp_mail_str_89; /* " folder..." */ + + MailClient.printDebug(this, + esp_mail_cb_str_27 /* "Closing the mailbox folder..." */, + dbMsg.c_str(), + esp_mail_debug_tag_type_client, + true, + false); +#endif + if (!MailClient.reconnect(this)) + return false; + + // If folder was opened in readonly mode, use CLOSE command will not expunge the deleted messages + // Or user intent to expunge the deleted message after close the folder. + if (expunge || _readOnlyMode) + { + + if (MailClient.imapSend(this, prependTag(imap_commands[esp_mail_imap_command_close].text).c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return false; + + _imap_cmd = esp_mail_imap_cmd_close; + if (!MailClient.handleIMAPResponse(this, IMAP_STATUS_CLOSE_MAILBOX_FAILED, false)) + return false; + } + else + { + // Close folder without expunge + if (_feature_capability[esp_mail_imap_read_capability_unselect]) + { + if (MailClient.imapSend(this, prependTag(imap_commands[esp_mail_imap_command_unselect].text).c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return false; + + _imap_cmd = esp_mail_imap_cmd_unselect; + if (!MailClient.handleIMAPResponse(this, IMAP_STATUS_CLOSE_MAILBOX_FAILED, false)) + return false; + } + else + { + // Open non-existing folder + MB_String folder = esp_mail_str_84 /* "message" */; + folder += MailClient.Time.getCurrentTimestamp(); + MB_StringPtr folderPtr; + folderPtr = toStringPtr(folder); + openMailbox(folderPtr, esp_mail_imap_auth_mode::esp_mail_imap_mode_examine, true, true); + } + } + + _currentFolder.clear(); + _mailboxOpened = false; + + return true; +} + +bool IMAPSession::openMailbox(MB_StringPtr folder, esp_mail_imap_auth_mode mode, bool waitResponse, bool unselect) +{ + + if (!MailClient.sessionExisted(this)) + return false; + + MB_String _folder = folder; + + if (!MailClient.reconnect(this)) + return false; + + if (_folder.length() == 0) + return false; + + bool _dbg = _debug; + imapStatusCallback _cb = _statusCallback; + + // The SELECT/EXAMINE command automatically deselects any currently selected mailbox + // before attempting the new selection (RFC3501 p.33) + + // folder should not close for re-selection otherwise the server returned * BAD Command Argument Error. 12 + + if (!unselect) + { + + bool sameFolder = strcmp(_currentFolder.c_str(), _folder.c_str()) == 0; + + // guards 3 seconds to prevent accidently frequently select the same folder with the same mode + if (!_mailboxOpened && sameFolder && millis() - _lastSameFolderOpenMillis < 3000) + { + if ((_readOnlyMode && mode == esp_mail_imap_mode_examine) || (!_readOnlyMode && mode == esp_mail_imap_mode_select)) + return true; + } + + if (!sameFolder) + _currentFolder = folder; + +#if !defined(SILENT_MODE) + MB_String dbMsg = esp_mail_dbg_str_68; /* "selecting the " */ + dbMsg += _currentFolder; + dbMsg += esp_mail_str_89; /* " folder..." */ + + MailClient.printDebug(this, + esp_mail_cb_str_51 /* "Open the mailbox folder..." */, + dbMsg.c_str(), + esp_mail_debug_tag_type_client, + true, + false); +#endif + } + else + { + // Hide the callback and debug info + _debug = false; + _statusCallback = NULL; + _currentFolder = folder; + } + + MB_String cmd; + MailClient.appendSpace(cmd, true, mode == esp_mail_imap_mode_examine ? imap_commands[esp_mail_imap_command_examine].text : imap_commands[esp_mail_imap_command_select].text); + MailClient.appendString(cmd, _currentFolder.c_str(), false, false, esp_mail_string_mark_type_double_quote); + + if (isCondStoreSupported()) + { + MailClient.appendSpace(cmd); + MailClient.appendString(cmd, imap_commands[esp_mail_imap_command_condstore].text, false, false, esp_mail_string_mark_type_round_bracket); + } + + _imap_cmd = mode == esp_mail_imap_mode_examine ? esp_mail_imap_cmd_examine : esp_mail_imap_cmd_select; + + if (MailClient.imapSend(this, cmd.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return false; + + if (!unselect) + _lastSameFolderOpenMillis = millis(); + + if (waitResponse && !MailClient.handleIMAPResponse(this, IMAP_STATUS_OPEN_MAILBOX_FAILED, false)) + { + if (!unselect) + return false; + } + + if (unselect) + { + _statusCallback = _cb; + _debug = _dbg; + } + + if (mode == esp_mail_imap_mode_examine) + _readOnlyMode = true; + else if (mode == esp_mail_imap_mode_select) + _readOnlyMode = false; + + _mailboxOpened = !unselect; + + return true; +} + +bool IMAPSession::getMailboxes(FoldersCollection &folders) +{ +#if !defined(SILENT_MODE) + MailClient.printDebug(this, + esp_mail_cb_str_16 /* "Reading the list of mailboxes..." */, + esp_mail_dbg_str_35 /* "send IMAP command, LIST" */, + esp_mail_debug_tag_type_client, + true, + false); +#endif + _folders.clear(); + + MB_String cmd; + MailClient.appendSpace(cmd, true, imap_commands[esp_mail_imap_command_list].text); + MailClient.appendString(cmd, NULL, false, false, esp_mail_string_mark_type_double_quote); + MailClient.prependSpace(cmd, esp_mail_str_3 /* "*" */); + + if (MailClient.imapSend(this, cmd.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return false; + + _imap_cmd = esp_mail_imap_cmd_list; + if (!MailClient.handleIMAPResponse(this, IMAP_STATUS_LIST_MAILBOXS_FAILED, false)) + return false; + + folders = _folders; + return true; +} + +bool IMAPSession::mGetSubscribesMailboxes(MB_StringPtr reference, MB_StringPtr mailbox, FoldersCollection &folders) +{ +#if !defined(SILENT_MODE) + MailClient.printDebug(this, + esp_mail_cb_str_30 /* "Listing the subscribed mailboxes..." */, + esp_mail_dbg_str_56 /* "send IMAP command, LSUB" */, + esp_mail_debug_tag_type_client, + true, + false); +#endif + folders.clear(); + + MB_String cmd; + MailClient.appendSpace(cmd, true, imap_commands[esp_mail_imap_command_lsub].text); + MailClient.appendString(cmd, MB_String(reference).c_str(), false, false, esp_mail_string_mark_type_double_quote); + MailClient.appendSpace(cmd); + MailClient.appendString(cmd, MB_String(mailbox).c_str(), false, false, esp_mail_string_mark_type_double_quote); + + if (MailClient.imapSend(this, cmd.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return false; + + FoldersCollection tmp; + + for (size_t i = 0; i < this->_folders.size(); i++) + tmp.add(this->_folders[i]); + + this->_folders.clear(); + + _imap_cmd = esp_mail_imap_cmd_lsub; + if (!MailClient.handleIMAPResponse(this, IMAP_STATUS_LIST_MAILBOXS_FAILED, false)) + return false; + + for (size_t i = 0; i < this->_folders.size(); i++) + folders.add(this->_folders[i]); + + this->_folders.clear(); + + for (size_t i = 0; i < tmp.size(); i++) + this->_folders.add(tmp[i]); + + tmp.clear(); + + return true; +} + +bool IMAPSession::mSubscribe(MB_StringPtr folder) +{ +#if !defined(SILENT_MODE) + MailClient.printDebug(this, + esp_mail_cb_str_31 /* "Subscribe mailbox..." */, + esp_mail_dbg_str_57 /* "send IMAP command, SUBSCRIBE" */, + esp_mail_debug_tag_type_client, + true, + false); +#endif + MB_String cmd; + MailClient.appendSpace(cmd, true, imap_commands[esp_mail_imap_command_subscribe].text); + MailClient.appendString(cmd, MB_String(folder).c_str(), false, false, esp_mail_string_mark_type_double_quote); + + if (MailClient.imapSend(this, cmd.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return false; + + _imap_cmd = esp_mail_imap_cmd_subscribe; + if (!MailClient.handleIMAPResponse(this, IMAP_STATUS_LIST_MAILBOXS_FAILED, false)) + return false; + + return true; +} + +bool IMAPSession::mUnSubscribe(MB_StringPtr folder) +{ +#if !defined(SILENT_MODE) + MailClient.printDebug(this, + esp_mail_cb_str_32 /* "Unsubscribe mailbox..." */, + esp_mail_dbg_str_58 /* "send IMAP command, UNSUBSCRIBE" */, + esp_mail_debug_tag_type_client, + true, + false); +#endif + MB_String cmd; + MailClient.appendSpace(cmd, true, imap_commands[esp_mail_imap_command_unsubscribe].text); + MailClient.appendString(cmd, MB_String(folder).c_str(), false, false, esp_mail_string_mark_type_double_quote); + + if (MailClient.imapSend(this, cmd.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return false; + + _imap_cmd = esp_mail_imap_cmd_unsubscribe; + if (!MailClient.handleIMAPResponse(this, IMAP_STATUS_LIST_MAILBOXS_FAILED, false)) + return false; + + return true; +} + +bool IMAPSession::mFetchSequenceSet() +{ + + MB_String cmd; + if (_imap_data->fetch.sequence_set.UID) + MailClient.appendSpace(cmd, true, 2, imap_commands[esp_mail_imap_command_uid].text, imap_commands[esp_mail_imap_command_fetch].text); + else + MailClient.appendSpace(cmd, true, imap_commands[esp_mail_imap_command_fetch].text); + + MailClient.appendSpace(cmd, false, _imap_data->fetch.sequence_set.string.c_str()); + MailClient.appendString(cmd, imap_commands[esp_mail_imap_command_uid].text, false, false, esp_mail_string_mark_type_round_bracket); + + addModifier(cmd, esp_mail_imap_command_changedsince, _imap_data->fetch.modsequence); + + if (MailClient.imapSend(this, cmd.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return false; + + _imap_msg_num.clear(); + + _imap_cmd = esp_mail_imap_cmd_fetch_sequence_set; + if (!MailClient.handleIMAPResponse(this, IMAP_STATUS_LIST_MAILBOXS_FAILED, false)) + return false; + + return true; +} + +MB_String IMAPSession::prependTag(PGM_P cmd, PGM_P tag) +{ + MB_String s = (tag == NULL) ? esp_mail_imap_tag_str : tag; + MailClient.appendSpace(s); + s += cmd; + return s; +} + +bool IMAPSession::checkCapabilities() +{ +#if !defined(SILENT_MODE) + MailClient.printDebug(this, + esp_mail_cb_str_52 /* "Checking the capability..." */, + esp_mail_dbg_str_76 /* "check the capability" */, + esp_mail_debug_tag_type_client, + true, + false); +#endif + if (MailClient.imapSend(this, prependTag(imap_commands[esp_mail_imap_command_capability].text).c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return false; + + _imap_cmd = esp_mail_imap_cmd_capability; + if (!MailClient.handleIMAPResponse(this, IMAP_STATUS_CHECK_CAPABILITIES_FAILED, false)) + return false; + + return true; +} + +bool IMAPSession::mCreateFolder(MB_StringPtr folderName) +{ +#if !defined(SILENT_MODE) + MailClient.printDebug(this, + esp_mail_cb_str_59 /* "Creating folder..." */, + esp_mail_dbg_str_49 /* "creating folder" */, + esp_mail_debug_tag_type_client, + true, + false); +#endif + MB_String cmd; + MailClient.joinStringSpace(cmd, true, 2, imap_commands[esp_mail_imap_command_create].text, folderName); + + if (MailClient.imapSend(this, cmd.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return false; + + _imap_cmd = esp_mail_imap_cmd_create; + if (!MailClient.handleIMAPResponse(this, IMAP_STATUS_BAD_COMMAND, false)) + return false; + + return true; +} + +bool IMAPSession::mRenameFolder(MB_StringPtr currentFolderName, MB_StringPtr newFolderName) +{ +#if !defined(SILENT_MODE) + MailClient.printDebug(this, + esp_mail_cb_str_53 /* "Renaming folder..." */, + esp_mail_dbg_str_55 /* "renaming folder" */, + esp_mail_debug_tag_type_client, + true, + false); +#endif + MB_String o = currentFolderName; + MB_String n = newFolderName; + + o.trim(); + n.trim(); + + if (o == n) + return true; + + if (o.length() == 0 || n.length() == 0) + return false; + + MB_String cmd; + MailClient.appendSpace(cmd, true, imap_commands[esp_mail_imap_command_rename].text); + MailClient.appendString(cmd, o.c_str(), false, false, esp_mail_string_mark_type_double_quote); + MailClient.appendSpace(cmd); + MailClient.appendString(cmd, n.c_str(), false, false, esp_mail_string_mark_type_double_quote); + + if (MailClient.imapSend(this, cmd.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return false; + + _imap_cmd = esp_mail_imap_cmd_rename; + if (!MailClient.handleIMAPResponse(this, IMAP_STATUS_BAD_COMMAND, false)) + return false; + + if (_currentFolder == o) + selectFolder(n.c_str(), false); + + return true; +} + +int IMAPSession::getUID(int msgNum) +{ +#if !defined(SILENT_MODE) + MailClient.printDebug(this, + esp_mail_cb_str_25 /* "Get UID..." */, + esp_mail_dbg_str_79 /* "get UID" */, + esp_mail_debug_tag_type_client, + true, + false); +#endif + int uid = mGetUID(msgNum); + + if (!MailClient.sessionExisted(this)) + return false; + +#if !defined(SILENT_MODE) + MB_String dbMsg = esp_mail_cb_str_54; /* "UID is " */ + dbMsg += uid; + + MailClient.printDebug(this, + dbMsg.c_str(), + dbMsg.c_str(), + esp_mail_debug_tag_type_client, + true, + false); +#endif + return uid; +} + +int IMAPSession::mGetUID(int msgNum) +{ + + if (_currentFolder.length() == 0) + return 0; + + MB_String cmd; + MailClient.joinStringSpace(cmd, true, 3, imap_commands[esp_mail_imap_command_fetch].text, MB_String(msgNum).c_str(), imap_commands[esp_mail_imap_command_uid].text); + + if (MailClient.imapSend(this, cmd.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return 0; + + _imap_cmd = esp_mail_imap_cmd_get_uid; + if (!MailClient.handleIMAPResponse(this, IMAP_STATUS_BAD_COMMAND, false)) + return 0; + + return _uid_tmp; +} + +const char *IMAPSession::getFlags(int msgNum) +{ +#if !defined(SILENT_MODE) + MailClient.printDebug(this, + esp_mail_cb_str_55 /* "Get Flags..." */, + esp_mail_dbg_str_80 /* "get flags" */, + esp_mail_debug_tag_type_client, + true, + false); +#endif + + _flags_tmp.clear(); + if (_currentFolder.length() == 0) + return _flags_tmp.c_str(); + + MB_String cmd, cmd2; + MailClient.appendSpace(cmd, true, imap_commands[esp_mail_imap_command_fetch].text); + MailClient.appendString(cmd2, imap_commands[esp_mail_imap_command_flags].text, false, false, esp_mail_string_mark_type_round_bracket); + MailClient.joinStringSpace(cmd, false, 2, MB_String(msgNum).c_str(), cmd2.c_str()); + + if (MailClient.imapSend(this, cmd.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return _flags_tmp.c_str(); + + _imap_cmd = esp_mail_imap_cmd_get_flags; + MailClient.handleIMAPResponse(this, IMAP_STATUS_BAD_COMMAND, false); + + return _flags_tmp.c_str(); +} + +bool IMAPSession::mSendCustomCommand(MB_StringPtr cmd, imapResponseCallback callback, MB_StringPtr tag) +{ + + _customCmdResCallback = callback; + _cmd = cmd; + _cmd.trim(); + + MB_String _tag = cmd; + _tag.trim(); + + MB_String _tag2 = tag; + _tag2.trim(); + + if (_tag2.length() == 0) + { + int p = MailClient.strpos(_tag.c_str(), " ", 0); + if (p > -1) + { + _tag.erase(p, _tag.length() - p); + _tag.trim(); + _responseStatus.tag = _tag; + } + } + else + { + _responseStatus.tag = tag; + _responseStatus.tag.trim(); + if (MailClient.strpos(_cmd.c_str(), _responseStatus.tag.c_str(), 0, false) == -1) + _cmd = prependTag(_cmd.c_str(), _responseStatus.tag.c_str()); + } + + // filter for specific command + if (_cmd.find(imap_cmd_pre_tokens[esp_mail_imap_command_idle].c_str()) != MB_String::npos) + _imap_custom_cmd = esp_mail_imap_cmd_idle; + else if (_cmd.find(imap_cmd_pre_tokens[esp_mail_imap_command_append].c_str()) != MB_String::npos) + _imap_custom_cmd = esp_mail_imap_cmd_append; + else if (_cmd.find(imap_cmd_pre_tokens[esp_mail_imap_command_login].c_str()) != MB_String::npos) + _imap_custom_cmd = esp_mail_imap_cmd_sasl_login; + else if (_cmd.find(imap_cmd_pre_tokens[esp_mail_imap_command_logout].c_str()) != MB_String::npos) + _imap_custom_cmd = esp_mail_imap_cmd_logout; + else + _imap_custom_cmd = esp_mail_imap_cmd_custom; + + if (_prev_imap_custom_cmd != _imap_custom_cmd || _imap_custom_cmd != esp_mail_imap_cmd_idle) + { + if (MailClient.imapSend(this, _cmd.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + { + _prev_imap_custom_cmd = esp_mail_imap_cmd_custom; + return false; + } + } + + _imap_cmd = esp_mail_imap_cmd_custom; + + if (!MailClient.handleIMAPResponse(this, IMAP_STATUS_BAD_COMMAND, false)) + { + _prev_imap_custom_cmd = esp_mail_imap_cmd_custom; + return false; + } + + if (_imap_custom_cmd == esp_mail_imap_cmd_sasl_login) + { + _authenticated = true; + _loginStatus = true; + } + else if (_imap_custom_cmd == esp_mail_imap_cmd_logout) + { + _authenticated = false; + _loginStatus = false; + } + + _prev_imap_custom_cmd = _imap_custom_cmd; + + if (MailClient.strposP(_cmd.c_str(), imap_auth_capabilities[esp_mail_auth_capability_starttls].text, 0, false) == 0) + { + bool verify = false; + + if (_session_cfg) + verify = _session_cfg->certificate.verify; + + if (!client.connectSSL(verify)) + return false; + + // set the secure mode + if (_session_cfg) + { + // We reset the prefer connection mode in case user set it. + _session_cfg->secure.startTLS = false; + _session_cfg->secure.mode = esp_mail_secure_mode_undefined; + } + + _secure = true; + } + + return true; +} + +bool IMAPSession::mSendData(MB_StringPtr data, bool lastData, esp_mail_imap_command cmd) +{ + MB_String _data = data; + if (MailClient.imapSend(this, _data.c_str(), lastData) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return false; + + if (lastData) + { + _imap_cmd = cmd; + _cmd.clear(); + + if (!MailClient.handleIMAPResponse(this, IMAP_STATUS_BAD_COMMAND, false)) + return false; + } + + return true; +} + +bool IMAPSession::mSendData(uint8_t *data, size_t size, bool lastData, esp_mail_imap_command cmd) +{ + + if (MailClient.imapSend(this, data, size) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return false; + + if (lastData) + { + if (MailClient.imapSend(this, pgm2Str(esp_mail_str_42 /* "\r\n" */), false) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return false; + + _imap_cmd = cmd; + _cmd.clear(); + + if (!MailClient.handleIMAPResponse(this, IMAP_STATUS_BAD_COMMAND, false)) + return false; + } + + return true; +} + +bool IMAPSession::mDeleteFolder(MB_StringPtr folderName) +{ +#if !defined(SILENT_MODE) + MailClient.printDebug(this, + esp_mail_cb_str_56 /* "Deleting folder..." */, + esp_mail_dbg_str_81 /* "delete folder" */, + esp_mail_debug_tag_type_client, + true, + false); +#endif + MB_String cmd; + MailClient.joinStringSpace(cmd, true, 2, imap_commands[esp_mail_imap_command_delete].text, MB_String(folderName).c_str()); + + if (MailClient.imapSend(this, cmd.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return false; + + _imap_cmd = esp_mail_imap_cmd_delete; + if (!MailClient.handleIMAPResponse(this, IMAP_STATUS_BAD_COMMAND, false)) + return false; + + return true; +} + +bool IMAPSession::isCondStoreSupported() +{ + return _feature_capability[esp_mail_imap_read_capability_condstore]; +} + +bool IMAPSession::isModseqSupported() +{ + return isCondStoreSupported() && !_mbif._nomodsec; +} + +void IMAPSession::addModifier(MB_String &cmd, esp_mail_imap_command_types type, int32_t modsequence) +{ + if (modsequence > -1 && isModseqSupported()) + { + MB_String modifier; + MailClient.joinStringSpace(modifier, false, 2, imap_commands[type].text, MB_String(modsequence).c_str()); + MailClient.appendSpace(cmd); + MailClient.appendString(cmd, modifier.c_str(), false, false, esp_mail_string_mark_type_round_bracket); + } +} + +bool IMAPSession::deleteMsg(MessageList *toDelete, const char *sequenceSet, bool UID, bool expunge, int32_t modsequence) +{ + if ((toDelete && toDelete->_list.size() == 0) || (!toDelete && strlen(sequenceSet) == 0)) + return false; + + if (!selectFolder(_currentFolder.c_str(), false)) + return false; + +#if !defined(SILENT_MODE) + MailClient.printDebug(this, + esp_mail_cb_str_57 /* "Deleting message(s)..." */, + esp_mail_dbg_str_75 /* "delete message(s)" */, + esp_mail_debug_tag_type_client, + true, + false); +#endif + + if (!MailClient.sessionExisted(this)) + return false; + + MB_String cmd; + if (UID || toDelete) + { + MailClient.appendSpace(cmd, true, 2, imap_commands[esp_mail_imap_command_uid].text, imap_commands[esp_mail_imap_command_store].text); + + if (toDelete && toDelete->_list.size() > 0) + MailClient.appendList(cmd, toDelete->_list); + } + else if (!toDelete && strlen(sequenceSet) > 0) + MailClient.appendSpace(cmd, true, imap_commands[esp_mail_imap_command_store].text); + + if (!toDelete && strlen(sequenceSet) > 0) + cmd += sequenceSet; + + addModifier(cmd, esp_mail_imap_command_unchangedsince, modsequence); + + cmd += imap_cmd_pre_tokens[esp_mail_imap_command_plus_flags]; + MailClient.prependDot(cmd, imap_commands[esp_mail_imap_command_silent].text); + MailClient.appendSpace(cmd); + MailClient.appendString(cmd, esp_mail_str_91 /* "\\Deleted" */, false, false, esp_mail_string_mark_type_round_bracket); + + if (MailClient.imapSend(this, cmd.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return false; + + _imap_cmd = esp_mail_imap_cmd_store; + if (!MailClient.handleIMAPResponse(this, IMAP_STATUS_BAD_COMMAND, false)) + return false; + + if (expunge) + { + if (MailClient.imapSend(this, prependTag(imap_commands[esp_mail_imap_command_expunge].text).c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return false; + + _imap_cmd = esp_mail_imap_cmd_expunge; + if (!MailClient.handleIMAPResponse(this, IMAP_STATUS_BAD_COMMAND, false)) + return false; + } + + return true; +} + +bool IMAPSession::mDeleteMessages(MessageList *toDelete, bool expunge, int32_t modsequence) +{ + if (toDelete->_list.size() > 0) + return deleteMsg(toDelete, "", false, expunge); + return true; +} + +bool IMAPSession::mDeleteMessagesSet(MB_StringPtr sequenceSet, bool UID, bool expunge, int32_t modsequence) +{ + return deleteMsg(nullptr, MB_String(sequenceSet).c_str(), UID, expunge); +} + +bool IMAPSession::copyMsg(MessageList *toCopy, const char *sequenceSet, bool UID, MB_StringPtr dest) +{ +#if !defined(SILENT_MODE) + MB_String dbMsg = esp_mail_dbg_str_48; /* "copying message(s) to " */ + dbMsg += dest; + + MailClient.printDebug(this, + esp_mail_cb_str_58 /* "Copying message(s)..." */, + dbMsg.c_str(), + esp_mail_debug_tag_type_client, + true, + false); +#endif + + if (!MailClient.sessionExisted(this)) + return false; + + if ((toCopy && toCopy->_list.size() == 0) || (!toCopy && strlen(sequenceSet) == 0)) + return false; + + if (!selectFolder(_currentFolder.c_str(), false)) + return false; + + MB_String cmd; + if (UID || toCopy) + { + MailClient.appendSpace(cmd, true, 2, imap_commands[esp_mail_imap_command_uid].text, imap_commands[esp_mail_imap_command_copy].text); + + if (toCopy && toCopy->_list.size() > 0) + MailClient.appendList(cmd, toCopy->_list); + } + else if (!toCopy && strlen(sequenceSet) > 0) + MailClient.appendSpace(cmd, true, imap_commands[esp_mail_imap_command_copy].text); + + if (!toCopy && strlen(sequenceSet) > 0) + cmd += sequenceSet; + + MailClient.prependSpace(cmd, MB_String(dest).c_str()); + + if (MailClient.imapSend(this, cmd.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return false; + + _imap_cmd = esp_mail_imap_cmd_copy; + if (!MailClient.handleIMAPResponse(this, IMAP_STATUS_BAD_COMMAND, false)) + return false; + + return true; +} + +bool IMAPSession::mCopyMessages(MessageList *toCopy, MB_StringPtr dest) +{ + return copyMsg(toCopy, "", false, dest); +} + +bool IMAPSession::mCopyMessagesSet(MB_StringPtr sequenceSet, bool UID, MB_StringPtr dest) +{ + return copyMsg(nullptr, MB_String(sequenceSet).c_str(), UID, dest); +} + +bool IMAPSession::moveMsg(MessageList *toMove, const char *sequenceSet, bool UID, MB_StringPtr dest) +{ +#if !defined(SILENT_MODE) + MB_String dbMsg = esp_mail_dbg_str_59; /* "moving message(s) to " */ + dbMsg += dest; + + MailClient.printDebug(this, + esp_mail_cb_str_60 /* "Moving message(s)..." */, + dbMsg.c_str(), + esp_mail_debug_tag_type_client, + true, + false); +#endif + + if (!MailClient.sessionExisted(this)) + return false; + + if ((toMove && toMove->_list.size() == 0) || (!toMove && strlen(sequenceSet) == 0)) + return false; + + if (!_feature_capability[esp_mail_imap_read_capability_move]) + { + + bool ret = mCopyMessages(toMove, dest); + + if (ret) + ret = mDeleteMessages(toMove, true); + + return ret; + } + + if (!selectFolder(_currentFolder.c_str(), false)) + return false; + + MB_String cmd; + if (UID || toMove) + { + MailClient.appendSpace(cmd, true, 2, imap_commands[esp_mail_imap_command_uid].text, imap_commands[esp_mail_imap_command_move].text); + if (toMove && toMove->_list.size() > 0) + MailClient.appendList(cmd, toMove->_list); + } + else if (!toMove && strlen(sequenceSet) > 0) + MailClient.appendSpace(cmd, true, imap_commands[esp_mail_imap_command_move].text); + + if (!toMove && strlen(sequenceSet) > 0) + cmd += sequenceSet; + + MailClient.prependSpace(cmd, MB_String(dest).c_str()); + + if (MailClient.imapSend(this, cmd.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return false; + + _imap_cmd = esp_mail_imap_cmd_move; + if (!MailClient.handleIMAPResponse(this, IMAP_STATUS_BAD_COMMAND, false)) + return false; + + return true; +} + +bool IMAPSession::mMoveMessages(MessageList *toMove, MB_StringPtr dest) +{ + return moveMsg(toMove, "", false, dest); +} + +bool IMAPSession::mMoveMessagesSet(MB_StringPtr sequenceSet, bool UID, MB_StringPtr dest) +{ + return moveMsg(nullptr, MB_String(sequenceSet).c_str(), UID, dest); +} + +bool IMAPSession::mGetSetQuota(MB_StringPtr quotaRoot, IMAP_Quota_Root_Info *data, bool getMode) +{ + +#if !defined(SILENT_MODE) + PGM_P p1 = getMode ? esp_mail_cb_str_33 /* "Get quota root resource usage and limit..." */ : esp_mail_cb_str_34 /* "Set quota root resource usage and limit..." */; + PGM_P p2 = getMode ? esp_mail_dbg_str_60 /* "send IMAP command, GETQUOTA" */ : esp_mail_dbg_str_61 /* "send IMAP command, SETQUOTA" */; + MailClient.printDebug(this, p1, p2, esp_mail_debug_tag_type_client, true, false); +#endif + + if (!_feature_capability[esp_mail_imap_read_capability_quota]) + { +#if !defined(SILENT_MODE) + printDebugNotSupported(); +#endif + return false; + } + + MB_String _quotaRoot = quotaRoot; + + MB_String cmd; + if (getMode) + { + MailClient.appendSpace(cmd, true, imap_commands[esp_mail_imap_command_getquota].text); + MailClient.appendString(cmd, _quotaRoot.c_str(), false, false, esp_mail_string_mark_type_double_quote); + } + else + { + MailClient.appendSpace(cmd, true, imap_commands[esp_mail_imap_command_setquota].text); + MailClient.appendString(cmd, _quotaRoot.c_str(), false, false, esp_mail_string_mark_type_double_quote); + MailClient.appendSpace(cmd); + + MB_String cmd2; + MailClient.joinStringSpace(cmd2, false, 2, data->name.c_str(), MB_String((int)data->limit).c_str()); + MailClient.appendString(cmd, cmd2.c_str(), false, false, esp_mail_string_mark_type_round_bracket); + } + + if (MailClient.imapSend(this, cmd.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return false; + + _quota_tmp.clear(); + + _imap_cmd = (getMode) ? esp_mail_imap_cmd_get_quota : esp_mail_imap_cmd_set_quota; + if (!MailClient.handleIMAPResponse(this, IMAP_STATUS_BAD_COMMAND, false)) + return false; + + if (getMode) + { + mParseQuota(_quota_tmp.c_str(), data); + } + + _quota_tmp.clear(); + + return true; +} + +void IMAPSession::mParseQuota(const char *quota, IMAP_Quota_Root_Info *data) +{ + _vectorImpl tokens; + MailClient.splitToken(quota, tokens, " "); + data->quota_root = tokens[0]; + tokens[1].erase(0, 1); + data->name = tokens[1]; + data->usage = atoi(tokens[2].c_str()); + data->limit = atoi(tokens[3].c_str()); +} + +bool IMAPSession::mGetQuotaRoots(MB_StringPtr mailbox, IMAP_Quota_Roots_List *quotaRootsList) +{ +#if !defined(SILENT_MODE) + MailClient.printDebug(this, + esp_mail_cb_str_35 /* "Get the list of quota roots..." */, + esp_mail_dbg_str_62 /* "send IMAP command, GETQUOTAROOT" */, + esp_mail_debug_tag_type_client, + true, + false); +#endif + + if (!MailClient.sessionExisted(this)) + return false; + + if (!_feature_capability[esp_mail_imap_read_capability_quota]) + { +#if !defined(SILENT_MODE) + printDebugNotSupported(); +#endif + return false; + } + + MB_String _mailbox = mailbox; + + MB_String cmd; + MailClient.appendSpace(cmd, true, 2, imap_commands[esp_mail_imap_command_getquota].text, imap_commands[esp_mail_imap_command_root].text); + MailClient.appendString(cmd, _mailbox.c_str(), false, false, esp_mail_string_mark_type_double_quote); + + if (MailClient.imapSend(this, cmd.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return false; + + _quota_root_tmp.clear(); + _quota_tmp.clear(); + + _imap_cmd = esp_mail_imap_cmd_get_quota_root; + if (!MailClient.handleIMAPResponse(this, IMAP_STATUS_BAD_COMMAND, false)) + return false; + + _vectorImpl tokens; + MailClient.splitToken(_quota_root_tmp.c_str(), tokens, ","); + + for (size_t i = 0; i < tokens.size(); i++) + { + _vectorImpl tk; + MailClient.splitToken(tokens[i].c_str(), tk, ":"); + IMAP_Quota_Root_Info data; + if (tk.size() > 1) + mParseQuota(tk[1].c_str(), &data); + else + data.quota_root = tk[0]; + + quotaRootsList->add(data); + } + + _quota_root_tmp.clear(); + _quota_tmp.clear(); + + return true; +} + +bool IMAPSession::mManageACL(MB_StringPtr mailbox, IMAP_Rights_List *acl_list, IMAP_Rights_Info *acl, MB_StringPtr identifier, esp_mail_imap_command type) +{ + +#if !defined(SILENT_MODE) + + PGM_P p1 = NULL; + PGM_P p2 = NULL; + if (type == esp_mail_imap_cmd_get_acl) + { + p1 = esp_mail_cb_str_36; /* "Get the ACL..." */ + p2 = esp_mail_dbg_str_77; /* "get the ACL" */ + } + else if (type == esp_mail_imap_cmd_set_acl) + { + p1 = esp_mail_cb_str_37; /* "Setting the ACL..." */ + p2 = esp_mail_dbg_str_78; /* "set the ACL" */ + } + else if (type == esp_mail_imap_cmd_delete_acl) + { + p1 = esp_mail_cb_str_38; /* "Deleting the ACL..." */ + p2 = esp_mail_dbg_str_72; /* "delete the ACL" */ + } + else if (type == esp_mail_imap_cmd_my_rights) + { + p1 = esp_mail_cb_str_39; /* "Get my ACL..." */ + p2 = esp_mail_dbg_str_23; /* "get my ACL" */ + } + + MailClient.printDebug(this, p1, p2, esp_mail_debug_tag_type_client, true, false); + +#endif + + if (!MailClient.sessionExisted(this)) + return false; + + if (!_feature_capability[esp_mail_imap_read_capability_acl]) + { +#if !defined(SILENT_MODE) + printDebugNotSupported(); +#endif + return false; + } + + MB_String _mailbox = mailbox; + MB_String _identifier = identifier; + + MB_String cmd; + if (type == esp_mail_imap_cmd_get_acl) + { + MailClient.appendSpace(cmd, true, imap_commands[esp_mail_imap_command_get_acl].text); + MailClient.appendString(cmd, _mailbox.c_str(), false, false, esp_mail_string_mark_type_double_quote); + } + else if (type == esp_mail_imap_cmd_set_acl) + { + MailClient.appendSpace(cmd, true, imap_commands[esp_mail_imap_command_set_acl].text); + MailClient.appendString(cmd, MB_String(mailbox).c_str(), false, false, esp_mail_string_mark_type_double_quote); + MailClient.appendSpace(cmd); + MailClient.appendString(cmd, acl->identifier.c_str(), false, false, esp_mail_string_mark_type_double_quote); + MailClient.appendSpace(cmd); + MB_String rights; + getRights(rights, acl); + MailClient.appendString(cmd, rights.c_str(), false, false, esp_mail_string_mark_type_double_quote); + } + else if (type == esp_mail_imap_cmd_delete_acl) + { + MailClient.appendSpace(cmd, true, imap_commands[esp_mail_imap_command_delete_acl].text); + MailClient.appendString(cmd, _mailbox.c_str(), false, false, esp_mail_string_mark_type_double_quote); + MailClient.appendSpace(cmd); + MailClient.appendString(cmd, _identifier.c_str(), false, false, esp_mail_string_mark_type_double_quote); + } + else if (type == esp_mail_imap_cmd_my_rights) + { + MailClient.appendSpace(cmd, true, imap_commands[esp_mail_imap_command_myrights].text); + MailClient.appendString(cmd, _mailbox.c_str(), false, false, esp_mail_string_mark_type_double_quote); + } + + if (MailClient.imapSend(this, cmd.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return false; + + _acl_tmp.clear(); + + _imap_cmd = type; + if (!MailClient.handleIMAPResponse(this, IMAP_STATUS_BAD_COMMAND, false)) + return false; + + if (type == esp_mail_imap_cmd_get_acl) + parseACL(_acl_tmp, acl_list); + else if (type == esp_mail_imap_cmd_my_rights) + parseRights(_acl_tmp, acl); + + _acl_tmp.clear(); + + return true; +} + +void IMAPSession::parseACL(MB_String &acl_str, IMAP_Rights_List *right_list) +{ + _vectorImpl tokens; + MailClient.splitToken(acl_str.c_str(), tokens, " "); + + for (size_t i = 0; i < tokens.size(); i += 2) + { + IMAP_Rights_Info info; + info.identifier = tokens[i]; + parseRights(tokens[i + 1], &info); + right_list->add(info); + } +} + +void IMAPSession::parseRights(MB_String &righs_str, IMAP_Rights_Info *info) +{ + for (size_t i = 0; i < righs_str.length(); i++) + { + uint8_t c = righs_str[i] - 97; + if (c >= esp_mail_imap_rights_administer && c < esp_mail_imap_rights_maxType) + info->rights[c] = true; + } +} + +void IMAPSession::getRights(MB_String &righs_str, IMAP_Rights_Info *info) +{ + for (size_t i = esp_mail_imap_rights_administer; i < esp_mail_imap_rights_maxType; i++) + { + if (info->rights[i]) + righs_str += (char)(i + 97); + } +} + +bool IMAPSession::mNamespace(IMAP_Namespaces_List *ns) +{ + +#if !defined(SILENT_MODE) + MailClient.printDebug(this, + esp_mail_cb_str_40 /* "Get namespace..." */, + esp_mail_dbg_str_67 /* "send IMAP command, NAMESPACE" */, + esp_mail_debug_tag_type_client, + true, + false); +#endif + + if (!MailClient.sessionExisted(this)) + return false; + + if (!_feature_capability[esp_mail_imap_read_capability_namespace]) + { +#if !defined(SILENT_MODE) + printDebugNotSupported(); +#endif + return false; + } + + if (MailClient.imapSend(this, prependTag(imap_commands[esp_mail_imap_command_namespace].text).c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return false; + + _ns_tmp.clear(); + + _imap_cmd = esp_mail_imap_cmd_namespace; + if (!MailClient.handleIMAPResponse(this, IMAP_STATUS_BAD_COMMAND, false)) + return false; + + int cnt = 0; + MB_String personal, other, shared; + + for (size_t i = 0; i < _ns_tmp.length(); i++) + { + if (i > 0 && i < _ns_tmp.length() - 1 && _ns_tmp[i] == ' ' && _ns_tmp[i - 1] != '"' && _ns_tmp[i + 1] != '"') + { + if (cnt == 0) + personal = _ns_tmp.substr(0, i); + else if (cnt == 1) + { + other = _ns_tmp.substr(personal.length() + 1, i - personal.length() - 1); + shared = _ns_tmp.substr(i + 1, _ns_tmp.length() - i - 1); + } + cnt++; + } + } + + if (personal.length() > 4) + parseNamespaces(personal, &(ns->personal_namespaces)); + + if (other.length() > 4) + parseNamespaces(other, &(ns->other_users_namespaces)); + + if (shared.length() > 4) + parseNamespaces(shared, &(ns->shared_namespaces)); + + return true; +} + +bool IMAPSession::mEnable(MB_StringPtr capability) +{ + +#if !defined(SILENT_MODE) + MailClient.printDebug(this, + esp_mail_cb_str_41 /* "Enable capability..." */, + esp_mail_dbg_str_68 /* "send IMAP command, ENABLE" */, + esp_mail_debug_tag_type_client, + true, + false); +#endif + + if (!_feature_capability[esp_mail_imap_read_capability_enable]) + { +#if !defined(SILENT_MODE) + printDebugNotSupported(); +#endif + return false; + } + + MB_String _cap = capability; + + MB_String cmd; + MailClient.joinStringSpace(cmd, true, 2, imap_commands[esp_mail_imap_command_enable].text, _cap.c_str()); + + if (MailClient.imapSend(this, cmd.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return false; + + _imap_cmd = esp_mail_imap_cmd_enable; + if (!MailClient.handleIMAPResponse(this, IMAP_STATUS_BAD_COMMAND, false)) + return false; + + return true; +} + +void IMAPSession::parseNamespaces(MB_String &ns_str, IMAP_Namespaces *ns) +{ + MB_String tmp = ns_str.substr(2, ns_str.length() - 4); + tmp.replaceAll(")(", " "); + _vectorImpl tokens; + MailClient.splitToken(tmp.c_str(), tokens, " "); + + for (size_t i = 0; i < tokens.size(); i += 2) + { + IMAP_Namespace_Info info; + info.prefix = tokens[i]; + info.delimiter = tokens[i + 1]; + ns->add(info); + } +} + +void IMAPSession::empty() +{ + _nextUID.clear(); + _unseenMsgIndex.clear(); + _flags_tmp.clear(); + _quota_tmp.clear(); + _quota_root_tmp.clear(); + _acl_tmp.clear(); + _ns_tmp.clear(); + _server_id_tmp.clear(); + _sdFileList.clear(); + clearMessageData(); +} + +IMAP_Status IMAPSession::status() +{ + return _cbData; +} + +String IMAPSession::fileList() +{ + return _sdFileList.c_str(); +} + +void IMAPSession::clearMessageData() +{ + for (size_t i = 0; i < _headers.size(); i++) + { + _headers[i].part_headers.clear(); + } + + _headers.clear(); + _imap_msg_num.clear(); + _mbif._searchCount = 0; + _flags_tmp.clear(); + +#if defined(MB_USE_STD_VECTOR) + _folders.clear(); + _mbif._flags.clear(); +#endif +} + +void IMAPSession::printDebugNotSupported() +{ + +#if !defined(SILENT_MODE) + MailClient.printDebug(this, + esp_mail_error_imap_str_13 /* "not supported by IMAP server" */, + esp_mail_error_imap_str_13 /* "not supported by IMAP server" */, + esp_mail_debug_tag_type_error, + true, + false); +#endif +} + +IMAP_Status::IMAP_Status() +{ +} + +IMAP_Status::~IMAP_Status() +{ + empty(); +} + +const char *IMAP_Status::info() +{ + return _info.c_str(); +} + +bool IMAP_Status::success() +{ + return _success; +} + +void IMAP_Status::empty() +{ + _info.clear(); +} + +#endif + +#endif /* ESP_MAIL_IMAP_H */ \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/ESP_Mail_SMTP.h b/lib/libesp32/ESP-Mail-Client/src/ESP_Mail_SMTP.h new file mode 100644 index 000000000..8371e95ca --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/ESP_Mail_SMTP.h @@ -0,0 +1,3631 @@ + +#ifndef ESP_MAIL_SMTP_H +#define ESP_MAIL_SMTP_H + +#include "ESP_Mail_Client_Version.h" +#if !VALID_VERSION_CHECK(30409) +#error "Mixed versions compilation." +#endif + +/** + * Mail Client Arduino Library for Espressif's ESP32 and ESP8266, Raspberry Pi RP2040 Pico, and SAMD21 with u-blox NINA-W102 WiFi/Bluetooth module + * + * Created August 28, 2023 + * + * This library allows Espressif's ESP32, ESP8266, SAMD and RP2040 Pico devices to send and read Email through the SMTP and IMAP servers. + * + * The MIT License (MIT) + * Copyright (c) 2023 K. Suwatchai (Mobizt) + * + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include "ESP_Mail_Client_Version.h" +#include "ESP_Mail_Client.h" + +#if defined(ENABLE_SMTP) + +void ESP_Mail_Client::mimeFromFile(const char *name, MB_String &mime) +{ + MB_String ext = name; + size_t p = ext.find_last_of("."); + if (p != MB_String::npos) + { + ext = ext.substr(p, ext.length() - p); + if (ext.length() > 0) + getMIME(ext.c_str(), mime); + } +} + +void ESP_Mail_Client::getMIME(const char *ext, MB_String &mime) +{ + mime.clear(); + for (int i = 0; i < esp_mail_file_extension_maxType; i++) + { + if (strcmp_P(ext, mimeinfo[i].endsWith) == 0) + { + mime = mimeinfo[i].mimeType; + break; + } + } +} + +bool ESP_Mail_Client::smtpAuth(SMTPSession *smtp, bool &ssl) +{ + if (!smtp) + return false; + + smtp->_auth_capability[esp_mail_auth_capability_login] = false; + + smtp->_session_cfg->int_start_tls = smtp->_session_cfg->secure.startTLS; + smtp->_session_cfg->int_mode = smtp->_session_cfg->secure.mode; + +#if !defined(ESP_MAIL_DISABLE_SSL) +initial_stage: +#endif + +// Sending greeting helo response +#if !defined(SILENT_MODE) + printDebug(smtp, + esp_mail_cb_str_3 /* "Sending greeting response..." */, + esp_mail_dbg_str_5 /* "send SMTP command, EHLO" */, + esp_mail_debug_tag_type_client, + true, + false); +#endif + + // The Extended HELLO (EHLO) and HELLO (HELO) commands are used to identify Client (ourself) + + // Since we support ESMTP (rfc5321), let server knows by sending EHLO first + + // If server was not support ESMTP (rfc5321) the failure 501, 500, 502, or 550 would be replied. + + // To prevent connection rejection, EHLO/HELO command parameter should be primary host name (domain name) of client system. + // Otherwise client public IP address string (IPv4 or IPv6) can be assign when no host name is available + + MB_String s = smtp_cmd_post_tokens[esp_mail_smtp_command_ehlo]; + appendDomain(s, smtp->_session_cfg->login.user_domain.c_str()); + + if (smtpSend(smtp, s.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return false; + + // expected success status code 250 + // expected error status code 500, 501, 504, 421 + if (!handleSMTPResponse(smtp, esp_mail_smtp_cmd_greeting, esp_mail_smtp_status_code_250, 0)) + { + +#if !defined(SILENT_MODE) + if (smtp->_debug) + esp_mail_debug_print_tag(esp_mail_dbg_str_17 /* "No ESMTP supported, send SMTP command, HELO" */, esp_mail_debug_tag_type_client, true); +#endif + // In case EHLO (rfc5321) is not acceptable, + // send HELO command (rfc821) instead. + s = smtp_cmd_post_tokens[esp_mail_smtp_command_helo]; + appendDomain(s, smtp->_session_cfg->login.user_domain.c_str()); + + if (!smtpSend(smtp, s.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return false; + + // expected success status code 250 + // expected error status code 500, 501, 504, 421 + if (!handleSMTPResponse(smtp, esp_mail_smtp_cmd_greeting, esp_mail_smtp_status_code_250, SMTP_STATUS_SMTP_GREETING_SEND_ACK_FAILED)) + return false; + + smtp->_feature_capability[esp_mail_smtp_send_capability_esmtp] = false; + smtp->_auth_capability[esp_mail_auth_capability_login] = true; + } + else + smtp->_feature_capability[esp_mail_smtp_send_capability_esmtp] = true; + +#if !defined(ESP_MAIL_DISABLE_SSL) + + if (smtp->_session_cfg->int_mode != esp_mail_secure_mode_nonsecure) + { + // start TLS when needed + // rfc3207 + if ((smtp->_auth_capability[esp_mail_auth_capability_starttls] || smtp->_session_cfg->int_start_tls || smtp->_session_cfg->int_mode == esp_mail_secure_mode_ssl_tls) && !ssl) + { +// send starttls command +#if !defined(SILENT_MODE) + printDebug(smtp, + esp_mail_cb_str_2 /* "Sending STARTTLS command..." */, + esp_mail_dbg_str_1 /* "send command, STARTTLS" */, + esp_mail_debug_tag_type_client, + true, + false); +#endif + + // expected success status code 250 for complete the request + // some server returns 220 to restart to initial state + + // expected error status code 500, 501, 504, 421 + smtpSend(smtp, smtp_commands[esp_mail_smtp_command_starttls].text, true); + if (!handleSMTPResponse(smtp, esp_mail_smtp_cmd_start_tls, esp_mail_smtp_status_code_250, SMTP_STATUS_SMTP_GREETING_SEND_ACK_FAILED)) + return false; + +#if !defined(SILENT_MODE) + if (smtp->_debug) + esp_mail_debug_print_tag(esp_mail_dbg_str_22 /* "perform SSL/TLS handshake" */, esp_mail_debug_tag_type_client, true); +#endif + + // connect in secure mode + // do TLS handshake + if (!smtp->client.connectSSL(smtp->_session_cfg->certificate.verify)) + return handleSMTPError(smtp, MAIL_CLIENT_ERROR_SSL_TLS_STRUCTURE_SETUP); + + // set the secure mode + smtp->_session_cfg->int_start_tls = false; + smtp->_session_cfg->int_mode = esp_mail_secure_mode_undefined; + ssl = true; + smtp->_secure = true; + + // return to initial stage if the response status is 220. + if (smtp->_responseStatus.statusCode == esp_mail_smtp_status_code_220) + goto initial_stage; + } + } + +#endif + + bool creds = smtp->_session_cfg->login.email.length() > 0 && smtp->_session_cfg->login.password.length() > 0; + bool sasl_auth_oauth = smtp->_session_cfg->login.accessToken.length() > 0 && smtp->_auth_capability[esp_mail_auth_capability_xoauth2]; + bool sasl_login = smtp->_auth_capability[esp_mail_auth_capability_login] && creds; + bool sasl_auth_plain = smtp->_auth_capability[esp_mail_auth_capability_plain] && creds; + + if (sasl_auth_oauth || sasl_login || sasl_auth_plain) + { +#if !defined(SILENT_MODE) + if (smtp->_statusCallback) + sendCB(smtp, esp_mail_cb_str_14 /* "Logging in..." */, true, false); +#endif + + // log in + if (sasl_auth_oauth) + { +#if !defined(SILENT_MODE) + if (smtp->_debug) + esp_mail_debug_print_tag(esp_mail_dbg_str_15 /* "send smtp command, AUTH XOAUTH2" */, esp_mail_debug_tag_type_client, true); +#endif + if (!smtp->_auth_capability[esp_mail_auth_capability_xoauth2]) + return handleSMTPError(smtp, SMTP_STATUS_SERVER_OAUTH2_LOGIN_DISABLED, false); + + MB_String cmd = smtp_cmd_post_tokens[esp_mail_smtp_command_auth]; + cmd += smtp_auth_cap_post_tokens[esp_mail_auth_capability_xoauth2]; + + if (smtpSend(smtp, cmd.c_str(), false) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return false; + + if (smtpSend(smtp, getXOAUTH2String(smtp->_session_cfg->login.email, smtp->_session_cfg->login.accessToken).c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return false; + + if (!handleSMTPResponse(smtp, esp_mail_smtp_cmd_auth_xoauth2, esp_mail_smtp_status_code_235, SMTP_STATUS_AUTHEN_FAILED)) + return false; + } + else if (sasl_auth_plain) + { +#if !defined(SILENT_MODE) + if (smtp->_debug) + { + esp_mail_debug_print_tag(esp_mail_dbg_str_7 /* "send SMTP command, AUTH PLAIN" */, esp_mail_debug_tag_type_client, true); + esp_mail_debug_print_tag(smtp->_session_cfg->login.email.c_str(), esp_mail_debug_tag_type_client, true); + MB_String mask; + maskString(mask, smtp->_session_cfg->login.password.length()); + esp_mail_debug_print_tag(mask.c_str(), esp_mail_debug_tag_type_client, true); + } +#endif + // rfc4616 + int len = smtp->_session_cfg->login.email.length() + smtp->_session_cfg->login.password.length() + 2; + uint8_t *tmp = allocMem(len); + memset(tmp, 0, len); + int p = 1; + memcpy(tmp + p, smtp->_session_cfg->login.email.c_str(), smtp->_session_cfg->login.email.length()); + p += smtp->_session_cfg->login.email.length() + 1; + memcpy(tmp + p, smtp->_session_cfg->login.password.c_str(), smtp->_session_cfg->login.password.length()); + p += smtp->_session_cfg->login.password.length(); + + MB_String cmd = smtp_cmd_post_tokens[esp_mail_smtp_command_auth]; + cmd += smtp_cmd_post_tokens[esp_mail_smtp_command_plain]; + cmd += encodeBase64Str(tmp, p); + // release memory + freeMem(&tmp); + + if (smtpSend(smtp, cmd.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return false; + + if (!handleSMTPResponse(smtp, esp_mail_smtp_cmd_auth_plain, esp_mail_smtp_status_code_235, SMTP_STATUS_USER_LOGIN_FAILED)) + return false; + } + else if (sasl_login) + { +#if !defined(SILENT_MODE) + if (smtp->_debug) + esp_mail_debug_print_tag(esp_mail_dbg_str_6 /* "send SMTP command, AUTH LOGIN" */, esp_mail_debug_tag_type_client, true); +#endif + MB_String cmd = smtp_cmd_post_tokens[esp_mail_smtp_command_auth]; + cmd += smtp_commands[esp_mail_smtp_command_login].text; + + if (smtpSend(smtp, cmd.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return false; + + // expected server challenge response + if (!handleSMTPResponse(smtp, esp_mail_smtp_cmd_auth_login, esp_mail_smtp_status_code_334, SMTP_STATUS_AUTHEN_FAILED)) + return false; + +#if !defined(SILENT_MODE) + if (smtp->_debug) + esp_mail_debug_print_tag(smtp->_session_cfg->login.email.c_str(), esp_mail_debug_tag_type_client, true); +#endif + if (smtpSend(smtp, encodeBase64Str((const unsigned char *)smtp->_session_cfg->login.email.c_str(), smtp->_session_cfg->login.email.length()).c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return false; + + // expected server challenge response + if (!handleSMTPResponse(smtp, esp_mail_smtp_cmd_login_user, esp_mail_smtp_status_code_334, SMTP_STATUS_USER_LOGIN_FAILED)) + return false; + +#if !defined(SILENT_MODE) + if (smtp->_debug) + { + MB_String mask; + maskString(mask, smtp->_session_cfg->login.password.length()); + esp_mail_debug_print_tag(mask.c_str(), esp_mail_debug_tag_type_client, true); + } +#endif + if (smtpSend(smtp, encodeBase64Str((const unsigned char *)smtp->_session_cfg->login.password.c_str(), smtp->_session_cfg->login.password.length()).c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return false; + + if (!handleSMTPResponse(smtp, esp_mail_smtp_cmd_login_psw, esp_mail_smtp_status_code_235, SMTP_STATUS_PASSWORD_LOGIN_FAILED)) + return false; + } + + smtp->_authenticated = true; + } + + return true; +} + +bool ESP_Mail_Client::addSendingResult(SMTPSession *smtp, SMTP_Message *msg, bool result, bool showResult) +{ + if (!smtp) + return false; + + if (result) + smtp->_sentSuccessCount++; + else + smtp->_sentFailedCount++; + + if (smtp->_session_cfg->sentLogs.filename.length() > 0 && smtp->_session_cfg->sentLogs.storage_type != esp_mail_file_storage_type_none) + saveSendingLogs(smtp, msg, result); + + // Store only tatest result + smtp->sendingResult.clear(); + + SMTP_Result status; + status.completed = result; + status.timestamp = smtp->ts; + status.subject = msg->subject.c_str(); + + if (msg->timestamp.tag.length() && msg->timestamp.format.length()) + status.subject.replaceAll(msg->timestamp.tag, Time.getDateTimeString(Time.getCurrentTimestamp(), msg->timestamp.format.c_str())); + + status.recipients = msg->_rcp[0].email.c_str(); + smtp->sendingResult.add(&status); + + smtp->_cbData._sentSuccess = smtp->_sentSuccessCount; + smtp->_cbData._sentFailed = smtp->_sentFailedCount; + +#if !defined(SILENT_MODE) + if (smtp->_statusCallback) + { + if (showResult) + { + int bufLen = 512; + char *buf = allocMem(bufLen); + time_t ts = (time_t)smtp->ts; + MB_String sep; + for (int i = 0; i < 25; i++) + sep += '-'; + + sendCallback(smtp, sep.c_str(), true, false); + snprintf(buf, bufLen, pgm2Str(esp_mail_str_93 /* "Message sent success: %d" */), smtp->_sentSuccessCount); + sendCallback(smtp, buf, false, false); + snprintf(buf, bufLen, pgm2Str(esp_mail_str_94 /* "Message sent failed: %d" */), smtp->_sentFailedCount); + sendCallback(smtp, buf, false, false); + sendCallback(smtp, sep.c_str(), false, false); + snprintf(buf, bufLen, pgm2Str(esp_mail_str_95 /* "Status: %s" */), result ? pgm2Str(esp_mail_str_98 /* "success" */) : pgm2Str(esp_mail_str_99 /* "failed" */)); + sendCallback(smtp, buf, false, false); + snprintf(buf, bufLen, pgm2Str(esp_mail_str_96 /* "Date/Time: %s" */), Time.getDateTimeString(ts, "%B %d, %Y %H:%M:%S").c_str()); + sendCallback(smtp, buf, false, false); + snprintf(buf, bufLen, pgm2Str(esp_mail_str_97 /* "Recipient: %s" */), msg->_rcp[0].email.c_str()); + sendCallback(smtp, buf, false, false); + snprintf(buf, bufLen, pgm2Str(esp_mail_str_92 /* "Subject: %s" */), msg->subject.c_str()); + sendCallback(smtp, buf, false, false); + freeMem(&buf); + } + } +#endif + + return result; +} + +void ESP_Mail_Client::saveSendingLogs(SMTPSession *smtp, SMTP_Message *msg, bool result) +{ + if (!smtp->_session_cfg || smtp->_session_cfg->sentLogs.filename.length() == 0 || smtp->_session_cfg->sentLogs.storage_type == esp_mail_file_storage_type_none) + return; + + int sz = mbfs->open(smtp->_session_cfg->sentLogs.filename.c_str(), mbfs_type smtp->_session_cfg->sentLogs.storage_type, mb_fs_open_mode_append); + if (sz < 0) + return; + + MB_String cm = esp_mail_str_8; /* "," */ + mbfs->print(mbfs_type smtp->_session_cfg->sentLogs.storage_type, (int)result); + mbfs->print(mbfs_type smtp->_session_cfg->sentLogs.storage_type, cm.c_str()); + mbfs->print(mbfs_type smtp->_session_cfg->sentLogs.storage_type, (int)smtp->ts); + mbfs->print(mbfs_type smtp->_session_cfg->sentLogs.storage_type, cm.c_str()); + mbfs->print(mbfs_type smtp->_session_cfg->sentLogs.storage_type, msg->_rcp[0].email.c_str()); + mbfs->print(mbfs_type smtp->_session_cfg->sentLogs.storage_type, cm.c_str()); + mbfs->println(mbfs_type smtp->_session_cfg->sentLogs.storage_type, msg->subject.c_str()); + mbfs->close(mbfs_type smtp->_session_cfg->sentLogs.storage_type); +} + +bool ESP_Mail_Client::sendMail(SMTPSession *smtp, SMTP_Message *msg, bool closeSession) +{ + if (!smtp || !sessionExisted(smtp)) + return false; + + smtp->_customCmdResCallback = NULL; + + return mSendMail(smtp, msg, closeSession); +} + +size_t ESP_Mail_Client::numAtt(SMTPSession *smtp, esp_mail_attach_type type, SMTP_Message *msg) +{ + size_t count = 0; + for (size_t i = 0; i < msg->_att.size(); i++) + { + if (msg->_att[i]._int.att_type == type) + count++; + } + return count; +} + +bool ESP_Mail_Client::checkEmail(SMTPSession *smtp, SMTP_Message *msg) +{ + bool validRecipient = false; + + if (!validEmail(msg->sender.email.c_str())) + { + errorStatusCB(smtp, this->imap, SMTP_STATUS_NO_VALID_SENDER_EXISTED, false); + return addSendingResult(smtp, msg, false, true); + } + + for (uint8_t i = 0; i < msg->_rcp.size(); i++) + { + if (validEmail(msg->_rcp[i].email.c_str())) + validRecipient = true; + } + + if (!validRecipient) + { + errorStatusCB(smtp, this->imap, SMTP_STATUS_NO_VALID_RECIPIENTS_EXISTED, false); + return addSendingResult(smtp, msg, false, true); + } + + return true; +} + +bool ESP_Mail_Client::mSendMail(SMTPSession *smtp, SMTP_Message *msg, bool closeSession) +{ + if (!smtp) + return false; + + smtp->_responseStatus.errorCode = 0; + smtp->_responseStatus.statusCode = 0; + smtp->_responseStatus.text.clear(); + smtp->_cbData._success = false; + bool rfc822MSG = false; + + if (!checkEmail(smtp, msg)) + return false; + + smtp->_chunkedEnable = false; + smtp->_chunkCount = 0; + + if (!smtp->connected() && !smtp->_loginStatus) + { +#if !defined(SILENT_MODE) + if (smtp->_debug && smtp->_statusCallback && !smtp->_customCmdResCallback) + { + esp_mail_debug_print(); + errorStatusCB(smtp, this->imap, MAIL_CLIENT_ERROR_NOT_YET_LOGIN, false); + } +#endif + return false; + } + + // new session + if (!smtp->connected()) + { + bool ssl = false; + + if (!smtp->connect(ssl)) + { + closeTCPSession(smtp); + return addSendingResult(smtp, msg, false, true); + } + + if (!smtpAuth(smtp, ssl)) + { + closeTCPSession(smtp); + return addSendingResult(smtp, msg, false, true); + } + smtp->_sentSuccessCount = 0; + smtp->_sentFailedCount = 0; + smtp->sendingResult.clear(); + } + else + { + // If time config changed, we will update time + MailClient.prepareTime(smtp->_session_cfg, smtp); + // reuse session +#if !defined(SILENT_MODE) + PGM_P p1 = smtp->_sentSuccessCount || smtp->_sentFailedCount ? esp_mail_cb_str_10 /* "Sending next Email..." */ : esp_mail_cb_str_9 /* "Sending Email..." */; + PGM_P p2 = smtp->_sentSuccessCount || smtp->_sentFailedCount ? esp_mail_dbg_str_13 /* "send next Email" */ : esp_mail_dbg_str_3 /* "send Email" */; + + printDebug(smtp, + p1, + p2, + esp_mail_debug_tag_type_client, + true, + false); +#endif + } + +#if !defined(SILENT_MODE) + printDebug(smtp, + esp_mail_cb_str_4 /* "Sending message header..." */, + esp_mail_dbg_str_8 /* "send message header" */, + esp_mail_debug_tag_type_client, + true, + false); +#endif + + imap = nullptr; + calDataLen = false; + dataLen = 0; + + return sendContent(smtp, msg, closeSession, rfc822MSG); +} + +bool ESP_Mail_Client::sendContent(SMTPSession *smtp, SMTP_Message *msg, bool closeSession, bool rfc822MSG) +{ + + if (msg->html.content.length() > 0 || strlen(msg->html.nonCopyContent) > 0 || msg->html.blob.size > 0 || msg->html.file.name.length() > 0) + msg->type |= esp_mail_msg_type_html; + + if (msg->text.content.length() > 0 || strlen(msg->text.nonCopyContent) > 0 || msg->text.blob.size > 0 || msg->text.file.name.length() > 0) + msg->type |= esp_mail_msg_type_plain; + + for (size_t i = 0; i < msg->_rfc822.size(); i++) + { + if (msg->_rfc822[i].html.content.length() > 0) + msg->_rfc822[i].type |= esp_mail_msg_type_html; + + if (msg->_rfc822[i].text.content.length() > 0) + msg->_rfc822[i].type |= esp_mail_msg_type_plain; + } + + MB_String buf; + MB_String buf2; + checkUnencodedData(smtp, msg); + + if (msg->priority >= esp_mail_smtp_priority_high && msg->priority <= esp_mail_smtp_priority_low) + { + appendHeaderField(buf2, message_headers[esp_mail_message_header_field_x_priority].text, MB_String(msg->priority).c_str(), false, true); + + PGM_P p = nullptr; + if (msg->priority == esp_mail_smtp_priority_high) + p = esp_mail_str_4; /* "High" */ + else if (msg->priority == esp_mail_smtp_priority_normal) + p = esp_mail_str_5; /* "Normal" */ + else if (msg->priority == esp_mail_smtp_priority_low) + p = esp_mail_str_6; /* "Low" */ + + if (p) + { + appendHeaderField(buf2, message_headers[esp_mail_message_header_field_x_msmail_priority].text, p, false, true); + appendHeaderField(buf2, message_headers[esp_mail_message_header_field_importance].text, p, false, true); + } + } + + // If author and transmitter (sender or agent) are not identical, send both 'From' and 'Sender' headers + if (msg->sender.email.length() > 0 && msg->author.email.length() > 0 && + strcmp(msg->sender.email.c_str(), msg->author.email.c_str()) != 0) + { + appendAddressHeaderField(buf2, msg->author, esp_mail_rfc822_header_field_from, true, false, true); + appendAddressHeaderField(buf2, msg->sender, esp_mail_rfc822_header_field_sender, true, false, true); + } + // If author and transmitter (agent) are identical, send only 'From' header + else if (msg->sender.email.length() > 0) + appendAddressHeaderField(buf2, msg->sender, esp_mail_rfc822_header_field_from, true, false, true); + + if (!imap && smtp) + { + + buf = smtp_cmd_post_tokens[esp_mail_smtp_command_mail]; + buf += smtp_commands[esp_mail_smtp_command_from].text; + + appendString(buf, msg->author.email.length() ? msg->author.email.c_str() : msg->sender.email.c_str(), false, false, esp_mail_string_mark_type_angle_bracket); + + if (msg->text._int.xencoding == esp_mail_msg_xencoding_binary || msg->html._int.xencoding == esp_mail_msg_xencoding_binary) + { + if (smtp->_feature_capability[esp_mail_smtp_send_capability_binary_mime] || (smtp->_feature_capability[esp_mail_smtp_send_capability_chunking] && msg->enable.chunking)) + { + buf += smtp_cmd_pre_tokens[esp_mail_smtp_command_body]; + buf += esp_mail_str_7; /* "=" */ + buf += smtp_send_capabilities[esp_mail_smtp_send_capability_binary_mime].text; + } + } + else if (msg->text._int.xencoding == esp_mail_msg_xencoding_8bit || msg->html._int.xencoding == esp_mail_msg_xencoding_8bit) + { + if (smtp->_feature_capability[esp_mail_smtp_send_capability_8bit_mime]) + { + buf += smtp_cmd_pre_tokens[esp_mail_smtp_command_body]; + buf += esp_mail_str_7; /* "=" */ + buf += smtp_send_capabilities[esp_mail_smtp_send_capability_8bit_mime].text; + } + } + + // expected success status code 250 + // expected failure status code 552, 451, 452 + // expected error status code 500, 501, 421 + if (!altSendData(buf, true, smtp, msg, true, true, esp_mail_smtp_cmd_send_header_sender, esp_mail_smtp_status_code_250, SMTP_STATUS_SEND_HEADER_SENDER_FAILED)) + return false; + } + + // Construct 'To' header fields. + + for (uint8_t i = 0; i < msg->_rcp.size(); i++) + { + appendAddressHeaderField(buf2, msg->_rcp[i], esp_mail_rfc822_header_field_to, i == 0, i > 0, i == msg->_rcp.size() - 1); + if (!imap && smtp) + { + // only address + buf = smtp_cmd_post_tokens[esp_mail_smtp_command_rcpt]; + buf += smtp_commands[esp_mail_smtp_command_to].text; + appendString(buf, msg->_rcp[i].email.c_str(), false, false, esp_mail_string_mark_type_angle_bracket); + + // rfc3461, rfc3464 + if (smtp->_feature_capability[esp_mail_smtp_send_capability_dsn]) + { + if (msg->response.notify != esp_mail_smtp_notify_never) + { + buf += smtp_cmd_pre_tokens[esp_mail_smtp_command_notify]; + buf += esp_mail_str_7; /* "=" */ + + MB_String notify; + + if ((msg->response.notify & esp_mail_smtp_notify_success) == esp_mail_smtp_notify_success) + notify = smtp_commands[esp_mail_smtp_command_success].text; + + if (notify.length()) + notify += esp_mail_str_8; /* "," */ + + if ((msg->response.notify & esp_mail_smtp_notify_failure) == esp_mail_smtp_notify_failure) + notify += smtp_commands[esp_mail_smtp_command_failure].text; + + if (notify.length()) + notify += esp_mail_str_8; /* "," */ + + if ((msg->response.notify & esp_mail_smtp_notify_delay) == esp_mail_smtp_notify_delay) + notify += smtp_commands[esp_mail_smtp_command_delay].text; + + buf += notify; + } + } + + smtp->_canForward = true; + + // expected success status code 250, 251 + // expected failure status code 550, 551, 552, 553, 450, 451, 452 + // expected error status code 500, 501, 503, 421 + if (!altSendData(buf, true, smtp, msg, true, true, esp_mail_smtp_cmd_send_header_recipient, esp_mail_smtp_status_code_250, SMTP_STATUS_SEND_HEADER_RECIPIENT_FAILED)) + return false; + } + } + + // Construct 'Cc' header field. + for (uint8_t i = 0; i < msg->_cc.size(); i++) + { + appendAddressHeaderField(buf2, msg->_cc[i], esp_mail_rfc822_header_field_cc, i == 0, i > 0, i == msg->_cc.size() - 1); + if (!imap) + { + // only address + buf = smtp_cmd_post_tokens[esp_mail_smtp_command_rcpt]; + buf += smtp_commands[esp_mail_smtp_command_to].text; + appendString(buf, msg->_cc[i].email.c_str(), false, false, esp_mail_string_mark_type_angle_bracket); + + smtp->_canForward = true; + + // expected success status code 250, 251 + // expected failure status code 550, 551, 552, 553, 450, 451, 452 + // expected error status code 500, 501, 503, 421 + if (!altSendData(buf, true, smtp, msg, true, true, esp_mail_smtp_cmd_send_header_recipient, esp_mail_smtp_status_code_250, SMTP_STATUS_SEND_HEADER_RECIPIENT_FAILED)) + return false; + } + } + + if (!imap && smtp) + { + for (uint8_t i = 0; i < msg->_bcc.size(); i++) + { + // only address + buf = smtp_cmd_post_tokens[esp_mail_smtp_command_rcpt]; + buf += smtp_commands[esp_mail_smtp_command_to].text; + appendString(buf, msg->_bcc[i].email.c_str(), false, false, esp_mail_string_mark_type_angle_bracket); + + smtp->_canForward = true; + + // expected success status code 250, 251 + // expected failure status code 550, 551, 552, 553, 450, 451, 452 + // expected error status code 500, 501, 503, 421 + if (!altSendData(buf, true, smtp, msg, true, true, esp_mail_smtp_cmd_send_header_recipient, esp_mail_smtp_status_code_250, SMTP_STATUS_SEND_HEADER_RECIPIENT_FAILED)) + return false; + } + +#if !defined(SILENT_MODE) + altSendCallback(smtp, esp_mail_cb_str_5 /* "Sending message body..." */, esp_mail_dbg_str_9 /* "send message body" */, esp_mail_debug_tag_type_client, true, false); +#endif + if (smtp->_feature_capability[esp_mail_smtp_send_capability_chunking] && msg->enable.chunking) + { + smtp->_chunkedEnable = true; + if (!sendBDAT(smtp, msg, buf2.length(), false)) + return false; + } + else + { + // expected success status code 354 + // expected failure status code 451, 554 + // expected error status code 500, 501, 503, 421 + MB_String sdata = smtp_commands[esp_mail_smtp_command_data].text; + if (!altSendData(sdata, true, smtp, msg, true, true, esp_mail_smtp_cmd_send_body, esp_mail_smtp_status_code_354, SMTP_STATUS_SEND_BODY_FAILED)) + return false; + } + } + +#if defined(ENABLE_IMAP) && !defined(SILENT_MODE) + if (imap) + altSendCallback(smtp, esp_mail_cb_str_14 /* "Appending message..." */, esp_mail_dbg_str_69 /* "appending message" */, esp_mail_debug_tag_type_client, true, false); + +#endif + + if (!altSendData(buf2, false, smtp, msg, true, false, esp_mail_smtp_cmd_undefined, esp_mail_smtp_status_code_0, SMTP_STATUS_UNDEFINED)) + return false; + + MB_String s; + appendHeaderField(s, rfc822_headers[esp_mail_rfc822_header_field_subject].text, msg->subject.c_str(), false, true); + + if (msg->timestamp.tag.length() && msg->timestamp.format.length()) + s.replaceAll(msg->timestamp.tag, Time.getDateTimeString(Time.getCurrentTimestamp(), msg->timestamp.format.c_str())); + + // Construct the 'Date' header field. + // The 'Date' header field should be valid and should be included in the message headers to + // prevent the 'spam' or 'junk' message considered by mail server. + + bool dateHdr = false; + MB_String dt; + + uint32_t ts = 0; + + if (smtp) + smtp->ts = ts; + + // Check if valid 'Date' field assigned from custom headers. + if (msg->_hdr.size() > 0) + { + for (uint8_t k = 0; k < msg->_hdr.size(); k++) + { + appendString(s, msg->_hdr[k].c_str(), false, true); + + if (getHeader(msg->_hdr[k].c_str(), rfc822_headers[esp_mail_rfc822_header_field_date].text, dt, false)) + { + ts = Time.getTimestamp(dt.c_str(), true); + dateHdr = ts > ESP_MAIL_CLIENT_VALID_TS; + if (smtp) + smtp->ts = ts; + } + } + } + + // Check if valid 'Date' field assigned from SMTP_Message's date property. + if (!dateHdr && msg->date.length() > 0) + { + dt = msg->date; + ts = Time.getTimestamp(msg->date.c_str(), true); + dateHdr = ts > ESP_MAIL_CLIENT_VALID_TS; + if (smtp) + smtp->ts = ts; + } + + if (dateHdr) + { + // 'Date' header field assigned. + appendHeaderField(s, rfc822_headers[esp_mail_rfc822_header_field_date].text, dt.c_str(), false, true); + } + else + { + // If there is no 'Date' field assigned, get time from system and construct 'Date' header field. + if (smtp) + { + ts = MailClient.Time.getCurrentTimestamp(); + smtp->ts = ts; + } + else if (imap) + { +#if defined(ENABLE_IMAP) + if (calDataLen) + { + ts = MailClient.Time.getCurrentTimestamp(); + imap_ts = ts; + } + else + ts = imap_ts; +#endif + } + + if (ts > ESP_MAIL_CLIENT_VALID_TS) + appendHeaderField(s, rfc822_headers[esp_mail_rfc822_header_field_date].text, Time.getDateTimeString().c_str(), false, true); + } + + if (msg->response.reply_to.length() > 0) + appendHeaderField(s, rfc822_headers[esp_mail_rfc822_header_field_reply_to].text, msg->response.reply_to.c_str(), false, true, esp_mail_string_mark_type_angle_bracket); + + if (msg->response.return_path.length() > 0) + appendHeaderField(s, rfc822_headers[esp_mail_rfc822_header_field_return_path].text, msg->response.return_path.c_str(), false, true, esp_mail_string_mark_type_angle_bracket); + + if (msg->in_reply_to.length() > 0) + appendHeaderField(s, rfc822_headers[esp_mail_rfc822_header_field_in_reply_to].text, msg->in_reply_to.c_str(), false, true); + + if (msg->references.length() > 0) + appendHeaderField(s, rfc822_headers[esp_mail_rfc822_header_field_references].text, msg->references.c_str(), false, true); + + if (msg->comments.length() > 0) + appendHeaderField(s, rfc822_headers[esp_mail_rfc822_header_field_comments].text, msg->comments.c_str(), false, true); + + if (msg->keywords.length() > 0) + appendHeaderField(s, rfc822_headers[esp_mail_rfc822_header_field_keywords].text, msg->keywords.c_str(), false, true); + + if (msg->messageID.length() > 0) + appendHeaderField(s, rfc822_headers[esp_mail_rfc822_header_field_msg_id].text, msg->messageID.c_str(), false, true, esp_mail_string_mark_type_angle_bracket); + + appendHeaderField(s, message_headers[esp_mail_message_header_field_mime_version].text, esp_mail_str_51 /* "1.0" */, false, true); + + if (!sendBDAT(smtp, msg, s.length(), false)) + return false; + + if (!altSendData(s, false, smtp, msg, true, false, esp_mail_smtp_cmd_undefined, esp_mail_smtp_status_code_0, SMTP_STATUS_UNDEFINED)) + return false; + + return sendMSGData(smtp, msg, closeSession, rfc822MSG); +} + +void ESP_Mail_Client::altSendCallback(SMTPSession *smtp, PGM_P cbMsg, PGM_P dbMsg, esp_mail_debug_tag_type type, bool prependCRLF, bool success) +{ +#if !defined(SILENT_MODE) + if (smtp) + printDebug(smtp, cbMsg, dbMsg, type, prependCRLF, success); + else if (imap && !calDataLen) + { +#if defined(ENABLE_IMAP) + printDebug(imap, cbMsg, dbMsg, type, prependCRLF, success); +#endif + } +#endif +} + +bool ESP_Mail_Client::sendMSGData(SMTPSession *smtp, SMTP_Message *msg, bool closeSession, bool rfc822MSG) +{ + MB_String s; + MB_String mixed = getMIMEBoundary(15); + MB_String alt = getMIMEBoundary(15); + + if (numAtt(smtp, esp_mail_att_type_attachment, msg) == 0 && msg->_parallel.size() == 0 && msg->_rfc822.size() == 0) + { + if (msg->type == (esp_mail_msg_type_plain | esp_mail_msg_type_html | esp_mail_msg_type_enriched) || numAtt(smtp, esp_mail_att_type_inline, msg) > 0) + { + if (!sendMSG(smtp, msg, alt)) + return addSendingResult(smtp, msg, false, true); + } + else if (msg->type != esp_mail_msg_type_none) + { + if (!sendPartText(smtp, msg, msg->type, "")) + return addSendingResult(smtp, msg, false, true); + } + } + else + { + s.clear(); + appendMultipartContentType(s, esp_mail_multipart_type_mixed, mixed.c_str()); + appendBoundaryString(s, mixed.c_str(), false, true); + + if (!sendBDAT(smtp, msg, s.length(), false)) + return false; + + if (!altSendData(s, false, smtp, msg, true, false, esp_mail_smtp_cmd_undefined, esp_mail_smtp_status_code_0, SMTP_STATUS_UNDEFINED)) + return false; + + if (!sendMSG(smtp, msg, alt)) + return addSendingResult(smtp, msg, false, true); + + if (!sendBDAT(smtp, msg, 2, false)) + return false; + + MB_String str; + appendNewline(str); + + if (!altSendData(str, false, smtp, msg, true, false, esp_mail_smtp_cmd_undefined, esp_mail_smtp_status_code_0, SMTP_STATUS_UNDEFINED)) + return false; + +#if !defined(SILENT_MODE) + altSendCallback(smtp, esp_mail_cb_str_6 /* "Sending attachments..." */, esp_mail_dbg_str_10 /* "send attachments" */, esp_mail_debug_tag_type_client, true, false); +#endif + if (!sendAttachments(smtp, msg, mixed)) + return addSendingResult(smtp, msg, false, true); + + if (!sendParallelAttachments(smtp, msg, mixed)) + return addSendingResult(smtp, msg, false, true); + + if (!sendRFC822Msg(smtp, msg, mixed, closeSession, msg->_rfc822.size() > 0)) + return addSendingResult(smtp, msg, false, true); + + s.clear(); + appendBoundaryString(s, mixed.c_str(), true, false); + + if (!sendBDAT(smtp, msg, s.length(), false)) + return false; + + if (!altSendData(s, false, smtp, msg, true, false, esp_mail_smtp_cmd_undefined, esp_mail_smtp_status_code_0, SMTP_STATUS_UNDEFINED)) + return false; + } + + if (!rfc822MSG && !imap && smtp) + { +#if !defined(SILENT_MODE) + altSendCallback(smtp, esp_mail_cb_str_11 /* "Finishing the message sending..." */, esp_mail_dbg_str_16 /* "finishing the message sending" */, esp_mail_debug_tag_type_client, true, false); +#endif + if (smtp->_chunkedEnable) + { + + if (!sendBDAT(smtp, msg, 0, true)) + return false; + + // expected success status code 250 + // expected failure status code 451, 554 + // expected error status code 500, 501, 503, 421 + if (!handleSMTPResponse(smtp, esp_mail_smtp_cmd_chunk_termination, esp_mail_smtp_status_code_250, SMTP_STATUS_SEND_BODY_FAILED)) + return false; + } + else + { + // expected success status code 250 + // expected failure status code 451, 554 + // expected error status code 500, 501, 503, 421 + MB_String str = smtp_commands[esp_mail_smtp_command_terminate].text; + if (!altSendData(str, false, smtp, msg, true, true, esp_mail_smtp_cmd_send_body, esp_mail_smtp_status_code_250, SMTP_STATUS_SEND_BODY_FAILED)) + return false; + } + + addSendingResult(smtp, msg, true, !closeSession); + + if (closeSession && smtp) + { + if (!smtp->closeSession()) + return false; + } + } + if (smtp) + smtp->_cbData._success = true; + return true; +} + +bool ESP_Mail_Client::sendRFC822Msg(SMTPSession *smtp, SMTP_Message *msg, const MB_String &boundary, bool closeSession, bool rfc822MSG) +{ + if (msg->_rfc822.size() == 0) + return true; + + MB_String buf; + + for (uint8_t i = 0; i < msg->_rfc822.size(); i++) + { + buf.clear(); + getRFC822PartHeader(smtp, buf, boundary); + + getRFC822MsgEnvelope(smtp, &msg->_rfc822[i], buf); + + if (!sendBDAT(smtp, msg, buf.length(), false)) + return false; + + if (!altSendData(buf, false, smtp, msg, false, false, esp_mail_smtp_cmd_undefined, esp_mail_smtp_status_code_0, SMTP_STATUS_UNDEFINED)) + return false; + + if (!sendMSGData(smtp, &msg->_rfc822[i], closeSession, rfc822MSG)) + return false; + } + + return true; +} + +void ESP_Mail_Client::getRFC822MsgEnvelope(SMTPSession *smtp, SMTP_Message *msg, MB_String &buf) +{ + if (msg->date.length() > 0) + appendHeaderField(buf, rfc822_headers[esp_mail_rfc822_header_field_date].text, msg->date.c_str(), false, true); + else + { + time_t now = 0; + if (smtp) + now = MailClient.Time.getCurrentTimestamp(); + else if (imap) + { +#if defined(ENABLE_IMAP) + if (calDataLen) + { + now = MailClient.Time.getCurrentTimestamp(); + imap_ts = now; + } + else + now = imap_ts; +#endif + } + + if (now > ESP_MAIL_CLIENT_VALID_TS) + appendHeaderField(buf, rfc822_headers[esp_mail_rfc822_header_field_date].text, Time.getDateTimeString().c_str(), false, true); + } + + // Construct 'From' header field. + if (msg->from.email.length() > 0) + appendAddressHeaderField(buf, msg->from, esp_mail_rfc822_header_field_from, true, false, true); + + // Construct 'Sender' header field. + if (msg->sender.email.length() > 0) + appendAddressHeaderField(buf, msg->sender, esp_mail_rfc822_header_field_sender, true, false, true); + + if (msg->response.reply_to.length() > 0) + appendHeaderField(buf, rfc822_headers[esp_mail_rfc822_header_field_reply_to].text, msg->response.reply_to.c_str(), false, true, esp_mail_string_mark_type_angle_bracket); + + if (msg->response.return_path.length() > 0) + appendHeaderField(buf, rfc822_headers[esp_mail_rfc822_header_field_return_path].text, msg->response.return_path.c_str(), false, true, esp_mail_string_mark_type_angle_bracket); + + // Construct 'To' header field. + for (uint8_t i = 0; i < msg->_rcp.size(); i++) + appendAddressHeaderField(buf, msg->_rcp[i], esp_mail_rfc822_header_field_to, i == 0, i > 0, i == msg->_rcp.size() - 1); + + for (uint8_t i = 0; i < msg->_cc.size(); i++) + appendAddressHeaderField(buf, msg->_cc[i], esp_mail_rfc822_header_field_cc, i == 0, i > 0, i == msg->_cc.size() - 1); + + for (uint8_t i = 0; i < msg->_bcc.size(); i++) + appendAddressHeaderField(buf, msg->_bcc[i], esp_mail_rfc822_header_field_bcc, i == 0, i > 0, i == msg->_bcc.size() - 1); + + if (msg->subject.length() > 0) + appendHeaderField(buf, rfc822_headers[esp_mail_rfc822_header_field_subject].text, msg->subject.c_str(), false, true); + + if (msg->keywords.length() > 0) + appendHeaderField(buf, rfc822_headers[esp_mail_rfc822_header_field_keywords].text, msg->keywords.c_str(), false, true); + + if (msg->comments.length() > 0) + appendHeaderField(buf, rfc822_headers[esp_mail_rfc822_header_field_comments].text, msg->comments.c_str(), false, true); + + if (msg->in_reply_to.length() > 0) + appendHeaderField(buf, rfc822_headers[esp_mail_rfc822_header_field_in_reply_to].text, msg->in_reply_to.c_str(), false, true); + + if (msg->references.length() > 0) + appendHeaderField(buf, rfc822_headers[esp_mail_rfc822_header_field_references].text, msg->references.c_str(), false, true); + + if (msg->messageID.length() > 0) + appendHeaderField(buf, rfc822_headers[esp_mail_rfc822_header_field_msg_id].text, msg->messageID.c_str(), false, true, esp_mail_string_mark_type_angle_bracket); +} + +void ESP_Mail_Client::appendBoundaryString(MB_String &buf, const char *value, bool endMark, bool newLine) +{ + buf += esp_mail_str_9; /* "--" */ + buf += value; + if (endMark) + buf += esp_mail_str_9; /* "--" */ + if (newLine) + appendNewline(buf); +} + +bool ESP_Mail_Client::sendBDAT(SMTPSession *smtp, SMTP_Message *msg, int len, bool last) +{ + if (!smtp) + return true; + + if (!smtp->_chunkedEnable || !msg->enable.chunking) + return true; + + smtp->_chunkCount++; + + MB_String bdat = smtp_cmd_post_tokens[esp_mail_smtp_command_bdat]; + bdat += len; + if (last) + bdat += smtp_cmd_pre_tokens[esp_mail_smtp_command_last]; + + if (smtpSend(smtp, bdat.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return addSendingResult(smtp, msg, false, true); + + if (!smtp->_feature_capability[esp_mail_smtp_send_capability_pipelining]) + { + // expected success status code 250 + // expected failure status code 451, 554 + // expected error status code 500, 501, 503, 421 + if (!handleSMTPResponse(smtp, esp_mail_smtp_cmd_send_body, esp_mail_smtp_status_code_250, SMTP_STATUS_SEND_BODY_FAILED)) + return addSendingResult(smtp, msg, false, true); + smtp->_chunkCount = 0; + } + return true; +} + +void ESP_Mail_Client::getXEncoding(esp_mail_msg_xencoding &xencoding, const char *enc) +{ + if (strcmp(enc, Content_Transfer_Encoding::enc_binary) == 0) + xencoding = esp_mail_msg_xencoding_binary; + else if (strcmp(enc, Content_Transfer_Encoding::enc_8bit) == 0) + xencoding = esp_mail_msg_xencoding_8bit; + else if (strcmp(enc, Content_Transfer_Encoding::enc_7bit) == 0) + xencoding = esp_mail_msg_xencoding_7bit; +} + +void ESP_Mail_Client::checkUnencodedData(SMTPSession *smtp, SMTP_Message *msg) +{ + if (msg->type & esp_mail_msg_type_plain || msg->type == esp_mail_msg_type_enriched || msg->type & esp_mail_msg_type_html) + { + if ((msg->type & esp_mail_msg_type_plain || msg->type == esp_mail_msg_type_enriched) > 0 && msg->text.transfer_encoding.length() > 0) + getXEncoding(msg->text._int.xencoding, msg->text.transfer_encoding.c_str()); + + if ((msg->type & esp_mail_msg_type_html) > 0 && msg->html.transfer_encoding.length() > 0) + getXEncoding(msg->html._int.xencoding, msg->html.transfer_encoding.c_str()); + } + + for (size_t i = 0; i < msg->_att.size(); i++) + getXEncoding(msg->_att[i]._int.xencoding, msg->_att[i].descr.transfer_encoding.c_str()); +} + +bool ESP_Mail_Client::altIsCB(SMTPSession *smtp) +{ + bool cb = false; + if (smtp) + cb = smtp->_statusCallback != NULL; + else if (imap && !calDataLen) + { +#if defined(ENABLE_IMAP) + cb = imap->_statusCallback != NULL; +#endif + } + + return cb; +} + +bool ESP_Mail_Client::altIsDebug(SMTPSession *smtp) +{ + bool dbg = false; + if (smtp) + dbg = smtp->_debug; + else if (imap && !calDataLen) + { +#if defined(ENABLE_IMAP) + dbg = imap->_debug; +#endif + } + + return dbg; +} + +bool ESP_Mail_Client::sendBlobAttachment(SMTPSession *smtp, SMTP_Message *msg, SMTP_Attachment *att) +{ + bool cb = altIsCB(smtp); + uint32_t addr = altProgressPtr(smtp); + + if (strcmp(att->descr.transfer_encoding.c_str(), Content_Transfer_Encoding::enc_base64) == 0 && strcmp(att->descr.transfer_encoding.c_str(), att->descr.content_encoding.c_str()) != 0) + { + esp_mail_smtp_send_base64_data_info_t data_info; + + data_info.rawPtr = att->blob.data; + data_info.size = att->blob.size; + data_info.flashMem = att->_int.flash_blob; + data_info.filename = att->descr.filename.c_str(); + + if (!sendBase64(smtp, msg, data_info, true, cb)) + return false; + + return true; + } + else + { + if (att->blob.size > 0) + { + if (strcmp(att->descr.content_encoding.c_str(), Content_Transfer_Encoding::enc_base64) == 0) + { + esp_mail_smtp_send_base64_data_info_t data_info; + + data_info.rawPtr = att->blob.data; + data_info.size = att->blob.size; + data_info.flashMem = att->_int.flash_blob; + data_info.filename = att->descr.filename.c_str(); + + if (!sendBase64(smtp, msg, data_info, false, cb)) + return false; + + return true; + } + else + { + + size_t chunkSize = ESP_MAIL_CLIENT_STREAM_CHUNK_SIZE; + size_t writeLen = 0; + uint8_t *buf = allocMem(chunkSize); + while (writeLen < att->blob.size) + { + if (writeLen > att->blob.size - chunkSize) + chunkSize = att->blob.size - writeLen; + + if (!sendBDAT(smtp, msg, chunkSize, false)) + break; + memcpy_P(buf, att->blob.data, chunkSize); + + if (!altSendData(buf, chunkSize, smtp, msg, false, false, esp_mail_smtp_cmd_undefined, esp_mail_smtp_status_code_0, SMTP_STATUS_UNDEFINED)) + break; + + if (smtp->_debug) + uploadReport(att->descr.filename.c_str(), addr, 100 * writeLen / att->blob.size); + + writeLen += chunkSize; + } + + // release memory + freeMem(&buf); + + if (smtp->_debug) + uploadReport(att->descr.filename.c_str(), addr, 100); + + return writeLen >= att->blob.size; + } + } + } + return false; +} + +bool ESP_Mail_Client::sendFile(SMTPSession *smtp, SMTP_Message *msg, SMTP_Attachment *att) +{ + bool cb = altIsCB(smtp); + uint32_t addr = altProgressPtr(smtp); + + if (strcmp(att->descr.transfer_encoding.c_str(), Content_Transfer_Encoding::enc_base64) == 0 && strcmp(att->descr.transfer_encoding.c_str(), att->descr.content_encoding.c_str()) != 0) + { + esp_mail_smtp_send_base64_data_info_t data_info; + + data_info.filename = att->descr.filename.c_str(); + data_info.storageType = att->file.storage_type; + + if (!sendBase64(smtp, msg, data_info, true, cb)) + return false; + + return true; + } + else + { + if (mbfs->size(mbfs_type att->file.storage_type) > 0) + { + if (strcmp(att->descr.content_encoding.c_str(), Content_Transfer_Encoding::enc_base64) == 0) + { + esp_mail_smtp_send_base64_data_info_t data_info; + + data_info.filename = att->descr.filename.c_str(); + data_info.storageType = att->file.storage_type; + + if (!sendBase64(smtp, msg, data_info, false, cb)) + return false; + + return true; + } + else + { + int chunkSize = ESP_MAIL_CLIENT_STREAM_CHUNK_SIZE; + int writeLen = 0; + + int fileSize = mbfs->size(mbfs_type att->file.storage_type); + + if (fileSize < chunkSize) + chunkSize = fileSize; + + uint8_t *buf = allocMem(chunkSize); + + while (writeLen < fileSize && mbfs->available(mbfs_type att->file.storage_type)) + { + if (writeLen > fileSize - chunkSize) + chunkSize = fileSize - writeLen; + int readLen = mbfs->read(mbfs_type att->file.storage_type, buf, chunkSize); + if (readLen != chunkSize) + { + errorStatusCB(smtp, this->imap, MB_FS_ERROR_FILE_IO_ERROR, false); + break; + } + + if (!sendBDAT(smtp, msg, chunkSize, false)) + break; + + if (!altSendData(buf, chunkSize, smtp, msg, false, false, esp_mail_smtp_cmd_undefined, esp_mail_smtp_status_code_0, SMTP_STATUS_UNDEFINED)) + break; + + if (smtp->_debug) + uploadReport(att->descr.filename.c_str(), addr, 100 * writeLen / fileSize); + + writeLen += chunkSize; + } + + // release memory + freeMem(&buf); + + if (smtp->_debug) + uploadReport(att->descr.filename.c_str(), addr, 100); + + return writeLen == fileSize; + } + } + return false; + } + return false; +} + +bool ESP_Mail_Client::sendParallelAttachments(SMTPSession *smtp, SMTP_Message *msg, const MB_String &boundary) +{ + if (msg->_parallel.size() == 0) + return true; + + MB_String parallel = getMIMEBoundary(15); + MB_String buf; + + appendBoundaryString(buf, boundary.c_str(), false, true); + + appendMultipartContentType(buf, esp_mail_multipart_type_parallel, parallel.c_str()); + + if (!sendBDAT(smtp, msg, buf.length(), false)) + return false; + + if (!altSendData(buf, false, smtp, msg, true, false, esp_mail_smtp_cmd_undefined, esp_mail_smtp_status_code_0, SMTP_STATUS_UNDEFINED)) + return false; + + if (!sendAttachments(smtp, msg, parallel, true)) + return addSendingResult(smtp, msg, false, true); + + buf.clear(); + appendBoundaryString(buf, parallel.c_str(), true, false); + + if (!sendBDAT(smtp, msg, buf.length(), false)) + return false; + + if (!altSendData(buf, false, smtp, msg, true, false, esp_mail_smtp_cmd_undefined, esp_mail_smtp_status_code_0, SMTP_STATUS_UNDEFINED)) + return false; + + return true; +} + +bool ESP_Mail_Client::sendAttachments(SMTPSession *smtp, SMTP_Message *msg, const MB_String &boundary, bool parallel) +{ + MB_String s; + MB_String buf; + int cnt = 0; + + SMTP_Attachment *att = nullptr; + + size_t sz = msg->_att.size(); + if (parallel) + sz = msg->_parallel.size(); + + for (size_t i = 0; i < sz; i++) + { + if (parallel) + att = &msg->_parallel[i]; + else + att = &msg->_att[i]; + + if (att->_int.att_type == esp_mail_att_type_attachment) + { +#if !defined(SILENT_MODE) + altSendCallback(smtp, att->descr.filename.c_str(), att->descr.filename.c_str(), esp_mail_debug_tag_type_client, true, false); +#endif + cnt++; + + if (att->file.storage_type == esp_mail_file_storage_type_none) + { + if (!att->blob.data) + continue; + + if (att->blob.size == 0) + continue; + + buf.clear(); + getAttachHeader(buf, boundary, att, att->blob.size, false); + + if (!sendBDAT(smtp, msg, buf.length(), false)) + return false; + + if (!altSendData(buf, false, smtp, msg, false, false, esp_mail_smtp_cmd_undefined, esp_mail_smtp_status_code_0, SMTP_STATUS_UNDEFINED)) + return false; + + if (!sendBlobAttachment(smtp, msg, att)) + return false; + + if (!sendBDAT(smtp, msg, 2, false)) + return false; + + MB_String str; + appendNewline(str); + + if (!altSendData(str, false, smtp, msg, false, false, esp_mail_smtp_cmd_undefined, esp_mail_smtp_status_code_0, SMTP_STATUS_UNDEFINED)) + return false; + } + else + { + if (att->file.storage_type == esp_mail_file_storage_type_sd && !smtp->_sdStorageChecked && !smtp->_sdStorageReady) + { + smtp->_sdStorageChecked = true; + smtp->_sdStorageReady = mbfs->sdReady(); + } + else if (att->file.storage_type == esp_mail_file_storage_type_flash && !smtp->_flashStorageChecked && !smtp->_flashStorageReady) + { + smtp->_flashStorageChecked = true; + smtp->_flashStorageReady = mbfs->flashReady(); + } + + if (!smtp->_flashStorageReady && !smtp->_sdStorageReady) + { + sendStorageNotReadyError(smtp, att->file.storage_type); + continue; + } + + if (openFileRead(smtp, msg, att, buf, boundary, false)) + { + + if (!sendFile(smtp, msg, att)) + return false; + + if (!sendBDAT(smtp, msg, 2, false)) + return false; + + MB_String str; + appendNewline(str); + + if (!altSendData(str, false, smtp, msg, false, false, esp_mail_smtp_cmd_undefined, esp_mail_smtp_status_code_0, SMTP_STATUS_UNDEFINED)) + return false; + } + } + } + } + return true; +} + +void ESP_Mail_Client::altSendStorageErrorCB(SMTPSession *smtp, int err) +{ +#if defined(MBFS_FLASH_FS) || defined(MBFS_SD_FS) + + if (smtp) + { + smtp->_responseStatus.errorCode = err; + smtp->_responseStatus.text.clear(); + +#if !defined(SILENT_MODE) + if (smtp->_statusCallback) + esp_mail_debug_print_tag(esp_mail_error_mem_str_3 /* "file does not exist or can't access" */, esp_mail_debug_tag_type_client, true); + + if (smtp->_debug) + esp_mail_debug_print_tag(smtp->errorReason().c_str(), esp_mail_debug_tag_type_error, true); +#endif + } + else if (imap && !calDataLen) + { +#if defined(ENABLE_IMAP) + + imap->_responseStatus.errorCode = err; + imap->_responseStatus.text.clear(); + +#if !defined(SILENT_MODE) + if (imap->_statusCallback) + esp_mail_debug_print_tag(esp_mail_error_mem_str_3 /* "file does not exist or can't access" */, esp_mail_debug_tag_type_client, true); + + if (imap->_debug) + { + esp_mail_debug_print_tag(smtp->errorReason().c_str(), esp_mail_debug_tag_type_error, true); + } +#endif +#endif + } + +#endif +} + +bool ESP_Mail_Client::openFileRead(SMTPSession *smtp, SMTP_Message *msg, SMTP_Attachment *att, MB_String &buf, const MB_String &boundary, bool inlined) +{ + int sz = -1; + MB_String filepath; + + if (att->file.path.length() > 0) + { + if (att->file.path[0] != '/') + filepath = esp_mail_str_10; /* "/" */ + filepath += att->file.path; + } + + sz = mbfs->open(filepath, mbfs_type att->file.storage_type, mb_fs_open_mode_read); + if (sz < 0) + { + + if (strlen(att->descr.filename.c_str()) > 0) + { + filepath.clear(); + if (att->descr.filename[0] != '/') + filepath = esp_mail_str_10; /* "/" */ + filepath += att->descr.filename; + } + + sz = mbfs->open(filepath, mbfs_type att->file.storage_type, mb_fs_open_mode_read); + } + + if (sz < 0) + { + altSendStorageErrorCB(smtp, sz); + } + else + { + + buf.clear(); + + getAttachHeader(buf, boundary, att, sz, inlined); + + if (!sendBDAT(smtp, msg, buf.length(), false)) + return false; + + if (!altSendData(buf, false, smtp, msg, false, false, esp_mail_smtp_cmd_undefined, esp_mail_smtp_status_code_0, SMTP_STATUS_UNDEFINED)) + return false; + + return true; + } + + return false; +} + +bool ESP_Mail_Client::openFileRead2(SMTPSession *smtp, SMTP_Message *msg, const char *path, esp_mail_file_storage_type storageType) +{ + + MB_String filepath; + + if (strlen(path) > 0) + { + if (path[0] != '/') + filepath = esp_mail_str_10; /* "/" */ + filepath += path; + } + + int sz = mbfs->open(filepath, mbfs_type storageType, mb_fs_open_mode_read); + if (sz < 0) + { + altSendStorageErrorCB(smtp, sz); + return false; + } + + return true; +} + +void ESP_Mail_Client::sendStorageNotReadyError(SMTPSession *smtp, esp_mail_file_storage_type storageType) +{ + +#if defined(MBFS_FLASH_FS) || defined(MBFS_SD_FS) + +#if !defined(SILENT_MODE) + if (altIsCB(smtp)) + { + if (storageType == esp_mail_file_storage_type_flash) + { + esp_mail_debug_print_tag(esp_mail_error_mem_str_1 /* "flash Storage is not ready." */, esp_mail_debug_tag_type_error, true); +#if defined(MB_ARDUINO_PICO) + esp_mail_debug_print_tag(esp_mail_error_mem_str_10 /* "please make sure that the size of flash filesystem is not 0 in Pico." */, esp_mail_debug_tag_type_error, true); +#endif + } + else if (storageType == esp_mail_file_storage_type_sd) + esp_mail_debug_print_tag(esp_mail_error_mem_str_2 /* "SD Storage is not ready." */, esp_mail_debug_tag_type_error, true); + } + + if (altIsDebug(smtp)) + { + if (storageType == esp_mail_file_storage_type_flash) + { + esp_mail_debug_print_tag(esp_mail_error_mem_str_1 /* "flash Storage is not ready." */, esp_mail_debug_tag_type_error, true); +#if defined(MB_ARDUINO_PICO) + esp_mail_debug_print_tag(esp_mail_error_mem_str_10 /* "please make sure that the size of flash filesystem is not 0 in Pico." */, esp_mail_debug_tag_type_error, true); +#endif + } + else if (storageType == esp_mail_file_storage_type_sd) + esp_mail_debug_print_tag(esp_mail_error_mem_str_2 /* "SD Storage is not ready." */, esp_mail_debug_tag_type_error, true); + } +#endif + +#endif +} + +bool ESP_Mail_Client::sendInline(SMTPSession *smtp, SMTP_Message *msg, const MB_String &boundary, byte type) +{ + size_t num = numAtt(smtp, esp_mail_att_type_inline, msg) > 0; + +#if !defined(SILENT_MODE) + if (num > 0) + altSendCallback(smtp, esp_mail_cb_str_8 /* "Sending inline data..." */, esp_mail_dbg_str_14 /* "send inline data" */, esp_mail_debug_tag_type_client, true, false); +#endif + MB_String buf; + MB_String related = getMIMEBoundary(15); + int cnt = 0; + SMTP_Attachment *att = nullptr; + + MB_String s; + + appendBoundaryString(s, boundary.c_str(), false, true); + + appendMultipartContentType(s, esp_mail_multipart_type_related, related.c_str()); + + if (!sendBDAT(smtp, msg, s.length(), false)) + return false; + + if (!altSendData(s, false, smtp, msg, false, false, esp_mail_smtp_cmd_undefined, esp_mail_smtp_status_code_0, SMTP_STATUS_UNDEFINED)) + return false; + + if (!sendPartText(smtp, msg, type, related.c_str())) + return false; + +#if !defined(SILENT_MODE) + bool cb = altIsCB(smtp); + + if (cb && numAtt(smtp, esp_mail_att_type_inline, msg) > 0) + esp_mail_debug_print(); +#endif + + if (num > 0) + { + for (uint8_t i = 0; i < msg->_att.size(); i++) + { + att = &msg->_att[i]; + if (att->_int.att_type == esp_mail_att_type_inline) + { +#if !defined(SILENT_MODE) + altSendCallback(smtp, att->descr.filename.c_str(), att->descr.filename.c_str(), esp_mail_debug_tag_type_client, true, false); +#endif + cnt++; + + if (att->file.storage_type == esp_mail_file_storage_type_none) + { + if (!att->blob.data) + continue; + + if (att->blob.size == 0) + continue; +#if !defined(SILENT_MODE) + altSendCallback(smtp, att->descr.filename.c_str(), att->descr.filename.c_str(), esp_mail_debug_tag_type_client, true, false); +#endif + buf.clear(); + getAttachHeader(buf, related, att, att->blob.size, true); + + if (!sendBDAT(smtp, msg, buf.length(), false)) + return false; + + if (!altSendData(buf, false, smtp, msg, false, false, esp_mail_smtp_cmd_undefined, esp_mail_smtp_status_code_0, SMTP_STATUS_UNDEFINED)) + return false; + + if (!sendBlobAttachment(smtp, msg, att)) + return false; + + if (!sendBDAT(smtp, msg, 2, false)) + return false; + + MB_String str; + appendNewline(str); + + if (!altSendData(str, false, smtp, msg, false, false, esp_mail_smtp_cmd_undefined, esp_mail_smtp_status_code_0, SMTP_STATUS_UNDEFINED)) + return false; + } + else + { + + if (att->file.storage_type == esp_mail_file_storage_type_sd && !smtp->_sdStorageChecked && !smtp->_sdStorageReady) + { + smtp->_sdStorageChecked = true; + smtp->_sdStorageReady = mbfs->sdReady(); + } + else if (att->file.storage_type == esp_mail_file_storage_type_flash && !smtp->_flashStorageChecked && !smtp->_flashStorageReady) + { + smtp->_flashStorageChecked = true; + smtp->_flashStorageReady = mbfs->flashReady(); + } + + if (!smtp->_flashStorageReady && !smtp->_sdStorageReady) + { + sendStorageNotReadyError(smtp, att->file.storage_type); + continue; + } + + if (openFileRead(smtp, msg, att, buf, related, true)) + { + if (!sendFile(smtp, msg, att)) + return false; + + if (!sendBDAT(smtp, msg, 2, false)) + return false; + + MB_String str; + appendNewline(str); + + if (!altSendData(str, false, smtp, msg, false, false, esp_mail_smtp_cmd_undefined, esp_mail_smtp_status_code_0, SMTP_STATUS_UNDEFINED)) + return false; + } + } + } + } + } + + appendNewline(s); + + appendBoundaryString(s, related.c_str(), true, true); + + if (!sendBDAT(smtp, msg, s.length(), false)) + return false; + + if (!altSendData(s, false, smtp, msg, false, false, esp_mail_smtp_cmd_undefined, esp_mail_smtp_status_code_0, SMTP_STATUS_UNDEFINED)) + return false; + + return true; +} + +size_t ESP_Mail_Client::smtpSend(SMTPSession *smtp, PGM_P data, bool newline) +{ + if (!smtp || !sessionReady(smtp)) + return 0; + + int sent = 0; + + MB_String s = data; + + int toSend = newline ? s.length() + 2 : s.length(); + +#if !defined(SILENT_MODE) + if (!smtp->_customCmdResCallback && smtp->_debugLevel > esp_mail_debug_level_maintainer) + esp_mail_debug_print(s.c_str(), newline); +#endif + + sent = newline ? smtp->client.println(s.c_str()) : smtp->client.print(s.c_str()); + + if (sent != toSend) + { + errorStatusCB(smtp, this->imap, sent, false); + sent = 0; + } + + return sent; +} + +size_t ESP_Mail_Client::smtpSend(SMTPSession *smtp, int data, bool newline) +{ + MB_String s = data; + return smtpSend(smtp, s.c_str(), newline); +} + +size_t ESP_Mail_Client::smtpSend(SMTPSession *smtp, uint8_t *data, size_t size) +{ + if (!smtp || !sessionReady(smtp)) + return 0; + + size_t sent = smtp->client.write(data, size); + + if (sent != size) + { + errorStatusCB(smtp, this->imap, sent, false); + sent = 0; + } + + return sent; +} + +bool ESP_Mail_Client::handleSMTPError(SMTPSession *smtp, int err, bool ret) +{ + + if (err < 0) + errorStatusCB(smtp, this->imap, err, false); + + if (smtp) + { + closeTCPSession(smtp); + } + else if (imap && !calDataLen) + { +#if defined(ENABLE_IMAP) + if (imap->connected()) + closeTCPSession(imap); +#endif + } + + return ret; +} + +bool ESP_Mail_Client::sendPartText(SMTPSession *smtp, SMTP_Message *msg, uint8_t type, const char *boundary) +{ + MB_String header; + + if (strlen(boundary) > 0) + appendBoundaryString(header, boundary, false, true); + + if (type == esp_mail_msg_type_plain || type == esp_mail_msg_type_enriched) + { + if (msg->text.content_type.length() > 0) + { + appendHeaderField(header, message_headers[esp_mail_message_header_field_content_type].text, msg->text.content_type.c_str(), false, false); + + bool firstProp = true; + + if (msg->text.charSet.length() > 0) + appendHeaderProp(header, message_headers[esp_mail_message_header_field_charset].text, msg->text.charSet.c_str(), firstProp, true, true, false); + + if (msg->text.flowed) + { + appendHeaderProp(header, message_headers[esp_mail_message_header_field_format].text, "flowed", firstProp, true, true, false); + appendHeaderProp(header, message_headers[esp_mail_message_header_field_delsp].text, "no", firstProp, true, true, false); + } + + if (msg->text.embed.enable) + { + appendHeaderProp(header, message_headers[esp_mail_message_header_field_name].text, esp_mail_str_13 /* "msg.txt" */, firstProp, false, true, false); + char *uid = getRandomUID(); + msg->text._int.cid = uid; + // release memory + freeMem(&uid); + } + + appendNewline(header); + } + + if (msg->text.transfer_encoding.length() > 0) + appendHeaderField(header, message_headers[esp_mail_message_header_field_content_transfer_encoding].text, msg->text.transfer_encoding.c_str(), false, true); + } + else if (type == esp_mail_msg_type_html) + { + if (msg->text.content_type.length() > 0) + { + appendHeaderField(header, message_headers[esp_mail_message_header_field_content_type].text, msg->html.content_type.c_str(), false, false); + bool firstProp = true; + + if (msg->html.charSet.length() > 0) + appendHeaderProp(header, message_headers[esp_mail_message_header_field_charset].text, msg->html.charSet.c_str(), firstProp, true, true, false); + + if (msg->html.embed.enable) + { + appendHeaderProp(header, message_headers[esp_mail_message_header_field_name].text, esp_mail_str_14 /* "msg.html" */, firstProp, true, true, false); + char *uid = getRandomUID(); + msg->html._int.cid = uid; + // release memory + freeMem(&uid); + } + + appendNewline(header); + } + + if (msg->html.transfer_encoding.length() > 0) + appendHeaderField(header, message_headers[esp_mail_message_header_field_content_transfer_encoding].text, msg->html.transfer_encoding.c_str(), false, true); + } + + if ((type == esp_mail_msg_type_html && msg->html.embed.enable) || ((type == esp_mail_msg_type_plain || type == esp_mail_msg_type_enriched) && msg->text.embed.enable)) + { + + if ((type == esp_mail_msg_type_plain || type == esp_mail_msg_type_enriched) && msg->text.embed.enable) + appendEmbedMessage(header, msg->text, false); + else if (type == esp_mail_msg_type_html && msg->html.embed.enable) + appendEmbedMessage(header, msg->html, true); + } + + appendNewline(header); + + bool rawBlob = (msg->text.blob.size > 0 && (type == esp_mail_msg_type_plain || type == esp_mail_msg_type_enriched)) || (msg->html.blob.size > 0 && type == esp_mail_msg_type_html); + bool rawFile = (msg->text.file.name.length() > 0 && (type == esp_mail_msg_type_plain || type == esp_mail_msg_type_enriched)) || (msg->html.file.name.length() > 0 && type == esp_mail_msg_type_html); + bool rawContent = ((type == esp_mail_msg_type_plain || type == esp_mail_msg_type_enriched) && msg->text.content.length() > 0) || (type == esp_mail_msg_type_html && msg->html.content.length() > 0); + bool nonCopyContent = ((type == esp_mail_msg_type_plain || type == esp_mail_msg_type_enriched) && strlen(msg->text.nonCopyContent) > 0) || (type == esp_mail_msg_type_html && strlen(msg->html.nonCopyContent) > 0); + + if (rawBlob || rawFile || nonCopyContent) + { + if (!sendBDAT(smtp, msg, header.length(), false)) + return false; + + if (!altSendData(header, false, smtp, msg, false, false, esp_mail_smtp_cmd_undefined, esp_mail_smtp_status_code_0, SMTP_STATUS_UNDEFINED)) + return false; + + header.clear(); + + if (rawBlob || nonCopyContent) + { + if (!sendBlobBody(smtp, msg, type)) + return false; + } + else if (rawFile) + { + if (!sendFileBody(smtp, msg, type)) + return false; + } + } + else if (rawContent) + encodingText(smtp, msg, type, header); + + appendNewline(header); + + if (strlen(boundary) > 0) + appendNewline(header); + + if (!sendBDAT(smtp, msg, header.length(), false)) + return false; + + if (!altSendData(header, false, smtp, msg, false, false, esp_mail_smtp_cmd_undefined, esp_mail_smtp_status_code_0, SMTP_STATUS_UNDEFINED)) + return false; + + return true; +} + +bool ESP_Mail_Client::sendBlobBody(SMTPSession *smtp, SMTP_Message *msg, uint8_t type) +{ + + bool cb = altIsCB(smtp); + uint32_t addr = altProgressPtr(smtp); + + if (msg->text.blob.size == 0 && msg->html.blob.size == 0 && strlen(msg->text.nonCopyContent) == 0 && strlen(msg->html.nonCopyContent) == 0) + return true; + + bool ret = true; + int bufLen = 512; + size_t pos = 0; + + const uint8_t *raw = NULL; + int len = 0; + bool base64 = false; + + if ((type == esp_mail_msg_type_plain || type == esp_mail_msg_type_enriched)) + { + if (strlen(msg->text.nonCopyContent) > 0) + { + raw = (const uint8_t *)msg->text.nonCopyContent; + len = strlen(msg->text.nonCopyContent); + } + else + { + raw = msg->text.blob.data; + len = msg->text.blob.size; + } + base64 = msg->text.transfer_encoding.length() > 0 && strcmp(msg->text.transfer_encoding.c_str(), Content_Transfer_Encoding::enc_base64) == 0; + } + else if (type == esp_mail_msg_type_html) + { + if (strlen(msg->html.nonCopyContent) > 0) + { + raw = (const uint8_t *)msg->html.nonCopyContent; + len = strlen(msg->html.nonCopyContent); + } + else + { + raw = msg->html.blob.data; + len = msg->html.blob.size; + } + base64 = msg->html.transfer_encoding.length() > 0 && strcmp(msg->html.transfer_encoding.c_str(), Content_Transfer_Encoding::enc_base64) == 0; + } + + if (base64) + { + MB_String s1 = esp_mail_str_15; /* "flash content message" */ + + esp_mail_smtp_send_base64_data_info_t data_info; + + data_info.flashMem = true; + data_info.filename = s1.c_str(); + data_info.rawPtr = raw; + data_info.size = len; + + return sendBase64(smtp, msg, data_info, true, cb); + } + + int available = len; + int sz = len; + uint8_t *buf = allocMem(bufLen + 1); + while (available) + { + if (available > bufLen) + available = bufLen; + + memcpy_P(buf, raw + pos, available); + + if (!sendBDAT(smtp, msg, available, false)) + { + ret = false; + break; + } + + if (!altSendData(buf, available, smtp, msg, false, false, esp_mail_smtp_cmd_undefined, esp_mail_smtp_status_code_0, SMTP_STATUS_UNDEFINED)) + { + ret = false; + break; + } + + pos += available; + len -= available; + available = len; + + if (smtp->_debug) + { + MB_String s1 = esp_mail_str_15; /* "flash content message" */ + uploadReport(s1.c_str(), addr, 100 * pos / sz); + } + } + + // release memory + freeMem(&buf); + + return ret; +} + +bool ESP_Mail_Client::sendFileBody(SMTPSession *smtp, SMTP_Message *msg, uint8_t type) +{ + bool cb = altIsCB(smtp); + uint32_t addr = altProgressPtr(smtp); + + if (msg->text.file.name.length() == 0 && msg->html.file.name.length() == 0) + return true; + + bool ret = true; + int chunkSize = ESP_MAIL_CLIENT_STREAM_CHUNK_SIZE; + int writeLen = 0; + + if (type == esp_mail_msg_type_plain || type == esp_mail_msg_type_enriched) + { + + if (!openFileRead2(smtp, msg, msg->text.file.name.c_str(), msg->text.file.type)) + return false; + + if (msg->text.transfer_encoding.length() > 0) + { + if (strcmp(msg->text.transfer_encoding.c_str(), Content_Transfer_Encoding::enc_base64) == 0) + { + MB_String s1 = esp_mail_str_16; /* "file content message" */ + + esp_mail_smtp_send_base64_data_info_t data_info; + + data_info.filename = s1.c_str(); + data_info.storageType = msg->text.file.type; + + return sendBase64(smtp, msg, data_info, true, cb); + } + } + + int fileSize = mbfs->size(mbfs_type msg->text.file.type); + + if (fileSize > 0) + { + + if (fileSize < chunkSize) + chunkSize = fileSize; + + uint8_t *buf = allocMem(chunkSize); + + while (writeLen < fileSize && mbfs->available(mbfs_type msg->text.file.type)) + { + if (writeLen > fileSize - chunkSize) + chunkSize = fileSize - writeLen; + int readLen = mbfs->read(mbfs_type msg->text.file.type, buf, chunkSize); + + if (readLen != chunkSize) + { + errorStatusCB(smtp, this->imap, MB_FS_ERROR_FILE_IO_ERROR, false); + break; + } + + if (!sendBDAT(smtp, msg, chunkSize, false)) + { + ret = false; + break; + } + + if (!altSendData(buf, chunkSize, smtp, msg, false, false, esp_mail_smtp_cmd_undefined, esp_mail_smtp_status_code_0, SMTP_STATUS_UNDEFINED)) + { + ret = false; + break; + } + + if (smtp->_debug) + uploadReport(pgm2Str(esp_mail_str_16 /* "file content message" */), addr, 100 * writeLen / fileSize); + + writeLen += chunkSize; + } + + // release memory + freeMem(&buf); + + if (smtp->_debug) + uploadReport(pgm2Str(esp_mail_str_16 /* "file content message" */), addr, 100); + + return ret && writeLen == fileSize; + } + } + else if (type == esp_mail_message_type::esp_mail_msg_type_html) + { + + if (!openFileRead2(smtp, msg, msg->html.file.name.c_str(), msg->html.file.type)) + return false; + + if (msg->html.transfer_encoding.length() > 0) + { + if (strcmp(msg->html.transfer_encoding.c_str(), Content_Transfer_Encoding::enc_base64) == 0) + { + MB_String s1 = esp_mail_str_16; /* "file content message" */ + + esp_mail_smtp_send_base64_data_info_t data_info; + + data_info.filename = s1.c_str(); + data_info.storageType = msg->html.file.type; + + return sendBase64(smtp, msg, data_info, true, cb); + } + } + + int fileSize = mbfs->size(mbfs_type msg->html.file.type); + + if (fileSize > 0) + { + + if (fileSize < chunkSize) + chunkSize = fileSize; + + uint8_t *buf = allocMem(chunkSize); + + while (writeLen < fileSize && mbfs->available(mbfs_type msg->html.file.type)) + { + if (writeLen > fileSize - chunkSize) + chunkSize = fileSize - writeLen; + int readLen = mbfs->read(mbfs_type msg->html.file.type, buf, chunkSize); + + if (readLen != chunkSize) + { + errorStatusCB(smtp, this->imap, MB_FS_ERROR_FILE_IO_ERROR, false); + break; + } + + if (!sendBDAT(smtp, msg, chunkSize, false)) + { + ret = false; + break; + } + + if (!altSendData(buf, chunkSize, smtp, msg, false, false, esp_mail_smtp_cmd_undefined, esp_mail_smtp_status_code_0, SMTP_STATUS_UNDEFINED)) + { + ret = false; + break; + } + + if (cb) + uploadReport(pgm2Str(esp_mail_str_16 /* "file content message" */), addr, 100 * writeLen / fileSize); + + writeLen += chunkSize; + } + + // release memory + freeMem(&buf); + + if (cb) + uploadReport(pgm2Str(esp_mail_str_16 /* "file content message" */), addr, 100); + + return ret && writeLen == fileSize; + } + } + + return false; +} + +void ESP_Mail_Client::encodingText(SMTPSession *smtp, SMTP_Message *msg, uint8_t type, MB_String &content) +{ + if (type == esp_mail_msg_type_plain || type == esp_mail_msg_type_enriched) + { + MB_String s = msg->text.content; + + if (msg->text.flowed) + formatFlowedText(s); + + if (msg->text.transfer_encoding.length() > 0) + { + if (strcmp(msg->text.transfer_encoding.c_str(), Content_Transfer_Encoding::enc_base64) == 0) + content += encodeBase64Str((const unsigned char *)s.c_str(), s.length()); + else if (strcmp(msg->text.transfer_encoding.c_str(), Content_Transfer_Encoding::enc_qp) == 0) + { + char *out = allocMem(s.length() * 3 + 1); + encodeQP(s.c_str(), out); + content += out; + + // release memory + freeMem(&out); + } + else + content += s; + } + else + content += s; + } + else if (type == esp_mail_message_type::esp_mail_msg_type_html) + { + MB_String s = msg->html.content; + MB_String fnd, rep; + SMTP_Attachment *att = nullptr; + for (uint8_t i = 0; i < msg->_att.size(); i++) + { + att = &msg->_att[i]; + if (att->_int.att_type == esp_mail_att_type_inline) + { + MB_String filename(att->descr.filename); + + size_t found = filename.find_last_of("/\\"); + if (found != MB_String::npos) + filename = filename.substr(found + 1); + + appendString(fnd, filename.c_str(), false, false, esp_mail_string_mark_type_double_quote); + + MB_String cid = esp_mail_str_17; /* "cid:" */ + cid += att->descr.content_id.length() > 0 ? att->descr.content_id : att->_int.cid; + + appendString(rep, cid.c_str(), false, false, esp_mail_string_mark_type_double_quote); + + s.replaceAll(fnd, rep); + } + } + + if (msg->html.transfer_encoding.length() > 0) + { + if (strcmp(msg->html.transfer_encoding.c_str(), Content_Transfer_Encoding::enc_base64) == 0) + content += encodeBase64Str((const unsigned char *)s.c_str(), s.length()); + else if (strcmp(msg->html.transfer_encoding.c_str(), Content_Transfer_Encoding::enc_qp) == 0) + { + char *out = allocMem(msg->html.content.length() * 3 + 1); + encodeQP(msg->html.content.c_str(), out); + content += out; + + // release memory + freeMem(&out); + } + else + content += s; + } + else + content += s; + s.clear(); + } + + if (msg->timestamp.tag.length() && msg->timestamp.format.length()) + content.replaceAll(msg->timestamp.tag, Time.getDateTimeString(Time.getCurrentTimestamp(), msg->timestamp.format.c_str())); +} + +void ESP_Mail_Client::encodeQP(const char *buf, char *out) +{ + int n = 0, p = 0, pos = 0; + for (n = 0; *buf; buf++) + { + if (n >= 73 && *buf != 10 && *buf != 13) + { + p = sprintf(out + pos, "=\r\n"); + pos += p; + n = 0; + } + + if (*buf == 10 || *buf == 13) + { + out[pos++] = *buf; + n = 0; + } + else if (*buf < 32 || *buf == 61 || *buf > 126) + { + p = sprintf(out + pos, "=%02X", (unsigned char)*buf); + n += p; + pos += p; + } + else if (*buf != 32 || (*(buf + 1) != 10 && *(buf + 1) != 13)) + { + out[pos++] = *buf; + n++; + } + else + { + p = sprintf(out + pos, "=20"); + n += p; + pos += p; + } + } +} + +/** Add the soft line break to the long text line (rfc 3676) + * and add Format=flowed parameter in the plain text content-type header. + * We use the existing white space as a part of this soft line break + * and set delSp="no" parameter to the header. + * + * Some servers are not rfc 3676 compliant. + * This causes the text lines are wrapped instead of joined. + * + * Some mail clients trim the space before the line break + * which makes the soft line break cannot be seen. + */ +void ESP_Mail_Client::formatFlowedText(MB_String &content) +{ + int count = 0; + MB_String qms; + int j = 0; + _vectorImpl tokens; + char *stk = strP(esp_mail_str_18); /* "\r\n" */ + char *qm = strP(esp_mail_str_20); /* ">" */ + splitToken(content.c_str(), tokens, stk); + content.clear(); + for (size_t i = 0; i < tokens.size(); i++) + { + if (tokens[i].length() > 0) + { + j = 0; + qms.clear(); + while (tokens[i][j] == qm[0]) + { + qms += qm; + j++; + } + softBreak(tokens[i], qms.c_str()); + if (count > 0) + content += stk; + content += tokens[i]; + } + else if (count > 0) + content += stk; + count++; + } + + // release memory + freeMem(&stk); + freeMem(&qm); + tokens.clear(); +} + +void ESP_Mail_Client::softBreak(MB_String &content, const char *quoteMarks) +{ + size_t len = 0; + char *stk = strP(esp_mail_str_2); /* " " */ + _vectorImpl tokens; + splitToken(content.c_str(), tokens, stk); + content.clear(); + for (size_t i = 0; i < tokens.size(); i++) + { + if (tokens[i].length() > 0) + { + if (len + tokens[i].length() + 3 > FLOWED_TEXT_LEN) + { + /* insert soft crlf */ + content += stk; + appendNewline(content); + + /* insert quote marks */ + if (strlen(quoteMarks) > 0) + content += quoteMarks; + content += tokens[i]; + len = tokens[i].length(); + } + else + { + if (len > 0) + { + content += stk; + len += strlen(stk); + } + content += tokens[i]; + len += tokens[i].length(); + } + } + } + + // release memory + freeMem(&stk); + tokens.clear(); +} + +bool ESP_Mail_Client::altSendData(MB_String &s, bool newLine, SMTPSession *smtp, SMTP_Message *msg, bool addSendResult, bool getResponse, esp_mail_smtp_command cmd, esp_mail_smtp_status_code statusCode, int errCode) +{ + if (!imap && smtp) + { + if (smtpSend(smtp, s.c_str(), newLine) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + { + if (addSendResult) + return addSendingResult(smtp, msg, false, true); + else + return false; + } + + if (getResponse) + { + if (!handleSMTPResponse(smtp, cmd, statusCode, errCode)) + { + if (addSendResult) + return addSendingResult(smtp, msg, false, true); + else + return false; + } + } + } + else if (imap) + { +#if defined(ENABLE_IMAP) + if (newLine) + appendNewline(s); + MB_StringPtr data = toStringPtr(s); + + if (calDataLen) + dataLen += s.length(); + else + return imap->mSendData(data, false, esp_mail_imap_cmd_append); +#endif + } + + return true; +} + +bool ESP_Mail_Client::altSendData(uint8_t *data, size_t size, SMTPSession *smtp, SMTP_Message *msg, bool addSendResult, bool getResponse, esp_mail_smtp_command cmd, esp_mail_smtp_status_code statusCode, int errCode) +{ + if (!imap && smtp) + { + if (smtpSend(smtp, data, size) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + { + if (addSendResult) + return addSendingResult(smtp, msg, false, true); + else + return false; + } + + if (getResponse) + { + if (!handleSMTPResponse(smtp, cmd, statusCode, errCode)) + { + if (addSendResult) + return addSendingResult(smtp, msg, false, true); + else + return false; + } + } + } + else if (imap) + { +#if defined(ENABLE_IMAP) + + if (calDataLen) + dataLen += size; + else + return imap->mSendData(data, size, false, esp_mail_imap_cmd_append); +#endif + } + + return true; +} + +bool ESP_Mail_Client::sendMSG(SMTPSession *smtp, SMTP_Message *msg, const MB_String &boundary) +{ + MB_String s; + + if (numAtt(smtp, esp_mail_att_type_inline, msg) > 0) + { + appendMultipartContentType(s, esp_mail_multipart_type_alternative, boundary.c_str()); + + if (!sendBDAT(smtp, msg, s.length(), false)) + return false; + + if (!altSendData(s, false, smtp, msg, false, false, esp_mail_smtp_cmd_undefined, esp_mail_smtp_status_code_0, SMTP_STATUS_UNDEFINED)) + return false; + + if (msg->type == esp_mail_msg_type_plain || msg->type == esp_mail_msg_type_enriched || msg->type == esp_mail_msg_type_html) + { + if (!sendInline(smtp, msg, boundary, msg->type)) + return false; + } + else if (msg->type == (esp_mail_msg_type_html | esp_mail_msg_type_enriched | esp_mail_msg_type_plain)) + { + if (!sendPartText(smtp, msg, esp_mail_msg_type_plain, boundary.c_str())) + return false; + if (!sendInline(smtp, msg, boundary, esp_mail_msg_type_html)) + return false; + } + + appendBoundaryString(s, boundary.c_str(), true, true); + + if (!sendBDAT(smtp, msg, s.length(), false)) + return false; + + if (!altSendData(s, false, smtp, msg, false, false, esp_mail_smtp_cmd_undefined, esp_mail_smtp_status_code_0, SMTP_STATUS_UNDEFINED)) + return false; + } + else + { + if (msg->type == esp_mail_msg_type_plain || msg->type == esp_mail_msg_type_enriched || msg->type == esp_mail_msg_type_html) + { + if (!sendPartText(smtp, msg, msg->type, "")) + return false; + } + else if (msg->type == (esp_mail_msg_type_html | esp_mail_msg_type_enriched | esp_mail_msg_type_plain)) + { + appendMultipartContentType(s, esp_mail_multipart_type_alternative, boundary.c_str()); + + if (!sendBDAT(smtp, msg, s.length(), false)) + return false; + + if (!altSendData(s, false, smtp, msg, false, false, esp_mail_smtp_cmd_undefined, esp_mail_smtp_status_code_0, SMTP_STATUS_UNDEFINED)) + return false; + + if (!sendPartText(smtp, msg, esp_mail_msg_type_plain, boundary.c_str())) + return false; + + if (!sendPartText(smtp, msg, esp_mail_msg_type_html, boundary.c_str())) + return false; + + s.clear(); + appendBoundaryString(s, boundary.c_str(), true, false); + + if (!sendBDAT(smtp, msg, s.length(), false)) + return false; + + if (!altSendData(s, false, smtp, msg, true, false, esp_mail_smtp_cmd_undefined, esp_mail_smtp_status_code_0, SMTP_STATUS_UNDEFINED)) + return false; + } + } + return true; +} + +void ESP_Mail_Client::getAttachHeader(MB_String &header, const MB_String &boundary, SMTP_Attachment *attach, size_t size, bool isInline) +{ + appendBoundaryString(header, boundary.c_str(), false, true); + + appendHeaderName(header, message_headers[esp_mail_message_header_field_content_type].text); + + if (attach->descr.mime.length() == 0) + { + MB_String mime; + mimeFromFile(attach->descr.filename.c_str(), mime); + if (mime.length() > 0) + appendString(header, mime.c_str(), false, false); + else + appendString(header, mimeinfo[esp_mail_file_extension_binary].mimeType, false, false); + } + else + appendString(header, attach->descr.mime.c_str(), false, false); + + MB_String filename = attach->descr.filename; + + size_t found = filename.find_last_of("/\\"); + if (found != MB_String::npos) + filename = filename.substr(found + 1); + + bool firstProp = true; + + appendHeaderProp(header, message_headers[esp_mail_message_header_field_name].text, filename.c_str(), firstProp, false, true, true); + + if (isInline || (!isInline && !attach->_int.parallel)) + { + appendHeaderName(header, message_headers[esp_mail_message_header_field_content_disposition].text); + appendString(header, isInline ? esp_mail_content_disposition_type_t::inline_ : esp_mail_content_disposition_type_t::attachment, false, false); + + firstProp = true; + appendHeaderProp(header, message_headers[esp_mail_message_header_field_filename].text, filename.c_str(), firstProp, true, true, false); + appendHeaderProp(header, message_headers[esp_mail_message_header_field_size].text, MB_String((int)size).c_str(), firstProp, true, false, true); + } + + if (isInline) + { + + appendHeaderField(header, message_headers[esp_mail_message_header_field_content_location].text, filename.c_str(), false, true); + + appendHeaderName(header, message_headers[esp_mail_message_header_field_content_id].text); + if (attach->descr.content_id.length() > 0) + appendString(header, attach->descr.content_id.c_str(), false, true, esp_mail_string_mark_type_angle_bracket); + else + appendString(header, attach->_int.cid.c_str(), false, true, esp_mail_string_mark_type_angle_bracket); + } + + if (attach->descr.transfer_encoding.length() > 0) + appendHeaderField(header, message_headers[esp_mail_message_header_field_content_transfer_encoding].text, attach->descr.transfer_encoding.c_str(), false, true); + + if (attach->descr.description.length() > 0) + appendHeaderField(header, message_headers[esp_mail_message_header_field_content_description].text, attach->descr.description.c_str(), false, true); + + appendNewline(header); +} + +void ESP_Mail_Client::getRFC822PartHeader(SMTPSession *smtp, MB_String &header, const MB_String &boundary) +{ + appendBoundaryString(header, boundary.c_str(), false, true); + + appendHeaderName(header, message_headers[esp_mail_message_header_field_content_type].text); + appendString(header, esp_mail_str_22 /* "message/rfc822" */, false, true); + + appendHeaderName(header, message_headers[esp_mail_message_header_field_content_disposition].text); + appendString(header, esp_mail_content_disposition_type_t::attachment, false, true); + appendNewline(header); +} + +uint32_t ESP_Mail_Client::altProgressPtr(SMTPSession *smtp) +{ + uint32_t addr = 0; + if (smtp) + { + smtp->_lastProgress = -1; + addr = toAddr(smtp->_lastProgress); + } + else if (imap && !calDataLen) + { +#if defined(ENABLE_IMAP) + imap->_lastProgress = -1; + addr = toAddr(imap->_lastProgress); +#endif + } + + return addr; +} + +void ESP_Mail_Client::parseAuthCapability(SMTPSession *smtp, char *buf) +{ + if (!smtp) + return; + + if (strposP(buf, smtp_cmd_post_tokens[esp_mail_smtp_command_auth].c_str(), 0) > -1) + { + for (int i = esp_mail_auth_capability_plain; i < esp_mail_auth_capability_maxType; i++) + { + if (strposP(buf, smtp_auth_cap_pre_tokens[i].c_str(), 0) > -1) + { + smtp->_auth_capability[i] = true; + // Don't exit the loop + // and continue checking for all auth types + } + } + } + else if (strposP(buf, smtp_auth_capabilities[esp_mail_auth_capability_starttls].text, 0) > -1) + { + smtp->_auth_capability[esp_mail_auth_capability_starttls] = true; + return; + } + + for (int i = esp_mail_smtp_send_capability_binary_mime; i < esp_mail_smtp_send_capability_maxType; i++) + { + if (strposP(buf, smtp_send_cap_pre_tokens[i].c_str(), 0) > -1) + { + smtp->_feature_capability[i] = true; + return; + } + } +} + +bool ESP_Mail_Client::handleSMTPResponse(SMTPSession *smtp, esp_mail_smtp_command cmd, esp_mail_smtp_status_code statusCode, int errCode) +{ + if (!smtp) + return false; + + smtp->_smtp_cmd = cmd; + + if (!reconnect(smtp)) + return false; + + bool ret = false; + char *response = nullptr; + int readLen = 0; + long dataTime = millis(); + int chunkBufSize = 0; + MB_String s, r, err; + int chunkIndex = 0; + int count = 0; + bool completedResponse = false; + smtp->_responseStatus.errorCode = 0; + smtp->_responseStatus.statusCode = 0; + smtp->_responseStatus.text.clear(); + uint8_t minResLen = 5; + struct esp_mail_smtp_response_status_t status; + + bool canForward = smtp->_canForward; + smtp->_canForward = false; + + status.id = smtp->_commandID; + + chunkBufSize = smtp->client.available(); + + while (smtp->connected() && chunkBufSize <= 0) + { + if (!reconnect(smtp, dataTime)) + return false; + if (!connected(smtp)) + { + if (cmd != esp_mail_smtp_cmd_logout) + errorStatusCB(smtp, this->imap, MAIL_CLIENT_ERROR_CONNECTION_CLOSED, false); + + return false; + } + chunkBufSize = smtp->client.available(); + yield_impl(); + } + + dataTime = millis(); + + if (chunkBufSize > 1) + { + while (!completedResponse) + { + yield_impl(); + + if (!reconnect(smtp, dataTime)) + return false; + + if (!connected(smtp)) + { + if (cmd != esp_mail_smtp_cmd_logout) + errorStatusCB(smtp, this->imap, MAIL_CLIENT_ERROR_CONNECTION_CLOSED, false); + return false; + } + + chunkBufSize = smtp->client.available(); + + if (chunkBufSize <= 0) + break; + + if (chunkBufSize > 0) + { + + chunkBufSize = ESP_MAIL_CLIENT_RESPONSE_BUFFER_SIZE; + response = allocMem(chunkBufSize + 1); + + read_line: + + MB_String ovfBuf; + if (!readResponse(smtp, response, chunkBufSize, readLen, false, count, ovfBuf)) + { + closeTCPSession(smtp); + errorStatusCB(smtp, this->imap, MAIL_CLIENT_ERROR_READ_TIMEOUT, false); + return false; + } + + // If buffer overflown, copy from overflow buffer + if (ovfBuf.length() > 0) + { + // release memory + freeMem(&response); + response = allocMem(ovfBuf.length() + 1); + strcpy(response, ovfBuf.c_str()); + ovfBuf.clear(); + } + + if (readLen) + { + if (smtp->_smtp_cmd != esp_mail_smtp_command::esp_mail_smtp_cmd_initial_state) + { + // sometimes server sent multiple lines response + // sometimes rx buffer is not ready for a while + + if (strlen(response) < minResLen) + { + r += response; + chunkBufSize = 0; + while (chunkBufSize == 0) + { + yield_impl(); + if (!reconnect(smtp, dataTime)) + return false; + chunkBufSize = smtp->client.available(); + } + } + else + { + if (r.length() > 0) + { + r += response; + memset(response, 0, chunkBufSize); + strcpy(response, r.c_str()); + } +#if !defined(SILENT_MODE) + if (!smtp->_customCmdResCallback && smtp->_debugLevel > esp_mail_debug_level_basic) + esp_mail_debug_print((const char *)response, true); +#endif + } + + if (smtp->_smtp_cmd == esp_mail_smtp_command::esp_mail_smtp_cmd_greeting) + parseAuthCapability(smtp, response); + } + + getResponseStatus(response, statusCode, 0, status); + + // No response code from greeting? + // Assumed multi-line greeting responses. + + if (status.statusCode == 0 && smtp->_smtp_cmd == esp_mail_smtp_command::esp_mail_smtp_cmd_initial_state) + { + +#if !defined(SILENT_MODE) + if (smtp->_debug && !smtp->_customCmdResCallback) + esp_mail_debug_print_tag(response, esp_mail_debug_tag_type_server, true); +#endif + + memset(response, 0, chunkBufSize + 1); + + // read again until we get the response code + goto read_line; + } + + // get the status code again for unexpected return code + if (smtp->_smtp_cmd == esp_mail_smtp_command::esp_mail_smtp_cmd_start_tls || status.statusCode == 0) + getResponseStatus(response, esp_mail_smtp_status_code_0, 0, status); + + smtp->_responseStatus = status; + + if ((status.statusCode > 0 && status.statusCode == statusCode) || + (smtp->_smtp_cmd == esp_mail_smtp_cmd_start_tls && status.statusCode == esp_mail_smtp_status_code_220) || + (canForward && statusCode == esp_mail_smtp_status_code_250 && status.statusCode == esp_mail_smtp_status_code_251) + + ) + { + ret = true; + } + + if (strlen(response) >= minResLen) + { +#if !defined(SILENT_MODE) + if (smtp->_debug) + { + if (!smtp->_customCmdResCallback) + { + appendDebugTag(s, esp_mail_debug_tag_type_server, true); + if (smtp->_responseStatus.statusCode != esp_mail_smtp_status_code_334) + s += response; + else + { + // base64 encoded server challenge message + size_t olen = 0; + char *decoded = (char *)decodeBase64((const unsigned char *)status.text.c_str(), status.text.length(), &olen); + if (decoded && olen > 0) + { + s.append(decoded, olen); + err = decoded; + } + + // release memory + freeMem(&decoded); + } + esp_mail_debug_print(s.c_str(), true); + } + } + +#endif + r.clear(); + } + + if (smtp->_customCmdResCallback && (smtp->_smtp_cmd == esp_mail_smtp_command::esp_mail_smtp_cmd_initial_state || smtp->_smtp_cmd == esp_mail_smtp_command::esp_mail_smtp_cmd_custom)) + { + struct esp_mail_smtp_response_status_t res = status; + res.text = response; + smtp->_customCmdResCallback(res); + } + + completedResponse = smtp->_responseStatus.statusCode > 0 && status.text.length() > minResLen; + + if (smtp->_smtp_cmd == esp_mail_smtp_command::esp_mail_smtp_cmd_auth_xoauth2 && smtp->_responseStatus.statusCode == esp_mail_smtp_status_code_334) + { + if (isOAuthError(response, readLen, chunkIndex, 4)) + { + smtp->_responseStatus.text = err; + smtp->_responseStatus.errorCode = SMTP_STATUS_XOAUTH2_AUTH_FAILED; + ret = false; + } + } + + chunkIndex++; + + if (smtp->_chunkedEnable && smtp->_smtp_cmd == esp_mail_smtp_command::esp_mail_smtp_cmd_chunk_termination) + completedResponse = smtp->_chunkCount == chunkIndex; + } + + // release memory + freeMem(&response); + } + } + + if (!ret && !smtp->_customCmdResCallback) + handleSMTPError(smtp, errCode, false); + } + + return ret; +} + +void ESP_Mail_Client::getResponseStatus(const char *buf, esp_mail_smtp_status_code statusCode, int beginPos, struct esp_mail_smtp_response_status_t &status) +{ + if (statusCode > esp_mail_smtp_status_code_0) + { + int codeLength = 3; + int textLength = strlen(buf) - codeLength - 1; + + if ((int)strlen(buf) > codeLength && (buf[codeLength] == ' ' || buf[codeLength] == '-') && textLength > 0) + { + char *tmp = nullptr; + tmp = allocMem(codeLength + 1); + memcpy(tmp, &buf[0], codeLength); + + int code = atoi(tmp); + + // release memory + freeMem(&tmp); + + if (buf[codeLength] == ' ') + status.statusCode = code; + + int i = codeLength + 1; + + // We will collect the status text starting from status code 334 and 4xx + // The status text of 334 will be used for debugging display of the base64 server challenge + if (code == esp_mail_smtp_status_code_334 || code >= esp_mail_smtp_status_code_421) + { + // find the next sp + while (i < (int)strlen(buf) && buf[i] != ' ') + i++; + + // if sp found, set index to the next pos, otherwise set index to num length + 1 + i = (i < (int)strlen(buf) - 1) ? i + 1 : codeLength + 1; + + tmp = allocMem(textLength + 1); + memcpy(tmp, &buf[i], strlen(buf) - i - 1); + status.text += tmp; + // release memory + freeMem(&tmp); + } + } + } +} + +void ESP_Mail_Client::uploadReport(const char *filename, uint32_t pgAddr, int progress) +{ + if (pgAddr == 0) + return; + + int *lastProgress = addrTo(pgAddr); + + printProgress(progress, *lastProgress); +} + +MB_String ESP_Mail_Client::getMIMEBoundary(size_t len) +{ + MB_String tmp = boundary_table; + char *buf = allocMem(len); + if (len) + { + --len; + buf[0] = tmp[0]; + buf[1] = tmp[1]; + for (size_t n = 2; n < len; n++) + { + int key = rand() % (int)(tmp.length() - 1); + buf[n] = tmp[key]; + } + buf[len] = '\0'; + } + MB_String s = buf; + // release memory + freeMem(&buf); + return s; +} + +int ESP_Mail_Client::chunkAvailable(SMTPSession *smtp, esp_mail_smtp_send_base64_data_info_t &data_info) +{ + if (!data_info.rawPtr) + { + int fileSize = mbfs->size(mbfs_type data_info.storageType); + if (!fileSize) + { + errorStatusCB(smtp, this->imap, MB_FS_ERROR_FILE_IO_ERROR, false); + return -1; + } + + return mbfs->available(mbfs_type data_info.storageType); + } + + return data_info.size - data_info.dataIndex; +} + +int ESP_Mail_Client::getChunk(SMTPSession *smtp, esp_mail_smtp_send_base64_data_info_t &data_info, unsigned char *rawChunk, bool base64) +{ + int available = chunkAvailable(smtp, data_info); + + if (available <= 0) + return available; + + size_t size = base64 ? 3 : 4; + + if (data_info.dataIndex + size > data_info.size) + size = data_info.size - data_info.dataIndex; + + if (!data_info.rawPtr) + { + + int readLen = mbfs->read(mbfs_type data_info.storageType, rawChunk, size); + + if (readLen >= 0) + data_info.dataIndex += readLen; + + return readLen; + } + + if (data_info.flashMem) + memcpy_P(rawChunk, data_info.rawPtr + data_info.dataIndex, size); + else + memcpy(rawChunk, data_info.rawPtr + data_info.dataIndex, size); + + data_info.dataIndex += size; + + return size; +} + +void ESP_Mail_Client::closeChunk(esp_mail_smtp_send_base64_data_info_t &data_info) +{ + if (!data_info.rawPtr) + { + mbfs->close(mbfs_type data_info.storageType); + } +} + +bool ESP_Mail_Client::sendBase64(SMTPSession *smtp, SMTP_Message *msg, esp_mail_smtp_send_base64_data_info_t &data_info, bool base64, bool report) +{ + int size = chunkAvailable(smtp, data_info); + + if (size <= 0) + return false; + + data_info.size = size; + + bool ret = false; + + uint32_t addr = altProgressPtr(smtp); + + size_t chunkSize = (BASE64_CHUNKED_LEN * UPLOAD_CHUNKS_NUM) + (2 * UPLOAD_CHUNKS_NUM); + int bufIndex = 0; + bool dataReady = false; + int encodedCount = 0; + int read = 0; + + if (!base64) + { + if (data_info.size < chunkSize) + chunkSize = data_info.size; + } + + uint8_t *buf = allocMem(chunkSize); + memset(buf, 0, chunkSize); + + uint8_t *rawChunk = allocMem(base64 ? 3 : 4); + + if (report) + uploadReport(data_info.filename, addr, data_info.dataIndex / data_info.size); + + int min = base64 ? 3 : 1; + + while (chunkAvailable(smtp, data_info)) + { + + if (chunkAvailable(smtp, data_info) >= min) + { + + read = getChunk(smtp, data_info, rawChunk, base64); + + if (!read) + goto ex; + + getBuffer(base64, buf, rawChunk, encodedCount, bufIndex, dataReady, read, chunkSize); + + if (dataReady) + { + + if (!sendBDAT(smtp, msg, base64 ? bufIndex : bufIndex + 1, false)) + goto ex; + + if (!altSendData(buf, base64 ? bufIndex : bufIndex + 1, smtp, msg, false, false, esp_mail_smtp_cmd_undefined, esp_mail_smtp_status_code_0, SMTP_STATUS_UNDEFINED)) + goto ex; + + memset(buf, 0, chunkSize); + bufIndex = 0; + } + + if (report) + uploadReport(data_info.filename, addr, 100 * data_info.dataIndex / data_info.size); + } + else if (base64) + { + read = getChunk(smtp, data_info, rawChunk, base64); + if (!read) + goto ex; + } + } + + closeChunk(data_info); + + if (base64) + { + if (bufIndex > 0) + { + if (!sendBDAT(smtp, msg, bufIndex, false)) + goto ex; + + if (!altSendData(buf, bufIndex, smtp, msg, false, false, esp_mail_smtp_cmd_undefined, esp_mail_smtp_status_code_0, SMTP_STATUS_UNDEFINED)) + goto ex; + } + + if (read) + { + memset(buf, 0, chunkSize); + bufIndex = 0; + buf[bufIndex++] = b64_index_table[rawChunk[0] >> 2]; + if (read == 1) + { + buf[bufIndex++] = b64_index_table[(rawChunk[0] & 0x03) << 4]; + buf[bufIndex++] = '='; + } + else + { + buf[bufIndex++] = b64_index_table[((rawChunk[0] & 0x03) << 4) | (rawChunk[1] >> 4)]; + buf[bufIndex++] = b64_index_table[(rawChunk[1] & 0x0f) << 2]; + } + buf[bufIndex++] = '='; + + if (!sendBDAT(smtp, msg, bufIndex, false)) + goto ex; + + if (!altSendData(buf, bufIndex, smtp, msg, false, false, esp_mail_smtp_cmd_undefined, esp_mail_smtp_status_code_0, SMTP_STATUS_UNDEFINED)) + goto ex; + } + } + + ret = true; + + if (report) + uploadReport(data_info.filename, addr, 100); + +ex: + // release memory + freeMem(&buf); + freeMem(&rawChunk); + + if (!ret) + closeChunk(data_info); + + return ret; +} + +void ESP_Mail_Client::getBuffer(bool base64, uint8_t *out, uint8_t *in, int &encodedCount, int &bufIndex, bool &dataReady, int &size, size_t chunkSize) +{ + if (base64) + { + size = 0; + out[bufIndex++] = b64_index_table[in[0] >> 2]; + out[bufIndex++] = b64_index_table[((in[0] & 0x03) << 4) | (in[1] >> 4)]; + out[bufIndex++] = b64_index_table[((in[1] & 0x0f) << 2) | (in[2] >> 6)]; + out[bufIndex++] = b64_index_table[in[2] & 0x3f]; + + encodedCount += 4; + + if (encodedCount == BASE64_CHUNKED_LEN) + { + if (bufIndex + 1 < (int)chunkSize) + { + out[bufIndex++] = 0x0d; + out[bufIndex++] = 0x0a; + } + encodedCount = 0; + } + + dataReady = bufIndex >= (int)chunkSize - 4; + } + else + { + memcpy(out + bufIndex, in, size); + bufIndex += size; + + if (bufIndex + 1 == BASE64_CHUNKED_LEN) + { + if (bufIndex + 2 < (int)chunkSize) + { + out[bufIndex++] = 0x0d; + out[bufIndex++] = 0x0a; + } + } + + dataReady = bufIndex + 1 >= (int)chunkSize - size; + } +} + +MB_FS *ESP_Mail_Client::getMBFS() +{ + return mbfs; +} + +SMTPSession::SMTPSession(Client *client) +{ + setClient(client); +} + +SMTPSession::SMTPSession() +{ +} + +SMTPSession::~SMTPSession() +{ + closeSession(); +} + +bool SMTPSession::connect(Session_Config *session_config, bool login) +{ + _sessionSSL = false; + _sessionLogin = login; + + if (session_config) + session_config->clearPorts(); + + this->_customCmdResCallback = NULL; + + int ptr = toAddr(*session_config); + session_config->addPtr(&_configPtrList, ptr); + + if (!handleConnection(session_config, _sessionSSL)) + return false; + + if (!_sessionLogin) + return true; + + _loginStatus = MailClient.smtpAuth(this, _sessionSSL); + + return _loginStatus; +} + +bool SMTPSession::mLogin(MB_StringPtr email, MB_StringPtr password, bool isToken) +{ + if (_loginStatus) + return true; + + if (!MailClient.sessionExisted(this)) + return false; + + _session_cfg->login.email = email; + + _session_cfg->login.accessToken.clear(); + _session_cfg->login.password.clear(); + + if (isToken) + _session_cfg->login.accessToken = password; + else + _session_cfg->login.password = password; + + _loginStatus = MailClient.smtpAuth(this, _sessionSSL); + + return _loginStatus; +} + +bool SMTPSession::isAuthenticated() +{ + return _authenticated; +} + +bool SMTPSession::isLoggedIn() +{ + return _loginStatus; +} + +int SMTPSession::customConnect(Session_Config *session_config, smtpResponseCallback callback, int commandID) +{ + this->_customCmdResCallback = callback; + + if (commandID > -1) + this->_commandID = commandID; + else + this->_commandID++; + + bool ssl = false; + if (!handleConnection(session_config, ssl)) + return -1; + + return this->_responseStatus.statusCode; +} + +bool SMTPSession::handleConnection(Session_Config *session_config, bool &ssl) +{ + _session_cfg = session_config; + + if (!client.isInitialized()) + return MailClient.handleSMTPError(this, TCP_CLIENT_ERROR_NOT_INITIALIZED); + + // Resources are also released if network disconnected. + if (!MailClient.reconnect(this)) + return false; + + // Close previous connection first to free resources. + MailClient.closeTCPSession(this); + + _session_cfg = session_config; + + MailClient.setCert(_session_cfg, _session_cfg->certificate.cert_data); + + ssl = false; + + if (!connect(ssl)) + { + MailClient.closeTCPSession(this); + return false; + } + + return true; +} + +bool SMTPSession::connect(bool &ssl) +{ + if (!MailClient.reconnect(this)) + return false; + + ssl = false; + _secure = true; + bool secureMode = true; + + MB_String s; + + client.rxBufDivider = 16; // minimum rx buffer for smtp status response + client.txBufDivider = 8; // medium tx buffer for faster attachment/inline data transfer + + MailClient.preparePortFunction(_session_cfg, true, _secure, secureMode, ssl); + +#if !defined(SILENT_MODE) + MailClient.printLibInfo(this); +#endif + + MailClient.prepareTime(_session_cfg, this); + + MailClient.setSecure(client, _session_cfg); + + if (!MailClient.beginConnection(_session_cfg, this, secureMode)) + return false; + + // server connected +#if !defined(SILENT_MODE) + if (!_customCmdResCallback) + { + + MailClient.printDebug(this, + esp_mail_dbg_str_4 /* "SMTP server connected" */, + esp_mail_cb_str_12 /* "SMTP server connected, wait for greeting..." */, + esp_mail_debug_tag_type_client, + true, + false); + } +#endif + + client.setTimeout(tcpTimeout); + + // expected success status code 220 for ready to service + // expected failure status code 421 + if (!MailClient.handleSMTPResponse(this, esp_mail_smtp_cmd_initial_state, esp_mail_smtp_status_code_220, SMTP_STATUS_SMTP_GREETING_GET_RESPONSE_FAILED)) + return false; + + return true; +} + +int SMTPSession::mSendCustomCommand(MB_StringPtr cmd, smtpResponseCallback callback, int commandID) +{ + _customCmdResCallback = callback; + + if (commandID > -1) + _commandID = commandID; + else + _commandID++; + + MB_String _cmd = cmd; + + if (MailClient.smtpSend(this, _cmd.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return -1; + + if (!MailClient.handleSMTPResponse(this, esp_mail_smtp_cmd_custom, esp_mail_smtp_status_code_0, SMTP_STATUS_SEND_CUSTOM_COMMAND_FAILED)) + return -1; + + bool tlsCmd = false; + for (int i = esp_mail_auth_capability_plain; i < esp_mail_auth_capability_maxType; i++) + { + if (MailClient.strposP(_cmd.c_str(), smtp_auth_capabilities[i].text, 0) > -1) + { + if (i == esp_mail_auth_capability_starttls) + tlsCmd = true; + else + _waitForAuthenticate = true; + } + } + + if (MailClient.strposP(_cmd.c_str(), smtp_commands[esp_mail_smtp_command_quit].text, 0, false) > -1) + { + _authenticated = false; + _waitForAuthenticate = false; + } + + if (_waitForAuthenticate && _responseStatus.statusCode == esp_mail_smtp_status_code_235) + { + _authenticated = true; + _waitForAuthenticate = false; + _loginStatus = true; + } + + if (tlsCmd) + { + bool verify = false; + + if (_session_cfg) + verify = _session_cfg->certificate.verify; + + if (!client.connectSSL(verify)) + return false; + + // set the secure mode + if (_session_cfg) + { + // We reset the prefer connection mode in case user set it. + _session_cfg->secure.startTLS = false; + _session_cfg->secure.mode = esp_mail_secure_mode_undefined; + } + + _secure = true; + } + + return this->_responseStatus.statusCode; +} + +bool SMTPSession::mSendData(MB_StringPtr data) +{ + + MB_String _data = data; + + if (MailClient.smtpSend(this, _data.c_str(), false) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return false; + + return true; +} + +bool SMTPSession::mSendData(uint8_t *data, size_t size) +{ + + if (MailClient.smtpSend(this, data, size) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return false; + + return true; +} + +void SMTPSession::debug(int level) +{ + if (level > esp_mail_debug_level_none) + { + if (level > esp_mail_debug_level_basic && level < esp_mail_debug_level_maintainer) + level = esp_mail_debug_level_basic; + _debugLevel = level; + _debug = true; + client.setDebugLevel(level); + } + else + { + _debugLevel = esp_mail_debug_level_none; + _debug = false; + client.setDebugLevel(0); + } +} + +String SMTPSession::errorReason() +{ + String s = MailClient.errorReason(true, _responseStatus.errorCode, ""); + return s; +} + +int SMTPSession::statusCode() +{ + return _responseStatus.statusCode; +} + +String SMTPSession::statusMessage() +{ + return _responseStatus.text.c_str(); +} + +int SMTPSession::errorCode() +{ + return _responseStatus.errorCode; +} + +bool SMTPSession::closeSession() +{ + + if (!connected()) + return false; + + _cbData._sentSuccess = _sentSuccessCount; + _cbData._sentFailed = _sentFailedCount; + +#if !defined(SILENT_MODE) + MailClient.printDebug(this, + esp_mail_cb_str_7 /* "Closing the session..." */, + esp_mail_dbg_str_11 /* "terminate the SMTP session" */, + esp_mail_debug_tag_type_client, + true, + false); +#endif + + bool ret = true; + + if (_loginStatus) + { + +/* Sign out */ +#if !defined(ESP8266) + + // QUIT command asks SMTP server to close the TCP session. + // The connection may drop immediately. + + // There is memory leaks bug in ESP8266 BearSSLWiFiClientSecure class when the remote server + // drops the connection. + + ret = MailClient.smtpSend(this, smtp_commands[esp_mail_smtp_command_quit].text, true) > 0; + + // This may return false due to connection drops before get any response. + + // expected success status code 221 + // expected error status code 500 + MailClient.handleSMTPResponse(this, esp_mail_smtp_cmd_logout, esp_mail_smtp_status_code_221, SMTP_STATUS_SEND_BODY_FAILED); + + if (_responseStatus.statusCode == esp_mail_smtp_status_code_500) + return false; +#endif + + if (ret) + { + +#if !defined(SILENT_MODE) + if (_sentSuccessCount > 0) + { + MailClient.printDebug(this, + esp_mail_cb_str_13 /* "Message sent successfully" */, + esp_mail_dbg_str_12 /* "message sent successfully" */, + esp_mail_debug_tag_type_client, + true, + false); + } + + if (_statusCallback) + MailClient.callBackSendNewLine(this, true); +#endif + + _authenticated = false; + _waitForAuthenticate = false; + } + } + +#if !defined(SILENT_MODE) + if (_statusCallback) + sendingResult.clear(); +#endif + + return MailClient.handleSMTPError(this, 0, ret); +} + +bool SMTPSession::connected() +{ + return client.connected(); +} + +void SMTPSession::callback(smtpStatusCallback smtpCallback) +{ + _statusCallback = smtpCallback; +} + +SMTP_Status SMTPSession::status() +{ + return _cbData; +} + +void SMTPSession::setSystemTime(time_t ts, float gmtOffset) +{ + MailClient.Time.setTimestamp(ts, gmtOffset); +} + +void SMTPSession::keepAlive(int tcpKeepIdleSeconds, int tcpKeepIntervalSeconds, int tcpKeepCount) +{ + this->client.keepAlive(tcpKeepIdleSeconds, tcpKeepIntervalSeconds, tcpKeepCount); +} + +bool SMTPSession::isKeepAlive() +{ + return this->client.isKeepAlive(); +} + +void SMTPSession::setTCPTimeout(unsigned long timeoutSec) +{ + tcpTimeout = timeoutSec; +} + +void SMTPSession::setClient(Client *client) +{ + this->client.setClient(client); +} + +void SMTPSession::setGSMClient(Client *client, void *modem, const char *pin, const char *apn, const char *user, const char *password) +{ + this->client.setGSMClient(client, modem, pin, apn, user, password); +} + +void SMTPSession::networkConnectionRequestCallback(NetworkConnectionRequestCallback networkConnectionCB) +{ + this->client.networkConnectionRequestCallback(networkConnectionCB); +} + +void SMTPSession::networkStatusRequestCallback(NetworkStatusRequestCallback networkStatusCB) +{ + this->client.networkStatusRequestCallback(networkStatusCB); +} + +void SMTPSession::setNetworkStatus(bool status) +{ + this->client.setNetworkStatus(status); + MailClient.networkStatus = status; +} + +void SMTPSession::setSSLBufferSize(int rx, int tx) +{ + this->client.setIOBufferSize(rx, tx); +} + +SMTP_Status::SMTP_Status() +{ +} + +SMTP_Status::~SMTP_Status() +{ + empty(); +} + +const char *SMTP_Status::info() +{ + return _info.c_str(); +} + +bool SMTP_Status::success() +{ + return _success; +} + +size_t SMTP_Status::completedCount() +{ + return _sentSuccess; +} + +size_t SMTP_Status::failedCount() +{ + return _sentFailed; +} + +void SMTP_Status::empty() +{ + _info.clear(); +} + +#endif + +#endif /* ESP_MAIL_SMTP_H */ diff --git a/lib/libesp32/ESP-Mail-Client/src/ESP_Mail_TCPClient.h b/lib/libesp32/ESP-Mail-Client/src/ESP_Mail_TCPClient.h new file mode 100644 index 000000000..9302f6d4e --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/ESP_Mail_TCPClient.h @@ -0,0 +1,1093 @@ +/** + * + * The Network Upgradable Arduino Secure TCP Client Class, ESP_Mail_TCPClient.h v1.0.1 + * + * Created August 27, 2023 + * + * The MIT License (MIT) + * Copyright (c) 2023 K. Suwatchai (Mobizt) + * + * + * Permission is hereby granted, free of charge, to any person returning a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef ESP_MAIL_TCPCLIENT_H +#define ESP_MAIL_TCPCLIENT_H + +#include "ESP_Mail_Client_Version.h" +#if !VALID_VERSION_CHECK(30409) +#error "Mixed versions compilation." +#endif + +#pragma GCC diagnostic ignored "-Wunused-variable" +#pragma GCC diagnostic ignored "-Wdelete-non-virtual-dtor" + +#include "ESP_Mail_Const.h" + +#if defined(ESP32) && (defined(ENABLE_SMTP) || defined(ENABLE_IMAP)) +#include "IPAddress.h" +#include "lwip/sockets.h" +#endif + +#if defined(ESP32) + +#if defined(ESP_MAIL_WIFI_IS_AVAILABLE) +#define WIFI_HAS_HOST_BY_NAME +#endif +#include "extras/WiFiClientImpl.h" +#define BASE_WIFICLIENT WiFiClientImpl + +#elif defined(ESP_MAIL_WIFI_IS_AVAILABLE) +#include "WiFiClient.h" +#define BASE_WIFICLIENT WiFiClient +#endif + +#include "SSLClient/ESP_SSLClient.h" + +class ESP_Mail_TCPClient +{ +public: + ESP_Mail_TCPClient() + { +#if !defined(ESP_MAIL_DISABLE_SSL) + _tcp_client = new ESP_SSLClient(); +#endif + } + + ~ESP_Mail_TCPClient() + { + clear(); +#if !defined(ESP_MAIL_DISABLE_SSL) + if (_tcp_client) + delete _tcp_client; + _tcp_client = nullptr; +#endif + } + + /** + * Set the client. + * @param client The Client interface. + */ + void setClient(Client *client) + { + clear(); + _basic_client = client; + _client_type = esp_mail_client_type_external_basic_client; + } + + /** Assign TinyGsm Clients. + * + * @param client The pointer to TinyGsmClient. + * @param modem The pointer to TinyGsm modem object. Modem should be initialized and/or set mode before transfering data + * @param pin The SIM pin. + * @param apn The GPRS APN (Access Point Name). + * @param user The GPRS user. + * @param password The GPRS password. + */ + void setGSMClient(Client *client, void *modem = nullptr, const char *pin = nullptr, const char *apn = nullptr, const char *user = nullptr, const char *password = nullptr) + { +#if defined(ESP_MAIL_GSM_MODEM_IS_AVAILABLE) + _pin = pin; + _apn = apn; + _user = user; + _password = password; + _modem = modem; + _client_type = esp_mail_client_type_external_gsm_client; + _basic_client = client; +#endif + } + + /** + * Set Root CA certificate to verify. + * @param caCert The certificate. + */ + void setCACert(const char *caCert) + { +#if !defined(ESP_MAIL_DISABLE_SSL) + if (caCert) + { + if (_x509) + delete _x509; + + _x509 = new X509List(caCert); + _tcp_client->setTrustAnchors(_x509); + + setCertType(esp_mail_cert_type_data); + setTA(true); + } + else + { + setCertType(esp_mail_cert_type_none); + setInSecure(); + } +#endif + } + + /** + * Set Root CA certificate to verify. + * @param certFile The certificate file path. + * @param storageType The storage type mb_fs_mem_storage_type_flash or mb_fs_mem_storage_type_sd. + * @return true when certificate loaded successfully. + */ + bool setCertFile(const char *certFile, mb_fs_mem_storage_type storageType) + { +#if !defined(ESP_MAIL_DISABLE_SSL) + if (!_mbfs) + return false; + + if (_clock_ready && strlen(certFile) > 0) + { + MB_String filename = certFile; + if (filename.length() > 0) + { + if (filename[0] != '/') + filename.prepend('/'); + } + + int len = _mbfs->open(filename, storageType, mb_fs_open_mode_read); + if (len > -1) + { + uint8_t *der = (uint8_t *)_mbfs->newP(len); + if (_mbfs->available(storageType)) + _mbfs->read(storageType, der, len); + _mbfs->close(storageType); + + if (_x509) + delete _x509; + + _x509 = new X509List(der, len); + _tcp_client->setTrustAnchors(_x509); + setTA(true); + _mbfs->delP(&der); + + setCertType(esp_mail_cert_type_file); + } + } +#endif + + return getCertType() == esp_mail_cert_type_file; + } + + /** + * Set TCP connection time out in seconds. + * @param timeoutSec The time out in seconds. + */ + void setTimeout(uint32_t timeoutSec) + { + _tcp_client->setTimeout(timeoutSec); + } + + /** Set the BearSSL IO buffer size. + * + * @param rx The BearSSL receive buffer size in bytes. + * @param tx The BearSSL trasmit buffer size in bytes. + */ + void setIOBufferSize(int rx, int tx) + { + _rx_size = rx; + _tx_size = tx; + } + + /** + * Get the ethernet link status. + * @return true for link up or false for link down. + */ + bool ethLinkUp() + { + bool ret = false; + +#if !defined(ESP_MAIL_DISABLE_NATIVE_ETHERNET) && (defined(ENABLE_IMAP) || defined(ENABLE_SMTP)) + +#if defined(ESP_MAIL_ETH_IS_AVAILABLE) + +#if defined(ESP32) + if (validIP(ETH.localIP())) + { + ETH.linkUp(); + ret = true; + } +#elif defined(ESP8266) + +#if defined(ENABLE_SMTP) || defined(ENABLE_IMAP) + if (!_session_config) + return false; +#endif + +#if defined(ESP8266) && defined(ESP8266_CORE_SDK_V3_X_X) + +#if defined(INC_ENC28J60_LWIP) + if (_session_config->spi_ethernet_module.enc28j60) + { + ret = _session_config->spi_ethernet_module.enc28j60->status() == WL_CONNECTED; + goto ex; + } +#endif +#if defined(INC_W5100_LWIP) + if (_session_config->spi_ethernet_module.w5100) + { + ret = _session_config->spi_ethernet_module.w5100->status() == WL_CONNECTED; + goto ex; + } +#endif +#if defined(INC_W5500_LWIP) + if (_session_config->spi_ethernet_module.w5500) + { + ret = _session_config->spi_ethernet_module.w5500->status() == WL_CONNECTED; + goto ex; + } +#endif +#elif defined(MB_ARDUINO_PICO) + +#endif + + return ret; + +#if defined(INC_ENC28J60_LWIP) || defined(INC_W5100_LWIP) || defined(INC_W5500_LWIP) + ex: +#endif + // workaround for ESP8266 Ethernet + delayMicroseconds(0); +#endif + +#endif + +#endif + + return ret; + } + + /** + * Checking for valid IP. + * @return true for valid. + */ + bool validIP(IPAddress ip) + { + char buf[16]; + sprintf(buf, "%u.%u.%u.%u", ip[0], ip[1], ip[2], ip[3]); + return strcmp(buf, "0.0.0.0") != 0; + } + + /** + * Ethernet DNS workaround. + */ + void ethDNSWorkAround() + { + +#if !defined(ESP_MAIL_DISABLE_NATIVE_ETHERNET) && (defined(ENABLE_SMTP) || defined(ENABLE_IMAP)) + if (!_session_config) + return; + +#if defined(ESP8266_CORE_SDK_V3_X_X) + +#if defined(INC_ENC28J60_LWIP) + if (_session_config->spi_ethernet_module.enc28j60) + goto ex; +#endif +#if defined(INC_W5100_LWIP) + if (_session_config->spi_ethernet_module.w5100) + goto ex; +#endif +#if defined(INC_W5500_LWIP) + if (_session_config->spi_ethernet_module.w5500) + goto ex; +#endif + +#elif defined(MB_ARDUINO_PICO) + +#endif + + return; + +#if defined(INC_ENC28J60_LWIP) || defined(INC_W5100_LWIP) || defined(INC_W5500_LWIP) + ex: +#if defined(ESP_MAIL_WIFI_IS_AVAILABLE) + BASE_WIFICLIENT client; + client.connect(_session_config->server.host_name.c_str(), _session_config->server.port); + client.stop(); +#endif +#endif + +#endif + } + + /** + * Get the network status. + * @return true for connected or false for not connected. + */ + bool networkReady() + { + + // We will not invoke the network status request when device has built-in WiFi or Ethernet and it is connected. + if (_client_type == esp_mail_client_type_external_gsm_client) + { + _network_status = gprsConnected(); + if (!_network_status) + gprsConnect(); + } + else if (WiFI_CONNECTED || ethLinkUp()) + _network_status = true; + else if (_client_type == esp_mail_client_type_external_basic_client) + { + if (!_network_status_cb) + _last_error = 1; + else + _network_status_cb(); + } + + return _network_status; + } + + /** + * Reconnect the network. + */ + void networkReconnect() + { + + if (_client_type == esp_mail_client_type_external_basic_client) + { +#if defined(ESP_MAIL_HAS_WIFI_DISCONNECT) + // We can reconnect WiFi when device connected via built-in WiFi that supports reconnect + if (WiFI_CONNECTED) + { + WiFi.reconnect(); + return; + } + +#endif + + if (_network_connection_cb) + _network_connection_cb(); + } + else if (_client_type == esp_mail_client_type_external_gsm_client) + { + gprsDisconnect(); + gprsConnect(); + } + else if (_client_type == esp_mail_client_type_internal_basic_client) + { + +#if defined(ESP_MAIL_WIFI_IS_AVAILABLE) +#if defined(ESP32) || defined(ESP8266) + WiFi.reconnect(); +#else + if (_wifi_multi && _wifi_multi->credentials.size()) + _wifi_multi->reconnect(); +#endif +#endif + } + } + + /** + * Disconnect the network. + */ + void networkDisconnect() {} + + /** + * Get the Client type. + * @return The esp_mail_client_type enum value. + */ + esp_mail_client_type type() { return _client_type; } + + /** + * Get the Client initialization status. + * @return The initialization status. + */ + bool isInitialized() + { + bool rdy = true; +#if !defined(ESP_MAIL_WIFI_IS_AVAILABLE) + if (_client_type == esp_mail_client_type_external_basic_client && + (!_network_connection_cb || !_network_status_cb)) + rdy = false; + else if (_client_type != esp_mail_client_type_external_basic_client || + _client_type != esp_mail_client_type_external_gsm_client) + rdy = false; +#else + // assume external client is WiFiClient and network status request callback is not required + // when device was connected to network using on board WiFi + if (_client_type == esp_mail_client_type_external_basic_client && + (!_network_connection_cb || (!_network_status_cb && !WiFI_CONNECTED && !ethLinkUp()))) + { + rdy = false; + } + +#endif + + if (!rdy) + { +#if !defined(SILENT_MODE) && (defined(ENABLE_SMTP) || defined(ENABLE_IMAP)) + if (_debug_level > 0) + { + if (!_network_connection_cb) + esp_mail_debug_print_tag(esp_mail_error_client_str_2 /* "network connection callback is required" */, esp_mail_debug_tag_type_error, true); + if (!WiFI_CONNECTED && !ethLinkUp()) + { + if (!_network_status_cb) + esp_mail_debug_print_tag(esp_mail_error_client_str_3 /* "network connection status callback is required" */, esp_mail_debug_tag_type_error, true); + } + } +#endif + } + + return rdy; + } + + /** + * Set Root CA certificate to verify. + * @param name The host name. + * @param ip The ip address result. + * @return 1 for success or 0 for failed. + */ + int hostByName(const char *name, IPAddress &ip) + { +#if defined(ESP_MAIL_WIFI_IS_AVAILABLE) + return WiFi.hostByName(name, ip); +#else + return 1; +#endif + } + + /** + * Store the host name and port. + * @param host The host name to connect. + * @param port The port to connect. + * @return true. + */ + bool begin(const char *host, uint16_t port) + { + _host = host; + _port = port; +#if !defined(ESP_MAIL_DISABLE_SSL) + _tcp_client->setBufferSizes(_rx_size >= _minRXTXBufSize && _rx_size <= _maxRXBufSize ? _rx_size : _maxRXBufSize / rxBufDivider, + _tx_size >= _minRXTXBufSize && _tx_size <= _maxTXBufSize ? _tx_size : _maxTXBufSize / txBufDivider); +#endif + _last_error = 0; + return true; + } + + /** + * Start TCP connection using stored host name and port. + * @param secure The secure mode option. + * @param verify The Root CA certificate verification option. + * @return true for success or false for error. + */ + + bool connect(bool secured, bool verify) + { + bool ret = false; + +#if defined(ENABLE_SMTP) || defined(ENABLE_IMAP) + _last_error = 0; + +#if !defined(ESP_MAIL_DISABLE_SSL) + _tcp_client->enableSSL(secured); + setSecure(secured); + setVerify(verify); +#endif + + if (connected()) + { + flush(); + return true; + } + + if (!_basic_client) + { + if (_client_type == esp_mail_client_type_external_basic_client) + { + _last_error = 1; + return false; + } + else if (_client_type != esp_mail_client_type_external_gsm_client) + { +// Device has no built-in WiFi, external client required. +#if defined(ESP_MAIL_WIFI_IS_AVAILABLE) + _basic_client = new BASE_WIFICLIENT(); + _client_type = esp_mail_client_type_internal_basic_client; +#else + _last_error = 1; + return false; +#endif + } + } + +#if defined(ESP_MAIL_DISABLE_SSL) + _tcp_client = _basic_client; +#else + _tcp_client->setClient(_basic_client); +#endif + + if (!_tcp_client->connect(_host.c_str(), _port)) + return false; + +#if defined(ESP_MAIL_WIFI_IS_AVAILABLE) && (defined(ESP32) || defined(ESP8266) || defined(MB_ARDUINO_PICO)) + if (_client_type == esp_mail_client_type_internal_basic_client) + reinterpret_cast(_basic_client)->setNoDelay(true); +#endif + + // For TCP keepalive should work in ESP8266 core > 3.1.2. + // https://github.com/esp8266/Arduino/pull/8940 + + // Not currently supported by WiFiClientSecure in Arduino Pico core + + if (_client_type == esp_mail_client_type_internal_basic_client) + { + if (isKeepAliveSet()) + { +#if defined(ESP_MAIL_WIFI_IS_AVAILABLE) + +#if defined(ESP8266) + if (_tcpKeepIdleSeconds == 0 || _tcpKeepIntervalSeconds == 0 || _tcpKeepCount == 0) + reinterpret_cast(_basic_client)->disableKeepAlive(); + else + reinterpret_cast(_basic_client)->keepAlive(_tcpKeepIdleSeconds, _tcpKeepIntervalSeconds, _tcpKeepCount); + +#elif defined(ESP32) + + if (_tcpKeepIdleSeconds == 0 || _tcpKeepIntervalSeconds == 0 || _tcpKeepCount == 0) + { + _tcpKeepIdleSeconds = 0; + _tcpKeepIntervalSeconds = 0; + _tcpKeepCount = 0; + } + + bool success = setOption(TCP_KEEPIDLE, &_tcpKeepIdleSeconds) > -1 && + setOption(TCP_KEEPINTVL, &_tcpKeepIntervalSeconds) > -1 && + setOption(TCP_KEEPCNT, &_tcpKeepCount) > -1; + if (!success) + _isKeepAlive = false; +#endif + +#endif + } + } + + ret = connected(); + if (!ret) + stop(); +#endif + return ret; + } + + /** + * Upgrade the current connection by setting up the SSL and perform the SSL handshake. + * + * @param verify The Root CA certificate verification option + * @return operating result. + */ + + bool connectSSL(bool verify) + { +#if !defined(ESP_MAIL_DISABLE_SSL) + _tcp_client->setDebugLevel(2); + + bool ret = _tcp_client->connected(); + + if (ret) + { + setVerify(verify); + ret = _tcp_client->connectSSL(_host.c_str(), _port); + if (ret) + _secured = true; + } + + if (!ret) + stop(); + + return ret; +#endif + return false; + } + + /** + * Stop TCP connection. + */ + void stop() + { + if (_tcp_client) + _tcp_client->stop(); + } + + /** + * Get the TCP connection status. + * @return true for connected or false for not connected. + */ + bool connected() { return _tcp_client && _tcp_client->connected(); }; + + /** + * The TCP data write function. + * @param data The data to write. + * @param len The length of data to write. + * @return The size of data that was successfully written or 0 for error. + */ + int write(uint8_t *data, int len) + { + if (!_tcp_client) + return TCP_CLIENT_ERROR_NOT_INITIALIZED; + + if (!data) + return TCP_CLIENT_ERROR_SEND_DATA_FAILED; + + if (len == 0) + return TCP_CLIENT_ERROR_SEND_DATA_FAILED; + + if (!networkReady()) + return TCP_CLIENT_ERROR_NOT_CONNECTED; + + if (!connect(isSecure(), isVerify())) + return TCP_CLIENT_ERROR_CONNECTION_REFUSED; + + int toSend = _chunkSize; + int sent = 0; + while (sent < len) + { + if (sent + toSend > len) + toSend = len - sent; + + if ((int)_tcp_client->write(data + sent, toSend) != toSend) + return TCP_CLIENT_ERROR_SEND_DATA_FAILED; + + sent += toSend; + } + + return len; + } + + /** + * The TCP data send function. + * @param data The data to send. + * @return The size of data that was successfully sent or 0 for error. + */ + int send(const char *data) { return write((uint8_t *)data, strlen(data)); } + + /** + * The TCP data print function. + * @param data The data to print. + * @return The size of data that was successfully print or 0 for error. + */ + int print(const char *data) { return send(data); } + + /** + * The TCP data print function. + * @param data The data to print. + * @return The size of data that was successfully print or 0 for error. + */ + int print(int data) + { + char buf[64]; + memset(buf, 0, 64); + sprintf(buf, (const char *)FPSTR("%d"), data); + int ret = send(buf); + return ret; + } + + /** + * The TCP data print with new line function. + * @param data The data to print. + * @return The size of data that was successfully print or 0 for error. + */ + int println(const char *data) + { + int len = send(data); + if (len < 0) + return len; + int sz = send((const char *)FPSTR("\r\n")); + if (sz < 0) + return sz; + return len + sz; + } + + /** + * The TCP data print with new line function. + * @param data The data to print. + * @return The size of data that was successfully print or 0 for error. + */ + int println(int data) + { + char buf[64]; + memset(buf, 0, 64); + sprintf(buf, (const char *)FPSTR("%d\r\n"), data); + int ret = send(buf); + return ret; + } + + /** + * Get available data size to read. + * @return The avaiable data size. + */ + int available() + { + if (!_basic_client) + return TCP_CLIENT_ERROR_NOT_INITIALIZED; + + return _tcp_client->available(); + } + + /** + * The TCP data read function. + * @return The read value or -1 for error. + */ + int read() + { + if (!_basic_client) + return TCP_CLIENT_ERROR_NOT_INITIALIZED; + + return _tcp_client->read(); + } + + /** + * The TCP data read function. + * @param buf The data buffer. + * @param len The length of data that read. + * @return The size of data that was successfully read or negative value for error. + */ + int readBytes(uint8_t *buf, int len) + { + if (!_basic_client) + return TCP_CLIENT_ERROR_NOT_INITIALIZED; + + return _tcp_client->read(buf, len); + } + + /** + * The TCP data read function. + * @param buf The data buffer. + * @param len The length of data that read. + * @return The size of data that was successfully read or negative value for error. + */ + int readBytes(char *buf, int len) + { + return readBytes((uint8_t *)buf, len); + } + + /** + * Wait for all receive buffer data read. + */ + void flush() + { + if (_tcp_client) + _tcp_client->flush(); + } + + /** + * Set the network connection request callback. + * @param networkConnectionCB The callback function that handles the network connection. + */ + void networkConnectionRequestCallback(NetworkConnectionRequestCallback networkConnectionCB) + { + _network_connection_cb = networkConnectionCB; + } + + /** + * Set the network status request callback. + * @param networkStatusCB The callback function that calls the setNetworkStatus function to set the network status. + */ + void networkStatusRequestCallback(NetworkStatusRequestCallback networkStatusCB) + { + _network_status_cb = networkStatusCB; + } + + /** + * Set the network status which should call in side the networkStatusRequestCallback function. + * @param status The status of network. + */ + void setNetworkStatus(bool status) + { + _network_status = status; + } + + void setMBFS(MB_FS *mbfs) { _mbfs = mbfs; } + +#if defined(ENABLE_SMTP) || defined(ENABLE_IMAP) + void setSession(Session_Config *session_config) + { + _session_config = session_config; + } +#endif + + void setClockReady(bool rdy) + { + _clock_ready = rdy; + } + + void setCertType(esp_mail_cert_type type) { _cert_type = type; } + + esp_mail_cert_type getCertType() { return _cert_type; } + + void setDebugLevel(int debug) { _debug_level = debug; } + + unsigned long tcpTimeout() + { + if (_tcp_client) + return 1000 * _tcp_client->getTimeout(); + return 0; + } + + void disconnect(){}; + + void keepAlive(int tcpKeepIdleSeconds, int tcpKeepIntervalSeconds, int tcpKeepCount) + { + _tcpKeepIdleSeconds = tcpKeepIdleSeconds; + _tcpKeepIntervalSeconds = tcpKeepIntervalSeconds; + _tcpKeepCount = tcpKeepCount; + _isKeepAlive = tcpKeepIdleSeconds > 0 && tcpKeepIntervalSeconds > 0 && tcpKeepCount > 0; + } + + bool isKeepAliveSet() { return _tcpKeepIdleSeconds > -1 && _tcpKeepIntervalSeconds > -1 && _tcpKeepCount > -1; }; + + bool isKeepAlive() { return _isKeepAlive; }; + + void clear() + { +#if !defined(ESP_MAIL_DISABLE_SSL) + if (_basic_client && _client_type == esp_mail_client_type_internal_basic_client) + { +#if defined(ESP_MAIL_WIFI_IS_AVAILABLE) + delete (BASE_WIFICLIENT *)_basic_client; +#else + delete _basic_client; +#endif + _basic_client = nullptr; + } +#else + _basic_client = nullptr; +#endif + _client_type = esp_mail_client_type_undefined; + } + + void setWiFi(esp_mail_wifi_credentials_t *wifi) { _wifi_multi = wifi; } + + bool gprsConnect() + { +#if defined(ESP_MAIL_GSM_MODEM_IS_AVAILABLE) + TinyGsm *gsmModem = (TinyGsm *)_modem; + if (gsmModem) + { + // Unlock your SIM card with a PIN if needed + if (_pin.length() && gsmModem->getSimStatus() != 3) + gsmModem->simUnlock(_pin.c_str()); + +#if defined(TINY_GSM_MODEM_XBEE) + // The XBee must run the gprsConnect function BEFORE waiting for network! + gsmModem->gprsConnect(_apn.c_str(), _user.c_str(), _password.c_str()); +#endif + +#if !defined(SILENT_MODE) && (defined(ENABLE_IMAP) || defined(ENABLE_SMTP)) + if (_debug_level > 0 && _last_error == 0) + esp_mail_debug_print_tag((const char *)MBSTRING_FLASH_MCR("Waiting for network..."), esp_mail_debug_tag_type_info, false); +#endif + if (!gsmModem->waitForNetwork()) + { +#if !defined(SILENT_MODE) && (defined(ENABLE_IMAP) || defined(ENABLE_SMTP)) + if (_debug_level > 0 && _last_error == 0) + esp_mail_debug_print_tag((const char *)MBSTRING_FLASH_MCR(" fail"), esp_mail_debug_tag_type_info, true, false); +#endif + _last_error = 1; + _network_status = false; + return false; + } + +#if !defined(SILENT_MODE) && (defined(ENABLE_IMAP) || defined(ENABLE_SMTP)) + if (_debug_level > 0 && _last_error == 0) + esp_mail_debug_print_tag((const char *)MBSTRING_FLASH_MCR(" success"), esp_mail_debug_tag_type_info, true, false); +#endif + + if (gsmModem->isNetworkConnected()) + { +#if !defined(SILENT_MODE) && (defined(ENABLE_IMAP) || defined(ENABLE_SMTP)) + if (_debug_level > 0 && _last_error == 0) + { + esp_mail_debug_print_tag((const char *)MBSTRING_FLASH_MCR("Connecting to "), esp_mail_debug_tag_type_info, false); + esp_mail_debug_print_tag(_apn.c_str(), esp_mail_debug_tag_type_info, false, false); + } +#endif + _network_status = gsmModem->gprsConnect(_apn.c_str(), _user.c_str(), _password.c_str()) && + gsmModem->isGprsConnected(); + +#if !defined(SILENT_MODE) && (defined(ENABLE_IMAP) || defined(ENABLE_SMTP)) + if (_debug_level > 0 && _last_error == 0) + { + if (_network_status) + esp_mail_debug_print_tag((const char *)MBSTRING_FLASH_MCR(" success"), esp_mail_debug_tag_type_info, true, false); + else + esp_mail_debug_print_tag((const char *)MBSTRING_FLASH_MCR(" fail"), esp_mail_debug_tag_type_info, true, false); + } +#endif + } + + if (!_network_status) + _last_error = 1; + + return _network_status; + } + +#endif + return false; + } + + bool gprsConnected() + { +#if defined(ESP_MAIL_GSM_MODEM_IS_AVAILABLE) + TinyGsm *gsmModem = (TinyGsm *)_modem; + _network_status = gsmModem && gsmModem->isGprsConnected(); +#endif + return _network_status; + } + + bool gprsDisconnect() + { +#if defined(ESP_MAIL_GSM_MODEM_IS_AVAILABLE) + TinyGsm *gsmModem = (TinyGsm *)_modem; + _network_status = gsmModem && gsmModem->gprsDisconnect(); +#endif + return !_network_status; + } + + bool gprsGetTime(int &year, int &month, int &day, int &hour, int &min, int &sec, float &timezone) + { +#if defined(ESP_MAIL_GSM_MODEM_IS_AVAILABLE) && defined(TINY_GSM_MODEM_HAS_TIME) + + if (!gprsConnected()) + return 0; + + TinyGsm *gsmModem = (TinyGsm *)_modem; + year = 0; + month = 0; + day = 0; + hour = 0; + min = 0; + sec = 0; + timezone = 0; + for (int8_t i = 5; i; i--) + { + if (gsmModem->getNetworkTime(&year, &month, &day, &hour, &min, &sec, &timezone)) + { + return true; + } + } +#endif + return false; + } + + int setOption(int option, int *value) + { +#if defined(ESP32) && defined(ESP_MAIL_WIFI_IS_AVAILABLE) + // Actually we wish to use setSocketOption directly but it is ambiguous in old ESP32 core v1.0.x.; + // Use setOption instead for old core support. + return reinterpret_cast(_basic_client)->setOption(option, value); +#endif + return 0; + } + + void setTA(bool hasTA) + { + _has_ta = hasTA; + } + + void setSecure(bool secure) + { + _secured = secure; + } + + void setInSecure() + { +#if !defined(ESP_MAIL_DISABLE_SSL) + _use_insecure = true; + setTA(false); +#endif + } + + void setVerify(bool verify) + { +#if !defined(ESP_MAIL_DISABLE_SSL) + if (_has_ta) + _use_insecure = !verify; + + if (_use_insecure) + _tcp_client->setInsecure(); +#endif + } + + bool isSecure() + { + return _secured; + } + + bool isVerify() + { + return !_use_insecure; + } + + int rxBufDivider = 16; + int txBufDivider = 32; + +private: + // lwIP TCP Keepalive idle in seconds. + int _tcpKeepIdleSeconds = -1; + // lwIP TCP Keepalive interval in seconds. + int _tcpKeepIntervalSeconds = -1; + // lwIP TCP Keepalive count. + int _tcpKeepCount = -1; + bool _isKeepAlive = false; + + uint16_t _bsslRxSize = 1024; + uint16_t _bsslTxSize = 1024; + const int _maxRXBufSize = 16384; // SSL full supported 16 kB + const int _maxTXBufSize = 16384; + const int _minRXTXBufSize = 512; +#if defined(ESP_MAIL_DISABLE_SSL) + Client *_tcp_client = nullptr; +#else + ESP_SSLClient *_tcp_client = nullptr; + X509List *_x509 = nullptr; +#endif + + MB_String _host; + uint16_t _port = 443; + + MB_FS *_mbfs = nullptr; + Client *_basic_client = nullptr; + esp_mail_wifi_credentials_t *_wifi_multi = nullptr; +#if defined(ENABLE_SMTP) || defined(ENABLE_IMAP) + Session_Config *_session_config = nullptr; +#endif + NetworkConnectionRequestCallback _network_connection_cb = NULL; + NetworkStatusRequestCallback _network_status_cb = NULL; +#if defined(ESP_MAIL_HAS_WIFIMULTI) + WiFiMulti *_multi = nullptr; +#endif +#if defined(ESP_MAIL_GSM_MODEM_IS_AVAILABLE) + MB_String _pin, _apn, _user, _password; + void *_modem = nullptr; +#endif + + bool _has_ta = false; + bool _secured = false; + bool _use_insecure = false; + int _debug_level = 0; + int _chunkSize = 1024; + bool _clock_ready = false; + int _last_error = 0; + volatile bool _network_status = false; + int _rx_size = -1, _tx_size = -1; + + esp_mail_cert_type _cert_type = esp_mail_cert_type_undefined; + esp_mail_client_type _client_type = esp_mail_client_type_undefined; +}; + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/HeapStat.h b/lib/libesp32/ESP-Mail-Client/src/HeapStat.h new file mode 100644 index 000000000..c6ed4e865 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/HeapStat.h @@ -0,0 +1,146 @@ +/** Memory usage info for debugging purpose + +#include "HeapStat.h" + +HeapStat heapInfo; + +void setup() +{ + Serial.begin(115200); +} + +void loop() +{ + // Other codes here + + // Collect memory info + heapInfo.collect(); + + // Print memory info + heapInfo.print(); + +} + +*/ + +#ifndef HEAP_STAT_H +#define HEAP_STAT_H + +#if defined(ESP8266) || defined(ESP32) +#ifndef MB_ARDUINO_ESP +#define MB_ARDUINO_ESP +#endif +#endif + +#if defined(ARDUINO_ARCH_RP2040) + +#if defined(ARDUINO_NANO_RP2040_CONNECT) +#ifndef MB_ARDUINO_NANO_RP2040_CONNECT +#define MB_ARDUINO_NANO_RP2040_CONNECT +#endif +#else +#ifndef MB_ARDUINO_PICO +#define MB_ARDUINO_PICO +#endif +#endif + +#endif + +#include "ESP_Mail_Client.h" + +class HeapStat +{ +private: + int current_heap = 0; + int first_round_heap = 0; + int min_heap = 0; + int max_heap = 0; + int diff_heap_from_first_round = 0; + int diff_heap_from_current_round = 0; + int _count = 0; + + int getFreeHeap() + { +#if defined(MB_ARDUINO_ESP) + return ESP.getFreeHeap(); +#elif defined(MB_ARDUINO_PICO) + return rp2040.getFreeHeap(); +#else + return 0; +#endif + } + +public: + HeapStat() {} + ~HeapStat() {} + + void reset() + { + current_heap = 0; + first_round_heap = 0; + min_heap = 0; + max_heap = 0; + diff_heap_from_first_round = 0; + diff_heap_from_current_round = 0; + _count = 0; + } + + void collect() + { + _count++; + + if (max_heap < getFreeHeap()) + max_heap = getFreeHeap(); + + if (min_heap == 0 || min_heap > getFreeHeap()) + min_heap = getFreeHeap(); + + if (first_round_heap == 0) + first_round_heap = getFreeHeap(); + + if (current_heap > 0) + { + diff_heap_from_first_round = getFreeHeap() - first_round_heap; + diff_heap_from_current_round = getFreeHeap() - current_heap; + } + + current_heap = getFreeHeap(); + } + + int current() + { + return current_heap; + } + + int min() + { + return min_heap; + } + + int max() + { + return max_heap; + } + + int diff1() + { + return diff_heap_from_first_round; + } + + int diffN() + { + return diff_heap_from_current_round; + } + + int count() + { + return _count; + } + + void print() + { + MailClient.printf("#### Heap Info\n#### Current: %d, Min: %d, Max: %d, Diff_1: %d, Diff_%d: %d\n", current(), min(), max(), diff1(), count(), diffN()); + } +}; + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/README.md b/lib/libesp32/ESP-Mail-Client/src/README.md new file mode 100644 index 000000000..8fe315876 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/README.md @@ -0,0 +1,3416 @@ +# ESP Mail Client Arduino Library + + +The description of the available functions in the current reease are shown below. + + +## Global functions + + +#### Sending Email through the SMTP server. + +param **`smtp`** The pointer to SMTP session object which holds the data and the TCP client. + +param **`msg`** The pointer to SMTP_Message class which contains the header, body, and attachments. + +param **`closeSession`** The option to Close the SMTP session after sent. + +return **`boolean`** The boolean value indicates the success of operation. + +```cpp +bool sendMail(SMTPSession *smtp, SMTP_Message *msg, bool closeSession = true); +``` + + + +#### Append message to the mailbox + +param **`imap`** The pointer to IMAP sesssion object which holds the data and the TCP client. + +param **`msg`** The pointer to SMTP_Message class which contains the header, body, and attachments. + +param **`lastAppend`** The last message to append (optional). In case MULTIAPPEND extension + +is supported, set this to false will append messages in single APPEND command. + +param **`flags`** The flags to set to this message. + + param **`dateTime`** The date/time to set to this message (optional). + +return **`boolean`** The boolean value indicates the success of operation. + +```cpp +bool appendMessage(IMAPSession *imap, SMTP_Message *msg, T flags = ""); +``` + + +#### Reading Email through IMAP server. + +param **`imap`** The pointer to IMAP sesssion object which holds the data and the TCP client. + +param **`closeSession`** The option to close the IMAP session after fetching or searching the Email. + +return **`boolean`** The boolean value indicates the success of operation. + +```cpp +bool readMail(IMAPSession *imap, bool closeSession = true); +``` + + + + + +#### Set the argument to the Flags for the specified message. + +param **`imap`** The pointer to IMAP session object which holds the data and the TCP client. + +param **`msgUID`** The UID of the message. + +param **`flags`** The flag list to set. + +param **`closeSession`** The option to close the IMAP session after set flag. + +param **`silent`** The option to ignore the response. + +param **`modsequence`** The int32_t option for UNCHANGESINCE conditional test. + +return **`boolean`** The boolean value indicates the success of operation. + +The modsequence value can be used only if IMAP server supports Conditional STORE extension and the selected mailbox supports modsequences. + +```cpp +bool setFlag(IMAPSession *imap, int msgUID, flags, bool closeSession, bool silent = false, int32_t modsequence = -1); +``` + + + + + +#### Set the argument to the Flags for the specified message. + +param **`imap`** The pointer to IMAP session object which holds the data and the TCP client. + +param **`sequenceSet`** The sequence set string i.g., unique identifier (UID) or +message sequence number or ranges of UID or sequence number. + +param **`UID`** The option for sequenceSet whether it is UID or message sequence number. + +param **`flags`** The flag list to set. + +param **`closeSession`** The option to close the IMAP session after set flag. + +param **`silent`** The option to ignore the response. + +param **`modsequence`** The int32_t option for UNCHANGESINCE conditional test. + +return **`boolean`** The boolean value indicates the success of operation. + +The modsequence value can be used only if IMAP server supports Conditional STORE extension and the selected mailbox supports modsequences. + +```cpp +bool setFlag(IMAPSession *imap, sequenceSet, bool UID, flags, bool closeSession, bool silent = false, int32_t modsequence = -1); +``` + + + + + +#### Add the argument to the Flags for the specified message. + +param **`imap`** The pointer to IMAP session object which holds the data and the TCP client. + +param **`msgUID`** The UID of the message. + +param **`flags`** The flag list to add. + +param **`closeSession`** The option to close the IMAP session after add flag. + +param **`silent`** The option to ignore the response. + +param **`modsequence`** The int32_t option for UNCHANGESINCE conditional test. + +return **`boolean`** The boolean value indicates the success of operation. + +The modsequence value can be used only if IMAP server supports Conditional STORE extension and the selected mailbox supports modsequences. + +```cpp +bool addFlag(IMAPSession *imap, int msgUID, flags, bool closeSession, int32_t modsequence = -1); +``` + + + + + +#### Add the argument to the Flags for the specified message. + +param **`imap`** The pointer to IMAP session object which holds the data and the TCP client. + +param **`sequenceSet`** The sequence set string i.g., unique identifier (UID) or +message sequence number or ranges of UID or sequence number. + +param **`UID`** The option for sequenceSet whether it is UID or message sequence number. + +param **`flags`** The flag list to add. + +param **`closeSession`** The option to close the IMAP session after set flag. + +param **`silent`** The option to ignore the response. + +param **`modsequence`** The int32_t option for UNCHANGESINCE conditional test. + +return **`boolean`** The boolean value indicates the success of operation. + +The modsequence value can be used only if IMAP server supports Conditional STORE extension and the selected mailbox supports modsequences. + +```cpp +bool addFlag(IMAPSession *imap, sequenceSet, bool UID, flags, bool closeSession, bool silent = false, int32_t modsequence = -1); +``` + + + + + +#### Remove the argument from the Flags for the specified message. + +param **`imap`** The pointer to IMAP session object which holds the data and the TCP client. + +param **`msgUID`** The UID of the message that flags to be removed. + +param **`flags`** The flag list to remove. + +param **`closeSession`** The option to close the IMAP session after remove flag. + +param **`silent`** The option to ignore the response. + +param **`modsequence`** The int32_t option for UNCHANGESINCE conditional test. + +return **`boolean`** The boolean value indicates the success of operation. + +The modsequence value can be used only if IMAP server supports Conditional STORE extension and the selected mailbox supports modsequences. + +```cpp +bool removeFlag(IMAPSession *imap, int msgUID, flags, bool closeSession, int32_t modsequence = -1); +``` + + + + + +#### Remove the argument from the Flags for the specified message. + +param **`imap`** The pointer to IMAP session object which holds the data and the TCP client. + +param **`sequenceSet`** The sequence set string i.g., unique identifier (UID) or +message sequence number or ranges of UID or sequence number. + +param **`UID`** The option for sequenceSet whether it is UID or message sequence number. + +param **`flags`** The flag list to remove. + +param **`closeSession`** The option to close the IMAP session after set flag. + +param **`silent`** The option to ignore the response. + +param **`modsequence`** The int32_t option for UNCHANGESINCE conditional test. + +return **`boolean`** The boolean value indicates the success of operation. + +The modsequence value can be used only if IMAP server supports Conditional STORE extension and the selected mailbox supports modsequences. + +```cpp +bool removeFlag(IMAPSession *imap, sequenceSet, bool UID, flags, bool closeSession, bool silent = false, int32_t modsequence = -1); +``` + + + + + + +#### Reconnect WiFi or network if lost connection. + +param **`reconnect`** The boolean to set/unset WiFi AP reconnection. + +```cpp +void networkReconnect(bool reconnect); +``` + + + + +#### Initiate SD card with SPI port configuration. + +param **`ss`** The SPI Chip/Slave Select pin. + +param **`sck`** The SPI Clock pin. + +param **`miso`** The SPI MISO pin. + +param **`mosi`** The SPI MOSI pin. + +aram **`frequency`** The SPI frequency. + +return **`boolean`** The boolean value indicates the success of operation. + +```cpp +bool sdBegin(int8_t ss = -1, int8_t sck = -1, int8_t miso = -1, int8_t mosi = -1, uint32_t frequency = 4000000); +``` + + + + + +#### Initiate SD card with SD FS configurations (ESP8266 only). + +param **`ss`** SPI Chip/Slave Select pin. + +param **`sdFSConfig`** The pointer to SDFSConfig object (ESP8266 only). + +return **`boolean`** type status indicates the success of the operation. + +```cpp + bool sdBegin(SDFSConfig *sdFSConfig); +``` + + + + + +#### Initiate SD card with chip select and SPI configuration (ESP32 only). + +param **`ss`** The SPI Chip/Slave Select pin. + +param **`spiConfig`** The pointer to SPIClass object for SPI configuartion. + +param **`frequency`** The SPI frequency. + +return **`boolean`** The boolean value indicates the success of operation. + +```cpp +bool sdBegin(int8_t ss, SPIClass *spiConfig = nullptr, uint32_t frequency = 4000000); +``` + + + + + +#### Initiate SD card with SdFat SPI and pins configurations (with SdFat included only). + +param **`sdFatSPIConfig`** The pointer to SdSpiConfig object for SdFat SPI configuration. + +param **`ss`** The SPI Chip/Slave Select pin. + +param **`sck`** The SPI Clock pin. + +param **`miso`** The SPI MISO pin. + +param **`mosi`** The SPI MOSI pin. + +return **`boolean`** The boolean value indicates the success of operation. + +```cpp + bool sdBegin(SdSpiConfig *sdFatSPIConfig, int8_t ss = -1, int8_t sck = -1, int8_t miso = -1, int8_t mosi = -1); +``` + + + + + +#### Initiate SD card with SdFat SDIO configuration (with SdFat included only). + +param **`sdFatSDIOConfig`** The pointer to SdioConfig object for SdFat SDIO configuration. + +return **`boolean`** The boolean value indicates the success of operation. + +```cpp + bool sdBegin(SdioConfig *sdFatSDIOConfig); +``` + + + + +#### Initialize the SD_MMC card (ESP32 only). + +param **`mountpoint`** The mounting point. + +param **`mode1bit`** Allow 1 bit data line (SPI mode). + +param **`format_if_mount_failed`** Format SD_MMC card if mount failed. + +return **`Boolean`** type status indicates the success of the operation. + +```cpp +bool sdMMCBegin(const char *mountpoint = "/sdcard", bool mode1bit = false, bool format_if_mount_failed = false); +``` + + + + +#### Get free Heap memory. + +return **`int`** Free memory amount in byte. + +```cpp +int getFreeHeap(); +``` + + + + + +## IMAPSession class functions + + +The following functions are available from the IMAP Session class. + +This class used for controlling IMAP transports and retrieving the data from the IMAP server. + + + + +#### Set the tcp timeout. + +param **`timeoutSec`** The tcp timeout in seconds. + +```cpp +void setTCPTimeout(unsigned long timeoutSec); +``` + + + +#### Assign custom Client from Arduino Clients. + +param **`client`** The pointer to Arduino Client derived class e.g. WiFiClient, WiFiClientSecure, EthernetClient or GSMClient. + +```cpp +void setClient(Client *client); +``` + + +#### Assign TinyGsm Clients. + +param **`client`** The pointer to TinyGsmClient. + +param **`modem`** The pointer to TinyGsm modem object. Modem should be initialized and/or set mode before transfering data. + +param **`pin`** The SIM pin. + +param **`apn`** The GPRS APN (Access Point Name). + +param **`user`** The GPRS user. + +param **`password`** The GPRS password. + +```cpp +void setGSMClient(Client *client, void *modem, const char *pin, const char *apn, const char *user, const char *password); +``` + + +#### Assign the callback function to handle the network connection for custom Client. + +param **`networkConnectionCB`** The function that handles the network connection. + +```cpp +void networkConnectionRequestCallback(NetworkConnectionRequestCallback networkConnectionCB); +``` + + + +#### Assign the callback function to handle the network connection status acknowledgement. + +param **`networkStatusCB`** The function that handle the network connection status acknowledgement. + +```cpp +void networkStatusRequestCallback(NetworkStatusRequestCallback networkStatusCB); +``` + + + +#### Set the network status acknowledgement. + +param **`status`** The network status. + +```cpp +void setNetworkStatus(bool status); +``` + + + +#### Set the BearSSL IO buffer size. + +param **`rx`** The BearSSL receive buffer size in bytes. + +param **`tx`** The BearSSL trasmit buffer size in bytes. + +```cpp +void setSSLBufferSize(int rx = -1, int tx = -1); +``` + + + +#### Set system time with timestamp. + +param **`ts`** timestamp in seconds from midnight Jan 1, 1970. + +param **`gmtOffset`** The GMT offset. + +This function allows the internal time setting by timestamp i.e. timestamp from external RTC. + +```cpp +void setSystemTime(time_t ts, float gmtOffset = 0); +``` + + + +#### Begin the IMAP server connection. + +param **`session_config`** The pointer to Session_Config structured data that keeps the server and log in details. + +param **`imap_data`** The pointer to IMAP_Data structured data that keeps the operation options. + +param **`login`** The bool option for login after server connection. + +return **`boolean`** The boolean value which indicates the success of operation. + +```cpp +bool connect(Session_Config *session_config, IMAP_Data *imap_data, bool login = true); +``` + + + +#### Login to IMAP server using Email and password. + +param **`email`** The IMAP server account email. + +param **`password`** The IMAP server account password. + +return **`boolean`** The boolean value which indicates the success of operation. + +```cpp +bbool loginWithPassword( email, password); +``` + + + +#### Login to IMAP server using Email and access token. + +param **`email`** The IMAP server account email. + +param **`token`** The Access token to log in. + +return **`boolean`** The boolean value which indicates the success of operation. + +```cpp +bbool loginWithAccessToken( email, token); +``` + + +#### Send the client identification to the server + +param **`identification`** The pointer to IMAP_Identification structured data that keeps + +the key properties e.g., name, version, os, os_version, vendor, support_url, address, + +date, command, arguments, and environment. + +```cpp +bool id(IMAP_Identification *identification); +``` + + +#### Return the server ID returns from ID command. + +return **`The server ID string.`** + +```cpp +String serverID(); +``` + + +#### Return the SASL authentication status. + +return **`boolean`** The boolean value indicates SASL authentication status. + +```cpp +bool isAuthenticated(); +``` + + +#### Return the log in status. + +return **`boolean`** The boolean value indicates log in status. + +```cpp +bool isLoggedIn(); +``` + + +#### Return firmware update result when attachment filename matches. + +return **`boolean`** The boolean value indicates the firmware update status. + +```cpp +bool isFirmwareUpdateSuccess(); +``` + + +#### Close the IMAP session. + +return **`boolean`** The boolean value which indicates the success of operation. + +```cpp +bool closeSession(); +``` + + +#### Setup TCP KeepAlive for internal TCP client. + +param **`tcpKeepIdleSeconds`** lwIP TCP Keepalive idle in seconds. + +param **`tcpKeepIntervalSeconds`** lwIP TCP Keepalive interval in seconds. + +param **`tcpKeepCount`** lwIP TCP Keepalive count. + +For the TCP (KeepAlive) options, see [this doc](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/lwip.html#tcp-options). + +If value of one of these parameters is zero, the TCP KeepAlive will be disabled. + +You can check the server connecting status, by exexuting `.connected()` which will return true when connection to the server is still alive. + +```cpp +void keepAlive(int tcpKeepIdleSeconds, int tcpKeepIntervalSeconds, int tcpKeepCount); +``` + + + +#### Get TCP KeepAlive status. + +return **`Boolean`** status of TCP Keepalive. + +```cpp +bool isKeepAlive(); +``` + + + +#### Get TCP connection status. + +return **`boolean`** The boolean value indicates the connection status. + +```cpp +bool connected(); +``` + + + + + + +#### Set to enable the debug. + +param **`level`** The level to enable the debug message + +level = 0, no debugging + +level = 1, basic level debugging + +```cpp +void debug(int level); +``` + + + + + +#### Get the list of all the mailbox folders since the TCP session was opened and user was authenticated. + +param **`folders`** The FoldersCollection class that contains the collection of the +FolderInfo structured data. + +return **`boolean`** The boolean value which indicates the success of operation. + +```cpp +bool getFolders(FoldersCollection &folders); +``` + + + + + +#### Select or open the mailbox folder to search or fetch the message inside. + +param **`folderName`** The known mailbox folder name. The default name is INBOX. + +param **`readOnly`** The option to open the mailbox for read only. Set this option to false when you wish +to modify the Flags using the setFlag, addFlag and removeFlag functions. + +return **`boolean`** The boolean value which indicates the success of operation. + +note: the function will exit immediately and return true if the time since previous success folder selection (open) with the same readOnly mode, is less than 5 seconds. + +```cpp +bool selectFolder( folderName, bool readOnly = true); +``` + + + + + +#### Open the mailbox folder to read or search the mesages. + +param **`folderName`** The name of known mailbox folder to be opened. + +param **`readOnly`** The option to open the mailbox for reading only. Set this option to false when you wish +to modify the flags using the setFlag, addFlag and removeFlag functions. + +return **`boolean`** The boolean value which indicates the success of operation. + +note: the function will exit immediately and return true if the time since previous success folder selection (open) with the same readOnly mode, is less than 5 seconds. + +```cpp +bool openFolder( folderName, bool readOnly = true); +``` + + + + + +#### Close the mailbox folder that was opened. + +param **`expunge`** The option to allow emty the deleted flag set messages in case folder was open with editable mode. + +return **`boolean`** The boolean value which indicates the success of operation. + +```cpp +bool closeFolder(bool expunge = false); +``` + + + + + + +#### Create folder. + +param **`folderName`** The name of folder to create. + +return **`boolean`** The boolean value which indicates the success of operation. + +```cpp +bool createFolder( folderName); +``` + + + + + +#### Get subscribes mailboxes. + +param **`reference`** The reference name. + +param **`mailbox`** The mailbox name with possible wildcards. + +param **`folders`** The return FoldersCollection that contains the folder info e.g., name, attribute and delimiter. + +return **`boolean`** The boolean value which indicates the success of operation. + +```cpp +bool getSubscribesMailboxes( reference, mailbox, FoldersCollection &folders); +``` + + + + +#### Subscribe mailbox. + +param **`folderName`** The name of folder to subscribe. + +return **`boolean`** The boolean value which indicates the success of operation. + +```cpp +bool subscribe( folderName) +``` + + + + +#### Unsubscribe mailbox. + +param **`folderName`** The name of folder to unsubscribe. + +return **`boolean`** The boolean value which indicates the success of operation. + +```cpp +bool unSubscribe( folderName) +``` + + + + + +#### Rename folder. + +param **`currentFolderName`** The name of folder to create. + +param **`newFolderName`** The new name of folder to create. + +return **`boolean`** The boolean value which indicates the success of operation. + +```cpp +bool renameFolder( currentFolderName, newFolderName); +``` + + + +#### Delete folder. + +param **`folderName`** The name of folder to delete.. + +return **`boolean`** The boolean value which indicates the success of operation. + +```cpp +bool deleteFolder( folderName); +``` + + + + + + +#### Get UID number in selected or opened mailbox. + +param **`msgNum`** The message number or order in the total message numbers. + +return **`boolean`** The boolean value which indicates the success of operation. + +Returns 0 when fail to get UID. + +```cpp +int getUID(int msgNum); +``` + + + + + + + +#### Get message flags in selected or opened mailbox. + +param **`msgNum`** The message number or order in the total message numbers. + +return **`string`** Message flags in selected or opened mailbox. + +empty string when fail to get flags. + +```cpp +const char *getFlags(int msgNum); +``` + + + + + + +#### Send the custom IMAP command and get the result via callback. + +param **`cmd`** The command string. + +param **`callback`** The function that accepts IMAP_Response as parameter. + +param **`tag`** The tag string to pass to the callback function. + +return **`boolean`** The boolean value which indicates the success of operation. + +imap.connect and imap.selectFolder or imap.openFolder are needed to call once prior to call this function. + +```cpp +bool sendCustomCommand( cmd, imapResponseCallback callback, tag); +``` + + + + + +#### Send the custom IMAP command data string. + +param **`data`** The string data. + +param **`lastData`** The flag represents the last data to send (optional). + +return **`boolean`** The boolean value which indicates the success of operation. + +Should be used after calling sendCustomCommand("APPEND xxxxxx"); + +```cpp +bool sendCustomData(T data, bool lastData = false); +``` + + + + + +#### Send the custom IMAP command data. + +param **`data`** The byte data. + +param **`size`** The data size. + +param **`lastData`** The flag represents the last data to send (optional). + +return **`boolean`** The boolean value which indicates the success of operation. + +Should be used after calling ssendCustomCommand("APPEND xxxxxx"); + +```cpp +bool sendCustomData(uint8_t *data, size_t size, bool lastData = false); +``` + + + + +#### Begin the IMAP server connection without authentication. + +param **`session_config`** The pointer to Session_Config structured data that keeps the server and log in details. + +param **`callback`** The callback function that accepts IMAP_Response as parameter. + +param **`tag`** The tag that pass to the callback function. + +return **`The boolean`** value indicates the success of operation. + +```cpp +bool customConnect(Session_Config *session_config, imapResponseCallback callback, tag); +``` + + + + +#### Copy the messages to the defined mailbox folder. + +param **`toCopy`** The pointer to the MessageList class that contains the list of messages to copy. + +param **`dest`** The destination folder that the messages to copy to. + +return **`boolean`** The boolean value which indicates the success of operation. + +```cpp +bool copyMessages(MessageList *toCopy, dest); +``` + + + + + +#### Copy the messages to the defined mailbox folder. + +param **`sequenceSet`** The sequence set string i.g., unique identifier (UID) or +message sequence number or ranges of UID or sequence number. + +param **`UID`** The option for sequenceSet whether it is UID or message sequence number. + +param **`dest`** The destination folder that the messages to copy to. + +return **`boolean`** The boolean value which indicates the success of operation. + +```cpp +bool copyMessages( sequenceSet, bool UID, dest); +``` + + + + + + +#### Move the messages to the defined mailbox folder. + +param **`toMove`** The pointer to the MessageList class that contains the list of messages to move. + +param **`dest`** The destination folder that the messages to move to. + +return **`boolean`** The boolean value which indicates the success of operation. + +```cpp +bool moveMessages(MessageList *toMove, dest); +``` + + + + + +#### Move the messages to the defined mailbox folder. + +param **`sequenceSet`** The sequence set string i.g., unique identifier (UID) or +message sequence number or ranges of UID or sequence number. + +param **`UID`** The option for sequenceSet whether it is UID or message sequence number. + +param **`dest`** The destination folder that the messages to move to. + +return **`boolean`** The boolean value which indicates the success of operation. + +```cpp +bool moveMessages( sequenceSet, bool UID, dest); +``` + + + + + + +#### Delete the messages in the opened mailbox folder. + +param **`toDelete`** The pointer to the MessageList class that contains the list of messages to delete. + +param **`expunge`** The boolean option to expunge all messages. + +param **`modsequence`** The int32_t option for UNCHANGESINCE conditional test. + +return **`boolean`** The boolean value indicates the success of operation. + +The modsequence value can be used only if IMAP server supports Conditional STORE extension and the selected mailbox supports modsequences. + +```cpp +bool deleteMessages(MessageList *toDelete, bool expunge = false, int32_t modsequence = -1); +``` + + + + + + +#### Delete the messages in the opened mailbox folder. + +param **`sequenceSet`** The sequence set string i.g., unique identifier (UID) or +message sequence number or ranges of UID or sequence number. + +param **`UID`** The option for sequenceSet whether it is UID or message sequence number. + +param **`expunge`** The boolean option to expunge all messages. + +param **`modsequence`** The int32_t option for UNCHANGESINCE conditional test. + +return **`boolean`** The boolean value indicates the success of operation. + +The modsequence value can be used only if IMAP server supports Conditional STORE extension and the selected mailbox supports modsequences. + +```cpp +bool deleteMessages( sequenceSet, bool UID, bool expunge = false, int32_t modsequence = -1); +``` + + + + + + +#### Get the quota root's resource usage and limits. + +param **`quotaRoot`** The quota root to get. + +param **`info`** The pointer to `IMAP_Quota_Root_Info` that contains quota root's resource name, usage and limit. + +return **`boolean`** The boolean value which indicates the success of operation. + +```cpp +bool getQuota( quotaRoot, IMAP_Quota_Root_Info *info); +``` + + + + + +#### Set the quota root's resource usage and limits. + +param **`quotaRoot`** The quota root to set. + +param **`data`** The pointer to `IMAP_Quota_Root_Info` that contains quota root's resource name, usage and limit. + +return **`boolean`** The boolean value which indicates the success of operation. + +```cpp +bool setQuota( quotaRoot, IMAP_Quota_Root_Info *data); +``` + + + + + +#### Get the list of quota roots for the named mailbox. + +param **`mailbox`** The mailbox name. + +param **`quotaRootsList`** The pointer to `IMAP_Quota_Roots_List` that contains the list of `IMAP_Quota_Root_Info`. + +return **`boolean`** The boolean value which indicates the success of operation. + +```cpp +bool getQuotaRoot( mailbox, IMAP_Quota_Roots_List *quotaRootsList); +``` + + + + + +#### Get the ACLs for a mailbox. + +param **`mailbox`** The mailbox name. + +param **`aclList`** The pointer to the returning `IMAP_Rights_List` object. + +return **`boolean`** The boolean value which indicates the success of operation. + +```cpp +bool getACL( mailbox, IMAP_Rights_List *aclList); +``` + + + + + + +#### Get the ACLs for a mailbox. + +param **`mailbox`** The mailbox name. + +param **`acl`** The pointer to the acl IMAP_Rights_Info to set. + +return **`boolean`** The boolean value which indicates the success of operation. + +```cpp +bool setACL( mailbox, IMAP_Rights_Info *acl); +``` + + + + + + +#### Delete the ACLs set for identifier on mailbox. + +param **`mailbox`** The mailbox name. + +param **`identifier`** The identifier (user) to remove the rights. + +return **`boolean`** The boolean value which indicates the success of operation. + +```cpp +bool deleteACL( mailbox, identifier); +``` + + + + + +#### Show my ACLs for a mailbox. + +param **`mailbox`** The mailbox name. + +param **`acl`** The pointer to the returning `IMAP_Rights_Info` object. + +return **`boolean`** The boolean value which indicates the success of operation. + +```cpp +bool myRights( mailbox, IMAP_Rights_Info *acl); +``` + + + + + +#### Returns IMAP namespaces. + +param **`mailbox`** The mailbox name. + +param **`ns`** The pointer to the returning `IMAP_Namespaces_List` object. + +return **`boolean`** The boolean value which indicates the success of operation. + +```cpp +bool getNamespace(IMAP_Namespaces_List *ns); +``` + + + + + + +#### Enable IMAP capability. + +param **`capability`** The mailbox name. + +return **`boolean`** The boolean value which indicates the success of operation. + +```cpp +bool enable( capability); +``` + + + + + +#### Listen for the selected or open mailbox for updates. + +return **`boolean`** The boolean value which indicates the success of operation. + +```cpp +bool listen(); +``` + + + + + + +#### Stop listen for the mailbox for updates. + +return **`boolean`** The boolean value which indicates the success of operation. + +```cpp +bool stopListen(); +``` + + + + + + + +#### Check for the selected or open mailbox updates. + +return **`boolean`** The boolean value which indicates the changes status of mailbox. + +```cpp +bool folderChanged(); +``` + + + + + + +#### Assign the callback function that returns the operating status when fetching or reading the Email. + +param **`imapCallback`** The function that accepts the `imapStatusCallback` as parameter. + +```cpp +void callback(imapStatusCallback imapCallback); +``` + + + + +#### Assign the callback function to decode the string based on the character set. + +param **`callback`** The function that accepts the pointer to `IMAP_Decoding_Info` as parameter. + +```cpp +void characterDecodingCallback(imapCharacterDecodingCallback callback); +``` + + + +#### Assign the callback function that returns the MIME data stream from fetching or reading the Email. + +param **`mimeDataStreamCallback`** The function that accepts the `MIME_Stream_Info` as parameter. + +```cpp +void mimeDataStreamCallback(MIMEDataStreamCallback mimeDataStreamCallback); +``` + + + + + +#### Determine if no message body contained in the search result and only the message header is available. + +```cpp +bool headerOnly(); +``` + + + + + +#### Get the message list from search or fetch the Emails + +return **`The IMAP_MSG_List structured`** data which contains the text and html contents, +attachments, inline images, embedded rfc822 messages details for each message. + +```cpp +IMAP_MSG_List data(); +``` + + + + +#### Get the details of the selected or opned mailbox folder + +return **`The SelectedFolderInfo class`** instance which contains the info about flags, total messages, next UID, +earch count and the available messages count. + +```cpp +SelectedFolderInfo selectedFolder(); +``` + + + + + +#### Get the error details when readingg the Emails. + +return **`String`** The string of error details. + +```cpp +String errorReason(); +``` + + +#### Get the operating status error code. + +return **`int`** The value of operating status error code. + +The negative value indicated error. + +See src/ESP_Mail_Error.h and extras/MB_FS.h + +```cpp +int errorCode(); +``` + + + +#### Clear all the cache data stored in the IMAP session object. + +```cpp +void empty(); +``` + + + +#### Get the status of message fetching and searching. + +return **`IMAP_Status`** The IMAP_Status object contains the fetching and searching statuses. + +```cpp +IMAP_Status status(); +``` + + + +#### Get the JSON string of file name list of files that stored in SD card. + +return **`The JSON string`** of filenames. + +note This will available only when standard SD library was used and file storage is SD. + +```cpp +String fileList(); +``` + + +## SMTPSession class functions + + +The following functions are available from the SMTP Session class. + +This class is similar to the IMAP session class, used for controlling SMTP transports +and retrieving the data from the SMTP server. + + + + +#### Set the tcp timeout. + +param **`timeoutSec`** The tcp timeout in seconds. + +```cpp +void setTCPTimeout(unsigned long timeoutSec); +``` + + + +#### Assign custom Client from Arduino Clients. + +param **`client`** The pointer to Arduino Client derived class e.g. WiFiClient, WiFiClientSecure, EthernetClient or GSMClient. + +```cpp +void setClient(Client *client); +``` + + +#### Assign TinyGsm Clients. + +param **`client`** The pointer to TinyGsmClient. + +param **`modem`** The pointer to TinyGsm modem object. Modem should be initialized and/or set mode before transfering data. + +param **`pin`** The SIM pin. + +param **`apn`** The GPRS APN (Access Point Name). + +param **`user`** The GPRS user. + +param **`password`** The GPRS password. + +```cpp +void setGSMClient(Client *client, void *modem, const char *pin, const char *apn, const char *user, const char *password); +``` + + + +#### Assign the callback function to handle the network connection for custom Client. + +param **`networkConnectionCB`** The function that handles the network connection. + +```cpp +void networkConnectionRequestCallback(NetworkConnectionRequestCallback networkConnectionCB); +``` + + +#### Assign the callback function to handle the network connection status acknowledgement. + +param **`networkStatusCB`** The function that handle the network connection status acknowledgement. + +```cpp +void networkStatusRequestCallback(NetworkStatusRequestCallback networkStatusCB); +``` + + + +#### Set the network status acknowledgement. + +param **`status`** The network status. + +```cpp +void setNetworkStatus(bool status); +``` + + + +#### Set the BearSSL IO buffer size. + +param **`rx`** The BearSSL receive buffer size in bytes. + +param **`tx`** The BearSSL trasmit buffer size in bytes. + +```cpp +void setSSLBufferSize(int rx = -1, int tx = -1); +``` + + + +#### Set system time with timestamp. + +param **`ts`** timestamp in seconds from midnight Jan 1, 1970. + +param **`gmtOffset`** The GMT offset. + +This function allows the internal time setting by timestamp i.e. timestamp from external RTC. + +```cpp +void setSystemTime(time_t ts, float gmtOffset = 0); +``` + + + +#### Begin the SMTP server connection. + +param **`session_config`** The pointer to Session_Config structured data that keeps the server and log in details. + +param **`login`** The bool option for login after server connection. + +return **`boolean`** The boolean value indicates the success of operation. + +```cpp +bool connect(Session_Config *session_config, bool login = true); +``` + + + +#### Login to SMTP server using Email and password. + +param **`email`** The SMTP server account email. + +param **`password`** The SMTP server account password. + +return **`boolean`** The boolean value which indicates the success of operation. + +```cpp +bool loginWithPassword( email, password); +``` + + + +#### Login to SMTP server using Email and access token. + +param **`email`** The SMTP server account email. + +param **`token`** The Access token to log in. + +return **`boolean`** The boolean value which indicates the success of operation. + +```cpp +bool loginWithAccessToken( email, token); +``` + + +#### Return the SASL authentication status. + +return **`boolean`** The boolean value indicates SASL authentication status. + +```cpp +bool isAuthenticated(); +``` + + + +#### Return the log in status. + +return **`boolean`** The boolean value indicates log in status. + +```cpp +bool isLoggedIn(); +``` + + +#### Close the SMTP session. + +```cpp +bool closeSession(); +``` + + + +#### Setup TCP KeepAlive for internal TCP client. + +param **`tcpKeepIdleSeconds`** lwIP TCP Keepalive idle in seconds. + +param **`tcpKeepIntervalSeconds`** lwIP TCP Keepalive interval in seconds. + +param **`tcpKeepCount`** lwIP TCP Keepalive count. + +For the TCP (KeepAlive) options, see [this doc](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/lwip.html#tcp-options). + +If value of one of these parameters is zero, the TCP KeepAlive will be disabled. + +You can check the server connecting status, by exexuting `.connected()` which will return true when connection to the server is still alive. + +```cpp +void keepAlive(int tcpKeepIdleSeconds, int tcpKeepIntervalSeconds, int tcpKeepCount); +``` + + + +#### Get TCP KeepAlive status. + +return **`Boolean`** status of TCP Keepalive. + +```cpp +bool isKeepAlive(); +``` + + + +#### Get TCP connection status. + +return **`boolean`** The boolean value indicates the connection status. + +```cpp +bool connected(); +``` + + + + +#### Begin the SMTP server connection without authentication. + +param **`session_config`** The pointer to Session_Config structured data that keeps the server and log in details. + +param **`callback`** The callback function that accepts the SMTP_Response as parameter. + +param **`commandID`** The command identifier number that will pass to the callback. + +return **`The int`** value of response code. + +If commandID was not set or set to -1, the command identifier will be auto increased started from zero. + +```cpp +int customConnect(Session_Config *session_config, smtpResponseCallback callback, int commandID = -1); +``` + + + + + + +#### Send the custom SMTP command and get the result via callback. + +param **`cmd`** The command string. + +param **`callback`** The function that accepts the SMTP_Response as parameter. + +return **`boolean`** The boolean value which indicates the success of operation. + +smtp.connect or smtp.customConnect is needed to call once prior to call this function. + +```cpp +bool sendCustomCommand( cmd, smtpResponseCallback callback); +``` + + + + + +#### Send the custom SMTP command data string. + +param **`data`** The string data. + +return **`The boolean`** value which indicates the success of operation. + +Should be used after calling sendCustomCommand("DATA"); + +```cpp +bool sendCustomData( data); +``` + + + + +#### Send the custom SMTP command data. + +param **`data`** The byte data. + +param **`size`** The data size. + +return **`The boolean`** value which indicates the success of operation. + +Should be used after calling sendCustomCommand("DATA"); + +```cpp +bool sendCustomData(uint8_t *data, size_t size); +``` + + + + + +#### Set to enable the debug. + +param **`level`** The level to enable the debug message + +level = 0, no debugging + +level = 1, basic level debugging + +```cpp +void debug(int level); +``` + + + + + +#### Get the error details when sending the Email + +return **`String`** The string of error details. + +```cpp +String errorReason(); +``` + + +#### Get the operating status error code. + +return **`int`** The value of operating status error code. + +The negative value indicated error. + +See src/ESP_Mail_Error.h and extras/MB_FS.h + +```cpp +int errorCode(); +``` + + + +#### Get the SMTP server response status code. + +return **`int`** The value of SMTP server response status code. + +See RFC 5321 standard's documentation. + +```cpp +int statusCode(); +``` + + + +#### Get the SMTP server response status message. + +return **`String`** The value of SMTP server response status message. + +```cpp +String statusMessage(); +``` + + + +#### Set the Email sending status callback function. + +param **`smtpCallback`** The callback function that accept the `smtpStatusCallback` param. + +```cpp +void callback(smtpStatusCallback smtpCallback); +``` + + +#### Get the status of message fetching and searching. + +return **`SMTP_Status`** The SMTP_Status object contains the sending status. + +```cpp +SMTP_Status status(); +``` + +## SMTP_Message class functions + + +The following functions are available from the SMTP Message class. + +This class is used for storing the message data including headers, body and attachments +which will be processed with the SMTP session class. + + + + +#### To reset the SMTP_Attachment item data + +param **`att`** The SMTP_Attachment class that stores the info about attachment + +This function was used for clear the internal data of attachment item to be ready for reuse. + +```cpp +void resetAttachItem(SMTP_Attachment &att); +``` + + + +#### To clear all data in SMTP_Message class included headers, bodies and attachments + +```cpp +void clear(); +``` + + + + +#### To clear all the inline images in SMTP_Message class. + +```cpp +void clearInlineimages(); +``` + + + + + +#### To clear all the attachments. + +```cpp +void clearAttachments(); +``` + + + + + +#### To clear all rfc822 message attachment. + +```cpp +void clearRFC822Messages(); +``` + + + + + +#### To clear the primary recipient mailboxes. + +```cpp +void clearRecipients(); +``` + + + + + +#### To clear the Carbon-copy recipient mailboxes. + +```cpp +void clearCc(); +``` + + + + + +#### To clear the Blind-carbon-copy recipient mailboxes. + +```cpp +void clearBcc(); +``` + + +#### To clear the custom message headers. + +```cpp +void clearHeader(); +``` + + + + +#### To add attachment to the message. + +param **`att`** The SMTP_Attachment data item + +```cpp +void addAttachment(SMTP_Attachment &att); +``` + + + + + +#### To add parallel attachment to the message. + +param **`att`** The SMTP_Attachment data item + +```cpp +void addParallelAttachment(SMTP_Attachment &att); +``` + + + + + +#### To add inline image to the message. + +param **`att`** The SMTP_Attachment data item + +```cpp +void addInlineImage(SMTP_Attachment &att); +``` + + + + + +#### To add rfc822 message to the message. + +param **`msg`** The RFC822_Message class object + +```cpp +void addMessage(SMTP_Message &msg); +``` + + + + + +#### To add the primary recipient mailbox to the message. + +param **`name`** The name of primary recipient + +param **`email`** The Email address of primary recipient + +```cpp +void addRecipient( name, email); +``` + + + + + +#### To add Carbon-copy recipient mailbox. + +param **`email`** The Email address of secondary recipient + +```cpp +void addCc( email); +``` + + + + + +#### To add Blind-carbon-copy recipient mailbox. + +param **`email`** The Email address of the tertiary recipient + +```cpp +void addBcc( email); +``` + + + + + +#### To add the custom header to the message. + +param **`hdr`** The header name and value + +```cpp +void addHeader( hdr); +``` + + + + +##### [properties] The message author config + +This property has the sub properties + +###### [const char*] name - The sender name. + +###### [const char*] email - The sender Email address. + +```cpp +esp_mail_email_info_t sender; +``` + + +##### [properties] The topic of message + +```cpp +const char *subject; +``` + + +##### [properties] The message type + +```cpp +byte type; +``` + + +##### [properties] The PLAIN text message + +This property has the sub properties + +###### [esp_mail_smtp_embed_message_body_t] embed - The option to embed this message content as a file. + +###### [const char*] content - The PLAIN text content of the message. + +###### [esp_mail_blob_message_content_t] blob - The blob that contins PLAIN text content of the message. + +###### [esp_mail_file_message_content_t] file - The file that contins PLAIN text content of the message. + +###### [const char*] charSet - The character transcoding of the PLAIN text content of the message. + +###### [const char*] content_type - The content type of message. + +###### [const char*] transfer_encoding - The option to encode the content for data transfer. + +###### [boolean] flowed - The option to send the PLAIN text with wrapping. + +```cpp +esp_mail_plain_body_t text; +``` + + +##### [properties] The HTML text message + +This propery has the sub properties + +###### [const char*] content - The HTML content of the message. + +###### [esp_mail_blob_message_content_t] blob - The blob that contins HTML content of the message. + +###### [esp_mail_file_message_content_t] file - The file that contins HTML content of the message. + +###### [const char*] charSet - The character transcoding of the HTML content of the message. + +###### [const char*] content_type - The content type of message. + +###### [const char*] transfer_encoding - The option to encode the content for data transfer. + +```cpp +esp_mail_html_body_t html; +``` + + +##### [properties] The response config + +This propery has the sub properties + +###### [const char*] reply_to - The author Email address to reply. + +###### [const char*] return_path - The sender Email address to return the message. + +###### [int] notify - The Delivery Status Notifications enumeration e.g. + +esp_mail_smtp_notify_never = 0, + +esp_mail_smtp_notify_success = 1, + +esp_mail_smtp_notify_failure = 2, and + +esp_mail_smtp_notify_delay = 4 + +```cpp +esp_mail_smtp_msg_response_t response; +``` + + +##### [properties] The priority of the message + +This property has the enumeration values + +esp_mail_smtp_priority_high = 1, + +esp_mail_smtp_priority_normal = 3, + +esp_mail_smtp_priority_low = 5 + +```cpp +esp_mail_smtp_priority priority; +``` + + +##### [properties] The enable options + +This propery has the sub property + +###### [boolean] chunking - enable chunk data sending for large message. + +```cpp +esp_mail_smtp_enable_option_t enable; +``` + + +##### [properties] The message from config + +This property has the sub properties + +###### [const char*] name - The messsage author name. + +###### [const char*] email - The message author Email address. + +```cpp +esp_mail_email_info_t from; +``` + + +##### [properties] The message identifier + +```cpp +const char *ID; +``` + +##### [properties] The keywords or phrases, separated by commas + +```cpp +const char *keywords; +``` + + +##### [properties] The comments about message + +```cpp +const char *comments; +``` + + +##### [properties] The date of message + +```cpp +const char *date; +``` + + +##### [properties] The return recipient of the message + +```cpp +const char *return_path; +``` + + + +##### [properties] The field that contains the parent's message ID of the message to which this one is a reply + +```cpp +const char *in_reply_to; +``` + + + +##### [properties] The field that contains the parent's references (if any) and followed by the parent's message ID (if any) of the message to which this one is a reply + +```cpp +const char *references; +``` + + +## IMAP_Status class functions + + +The following functions are available from the IMAP Status class. + +This class is used as the callback parameter for retrieving the status while reading the Email. + + + + +#### Get the information of each process in the reading operation. + +return **`string`** The info for each process + +```cpp +const char *info(); +``` + + + + +#### Get the status of completion. + +return **`boolean`** The bool value indicates that all reading processes are finished + +```cpp +bool success(); +``` + + + + + +#### To clear all data store in this class. + +```cpp +void empty(); +``` + + + + + + +## SMTP_Status class functions + + +The following functions are available from the SMTP Status class. + +This class is used as the callback parameter for retrieving the status while sending the Email. + + + + +#### Get the information of each process in the sending operation. + +return **`string`** The info for each process + +```cpp +const char *info(); +``` + + + + +#### Get the status of completion. + +return **`boolean`** The bool value indicates that all sending processes are finished + +```cpp +bool success(); +``` + + + + + +#### To clear all data store in this class. + +```cpp +void empty(); +``` + + + + +#### Get the number of complete sending message. + +return **`number`** The number of message that was sent + +```cpp +size_t completedCount(); +``` + + + + + +#### Get the number of failed sending message. + +return **`number`** The number of message that was not sent + +```cpp +size_t failedCount(); +``` + + + + +## SendingResult class functions + + +The following functions are available from the SendingResult class. + +This class is used for retrieving the info about the result of sending the messages. + + + + +#### Get the information of a message sending status. + +param **`index`** The index number of a message sending status + +return **`SMTP_Result`** The SMTP_Result type data that provides these properties + +##### [bool] completed - The status of the message + +#### [MB_String] recipients - The primary recipient mailbox of the message + +#### [MB_String] subject - The topic of the message + +#### [time_t] timesstamp - The timestamp of the message + +```cpp +SMTP_Result getItem(size_t index); +``` + + + + + +#### Get the amount of the result data. + +return **`number`** The number of result item + +```cpp +size_t size(); +``` + + + + +## SMTP_Response type data + +The following properties are available from the SMTP_Response data type. + +This data type obtains the response from sending custom SMTP commands. + + +#### [Properties] The command identifier + +```cpp +int id; +``` + +#### [Properties] The response text + +```cpp +MB_String text; +``` + + +#### [Properties] The response code + +```cpp +int respCode; +``` + + + + +## FoldersCollection class functions + + +The following functions are available from the FoldersCollection class. + +This class is used for retrieving the info about the mailbox folders which available to read or serach +in the user Email mailbox. + + + + +#### Get the information of a folder in a folder collection. + +param **`index`** The index number of folders + +return **`esp_mail_folder_info_item_t`** The esp_mail_folder_info_item_t structured data that provides these properties + +#### [MB_String] name - The name of folder + +#### [MB_String] attributes - The attributes of folder + +#### [MB_String] delimiter - The delimeter of folder + +```cpp +esp_mail_folder_info_item_t info(size_t index); +``` + + + + + +#### Get the number of folders in the collection. + +return **`number`** The number of folder in the collection + +```cpp +size_t size(); +``` + + + + + + +## SelectedFolderInfo class functions + + +The following functions are available from the SelectedFolderInfo class. + +This class is used for retrieving the info about the sselected or opened mailbox folder. + + + + +#### Get the numbers of flags in the user Email mailbox. + +return **`number`** The numbers of flags + +```cpp +size_t flagCount(); +``` + + + + + +#### Get the numbers of messages in this mailbox. + +return **`number`** The numbers of messages in the selected mailbox folder + +```cpp +size_t msgCount(); +``` + + + + + + +#### Get the numbers of messages in this mailbox that recent flag was set. + +return **`number`** The numbers of messages in the selected mailbox folder that recent flag was set + +```cpp +size_t recentCount(); +``` + + + + + + +#### Get the order of message in number of message in this mailbox that reoved. + +return **`IMAP_Polling_Status`** The data that holds the polling status. + +The IMAP_Polling_Status has the properties e.g. type, messageNum, and argument. + +The type property is the type of status e.g.imap_polling_status_type_undefined, imap_polling_status_type_new_message, +imap_polling_status_type_remove_message, and imap_polling_status_type_fetch_message. + +The messageNum property is message number or order from the total number of message that added, fetched or deleted. + +The argument property is the argument of commands e.g. FETCH + +```cpp +struct IMAP_Polling_Status pollingStatus(); +``` + + + + + + + + +#### Get the predicted next message UID in the sselected folder. + +return **`number`** The number represents the next message UID number + +```cpp +size_t nextUID(); +``` + + + + + + + +#### Get the numbers of messages from search result based on the search criteria. + +return **`number`** The total number of messsages from search + +```cpp +size_t searchCount(); +``` + + + + + +#### Get the numbers of messages to be stored in the ressult. + +return **`number`** The number of messsage stored from search + +```cpp +size_t availableMessages(); +``` + + + + + +#### Get the flag argument at the specified index. + +return **`index`** The index of flag in the flags list + +return **`String`** The argument of selected flag + +```cpp +String flag(size_t index); +``` + + + + +## Session_Config type data + + +The following properties are available from the Session_Config data type. + +This data type is used for storing the session info about the server and login credentials. + + +#### [Properties] The server config + +This property has the sub properties + +##### [MB_String] host_name - The hostName of the server. + +##### [uint16_t] port - The port on the server to connect to. + +```cpp +esp_mail_sesson_sever_config_t server; +``` + + +#### [Properties] The log in config + +This property has the sub properties + +##### [MB_String] email - The user Email address to log in. + +##### [consst char *] password - The user password to log in. + +##### [consst char *] accessToken - The OAuth2.0 access token to log in. + +##### [consst char *] user_domain - The host name or public IP of client system. + +```cpp +esp_mail_sesson_login_config_t login; +``` + + +#### [Properties] The secure config + +This property has the sub properties + +##### [bool] startTLS - The option to send the command to start the TLS connection. + +```cpp +esp_mail_sesson_secure_config_t secure; +``` + + +#### [Properties] The ports and protocols config + +This property has the sub properties + +##### [port_function *] list - The list (aray) of port_function. + +##### [size_t] size - The size of array. + +```cpp +esp_mail_ports_functions ports_functions; +``` + + + + +#### [Properties] The certificate config + +##### [const char *] cert_data - The certificate data (base64 data). + +##### [const char *] cert_file - The certificate file (DER format). + +##### [esp_mail_file_storage_type] cert_file_storage_type - The storage type. + +##### [bool] verify - The cerificate verification option. + +```cpp +esp_mail_sesson_cert_config_t certificate; +``` + + + +#### [Properties] SPI Ethernet Module config for ESP8266 + +##### [ENC28J60lwIP *] enc28j60 - The ENC28J60 Ethernet module lwip interfac. + +##### [Wiznet5100lwIP *] w5100 - The W5100 Ethernet module lwip interfac. + +##### [Wiznet5500lwIP *] w5500 - The W5500 Ethernet module lwip interfac. + +```cpp +esp_mail_spi_ethernet_module_t spi_ethernet_module; +``` + + + +#### [Properties] The callback function for WiFi connection + +```cpp +NetworkConnectionHandler network_connection_handler; +``` + + + + +## port_function type data + +#### [Properties] The port number + +```cpp +uint16_t port; +``` + +#### [Properties] The protocol + +The port protocol e.g. esp_mail_protocol_plain_text, esp_mail_protocol_ssl and esp_mail_protocol_tls. + +```cpp +esp_mail_protocol protocol; +``` + + + + +## IMAP_Data type data + + +The following properties are available from the IMAP_Data data type. + +This data type is used for storing the IMAP transport and operating options to +control and store the operation result e.g. the messahe contents from search and fetch. + + + + +#### [Properties] The config for fetching + +This property has the sub properties + +##### [MB_String] uid - The UID of message to fetch. + +##### [MB_String] number - The message sequence number to fetch. + +##### [esp_mail_imap_sequence_set_t] sequence_set - The sequence set options. + +##### [MB_String] set_seen - Set the message flag as seen. + +```cpp +esp_mail_imap_fetch_config_t fetch; +``` + + +#### [Properties] The config for IMAP sequence set fetching + +This property has the sub properties + +##### [MB_String] string - The sequence set string i.g., unique identifier (UID) +or message sequence number or ranges of UID or sequence number. + +##### [bool] UID - The option for sequenceSet whether it is UID or message sequence number. + +##### [bool] headerOnly - The option for header only fetching. + +```cpp +esp_mail_imap_sequence_set_t fetch; +``` + + +#### [Properties] The config for search + +This property has the sub properties + +##### [MB_String] criteria - The search criteria. + +##### [boolean] unseen_msg - The option to search the unseen message. + +```cpp +esp_mail_imap_search_config_t search; +``` + + +#### [Properties] The config about the limits + +This property has the sub properties + +##### [size_t] search - The maximum messages from the search result. + +##### [size_t] fetch - The maximum messages from the sequence set fetching result. + +##### [size_t] msg_size - The maximum size of the memory buffer to store the message content. + +This is only limit for data to be stored in the IMAPSession. + +##### [size_t] attachment_size - The maximum size of each attachment to download. + +The IMAP idle (polling) timeout in ms (1 min to 29 min). Default is 10 min. + +##### [size_t] imap_idle_timeout - The IMAP idle timeout in ms. + +The IMAP idle (polling) host check interval in ms (30 sec to imap_idle_timeout) +for internet availability checking to ensure the connection is active. + +Default is 1 min. + +##### [size_t] imap_idle_host_check_interval - The IMAP idle host check interval in ms. + + +```cpp +esp_mail_imap_limit_config_t limit; +``` + + + +#### [Properties] The config to enable the features + +This property has the sub properties + +##### [boolean] text - To store the PLAIN text of the message in the IMAPSession. + +##### [boolean] html - To store the HTML of the message in the IMAPSession. + +##### [boolean] rfc822 - To store the rfc822 messages in the IMAPSession. + +##### [boolean] download_status - To enable the download status via the serial port. + +##### [boolean] recent_sort - To sort the message UID of the search result in descending order. + +##### [boolean] header_case_sesitive - To allow case sesitive in header parsing. + +```cpp +esp_mail_imap_enable_config_t enable; +``` + + + +#### [Properties] The config about downloads + +This property has the sub properties + +##### [boolean] text - To download the PLAIN text content of the message. + +##### [boolean] html - To download the HTML content of the message. + +##### [boolean] attachment - To download the attachments of the message. + +##### [boolean] inlineImg - To download the inline image of the message. + +##### [boolean] rfc822 - To download the rfc822 mesages in the message. + +##### [boolean] header - To download the message header. + +```cpp +esp_mail_imap_download_config_t download; +``` + + + +#### [Properties] The config about the storage and path to save the downloaded file. + +This property has the sub properties + +##### [const char*] saved_path - The path to save the downloaded file. + +##### [esp_mail_file_storage_type] type - The type of file storages enumeration e.g. + +esp_mail_file_storage_type_none = 0, + +esp_mail_file_storage_type_flash = 1, and + +esp_mail_file_storage_type_sd = 2 + +```cpp +esp_mail_imap_storage_config_t storage; +``` + + +#### [Properties] The config about firmware updates and downloads for ESP32, ESP8266 and Raspberry Pi Pico. + +This property has the sub properties + +##### [string] attach_filename - Update firmware using message attachments if one of its filename matches. + +##### [bool] save_to_file - Save firmware file option. + +```cpp +esp_mail_imap_firmware_config_t firmware_update; +``` + + + +## esp_mail_smtp_embed_message_body_t structured data + + +The following properties are available from the IMAP_Data data type. + +This data type is used for storing the IMAP transport and operating options to +control and store the operation result e.g. the messahe contents from search and fetch. + + + + +##### [Properties] Enable to send this message body as file + +```cpp +bool enable; +``` + + +##### [Properties] The name of embedded file + +```cpp +const char* enable; +``` + + +##### [Properties] The embedded type enumeration + +esp_mail_smtp_embed_message_type_attachment = 0 + +sp_mail_smtp_embed_message_type_inline = 1 + +```cpp +esp_mail_smtp_embed_message_type type; +``` + +## esp_mail_blob_message_content_t structured data + + +The following properties are available from the esp_mail_blob_message_content_t data type. + +This data type is used for storing the blob info of message body. + + + +##### [Properties] The array of content in flash memory. + +```cpp +const uint8_t * data; +``` + + +##### [Properties] The array size in bytes. + +```cpp +size_t size; +``` + + + + + +## esp_mail_file_message_content_t structured data + + +The following properties are available from the esp_mail_file_message_content_t data type. + +This data type is used for storing the file info of message body. + + +##### [Properties] The file path include its name. + +```cpp +const char *name; +``` + + +##### [Properties] The type of file storages. + +```cpp +esp_mail_file_storage_type type; +``` + + + + + +## IMAP_MSG_Item type data + + +The following properties are available from the IMAP_MSG_Item data type. + +This data type is used for message item info and its contents from search and fetch. + + + + +#### [Properties] The message number + +```cpp +int msgNo; +``` + + +#### [Properties] The message UID + +```cpp +int UID; +``` + + +#### [Properties] The message identifier + +```cpp +const char *ID; +``` + + + +#### [Properties] The language(s) for auto-responses + +```cpp +const char *acceptLang; +``` + + + +#### [Properties] The language of message content + +```cpp +const char *contentLang; +``` + + + +#### [Properties] The mailbox of message author + +```cpp +const char *from; +``` + + +#### [Properties] The charset of the mailbox of message author (deprecate) + +```cpp +const char *fromCharset; +``` + + +#### [Properties] The primary recipient mailbox + +```cpp +const char *to; +``` + + +#### [Properties] The charset of the primary recipient mailbox (deprecate) + +```cpp +const char *toCharset; +``` + + +#### [Properties] The Carbon-copy recipient mailboxes + +```cpp +const char *cc; +``` + + +#### [Properties] The charset of the Carbon-copy recipient mailbox header (deprecate) + +```cpp +const char *ccCharset; +``` + +#### [Properties] The message date and time + +```cpp +const char *date; +``` + +#### [Properties] The topic of message + +```cpp +const char *subject; +``` + +#### [Properties] The topic of message charset (deprecate) + +```cpp +const char *subjectCharset; +``` + +#### [Properties] The PLAIN text content of the message + +```cpp +esp_mail_plain_body_t text; +``` + +#### [Properties] The HTML content of the message + +```cpp +esp_mail_html_body_t html; +``` + +#### [Properties] The sender Email + +```cpp +const char *sender; +``` + + +#### [Properties] The charset of the sender Email (obsoleted) + +```cpp +const char *senderCharset; +``` + + +#### [Properties] The keywords or phrases, separated by commas + +```cpp +const char *keyword; +``` + +#### [Properties] The comments about message + +```cpp +const char *comments; +``` + + +#### [Properties] The return recipient of the message + +```cpp +const char *return_path; +``` + + +#### [Properties] The Email address to reply + +```cpp +const char *reply_to; +``` + + +#### [Properties] The field that contains the parent's message ID of the message to which this one is a reply + +```cpp +const char *in_reply_to; +``` + + +#### [Properties] The field that contains the parent's references (if any) and followed by the parent's message ID (if any) of the message to which this one is a reply + +```cpp +const char *references; +``` + + +#### [Properties] The Blind carbon-copy recipients + +```cpp +const char *bcc; +``` + +#### [Properties] The charset of the Blind carbon-copy recipient mailbox header (obsoleted) + +```cpp +const char *bccCharset; +``` + + +#### [Properties] The error description from fetching the message + +```cpp +const char *fetchError; +``` + + +#### [Properties] The info about the attachments in the message + +```cpp +std::vector attachments; +``` + +#### [Properties] The info about the rfc822 messages included in the message + +```cpp +std::vector rfc822; +``` + + + + +## IMAP_Response type data + +The following properties are available from the IMAP_Response data type. + +This data type obtains the response from sending custom IMAP commands. + + +#### [Properties] The status tag + +```cpp +MB_String tag; +``` + +#### [Properties] The status text + +```cpp +MB_String text; +``` + + +#### [Properties] The completion of response + +```cpp +bool completed; +``` + + + + + + +## MIME_Data_Stream_Info type data + +The following properties are available from the MIME_Data_Stream_Info data type. + +This data type obtains the IMAP multipart body or MIME stream data via the callback function. + + +#### [Properties] The message UID + +```cpp +uint32_t uid; +``` + +#### [Properties] The content type of the message part + +```cpp +const char *type; +``` + +#### [Properties] The content disposition of the message part + +```cpp +const char *disposition; +``` + + +#### [Properties] The content character set of the message part + +```cpp +const char *charSet; +``` + + +#### [Properties] The text content flowed format parameter of the message part + +```cpp +bool flowed; +``` + + +#### [Properties] The text content format DelSp parameter of the message part + +```cpp +bool delsp; +``` + + +#### [Properties] The content transfer encoding of the message part + +```cpp +const char *transfer_encoding; +``` + + +#### [Properties] The content ID of the inline attachment type message part + +```cpp +const char *cid; +``` + + +#### [Properties] The content description of the message part + +```cpp +const char *description; +``` + +#### [Properties] The file name of the attachment type message part + +```cpp +const char *filename; +``` + + +#### [Properties] The name of the attachment type message part + +```cpp +const char *name; +``` + + +#### [Properties] The creation date of the message part + +```cpp +const char *date; +``` + +#### [Properties] The size of the attachment (unencoded) type message part + +```cpp +size_t size; +``` + + +#### [Properties] The total octet of the message part + +```cpp +size_t octet_size; +``` + +#### [Properties] The current octet count of the message part that currently parses + +```cpp +int octet_count; +``` + +#### [Properties] The size of content (unencoded) of message part + +```cpp +size_t data_size; +``` + + +#### [Properties] The data buffer of message part that currently parses + +```cpp +void *data; +``` + + +#### [Properties] The flag that states the first chunk data of message part that currently parses + +```cpp +bool isFirstData; +``` + +#### [Properties] The flag that states the final chunk data of message part that currently parses + +```cpp +bool isLastData; +``` + + + + +## IMAP_Decoding_Info type data + +The following properties are available from the IMAP_Decoding_Info data type. + +This data type obtains the IMAP header and text (plain and html) strings to be decoded via the callback function based on its character set. + + +#### [Properties] The character set of the string to decode + +```cpp +const char *charset; +``` + +#### [Properties] The string to decode + +```cpp +const char *data; +``` + + +#### [Properties] The type of data that currently processed + +0 or IMAP_Decoding_Info::message_part_type_header + +1 or IMAP_Decoding_Info::message_part_type_text + +```cpp +message_part_type type; +``` + + + + + +## Search Criteria + +Search crieria is used for searching the mailbox for messages that match +the given searching criteria. + +Searching criteria consist of one or more search keys. When multiple keys are +specified, the result is the intersection (AND function) of all the messages +that match those keys. + +Example: + + **`DELETED FROM "SMITH" SINCE 1-Feb-1994`** refers +to all deleted messages from Smith that were placed in the mailbox since +February 1, 1994. + +A search key can also be a parenthesized list of one or more search keys +(e.g., for use with the OR and NOT keys). + +**`SINCE 10-Feb-2019`** will search all messages that received since 10 Feb 2019 + +**`UID SEARCH ALL`** will seach all message which will return the message UID +that can be use later for fetch one or more messages. + + +The following keywords can be used for the search criteria. + + +**ALL** - All messages in the mailbox; the default initial key for ANDing. + +**ANSWERED** - Messages with the \Answered flag set. + +**BCC** - Messages that contain the specified string in the envelope structure's BCC field. + +**BEFORE** - Messages whose internal date (disregarding time and timezone) is earlier than the specified date. + +**BODY** - Messages that contain the specified string in the body of the message. + +**CC** - Messages that contain the specified string in the envelope structure's CC field. + +**DELETED** - Messages with the \Deleted flag set. + +**DRAFT** - Messages with the \Draft flag set. + +**FLAGGED** - Messages with the \Flagged flag set. + +**FROM** - Messages that contain the specified string in the envelope structure's FROM field. + +**HEADER** - Messages that have a header with the specified field-name (as defined in [RFC-2822]) + +and that contains the specified string in the text of the header (what comes after the colon). + +If the string to search is zero-length, this matches all messages that have a header line with + +the specified field-name regardless of the contents. + +**KEYWORD** - Messages with the specified keyword flag set. + +**LARGER** - Messages with an (RFC-2822) size larger than the specified number of octets. + +**NEW** - Messages that have the \Recent flag set but not the \Seen flag. + +This is functionally equivalent to **"(RECENT UNSEEN)"**. + +**NOT** - Messages that do not match the specified search key. + +**OLD** - Messages that do not have the \Recent flag set. This is functionally equivalent to + +**"NOT RECENT"** (as opposed to **"NOT NEW"**). + +**ON** - Messages whose internal date (disregarding time and timezone) is within the specified date. + +**OR** - Messages that match either search key. + +**RECENT** - Messages that have the \Recent flag set. + +**SEEN** - Messages that have the \Seen flag set. + +**SENTBEFORE** - Messages whose (RFC-2822) Date: header (disregarding time and timezone) is earlier than the specified date. + +**SENTON** - Messages whose (RFC-2822) Date: header (disregarding time and timezone) is within the specified date. + +**SENTSINCE** - Messages whose (RFC-2822) Date: header (disregarding time and timezone) is within or later than the specified date. + +**SINCE** - Messages whose internal date (disregarding time and timezone) is within or later than the specified date. + +**SMALLER** - Messages with an (RFC-2822) size smaller than the specified number of octets. + +**SUBJECT** - Messages that contain the specified string in the envelope structure's SUBJECT field. + +**TEXT** - Messages that contain the specified string in the header or body of the message. + +**TO** - Messages that contain the specified string in the envelope structure's TO field. + +**UID** - Messages with unique identifiers corresponding to the specified unique identifier set. + +Sequence set ranges are permitted. + +**UNANSWERED** - Messages that do not have the \Answered flag set. + +**UNDELETED** - Messages that do not have the \Deleted flag set. + +**UNDRAFT** - Messages that do not have the \Draft flag set. + +**UNFLAGGED** - Messages that do not have the \Flagged flag set. + +**UNKEYWORD** - Messages that do not have the specified keyword flag set. + +**UNSEEN** - Messages that do not have the \Seen flag set. + + + + + + + + + +## MailClient.Time functions + + +The helper function to set and get the system time. + + + + + +#### Set the system time from the NTP server. + +param **`gmtOffset`** The GMT time offset in hour. + +param **`daylightOffset`** The Daylight time offset in hour. + +return **`boolean`** The status indicates the success of operation. + +This requires internet connection + +```cpp +bool setClock(float gmtOffset, float daylightOffset); +``` + + + + + +#### Get the timestamp from the year, month, date, hour, minute, and second provided. + +param **`year`** The year. + +param **`mon`** The months from 1 to 12. + +param **`date`** The dates. + +param **`hour`** The hours. + +param **`mins`** The minutes. + +param **`sec`** The seconds. + +return **`time_t`** The value of timestamp. + +```cpp +time_t getTimestamp(int year, int mon, int date, int hour, int mins, int sec); +``` + + + + +#### Get the timestamp from the time string. + +param **`gmt`** Return GMT time. + +return **`timestamp`** of time string. + +```cpp +time_t getTimestamp(const char* timeString, bool gmt = false); +``` + + + + + + +#### Get the current timestamp. + +return **`uint64_t`** The value of current timestamp. + +```cpp +uint64_t getCurrentTimestamp(); +``` + + + + + + +#### Get the current date time string that valid for Email + +return **`String`** The current date time string. + +```cpp +String getDateTimeString(); +``` + + + + + + +## License + +The MIT License (MIT) + +Copyright (c) 2023 K. Suwatchai (Mobizt) + + +Permission is hereby granted, free of charge, to any person returning a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/Custom_ESP_SSLClient_FS.h b/lib/libesp32/ESP-Mail-Client/src/SSLClient/Custom_ESP_SSLClient_FS.h new file mode 100644 index 000000000..1f28bdb0c --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/Custom_ESP_SSLClient_FS.h @@ -0,0 +1,23 @@ + +#ifndef CUSTOM_ESP_SSLCLIENT_FS_H +#define CUSTOM_ESP_SSLCLIENT_FS_H + +#include "../ESP_Mail_FS.h" + +#if defined(ESP_MAIL_DISABLE_SSL) +#undef USE_LIB_SSL_ENGINE +#undef USE_EMBED_SSL_ENGINE +#endif + +#if defined(ESP_MAIL_USE_PSRAM) +#if !defined(ESP_SSLCLIENT_USE_PSRAM) +#define ESP_SSLCLIENT_USE_PSRAM +#endif +#else +#undef ESP_SSLCLIENT_USE_PSRAM +#endif + +#undef ESP_SSLCLIENT_ENABLE_DEBUG +#undef ESP_SSLCLIENT_ENABLE_SSL_ERROR_STRING + +#endif diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/ESP_SSLClient.h b/lib/libesp32/ESP-Mail-Client/src/SSLClient/ESP_SSLClient.h new file mode 100644 index 000000000..a77b08080 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/ESP_SSLClient.h @@ -0,0 +1,79 @@ +/** + * + * The ESP SSL Client Class, ESP_SSLClient.h v2.1.6 + * + * Created August 27, 2023 + * + * The MIT License (MIT) + * Copyright (c) 2023 K. Suwatchai (Mobizt) + * + * + * Permission is hereby granted, free of charge, to any person returning a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef ESP_SSLCLIENT_H +#define ESP_SSLCLIENT_H + +#include "ESP_SSLClient_FS.h" + +#ifndef SSLCLIENT_CONNECTION_UPGRADABLE +#define SSLCLIENT_CONNECTION_UPGRADABLE +#endif +#include "ESP_SSLClient_Const.h" +#if defined(USE_EMBED_SSL_ENGINE) || defined(USE_LIB_SSL_ENGINE) +#include "client/BSSL_TCP_Client.h" +class ESP_SSLClient : public BSSL_TCP_Client +{ +public: + ESP_SSLClient(){}; + ~ESP_SSLClient(){}; +}; + +class ESP_SSLClient2 : public BSSL_TCP_Client +{ +public: + ESP_SSLClient2(Client &client, bool enableSSL = true) : _base_client(client) + { + setClient(&_base_client, enableSSL); + }; + ~ESP_SSLClient2(){}; + +private: + Client &_base_client; +}; + +#else +class ESP_SSLClient +{ +public: + ESP_SSLClient(){}; + ~ESP_SSLClient(){}; +}; + +class ESP_SSLClient2 +{ +public: + ESP_SSLClient2(Client &client, bool enableSSL = true) : _base_client(client){}; + ~ESP_SSLClient2(){}; + +private: + Client &_base_client; +}; +#endif + +#endif diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/ESP_SSLClient_Const.h b/lib/libesp32/ESP-Mail-Client/src/SSLClient/ESP_SSLClient_Const.h new file mode 100644 index 000000000..290e702ba --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/ESP_SSLClient_Const.h @@ -0,0 +1,138 @@ +#ifndef ESP_SSLCLIENT_CONST_H +#define ESP_SSLCLIENT_CONST_H + +#pragma GCC diagnostic ignored "-Wunused-function" +#pragma GCC diagnostic ignored "-Wvla" + +#include "ESP_SSLClient_FS.h" + +#include +#include + +#if defined(__AVR__) +#undef USE_LIB_SSL_ENGINE +#undef USE_EMBED_SSL_ENGINE +#error "Not support AVR architecture" +#endif + +#define ESP_SSLCLIENT_VALID_TIMESTAMP 1690979919 + +#ifndef SSLCLIENT_CONNECTION_UPGRADABLE +#define SSLCLIENT_CONNECTION_UPGRADABLE +#endif + +#ifdef ESP_SSLCLIENT_ENABLE_DEBUG +#if !defined(ESP_SSLCLIENT_DEBUG_PORT) +#define ESP_SSLCLIENT_DEBUG_PORT Serial +#endif +#define ESP_SSLCLIENT_DEBUG_PRINT ESP_SSLCLIENT_DEBUG_PORT.print +#else +#define ESP_SSLCLIENT_DEBUG_PRINT(...) +#endif + +#if !defined(FPSTR) +#define FPSTR +#endif + +#if defined(USE_EMBED_SSL_ENGINE) || defined(USE_LIB_SSL_ENGINE) + +enum esp_ssl_client_debug_level +{ + esp_ssl_debug_none = 0, + esp_ssl_debug_error = 1, + esp_ssl_debug_warn = 2, + esp_ssl_debug_info = 3, + esp_ssl_debug_dump = 4 +}; + +enum esp_ssl_client_error_types +{ + esp_ssl_ok, + esp_ssl_connection_fail, + esp_ssl_write_error, + esp_ssl_read_error, + esp_ssl_out_of_memory, + esp_ssl_internal_error +}; + +#if defined(ESP_SSLCLIENT_ENABLE_DEBUG) + +static void esp_ssl_debug_print_prefix(const char *func_name, int level) +{ + ESP_SSLCLIENT_DEBUG_PRINT(PSTR("> ")); + // print the debug level + switch (level) + { + case esp_ssl_debug_info: + ESP_SSLCLIENT_DEBUG_PRINT(PSTR("INFO.")); + break; + case esp_ssl_debug_warn: + ESP_SSLCLIENT_DEBUG_PRINT(PSTR("WARN.")); + break; + case esp_ssl_debug_error: + ESP_SSLCLIENT_DEBUG_PRINT(PSTR("ERROR.")); + break; + default: + break; + } + + // print the function name + ESP_SSLCLIENT_DEBUG_PRINT(PSTR("")); + ESP_SSLCLIENT_DEBUG_PRINT(func_name); + ESP_SSLCLIENT_DEBUG_PRINT(PSTR(": ")); +} + +static void esp_ssl_debug_print(PGM_P msg, int debug_level, int level, const char *func_name) +{ + if (debug_level >= level) + { + esp_ssl_debug_print_prefix(func_name, level); + ESP_SSLCLIENT_DEBUG_PRINT(msg); + ESP_SSLCLIENT_DEBUG_PRINT("\r\n"); + } +} + +#endif + +static uint8_t htoi(unsigned char c) +{ + if (c >= '0' && c <= '9') + return c - '0'; + else if (c >= 'A' && c <= 'F') + return 10 + c - 'A'; + else if (c >= 'a' && c <= 'f') + return 10 + c - 'a'; + else + return 255; +} + +// Helper function which aborts a TLS handshake by sending TLS +// ClientAbort and ClientClose messages. +static bool send_abort(Client *probe, bool supportsLen) +{ + // If we're still connected, send the appropriate notice that + // we're aborting the handshake per RFCs. + static const uint8_t clientAbort_P[] PROGMEM = { + 0x15 /*alert*/, 0x03, 0x03 /*TLS 1.2*/, 0x00, 0x02, + 1, 90 /* warning: user_cancelled */ + }; + static const uint8_t clientClose_P[] PROGMEM = { + 0x15 /*alert*/, 0x03, 0x03 /*TLS 1.2*/, 0x00, 0x02, + 1, 0 /* warning: close_notify */ + }; + if (probe->connected()) + { + uint8_t msg[sizeof(clientAbort_P)]; + memcpy_P(msg, clientAbort_P, sizeof(clientAbort_P)); + probe->write(msg, sizeof(clientAbort_P)); + memcpy_P(msg, clientClose_P, sizeof(clientClose_P)); + probe->write(msg, sizeof(clientClose_P)); + } + return supportsLen; +} + +const uint16_t _secure_ports[26] = {443 /* HTTPS */, 465 /* SMTP */, 563 /* NNTP */, 636 /* LDAPS */, 695 /* IEEE-MMS-SSL */, 832 /* NETCONF */, 853 /* DNS */, 989 /* FTPS */, 990 /* FTPS */, 992 /* Telnet */, 993 /* IMAP */, 995 /* POP3 */, 4116 /* Smartcard */, 4843 /* OPC */, 5061 /* SIP */, 5085 /* LLIP */, 5349 /* NAT */, 5671 /* AMQP */, 5986 /* WinRM-HTTPS */, 6513 /* NETCONF */, 6514 /* Syslog */, 6515 /* Elipse RPC */, 6619 /* OFTP */, 8243 /* Apache Synapse */, 8403 /* GxFWD */, 8883 /* MQTT */}; + +#endif + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/ESP_SSLClient_FS.h b/lib/libesp32/ESP-Mail-Client/src/SSLClient/ESP_SSLClient_FS.h new file mode 100644 index 000000000..8c56a873c --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/ESP_SSLClient_FS.h @@ -0,0 +1,42 @@ +#ifndef ESP_SSLClient_FS_H +#define ESP_SSLClient_FS_H + +// #if (defined(ESP8266) || defined(ARDUINO_ARCH_RP2040)) && !defined(ARDUINO_NANO_RP2040_CONNECT) +// // for ESP8266 and Raspberry Pi Pico (RP2040) only except for Arduino Nano RP2040 Connect +// #define USE_EMBED_SSL_ENGINE +// #else +#define USE_LIB_SSL_ENGINE +// #endif + +#pragma once + +// for enable debugging +#define ESP_SSLCLIENT_ENABLE_DEBUG + +/** Call ssl_client.setDebugLevel(x) to set the debug + * esp_ssl_debug_none = 0 + * esp_ssl_debug_error = 1 + * esp_ssl_debug_warn = 2 + * esp_ssl_debug_info = 3 + * esp_ssl_debug_dump = 4 + */ + +// for debug port +#define ESP_SSLCLIENT_DEBUG_PORT Serial + +// for SSL Error String +#define ESP_SSLCLIENT_ENABLE_SSL_ERROR_STRING + +// for Filesystem support that required for CertStore +#define ESP_SSLCLIENT_USE_FILESYSTEM + +// For external SRAM (PSRAM) support +#define ESP_SSLCLIENT_USE_PSRAM + +#if defined __has_include +#if __has_include() +#include "Custom_ESP_SSLClient_FS.h" +#endif +#endif + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_big_cbcdec.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_big_cbcdec.c new file mode 100644 index 000000000..547d714bc --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_big_cbcdec.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_block.h */ +void +br_aes_big_cbcdec_init(br_aes_big_cbcdec_keys *ctx, + const void *key, size_t len) +{ + ctx->vtable = &br_aes_big_cbcdec_vtable; + ctx->num_rounds = br_aes_big_keysched_inv(ctx->skey, key, len); +} + +/* see bearssl_block.h */ +void +br_aes_big_cbcdec_run(const br_aes_big_cbcdec_keys *ctx, + void *iv, void *data, size_t len) +{ + unsigned char *buf, *ivbuf; + + ivbuf = iv; + buf = data; + while (len > 0) { + unsigned char tmp[16]; + int i; + + memcpy(tmp, buf, 16); + br_aes_big_decrypt(ctx->num_rounds, ctx->skey, buf); + for (i = 0; i < 16; i ++) { + buf[i] ^= ivbuf[i]; + } + memcpy(ivbuf, tmp, 16); + buf += 16; + len -= 16; + } +} + +/* see bearssl_block.h */ +const br_block_cbcdec_class br_aes_big_cbcdec_vtable = { + sizeof(br_aes_big_cbcdec_keys), + 16, + 4, + (void (*)(const br_block_cbcdec_class **, const void *, size_t)) + &br_aes_big_cbcdec_init, + (void (*)(const br_block_cbcdec_class *const *, void *, void *, size_t)) + &br_aes_big_cbcdec_run +}; + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_big_cbcenc.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_big_cbcenc.c new file mode 100644 index 000000000..801568fc7 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_big_cbcenc.c @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_block.h */ +void +br_aes_big_cbcenc_init(br_aes_big_cbcenc_keys *ctx, + const void *key, size_t len) +{ + ctx->vtable = &br_aes_big_cbcenc_vtable; + ctx->num_rounds = br_aes_keysched(ctx->skey, key, len); +} + +/* see bearssl_block.h */ +void +br_aes_big_cbcenc_run(const br_aes_big_cbcenc_keys *ctx, + void *iv, void *data, size_t len) +{ + unsigned char *buf, *ivbuf; + + ivbuf = iv; + buf = data; + while (len > 0) { + int i; + + for (i = 0; i < 16; i ++) { + buf[i] ^= ivbuf[i]; + } + br_aes_big_encrypt(ctx->num_rounds, ctx->skey, buf); + memcpy(ivbuf, buf, 16); + buf += 16; + len -= 16; + } +} + +/* see bearssl_block.h */ +const br_block_cbcenc_class br_aes_big_cbcenc_vtable = { + sizeof(br_aes_big_cbcenc_keys), + 16, + 4, + (void (*)(const br_block_cbcenc_class **, const void *, size_t)) + &br_aes_big_cbcenc_init, + (void (*)(const br_block_cbcenc_class *const *, void *, void *, size_t)) + &br_aes_big_cbcenc_run +}; + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_big_ctr.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_big_ctr.c new file mode 100644 index 000000000..b6b18ab8b --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_big_ctr.c @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_block.h */ +void +br_aes_big_ctr_init(br_aes_big_ctr_keys *ctx, + const void *key, size_t len) +{ + ctx->vtable = &br_aes_big_ctr_vtable; + ctx->num_rounds = br_aes_keysched(ctx->skey, key, len); +} + +static void +xorbuf(void *dst, const void *src, size_t len) +{ + unsigned char *d; + const unsigned char *s; + + d = dst; + s = src; + while (len -- > 0) { + *d ++ ^= *s ++; + } +} + +/* see bearssl_block.h */ +uint32_t +br_aes_big_ctr_run(const br_aes_big_ctr_keys *ctx, + const void *iv, uint32_t cc, void *data, size_t len) +{ + unsigned char *buf; + + buf = data; + while (len > 0) { + unsigned char tmp[16]; + + memcpy(tmp, iv, 12); + br_enc32be(tmp + 12, cc ++); + br_aes_big_encrypt(ctx->num_rounds, ctx->skey, tmp); + if (len <= 16) { + xorbuf(buf, tmp, len); + break; + } + xorbuf(buf, tmp, 16); + buf += 16; + len -= 16; + } + return cc; +} + +/* see bearssl_block.h */ +const br_block_ctr_class br_aes_big_ctr_vtable = { + sizeof(br_aes_big_ctr_keys), + 16, + 4, + (void (*)(const br_block_ctr_class **, const void *, size_t)) + &br_aes_big_ctr_init, + (uint32_t (*)(const br_block_ctr_class *const *, + const void *, uint32_t, void *, size_t)) + &br_aes_big_ctr_run +}; + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_big_ctrcbc.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_big_ctrcbc.c new file mode 100644 index 000000000..27cb153f3 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_big_ctrcbc.c @@ -0,0 +1,147 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_block.h */ +void +br_aes_big_ctrcbc_init(br_aes_big_ctrcbc_keys *ctx, + const void *key, size_t len) +{ + ctx->vtable = &br_aes_big_ctrcbc_vtable; + ctx->num_rounds = br_aes_keysched(ctx->skey, key, len); +} + +static void +xorbuf(void *dst, const void *src, size_t len) +{ + unsigned char *d; + const unsigned char *s; + + d = dst; + s = src; + while (len -- > 0) { + *d ++ ^= *s ++; + } +} + +/* see bearssl_block.h */ +void +br_aes_big_ctrcbc_ctr(const br_aes_big_ctrcbc_keys *ctx, + void *ctr, void *data, size_t len) +{ + unsigned char *buf, *bctr; + uint32_t cc0, cc1, cc2, cc3; + + buf = data; + bctr = ctr; + cc3 = br_dec32be(bctr + 0); + cc2 = br_dec32be(bctr + 4); + cc1 = br_dec32be(bctr + 8); + cc0 = br_dec32be(bctr + 12); + while (len > 0) { + unsigned char tmp[16]; + uint32_t carry; + + br_enc32be(tmp + 0, cc3); + br_enc32be(tmp + 4, cc2); + br_enc32be(tmp + 8, cc1); + br_enc32be(tmp + 12, cc0); + br_aes_big_encrypt(ctx->num_rounds, ctx->skey, tmp); + xorbuf(buf, tmp, 16); + buf += 16; + len -= 16; + cc0 ++; + carry = (~(cc0 | -cc0)) >> 31; + cc1 += carry; + carry &= (~(cc1 | -cc1)) >> 31; + cc2 += carry; + carry &= (~(cc2 | -cc2)) >> 31; + cc3 += carry; + } + br_enc32be(bctr + 0, cc3); + br_enc32be(bctr + 4, cc2); + br_enc32be(bctr + 8, cc1); + br_enc32be(bctr + 12, cc0); +} + +/* see bearssl_block.h */ +void +br_aes_big_ctrcbc_mac(const br_aes_big_ctrcbc_keys *ctx, + void *cbcmac, const void *data, size_t len) +{ + const unsigned char *buf; + + buf = data; + while (len > 0) { + xorbuf(cbcmac, buf, 16); + br_aes_big_encrypt(ctx->num_rounds, ctx->skey, cbcmac); + buf += 16; + len -= 16; + } +} + +/* see bearssl_block.h */ +void +br_aes_big_ctrcbc_encrypt(const br_aes_big_ctrcbc_keys *ctx, + void *ctr, void *cbcmac, void *data, size_t len) +{ + br_aes_big_ctrcbc_ctr(ctx, ctr, data, len); + br_aes_big_ctrcbc_mac(ctx, cbcmac, data, len); +} + +/* see bearssl_block.h */ +void +br_aes_big_ctrcbc_decrypt(const br_aes_big_ctrcbc_keys *ctx, + void *ctr, void *cbcmac, void *data, size_t len) +{ + br_aes_big_ctrcbc_mac(ctx, cbcmac, data, len); + br_aes_big_ctrcbc_ctr(ctx, ctr, data, len); +} + +/* see bearssl_block.h */ +const br_block_ctrcbc_class br_aes_big_ctrcbc_vtable = { + sizeof(br_aes_big_ctrcbc_keys), + 16, + 4, + (void (*)(const br_block_ctrcbc_class **, const void *, size_t)) + &br_aes_big_ctrcbc_init, + (void (*)(const br_block_ctrcbc_class *const *, + void *, void *, void *, size_t)) + &br_aes_big_ctrcbc_encrypt, + (void (*)(const br_block_ctrcbc_class *const *, + void *, void *, void *, size_t)) + &br_aes_big_ctrcbc_decrypt, + (void (*)(const br_block_ctrcbc_class *const *, + void *, void *, size_t)) + &br_aes_big_ctrcbc_ctr, + (void (*)(const br_block_ctrcbc_class *const *, + void *, const void *, size_t)) + &br_aes_big_ctrcbc_mac +}; + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_big_dec.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_big_dec.c new file mode 100644 index 000000000..56c33b96c --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_big_dec.c @@ -0,0 +1,259 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* + * Inverse S-box (used in key schedule for decryption). + */ +static const unsigned char iS[] = { + 0x52, 0x09, 0x6A, 0xD5, 0x30, 0x36, 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 0xC0, 0xFE, 0x78, 0xCD, 0x5A, 0xF4, + 0x1F, 0xDD, 0xA8, 0x33, 0x88, 0x07, 0xC7, 0x31, 0xB1, 0x12, 0x10, 0x59, + 0x27, 0x80, 0xEC, 0x5F, 0x60, 0x51, 0x7F, 0xA9, 0x19, 0xB5, 0x4A, 0x0D, + 0x2D, 0xE5, 0x7A, 0x9F, 0x93, 0xC9, 0x9C, 0xEF, 0xA0, 0xE0, 0x3B, 0x4D, + 0xAE, 0x2A, 0xF5, 0xB0, 0xC8, 0xEB, 0xBB, 0x3C, 0x83, 0x53, 0x99, 0x61, + 0x17, 0x2B, 0x04, 0x7E, 0xBA, 0x77, 0xD6, 0x26, 0xE1, 0x69, 0x14, 0x63, + 0x55, 0x21, 0x0C, 0x7D +}; + +static const uint32_t iSsm0[] = { + 0x51F4A750, 0x7E416553, 0x1A17A4C3, 0x3A275E96, 0x3BAB6BCB, 0x1F9D45F1, + 0xACFA58AB, 0x4BE30393, 0x2030FA55, 0xAD766DF6, 0x88CC7691, 0xF5024C25, + 0x4FE5D7FC, 0xC52ACBD7, 0x26354480, 0xB562A38F, 0xDEB15A49, 0x25BA1B67, + 0x45EA0E98, 0x5DFEC0E1, 0xC32F7502, 0x814CF012, 0x8D4697A3, 0x6BD3F9C6, + 0x038F5FE7, 0x15929C95, 0xBF6D7AEB, 0x955259DA, 0xD4BE832D, 0x587421D3, + 0x49E06929, 0x8EC9C844, 0x75C2896A, 0xF48E7978, 0x99583E6B, 0x27B971DD, + 0xBEE14FB6, 0xF088AD17, 0xC920AC66, 0x7DCE3AB4, 0x63DF4A18, 0xE51A3182, + 0x97513360, 0x62537F45, 0xB16477E0, 0xBB6BAE84, 0xFE81A01C, 0xF9082B94, + 0x70486858, 0x8F45FD19, 0x94DE6C87, 0x527BF8B7, 0xAB73D323, 0x724B02E2, + 0xE31F8F57, 0x6655AB2A, 0xB2EB2807, 0x2FB5C203, 0x86C57B9A, 0xD33708A5, + 0x302887F2, 0x23BFA5B2, 0x02036ABA, 0xED16825C, 0x8ACF1C2B, 0xA779B492, + 0xF307F2F0, 0x4E69E2A1, 0x65DAF4CD, 0x0605BED5, 0xD134621F, 0xC4A6FE8A, + 0x342E539D, 0xA2F355A0, 0x058AE132, 0xA4F6EB75, 0x0B83EC39, 0x4060EFAA, + 0x5E719F06, 0xBD6E1051, 0x3E218AF9, 0x96DD063D, 0xDD3E05AE, 0x4DE6BD46, + 0x91548DB5, 0x71C45D05, 0x0406D46F, 0x605015FF, 0x1998FB24, 0xD6BDE997, + 0x894043CC, 0x67D99E77, 0xB0E842BD, 0x07898B88, 0xE7195B38, 0x79C8EEDB, + 0xA17C0A47, 0x7C420FE9, 0xF8841EC9, 0x00000000, 0x09808683, 0x322BED48, + 0x1E1170AC, 0x6C5A724E, 0xFD0EFFFB, 0x0F853856, 0x3DAED51E, 0x362D3927, + 0x0A0FD964, 0x685CA621, 0x9B5B54D1, 0x24362E3A, 0x0C0A67B1, 0x9357E70F, + 0xB4EE96D2, 0x1B9B919E, 0x80C0C54F, 0x61DC20A2, 0x5A774B69, 0x1C121A16, + 0xE293BA0A, 0xC0A02AE5, 0x3C22E043, 0x121B171D, 0x0E090D0B, 0xF28BC7AD, + 0x2DB6A8B9, 0x141EA9C8, 0x57F11985, 0xAF75074C, 0xEE99DDBB, 0xA37F60FD, + 0xF701269F, 0x5C72F5BC, 0x44663BC5, 0x5BFB7E34, 0x8B432976, 0xCB23C6DC, + 0xB6EDFC68, 0xB8E4F163, 0xD731DCCA, 0x42638510, 0x13972240, 0x84C61120, + 0x854A247D, 0xD2BB3DF8, 0xAEF93211, 0xC729A16D, 0x1D9E2F4B, 0xDCB230F3, + 0x0D8652EC, 0x77C1E3D0, 0x2BB3166C, 0xA970B999, 0x119448FA, 0x47E96422, + 0xA8FC8CC4, 0xA0F03F1A, 0x567D2CD8, 0x223390EF, 0x87494EC7, 0xD938D1C1, + 0x8CCAA2FE, 0x98D40B36, 0xA6F581CF, 0xA57ADE28, 0xDAB78E26, 0x3FADBFA4, + 0x2C3A9DE4, 0x5078920D, 0x6A5FCC9B, 0x547E4662, 0xF68D13C2, 0x90D8B8E8, + 0x2E39F75E, 0x82C3AFF5, 0x9F5D80BE, 0x69D0937C, 0x6FD52DA9, 0xCF2512B3, + 0xC8AC993B, 0x10187DA7, 0xE89C636E, 0xDB3BBB7B, 0xCD267809, 0x6E5918F4, + 0xEC9AB701, 0x834F9AA8, 0xE6956E65, 0xAAFFE67E, 0x21BCCF08, 0xEF15E8E6, + 0xBAE79BD9, 0x4A6F36CE, 0xEA9F09D4, 0x29B07CD6, 0x31A4B2AF, 0x2A3F2331, + 0xC6A59430, 0x35A266C0, 0x744EBC37, 0xFC82CAA6, 0xE090D0B0, 0x33A7D815, + 0xF104984A, 0x41ECDAF7, 0x7FCD500E, 0x1791F62F, 0x764DD68D, 0x43EFB04D, + 0xCCAA4D54, 0xE49604DF, 0x9ED1B5E3, 0x4C6A881B, 0xC12C1FB8, 0x4665517F, + 0x9D5EEA04, 0x018C355D, 0xFA877473, 0xFB0B412E, 0xB3671D5A, 0x92DBD252, + 0xE9105633, 0x6DD64713, 0x9AD7618C, 0x37A10C7A, 0x59F8148E, 0xEB133C89, + 0xCEA927EE, 0xB761C935, 0xE11CE5ED, 0x7A47B13C, 0x9CD2DF59, 0x55F2733F, + 0x1814CE79, 0x73C737BF, 0x53F7CDEA, 0x5FFDAA5B, 0xDF3D6F14, 0x7844DB86, + 0xCAAFF381, 0xB968C43E, 0x3824342C, 0xC2A3405F, 0x161DC372, 0xBCE2250C, + 0x283C498B, 0xFF0D9541, 0x39A80171, 0x080CB3DE, 0xD8B4E49C, 0x6456C190, + 0x7BCB8461, 0xD532B670, 0x486C5C74, 0xD0B85742 +}; + +static unsigned +mul2(unsigned x) +{ + x <<= 1; + return x ^ ((unsigned)(-(int)(x >> 8)) & 0x11B); +} + +static unsigned +mul9(unsigned x) +{ + return x ^ mul2(mul2(mul2(x))); +} + +static unsigned +mulb(unsigned x) +{ + unsigned x2; + + x2 = mul2(x); + return x ^ x2 ^ mul2(mul2(x2)); +} + +static unsigned +muld(unsigned x) +{ + unsigned x4; + + x4 = mul2(mul2(x)); + return x ^ x4 ^ mul2(x4); +} + +static unsigned +mule(unsigned x) +{ + unsigned x2, x4; + + x2 = mul2(x); + x4 = mul2(x2); + return x2 ^ x4 ^ mul2(x4); +} + +/* see inner.h */ +unsigned +br_aes_big_keysched_inv(uint32_t *skey, const void *key, size_t key_len) +{ + unsigned num_rounds; + int i, m; + + /* + * Sub-keys for decryption are distinct from encryption sub-keys + * in that InvMixColumns() is already applied for the inner + * rounds. + */ + num_rounds = br_aes_keysched(skey, key, key_len); + m = (int)(num_rounds << 2); + for (i = 4; i < m; i ++) { + uint32_t p; + unsigned p0, p1, p2, p3; + uint32_t q0, q1, q2, q3; + + p = skey[i]; + p0 = p >> 24; + p1 = (p >> 16) & 0xFF; + p2 = (p >> 8) & 0xFF; + p3 = p & 0xFF; + q0 = mule(p0) ^ mulb(p1) ^ muld(p2) ^ mul9(p3); + q1 = mul9(p0) ^ mule(p1) ^ mulb(p2) ^ muld(p3); + q2 = muld(p0) ^ mul9(p1) ^ mule(p2) ^ mulb(p3); + q3 = mulb(p0) ^ muld(p1) ^ mul9(p2) ^ mule(p3); + skey[i] = (q0 << 24) | (q1 << 16) | (q2 << 8) | q3; + } + return num_rounds; +} + +static inline uint32_t +rotr(uint32_t x, int n) +{ + return (x << (32 - n)) | (x >> n); +} + +#define iSboxExt0(x) (iSsm0[x]) +#define iSboxExt1(x) (rotr(iSsm0[x], 8)) +#define iSboxExt2(x) (rotr(iSsm0[x], 16)) +#define iSboxExt3(x) (rotr(iSsm0[x], 24)) + +/* see bearssl.h */ +void +br_aes_big_decrypt(unsigned num_rounds, const uint32_t *skey, void *data) +{ + unsigned char *buf; + uint32_t s0, s1, s2, s3; + uint32_t t0, t1, t2, t3; + unsigned u; + + buf = data; + s0 = br_dec32be(buf); + s1 = br_dec32be(buf + 4); + s2 = br_dec32be(buf + 8); + s3 = br_dec32be(buf + 12); + s0 ^= skey[(num_rounds << 2) + 0]; + s1 ^= skey[(num_rounds << 2) + 1]; + s2 ^= skey[(num_rounds << 2) + 2]; + s3 ^= skey[(num_rounds << 2) + 3]; + for (u = num_rounds - 1; u > 0; u --) { + uint32_t v0 = iSboxExt0(s0 >> 24) + ^ iSboxExt1((s3 >> 16) & 0xFF) + ^ iSboxExt2((s2 >> 8) & 0xFF) + ^ iSboxExt3(s1 & 0xFF); + uint32_t v1 = iSboxExt0(s1 >> 24) + ^ iSboxExt1((s0 >> 16) & 0xFF) + ^ iSboxExt2((s3 >> 8) & 0xFF) + ^ iSboxExt3(s2 & 0xFF); + uint32_t v2 = iSboxExt0(s2 >> 24) + ^ iSboxExt1((s1 >> 16) & 0xFF) + ^ iSboxExt2((s0 >> 8) & 0xFF) + ^ iSboxExt3(s3 & 0xFF); + uint32_t v3 = iSboxExt0(s3 >> 24) + ^ iSboxExt1((s2 >> 16) & 0xFF) + ^ iSboxExt2((s1 >> 8) & 0xFF) + ^ iSboxExt3(s0 & 0xFF); + s0 = v0; + s1 = v1; + s2 = v2; + s3 = v3; + s0 ^= skey[u << 2]; + s1 ^= skey[(u << 2) + 1]; + s2 ^= skey[(u << 2) + 2]; + s3 ^= skey[(u << 2) + 3]; + } + t0 = ((uint32_t)iS[s0 >> 24] << 24) + | ((uint32_t)iS[(s3 >> 16) & 0xFF] << 16) + | ((uint32_t)iS[(s2 >> 8) & 0xFF] << 8) + | (uint32_t)iS[s1 & 0xFF]; + t1 = ((uint32_t)iS[s1 >> 24] << 24) + | ((uint32_t)iS[(s0 >> 16) & 0xFF] << 16) + | ((uint32_t)iS[(s3 >> 8) & 0xFF] << 8) + | (uint32_t)iS[s2 & 0xFF]; + t2 = ((uint32_t)iS[s2 >> 24] << 24) + | ((uint32_t)iS[(s1 >> 16) & 0xFF] << 16) + | ((uint32_t)iS[(s0 >> 8) & 0xFF] << 8) + | (uint32_t)iS[s3 & 0xFF]; + t3 = ((uint32_t)iS[s3 >> 24] << 24) + | ((uint32_t)iS[(s2 >> 16) & 0xFF] << 16) + | ((uint32_t)iS[(s1 >> 8) & 0xFF] << 8) + | (uint32_t)iS[s0 & 0xFF]; + s0 = t0 ^ skey[0]; + s1 = t1 ^ skey[1]; + s2 = t2 ^ skey[2]; + s3 = t3 ^ skey[3]; + br_enc32be(buf, s0); + br_enc32be(buf + 4, s1); + br_enc32be(buf + 8, s2); + br_enc32be(buf + 12, s3); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_big_enc.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_big_enc.c new file mode 100644 index 000000000..29af02e22 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_big_enc.c @@ -0,0 +1,162 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +#define S br_aes_S + +static const uint32_t Ssm0[] = { + 0xC66363A5, 0xF87C7C84, 0xEE777799, 0xF67B7B8D, 0xFFF2F20D, 0xD66B6BBD, + 0xDE6F6FB1, 0x91C5C554, 0x60303050, 0x02010103, 0xCE6767A9, 0x562B2B7D, + 0xE7FEFE19, 0xB5D7D762, 0x4DABABE6, 0xEC76769A, 0x8FCACA45, 0x1F82829D, + 0x89C9C940, 0xFA7D7D87, 0xEFFAFA15, 0xB25959EB, 0x8E4747C9, 0xFBF0F00B, + 0x41ADADEC, 0xB3D4D467, 0x5FA2A2FD, 0x45AFAFEA, 0x239C9CBF, 0x53A4A4F7, + 0xE4727296, 0x9BC0C05B, 0x75B7B7C2, 0xE1FDFD1C, 0x3D9393AE, 0x4C26266A, + 0x6C36365A, 0x7E3F3F41, 0xF5F7F702, 0x83CCCC4F, 0x6834345C, 0x51A5A5F4, + 0xD1E5E534, 0xF9F1F108, 0xE2717193, 0xABD8D873, 0x62313153, 0x2A15153F, + 0x0804040C, 0x95C7C752, 0x46232365, 0x9DC3C35E, 0x30181828, 0x379696A1, + 0x0A05050F, 0x2F9A9AB5, 0x0E070709, 0x24121236, 0x1B80809B, 0xDFE2E23D, + 0xCDEBEB26, 0x4E272769, 0x7FB2B2CD, 0xEA75759F, 0x1209091B, 0x1D83839E, + 0x582C2C74, 0x341A1A2E, 0x361B1B2D, 0xDC6E6EB2, 0xB45A5AEE, 0x5BA0A0FB, + 0xA45252F6, 0x763B3B4D, 0xB7D6D661, 0x7DB3B3CE, 0x5229297B, 0xDDE3E33E, + 0x5E2F2F71, 0x13848497, 0xA65353F5, 0xB9D1D168, 0x00000000, 0xC1EDED2C, + 0x40202060, 0xE3FCFC1F, 0x79B1B1C8, 0xB65B5BED, 0xD46A6ABE, 0x8DCBCB46, + 0x67BEBED9, 0x7239394B, 0x944A4ADE, 0x984C4CD4, 0xB05858E8, 0x85CFCF4A, + 0xBBD0D06B, 0xC5EFEF2A, 0x4FAAAAE5, 0xEDFBFB16, 0x864343C5, 0x9A4D4DD7, + 0x66333355, 0x11858594, 0x8A4545CF, 0xE9F9F910, 0x04020206, 0xFE7F7F81, + 0xA05050F0, 0x783C3C44, 0x259F9FBA, 0x4BA8A8E3, 0xA25151F3, 0x5DA3A3FE, + 0x804040C0, 0x058F8F8A, 0x3F9292AD, 0x219D9DBC, 0x70383848, 0xF1F5F504, + 0x63BCBCDF, 0x77B6B6C1, 0xAFDADA75, 0x42212163, 0x20101030, 0xE5FFFF1A, + 0xFDF3F30E, 0xBFD2D26D, 0x81CDCD4C, 0x180C0C14, 0x26131335, 0xC3ECEC2F, + 0xBE5F5FE1, 0x359797A2, 0x884444CC, 0x2E171739, 0x93C4C457, 0x55A7A7F2, + 0xFC7E7E82, 0x7A3D3D47, 0xC86464AC, 0xBA5D5DE7, 0x3219192B, 0xE6737395, + 0xC06060A0, 0x19818198, 0x9E4F4FD1, 0xA3DCDC7F, 0x44222266, 0x542A2A7E, + 0x3B9090AB, 0x0B888883, 0x8C4646CA, 0xC7EEEE29, 0x6BB8B8D3, 0x2814143C, + 0xA7DEDE79, 0xBC5E5EE2, 0x160B0B1D, 0xADDBDB76, 0xDBE0E03B, 0x64323256, + 0x743A3A4E, 0x140A0A1E, 0x924949DB, 0x0C06060A, 0x4824246C, 0xB85C5CE4, + 0x9FC2C25D, 0xBDD3D36E, 0x43ACACEF, 0xC46262A6, 0x399191A8, 0x319595A4, + 0xD3E4E437, 0xF279798B, 0xD5E7E732, 0x8BC8C843, 0x6E373759, 0xDA6D6DB7, + 0x018D8D8C, 0xB1D5D564, 0x9C4E4ED2, 0x49A9A9E0, 0xD86C6CB4, 0xAC5656FA, + 0xF3F4F407, 0xCFEAEA25, 0xCA6565AF, 0xF47A7A8E, 0x47AEAEE9, 0x10080818, + 0x6FBABAD5, 0xF0787888, 0x4A25256F, 0x5C2E2E72, 0x381C1C24, 0x57A6A6F1, + 0x73B4B4C7, 0x97C6C651, 0xCBE8E823, 0xA1DDDD7C, 0xE874749C, 0x3E1F1F21, + 0x964B4BDD, 0x61BDBDDC, 0x0D8B8B86, 0x0F8A8A85, 0xE0707090, 0x7C3E3E42, + 0x71B5B5C4, 0xCC6666AA, 0x904848D8, 0x06030305, 0xF7F6F601, 0x1C0E0E12, + 0xC26161A3, 0x6A35355F, 0xAE5757F9, 0x69B9B9D0, 0x17868691, 0x99C1C158, + 0x3A1D1D27, 0x279E9EB9, 0xD9E1E138, 0xEBF8F813, 0x2B9898B3, 0x22111133, + 0xD26969BB, 0xA9D9D970, 0x078E8E89, 0x339494A7, 0x2D9B9BB6, 0x3C1E1E22, + 0x15878792, 0xC9E9E920, 0x87CECE49, 0xAA5555FF, 0x50282878, 0xA5DFDF7A, + 0x038C8C8F, 0x59A1A1F8, 0x09898980, 0x1A0D0D17, 0x65BFBFDA, 0xD7E6E631, + 0x844242C6, 0xD06868B8, 0x824141C3, 0x299999B0, 0x5A2D2D77, 0x1E0F0F11, + 0x7BB0B0CB, 0xA85454FC, 0x6DBBBBD6, 0x2C16163A +}; + +static inline uint32_t +rotr(uint32_t x, int n) +{ + return (x << (32 - n)) | (x >> n); +} + +#define SboxExt0(x) (Ssm0[x]) +#define SboxExt1(x) (rotr(Ssm0[x], 8)) +#define SboxExt2(x) (rotr(Ssm0[x], 16)) +#define SboxExt3(x) (rotr(Ssm0[x], 24)) + + +/* see bearssl.h */ +void +br_aes_big_encrypt(unsigned num_rounds, const uint32_t *skey, void *data) +{ + unsigned char *buf; + uint32_t s0, s1, s2, s3; + uint32_t t0, t1, t2, t3; + unsigned u; + + buf = data; + s0 = br_dec32be(buf); + s1 = br_dec32be(buf + 4); + s2 = br_dec32be(buf + 8); + s3 = br_dec32be(buf + 12); + s0 ^= skey[0]; + s1 ^= skey[1]; + s2 ^= skey[2]; + s3 ^= skey[3]; + for (u = 1; u < num_rounds; u ++) { + uint32_t v0, v1, v2, v3; + + v0 = SboxExt0(s0 >> 24) + ^ SboxExt1((s1 >> 16) & 0xFF) + ^ SboxExt2((s2 >> 8) & 0xFF) + ^ SboxExt3(s3 & 0xFF); + v1 = SboxExt0(s1 >> 24) + ^ SboxExt1((s2 >> 16) & 0xFF) + ^ SboxExt2((s3 >> 8) & 0xFF) + ^ SboxExt3(s0 & 0xFF); + v2 = SboxExt0(s2 >> 24) + ^ SboxExt1((s3 >> 16) & 0xFF) + ^ SboxExt2((s0 >> 8) & 0xFF) + ^ SboxExt3(s1 & 0xFF); + v3 = SboxExt0(s3 >> 24) + ^ SboxExt1((s0 >> 16) & 0xFF) + ^ SboxExt2((s1 >> 8) & 0xFF) + ^ SboxExt3(s2 & 0xFF); + s0 = v0; + s1 = v1; + s2 = v2; + s3 = v3; + s0 ^= skey[u << 2]; + s1 ^= skey[(u << 2) + 1]; + s2 ^= skey[(u << 2) + 2]; + s3 ^= skey[(u << 2) + 3]; + } + t0 = ((uint32_t)S[s0 >> 24] << 24) + | ((uint32_t)S[(s1 >> 16) & 0xFF] << 16) + | ((uint32_t)S[(s2 >> 8) & 0xFF] << 8) + | (uint32_t)S[s3 & 0xFF]; + t1 = ((uint32_t)S[s1 >> 24] << 24) + | ((uint32_t)S[(s2 >> 16) & 0xFF] << 16) + | ((uint32_t)S[(s3 >> 8) & 0xFF] << 8) + | (uint32_t)S[s0 & 0xFF]; + t2 = ((uint32_t)S[s2 >> 24] << 24) + | ((uint32_t)S[(s3 >> 16) & 0xFF] << 16) + | ((uint32_t)S[(s0 >> 8) & 0xFF] << 8) + | (uint32_t)S[s1 & 0xFF]; + t3 = ((uint32_t)S[s3 >> 24] << 24) + | ((uint32_t)S[(s0 >> 16) & 0xFF] << 16) + | ((uint32_t)S[(s1 >> 8) & 0xFF] << 8) + | (uint32_t)S[s2 & 0xFF]; + s0 = t0 ^ skey[num_rounds << 2]; + s1 = t1 ^ skey[(num_rounds << 2) + 1]; + s2 = t2 ^ skey[(num_rounds << 2) + 2]; + s3 = t3 ^ skey[(num_rounds << 2) + 3]; + br_enc32be(buf, s0); + br_enc32be(buf + 4, s1); + br_enc32be(buf + 8, s2); + br_enc32be(buf + 12, s3); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_common.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_common.c new file mode 100644 index 000000000..e216c94bd --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_common.c @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +static const uint32_t Rcon[] = { + 0x01000000, 0x02000000, 0x04000000, 0x08000000, 0x10000000, 0x20000000, + 0x40000000, 0x80000000, 0x1B000000, 0x36000000 +}; + +#define S br_aes_S + +/* see inner.h */ +const unsigned char br_aes_S[] = { + 0x63, 0x7C, 0x77, 0x7B, 0xF2, 0x6B, 0x6F, 0xC5, 0x30, 0x01, 0x67, 0x2B, + 0xFE, 0xD7, 0xAB, 0x76, 0xCA, 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xA6, 0xB4, 0xC6, 0xE8, 0xDD, 0x74, 0x1F, + 0x4B, 0xBD, 0x8B, 0x8A, 0x70, 0x3E, 0xB5, 0x66, 0x48, 0x03, 0xF6, 0x0E, + 0x61, 0x35, 0x57, 0xB9, 0x86, 0xC1, 0x1D, 0x9E, 0xE1, 0xF8, 0x98, 0x11, + 0x69, 0xD9, 0x8E, 0x94, 0x9B, 0x1E, 0x87, 0xE9, 0xCE, 0x55, 0x28, 0xDF, + 0x8C, 0xA1, 0x89, 0x0D, 0xBF, 0xE6, 0x42, 0x68, 0x41, 0x99, 0x2D, 0x0F, + 0xB0, 0x54, 0xBB, 0x16 +}; + +static uint32_t +SubWord(uint32_t x) +{ + return ((uint32_t)S[x >> 24] << 24) + | ((uint32_t)S[(x >> 16) & 0xFF] << 16) + | ((uint32_t)S[(x >> 8) & 0xFF] << 8) + | (uint32_t)S[x & 0xFF]; +} + +/* see inner.h */ +unsigned +br_aes_keysched(uint32_t *skey, const void *key, size_t key_len) +{ + unsigned num_rounds; + int i, j, k, nk, nkf; + + switch (key_len) { + case 16: + num_rounds = 10; + break; + case 24: + num_rounds = 12; + break; + case 32: + num_rounds = 14; + break; + default: + /* abort(); */ + return 0; + } + nk = (int)(key_len >> 2); + nkf = (int)((num_rounds + 1) << 2); + for (i = 0; i < nk; i ++) { + skey[i] = br_dec32be((const unsigned char *)key + (i << 2)); + } + for (i = nk, j = 0, k = 0; i < nkf; i ++) { + uint32_t tmp; + + tmp = skey[i - 1]; + if (j == 0) { + tmp = (tmp << 8) | (tmp >> 24); + tmp = SubWord(tmp) ^ Rcon[k]; + } else if (nk > 6 && j == 4) { + tmp = SubWord(tmp); + } + skey[i] = skey[i - nk] ^ tmp; + if (++ j == nk) { + j = 0; + k ++; + } + } + return num_rounds; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_ct.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_ct.c new file mode 100644 index 000000000..a2fcb783a --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_ct.c @@ -0,0 +1,333 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +void +br_aes_ct_bitslice_Sbox(uint32_t *q) +{ + /* + * This S-box implementation is a straightforward translation of + * the circuit described by Boyar and Peralta in "A new + * combinational logic minimization technique with applications + * to cryptology" (https://eprint.iacr.org/2009/191.pdf). + * + * Note that variables x* (input) and s* (output) are numbered + * in "reverse" order (x0 is the high bit, x7 is the low bit). + */ + + uint32_t x0, x1, x2, x3, x4, x5, x6, x7; + uint32_t y1, y2, y3, y4, y5, y6, y7, y8, y9; + uint32_t y10, y11, y12, y13, y14, y15, y16, y17, y18, y19; + uint32_t y20, y21; + uint32_t z0, z1, z2, z3, z4, z5, z6, z7, z8, z9; + uint32_t z10, z11, z12, z13, z14, z15, z16, z17; + uint32_t t0, t1, t2, t3, t4, t5, t6, t7, t8, t9; + uint32_t t10, t11, t12, t13, t14, t15, t16, t17, t18, t19; + uint32_t t20, t21, t22, t23, t24, t25, t26, t27, t28, t29; + uint32_t t30, t31, t32, t33, t34, t35, t36, t37, t38, t39; + uint32_t t40, t41, t42, t43, t44, t45, t46, t47, t48, t49; + uint32_t t50, t51, t52, t53, t54, t55, t56, t57, t58, t59; + uint32_t t60, t61, t62, t63, t64, t65, t66, t67; + uint32_t s0, s1, s2, s3, s4, s5, s6, s7; + + x0 = q[7]; + x1 = q[6]; + x2 = q[5]; + x3 = q[4]; + x4 = q[3]; + x5 = q[2]; + x6 = q[1]; + x7 = q[0]; + + /* + * Top linear transformation. + */ + y14 = x3 ^ x5; + y13 = x0 ^ x6; + y9 = x0 ^ x3; + y8 = x0 ^ x5; + t0 = x1 ^ x2; + y1 = t0 ^ x7; + y4 = y1 ^ x3; + y12 = y13 ^ y14; + y2 = y1 ^ x0; + y5 = y1 ^ x6; + y3 = y5 ^ y8; + t1 = x4 ^ y12; + y15 = t1 ^ x5; + y20 = t1 ^ x1; + y6 = y15 ^ x7; + y10 = y15 ^ t0; + y11 = y20 ^ y9; + y7 = x7 ^ y11; + y17 = y10 ^ y11; + y19 = y10 ^ y8; + y16 = t0 ^ y11; + y21 = y13 ^ y16; + y18 = x0 ^ y16; + + /* + * Non-linear section. + */ + t2 = y12 & y15; + t3 = y3 & y6; + t4 = t3 ^ t2; + t5 = y4 & x7; + t6 = t5 ^ t2; + t7 = y13 & y16; + t8 = y5 & y1; + t9 = t8 ^ t7; + t10 = y2 & y7; + t11 = t10 ^ t7; + t12 = y9 & y11; + t13 = y14 & y17; + t14 = t13 ^ t12; + t15 = y8 & y10; + t16 = t15 ^ t12; + t17 = t4 ^ t14; + t18 = t6 ^ t16; + t19 = t9 ^ t14; + t20 = t11 ^ t16; + t21 = t17 ^ y20; + t22 = t18 ^ y19; + t23 = t19 ^ y21; + t24 = t20 ^ y18; + + t25 = t21 ^ t22; + t26 = t21 & t23; + t27 = t24 ^ t26; + t28 = t25 & t27; + t29 = t28 ^ t22; + t30 = t23 ^ t24; + t31 = t22 ^ t26; + t32 = t31 & t30; + t33 = t32 ^ t24; + t34 = t23 ^ t33; + t35 = t27 ^ t33; + t36 = t24 & t35; + t37 = t36 ^ t34; + t38 = t27 ^ t36; + t39 = t29 & t38; + t40 = t25 ^ t39; + + t41 = t40 ^ t37; + t42 = t29 ^ t33; + t43 = t29 ^ t40; + t44 = t33 ^ t37; + t45 = t42 ^ t41; + z0 = t44 & y15; + z1 = t37 & y6; + z2 = t33 & x7; + z3 = t43 & y16; + z4 = t40 & y1; + z5 = t29 & y7; + z6 = t42 & y11; + z7 = t45 & y17; + z8 = t41 & y10; + z9 = t44 & y12; + z10 = t37 & y3; + z11 = t33 & y4; + z12 = t43 & y13; + z13 = t40 & y5; + z14 = t29 & y2; + z15 = t42 & y9; + z16 = t45 & y14; + z17 = t41 & y8; + + /* + * Bottom linear transformation. + */ + t46 = z15 ^ z16; + t47 = z10 ^ z11; + t48 = z5 ^ z13; + t49 = z9 ^ z10; + t50 = z2 ^ z12; + t51 = z2 ^ z5; + t52 = z7 ^ z8; + t53 = z0 ^ z3; + t54 = z6 ^ z7; + t55 = z16 ^ z17; + t56 = z12 ^ t48; + t57 = t50 ^ t53; + t58 = z4 ^ t46; + t59 = z3 ^ t54; + t60 = t46 ^ t57; + t61 = z14 ^ t57; + t62 = t52 ^ t58; + t63 = t49 ^ t58; + t64 = z4 ^ t59; + t65 = t61 ^ t62; + t66 = z1 ^ t63; + s0 = t59 ^ t63; + s6 = t56 ^ ~t62; + s7 = t48 ^ ~t60; + t67 = t64 ^ t65; + s3 = t53 ^ t66; + s4 = t51 ^ t66; + s5 = t47 ^ t65; + s1 = t64 ^ ~s3; + s2 = t55 ^ ~t67; + + q[7] = s0; + q[6] = s1; + q[5] = s2; + q[4] = s3; + q[3] = s4; + q[2] = s5; + q[1] = s6; + q[0] = s7; +} + +/* see inner.h */ +void +br_aes_ct_ortho(uint32_t *q) +{ +#define SWAPN(cl, ch, s, x, y) do { \ + uint32_t a, b; \ + a = (x); \ + b = (y); \ + (x) = (a & (uint32_t)cl) | ((b & (uint32_t)cl) << (s)); \ + (y) = ((a & (uint32_t)ch) >> (s)) | (b & (uint32_t)ch); \ + } while (0) + +#define SWAP2(x, y) SWAPN(0x55555555, 0xAAAAAAAA, 1, x, y) +#define SWAP4(x, y) SWAPN(0x33333333, 0xCCCCCCCC, 2, x, y) +#define SWAP8(x, y) SWAPN(0x0F0F0F0F, 0xF0F0F0F0, 4, x, y) + + SWAP2(q[0], q[1]); + SWAP2(q[2], q[3]); + SWAP2(q[4], q[5]); + SWAP2(q[6], q[7]); + + SWAP4(q[0], q[2]); + SWAP4(q[1], q[3]); + SWAP4(q[4], q[6]); + SWAP4(q[5], q[7]); + + SWAP8(q[0], q[4]); + SWAP8(q[1], q[5]); + SWAP8(q[2], q[6]); + SWAP8(q[3], q[7]); +} + +static const unsigned char Rcon[] = { + 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1B, 0x36 +}; + +static uint32_t +sub_word(uint32_t x) +{ + uint32_t q[8]; + int i; + + for (i = 0; i < 8; i ++) { + q[i] = x; + } + br_aes_ct_ortho(q); + br_aes_ct_bitslice_Sbox(q); + br_aes_ct_ortho(q); + return q[0]; +} + +/* see inner.h */ +unsigned +br_aes_ct_keysched(uint32_t *comp_skey, const void *key, size_t key_len) +{ + unsigned num_rounds; + int i, j, k, nk, nkf; + uint32_t tmp; + uint32_t skey[120]; + + switch (key_len) { + case 16: + num_rounds = 10; + break; + case 24: + num_rounds = 12; + break; + case 32: + num_rounds = 14; + break; + default: + /* abort(); */ + return 0; + } + nk = (int)(key_len >> 2); + nkf = (int)((num_rounds + 1) << 2); + tmp = 0; + for (i = 0; i < nk; i ++) { + tmp = br_dec32le((const unsigned char *)key + (i << 2)); + skey[(i << 1) + 0] = tmp; + skey[(i << 1) + 1] = tmp; + } + for (i = nk, j = 0, k = 0; i < nkf; i ++) { + if (j == 0) { + tmp = (tmp << 24) | (tmp >> 8); + tmp = sub_word(tmp) ^ Rcon[k]; + } else if (nk > 6 && j == 4) { + tmp = sub_word(tmp); + } + tmp ^= skey[(i - nk) << 1]; + skey[(i << 1) + 0] = tmp; + skey[(i << 1) + 1] = tmp; + if (++ j == nk) { + j = 0; + k ++; + } + } + for (i = 0; i < nkf; i += 4) { + br_aes_ct_ortho(skey + (i << 1)); + } + for (i = 0, j = 0; i < nkf; i ++, j += 2) { + comp_skey[i] = (skey[j + 0] & 0x55555555) + | (skey[j + 1] & 0xAAAAAAAA); + } + return num_rounds; +} + +/* see inner.h */ +void +br_aes_ct_skey_expand(uint32_t *skey, + unsigned num_rounds, const uint32_t *comp_skey) +{ + unsigned u, v, n; + + n = (num_rounds + 1) << 2; + for (u = 0, v = 0; u < n; u ++, v += 2) { + uint32_t x, y; + + x = y = comp_skey[u]; + x &= 0x55555555; + skey[v + 0] = x | (x << 1); + y &= 0xAAAAAAAA; + skey[v + 1] = y | (y >> 1); + } +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_ct64.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_ct64.c new file mode 100644 index 000000000..54da2aa1c --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_ct64.c @@ -0,0 +1,403 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +void +br_aes_ct64_bitslice_Sbox(uint64_t *q) +{ + /* + * This S-box implementation is a straightforward translation of + * the circuit described by Boyar and Peralta in "A new + * combinational logic minimization technique with applications + * to cryptology" (https://eprint.iacr.org/2009/191.pdf). + * + * Note that variables x* (input) and s* (output) are numbered + * in "reverse" order (x0 is the high bit, x7 is the low bit). + */ + + uint64_t x0, x1, x2, x3, x4, x5, x6, x7; + uint64_t y1, y2, y3, y4, y5, y6, y7, y8, y9; + uint64_t y10, y11, y12, y13, y14, y15, y16, y17, y18, y19; + uint64_t y20, y21; + uint64_t z0, z1, z2, z3, z4, z5, z6, z7, z8, z9; + uint64_t z10, z11, z12, z13, z14, z15, z16, z17; + uint64_t t0, t1, t2, t3, t4, t5, t6, t7, t8, t9; + uint64_t t10, t11, t12, t13, t14, t15, t16, t17, t18, t19; + uint64_t t20, t21, t22, t23, t24, t25, t26, t27, t28, t29; + uint64_t t30, t31, t32, t33, t34, t35, t36, t37, t38, t39; + uint64_t t40, t41, t42, t43, t44, t45, t46, t47, t48, t49; + uint64_t t50, t51, t52, t53, t54, t55, t56, t57, t58, t59; + uint64_t t60, t61, t62, t63, t64, t65, t66, t67; + uint64_t s0, s1, s2, s3, s4, s5, s6, s7; + + x0 = q[7]; + x1 = q[6]; + x2 = q[5]; + x3 = q[4]; + x4 = q[3]; + x5 = q[2]; + x6 = q[1]; + x7 = q[0]; + + /* + * Top linear transformation. + */ + y14 = x3 ^ x5; + y13 = x0 ^ x6; + y9 = x0 ^ x3; + y8 = x0 ^ x5; + t0 = x1 ^ x2; + y1 = t0 ^ x7; + y4 = y1 ^ x3; + y12 = y13 ^ y14; + y2 = y1 ^ x0; + y5 = y1 ^ x6; + y3 = y5 ^ y8; + t1 = x4 ^ y12; + y15 = t1 ^ x5; + y20 = t1 ^ x1; + y6 = y15 ^ x7; + y10 = y15 ^ t0; + y11 = y20 ^ y9; + y7 = x7 ^ y11; + y17 = y10 ^ y11; + y19 = y10 ^ y8; + y16 = t0 ^ y11; + y21 = y13 ^ y16; + y18 = x0 ^ y16; + + /* + * Non-linear section. + */ + t2 = y12 & y15; + t3 = y3 & y6; + t4 = t3 ^ t2; + t5 = y4 & x7; + t6 = t5 ^ t2; + t7 = y13 & y16; + t8 = y5 & y1; + t9 = t8 ^ t7; + t10 = y2 & y7; + t11 = t10 ^ t7; + t12 = y9 & y11; + t13 = y14 & y17; + t14 = t13 ^ t12; + t15 = y8 & y10; + t16 = t15 ^ t12; + t17 = t4 ^ t14; + t18 = t6 ^ t16; + t19 = t9 ^ t14; + t20 = t11 ^ t16; + t21 = t17 ^ y20; + t22 = t18 ^ y19; + t23 = t19 ^ y21; + t24 = t20 ^ y18; + + t25 = t21 ^ t22; + t26 = t21 & t23; + t27 = t24 ^ t26; + t28 = t25 & t27; + t29 = t28 ^ t22; + t30 = t23 ^ t24; + t31 = t22 ^ t26; + t32 = t31 & t30; + t33 = t32 ^ t24; + t34 = t23 ^ t33; + t35 = t27 ^ t33; + t36 = t24 & t35; + t37 = t36 ^ t34; + t38 = t27 ^ t36; + t39 = t29 & t38; + t40 = t25 ^ t39; + + t41 = t40 ^ t37; + t42 = t29 ^ t33; + t43 = t29 ^ t40; + t44 = t33 ^ t37; + t45 = t42 ^ t41; + z0 = t44 & y15; + z1 = t37 & y6; + z2 = t33 & x7; + z3 = t43 & y16; + z4 = t40 & y1; + z5 = t29 & y7; + z6 = t42 & y11; + z7 = t45 & y17; + z8 = t41 & y10; + z9 = t44 & y12; + z10 = t37 & y3; + z11 = t33 & y4; + z12 = t43 & y13; + z13 = t40 & y5; + z14 = t29 & y2; + z15 = t42 & y9; + z16 = t45 & y14; + z17 = t41 & y8; + + /* + * Bottom linear transformation. + */ + t46 = z15 ^ z16; + t47 = z10 ^ z11; + t48 = z5 ^ z13; + t49 = z9 ^ z10; + t50 = z2 ^ z12; + t51 = z2 ^ z5; + t52 = z7 ^ z8; + t53 = z0 ^ z3; + t54 = z6 ^ z7; + t55 = z16 ^ z17; + t56 = z12 ^ t48; + t57 = t50 ^ t53; + t58 = z4 ^ t46; + t59 = z3 ^ t54; + t60 = t46 ^ t57; + t61 = z14 ^ t57; + t62 = t52 ^ t58; + t63 = t49 ^ t58; + t64 = z4 ^ t59; + t65 = t61 ^ t62; + t66 = z1 ^ t63; + s0 = t59 ^ t63; + s6 = t56 ^ ~t62; + s7 = t48 ^ ~t60; + t67 = t64 ^ t65; + s3 = t53 ^ t66; + s4 = t51 ^ t66; + s5 = t47 ^ t65; + s1 = t64 ^ ~s3; + s2 = t55 ^ ~t67; + + q[7] = s0; + q[6] = s1; + q[5] = s2; + q[4] = s3; + q[3] = s4; + q[2] = s5; + q[1] = s6; + q[0] = s7; +} + +/* see inner.h */ +void +br_aes_ct64_ortho(uint64_t *q) +{ +#define SWAPN(cl, ch, s, x, y) do { \ + uint64_t a, b; \ + a = (x); \ + b = (y); \ + (x) = (a & (uint64_t)cl) | ((b & (uint64_t)cl) << (s)); \ + (y) = ((a & (uint64_t)ch) >> (s)) | (b & (uint64_t)ch); \ + } while (0) + +#define SWAP2(x, y) SWAPN(0x5555555555555555, 0xAAAAAAAAAAAAAAAA, 1, x, y) +#define SWAP4(x, y) SWAPN(0x3333333333333333, 0xCCCCCCCCCCCCCCCC, 2, x, y) +#define SWAP8(x, y) SWAPN(0x0F0F0F0F0F0F0F0F, 0xF0F0F0F0F0F0F0F0, 4, x, y) + + SWAP2(q[0], q[1]); + SWAP2(q[2], q[3]); + SWAP2(q[4], q[5]); + SWAP2(q[6], q[7]); + + SWAP4(q[0], q[2]); + SWAP4(q[1], q[3]); + SWAP4(q[4], q[6]); + SWAP4(q[5], q[7]); + + SWAP8(q[0], q[4]); + SWAP8(q[1], q[5]); + SWAP8(q[2], q[6]); + SWAP8(q[3], q[7]); +} + +/* see inner.h */ +void +br_aes_ct64_interleave_in(uint64_t *q0, uint64_t *q1, const uint32_t *w) +{ + uint64_t x0, x1, x2, x3; + + x0 = w[0]; + x1 = w[1]; + x2 = w[2]; + x3 = w[3]; + x0 |= (x0 << 16); + x1 |= (x1 << 16); + x2 |= (x2 << 16); + x3 |= (x3 << 16); + x0 &= (uint64_t)0x0000FFFF0000FFFF; + x1 &= (uint64_t)0x0000FFFF0000FFFF; + x2 &= (uint64_t)0x0000FFFF0000FFFF; + x3 &= (uint64_t)0x0000FFFF0000FFFF; + x0 |= (x0 << 8); + x1 |= (x1 << 8); + x2 |= (x2 << 8); + x3 |= (x3 << 8); + x0 &= (uint64_t)0x00FF00FF00FF00FF; + x1 &= (uint64_t)0x00FF00FF00FF00FF; + x2 &= (uint64_t)0x00FF00FF00FF00FF; + x3 &= (uint64_t)0x00FF00FF00FF00FF; + *q0 = x0 | (x2 << 8); + *q1 = x1 | (x3 << 8); +} + +/* see inner.h */ +void +br_aes_ct64_interleave_out(uint32_t *w, uint64_t q0, uint64_t q1) +{ + uint64_t x0, x1, x2, x3; + + x0 = q0 & (uint64_t)0x00FF00FF00FF00FF; + x1 = q1 & (uint64_t)0x00FF00FF00FF00FF; + x2 = (q0 >> 8) & (uint64_t)0x00FF00FF00FF00FF; + x3 = (q1 >> 8) & (uint64_t)0x00FF00FF00FF00FF; + x0 |= (x0 >> 8); + x1 |= (x1 >> 8); + x2 |= (x2 >> 8); + x3 |= (x3 >> 8); + x0 &= (uint64_t)0x0000FFFF0000FFFF; + x1 &= (uint64_t)0x0000FFFF0000FFFF; + x2 &= (uint64_t)0x0000FFFF0000FFFF; + x3 &= (uint64_t)0x0000FFFF0000FFFF; + w[0] = (uint32_t)x0 | (uint32_t)(x0 >> 16); + w[1] = (uint32_t)x1 | (uint32_t)(x1 >> 16); + w[2] = (uint32_t)x2 | (uint32_t)(x2 >> 16); + w[3] = (uint32_t)x3 | (uint32_t)(x3 >> 16); +} + +static const unsigned char Rcon[] = { + 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1B, 0x36 +}; + +static uint32_t +sub_word(uint32_t x) +{ + uint64_t q[8]; + + memset(q, 0, sizeof q); + q[0] = x; + br_aes_ct64_ortho(q); + br_aes_ct64_bitslice_Sbox(q); + br_aes_ct64_ortho(q); + return (uint32_t)q[0]; +} + +/* see inner.h */ +unsigned +br_aes_ct64_keysched(uint64_t *comp_skey, const void *key, size_t key_len) +{ + unsigned num_rounds; + int i, j, k, nk, nkf; + uint32_t tmp; + uint32_t skey[60]; + + switch (key_len) { + case 16: + num_rounds = 10; + break; + case 24: + num_rounds = 12; + break; + case 32: + num_rounds = 14; + break; + default: + /* abort(); */ + return 0; + } + nk = (int)(key_len >> 2); + nkf = (int)((num_rounds + 1) << 2); + br_range_dec32le(skey, (key_len >> 2), key); + tmp = skey[(key_len >> 2) - 1]; + for (i = nk, j = 0, k = 0; i < nkf; i ++) { + if (j == 0) { + tmp = (tmp << 24) | (tmp >> 8); + tmp = sub_word(tmp) ^ Rcon[k]; + } else if (nk > 6 && j == 4) { + tmp = sub_word(tmp); + } + tmp ^= skey[i - nk]; + skey[i] = tmp; + if (++ j == nk) { + j = 0; + k ++; + } + } + + for (i = 0, j = 0; i < nkf; i += 4, j += 2) { + uint64_t q[8]; + + br_aes_ct64_interleave_in(&q[0], &q[4], skey + i); + q[1] = q[0]; + q[2] = q[0]; + q[3] = q[0]; + q[5] = q[4]; + q[6] = q[4]; + q[7] = q[4]; + br_aes_ct64_ortho(q); + comp_skey[j + 0] = + (q[0] & (uint64_t)0x1111111111111111) + | (q[1] & (uint64_t)0x2222222222222222) + | (q[2] & (uint64_t)0x4444444444444444) + | (q[3] & (uint64_t)0x8888888888888888); + comp_skey[j + 1] = + (q[4] & (uint64_t)0x1111111111111111) + | (q[5] & (uint64_t)0x2222222222222222) + | (q[6] & (uint64_t)0x4444444444444444) + | (q[7] & (uint64_t)0x8888888888888888); + } + return num_rounds; +} + +/* see inner.h */ +void +br_aes_ct64_skey_expand(uint64_t *skey, + unsigned num_rounds, const uint64_t *comp_skey) +{ + unsigned u, v, n; + + n = (num_rounds + 1) << 1; + for (u = 0, v = 0; u < n; u ++, v += 4) { + uint64_t x0, x1, x2, x3; + + x0 = x1 = x2 = x3 = comp_skey[u]; + x0 &= (uint64_t)0x1111111111111111; + x1 &= (uint64_t)0x2222222222222222; + x2 &= (uint64_t)0x4444444444444444; + x3 &= (uint64_t)0x8888888888888888; + x1 >>= 1; + x2 >>= 2; + x3 >>= 3; + skey[v + 0] = (x0 << 4) - x0; + skey[v + 1] = (x1 << 4) - x1; + skey[v + 2] = (x2 << 4) - x2; + skey[v + 3] = (x3 << 4) - x3; + } +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_ct64_cbcdec.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_ct64_cbcdec.c new file mode 100644 index 000000000..2827fa2db --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_ct64_cbcdec.c @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_block.h */ +void +br_aes_ct64_cbcdec_init(br_aes_ct64_cbcdec_keys *ctx, + const void *key, size_t len) +{ + ctx->vtable = &br_aes_ct64_cbcdec_vtable; + ctx->num_rounds = br_aes_ct64_keysched(ctx->skey, key, len); +} + +/* see bearssl_block.h */ +void +br_aes_ct64_cbcdec_run(const br_aes_ct64_cbcdec_keys *ctx, + void *iv, void *data, size_t len) +{ + unsigned char *buf; + uint64_t sk_exp[120]; + uint32_t ivw[4]; + + br_aes_ct64_skey_expand(sk_exp, ctx->num_rounds, ctx->skey); + br_range_dec32le(ivw, 4, iv); + buf = data; + while (len > 0) { + uint64_t q[8]; + uint32_t w1[16], w2[16]; + int i; + + if (len >= 64) { + br_range_dec32le(w1, 16, buf); + } else { + br_range_dec32le(w1, len >> 2, buf); + } + for (i = 0; i < 4; i ++) { + br_aes_ct64_interleave_in( + &q[i], &q[i + 4], w1 + (i << 2)); + } + br_aes_ct64_ortho(q); + br_aes_ct64_bitslice_decrypt(ctx->num_rounds, sk_exp, q); + br_aes_ct64_ortho(q); + for (i = 0; i < 4; i ++) { + br_aes_ct64_interleave_out( + w2 + (i << 2), q[i], q[i + 4]); + } + for (i = 0; i < 4; i ++) { + w2[i] ^= ivw[i]; + } + if (len >= 64) { + for (i = 4; i < 16; i ++) { + w2[i] ^= w1[i - 4]; + } + memcpy(ivw, w1 + 12, sizeof ivw); + br_range_enc32le(buf, w2, 16); + } else { + int j; + + j = (int)(len >> 2); + for (i = 4; i < j; i ++) { + w2[i] ^= w1[i - 4]; + } + memcpy(ivw, w1 + j - 4, sizeof ivw); + br_range_enc32le(buf, w2, j); + break; + } + buf += 64; + len -= 64; + } + br_range_enc32le(iv, ivw, 4); +} + +/* see bearssl_block.h */ +const br_block_cbcdec_class br_aes_ct64_cbcdec_vtable = { + sizeof(br_aes_ct64_cbcdec_keys), + 16, + 4, + (void (*)(const br_block_cbcdec_class **, const void *, size_t)) + &br_aes_ct64_cbcdec_init, + (void (*)(const br_block_cbcdec_class *const *, void *, void *, size_t)) + &br_aes_ct64_cbcdec_run +}; + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_ct64_cbcenc.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_ct64_cbcenc.c new file mode 100644 index 000000000..73a5ee1bc --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_ct64_cbcenc.c @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_block.h */ +void +br_aes_ct64_cbcenc_init(br_aes_ct64_cbcenc_keys *ctx, + const void *key, size_t len) +{ + ctx->vtable = &br_aes_ct64_cbcenc_vtable; + ctx->num_rounds = br_aes_ct64_keysched(ctx->skey, key, len); +} + +/* see bearssl_block.h */ +void +br_aes_ct64_cbcenc_run(const br_aes_ct64_cbcenc_keys *ctx, + void *iv, void *data, size_t len) +{ + unsigned char *buf; + uint64_t sk_exp[120]; + uint32_t ivw[4]; + + br_aes_ct64_skey_expand(sk_exp, ctx->num_rounds, ctx->skey); + br_range_dec32le(ivw, 4, iv); + buf = data; + while (len > 0) { + uint32_t w[4]; + uint64_t q[8]; + + w[0] = ivw[0] ^ br_dec32le(buf); + w[1] = ivw[1] ^ br_dec32le(buf + 4); + w[2] = ivw[2] ^ br_dec32le(buf + 8); + w[3] = ivw[3] ^ br_dec32le(buf + 12); + br_aes_ct64_interleave_in(&q[0], &q[4], w); + br_aes_ct64_ortho(q); + br_aes_ct64_bitslice_encrypt(ctx->num_rounds, sk_exp, q); + br_aes_ct64_ortho(q); + br_aes_ct64_interleave_out(w, q[0], q[4]); + memcpy(ivw, w, sizeof w); + br_enc32le(buf, w[0]); + br_enc32le(buf + 4, w[1]); + br_enc32le(buf + 8, w[2]); + br_enc32le(buf + 12, w[3]); + buf += 16; + len -= 16; + } + br_range_enc32le(iv, ivw, 4); +} + +/* see bearssl_block.h */ +const br_block_cbcenc_class br_aes_ct64_cbcenc_vtable = { + sizeof(br_aes_ct64_cbcenc_keys), + 16, + 4, + (void (*)(const br_block_cbcenc_class **, const void *, size_t)) + &br_aes_ct64_cbcenc_init, + (void (*)(const br_block_cbcenc_class *const *, void *, void *, size_t)) + &br_aes_ct64_cbcenc_run +}; + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_ct64_ctr.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_ct64_ctr.c new file mode 100644 index 000000000..bbc05bbf3 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_ct64_ctr.c @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_block.h */ +void +br_aes_ct64_ctr_init(br_aes_ct64_ctr_keys *ctx, + const void *key, size_t len) +{ + ctx->vtable = &br_aes_ct64_ctr_vtable; + ctx->num_rounds = br_aes_ct64_keysched(ctx->skey, key, len); +} + +static void +xorbuf(void *dst, const void *src, size_t len) +{ + unsigned char *d; + const unsigned char *s; + + d = dst; + s = src; + while (len -- > 0) { + *d ++ ^= *s ++; + } +} + +/* see bearssl_block.h */ +uint32_t +br_aes_ct64_ctr_run(const br_aes_ct64_ctr_keys *ctx, + const void *iv, uint32_t cc, void *data, size_t len) +{ + unsigned char *buf; + uint32_t ivw[16]; + uint64_t sk_exp[120]; + + br_aes_ct64_skey_expand(sk_exp, ctx->num_rounds, ctx->skey); + br_range_dec32le(ivw, 3, iv); + memcpy(ivw + 4, ivw, 3 * sizeof(uint32_t)); + memcpy(ivw + 8, ivw, 3 * sizeof(uint32_t)); + memcpy(ivw + 12, ivw, 3 * sizeof(uint32_t)); + buf = data; + while (len > 0) { + uint64_t q[8]; + uint32_t w[16]; + unsigned char tmp[64]; + int i; + + /* + * TODO: see if we can save on the first br_aes_ct64_ortho() + * call, since iv0/iv1/iv2 are constant for the whole run. + */ + memcpy(w, ivw, sizeof ivw); + w[3] = br_swap32(cc); + w[7] = br_swap32(cc + 1); + w[11] = br_swap32(cc + 2); + w[15] = br_swap32(cc + 3); + for (i = 0; i < 4; i ++) { + br_aes_ct64_interleave_in( + &q[i], &q[i + 4], w + (i << 2)); + } + br_aes_ct64_ortho(q); + br_aes_ct64_bitslice_encrypt(ctx->num_rounds, sk_exp, q); + br_aes_ct64_ortho(q); + for (i = 0; i < 4; i ++) { + br_aes_ct64_interleave_out( + w + (i << 2), q[i], q[i + 4]); + } + br_range_enc32le(tmp, w, 16); + if (len <= 64) { + xorbuf(buf, tmp, len); + cc += (uint32_t)len >> 4; + break; + } + xorbuf(buf, tmp, 64); + buf += 64; + len -= 64; + cc += 4; + } + return cc; +} + +/* see bearssl_block.h */ +const br_block_ctr_class br_aes_ct64_ctr_vtable = { + sizeof(br_aes_ct64_ctr_keys), + 16, + 4, + (void (*)(const br_block_ctr_class **, const void *, size_t)) + &br_aes_ct64_ctr_init, + (uint32_t (*)(const br_block_ctr_class *const *, + const void *, uint32_t, void *, size_t)) + &br_aes_ct64_ctr_run +}; + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_ct64_ctrcbc.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_ct64_ctrcbc.c new file mode 100644 index 000000000..50bf8b32b --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_ct64_ctrcbc.c @@ -0,0 +1,438 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_block.h */ +void +br_aes_ct64_ctrcbc_init(br_aes_ct64_ctrcbc_keys *ctx, + const void *key, size_t len) +{ + ctx->vtable = &br_aes_ct64_ctrcbc_vtable; + ctx->num_rounds = br_aes_ct64_keysched(ctx->skey, key, len); +} + +static void +xorbuf(void *dst, const void *src, size_t len) +{ + unsigned char *d; + const unsigned char *s; + + d = dst; + s = src; + while (len -- > 0) { + *d ++ ^= *s ++; + } +} + +/* see bearssl_block.h */ +void +br_aes_ct64_ctrcbc_ctr(const br_aes_ct64_ctrcbc_keys *ctx, + void *ctr, void *data, size_t len) +{ + unsigned char *buf; + unsigned char *ivbuf; + uint32_t iv0, iv1, iv2, iv3; + uint64_t sk_exp[120]; + + br_aes_ct64_skey_expand(sk_exp, ctx->num_rounds, ctx->skey); + + /* + * We keep the counter as four 32-bit values, with big-endian + * convention, because that's what is expected for purposes of + * incrementing the counter value. + */ + ivbuf = ctr; + iv0 = br_dec32be(ivbuf + 0); + iv1 = br_dec32be(ivbuf + 4); + iv2 = br_dec32be(ivbuf + 8); + iv3 = br_dec32be(ivbuf + 12); + + buf = data; + while (len > 0) { + uint64_t q[8]; + uint32_t w[16]; + unsigned char tmp[64]; + int i, j; + + /* + * The bitslice implementation expects values in + * little-endian convention, so we have to byteswap them. + */ + j = (len >= 64) ? 16 : (int)(len >> 2); + for (i = 0; i < j; i += 4) { + uint32_t carry; + + w[i + 0] = br_swap32(iv0); + w[i + 1] = br_swap32(iv1); + w[i + 2] = br_swap32(iv2); + w[i + 3] = br_swap32(iv3); + iv3 ++; + carry = ~(iv3 | -iv3) >> 31; + iv2 += carry; + carry &= -(~(iv2 | -iv2) >> 31); + iv1 += carry; + carry &= -(~(iv1 | -iv1) >> 31); + iv0 += carry; + } + memset(w + i, 0, (16 - i) * sizeof(uint32_t)); + + for (i = 0; i < 4; i ++) { + br_aes_ct64_interleave_in( + &q[i], &q[i + 4], w + (i << 2)); + } + br_aes_ct64_ortho(q); + br_aes_ct64_bitslice_encrypt(ctx->num_rounds, sk_exp, q); + br_aes_ct64_ortho(q); + for (i = 0; i < 4; i ++) { + br_aes_ct64_interleave_out( + w + (i << 2), q[i], q[i + 4]); + } + + br_range_enc32le(tmp, w, 16); + if (len <= 64) { + xorbuf(buf, tmp, len); + break; + } + xorbuf(buf, tmp, 64); + buf += 64; + len -= 64; + } + br_enc32be(ivbuf + 0, iv0); + br_enc32be(ivbuf + 4, iv1); + br_enc32be(ivbuf + 8, iv2); + br_enc32be(ivbuf + 12, iv3); +} + +/* see bearssl_block.h */ +void +br_aes_ct64_ctrcbc_mac(const br_aes_ct64_ctrcbc_keys *ctx, + void *cbcmac, const void *data, size_t len) +{ + const unsigned char *buf; + uint32_t cm0, cm1, cm2, cm3; + uint64_t q[8]; + uint64_t sk_exp[120]; + + br_aes_ct64_skey_expand(sk_exp, ctx->num_rounds, ctx->skey); + + cm0 = br_dec32le((unsigned char *)cbcmac + 0); + cm1 = br_dec32le((unsigned char *)cbcmac + 4); + cm2 = br_dec32le((unsigned char *)cbcmac + 8); + cm3 = br_dec32le((unsigned char *)cbcmac + 12); + + buf = data; + memset(q, 0, sizeof q); + while (len > 0) { + uint32_t w[4]; + + w[0] = cm0 ^ br_dec32le(buf + 0); + w[1] = cm1 ^ br_dec32le(buf + 4); + w[2] = cm2 ^ br_dec32le(buf + 8); + w[3] = cm3 ^ br_dec32le(buf + 12); + + br_aes_ct64_interleave_in(&q[0], &q[4], w); + br_aes_ct64_ortho(q); + br_aes_ct64_bitslice_encrypt(ctx->num_rounds, sk_exp, q); + br_aes_ct64_ortho(q); + br_aes_ct64_interleave_out(w, q[0], q[4]); + + cm0 = w[0]; + cm1 = w[1]; + cm2 = w[2]; + cm3 = w[3]; + buf += 16; + len -= 16; + } + + br_enc32le((unsigned char *)cbcmac + 0, cm0); + br_enc32le((unsigned char *)cbcmac + 4, cm1); + br_enc32le((unsigned char *)cbcmac + 8, cm2); + br_enc32le((unsigned char *)cbcmac + 12, cm3); +} + +/* see bearssl_block.h */ +void +br_aes_ct64_ctrcbc_encrypt(const br_aes_ct64_ctrcbc_keys *ctx, + void *ctr, void *cbcmac, void *data, size_t len) +{ + /* + * When encrypting, the CBC-MAC processing must be lagging by + * one block, since it operates on the encrypted values, so + * it must wait for that encryption to complete. + */ + + unsigned char *buf; + unsigned char *ivbuf; + uint32_t iv0, iv1, iv2, iv3; + uint32_t cm0, cm1, cm2, cm3; + uint64_t sk_exp[120]; + uint64_t q[8]; + int first_iter; + + br_aes_ct64_skey_expand(sk_exp, ctx->num_rounds, ctx->skey); + + /* + * We keep the counter as four 32-bit values, with big-endian + * convention, because that's what is expected for purposes of + * incrementing the counter value. + */ + ivbuf = ctr; + iv0 = br_dec32be(ivbuf + 0); + iv1 = br_dec32be(ivbuf + 4); + iv2 = br_dec32be(ivbuf + 8); + iv3 = br_dec32be(ivbuf + 12); + + /* + * The current CBC-MAC value is kept in little-endian convention. + */ + cm0 = br_dec32le((unsigned char *)cbcmac + 0); + cm1 = br_dec32le((unsigned char *)cbcmac + 4); + cm2 = br_dec32le((unsigned char *)cbcmac + 8); + cm3 = br_dec32le((unsigned char *)cbcmac + 12); + + buf = data; + first_iter = 1; + memset(q, 0, sizeof q); + while (len > 0) { + uint32_t w[8], carry; + + /* + * The bitslice implementation expects values in + * little-endian convention, so we have to byteswap them. + */ + w[0] = br_swap32(iv0); + w[1] = br_swap32(iv1); + w[2] = br_swap32(iv2); + w[3] = br_swap32(iv3); + iv3 ++; + carry = ~(iv3 | -iv3) >> 31; + iv2 += carry; + carry &= -(~(iv2 | -iv2) >> 31); + iv1 += carry; + carry &= -(~(iv1 | -iv1) >> 31); + iv0 += carry; + + /* + * The block for CBC-MAC. + */ + w[4] = cm0; + w[5] = cm1; + w[6] = cm2; + w[7] = cm3; + + br_aes_ct64_interleave_in(&q[0], &q[4], w); + br_aes_ct64_interleave_in(&q[1], &q[5], w + 4); + br_aes_ct64_ortho(q); + br_aes_ct64_bitslice_encrypt(ctx->num_rounds, sk_exp, q); + br_aes_ct64_ortho(q); + br_aes_ct64_interleave_out(w, q[0], q[4]); + br_aes_ct64_interleave_out(w + 4, q[1], q[5]); + + /* + * We do the XOR with the plaintext in 32-bit registers, + * so that the value are available for CBC-MAC processing + * as well. + */ + w[0] ^= br_dec32le(buf + 0); + w[1] ^= br_dec32le(buf + 4); + w[2] ^= br_dec32le(buf + 8); + w[3] ^= br_dec32le(buf + 12); + br_enc32le(buf + 0, w[0]); + br_enc32le(buf + 4, w[1]); + br_enc32le(buf + 8, w[2]); + br_enc32le(buf + 12, w[3]); + + buf += 16; + len -= 16; + + /* + * We set the cm* values to the block to encrypt in the + * next iteration. + */ + if (first_iter) { + first_iter = 0; + cm0 ^= w[0]; + cm1 ^= w[1]; + cm2 ^= w[2]; + cm3 ^= w[3]; + } else { + cm0 = w[0] ^ w[4]; + cm1 = w[1] ^ w[5]; + cm2 = w[2] ^ w[6]; + cm3 = w[3] ^ w[7]; + } + + /* + * If this was the last iteration, then compute the + * extra block encryption to complete CBC-MAC. + */ + if (len == 0) { + w[0] = cm0; + w[1] = cm1; + w[2] = cm2; + w[3] = cm3; + br_aes_ct64_interleave_in(&q[0], &q[4], w); + br_aes_ct64_ortho(q); + br_aes_ct64_bitslice_encrypt( + ctx->num_rounds, sk_exp, q); + br_aes_ct64_ortho(q); + br_aes_ct64_interleave_out(w, q[0], q[4]); + cm0 = w[0]; + cm1 = w[1]; + cm2 = w[2]; + cm3 = w[3]; + break; + } + } + + br_enc32be(ivbuf + 0, iv0); + br_enc32be(ivbuf + 4, iv1); + br_enc32be(ivbuf + 8, iv2); + br_enc32be(ivbuf + 12, iv3); + br_enc32le((unsigned char *)cbcmac + 0, cm0); + br_enc32le((unsigned char *)cbcmac + 4, cm1); + br_enc32le((unsigned char *)cbcmac + 8, cm2); + br_enc32le((unsigned char *)cbcmac + 12, cm3); +} + +/* see bearssl_block.h */ +void +br_aes_ct64_ctrcbc_decrypt(const br_aes_ct64_ctrcbc_keys *ctx, + void *ctr, void *cbcmac, void *data, size_t len) +{ + unsigned char *buf; + unsigned char *ivbuf; + uint32_t iv0, iv1, iv2, iv3; + uint32_t cm0, cm1, cm2, cm3; + uint64_t sk_exp[120]; + uint64_t q[8]; + + br_aes_ct64_skey_expand(sk_exp, ctx->num_rounds, ctx->skey); + + /* + * We keep the counter as four 32-bit values, with big-endian + * convention, because that's what is expected for purposes of + * incrementing the counter value. + */ + ivbuf = ctr; + iv0 = br_dec32be(ivbuf + 0); + iv1 = br_dec32be(ivbuf + 4); + iv2 = br_dec32be(ivbuf + 8); + iv3 = br_dec32be(ivbuf + 12); + + /* + * The current CBC-MAC value is kept in little-endian convention. + */ + cm0 = br_dec32le((unsigned char *)cbcmac + 0); + cm1 = br_dec32le((unsigned char *)cbcmac + 4); + cm2 = br_dec32le((unsigned char *)cbcmac + 8); + cm3 = br_dec32le((unsigned char *)cbcmac + 12); + + buf = data; + memset(q, 0, sizeof q); + while (len > 0) { + uint32_t w[8], carry; + unsigned char tmp[16]; + + /* + * The bitslice implementation expects values in + * little-endian convention, so we have to byteswap them. + */ + w[0] = br_swap32(iv0); + w[1] = br_swap32(iv1); + w[2] = br_swap32(iv2); + w[3] = br_swap32(iv3); + iv3 ++; + carry = ~(iv3 | -iv3) >> 31; + iv2 += carry; + carry &= -(~(iv2 | -iv2) >> 31); + iv1 += carry; + carry &= -(~(iv1 | -iv1) >> 31); + iv0 += carry; + + /* + * The block for CBC-MAC. + */ + w[4] = cm0 ^ br_dec32le(buf + 0); + w[5] = cm1 ^ br_dec32le(buf + 4); + w[6] = cm2 ^ br_dec32le(buf + 8); + w[7] = cm3 ^ br_dec32le(buf + 12); + + br_aes_ct64_interleave_in(&q[0], &q[4], w); + br_aes_ct64_interleave_in(&q[1], &q[5], w + 4); + br_aes_ct64_ortho(q); + br_aes_ct64_bitslice_encrypt(ctx->num_rounds, sk_exp, q); + br_aes_ct64_ortho(q); + br_aes_ct64_interleave_out(w, q[0], q[4]); + br_aes_ct64_interleave_out(w + 4, q[1], q[5]); + + br_enc32le(tmp + 0, w[0]); + br_enc32le(tmp + 4, w[1]); + br_enc32le(tmp + 8, w[2]); + br_enc32le(tmp + 12, w[3]); + xorbuf(buf, tmp, 16); + cm0 = w[4]; + cm1 = w[5]; + cm2 = w[6]; + cm3 = w[7]; + buf += 16; + len -= 16; + } + + br_enc32be(ivbuf + 0, iv0); + br_enc32be(ivbuf + 4, iv1); + br_enc32be(ivbuf + 8, iv2); + br_enc32be(ivbuf + 12, iv3); + br_enc32le((unsigned char *)cbcmac + 0, cm0); + br_enc32le((unsigned char *)cbcmac + 4, cm1); + br_enc32le((unsigned char *)cbcmac + 8, cm2); + br_enc32le((unsigned char *)cbcmac + 12, cm3); +} + +/* see bearssl_block.h */ +const br_block_ctrcbc_class br_aes_ct64_ctrcbc_vtable = { + sizeof(br_aes_ct64_ctrcbc_keys), + 16, + 4, + (void (*)(const br_block_ctrcbc_class **, const void *, size_t)) + &br_aes_ct64_ctrcbc_init, + (void (*)(const br_block_ctrcbc_class *const *, + void *, void *, void *, size_t)) + &br_aes_ct64_ctrcbc_encrypt, + (void (*)(const br_block_ctrcbc_class *const *, + void *, void *, void *, size_t)) + &br_aes_ct64_ctrcbc_decrypt, + (void (*)(const br_block_ctrcbc_class *const *, + void *, void *, size_t)) + &br_aes_ct64_ctrcbc_ctr, + (void (*)(const br_block_ctrcbc_class *const *, + void *, const void *, size_t)) + &br_aes_ct64_ctrcbc_mac +}; + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_ct64_dec.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_ct64_dec.c new file mode 100644 index 000000000..236b4f79d --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_ct64_dec.c @@ -0,0 +1,164 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +void +br_aes_ct64_bitslice_invSbox(uint64_t *q) +{ + /* + * See br_aes_ct_bitslice_invSbox(). This is the natural extension + * to 64-bit registers. + */ + uint64_t q0, q1, q2, q3, q4, q5, q6, q7; + + q0 = ~q[0]; + q1 = ~q[1]; + q2 = q[2]; + q3 = q[3]; + q4 = q[4]; + q5 = ~q[5]; + q6 = ~q[6]; + q7 = q[7]; + q[7] = q1 ^ q4 ^ q6; + q[6] = q0 ^ q3 ^ q5; + q[5] = q7 ^ q2 ^ q4; + q[4] = q6 ^ q1 ^ q3; + q[3] = q5 ^ q0 ^ q2; + q[2] = q4 ^ q7 ^ q1; + q[1] = q3 ^ q6 ^ q0; + q[0] = q2 ^ q5 ^ q7; + + br_aes_ct64_bitslice_Sbox(q); + + q0 = ~q[0]; + q1 = ~q[1]; + q2 = q[2]; + q3 = q[3]; + q4 = q[4]; + q5 = ~q[5]; + q6 = ~q[6]; + q7 = q[7]; + q[7] = q1 ^ q4 ^ q6; + q[6] = q0 ^ q3 ^ q5; + q[5] = q7 ^ q2 ^ q4; + q[4] = q6 ^ q1 ^ q3; + q[3] = q5 ^ q0 ^ q2; + q[2] = q4 ^ q7 ^ q1; + q[1] = q3 ^ q6 ^ q0; + q[0] = q2 ^ q5 ^ q7; +} + +static void +add_round_key(uint64_t *q, const uint64_t *sk) +{ + int i; + + for (i = 0; i < 8; i ++) { + q[i] ^= sk[i]; + } +} + +static void +inv_shift_rows(uint64_t *q) +{ + int i; + + for (i = 0; i < 8; i ++) { + uint64_t x; + + x = q[i]; + q[i] = (x & (uint64_t)0x000000000000FFFF) + | ((x & (uint64_t)0x000000000FFF0000) << 4) + | ((x & (uint64_t)0x00000000F0000000) >> 12) + | ((x & (uint64_t)0x000000FF00000000) << 8) + | ((x & (uint64_t)0x0000FF0000000000) >> 8) + | ((x & (uint64_t)0x000F000000000000) << 12) + | ((x & (uint64_t)0xFFF0000000000000) >> 4); + } +} + +static inline uint64_t +rotr32(uint64_t x) +{ + return (x << 32) | (x >> 32); +} + +static void +inv_mix_columns(uint64_t *q) +{ + uint64_t q0, q1, q2, q3, q4, q5, q6, q7; + uint64_t r0, r1, r2, r3, r4, r5, r6, r7; + + q0 = q[0]; + q1 = q[1]; + q2 = q[2]; + q3 = q[3]; + q4 = q[4]; + q5 = q[5]; + q6 = q[6]; + q7 = q[7]; + r0 = (q0 >> 16) | (q0 << 48); + r1 = (q1 >> 16) | (q1 << 48); + r2 = (q2 >> 16) | (q2 << 48); + r3 = (q3 >> 16) | (q3 << 48); + r4 = (q4 >> 16) | (q4 << 48); + r5 = (q5 >> 16) | (q5 << 48); + r6 = (q6 >> 16) | (q6 << 48); + r7 = (q7 >> 16) | (q7 << 48); + + q[0] = q5 ^ q6 ^ q7 ^ r0 ^ r5 ^ r7 ^ rotr32(q0 ^ q5 ^ q6 ^ r0 ^ r5); + q[1] = q0 ^ q5 ^ r0 ^ r1 ^ r5 ^ r6 ^ r7 ^ rotr32(q1 ^ q5 ^ q7 ^ r1 ^ r5 ^ r6); + q[2] = q0 ^ q1 ^ q6 ^ r1 ^ r2 ^ r6 ^ r7 ^ rotr32(q0 ^ q2 ^ q6 ^ r2 ^ r6 ^ r7); + q[3] = q0 ^ q1 ^ q2 ^ q5 ^ q6 ^ r0 ^ r2 ^ r3 ^ r5 ^ rotr32(q0 ^ q1 ^ q3 ^ q5 ^ q6 ^ q7 ^ r0 ^ r3 ^ r5 ^ r7); + q[4] = q1 ^ q2 ^ q3 ^ q5 ^ r1 ^ r3 ^ r4 ^ r5 ^ r6 ^ r7 ^ rotr32(q1 ^ q2 ^ q4 ^ q5 ^ q7 ^ r1 ^ r4 ^ r5 ^ r6); + q[5] = q2 ^ q3 ^ q4 ^ q6 ^ r2 ^ r4 ^ r5 ^ r6 ^ r7 ^ rotr32(q2 ^ q3 ^ q5 ^ q6 ^ r2 ^ r5 ^ r6 ^ r7); + q[6] = q3 ^ q4 ^ q5 ^ q7 ^ r3 ^ r5 ^ r6 ^ r7 ^ rotr32(q3 ^ q4 ^ q6 ^ q7 ^ r3 ^ r6 ^ r7); + q[7] = q4 ^ q5 ^ q6 ^ r4 ^ r6 ^ r7 ^ rotr32(q4 ^ q5 ^ q7 ^ r4 ^ r7); +} + +/* see inner.h */ +void +br_aes_ct64_bitslice_decrypt(unsigned num_rounds, + const uint64_t *skey, uint64_t *q) +{ + unsigned u; + + add_round_key(q, skey + (num_rounds << 3)); + for (u = num_rounds - 1; u > 0; u --) { + inv_shift_rows(q); + br_aes_ct64_bitslice_invSbox(q); + add_round_key(q, skey + (u << 3)); + inv_mix_columns(q); + } + inv_shift_rows(q); + br_aes_ct64_bitslice_invSbox(q); + add_round_key(q, skey); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_ct64_enc.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_ct64_enc.c new file mode 100644 index 000000000..f2669b8d7 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_ct64_enc.c @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +static inline void +add_round_key(uint64_t *q, const uint64_t *sk) +{ + q[0] ^= sk[0]; + q[1] ^= sk[1]; + q[2] ^= sk[2]; + q[3] ^= sk[3]; + q[4] ^= sk[4]; + q[5] ^= sk[5]; + q[6] ^= sk[6]; + q[7] ^= sk[7]; +} + +static inline void +shift_rows(uint64_t *q) +{ + int i; + + for (i = 0; i < 8; i ++) { + uint64_t x; + + x = q[i]; + q[i] = (x & (uint64_t)0x000000000000FFFF) + | ((x & (uint64_t)0x00000000FFF00000) >> 4) + | ((x & (uint64_t)0x00000000000F0000) << 12) + | ((x & (uint64_t)0x0000FF0000000000) >> 8) + | ((x & (uint64_t)0x000000FF00000000) << 8) + | ((x & (uint64_t)0xF000000000000000) >> 12) + | ((x & (uint64_t)0x0FFF000000000000) << 4); + } +} + +static inline uint64_t +rotr32(uint64_t x) +{ + return (x << 32) | (x >> 32); +} + +static inline void +mix_columns(uint64_t *q) +{ + uint64_t q0, q1, q2, q3, q4, q5, q6, q7; + uint64_t r0, r1, r2, r3, r4, r5, r6, r7; + + q0 = q[0]; + q1 = q[1]; + q2 = q[2]; + q3 = q[3]; + q4 = q[4]; + q5 = q[5]; + q6 = q[6]; + q7 = q[7]; + r0 = (q0 >> 16) | (q0 << 48); + r1 = (q1 >> 16) | (q1 << 48); + r2 = (q2 >> 16) | (q2 << 48); + r3 = (q3 >> 16) | (q3 << 48); + r4 = (q4 >> 16) | (q4 << 48); + r5 = (q5 >> 16) | (q5 << 48); + r6 = (q6 >> 16) | (q6 << 48); + r7 = (q7 >> 16) | (q7 << 48); + + q[0] = q7 ^ r7 ^ r0 ^ rotr32(q0 ^ r0); + q[1] = q0 ^ r0 ^ q7 ^ r7 ^ r1 ^ rotr32(q1 ^ r1); + q[2] = q1 ^ r1 ^ r2 ^ rotr32(q2 ^ r2); + q[3] = q2 ^ r2 ^ q7 ^ r7 ^ r3 ^ rotr32(q3 ^ r3); + q[4] = q3 ^ r3 ^ q7 ^ r7 ^ r4 ^ rotr32(q4 ^ r4); + q[5] = q4 ^ r4 ^ r5 ^ rotr32(q5 ^ r5); + q[6] = q5 ^ r5 ^ r6 ^ rotr32(q6 ^ r6); + q[7] = q6 ^ r6 ^ r7 ^ rotr32(q7 ^ r7); +} + +/* see inner.h */ +void +br_aes_ct64_bitslice_encrypt(unsigned num_rounds, + const uint64_t *skey, uint64_t *q) +{ + unsigned u; + + add_round_key(q, skey); + for (u = 1; u < num_rounds; u ++) { + br_aes_ct64_bitslice_Sbox(q); + shift_rows(q); + mix_columns(q); + add_round_key(q, skey + (u << 3)); + } + br_aes_ct64_bitslice_Sbox(q); + shift_rows(q); + add_round_key(q, skey + (num_rounds << 3)); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_ct_cbcdec.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_ct_cbcdec.c new file mode 100644 index 000000000..151e41e2a --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_ct_cbcdec.c @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_block.h */ +void +br_aes_ct_cbcdec_init(br_aes_ct_cbcdec_keys *ctx, + const void *key, size_t len) +{ + ctx->vtable = &br_aes_ct_cbcdec_vtable; + ctx->num_rounds = br_aes_ct_keysched(ctx->skey, key, len); +} + +/* see bearssl_block.h */ +void +br_aes_ct_cbcdec_run(const br_aes_ct_cbcdec_keys *ctx, + void *iv, void *data, size_t len) +{ + unsigned char *buf, *ivbuf; + uint32_t iv0, iv1, iv2, iv3; + uint32_t sk_exp[120]; + + br_aes_ct_skey_expand(sk_exp, ctx->num_rounds, ctx->skey); + ivbuf = iv; + iv0 = br_dec32le(ivbuf); + iv1 = br_dec32le(ivbuf + 4); + iv2 = br_dec32le(ivbuf + 8); + iv3 = br_dec32le(ivbuf + 12); + buf = data; + while (len > 0) { + uint32_t q[8], sq[8]; + + q[0] = br_dec32le(buf); + q[2] = br_dec32le(buf + 4); + q[4] = br_dec32le(buf + 8); + q[6] = br_dec32le(buf + 12); + if (len >= 32) { + q[1] = br_dec32le(buf + 16); + q[3] = br_dec32le(buf + 20); + q[5] = br_dec32le(buf + 24); + q[7] = br_dec32le(buf + 28); + } else { + q[1] = 0; + q[3] = 0; + q[5] = 0; + q[7] = 0; + } + memcpy(sq, q, sizeof q); + br_aes_ct_ortho(q); + br_aes_ct_bitslice_decrypt(ctx->num_rounds, sk_exp, q); + br_aes_ct_ortho(q); + br_enc32le(buf, q[0] ^ iv0); + br_enc32le(buf + 4, q[2] ^ iv1); + br_enc32le(buf + 8, q[4] ^ iv2); + br_enc32le(buf + 12, q[6] ^ iv3); + if (len < 32) { + iv0 = sq[0]; + iv1 = sq[2]; + iv2 = sq[4]; + iv3 = sq[6]; + break; + } + br_enc32le(buf + 16, q[1] ^ sq[0]); + br_enc32le(buf + 20, q[3] ^ sq[2]); + br_enc32le(buf + 24, q[5] ^ sq[4]); + br_enc32le(buf + 28, q[7] ^ sq[6]); + iv0 = sq[1]; + iv1 = sq[3]; + iv2 = sq[5]; + iv3 = sq[7]; + buf += 32; + len -= 32; + } + br_enc32le(ivbuf, iv0); + br_enc32le(ivbuf + 4, iv1); + br_enc32le(ivbuf + 8, iv2); + br_enc32le(ivbuf + 12, iv3); +} + +/* see bearssl_block.h */ +const br_block_cbcdec_class br_aes_ct_cbcdec_vtable = { + sizeof(br_aes_ct_cbcdec_keys), + 16, + 4, + (void (*)(const br_block_cbcdec_class **, const void *, size_t)) + &br_aes_ct_cbcdec_init, + (void (*)(const br_block_cbcdec_class *const *, void *, void *, size_t)) + &br_aes_ct_cbcdec_run +}; + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_ct_cbcenc.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_ct_cbcenc.c new file mode 100644 index 000000000..89877f011 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_ct_cbcenc.c @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_block.h */ +void +br_aes_ct_cbcenc_init(br_aes_ct_cbcenc_keys *ctx, + const void *key, size_t len) +{ + ctx->vtable = &br_aes_ct_cbcenc_vtable; + ctx->num_rounds = br_aes_ct_keysched(ctx->skey, key, len); +} + +/* see bearssl_block.h */ +void +br_aes_ct_cbcenc_run(const br_aes_ct_cbcenc_keys *ctx, + void *iv, void *data, size_t len) +{ + unsigned char *buf, *ivbuf; + uint32_t q[8]; + uint32_t iv0, iv1, iv2, iv3; + uint32_t sk_exp[120]; + + q[1] = 0; + q[3] = 0; + q[5] = 0; + q[7] = 0; + br_aes_ct_skey_expand(sk_exp, ctx->num_rounds, ctx->skey); + ivbuf = iv; + iv0 = br_dec32le(ivbuf); + iv1 = br_dec32le(ivbuf + 4); + iv2 = br_dec32le(ivbuf + 8); + iv3 = br_dec32le(ivbuf + 12); + buf = data; + while (len > 0) { + q[0] = iv0 ^ br_dec32le(buf); + q[2] = iv1 ^ br_dec32le(buf + 4); + q[4] = iv2 ^ br_dec32le(buf + 8); + q[6] = iv3 ^ br_dec32le(buf + 12); + br_aes_ct_ortho(q); + br_aes_ct_bitslice_encrypt(ctx->num_rounds, sk_exp, q); + br_aes_ct_ortho(q); + iv0 = q[0]; + iv1 = q[2]; + iv2 = q[4]; + iv3 = q[6]; + br_enc32le(buf, iv0); + br_enc32le(buf + 4, iv1); + br_enc32le(buf + 8, iv2); + br_enc32le(buf + 12, iv3); + buf += 16; + len -= 16; + } + br_enc32le(ivbuf, iv0); + br_enc32le(ivbuf + 4, iv1); + br_enc32le(ivbuf + 8, iv2); + br_enc32le(ivbuf + 12, iv3); +} + +/* see bearssl_block.h */ +const br_block_cbcenc_class br_aes_ct_cbcenc_vtable = { + sizeof(br_aes_ct_cbcenc_keys), + 16, + 4, + (void (*)(const br_block_cbcenc_class **, const void *, size_t)) + &br_aes_ct_cbcenc_init, + (void (*)(const br_block_cbcenc_class *const *, void *, void *, size_t)) + &br_aes_ct_cbcenc_run +}; + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_ct_ctr.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_ct_ctr.c new file mode 100644 index 000000000..301c0a2d3 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_ct_ctr.c @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_block.h */ +void +br_aes_ct_ctr_init(br_aes_ct_ctr_keys *ctx, + const void *key, size_t len) +{ + ctx->vtable = &br_aes_ct_ctr_vtable; + ctx->num_rounds = br_aes_ct_keysched(ctx->skey, key, len); +} + +static void +xorbuf(void *dst, const void *src, size_t len) +{ + unsigned char *d; + const unsigned char *s; + + d = dst; + s = src; + while (len -- > 0) { + *d ++ ^= *s ++; + } +} + +/* see bearssl_block.h */ +uint32_t +br_aes_ct_ctr_run(const br_aes_ct_ctr_keys *ctx, + const void *iv, uint32_t cc, void *data, size_t len) +{ + unsigned char *buf; + const unsigned char *ivbuf; + uint32_t iv0, iv1, iv2; + uint32_t sk_exp[120]; + + br_aes_ct_skey_expand(sk_exp, ctx->num_rounds, ctx->skey); + ivbuf = iv; + iv0 = br_dec32le(ivbuf); + iv1 = br_dec32le(ivbuf + 4); + iv2 = br_dec32le(ivbuf + 8); + buf = data; + while (len > 0) { + uint32_t q[8]; + unsigned char tmp[32]; + + /* + * TODO: see if we can save on the first br_aes_ct_ortho() + * call, since iv0/iv1/iv2 are constant for the whole run. + */ + q[0] = q[1] = iv0; + q[2] = q[3] = iv1; + q[4] = q[5] = iv2; + q[6] = br_swap32(cc); + q[7] = br_swap32(cc + 1); + br_aes_ct_ortho(q); + br_aes_ct_bitslice_encrypt(ctx->num_rounds, sk_exp, q); + br_aes_ct_ortho(q); + br_enc32le(tmp, q[0]); + br_enc32le(tmp + 4, q[2]); + br_enc32le(tmp + 8, q[4]); + br_enc32le(tmp + 12, q[6]); + br_enc32le(tmp + 16, q[1]); + br_enc32le(tmp + 20, q[3]); + br_enc32le(tmp + 24, q[5]); + br_enc32le(tmp + 28, q[7]); + + if (len <= 32) { + xorbuf(buf, tmp, len); + cc ++; + if (len > 16) { + cc ++; + } + break; + } + xorbuf(buf, tmp, 32); + buf += 32; + len -= 32; + cc += 2; + } + return cc; +} + +/* see bearssl_block.h */ +const br_block_ctr_class br_aes_ct_ctr_vtable = { + sizeof(br_aes_ct_ctr_keys), + 16, + 4, + (void (*)(const br_block_ctr_class **, const void *, size_t)) + &br_aes_ct_ctr_init, + (uint32_t (*)(const br_block_ctr_class *const *, + const void *, uint32_t, void *, size_t)) + &br_aes_ct_ctr_run +}; + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_ct_ctrcbc.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_ct_ctrcbc.c new file mode 100644 index 000000000..5a29f5d69 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_ct_ctrcbc.c @@ -0,0 +1,427 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_block.h */ +void +br_aes_ct_ctrcbc_init(br_aes_ct_ctrcbc_keys *ctx, + const void *key, size_t len) +{ + ctx->vtable = &br_aes_ct_ctrcbc_vtable; + ctx->num_rounds = br_aes_ct_keysched(ctx->skey, key, len); +} + +static void +xorbuf(void *dst, const void *src, size_t len) +{ + unsigned char *d; + const unsigned char *s; + + d = dst; + s = src; + while (len -- > 0) { + *d ++ ^= *s ++; + } +} + +/* see bearssl_block.h */ +void +br_aes_ct_ctrcbc_ctr(const br_aes_ct_ctrcbc_keys *ctx, + void *ctr, void *data, size_t len) +{ + unsigned char *buf; + unsigned char *ivbuf; + uint32_t iv0, iv1, iv2, iv3; + uint32_t sk_exp[120]; + + br_aes_ct_skey_expand(sk_exp, ctx->num_rounds, ctx->skey); + + /* + * We keep the counter as four 32-bit values, with big-endian + * convention, because that's what is expected for purposes of + * incrementing the counter value. + */ + ivbuf = ctr; + iv0 = br_dec32be(ivbuf + 0); + iv1 = br_dec32be(ivbuf + 4); + iv2 = br_dec32be(ivbuf + 8); + iv3 = br_dec32be(ivbuf + 12); + + buf = data; + while (len > 0) { + uint32_t q[8], carry; + unsigned char tmp[32]; + + /* + * The bitslice implementation expects values in + * little-endian convention, so we have to byteswap them. + */ + q[0] = br_swap32(iv0); + q[2] = br_swap32(iv1); + q[4] = br_swap32(iv2); + q[6] = br_swap32(iv3); + iv3 ++; + carry = ~(iv3 | -iv3) >> 31; + iv2 += carry; + carry &= -(~(iv2 | -iv2) >> 31); + iv1 += carry; + carry &= -(~(iv1 | -iv1) >> 31); + iv0 += carry; + q[1] = br_swap32(iv0); + q[3] = br_swap32(iv1); + q[5] = br_swap32(iv2); + q[7] = br_swap32(iv3); + if (len > 16) { + iv3 ++; + carry = ~(iv3 | -iv3) >> 31; + iv2 += carry; + carry &= -(~(iv2 | -iv2) >> 31); + iv1 += carry; + carry &= -(~(iv1 | -iv1) >> 31); + iv0 += carry; + } + + br_aes_ct_ortho(q); + br_aes_ct_bitslice_encrypt(ctx->num_rounds, sk_exp, q); + br_aes_ct_ortho(q); + + br_enc32le(tmp, q[0]); + br_enc32le(tmp + 4, q[2]); + br_enc32le(tmp + 8, q[4]); + br_enc32le(tmp + 12, q[6]); + br_enc32le(tmp + 16, q[1]); + br_enc32le(tmp + 20, q[3]); + br_enc32le(tmp + 24, q[5]); + br_enc32le(tmp + 28, q[7]); + + if (len <= 32) { + xorbuf(buf, tmp, len); + break; + } + xorbuf(buf, tmp, 32); + buf += 32; + len -= 32; + } + br_enc32be(ivbuf + 0, iv0); + br_enc32be(ivbuf + 4, iv1); + br_enc32be(ivbuf + 8, iv2); + br_enc32be(ivbuf + 12, iv3); +} + +/* see bearssl_block.h */ +void +br_aes_ct_ctrcbc_mac(const br_aes_ct_ctrcbc_keys *ctx, + void *cbcmac, const void *data, size_t len) +{ + const unsigned char *buf; + uint32_t cm0, cm1, cm2, cm3; + uint32_t q[8]; + uint32_t sk_exp[120]; + + br_aes_ct_skey_expand(sk_exp, ctx->num_rounds, ctx->skey); + + buf = data; + cm0 = br_dec32le((unsigned char *)cbcmac + 0); + cm1 = br_dec32le((unsigned char *)cbcmac + 4); + cm2 = br_dec32le((unsigned char *)cbcmac + 8); + cm3 = br_dec32le((unsigned char *)cbcmac + 12); + q[1] = 0; + q[3] = 0; + q[5] = 0; + q[7] = 0; + + while (len > 0) { + q[0] = cm0 ^ br_dec32le(buf + 0); + q[2] = cm1 ^ br_dec32le(buf + 4); + q[4] = cm2 ^ br_dec32le(buf + 8); + q[6] = cm3 ^ br_dec32le(buf + 12); + + br_aes_ct_ortho(q); + br_aes_ct_bitslice_encrypt(ctx->num_rounds, sk_exp, q); + br_aes_ct_ortho(q); + + cm0 = q[0]; + cm1 = q[2]; + cm2 = q[4]; + cm3 = q[6]; + buf += 16; + len -= 16; + } + + br_enc32le((unsigned char *)cbcmac + 0, cm0); + br_enc32le((unsigned char *)cbcmac + 4, cm1); + br_enc32le((unsigned char *)cbcmac + 8, cm2); + br_enc32le((unsigned char *)cbcmac + 12, cm3); +} + +/* see bearssl_block.h */ +void +br_aes_ct_ctrcbc_encrypt(const br_aes_ct_ctrcbc_keys *ctx, + void *ctr, void *cbcmac, void *data, size_t len) +{ + /* + * When encrypting, the CBC-MAC processing must be lagging by + * one block, since it operates on the encrypted values, so + * it must wait for that encryption to complete. + */ + + unsigned char *buf; + unsigned char *ivbuf; + uint32_t iv0, iv1, iv2, iv3; + uint32_t cm0, cm1, cm2, cm3; + uint32_t sk_exp[120]; + int first_iter; + + br_aes_ct_skey_expand(sk_exp, ctx->num_rounds, ctx->skey); + + /* + * We keep the counter as four 32-bit values, with big-endian + * convention, because that's what is expected for purposes of + * incrementing the counter value. + */ + ivbuf = ctr; + iv0 = br_dec32be(ivbuf + 0); + iv1 = br_dec32be(ivbuf + 4); + iv2 = br_dec32be(ivbuf + 8); + iv3 = br_dec32be(ivbuf + 12); + + /* + * The current CBC-MAC value is kept in little-endian convention. + */ + cm0 = br_dec32le((unsigned char *)cbcmac + 0); + cm1 = br_dec32le((unsigned char *)cbcmac + 4); + cm2 = br_dec32le((unsigned char *)cbcmac + 8); + cm3 = br_dec32le((unsigned char *)cbcmac + 12); + + buf = data; + first_iter = 1; + while (len > 0) { + uint32_t q[8], carry; + + /* + * The bitslice implementation expects values in + * little-endian convention, so we have to byteswap them. + */ + q[0] = br_swap32(iv0); + q[2] = br_swap32(iv1); + q[4] = br_swap32(iv2); + q[6] = br_swap32(iv3); + iv3 ++; + carry = ~(iv3 | -iv3) >> 31; + iv2 += carry; + carry &= -(~(iv2 | -iv2) >> 31); + iv1 += carry; + carry &= -(~(iv1 | -iv1) >> 31); + iv0 += carry; + + /* + * The odd values are used for CBC-MAC. + */ + q[1] = cm0; + q[3] = cm1; + q[5] = cm2; + q[7] = cm3; + + br_aes_ct_ortho(q); + br_aes_ct_bitslice_encrypt(ctx->num_rounds, sk_exp, q); + br_aes_ct_ortho(q); + + /* + * We do the XOR with the plaintext in 32-bit registers, + * so that the value are available for CBC-MAC processing + * as well. + */ + q[0] ^= br_dec32le(buf + 0); + q[2] ^= br_dec32le(buf + 4); + q[4] ^= br_dec32le(buf + 8); + q[6] ^= br_dec32le(buf + 12); + br_enc32le(buf + 0, q[0]); + br_enc32le(buf + 4, q[2]); + br_enc32le(buf + 8, q[4]); + br_enc32le(buf + 12, q[6]); + + buf += 16; + len -= 16; + + /* + * We set the cm* values to the block to encrypt in the + * next iteration. + */ + if (first_iter) { + first_iter = 0; + cm0 ^= q[0]; + cm1 ^= q[2]; + cm2 ^= q[4]; + cm3 ^= q[6]; + } else { + cm0 = q[0] ^ q[1]; + cm1 = q[2] ^ q[3]; + cm2 = q[4] ^ q[5]; + cm3 = q[6] ^ q[7]; + } + + /* + * If this was the last iteration, then compute the + * extra block encryption to complete CBC-MAC. + */ + if (len == 0) { + q[0] = cm0; + q[2] = cm1; + q[4] = cm2; + q[6] = cm3; + br_aes_ct_ortho(q); + br_aes_ct_bitslice_encrypt(ctx->num_rounds, sk_exp, q); + br_aes_ct_ortho(q); + cm0 = q[0]; + cm1 = q[2]; + cm2 = q[4]; + cm3 = q[6]; + break; + } + } + + br_enc32be(ivbuf + 0, iv0); + br_enc32be(ivbuf + 4, iv1); + br_enc32be(ivbuf + 8, iv2); + br_enc32be(ivbuf + 12, iv3); + br_enc32le((unsigned char *)cbcmac + 0, cm0); + br_enc32le((unsigned char *)cbcmac + 4, cm1); + br_enc32le((unsigned char *)cbcmac + 8, cm2); + br_enc32le((unsigned char *)cbcmac + 12, cm3); +} + +/* see bearssl_block.h */ +void +br_aes_ct_ctrcbc_decrypt(const br_aes_ct_ctrcbc_keys *ctx, + void *ctr, void *cbcmac, void *data, size_t len) +{ + unsigned char *buf; + unsigned char *ivbuf; + uint32_t iv0, iv1, iv2, iv3; + uint32_t cm0, cm1, cm2, cm3; + uint32_t sk_exp[120]; + + br_aes_ct_skey_expand(sk_exp, ctx->num_rounds, ctx->skey); + + /* + * We keep the counter as four 32-bit values, with big-endian + * convention, because that's what is expected for purposes of + * incrementing the counter value. + */ + ivbuf = ctr; + iv0 = br_dec32be(ivbuf + 0); + iv1 = br_dec32be(ivbuf + 4); + iv2 = br_dec32be(ivbuf + 8); + iv3 = br_dec32be(ivbuf + 12); + + /* + * The current CBC-MAC value is kept in little-endian convention. + */ + cm0 = br_dec32le((unsigned char *)cbcmac + 0); + cm1 = br_dec32le((unsigned char *)cbcmac + 4); + cm2 = br_dec32le((unsigned char *)cbcmac + 8); + cm3 = br_dec32le((unsigned char *)cbcmac + 12); + + buf = data; + while (len > 0) { + uint32_t q[8], carry; + unsigned char tmp[16]; + + /* + * The bitslice implementation expects values in + * little-endian convention, so we have to byteswap them. + */ + q[0] = br_swap32(iv0); + q[2] = br_swap32(iv1); + q[4] = br_swap32(iv2); + q[6] = br_swap32(iv3); + iv3 ++; + carry = ~(iv3 | -iv3) >> 31; + iv2 += carry; + carry &= -(~(iv2 | -iv2) >> 31); + iv1 += carry; + carry &= -(~(iv1 | -iv1) >> 31); + iv0 += carry; + + /* + * The odd values are used for CBC-MAC. + */ + q[1] = cm0 ^ br_dec32le(buf + 0); + q[3] = cm1 ^ br_dec32le(buf + 4); + q[5] = cm2 ^ br_dec32le(buf + 8); + q[7] = cm3 ^ br_dec32le(buf + 12); + + br_aes_ct_ortho(q); + br_aes_ct_bitslice_encrypt(ctx->num_rounds, sk_exp, q); + br_aes_ct_ortho(q); + + br_enc32le(tmp + 0, q[0]); + br_enc32le(tmp + 4, q[2]); + br_enc32le(tmp + 8, q[4]); + br_enc32le(tmp + 12, q[6]); + xorbuf(buf, tmp, 16); + cm0 = q[1]; + cm1 = q[3]; + cm2 = q[5]; + cm3 = q[7]; + buf += 16; + len -= 16; + } + + br_enc32be(ivbuf + 0, iv0); + br_enc32be(ivbuf + 4, iv1); + br_enc32be(ivbuf + 8, iv2); + br_enc32be(ivbuf + 12, iv3); + br_enc32le((unsigned char *)cbcmac + 0, cm0); + br_enc32le((unsigned char *)cbcmac + 4, cm1); + br_enc32le((unsigned char *)cbcmac + 8, cm2); + br_enc32le((unsigned char *)cbcmac + 12, cm3); +} + +/* see bearssl_block.h */ +const br_block_ctrcbc_class br_aes_ct_ctrcbc_vtable = { + sizeof(br_aes_ct_ctrcbc_keys), + 16, + 4, + (void (*)(const br_block_ctrcbc_class **, const void *, size_t)) + &br_aes_ct_ctrcbc_init, + (void (*)(const br_block_ctrcbc_class *const *, + void *, void *, void *, size_t)) + &br_aes_ct_ctrcbc_encrypt, + (void (*)(const br_block_ctrcbc_class *const *, + void *, void *, void *, size_t)) + &br_aes_ct_ctrcbc_decrypt, + (void (*)(const br_block_ctrcbc_class *const *, + void *, void *, size_t)) + &br_aes_ct_ctrcbc_ctr, + (void (*)(const br_block_ctrcbc_class *const *, + void *, const void *, size_t)) + &br_aes_ct_ctrcbc_mac +}; + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_ct_dec.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_ct_dec.c new file mode 100644 index 000000000..63fa10ff6 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_ct_dec.c @@ -0,0 +1,175 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +void +br_aes_ct_bitslice_invSbox(uint32_t *q) +{ + /* + * AES S-box is: + * S(x) = A(I(x)) ^ 0x63 + * where I() is inversion in GF(256), and A() is a linear + * transform (0 is formally defined to be its own inverse). + * Since inversion is an involution, the inverse S-box can be + * computed from the S-box as: + * iS(x) = B(S(B(x ^ 0x63)) ^ 0x63) + * where B() is the inverse of A(). Indeed, for any y in GF(256): + * iS(S(y)) = B(A(I(B(A(I(y)) ^ 0x63 ^ 0x63))) ^ 0x63 ^ 0x63) = y + * + * Note: we reuse the implementation of the forward S-box, + * instead of duplicating it here, so that total code size is + * lower. By merging the B() transforms into the S-box circuit + * we could make faster CBC decryption, but CBC decryption is + * already quite faster than CBC encryption because we can + * process two blocks in parallel. + */ + uint32_t q0, q1, q2, q3, q4, q5, q6, q7; + + q0 = ~q[0]; + q1 = ~q[1]; + q2 = q[2]; + q3 = q[3]; + q4 = q[4]; + q5 = ~q[5]; + q6 = ~q[6]; + q7 = q[7]; + q[7] = q1 ^ q4 ^ q6; + q[6] = q0 ^ q3 ^ q5; + q[5] = q7 ^ q2 ^ q4; + q[4] = q6 ^ q1 ^ q3; + q[3] = q5 ^ q0 ^ q2; + q[2] = q4 ^ q7 ^ q1; + q[1] = q3 ^ q6 ^ q0; + q[0] = q2 ^ q5 ^ q7; + + br_aes_ct_bitslice_Sbox(q); + + q0 = ~q[0]; + q1 = ~q[1]; + q2 = q[2]; + q3 = q[3]; + q4 = q[4]; + q5 = ~q[5]; + q6 = ~q[6]; + q7 = q[7]; + q[7] = q1 ^ q4 ^ q6; + q[6] = q0 ^ q3 ^ q5; + q[5] = q7 ^ q2 ^ q4; + q[4] = q6 ^ q1 ^ q3; + q[3] = q5 ^ q0 ^ q2; + q[2] = q4 ^ q7 ^ q1; + q[1] = q3 ^ q6 ^ q0; + q[0] = q2 ^ q5 ^ q7; +} + +static void +add_round_key(uint32_t *q, const uint32_t *sk) +{ + int i; + + for (i = 0; i < 8; i ++) { + q[i] ^= sk[i]; + } +} + +static void +inv_shift_rows(uint32_t *q) +{ + int i; + + for (i = 0; i < 8; i ++) { + uint32_t x; + + x = q[i]; + q[i] = (x & 0x000000FF) + | ((x & 0x00003F00) << 2) | ((x & 0x0000C000) >> 6) + | ((x & 0x000F0000) << 4) | ((x & 0x00F00000) >> 4) + | ((x & 0x03000000) << 6) | ((x & 0xFC000000) >> 2); + } +} + +static inline uint32_t +rotr16(uint32_t x) +{ + return (x << 16) | (x >> 16); +} + +static void +inv_mix_columns(uint32_t *q) +{ + uint32_t q0, q1, q2, q3, q4, q5, q6, q7; + uint32_t r0, r1, r2, r3, r4, r5, r6, r7; + + q0 = q[0]; + q1 = q[1]; + q2 = q[2]; + q3 = q[3]; + q4 = q[4]; + q5 = q[5]; + q6 = q[6]; + q7 = q[7]; + r0 = (q0 >> 8) | (q0 << 24); + r1 = (q1 >> 8) | (q1 << 24); + r2 = (q2 >> 8) | (q2 << 24); + r3 = (q3 >> 8) | (q3 << 24); + r4 = (q4 >> 8) | (q4 << 24); + r5 = (q5 >> 8) | (q5 << 24); + r6 = (q6 >> 8) | (q6 << 24); + r7 = (q7 >> 8) | (q7 << 24); + + q[0] = q5 ^ q6 ^ q7 ^ r0 ^ r5 ^ r7 ^ rotr16(q0 ^ q5 ^ q6 ^ r0 ^ r5); + q[1] = q0 ^ q5 ^ r0 ^ r1 ^ r5 ^ r6 ^ r7 ^ rotr16(q1 ^ q5 ^ q7 ^ r1 ^ r5 ^ r6); + q[2] = q0 ^ q1 ^ q6 ^ r1 ^ r2 ^ r6 ^ r7 ^ rotr16(q0 ^ q2 ^ q6 ^ r2 ^ r6 ^ r7); + q[3] = q0 ^ q1 ^ q2 ^ q5 ^ q6 ^ r0 ^ r2 ^ r3 ^ r5 ^ rotr16(q0 ^ q1 ^ q3 ^ q5 ^ q6 ^ q7 ^ r0 ^ r3 ^ r5 ^ r7); + q[4] = q1 ^ q2 ^ q3 ^ q5 ^ r1 ^ r3 ^ r4 ^ r5 ^ r6 ^ r7 ^ rotr16(q1 ^ q2 ^ q4 ^ q5 ^ q7 ^ r1 ^ r4 ^ r5 ^ r6); + q[5] = q2 ^ q3 ^ q4 ^ q6 ^ r2 ^ r4 ^ r5 ^ r6 ^ r7 ^ rotr16(q2 ^ q3 ^ q5 ^ q6 ^ r2 ^ r5 ^ r6 ^ r7); + q[6] = q3 ^ q4 ^ q5 ^ q7 ^ r3 ^ r5 ^ r6 ^ r7 ^ rotr16(q3 ^ q4 ^ q6 ^ q7 ^ r3 ^ r6 ^ r7); + q[7] = q4 ^ q5 ^ q6 ^ r4 ^ r6 ^ r7 ^ rotr16(q4 ^ q5 ^ q7 ^ r4 ^ r7); +} + +/* see inner.h */ +void +br_aes_ct_bitslice_decrypt(unsigned num_rounds, + const uint32_t *skey, uint32_t *q) +{ + unsigned u; + + add_round_key(q, skey + (num_rounds << 3)); + for (u = num_rounds - 1; u > 0; u --) { + inv_shift_rows(q); + br_aes_ct_bitslice_invSbox(q); + add_round_key(q, skey + (u << 3)); + inv_mix_columns(q); + } + inv_shift_rows(q); + br_aes_ct_bitslice_invSbox(q); + add_round_key(q, skey); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_ct_enc.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_ct_enc.c new file mode 100644 index 000000000..327bd18af --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_ct_enc.c @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +static inline void +add_round_key(uint32_t *q, const uint32_t *sk) +{ + q[0] ^= sk[0]; + q[1] ^= sk[1]; + q[2] ^= sk[2]; + q[3] ^= sk[3]; + q[4] ^= sk[4]; + q[5] ^= sk[5]; + q[6] ^= sk[6]; + q[7] ^= sk[7]; +} + +static inline void +shift_rows(uint32_t *q) +{ + int i; + + for (i = 0; i < 8; i ++) { + uint32_t x; + + x = q[i]; + q[i] = (x & 0x000000FF) + | ((x & 0x0000FC00) >> 2) | ((x & 0x00000300) << 6) + | ((x & 0x00F00000) >> 4) | ((x & 0x000F0000) << 4) + | ((x & 0xC0000000) >> 6) | ((x & 0x3F000000) << 2); + } +} + +static inline uint32_t +rotr16(uint32_t x) +{ + return (x << 16) | (x >> 16); +} + +static inline void +mix_columns(uint32_t *q) +{ + uint32_t q0, q1, q2, q3, q4, q5, q6, q7; + uint32_t r0, r1, r2, r3, r4, r5, r6, r7; + + q0 = q[0]; + q1 = q[1]; + q2 = q[2]; + q3 = q[3]; + q4 = q[4]; + q5 = q[5]; + q6 = q[6]; + q7 = q[7]; + r0 = (q0 >> 8) | (q0 << 24); + r1 = (q1 >> 8) | (q1 << 24); + r2 = (q2 >> 8) | (q2 << 24); + r3 = (q3 >> 8) | (q3 << 24); + r4 = (q4 >> 8) | (q4 << 24); + r5 = (q5 >> 8) | (q5 << 24); + r6 = (q6 >> 8) | (q6 << 24); + r7 = (q7 >> 8) | (q7 << 24); + + q[0] = q7 ^ r7 ^ r0 ^ rotr16(q0 ^ r0); + q[1] = q0 ^ r0 ^ q7 ^ r7 ^ r1 ^ rotr16(q1 ^ r1); + q[2] = q1 ^ r1 ^ r2 ^ rotr16(q2 ^ r2); + q[3] = q2 ^ r2 ^ q7 ^ r7 ^ r3 ^ rotr16(q3 ^ r3); + q[4] = q3 ^ r3 ^ q7 ^ r7 ^ r4 ^ rotr16(q4 ^ r4); + q[5] = q4 ^ r4 ^ r5 ^ rotr16(q5 ^ r5); + q[6] = q5 ^ r5 ^ r6 ^ rotr16(q6 ^ r6); + q[7] = q6 ^ r6 ^ r7 ^ rotr16(q7 ^ r7); +} + +/* see inner.h */ +void +br_aes_ct_bitslice_encrypt(unsigned num_rounds, + const uint32_t *skey, uint32_t *q) +{ + unsigned u; + + add_round_key(q, skey); + for (u = 1; u < num_rounds; u ++) { + br_aes_ct_bitslice_Sbox(q); + shift_rows(q); + mix_columns(q); + add_round_key(q, skey + (u << 3)); + } + br_aes_ct_bitslice_Sbox(q); + shift_rows(q); + add_round_key(q, skey + (num_rounds << 3)); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_pwr8.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_pwr8.c new file mode 100644 index 000000000..b4259f52f --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_pwr8.c @@ -0,0 +1,450 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#define BR_POWER_ASM_MACROS 1 +#include "inner.h" + +/* + * This code contains the AES key schedule implementation using the + * POWER8 opcodes. + */ + +#if BR_POWER8 + +static void +key_schedule_128(unsigned char *sk, const unsigned char *key) +{ + long cc; + + static const uint32_t fmod[] = { 0x11B, 0x11B, 0x11B, 0x11B }; +#if BR_POWER8_LE + static const uint32_t idx2be[] = { + 0x03020100, 0x07060504, 0x0B0A0908, 0x0F0E0D0C + }; +#endif + + cc = 0; + + /* + * We use the VSX instructions for loading and storing the + * key/subkeys, since they support unaligned accesses. The rest + * of the computation is VMX only. VMX register 0 is VSX + * register 32. + */ + asm volatile ( + + /* + * v0 = all-zero word + * v1 = constant -8 / +8, copied into four words + * v2 = current subkey + * v3 = Rcon (x4 words) + * v6 = constant 8, copied into four words + * v7 = constant 0x11B, copied into four words + * v8 = constant for byteswapping words + */ + vspltisw(0, 0) +#if BR_POWER8_LE + vspltisw(1, -8) +#else + vspltisw(1, 8) +#endif + lxvw4x(34, 0, %[key]) + vspltisw(3, 1) + vspltisw(6, 8) + lxvw4x(39, 0, %[fmod]) +#if BR_POWER8_LE + lxvw4x(40, 0, %[idx2be]) +#endif + + /* + * First subkey is a copy of the key itself. + */ +#if BR_POWER8_LE + vperm(4, 2, 2, 8) + stxvw4x(36, 0, %[sk]) +#else + stxvw4x(34, 0, %[sk]) +#endif + + /* + * Loop must run 10 times. + */ + li(%[cc], 10) + mtctr(%[cc]) + label(loop) + /* Increment subkey address */ + addi(%[sk], %[sk], 16) + + /* Compute SubWord(RotWord(temp)) xor Rcon (into v4, splat) */ + vrlw(4, 2, 1) + vsbox(4, 4) +#if BR_POWER8_LE + vxor(4, 4, 3) +#else + vsldoi(5, 3, 0, 3) + vxor(4, 4, 5) +#endif + vspltw(4, 4, 3) + + /* XOR words for next subkey */ + vsldoi(5, 0, 2, 12) + vxor(2, 2, 5) + vsldoi(5, 0, 2, 12) + vxor(2, 2, 5) + vsldoi(5, 0, 2, 12) + vxor(2, 2, 5) + vxor(2, 2, 4) + + /* Store next subkey */ +#if BR_POWER8_LE + vperm(4, 2, 2, 8) + stxvw4x(36, 0, %[sk]) +#else + stxvw4x(34, 0, %[sk]) +#endif + + /* Update Rcon */ + vadduwm(3, 3, 3) + vsrw(4, 3, 6) + vsubuwm(4, 0, 4) + vand(4, 4, 7) + vxor(3, 3, 4) + + bdnz(loop) + +: [sk] "+b" (sk), [cc] "+b" (cc) +: [key] "b" (key), [fmod] "b" (fmod) +#if BR_POWER8_LE + , [idx2be] "b" (idx2be) +#endif +: "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "ctr", "memory" + ); +} + +static void +key_schedule_192(unsigned char *sk, const unsigned char *key) +{ + long cc; + +#if BR_POWER8_LE + static const uint32_t idx2be[] = { + 0x03020100, 0x07060504, 0x0B0A0908, 0x0F0E0D0C + }; +#endif + + cc = 0; + + /* + * We use the VSX instructions for loading and storing the + * key/subkeys, since they support unaligned accesses. The rest + * of the computation is VMX only. VMX register 0 is VSX + * register 32. + */ + asm volatile ( + + /* + * v0 = all-zero word + * v1 = constant -8 / +8, copied into four words + * v2, v3 = current subkey + * v5 = Rcon (x4 words) (already shifted on big-endian) + * v6 = constant 8, copied into four words + * v8 = constant for byteswapping words + * + * The left two words of v3 are ignored. + */ + vspltisw(0, 0) +#if BR_POWER8_LE + vspltisw(1, -8) +#else + vspltisw(1, 8) +#endif + li(%[cc], 8) + lxvw4x(34, 0, %[key]) + lxvw4x(35, %[cc], %[key]) + vsldoi(3, 3, 0, 8) + vspltisw(5, 1) +#if !BR_POWER8_LE + vsldoi(5, 5, 0, 3) +#endif + vspltisw(6, 8) +#if BR_POWER8_LE + lxvw4x(40, 0, %[idx2be]) +#endif + + /* + * Loop must run 8 times. Each iteration produces 256 + * bits of subkeys, with a 64-bit overlap. + */ + li(%[cc], 8) + mtctr(%[cc]) + li(%[cc], 16) + label(loop) + + /* + * Last 6 words in v2:v3l. Compute next 6 words into + * v3r:v4. + */ + vrlw(10, 3, 1) + vsbox(10, 10) + vxor(10, 10, 5) + vspltw(10, 10, 1) + vsldoi(11, 0, 10, 8) + + vsldoi(12, 0, 2, 12) + vxor(12, 2, 12) + vsldoi(13, 0, 12, 12) + vxor(12, 12, 13) + vsldoi(13, 0, 12, 12) + vxor(12, 12, 13) + + vspltw(13, 12, 3) + vxor(13, 13, 3) + vsldoi(14, 0, 3, 12) + vxor(13, 13, 14) + + vsldoi(4, 12, 13, 8) + vsldoi(14, 0, 3, 8) + vsldoi(3, 14, 12, 8) + + vxor(3, 3, 11) + vxor(4, 4, 10) + + /* + * Update Rcon. Since for a 192-bit key, we use only 8 + * such constants, we will not hit the field modulus, + * so a simple shift (addition) works well. + */ + vadduwm(5, 5, 5) + + /* + * Write out the two left 128-bit words + */ +#if BR_POWER8_LE + vperm(10, 2, 2, 8) + vperm(11, 3, 3, 8) + stxvw4x(42, 0, %[sk]) + stxvw4x(43, %[cc], %[sk]) +#else + stxvw4x(34, 0, %[sk]) + stxvw4x(35, %[cc], %[sk]) +#endif + addi(%[sk], %[sk], 24) + + /* + * Shift words for next iteration. + */ + vsldoi(2, 3, 4, 8) + vsldoi(3, 4, 0, 8) + + bdnz(loop) + + /* + * The loop wrote the first 50 subkey words, but we need + * to produce 52, so we must do one last write. + */ +#if BR_POWER8_LE + vperm(10, 2, 2, 8) + stxvw4x(42, 0, %[sk]) +#else + stxvw4x(34, 0, %[sk]) +#endif + +: [sk] "+b" (sk), [cc] "+b" (cc) +: [key] "b" (key) +#if BR_POWER8_LE + , [idx2be] "b" (idx2be) +#endif +: "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", + "v8", "v9", "v10", "v11", "v12", "v13", "v14", "ctr", "memory" + ); +} + +static void +key_schedule_256(unsigned char *sk, const unsigned char *key) +{ + long cc; + +#if BR_POWER8_LE + static const uint32_t idx2be[] = { + 0x03020100, 0x07060504, 0x0B0A0908, 0x0F0E0D0C + }; +#endif + + cc = 0; + + /* + * We use the VSX instructions for loading and storing the + * key/subkeys, since they support unaligned accesses. The rest + * of the computation is VMX only. VMX register 0 is VSX + * register 32. + */ + asm volatile ( + + /* + * v0 = all-zero word + * v1 = constant -8 / +8, copied into four words + * v2, v3 = current subkey + * v6 = Rcon (x4 words) (already shifted on big-endian) + * v7 = constant 8, copied into four words + * v8 = constant for byteswapping words + * + * The left two words of v3 are ignored. + */ + vspltisw(0, 0) +#if BR_POWER8_LE + vspltisw(1, -8) +#else + vspltisw(1, 8) +#endif + li(%[cc], 16) + lxvw4x(34, 0, %[key]) + lxvw4x(35, %[cc], %[key]) + vspltisw(6, 1) +#if !BR_POWER8_LE + vsldoi(6, 6, 0, 3) +#endif + vspltisw(7, 8) +#if BR_POWER8_LE + lxvw4x(40, 0, %[idx2be]) +#endif + + /* + * Loop must run 7 times. Each iteration produces two + * subkeys. + */ + li(%[cc], 7) + mtctr(%[cc]) + li(%[cc], 16) + label(loop) + + /* + * Current words are in v2:v3. Compute next word in v4. + */ + vrlw(10, 3, 1) + vsbox(10, 10) + vxor(10, 10, 6) + vspltw(10, 10, 3) + + vsldoi(4, 0, 2, 12) + vxor(4, 2, 4) + vsldoi(5, 0, 4, 12) + vxor(4, 4, 5) + vsldoi(5, 0, 4, 12) + vxor(4, 4, 5) + vxor(4, 4, 10) + + /* + * Then other word in v5. + */ + vsbox(10, 4) + vspltw(10, 10, 3) + + vsldoi(5, 0, 3, 12) + vxor(5, 3, 5) + vsldoi(11, 0, 5, 12) + vxor(5, 5, 11) + vsldoi(11, 0, 5, 12) + vxor(5, 5, 11) + vxor(5, 5, 10) + + /* + * Update Rcon. Since for a 256-bit key, we use only 7 + * such constants, we will not hit the field modulus, + * so a simple shift (addition) works well. + */ + vadduwm(6, 6, 6) + + /* + * Write out the two left 128-bit words + */ +#if BR_POWER8_LE + vperm(10, 2, 2, 8) + vperm(11, 3, 3, 8) + stxvw4x(42, 0, %[sk]) + stxvw4x(43, %[cc], %[sk]) +#else + stxvw4x(34, 0, %[sk]) + stxvw4x(35, %[cc], %[sk]) +#endif + addi(%[sk], %[sk], 32) + + /* + * Replace v2:v3 with v4:v5. + */ + vxor(2, 0, 4) + vxor(3, 0, 5) + + bdnz(loop) + + /* + * The loop wrote the first 14 subkeys, but we need 15, + * so we must do an extra write. + */ +#if BR_POWER8_LE + vperm(10, 2, 2, 8) + stxvw4x(42, 0, %[sk]) +#else + stxvw4x(34, 0, %[sk]) +#endif + +: [sk] "+b" (sk), [cc] "+b" (cc) +: [key] "b" (key) +#if BR_POWER8_LE + , [idx2be] "b" (idx2be) +#endif +: "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", + "v8", "v9", "v10", "v11", "v12", "v13", "v14", "ctr", "memory" + ); +} + +/* see inner.h */ +int +br_aes_pwr8_supported(void) +{ + return 1; +} + +/* see inner.h */ +unsigned +br_aes_pwr8_keysched(unsigned char *sk, const void *key, size_t len) +{ + switch (len) { + case 16: + key_schedule_128(sk, key); + return 10; + case 24: + key_schedule_192(sk, key); + return 12; + default: + key_schedule_256(sk, key); + return 14; + } +} + +#endif + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_pwr8_cbcdec.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_pwr8_cbcdec.c new file mode 100644 index 000000000..33df4fe7a --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_pwr8_cbcdec.c @@ -0,0 +1,675 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#define BR_POWER_ASM_MACROS 1 +#include "inner.h" + +#if BR_POWER8 + +/* see bearssl_block.h */ +void +br_aes_pwr8_cbcdec_init(br_aes_pwr8_cbcdec_keys *ctx, + const void *key, size_t len) +{ + ctx->vtable = &br_aes_pwr8_cbcdec_vtable; + ctx->num_rounds = br_aes_pwr8_keysched(ctx->skey.skni, key, len); +} + +static void +cbcdec_128(const unsigned char *sk, + const unsigned char *iv, unsigned char *buf, size_t num_blocks) +{ + long cc0, cc1, cc2, cc3; + +#if BR_POWER8_LE + static const uint32_t idx2be[] = { + 0x03020100, 0x07060504, 0x0B0A0908, 0x0F0E0D0C + }; +#endif + + cc0 = 0; + cc1 = 16; + cc2 = 32; + cc3 = 48; + asm volatile ( + + /* + * Load subkeys into v0..v10 + */ + lxvw4x(32, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(33, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(34, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(35, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(36, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(37, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(38, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(39, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(40, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(41, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(42, %[cc0], %[sk]) + li(%[cc0], 0) + +#if BR_POWER8_LE + /* + * v15 = constant for byteswapping words + */ + lxvw4x(47, 0, %[idx2be]) +#endif + /* + * Load IV into v24. + */ + lxvw4x(56, 0, %[iv]) +#if BR_POWER8_LE + vperm(24, 24, 24, 15) +#endif + + mtctr(%[num_blocks]) + label(loop) + /* + * Load next ciphertext words in v16..v19. Also save them + * in v20..v23. + */ + lxvw4x(48, %[cc0], %[buf]) + lxvw4x(49, %[cc1], %[buf]) + lxvw4x(50, %[cc2], %[buf]) + lxvw4x(51, %[cc3], %[buf]) +#if BR_POWER8_LE + vperm(16, 16, 16, 15) + vperm(17, 17, 17, 15) + vperm(18, 18, 18, 15) + vperm(19, 19, 19, 15) +#endif + vand(20, 16, 16) + vand(21, 17, 17) + vand(22, 18, 18) + vand(23, 19, 19) + + /* + * Decrypt the blocks. + */ + vxor(16, 16, 10) + vxor(17, 17, 10) + vxor(18, 18, 10) + vxor(19, 19, 10) + vncipher(16, 16, 9) + vncipher(17, 17, 9) + vncipher(18, 18, 9) + vncipher(19, 19, 9) + vncipher(16, 16, 8) + vncipher(17, 17, 8) + vncipher(18, 18, 8) + vncipher(19, 19, 8) + vncipher(16, 16, 7) + vncipher(17, 17, 7) + vncipher(18, 18, 7) + vncipher(19, 19, 7) + vncipher(16, 16, 6) + vncipher(17, 17, 6) + vncipher(18, 18, 6) + vncipher(19, 19, 6) + vncipher(16, 16, 5) + vncipher(17, 17, 5) + vncipher(18, 18, 5) + vncipher(19, 19, 5) + vncipher(16, 16, 4) + vncipher(17, 17, 4) + vncipher(18, 18, 4) + vncipher(19, 19, 4) + vncipher(16, 16, 3) + vncipher(17, 17, 3) + vncipher(18, 18, 3) + vncipher(19, 19, 3) + vncipher(16, 16, 2) + vncipher(17, 17, 2) + vncipher(18, 18, 2) + vncipher(19, 19, 2) + vncipher(16, 16, 1) + vncipher(17, 17, 1) + vncipher(18, 18, 1) + vncipher(19, 19, 1) + vncipherlast(16, 16, 0) + vncipherlast(17, 17, 0) + vncipherlast(18, 18, 0) + vncipherlast(19, 19, 0) + + /* + * XOR decrypted blocks with IV / previous block. + */ + vxor(16, 16, 24) + vxor(17, 17, 20) + vxor(18, 18, 21) + vxor(19, 19, 22) + + /* + * Store back result (with byteswap) + */ +#if BR_POWER8_LE + vperm(16, 16, 16, 15) + vperm(17, 17, 17, 15) + vperm(18, 18, 18, 15) + vperm(19, 19, 19, 15) +#endif + stxvw4x(48, %[cc0], %[buf]) + stxvw4x(49, %[cc1], %[buf]) + stxvw4x(50, %[cc2], %[buf]) + stxvw4x(51, %[cc3], %[buf]) + + /* + * Fourth encrypted block is IV for next run. + */ + vand(24, 23, 23) + + addi(%[buf], %[buf], 64) + + bdnz(loop) + +: [cc0] "+b" (cc0), [cc1] "+b" (cc1), [cc2] "+b" (cc2), [cc3] "+b" (cc3), + [buf] "+b" (buf) +: [sk] "b" (sk), [iv] "b" (iv), [num_blocks] "b" (num_blocks >> 2) +#if BR_POWER8_LE + , [idx2be] "b" (idx2be) +#endif +: "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", + "v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17", "v18", "v19", + "v20", "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", + "ctr", "memory" + ); +} + +static void +cbcdec_192(const unsigned char *sk, + const unsigned char *iv, unsigned char *buf, size_t num_blocks) +{ + long cc0, cc1, cc2, cc3; + +#if BR_POWER8_LE + static const uint32_t idx2be[] = { + 0x03020100, 0x07060504, 0x0B0A0908, 0x0F0E0D0C + }; +#endif + + cc0 = 0; + cc1 = 16; + cc2 = 32; + cc3 = 48; + asm volatile ( + + /* + * Load subkeys into v0..v12 + */ + lxvw4x(32, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(33, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(34, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(35, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(36, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(37, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(38, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(39, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(40, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(41, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(42, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(43, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(44, %[cc0], %[sk]) + li(%[cc0], 0) + +#if BR_POWER8_LE + /* + * v15 = constant for byteswapping words + */ + lxvw4x(47, 0, %[idx2be]) +#endif + /* + * Load IV into v24. + */ + lxvw4x(56, 0, %[iv]) +#if BR_POWER8_LE + vperm(24, 24, 24, 15) +#endif + + mtctr(%[num_blocks]) + label(loop) + /* + * Load next ciphertext words in v16..v19. Also save them + * in v20..v23. + */ + lxvw4x(48, %[cc0], %[buf]) + lxvw4x(49, %[cc1], %[buf]) + lxvw4x(50, %[cc2], %[buf]) + lxvw4x(51, %[cc3], %[buf]) +#if BR_POWER8_LE + vperm(16, 16, 16, 15) + vperm(17, 17, 17, 15) + vperm(18, 18, 18, 15) + vperm(19, 19, 19, 15) +#endif + vand(20, 16, 16) + vand(21, 17, 17) + vand(22, 18, 18) + vand(23, 19, 19) + + /* + * Decrypt the blocks. + */ + vxor(16, 16, 12) + vxor(17, 17, 12) + vxor(18, 18, 12) + vxor(19, 19, 12) + vncipher(16, 16, 11) + vncipher(17, 17, 11) + vncipher(18, 18, 11) + vncipher(19, 19, 11) + vncipher(16, 16, 10) + vncipher(17, 17, 10) + vncipher(18, 18, 10) + vncipher(19, 19, 10) + vncipher(16, 16, 9) + vncipher(17, 17, 9) + vncipher(18, 18, 9) + vncipher(19, 19, 9) + vncipher(16, 16, 8) + vncipher(17, 17, 8) + vncipher(18, 18, 8) + vncipher(19, 19, 8) + vncipher(16, 16, 7) + vncipher(17, 17, 7) + vncipher(18, 18, 7) + vncipher(19, 19, 7) + vncipher(16, 16, 6) + vncipher(17, 17, 6) + vncipher(18, 18, 6) + vncipher(19, 19, 6) + vncipher(16, 16, 5) + vncipher(17, 17, 5) + vncipher(18, 18, 5) + vncipher(19, 19, 5) + vncipher(16, 16, 4) + vncipher(17, 17, 4) + vncipher(18, 18, 4) + vncipher(19, 19, 4) + vncipher(16, 16, 3) + vncipher(17, 17, 3) + vncipher(18, 18, 3) + vncipher(19, 19, 3) + vncipher(16, 16, 2) + vncipher(17, 17, 2) + vncipher(18, 18, 2) + vncipher(19, 19, 2) + vncipher(16, 16, 1) + vncipher(17, 17, 1) + vncipher(18, 18, 1) + vncipher(19, 19, 1) + vncipherlast(16, 16, 0) + vncipherlast(17, 17, 0) + vncipherlast(18, 18, 0) + vncipherlast(19, 19, 0) + + /* + * XOR decrypted blocks with IV / previous block. + */ + vxor(16, 16, 24) + vxor(17, 17, 20) + vxor(18, 18, 21) + vxor(19, 19, 22) + + /* + * Store back result (with byteswap) + */ +#if BR_POWER8_LE + vperm(16, 16, 16, 15) + vperm(17, 17, 17, 15) + vperm(18, 18, 18, 15) + vperm(19, 19, 19, 15) +#endif + stxvw4x(48, %[cc0], %[buf]) + stxvw4x(49, %[cc1], %[buf]) + stxvw4x(50, %[cc2], %[buf]) + stxvw4x(51, %[cc3], %[buf]) + + /* + * Fourth encrypted block is IV for next run. + */ + vand(24, 23, 23) + + addi(%[buf], %[buf], 64) + + bdnz(loop) + +: [cc0] "+b" (cc0), [cc1] "+b" (cc1), [cc2] "+b" (cc2), [cc3] "+b" (cc3), + [buf] "+b" (buf) +: [sk] "b" (sk), [iv] "b" (iv), [num_blocks] "b" (num_blocks >> 2) +#if BR_POWER8_LE + , [idx2be] "b" (idx2be) +#endif +: "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", + "v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17", "v18", "v19", + "v20", "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", + "ctr", "memory" + ); +} + +static void +cbcdec_256(const unsigned char *sk, + const unsigned char *iv, unsigned char *buf, size_t num_blocks) +{ + long cc0, cc1, cc2, cc3; + +#if BR_POWER8_LE + static const uint32_t idx2be[] = { + 0x03020100, 0x07060504, 0x0B0A0908, 0x0F0E0D0C + }; +#endif + + cc0 = 0; + cc1 = 16; + cc2 = 32; + cc3 = 48; + asm volatile ( + + /* + * Load subkeys into v0..v14 + */ + lxvw4x(32, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(33, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(34, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(35, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(36, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(37, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(38, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(39, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(40, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(41, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(42, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(43, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(44, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(45, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(46, %[cc0], %[sk]) + li(%[cc0], 0) + +#if BR_POWER8_LE + /* + * v15 = constant for byteswapping words + */ + lxvw4x(47, 0, %[idx2be]) +#endif + /* + * Load IV into v24. + */ + lxvw4x(56, 0, %[iv]) +#if BR_POWER8_LE + vperm(24, 24, 24, 15) +#endif + + mtctr(%[num_blocks]) + label(loop) + /* + * Load next ciphertext words in v16..v19. Also save them + * in v20..v23. + */ + lxvw4x(48, %[cc0], %[buf]) + lxvw4x(49, %[cc1], %[buf]) + lxvw4x(50, %[cc2], %[buf]) + lxvw4x(51, %[cc3], %[buf]) +#if BR_POWER8_LE + vperm(16, 16, 16, 15) + vperm(17, 17, 17, 15) + vperm(18, 18, 18, 15) + vperm(19, 19, 19, 15) +#endif + vand(20, 16, 16) + vand(21, 17, 17) + vand(22, 18, 18) + vand(23, 19, 19) + + /* + * Decrypt the blocks. + */ + vxor(16, 16, 14) + vxor(17, 17, 14) + vxor(18, 18, 14) + vxor(19, 19, 14) + vncipher(16, 16, 13) + vncipher(17, 17, 13) + vncipher(18, 18, 13) + vncipher(19, 19, 13) + vncipher(16, 16, 12) + vncipher(17, 17, 12) + vncipher(18, 18, 12) + vncipher(19, 19, 12) + vncipher(16, 16, 11) + vncipher(17, 17, 11) + vncipher(18, 18, 11) + vncipher(19, 19, 11) + vncipher(16, 16, 10) + vncipher(17, 17, 10) + vncipher(18, 18, 10) + vncipher(19, 19, 10) + vncipher(16, 16, 9) + vncipher(17, 17, 9) + vncipher(18, 18, 9) + vncipher(19, 19, 9) + vncipher(16, 16, 8) + vncipher(17, 17, 8) + vncipher(18, 18, 8) + vncipher(19, 19, 8) + vncipher(16, 16, 7) + vncipher(17, 17, 7) + vncipher(18, 18, 7) + vncipher(19, 19, 7) + vncipher(16, 16, 6) + vncipher(17, 17, 6) + vncipher(18, 18, 6) + vncipher(19, 19, 6) + vncipher(16, 16, 5) + vncipher(17, 17, 5) + vncipher(18, 18, 5) + vncipher(19, 19, 5) + vncipher(16, 16, 4) + vncipher(17, 17, 4) + vncipher(18, 18, 4) + vncipher(19, 19, 4) + vncipher(16, 16, 3) + vncipher(17, 17, 3) + vncipher(18, 18, 3) + vncipher(19, 19, 3) + vncipher(16, 16, 2) + vncipher(17, 17, 2) + vncipher(18, 18, 2) + vncipher(19, 19, 2) + vncipher(16, 16, 1) + vncipher(17, 17, 1) + vncipher(18, 18, 1) + vncipher(19, 19, 1) + vncipherlast(16, 16, 0) + vncipherlast(17, 17, 0) + vncipherlast(18, 18, 0) + vncipherlast(19, 19, 0) + + /* + * XOR decrypted blocks with IV / previous block. + */ + vxor(16, 16, 24) + vxor(17, 17, 20) + vxor(18, 18, 21) + vxor(19, 19, 22) + + /* + * Store back result (with byteswap) + */ +#if BR_POWER8_LE + vperm(16, 16, 16, 15) + vperm(17, 17, 17, 15) + vperm(18, 18, 18, 15) + vperm(19, 19, 19, 15) +#endif + stxvw4x(48, %[cc0], %[buf]) + stxvw4x(49, %[cc1], %[buf]) + stxvw4x(50, %[cc2], %[buf]) + stxvw4x(51, %[cc3], %[buf]) + + /* + * Fourth encrypted block is IV for next run. + */ + vand(24, 23, 23) + + addi(%[buf], %[buf], 64) + + bdnz(loop) + +: [cc0] "+b" (cc0), [cc1] "+b" (cc1), [cc2] "+b" (cc2), [cc3] "+b" (cc3), + [buf] "+b" (buf) +: [sk] "b" (sk), [iv] "b" (iv), [num_blocks] "b" (num_blocks >> 2) +#if BR_POWER8_LE + , [idx2be] "b" (idx2be) +#endif +: "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", + "v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17", "v18", "v19", + "v20", "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", + "ctr", "memory" + ); +} + +/* see bearssl_block.h */ +void +br_aes_pwr8_cbcdec_run(const br_aes_pwr8_cbcdec_keys *ctx, + void *iv, void *data, size_t len) +{ + unsigned char nextiv[16]; + unsigned char *buf; + + if (len == 0) { + return; + } + buf = data; + memcpy(nextiv, buf + len - 16, 16); + if (len >= 64) { + size_t num_blocks; + unsigned char tmp[16]; + + num_blocks = (len >> 4) & ~(size_t)3; + memcpy(tmp, buf + (num_blocks << 4) - 16, 16); + switch (ctx->num_rounds) { + case 10: + cbcdec_128(ctx->skey.skni, iv, buf, num_blocks); + break; + case 12: + cbcdec_192(ctx->skey.skni, iv, buf, num_blocks); + break; + default: + cbcdec_256(ctx->skey.skni, iv, buf, num_blocks); + break; + } + buf += num_blocks << 4; + len &= 63; + memcpy(iv, tmp, 16); + } + if (len > 0) { + unsigned char tmp[64]; + + memcpy(tmp, buf, len); + memset(tmp + len, 0, (sizeof tmp) - len); + switch (ctx->num_rounds) { + case 10: + cbcdec_128(ctx->skey.skni, iv, tmp, 4); + break; + case 12: + cbcdec_192(ctx->skey.skni, iv, tmp, 4); + break; + default: + cbcdec_256(ctx->skey.skni, iv, tmp, 4); + break; + } + memcpy(buf, tmp, len); + } + memcpy(iv, nextiv, 16); +} + +/* see bearssl_block.h */ +const br_block_cbcdec_class br_aes_pwr8_cbcdec_vtable = { + sizeof(br_aes_pwr8_cbcdec_keys), + 16, + 4, + (void (*)(const br_block_cbcdec_class **, const void *, size_t)) + &br_aes_pwr8_cbcdec_init, + (void (*)(const br_block_cbcdec_class *const *, void *, void *, size_t)) + &br_aes_pwr8_cbcdec_run +}; + +/* see bearssl_block.h */ +const br_block_cbcdec_class * +br_aes_pwr8_cbcdec_get_vtable(void) +{ + return br_aes_pwr8_supported() ? &br_aes_pwr8_cbcdec_vtable : NULL; +} + +#else + +/* see bearssl_block.h */ +const br_block_cbcdec_class * +br_aes_pwr8_cbcdec_get_vtable(void) +{ + return NULL; +} + +#endif + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_pwr8_cbcenc.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_pwr8_cbcenc.c new file mode 100644 index 000000000..4f9b28f6b --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_pwr8_cbcenc.c @@ -0,0 +1,422 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#define BR_POWER_ASM_MACROS 1 +#include "inner.h" + +#if BR_POWER8 + +/* see bearssl_block.h */ +void +br_aes_pwr8_cbcenc_init(br_aes_pwr8_cbcenc_keys *ctx, + const void *key, size_t len) +{ + ctx->vtable = &br_aes_pwr8_cbcenc_vtable; + ctx->num_rounds = br_aes_pwr8_keysched(ctx->skey.skni, key, len); +} + +static void +cbcenc_128(const unsigned char *sk, + const unsigned char *iv, unsigned char *buf, size_t len) +{ + long cc; + +#if BR_POWER8_LE + static const uint32_t idx2be[] = { + 0x03020100, 0x07060504, 0x0B0A0908, 0x0F0E0D0C + }; +#endif + + cc = 0; + asm volatile ( + + /* + * Load subkeys into v0..v10 + */ + lxvw4x(32, %[cc], %[sk]) + addi(%[cc], %[cc], 16) + lxvw4x(33, %[cc], %[sk]) + addi(%[cc], %[cc], 16) + lxvw4x(34, %[cc], %[sk]) + addi(%[cc], %[cc], 16) + lxvw4x(35, %[cc], %[sk]) + addi(%[cc], %[cc], 16) + lxvw4x(36, %[cc], %[sk]) + addi(%[cc], %[cc], 16) + lxvw4x(37, %[cc], %[sk]) + addi(%[cc], %[cc], 16) + lxvw4x(38, %[cc], %[sk]) + addi(%[cc], %[cc], 16) + lxvw4x(39, %[cc], %[sk]) + addi(%[cc], %[cc], 16) + lxvw4x(40, %[cc], %[sk]) + addi(%[cc], %[cc], 16) + lxvw4x(41, %[cc], %[sk]) + addi(%[cc], %[cc], 16) + lxvw4x(42, %[cc], %[sk]) + +#if BR_POWER8_LE + /* + * v15 = constant for byteswapping words + */ + lxvw4x(47, 0, %[idx2be]) +#endif + /* + * Load IV into v16. + */ + lxvw4x(48, 0, %[iv]) +#if BR_POWER8_LE + vperm(16, 16, 16, 15) +#endif + + mtctr(%[num_blocks]) + label(loop) + /* + * Load next plaintext word and XOR with current IV. + */ + lxvw4x(49, 0, %[buf]) +#if BR_POWER8_LE + vperm(17, 17, 17, 15) +#endif + vxor(16, 16, 17) + + /* + * Encrypt the block. + */ + vxor(16, 16, 0) + vcipher(16, 16, 1) + vcipher(16, 16, 2) + vcipher(16, 16, 3) + vcipher(16, 16, 4) + vcipher(16, 16, 5) + vcipher(16, 16, 6) + vcipher(16, 16, 7) + vcipher(16, 16, 8) + vcipher(16, 16, 9) + vcipherlast(16, 16, 10) + + /* + * Store back result (with byteswap) + */ +#if BR_POWER8_LE + vperm(17, 16, 16, 15) + stxvw4x(49, 0, %[buf]) +#else + stxvw4x(48, 0, %[buf]) +#endif + addi(%[buf], %[buf], 16) + + bdnz(loop) + +: [cc] "+b" (cc), [buf] "+b" (buf) +: [sk] "b" (sk), [iv] "b" (iv), [num_blocks] "b" (len >> 4) +#if BR_POWER8_LE + , [idx2be] "b" (idx2be) +#endif +: "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", + "v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17", "v18", "v19", + "ctr", "memory" + ); +} + +static void +cbcenc_192(const unsigned char *sk, + const unsigned char *iv, unsigned char *buf, size_t len) +{ + long cc; + +#if BR_POWER8_LE + static const uint32_t idx2be[] = { + 0x03020100, 0x07060504, 0x0B0A0908, 0x0F0E0D0C + }; +#endif + + cc = 0; + asm volatile ( + + /* + * Load subkeys into v0..v12 + */ + lxvw4x(32, %[cc], %[sk]) + addi(%[cc], %[cc], 16) + lxvw4x(33, %[cc], %[sk]) + addi(%[cc], %[cc], 16) + lxvw4x(34, %[cc], %[sk]) + addi(%[cc], %[cc], 16) + lxvw4x(35, %[cc], %[sk]) + addi(%[cc], %[cc], 16) + lxvw4x(36, %[cc], %[sk]) + addi(%[cc], %[cc], 16) + lxvw4x(37, %[cc], %[sk]) + addi(%[cc], %[cc], 16) + lxvw4x(38, %[cc], %[sk]) + addi(%[cc], %[cc], 16) + lxvw4x(39, %[cc], %[sk]) + addi(%[cc], %[cc], 16) + lxvw4x(40, %[cc], %[sk]) + addi(%[cc], %[cc], 16) + lxvw4x(41, %[cc], %[sk]) + addi(%[cc], %[cc], 16) + lxvw4x(42, %[cc], %[sk]) + addi(%[cc], %[cc], 16) + lxvw4x(43, %[cc], %[sk]) + addi(%[cc], %[cc], 16) + lxvw4x(44, %[cc], %[sk]) + +#if BR_POWER8_LE + /* + * v15 = constant for byteswapping words + */ + lxvw4x(47, 0, %[idx2be]) +#endif + /* + * Load IV into v16. + */ + lxvw4x(48, 0, %[iv]) +#if BR_POWER8_LE + vperm(16, 16, 16, 15) +#endif + + mtctr(%[num_blocks]) + label(loop) + /* + * Load next plaintext word and XOR with current IV. + */ + lxvw4x(49, 0, %[buf]) +#if BR_POWER8_LE + vperm(17, 17, 17, 15) +#endif + vxor(16, 16, 17) + + /* + * Encrypt the block. + */ + vxor(16, 16, 0) + vcipher(16, 16, 1) + vcipher(16, 16, 2) + vcipher(16, 16, 3) + vcipher(16, 16, 4) + vcipher(16, 16, 5) + vcipher(16, 16, 6) + vcipher(16, 16, 7) + vcipher(16, 16, 8) + vcipher(16, 16, 9) + vcipher(16, 16, 10) + vcipher(16, 16, 11) + vcipherlast(16, 16, 12) + + /* + * Store back result (with byteswap) + */ +#if BR_POWER8_LE + vperm(17, 16, 16, 15) + stxvw4x(49, 0, %[buf]) +#else + stxvw4x(48, 0, %[buf]) +#endif + addi(%[buf], %[buf], 16) + + bdnz(loop) + +: [cc] "+b" (cc), [buf] "+b" (buf) +: [sk] "b" (sk), [iv] "b" (iv), [num_blocks] "b" (len >> 4) +#if BR_POWER8_LE + , [idx2be] "b" (idx2be) +#endif +: "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", + "v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17", "v18", "v19", + "ctr", "memory" + ); +} + +static void +cbcenc_256(const unsigned char *sk, + const unsigned char *iv, unsigned char *buf, size_t len) +{ + long cc; + +#if BR_POWER8_LE + static const uint32_t idx2be[] = { + 0x03020100, 0x07060504, 0x0B0A0908, 0x0F0E0D0C + }; +#endif + + cc = 0; + asm volatile ( + + /* + * Load subkeys into v0..v14 + */ + lxvw4x(32, %[cc], %[sk]) + addi(%[cc], %[cc], 16) + lxvw4x(33, %[cc], %[sk]) + addi(%[cc], %[cc], 16) + lxvw4x(34, %[cc], %[sk]) + addi(%[cc], %[cc], 16) + lxvw4x(35, %[cc], %[sk]) + addi(%[cc], %[cc], 16) + lxvw4x(36, %[cc], %[sk]) + addi(%[cc], %[cc], 16) + lxvw4x(37, %[cc], %[sk]) + addi(%[cc], %[cc], 16) + lxvw4x(38, %[cc], %[sk]) + addi(%[cc], %[cc], 16) + lxvw4x(39, %[cc], %[sk]) + addi(%[cc], %[cc], 16) + lxvw4x(40, %[cc], %[sk]) + addi(%[cc], %[cc], 16) + lxvw4x(41, %[cc], %[sk]) + addi(%[cc], %[cc], 16) + lxvw4x(42, %[cc], %[sk]) + addi(%[cc], %[cc], 16) + lxvw4x(43, %[cc], %[sk]) + addi(%[cc], %[cc], 16) + lxvw4x(44, %[cc], %[sk]) + addi(%[cc], %[cc], 16) + lxvw4x(45, %[cc], %[sk]) + addi(%[cc], %[cc], 16) + lxvw4x(46, %[cc], %[sk]) + +#if BR_POWER8_LE + /* + * v15 = constant for byteswapping words + */ + lxvw4x(47, 0, %[idx2be]) +#endif + /* + * Load IV into v16. + */ + lxvw4x(48, 0, %[iv]) +#if BR_POWER8_LE + vperm(16, 16, 16, 15) +#endif + + mtctr(%[num_blocks]) + label(loop) + /* + * Load next plaintext word and XOR with current IV. + */ + lxvw4x(49, 0, %[buf]) +#if BR_POWER8_LE + vperm(17, 17, 17, 15) +#endif + vxor(16, 16, 17) + + /* + * Encrypt the block. + */ + vxor(16, 16, 0) + vcipher(16, 16, 1) + vcipher(16, 16, 2) + vcipher(16, 16, 3) + vcipher(16, 16, 4) + vcipher(16, 16, 5) + vcipher(16, 16, 6) + vcipher(16, 16, 7) + vcipher(16, 16, 8) + vcipher(16, 16, 9) + vcipher(16, 16, 10) + vcipher(16, 16, 11) + vcipher(16, 16, 12) + vcipher(16, 16, 13) + vcipherlast(16, 16, 14) + + /* + * Store back result (with byteswap) + */ +#if BR_POWER8_LE + vperm(17, 16, 16, 15) + stxvw4x(49, 0, %[buf]) +#else + stxvw4x(48, 0, %[buf]) +#endif + addi(%[buf], %[buf], 16) + + bdnz(loop) + +: [cc] "+b" (cc), [buf] "+b" (buf) +: [sk] "b" (sk), [iv] "b" (iv), [num_blocks] "b" (len >> 4) +#if BR_POWER8_LE + , [idx2be] "b" (idx2be) +#endif +: "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", + "v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17", "v18", "v19", + "ctr", "memory" + ); +} + +/* see bearssl_block.h */ +void +br_aes_pwr8_cbcenc_run(const br_aes_pwr8_cbcenc_keys *ctx, + void *iv, void *data, size_t len) +{ + if (len > 0) { + switch (ctx->num_rounds) { + case 10: + cbcenc_128(ctx->skey.skni, iv, data, len); + break; + case 12: + cbcenc_192(ctx->skey.skni, iv, data, len); + break; + default: + cbcenc_256(ctx->skey.skni, iv, data, len); + break; + } + memcpy(iv, (unsigned char *)data + (len - 16), 16); + } +} + +/* see bearssl_block.h */ +const br_block_cbcenc_class br_aes_pwr8_cbcenc_vtable = { + sizeof(br_aes_pwr8_cbcenc_keys), + 16, + 4, + (void (*)(const br_block_cbcenc_class **, const void *, size_t)) + &br_aes_pwr8_cbcenc_init, + (void (*)(const br_block_cbcenc_class *const *, void *, void *, size_t)) + &br_aes_pwr8_cbcenc_run +}; + +/* see bearssl_block.h */ +const br_block_cbcenc_class * +br_aes_pwr8_cbcenc_get_vtable(void) +{ + return br_aes_pwr8_supported() ? &br_aes_pwr8_cbcenc_vtable : NULL; +} + +#else + +/* see bearssl_block.h */ +const br_block_cbcenc_class * +br_aes_pwr8_cbcenc_get_vtable(void) +{ + return NULL; +} + +#endif + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_pwr8_ctr.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_pwr8_ctr.c new file mode 100644 index 000000000..69558cb54 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_pwr8_ctr.c @@ -0,0 +1,722 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#define BR_POWER_ASM_MACROS 1 +#include "inner.h" + +#if BR_POWER8 + +/* see bearssl_block.h */ +void +br_aes_pwr8_ctr_init(br_aes_pwr8_ctr_keys *ctx, + const void *key, size_t len) +{ + ctx->vtable = &br_aes_pwr8_ctr_vtable; + ctx->num_rounds = br_aes_pwr8_keysched(ctx->skey.skni, key, len); +} + +static void +ctr_128(const unsigned char *sk, const unsigned char *ivbuf, + unsigned char *buf, size_t num_blocks) +{ + long cc0, cc1, cc2, cc3; + +#if BR_POWER8_LE + static const uint32_t idx2be[] = { + 0x03020100, 0x07060504, 0x0B0A0908, 0x0F0E0D0C + }; +#endif + static const uint32_t ctrinc[] = { + 0, 0, 0, 4 + }; + + cc0 = 0; + cc1 = 16; + cc2 = 32; + cc3 = 48; + asm volatile ( + + /* + * Load subkeys into v0..v10 + */ + lxvw4x(32, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(33, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(34, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(35, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(36, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(37, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(38, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(39, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(40, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(41, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(42, %[cc0], %[sk]) + li(%[cc0], 0) + +#if BR_POWER8_LE + /* + * v15 = constant for byteswapping words + */ + lxvw4x(47, 0, %[idx2be]) +#endif + /* + * v28 = increment for IV counter. + */ + lxvw4x(60, 0, %[ctrinc]) + + /* + * Load IV into v16..v19 + */ + lxvw4x(48, %[cc0], %[ivbuf]) + lxvw4x(49, %[cc1], %[ivbuf]) + lxvw4x(50, %[cc2], %[ivbuf]) + lxvw4x(51, %[cc3], %[ivbuf]) +#if BR_POWER8_LE + vperm(16, 16, 16, 15) + vperm(17, 17, 17, 15) + vperm(18, 18, 18, 15) + vperm(19, 19, 19, 15) +#endif + + mtctr(%[num_blocks]) + label(loop) + /* + * Compute next IV into v24..v27 + */ + vadduwm(24, 16, 28) + vadduwm(25, 17, 28) + vadduwm(26, 18, 28) + vadduwm(27, 19, 28) + + /* + * Load next data blocks. We do this early on but we + * won't need them until IV encryption is done. + */ + lxvw4x(52, %[cc0], %[buf]) + lxvw4x(53, %[cc1], %[buf]) + lxvw4x(54, %[cc2], %[buf]) + lxvw4x(55, %[cc3], %[buf]) + + /* + * Encrypt the current IV. + */ + vxor(16, 16, 0) + vxor(17, 17, 0) + vxor(18, 18, 0) + vxor(19, 19, 0) + vcipher(16, 16, 1) + vcipher(17, 17, 1) + vcipher(18, 18, 1) + vcipher(19, 19, 1) + vcipher(16, 16, 2) + vcipher(17, 17, 2) + vcipher(18, 18, 2) + vcipher(19, 19, 2) + vcipher(16, 16, 3) + vcipher(17, 17, 3) + vcipher(18, 18, 3) + vcipher(19, 19, 3) + vcipher(16, 16, 4) + vcipher(17, 17, 4) + vcipher(18, 18, 4) + vcipher(19, 19, 4) + vcipher(16, 16, 5) + vcipher(17, 17, 5) + vcipher(18, 18, 5) + vcipher(19, 19, 5) + vcipher(16, 16, 6) + vcipher(17, 17, 6) + vcipher(18, 18, 6) + vcipher(19, 19, 6) + vcipher(16, 16, 7) + vcipher(17, 17, 7) + vcipher(18, 18, 7) + vcipher(19, 19, 7) + vcipher(16, 16, 8) + vcipher(17, 17, 8) + vcipher(18, 18, 8) + vcipher(19, 19, 8) + vcipher(16, 16, 9) + vcipher(17, 17, 9) + vcipher(18, 18, 9) + vcipher(19, 19, 9) + vcipherlast(16, 16, 10) + vcipherlast(17, 17, 10) + vcipherlast(18, 18, 10) + vcipherlast(19, 19, 10) + +#if BR_POWER8_LE + vperm(16, 16, 16, 15) + vperm(17, 17, 17, 15) + vperm(18, 18, 18, 15) + vperm(19, 19, 19, 15) +#endif + + /* + * Load next plaintext word and XOR with encrypted IV. + */ + vxor(16, 20, 16) + vxor(17, 21, 17) + vxor(18, 22, 18) + vxor(19, 23, 19) + stxvw4x(48, %[cc0], %[buf]) + stxvw4x(49, %[cc1], %[buf]) + stxvw4x(50, %[cc2], %[buf]) + stxvw4x(51, %[cc3], %[buf]) + + addi(%[buf], %[buf], 64) + + /* + * Update IV. + */ + vand(16, 24, 24) + vand(17, 25, 25) + vand(18, 26, 26) + vand(19, 27, 27) + + bdnz(loop) + +: [cc0] "+b" (cc0), [cc1] "+b" (cc1), [cc2] "+b" (cc2), [cc3] "+b" (cc3), + [buf] "+b" (buf) +: [sk] "b" (sk), [ivbuf] "b" (ivbuf), [num_blocks] "b" (num_blocks >> 2), + [ctrinc] "b" (ctrinc) +#if BR_POWER8_LE + , [idx2be] "b" (idx2be) +#endif +: "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", + "v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17", "v18", "v19", + "v20", "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", + "ctr", "memory" + ); +} + +static void +ctr_192(const unsigned char *sk, const unsigned char *ivbuf, + unsigned char *buf, size_t num_blocks) +{ + long cc0, cc1, cc2, cc3; + +#if BR_POWER8_LE + static const uint32_t idx2be[] = { + 0x03020100, 0x07060504, 0x0B0A0908, 0x0F0E0D0C + }; +#endif + static const uint32_t ctrinc[] = { + 0, 0, 0, 4 + }; + + cc0 = 0; + cc1 = 16; + cc2 = 32; + cc3 = 48; + asm volatile ( + + /* + * Load subkeys into v0..v12 + */ + lxvw4x(32, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(33, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(34, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(35, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(36, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(37, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(38, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(39, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(40, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(41, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(42, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(43, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(44, %[cc0], %[sk]) + li(%[cc0], 0) + +#if BR_POWER8_LE + /* + * v15 = constant for byteswapping words + */ + lxvw4x(47, 0, %[idx2be]) +#endif + /* + * v28 = increment for IV counter. + */ + lxvw4x(60, 0, %[ctrinc]) + + /* + * Load IV into v16..v19 + */ + lxvw4x(48, %[cc0], %[ivbuf]) + lxvw4x(49, %[cc1], %[ivbuf]) + lxvw4x(50, %[cc2], %[ivbuf]) + lxvw4x(51, %[cc3], %[ivbuf]) +#if BR_POWER8_LE + vperm(16, 16, 16, 15) + vperm(17, 17, 17, 15) + vperm(18, 18, 18, 15) + vperm(19, 19, 19, 15) +#endif + + mtctr(%[num_blocks]) + label(loop) + /* + * Compute next IV into v24..v27 + */ + vadduwm(24, 16, 28) + vadduwm(25, 17, 28) + vadduwm(26, 18, 28) + vadduwm(27, 19, 28) + + /* + * Load next data blocks. We do this early on but we + * won't need them until IV encryption is done. + */ + lxvw4x(52, %[cc0], %[buf]) + lxvw4x(53, %[cc1], %[buf]) + lxvw4x(54, %[cc2], %[buf]) + lxvw4x(55, %[cc3], %[buf]) + + /* + * Encrypt the current IV. + */ + vxor(16, 16, 0) + vxor(17, 17, 0) + vxor(18, 18, 0) + vxor(19, 19, 0) + vcipher(16, 16, 1) + vcipher(17, 17, 1) + vcipher(18, 18, 1) + vcipher(19, 19, 1) + vcipher(16, 16, 2) + vcipher(17, 17, 2) + vcipher(18, 18, 2) + vcipher(19, 19, 2) + vcipher(16, 16, 3) + vcipher(17, 17, 3) + vcipher(18, 18, 3) + vcipher(19, 19, 3) + vcipher(16, 16, 4) + vcipher(17, 17, 4) + vcipher(18, 18, 4) + vcipher(19, 19, 4) + vcipher(16, 16, 5) + vcipher(17, 17, 5) + vcipher(18, 18, 5) + vcipher(19, 19, 5) + vcipher(16, 16, 6) + vcipher(17, 17, 6) + vcipher(18, 18, 6) + vcipher(19, 19, 6) + vcipher(16, 16, 7) + vcipher(17, 17, 7) + vcipher(18, 18, 7) + vcipher(19, 19, 7) + vcipher(16, 16, 8) + vcipher(17, 17, 8) + vcipher(18, 18, 8) + vcipher(19, 19, 8) + vcipher(16, 16, 9) + vcipher(17, 17, 9) + vcipher(18, 18, 9) + vcipher(19, 19, 9) + vcipher(16, 16, 10) + vcipher(17, 17, 10) + vcipher(18, 18, 10) + vcipher(19, 19, 10) + vcipher(16, 16, 11) + vcipher(17, 17, 11) + vcipher(18, 18, 11) + vcipher(19, 19, 11) + vcipherlast(16, 16, 12) + vcipherlast(17, 17, 12) + vcipherlast(18, 18, 12) + vcipherlast(19, 19, 12) + +#if BR_POWER8_LE + vperm(16, 16, 16, 15) + vperm(17, 17, 17, 15) + vperm(18, 18, 18, 15) + vperm(19, 19, 19, 15) +#endif + + /* + * Load next plaintext word and XOR with encrypted IV. + */ + vxor(16, 20, 16) + vxor(17, 21, 17) + vxor(18, 22, 18) + vxor(19, 23, 19) + stxvw4x(48, %[cc0], %[buf]) + stxvw4x(49, %[cc1], %[buf]) + stxvw4x(50, %[cc2], %[buf]) + stxvw4x(51, %[cc3], %[buf]) + + addi(%[buf], %[buf], 64) + + /* + * Update IV. + */ + vand(16, 24, 24) + vand(17, 25, 25) + vand(18, 26, 26) + vand(19, 27, 27) + + bdnz(loop) + +: [cc0] "+b" (cc0), [cc1] "+b" (cc1), [cc2] "+b" (cc2), [cc3] "+b" (cc3), + [buf] "+b" (buf) +: [sk] "b" (sk), [ivbuf] "b" (ivbuf), [num_blocks] "b" (num_blocks >> 2), + [ctrinc] "b" (ctrinc) +#if BR_POWER8_LE + , [idx2be] "b" (idx2be) +#endif +: "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", + "v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17", "v18", "v19", + "v20", "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", + "ctr", "memory" + ); +} + +static void +ctr_256(const unsigned char *sk, const unsigned char *ivbuf, + unsigned char *buf, size_t num_blocks) +{ + long cc0, cc1, cc2, cc3; + +#if BR_POWER8_LE + static const uint32_t idx2be[] = { + 0x03020100, 0x07060504, 0x0B0A0908, 0x0F0E0D0C + }; +#endif + static const uint32_t ctrinc[] = { + 0, 0, 0, 4 + }; + + cc0 = 0; + cc1 = 16; + cc2 = 32; + cc3 = 48; + asm volatile ( + + /* + * Load subkeys into v0..v14 + */ + lxvw4x(32, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(33, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(34, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(35, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(36, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(37, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(38, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(39, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(40, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(41, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(42, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(43, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(44, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(45, %[cc0], %[sk]) + addi(%[cc0], %[cc0], 16) + lxvw4x(46, %[cc0], %[sk]) + li(%[cc0], 0) + +#if BR_POWER8_LE + /* + * v15 = constant for byteswapping words + */ + lxvw4x(47, 0, %[idx2be]) +#endif + /* + * v28 = increment for IV counter. + */ + lxvw4x(60, 0, %[ctrinc]) + + /* + * Load IV into v16..v19 + */ + lxvw4x(48, %[cc0], %[ivbuf]) + lxvw4x(49, %[cc1], %[ivbuf]) + lxvw4x(50, %[cc2], %[ivbuf]) + lxvw4x(51, %[cc3], %[ivbuf]) +#if BR_POWER8_LE + vperm(16, 16, 16, 15) + vperm(17, 17, 17, 15) + vperm(18, 18, 18, 15) + vperm(19, 19, 19, 15) +#endif + + mtctr(%[num_blocks]) + label(loop) + /* + * Compute next IV into v24..v27 + */ + vadduwm(24, 16, 28) + vadduwm(25, 17, 28) + vadduwm(26, 18, 28) + vadduwm(27, 19, 28) + + /* + * Load next data blocks. We do this early on but we + * won't need them until IV encryption is done. + */ + lxvw4x(52, %[cc0], %[buf]) + lxvw4x(53, %[cc1], %[buf]) + lxvw4x(54, %[cc2], %[buf]) + lxvw4x(55, %[cc3], %[buf]) + + /* + * Encrypt the current IV. + */ + vxor(16, 16, 0) + vxor(17, 17, 0) + vxor(18, 18, 0) + vxor(19, 19, 0) + vcipher(16, 16, 1) + vcipher(17, 17, 1) + vcipher(18, 18, 1) + vcipher(19, 19, 1) + vcipher(16, 16, 2) + vcipher(17, 17, 2) + vcipher(18, 18, 2) + vcipher(19, 19, 2) + vcipher(16, 16, 3) + vcipher(17, 17, 3) + vcipher(18, 18, 3) + vcipher(19, 19, 3) + vcipher(16, 16, 4) + vcipher(17, 17, 4) + vcipher(18, 18, 4) + vcipher(19, 19, 4) + vcipher(16, 16, 5) + vcipher(17, 17, 5) + vcipher(18, 18, 5) + vcipher(19, 19, 5) + vcipher(16, 16, 6) + vcipher(17, 17, 6) + vcipher(18, 18, 6) + vcipher(19, 19, 6) + vcipher(16, 16, 7) + vcipher(17, 17, 7) + vcipher(18, 18, 7) + vcipher(19, 19, 7) + vcipher(16, 16, 8) + vcipher(17, 17, 8) + vcipher(18, 18, 8) + vcipher(19, 19, 8) + vcipher(16, 16, 9) + vcipher(17, 17, 9) + vcipher(18, 18, 9) + vcipher(19, 19, 9) + vcipher(16, 16, 10) + vcipher(17, 17, 10) + vcipher(18, 18, 10) + vcipher(19, 19, 10) + vcipher(16, 16, 11) + vcipher(17, 17, 11) + vcipher(18, 18, 11) + vcipher(19, 19, 11) + vcipher(16, 16, 12) + vcipher(17, 17, 12) + vcipher(18, 18, 12) + vcipher(19, 19, 12) + vcipher(16, 16, 13) + vcipher(17, 17, 13) + vcipher(18, 18, 13) + vcipher(19, 19, 13) + vcipherlast(16, 16, 14) + vcipherlast(17, 17, 14) + vcipherlast(18, 18, 14) + vcipherlast(19, 19, 14) + +#if BR_POWER8_LE + vperm(16, 16, 16, 15) + vperm(17, 17, 17, 15) + vperm(18, 18, 18, 15) + vperm(19, 19, 19, 15) +#endif + + /* + * Load next plaintext word and XOR with encrypted IV. + */ + vxor(16, 20, 16) + vxor(17, 21, 17) + vxor(18, 22, 18) + vxor(19, 23, 19) + stxvw4x(48, %[cc0], %[buf]) + stxvw4x(49, %[cc1], %[buf]) + stxvw4x(50, %[cc2], %[buf]) + stxvw4x(51, %[cc3], %[buf]) + + addi(%[buf], %[buf], 64) + + /* + * Update IV. + */ + vand(16, 24, 24) + vand(17, 25, 25) + vand(18, 26, 26) + vand(19, 27, 27) + + bdnz(loop) + +: [cc0] "+b" (cc0), [cc1] "+b" (cc1), [cc2] "+b" (cc2), [cc3] "+b" (cc3), + [buf] "+b" (buf) +: [sk] "b" (sk), [ivbuf] "b" (ivbuf), [num_blocks] "b" (num_blocks >> 2), + [ctrinc] "b" (ctrinc) +#if BR_POWER8_LE + , [idx2be] "b" (idx2be) +#endif +: "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", + "v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17", "v18", "v19", + "v20", "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", + "ctr", "memory" + ); +} + +/* see bearssl_block.h */ +uint32_t +br_aes_pwr8_ctr_run(const br_aes_pwr8_ctr_keys *ctx, + const void *iv, uint32_t cc, void *data, size_t len) +{ + unsigned char *buf; + unsigned char ivbuf[64]; + + buf = data; + memcpy(ivbuf + 0, iv, 12); + memcpy(ivbuf + 16, iv, 12); + memcpy(ivbuf + 32, iv, 12); + memcpy(ivbuf + 48, iv, 12); + if (len >= 64) { + br_enc32be(ivbuf + 12, cc + 0); + br_enc32be(ivbuf + 28, cc + 1); + br_enc32be(ivbuf + 44, cc + 2); + br_enc32be(ivbuf + 60, cc + 3); + switch (ctx->num_rounds) { + case 10: + ctr_128(ctx->skey.skni, ivbuf, buf, + (len >> 4) & ~(size_t)3); + break; + case 12: + ctr_192(ctx->skey.skni, ivbuf, buf, + (len >> 4) & ~(size_t)3); + break; + default: + ctr_256(ctx->skey.skni, ivbuf, buf, + (len >> 4) & ~(size_t)3); + break; + } + cc += (len >> 4) & ~(size_t)3; + buf += len & ~(size_t)63; + len &= 63; + } + if (len > 0) { + unsigned char tmp[64]; + + memcpy(tmp, buf, len); + memset(tmp + len, 0, (sizeof tmp) - len); + br_enc32be(ivbuf + 12, cc + 0); + br_enc32be(ivbuf + 28, cc + 1); + br_enc32be(ivbuf + 44, cc + 2); + br_enc32be(ivbuf + 60, cc + 3); + switch (ctx->num_rounds) { + case 10: + ctr_128(ctx->skey.skni, ivbuf, tmp, 4); + break; + case 12: + ctr_192(ctx->skey.skni, ivbuf, tmp, 4); + break; + default: + ctr_256(ctx->skey.skni, ivbuf, tmp, 4); + break; + } + memcpy(buf, tmp, len); + cc += (len + 15) >> 4; + } + return cc; +} + +/* see bearssl_block.h */ +const br_block_ctr_class br_aes_pwr8_ctr_vtable = { + sizeof(br_aes_pwr8_ctr_keys), + 16, + 4, + (void (*)(const br_block_ctr_class **, const void *, size_t)) + &br_aes_pwr8_ctr_init, + (uint32_t (*)(const br_block_ctr_class *const *, + const void *, uint32_t, void *, size_t)) + &br_aes_pwr8_ctr_run +}; + +/* see bearssl_block.h */ +const br_block_ctr_class * +br_aes_pwr8_ctr_get_vtable(void) +{ + return br_aes_pwr8_supported() ? &br_aes_pwr8_ctr_vtable : NULL; +} + +#else + +/* see bearssl_block.h */ +const br_block_ctr_class * +br_aes_pwr8_ctr_get_vtable(void) +{ + return NULL; +} + +#endif + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_pwr8_ctrcbc.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_pwr8_ctrcbc.c new file mode 100644 index 000000000..62175f073 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_pwr8_ctrcbc.c @@ -0,0 +1,951 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#define BR_POWER_ASM_MACROS 1 +#include "inner.h" + +#if BR_POWER8 + +/* see bearssl_block.h */ +const br_block_ctrcbc_class * +br_aes_pwr8_ctrcbc_get_vtable(void) +{ + return br_aes_pwr8_supported() ? &br_aes_pwr8_ctrcbc_vtable : NULL; +} + +/* see bearssl_block.h */ +void +br_aes_pwr8_ctrcbc_init(br_aes_pwr8_ctrcbc_keys *ctx, + const void *key, size_t len) +{ + ctx->vtable = &br_aes_pwr8_ctrcbc_vtable; + ctx->num_rounds = br_aes_pwr8_keysched(ctx->skey.skni, key, len); +} + +/* + * Register conventions for CTR + CBC-MAC: + * + * AES subkeys are in registers 0 to 10/12/14 (depending on keys size) + * Register v15 contains the byteswap index register (little-endian only) + * Register v16 contains the CTR counter value + * Register v17 contains the CBC-MAC current value + * Registers v18 to v27 are scratch + * Counter increment uses v28, v29 and v30 + * + * For CTR alone: + * + * AES subkeys are in registers 0 to 10/12/14 (depending on keys size) + * Register v15 contains the byteswap index register (little-endian only) + * Registers v16 to v19 contain the CTR counter values (four blocks) + * Registers v20 to v27 are scratch + * Counter increment uses v28, v29 and v30 + */ + +#define LOAD_SUBKEYS_128 \ + lxvw4x(32, %[cc], %[sk]) \ + addi(%[cc], %[cc], 16) \ + lxvw4x(33, %[cc], %[sk]) \ + addi(%[cc], %[cc], 16) \ + lxvw4x(34, %[cc], %[sk]) \ + addi(%[cc], %[cc], 16) \ + lxvw4x(35, %[cc], %[sk]) \ + addi(%[cc], %[cc], 16) \ + lxvw4x(36, %[cc], %[sk]) \ + addi(%[cc], %[cc], 16) \ + lxvw4x(37, %[cc], %[sk]) \ + addi(%[cc], %[cc], 16) \ + lxvw4x(38, %[cc], %[sk]) \ + addi(%[cc], %[cc], 16) \ + lxvw4x(39, %[cc], %[sk]) \ + addi(%[cc], %[cc], 16) \ + lxvw4x(40, %[cc], %[sk]) \ + addi(%[cc], %[cc], 16) \ + lxvw4x(41, %[cc], %[sk]) \ + addi(%[cc], %[cc], 16) \ + lxvw4x(42, %[cc], %[sk]) + +#define LOAD_SUBKEYS_192 \ + LOAD_SUBKEYS_128 \ + addi(%[cc], %[cc], 16) \ + lxvw4x(43, %[cc], %[sk]) \ + addi(%[cc], %[cc], 16) \ + lxvw4x(44, %[cc], %[sk]) + +#define LOAD_SUBKEYS_256 \ + LOAD_SUBKEYS_192 \ + addi(%[cc], %[cc], 16) \ + lxvw4x(45, %[cc], %[sk]) \ + addi(%[cc], %[cc], 16) \ + lxvw4x(46, %[cc], %[sk]) + +#define BLOCK_ENCRYPT_128(x) \ + vxor(x, x, 0) \ + vcipher(x, x, 1) \ + vcipher(x, x, 2) \ + vcipher(x, x, 3) \ + vcipher(x, x, 4) \ + vcipher(x, x, 5) \ + vcipher(x, x, 6) \ + vcipher(x, x, 7) \ + vcipher(x, x, 8) \ + vcipher(x, x, 9) \ + vcipherlast(x, x, 10) + +#define BLOCK_ENCRYPT_192(x) \ + vxor(x, x, 0) \ + vcipher(x, x, 1) \ + vcipher(x, x, 2) \ + vcipher(x, x, 3) \ + vcipher(x, x, 4) \ + vcipher(x, x, 5) \ + vcipher(x, x, 6) \ + vcipher(x, x, 7) \ + vcipher(x, x, 8) \ + vcipher(x, x, 9) \ + vcipher(x, x, 10) \ + vcipher(x, x, 11) \ + vcipherlast(x, x, 12) + +#define BLOCK_ENCRYPT_256(x) \ + vxor(x, x, 0) \ + vcipher(x, x, 1) \ + vcipher(x, x, 2) \ + vcipher(x, x, 3) \ + vcipher(x, x, 4) \ + vcipher(x, x, 5) \ + vcipher(x, x, 6) \ + vcipher(x, x, 7) \ + vcipher(x, x, 8) \ + vcipher(x, x, 9) \ + vcipher(x, x, 10) \ + vcipher(x, x, 11) \ + vcipher(x, x, 12) \ + vcipher(x, x, 13) \ + vcipherlast(x, x, 14) + +#define BLOCK_ENCRYPT_X2_128(x, y) \ + vxor(x, x, 0) \ + vxor(y, y, 0) \ + vcipher(x, x, 1) \ + vcipher(y, y, 1) \ + vcipher(x, x, 2) \ + vcipher(y, y, 2) \ + vcipher(x, x, 3) \ + vcipher(y, y, 3) \ + vcipher(x, x, 4) \ + vcipher(y, y, 4) \ + vcipher(x, x, 5) \ + vcipher(y, y, 5) \ + vcipher(x, x, 6) \ + vcipher(y, y, 6) \ + vcipher(x, x, 7) \ + vcipher(y, y, 7) \ + vcipher(x, x, 8) \ + vcipher(y, y, 8) \ + vcipher(x, x, 9) \ + vcipher(y, y, 9) \ + vcipherlast(x, x, 10) \ + vcipherlast(y, y, 10) + +#define BLOCK_ENCRYPT_X2_192(x, y) \ + vxor(x, x, 0) \ + vxor(y, y, 0) \ + vcipher(x, x, 1) \ + vcipher(y, y, 1) \ + vcipher(x, x, 2) \ + vcipher(y, y, 2) \ + vcipher(x, x, 3) \ + vcipher(y, y, 3) \ + vcipher(x, x, 4) \ + vcipher(y, y, 4) \ + vcipher(x, x, 5) \ + vcipher(y, y, 5) \ + vcipher(x, x, 6) \ + vcipher(y, y, 6) \ + vcipher(x, x, 7) \ + vcipher(y, y, 7) \ + vcipher(x, x, 8) \ + vcipher(y, y, 8) \ + vcipher(x, x, 9) \ + vcipher(y, y, 9) \ + vcipher(x, x, 10) \ + vcipher(y, y, 10) \ + vcipher(x, x, 11) \ + vcipher(y, y, 11) \ + vcipherlast(x, x, 12) \ + vcipherlast(y, y, 12) + +#define BLOCK_ENCRYPT_X2_256(x, y) \ + vxor(x, x, 0) \ + vxor(y, y, 0) \ + vcipher(x, x, 1) \ + vcipher(y, y, 1) \ + vcipher(x, x, 2) \ + vcipher(y, y, 2) \ + vcipher(x, x, 3) \ + vcipher(y, y, 3) \ + vcipher(x, x, 4) \ + vcipher(y, y, 4) \ + vcipher(x, x, 5) \ + vcipher(y, y, 5) \ + vcipher(x, x, 6) \ + vcipher(y, y, 6) \ + vcipher(x, x, 7) \ + vcipher(y, y, 7) \ + vcipher(x, x, 8) \ + vcipher(y, y, 8) \ + vcipher(x, x, 9) \ + vcipher(y, y, 9) \ + vcipher(x, x, 10) \ + vcipher(y, y, 10) \ + vcipher(x, x, 11) \ + vcipher(y, y, 11) \ + vcipher(x, x, 12) \ + vcipher(y, y, 12) \ + vcipher(x, x, 13) \ + vcipher(y, y, 13) \ + vcipherlast(x, x, 14) \ + vcipherlast(y, y, 14) + +#define BLOCK_ENCRYPT_X4_128(x0, x1, x2, x3) \ + vxor(x0, x0, 0) \ + vxor(x1, x1, 0) \ + vxor(x2, x2, 0) \ + vxor(x3, x3, 0) \ + vcipher(x0, x0, 1) \ + vcipher(x1, x1, 1) \ + vcipher(x2, x2, 1) \ + vcipher(x3, x3, 1) \ + vcipher(x0, x0, 2) \ + vcipher(x1, x1, 2) \ + vcipher(x2, x2, 2) \ + vcipher(x3, x3, 2) \ + vcipher(x0, x0, 3) \ + vcipher(x1, x1, 3) \ + vcipher(x2, x2, 3) \ + vcipher(x3, x3, 3) \ + vcipher(x0, x0, 4) \ + vcipher(x1, x1, 4) \ + vcipher(x2, x2, 4) \ + vcipher(x3, x3, 4) \ + vcipher(x0, x0, 5) \ + vcipher(x1, x1, 5) \ + vcipher(x2, x2, 5) \ + vcipher(x3, x3, 5) \ + vcipher(x0, x0, 6) \ + vcipher(x1, x1, 6) \ + vcipher(x2, x2, 6) \ + vcipher(x3, x3, 6) \ + vcipher(x0, x0, 7) \ + vcipher(x1, x1, 7) \ + vcipher(x2, x2, 7) \ + vcipher(x3, x3, 7) \ + vcipher(x0, x0, 8) \ + vcipher(x1, x1, 8) \ + vcipher(x2, x2, 8) \ + vcipher(x3, x3, 8) \ + vcipher(x0, x0, 9) \ + vcipher(x1, x1, 9) \ + vcipher(x2, x2, 9) \ + vcipher(x3, x3, 9) \ + vcipherlast(x0, x0, 10) \ + vcipherlast(x1, x1, 10) \ + vcipherlast(x2, x2, 10) \ + vcipherlast(x3, x3, 10) + +#define BLOCK_ENCRYPT_X4_192(x0, x1, x2, x3) \ + vxor(x0, x0, 0) \ + vxor(x1, x1, 0) \ + vxor(x2, x2, 0) \ + vxor(x3, x3, 0) \ + vcipher(x0, x0, 1) \ + vcipher(x1, x1, 1) \ + vcipher(x2, x2, 1) \ + vcipher(x3, x3, 1) \ + vcipher(x0, x0, 2) \ + vcipher(x1, x1, 2) \ + vcipher(x2, x2, 2) \ + vcipher(x3, x3, 2) \ + vcipher(x0, x0, 3) \ + vcipher(x1, x1, 3) \ + vcipher(x2, x2, 3) \ + vcipher(x3, x3, 3) \ + vcipher(x0, x0, 4) \ + vcipher(x1, x1, 4) \ + vcipher(x2, x2, 4) \ + vcipher(x3, x3, 4) \ + vcipher(x0, x0, 5) \ + vcipher(x1, x1, 5) \ + vcipher(x2, x2, 5) \ + vcipher(x3, x3, 5) \ + vcipher(x0, x0, 6) \ + vcipher(x1, x1, 6) \ + vcipher(x2, x2, 6) \ + vcipher(x3, x3, 6) \ + vcipher(x0, x0, 7) \ + vcipher(x1, x1, 7) \ + vcipher(x2, x2, 7) \ + vcipher(x3, x3, 7) \ + vcipher(x0, x0, 8) \ + vcipher(x1, x1, 8) \ + vcipher(x2, x2, 8) \ + vcipher(x3, x3, 8) \ + vcipher(x0, x0, 9) \ + vcipher(x1, x1, 9) \ + vcipher(x2, x2, 9) \ + vcipher(x3, x3, 9) \ + vcipher(x0, x0, 10) \ + vcipher(x1, x1, 10) \ + vcipher(x2, x2, 10) \ + vcipher(x3, x3, 10) \ + vcipher(x0, x0, 11) \ + vcipher(x1, x1, 11) \ + vcipher(x2, x2, 11) \ + vcipher(x3, x3, 11) \ + vcipherlast(x0, x0, 12) \ + vcipherlast(x1, x1, 12) \ + vcipherlast(x2, x2, 12) \ + vcipherlast(x3, x3, 12) + +#define BLOCK_ENCRYPT_X4_256(x0, x1, x2, x3) \ + vxor(x0, x0, 0) \ + vxor(x1, x1, 0) \ + vxor(x2, x2, 0) \ + vxor(x3, x3, 0) \ + vcipher(x0, x0, 1) \ + vcipher(x1, x1, 1) \ + vcipher(x2, x2, 1) \ + vcipher(x3, x3, 1) \ + vcipher(x0, x0, 2) \ + vcipher(x1, x1, 2) \ + vcipher(x2, x2, 2) \ + vcipher(x3, x3, 2) \ + vcipher(x0, x0, 3) \ + vcipher(x1, x1, 3) \ + vcipher(x2, x2, 3) \ + vcipher(x3, x3, 3) \ + vcipher(x0, x0, 4) \ + vcipher(x1, x1, 4) \ + vcipher(x2, x2, 4) \ + vcipher(x3, x3, 4) \ + vcipher(x0, x0, 5) \ + vcipher(x1, x1, 5) \ + vcipher(x2, x2, 5) \ + vcipher(x3, x3, 5) \ + vcipher(x0, x0, 6) \ + vcipher(x1, x1, 6) \ + vcipher(x2, x2, 6) \ + vcipher(x3, x3, 6) \ + vcipher(x0, x0, 7) \ + vcipher(x1, x1, 7) \ + vcipher(x2, x2, 7) \ + vcipher(x3, x3, 7) \ + vcipher(x0, x0, 8) \ + vcipher(x1, x1, 8) \ + vcipher(x2, x2, 8) \ + vcipher(x3, x3, 8) \ + vcipher(x0, x0, 9) \ + vcipher(x1, x1, 9) \ + vcipher(x2, x2, 9) \ + vcipher(x3, x3, 9) \ + vcipher(x0, x0, 10) \ + vcipher(x1, x1, 10) \ + vcipher(x2, x2, 10) \ + vcipher(x3, x3, 10) \ + vcipher(x0, x0, 11) \ + vcipher(x1, x1, 11) \ + vcipher(x2, x2, 11) \ + vcipher(x3, x3, 11) \ + vcipher(x0, x0, 12) \ + vcipher(x1, x1, 12) \ + vcipher(x2, x2, 12) \ + vcipher(x3, x3, 12) \ + vcipher(x0, x0, 13) \ + vcipher(x1, x1, 13) \ + vcipher(x2, x2, 13) \ + vcipher(x3, x3, 13) \ + vcipherlast(x0, x0, 14) \ + vcipherlast(x1, x1, 14) \ + vcipherlast(x2, x2, 14) \ + vcipherlast(x3, x3, 14) + +#if BR_POWER8_LE +static const uint32_t idx2be[] = { + 0x03020100, 0x07060504, 0x0B0A0908, 0x0F0E0D0C +}; +#define BYTESWAP_INIT lxvw4x(47, 0, %[idx2be]) +#define BYTESWAP(x) vperm(x, x, x, 15) +#define BYTESWAPX(d, s) vperm(d, s, s, 15) +#define BYTESWAP_REG , [idx2be] "b" (idx2be) +#else +#define BYTESWAP_INIT +#define BYTESWAP(x) +#define BYTESWAPX(d, s) vand(d, s, s) +#define BYTESWAP_REG +#endif + +static const uint32_t ctrinc[] = { + 0, 0, 0, 1 +}; +static const uint32_t ctrinc_x4[] = { + 0, 0, 0, 4 +}; +#define INCR_128_INIT lxvw4x(60, 0, %[ctrinc]) +#define INCR_128_X4_INIT lxvw4x(60, 0, %[ctrinc_x4]) +#define INCR_128(d, s) \ + vaddcuw(29, s, 28) \ + vadduwm(d, s, 28) \ + vsldoi(30, 29, 29, 4) \ + vaddcuw(29, d, 30) \ + vadduwm(d, d, 30) \ + vsldoi(30, 29, 29, 4) \ + vaddcuw(29, d, 30) \ + vadduwm(d, d, 30) \ + vsldoi(30, 29, 29, 4) \ + vadduwm(d, d, 30) + +#define MKCTR(size) \ +static void \ +ctr_ ## size(const unsigned char *sk, \ + unsigned char *ctrbuf, unsigned char *buf, size_t num_blocks_x4) \ +{ \ + long cc, cc0, cc1, cc2, cc3; \ + \ + cc = 0; \ + cc0 = 0; \ + cc1 = 16; \ + cc2 = 32; \ + cc3 = 48; \ + asm volatile ( \ + \ + /* \ + * Load subkeys into v0..v10 \ + */ \ + LOAD_SUBKEYS_ ## size \ + li(%[cc], 0) \ + \ + BYTESWAP_INIT \ + INCR_128_X4_INIT \ + \ + /* \ + * Load current CTR counters into v16 to v19. \ + */ \ + lxvw4x(48, %[cc0], %[ctrbuf]) \ + lxvw4x(49, %[cc1], %[ctrbuf]) \ + lxvw4x(50, %[cc2], %[ctrbuf]) \ + lxvw4x(51, %[cc3], %[ctrbuf]) \ + BYTESWAP(16) \ + BYTESWAP(17) \ + BYTESWAP(18) \ + BYTESWAP(19) \ + \ + mtctr(%[num_blocks_x4]) \ + \ + label(loop) \ + /* \ + * Compute next counter values into v20..v23. \ + */ \ + INCR_128(20, 16) \ + INCR_128(21, 17) \ + INCR_128(22, 18) \ + INCR_128(23, 19) \ + \ + /* \ + * Encrypt counter values and XOR into next data blocks. \ + */ \ + lxvw4x(56, %[cc0], %[buf]) \ + lxvw4x(57, %[cc1], %[buf]) \ + lxvw4x(58, %[cc2], %[buf]) \ + lxvw4x(59, %[cc3], %[buf]) \ + BYTESWAP(24) \ + BYTESWAP(25) \ + BYTESWAP(26) \ + BYTESWAP(27) \ + BLOCK_ENCRYPT_X4_ ## size(16, 17, 18, 19) \ + vxor(16, 16, 24) \ + vxor(17, 17, 25) \ + vxor(18, 18, 26) \ + vxor(19, 19, 27) \ + BYTESWAP(16) \ + BYTESWAP(17) \ + BYTESWAP(18) \ + BYTESWAP(19) \ + stxvw4x(48, %[cc0], %[buf]) \ + stxvw4x(49, %[cc1], %[buf]) \ + stxvw4x(50, %[cc2], %[buf]) \ + stxvw4x(51, %[cc3], %[buf]) \ + \ + /* \ + * Update counters and data pointer. \ + */ \ + vand(16, 20, 20) \ + vand(17, 21, 21) \ + vand(18, 22, 22) \ + vand(19, 23, 23) \ + addi(%[buf], %[buf], 64) \ + \ + bdnz(loop) \ + \ + /* \ + * Write back new counter values. \ + */ \ + BYTESWAP(16) \ + BYTESWAP(17) \ + BYTESWAP(18) \ + BYTESWAP(19) \ + stxvw4x(48, %[cc0], %[ctrbuf]) \ + stxvw4x(49, %[cc1], %[ctrbuf]) \ + stxvw4x(50, %[cc2], %[ctrbuf]) \ + stxvw4x(51, %[cc3], %[ctrbuf]) \ + \ +: [cc] "+b" (cc), [buf] "+b" (buf), \ + [cc0] "+b" (cc0), [cc1] "+b" (cc1), [cc2] "+b" (cc2), [cc3] "+b" (cc3) \ +: [sk] "b" (sk), [ctrbuf] "b" (ctrbuf), \ + [num_blocks_x4] "b" (num_blocks_x4), [ctrinc_x4] "b" (ctrinc_x4) \ + BYTESWAP_REG \ +: "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", \ + "v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17", "v18", "v19", \ + "v20", "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", \ + "v30", "ctr", "memory" \ + ); \ +} + +MKCTR(128) +MKCTR(192) +MKCTR(256) + +#define MKCBCMAC(size) \ +static void \ +cbcmac_ ## size(const unsigned char *sk, \ + unsigned char *cbcmac, const unsigned char *buf, size_t num_blocks) \ +{ \ + long cc; \ + \ + cc = 0; \ + asm volatile ( \ + \ + /* \ + * Load subkeys into v0..v10 \ + */ \ + LOAD_SUBKEYS_ ## size \ + li(%[cc], 0) \ + \ + BYTESWAP_INIT \ + \ + /* \ + * Load current CBC-MAC value into v16. \ + */ \ + lxvw4x(48, %[cc], %[cbcmac]) \ + BYTESWAP(16) \ + \ + mtctr(%[num_blocks]) \ + \ + label(loop) \ + /* \ + * Load next block, XOR into current CBC-MAC value, \ + * and then encrypt it. \ + */ \ + lxvw4x(49, %[cc], %[buf]) \ + BYTESWAP(17) \ + vxor(16, 16, 17) \ + BLOCK_ENCRYPT_ ## size(16) \ + addi(%[buf], %[buf], 16) \ + \ + bdnz(loop) \ + \ + /* \ + * Write back new CBC-MAC value. \ + */ \ + BYTESWAP(16) \ + stxvw4x(48, %[cc], %[cbcmac]) \ + \ +: [cc] "+b" (cc), [buf] "+b" (buf) \ +: [sk] "b" (sk), [cbcmac] "b" (cbcmac), [num_blocks] "b" (num_blocks) \ + BYTESWAP_REG \ +: "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", \ + "v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17", "v18", "v19", \ + "v20", "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", \ + "v30", "ctr", "memory" \ + ); \ +} + +MKCBCMAC(128) +MKCBCMAC(192) +MKCBCMAC(256) + +#define MKENCRYPT(size) \ +static void \ +ctrcbc_ ## size ## _encrypt(const unsigned char *sk, \ + unsigned char *ctr, unsigned char *cbcmac, unsigned char *buf, \ + size_t num_blocks) \ +{ \ + long cc; \ + \ + cc = 0; \ + asm volatile ( \ + \ + /* \ + * Load subkeys into v0..v10 \ + */ \ + LOAD_SUBKEYS_ ## size \ + li(%[cc], 0) \ + \ + BYTESWAP_INIT \ + INCR_128_INIT \ + \ + /* \ + * Load current CTR counter into v16, and current \ + * CBC-MAC IV into v17. \ + */ \ + lxvw4x(48, %[cc], %[ctr]) \ + lxvw4x(49, %[cc], %[cbcmac]) \ + BYTESWAP(16) \ + BYTESWAP(17) \ + \ + /* \ + * At each iteration, we do two parallel encryption: \ + * - new counter value for encryption of the next block; \ + * - CBC-MAC over the previous encrypted block. \ + * Thus, each plaintext block implies two AES instances, \ + * over two successive iterations. This requires a single \ + * counter encryption before the loop, and a single \ + * CBC-MAC encryption after the loop. \ + */ \ + \ + /* \ + * Encrypt first block (into v20). \ + */ \ + lxvw4x(52, %[cc], %[buf]) \ + BYTESWAP(20) \ + INCR_128(22, 16) \ + BLOCK_ENCRYPT_ ## size(16) \ + vxor(20, 20, 16) \ + BYTESWAPX(21, 20) \ + stxvw4x(53, %[cc], %[buf]) \ + vand(16, 22, 22) \ + addi(%[buf], %[buf], 16) \ + \ + /* \ + * Load loop counter; skip the loop if there is only \ + * one block in total (already handled by the boundary \ + * conditions). \ + */ \ + mtctr(%[num_blocks]) \ + bdz(fastexit) \ + \ + label(loop) \ + /* \ + * Upon loop entry: \ + * v16 counter value for next block \ + * v17 current CBC-MAC value \ + * v20 encrypted previous block \ + */ \ + vxor(17, 17, 20) \ + INCR_128(22, 16) \ + lxvw4x(52, %[cc], %[buf]) \ + BYTESWAP(20) \ + BLOCK_ENCRYPT_X2_ ## size(16, 17) \ + vxor(20, 20, 16) \ + BYTESWAPX(21, 20) \ + stxvw4x(53, %[cc], %[buf]) \ + addi(%[buf], %[buf], 16) \ + vand(16, 22, 22) \ + \ + bdnz(loop) \ + \ + label(fastexit) \ + vxor(17, 17, 20) \ + BLOCK_ENCRYPT_ ## size(17) \ + BYTESWAP(16) \ + BYTESWAP(17) \ + stxvw4x(48, %[cc], %[ctr]) \ + stxvw4x(49, %[cc], %[cbcmac]) \ + \ +: [cc] "+b" (cc), [buf] "+b" (buf) \ +: [sk] "b" (sk), [ctr] "b" (ctr), [cbcmac] "b" (cbcmac), \ + [num_blocks] "b" (num_blocks), [ctrinc] "b" (ctrinc) \ + BYTESWAP_REG \ +: "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", \ + "v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17", "v18", "v19", \ + "v20", "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", \ + "v30", "ctr", "memory" \ + ); \ +} + +MKENCRYPT(128) +MKENCRYPT(192) +MKENCRYPT(256) + +#define MKDECRYPT(size) \ +static void \ +ctrcbc_ ## size ## _decrypt(const unsigned char *sk, \ + unsigned char *ctr, unsigned char *cbcmac, unsigned char *buf, \ + size_t num_blocks) \ +{ \ + long cc; \ + \ + cc = 0; \ + asm volatile ( \ + \ + /* \ + * Load subkeys into v0..v10 \ + */ \ + LOAD_SUBKEYS_ ## size \ + li(%[cc], 0) \ + \ + BYTESWAP_INIT \ + INCR_128_INIT \ + \ + /* \ + * Load current CTR counter into v16, and current \ + * CBC-MAC IV into v17. \ + */ \ + lxvw4x(48, %[cc], %[ctr]) \ + lxvw4x(49, %[cc], %[cbcmac]) \ + BYTESWAP(16) \ + BYTESWAP(17) \ + \ + /* \ + * At each iteration, we do two parallel encryption: \ + * - new counter value for decryption of the next block; \ + * - CBC-MAC over the next encrypted block. \ + * Each iteration performs the two AES instances related \ + * to the current block; there is thus no need for some \ + * extra pre-loop and post-loop work as in encryption. \ + */ \ + \ + mtctr(%[num_blocks]) \ + \ + label(loop) \ + /* \ + * Upon loop entry: \ + * v16 counter value for next block \ + * v17 current CBC-MAC value \ + */ \ + lxvw4x(52, %[cc], %[buf]) \ + BYTESWAP(20) \ + vxor(17, 17, 20) \ + INCR_128(22, 16) \ + BLOCK_ENCRYPT_X2_ ## size(16, 17) \ + vxor(20, 20, 16) \ + BYTESWAPX(21, 20) \ + stxvw4x(53, %[cc], %[buf]) \ + addi(%[buf], %[buf], 16) \ + vand(16, 22, 22) \ + \ + bdnz(loop) \ + \ + /* \ + * Store back counter and CBC-MAC value. \ + */ \ + BYTESWAP(16) \ + BYTESWAP(17) \ + stxvw4x(48, %[cc], %[ctr]) \ + stxvw4x(49, %[cc], %[cbcmac]) \ + \ +: [cc] "+b" (cc), [buf] "+b" (buf) \ +: [sk] "b" (sk), [ctr] "b" (ctr), [cbcmac] "b" (cbcmac), \ + [num_blocks] "b" (num_blocks), [ctrinc] "b" (ctrinc) \ + BYTESWAP_REG \ +: "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", \ + "v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17", "v18", "v19", \ + "v20", "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", \ + "v30", "ctr", "memory" \ + ); \ +} + +MKDECRYPT(128) +MKDECRYPT(192) +MKDECRYPT(256) + +/* see bearssl_block.h */ +void +br_aes_pwr8_ctrcbc_encrypt(const br_aes_pwr8_ctrcbc_keys *ctx, + void *ctr, void *cbcmac, void *data, size_t len) +{ + if (len == 0) { + return; + } + switch (ctx->num_rounds) { + case 10: + ctrcbc_128_encrypt(ctx->skey.skni, ctr, cbcmac, data, len >> 4); + break; + case 12: + ctrcbc_192_encrypt(ctx->skey.skni, ctr, cbcmac, data, len >> 4); + break; + default: + ctrcbc_256_encrypt(ctx->skey.skni, ctr, cbcmac, data, len >> 4); + break; + } +} + +/* see bearssl_block.h */ +void +br_aes_pwr8_ctrcbc_decrypt(const br_aes_pwr8_ctrcbc_keys *ctx, + void *ctr, void *cbcmac, void *data, size_t len) +{ + if (len == 0) { + return; + } + switch (ctx->num_rounds) { + case 10: + ctrcbc_128_decrypt(ctx->skey.skni, ctr, cbcmac, data, len >> 4); + break; + case 12: + ctrcbc_192_decrypt(ctx->skey.skni, ctr, cbcmac, data, len >> 4); + break; + default: + ctrcbc_256_decrypt(ctx->skey.skni, ctr, cbcmac, data, len >> 4); + break; + } +} + +static inline void +incr_ctr(void *dst, const void *src) +{ + uint64_t hi, lo; + + hi = br_dec64be(src); + lo = br_dec64be((const unsigned char *)src + 8); + lo ++; + hi += ((lo | -lo) >> 63) ^ (uint64_t)1; + br_enc64be(dst, hi); + br_enc64be((unsigned char *)dst + 8, lo); +} + +/* see bearssl_block.h */ +void +br_aes_pwr8_ctrcbc_ctr(const br_aes_pwr8_ctrcbc_keys *ctx, + void *ctr, void *data, size_t len) +{ + unsigned char ctrbuf[64]; + + memcpy(ctrbuf, ctr, 16); + incr_ctr(ctrbuf + 16, ctrbuf); + incr_ctr(ctrbuf + 32, ctrbuf + 16); + incr_ctr(ctrbuf + 48, ctrbuf + 32); + if (len >= 64) { + switch (ctx->num_rounds) { + case 10: + ctr_128(ctx->skey.skni, ctrbuf, data, len >> 6); + break; + case 12: + ctr_192(ctx->skey.skni, ctrbuf, data, len >> 6); + break; + default: + ctr_256(ctx->skey.skni, ctrbuf, data, len >> 6); + break; + } + data = (unsigned char *)data + (len & ~(size_t)63); + len &= 63; + } + if (len > 0) { + unsigned char tmp[64]; + + if (len >= 32) { + if (len >= 48) { + memcpy(ctr, ctrbuf + 48, 16); + } else { + memcpy(ctr, ctrbuf + 32, 16); + } + } else { + if (len >= 16) { + memcpy(ctr, ctrbuf + 16, 16); + } + } + memcpy(tmp, data, len); + memset(tmp + len, 0, (sizeof tmp) - len); + switch (ctx->num_rounds) { + case 10: + ctr_128(ctx->skey.skni, ctrbuf, tmp, 1); + break; + case 12: + ctr_192(ctx->skey.skni, ctrbuf, tmp, 1); + break; + default: + ctr_256(ctx->skey.skni, ctrbuf, tmp, 1); + break; + } + memcpy(data, tmp, len); + } else { + memcpy(ctr, ctrbuf, 16); + } +} + +/* see bearssl_block.h */ +void +br_aes_pwr8_ctrcbc_mac(const br_aes_pwr8_ctrcbc_keys *ctx, + void *cbcmac, const void *data, size_t len) +{ + if (len > 0) { + switch (ctx->num_rounds) { + case 10: + cbcmac_128(ctx->skey.skni, cbcmac, data, len >> 4); + break; + case 12: + cbcmac_192(ctx->skey.skni, cbcmac, data, len >> 4); + break; + default: + cbcmac_256(ctx->skey.skni, cbcmac, data, len >> 4); + break; + } + } +} + +/* see bearssl_block.h */ +const br_block_ctrcbc_class br_aes_pwr8_ctrcbc_vtable = { + sizeof(br_aes_pwr8_ctrcbc_keys), + 16, + 4, + (void (*)(const br_block_ctrcbc_class **, const void *, size_t)) + &br_aes_pwr8_ctrcbc_init, + (void (*)(const br_block_ctrcbc_class *const *, + void *, void *, void *, size_t)) + &br_aes_pwr8_ctrcbc_encrypt, + (void (*)(const br_block_ctrcbc_class *const *, + void *, void *, void *, size_t)) + &br_aes_pwr8_ctrcbc_decrypt, + (void (*)(const br_block_ctrcbc_class *const *, + void *, void *, size_t)) + &br_aes_pwr8_ctrcbc_ctr, + (void (*)(const br_block_ctrcbc_class *const *, + void *, const void *, size_t)) + &br_aes_pwr8_ctrcbc_mac +}; + +#else + +/* see bearssl_block.h */ +const br_block_ctrcbc_class * +br_aes_pwr8_ctrcbc_get_vtable(void) +{ + return NULL; +} + +#endif + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_small_cbcdec.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_small_cbcdec.c new file mode 100644 index 000000000..58f4f4531 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_small_cbcdec.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_block.h */ +void +br_aes_small_cbcdec_init(br_aes_small_cbcdec_keys *ctx, + const void *key, size_t len) +{ + ctx->vtable = &br_aes_small_cbcdec_vtable; + ctx->num_rounds = br_aes_keysched(ctx->skey, key, len); +} + +/* see bearssl_block.h */ +void +br_aes_small_cbcdec_run(const br_aes_small_cbcdec_keys *ctx, + void *iv, void *data, size_t len) +{ + unsigned char *buf, *ivbuf; + + ivbuf = iv; + buf = data; + while (len > 0) { + unsigned char tmp[16]; + int i; + + memcpy(tmp, buf, 16); + br_aes_small_decrypt(ctx->num_rounds, ctx->skey, buf); + for (i = 0; i < 16; i ++) { + buf[i] ^= ivbuf[i]; + } + memcpy(ivbuf, tmp, 16); + buf += 16; + len -= 16; + } +} + +/* see bearssl_block.h */ +const br_block_cbcdec_class br_aes_small_cbcdec_vtable = { + sizeof(br_aes_small_cbcdec_keys), + 16, + 4, + (void (*)(const br_block_cbcdec_class **, const void *, size_t)) + &br_aes_small_cbcdec_init, + (void (*)(const br_block_cbcdec_class *const *, void *, void *, size_t)) + &br_aes_small_cbcdec_run +}; + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_small_cbcenc.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_small_cbcenc.c new file mode 100644 index 000000000..d8e74dc1b --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_small_cbcenc.c @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_block.h */ +void +br_aes_small_cbcenc_init(br_aes_small_cbcenc_keys *ctx, + const void *key, size_t len) +{ + ctx->vtable = &br_aes_small_cbcenc_vtable; + ctx->num_rounds = br_aes_keysched(ctx->skey, key, len); +} + +/* see bearssl_block.h */ +void +br_aes_small_cbcenc_run(const br_aes_small_cbcenc_keys *ctx, + void *iv, void *data, size_t len) +{ + unsigned char *buf, *ivbuf; + + ivbuf = iv; + buf = data; + while (len > 0) { + int i; + + for (i = 0; i < 16; i ++) { + buf[i] ^= ivbuf[i]; + } + br_aes_small_encrypt(ctx->num_rounds, ctx->skey, buf); + memcpy(ivbuf, buf, 16); + buf += 16; + len -= 16; + } +} + +/* see bearssl_block.h */ +const br_block_cbcenc_class br_aes_small_cbcenc_vtable = { + sizeof(br_aes_small_cbcenc_keys), + 16, + 4, + (void (*)(const br_block_cbcenc_class **, const void *, size_t)) + &br_aes_small_cbcenc_init, + (void (*)(const br_block_cbcenc_class *const *, void *, void *, size_t)) + &br_aes_small_cbcenc_run +}; + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_small_ctr.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_small_ctr.c new file mode 100644 index 000000000..b79e04f54 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_small_ctr.c @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_block.h */ +void +br_aes_small_ctr_init(br_aes_small_ctr_keys *ctx, + const void *key, size_t len) +{ + ctx->vtable = &br_aes_small_ctr_vtable; + ctx->num_rounds = br_aes_keysched(ctx->skey, key, len); +} + +static void +xorbuf(void *dst, const void *src, size_t len) +{ + unsigned char *d; + const unsigned char *s; + + d = dst; + s = src; + while (len -- > 0) { + *d ++ ^= *s ++; + } +} + +/* see bearssl_block.h */ +uint32_t +br_aes_small_ctr_run(const br_aes_small_ctr_keys *ctx, + const void *iv, uint32_t cc, void *data, size_t len) +{ + unsigned char *buf; + + buf = data; + while (len > 0) { + unsigned char tmp[16]; + + memcpy(tmp, iv, 12); + br_enc32be(tmp + 12, cc ++); + br_aes_small_encrypt(ctx->num_rounds, ctx->skey, tmp); + if (len <= 16) { + xorbuf(buf, tmp, len); + break; + } + xorbuf(buf, tmp, 16); + buf += 16; + len -= 16; + } + return cc; +} + +/* see bearssl_block.h */ +const br_block_ctr_class br_aes_small_ctr_vtable = { + sizeof(br_aes_small_ctr_keys), + 16, + 4, + (void (*)(const br_block_ctr_class **, const void *, size_t)) + &br_aes_small_ctr_init, + (uint32_t (*)(const br_block_ctr_class *const *, + const void *, uint32_t, void *, size_t)) + &br_aes_small_ctr_run +}; + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_small_ctrcbc.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_small_ctrcbc.c new file mode 100644 index 000000000..a75d2af6e --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_small_ctrcbc.c @@ -0,0 +1,147 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_block.h */ +void +br_aes_small_ctrcbc_init(br_aes_small_ctrcbc_keys *ctx, + const void *key, size_t len) +{ + ctx->vtable = &br_aes_small_ctrcbc_vtable; + ctx->num_rounds = br_aes_keysched(ctx->skey, key, len); +} + +static void +xorbuf(void *dst, const void *src, size_t len) +{ + unsigned char *d; + const unsigned char *s; + + d = dst; + s = src; + while (len -- > 0) { + *d ++ ^= *s ++; + } +} + +/* see bearssl_block.h */ +void +br_aes_small_ctrcbc_ctr(const br_aes_small_ctrcbc_keys *ctx, + void *ctr, void *data, size_t len) +{ + unsigned char *buf, *bctr; + uint32_t cc0, cc1, cc2, cc3; + + buf = data; + bctr = ctr; + cc3 = br_dec32be(bctr + 0); + cc2 = br_dec32be(bctr + 4); + cc1 = br_dec32be(bctr + 8); + cc0 = br_dec32be(bctr + 12); + while (len > 0) { + unsigned char tmp[16]; + uint32_t carry; + + br_enc32be(tmp + 0, cc3); + br_enc32be(tmp + 4, cc2); + br_enc32be(tmp + 8, cc1); + br_enc32be(tmp + 12, cc0); + br_aes_small_encrypt(ctx->num_rounds, ctx->skey, tmp); + xorbuf(buf, tmp, 16); + buf += 16; + len -= 16; + cc0 ++; + carry = (~(cc0 | -cc0)) >> 31; + cc1 += carry; + carry &= (~(cc1 | -cc1)) >> 31; + cc2 += carry; + carry &= (~(cc2 | -cc2)) >> 31; + cc3 += carry; + } + br_enc32be(bctr + 0, cc3); + br_enc32be(bctr + 4, cc2); + br_enc32be(bctr + 8, cc1); + br_enc32be(bctr + 12, cc0); +} + +/* see bearssl_block.h */ +void +br_aes_small_ctrcbc_mac(const br_aes_small_ctrcbc_keys *ctx, + void *cbcmac, const void *data, size_t len) +{ + const unsigned char *buf; + + buf = data; + while (len > 0) { + xorbuf(cbcmac, buf, 16); + br_aes_small_encrypt(ctx->num_rounds, ctx->skey, cbcmac); + buf += 16; + len -= 16; + } +} + +/* see bearssl_block.h */ +void +br_aes_small_ctrcbc_encrypt(const br_aes_small_ctrcbc_keys *ctx, + void *ctr, void *cbcmac, void *data, size_t len) +{ + br_aes_small_ctrcbc_ctr(ctx, ctr, data, len); + br_aes_small_ctrcbc_mac(ctx, cbcmac, data, len); +} + +/* see bearssl_block.h */ +void +br_aes_small_ctrcbc_decrypt(const br_aes_small_ctrcbc_keys *ctx, + void *ctr, void *cbcmac, void *data, size_t len) +{ + br_aes_small_ctrcbc_mac(ctx, cbcmac, data, len); + br_aes_small_ctrcbc_ctr(ctx, ctr, data, len); +} + +/* see bearssl_block.h */ +const br_block_ctrcbc_class br_aes_small_ctrcbc_vtable = { + sizeof(br_aes_small_ctrcbc_keys), + 16, + 4, + (void (*)(const br_block_ctrcbc_class **, const void *, size_t)) + &br_aes_small_ctrcbc_init, + (void (*)(const br_block_ctrcbc_class *const *, + void *, void *, void *, size_t)) + &br_aes_small_ctrcbc_encrypt, + (void (*)(const br_block_ctrcbc_class *const *, + void *, void *, void *, size_t)) + &br_aes_small_ctrcbc_decrypt, + (void (*)(const br_block_ctrcbc_class *const *, + void *, void *, size_t)) + &br_aes_small_ctrcbc_ctr, + (void (*)(const br_block_ctrcbc_class *const *, + void *, const void *, size_t)) + &br_aes_small_ctrcbc_mac +}; + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_small_dec.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_small_dec.c new file mode 100644 index 000000000..980045744 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_small_dec.c @@ -0,0 +1,181 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* + * Inverse S-box. + */ +static const unsigned char iS[] = { + 0x52, 0x09, 0x6A, 0xD5, 0x30, 0x36, 0xA5, 0x38, 0xBF, 0x40, 0xA3, 0x9E, + 0x81, 0xF3, 0xD7, 0xFB, 0x7C, 0xE3, 0x39, 0x82, 0x9B, 0x2F, 0xFF, 0x87, + 0x34, 0x8E, 0x43, 0x44, 0xC4, 0xDE, 0xE9, 0xCB, 0x54, 0x7B, 0x94, 0x32, + 0xA6, 0xC2, 0x23, 0x3D, 0xEE, 0x4C, 0x95, 0x0B, 0x42, 0xFA, 0xC3, 0x4E, + 0x08, 0x2E, 0xA1, 0x66, 0x28, 0xD9, 0x24, 0xB2, 0x76, 0x5B, 0xA2, 0x49, + 0x6D, 0x8B, 0xD1, 0x25, 0x72, 0xF8, 0xF6, 0x64, 0x86, 0x68, 0x98, 0x16, +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x63, + 0x55, 0x21, 0x0C, 0x7D +}; + +static void +add_round_key(unsigned *state, const uint32_t *skeys) +{ + int i; + + for (i = 0; i < 16; i += 4) { + uint32_t k; + + k = *skeys ++; + state[i + 0] ^= (unsigned)(k >> 24); + state[i + 1] ^= (unsigned)(k >> 16) & 0xFF; + state[i + 2] ^= (unsigned)(k >> 8) & 0xFF; + state[i + 3] ^= (unsigned)k & 0xFF; + } +} + +static void +inv_sub_bytes(unsigned *state) +{ + int i; + + for (i = 0; i < 16; i ++) { + state[i] = iS[state[i]]; + } +} + +static void +inv_shift_rows(unsigned *state) +{ + unsigned tmp; + + tmp = state[13]; + state[13] = state[9]; + state[9] = state[5]; + state[5] = state[1]; + state[1] = tmp; + + tmp = state[2]; + state[2] = state[10]; + state[10] = tmp; + tmp = state[6]; + state[6] = state[14]; + state[14] = tmp; + + tmp = state[3]; + state[3] = state[7]; + state[7] = state[11]; + state[11] = state[15]; + state[15] = tmp; +} + +static inline unsigned +gf256red(unsigned x) +{ + unsigned y; + + y = x >> 8; + return (x ^ y ^ (y << 1) ^ (y << 3) ^ (y << 4)) & 0xFF; +} + +static void +inv_mix_columns(unsigned *state) +{ + int i; + + for (i = 0; i < 16; i += 4) { + unsigned s0, s1, s2, s3; + unsigned t0, t1, t2, t3; + + s0 = state[i + 0]; + s1 = state[i + 1]; + s2 = state[i + 2]; + s3 = state[i + 3]; + t0 = (s0 << 1) ^ (s0 << 2) ^ (s0 << 3) + ^ s1 ^ (s1 << 1) ^ (s1 << 3) + ^ s2 ^ (s2 << 2) ^ (s2 << 3) + ^ s3 ^ (s3 << 3); + t1 = s0 ^ (s0 << 3) + ^ (s1 << 1) ^ (s1 << 2) ^ (s1 << 3) + ^ s2 ^ (s2 << 1) ^ (s2 << 3) + ^ s3 ^ (s3 << 2) ^ (s3 << 3); + t2 = s0 ^ (s0 << 2) ^ (s0 << 3) + ^ s1 ^ (s1 << 3) + ^ (s2 << 1) ^ (s2 << 2) ^ (s2 << 3) + ^ s3 ^ (s3 << 1) ^ (s3 << 3); + t3 = s0 ^ (s0 << 1) ^ (s0 << 3) + ^ s1 ^ (s1 << 2) ^ (s1 << 3) + ^ s2 ^ (s2 << 3) + ^ (s3 << 1) ^ (s3 << 2) ^ (s3 << 3); + state[i + 0] = gf256red(t0); + state[i + 1] = gf256red(t1); + state[i + 2] = gf256red(t2); + state[i + 3] = gf256red(t3); + } +} + +/* see inner.h */ +void +br_aes_small_decrypt(unsigned num_rounds, const uint32_t *skey, void *data) +{ + unsigned char *buf; + unsigned state[16]; + unsigned u; + + buf = data; + for (u = 0; u < 16; u ++) { + state[u] = buf[u]; + } + add_round_key(state, skey + (num_rounds << 2)); + for (u = num_rounds - 1; u > 0; u --) { + inv_shift_rows(state); + inv_sub_bytes(state); + add_round_key(state, skey + (u << 2)); + inv_mix_columns(state); + } + inv_shift_rows(state); + inv_sub_bytes(state); + add_round_key(state, skey); + for (u = 0; u < 16; u ++) { + buf[u] = state[u]; + } +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_small_enc.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_small_enc.c new file mode 100644 index 000000000..3769c07ed --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_small_enc.c @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +#define S br_aes_S + +static void +add_round_key(unsigned *state, const uint32_t *skeys) +{ + int i; + + for (i = 0; i < 16; i += 4) { + uint32_t k; + + k = *skeys ++; + state[i + 0] ^= (unsigned)(k >> 24); + state[i + 1] ^= (unsigned)(k >> 16) & 0xFF; + state[i + 2] ^= (unsigned)(k >> 8) & 0xFF; + state[i + 3] ^= (unsigned)k & 0xFF; + } +} + +static void +sub_bytes(unsigned *state) +{ + int i; + + for (i = 0; i < 16; i ++) { + state[i] = S[state[i]]; + } +} + +static void +shift_rows(unsigned *state) +{ + unsigned tmp; + + tmp = state[1]; + state[1] = state[5]; + state[5] = state[9]; + state[9] = state[13]; + state[13] = tmp; + + tmp = state[2]; + state[2] = state[10]; + state[10] = tmp; + tmp = state[6]; + state[6] = state[14]; + state[14] = tmp; + + tmp = state[15]; + state[15] = state[11]; + state[11] = state[7]; + state[7] = state[3]; + state[3] = tmp; +} + +static void +mix_columns(unsigned *state) +{ + int i; + + for (i = 0; i < 16; i += 4) { + unsigned s0, s1, s2, s3; + unsigned t0, t1, t2, t3; + + s0 = state[i + 0]; + s1 = state[i + 1]; + s2 = state[i + 2]; + s3 = state[i + 3]; + t0 = (s0 << 1) ^ s1 ^ (s1 << 1) ^ s2 ^ s3; + t1 = s0 ^ (s1 << 1) ^ s2 ^ (s2 << 1) ^ s3; + t2 = s0 ^ s1 ^ (s2 << 1) ^ s3 ^ (s3 << 1); + t3 = s0 ^ (s0 << 1) ^ s1 ^ s2 ^ (s3 << 1); + state[i + 0] = t0 ^ ((unsigned)(-(int)(t0 >> 8)) & 0x11B); + state[i + 1] = t1 ^ ((unsigned)(-(int)(t1 >> 8)) & 0x11B); + state[i + 2] = t2 ^ ((unsigned)(-(int)(t2 >> 8)) & 0x11B); + state[i + 3] = t3 ^ ((unsigned)(-(int)(t3 >> 8)) & 0x11B); + } +} + +/* see inner.h */ +void +br_aes_small_encrypt(unsigned num_rounds, const uint32_t *skey, void *data) +{ + unsigned char *buf; + unsigned state[16]; + unsigned u; + + buf = data; + for (u = 0; u < 16; u ++) { + state[u] = buf[u]; + } + add_round_key(state, skey); + for (u = 1; u < num_rounds; u ++) { + sub_bytes(state); + shift_rows(state); + mix_columns(state); + add_round_key(state, skey + (u << 2)); + } + sub_bytes(state); + shift_rows(state); + add_round_key(state, skey + (num_rounds << 2)); + for (u = 0; u < 16; u ++) { + buf[u] = state[u]; + } +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_x86ni.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_x86ni.c new file mode 100644 index 000000000..c851657db --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_x86ni.c @@ -0,0 +1,245 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#define BR_ENABLE_INTRINSICS 1 +#include "inner.h" + +/* + * This code contains the AES key schedule implementation using the + * AES-NI opcodes. + */ + +#if BR_AES_X86NI + +/* see inner.h */ +int +br_aes_x86ni_supported(void) +{ + /* + * Bit mask for features in ECX: + * 19 SSE4.1 (used for _mm_insert_epi32(), for AES-CTR) + * 25 AES-NI + */ + return br_cpuid(0, 0, 0x02080000, 0); +} + +BR_TARGETS_X86_UP + +BR_TARGET("sse2,aes") +static inline __m128i +expand_step128(__m128i k, __m128i k2) +{ + k = _mm_xor_si128(k, _mm_slli_si128(k, 4)); + k = _mm_xor_si128(k, _mm_slli_si128(k, 4)); + k = _mm_xor_si128(k, _mm_slli_si128(k, 4)); + k2 = _mm_shuffle_epi32(k2, 0xFF); + return _mm_xor_si128(k, k2); +} + +BR_TARGET("sse2,aes") +static inline void +expand_step192(__m128i *t1, __m128i *t2, __m128i *t3) +{ + __m128i t4; + + *t2 = _mm_shuffle_epi32(*t2, 0x55); + t4 = _mm_slli_si128(*t1, 0x4); + *t1 = _mm_xor_si128(*t1, t4); + t4 = _mm_slli_si128(t4, 0x4); + *t1 = _mm_xor_si128(*t1, t4); + t4 = _mm_slli_si128(t4, 0x4); + *t1 = _mm_xor_si128(*t1, t4); + *t1 = _mm_xor_si128(*t1, *t2); + *t2 = _mm_shuffle_epi32(*t1, 0xFF); + t4 = _mm_slli_si128(*t3, 0x4); + *t3 = _mm_xor_si128(*t3, t4); + *t3 = _mm_xor_si128(*t3, *t2); +} + +BR_TARGET("sse2,aes") +static inline void +expand_step256_1(__m128i *t1, __m128i *t2) +{ + __m128i t4; + + *t2 = _mm_shuffle_epi32(*t2, 0xFF); + t4 = _mm_slli_si128(*t1, 0x4); + *t1 = _mm_xor_si128(*t1, t4); + t4 = _mm_slli_si128(t4, 0x4); + *t1 = _mm_xor_si128(*t1, t4); + t4 = _mm_slli_si128(t4, 0x4); + *t1 = _mm_xor_si128(*t1, t4); + *t1 = _mm_xor_si128(*t1, *t2); +} + +BR_TARGET("sse2,aes") +static inline void +expand_step256_2(__m128i *t1, __m128i *t3) +{ + __m128i t2, t4; + + t4 = _mm_aeskeygenassist_si128(*t1, 0x0); + t2 = _mm_shuffle_epi32(t4, 0xAA); + t4 = _mm_slli_si128(*t3, 0x4); + *t3 = _mm_xor_si128(*t3, t4); + t4 = _mm_slli_si128(t4, 0x4); + *t3 = _mm_xor_si128(*t3, t4); + t4 = _mm_slli_si128(t4, 0x4); + *t3 = _mm_xor_si128(*t3, t4); + *t3 = _mm_xor_si128(*t3, t2); +} + +/* + * Perform key schedule for AES, encryption direction. Subkeys are written + * in sk[], and the number of rounds is returned. Key length MUST be 16, + * 24 or 32 bytes. + */ +BR_TARGET("sse2,aes") +static unsigned +x86ni_keysched(__m128i *sk, const void *key, size_t len) +{ + const unsigned char *kb; + +#define KEXP128(k, i, rcon) do { \ + k = expand_step128(k, _mm_aeskeygenassist_si128(k, rcon)); \ + sk[i] = k; \ + } while (0) + +#define KEXP192(i, rcon1, rcon2) do { \ + sk[(i) + 0] = t1; \ + sk[(i) + 1] = t3; \ + t2 = _mm_aeskeygenassist_si128(t3, rcon1); \ + expand_step192(&t1, &t2, &t3); \ + sk[(i) + 1] = _mm_castpd_si128(_mm_shuffle_pd( \ + _mm_castsi128_pd(sk[(i) + 1]), \ + _mm_castsi128_pd(t1), 0)); \ + sk[(i) + 2] = _mm_castpd_si128(_mm_shuffle_pd( \ + _mm_castsi128_pd(t1), \ + _mm_castsi128_pd(t3), 1)); \ + t2 = _mm_aeskeygenassist_si128(t3, rcon2); \ + expand_step192(&t1, &t2, &t3); \ + } while (0) + +#define KEXP256(i, rcon) do { \ + sk[(i) + 0] = t3; \ + t2 = _mm_aeskeygenassist_si128(t3, rcon); \ + expand_step256_1(&t1, &t2); \ + sk[(i) + 1] = t1; \ + expand_step256_2(&t1, &t3); \ + } while (0) + + kb = key; + switch (len) { + __m128i t1, t2, t3; + + case 16: + t1 = _mm_loadu_si128((const void *)kb); + sk[0] = t1; + KEXP128(t1, 1, 0x01); + KEXP128(t1, 2, 0x02); + KEXP128(t1, 3, 0x04); + KEXP128(t1, 4, 0x08); + KEXP128(t1, 5, 0x10); + KEXP128(t1, 6, 0x20); + KEXP128(t1, 7, 0x40); + KEXP128(t1, 8, 0x80); + KEXP128(t1, 9, 0x1B); + KEXP128(t1, 10, 0x36); + return 10; + + case 24: + t1 = _mm_loadu_si128((const void *)kb); + t3 = _mm_loadu_si128((const void *)(kb + 8)); + t3 = _mm_shuffle_epi32(t3, 0x4E); + KEXP192(0, 0x01, 0x02); + KEXP192(3, 0x04, 0x08); + KEXP192(6, 0x10, 0x20); + KEXP192(9, 0x40, 0x80); + sk[12] = t1; + return 12; + + case 32: + t1 = _mm_loadu_si128((const void *)kb); + t3 = _mm_loadu_si128((const void *)(kb + 16)); + sk[0] = t1; + KEXP256( 1, 0x01); + KEXP256( 3, 0x02); + KEXP256( 5, 0x04); + KEXP256( 7, 0x08); + KEXP256( 9, 0x10); + KEXP256(11, 0x20); + sk[13] = t3; + t2 = _mm_aeskeygenassist_si128(t3, 0x40); + expand_step256_1(&t1, &t2); + sk[14] = t1; + return 14; + + default: + return 0; + } + +#undef KEXP128 +#undef KEXP192 +#undef KEXP256 +} + +/* see inner.h */ +BR_TARGET("sse2,aes") +unsigned +br_aes_x86ni_keysched_enc(unsigned char *skni, const void *key, size_t len) +{ + __m128i sk[15]; + unsigned num_rounds; + + num_rounds = x86ni_keysched(sk, key, len); + memcpy(skni, sk, (num_rounds + 1) << 4); + return num_rounds; +} + +/* see inner.h */ +BR_TARGET("sse2,aes") +unsigned +br_aes_x86ni_keysched_dec(unsigned char *skni, const void *key, size_t len) +{ + __m128i sk[15]; + unsigned u, num_rounds; + + num_rounds = x86ni_keysched(sk, key, len); + _mm_storeu_si128((void *)skni, sk[num_rounds]); + for (u = 1; u < num_rounds; u ++) { + _mm_storeu_si128((void *)(skni + (u << 4)), + _mm_aesimc_si128(sk[num_rounds - u])); + } + _mm_storeu_si128((void *)(skni + (num_rounds << 4)), sk[0]); + return num_rounds; +} + +BR_TARGETS_X86_DOWN + +#endif + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_x86ni_cbcdec.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_x86ni_cbcdec.c new file mode 100644 index 000000000..a257dd872 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_x86ni_cbcdec.c @@ -0,0 +1,228 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#define BR_ENABLE_INTRINSICS 1 +#include "inner.h" + +#if BR_AES_X86NI + +/* see bearssl_block.h */ +const br_block_cbcdec_class * +br_aes_x86ni_cbcdec_get_vtable(void) +{ + return br_aes_x86ni_supported() ? &br_aes_x86ni_cbcdec_vtable : NULL; +} + +/* see bearssl_block.h */ +void +br_aes_x86ni_cbcdec_init(br_aes_x86ni_cbcdec_keys *ctx, + const void *key, size_t len) +{ + ctx->vtable = &br_aes_x86ni_cbcdec_vtable; + ctx->num_rounds = br_aes_x86ni_keysched_dec(ctx->skey.skni, key, len); +} + +BR_TARGETS_X86_UP + +/* see bearssl_block.h */ +BR_TARGET("sse2,aes") +void +br_aes_x86ni_cbcdec_run(const br_aes_x86ni_cbcdec_keys *ctx, + void *iv, void *data, size_t len) +{ + unsigned char *buf; + unsigned num_rounds; + __m128i sk[15], ivx; + unsigned u; + + buf = data; + ivx = _mm_loadu_si128(iv); + num_rounds = ctx->num_rounds; + for (u = 0; u <= num_rounds; u ++) { + sk[u] = _mm_loadu_si128((void *)(ctx->skey.skni + (u << 4))); + } + while (len > 0) { + __m128i x0, x1, x2, x3, e0, e1, e2, e3; + + x0 = _mm_loadu_si128((void *)(buf + 0)); + if (len >= 64) { + x1 = _mm_loadu_si128((void *)(buf + 16)); + x2 = _mm_loadu_si128((void *)(buf + 32)); + x3 = _mm_loadu_si128((void *)(buf + 48)); + } else { + x0 = _mm_loadu_si128((void *)(buf + 0)); + if (len >= 32) { + x1 = _mm_loadu_si128((void *)(buf + 16)); + if (len >= 48) { + x2 = _mm_loadu_si128( + (void *)(buf + 32)); + x3 = x2; + } else { + x2 = x0; + x3 = x1; + } + } else { + x1 = x0; + x2 = x0; + x3 = x0; + } + } + e0 = x0; + e1 = x1; + e2 = x2; + e3 = x3; + x0 = _mm_xor_si128(x0, sk[0]); + x1 = _mm_xor_si128(x1, sk[0]); + x2 = _mm_xor_si128(x2, sk[0]); + x3 = _mm_xor_si128(x3, sk[0]); + x0 = _mm_aesdec_si128(x0, sk[1]); + x1 = _mm_aesdec_si128(x1, sk[1]); + x2 = _mm_aesdec_si128(x2, sk[1]); + x3 = _mm_aesdec_si128(x3, sk[1]); + x0 = _mm_aesdec_si128(x0, sk[2]); + x1 = _mm_aesdec_si128(x1, sk[2]); + x2 = _mm_aesdec_si128(x2, sk[2]); + x3 = _mm_aesdec_si128(x3, sk[2]); + x0 = _mm_aesdec_si128(x0, sk[3]); + x1 = _mm_aesdec_si128(x1, sk[3]); + x2 = _mm_aesdec_si128(x2, sk[3]); + x3 = _mm_aesdec_si128(x3, sk[3]); + x0 = _mm_aesdec_si128(x0, sk[4]); + x1 = _mm_aesdec_si128(x1, sk[4]); + x2 = _mm_aesdec_si128(x2, sk[4]); + x3 = _mm_aesdec_si128(x3, sk[4]); + x0 = _mm_aesdec_si128(x0, sk[5]); + x1 = _mm_aesdec_si128(x1, sk[5]); + x2 = _mm_aesdec_si128(x2, sk[5]); + x3 = _mm_aesdec_si128(x3, sk[5]); + x0 = _mm_aesdec_si128(x0, sk[6]); + x1 = _mm_aesdec_si128(x1, sk[6]); + x2 = _mm_aesdec_si128(x2, sk[6]); + x3 = _mm_aesdec_si128(x3, sk[6]); + x0 = _mm_aesdec_si128(x0, sk[7]); + x1 = _mm_aesdec_si128(x1, sk[7]); + x2 = _mm_aesdec_si128(x2, sk[7]); + x3 = _mm_aesdec_si128(x3, sk[7]); + x0 = _mm_aesdec_si128(x0, sk[8]); + x1 = _mm_aesdec_si128(x1, sk[8]); + x2 = _mm_aesdec_si128(x2, sk[8]); + x3 = _mm_aesdec_si128(x3, sk[8]); + x0 = _mm_aesdec_si128(x0, sk[9]); + x1 = _mm_aesdec_si128(x1, sk[9]); + x2 = _mm_aesdec_si128(x2, sk[9]); + x3 = _mm_aesdec_si128(x3, sk[9]); + if (num_rounds == 10) { + x0 = _mm_aesdeclast_si128(x0, sk[10]); + x1 = _mm_aesdeclast_si128(x1, sk[10]); + x2 = _mm_aesdeclast_si128(x2, sk[10]); + x3 = _mm_aesdeclast_si128(x3, sk[10]); + } else if (num_rounds == 12) { + x0 = _mm_aesdec_si128(x0, sk[10]); + x1 = _mm_aesdec_si128(x1, sk[10]); + x2 = _mm_aesdec_si128(x2, sk[10]); + x3 = _mm_aesdec_si128(x3, sk[10]); + x0 = _mm_aesdec_si128(x0, sk[11]); + x1 = _mm_aesdec_si128(x1, sk[11]); + x2 = _mm_aesdec_si128(x2, sk[11]); + x3 = _mm_aesdec_si128(x3, sk[11]); + x0 = _mm_aesdeclast_si128(x0, sk[12]); + x1 = _mm_aesdeclast_si128(x1, sk[12]); + x2 = _mm_aesdeclast_si128(x2, sk[12]); + x3 = _mm_aesdeclast_si128(x3, sk[12]); + } else { + x0 = _mm_aesdec_si128(x0, sk[10]); + x1 = _mm_aesdec_si128(x1, sk[10]); + x2 = _mm_aesdec_si128(x2, sk[10]); + x3 = _mm_aesdec_si128(x3, sk[10]); + x0 = _mm_aesdec_si128(x0, sk[11]); + x1 = _mm_aesdec_si128(x1, sk[11]); + x2 = _mm_aesdec_si128(x2, sk[11]); + x3 = _mm_aesdec_si128(x3, sk[11]); + x0 = _mm_aesdec_si128(x0, sk[12]); + x1 = _mm_aesdec_si128(x1, sk[12]); + x2 = _mm_aesdec_si128(x2, sk[12]); + x3 = _mm_aesdec_si128(x3, sk[12]); + x0 = _mm_aesdec_si128(x0, sk[13]); + x1 = _mm_aesdec_si128(x1, sk[13]); + x2 = _mm_aesdec_si128(x2, sk[13]); + x3 = _mm_aesdec_si128(x3, sk[13]); + x0 = _mm_aesdeclast_si128(x0, sk[14]); + x1 = _mm_aesdeclast_si128(x1, sk[14]); + x2 = _mm_aesdeclast_si128(x2, sk[14]); + x3 = _mm_aesdeclast_si128(x3, sk[14]); + } + x0 = _mm_xor_si128(x0, ivx); + x1 = _mm_xor_si128(x1, e0); + x2 = _mm_xor_si128(x2, e1); + x3 = _mm_xor_si128(x3, e2); + ivx = e3; + _mm_storeu_si128((void *)(buf + 0), x0); + if (len >= 64) { + _mm_storeu_si128((void *)(buf + 16), x1); + _mm_storeu_si128((void *)(buf + 32), x2); + _mm_storeu_si128((void *)(buf + 48), x3); + buf += 64; + len -= 64; + } else { + if (len >= 32) { + _mm_storeu_si128((void *)(buf + 16), x1); + if (len >= 48) { + _mm_storeu_si128( + (void *)(buf + 32), x2); + } + } + break; + } + } + _mm_storeu_si128(iv, ivx); +} + +BR_TARGETS_X86_DOWN + +/* see bearssl_block.h */ +const br_block_cbcdec_class br_aes_x86ni_cbcdec_vtable = { + sizeof(br_aes_x86ni_cbcdec_keys), + 16, + 4, + (void (*)(const br_block_cbcdec_class **, const void *, size_t)) + &br_aes_x86ni_cbcdec_init, + (void (*)(const br_block_cbcdec_class *const *, void *, void *, size_t)) + &br_aes_x86ni_cbcdec_run +}; + +#else + +/* see bearssl_block.h */ +const br_block_cbcdec_class * +br_aes_x86ni_cbcdec_get_vtable(void) +{ + return NULL; +} + +#endif + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_x86ni_cbcenc.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_x86ni_cbcenc.c new file mode 100644 index 000000000..93e72d6e2 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_x86ni_cbcenc.c @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#define BR_ENABLE_INTRINSICS 1 +#include "inner.h" + +#if BR_AES_X86NI + +/* see bearssl_block.h */ +const br_block_cbcenc_class * +br_aes_x86ni_cbcenc_get_vtable(void) +{ + return br_aes_x86ni_supported() ? &br_aes_x86ni_cbcenc_vtable : NULL; +} + +/* see bearssl_block.h */ +void +br_aes_x86ni_cbcenc_init(br_aes_x86ni_cbcenc_keys *ctx, + const void *key, size_t len) +{ + ctx->vtable = &br_aes_x86ni_cbcenc_vtable; + ctx->num_rounds = br_aes_x86ni_keysched_enc(ctx->skey.skni, key, len); +} + +BR_TARGETS_X86_UP + +/* see bearssl_block.h */ +BR_TARGET("sse2,aes") +void +br_aes_x86ni_cbcenc_run(const br_aes_x86ni_cbcenc_keys *ctx, + void *iv, void *data, size_t len) +{ + unsigned char *buf; + unsigned num_rounds; + __m128i sk[15], ivx; + unsigned u; + + buf = data; + ivx = _mm_loadu_si128(iv); + num_rounds = ctx->num_rounds; + for (u = 0; u <= num_rounds; u ++) { + sk[u] = _mm_loadu_si128((void *)(ctx->skey.skni + (u << 4))); + } + while (len > 0) { + __m128i x; + + x = _mm_xor_si128(_mm_loadu_si128((void *)buf), ivx); + x = _mm_xor_si128(x, sk[0]); + x = _mm_aesenc_si128(x, sk[1]); + x = _mm_aesenc_si128(x, sk[2]); + x = _mm_aesenc_si128(x, sk[3]); + x = _mm_aesenc_si128(x, sk[4]); + x = _mm_aesenc_si128(x, sk[5]); + x = _mm_aesenc_si128(x, sk[6]); + x = _mm_aesenc_si128(x, sk[7]); + x = _mm_aesenc_si128(x, sk[8]); + x = _mm_aesenc_si128(x, sk[9]); + if (num_rounds == 10) { + x = _mm_aesenclast_si128(x, sk[10]); + } else if (num_rounds == 12) { + x = _mm_aesenc_si128(x, sk[10]); + x = _mm_aesenc_si128(x, sk[11]); + x = _mm_aesenclast_si128(x, sk[12]); + } else { + x = _mm_aesenc_si128(x, sk[10]); + x = _mm_aesenc_si128(x, sk[11]); + x = _mm_aesenc_si128(x, sk[12]); + x = _mm_aesenc_si128(x, sk[13]); + x = _mm_aesenclast_si128(x, sk[14]); + } + ivx = x; + _mm_storeu_si128((void *)buf, x); + buf += 16; + len -= 16; + } + _mm_storeu_si128(iv, ivx); +} + +BR_TARGETS_X86_DOWN + +/* see bearssl_block.h */ +const br_block_cbcenc_class br_aes_x86ni_cbcenc_vtable = { + sizeof(br_aes_x86ni_cbcenc_keys), + 16, + 4, + (void (*)(const br_block_cbcenc_class **, const void *, size_t)) + &br_aes_x86ni_cbcenc_init, + (void (*)(const br_block_cbcenc_class *const *, void *, void *, size_t)) + &br_aes_x86ni_cbcenc_run +}; + +#else + +/* see bearssl_block.h */ +const br_block_cbcenc_class * +br_aes_x86ni_cbcenc_get_vtable(void) +{ + return NULL; +} + +#endif + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_x86ni_ctr.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_x86ni_ctr.c new file mode 100644 index 000000000..4a4ad1d58 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_x86ni_ctr.c @@ -0,0 +1,216 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#define BR_ENABLE_INTRINSICS 1 +#include "inner.h" + +#if BR_AES_X86NI + +/* see bearssl_block.h */ +const br_block_ctr_class * +br_aes_x86ni_ctr_get_vtable(void) +{ + return br_aes_x86ni_supported() ? &br_aes_x86ni_ctr_vtable : NULL; +} + +/* see bearssl_block.h */ +void +br_aes_x86ni_ctr_init(br_aes_x86ni_ctr_keys *ctx, + const void *key, size_t len) +{ + ctx->vtable = &br_aes_x86ni_ctr_vtable; + ctx->num_rounds = br_aes_x86ni_keysched_enc(ctx->skey.skni, key, len); +} + +BR_TARGETS_X86_UP + +/* see bearssl_block.h */ +BR_TARGET("sse2,sse4.1,aes") +uint32_t +br_aes_x86ni_ctr_run(const br_aes_x86ni_ctr_keys *ctx, + const void *iv, uint32_t cc, void *data, size_t len) +{ + unsigned char *buf; + unsigned char ivbuf[16]; + unsigned num_rounds; + __m128i sk[15]; + __m128i ivx; + unsigned u; + + buf = data; + memcpy(ivbuf, iv, 12); + num_rounds = ctx->num_rounds; + for (u = 0; u <= num_rounds; u ++) { + sk[u] = _mm_loadu_si128((void *)(ctx->skey.skni + (u << 4))); + } + ivx = _mm_loadu_si128((void *)ivbuf); + while (len > 0) { + __m128i x0, x1, x2, x3; + + x0 = _mm_insert_epi32(ivx, br_bswap32(cc + 0), 3); + x1 = _mm_insert_epi32(ivx, br_bswap32(cc + 1), 3); + x2 = _mm_insert_epi32(ivx, br_bswap32(cc + 2), 3); + x3 = _mm_insert_epi32(ivx, br_bswap32(cc + 3), 3); + x0 = _mm_xor_si128(x0, sk[0]); + x1 = _mm_xor_si128(x1, sk[0]); + x2 = _mm_xor_si128(x2, sk[0]); + x3 = _mm_xor_si128(x3, sk[0]); + x0 = _mm_aesenc_si128(x0, sk[1]); + x1 = _mm_aesenc_si128(x1, sk[1]); + x2 = _mm_aesenc_si128(x2, sk[1]); + x3 = _mm_aesenc_si128(x3, sk[1]); + x0 = _mm_aesenc_si128(x0, sk[2]); + x1 = _mm_aesenc_si128(x1, sk[2]); + x2 = _mm_aesenc_si128(x2, sk[2]); + x3 = _mm_aesenc_si128(x3, sk[2]); + x0 = _mm_aesenc_si128(x0, sk[3]); + x1 = _mm_aesenc_si128(x1, sk[3]); + x2 = _mm_aesenc_si128(x2, sk[3]); + x3 = _mm_aesenc_si128(x3, sk[3]); + x0 = _mm_aesenc_si128(x0, sk[4]); + x1 = _mm_aesenc_si128(x1, sk[4]); + x2 = _mm_aesenc_si128(x2, sk[4]); + x3 = _mm_aesenc_si128(x3, sk[4]); + x0 = _mm_aesenc_si128(x0, sk[5]); + x1 = _mm_aesenc_si128(x1, sk[5]); + x2 = _mm_aesenc_si128(x2, sk[5]); + x3 = _mm_aesenc_si128(x3, sk[5]); + x0 = _mm_aesenc_si128(x0, sk[6]); + x1 = _mm_aesenc_si128(x1, sk[6]); + x2 = _mm_aesenc_si128(x2, sk[6]); + x3 = _mm_aesenc_si128(x3, sk[6]); + x0 = _mm_aesenc_si128(x0, sk[7]); + x1 = _mm_aesenc_si128(x1, sk[7]); + x2 = _mm_aesenc_si128(x2, sk[7]); + x3 = _mm_aesenc_si128(x3, sk[7]); + x0 = _mm_aesenc_si128(x0, sk[8]); + x1 = _mm_aesenc_si128(x1, sk[8]); + x2 = _mm_aesenc_si128(x2, sk[8]); + x3 = _mm_aesenc_si128(x3, sk[8]); + x0 = _mm_aesenc_si128(x0, sk[9]); + x1 = _mm_aesenc_si128(x1, sk[9]); + x2 = _mm_aesenc_si128(x2, sk[9]); + x3 = _mm_aesenc_si128(x3, sk[9]); + if (num_rounds == 10) { + x0 = _mm_aesenclast_si128(x0, sk[10]); + x1 = _mm_aesenclast_si128(x1, sk[10]); + x2 = _mm_aesenclast_si128(x2, sk[10]); + x3 = _mm_aesenclast_si128(x3, sk[10]); + } else if (num_rounds == 12) { + x0 = _mm_aesenc_si128(x0, sk[10]); + x1 = _mm_aesenc_si128(x1, sk[10]); + x2 = _mm_aesenc_si128(x2, sk[10]); + x3 = _mm_aesenc_si128(x3, sk[10]); + x0 = _mm_aesenc_si128(x0, sk[11]); + x1 = _mm_aesenc_si128(x1, sk[11]); + x2 = _mm_aesenc_si128(x2, sk[11]); + x3 = _mm_aesenc_si128(x3, sk[11]); + x0 = _mm_aesenclast_si128(x0, sk[12]); + x1 = _mm_aesenclast_si128(x1, sk[12]); + x2 = _mm_aesenclast_si128(x2, sk[12]); + x3 = _mm_aesenclast_si128(x3, sk[12]); + } else { + x0 = _mm_aesenc_si128(x0, sk[10]); + x1 = _mm_aesenc_si128(x1, sk[10]); + x2 = _mm_aesenc_si128(x2, sk[10]); + x3 = _mm_aesenc_si128(x3, sk[10]); + x0 = _mm_aesenc_si128(x0, sk[11]); + x1 = _mm_aesenc_si128(x1, sk[11]); + x2 = _mm_aesenc_si128(x2, sk[11]); + x3 = _mm_aesenc_si128(x3, sk[11]); + x0 = _mm_aesenc_si128(x0, sk[12]); + x1 = _mm_aesenc_si128(x1, sk[12]); + x2 = _mm_aesenc_si128(x2, sk[12]); + x3 = _mm_aesenc_si128(x3, sk[12]); + x0 = _mm_aesenc_si128(x0, sk[13]); + x1 = _mm_aesenc_si128(x1, sk[13]); + x2 = _mm_aesenc_si128(x2, sk[13]); + x3 = _mm_aesenc_si128(x3, sk[13]); + x0 = _mm_aesenclast_si128(x0, sk[14]); + x1 = _mm_aesenclast_si128(x1, sk[14]); + x2 = _mm_aesenclast_si128(x2, sk[14]); + x3 = _mm_aesenclast_si128(x3, sk[14]); + } + if (len >= 64) { + x0 = _mm_xor_si128(x0, + _mm_loadu_si128((void *)(buf + 0))); + x1 = _mm_xor_si128(x1, + _mm_loadu_si128((void *)(buf + 16))); + x2 = _mm_xor_si128(x2, + _mm_loadu_si128((void *)(buf + 32))); + x3 = _mm_xor_si128(x3, + _mm_loadu_si128((void *)(buf + 48))); + _mm_storeu_si128((void *)(buf + 0), x0); + _mm_storeu_si128((void *)(buf + 16), x1); + _mm_storeu_si128((void *)(buf + 32), x2); + _mm_storeu_si128((void *)(buf + 48), x3); + buf += 64; + len -= 64; + cc += 4; + } else { + unsigned char tmp[64]; + + _mm_storeu_si128((void *)(tmp + 0), x0); + _mm_storeu_si128((void *)(tmp + 16), x1); + _mm_storeu_si128((void *)(tmp + 32), x2); + _mm_storeu_si128((void *)(tmp + 48), x3); + for (u = 0; u < len; u ++) { + buf[u] ^= tmp[u]; + } + cc += (uint32_t)len >> 4; + break; + } + } + return cc; +} + +BR_TARGETS_X86_DOWN + +/* see bearssl_block.h */ +const br_block_ctr_class br_aes_x86ni_ctr_vtable = { + sizeof(br_aes_x86ni_ctr_keys), + 16, + 4, + (void (*)(const br_block_ctr_class **, const void *, size_t)) + &br_aes_x86ni_ctr_init, + (uint32_t (*)(const br_block_ctr_class *const *, + const void *, uint32_t, void *, size_t)) + &br_aes_x86ni_ctr_run +}; + +#else + +/* see bearssl_block.h */ +const br_block_ctr_class * +br_aes_x86ni_ctr_get_vtable(void) +{ + return NULL; +} + +#endif + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_x86ni_ctrcbc.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_x86ni_ctrcbc.c new file mode 100644 index 000000000..44664b5ac --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aes_x86ni_ctrcbc.c @@ -0,0 +1,601 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#define BR_ENABLE_INTRINSICS 1 +#include "inner.h" + +#if BR_AES_X86NI + +/* see bearssl_block.h */ +const br_block_ctrcbc_class * +br_aes_x86ni_ctrcbc_get_vtable(void) +{ + return br_aes_x86ni_supported() ? &br_aes_x86ni_ctrcbc_vtable : NULL; +} + +/* see bearssl_block.h */ +void +br_aes_x86ni_ctrcbc_init(br_aes_x86ni_ctrcbc_keys *ctx, + const void *key, size_t len) +{ + ctx->vtable = &br_aes_x86ni_ctrcbc_vtable; + ctx->num_rounds = br_aes_x86ni_keysched_enc(ctx->skey.skni, key, len); +} + +BR_TARGETS_X86_UP + +/* see bearssl_block.h */ +BR_TARGET("sse2,sse4.1,aes") +void +br_aes_x86ni_ctrcbc_ctr(const br_aes_x86ni_ctrcbc_keys *ctx, + void *ctr, void *data, size_t len) +{ + unsigned char *buf; + unsigned num_rounds; + __m128i sk[15]; + __m128i ivx0, ivx1, ivx2, ivx3; + __m128i erev, zero, one, four, notthree; + unsigned u; + + buf = data; + num_rounds = ctx->num_rounds; + for (u = 0; u <= num_rounds; u ++) { + sk[u] = _mm_loadu_si128((void *)(ctx->skey.skni + (u << 4))); + } + + /* + * Some SSE2 constants. + */ + erev = _mm_set_epi8(0, 1, 2, 3, 4, 5, 6, 7, + 8, 9, 10, 11, 12, 13, 14, 15); + zero = _mm_setzero_si128(); + one = _mm_set_epi64x(0, 1); + four = _mm_set_epi64x(0, 4); + notthree = _mm_sub_epi64(zero, four); + + /* + * Decode the counter in big-endian and pre-increment the other + * three counters. + */ + ivx0 = _mm_shuffle_epi8(_mm_loadu_si128((void *)ctr), erev); + ivx1 = _mm_add_epi64(ivx0, one); + ivx1 = _mm_sub_epi64(ivx1, + _mm_slli_si128(_mm_cmpeq_epi64(ivx1, zero), 8)); + ivx2 = _mm_add_epi64(ivx1, one); + ivx2 = _mm_sub_epi64(ivx2, + _mm_slli_si128(_mm_cmpeq_epi64(ivx2, zero), 8)); + ivx3 = _mm_add_epi64(ivx2, one); + ivx3 = _mm_sub_epi64(ivx3, + _mm_slli_si128(_mm_cmpeq_epi64(ivx3, zero), 8)); + while (len > 0) { + __m128i x0, x1, x2, x3; + + /* + * Load counter values; we need to byteswap them because + * the specification says that they use big-endian. + */ + x0 = _mm_shuffle_epi8(ivx0, erev); + x1 = _mm_shuffle_epi8(ivx1, erev); + x2 = _mm_shuffle_epi8(ivx2, erev); + x3 = _mm_shuffle_epi8(ivx3, erev); + + x0 = _mm_xor_si128(x0, sk[0]); + x1 = _mm_xor_si128(x1, sk[0]); + x2 = _mm_xor_si128(x2, sk[0]); + x3 = _mm_xor_si128(x3, sk[0]); + x0 = _mm_aesenc_si128(x0, sk[1]); + x1 = _mm_aesenc_si128(x1, sk[1]); + x2 = _mm_aesenc_si128(x2, sk[1]); + x3 = _mm_aesenc_si128(x3, sk[1]); + x0 = _mm_aesenc_si128(x0, sk[2]); + x1 = _mm_aesenc_si128(x1, sk[2]); + x2 = _mm_aesenc_si128(x2, sk[2]); + x3 = _mm_aesenc_si128(x3, sk[2]); + x0 = _mm_aesenc_si128(x0, sk[3]); + x1 = _mm_aesenc_si128(x1, sk[3]); + x2 = _mm_aesenc_si128(x2, sk[3]); + x3 = _mm_aesenc_si128(x3, sk[3]); + x0 = _mm_aesenc_si128(x0, sk[4]); + x1 = _mm_aesenc_si128(x1, sk[4]); + x2 = _mm_aesenc_si128(x2, sk[4]); + x3 = _mm_aesenc_si128(x3, sk[4]); + x0 = _mm_aesenc_si128(x0, sk[5]); + x1 = _mm_aesenc_si128(x1, sk[5]); + x2 = _mm_aesenc_si128(x2, sk[5]); + x3 = _mm_aesenc_si128(x3, sk[5]); + x0 = _mm_aesenc_si128(x0, sk[6]); + x1 = _mm_aesenc_si128(x1, sk[6]); + x2 = _mm_aesenc_si128(x2, sk[6]); + x3 = _mm_aesenc_si128(x3, sk[6]); + x0 = _mm_aesenc_si128(x0, sk[7]); + x1 = _mm_aesenc_si128(x1, sk[7]); + x2 = _mm_aesenc_si128(x2, sk[7]); + x3 = _mm_aesenc_si128(x3, sk[7]); + x0 = _mm_aesenc_si128(x0, sk[8]); + x1 = _mm_aesenc_si128(x1, sk[8]); + x2 = _mm_aesenc_si128(x2, sk[8]); + x3 = _mm_aesenc_si128(x3, sk[8]); + x0 = _mm_aesenc_si128(x0, sk[9]); + x1 = _mm_aesenc_si128(x1, sk[9]); + x2 = _mm_aesenc_si128(x2, sk[9]); + x3 = _mm_aesenc_si128(x3, sk[9]); + if (num_rounds == 10) { + x0 = _mm_aesenclast_si128(x0, sk[10]); + x1 = _mm_aesenclast_si128(x1, sk[10]); + x2 = _mm_aesenclast_si128(x2, sk[10]); + x3 = _mm_aesenclast_si128(x3, sk[10]); + } else if (num_rounds == 12) { + x0 = _mm_aesenc_si128(x0, sk[10]); + x1 = _mm_aesenc_si128(x1, sk[10]); + x2 = _mm_aesenc_si128(x2, sk[10]); + x3 = _mm_aesenc_si128(x3, sk[10]); + x0 = _mm_aesenc_si128(x0, sk[11]); + x1 = _mm_aesenc_si128(x1, sk[11]); + x2 = _mm_aesenc_si128(x2, sk[11]); + x3 = _mm_aesenc_si128(x3, sk[11]); + x0 = _mm_aesenclast_si128(x0, sk[12]); + x1 = _mm_aesenclast_si128(x1, sk[12]); + x2 = _mm_aesenclast_si128(x2, sk[12]); + x3 = _mm_aesenclast_si128(x3, sk[12]); + } else { + x0 = _mm_aesenc_si128(x0, sk[10]); + x1 = _mm_aesenc_si128(x1, sk[10]); + x2 = _mm_aesenc_si128(x2, sk[10]); + x3 = _mm_aesenc_si128(x3, sk[10]); + x0 = _mm_aesenc_si128(x0, sk[11]); + x1 = _mm_aesenc_si128(x1, sk[11]); + x2 = _mm_aesenc_si128(x2, sk[11]); + x3 = _mm_aesenc_si128(x3, sk[11]); + x0 = _mm_aesenc_si128(x0, sk[12]); + x1 = _mm_aesenc_si128(x1, sk[12]); + x2 = _mm_aesenc_si128(x2, sk[12]); + x3 = _mm_aesenc_si128(x3, sk[12]); + x0 = _mm_aesenc_si128(x0, sk[13]); + x1 = _mm_aesenc_si128(x1, sk[13]); + x2 = _mm_aesenc_si128(x2, sk[13]); + x3 = _mm_aesenc_si128(x3, sk[13]); + x0 = _mm_aesenclast_si128(x0, sk[14]); + x1 = _mm_aesenclast_si128(x1, sk[14]); + x2 = _mm_aesenclast_si128(x2, sk[14]); + x3 = _mm_aesenclast_si128(x3, sk[14]); + } + if (len >= 64) { + x0 = _mm_xor_si128(x0, + _mm_loadu_si128((void *)(buf + 0))); + x1 = _mm_xor_si128(x1, + _mm_loadu_si128((void *)(buf + 16))); + x2 = _mm_xor_si128(x2, + _mm_loadu_si128((void *)(buf + 32))); + x3 = _mm_xor_si128(x3, + _mm_loadu_si128((void *)(buf + 48))); + _mm_storeu_si128((void *)(buf + 0), x0); + _mm_storeu_si128((void *)(buf + 16), x1); + _mm_storeu_si128((void *)(buf + 32), x2); + _mm_storeu_si128((void *)(buf + 48), x3); + buf += 64; + len -= 64; + } else { + unsigned char tmp[64]; + + _mm_storeu_si128((void *)(tmp + 0), x0); + _mm_storeu_si128((void *)(tmp + 16), x1); + _mm_storeu_si128((void *)(tmp + 32), x2); + _mm_storeu_si128((void *)(tmp + 48), x3); + for (u = 0; u < len; u ++) { + buf[u] ^= tmp[u]; + } + switch (len) { + case 16: + ivx0 = ivx1; + break; + case 32: + ivx0 = ivx2; + break; + case 48: + ivx0 = ivx3; + break; + } + break; + } + + /* + * Add 4 to each counter value. For carry propagation + * into the upper 64-bit words, we would need to compare + * the results with 4, but SSE2+ has only _signed_ + * comparisons. Instead, we mask out the low two bits, + * and check whether the remaining bits are zero. + */ + ivx0 = _mm_add_epi64(ivx0, four); + ivx1 = _mm_add_epi64(ivx1, four); + ivx2 = _mm_add_epi64(ivx2, four); + ivx3 = _mm_add_epi64(ivx3, four); + ivx0 = _mm_sub_epi64(ivx0, + _mm_slli_si128(_mm_cmpeq_epi64( + _mm_and_si128(ivx0, notthree), zero), 8)); + ivx1 = _mm_sub_epi64(ivx1, + _mm_slli_si128(_mm_cmpeq_epi64( + _mm_and_si128(ivx1, notthree), zero), 8)); + ivx2 = _mm_sub_epi64(ivx2, + _mm_slli_si128(_mm_cmpeq_epi64( + _mm_and_si128(ivx2, notthree), zero), 8)); + ivx3 = _mm_sub_epi64(ivx3, + _mm_slli_si128(_mm_cmpeq_epi64( + _mm_and_si128(ivx3, notthree), zero), 8)); + } + + /* + * Write back new counter value. The loop took care to put the + * right counter value in ivx0. + */ + _mm_storeu_si128((void *)ctr, _mm_shuffle_epi8(ivx0, erev)); +} + +/* see bearssl_block.h */ +BR_TARGET("sse2,sse4.1,aes") +void +br_aes_x86ni_ctrcbc_mac(const br_aes_x86ni_ctrcbc_keys *ctx, + void *cbcmac, const void *data, size_t len) +{ + const unsigned char *buf; + unsigned num_rounds; + __m128i sk[15], ivx; + unsigned u; + + buf = data; + ivx = _mm_loadu_si128(cbcmac); + num_rounds = ctx->num_rounds; + for (u = 0; u <= num_rounds; u ++) { + sk[u] = _mm_loadu_si128((void *)(ctx->skey.skni + (u << 4))); + } + while (len > 0) { + __m128i x; + + x = _mm_xor_si128(_mm_loadu_si128((void *)buf), ivx); + x = _mm_xor_si128(x, sk[0]); + x = _mm_aesenc_si128(x, sk[1]); + x = _mm_aesenc_si128(x, sk[2]); + x = _mm_aesenc_si128(x, sk[3]); + x = _mm_aesenc_si128(x, sk[4]); + x = _mm_aesenc_si128(x, sk[5]); + x = _mm_aesenc_si128(x, sk[6]); + x = _mm_aesenc_si128(x, sk[7]); + x = _mm_aesenc_si128(x, sk[8]); + x = _mm_aesenc_si128(x, sk[9]); + if (num_rounds == 10) { + x = _mm_aesenclast_si128(x, sk[10]); + } else if (num_rounds == 12) { + x = _mm_aesenc_si128(x, sk[10]); + x = _mm_aesenc_si128(x, sk[11]); + x = _mm_aesenclast_si128(x, sk[12]); + } else { + x = _mm_aesenc_si128(x, sk[10]); + x = _mm_aesenc_si128(x, sk[11]); + x = _mm_aesenc_si128(x, sk[12]); + x = _mm_aesenc_si128(x, sk[13]); + x = _mm_aesenclast_si128(x, sk[14]); + } + ivx = x; + buf += 16; + len -= 16; + } + _mm_storeu_si128(cbcmac, ivx); +} + +/* see bearssl_block.h */ +BR_TARGET("sse2,sse4.1,aes") +void +br_aes_x86ni_ctrcbc_encrypt(const br_aes_x86ni_ctrcbc_keys *ctx, + void *ctr, void *cbcmac, void *data, size_t len) +{ + unsigned char *buf; + unsigned num_rounds; + __m128i sk[15]; + __m128i ivx, cmx; + __m128i erev, zero, one; + unsigned u; + int first_iter; + + num_rounds = ctx->num_rounds; + for (u = 0; u <= num_rounds; u ++) { + sk[u] = _mm_loadu_si128((void *)(ctx->skey.skni + (u << 4))); + } + + /* + * Some SSE2 constants. + */ + erev = _mm_set_epi8(0, 1, 2, 3, 4, 5, 6, 7, + 8, 9, 10, 11, 12, 13, 14, 15); + zero = _mm_setzero_si128(); + one = _mm_set_epi64x(0, 1); + + /* + * Decode the counter in big-endian. + */ + ivx = _mm_shuffle_epi8(_mm_loadu_si128(ctr), erev); + cmx = _mm_loadu_si128(cbcmac); + + buf = data; + first_iter = 1; + while (len > 0) { + __m128i dx, x0, x1; + + /* + * Load initial values: + * dx encrypted block of data + * x0 counter (for CTR encryption) + * x1 input for CBC-MAC + */ + dx = _mm_loadu_si128((void *)buf); + x0 = _mm_shuffle_epi8(ivx, erev); + x1 = cmx; + + x0 = _mm_xor_si128(x0, sk[0]); + x1 = _mm_xor_si128(x1, sk[0]); + x0 = _mm_aesenc_si128(x0, sk[1]); + x1 = _mm_aesenc_si128(x1, sk[1]); + x0 = _mm_aesenc_si128(x0, sk[2]); + x1 = _mm_aesenc_si128(x1, sk[2]); + x0 = _mm_aesenc_si128(x0, sk[3]); + x1 = _mm_aesenc_si128(x1, sk[3]); + x0 = _mm_aesenc_si128(x0, sk[4]); + x1 = _mm_aesenc_si128(x1, sk[4]); + x0 = _mm_aesenc_si128(x0, sk[5]); + x1 = _mm_aesenc_si128(x1, sk[5]); + x0 = _mm_aesenc_si128(x0, sk[6]); + x1 = _mm_aesenc_si128(x1, sk[6]); + x0 = _mm_aesenc_si128(x0, sk[7]); + x1 = _mm_aesenc_si128(x1, sk[7]); + x0 = _mm_aesenc_si128(x0, sk[8]); + x1 = _mm_aesenc_si128(x1, sk[8]); + x0 = _mm_aesenc_si128(x0, sk[9]); + x1 = _mm_aesenc_si128(x1, sk[9]); + if (num_rounds == 10) { + x0 = _mm_aesenclast_si128(x0, sk[10]); + x1 = _mm_aesenclast_si128(x1, sk[10]); + } else if (num_rounds == 12) { + x0 = _mm_aesenc_si128(x0, sk[10]); + x1 = _mm_aesenc_si128(x1, sk[10]); + x0 = _mm_aesenc_si128(x0, sk[11]); + x1 = _mm_aesenc_si128(x1, sk[11]); + x0 = _mm_aesenclast_si128(x0, sk[12]); + x1 = _mm_aesenclast_si128(x1, sk[12]); + } else { + x0 = _mm_aesenc_si128(x0, sk[10]); + x1 = _mm_aesenc_si128(x1, sk[10]); + x0 = _mm_aesenc_si128(x0, sk[11]); + x1 = _mm_aesenc_si128(x1, sk[11]); + x0 = _mm_aesenc_si128(x0, sk[12]); + x1 = _mm_aesenc_si128(x1, sk[12]); + x0 = _mm_aesenc_si128(x0, sk[13]); + x1 = _mm_aesenc_si128(x1, sk[13]); + x0 = _mm_aesenclast_si128(x0, sk[14]); + x1 = _mm_aesenclast_si128(x1, sk[14]); + } + + x0 = _mm_xor_si128(x0, dx); + if (first_iter) { + cmx = _mm_xor_si128(cmx, x0); + first_iter = 0; + } else { + cmx = _mm_xor_si128(x1, x0); + } + _mm_storeu_si128((void *)buf, x0); + + buf += 16; + len -= 16; + + /* + * Increment the counter value. + */ + ivx = _mm_add_epi64(ivx, one); + ivx = _mm_sub_epi64(ivx, + _mm_slli_si128(_mm_cmpeq_epi64(ivx, zero), 8)); + + /* + * If this was the last iteration, then compute the + * extra block encryption to complete CBC-MAC. + */ + if (len == 0) { + cmx = _mm_xor_si128(cmx, sk[0]); + cmx = _mm_aesenc_si128(cmx, sk[1]); + cmx = _mm_aesenc_si128(cmx, sk[2]); + cmx = _mm_aesenc_si128(cmx, sk[3]); + cmx = _mm_aesenc_si128(cmx, sk[4]); + cmx = _mm_aesenc_si128(cmx, sk[5]); + cmx = _mm_aesenc_si128(cmx, sk[6]); + cmx = _mm_aesenc_si128(cmx, sk[7]); + cmx = _mm_aesenc_si128(cmx, sk[8]); + cmx = _mm_aesenc_si128(cmx, sk[9]); + if (num_rounds == 10) { + cmx = _mm_aesenclast_si128(cmx, sk[10]); + } else if (num_rounds == 12) { + cmx = _mm_aesenc_si128(cmx, sk[10]); + cmx = _mm_aesenc_si128(cmx, sk[11]); + cmx = _mm_aesenclast_si128(cmx, sk[12]); + } else { + cmx = _mm_aesenc_si128(cmx, sk[10]); + cmx = _mm_aesenc_si128(cmx, sk[11]); + cmx = _mm_aesenc_si128(cmx, sk[12]); + cmx = _mm_aesenc_si128(cmx, sk[13]); + cmx = _mm_aesenclast_si128(cmx, sk[14]); + } + break; + } + } + + /* + * Write back new counter value and CBC-MAC value. + */ + _mm_storeu_si128(ctr, _mm_shuffle_epi8(ivx, erev)); + _mm_storeu_si128(cbcmac, cmx); +} + +/* see bearssl_block.h */ +BR_TARGET("sse2,sse4.1,aes") +void +br_aes_x86ni_ctrcbc_decrypt(const br_aes_x86ni_ctrcbc_keys *ctx, + void *ctr, void *cbcmac, void *data, size_t len) +{ + unsigned char *buf; + unsigned num_rounds; + __m128i sk[15]; + __m128i ivx, cmx; + __m128i erev, zero, one; + unsigned u; + + num_rounds = ctx->num_rounds; + for (u = 0; u <= num_rounds; u ++) { + sk[u] = _mm_loadu_si128((void *)(ctx->skey.skni + (u << 4))); + } + + /* + * Some SSE2 constants. + */ + erev = _mm_set_epi8(0, 1, 2, 3, 4, 5, 6, 7, + 8, 9, 10, 11, 12, 13, 14, 15); + zero = _mm_setzero_si128(); + one = _mm_set_epi64x(0, 1); + + /* + * Decode the counter in big-endian. + */ + ivx = _mm_shuffle_epi8(_mm_loadu_si128(ctr), erev); + cmx = _mm_loadu_si128(cbcmac); + + buf = data; + while (len > 0) { + __m128i dx, x0, x1; + + /* + * Load initial values: + * dx encrypted block of data + * x0 counter (for CTR encryption) + * x1 input for CBC-MAC + */ + dx = _mm_loadu_si128((void *)buf); + x0 = _mm_shuffle_epi8(ivx, erev); + x1 = _mm_xor_si128(cmx, dx); + + x0 = _mm_xor_si128(x0, sk[0]); + x1 = _mm_xor_si128(x1, sk[0]); + x0 = _mm_aesenc_si128(x0, sk[1]); + x1 = _mm_aesenc_si128(x1, sk[1]); + x0 = _mm_aesenc_si128(x0, sk[2]); + x1 = _mm_aesenc_si128(x1, sk[2]); + x0 = _mm_aesenc_si128(x0, sk[3]); + x1 = _mm_aesenc_si128(x1, sk[3]); + x0 = _mm_aesenc_si128(x0, sk[4]); + x1 = _mm_aesenc_si128(x1, sk[4]); + x0 = _mm_aesenc_si128(x0, sk[5]); + x1 = _mm_aesenc_si128(x1, sk[5]); + x0 = _mm_aesenc_si128(x0, sk[6]); + x1 = _mm_aesenc_si128(x1, sk[6]); + x0 = _mm_aesenc_si128(x0, sk[7]); + x1 = _mm_aesenc_si128(x1, sk[7]); + x0 = _mm_aesenc_si128(x0, sk[8]); + x1 = _mm_aesenc_si128(x1, sk[8]); + x0 = _mm_aesenc_si128(x0, sk[9]); + x1 = _mm_aesenc_si128(x1, sk[9]); + if (num_rounds == 10) { + x0 = _mm_aesenclast_si128(x0, sk[10]); + x1 = _mm_aesenclast_si128(x1, sk[10]); + } else if (num_rounds == 12) { + x0 = _mm_aesenc_si128(x0, sk[10]); + x1 = _mm_aesenc_si128(x1, sk[10]); + x0 = _mm_aesenc_si128(x0, sk[11]); + x1 = _mm_aesenc_si128(x1, sk[11]); + x0 = _mm_aesenclast_si128(x0, sk[12]); + x1 = _mm_aesenclast_si128(x1, sk[12]); + } else { + x0 = _mm_aesenc_si128(x0, sk[10]); + x1 = _mm_aesenc_si128(x1, sk[10]); + x0 = _mm_aesenc_si128(x0, sk[11]); + x1 = _mm_aesenc_si128(x1, sk[11]); + x0 = _mm_aesenc_si128(x0, sk[12]); + x1 = _mm_aesenc_si128(x1, sk[12]); + x0 = _mm_aesenc_si128(x0, sk[13]); + x1 = _mm_aesenc_si128(x1, sk[13]); + x0 = _mm_aesenclast_si128(x0, sk[14]); + x1 = _mm_aesenclast_si128(x1, sk[14]); + } + x0 = _mm_xor_si128(x0, dx); + cmx = x1; + _mm_storeu_si128((void *)buf, x0); + + buf += 16; + len -= 16; + + /* + * Increment the counter value. + */ + ivx = _mm_add_epi64(ivx, one); + ivx = _mm_sub_epi64(ivx, + _mm_slli_si128(_mm_cmpeq_epi64(ivx, zero), 8)); + } + + /* + * Write back new counter value and CBC-MAC value. + */ + _mm_storeu_si128(ctr, _mm_shuffle_epi8(ivx, erev)); + _mm_storeu_si128(cbcmac, cmx); +} + +BR_TARGETS_X86_DOWN + +/* see bearssl_block.h */ +const br_block_ctrcbc_class br_aes_x86ni_ctrcbc_vtable = { + sizeof(br_aes_x86ni_ctrcbc_keys), + 16, + 4, + (void (*)(const br_block_ctrcbc_class **, const void *, size_t)) + &br_aes_x86ni_ctrcbc_init, + (void (*)(const br_block_ctrcbc_class *const *, + void *, void *, void *, size_t)) + &br_aes_x86ni_ctrcbc_encrypt, + (void (*)(const br_block_ctrcbc_class *const *, + void *, void *, void *, size_t)) + &br_aes_x86ni_ctrcbc_decrypt, + (void (*)(const br_block_ctrcbc_class *const *, + void *, void *, size_t)) + &br_aes_x86ni_ctrcbc_ctr, + (void (*)(const br_block_ctrcbc_class *const *, + void *, const void *, size_t)) + &br_aes_x86ni_ctrcbc_mac +}; + +#else + +/* see bearssl_block.h */ +const br_block_ctrcbc_class * +br_aes_x86ni_ctrcbc_get_vtable(void) +{ + return NULL; +} + +#endif + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aesctr_drbg.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aesctr_drbg.c new file mode 100644 index 000000000..5f2d39337 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/aesctr_drbg.c @@ -0,0 +1,211 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_rand.h */ +void +br_aesctr_drbg_init(br_aesctr_drbg_context *ctx, + const br_block_ctr_class *aesctr, + const void *seed, size_t len) +{ + unsigned char tmp[16]; + + ctx->vtable = &br_aesctr_drbg_vtable; + memset(tmp, 0, sizeof tmp); + aesctr->init(&ctx->sk.vtable, tmp, 16); + ctx->cc = 0; + br_aesctr_drbg_update(ctx, seed, len); +} + +/* see bearssl_rand.h */ +void +br_aesctr_drbg_generate(br_aesctr_drbg_context *ctx, void *out, size_t len) +{ + unsigned char *buf; + unsigned char iv[12]; + + buf = out; + memset(iv, 0, sizeof iv); + while (len > 0) { + size_t clen; + + /* + * We generate data by blocks of at most 65280 bytes. This + * allows for unambiguously testing the counter overflow + * condition; also, it should work on 16-bit architectures + * (where 'size_t' is 16 bits only). + */ + clen = len; + if (clen > 65280) { + clen = 65280; + } + + /* + * We make sure that the counter won't exceed the configured + * limit. + */ + if ((uint32_t)(ctx->cc + ((clen + 15) >> 4)) > 32768) { + clen = (32768 - ctx->cc) << 4; + if (clen > len) { + clen = len; + } + } + + /* + * Run CTR. + */ + memset(buf, 0, clen); + ctx->cc = ctx->sk.vtable->run(&ctx->sk.vtable, + iv, ctx->cc, buf, clen); + buf += clen; + len -= clen; + + /* + * Every 32768 blocks, we force a state update. + */ + if (ctx->cc >= 32768) { + br_aesctr_drbg_update(ctx, NULL, 0); + } + } +} + +/* see bearssl_rand.h */ +void +br_aesctr_drbg_update(br_aesctr_drbg_context *ctx, const void *seed, size_t len) +{ + /* + * We use a Hirose construction on AES-256 to make a hash function. + * Function definition: + * - running state consists in two 16-byte blocks G and H + * - initial values of G and H are conventional + * - there is a fixed block-sized constant C + * - for next data block m: + * set AES key to H||m + * G' = E(G) xor G + * H' = E(G xor C) xor G xor C + * G <- G', H <- H' + * - once all blocks have been processed, output is H||G + * + * Constants: + * G_init = B6 B6 ... B6 + * H_init = A5 A5 ... A5 + * C = 01 00 ... 00 + * + * With this hash function h(), we compute the new state as + * follows: + * - produce a state-dependent value s as encryption of an + * all-one block with AES and the current key + * - compute the new key as the first 128 bits of h(s||seed) + * + * Original Hirose article: + * https://www.iacr.org/archive/fse2006/40470213/40470213.pdf + */ + + unsigned char s[16], iv[12]; + unsigned char G[16], H[16]; + int first; + + /* + * Use an all-one IV to get a fresh output block that depends on the + * current seed. + */ + memset(iv, 0xFF, sizeof iv); + memset(s, 0, 16); + ctx->sk.vtable->run(&ctx->sk.vtable, iv, 0xFFFFFFFF, s, 16); + + /* + * Set G[] and H[] to conventional start values. + */ + memset(G, 0xB6, sizeof G); + memset(H, 0x5A, sizeof H); + + /* + * Process the concatenation of the current state and the seed + * with the custom hash function. + */ + first = 1; + for (;;) { + unsigned char tmp[32]; + unsigned char newG[16]; + + /* + * Assemble new key H||m into tmp[]. + */ + memcpy(tmp, H, 16); + if (first) { + memcpy(tmp + 16, s, 16); + first = 0; + } else { + size_t clen; + + if (len == 0) { + break; + } + clen = len < 16 ? len : 16; + memcpy(tmp + 16, seed, clen); + memset(tmp + 16 + clen, 0, 16 - clen); + seed = (const unsigned char *)seed + clen; + len -= clen; + } + ctx->sk.vtable->init(&ctx->sk.vtable, tmp, 32); + + /* + * Compute new G and H values. + */ + memcpy(iv, G, 12); + memcpy(newG, G, 16); + ctx->sk.vtable->run(&ctx->sk.vtable, iv, + br_dec32be(G + 12), newG, 16); + iv[0] ^= 0x01; + memcpy(H, G, 16); + H[0] ^= 0x01; + ctx->sk.vtable->run(&ctx->sk.vtable, iv, + br_dec32be(G + 12), H, 16); + memcpy(G, newG, 16); + } + + /* + * Output hash value is H||G. We truncate it to its first 128 bits, + * i.e. H; that's our new AES key. + */ + ctx->sk.vtable->init(&ctx->sk.vtable, H, 16); + ctx->cc = 0; +} + +/* see bearssl_rand.h */ +const br_prng_class br_aesctr_drbg_vtable = { + sizeof(br_aesctr_drbg_context), + (void (*)(const br_prng_class **, const void *, const void *, size_t)) + &br_aesctr_drbg_init, + (void (*)(const br_prng_class **, void *, size_t)) + &br_aesctr_drbg_generate, + (void (*)(const br_prng_class **, const void *, size_t)) + &br_aesctr_drbg_update +}; + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/asn1.t0 b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/asn1.t0 new file mode 100644 index 000000000..c329514ad --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/asn1.t0 @@ -0,0 +1,757 @@ +\ Copyright (c) 2016 Thomas Pornin +\ +\ Permission is hereby granted, free of charge, to any person obtaining +\ a copy of this software and associated documentation files (the +\ "Software"), to deal in the Software without restriction, including +\ without limitation the rights to use, copy, modify, merge, publish, +\ distribute, sublicense, and/or sell copies of the Software, and to +\ permit persons to whom the Software is furnished to do so, subject to +\ the following conditions: +\ +\ The above copyright notice and this permission notice shall be +\ included in all copies or substantial portions of the Software. +\ +\ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +\ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +\ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +\ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +\ BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +\ ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +\ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +\ SOFTWARE. + +\ ======================================================================= + +\ This file contains code which is common to all engines that do some +\ ASN.1 decoding. It should not be compiled on its own, but only along +\ with another file (e.g. x509_minimal.t0) which uses it. +\ +\ Users must define several things: +\ +\ -- In the preamble, a macro called "CTX" that evaluates to the current +\ context structure. +\ +\ -- In the preamble, a macro called "CONTEXT_NAME" that evaluates to the +\ context structure type. This will be invoked during compilation. +\ +\ -- A word called "read8-low" ( -- x ) that reads the next byte, or -1 +\ if the input buffer is empty. That word is usually written in C. +\ +\ -- A word called "read-blob-inner" ( addr len -- addr len ) that is +\ the multi-byte version of read8-low. +\ +\ -- A word called "skip-remaining-inner" ( lim -- lim ) which reads but +\ drops some input bytes. + +preamble { + +#include "inner.h" + +} + +\ Read next source character, skipping blanks. +: skip-blanks begin char dup 32 > if ret then drop again ; + +: fail-oid + "Invalid OID" puts cr exitvm ; + +\ Read a decimal integer, followed by either a dot or whitespace. +\ Note: this does not check for overflows. +: parse-number ( -- val nextchar ) + char decval + begin + char + dup dup `. = swap 32 <= or if ret then + decval swap 10 * + + again ; + +\ Encode a number in unsigned 7E format. +: encode7E ( val -- ) + 0 encode7E-inner ; + +: encode7E-inner ( val eb -- ) + swap dup 0x7F > if + dup 7 u>> 0x80 encode7E-inner 0x7F and + then + or data-add8 ; + +\ Decode an OID from source, and encode it. First byte is length, +\ followed by encoded ASN.1 DER value. The OID is encoded in the +\ current data block. +: OID + \ Get current data address, and push a 0 for length. + current-data 0 data-add8 + \ Skip blanks and get first digit, which must be 0, 1 or 2. + skip-blanks decval dup 2 > if fail-oid then + 40 * + \ Next character must be a dot. + char `. <> if fail-oid then + \ Second group must be one or two digits. + parse-number { nextchar } + dup 40 >= if fail-oid then + + encode7E + \ While next character is a dot, keep encoding numbers. + begin nextchar `. = while + parse-number >nextchar + encode7E + repeat + \ Write back length in the first byte. + dup current-data swap - 1- swap data-set8 + ; immediate + +\ Define a new data word for an encoded OID. The OID is read from the +\ source. +: OID: + new-data-block next-word define-data-word postpone OID ; + +\ Define a word that evaluates to the address of a field within the +\ context. +: addr: + next-word { field } + "addr-" field + 0 1 define-word + 0 8191 "offsetof(CONTEXT_NAME, " field + ")" + make-CX + postpone literal postpone ; ; + +addr: pad + +\ Define a word that evaluates to an error code through a macro name. +: err: + next-word { name } + name 0 1 define-word + 0 63 "BR_" name + make-CX postpone literal postpone ; ; + +err: ERR_X509_INVALID_VALUE +err: ERR_X509_TRUNCATED +err: ERR_X509_EMPTY_CHAIN +err: ERR_X509_INNER_TRUNC +err: ERR_X509_BAD_TAG_CLASS +err: ERR_X509_BAD_TAG_VALUE +err: ERR_X509_INDEFINITE_LENGTH +err: ERR_X509_EXTRA_ELEMENT +err: ERR_X509_UNEXPECTED +err: ERR_X509_NOT_CONSTRUCTED +err: ERR_X509_NOT_PRIMITIVE +err: ERR_X509_PARTIAL_BYTE +err: ERR_X509_BAD_BOOLEAN +err: ERR_X509_OVERFLOW +err: ERR_X509_BAD_DN +err: ERR_X509_BAD_TIME +err: ERR_X509_UNSUPPORTED +err: ERR_X509_LIMIT_EXCEEDED +err: ERR_X509_WRONG_KEY_TYPE +err: ERR_X509_BAD_SIGNATURE +err: ERR_X509_EXPIRED +err: ERR_X509_DN_MISMATCH +err: ERR_X509_BAD_SERVER_NAME +err: ERR_X509_CRITICAL_EXTENSION +err: ERR_X509_NOT_CA +err: ERR_X509_FORBIDDEN_KEY_USAGE +err: ERR_X509_WEAK_PUBLIC_KEY + +: KEYTYPE_RSA CX 0 15 { BR_KEYTYPE_RSA } ; +: KEYTYPE_EC CX 0 15 { BR_KEYTYPE_EC } ; + +cc: fail ( err -- ! ) { + CTX->err = T0_POPi(); + T0_CO(); +} + +\ Read one byte from the stream. +: read8-nc ( -- x ) + begin + read8-low dup 0 >= if ret then + drop co + again ; + +\ Read one byte, enforcing current read limit. +: read8 ( lim -- lim x ) + dup ifnot ERR_X509_INNER_TRUNC fail then + 1- read8-nc ; + +\ Read a 16-bit value, big-endian encoding. +: read16be ( lim -- lim x ) + read8 8 << swap read8 rot + ; + +\ Read a 16-bit value, little-endian encoding. +: read16le ( lim -- lim x ) + read8 swap read8 8 << rot + ; + +\ Read all bytes from the current element, then close it (i.e. drop the +\ limit). Destination address is an offset within the context. +: read-blob ( lim addr -- ) + swap + begin dup while read-blob-inner dup if co then repeat + 2drop ; + +\ Skip remaining bytes in the current structure, but do not close it +\ (thus, this leaves the value 0 on the stack). +: skip-remaining ( lim -- lim ) + begin dup while skip-remaining-inner dup if co then repeat ; + +: skip-remaining-inner ( lim -- lim ) + 0 over read-blob-inner -rot 2drop ; + +cc: set8 ( val addr -- ) { + uint32_t addr = T0_POP(); + *((unsigned char *)CTX + addr) = (unsigned char)T0_POP(); +} + +cc: set16 ( val addr -- ) { + uint32_t addr = T0_POP(); + *(uint16_t *)(void *)((unsigned char *)CTX + addr) = T0_POP(); +} + +cc: set32 ( val addr -- ) { + uint32_t addr = T0_POP(); + *(uint32_t *)(void *)((unsigned char *)CTX + addr) = T0_POP(); +} + +cc: get8 ( addr -- val ) { + uint32_t addr = T0_POP(); + T0_PUSH(*((unsigned char *)CTX + addr)); +} + +cc: get16 ( addr -- val ) { + uint32_t addr = T0_POP(); + T0_PUSH(*(uint16_t *)(void *)((unsigned char *)CTX + addr)); +} + +cc: get32 ( addr -- val ) { + uint32_t addr = T0_POP(); + T0_PUSH(*(uint32_t *)(void *)((unsigned char *)CTX + addr)); +} + +\ Read an ASN.1 tag. This function returns the "constructed" status +\ and the tag value. The constructed status is a boolean (-1 for +\ constructed, 0 for primitive). The tag value is either 0 to 31 for +\ a universal tag, or 32+x for a contextual tag of value x. Tag classes +\ "application" and "private" are rejected. Universal tags beyond 30 +\ are rejected. Contextual tags beyond 30 are rejected. Thus, accepted +\ tags will necessarily fit on exactly one byte. This does not support +\ the whole of ASN.1/BER, but is sufficient for certificate parsing. +: read-tag ( lim -- lim constructed value ) + read8 { fb } + + \ Constructed flag is bit 5. + fb 5 >> 0x01 and neg + + \ Class is in bits 6 and 7. Accepted classes are 00 (universal) + \ and 10 (context). We check that bit 6 is 0, and shift back + \ bit 7 so that we get 0 (universal) or 32 (context). + fb 6 >> dup 0x01 and if ERR_X509_BAD_TAG_CLASS fail then + 4 << + + \ Tag value is in bits 0..4. If the value is 31, then this is + \ an extended tag, encoded over subsequent bytes, and we do + \ not support that. + fb 0x1F and dup 0x1F = if ERR_X509_BAD_TAG_VALUE fail then + + ; + +\ Read a tag, but only if not at the end of the current object. If there +\ is no room for another element (limit is zero), then this will push a +\ synthetic "no tag" value (primitive, with value -1). +: read-tag-or-end ( lim -- lim constructed value ) + dup ifnot 0 -1 ret then + read-tag ; + +\ Compare the read tag with the provided value. If equal, then the +\ element is skipped, and a new tag is read (or end of object). +: iftag-skip ( lim constructed value ref -- lim constructed value ) + over = if + 2drop + read-length-open-elt skip-close-elt + read-tag-or-end + then ; + +\ Read an ASN.1 length. This supports only definite lengths (theoretically, +\ certificates may use an indefinite length for the outer structure, using +\ DER only in the TBS, but this never happens in practice, except in a +\ single example certificate from 15 years ago that also fails to decode +\ properly for other reasons). +: read-length ( lim -- lim length ) + read8 + \ Lengths in 0x00..0x7F get encoded as a single byte. + dup 0x80 < if ret then + + \ If the byte is 0x80 then this is an indefinite length, and we + \ do not support that. + 0x80 - dup ifnot ERR_X509_INDEFINITE_LENGTH fail then + + \ Masking out bit 7, this yields the number of bytes over which + \ the value is encoded. Since the total certificate length must + \ fit over 3 bytes (this is a consequence of SSL/TLS message + \ format), we can reject big lengths and keep the length in a + \ single integer. + { n } 0 + begin n 0 > while n 1- >n + dup 0x7FFFFF > if ERR_X509_INNER_TRUNC fail then + 8 << swap read8 rot + + repeat ; + +\ Open a sub-structure. This subtracts the length from the limit, and +\ pushes the length back as new limit. +: open-elt ( lim length -- lim_outer lim_inner ) + dup2 < if ERR_X509_INNER_TRUNC fail then + dup { len } - len ; + +\ Read a length and open the value as a sub-structure. +: read-length-open-elt ( lim -- lim_outer lim_inner ) + read-length open-elt ; + +\ Close a sub-structure. This verifies that there is no remaining +\ element to read. +: close-elt ( lim -- ) + if ERR_X509_EXTRA_ELEMENT fail then ; + +\ Skip remaining bytes in the current structure, then close it. +: skip-close-elt ( lim -- ) + skip-remaining drop ; + +\ Read a length and then skip the value. +: read-length-skip ( lim -- lim ) + read-length-open-elt skip-close-elt ; + +\ Check that a given tag is constructed and has the expected value. +: check-tag-constructed ( constructed value refvalue -- ) + = ifnot ERR_X509_UNEXPECTED fail then + check-constructed ; + +\ Check that the top value is true; report a "not constructed" +\ error otherwise. +: check-constructed ( constructed -- ) + ifnot ERR_X509_NOT_CONSTRUCTED fail then ; + +\ Check that a given tag is primitive and has the expected value. +: check-tag-primitive ( constructed value refvalue -- ) + = ifnot ERR_X509_UNEXPECTED fail then + check-primitive ; + +\ Check that the top value is true; report a "not primitive" +\ error otherwise. +: check-primitive ( constructed -- ) + if ERR_X509_NOT_PRIMITIVE fail then ; + +\ Check that the tag is for a constructed SEQUENCE. +: check-sequence ( constructed value -- ) + 0x10 check-tag-constructed ; + +\ Read a tag, check that it is for a constructed SEQUENCE, and open +\ it as a sub-element. +: read-sequence-open ( lim -- lim_outer lim_inner ) + read-tag check-sequence read-length-open-elt ; + +\ Read the next element as a BIT STRING with no ignore bits, and open +\ it as a sub-element. +: read-bits-open ( lim -- lim_outer lim_inner ) + read-tag 0x03 check-tag-primitive + read-length-open-elt + read8 if ERR_X509_PARTIAL_BYTE fail then ; + +OID: rsaEncryption 1.2.840.113549.1.1.1 + +OID: sha1WithRSAEncryption 1.2.840.113549.1.1.5 +OID: sha224WithRSAEncryption 1.2.840.113549.1.1.14 +OID: sha256WithRSAEncryption 1.2.840.113549.1.1.11 +OID: sha384WithRSAEncryption 1.2.840.113549.1.1.12 +OID: sha512WithRSAEncryption 1.2.840.113549.1.1.13 + +OID: id-sha1 1.3.14.3.2.26 +OID: id-sha224 2.16.840.1.101.3.4.2.4 +OID: id-sha256 2.16.840.1.101.3.4.2.1 +OID: id-sha384 2.16.840.1.101.3.4.2.2 +OID: id-sha512 2.16.840.1.101.3.4.2.3 + +OID: id-ecPublicKey 1.2.840.10045.2.1 + +OID: ansix9p256r1 1.2.840.10045.3.1.7 +OID: ansix9p384r1 1.3.132.0.34 +OID: ansix9p521r1 1.3.132.0.35 + +OID: ecdsa-with-SHA1 1.2.840.10045.4.1 +OID: ecdsa-with-SHA224 1.2.840.10045.4.3.1 +OID: ecdsa-with-SHA256 1.2.840.10045.4.3.2 +OID: ecdsa-with-SHA384 1.2.840.10045.4.3.3 +OID: ecdsa-with-SHA512 1.2.840.10045.4.3.4 + +OID: id-at-commonName 2.5.4.3 + +\ Read a "small value". This assumes that the tag has just been read +\ and processed, but not the length. The first pad byte is set to the +\ value length; the encoded value itself follows. If the value length +\ exceeds 255 bytes, then a single 0 is written in the pad, and this +\ method returns false (0). Otherwise, it returns true (-1). +\ Either way, the element is fully read. +: read-small-value ( lim -- lim bool ) + read-length-open-elt + dup 255 > if skip-close-elt 0 addr-pad set8 0 ret then + dup addr-pad set8 + addr-pad 1+ read-blob + -1 ; + +\ Read an OID as a "small value" (tag, length and value). A boolean +\ value is returned, which is true (-1) if the OID value fits on the pad, +\ false (0) otherwise. +: read-OID ( lim -- lim bool ) + read-tag 0x06 check-tag-primitive read-small-value ; + +\ Read a UTF-8 code point. On error, return 0. Reading a code point of +\ value 0 is considered to be an error. +: read-UTF8 ( lim -- lim val ) + read8 + choice + dup 0x80 < uf ret enduf + dup 0xC0 < uf drop 0 ret enduf + dup 0xE0 < uf 0x1F and 1 read-UTF8-next 0x80 0x7FF enduf + dup 0xF0 < uf 0x0F and 2 read-UTF8-next 0x800 0xFFFF enduf + dup 0xF8 < uf 0x07 and 3 read-UTF8-next 0x10000 0x10FFFF enduf + drop 0 ret + endchoice + between? ifnot drop 0 then + ; + +\ Read n subsequent bytes to complete the provided first byte. The final +\ value is -1 on error, or the code point numerical value. The final +\ value is duplicated. +: read-UTF8-next ( lim val n -- lim val val ) + begin dup while + -rot + read-UTF8-chunk + rot 1- + repeat + drop dup ; + +\ Read one byte, that should be a trailing UTF-8 byte, and complement the +\ current value. On error, value is set to -1. +: read-UTF8-chunk ( lim val -- lim val ) + swap + \ If we are at the end of the value, report an error but don't fail. + dup ifnot 2drop 0 -1 ret then + read8 rot + dup 0< if swap drop ret then 6 << + swap dup 6 >> 2 <> if 2drop -1 ret then + 0x3F and + ; + +: high-surrogate? ( x -- x bool ) + dup 0xD800 0xDBFF between? ; + +: low-surrogate? ( x -- x bool ) + dup 0xDC00 0xDFFF between? ; + +: assemble-surrogate-pair ( hi lim lo -- lim val ) + low-surrogate? ifnot rot 2drop 0 ret then + rot 10 << + 0x35FDC00 - ; + +\ Read a UTF-16 code point (big-endian). Returned value is 0 on error. +: read-UTF16BE ( lim -- lim val ) + read16be + choice + high-surrogate? uf + swap dup ifnot 2drop 0 0 ret then + read16be assemble-surrogate-pair + enduf + low-surrogate? uf + drop 0 + enduf + endchoice ; + +\ Read a UTF-16 code point (little-endian). Returned value is 0 on error. +: read-UTF16LE ( lim -- lim val ) + read16le + choice + high-surrogate? uf + swap dup ifnot 2drop 0 0 ret then + read16le assemble-surrogate-pair + enduf + low-surrogate? uf + drop 0 + enduf + endchoice ; + +\ Add byte to current pad value. Offset is updated, or set to 0 on error. +: pad-append ( off val -- off ) + over dup 0= swap 256 >= or if 2drop 0 ret then + over addr-pad + set8 1+ ; + +\ Add UTF-8 chunk byte to the pad. The 'nn' parameter is the shift count. +: pad-append-UTF8-chunk ( off val nn -- off ) + >> 0x3F and 0x80 or pad-append ; + +\ Test whether a code point is invalid when encoding. This rejects the +\ 66 noncharacters, and also the surrogate range; this function does NOT +\ check that the value is in the 0..10FFFF range. +: valid-unicode? ( val -- bool ) + dup 0xFDD0 0xFDEF between? if drop 0 ret then + dup 0xD800 0xDFFF between? if drop 0 ret then + 0xFFFF and 0xFFFE < ; + +\ Encode a code point in UTF-8. Offset is in the pad; it is updated, or +\ set to 0 on error. Leading BOM are ignored. +: encode-UTF8 ( val off -- off ) + \ Skip leading BOM (U+FEFF when off is 1). + dup2 1 = swap 0xFEFF = and if swap drop ret then + + swap dup { val } + dup valid-unicode? ifnot 2drop 0 ret then + choice + dup 0x80 < uf pad-append enduf + dup 0x800 < uf + 6 >> 0xC0 or pad-append + val 0 pad-append-UTF8-chunk + enduf + dup 0xFFFF < uf + 12 >> 0xE0 or pad-append + val 6 pad-append-UTF8-chunk + val 0 pad-append-UTF8-chunk + enduf + 18 >> 0xF0 or pad-append + val 12 pad-append-UTF8-chunk + val 6 pad-append-UTF8-chunk + val 0 pad-append-UTF8-chunk + endchoice ; + +\ Read a string value into the pad; this function checks that the source +\ characters are UTF-8 and non-zero. The string length (in bytes) is +\ written in the first pad byte. Returned value is true (-1) on success, +\ false (0) on error. +: read-value-UTF8 ( lim -- lim bool ) + read-length-open-elt + 1 { off } + begin dup while + read-UTF8 dup ifnot drop skip-close-elt 0 ret then + off encode-UTF8 >off + repeat + drop off dup ifnot ret then 1- addr-pad set8 -1 ; + +\ Decode a UTF-16 string into the pad. The string is converted to UTF-8, +\ and the length is written in the first pad byte. A leading BOM is +\ honoured (big-endian is assumed if there is no BOM). A code point of +\ value 0 is an error. Returned value is true (-1) on success, false (0) +\ on error. +: read-value-UTF16 ( lim -- lim bool ) + read-length-open-elt + dup ifnot addr-pad set8 -1 ret then + 1 { off } + read-UTF16BE dup 0xFFFE = if + \ Leading BOM, and indicates little-endian. + drop + begin dup while + read-UTF16LE dup ifnot drop skip-close-elt 0 ret then + off encode-UTF8 >off + repeat + else + dup ifnot drop skip-close-elt 0 ret then + \ Big-endian BOM, or no BOM. + begin + off encode-UTF8 >off + dup while + read-UTF16BE dup ifnot drop skip-close-elt 0 ret then + repeat + then + drop off dup ifnot ret then 1- addr-pad set8 -1 ; + +\ Decode a latin-1 string into the pad. The string is converted to UTF-8, +\ and the length is written in the first pad byte. A source byte of +\ value 0 is an error. Returned value is true (-1) on success, false (0) +\ on error. +: read-value-latin1 ( lim -- lim bool ) + read-length-open-elt + 1 { off } + begin dup while + read8 dup ifnot drop skip-close-elt 0 ret then + off encode-UTF8 >off + repeat + drop off dup ifnot ret then 1- addr-pad set8 -1 ; + +\ Read a value and interpret it as an INTEGER or ENUMERATED value. If +\ the integer value does not fit on an unsigned 32-bit value, an error +\ is reported. This function assumes that the tag has just been read +\ and processed, but not the length. +: read-small-int-value ( lim -- lim x ) + read-length-open-elt + dup ifnot ERR_X509_OVERFLOW fail then + read8 dup 0x80 >= if ERR_X509_OVERFLOW fail then + { x } + begin dup while + read8 x dup 0xFFFFFF >= if ERR_X509_OVERFLOW fail then + 8 << + >x + repeat + drop x ; + +\ Compare the OID in the pad with an OID in the constant data block. +\ Returned value is -1 on equality, 0 otherwise. +cc: eqOID ( addrConst -- bool ) { + const unsigned char *a2 = &t0_datablock[T0_POP()]; + const unsigned char *a1 = &CTX->pad[0]; + size_t len = a1[0]; + int x; + if (len == a2[0]) { + x = -(memcmp(a1 + 1, a2 + 1, len) == 0); + } else { + x = 0; + } + T0_PUSH((uint32_t)x); +} + +\ Compare two blobs in the context. Returned value is -1 on equality, 0 +\ otherwise. +cc: eqblob ( addr1 addr2 len -- bool ) { + size_t len = T0_POP(); + const unsigned char *a2 = (const unsigned char *)CTX + T0_POP(); + const unsigned char *a1 = (const unsigned char *)CTX + T0_POP(); + T0_PUSHi(-(memcmp(a1, a2, len) == 0)); +} + +\ Check that a value is in a given range (inclusive). +: between? ( x min max -- bool ) + { min max } dup min >= swap max <= and ; + +\ Convert the provided byte value into a number in the 0..9 range, +\ assuming that it is an ASCII digit. A non-digit triggers an error +\ (a "bad time" error since this is used in date/time decoding). +: digit-dec ( char -- value ) + `0 - dup 0 9 between? ifnot ERR_X509_BAD_TIME fail then ; + +\ Read two ASCII digits and return the value in the 0..99 range. An +\ error is reported if the characters are not ASCII digits. +: read-dec2 ( lim -- lim x ) + read8 digit-dec 10 * { x } read8 digit-dec x + ; + +\ Read two ASCII digits and check that the value is in the provided +\ range (inclusive). +: read-dec2-range ( lim min max -- lim x ) + { min max } + read-dec2 dup min max between? ifnot ERR_X509_BAD_TIME fail then ; + +\ Maximum days in a month and accumulated day count. Each +\ 16-bit value contains the month day count in its lower 5 bits. The first +\ 12 values are for a normal year, the other 12 for a leap year. +data: month-to-days +hexb| 001F 03FC 077F 0B5E 0F1F 12FE 16BF 1A9F 1E7E 223F 261E 29DF | +hexb| 001F 03FD 079F 0B7E 0F3F 131E 16DF 1ABF 1E9E 225F 263E 29FF | + +\ Read a date (UTCTime or GeneralizedTime). The date value is converted +\ to a day count and a second count. The day count starts at 0 for +\ January 1st, 0 AD (that's they year before 1 AD, also known as 1 BC) +\ in a proleptic Gregorian calendar (i.e. Gregorian rules are assumed to +\ extend indefinitely in the past). The second count is between 0 and +\ 86400 (inclusive, in case of a leap second). +: read-date ( lim -- lim days seconds ) + \ Read tag; must be UTCTime or GeneralizedTime. Year count is + \ 4 digits with GeneralizedTime, 2 digits with UTCTime. + read-tag + dup 0x17 0x18 between? ifnot ERR_X509_BAD_TIME fail then + 0x18 = { y4d } + check-primitive + read-length-open-elt + + \ We compute the days and seconds counts during decoding, in + \ order to minimize the number of needed temporary variables. + { ; days seconds x } + + \ Year is 4-digit with GeneralizedTime. With UTCTime, the year + \ is in the 1950..2049 range, and only the last two digits are + \ present in the encoding. + read-dec2 + y4d if + 100 * >x read-dec2 x + + else + dup 50 < if 100 + then 1900 + + then + >x + x 365 * x 3 + 4 / + x 99 + 100 / - x 399 + 400 / + >days + + \ Month is 1..12. Number of days in a months depend on the + \ month and on the year (year count is in x at that point). + 1 12 read-dec2-range + 1- 1 << + x 4 % 0= x 100 % 0<> x 400 % 0= or and if 24 + then + month-to-days + data-get16 + dup 5 >> days + >days + 0x1F and + + \ Day. At this point, the TOS contains the maximum day count for + \ the current month. + 1 swap read-dec2-range + days + 1- >days + + \ Hour, minute and seconds. Count of seconds is allowed to go to + \ 60 in case of leap seconds (in practice, leap seconds really + \ occur only at the very end of the day, so this computation is + \ exact for a real leap second, and a spurious leap second only + \ implies a one-second shift that we can ignore). + 0 23 read-dec2-range 3600 * >seconds + 0 59 read-dec2-range 60 * seconds + >seconds + 0 60 read-dec2-range seconds + >seconds + + \ At this point, we may have fractional seconds. This should + \ happen only with GeneralizedTime, but we accept it for UTCTime + \ too (and, anyway, we ignore these fractional seconds). + read8 dup `. = if + drop + begin read8 dup `0 `9 between? while drop repeat + then + + \ The time zone should be 'Z', not followed by anything. Other + \ time zone indications are not DER and thus not supposed to + \ appear in certificates. + `Z <> if ERR_X509_BAD_TIME fail then + close-elt + days seconds ; + +\ Read an INTEGER (tag, length and value). The INTEGER is supposed to be +\ positive; its unsigned big-endian encoding is stored in the provided +\ in-context buffer. Returned value is the decoded length. If the integer +\ did not fit, or the value is negative, then an error is reported. +: read-integer ( lim addr len -- lim dlen ) + rot read-tag 0x02 check-tag-primitive -rot + read-integer-next ; + +\ Identical to read-integer, but the tag has already been read and checked. +: read-integer-next ( lim addr len -- lim dlen ) + dup { addr len origlen } + read-length-open-elt + \ Read first byte; sign bit must be 0. + read8 dup 0x80 >= if ERR_X509_OVERFLOW fail then + \ Skip leading bytes of value 0. If there are only bytes of + \ value 0, then return. + begin dup 0 = while + drop dup ifnot drop 0 ret then + read8 + repeat + \ At that point, we have the first non-zero byte on the stack. + begin + len dup ifnot ERR_X509_LIMIT_EXCEEDED fail then 1- >len + addr set8 addr 1+ >addr + dup while read8 + repeat + drop origlen len - ; + +\ Read a BOOLEAN value. This should be called immediately after reading +\ the tag. +: read-boolean ( lim constructed value -- lim bool ) + 0x01 check-tag-primitive + read-length 1 <> if ERR_X509_BAD_BOOLEAN fail then + read8 0<> ; + +\ Identify an elliptic curve: read the OID, then check it against the +\ known curve OID. +: read-curve-ID ( lim -- lim curve ) + read-OID ifnot ERR_X509_UNSUPPORTED fail then + choice + ansix9p256r1 eqOID uf 23 enduf + ansix9p384r1 eqOID uf 24 enduf + ansix9p521r1 eqOID uf 25 enduf + ERR_X509_UNSUPPORTED fail + endchoice ; + +\ A convenient debug word: print the current data stack contents. +cc: DEBUG ( -- ) { + extern int printf(const char *fmt, ...); + uint32_t *p; + + printf("dp_stack[0]; p != dp; p ++) { + printf(" %lu", (unsigned long)*p); + } + printf(" >\n"); +} diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/asn1enc.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/asn1enc.c new file mode 100644 index 000000000..00b531e6b --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/asn1enc.c @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +br_asn1_uint +br_asn1_uint_prepare(const void *xdata, size_t xlen) +{ + const unsigned char *x; + br_asn1_uint t; + + x = xdata; + while (xlen > 0 && *x == 0) { + x ++; + xlen --; + } + t.data = x; + t.len = xlen; + t.asn1len = xlen; + if (xlen == 0 || x[0] >= 0x80) { + t.asn1len ++; + } + return t; +} + +/* see inner.h */ +size_t +br_asn1_encode_length(void *dest, size_t len) +{ + unsigned char *buf; + size_t z; + int i, j; + + buf = dest; + if (len < 0x80) { + if (buf != NULL) { + *buf = len; + } + return 1; + } + i = 0; + for (z = len; z != 0; z >>= 8) { + i ++; + } + if (buf != NULL) { + *buf ++ = 0x80 + i; + for (j = i - 1; j >= 0; j --) { + *buf ++ = len >> (j << 3); + } + } + return i + 1; +} + +/* see inner.h */ +size_t +br_asn1_encode_uint(void *dest, br_asn1_uint pp) +{ + unsigned char *buf; + size_t lenlen; + + if (dest == NULL) { + return 1 + br_asn1_encode_length(NULL, pp.asn1len) + pp.asn1len; + } + buf = dest; + *buf ++ = 0x02; + lenlen = br_asn1_encode_length(buf, pp.asn1len); + buf += lenlen; + *buf = 0x00; + memcpy(buf + pp.asn1len - pp.len, pp.data, pp.len); + return 1 + lenlen + pp.asn1len; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/bearssl.h b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/bearssl.h new file mode 100644 index 000000000..cc1e52795 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/bearssl.h @@ -0,0 +1,175 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#ifndef BR_BEARSSL_H__ +#define BR_BEARSSL_H__ + +#include +#include + +/** \mainpage BearSSL API + * + * # API Layout + * + * The functions and structures defined by the BearSSL API are located + * in various header files: + * + * | Header file | Elements | + * | :-------------- | :------------------------------------------------ | + * | bearssl_hash.h | Hash functions | + * | bearssl_hmac.h | HMAC | + * | bearssl_kdf.h | Key Derivation Functions | + * | bearssl_rand.h | Pseudorandom byte generators | + * | bearssl_prf.h | PRF implementations (for SSL/TLS) | + * | bearssl_block.h | Symmetric encryption | + * | bearssl_aead.h | AEAD algorithms (combined encryption + MAC) | + * | bearssl_rsa.h | RSA encryption and signatures | + * | bearssl_ec.h | Elliptic curves support (including ECDSA) | + * | bearssl_ssl.h | SSL/TLS engine interface | + * | bearssl_x509.h | X.509 certificate decoding and validation | + * | bearssl_pem.h | Base64/PEM decoding support functions | + * + * Applications using BearSSL are supposed to simply include `bearssl.h` + * as follows: + * + * #include + * + * The `bearssl.h` file itself includes all the other header files. It is + * possible to include specific header files, but it has no practical + * advantage for the application. The API is separated into separate + * header files only for documentation convenience. + * + * + * # Conventions + * + * ## MUST and SHALL + * + * In all descriptions, the usual "MUST", "SHALL", "MAY",... terminology + * is used. Failure to meet requirements expressed with a "MUST" or + * "SHALL" implies undefined behaviour, which means that segmentation + * faults, buffer overflows, and other similar adverse events, may occur. + * + * In general, BearSSL is not very forgiving of programming errors, and + * does not include much failsafes or error reporting when the problem + * does not arise from external transient conditions, and can be fixed + * only in the application code. This is done so in order to make the + * total code footprint lighter. + * + * + * ## `NULL` values + * + * Function parameters with a pointer type shall not be `NULL` unless + * explicitly authorised by the documentation. As an exception, when + * the pointer aims at a sequence of bytes and is accompanied with + * a length parameter, and the length is zero (meaning that there is + * no byte at all to retrieve), then the pointer may be `NULL` even if + * not explicitly allowed. + * + * + * ## Memory Allocation + * + * BearSSL does not perform dynamic memory allocation. This implies that + * for any functionality that requires a non-transient state, the caller + * is responsible for allocating the relevant context structure. Such + * allocation can be done in any appropriate area, including static data + * segments, the heap, and the stack, provided that proper alignment is + * respected. The header files define these context structures + * (including size and contents), so the C compiler should handle + * alignment automatically. + * + * Since there is no dynamic resource allocation, there is also nothing to + * release. When the calling code is done with a BearSSL feature, it + * may simple release the context structures it allocated itself, with + * no "close function" to call. If the context structures were allocated + * on the stack (as local variables), then even that release operation is + * implicit. + * + * + * ## Structure Contents + * + * Except when explicitly indicated, structure contents are opaque: they + * are included in the header files so that calling code may know the + * structure sizes and alignment requirements, but callers SHALL NOT + * access individual fields directly. For fields that are supposed to + * be read from or written to, the API defines accessor functions (the + * simplest of these accessor functions are defined as `static inline` + * functions, and the C compiler will optimise them away). + * + * + * # API Usage + * + * BearSSL usage for running a SSL/TLS client or server is described + * on the [BearSSL Web site](https://www.bearssl.org/api1.html). The + * BearSSL source archive also comes with sample code. + */ + +#include "bearssl_hash.h" +#include "bearssl_hmac.h" +#include "bearssl_kdf.h" +#include "bearssl_rand.h" +#include "bearssl_prf.h" +#include "bearssl_block.h" +#include "bearssl_aead.h" +#include "bearssl_rsa.h" +#include "bearssl_ec.h" +#include "bearssl_ssl.h" +#include "bearssl_x509.h" +#include "bearssl_pem.h" + +/** \brief Type for a configuration option. + * + * A "configuration option" is a value that is selected when the BearSSL + * library itself is compiled. Most options are boolean; their value is + * then either 1 (option is enabled) or 0 (option is disabled). Some + * values have other integer values. Option names correspond to macro + * names. Some of the options can be explicitly set in the internal + * `"config.h"` file. + */ +typedef struct { + /** \brief Configurable option name. */ + const char *name; + /** \brief Configurable option value. */ + long value; +} br_config_option; + +/** \brief Get configuration report. + * + * This function returns compiled configuration options, each as a + * 'long' value. Names match internal macro names, in particular those + * that can be set in the `"config.h"` inner file. For boolean options, + * the numerical value is 1 if enabled, 0 if disabled. For maximum + * key sizes, values are expressed in bits. + * + * The returned array is terminated by an entry whose `name` is `NULL`. + * + * \return the configuration report. + */ +const br_config_option *br_get_config(void); + +#endif + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/bearssl_aead.h b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/bearssl_aead.h new file mode 100644 index 000000000..621de90e9 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/bearssl_aead.h @@ -0,0 +1,1064 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#ifndef BR_BEARSSL_AEAD_H__ +#define BR_BEARSSL_AEAD_H__ + +#include +#include + +#include "bearssl_block.h" +#include "bearssl_hash.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** \file bearssl_aead.h + * + * # Authenticated Encryption with Additional Data + * + * This file documents the API for AEAD encryption. + * + * + * ## Procedural API + * + * An AEAD algorithm processes messages and provides confidentiality + * (encryption) and checked integrity (MAC). It uses the following + * parameters: + * + * - A symmetric key. Exact size depends on the AEAD algorithm. + * + * - A nonce (IV). Size depends on the AEAD algorithm; for most + * algorithms, it is crucial for security that any given nonce + * value is never used twice for the same key and distinct + * messages. + * + * - Data to encrypt and protect. + * + * - Additional authenticated data, which is covered by the MAC but + * otherwise left untouched (i.e. not encrypted). + * + * The AEAD algorithm encrypts the data, and produces an authentication + * tag. It is assumed that the encrypted data, the tag, the additional + * authenticated data and the nonce are sent to the receiver; the + * additional data and the nonce may be implicit (e.g. using elements of + * the underlying transport protocol, such as record sequence numbers). + * The receiver will recompute the tag value and compare it with the one + * received; if they match, then the data is correct, and can be + * decrypted and used; otherwise, at least one of the elements was + * altered in transit, normally leading to wholesale rejection of the + * complete message. + * + * For each AEAD algorithm, identified by a symbolic name (hereafter + * denoted as "`xxx`"), the following functions are defined: + * + * - `br_xxx_init()` + * + * Initialise the AEAD algorithm, on a provided context structure. + * Exact parameters depend on the algorithm, and may include + * pointers to extra implementations and context structures. The + * secret key is provided at this point, either directly or + * indirectly. + * + * - `br_xxx_reset()` + * + * Start a new AEAD computation. The nonce value is provided as + * parameter to this function. + * + * - `br_xxx_aad_inject()` + * + * Inject some additional authenticated data. Additional data may + * be provided in several chunks of arbitrary length. + * + * - `br_xxx_flip()` + * + * This function MUST be called after injecting all additional + * authenticated data, and before beginning to encrypt the plaintext + * (or decrypt the ciphertext). + * + * - `br_xxx_run()` + * + * Process some plaintext (to encrypt) or ciphertext (to decrypt). + * Encryption/decryption is done in place. Data may be provided in + * several chunks of arbitrary length. + * + * - `br_xxx_get_tag()` + * + * Compute the authentication tag. All message data (encrypted or + * decrypted) must have been injected at that point. Also, this + * call may modify internal context elements, so it may be called + * only once for a given AEAD computation. + * + * - `br_xxx_check_tag()` + * + * An alternative to `br_xxx_get_tag()`, meant to be used by the + * receiver: the authentication tag is internally recomputed, and + * compared with the one provided as parameter. + * + * This API makes the following assumptions on the AEAD algorithm: + * + * - Encryption does not expand the size of the ciphertext; there is + * no padding. This is true of most modern AEAD modes such as GCM. + * + * - The additional authenticated data must be processed first, + * before the encrypted/decrypted data. + * + * - Nonce, plaintext and additional authenticated data all consist + * in an integral number of bytes. There is no provision to use + * elements whose length in bits is not a multiple of 8. + * + * Each AEAD algorithm has its own requirements and limits on the sizes + * of additional data and plaintext. This API does not provide any + * way to report invalid usage; it is up to the caller to ensure that + * the provided key, nonce, and data elements all fit the algorithm's + * requirements. + * + * + * ## Object-Oriented API + * + * Each context structure begins with a field (called `vtable`) that + * points to an instance of a structure that references the relevant + * functions through pointers. Each such structure contains the + * following: + * + * - `reset` + * + * Pointer to the reset function, that allows starting a new + * computation. + * + * - `aad_inject` + * + * Pointer to the additional authenticated data injection function. + * + * - `flip` + * + * Pointer to the function that transitions from additional data + * to main message data processing. + * + * - `get_tag` + * + * Pointer to the function that computes and returns the tag. + * + * - `check_tag` + * + * Pointer to the function that computes and verifies the tag against + * a received value. + * + * Note that there is no OOP method for context initialisation: the + * various AEAD algorithms have different requirements that would not + * map well to a single initialisation API. + * + * The OOP API is not provided for CCM, due to its specific requirements + * (length of plaintext must be known in advance). + */ + +/** + * \brief Class type of an AEAD algorithm. + */ +typedef struct br_aead_class_ br_aead_class; +struct br_aead_class_ { + + /** + * \brief Size (in bytes) of authentication tags created by + * this AEAD algorithm. + */ + size_t tag_size; + + /** + * \brief Reset an AEAD context. + * + * This function resets an already initialised AEAD context for + * a new computation run. Implementations and keys are + * conserved. This function can be called at any time; it + * cancels any ongoing AEAD computation that uses the provided + * context structure. + + * The provided IV is a _nonce_. Each AEAD algorithm has its + * own requirements on IV size and contents; for most of them, + * it is crucial to security that each nonce value is used + * only once for a given secret key. + * + * \param cc AEAD context structure. + * \param iv AEAD nonce to use. + * \param len AEAD nonce length (in bytes). + */ + void (*reset)(const br_aead_class **cc, const void *iv, size_t len); + + /** + * \brief Inject additional authenticated data. + * + * The provided data is injected into a running AEAD + * computation. Additional data must be injected _before_ the + * call to `flip()`. Additional data can be injected in several + * chunks of arbitrary length. + * + * \param cc AEAD context structure. + * \param data pointer to additional authenticated data. + * \param len length of additional authenticated data (in bytes). + */ + void (*aad_inject)(const br_aead_class **cc, + const void *data, size_t len); + + /** + * \brief Finish injection of additional authenticated data. + * + * This function MUST be called before beginning the actual + * encryption or decryption (with `run()`), even if no + * additional authenticated data was injected. No additional + * authenticated data may be injected after this function call. + * + * \param cc AEAD context structure. + */ + void (*flip)(const br_aead_class **cc); + + /** + * \brief Encrypt or decrypt some data. + * + * Data encryption or decryption can be done after `flip()` has + * been called on the context. If `encrypt` is non-zero, then + * the provided data shall be plaintext, and it is encrypted in + * place. Otherwise, the data shall be ciphertext, and it is + * decrypted in place. + * + * Data may be provided in several chunks of arbitrary length. + * + * \param cc AEAD context structure. + * \param encrypt non-zero for encryption, zero for decryption. + * \param data data to encrypt or decrypt. + * \param len data length (in bytes). + */ + void (*run)(const br_aead_class **cc, int encrypt, + void *data, size_t len); + + /** + * \brief Compute authentication tag. + * + * Compute the AEAD authentication tag. The tag length depends + * on the AEAD algorithm; it is written in the provided `tag` + * buffer. This call terminates the AEAD run: no data may be + * processed with that AEAD context afterwards, until `reset()` + * is called to initiate a new AEAD run. + * + * The tag value must normally be sent along with the encrypted + * data. When decrypting, the tag value must be recomputed and + * compared with the received tag: if the two tag values differ, + * then either the tag or the encrypted data was altered in + * transit. As an alternative to this function, the + * `check_tag()` function may be used to compute and check the + * tag value. + * + * Tag length depends on the AEAD algorithm. + * + * \param cc AEAD context structure. + * \param tag destination buffer for the tag. + */ + void (*get_tag)(const br_aead_class **cc, void *tag); + + /** + * \brief Compute and check authentication tag. + * + * This function is an alternative to `get_tag()`, and is + * normally used on the receiving end (i.e. when decrypting + * messages). The tag value is recomputed and compared with the + * provided tag value. If they match, 1 is returned; on + * mismatch, 0 is returned. A returned value of 0 means that the + * data or the tag was altered in transit, normally leading to + * wholesale rejection of the complete message. + * + * Tag length depends on the AEAD algorithm. + * + * \param cc AEAD context structure. + * \param tag tag value to compare with. + * \return 1 on success (exact match of tag value), 0 otherwise. + */ + uint32_t (*check_tag)(const br_aead_class **cc, const void *tag); + + /** + * \brief Compute authentication tag (with truncation). + * + * This function is similar to `get_tag()`, except that the tag + * length is provided. Some AEAD algorithms allow several tag + * lengths, usually by truncating the normal tag. Shorter tags + * mechanically increase success probability of forgeries. + * The range of allowed tag lengths depends on the algorithm. + * + * \param cc AEAD context structure. + * \param tag destination buffer for the tag. + * \param len tag length (in bytes). + */ + void (*get_tag_trunc)(const br_aead_class **cc, void *tag, size_t len); + + /** + * \brief Compute and check authentication tag (with truncation). + * + * This function is similar to `check_tag()` except that it + * works over an explicit tag length. See `get_tag()` for a + * discussion of explicit tag lengths; the range of allowed tag + * lengths depends on the algorithm. + * + * \param cc AEAD context structure. + * \param tag tag value to compare with. + * \param len tag length (in bytes). + * \return 1 on success (exact match of tag value), 0 otherwise. + */ + uint32_t (*check_tag_trunc)(const br_aead_class **cc, + const void *tag, size_t len); +}; + +/** + * \brief Context structure for GCM. + * + * GCM is an AEAD mode that combines a block cipher in CTR mode with a + * MAC based on GHASH, to provide authenticated encryption: + * + * - Any block cipher with 16-byte blocks can be used with GCM. + * + * - The nonce can have any length, from 0 up to 2^64-1 bits; however, + * 96-bit nonces (12 bytes) are recommended (nonces with a length + * distinct from 12 bytes are internally hashed, which risks reusing + * nonce value with a small but not always negligible probability). + * + * - Additional authenticated data may have length up to 2^64-1 bits. + * + * - Message length may range up to 2^39-256 bits at most. + * + * - The authentication tag has length 16 bytes. + * + * The GCM initialisation function receives as parameter an + * _initialised_ block cipher implementation context, with the secret + * key already set. A pointer to that context will be kept within the + * GCM context structure. It is up to the caller to allocate and + * initialise that block cipher context. + */ +typedef struct { + /** \brief Pointer to vtable for this context. */ + const br_aead_class *vtable; + +#ifndef BR_DOXYGEN_IGNORE + const br_block_ctr_class **bctx; + br_ghash gh; + unsigned char h[16]; + unsigned char j0_1[12]; + unsigned char buf[16]; + unsigned char y[16]; + uint32_t j0_2, jc; + uint64_t count_aad, count_ctr; +#endif +} br_gcm_context; + +/** + * \brief Initialize a GCM context. + * + * A block cipher implementation, with its initialised context structure, + * is provided. The block cipher MUST use 16-byte blocks in CTR mode, + * and its secret key MUST have been already set in the provided context. + * A GHASH implementation must also be provided. The parameters are linked + * in the GCM context. + * + * After this function has been called, the `br_gcm_reset()` function must + * be called, to provide the IV for GCM computation. + * + * \param ctx GCM context structure. + * \param bctx block cipher context (already initialised with secret key). + * \param gh GHASH implementation. + */ +void br_gcm_init(br_gcm_context *ctx, + const br_block_ctr_class **bctx, br_ghash gh); + +/** + * \brief Reset a GCM context. + * + * This function resets an already initialised GCM context for a new + * computation run. Implementations and keys are conserved. This function + * can be called at any time; it cancels any ongoing GCM computation that + * uses the provided context structure. + * + * The provided IV is a _nonce_. It is critical to GCM security that IV + * values are not repeated for the same encryption key. IV can have + * arbitrary length (up to 2^64-1 bits), but the "normal" length is + * 96 bits (12 bytes). + * + * \param ctx GCM context structure. + * \param iv GCM nonce to use. + * \param len GCM nonce length (in bytes). + */ +void br_gcm_reset(br_gcm_context *ctx, const void *iv, size_t len); + +/** + * \brief Inject additional authenticated data into GCM. + * + * The provided data is injected into a running GCM computation. Additional + * data must be injected _before_ the call to `br_gcm_flip()`. + * Additional data can be injected in several chunks of arbitrary length; + * the maximum total size of additional authenticated data is 2^64-1 + * bits. + * + * \param ctx GCM context structure. + * \param data pointer to additional authenticated data. + * \param len length of additional authenticated data (in bytes). + */ +void br_gcm_aad_inject(br_gcm_context *ctx, const void *data, size_t len); + +/** + * \brief Finish injection of additional authenticated data into GCM. + * + * This function MUST be called before beginning the actual encryption + * or decryption (with `br_gcm_run()`), even if no additional authenticated + * data was injected. No additional authenticated data may be injected + * after this function call. + * + * \param ctx GCM context structure. + */ +void br_gcm_flip(br_gcm_context *ctx); + +/** + * \brief Encrypt or decrypt some data with GCM. + * + * Data encryption or decryption can be done after `br_gcm_flip()` + * has been called on the context. If `encrypt` is non-zero, then the + * provided data shall be plaintext, and it is encrypted in place. + * Otherwise, the data shall be ciphertext, and it is decrypted in place. + * + * Data may be provided in several chunks of arbitrary length. The maximum + * total length for data is 2^39-256 bits, i.e. about 65 gigabytes. + * + * \param ctx GCM context structure. + * \param encrypt non-zero for encryption, zero for decryption. + * \param data data to encrypt or decrypt. + * \param len data length (in bytes). + */ +void br_gcm_run(br_gcm_context *ctx, int encrypt, void *data, size_t len); + +/** + * \brief Compute GCM authentication tag. + * + * Compute the GCM authentication tag. The tag is a 16-byte value which + * is written in the provided `tag` buffer. This call terminates the + * GCM run: no data may be processed with that GCM context afterwards, + * until `br_gcm_reset()` is called to initiate a new GCM run. + * + * The tag value must normally be sent along with the encrypted data. + * When decrypting, the tag value must be recomputed and compared with + * the received tag: if the two tag values differ, then either the tag + * or the encrypted data was altered in transit. As an alternative to + * this function, the `br_gcm_check_tag()` function can be used to + * compute and check the tag value. + * + * \param ctx GCM context structure. + * \param tag destination buffer for the tag (16 bytes). + */ +void br_gcm_get_tag(br_gcm_context *ctx, void *tag); + +/** + * \brief Compute and check GCM authentication tag. + * + * This function is an alternative to `br_gcm_get_tag()`, normally used + * on the receiving end (i.e. when decrypting value). The tag value is + * recomputed and compared with the provided tag value. If they match, 1 + * is returned; on mismatch, 0 is returned. A returned value of 0 means + * that the data or the tag was altered in transit, normally leading to + * wholesale rejection of the complete message. + * + * \param ctx GCM context structure. + * \param tag tag value to compare with (16 bytes). + * \return 1 on success (exact match of tag value), 0 otherwise. + */ +uint32_t br_gcm_check_tag(br_gcm_context *ctx, const void *tag); + +/** + * \brief Compute GCM authentication tag (with truncation). + * + * This function is similar to `br_gcm_get_tag()`, except that it allows + * the tag to be truncated to a smaller length. The intended tag length + * is provided as `len` (in bytes); it MUST be no more than 16, but + * it may be smaller. Note that decreasing tag length mechanically makes + * forgeries easier; NIST SP 800-38D specifies that the tag length shall + * lie between 12 and 16 bytes (inclusive), but may be truncated down to + * 4 or 8 bytes, for specific applications that can tolerate it. It must + * also be noted that successful forgeries leak information on the + * authentication key, making subsequent forgeries easier. Therefore, + * tag truncation, and in particular truncation to sizes lower than 12 + * bytes, shall be envisioned only with great care. + * + * The tag is written in the provided `tag` buffer. This call terminates + * the GCM run: no data may be processed with that GCM context + * afterwards, until `br_gcm_reset()` is called to initiate a new GCM + * run. + * + * The tag value must normally be sent along with the encrypted data. + * When decrypting, the tag value must be recomputed and compared with + * the received tag: if the two tag values differ, then either the tag + * or the encrypted data was altered in transit. As an alternative to + * this function, the `br_gcm_check_tag_trunc()` function can be used to + * compute and check the tag value. + * + * \param ctx GCM context structure. + * \param tag destination buffer for the tag. + * \param len tag length (16 bytes or less). + */ +void br_gcm_get_tag_trunc(br_gcm_context *ctx, void *tag, size_t len); + +/** + * \brief Compute and check GCM authentication tag (with truncation). + * + * This function is an alternative to `br_gcm_get_tag_trunc()`, normally used + * on the receiving end (i.e. when decrypting value). The tag value is + * recomputed and compared with the provided tag value. If they match, 1 + * is returned; on mismatch, 0 is returned. A returned value of 0 means + * that the data or the tag was altered in transit, normally leading to + * wholesale rejection of the complete message. + * + * Tag length MUST be 16 bytes or less. The normal GCM tag length is 16 + * bytes. See `br_check_tag_trunc()` for some discussion on the potential + * perils of truncating authentication tags. + * + * \param ctx GCM context structure. + * \param tag tag value to compare with. + * \param len tag length (in bytes). + * \return 1 on success (exact match of tag value), 0 otherwise. + */ +uint32_t br_gcm_check_tag_trunc(br_gcm_context *ctx, + const void *tag, size_t len); + +/** + * \brief Class instance for GCM. + */ +extern const br_aead_class br_gcm_vtable; + +/** + * \brief Context structure for EAX. + * + * EAX is an AEAD mode that combines a block cipher in CTR mode with + * CBC-MAC using the same block cipher and the same key, to provide + * authenticated encryption: + * + * - Any block cipher with 16-byte blocks can be used with EAX + * (technically, other block sizes are defined as well, but this + * is not implemented by these functions; shorter blocks also + * imply numerous security issues). + * + * - The nonce can have any length, as long as nonce values are + * not reused (thus, if nonces are randomly selected, the nonce + * size should be such that reuse probability is negligible). + * + * - Additional authenticated data length is unlimited. + * + * - Message length is unlimited. + * + * - The authentication tag has length 16 bytes. + * + * The EAX initialisation function receives as parameter an + * _initialised_ block cipher implementation context, with the secret + * key already set. A pointer to that context will be kept within the + * EAX context structure. It is up to the caller to allocate and + * initialise that block cipher context. + */ +typedef struct { + /** \brief Pointer to vtable for this context. */ + const br_aead_class *vtable; + +#ifndef BR_DOXYGEN_IGNORE + const br_block_ctrcbc_class **bctx; + unsigned char L2[16]; + unsigned char L4[16]; + unsigned char nonce[16]; + unsigned char head[16]; + unsigned char ctr[16]; + unsigned char cbcmac[16]; + unsigned char buf[16]; + size_t ptr; +#endif +} br_eax_context; + +/** + * \brief EAX captured state. + * + * Some internal values computed by EAX may be captured at various + * points, and reused for another EAX run with the same secret key, + * for lower per-message overhead. Captured values do not depend on + * the nonce. + */ +typedef struct { +#ifndef BR_DOXYGEN_IGNORE + unsigned char st[3][16]; +#endif +} br_eax_state; + +/** + * \brief Initialize an EAX context. + * + * A block cipher implementation, with its initialised context + * structure, is provided. The block cipher MUST use 16-byte blocks in + * CTR + CBC-MAC mode, and its secret key MUST have been already set in + * the provided context. The parameters are linked in the EAX context. + * + * After this function has been called, the `br_eax_reset()` function must + * be called, to provide the nonce for EAX computation. + * + * \param ctx EAX context structure. + * \param bctx block cipher context (already initialised with secret key). + */ +void br_eax_init(br_eax_context *ctx, const br_block_ctrcbc_class **bctx); + +/** + * \brief Capture pre-AAD state. + * + * This function precomputes key-dependent data, and stores it in the + * provided `st` structure. This structure should then be used with + * `br_eax_reset_pre_aad()`, or updated with `br_eax_get_aad_mac()` + * and then used with `br_eax_reset_post_aad()`. + * + * The EAX context structure is unmodified by this call. + * + * \param ctx EAX context structure. + * \param st recipient for captured state. + */ +void br_eax_capture(const br_eax_context *ctx, br_eax_state *st); + +/** + * \brief Reset an EAX context. + * + * This function resets an already initialised EAX context for a new + * computation run. Implementations and keys are conserved. This function + * can be called at any time; it cancels any ongoing EAX computation that + * uses the provided context structure. + * + * It is critical to EAX security that nonce values are not repeated for + * the same encryption key. Nonces can have arbitrary length. If nonces + * are randomly generated, then a nonce length of at least 128 bits (16 + * bytes) is recommended, to make nonce reuse probability sufficiently + * low. + * + * \param ctx EAX context structure. + * \param nonce EAX nonce to use. + * \param len EAX nonce length (in bytes). + */ +void br_eax_reset(br_eax_context *ctx, const void *nonce, size_t len); + +/** + * \brief Reset an EAX context with a pre-AAD captured state. + * + * This function is an alternative to `br_eax_reset()`, that reuses a + * previously captured state structure for lower per-message overhead. + * The state should have been populated with `br_eax_capture_state()` + * but not updated with `br_eax_get_aad_mac()`. + * + * After this function is called, additional authenticated data MUST + * be injected. At least one byte of additional authenticated data + * MUST be provided with `br_eax_aad_inject()`; computation result will + * be incorrect if `br_eax_flip()` is called right away. + * + * After injection of the AAD and call to `br_eax_flip()`, at least + * one message byte must be provided. Empty messages are not supported + * with this reset mode. + * + * \param ctx EAX context structure. + * \param st pre-AAD captured state. + * \param nonce EAX nonce to use. + * \param len EAX nonce length (in bytes). + */ +void br_eax_reset_pre_aad(br_eax_context *ctx, const br_eax_state *st, + const void *nonce, size_t len); + +/** + * \brief Reset an EAX context with a post-AAD captured state. + * + * This function is an alternative to `br_eax_reset()`, that reuses a + * previously captured state structure for lower per-message overhead. + * The state should have been populated with `br_eax_capture_state()` + * and then updated with `br_eax_get_aad_mac()`. + * + * After this function is called, message data MUST be injected. The + * `br_eax_flip()` function MUST NOT be called. At least one byte of + * message data MUST be provided with `br_eax_run()`; empty messages + * are not supported with this reset mode. + * + * \param ctx EAX context structure. + * \param st post-AAD captured state. + * \param nonce EAX nonce to use. + * \param len EAX nonce length (in bytes). + */ +void br_eax_reset_post_aad(br_eax_context *ctx, const br_eax_state *st, + const void *nonce, size_t len); + +/** + * \brief Inject additional authenticated data into EAX. + * + * The provided data is injected into a running EAX computation. Additional + * data must be injected _before_ the call to `br_eax_flip()`. + * Additional data can be injected in several chunks of arbitrary length; + * the total amount of additional authenticated data is unlimited. + * + * \param ctx EAX context structure. + * \param data pointer to additional authenticated data. + * \param len length of additional authenticated data (in bytes). + */ +void br_eax_aad_inject(br_eax_context *ctx, const void *data, size_t len); + +/** + * \brief Finish injection of additional authenticated data into EAX. + * + * This function MUST be called before beginning the actual encryption + * or decryption (with `br_eax_run()`), even if no additional authenticated + * data was injected. No additional authenticated data may be injected + * after this function call. + * + * \param ctx EAX context structure. + */ +void br_eax_flip(br_eax_context *ctx); + +/** + * \brief Obtain a copy of the MAC on additional authenticated data. + * + * This function may be called only after `br_eax_flip()`; it copies the + * AAD-specific MAC value into the provided state. The MAC value depends + * on the secret key and the additional data itself, but not on the + * nonce. The updated state `st` is meant to be used as parameter for a + * further `br_eax_reset_post_aad()` call. + * + * \param ctx EAX context structure. + * \param st captured state to update. + */ +static inline void +br_eax_get_aad_mac(const br_eax_context *ctx, br_eax_state *st) +{ + memcpy(st->st[1], ctx->head, sizeof ctx->head); +} + +/** + * \brief Encrypt or decrypt some data with EAX. + * + * Data encryption or decryption can be done after `br_eax_flip()` + * has been called on the context. If `encrypt` is non-zero, then the + * provided data shall be plaintext, and it is encrypted in place. + * Otherwise, the data shall be ciphertext, and it is decrypted in place. + * + * Data may be provided in several chunks of arbitrary length. + * + * \param ctx EAX context structure. + * \param encrypt non-zero for encryption, zero for decryption. + * \param data data to encrypt or decrypt. + * \param len data length (in bytes). + */ +void br_eax_run(br_eax_context *ctx, int encrypt, void *data, size_t len); + +/** + * \brief Compute EAX authentication tag. + * + * Compute the EAX authentication tag. The tag is a 16-byte value which + * is written in the provided `tag` buffer. This call terminates the + * EAX run: no data may be processed with that EAX context afterwards, + * until `br_eax_reset()` is called to initiate a new EAX run. + * + * The tag value must normally be sent along with the encrypted data. + * When decrypting, the tag value must be recomputed and compared with + * the received tag: if the two tag values differ, then either the tag + * or the encrypted data was altered in transit. As an alternative to + * this function, the `br_eax_check_tag()` function can be used to + * compute and check the tag value. + * + * \param ctx EAX context structure. + * \param tag destination buffer for the tag (16 bytes). + */ +void br_eax_get_tag(br_eax_context *ctx, void *tag); + +/** + * \brief Compute and check EAX authentication tag. + * + * This function is an alternative to `br_eax_get_tag()`, normally used + * on the receiving end (i.e. when decrypting value). The tag value is + * recomputed and compared with the provided tag value. If they match, 1 + * is returned; on mismatch, 0 is returned. A returned value of 0 means + * that the data or the tag was altered in transit, normally leading to + * wholesale rejection of the complete message. + * + * \param ctx EAX context structure. + * \param tag tag value to compare with (16 bytes). + * \return 1 on success (exact match of tag value), 0 otherwise. + */ +uint32_t br_eax_check_tag(br_eax_context *ctx, const void *tag); + +/** + * \brief Compute EAX authentication tag (with truncation). + * + * This function is similar to `br_eax_get_tag()`, except that it allows + * the tag to be truncated to a smaller length. The intended tag length + * is provided as `len` (in bytes); it MUST be no more than 16, but + * it may be smaller. Note that decreasing tag length mechanically makes + * forgeries easier; NIST SP 800-38D specifies that the tag length shall + * lie between 12 and 16 bytes (inclusive), but may be truncated down to + * 4 or 8 bytes, for specific applications that can tolerate it. It must + * also be noted that successful forgeries leak information on the + * authentication key, making subsequent forgeries easier. Therefore, + * tag truncation, and in particular truncation to sizes lower than 12 + * bytes, shall be envisioned only with great care. + * + * The tag is written in the provided `tag` buffer. This call terminates + * the EAX run: no data may be processed with that EAX context + * afterwards, until `br_eax_reset()` is called to initiate a new EAX + * run. + * + * The tag value must normally be sent along with the encrypted data. + * When decrypting, the tag value must be recomputed and compared with + * the received tag: if the two tag values differ, then either the tag + * or the encrypted data was altered in transit. As an alternative to + * this function, the `br_eax_check_tag_trunc()` function can be used to + * compute and check the tag value. + * + * \param ctx EAX context structure. + * \param tag destination buffer for the tag. + * \param len tag length (16 bytes or less). + */ +void br_eax_get_tag_trunc(br_eax_context *ctx, void *tag, size_t len); + +/** + * \brief Compute and check EAX authentication tag (with truncation). + * + * This function is an alternative to `br_eax_get_tag_trunc()`, normally used + * on the receiving end (i.e. when decrypting value). The tag value is + * recomputed and compared with the provided tag value. If they match, 1 + * is returned; on mismatch, 0 is returned. A returned value of 0 means + * that the data or the tag was altered in transit, normally leading to + * wholesale rejection of the complete message. + * + * Tag length MUST be 16 bytes or less. The normal EAX tag length is 16 + * bytes. See `br_check_tag_trunc()` for some discussion on the potential + * perils of truncating authentication tags. + * + * \param ctx EAX context structure. + * \param tag tag value to compare with. + * \param len tag length (in bytes). + * \return 1 on success (exact match of tag value), 0 otherwise. + */ +uint32_t br_eax_check_tag_trunc(br_eax_context *ctx, + const void *tag, size_t len); + +/** + * \brief Class instance for EAX. + */ +extern const br_aead_class br_eax_vtable; + +/** + * \brief Context structure for CCM. + * + * CCM is an AEAD mode that combines a block cipher in CTR mode with + * CBC-MAC using the same block cipher and the same key, to provide + * authenticated encryption: + * + * - Any block cipher with 16-byte blocks can be used with CCM + * (technically, other block sizes are defined as well, but this + * is not implemented by these functions; shorter blocks also + * imply numerous security issues). + * + * - The authentication tag length, and plaintext length, MUST be + * known when starting processing data. Plaintext and ciphertext + * can still be provided by chunks, but the total size must match + * the value provided upon initialisation. + * + * - The nonce length is constrained between 7 and 13 bytes (inclusive). + * Furthermore, the plaintext length, when encoded, must fit over + * 15-nonceLen bytes; thus, if the nonce has length 13 bytes, then + * the plaintext length cannot exceed 65535 bytes. + * + * - Additional authenticated data length is practically unlimited + * (formal limit is at 2^64 bytes). + * + * - The authentication tag has length 4 to 16 bytes (even values only). + * + * The CCM initialisation function receives as parameter an + * _initialised_ block cipher implementation context, with the secret + * key already set. A pointer to that context will be kept within the + * CCM context structure. It is up to the caller to allocate and + * initialise that block cipher context. + */ +typedef struct { +#ifndef BR_DOXYGEN_IGNORE + const br_block_ctrcbc_class **bctx; + unsigned char ctr[16]; + unsigned char cbcmac[16]; + unsigned char tagmask[16]; + unsigned char buf[16]; + size_t ptr; + size_t tag_len; +#endif +} br_ccm_context; + +/** + * \brief Initialize a CCM context. + * + * A block cipher implementation, with its initialised context + * structure, is provided. The block cipher MUST use 16-byte blocks in + * CTR + CBC-MAC mode, and its secret key MUST have been already set in + * the provided context. The parameters are linked in the CCM context. + * + * After this function has been called, the `br_ccm_reset()` function must + * be called, to provide the nonce for CCM computation. + * + * \param ctx CCM context structure. + * \param bctx block cipher context (already initialised with secret key). + */ +void br_ccm_init(br_ccm_context *ctx, const br_block_ctrcbc_class **bctx); + +/** + * \brief Reset a CCM context. + * + * This function resets an already initialised CCM context for a new + * computation run. Implementations and keys are conserved. This function + * can be called at any time; it cancels any ongoing CCM computation that + * uses the provided context structure. + * + * The `aad_len` parameter contains the total length, in bytes, of the + * additional authenticated data. It may be zero. That length MUST be + * exact. + * + * The `data_len` parameter contains the total length, in bytes, of the + * data that will be injected (plaintext or ciphertext). That length MUST + * be exact. Moreover, that length MUST be less than 2^(8*(15-nonce_len)). + * + * The nonce length (`nonce_len`), in bytes, must be in the 7..13 range + * (inclusive). + * + * The tag length (`tag_len`), in bytes, must be in the 4..16 range, and + * be an even integer. Short tags mechanically allow for higher forgery + * probabilities; hence, tag sizes smaller than 12 bytes shall be used only + * with care. + * + * It is critical to CCM security that nonce values are not repeated for + * the same encryption key. Random generation of nonces is not generally + * recommended, due to the relatively small maximum nonce value. + * + * Returned value is 1 on success, 0 on error. An error is reported if + * the tag or nonce length is out of range, or if the + * plaintext/ciphertext length cannot be encoded with the specified + * nonce length. + * + * \param ctx CCM context structure. + * \param nonce CCM nonce to use. + * \param nonce_len CCM nonce length (in bytes, 7 to 13). + * \param aad_len additional authenticated data length (in bytes). + * \param data_len plaintext/ciphertext length (in bytes). + * \param tag_len tag length (in bytes). + * \return 1 on success, 0 on error. + */ +int br_ccm_reset(br_ccm_context *ctx, const void *nonce, size_t nonce_len, + uint64_t aad_len, uint64_t data_len, size_t tag_len); + +/** + * \brief Inject additional authenticated data into CCM. + * + * The provided data is injected into a running CCM computation. Additional + * data must be injected _before_ the call to `br_ccm_flip()`. + * Additional data can be injected in several chunks of arbitrary length, + * but the total amount MUST exactly match the value which was provided + * to `br_ccm_reset()`. + * + * \param ctx CCM context structure. + * \param data pointer to additional authenticated data. + * \param len length of additional authenticated data (in bytes). + */ +void br_ccm_aad_inject(br_ccm_context *ctx, const void *data, size_t len); + +/** + * \brief Finish injection of additional authenticated data into CCM. + * + * This function MUST be called before beginning the actual encryption + * or decryption (with `br_ccm_run()`), even if no additional authenticated + * data was injected. No additional authenticated data may be injected + * after this function call. + * + * \param ctx CCM context structure. + */ +void br_ccm_flip(br_ccm_context *ctx); + +/** + * \brief Encrypt or decrypt some data with CCM. + * + * Data encryption or decryption can be done after `br_ccm_flip()` + * has been called on the context. If `encrypt` is non-zero, then the + * provided data shall be plaintext, and it is encrypted in place. + * Otherwise, the data shall be ciphertext, and it is decrypted in place. + * + * Data may be provided in several chunks of arbitrary length, provided + * that the total length exactly matches the length provided to the + * `br_ccm_reset()` call. + * + * \param ctx CCM context structure. + * \param encrypt non-zero for encryption, zero for decryption. + * \param data data to encrypt or decrypt. + * \param len data length (in bytes). + */ +void br_ccm_run(br_ccm_context *ctx, int encrypt, void *data, size_t len); + +/** + * \brief Compute CCM authentication tag. + * + * Compute the CCM authentication tag. This call terminates the CCM + * run: all data must have been injected with `br_ccm_run()` (in zero, + * one or more successive calls). After this function has been called, + * no more data can br processed; a `br_ccm_reset()` call is required + * to start a new message. + * + * The tag length was provided upon context initialisation (last call + * to `br_ccm_reset()`); it is returned by this function. + * + * The tag value must normally be sent along with the encrypted data. + * When decrypting, the tag value must be recomputed and compared with + * the received tag: if the two tag values differ, then either the tag + * or the encrypted data was altered in transit. As an alternative to + * this function, the `br_ccm_check_tag()` function can be used to + * compute and check the tag value. + * + * \param ctx CCM context structure. + * \param tag destination buffer for the tag (up to 16 bytes). + * \return the tag length (in bytes). + */ +size_t br_ccm_get_tag(br_ccm_context *ctx, void *tag); + +/** + * \brief Compute and check CCM authentication tag. + * + * This function is an alternative to `br_ccm_get_tag()`, normally used + * on the receiving end (i.e. when decrypting value). The tag value is + * recomputed and compared with the provided tag value. If they match, 1 + * is returned; on mismatch, 0 is returned. A returned value of 0 means + * that the data or the tag was altered in transit, normally leading to + * wholesale rejection of the complete message. + * + * \param ctx CCM context structure. + * \param tag tag value to compare with (up to 16 bytes). + * \return 1 on success (exact match of tag value), 0 otherwise. + */ +uint32_t br_ccm_check_tag(br_ccm_context *ctx, const void *tag); + +#ifdef __cplusplus +} +#endif + +#endif + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/bearssl_block.h b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/bearssl_block.h new file mode 100644 index 000000000..22a9434ee --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/bearssl_block.h @@ -0,0 +1,2623 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#ifndef BR_BEARSSL_BLOCK_H__ +#define BR_BEARSSL_BLOCK_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** \file bearssl_block.h + * + * # Block Ciphers and Symmetric Ciphers + * + * This file documents the API for block ciphers and other symmetric + * ciphers. + * + * + * ## Procedural API + * + * For a block cipher implementation, up to three separate sets of + * functions are provided, for CBC encryption, CBC decryption, and CTR + * encryption/decryption. Each set has its own context structure, + * initialised with the encryption key. + * + * For CBC encryption and decryption, the data to encrypt or decrypt is + * referenced as a sequence of blocks. The implementations assume that + * there is no partial block; no padding is applied or removed. The + * caller is responsible for handling any kind of padding. + * + * Function for CTR encryption are defined only for block ciphers with + * blocks of 16 bytes or more (i.e. AES, but not DES/3DES). + * + * Each implemented block cipher is identified by an "internal name" + * from which are derived the names of structures and functions that + * implement the cipher. For the block cipher of internal name "`xxx`", + * the following are defined: + * + * - `br_xxx_BLOCK_SIZE` + * + * A macro that evaluates to the block size (in bytes) of the + * cipher. For all implemented block ciphers, this value is a + * power of two. + * + * - `br_xxx_cbcenc_keys` + * + * Context structure that contains the subkeys resulting from the key + * expansion. These subkeys are appropriate for CBC encryption. The + * structure first field is called `vtable` and points to the + * appropriate OOP structure. + * + * - `br_xxx_cbcenc_init(br_xxx_cbcenc_keys *ctx, const void *key, size_t len)` + * + * Perform key expansion: subkeys for CBC encryption are computed and + * written in the provided context structure. The key length MUST be + * adequate for the implemented block cipher. This function also sets + * the `vtable` field. + * + * - `br_xxx_cbcenc_run(const br_xxx_cbcenc_keys *ctx, void *iv, void *data, size_t len)` + * + * Perform CBC encryption of `len` bytes, in place. The encrypted data + * replaces the cleartext. `len` MUST be a multiple of the block length + * (if it is not, the function may loop forever or overflow a buffer). + * The IV is provided with the `iv` pointer; it is also updated with + * a copy of the last encrypted block. + * + * - `br_xxx_cbcdec_keys` + * + * Context structure that contains the subkeys resulting from the key + * expansion. These subkeys are appropriate for CBC decryption. The + * structure first field is called `vtable` and points to the + * appropriate OOP structure. + * + * - `br_xxx_cbcdec_init(br_xxx_cbcenc_keys *ctx, const void *key, size_t len)` + * + * Perform key expansion: subkeys for CBC decryption are computed and + * written in the provided context structure. The key length MUST be + * adequate for the implemented block cipher. This function also sets + * the `vtable` field. + * + * - `br_xxx_cbcdec_run(const br_xxx_cbcdec_keys *ctx, void *iv, void *data, size_t num_blocks)` + * + * Perform CBC decryption of `len` bytes, in place. The decrypted data + * replaces the ciphertext. `len` MUST be a multiple of the block length + * (if it is not, the function may loop forever or overflow a buffer). + * The IV is provided with the `iv` pointer; it is also updated with + * a copy of the last _encrypted_ block. + * + * - `br_xxx_ctr_keys` + * + * Context structure that contains the subkeys resulting from the key + * expansion. These subkeys are appropriate for CTR encryption and + * decryption. The structure first field is called `vtable` and + * points to the appropriate OOP structure. + * + * - `br_xxx_ctr_init(br_xxx_ctr_keys *ctx, const void *key, size_t len)` + * + * Perform key expansion: subkeys for CTR encryption and decryption + * are computed and written in the provided context structure. The + * key length MUST be adequate for the implemented block cipher. This + * function also sets the `vtable` field. + * + * - `br_xxx_ctr_run(const br_xxx_ctr_keys *ctx, const void *iv, uint32_t cc, void *data, size_t len)` (returns `uint32_t`) + * + * Perform CTR encryption/decryption of some data. Processing is done + * "in place" (the output data replaces the input data). This function + * implements the "standard incrementing function" from NIST SP800-38A, + * annex B: the IV length shall be 4 bytes less than the block size + * (i.e. 12 bytes for AES) and the counter is the 32-bit value starting + * with `cc`. The data length (`len`) is not necessarily a multiple of + * the block size. The new counter value is returned, which supports + * chunked processing, provided that each chunk length (except possibly + * the last one) is a multiple of the block size. + * + * - `br_xxx_ctrcbc_keys` + * + * Context structure that contains the subkeys resulting from the + * key expansion. These subkeys are appropriate for doing combined + * CTR encryption/decryption and CBC-MAC, as used in the CCM and EAX + * authenticated encryption modes. The structure first field is + * called `vtable` and points to the appropriate OOP structure. + * + * - `br_xxx_ctrcbc_init(br_xxx_ctr_keys *ctx, const void *key, size_t len)` + * + * Perform key expansion: subkeys for combined CTR + * encryption/decryption and CBC-MAC are computed and written in the + * provided context structure. The key length MUST be adequate for + * the implemented block cipher. This function also sets the + * `vtable` field. + * + * - `br_xxx_ctrcbc_encrypt(const br_xxx_ctrcbc_keys *ctx, void *ctr, void *cbcmac, void *data, size_t len)` + * + * Perform CTR encryption of some data, and CBC-MAC. Processing is + * done "in place" (the output data replaces the input data). This + * function applies CTR encryption on the data, using a full + * block-size counter (i.e. for 128-bit blocks, the counter is + * incremented as a 128-bit value). The 'ctr' array contains the + * initial value for the counter (used in the first block) and it is + * updated with the new value after data processing. The 'cbcmac' + * value shall point to a block-sized value which is used as IV for + * CBC-MAC, computed over the encrypted data (output of CTR + * encryption); the resulting CBC-MAC is written over 'cbcmac' on + * output. + * + * The data length MUST be a multiple of the block size. + * + * - `br_xxx_ctrcbc_decrypt(const br_xxx_ctrcbc_keys *ctx, void *ctr, void *cbcmac, void *data, size_t len)` + * + * Perform CTR decryption of some data, and CBC-MAC. Processing is + * done "in place" (the output data replaces the input data). This + * function applies CTR decryption on the data, using a full + * block-size counter (i.e. for 128-bit blocks, the counter is + * incremented as a 128-bit value). The 'ctr' array contains the + * initial value for the counter (used in the first block) and it is + * updated with the new value after data processing. The 'cbcmac' + * value shall point to a block-sized value which is used as IV for + * CBC-MAC, computed over the encrypted data (input of CTR + * encryption); the resulting CBC-MAC is written over 'cbcmac' on + * output. + * + * The data length MUST be a multiple of the block size. + * + * - `br_xxx_ctrcbc_ctr(const br_xxx_ctrcbc_keys *ctx, void *ctr, void *data, size_t len)` + * + * Perform CTR encryption or decryption of the provided data. The + * data is processed "in place" (the output data replaces the input + * data). A full block-sized counter is applied (i.e. for 128-bit + * blocks, the counter is incremented as a 128-bit value). The 'ctr' + * array contains the initial value for the counter (used in the + * first block), and it is updated with the new value after data + * processing. + * + * The data length MUST be a multiple of the block size. + * + * - `br_xxx_ctrcbc_mac(const br_xxx_ctrcbc_keys *ctx, void *cbcmac, const void *data, size_t len)` + * + * Compute CBC-MAC over the provided data. The IV for CBC-MAC is + * provided as 'cbcmac'; the output is written over the same array. + * The data itself is untouched. The data length MUST be a multiple + * of the block size. + * + * + * It shall be noted that the key expansion functions return `void`. If + * the provided key length is not allowed, then there will be no error + * reporting; implementations need not validate the key length, thus an + * invalid key length may result in undefined behaviour (e.g. buffer + * overflow). + * + * Subkey structures contain no interior pointer, and no external + * resources are allocated upon key expansion. They can thus be + * discarded without any explicit deallocation. + * + * + * ## Object-Oriented API + * + * Each context structure begins with a field (called `vtable`) that + * points to an instance of a structure that references the relevant + * functions through pointers. Each such structure contains the + * following: + * + * - `context_size` + * + * The size (in bytes) of the context structure for subkeys. + * + * - `block_size` + * + * The cipher block size (in bytes). + * + * - `log_block_size` + * + * The base-2 logarithm of cipher block size (e.g. 4 for blocks + * of 16 bytes). + * + * - `init` + * + * Pointer to the key expansion function. + * + * - `run` + * + * Pointer to the encryption/decryption function. + * + * For combined CTR/CBC-MAC encryption, the `vtable` has a slightly + * different structure: + * + * - `context_size` + * + * The size (in bytes) of the context structure for subkeys. + * + * - `block_size` + * + * The cipher block size (in bytes). + * + * - `log_block_size` + * + * The base-2 logarithm of cipher block size (e.g. 4 for blocks + * of 16 bytes). + * + * - `init` + * + * Pointer to the key expansion function. + * + * - `encrypt` + * + * Pointer to the CTR encryption + CBC-MAC function. + * + * - `decrypt` + * + * Pointer to the CTR decryption + CBC-MAC function. + * + * - `ctr` + * + * Pointer to the CTR encryption/decryption function. + * + * - `mac` + * + * Pointer to the CBC-MAC function. + * + * For block cipher "`xxx`", static, constant instances of these + * structures are defined, under the names: + * + * - `br_xxx_cbcenc_vtable` + * - `br_xxx_cbcdec_vtable` + * - `br_xxx_ctr_vtable` + * - `br_xxx_ctrcbc_vtable` + * + * + * ## Implemented Block Ciphers + * + * Provided implementations are: + * + * | Name | Function | Block Size (bytes) | Key lengths (bytes) | + * | :-------- | :------- | :----------------: | :-----------------: | + * | aes_big | AES | 16 | 16, 24 and 32 | + * | aes_small | AES | 16 | 16, 24 and 32 | + * | aes_ct | AES | 16 | 16, 24 and 32 | + * | aes_ct64 | AES | 16 | 16, 24 and 32 | + * | aes_x86ni | AES | 16 | 16, 24 and 32 | + * | aes_pwr8 | AES | 16 | 16, 24 and 32 | + * | des_ct | DES/3DES | 8 | 8, 16 and 24 | + * | des_tab | DES/3DES | 8 | 8, 16 and 24 | + * + * **Note:** DES/3DES nominally uses keys of 64, 128 and 192 bits (i.e. 8, + * 16 and 24 bytes), but some of the bits are ignored by the algorithm, so + * the _effective_ key lengths, from a security point of view, are 56, + * 112 and 168 bits, respectively. + * + * `aes_big` is a "classical" AES implementation, using tables. It + * is fast but not constant-time, since it makes data-dependent array + * accesses. + * + * `aes_small` is an AES implementation optimized for code size. It + * is substantially slower than `aes_big`; it is not constant-time + * either. + * + * `aes_ct` is a constant-time implementation of AES; its code is about + * as big as that of `aes_big`, while its performance is comparable to + * that of `aes_small`. However, it is constant-time. This + * implementation should thus be considered to be the "default" AES in + * BearSSL, to be used unless the operational context guarantees that a + * non-constant-time implementation is safe, or an architecture-specific + * constant-time implementation can be used (e.g. using dedicated + * hardware opcodes). + * + * `aes_ct64` is another constant-time implementation of AES. It is + * similar to `aes_ct` but uses 64-bit values. On 32-bit machines, + * `aes_ct64` is not faster than `aes_ct`, often a bit slower, and has + * a larger footprint; however, on 64-bit architectures, `aes_ct64` + * is typically twice faster than `aes_ct` for modes that allow parallel + * operations (i.e. CTR, and CBC decryption, but not CBC encryption). + * + * `aes_x86ni` exists only on x86 architectures (32-bit and 64-bit). It + * uses the AES-NI opcodes when available. + * + * `aes_pwr8` exists only on PowerPC / POWER architectures (32-bit and + * 64-bit, both little-endian and big-endian). It uses the AES opcodes + * present in POWER8 and later. + * + * `des_tab` is a classic, table-based implementation of DES/3DES. It + * is not constant-time. + * + * `des_ct` is an constant-time implementation of DES/3DES. It is + * substantially slower than `des_tab`. + * + * ## ChaCha20 and Poly1305 + * + * ChaCha20 is a stream cipher. Poly1305 is a MAC algorithm. They + * are described in [RFC 7539](https://tools.ietf.org/html/rfc7539). + * + * Two function pointer types are defined: + * + * - `br_chacha20_run` describes a function that implements ChaCha20 + * only. + * + * - `br_poly1305_run` describes an implementation of Poly1305, + * in the AEAD combination with ChaCha20 specified in RFC 7539 + * (the ChaCha20 implementation is provided as a function pointer). + * + * `chacha20_ct` is a straightforward implementation of ChaCha20 in + * plain C; it is constant-time, small, and reasonably fast. + * + * `chacha20_sse2` leverages SSE2 opcodes (on x86 architectures that + * support these opcodes). It is faster than `chacha20_ct`. + * + * `poly1305_ctmul` is an implementation of the ChaCha20+Poly1305 AEAD + * construction, where the Poly1305 part is performed with mixed 32-bit + * multiplications (operands are 32-bit, result is 64-bit). + * + * `poly1305_ctmul32` implements ChaCha20+Poly1305 using pure 32-bit + * multiplications (32-bit operands, 32-bit result). It is slower than + * `poly1305_ctmul`, except on some specific architectures such as + * the ARM Cortex M0+. + * + * `poly1305_ctmulq` implements ChaCha20+Poly1305 with mixed 64-bit + * multiplications (operands are 64-bit, result is 128-bit) on 64-bit + * platforms that support such operations. + * + * `poly1305_i15` implements ChaCha20+Poly1305 with the generic "i15" + * big integer implementation. It is meant mostly for testing purposes, + * although it can help with saving a few hundred bytes of code footprint + * on systems where code size is scarce. + */ + +/** + * \brief Class type for CBC encryption implementations. + * + * A `br_block_cbcenc_class` instance points to the functions implementing + * a specific block cipher, when used in CBC mode for encrypting data. + */ +typedef struct br_block_cbcenc_class_ br_block_cbcenc_class; +struct br_block_cbcenc_class_ { + /** + * \brief Size (in bytes) of the context structure appropriate + * for containing subkeys. + */ + size_t context_size; + + /** + * \brief Size of individual blocks (in bytes). + */ + unsigned block_size; + + /** + * \brief Base-2 logarithm of the size of individual blocks, + * expressed in bytes. + */ + unsigned log_block_size; + + /** + * \brief Initialisation function. + * + * This function sets the `vtable` field in the context structure. + * The key length MUST be one of the key lengths supported by + * the implementation. + * + * \param ctx context structure to initialise. + * \param key secret key. + * \param key_len key length (in bytes). + */ + void (*init)(const br_block_cbcenc_class **ctx, + const void *key, size_t key_len); + + /** + * \brief Run the CBC encryption. + * + * The `iv` parameter points to the IV for this run; it is + * updated with a copy of the last encrypted block. The data + * is encrypted "in place"; its length (`len`) MUST be a + * multiple of the block size. + * + * \param ctx context structure (already initialised). + * \param iv IV for CBC encryption (updated). + * \param data data to encrypt. + * \param len data length (in bytes, multiple of block size). + */ + void (*run)(const br_block_cbcenc_class *const *ctx, + void *iv, void *data, size_t len); +}; + +/** + * \brief Class type for CBC decryption implementations. + * + * A `br_block_cbcdec_class` instance points to the functions implementing + * a specific block cipher, when used in CBC mode for decrypting data. + */ +typedef struct br_block_cbcdec_class_ br_block_cbcdec_class; +struct br_block_cbcdec_class_ { + /** + * \brief Size (in bytes) of the context structure appropriate + * for containing subkeys. + */ + size_t context_size; + + /** + * \brief Size of individual blocks (in bytes). + */ + unsigned block_size; + + /** + * \brief Base-2 logarithm of the size of individual blocks, + * expressed in bytes. + */ + unsigned log_block_size; + + /** + * \brief Initialisation function. + * + * This function sets the `vtable` field in the context structure. + * The key length MUST be one of the key lengths supported by + * the implementation. + * + * \param ctx context structure to initialise. + * \param key secret key. + * \param key_len key length (in bytes). + */ + void (*init)(const br_block_cbcdec_class **ctx, + const void *key, size_t key_len); + + /** + * \brief Run the CBC decryption. + * + * The `iv` parameter points to the IV for this run; it is + * updated with a copy of the last encrypted block. The data + * is decrypted "in place"; its length (`len`) MUST be a + * multiple of the block size. + * + * \param ctx context structure (already initialised). + * \param iv IV for CBC decryption (updated). + * \param data data to decrypt. + * \param len data length (in bytes, multiple of block size). + */ + void (*run)(const br_block_cbcdec_class *const *ctx, + void *iv, void *data, size_t len); +}; + +/** + * \brief Class type for CTR encryption/decryption implementations. + * + * A `br_block_ctr_class` instance points to the functions implementing + * a specific block cipher, when used in CTR mode for encrypting or + * decrypting data. + */ +typedef struct br_block_ctr_class_ br_block_ctr_class; +struct br_block_ctr_class_ { + /** + * \brief Size (in bytes) of the context structure appropriate + * for containing subkeys. + */ + size_t context_size; + + /** + * \brief Size of individual blocks (in bytes). + */ + unsigned block_size; + + /** + * \brief Base-2 logarithm of the size of individual blocks, + * expressed in bytes. + */ + unsigned log_block_size; + + /** + * \brief Initialisation function. + * + * This function sets the `vtable` field in the context structure. + * The key length MUST be one of the key lengths supported by + * the implementation. + * + * \param ctx context structure to initialise. + * \param key secret key. + * \param key_len key length (in bytes). + */ + void (*init)(const br_block_ctr_class **ctx, + const void *key, size_t key_len); + + /** + * \brief Run the CTR encryption or decryption. + * + * The `iv` parameter points to the IV for this run; its + * length is exactly 4 bytes less than the block size (e.g. + * 12 bytes for AES/CTR). The IV is combined with a 32-bit + * block counter to produce the block value which is processed + * with the block cipher. + * + * The data to encrypt or decrypt is updated "in place". Its + * length (`len` bytes) is not required to be a multiple of + * the block size; if the final block is partial, then the + * corresponding key stream bits are dropped. + * + * The resulting counter value is returned. + * + * \param ctx context structure (already initialised). + * \param iv IV for CTR encryption/decryption. + * \param cc initial value for the block counter. + * \param data data to encrypt or decrypt. + * \param len data length (in bytes). + * \return the new block counter value. + */ + uint32_t (*run)(const br_block_ctr_class *const *ctx, + const void *iv, uint32_t cc, void *data, size_t len); +}; + +/** + * \brief Class type for combined CTR and CBC-MAC implementations. + * + * A `br_block_ctrcbc_class` instance points to the functions implementing + * a specific block cipher, when used in CTR mode for encrypting or + * decrypting data, along with CBC-MAC. + */ +typedef struct br_block_ctrcbc_class_ br_block_ctrcbc_class; +struct br_block_ctrcbc_class_ { + /** + * \brief Size (in bytes) of the context structure appropriate + * for containing subkeys. + */ + size_t context_size; + + /** + * \brief Size of individual blocks (in bytes). + */ + unsigned block_size; + + /** + * \brief Base-2 logarithm of the size of individual blocks, + * expressed in bytes. + */ + unsigned log_block_size; + + /** + * \brief Initialisation function. + * + * This function sets the `vtable` field in the context structure. + * The key length MUST be one of the key lengths supported by + * the implementation. + * + * \param ctx context structure to initialise. + * \param key secret key. + * \param key_len key length (in bytes). + */ + void (*init)(const br_block_ctrcbc_class **ctx, + const void *key, size_t key_len); + + /** + * \brief Run the CTR encryption + CBC-MAC. + * + * The `ctr` parameter points to the counter; its length shall + * be equal to the block size. It is updated by this function + * as encryption proceeds. + * + * The `cbcmac` parameter points to the IV for CBC-MAC. The MAC + * is computed over the encrypted data (output of CTR + * encryption). Its length shall be equal to the block size. The + * computed CBC-MAC value is written over the `cbcmac` array. + * + * The data to encrypt is updated "in place". Its length (`len` + * bytes) MUST be a multiple of the block size. + * + * \param ctx context structure (already initialised). + * \param ctr counter for CTR encryption (initial and final). + * \param cbcmac IV and output buffer for CBC-MAC. + * \param data data to encrypt. + * \param len data length (in bytes). + */ + void (*encrypt)(const br_block_ctrcbc_class *const *ctx, + void *ctr, void *cbcmac, void *data, size_t len); + + /** + * \brief Run the CTR decryption + CBC-MAC. + * + * The `ctr` parameter points to the counter; its length shall + * be equal to the block size. It is updated by this function + * as decryption proceeds. + * + * The `cbcmac` parameter points to the IV for CBC-MAC. The MAC + * is computed over the encrypted data (i.e. before CTR + * decryption). Its length shall be equal to the block size. The + * computed CBC-MAC value is written over the `cbcmac` array. + * + * The data to decrypt is updated "in place". Its length (`len` + * bytes) MUST be a multiple of the block size. + * + * \param ctx context structure (already initialised). + * \param ctr counter for CTR encryption (initial and final). + * \param cbcmac IV and output buffer for CBC-MAC. + * \param data data to decrypt. + * \param len data length (in bytes). + */ + void (*decrypt)(const br_block_ctrcbc_class *const *ctx, + void *ctr, void *cbcmac, void *data, size_t len); + + /** + * \brief Run the CTR encryption/decryption only. + * + * The `ctr` parameter points to the counter; its length shall + * be equal to the block size. It is updated by this function + * as decryption proceeds. + * + * The data to decrypt is updated "in place". Its length (`len` + * bytes) MUST be a multiple of the block size. + * + * \param ctx context structure (already initialised). + * \param ctr counter for CTR encryption (initial and final). + * \param data data to decrypt. + * \param len data length (in bytes). + */ + void (*ctr)(const br_block_ctrcbc_class *const *ctx, + void *ctr, void *data, size_t len); + + /** + * \brief Run the CBC-MAC only. + * + * The `cbcmac` parameter points to the IV for CBC-MAC. The MAC + * is computed over the encrypted data (i.e. before CTR + * decryption). Its length shall be equal to the block size. The + * computed CBC-MAC value is written over the `cbcmac` array. + * + * The data is unmodified. Its length (`len` bytes) MUST be a + * multiple of the block size. + * + * \param ctx context structure (already initialised). + * \param cbcmac IV and output buffer for CBC-MAC. + * \param data data to decrypt. + * \param len data length (in bytes). + */ + void (*mac)(const br_block_ctrcbc_class *const *ctx, + void *cbcmac, const void *data, size_t len); +}; + +/* + * Traditional, table-based AES implementation. It is fast, but uses + * internal tables (in particular a 1 kB table for encryption, another + * 1 kB table for decryption, and a 256-byte table for key schedule), + * and it is not constant-time. In contexts where cache-timing attacks + * apply, this implementation may leak the secret key. + */ + +/** \brief AES block size (16 bytes). */ +#define br_aes_big_BLOCK_SIZE 16 + +/** + * \brief Context for AES subkeys (`aes_big` implementation, CBC encryption). + * + * First field is a pointer to the vtable; it is set by the initialisation + * function. Other fields are not supposed to be accessed by user code. + */ +typedef struct { + /** \brief Pointer to vtable for this context. */ + const br_block_cbcenc_class *vtable; +#ifndef BR_DOXYGEN_IGNORE + uint32_t skey[60]; + unsigned num_rounds; +#endif +} br_aes_big_cbcenc_keys; + +/** + * \brief Context for AES subkeys (`aes_big` implementation, CBC decryption). + * + * First field is a pointer to the vtable; it is set by the initialisation + * function. Other fields are not supposed to be accessed by user code. + */ +typedef struct { + /** \brief Pointer to vtable for this context. */ + const br_block_cbcdec_class *vtable; +#ifndef BR_DOXYGEN_IGNORE + uint32_t skey[60]; + unsigned num_rounds; +#endif +} br_aes_big_cbcdec_keys; + +/** + * \brief Context for AES subkeys (`aes_big` implementation, CTR encryption + * and decryption). + * + * First field is a pointer to the vtable; it is set by the initialisation + * function. Other fields are not supposed to be accessed by user code. + */ +typedef struct { + /** \brief Pointer to vtable for this context. */ + const br_block_ctr_class *vtable; +#ifndef BR_DOXYGEN_IGNORE + uint32_t skey[60]; + unsigned num_rounds; +#endif +} br_aes_big_ctr_keys; + +/** + * \brief Context for AES subkeys (`aes_big` implementation, CTR encryption + * and decryption + CBC-MAC). + * + * First field is a pointer to the vtable; it is set by the initialisation + * function. Other fields are not supposed to be accessed by user code. + */ +typedef struct { + /** \brief Pointer to vtable for this context. */ + const br_block_ctrcbc_class *vtable; +#ifndef BR_DOXYGEN_IGNORE + uint32_t skey[60]; + unsigned num_rounds; +#endif +} br_aes_big_ctrcbc_keys; + +/** + * \brief Class instance for AES CBC encryption (`aes_big` implementation). + */ +extern const br_block_cbcenc_class br_aes_big_cbcenc_vtable; + +/** + * \brief Class instance for AES CBC decryption (`aes_big` implementation). + */ +extern const br_block_cbcdec_class br_aes_big_cbcdec_vtable; + +/** + * \brief Class instance for AES CTR encryption and decryption + * (`aes_big` implementation). + */ +extern const br_block_ctr_class br_aes_big_ctr_vtable; + +/** + * \brief Class instance for AES CTR encryption/decryption + CBC-MAC + * (`aes_big` implementation). + */ +extern const br_block_ctrcbc_class br_aes_big_ctrcbc_vtable; + +/** + * \brief Context initialisation (key schedule) for AES CBC encryption + * (`aes_big` implementation). + * + * \param ctx context to initialise. + * \param key secret key. + * \param len secret key length (in bytes). + */ +void br_aes_big_cbcenc_init(br_aes_big_cbcenc_keys *ctx, + const void *key, size_t len); + +/** + * \brief Context initialisation (key schedule) for AES CBC decryption + * (`aes_big` implementation). + * + * \param ctx context to initialise. + * \param key secret key. + * \param len secret key length (in bytes). + */ +void br_aes_big_cbcdec_init(br_aes_big_cbcdec_keys *ctx, + const void *key, size_t len); + +/** + * \brief Context initialisation (key schedule) for AES CTR encryption + * and decryption (`aes_big` implementation). + * + * \param ctx context to initialise. + * \param key secret key. + * \param len secret key length (in bytes). + */ +void br_aes_big_ctr_init(br_aes_big_ctr_keys *ctx, + const void *key, size_t len); + +/** + * \brief Context initialisation (key schedule) for AES CTR + CBC-MAC + * (`aes_big` implementation). + * + * \param ctx context to initialise. + * \param key secret key. + * \param len secret key length (in bytes). + */ +void br_aes_big_ctrcbc_init(br_aes_big_ctrcbc_keys *ctx, + const void *key, size_t len); + +/** + * \brief CBC encryption with AES (`aes_big` implementation). + * + * \param ctx context (already initialised). + * \param iv IV (updated). + * \param data data to encrypt (updated). + * \param len data length (in bytes, MUST be multiple of 16). + */ +void br_aes_big_cbcenc_run(const br_aes_big_cbcenc_keys *ctx, void *iv, + void *data, size_t len); + +/** + * \brief CBC decryption with AES (`aes_big` implementation). + * + * \param ctx context (already initialised). + * \param iv IV (updated). + * \param data data to decrypt (updated). + * \param len data length (in bytes, MUST be multiple of 16). + */ +void br_aes_big_cbcdec_run(const br_aes_big_cbcdec_keys *ctx, void *iv, + void *data, size_t len); + +/** + * \brief CTR encryption and decryption with AES (`aes_big` implementation). + * + * \param ctx context (already initialised). + * \param iv IV (constant, 12 bytes). + * \param cc initial block counter value. + * \param data data to encrypt or decrypt (updated). + * \param len data length (in bytes). + * \return new block counter value. + */ +uint32_t br_aes_big_ctr_run(const br_aes_big_ctr_keys *ctx, + const void *iv, uint32_t cc, void *data, size_t len); + +/** + * \brief CTR encryption + CBC-MAC with AES (`aes_big` implementation). + * + * \param ctx context (already initialised). + * \param ctr counter for CTR (16 bytes, updated). + * \param cbcmac IV for CBC-MAC (updated). + * \param data data to encrypt (updated). + * \param len data length (in bytes, MUST be a multiple of 16). + */ +void br_aes_big_ctrcbc_encrypt(const br_aes_big_ctrcbc_keys *ctx, + void *ctr, void *cbcmac, void *data, size_t len); + +/** + * \brief CTR decryption + CBC-MAC with AES (`aes_big` implementation). + * + * \param ctx context (already initialised). + * \param ctr counter for CTR (16 bytes, updated). + * \param cbcmac IV for CBC-MAC (updated). + * \param data data to decrypt (updated). + * \param len data length (in bytes, MUST be a multiple of 16). + */ +void br_aes_big_ctrcbc_decrypt(const br_aes_big_ctrcbc_keys *ctx, + void *ctr, void *cbcmac, void *data, size_t len); + +/** + * \brief CTR encryption/decryption with AES (`aes_big` implementation). + * + * \param ctx context (already initialised). + * \param ctr counter for CTR (16 bytes, updated). + * \param data data to MAC (updated). + * \param len data length (in bytes, MUST be a multiple of 16). + */ +void br_aes_big_ctrcbc_ctr(const br_aes_big_ctrcbc_keys *ctx, + void *ctr, void *data, size_t len); + +/** + * \brief CBC-MAC with AES (`aes_big` implementation). + * + * \param ctx context (already initialised). + * \param cbcmac IV for CBC-MAC (updated). + * \param data data to MAC (unmodified). + * \param len data length (in bytes, MUST be a multiple of 16). + */ +void br_aes_big_ctrcbc_mac(const br_aes_big_ctrcbc_keys *ctx, + void *cbcmac, const void *data, size_t len); + +/* + * AES implementation optimized for size. It is slower than the + * traditional table-based AES implementation, but requires much less + * code. It still uses data-dependent table accesses (albeit within a + * much smaller 256-byte table), which makes it conceptually vulnerable + * to cache-timing attacks. + */ + +/** \brief AES block size (16 bytes). */ +#define br_aes_small_BLOCK_SIZE 16 + +/** + * \brief Context for AES subkeys (`aes_small` implementation, CBC encryption). + * + * First field is a pointer to the vtable; it is set by the initialisation + * function. Other fields are not supposed to be accessed by user code. + */ +typedef struct { + /** \brief Pointer to vtable for this context. */ + const br_block_cbcenc_class *vtable; +#ifndef BR_DOXYGEN_IGNORE + uint32_t skey[60]; + unsigned num_rounds; +#endif +} br_aes_small_cbcenc_keys; + +/** + * \brief Context for AES subkeys (`aes_small` implementation, CBC decryption). + * + * First field is a pointer to the vtable; it is set by the initialisation + * function. Other fields are not supposed to be accessed by user code. + */ +typedef struct { + /** \brief Pointer to vtable for this context. */ + const br_block_cbcdec_class *vtable; +#ifndef BR_DOXYGEN_IGNORE + uint32_t skey[60]; + unsigned num_rounds; +#endif +} br_aes_small_cbcdec_keys; + +/** + * \brief Context for AES subkeys (`aes_small` implementation, CTR encryption + * and decryption). + * + * First field is a pointer to the vtable; it is set by the initialisation + * function. Other fields are not supposed to be accessed by user code. + */ +typedef struct { + /** \brief Pointer to vtable for this context. */ + const br_block_ctr_class *vtable; +#ifndef BR_DOXYGEN_IGNORE + uint32_t skey[60]; + unsigned num_rounds; +#endif +} br_aes_small_ctr_keys; + +/** + * \brief Context for AES subkeys (`aes_small` implementation, CTR encryption + * and decryption + CBC-MAC). + * + * First field is a pointer to the vtable; it is set by the initialisation + * function. Other fields are not supposed to be accessed by user code. + */ +typedef struct { + /** \brief Pointer to vtable for this context. */ + const br_block_ctrcbc_class *vtable; +#ifndef BR_DOXYGEN_IGNORE + uint32_t skey[60]; + unsigned num_rounds; +#endif +} br_aes_small_ctrcbc_keys; + +/** + * \brief Class instance for AES CBC encryption (`aes_small` implementation). + */ +extern const br_block_cbcenc_class br_aes_small_cbcenc_vtable; + +/** + * \brief Class instance for AES CBC decryption (`aes_small` implementation). + */ +extern const br_block_cbcdec_class br_aes_small_cbcdec_vtable; + +/** + * \brief Class instance for AES CTR encryption and decryption + * (`aes_small` implementation). + */ +extern const br_block_ctr_class br_aes_small_ctr_vtable; + +/** + * \brief Class instance for AES CTR encryption/decryption + CBC-MAC + * (`aes_small` implementation). + */ +extern const br_block_ctrcbc_class br_aes_small_ctrcbc_vtable; + +/** + * \brief Context initialisation (key schedule) for AES CBC encryption + * (`aes_small` implementation). + * + * \param ctx context to initialise. + * \param key secret key. + * \param len secret key length (in bytes). + */ +void br_aes_small_cbcenc_init(br_aes_small_cbcenc_keys *ctx, + const void *key, size_t len); + +/** + * \brief Context initialisation (key schedule) for AES CBC decryption + * (`aes_small` implementation). + * + * \param ctx context to initialise. + * \param key secret key. + * \param len secret key length (in bytes). + */ +void br_aes_small_cbcdec_init(br_aes_small_cbcdec_keys *ctx, + const void *key, size_t len); + +/** + * \brief Context initialisation (key schedule) for AES CTR encryption + * and decryption (`aes_small` implementation). + * + * \param ctx context to initialise. + * \param key secret key. + * \param len secret key length (in bytes). + */ +void br_aes_small_ctr_init(br_aes_small_ctr_keys *ctx, + const void *key, size_t len); + +/** + * \brief Context initialisation (key schedule) for AES CTR + CBC-MAC + * (`aes_small` implementation). + * + * \param ctx context to initialise. + * \param key secret key. + * \param len secret key length (in bytes). + */ +void br_aes_small_ctrcbc_init(br_aes_small_ctrcbc_keys *ctx, + const void *key, size_t len); + +/** + * \brief CBC encryption with AES (`aes_small` implementation). + * + * \param ctx context (already initialised). + * \param iv IV (updated). + * \param data data to encrypt (updated). + * \param len data length (in bytes, MUST be multiple of 16). + */ +void br_aes_small_cbcenc_run(const br_aes_small_cbcenc_keys *ctx, void *iv, + void *data, size_t len); + +/** + * \brief CBC decryption with AES (`aes_small` implementation). + * + * \param ctx context (already initialised). + * \param iv IV (updated). + * \param data data to decrypt (updated). + * \param len data length (in bytes, MUST be multiple of 16). + */ +void br_aes_small_cbcdec_run(const br_aes_small_cbcdec_keys *ctx, void *iv, + void *data, size_t len); + +/** + * \brief CTR encryption and decryption with AES (`aes_small` implementation). + * + * \param ctx context (already initialised). + * \param iv IV (constant, 12 bytes). + * \param cc initial block counter value. + * \param data data to decrypt (updated). + * \param len data length (in bytes). + * \return new block counter value. + */ +uint32_t br_aes_small_ctr_run(const br_aes_small_ctr_keys *ctx, + const void *iv, uint32_t cc, void *data, size_t len); + +/** + * \brief CTR encryption + CBC-MAC with AES (`aes_small` implementation). + * + * \param ctx context (already initialised). + * \param ctr counter for CTR (16 bytes, updated). + * \param cbcmac IV for CBC-MAC (updated). + * \param data data to encrypt (updated). + * \param len data length (in bytes, MUST be a multiple of 16). + */ +void br_aes_small_ctrcbc_encrypt(const br_aes_small_ctrcbc_keys *ctx, + void *ctr, void *cbcmac, void *data, size_t len); + +/** + * \brief CTR decryption + CBC-MAC with AES (`aes_small` implementation). + * + * \param ctx context (already initialised). + * \param ctr counter for CTR (16 bytes, updated). + * \param cbcmac IV for CBC-MAC (updated). + * \param data data to decrypt (updated). + * \param len data length (in bytes, MUST be a multiple of 16). + */ +void br_aes_small_ctrcbc_decrypt(const br_aes_small_ctrcbc_keys *ctx, + void *ctr, void *cbcmac, void *data, size_t len); + +/** + * \brief CTR encryption/decryption with AES (`aes_small` implementation). + * + * \param ctx context (already initialised). + * \param ctr counter for CTR (16 bytes, updated). + * \param data data to MAC (updated). + * \param len data length (in bytes, MUST be a multiple of 16). + */ +void br_aes_small_ctrcbc_ctr(const br_aes_small_ctrcbc_keys *ctx, + void *ctr, void *data, size_t len); + +/** + * \brief CBC-MAC with AES (`aes_small` implementation). + * + * \param ctx context (already initialised). + * \param cbcmac IV for CBC-MAC (updated). + * \param data data to MAC (unmodified). + * \param len data length (in bytes, MUST be a multiple of 16). + */ +void br_aes_small_ctrcbc_mac(const br_aes_small_ctrcbc_keys *ctx, + void *cbcmac, const void *data, size_t len); + +/* + * Constant-time AES implementation. Its size is similar to that of + * 'aes_big', and its performance is similar to that of 'aes_small' (faster + * decryption, slower encryption). However, it is constant-time, i.e. + * immune to cache-timing and similar attacks. + */ + +/** \brief AES block size (16 bytes). */ +#define br_aes_ct_BLOCK_SIZE 16 + +/** + * \brief Context for AES subkeys (`aes_ct` implementation, CBC encryption). + * + * First field is a pointer to the vtable; it is set by the initialisation + * function. Other fields are not supposed to be accessed by user code. + */ +typedef struct { + /** \brief Pointer to vtable for this context. */ + const br_block_cbcenc_class *vtable; +#ifndef BR_DOXYGEN_IGNORE + uint32_t skey[60]; + unsigned num_rounds; +#endif +} br_aes_ct_cbcenc_keys; + +/** + * \brief Context for AES subkeys (`aes_ct` implementation, CBC decryption). + * + * First field is a pointer to the vtable; it is set by the initialisation + * function. Other fields are not supposed to be accessed by user code. + */ +typedef struct { + /** \brief Pointer to vtable for this context. */ + const br_block_cbcdec_class *vtable; +#ifndef BR_DOXYGEN_IGNORE + uint32_t skey[60]; + unsigned num_rounds; +#endif +} br_aes_ct_cbcdec_keys; + +/** + * \brief Context for AES subkeys (`aes_ct` implementation, CTR encryption + * and decryption). + * + * First field is a pointer to the vtable; it is set by the initialisation + * function. Other fields are not supposed to be accessed by user code. + */ +typedef struct { + /** \brief Pointer to vtable for this context. */ + const br_block_ctr_class *vtable; +#ifndef BR_DOXYGEN_IGNORE + uint32_t skey[60]; + unsigned num_rounds; +#endif +} br_aes_ct_ctr_keys; + +/** + * \brief Context for AES subkeys (`aes_ct` implementation, CTR encryption + * and decryption + CBC-MAC). + * + * First field is a pointer to the vtable; it is set by the initialisation + * function. Other fields are not supposed to be accessed by user code. + */ +typedef struct { + /** \brief Pointer to vtable for this context. */ + const br_block_ctrcbc_class *vtable; +#ifndef BR_DOXYGEN_IGNORE + uint32_t skey[60]; + unsigned num_rounds; +#endif +} br_aes_ct_ctrcbc_keys; + +/** + * \brief Class instance for AES CBC encryption (`aes_ct` implementation). + */ +extern const br_block_cbcenc_class br_aes_ct_cbcenc_vtable; + +/** + * \brief Class instance for AES CBC decryption (`aes_ct` implementation). + */ +extern const br_block_cbcdec_class br_aes_ct_cbcdec_vtable; + +/** + * \brief Class instance for AES CTR encryption and decryption + * (`aes_ct` implementation). + */ +extern const br_block_ctr_class br_aes_ct_ctr_vtable; + +/** + * \brief Class instance for AES CTR encryption/decryption + CBC-MAC + * (`aes_ct` implementation). + */ +extern const br_block_ctrcbc_class br_aes_ct_ctrcbc_vtable; + +/** + * \brief Context initialisation (key schedule) for AES CBC encryption + * (`aes_ct` implementation). + * + * \param ctx context to initialise. + * \param key secret key. + * \param len secret key length (in bytes). + */ +void br_aes_ct_cbcenc_init(br_aes_ct_cbcenc_keys *ctx, + const void *key, size_t len); + +/** + * \brief Context initialisation (key schedule) for AES CBC decryption + * (`aes_ct` implementation). + * + * \param ctx context to initialise. + * \param key secret key. + * \param len secret key length (in bytes). + */ +void br_aes_ct_cbcdec_init(br_aes_ct_cbcdec_keys *ctx, + const void *key, size_t len); + +/** + * \brief Context initialisation (key schedule) for AES CTR encryption + * and decryption (`aes_ct` implementation). + * + * \param ctx context to initialise. + * \param key secret key. + * \param len secret key length (in bytes). + */ +void br_aes_ct_ctr_init(br_aes_ct_ctr_keys *ctx, + const void *key, size_t len); + +/** + * \brief Context initialisation (key schedule) for AES CTR + CBC-MAC + * (`aes_ct` implementation). + * + * \param ctx context to initialise. + * \param key secret key. + * \param len secret key length (in bytes). + */ +void br_aes_ct_ctrcbc_init(br_aes_ct_ctrcbc_keys *ctx, + const void *key, size_t len); + +/** + * \brief CBC encryption with AES (`aes_ct` implementation). + * + * \param ctx context (already initialised). + * \param iv IV (updated). + * \param data data to encrypt (updated). + * \param len data length (in bytes, MUST be multiple of 16). + */ +void br_aes_ct_cbcenc_run(const br_aes_ct_cbcenc_keys *ctx, void *iv, + void *data, size_t len); + +/** + * \brief CBC decryption with AES (`aes_ct` implementation). + * + * \param ctx context (already initialised). + * \param iv IV (updated). + * \param data data to decrypt (updated). + * \param len data length (in bytes, MUST be multiple of 16). + */ +void br_aes_ct_cbcdec_run(const br_aes_ct_cbcdec_keys *ctx, void *iv, + void *data, size_t len); + +/** + * \brief CTR encryption and decryption with AES (`aes_ct` implementation). + * + * \param ctx context (already initialised). + * \param iv IV (constant, 12 bytes). + * \param cc initial block counter value. + * \param data data to decrypt (updated). + * \param len data length (in bytes). + * \return new block counter value. + */ +uint32_t br_aes_ct_ctr_run(const br_aes_ct_ctr_keys *ctx, + const void *iv, uint32_t cc, void *data, size_t len); + +/** + * \brief CTR encryption + CBC-MAC with AES (`aes_ct` implementation). + * + * \param ctx context (already initialised). + * \param ctr counter for CTR (16 bytes, updated). + * \param cbcmac IV for CBC-MAC (updated). + * \param data data to encrypt (updated). + * \param len data length (in bytes, MUST be a multiple of 16). + */ +void br_aes_ct_ctrcbc_encrypt(const br_aes_ct_ctrcbc_keys *ctx, + void *ctr, void *cbcmac, void *data, size_t len); + +/** + * \brief CTR decryption + CBC-MAC with AES (`aes_ct` implementation). + * + * \param ctx context (already initialised). + * \param ctr counter for CTR (16 bytes, updated). + * \param cbcmac IV for CBC-MAC (updated). + * \param data data to decrypt (updated). + * \param len data length (in bytes, MUST be a multiple of 16). + */ +void br_aes_ct_ctrcbc_decrypt(const br_aes_ct_ctrcbc_keys *ctx, + void *ctr, void *cbcmac, void *data, size_t len); + +/** + * \brief CTR encryption/decryption with AES (`aes_ct` implementation). + * + * \param ctx context (already initialised). + * \param ctr counter for CTR (16 bytes, updated). + * \param data data to MAC (updated). + * \param len data length (in bytes, MUST be a multiple of 16). + */ +void br_aes_ct_ctrcbc_ctr(const br_aes_ct_ctrcbc_keys *ctx, + void *ctr, void *data, size_t len); + +/** + * \brief CBC-MAC with AES (`aes_ct` implementation). + * + * \param ctx context (already initialised). + * \param cbcmac IV for CBC-MAC (updated). + * \param data data to MAC (unmodified). + * \param len data length (in bytes, MUST be a multiple of 16). + */ +void br_aes_ct_ctrcbc_mac(const br_aes_ct_ctrcbc_keys *ctx, + void *cbcmac, const void *data, size_t len); + +/* + * 64-bit constant-time AES implementation. It is similar to 'aes_ct' + * but uses 64-bit registers, making it about twice faster than 'aes_ct' + * on 64-bit platforms, while remaining constant-time and with a similar + * code size. (The doubling in performance is only for CBC decryption + * and CTR mode; CBC encryption is non-parallel and cannot benefit from + * the larger registers.) + */ + +/** \brief AES block size (16 bytes). */ +#define br_aes_ct64_BLOCK_SIZE 16 + +/** + * \brief Context for AES subkeys (`aes_ct64` implementation, CBC encryption). + * + * First field is a pointer to the vtable; it is set by the initialisation + * function. Other fields are not supposed to be accessed by user code. + */ +typedef struct { + /** \brief Pointer to vtable for this context. */ + const br_block_cbcenc_class *vtable; +#ifndef BR_DOXYGEN_IGNORE + uint64_t skey[30]; + unsigned num_rounds; +#endif +} br_aes_ct64_cbcenc_keys; + +/** + * \brief Context for AES subkeys (`aes_ct64` implementation, CBC decryption). + * + * First field is a pointer to the vtable; it is set by the initialisation + * function. Other fields are not supposed to be accessed by user code. + */ +typedef struct { + /** \brief Pointer to vtable for this context. */ + const br_block_cbcdec_class *vtable; +#ifndef BR_DOXYGEN_IGNORE + uint64_t skey[30]; + unsigned num_rounds; +#endif +} br_aes_ct64_cbcdec_keys; + +/** + * \brief Context for AES subkeys (`aes_ct64` implementation, CTR encryption + * and decryption). + * + * First field is a pointer to the vtable; it is set by the initialisation + * function. Other fields are not supposed to be accessed by user code. + */ +typedef struct { + /** \brief Pointer to vtable for this context. */ + const br_block_ctr_class *vtable; +#ifndef BR_DOXYGEN_IGNORE + uint64_t skey[30]; + unsigned num_rounds; +#endif +} br_aes_ct64_ctr_keys; + +/** + * \brief Context for AES subkeys (`aes_ct64` implementation, CTR encryption + * and decryption + CBC-MAC). + * + * First field is a pointer to the vtable; it is set by the initialisation + * function. Other fields are not supposed to be accessed by user code. + */ +typedef struct { + /** \brief Pointer to vtable for this context. */ + const br_block_ctrcbc_class *vtable; +#ifndef BR_DOXYGEN_IGNORE + uint64_t skey[30]; + unsigned num_rounds; +#endif +} br_aes_ct64_ctrcbc_keys; + +/** + * \brief Class instance for AES CBC encryption (`aes_ct64` implementation). + */ +extern const br_block_cbcenc_class br_aes_ct64_cbcenc_vtable; + +/** + * \brief Class instance for AES CBC decryption (`aes_ct64` implementation). + */ +extern const br_block_cbcdec_class br_aes_ct64_cbcdec_vtable; + +/** + * \brief Class instance for AES CTR encryption and decryption + * (`aes_ct64` implementation). + */ +extern const br_block_ctr_class br_aes_ct64_ctr_vtable; + +/** + * \brief Class instance for AES CTR encryption/decryption + CBC-MAC + * (`aes_ct64` implementation). + */ +extern const br_block_ctrcbc_class br_aes_ct64_ctrcbc_vtable; + +/** + * \brief Context initialisation (key schedule) for AES CBC encryption + * (`aes_ct64` implementation). + * + * \param ctx context to initialise. + * \param key secret key. + * \param len secret key length (in bytes). + */ +void br_aes_ct64_cbcenc_init(br_aes_ct64_cbcenc_keys *ctx, + const void *key, size_t len); + +/** + * \brief Context initialisation (key schedule) for AES CBC decryption + * (`aes_ct64` implementation). + * + * \param ctx context to initialise. + * \param key secret key. + * \param len secret key length (in bytes). + */ +void br_aes_ct64_cbcdec_init(br_aes_ct64_cbcdec_keys *ctx, + const void *key, size_t len); + +/** + * \brief Context initialisation (key schedule) for AES CTR encryption + * and decryption (`aes_ct64` implementation). + * + * \param ctx context to initialise. + * \param key secret key. + * \param len secret key length (in bytes). + */ +void br_aes_ct64_ctr_init(br_aes_ct64_ctr_keys *ctx, + const void *key, size_t len); + +/** + * \brief Context initialisation (key schedule) for AES CTR + CBC-MAC + * (`aes_ct64` implementation). + * + * \param ctx context to initialise. + * \param key secret key. + * \param len secret key length (in bytes). + */ +void br_aes_ct64_ctrcbc_init(br_aes_ct64_ctrcbc_keys *ctx, + const void *key, size_t len); + +/** + * \brief CBC encryption with AES (`aes_ct64` implementation). + * + * \param ctx context (already initialised). + * \param iv IV (updated). + * \param data data to encrypt (updated). + * \param len data length (in bytes, MUST be multiple of 16). + */ +void br_aes_ct64_cbcenc_run(const br_aes_ct64_cbcenc_keys *ctx, void *iv, + void *data, size_t len); + +/** + * \brief CBC decryption with AES (`aes_ct64` implementation). + * + * \param ctx context (already initialised). + * \param iv IV (updated). + * \param data data to decrypt (updated). + * \param len data length (in bytes, MUST be multiple of 16). + */ +void br_aes_ct64_cbcdec_run(const br_aes_ct64_cbcdec_keys *ctx, void *iv, + void *data, size_t len); + +/** + * \brief CTR encryption and decryption with AES (`aes_ct64` implementation). + * + * \param ctx context (already initialised). + * \param iv IV (constant, 12 bytes). + * \param cc initial block counter value. + * \param data data to decrypt (updated). + * \param len data length (in bytes). + * \return new block counter value. + */ +uint32_t br_aes_ct64_ctr_run(const br_aes_ct64_ctr_keys *ctx, + const void *iv, uint32_t cc, void *data, size_t len); + +/** + * \brief CTR encryption + CBC-MAC with AES (`aes_ct64` implementation). + * + * \param ctx context (already initialised). + * \param ctr counter for CTR (16 bytes, updated). + * \param cbcmac IV for CBC-MAC (updated). + * \param data data to encrypt (updated). + * \param len data length (in bytes, MUST be a multiple of 16). + */ +void br_aes_ct64_ctrcbc_encrypt(const br_aes_ct64_ctrcbc_keys *ctx, + void *ctr, void *cbcmac, void *data, size_t len); + +/** + * \brief CTR decryption + CBC-MAC with AES (`aes_ct64` implementation). + * + * \param ctx context (already initialised). + * \param ctr counter for CTR (16 bytes, updated). + * \param cbcmac IV for CBC-MAC (updated). + * \param data data to decrypt (updated). + * \param len data length (in bytes, MUST be a multiple of 16). + */ +void br_aes_ct64_ctrcbc_decrypt(const br_aes_ct64_ctrcbc_keys *ctx, + void *ctr, void *cbcmac, void *data, size_t len); + +/** + * \brief CTR encryption/decryption with AES (`aes_ct64` implementation). + * + * \param ctx context (already initialised). + * \param ctr counter for CTR (16 bytes, updated). + * \param data data to MAC (updated). + * \param len data length (in bytes, MUST be a multiple of 16). + */ +void br_aes_ct64_ctrcbc_ctr(const br_aes_ct64_ctrcbc_keys *ctx, + void *ctr, void *data, size_t len); + +/** + * \brief CBC-MAC with AES (`aes_ct64` implementation). + * + * \param ctx context (already initialised). + * \param cbcmac IV for CBC-MAC (updated). + * \param data data to MAC (unmodified). + * \param len data length (in bytes, MUST be a multiple of 16). + */ +void br_aes_ct64_ctrcbc_mac(const br_aes_ct64_ctrcbc_keys *ctx, + void *cbcmac, const void *data, size_t len); + +/* + * AES implementation using AES-NI opcodes (x86 platform). + */ + +/** \brief AES block size (16 bytes). */ +#define br_aes_x86ni_BLOCK_SIZE 16 + +/** + * \brief Context for AES subkeys (`aes_x86ni` implementation, CBC encryption). + * + * First field is a pointer to the vtable; it is set by the initialisation + * function. Other fields are not supposed to be accessed by user code. + */ +typedef struct { + /** \brief Pointer to vtable for this context. */ + const br_block_cbcenc_class *vtable; +#ifndef BR_DOXYGEN_IGNORE + union { + unsigned char skni[16 * 15]; + } skey; + unsigned num_rounds; +#endif +} br_aes_x86ni_cbcenc_keys; + +/** + * \brief Context for AES subkeys (`aes_x86ni` implementation, CBC decryption). + * + * First field is a pointer to the vtable; it is set by the initialisation + * function. Other fields are not supposed to be accessed by user code. + */ +typedef struct { + /** \brief Pointer to vtable for this context. */ + const br_block_cbcdec_class *vtable; +#ifndef BR_DOXYGEN_IGNORE + union { + unsigned char skni[16 * 15]; + } skey; + unsigned num_rounds; +#endif +} br_aes_x86ni_cbcdec_keys; + +/** + * \brief Context for AES subkeys (`aes_x86ni` implementation, CTR encryption + * and decryption). + * + * First field is a pointer to the vtable; it is set by the initialisation + * function. Other fields are not supposed to be accessed by user code. + */ +typedef struct { + /** \brief Pointer to vtable for this context. */ + const br_block_ctr_class *vtable; +#ifndef BR_DOXYGEN_IGNORE + union { + unsigned char skni[16 * 15]; + } skey; + unsigned num_rounds; +#endif +} br_aes_x86ni_ctr_keys; + +/** + * \brief Context for AES subkeys (`aes_x86ni` implementation, CTR encryption + * and decryption + CBC-MAC). + * + * First field is a pointer to the vtable; it is set by the initialisation + * function. Other fields are not supposed to be accessed by user code. + */ +typedef struct { + /** \brief Pointer to vtable for this context. */ + const br_block_ctrcbc_class *vtable; +#ifndef BR_DOXYGEN_IGNORE + union { + unsigned char skni[16 * 15]; + } skey; + unsigned num_rounds; +#endif +} br_aes_x86ni_ctrcbc_keys; + +/** + * \brief Class instance for AES CBC encryption (`aes_x86ni` implementation). + * + * Since this implementation might be omitted from the library, or the + * AES opcode unavailable on the current CPU, a pointer to this class + * instance should be obtained through `br_aes_x86ni_cbcenc_get_vtable()`. + */ +extern const br_block_cbcenc_class br_aes_x86ni_cbcenc_vtable; + +/** + * \brief Class instance for AES CBC decryption (`aes_x86ni` implementation). + * + * Since this implementation might be omitted from the library, or the + * AES opcode unavailable on the current CPU, a pointer to this class + * instance should be obtained through `br_aes_x86ni_cbcdec_get_vtable()`. + */ +extern const br_block_cbcdec_class br_aes_x86ni_cbcdec_vtable; + +/** + * \brief Class instance for AES CTR encryption and decryption + * (`aes_x86ni` implementation). + * + * Since this implementation might be omitted from the library, or the + * AES opcode unavailable on the current CPU, a pointer to this class + * instance should be obtained through `br_aes_x86ni_ctr_get_vtable()`. + */ +extern const br_block_ctr_class br_aes_x86ni_ctr_vtable; + +/** + * \brief Class instance for AES CTR encryption/decryption + CBC-MAC + * (`aes_x86ni` implementation). + * + * Since this implementation might be omitted from the library, or the + * AES opcode unavailable on the current CPU, a pointer to this class + * instance should be obtained through `br_aes_x86ni_ctrcbc_get_vtable()`. + */ +extern const br_block_ctrcbc_class br_aes_x86ni_ctrcbc_vtable; + +/** + * \brief Context initialisation (key schedule) for AES CBC encryption + * (`aes_x86ni` implementation). + * + * \param ctx context to initialise. + * \param key secret key. + * \param len secret key length (in bytes). + */ +void br_aes_x86ni_cbcenc_init(br_aes_x86ni_cbcenc_keys *ctx, + const void *key, size_t len); + +/** + * \brief Context initialisation (key schedule) for AES CBC decryption + * (`aes_x86ni` implementation). + * + * \param ctx context to initialise. + * \param key secret key. + * \param len secret key length (in bytes). + */ +void br_aes_x86ni_cbcdec_init(br_aes_x86ni_cbcdec_keys *ctx, + const void *key, size_t len); + +/** + * \brief Context initialisation (key schedule) for AES CTR encryption + * and decryption (`aes_x86ni` implementation). + * + * \param ctx context to initialise. + * \param key secret key. + * \param len secret key length (in bytes). + */ +void br_aes_x86ni_ctr_init(br_aes_x86ni_ctr_keys *ctx, + const void *key, size_t len); + +/** + * \brief Context initialisation (key schedule) for AES CTR + CBC-MAC + * (`aes_x86ni` implementation). + * + * \param ctx context to initialise. + * \param key secret key. + * \param len secret key length (in bytes). + */ +void br_aes_x86ni_ctrcbc_init(br_aes_x86ni_ctrcbc_keys *ctx, + const void *key, size_t len); + +/** + * \brief CBC encryption with AES (`aes_x86ni` implementation). + * + * \param ctx context (already initialised). + * \param iv IV (updated). + * \param data data to encrypt (updated). + * \param len data length (in bytes, MUST be multiple of 16). + */ +void br_aes_x86ni_cbcenc_run(const br_aes_x86ni_cbcenc_keys *ctx, void *iv, + void *data, size_t len); + +/** + * \brief CBC decryption with AES (`aes_x86ni` implementation). + * + * \param ctx context (already initialised). + * \param iv IV (updated). + * \param data data to decrypt (updated). + * \param len data length (in bytes, MUST be multiple of 16). + */ +void br_aes_x86ni_cbcdec_run(const br_aes_x86ni_cbcdec_keys *ctx, void *iv, + void *data, size_t len); + +/** + * \brief CTR encryption and decryption with AES (`aes_x86ni` implementation). + * + * \param ctx context (already initialised). + * \param iv IV (constant, 12 bytes). + * \param cc initial block counter value. + * \param data data to decrypt (updated). + * \param len data length (in bytes). + * \return new block counter value. + */ +uint32_t br_aes_x86ni_ctr_run(const br_aes_x86ni_ctr_keys *ctx, + const void *iv, uint32_t cc, void *data, size_t len); + +/** + * \brief CTR encryption + CBC-MAC with AES (`aes_x86ni` implementation). + * + * \param ctx context (already initialised). + * \param ctr counter for CTR (16 bytes, updated). + * \param cbcmac IV for CBC-MAC (updated). + * \param data data to encrypt (updated). + * \param len data length (in bytes, MUST be a multiple of 16). + */ +void br_aes_x86ni_ctrcbc_encrypt(const br_aes_x86ni_ctrcbc_keys *ctx, + void *ctr, void *cbcmac, void *data, size_t len); + +/** + * \brief CTR decryption + CBC-MAC with AES (`aes_x86ni` implementation). + * + * \param ctx context (already initialised). + * \param ctr counter for CTR (16 bytes, updated). + * \param cbcmac IV for CBC-MAC (updated). + * \param data data to decrypt (updated). + * \param len data length (in bytes, MUST be a multiple of 16). + */ +void br_aes_x86ni_ctrcbc_decrypt(const br_aes_x86ni_ctrcbc_keys *ctx, + void *ctr, void *cbcmac, void *data, size_t len); + +/** + * \brief CTR encryption/decryption with AES (`aes_x86ni` implementation). + * + * \param ctx context (already initialised). + * \param ctr counter for CTR (16 bytes, updated). + * \param data data to MAC (updated). + * \param len data length (in bytes, MUST be a multiple of 16). + */ +void br_aes_x86ni_ctrcbc_ctr(const br_aes_x86ni_ctrcbc_keys *ctx, + void *ctr, void *data, size_t len); + +/** + * \brief CBC-MAC with AES (`aes_x86ni` implementation). + * + * \param ctx context (already initialised). + * \param cbcmac IV for CBC-MAC (updated). + * \param data data to MAC (unmodified). + * \param len data length (in bytes, MUST be a multiple of 16). + */ +void br_aes_x86ni_ctrcbc_mac(const br_aes_x86ni_ctrcbc_keys *ctx, + void *cbcmac, const void *data, size_t len); + +/** + * \brief Obtain the `aes_x86ni` AES-CBC (encryption) implementation, if + * available. + * + * This function returns a pointer to `br_aes_x86ni_cbcenc_vtable`, if + * that implementation was compiled in the library _and_ the x86 AES + * opcodes are available on the currently running CPU. If either of + * these conditions is not met, then this function returns `NULL`. + * + * \return the `aes_x86ni` AES-CBC (encryption) implementation, or `NULL`. + */ +const br_block_cbcenc_class *br_aes_x86ni_cbcenc_get_vtable(void); + +/** + * \brief Obtain the `aes_x86ni` AES-CBC (decryption) implementation, if + * available. + * + * This function returns a pointer to `br_aes_x86ni_cbcdec_vtable`, if + * that implementation was compiled in the library _and_ the x86 AES + * opcodes are available on the currently running CPU. If either of + * these conditions is not met, then this function returns `NULL`. + * + * \return the `aes_x86ni` AES-CBC (decryption) implementation, or `NULL`. + */ +const br_block_cbcdec_class *br_aes_x86ni_cbcdec_get_vtable(void); + +/** + * \brief Obtain the `aes_x86ni` AES-CTR implementation, if available. + * + * This function returns a pointer to `br_aes_x86ni_ctr_vtable`, if + * that implementation was compiled in the library _and_ the x86 AES + * opcodes are available on the currently running CPU. If either of + * these conditions is not met, then this function returns `NULL`. + * + * \return the `aes_x86ni` AES-CTR implementation, or `NULL`. + */ +const br_block_ctr_class *br_aes_x86ni_ctr_get_vtable(void); + +/** + * \brief Obtain the `aes_x86ni` AES-CTR + CBC-MAC implementation, if + * available. + * + * This function returns a pointer to `br_aes_x86ni_ctrcbc_vtable`, if + * that implementation was compiled in the library _and_ the x86 AES + * opcodes are available on the currently running CPU. If either of + * these conditions is not met, then this function returns `NULL`. + * + * \return the `aes_x86ni` AES-CTR implementation, or `NULL`. + */ +const br_block_ctrcbc_class *br_aes_x86ni_ctrcbc_get_vtable(void); + +/* + * AES implementation using POWER8 opcodes. + */ + +/** \brief AES block size (16 bytes). */ +#define br_aes_pwr8_BLOCK_SIZE 16 + +/** + * \brief Context for AES subkeys (`aes_pwr8` implementation, CBC encryption). + * + * First field is a pointer to the vtable; it is set by the initialisation + * function. Other fields are not supposed to be accessed by user code. + */ +typedef struct { + /** \brief Pointer to vtable for this context. */ + const br_block_cbcenc_class *vtable; +#ifndef BR_DOXYGEN_IGNORE + union { + unsigned char skni[16 * 15]; + } skey; + unsigned num_rounds; +#endif +} br_aes_pwr8_cbcenc_keys; + +/** + * \brief Context for AES subkeys (`aes_pwr8` implementation, CBC decryption). + * + * First field is a pointer to the vtable; it is set by the initialisation + * function. Other fields are not supposed to be accessed by user code. + */ +typedef struct { + /** \brief Pointer to vtable for this context. */ + const br_block_cbcdec_class *vtable; +#ifndef BR_DOXYGEN_IGNORE + union { + unsigned char skni[16 * 15]; + } skey; + unsigned num_rounds; +#endif +} br_aes_pwr8_cbcdec_keys; + +/** + * \brief Context for AES subkeys (`aes_pwr8` implementation, CTR encryption + * and decryption). + * + * First field is a pointer to the vtable; it is set by the initialisation + * function. Other fields are not supposed to be accessed by user code. + */ +typedef struct { + /** \brief Pointer to vtable for this context. */ + const br_block_ctr_class *vtable; +#ifndef BR_DOXYGEN_IGNORE + union { + unsigned char skni[16 * 15]; + } skey; + unsigned num_rounds; +#endif +} br_aes_pwr8_ctr_keys; + +/** + * \brief Context for AES subkeys (`aes_pwr8` implementation, CTR encryption + * and decryption + CBC-MAC). + * + * First field is a pointer to the vtable; it is set by the initialisation + * function. Other fields are not supposed to be accessed by user code. + */ +typedef struct { + /** \brief Pointer to vtable for this context. */ + const br_block_ctrcbc_class *vtable; +#ifndef BR_DOXYGEN_IGNORE + union { + unsigned char skni[16 * 15]; + } skey; + unsigned num_rounds; +#endif +} br_aes_pwr8_ctrcbc_keys; + +/** + * \brief Class instance for AES CBC encryption (`aes_pwr8` implementation). + * + * Since this implementation might be omitted from the library, or the + * AES opcode unavailable on the current CPU, a pointer to this class + * instance should be obtained through `br_aes_pwr8_cbcenc_get_vtable()`. + */ +extern const br_block_cbcenc_class br_aes_pwr8_cbcenc_vtable; + +/** + * \brief Class instance for AES CBC decryption (`aes_pwr8` implementation). + * + * Since this implementation might be omitted from the library, or the + * AES opcode unavailable on the current CPU, a pointer to this class + * instance should be obtained through `br_aes_pwr8_cbcdec_get_vtable()`. + */ +extern const br_block_cbcdec_class br_aes_pwr8_cbcdec_vtable; + +/** + * \brief Class instance for AES CTR encryption and decryption + * (`aes_pwr8` implementation). + * + * Since this implementation might be omitted from the library, or the + * AES opcode unavailable on the current CPU, a pointer to this class + * instance should be obtained through `br_aes_pwr8_ctr_get_vtable()`. + */ +extern const br_block_ctr_class br_aes_pwr8_ctr_vtable; + +/** + * \brief Class instance for AES CTR encryption/decryption + CBC-MAC + * (`aes_pwr8` implementation). + * + * Since this implementation might be omitted from the library, or the + * AES opcode unavailable on the current CPU, a pointer to this class + * instance should be obtained through `br_aes_pwr8_ctrcbc_get_vtable()`. + */ +extern const br_block_ctrcbc_class br_aes_pwr8_ctrcbc_vtable; + +/** + * \brief Context initialisation (key schedule) for AES CBC encryption + * (`aes_pwr8` implementation). + * + * \param ctx context to initialise. + * \param key secret key. + * \param len secret key length (in bytes). + */ +void br_aes_pwr8_cbcenc_init(br_aes_pwr8_cbcenc_keys *ctx, + const void *key, size_t len); + +/** + * \brief Context initialisation (key schedule) for AES CBC decryption + * (`aes_pwr8` implementation). + * + * \param ctx context to initialise. + * \param key secret key. + * \param len secret key length (in bytes). + */ +void br_aes_pwr8_cbcdec_init(br_aes_pwr8_cbcdec_keys *ctx, + const void *key, size_t len); + +/** + * \brief Context initialisation (key schedule) for AES CTR encryption + * and decryption (`aes_pwr8` implementation). + * + * \param ctx context to initialise. + * \param key secret key. + * \param len secret key length (in bytes). + */ +void br_aes_pwr8_ctr_init(br_aes_pwr8_ctr_keys *ctx, + const void *key, size_t len); + +/** + * \brief Context initialisation (key schedule) for AES CTR + CBC-MAC + * (`aes_pwr8` implementation). + * + * \param ctx context to initialise. + * \param key secret key. + * \param len secret key length (in bytes). + */ +void br_aes_pwr8_ctrcbc_init(br_aes_pwr8_ctrcbc_keys *ctx, + const void *key, size_t len); + +/** + * \brief CBC encryption with AES (`aes_pwr8` implementation). + * + * \param ctx context (already initialised). + * \param iv IV (updated). + * \param data data to encrypt (updated). + * \param len data length (in bytes, MUST be multiple of 16). + */ +void br_aes_pwr8_cbcenc_run(const br_aes_pwr8_cbcenc_keys *ctx, void *iv, + void *data, size_t len); + +/** + * \brief CBC decryption with AES (`aes_pwr8` implementation). + * + * \param ctx context (already initialised). + * \param iv IV (updated). + * \param data data to decrypt (updated). + * \param len data length (in bytes, MUST be multiple of 16). + */ +void br_aes_pwr8_cbcdec_run(const br_aes_pwr8_cbcdec_keys *ctx, void *iv, + void *data, size_t len); + +/** + * \brief CTR encryption and decryption with AES (`aes_pwr8` implementation). + * + * \param ctx context (already initialised). + * \param iv IV (constant, 12 bytes). + * \param cc initial block counter value. + * \param data data to decrypt (updated). + * \param len data length (in bytes). + * \return new block counter value. + */ +uint32_t br_aes_pwr8_ctr_run(const br_aes_pwr8_ctr_keys *ctx, + const void *iv, uint32_t cc, void *data, size_t len); + +/** + * \brief CTR encryption + CBC-MAC with AES (`aes_pwr8` implementation). + * + * \param ctx context (already initialised). + * \param ctr counter for CTR (16 bytes, updated). + * \param cbcmac IV for CBC-MAC (updated). + * \param data data to encrypt (updated). + * \param len data length (in bytes, MUST be a multiple of 16). + */ +void br_aes_pwr8_ctrcbc_encrypt(const br_aes_pwr8_ctrcbc_keys *ctx, + void *ctr, void *cbcmac, void *data, size_t len); + +/** + * \brief CTR decryption + CBC-MAC with AES (`aes_pwr8` implementation). + * + * \param ctx context (already initialised). + * \param ctr counter for CTR (16 bytes, updated). + * \param cbcmac IV for CBC-MAC (updated). + * \param data data to decrypt (updated). + * \param len data length (in bytes, MUST be a multiple of 16). + */ +void br_aes_pwr8_ctrcbc_decrypt(const br_aes_pwr8_ctrcbc_keys *ctx, + void *ctr, void *cbcmac, void *data, size_t len); + +/** + * \brief CTR encryption/decryption with AES (`aes_pwr8` implementation). + * + * \param ctx context (already initialised). + * \param ctr counter for CTR (16 bytes, updated). + * \param data data to MAC (updated). + * \param len data length (in bytes, MUST be a multiple of 16). + */ +void br_aes_pwr8_ctrcbc_ctr(const br_aes_pwr8_ctrcbc_keys *ctx, + void *ctr, void *data, size_t len); + +/** + * \brief CBC-MAC with AES (`aes_pwr8` implementation). + * + * \param ctx context (already initialised). + * \param cbcmac IV for CBC-MAC (updated). + * \param data data to MAC (unmodified). + * \param len data length (in bytes, MUST be a multiple of 16). + */ +void br_aes_pwr8_ctrcbc_mac(const br_aes_pwr8_ctrcbc_keys *ctx, + void *cbcmac, const void *data, size_t len); + +/** + * \brief Obtain the `aes_pwr8` AES-CBC (encryption) implementation, if + * available. + * + * This function returns a pointer to `br_aes_pwr8_cbcenc_vtable`, if + * that implementation was compiled in the library _and_ the POWER8 + * crypto opcodes are available on the currently running CPU. If either + * of these conditions is not met, then this function returns `NULL`. + * + * \return the `aes_pwr8` AES-CBC (encryption) implementation, or `NULL`. + */ +const br_block_cbcenc_class *br_aes_pwr8_cbcenc_get_vtable(void); + +/** + * \brief Obtain the `aes_pwr8` AES-CBC (decryption) implementation, if + * available. + * + * This function returns a pointer to `br_aes_pwr8_cbcdec_vtable`, if + * that implementation was compiled in the library _and_ the POWER8 + * crypto opcodes are available on the currently running CPU. If either + * of these conditions is not met, then this function returns `NULL`. + * + * \return the `aes_pwr8` AES-CBC (decryption) implementation, or `NULL`. + */ +const br_block_cbcdec_class *br_aes_pwr8_cbcdec_get_vtable(void); + +/** + * \brief Obtain the `aes_pwr8` AES-CTR implementation, if available. + * + * This function returns a pointer to `br_aes_pwr8_ctr_vtable`, if that + * implementation was compiled in the library _and_ the POWER8 crypto + * opcodes are available on the currently running CPU. If either of + * these conditions is not met, then this function returns `NULL`. + * + * \return the `aes_pwr8` AES-CTR implementation, or `NULL`. + */ +const br_block_ctr_class *br_aes_pwr8_ctr_get_vtable(void); + +/** + * \brief Obtain the `aes_pwr8` AES-CTR + CBC-MAC implementation, if + * available. + * + * This function returns a pointer to `br_aes_pwr8_ctrcbc_vtable`, if + * that implementation was compiled in the library _and_ the POWER8 AES + * opcodes are available on the currently running CPU. If either of + * these conditions is not met, then this function returns `NULL`. + * + * \return the `aes_pwr8` AES-CTR implementation, or `NULL`. + */ +const br_block_ctrcbc_class *br_aes_pwr8_ctrcbc_get_vtable(void); + +/** + * \brief Aggregate structure large enough to be used as context for + * subkeys (CBC encryption) for all AES implementations. + */ +typedef union { + const br_block_cbcenc_class *vtable; + br_aes_big_cbcenc_keys c_big; + br_aes_small_cbcenc_keys c_small; + br_aes_ct_cbcenc_keys c_ct; + br_aes_ct64_cbcenc_keys c_ct64; + br_aes_x86ni_cbcenc_keys c_x86ni; + br_aes_pwr8_cbcenc_keys c_pwr8; +} br_aes_gen_cbcenc_keys; + +/** + * \brief Aggregate structure large enough to be used as context for + * subkeys (CBC decryption) for all AES implementations. + */ +typedef union { + const br_block_cbcdec_class *vtable; + br_aes_big_cbcdec_keys c_big; + br_aes_small_cbcdec_keys c_small; + br_aes_ct_cbcdec_keys c_ct; + br_aes_ct64_cbcdec_keys c_ct64; + br_aes_x86ni_cbcdec_keys c_x86ni; + br_aes_pwr8_cbcdec_keys c_pwr8; +} br_aes_gen_cbcdec_keys; + +/** + * \brief Aggregate structure large enough to be used as context for + * subkeys (CTR encryption and decryption) for all AES implementations. + */ +typedef union { + const br_block_ctr_class *vtable; + br_aes_big_ctr_keys c_big; + br_aes_small_ctr_keys c_small; + br_aes_ct_ctr_keys c_ct; + br_aes_ct64_ctr_keys c_ct64; + br_aes_x86ni_ctr_keys c_x86ni; + br_aes_pwr8_ctr_keys c_pwr8; +} br_aes_gen_ctr_keys; + +/** + * \brief Aggregate structure large enough to be used as context for + * subkeys (CTR encryption/decryption + CBC-MAC) for all AES implementations. + */ +typedef union { + const br_block_ctrcbc_class *vtable; + br_aes_big_ctrcbc_keys c_big; + br_aes_small_ctrcbc_keys c_small; + br_aes_ct_ctrcbc_keys c_ct; + br_aes_ct64_ctrcbc_keys c_ct64; + br_aes_x86ni_ctrcbc_keys c_x86ni; + br_aes_pwr8_ctrcbc_keys c_pwr8; +} br_aes_gen_ctrcbc_keys; + +/* + * Traditional, table-based implementation for DES/3DES. Since tables are + * used, cache-timing attacks are conceptually possible. + */ + +/** \brief DES/3DES block size (8 bytes). */ +#define br_des_tab_BLOCK_SIZE 8 + +/** + * \brief Context for DES subkeys (`des_tab` implementation, CBC encryption). + * + * First field is a pointer to the vtable; it is set by the initialisation + * function. Other fields are not supposed to be accessed by user code. + */ +typedef struct { + /** \brief Pointer to vtable for this context. */ + const br_block_cbcenc_class *vtable; +#ifndef BR_DOXYGEN_IGNORE + uint32_t skey[96]; + unsigned num_rounds; +#endif +} br_des_tab_cbcenc_keys; + +/** + * \brief Context for DES subkeys (`des_tab` implementation, CBC decryption). + * + * First field is a pointer to the vtable; it is set by the initialisation + * function. Other fields are not supposed to be accessed by user code. + */ +typedef struct { + /** \brief Pointer to vtable for this context. */ + const br_block_cbcdec_class *vtable; +#ifndef BR_DOXYGEN_IGNORE + uint32_t skey[96]; + unsigned num_rounds; +#endif +} br_des_tab_cbcdec_keys; + +/** + * \brief Class instance for DES CBC encryption (`des_tab` implementation). + */ +extern const br_block_cbcenc_class br_des_tab_cbcenc_vtable; + +/** + * \brief Class instance for DES CBC decryption (`des_tab` implementation). + */ +extern const br_block_cbcdec_class br_des_tab_cbcdec_vtable; + +/** + * \brief Context initialisation (key schedule) for DES CBC encryption + * (`des_tab` implementation). + * + * \param ctx context to initialise. + * \param key secret key. + * \param len secret key length (in bytes). + */ +void br_des_tab_cbcenc_init(br_des_tab_cbcenc_keys *ctx, + const void *key, size_t len); + +/** + * \brief Context initialisation (key schedule) for DES CBC decryption + * (`des_tab` implementation). + * + * \param ctx context to initialise. + * \param key secret key. + * \param len secret key length (in bytes). + */ +void br_des_tab_cbcdec_init(br_des_tab_cbcdec_keys *ctx, + const void *key, size_t len); + +/** + * \brief CBC encryption with DES (`des_tab` implementation). + * + * \param ctx context (already initialised). + * \param iv IV (updated). + * \param data data to encrypt (updated). + * \param len data length (in bytes, MUST be multiple of 8). + */ +void br_des_tab_cbcenc_run(const br_des_tab_cbcenc_keys *ctx, void *iv, + void *data, size_t len); + +/** + * \brief CBC decryption with DES (`des_tab` implementation). + * + * \param ctx context (already initialised). + * \param iv IV (updated). + * \param data data to decrypt (updated). + * \param len data length (in bytes, MUST be multiple of 8). + */ +void br_des_tab_cbcdec_run(const br_des_tab_cbcdec_keys *ctx, void *iv, + void *data, size_t len); + +/* + * Constant-time implementation for DES/3DES. It is substantially slower + * (by a factor of about 4x), but also immune to cache-timing attacks. + */ + +/** \brief DES/3DES block size (8 bytes). */ +#define br_des_ct_BLOCK_SIZE 8 + +/** + * \brief Context for DES subkeys (`des_ct` implementation, CBC encryption). + * + * First field is a pointer to the vtable; it is set by the initialisation + * function. Other fields are not supposed to be accessed by user code. + */ +typedef struct { + /** \brief Pointer to vtable for this context. */ + const br_block_cbcenc_class *vtable; +#ifndef BR_DOXYGEN_IGNORE + uint32_t skey[96]; + unsigned num_rounds; +#endif +} br_des_ct_cbcenc_keys; + +/** + * \brief Context for DES subkeys (`des_ct` implementation, CBC decryption). + * + * First field is a pointer to the vtable; it is set by the initialisation + * function. Other fields are not supposed to be accessed by user code. + */ +typedef struct { + /** \brief Pointer to vtable for this context. */ + const br_block_cbcdec_class *vtable; +#ifndef BR_DOXYGEN_IGNORE + uint32_t skey[96]; + unsigned num_rounds; +#endif +} br_des_ct_cbcdec_keys; + +/** + * \brief Class instance for DES CBC encryption (`des_ct` implementation). + */ +extern const br_block_cbcenc_class br_des_ct_cbcenc_vtable; + +/** + * \brief Class instance for DES CBC decryption (`des_ct` implementation). + */ +extern const br_block_cbcdec_class br_des_ct_cbcdec_vtable; + +/** + * \brief Context initialisation (key schedule) for DES CBC encryption + * (`des_ct` implementation). + * + * \param ctx context to initialise. + * \param key secret key. + * \param len secret key length (in bytes). + */ +void br_des_ct_cbcenc_init(br_des_ct_cbcenc_keys *ctx, + const void *key, size_t len); + +/** + * \brief Context initialisation (key schedule) for DES CBC decryption + * (`des_ct` implementation). + * + * \param ctx context to initialise. + * \param key secret key. + * \param len secret key length (in bytes). + */ +void br_des_ct_cbcdec_init(br_des_ct_cbcdec_keys *ctx, + const void *key, size_t len); + +/** + * \brief CBC encryption with DES (`des_ct` implementation). + * + * \param ctx context (already initialised). + * \param iv IV (updated). + * \param data data to encrypt (updated). + * \param len data length (in bytes, MUST be multiple of 8). + */ +void br_des_ct_cbcenc_run(const br_des_ct_cbcenc_keys *ctx, void *iv, + void *data, size_t len); + +/** + * \brief CBC decryption with DES (`des_ct` implementation). + * + * \param ctx context (already initialised). + * \param iv IV (updated). + * \param data data to decrypt (updated). + * \param len data length (in bytes, MUST be multiple of 8). + */ +void br_des_ct_cbcdec_run(const br_des_ct_cbcdec_keys *ctx, void *iv, + void *data, size_t len); + +/* + * These structures are large enough to accommodate subkeys for all + * DES/3DES implementations. + */ + +/** + * \brief Aggregate structure large enough to be used as context for + * subkeys (CBC encryption) for all DES implementations. + */ +typedef union { + const br_block_cbcenc_class *vtable; + br_des_tab_cbcenc_keys tab; + br_des_ct_cbcenc_keys ct; +} br_des_gen_cbcenc_keys; + +/** + * \brief Aggregate structure large enough to be used as context for + * subkeys (CBC decryption) for all DES implementations. + */ +typedef union { + const br_block_cbcdec_class *vtable; + br_des_tab_cbcdec_keys c_tab; + br_des_ct_cbcdec_keys c_ct; +} br_des_gen_cbcdec_keys; + +/** + * \brief Type for a ChaCha20 implementation. + * + * An implementation follows the description in RFC 7539: + * + * - Key is 256 bits (`key` points to exactly 32 bytes). + * + * - IV is 96 bits (`iv` points to exactly 12 bytes). + * + * - Block counter is over 32 bits and starts at value `cc`; the + * resulting value is returned. + * + * Data (pointed to by `data`, of length `len`) is encrypted/decrypted + * in place. If `len` is not a multiple of 64, then the excess bytes from + * the last block processing are dropped (therefore, "chunked" processing + * works only as long as each non-final chunk has a length multiple of 64). + * + * \param key secret key (32 bytes). + * \param iv IV (12 bytes). + * \param cc initial counter value. + * \param data data to encrypt or decrypt. + * \param len data length (in bytes). + */ +typedef uint32_t (*br_chacha20_run)(const void *key, + const void *iv, uint32_t cc, void *data, size_t len); + +/** + * \brief ChaCha20 implementation (straightforward C code, constant-time). + * + * \see br_chacha20_run + * + * \param key secret key (32 bytes). + * \param iv IV (12 bytes). + * \param cc initial counter value. + * \param data data to encrypt or decrypt. + * \param len data length (in bytes). + */ +uint32_t br_chacha20_ct_run(const void *key, + const void *iv, uint32_t cc, void *data, size_t len); + +/** + * \brief ChaCha20 implementation (SSE2 code, constant-time). + * + * This implementation is available only on x86 platforms, depending on + * compiler support. Moreover, in 32-bit mode, it might not actually run, + * if the underlying hardware does not implement the SSE2 opcode (in + * 64-bit mode, SSE2 is part of the ABI, so if the code could be compiled + * at all, then it can run). Use `br_chacha20_sse2_get()` to safely obtain + * a pointer to that function. + * + * \see br_chacha20_run + * + * \param key secret key (32 bytes). + * \param iv IV (12 bytes). + * \param cc initial counter value. + * \param data data to encrypt or decrypt. + * \param len data length (in bytes). + */ +uint32_t br_chacha20_sse2_run(const void *key, + const void *iv, uint32_t cc, void *data, size_t len); + +/** + * \brief Obtain the `sse2` ChaCha20 implementation, if available. + * + * This function returns a pointer to `br_chacha20_sse2_run`, if + * that implementation was compiled in the library _and_ the SSE2 + * opcodes are available on the currently running CPU. If either of + * these conditions is not met, then this function returns `0`. + * + * \return the `sse2` ChaCha20 implementation, or `0`. + */ +br_chacha20_run br_chacha20_sse2_get(void); + +/** + * \brief Type for a ChaCha20+Poly1305 AEAD implementation. + * + * The provided data is encrypted or decrypted with ChaCha20. The + * authentication tag is computed on the concatenation of the + * additional data and the ciphertext, with the padding and lengths + * as described in RFC 7539 (section 2.8). + * + * After decryption, the caller is responsible for checking that the + * computed tag matches the expected value. + * + * \param key secret key (32 bytes). + * \param iv nonce (12 bytes). + * \param data data to encrypt or decrypt. + * \param len data length (in bytes). + * \param aad additional authenticated data. + * \param aad_len length of additional authenticated data (in bytes). + * \param tag output buffer for the authentication tag. + * \param ichacha implementation of ChaCha20. + * \param encrypt non-zero for encryption, zero for decryption. + */ +typedef void (*br_poly1305_run)(const void *key, const void *iv, + void *data, size_t len, const void *aad, size_t aad_len, + void *tag, br_chacha20_run ichacha, int encrypt); + +/** + * \brief ChaCha20+Poly1305 AEAD implementation (mixed 32-bit multiplications). + * + * \see br_poly1305_run + * + * \param key secret key (32 bytes). + * \param iv nonce (12 bytes). + * \param data data to encrypt or decrypt. + * \param len data length (in bytes). + * \param aad additional authenticated data. + * \param aad_len length of additional authenticated data (in bytes). + * \param tag output buffer for the authentication tag. + * \param ichacha implementation of ChaCha20. + * \param encrypt non-zero for encryption, zero for decryption. + */ +void br_poly1305_ctmul_run(const void *key, const void *iv, + void *data, size_t len, const void *aad, size_t aad_len, + void *tag, br_chacha20_run ichacha, int encrypt); + +/** + * \brief ChaCha20+Poly1305 AEAD implementation (pure 32-bit multiplications). + * + * \see br_poly1305_run + * + * \param key secret key (32 bytes). + * \param iv nonce (12 bytes). + * \param data data to encrypt or decrypt. + * \param len data length (in bytes). + * \param aad additional authenticated data. + * \param aad_len length of additional authenticated data (in bytes). + * \param tag output buffer for the authentication tag. + * \param ichacha implementation of ChaCha20. + * \param encrypt non-zero for encryption, zero for decryption. + */ +void br_poly1305_ctmul32_run(const void *key, const void *iv, + void *data, size_t len, const void *aad, size_t aad_len, + void *tag, br_chacha20_run ichacha, int encrypt); + +/** + * \brief ChaCha20+Poly1305 AEAD implementation (i15). + * + * This implementation relies on the generic big integer code "i15" + * (which uses pure 32-bit multiplications). As such, it may save a + * little code footprint in a context where "i15" is already included + * (e.g. for elliptic curves or for RSA); however, it is also + * substantially slower than the ctmul and ctmul32 implementations. + * + * \see br_poly1305_run + * + * \param key secret key (32 bytes). + * \param iv nonce (12 bytes). + * \param data data to encrypt or decrypt. + * \param len data length (in bytes). + * \param aad additional authenticated data. + * \param aad_len length of additional authenticated data (in bytes). + * \param tag output buffer for the authentication tag. + * \param ichacha implementation of ChaCha20. + * \param encrypt non-zero for encryption, zero for decryption. + */ +void br_poly1305_i15_run(const void *key, const void *iv, + void *data, size_t len, const void *aad, size_t aad_len, + void *tag, br_chacha20_run ichacha, int encrypt); + +/** + * \brief ChaCha20+Poly1305 AEAD implementation (ctmulq). + * + * This implementation uses 64-bit multiplications (result over 128 bits). + * It is available only on platforms that offer such a primitive (in + * practice, 64-bit architectures). Use `br_poly1305_ctmulq_get()` to + * dynamically obtain a pointer to that function, or 0 if not supported. + * + * \see br_poly1305_run + * + * \param key secret key (32 bytes). + * \param iv nonce (12 bytes). + * \param data data to encrypt or decrypt. + * \param len data length (in bytes). + * \param aad additional authenticated data. + * \param aad_len length of additional authenticated data (in bytes). + * \param tag output buffer for the authentication tag. + * \param ichacha implementation of ChaCha20. + * \param encrypt non-zero for encryption, zero for decryption. + */ +void br_poly1305_ctmulq_run(const void *key, const void *iv, + void *data, size_t len, const void *aad, size_t aad_len, + void *tag, br_chacha20_run ichacha, int encrypt); + +/** + * \brief Get the ChaCha20+Poly1305 "ctmulq" implementation, if available. + * + * This function returns a pointer to the `br_poly1305_ctmulq_run()` + * function if supported on the current platform; otherwise, it returns 0. + * + * \return the ctmulq ChaCha20+Poly1305 implementation, or 0. + */ +br_poly1305_run br_poly1305_ctmulq_get(void); + +#ifdef __cplusplus +} +#endif + +#endif + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/bearssl_ec.h b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/bearssl_ec.h new file mode 100644 index 000000000..ad07476e7 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/bearssl_ec.h @@ -0,0 +1,983 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#ifndef BR_BEARSSL_EC_H__ +#define BR_BEARSSL_EC_H__ + +#include +#include + +#include "bearssl_rand.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** \file bearssl_ec.h + * + * # Elliptic Curves + * + * This file documents the EC implementations provided with BearSSL, and + * ECDSA. + * + * ## Elliptic Curve API + * + * Only "named curves" are supported. Each EC implementation supports + * one or several named curves, identified by symbolic identifiers. + * These identifiers are small integers, that correspond to the values + * registered by the + * [IANA](http://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-8). + * + * Since all currently defined elliptic curve identifiers are in the 0..31 + * range, it is convenient to encode support of some curves in a 32-bit + * word, such that bit x corresponds to curve of identifier x. + * + * An EC implementation is incarnated by a `br_ec_impl` instance, that + * offers the following fields: + * + * - `supported_curves` + * + * A 32-bit word that documents the identifiers of the curves supported + * by this implementation. + * + * - `generator()` + * + * Callback method that returns a pointer to the conventional generator + * point for that curve. + * + * - `order()` + * + * Callback method that returns a pointer to the subgroup order for + * that curve. That value uses unsigned big-endian encoding. + * + * - `xoff()` + * + * Callback method that returns the offset and length of the X + * coordinate in an encoded point. + * + * - `mul()` + * + * Multiply a curve point with an integer. + * + * - `mulgen()` + * + * Multiply the curve generator with an integer. This may be faster + * than the generic `mul()`. + * + * - `muladd()` + * + * Multiply two curve points by two integers, and return the sum of + * the two products. + * + * All curve points are represented in uncompressed format. The `mul()` + * and `muladd()` methods take care to validate that the provided points + * are really part of the relevant curve subgroup. + * + * For all point multiplication functions, the following holds: + * + * - Functions validate that the provided points are valid members + * of the relevant curve subgroup. An error is reported if that is + * not the case. + * + * - Processing is constant-time, even if the point operands are not + * valid. This holds for both the source and resulting points, and + * the multipliers (integers). Only the byte length of the provided + * multiplier arrays (not their actual value length in bits) may + * leak through timing-based side channels. + * + * - The multipliers (integers) MUST be lower than the subgroup order. + * If this property is not met, then the result is indeterminate, + * but an error value is not necessarily returned. + * + * + * ## ECDSA + * + * ECDSA signatures have two standard formats, called "raw" and "asn1". + * Internally, such a signature is a pair of modular integers `(r,s)`. + * The "raw" format is the concatenation of the unsigned big-endian + * encodings of these two integers, possibly left-padded with zeros so + * that they have the same encoded length. The "asn1" format is the + * DER encoding of an ASN.1 structure that contains the two integer + * values: + * + * ECDSASignature ::= SEQUENCE { + * r INTEGER, + * s INTEGER + * } + * + * In general, in all of X.509 and SSL/TLS, the "asn1" format is used. + * BearSSL offers ECDSA implementations for both formats; conversion + * functions between the two formats are also provided. Conversion of a + * "raw" format signature into "asn1" may enlarge a signature by no more + * than 9 bytes for all supported curves; conversely, conversion of an + * "asn1" signature to "raw" may expand the signature but the "raw" + * length will never be more than twice the length of the "asn1" length + * (and usually it will be shorter). + * + * Note that for a given signature, the "raw" format is not fully + * deterministic, in that it does not enforce a minimal common length. + */ + +/* + * Standard curve ID. These ID are equal to the assigned numerical + * identifiers assigned to these curves for TLS: + * http://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-8 + */ + +/** \brief Identifier for named curve sect163k1. */ +#define BR_EC_sect163k1 1 + +/** \brief Identifier for named curve sect163r1. */ +#define BR_EC_sect163r1 2 + +/** \brief Identifier for named curve sect163r2. */ +#define BR_EC_sect163r2 3 + +/** \brief Identifier for named curve sect193r1. */ +#define BR_EC_sect193r1 4 + +/** \brief Identifier for named curve sect193r2. */ +#define BR_EC_sect193r2 5 + +/** \brief Identifier for named curve sect233k1. */ +#define BR_EC_sect233k1 6 + +/** \brief Identifier for named curve sect233r1. */ +#define BR_EC_sect233r1 7 + +/** \brief Identifier for named curve sect239k1. */ +#define BR_EC_sect239k1 8 + +/** \brief Identifier for named curve sect283k1. */ +#define BR_EC_sect283k1 9 + +/** \brief Identifier for named curve sect283r1. */ +#define BR_EC_sect283r1 10 + +/** \brief Identifier for named curve sect409k1. */ +#define BR_EC_sect409k1 11 + +/** \brief Identifier for named curve sect409r1. */ +#define BR_EC_sect409r1 12 + +/** \brief Identifier for named curve sect571k1. */ +#define BR_EC_sect571k1 13 + +/** \brief Identifier for named curve sect571r1. */ +#define BR_EC_sect571r1 14 + +/** \brief Identifier for named curve secp160k1. */ +#define BR_EC_secp160k1 15 + +/** \brief Identifier for named curve secp160r1. */ +#define BR_EC_secp160r1 16 + +/** \brief Identifier for named curve secp160r2. */ +#define BR_EC_secp160r2 17 + +/** \brief Identifier for named curve secp192k1. */ +#define BR_EC_secp192k1 18 + +/** \brief Identifier for named curve secp192r1. */ +#define BR_EC_secp192r1 19 + +/** \brief Identifier for named curve secp224k1. */ +#define BR_EC_secp224k1 20 + +/** \brief Identifier for named curve secp224r1. */ +#define BR_EC_secp224r1 21 + +/** \brief Identifier for named curve secp256k1. */ +#define BR_EC_secp256k1 22 + +/** \brief Identifier for named curve secp256r1. */ +#define BR_EC_secp256r1 23 + +/** \brief Identifier for named curve secp384r1. */ +#define BR_EC_secp384r1 24 + +/** \brief Identifier for named curve secp521r1. */ +#define BR_EC_secp521r1 25 + +/** \brief Identifier for named curve brainpoolP256r1. */ +#define BR_EC_brainpoolP256r1 26 + +/** \brief Identifier for named curve brainpoolP384r1. */ +#define BR_EC_brainpoolP384r1 27 + +/** \brief Identifier for named curve brainpoolP512r1. */ +#define BR_EC_brainpoolP512r1 28 + +/** \brief Identifier for named curve Curve25519. */ +#define BR_EC_curve25519 29 + +/** \brief Identifier for named curve Curve448. */ +#define BR_EC_curve448 30 + +/** + * \brief Structure for an EC public key. + */ +typedef struct { + /** \brief Identifier for the curve used by this key. */ + int curve; + /** \brief Public curve point (uncompressed format). */ + unsigned char *q; + /** \brief Length of public curve point (in bytes). */ + size_t qlen; +} br_ec_public_key; + +/** + * \brief Structure for an EC private key. + * + * The private key is an integer modulo the curve subgroup order. The + * encoding below tolerates extra leading zeros. In general, it is + * recommended that the private key has the same length as the curve + * subgroup order. + */ +typedef struct { + /** \brief Identifier for the curve used by this key. */ + int curve; + /** \brief Private key (integer, unsigned big-endian encoding). */ + unsigned char *x; + /** \brief Private key length (in bytes). */ + size_t xlen; +} br_ec_private_key; + +/** + * \brief Type for an EC implementation. + */ +typedef struct { + /** + * \brief Supported curves. + * + * This word is a bitfield: bit `x` is set if the curve of ID `x` + * is supported. E.g. an implementation supporting both NIST P-256 + * (secp256r1, ID 23) and NIST P-384 (secp384r1, ID 24) will have + * value `0x01800000` in this field. + */ + uint32_t supported_curves; + + /** + * \brief Get the conventional generator. + * + * This function returns the conventional generator (encoded + * curve point) for the specified curve. This function MUST NOT + * be called if the curve is not supported. + * + * \param curve curve identifier. + * \param len receiver for the encoded generator length (in bytes). + * \return the encoded generator. + */ + const unsigned char *(*generator)(int curve, size_t *len); + + /** + * \brief Get the subgroup order. + * + * This function returns the order of the subgroup generated by + * the conventional generator, for the specified curve. Unsigned + * big-endian encoding is used. This function MUST NOT be called + * if the curve is not supported. + * + * \param curve curve identifier. + * \param len receiver for the encoded order length (in bytes). + * \return the encoded order. + */ + const unsigned char *(*order)(int curve, size_t *len); + + /** + * \brief Get the offset and length for the X coordinate. + * + * This function returns the offset and length (in bytes) of + * the X coordinate in an encoded non-zero point. + * + * \param curve curve identifier. + * \param len receiver for the X coordinate length (in bytes). + * \return the offset for the X coordinate (in bytes). + */ + size_t (*xoff)(int curve, size_t *len); + + /** + * \brief Multiply a curve point by an integer. + * + * The source point is provided in array `G` (of size `Glen` bytes); + * the multiplication result is written over it. The multiplier + * `x` (of size `xlen` bytes) uses unsigned big-endian encoding. + * + * Rules: + * + * - The specified curve MUST be supported. + * + * - The source point must be a valid point on the relevant curve + * subgroup (and not the "point at infinity" either). If this is + * not the case, then this function returns an error (0). + * + * - The multiplier integer MUST be non-zero and less than the + * curve subgroup order. If this property does not hold, then + * the result is indeterminate and an error code is not + * guaranteed. + * + * Returned value is 1 on success, 0 on error. On error, the + * contents of `G` are indeterminate. + * + * \param G point to multiply. + * \param Glen length of the encoded point (in bytes). + * \param x multiplier (unsigned big-endian). + * \param xlen multiplier length (in bytes). + * \param curve curve identifier. + * \return 1 on success, 0 on error. + */ + uint32_t (*mul)(unsigned char *G, size_t Glen, + const unsigned char *x, size_t xlen, int curve); + + /** + * \brief Multiply the generator by an integer. + * + * The multiplier MUST be non-zero and less than the curve + * subgroup order. Results are indeterminate if this property + * does not hold. + * + * \param R output buffer for the point. + * \param x multiplier (unsigned big-endian). + * \param xlen multiplier length (in bytes). + * \param curve curve identifier. + * \return encoded result point length (in bytes). + */ + size_t (*mulgen)(unsigned char *R, + const unsigned char *x, size_t xlen, int curve); + + /** + * \brief Multiply two points by two integers and add the + * results. + * + * The point `x*A + y*B` is computed and written back in the `A` + * array. + * + * Rules: + * + * - The specified curve MUST be supported. + * + * - The source points (`A` and `B`) must be valid points on + * the relevant curve subgroup (and not the "point at + * infinity" either). If this is not the case, then this + * function returns an error (0). + * + * - If the `B` pointer is `NULL`, then the conventional + * subgroup generator is used. With some implementations, + * this may be faster than providing a pointer to the + * generator. + * + * - The multiplier integers (`x` and `y`) MUST be non-zero + * and less than the curve subgroup order. If either integer + * is zero, then an error is reported, but if one of them is + * not lower than the subgroup order, then the result is + * indeterminate and an error code is not guaranteed. + * + * - If the final result is the point at infinity, then an + * error is returned. + * + * Returned value is 1 on success, 0 on error. On error, the + * contents of `A` are indeterminate. + * + * \param A first point to multiply. + * \param B second point to multiply (`NULL` for the generator). + * \param len common length of the encoded points (in bytes). + * \param x multiplier for `A` (unsigned big-endian). + * \param xlen length of multiplier for `A` (in bytes). + * \param y multiplier for `A` (unsigned big-endian). + * \param ylen length of multiplier for `A` (in bytes). + * \param curve curve identifier. + * \return 1 on success, 0 on error. + */ + uint32_t (*muladd)(unsigned char *A, const unsigned char *B, size_t len, + const unsigned char *x, size_t xlen, + const unsigned char *y, size_t ylen, int curve); +} br_ec_impl; + +/** + * \brief EC implementation "i31". + * + * This implementation internally uses generic code for modular integers, + * with a representation as sequences of 31-bit words. It supports secp256r1, + * secp384r1 and secp521r1 (aka NIST curves P-256, P-384 and P-521). + */ +extern const br_ec_impl br_ec_prime_i31; + +/** + * \brief EC implementation "i15". + * + * This implementation internally uses generic code for modular integers, + * with a representation as sequences of 15-bit words. It supports secp256r1, + * secp384r1 and secp521r1 (aka NIST curves P-256, P-384 and P-521). + */ +extern const br_ec_impl br_ec_prime_i15; + +/** + * \brief EC implementation "m15" for P-256. + * + * This implementation uses specialised code for curve secp256r1 (also + * known as NIST P-256), with optional Karatsuba decomposition, and fast + * modular reduction thanks to the field modulus special format. Only + * 32-bit multiplications are used (with 32-bit results, not 64-bit). + */ +extern const br_ec_impl br_ec_p256_m15; + +/** + * \brief EC implementation "m31" for P-256. + * + * This implementation uses specialised code for curve secp256r1 (also + * known as NIST P-256), relying on multiplications of 31-bit values + * (MUL31). + */ +extern const br_ec_impl br_ec_p256_m31; + +/** + * \brief EC implementation "m62" (specialised code) for P-256. + * + * This implementation uses custom code relying on multiplication of + * integers up to 64 bits, with a 128-bit result. This implementation is + * defined only on platforms that offer the 64x64->128 multiplication + * support; use `br_ec_p256_m62_get()` to dynamically obtain a pointer + * to that implementation. + */ +extern const br_ec_impl br_ec_p256_m62; + +/** + * \brief Get the "m62" implementation of P-256, if available. + * + * \return the implementation, or 0. + */ +const br_ec_impl *br_ec_p256_m62_get(void); + +/** + * \brief EC implementation "m64" (specialised code) for P-256. + * + * This implementation uses custom code relying on multiplication of + * integers up to 64 bits, with a 128-bit result. This implementation is + * defined only on platforms that offer the 64x64->128 multiplication + * support; use `br_ec_p256_m64_get()` to dynamically obtain a pointer + * to that implementation. + */ +extern const br_ec_impl br_ec_p256_m64; + +/** + * \brief Get the "m64" implementation of P-256, if available. + * + * \return the implementation, or 0. + */ +const br_ec_impl *br_ec_p256_m64_get(void); + +/** + * \brief EC implementation "i15" (generic code) for Curve25519. + * + * This implementation uses the generic code for modular integers (with + * 15-bit words) to support Curve25519. Due to the specificities of the + * curve definition, the following applies: + * + * - `muladd()` is not implemented (the function returns 0 systematically). + * - `order()` returns 2^255-1, since the point multiplication algorithm + * accepts any 32-bit integer as input (it clears the top bit and low + * three bits systematically). + */ +extern const br_ec_impl br_ec_c25519_i15; + +/** + * \brief EC implementation "i31" (generic code) for Curve25519. + * + * This implementation uses the generic code for modular integers (with + * 31-bit words) to support Curve25519. Due to the specificities of the + * curve definition, the following applies: + * + * - `muladd()` is not implemented (the function returns 0 systematically). + * - `order()` returns 2^255-1, since the point multiplication algorithm + * accepts any 32-bit integer as input (it clears the top bit and low + * three bits systematically). + */ +extern const br_ec_impl br_ec_c25519_i31; + +/** + * \brief EC implementation "m15" (specialised code) for Curve25519. + * + * This implementation uses custom code relying on multiplication of + * integers up to 15 bits. Due to the specificities of the curve + * definition, the following applies: + * + * - `muladd()` is not implemented (the function returns 0 systematically). + * - `order()` returns 2^255-1, since the point multiplication algorithm + * accepts any 32-bit integer as input (it clears the top bit and low + * three bits systematically). + */ +extern const br_ec_impl br_ec_c25519_m15; + +/** + * \brief EC implementation "m31" (specialised code) for Curve25519. + * + * This implementation uses custom code relying on multiplication of + * integers up to 31 bits. Due to the specificities of the curve + * definition, the following applies: + * + * - `muladd()` is not implemented (the function returns 0 systematically). + * - `order()` returns 2^255-1, since the point multiplication algorithm + * accepts any 32-bit integer as input (it clears the top bit and low + * three bits systematically). + */ +extern const br_ec_impl br_ec_c25519_m31; + +/** + * \brief EC implementation "m62" (specialised code) for Curve25519. + * + * This implementation uses custom code relying on multiplication of + * integers up to 62 bits, with a 124-bit result. This implementation is + * defined only on platforms that offer the 64x64->128 multiplication + * support; use `br_ec_c25519_m62_get()` to dynamically obtain a pointer + * to that implementation. Due to the specificities of the curve + * definition, the following applies: + * + * - `muladd()` is not implemented (the function returns 0 systematically). + * - `order()` returns 2^255-1, since the point multiplication algorithm + * accepts any 32-bit integer as input (it clears the top bit and low + * three bits systematically). + */ +extern const br_ec_impl br_ec_c25519_m62; + +/** + * \brief Get the "m62" implementation of Curve25519, if available. + * + * \return the implementation, or 0. + */ +const br_ec_impl *br_ec_c25519_m62_get(void); + +/** + * \brief EC implementation "m64" (specialised code) for Curve25519. + * + * This implementation uses custom code relying on multiplication of + * integers up to 64 bits, with a 128-bit result. This implementation is + * defined only on platforms that offer the 64x64->128 multiplication + * support; use `br_ec_c25519_m64_get()` to dynamically obtain a pointer + * to that implementation. Due to the specificities of the curve + * definition, the following applies: + * + * - `muladd()` is not implemented (the function returns 0 systematically). + * - `order()` returns 2^255-1, since the point multiplication algorithm + * accepts any 32-bit integer as input (it clears the top bit and low + * three bits systematically). + */ +extern const br_ec_impl br_ec_c25519_m64; + +/** + * \brief Get the "m64" implementation of Curve25519, if available. + * + * \return the implementation, or 0. + */ +const br_ec_impl *br_ec_c25519_m64_get(void); + +/** + * \brief Aggregate EC implementation "m15". + * + * This implementation is a wrapper for: + * + * - `br_ec_c25519_m15` for Curve25519 + * - `br_ec_p256_m15` for NIST P-256 + * - `br_ec_prime_i15` for other curves (NIST P-384 and NIST-P512) + */ +extern const br_ec_impl br_ec_all_m15; + +/** + * \brief Aggregate EC implementation "m31". + * + * This implementation is a wrapper for: + * + * - `br_ec_c25519_m31` for Curve25519 + * - `br_ec_p256_m31` for NIST P-256 + * - `br_ec_prime_i31` for other curves (NIST P-384 and NIST-P512) + */ +extern const br_ec_impl br_ec_all_m31; + +/** + * \brief Aggregate EC implementation "m31". + * + * This implementation is a wrapper for: + * + * - `br_ec_p256_m31` for NIST P-256 + * - `br_ec_prime_i31` for other curves (NIST P-384 and NIST-P512) + */ +extern const br_ec_impl br_ec_prime_fast_256; + +/** + * \brief Get the "default" EC implementation for the current system. + * + * This returns a pointer to the preferred implementation on the + * current system. + * + * \return the default EC implementation. + */ +const br_ec_impl *br_ec_get_default(void); + +/** + * \brief Convert a signature from "raw" to "asn1". + * + * Conversion is done "in place" and the new length is returned. + * Conversion may enlarge the signature, but by no more than 9 bytes at + * most. On error, 0 is returned (error conditions include an odd raw + * signature length, or an oversized integer). + * + * \param sig signature to convert. + * \param sig_len signature length (in bytes). + * \return the new signature length, or 0 on error. + */ +size_t br_ecdsa_raw_to_asn1(void *sig, size_t sig_len); + +/** + * \brief Convert a signature from "asn1" to "raw". + * + * Conversion is done "in place" and the new length is returned. + * Conversion may enlarge the signature, but the new signature length + * will be less than twice the source length at most. On error, 0 is + * returned (error conditions include an invalid ASN.1 structure or an + * oversized integer). + * + * \param sig signature to convert. + * \param sig_len signature length (in bytes). + * \return the new signature length, or 0 on error. + */ +size_t br_ecdsa_asn1_to_raw(void *sig, size_t sig_len); + +/** + * \brief Type for an ECDSA signer function. + * + * A pointer to the EC implementation is provided. The hash value is + * assumed to have the length inferred from the designated hash function + * class. + * + * Signature is written in the buffer pointed to by `sig`, and the length + * (in bytes) is returned. On error, nothing is written in the buffer, + * and 0 is returned. This function returns 0 if the specified curve is + * not supported by the provided EC implementation. + * + * The signature format is either "raw" or "asn1", depending on the + * implementation; maximum length is predictable from the implemented + * curve: + * + * | curve | raw | asn1 | + * | :--------- | --: | ---: | + * | NIST P-256 | 64 | 72 | + * | NIST P-384 | 96 | 104 | + * | NIST P-521 | 132 | 139 | + * + * \param impl EC implementation to use. + * \param hf hash function used to process the data. + * \param hash_value signed data (hashed). + * \param sk EC private key. + * \param sig destination buffer. + * \return the signature length (in bytes), or 0 on error. + */ +typedef size_t (*br_ecdsa_sign)(const br_ec_impl *impl, + const br_hash_class *hf, const void *hash_value, + const br_ec_private_key *sk, void *sig); + +/** + * \brief Type for an ECDSA signature verification function. + * + * A pointer to the EC implementation is provided. The hashed value, + * computed over the purportedly signed data, is also provided with + * its length. + * + * The signature format is either "raw" or "asn1", depending on the + * implementation. + * + * Returned value is 1 on success (valid signature), 0 on error. This + * function returns 0 if the specified curve is not supported by the + * provided EC implementation. + * + * \param impl EC implementation to use. + * \param hash signed data (hashed). + * \param hash_len hash value length (in bytes). + * \param pk EC public key. + * \param sig signature. + * \param sig_len signature length (in bytes). + * \return 1 on success, 0 on error. + */ +typedef uint32_t (*br_ecdsa_vrfy)(const br_ec_impl *impl, + const void *hash, size_t hash_len, + const br_ec_public_key *pk, const void *sig, size_t sig_len); + +/** + * \brief ECDSA signature generator, "i31" implementation, "asn1" format. + * + * \see br_ecdsa_sign() + * + * \param impl EC implementation to use. + * \param hf hash function used to process the data. + * \param hash_value signed data (hashed). + * \param sk EC private key. + * \param sig destination buffer. + * \return the signature length (in bytes), or 0 on error. + */ +size_t br_ecdsa_i31_sign_asn1(const br_ec_impl *impl, + const br_hash_class *hf, const void *hash_value, + const br_ec_private_key *sk, void *sig); + +/** + * \brief ECDSA signature generator, "i31" implementation, "raw" format. + * + * \see br_ecdsa_sign() + * + * \param impl EC implementation to use. + * \param hf hash function used to process the data. + * \param hash_value signed data (hashed). + * \param sk EC private key. + * \param sig destination buffer. + * \return the signature length (in bytes), or 0 on error. + */ +size_t br_ecdsa_i31_sign_raw(const br_ec_impl *impl, + const br_hash_class *hf, const void *hash_value, + const br_ec_private_key *sk, void *sig); + +/** + * \brief ECDSA signature verifier, "i31" implementation, "asn1" format. + * + * \see br_ecdsa_vrfy() + * + * \param impl EC implementation to use. + * \param hash signed data (hashed). + * \param hash_len hash value length (in bytes). + * \param pk EC public key. + * \param sig signature. + * \param sig_len signature length (in bytes). + * \return 1 on success, 0 on error. + */ +uint32_t br_ecdsa_i31_vrfy_asn1(const br_ec_impl *impl, + const void *hash, size_t hash_len, + const br_ec_public_key *pk, const void *sig, size_t sig_len); + +/** + * \brief ECDSA signature verifier, "i31" implementation, "raw" format. + * + * \see br_ecdsa_vrfy() + * + * \param impl EC implementation to use. + * \param hash signed data (hashed). + * \param hash_len hash value length (in bytes). + * \param pk EC public key. + * \param sig signature. + * \param sig_len signature length (in bytes). + * \return 1 on success, 0 on error. + */ +uint32_t br_ecdsa_i31_vrfy_raw(const br_ec_impl *impl, + const void *hash, size_t hash_len, + const br_ec_public_key *pk, const void *sig, size_t sig_len); + +/** + * \brief ECDSA signature generator, "i15" implementation, "asn1" format. + * + * \see br_ecdsa_sign() + * + * \param impl EC implementation to use. + * \param hf hash function used to process the data. + * \param hash_value signed data (hashed). + * \param sk EC private key. + * \param sig destination buffer. + * \return the signature length (in bytes), or 0 on error. + */ +size_t br_ecdsa_i15_sign_asn1(const br_ec_impl *impl, + const br_hash_class *hf, const void *hash_value, + const br_ec_private_key *sk, void *sig); + +/** + * \brief ECDSA signature generator, "i15" implementation, "raw" format. + * + * \see br_ecdsa_sign() + * + * \param impl EC implementation to use. + * \param hf hash function used to process the data. + * \param hash_value signed data (hashed). + * \param sk EC private key. + * \param sig destination buffer. + * \return the signature length (in bytes), or 0 on error. + */ +size_t br_ecdsa_i15_sign_raw(const br_ec_impl *impl, + const br_hash_class *hf, const void *hash_value, + const br_ec_private_key *sk, void *sig); + +/** + * \brief ECDSA signature verifier, "i15" implementation, "asn1" format. + * + * \see br_ecdsa_vrfy() + * + * \param impl EC implementation to use. + * \param hash signed data (hashed). + * \param hash_len hash value length (in bytes). + * \param pk EC public key. + * \param sig signature. + * \param sig_len signature length (in bytes). + * \return 1 on success, 0 on error. + */ +uint32_t br_ecdsa_i15_vrfy_asn1(const br_ec_impl *impl, + const void *hash, size_t hash_len, + const br_ec_public_key *pk, const void *sig, size_t sig_len); + +/** + * \brief ECDSA signature verifier, "i15" implementation, "raw" format. + * + * \see br_ecdsa_vrfy() + * + * \param impl EC implementation to use. + * \param hash signed data (hashed). + * \param hash_len hash value length (in bytes). + * \param pk EC public key. + * \param sig signature. + * \param sig_len signature length (in bytes). + * \return 1 on success, 0 on error. + */ +uint32_t br_ecdsa_i15_vrfy_raw(const br_ec_impl *impl, + const void *hash, size_t hash_len, + const br_ec_public_key *pk, const void *sig, size_t sig_len); + +/** + * \brief Get "default" ECDSA implementation (signer, asn1 format). + * + * This returns the preferred implementation of ECDSA signature generation + * ("asn1" output format) on the current system. + * + * \return the default implementation. + */ +br_ecdsa_sign br_ecdsa_sign_asn1_get_default(void); + +/** + * \brief Get "default" ECDSA implementation (signer, raw format). + * + * This returns the preferred implementation of ECDSA signature generation + * ("raw" output format) on the current system. + * + * \return the default implementation. + */ +br_ecdsa_sign br_ecdsa_sign_raw_get_default(void); + +/** + * \brief Get "default" ECDSA implementation (verifier, asn1 format). + * + * This returns the preferred implementation of ECDSA signature verification + * ("asn1" output format) on the current system. + * + * \return the default implementation. + */ +br_ecdsa_vrfy br_ecdsa_vrfy_asn1_get_default(void); + +/** + * \brief Get "default" ECDSA implementation (verifier, raw format). + * + * This returns the preferred implementation of ECDSA signature verification + * ("raw" output format) on the current system. + * + * \return the default implementation. + */ +br_ecdsa_vrfy br_ecdsa_vrfy_raw_get_default(void); + +/** + * \brief Maximum size for EC private key element buffer. + * + * This is the largest number of bytes that `br_ec_keygen()` may need or + * ever return. + */ +#define BR_EC_KBUF_PRIV_MAX_SIZE 72 + +/** + * \brief Maximum size for EC public key element buffer. + * + * This is the largest number of bytes that `br_ec_compute_public()` may + * need or ever return. + */ +#define BR_EC_KBUF_PUB_MAX_SIZE 145 + +/** + * \brief Generate a new EC private key. + * + * If the specified `curve` is not supported by the elliptic curve + * implementation (`impl`), then this function returns zero. + * + * The `sk` structure fields are set to the new private key data. In + * particular, `sk.x` is made to point to the provided key buffer (`kbuf`), + * in which the actual private key data is written. That buffer is assumed + * to be large enough. The `BR_EC_KBUF_PRIV_MAX_SIZE` defines the maximum + * size for all supported curves. + * + * The number of bytes used in `kbuf` is returned. If `kbuf` is `NULL`, then + * the private key is not actually generated, and `sk` may also be `NULL`; + * the minimum length for `kbuf` is still computed and returned. + * + * If `sk` is `NULL` but `kbuf` is not `NULL`, then the private key is + * still generated and stored in `kbuf`. + * + * \param rng_ctx source PRNG context (already initialized). + * \param impl the elliptic curve implementation. + * \param sk the private key structure to fill, or `NULL`. + * \param kbuf the key element buffer, or `NULL`. + * \param curve the curve identifier. + * \return the key data length (in bytes), or zero. + */ +size_t br_ec_keygen(const br_prng_class **rng_ctx, + const br_ec_impl *impl, br_ec_private_key *sk, + void *kbuf, int curve); + +/** + * \brief Compute EC public key from EC private key. + * + * This function uses the provided elliptic curve implementation (`impl`) + * to compute the public key corresponding to the private key held in `sk`. + * The public key point is written into `kbuf`, which is then linked from + * the `*pk` structure. The size of the public key point, i.e. the number + * of bytes used in `kbuf`, is returned. + * + * If `kbuf` is `NULL`, then the public key point is NOT computed, and + * the public key structure `*pk` is unmodified (`pk` may be `NULL` in + * that case). The size of the public key point is still returned. + * + * If `pk` is `NULL` but `kbuf` is not `NULL`, then the public key + * point is computed and stored in `kbuf`, and its size is returned. + * + * If the curve used by the private key is not supported by the curve + * implementation, then this function returns zero. + * + * The private key MUST be valid. An off-range private key value is not + * necessarily detected, and leads to unpredictable results. + * + * \param impl the elliptic curve implementation. + * \param pk the public key structure to fill (or `NULL`). + * \param kbuf the public key point buffer (or `NULL`). + * \param sk the source private key. + * \return the public key point length (in bytes), or zero. + */ +size_t br_ec_compute_pub(const br_ec_impl *impl, br_ec_public_key *pk, + void *kbuf, const br_ec_private_key *sk); + +#ifdef __cplusplus +} +#endif + +#endif + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/bearssl_hash.h b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/bearssl_hash.h new file mode 100644 index 000000000..8d5a2a8ee --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/bearssl_hash.h @@ -0,0 +1,1352 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#ifndef BR_BEARSSL_HASH_H__ +#define BR_BEARSSL_HASH_H__ + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** \file bearssl_hash.h + * + * # Hash Functions + * + * This file documents the API for hash functions. + * + * + * ## Procedural API + * + * For each implemented hash function, of name "`xxx`", the following + * elements are defined: + * + * - `br_xxx_vtable` + * + * An externally defined instance of `br_hash_class`. + * + * - `br_xxx_SIZE` + * + * A macro that evaluates to the output size (in bytes) of the + * hash function. + * + * - `br_xxx_ID` + * + * A macro that evaluates to a symbolic identifier for the hash + * function. Such identifiers are used with HMAC and signature + * algorithm implementations. + * + * NOTE: for the "standard" hash functions defined in [the TLS + * standard](https://tools.ietf.org/html/rfc5246#section-7.4.1.4.1), + * the symbolic identifiers match the constants used in TLS, i.e. + * 1 to 6 for MD5, SHA-1, SHA-224, SHA-256, SHA-384 and SHA-512, + * respectively. + * + * - `br_xxx_context` + * + * Context for an ongoing computation. It is allocated by the + * caller, and a pointer to it is passed to all functions. A + * context contains no interior pointer, so it can be moved around + * and cloned (with a simple `memcpy()` or equivalent) in order to + * capture the function state at some point. Computations that use + * distinct context structures are independent of each other. The + * first field of `br_xxx_context` is always a pointer to the + * `br_xxx_vtable` structure; `br_xxx_init()` sets that pointer. + * + * - `br_xxx_init(br_xxx_context *ctx)` + * + * Initialise the provided context. Previous contents of the structure + * are ignored. This calls resets the context to the start of a new + * hash computation; it also sets the first field of the context + * structure (called `vtable`) to a pointer to the statically + * allocated constant `br_xxx_vtable` structure. + * + * - `br_xxx_update(br_xxx_context *ctx, const void *data, size_t len)` + * + * Add some more bytes to the hash computation represented by the + * provided context. + * + * - `br_xxx_out(const br_xxx_context *ctx, void *out)` + * + * Complete the hash computation and write the result in the provided + * buffer. The output buffer MUST be large enough to accommodate the + * result. The context is NOT modified by this operation, so this + * function can be used to get a "partial hash" while still keeping + * the possibility of adding more bytes to the input. + * + * - `br_xxx_state(const br_xxx_context *ctx, void *out)` + * + * Get a copy of the "current state" for the computation so far. For + * MD functions (MD5, SHA-1, SHA-2 family), this is the running state + * resulting from the processing of the last complete input block. + * Returned value is the current input length (in bytes). + * + * - `br_xxx_set_state(br_xxx_context *ctx, const void *stb, uint64_t count)` + * + * Set the internal state to the provided values. The 'stb' and + * 'count' values shall match that which was obtained from + * `br_xxx_state()`. This restores the hash state only if the state + * values were at an appropriate block boundary. This does NOT set + * the `vtable` pointer in the context. + * + * Context structures can be discarded without any explicit deallocation. + * Hash function implementations are purely software and don't reserve + * any resources outside of the context structure itself. + * + * + * ## Object-Oriented API + * + * For each hash function that follows the procedural API described + * above, an object-oriented API is also provided. In that API, function + * pointers from the vtable (`br_xxx_vtable`) are used. The vtable + * incarnates object-oriented programming. An introduction on the OOP + * concept used here can be read on the BearSSL Web site:
+ *    [https://www.bearssl.org/oop.html](https://www.bearssl.org/oop.html) + * + * The vtable offers functions called `init()`, `update()`, `out()`, + * `set()` and `set_state()`, which are in fact the functions from + * the procedural API. That vtable also contains two informative fields: + * + * - `context_size` + * + * The size of the context structure (`br_xxx_context`), in bytes. + * This can be used by generic implementations to perform dynamic + * context allocation. + * + * - `desc` + * + * A "descriptor" field that encodes some information on the hash + * function: symbolic identifier, output size, state size, + * internal block size, details on the padding. + * + * Users of this object-oriented API (in particular generic HMAC + * implementations) may make the following assumptions: + * + * - Hash output size is no more than 64 bytes. + * - Hash internal state size is no more than 64 bytes. + * - Internal block size is a power of two, no less than 16 and no more + * than 256. + * + * + * ## Implemented Hash Functions + * + * Implemented hash functions are: + * + * | Function | Name | Output length | State length | + * | :-------- | :------ | :-----------: | :----------: | + * | MD5 | md5 | 16 | 16 | + * | SHA-1 | sha1 | 20 | 20 | + * | SHA-224 | sha224 | 28 | 32 | + * | SHA-256 | sha256 | 32 | 32 | + * | SHA-384 | sha384 | 48 | 64 | + * | SHA-512 | sha512 | 64 | 64 | + * | MD5+SHA-1 | md5sha1 | 36 | 36 | + * + * (MD5+SHA-1 is the concatenation of MD5 and SHA-1 computed over the + * same input; in the implementation, the internal data buffer is + * shared, thus making it more memory-efficient than separate MD5 and + * SHA-1. It can be useful in implementing SSL 3.0, TLS 1.0 and TLS + * 1.1.) + * + * + * ## Multi-Hasher + * + * An aggregate hasher is provided, that can compute several standard + * hash functions in parallel. It uses `br_multihash_context` and a + * procedural API. It is configured with the implementations (the vtables) + * that it should use; it will then compute all these hash functions in + * parallel, on the same input. It is meant to be used in cases when the + * hash of an object will be used, but the exact hash function is not + * known yet (typically, streamed processing on X.509 certificates). + * + * Only the standard hash functions (MD5, SHA-1, SHA-224, SHA-256, SHA-384 + * and SHA-512) are supported by the multi-hasher. + * + * + * ## GHASH + * + * GHASH is not a generic hash function; it is a _universal_ hash function, + * which, as the name does not say, means that it CANNOT be used in most + * places where a hash function is needed. GHASH is used within the GCM + * encryption mode, to provide the checked integrity functionality. + * + * A GHASH implementation is basically a function that uses the type defined + * in this file under the name `br_ghash`: + * + * typedef void (*br_ghash)(void *y, const void *h, const void *data, size_t len); + * + * The `y` pointer refers to a 16-byte value which is used as input, and + * receives the output of the GHASH invocation. `h` is a 16-byte secret + * value (that serves as key). `data` and `len` define the input data. + * + * Three GHASH implementations are provided, all constant-time, based on + * the use of integer multiplications with appropriate masking to cancel + * carry propagation. + */ + +/** + * \brief Class type for hash function implementations. + * + * A `br_hash_class` instance references the methods implementing a hash + * function. Constant instances of this structure are defined for each + * implemented hash function. Such instances are also called "vtables". + * + * Vtables are used to support object-oriented programming, as + * described on [the BearSSL Web site](https://www.bearssl.org/oop.html). + */ +typedef struct br_hash_class_ br_hash_class; +struct br_hash_class_ { + /** + * \brief Size (in bytes) of the context structure appropriate for + * computing this hash function. + */ + size_t context_size; + + /** + * \brief Descriptor word that contains information about the hash + * function. + * + * For each word `xxx` described below, use `BR_HASHDESC_xxx_OFF` + * and `BR_HASHDESC_xxx_MASK` to access the specific value, as + * follows: + * + * (hf->desc >> BR_HASHDESC_xxx_OFF) & BR_HASHDESC_xxx_MASK + * + * The defined elements are: + * + * - `ID`: the symbolic identifier for the function, as defined + * in [TLS](https://tools.ietf.org/html/rfc5246#section-7.4.1.4.1) + * (MD5 = 1, SHA-1 = 2,...). + * + * - `OUT`: hash output size, in bytes. + * + * - `STATE`: internal running state size, in bytes. + * + * - `LBLEN`: base-2 logarithm for the internal block size, as + * defined for HMAC processing (this is 6 for MD5, SHA-1, SHA-224 + * and SHA-256, since these functions use 64-byte blocks; for + * SHA-384 and SHA-512, this is 7, corresponding to their + * 128-byte blocks). + * + * The descriptor may contain a few other flags. + */ + uint32_t desc; + + /** + * \brief Initialisation method. + * + * This method takes as parameter a pointer to a context area, + * that it initialises. The first field of the context is set + * to this vtable; other elements are initialised for a new hash + * computation. + * + * \param ctx pointer to (the first field of) the context. + */ + void (*init)(const br_hash_class **ctx); + + /** + * \brief Data injection method. + * + * The `len` bytes starting at address `data` are injected into + * the running hash computation incarnated by the specified + * context. The context is updated accordingly. It is allowed + * to have `len == 0`, in which case `data` is ignored (and could + * be `NULL`), and nothing happens. + * on the input data. + * + * \param ctx pointer to (the first field of) the context. + * \param data pointer to the first data byte to inject. + * \param len number of bytes to inject. + */ + void (*update)(const br_hash_class **ctx, const void *data, size_t len); + + /** + * \brief Produce hash output. + * + * The hash output corresponding to all data bytes injected in the + * context since the last `init()` call is computed, and written + * in the buffer pointed to by `dst`. The hash output size depends + * on the implemented hash function (e.g. 16 bytes for MD5). + * The context is _not_ modified by this call, so further bytes + * may be afterwards injected to continue the current computation. + * + * \param ctx pointer to (the first field of) the context. + * \param dst destination buffer for the hash output. + */ + void (*out)(const br_hash_class *const *ctx, void *dst); + + /** + * \brief Get running state. + * + * This method saves the current running state into the `dst` + * buffer. What constitutes the "running state" depends on the + * hash function; for Merkle-Damgård hash functions (like + * MD5 or SHA-1), this is the output obtained after processing + * each block. The number of bytes injected so far is returned. + * The context is not modified by this call. + * + * \param ctx pointer to (the first field of) the context. + * \param dst destination buffer for the state. + * \return the injected total byte length. + */ + uint64_t (*state)(const br_hash_class *const *ctx, void *dst); + + /** + * \brief Set running state. + * + * This methods replaces the running state for the function. + * + * \param ctx pointer to (the first field of) the context. + * \param stb source buffer for the state. + * \param count injected total byte length. + */ + void (*set_state)(const br_hash_class **ctx, + const void *stb, uint64_t count); +}; + +#ifndef BR_DOXYGEN_IGNORE +#define BR_HASHDESC_ID(id) ((uint32_t)(id) << BR_HASHDESC_ID_OFF) +#define BR_HASHDESC_ID_OFF 0 +#define BR_HASHDESC_ID_MASK 0xFF + +#define BR_HASHDESC_OUT(size) ((uint32_t)(size) << BR_HASHDESC_OUT_OFF) +#define BR_HASHDESC_OUT_OFF 8 +#define BR_HASHDESC_OUT_MASK 0x7F + +#define BR_HASHDESC_STATE(size) ((uint32_t)(size) << BR_HASHDESC_STATE_OFF) +#define BR_HASHDESC_STATE_OFF 15 +#define BR_HASHDESC_STATE_MASK 0xFF + +#define BR_HASHDESC_LBLEN(ls) ((uint32_t)(ls) << BR_HASHDESC_LBLEN_OFF) +#define BR_HASHDESC_LBLEN_OFF 23 +#define BR_HASHDESC_LBLEN_MASK 0x0F + +#define BR_HASHDESC_MD_PADDING ((uint32_t)1 << 28) +#define BR_HASHDESC_MD_PADDING_128 ((uint32_t)1 << 29) +#define BR_HASHDESC_MD_PADDING_BE ((uint32_t)1 << 30) +#endif + +/* + * Specific hash functions. + * + * Rules for contexts: + * -- No interior pointer. + * -- No pointer to external dynamically allocated resources. + * -- First field is called 'vtable' and is a pointer to a + * const-qualified br_hash_class instance (pointer is set by init()). + * -- SHA-224 and SHA-256 contexts are identical. + * -- SHA-384 and SHA-512 contexts are identical. + * + * Thus, contexts can be moved and cloned to capture the hash function + * current state; and there is no need for any explicit "release" function. + */ + +/** + * \brief Symbolic identifier for MD5. + */ +#define br_md5_ID 1 + +/** + * \brief MD5 output size (in bytes). + */ +#define br_md5_SIZE 16 + +/** + * \brief Constant vtable for MD5. + */ +extern const br_hash_class br_md5_vtable; + +/** + * \brief MD5 context. + * + * First field is a pointer to the vtable; it is set by the initialisation + * function. Other fields are not supposed to be accessed by user code. + */ +typedef struct { + /** + * \brief Pointer to vtable for this context. + */ + const br_hash_class *vtable; +#ifndef BR_DOXYGEN_IGNORE + unsigned char buf[64]; + uint64_t count; + uint32_t val[4]; +#endif +} br_md5_context; + +/** + * \brief MD5 context initialisation. + * + * This function initialises or resets a context for a new MD5 + * computation. It also sets the vtable pointer. + * + * \param ctx pointer to the context structure. + */ +void br_md5_init(br_md5_context *ctx); + +/** + * \brief Inject some data bytes in a running MD5 computation. + * + * The provided context is updated with some data bytes. If the number + * of bytes (`len`) is zero, then the data pointer (`data`) is ignored + * and may be `NULL`, and this function does nothing. + * + * \param ctx pointer to the context structure. + * \param data pointer to the injected data. + * \param len injected data length (in bytes). + */ +void br_md5_update(br_md5_context *ctx, const void *data, size_t len); + +/** + * \brief Compute MD5 output. + * + * The MD5 output for the concatenation of all bytes injected in the + * provided context since the last initialisation or reset call, is + * computed and written in the buffer pointed to by `out`. The context + * itself is not modified, so extra bytes may be injected afterwards + * to continue that computation. + * + * \param ctx pointer to the context structure. + * \param out destination buffer for the hash output. + */ +void br_md5_out(const br_md5_context *ctx, void *out); + +/** + * \brief Save MD5 running state. + * + * The running state for MD5 (output of the last internal block + * processing) is written in the buffer pointed to by `out`. The + * number of bytes injected since the last initialisation or reset + * call is returned. The context is not modified. + * + * \param ctx pointer to the context structure. + * \param out destination buffer for the running state. + * \return the injected total byte length. + */ +uint64_t br_md5_state(const br_md5_context *ctx, void *out); + +/** + * \brief Restore MD5 running state. + * + * The running state for MD5 is set to the provided values. + * + * \param ctx pointer to the context structure. + * \param stb source buffer for the running state. + * \param count the injected total byte length. + */ +void br_md5_set_state(br_md5_context *ctx, const void *stb, uint64_t count); + +/** + * \brief Symbolic identifier for SHA-1. + */ +#define br_sha1_ID 2 + +/** + * \brief SHA-1 output size (in bytes). + */ +#define br_sha1_SIZE 20 + +/** + * \brief Constant vtable for SHA-1. + */ +extern const br_hash_class br_sha1_vtable; + +/** + * \brief SHA-1 context. + * + * First field is a pointer to the vtable; it is set by the initialisation + * function. Other fields are not supposed to be accessed by user code. + */ +typedef struct { + /** + * \brief Pointer to vtable for this context. + */ + const br_hash_class *vtable; +#ifndef BR_DOXYGEN_IGNORE + unsigned char buf[64]; + uint64_t count; + uint32_t val[5]; +#endif +} br_sha1_context; + +/** + * \brief SHA-1 context initialisation. + * + * This function initialises or resets a context for a new SHA-1 + * computation. It also sets the vtable pointer. + * + * \param ctx pointer to the context structure. + */ +void br_sha1_init(br_sha1_context *ctx); + +/** + * \brief Inject some data bytes in a running SHA-1 computation. + * + * The provided context is updated with some data bytes. If the number + * of bytes (`len`) is zero, then the data pointer (`data`) is ignored + * and may be `NULL`, and this function does nothing. + * + * \param ctx pointer to the context structure. + * \param data pointer to the injected data. + * \param len injected data length (in bytes). + */ +void br_sha1_update(br_sha1_context *ctx, const void *data, size_t len); + +/** + * \brief Compute SHA-1 output. + * + * The SHA-1 output for the concatenation of all bytes injected in the + * provided context since the last initialisation or reset call, is + * computed and written in the buffer pointed to by `out`. The context + * itself is not modified, so extra bytes may be injected afterwards + * to continue that computation. + * + * \param ctx pointer to the context structure. + * \param out destination buffer for the hash output. + */ +void br_sha1_out(const br_sha1_context *ctx, void *out); + +/** + * \brief Save SHA-1 running state. + * + * The running state for SHA-1 (output of the last internal block + * processing) is written in the buffer pointed to by `out`. The + * number of bytes injected since the last initialisation or reset + * call is returned. The context is not modified. + * + * \param ctx pointer to the context structure. + * \param out destination buffer for the running state. + * \return the injected total byte length. + */ +uint64_t br_sha1_state(const br_sha1_context *ctx, void *out); + +/** + * \brief Restore SHA-1 running state. + * + * The running state for SHA-1 is set to the provided values. + * + * \param ctx pointer to the context structure. + * \param stb source buffer for the running state. + * \param count the injected total byte length. + */ +void br_sha1_set_state(br_sha1_context *ctx, const void *stb, uint64_t count); + +/** + * \brief Symbolic identifier for SHA-224. + */ +#define br_sha224_ID 3 + +/** + * \brief SHA-224 output size (in bytes). + */ +#define br_sha224_SIZE 28 + +/** + * \brief Constant vtable for SHA-224. + */ +extern const br_hash_class br_sha224_vtable; + +/** + * \brief SHA-224 context. + * + * First field is a pointer to the vtable; it is set by the initialisation + * function. Other fields are not supposed to be accessed by user code. + */ +typedef struct { + /** + * \brief Pointer to vtable for this context. + */ + const br_hash_class *vtable; +#ifndef BR_DOXYGEN_IGNORE + unsigned char buf[64]; + uint64_t count; + uint32_t val[8]; +#endif +} br_sha224_context; + +/** + * \brief SHA-224 context initialisation. + * + * This function initialises or resets a context for a new SHA-224 + * computation. It also sets the vtable pointer. + * + * \param ctx pointer to the context structure. + */ +void br_sha224_init(br_sha224_context *ctx); + +/** + * \brief Inject some data bytes in a running SHA-224 computation. + * + * The provided context is updated with some data bytes. If the number + * of bytes (`len`) is zero, then the data pointer (`data`) is ignored + * and may be `NULL`, and this function does nothing. + * + * \param ctx pointer to the context structure. + * \param data pointer to the injected data. + * \param len injected data length (in bytes). + */ +void br_sha224_update(br_sha224_context *ctx, const void *data, size_t len); + +/** + * \brief Compute SHA-224 output. + * + * The SHA-224 output for the concatenation of all bytes injected in the + * provided context since the last initialisation or reset call, is + * computed and written in the buffer pointed to by `out`. The context + * itself is not modified, so extra bytes may be injected afterwards + * to continue that computation. + * + * \param ctx pointer to the context structure. + * \param out destination buffer for the hash output. + */ +void br_sha224_out(const br_sha224_context *ctx, void *out); + +/** + * \brief Save SHA-224 running state. + * + * The running state for SHA-224 (output of the last internal block + * processing) is written in the buffer pointed to by `out`. The + * number of bytes injected since the last initialisation or reset + * call is returned. The context is not modified. + * + * \param ctx pointer to the context structure. + * \param out destination buffer for the running state. + * \return the injected total byte length. + */ +uint64_t br_sha224_state(const br_sha224_context *ctx, void *out); + +/** + * \brief Restore SHA-224 running state. + * + * The running state for SHA-224 is set to the provided values. + * + * \param ctx pointer to the context structure. + * \param stb source buffer for the running state. + * \param count the injected total byte length. + */ +void br_sha224_set_state(br_sha224_context *ctx, + const void *stb, uint64_t count); + +/** + * \brief Symbolic identifier for SHA-256. + */ +#define br_sha256_ID 4 + +/** + * \brief SHA-256 output size (in bytes). + */ +#define br_sha256_SIZE 32 + +/** + * \brief Constant vtable for SHA-256. + */ +extern const br_hash_class br_sha256_vtable; + +#ifdef BR_DOXYGEN_IGNORE +/** + * \brief SHA-256 context. + * + * First field is a pointer to the vtable; it is set by the initialisation + * function. Other fields are not supposed to be accessed by user code. + */ +typedef struct { + /** + * \brief Pointer to vtable for this context. + */ + const br_hash_class *vtable; +} br_sha256_context; +#else +typedef br_sha224_context br_sha256_context; +#endif + +/** + * \brief SHA-256 context initialisation. + * + * This function initialises or resets a context for a new SHA-256 + * computation. It also sets the vtable pointer. + * + * \param ctx pointer to the context structure. + */ +void br_sha256_init(br_sha256_context *ctx); + +#ifdef BR_DOXYGEN_IGNORE +/** + * \brief Inject some data bytes in a running SHA-256 computation. + * + * The provided context is updated with some data bytes. If the number + * of bytes (`len`) is zero, then the data pointer (`data`) is ignored + * and may be `NULL`, and this function does nothing. + * + * \param ctx pointer to the context structure. + * \param data pointer to the injected data. + * \param len injected data length (in bytes). + */ +void br_sha256_update(br_sha256_context *ctx, const void *data, size_t len); +#else +#define br_sha256_update br_sha224_update +#endif + +/** + * \brief Compute SHA-256 output. + * + * The SHA-256 output for the concatenation of all bytes injected in the + * provided context since the last initialisation or reset call, is + * computed and written in the buffer pointed to by `out`. The context + * itself is not modified, so extra bytes may be injected afterwards + * to continue that computation. + * + * \param ctx pointer to the context structure. + * \param out destination buffer for the hash output. + */ +void br_sha256_out(const br_sha256_context *ctx, void *out); + +#ifdef BR_DOXYGEN_IGNORE +/** + * \brief Save SHA-256 running state. + * + * The running state for SHA-256 (output of the last internal block + * processing) is written in the buffer pointed to by `out`. The + * number of bytes injected since the last initialisation or reset + * call is returned. The context is not modified. + * + * \param ctx pointer to the context structure. + * \param out destination buffer for the running state. + * \return the injected total byte length. + */ +uint64_t br_sha256_state(const br_sha256_context *ctx, void *out); +#else +#define br_sha256_state br_sha224_state +#endif + +#ifdef BR_DOXYGEN_IGNORE +/** + * \brief Restore SHA-256 running state. + * + * The running state for SHA-256 is set to the provided values. + * + * \param ctx pointer to the context structure. + * \param stb source buffer for the running state. + * \param count the injected total byte length. + */ +void br_sha256_set_state(br_sha256_context *ctx, + const void *stb, uint64_t count); +#else +#define br_sha256_set_state br_sha224_set_state +#endif + +/** + * \brief Symbolic identifier for SHA-384. + */ +#define br_sha384_ID 5 + +/** + * \brief SHA-384 output size (in bytes). + */ +#define br_sha384_SIZE 48 + +/** + * \brief Constant vtable for SHA-384. + */ +extern const br_hash_class br_sha384_vtable; + +/** + * \brief SHA-384 context. + * + * First field is a pointer to the vtable; it is set by the initialisation + * function. Other fields are not supposed to be accessed by user code. + */ +typedef struct { + /** + * \brief Pointer to vtable for this context. + */ + const br_hash_class *vtable; +#ifndef BR_DOXYGEN_IGNORE + unsigned char buf[128]; + uint64_t count; + uint64_t val[8]; +#endif +} br_sha384_context; + +/** + * \brief SHA-384 context initialisation. + * + * This function initialises or resets a context for a new SHA-384 + * computation. It also sets the vtable pointer. + * + * \param ctx pointer to the context structure. + */ +void br_sha384_init(br_sha384_context *ctx); + +/** + * \brief Inject some data bytes in a running SHA-384 computation. + * + * The provided context is updated with some data bytes. If the number + * of bytes (`len`) is zero, then the data pointer (`data`) is ignored + * and may be `NULL`, and this function does nothing. + * + * \param ctx pointer to the context structure. + * \param data pointer to the injected data. + * \param len injected data length (in bytes). + */ +void br_sha384_update(br_sha384_context *ctx, const void *data, size_t len); + +/** + * \brief Compute SHA-384 output. + * + * The SHA-384 output for the concatenation of all bytes injected in the + * provided context since the last initialisation or reset call, is + * computed and written in the buffer pointed to by `out`. The context + * itself is not modified, so extra bytes may be injected afterwards + * to continue that computation. + * + * \param ctx pointer to the context structure. + * \param out destination buffer for the hash output. + */ +void br_sha384_out(const br_sha384_context *ctx, void *out); + +/** + * \brief Save SHA-384 running state. + * + * The running state for SHA-384 (output of the last internal block + * processing) is written in the buffer pointed to by `out`. The + * number of bytes injected since the last initialisation or reset + * call is returned. The context is not modified. + * + * \param ctx pointer to the context structure. + * \param out destination buffer for the running state. + * \return the injected total byte length. + */ +uint64_t br_sha384_state(const br_sha384_context *ctx, void *out); + +/** + * \brief Restore SHA-384 running state. + * + * The running state for SHA-384 is set to the provided values. + * + * \param ctx pointer to the context structure. + * \param stb source buffer for the running state. + * \param count the injected total byte length. + */ +void br_sha384_set_state(br_sha384_context *ctx, + const void *stb, uint64_t count); + +/** + * \brief Symbolic identifier for SHA-512. + */ +#define br_sha512_ID 6 + +/** + * \brief SHA-512 output size (in bytes). + */ +#define br_sha512_SIZE 64 + +/** + * \brief Constant vtable for SHA-512. + */ +extern const br_hash_class br_sha512_vtable; + +#ifdef BR_DOXYGEN_IGNORE +/** + * \brief SHA-512 context. + * + * First field is a pointer to the vtable; it is set by the initialisation + * function. Other fields are not supposed to be accessed by user code. + */ +typedef struct { + /** + * \brief Pointer to vtable for this context. + */ + const br_hash_class *vtable; +} br_sha512_context; +#else +typedef br_sha384_context br_sha512_context; +#endif + +/** + * \brief SHA-512 context initialisation. + * + * This function initialises or resets a context for a new SHA-512 + * computation. It also sets the vtable pointer. + * + * \param ctx pointer to the context structure. + */ +void br_sha512_init(br_sha512_context *ctx); + +#ifdef BR_DOXYGEN_IGNORE +/** + * \brief Inject some data bytes in a running SHA-512 computation. + * + * The provided context is updated with some data bytes. If the number + * of bytes (`len`) is zero, then the data pointer (`data`) is ignored + * and may be `NULL`, and this function does nothing. + * + * \param ctx pointer to the context structure. + * \param data pointer to the injected data. + * \param len injected data length (in bytes). + */ +void br_sha512_update(br_sha512_context *ctx, const void *data, size_t len); +#else +#define br_sha512_update br_sha384_update +#endif + +/** + * \brief Compute SHA-512 output. + * + * The SHA-512 output for the concatenation of all bytes injected in the + * provided context since the last initialisation or reset call, is + * computed and written in the buffer pointed to by `out`. The context + * itself is not modified, so extra bytes may be injected afterwards + * to continue that computation. + * + * \param ctx pointer to the context structure. + * \param out destination buffer for the hash output. + */ +void br_sha512_out(const br_sha512_context *ctx, void *out); + +#ifdef BR_DOXYGEN_IGNORE +/** + * \brief Save SHA-512 running state. + * + * The running state for SHA-512 (output of the last internal block + * processing) is written in the buffer pointed to by `out`. The + * number of bytes injected since the last initialisation or reset + * call is returned. The context is not modified. + * + * \param ctx pointer to the context structure. + * \param out destination buffer for the running state. + * \return the injected total byte length. + */ +uint64_t br_sha512_state(const br_sha512_context *ctx, void *out); +#else +#define br_sha512_state br_sha384_state +#endif + +#ifdef BR_DOXYGEN_IGNORE +/** + * \brief Restore SHA-512 running state. + * + * The running state for SHA-512 is set to the provided values. + * + * \param ctx pointer to the context structure. + * \param stb source buffer for the running state. + * \param count the injected total byte length. + */ +void br_sha512_set_state(br_sha512_context *ctx, + const void *stb, uint64_t count); +#else +#define br_sha512_set_state br_sha384_set_state +#endif + +/* + * "md5sha1" is a special hash function that computes both MD5 and SHA-1 + * on the same input, and produces a 36-byte output (MD5 and SHA-1 + * concatenation, in that order). State size is also 36 bytes. + */ + +/** + * \brief Symbolic identifier for MD5+SHA-1. + * + * MD5+SHA-1 is the concatenation of MD5 and SHA-1, computed over the + * same input. It is not one of the functions identified in TLS, so + * we give it a symbolic identifier of value 0. + */ +#define br_md5sha1_ID 0 + +/** + * \brief MD5+SHA-1 output size (in bytes). + */ +#define br_md5sha1_SIZE 36 + +/** + * \brief Constant vtable for MD5+SHA-1. + */ +extern const br_hash_class br_md5sha1_vtable; + +/** + * \brief MD5+SHA-1 context. + * + * First field is a pointer to the vtable; it is set by the initialisation + * function. Other fields are not supposed to be accessed by user code. + */ +typedef struct { + /** + * \brief Pointer to vtable for this context. + */ + const br_hash_class *vtable; +#ifndef BR_DOXYGEN_IGNORE + unsigned char buf[64]; + uint64_t count; + uint32_t val_md5[4]; + uint32_t val_sha1[5]; +#endif +} br_md5sha1_context; + +/** + * \brief MD5+SHA-1 context initialisation. + * + * This function initialises or resets a context for a new SHA-512 + * computation. It also sets the vtable pointer. + * + * \param ctx pointer to the context structure. + */ +void br_md5sha1_init(br_md5sha1_context *ctx); + +/** + * \brief Inject some data bytes in a running MD5+SHA-1 computation. + * + * The provided context is updated with some data bytes. If the number + * of bytes (`len`) is zero, then the data pointer (`data`) is ignored + * and may be `NULL`, and this function does nothing. + * + * \param ctx pointer to the context structure. + * \param data pointer to the injected data. + * \param len injected data length (in bytes). + */ +void br_md5sha1_update(br_md5sha1_context *ctx, const void *data, size_t len); + +/** + * \brief Compute MD5+SHA-1 output. + * + * The MD5+SHA-1 output for the concatenation of all bytes injected in the + * provided context since the last initialisation or reset call, is + * computed and written in the buffer pointed to by `out`. The context + * itself is not modified, so extra bytes may be injected afterwards + * to continue that computation. + * + * \param ctx pointer to the context structure. + * \param out destination buffer for the hash output. + */ +void br_md5sha1_out(const br_md5sha1_context *ctx, void *out); + +/** + * \brief Save MD5+SHA-1 running state. + * + * The running state for MD5+SHA-1 (output of the last internal block + * processing) is written in the buffer pointed to by `out`. The + * number of bytes injected since the last initialisation or reset + * call is returned. The context is not modified. + * + * \param ctx pointer to the context structure. + * \param out destination buffer for the running state. + * \return the injected total byte length. + */ +uint64_t br_md5sha1_state(const br_md5sha1_context *ctx, void *out); + +/** + * \brief Restore MD5+SHA-1 running state. + * + * The running state for MD5+SHA-1 is set to the provided values. + * + * \param ctx pointer to the context structure. + * \param stb source buffer for the running state. + * \param count the injected total byte length. + */ +void br_md5sha1_set_state(br_md5sha1_context *ctx, + const void *stb, uint64_t count); + +/** + * \brief Aggregate context for configurable hash function support. + * + * The `br_hash_compat_context` type is a type which is large enough to + * serve as context for all standard hash functions defined above. + */ +typedef union { + const br_hash_class *vtable; + br_md5_context md5; + br_sha1_context sha1; + br_sha224_context sha224; + br_sha256_context sha256; + br_sha384_context sha384; + br_sha512_context sha512; + br_md5sha1_context md5sha1; +} br_hash_compat_context; + +/* + * The multi-hasher is a construct that handles hashing of the same input + * data with several hash functions, with a single shared input buffer. + * It can handle MD5, SHA-1, SHA-224, SHA-256, SHA-384 and SHA-512 + * simultaneously, though which functions are activated depends on + * the set implementation pointers. + */ + +/** + * \brief Multi-hasher context structure. + * + * The multi-hasher runs up to six hash functions in the standard TLS list + * (MD5, SHA-1, SHA-224, SHA-256, SHA-384 and SHA-512) in parallel, over + * the same input. + * + * The multi-hasher does _not_ follow the OOP structure with a vtable. + * Instead, it is configured with the vtables of the hash functions it + * should run. Structure fields are not supposed to be accessed directly. + */ +typedef struct { +#ifndef BR_DOXYGEN_IGNORE + unsigned char buf[128]; + uint64_t count; + uint32_t val_32[25]; + uint64_t val_64[16]; + const br_hash_class *impl[6]; +#endif +} br_multihash_context; + +/** + * \brief Clear a multi-hasher context. + * + * This should always be called once on a given context, _before_ setting + * the implementation pointers. + * + * \param ctx the multi-hasher context. + */ +void br_multihash_zero(br_multihash_context *ctx); + +/** + * \brief Set a hash function implementation. + * + * Implementations shall be set _after_ clearing the context (with + * `br_multihash_zero()`) but _before_ initialising the computation + * (with `br_multihash_init()`). The hash function implementation + * MUST be one of the standard hash functions (MD5, SHA-1, SHA-224, + * SHA-256, SHA-384 or SHA-512); it may also be `NULL` to remove + * an implementation from the multi-hasher. + * + * \param ctx the multi-hasher context. + * \param id the hash function symbolic identifier. + * \param impl the hash function vtable, or `NULL`. + */ +static inline void +br_multihash_setimpl(br_multihash_context *ctx, + int id, const br_hash_class *impl) +{ + /* + * This code relies on hash functions ID being values 1 to 6, + * in the MD5 to SHA-512 order. + */ + ctx->impl[id - 1] = impl; +} + +/** + * \brief Get a hash function implementation. + * + * This function returns the currently configured vtable for a given + * hash function (by symbolic ID). If no such function was configured in + * the provided multi-hasher context, then this function returns `NULL`. + * + * \param ctx the multi-hasher context. + * \param id the hash function symbolic identifier. + * \return the hash function vtable, or `NULL`. + */ +static inline const br_hash_class * +br_multihash_getimpl(const br_multihash_context *ctx, int id) +{ + return ctx->impl[id - 1]; +} + +/** + * \brief Reset a multi-hasher context. + * + * This function prepares the context for a new hashing computation, + * for all implementations configured at that point. + * + * \param ctx the multi-hasher context. + */ +void br_multihash_init(br_multihash_context *ctx); + +/** + * \brief Inject some data bytes in a running multi-hashing computation. + * + * The provided context is updated with some data bytes. If the number + * of bytes (`len`) is zero, then the data pointer (`data`) is ignored + * and may be `NULL`, and this function does nothing. + * + * \param ctx pointer to the context structure. + * \param data pointer to the injected data. + * \param len injected data length (in bytes). + */ +void br_multihash_update(br_multihash_context *ctx, + const void *data, size_t len); + +/** + * \brief Compute a hash output from a multi-hasher. + * + * The hash output for the concatenation of all bytes injected in the + * provided context since the last initialisation or reset call, is + * computed and written in the buffer pointed to by `dst`. The hash + * function to use is identified by `id` and must be one of the standard + * hash functions. If that hash function was indeed configured in the + * multi-hasher context, the corresponding hash value is written in + * `dst` and its length (in bytes) is returned. If the hash function + * was _not_ configured, then nothing is written in `dst` and 0 is + * returned. + * + * The context itself is not modified, so extra bytes may be injected + * afterwards to continue the hash computations. + * + * \param ctx pointer to the context structure. + * \param id the hash function symbolic identifier. + * \param dst destination buffer for the hash output. + * \return the hash output length (in bytes), or 0. + */ +size_t br_multihash_out(const br_multihash_context *ctx, int id, void *dst); + +/** + * \brief Type for a GHASH implementation. + * + * GHASH is a sort of keyed hash meant to be used to implement GCM in + * combination with a block cipher (with 16-byte blocks). + * + * The `y` array has length 16 bytes and is used for input and output; in + * a complete GHASH run, it starts with an all-zero value. `h` is a 16-byte + * value that serves as key (it is derived from the encryption key in GCM, + * using the block cipher). The data length (`len`) is expressed in bytes. + * The `y` array is updated. + * + * If the data length is not a multiple of 16, then the data is implicitly + * padded with zeros up to the next multiple of 16. Thus, when using GHASH + * in GCM, this method may be called twice, for the associated data and + * for the ciphertext, respectively; the zero-padding implements exactly + * the GCM rules. + * + * \param y the array to update. + * \param h the GHASH key. + * \param data the input data (may be `NULL` if `len` is zero). + * \param len the input data length (in bytes). + */ +typedef void (*br_ghash)(void *y, const void *h, const void *data, size_t len); + +/** + * \brief GHASH implementation using multiplications (mixed 32-bit). + * + * This implementation uses multiplications of 32-bit values, with a + * 64-bit result. It is constant-time (if multiplications are + * constant-time). + * + * \param y the array to update. + * \param h the GHASH key. + * \param data the input data (may be `NULL` if `len` is zero). + * \param len the input data length (in bytes). + */ +void br_ghash_ctmul(void *y, const void *h, const void *data, size_t len); + +/** + * \brief GHASH implementation using multiplications (strict 32-bit). + * + * This implementation uses multiplications of 32-bit values, with a + * 32-bit result. It is usually somewhat slower than `br_ghash_ctmul()`, + * but it is expected to be faster on architectures for which the + * 32-bit multiplication opcode does not yield the upper 32 bits of the + * product. It is constant-time (if multiplications are constant-time). + * + * \param y the array to update. + * \param h the GHASH key. + * \param data the input data (may be `NULL` if `len` is zero). + * \param len the input data length (in bytes). + */ +void br_ghash_ctmul32(void *y, const void *h, const void *data, size_t len); + +/** + * \brief GHASH implementation using multiplications (64-bit). + * + * This implementation uses multiplications of 64-bit values, with a + * 64-bit result. It is constant-time (if multiplications are + * constant-time). It is substantially faster than `br_ghash_ctmul()` + * and `br_ghash_ctmul32()` on most 64-bit architectures. + * + * \param y the array to update. + * \param h the GHASH key. + * \param data the input data (may be `NULL` if `len` is zero). + * \param len the input data length (in bytes). + */ +void br_ghash_ctmul64(void *y, const void *h, const void *data, size_t len); + +/** + * \brief GHASH implementation using the `pclmulqdq` opcode (part of the + * AES-NI instructions). + * + * This implementation is available only on x86 platforms where the + * compiler supports the relevant intrinsic functions. Even if the + * compiler supports these functions, the local CPU might not support + * the `pclmulqdq` opcode, meaning that a call will fail with an + * illegal instruction exception. To safely obtain a pointer to this + * function when supported (or 0 otherwise), use `br_ghash_pclmul_get()`. + * + * \param y the array to update. + * \param h the GHASH key. + * \param data the input data (may be `NULL` if `len` is zero). + * \param len the input data length (in bytes). + */ +void br_ghash_pclmul(void *y, const void *h, const void *data, size_t len); + +/** + * \brief Obtain the `pclmul` GHASH implementation, if available. + * + * If the `pclmul` implementation was compiled in the library (depending + * on the compiler abilities) _and_ the local CPU appears to support the + * opcode, then this function will return a pointer to the + * `br_ghash_pclmul()` function. Otherwise, it will return `0`. + * + * \return the `pclmul` GHASH implementation, or `0`. + */ +br_ghash br_ghash_pclmul_get(void); + +/** + * \brief GHASH implementation using the POWER8 opcodes. + * + * This implementation is available only on POWER8 platforms (and later). + * To safely obtain a pointer to this function when supported (or 0 + * otherwise), use `br_ghash_pwr8_get()`. + * + * \param y the array to update. + * \param h the GHASH key. + * \param data the input data (may be `NULL` if `len` is zero). + * \param len the input data length (in bytes). + */ +void br_ghash_pwr8(void *y, const void *h, const void *data, size_t len); + +/** + * \brief Obtain the `pwr8` GHASH implementation, if available. + * + * If the `pwr8` implementation was compiled in the library (depending + * on the compiler abilities) _and_ the local CPU appears to support the + * opcode, then this function will return a pointer to the + * `br_ghash_pwr8()` function. Otherwise, it will return `0`. + * + * \return the `pwr8` GHASH implementation, or `0`. + */ +br_ghash br_ghash_pwr8_get(void); + +#ifdef __cplusplus +} +#endif + +#endif + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/bearssl_hmac.h b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/bearssl_hmac.h new file mode 100644 index 000000000..70e9dd11e --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/bearssl_hmac.h @@ -0,0 +1,246 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#ifndef BR_BEARSSL_HMAC_H__ +#define BR_BEARSSL_HMAC_H__ + +#include +#include + +#include "bearssl_hash.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** \file bearssl_hmac.h + * + * # HMAC + * + * HMAC is initialized with a key and an underlying hash function; it + * then fills a "key context". That context contains the processed + * key. + * + * With the key context, a HMAC context can be initialized to process + * the input bytes and obtain the MAC output. The key context is not + * modified during that process, and can be reused. + * + * IMPORTANT: HMAC shall be used only with functions that have the + * following properties: + * + * - hash output size does not exceed 64 bytes; + * - hash internal state size does not exceed 64 bytes; + * - internal block length is a power of 2 between 16 and 256 bytes. + */ + +/** + * \brief HMAC key context. + * + * The HMAC key context is initialised with a hash function implementation + * and a secret key. Contents are opaque (callers should not access them + * directly). The caller is responsible for allocating the context where + * appropriate. Context initialisation and usage incurs no dynamic + * allocation, so there is no release function. + */ +typedef struct { +#ifndef BR_DOXYGEN_IGNORE + const br_hash_class *dig_vtable; + unsigned char ksi[64], kso[64]; +#endif +} br_hmac_key_context; + +/** + * \brief HMAC key context initialisation. + * + * Initialise the key context with the provided key, using the hash function + * identified by `digest_vtable`. This supports arbitrary key lengths. + * + * \param kc HMAC key context to initialise. + * \param digest_vtable pointer to the hash function implementation vtable. + * \param key pointer to the HMAC secret key. + * \param key_len HMAC secret key length (in bytes). + */ +void br_hmac_key_init(br_hmac_key_context *kc, + const br_hash_class *digest_vtable, const void *key, size_t key_len); + +/* + * \brief Get the underlying hash function. + * + * This function returns a pointer to the implementation vtable of the + * hash function used for this HMAC key context. + * + * \param kc HMAC key context. + * \return the hash function implementation. + */ +static inline const br_hash_class *br_hmac_key_get_digest( + const br_hmac_key_context *kc) +{ + return kc->dig_vtable; +} + +/** + * \brief HMAC computation context. + * + * The HMAC computation context maintains the state for a single HMAC + * computation. It is modified as input bytes are injected. The context + * is caller-allocated and has no release function since it does not + * dynamically allocate external resources. Its contents are opaque. + */ +typedef struct { +#ifndef BR_DOXYGEN_IGNORE + br_hash_compat_context dig; + unsigned char kso[64]; + size_t out_len; +#endif +} br_hmac_context; + +/** + * \brief HMAC computation initialisation. + * + * Initialise a HMAC context with a key context. The key context is + * unmodified. Relevant data from the key context is immediately copied; + * the key context can thus be independently reused, modified or released + * without impacting this HMAC computation. + * + * An explicit output length can be specified; the actual output length + * will be the minimum of that value and the natural HMAC output length. + * If `out_len` is 0, then the natural HMAC output length is selected. The + * "natural output length" is the output length of the underlying hash + * function. + * + * \param ctx HMAC context to initialise. + * \param kc HMAC key context (already initialised with the key). + * \param out_len HMAC output length (0 to select "natural length"). + */ +void br_hmac_init(br_hmac_context *ctx, + const br_hmac_key_context *kc, size_t out_len); + +/** + * \brief Get the HMAC output size. + * + * The HMAC output size is the number of bytes that will actually be + * produced with `br_hmac_out()` with the provided context. This function + * MUST NOT be called on a non-initialised HMAC computation context. + * The returned value is the minimum of the HMAC natural length (output + * size of the underlying hash function) and the `out_len` parameter which + * was used with the last `br_hmac_init()` call on that context (if the + * initialisation `out_len` parameter was 0, then this function will + * return the HMAC natural length). + * + * \param ctx the (already initialised) HMAC computation context. + * \return the HMAC actual output size. + */ +static inline size_t +br_hmac_size(br_hmac_context *ctx) +{ + return ctx->out_len; +} + +/* + * \brief Get the underlying hash function. + * + * This function returns a pointer to the implementation vtable of the + * hash function used for this HMAC context. + * + * \param hc HMAC context. + * \return the hash function implementation. + */ +static inline const br_hash_class *br_hmac_get_digest( + const br_hmac_context *hc) +{ + return hc->dig.vtable; +} + +/** + * \brief Inject some bytes in HMAC. + * + * The provided `len` bytes are injected as extra input in the HMAC + * computation incarnated by the `ctx` HMAC context. It is acceptable + * that `len` is zero, in which case `data` is ignored (and may be + * `NULL`) and this function does nothing. + */ +void br_hmac_update(br_hmac_context *ctx, const void *data, size_t len); + +/** + * \brief Compute the HMAC output. + * + * The destination buffer MUST be large enough to accommodate the result; + * its length is at most the "natural length" of HMAC (i.e. the output + * length of the underlying hash function). The context is NOT modified; + * further bytes may be processed. Thus, "partial HMAC" values can be + * efficiently obtained. + * + * Returned value is the output length (in bytes). + * + * \param ctx HMAC computation context. + * \param out destination buffer for the HMAC output. + * \return the produced value length (in bytes). + */ +size_t br_hmac_out(const br_hmac_context *ctx, void *out); + +/** + * \brief Constant-time HMAC computation. + * + * This function compute the HMAC output in constant time. Some extra + * input bytes are processed, then the output is computed. The extra + * input consists in the `len` bytes pointed to by `data`. The `len` + * parameter must lie between `min_len` and `max_len` (inclusive); + * `max_len` bytes are actually read from `data`. Computing time (and + * memory access pattern) will not depend upon the data byte contents or + * the value of `len`. + * + * The output is written in the `out` buffer, that MUST be large enough + * to receive it. + * + * The difference `max_len - min_len` MUST be less than 230 + * (i.e. about one gigabyte). + * + * This function computes the output properly only if the underlying + * hash function uses MD padding (i.e. MD5, SHA-1, SHA-224, SHA-256, + * SHA-384 or SHA-512). + * + * The provided context is NOT modified. + * + * \param ctx the (already initialised) HMAC computation context. + * \param data the extra input bytes. + * \param len the extra input length (in bytes). + * \param min_len minimum extra input length (in bytes). + * \param max_len maximum extra input length (in bytes). + * \param out destination buffer for the HMAC output. + * \return the produced value length (in bytes). + */ +size_t br_hmac_outCT(const br_hmac_context *ctx, + const void *data, size_t len, size_t min_len, size_t max_len, + void *out); + +#ifdef __cplusplus +} +#endif + +#endif + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/bearssl_kdf.h b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/bearssl_kdf.h new file mode 100644 index 000000000..f0968320f --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/bearssl_kdf.h @@ -0,0 +1,289 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#ifndef BR_BEARSSL_KDF_H__ +#define BR_BEARSSL_KDF_H__ + +#include +#include + +#include "bearssl_hash.h" +#include "bearssl_hmac.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** \file bearssl_kdf.h + * + * # Key Derivation Functions + * + * KDF are functions that takes a variable length input, and provide a + * variable length output, meant to be used to derive subkeys from a + * master key. + * + * ## HKDF + * + * HKDF is a KDF defined by [RFC 5869](https://tools.ietf.org/html/rfc5869). + * It is based on HMAC, itself using an underlying hash function. Any + * hash function can be used, as long as it is compatible with the rules + * for the HMAC implementation (i.e. output size is 64 bytes or less, hash + * internal state size is 64 bytes or less, and the internal block length is + * a power of 2 between 16 and 256 bytes). HKDF has two phases: + * + * - HKDF-Extract: the input data in ingested, along with a "salt" value. + * + * - HKDF-Expand: the output is produced, from the result of processing + * the input and salt, and using an extra non-secret parameter called + * "info". + * + * The "salt" and "info" strings are non-secret and can be empty. Their role + * is normally to bind the input and output, respectively, to conventional + * identifiers that qualifu them within the used protocol or application. + * + * The implementation defined in this file uses the following functions: + * + * - `br_hkdf_init()`: initialize an HKDF context, with a hash function, + * and the salt. This starts the HKDF-Extract process. + * + * - `br_hkdf_inject()`: inject more input bytes. This function may be + * called repeatedly if the input data is provided by chunks. + * + * - `br_hkdf_flip()`: end the HKDF-Extract process, and start the + * HKDF-Expand process. + * + * - `br_hkdf_produce()`: get the next bytes of output. This function + * may be called several times to obtain the full output by chunks. + * For correct HKDF processing, the same "info" string must be + * provided for each call. + * + * Note that the HKDF total output size (the number of bytes that + * HKDF-Expand is willing to produce) is limited: if the hash output size + * is _n_ bytes, then the maximum output size is _255*n_. + * + * ## SHAKE + * + * SHAKE is defined in + * [FIPS 202](https://csrc.nist.gov/publications/detail/fips/202/final) + * under two versions: SHAKE128 and SHAKE256, offering an alleged + * "security level" of 128 and 256 bits, respectively (SHAKE128 is + * about 20 to 25% faster than SHAKE256). SHAKE internally relies on + * the Keccak family of sponge functions, not on any externally provided + * hash function. Contrary to HKDF, SHAKE does not have a concept of + * either a "salt" or an "info" string. The API consists in four + * functions: + * + * - `br_shake_init()`: initialize a SHAKE context for a given + * security level. + * + * - `br_shake_inject()`: inject more input bytes. This function may be + * called repeatedly if the input data is provided by chunks. + * + * - `br_shake_flip()`: end the data injection process, and start the + * data production process. + * + * - `br_shake_produce()`: get the next bytes of output. This function + * may be called several times to obtain the full output by chunks. + */ + +/** + * \brief HKDF context. + * + * The HKDF context is initialized with a hash function implementation + * and a salt value. Contents are opaque (callers should not access them + * directly). The caller is responsible for allocating the context where + * appropriate. Context initialisation and usage incurs no dynamic + * allocation, so there is no release function. + */ +typedef struct { +#ifndef BR_DOXYGEN_IGNORE + union { + br_hmac_context hmac_ctx; + br_hmac_key_context prk_ctx; + } u; + unsigned char buf[64]; + size_t ptr; + size_t dig_len; + unsigned chunk_num; +#endif +} br_hkdf_context; + +/** + * \brief HKDF context initialization. + * + * The underlying hash function and salt value are provided. Arbitrary + * salt lengths can be used. + * + * HKDF makes a difference between a salt of length zero, and an + * absent salt (the latter being equivalent to a salt consisting of + * bytes of value zero, of the same length as the hash function output). + * If `salt_len` is zero, then this function assumes that the salt is + * present but of length zero. To specify an _absent_ salt, use + * `BR_HKDF_NO_SALT` as `salt` parameter (`salt_len` is then ignored). + * + * \param hc HKDF context to initialise. + * \param digest_vtable pointer to the hash function implementation vtable. + * \param salt HKDF-Extract salt. + * \param salt_len HKDF-Extract salt length (in bytes). + */ +void br_hkdf_init(br_hkdf_context *hc, const br_hash_class *digest_vtable, + const void *salt, size_t salt_len); + +/** + * \brief The special "absent salt" value for HKDF. + */ +#define BR_HKDF_NO_SALT (&br_hkdf_no_salt) + +#ifndef BR_DOXYGEN_IGNORE +extern const unsigned char br_hkdf_no_salt; +#endif + +/** + * \brief HKDF input injection (HKDF-Extract). + * + * This function injects some more input bytes ("key material") into + * HKDF. This function may be called several times, after `br_hkdf_init()` + * but before `br_hkdf_flip()`. + * + * \param hc HKDF context. + * \param ikm extra input bytes. + * \param ikm_len number of extra input bytes. + */ +void br_hkdf_inject(br_hkdf_context *hc, const void *ikm, size_t ikm_len); + +/** + * \brief HKDF switch to the HKDF-Expand phase. + * + * This call terminates the HKDF-Extract process (input injection), and + * starts the HKDF-Expand process (output production). + * + * \param hc HKDF context. + */ +void br_hkdf_flip(br_hkdf_context *hc); + +/** + * \brief HKDF output production (HKDF-Expand). + * + * Produce more output bytes from the current state. This function may be + * called several times, but only after `br_hkdf_flip()`. + * + * Returned value is the number of actually produced bytes. The total + * output length is limited to 255 times the output length of the + * underlying hash function. + * + * \param hc HKDF context. + * \param info application specific information string. + * \param info_len application specific information string length (in bytes). + * \param out destination buffer for the HKDF output. + * \param out_len the length of the requested output (in bytes). + * \return the produced output length (in bytes). + */ +size_t br_hkdf_produce(br_hkdf_context *hc, + const void *info, size_t info_len, void *out, size_t out_len); + +/** + * \brief SHAKE context. + * + * The HKDF context is initialized with a "security level". The internal + * notion is called "capacity"; the capacity is twice the security level + * (for instance, SHAKE128 has capacity 256). + * + * The caller is responsible for allocating the context where + * appropriate. Context initialisation and usage incurs no dynamic + * allocation, so there is no release function. + */ +typedef struct { +#ifndef BR_DOXYGEN_IGNORE + unsigned char dbuf[200]; + size_t dptr; + size_t rate; + uint64_t A[25]; +#endif +} br_shake_context; + +/** + * \brief SHAKE context initialization. + * + * The context is initialized for the provided "security level". + * Internally, this sets the "capacity" to twice the security level; + * thus, for SHAKE128, the `security_level` parameter should be 128, + * which corresponds to a 256-bit capacity. + * + * Allowed security levels are all multiples of 32, from 32 to 768, + * inclusive. Larger security levels imply lower performance; levels + * beyond 256 bits don't make much sense. Standard levels are 128 + * and 256 bits (for SHAKE128 and SHAKE256, respectively). + * + * \param sc SHAKE context to initialise. + * \param security_level security level (in bits). + */ +void br_shake_init(br_shake_context *sc, int security_level); + +/** + * \brief SHAKE input injection. + * + * This function injects some more input bytes ("key material") into + * SHAKE. This function may be called several times, after `br_shake_init()` + * but before `br_shake_flip()`. + * + * \param sc SHAKE context. + * \param data extra input bytes. + * \param len number of extra input bytes. + */ +void br_shake_inject(br_shake_context *sc, const void *data, size_t len); + +/** + * \brief SHAKE switch to production phase. + * + * This call terminates the input injection process, and starts the + * output production process. + * + * \param sc SHAKE context. + */ +void br_shake_flip(br_shake_context *hc); + +/** + * \brief SHAKE output production. + * + * Produce more output bytes from the current state. This function may be + * called several times, but only after `br_shake_flip()`. + * + * There is no practical limit to the number of bytes that may be produced. + * + * \param sc SHAKE context. + * \param out destination buffer for the SHAKE output. + * \param len the length of the requested output (in bytes). + */ +void br_shake_produce(br_shake_context *sc, void *out, size_t len); + +#ifdef __cplusplus +} +#endif + +#endif + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/bearssl_pem.h b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/bearssl_pem.h new file mode 100644 index 000000000..13b3b4b39 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/bearssl_pem.h @@ -0,0 +1,299 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#ifndef BR_BEARSSL_PEM_H__ +#define BR_BEARSSL_PEM_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** \file bearssl_pem.h + * + * # PEM Support + * + * PEM is a traditional encoding layer use to store binary objects (in + * particular X.509 certificates, and private keys) in text files. While + * the acronym comes from an old, defunct standard ("Privacy Enhanced + * Mail"), the format has been reused, with some variations, by many + * systems, and is a _de facto_ standard, even though it is not, actually, + * specified in all clarity anywhere. + * + * ## Format Details + * + * BearSSL contains a generic, streamed PEM decoder, which handles the + * following format: + * + * - The input source (a sequence of bytes) is assumed to be the + * encoding of a text file in an ASCII-compatible charset. This + * includes ISO-8859-1, Windows-1252, and UTF-8 encodings. Each + * line ends on a newline character (U+000A LINE FEED). The + * U+000D CARRIAGE RETURN characters are ignored, so the code + * accepts both Windows-style and Unix-style line endings. + * + * - Each object begins with a banner that occurs at the start of + * a line; the first banner characters are "`-----BEGIN `" (five + * dashes, the word "BEGIN", and a space). The banner matching is + * not case-sensitive. + * + * - The _object name_ consists in the characters that follow the + * banner start sequence, up to the end of the line, but without + * trailing dashes (in "normal" PEM, there are five trailing + * dashes, but this implementation is not picky about these dashes). + * The BearSSL decoder normalises the name characters to uppercase + * (for ASCII letters only) and accepts names up to 127 characters. + * + * - The object ends with a banner that again occurs at the start of + * a line, and starts with "`-----END `" (again case-insensitive). + * + * - Between that start and end banner, only Base64 data shall occur. + * Base64 converts each sequence of three bytes into four + * characters; the four characters are ASCII letters, digits, "`+`" + * or "`-`" signs, and one or two "`=`" signs may occur in the last + * quartet. Whitespace is ignored (whitespace is any ASCII character + * of code 32 or less, so control characters are whitespace) and + * lines may have arbitrary length; the only restriction is that the + * four characters of a quartet must appear on the same line (no + * line break inside a quartet). + * + * - A single file may contain more than one PEM object. Bytes that + * occur between objects are ignored. + * + * + * ## PEM Decoder API + * + * The PEM decoder offers a state-machine API. The caller allocates a + * decoder context, then injects source bytes. Source bytes are pushed + * with `br_pem_decoder_push()`. The decoder stops accepting bytes when + * it reaches an "event", which is either the start of an object, the + * end of an object, or a decoding error within an object. + * + * The `br_pem_decoder_event()` function is used to obtain the current + * event; it also clears it, thus allowing the decoder to accept more + * bytes. When a object start event is raised, the decoder context + * offers the found object name (normalised to ASCII uppercase). + * + * When an object is reached, the caller must set an appropriate callback + * function, which will receive (by chunks) the decoded object data. + * + * Since the decoder context makes no dynamic allocation, it requires + * no explicit deallocation. + */ + +/** + * \brief PEM decoder context. + * + * Contents are opaque (they should not be accessed directly). + */ +typedef struct { +#ifndef BR_DOXYGEN_IGNORE + /* CPU for the T0 virtual machine. */ + struct { + uint32_t *dp; + uint32_t *rp; + const unsigned char *ip; + } cpu; + uint32_t dp_stack[32]; + uint32_t rp_stack[32]; + int err; + + const unsigned char *hbuf; + size_t hlen; + + void (*dest)(void *dest_ctx, const void *src, size_t len); + void *dest_ctx; + + unsigned char event; + char name[128]; + unsigned char buf[255]; + size_t ptr; +#endif +} br_pem_decoder_context; + +/** + * \brief Initialise a PEM decoder structure. + * + * \param ctx decoder context to initialise. + */ +void br_pem_decoder_init(br_pem_decoder_context *ctx); + +/** + * \brief Push some bytes into the decoder. + * + * Returned value is the number of bytes actually consumed; this may be + * less than the number of provided bytes if an event is raised. When an + * event is raised, it must be read (with `br_pem_decoder_event()`); + * until the event is read, this function will return 0. + * + * \param ctx decoder context. + * \param data new data bytes. + * \param len number of new data bytes. + * \return the number of bytes actually received (may be less than `len`). + */ +size_t br_pem_decoder_push(br_pem_decoder_context *ctx, + const void *data, size_t len); + +/** + * \brief Set the receiver for decoded data. + * + * When an object is entered, the provided function (with opaque context + * pointer) will be called repeatedly with successive chunks of decoded + * data for that object. If `dest` is set to 0, then decoded data is + * simply ignored. The receiver can be set at any time, but, in practice, + * it should be called immediately after receiving a "start of object" + * event. + * + * \param ctx decoder context. + * \param dest callback for receiving decoded data. + * \param dest_ctx opaque context pointer for the `dest` callback. + */ +static inline void +br_pem_decoder_setdest(br_pem_decoder_context *ctx, + void (*dest)(void *dest_ctx, const void *src, size_t len), + void *dest_ctx) +{ + ctx->dest = dest; + ctx->dest_ctx = dest_ctx; +} + +/** + * \brief Get the last event. + * + * If an event was raised, then this function returns the event value, and + * also clears it, thereby allowing the decoder to proceed. If no event + * was raised since the last call to `br_pem_decoder_event()`, then this + * function returns 0. + * + * \param ctx decoder context. + * \return the raised event, or 0. + */ +int br_pem_decoder_event(br_pem_decoder_context *ctx); + +/** + * \brief Event: start of object. + * + * This event is raised when the start of a new object has been detected. + * The object name (normalised to uppercase) can be accessed with + * `br_pem_decoder_name()`. + */ +#define BR_PEM_BEGIN_OBJ 1 + +/** + * \brief Event: end of object. + * + * This event is raised when the end of the current object is reached + * (normally, i.e. with no decoding error). + */ +#define BR_PEM_END_OBJ 2 + +/** + * \brief Event: decoding error. + * + * This event is raised when decoding fails within an object. + * This formally closes the current object and brings the decoder back + * to the "out of any object" state. The offending line in the source + * is consumed. + */ +#define BR_PEM_ERROR 3 + +/** + * \brief Get the name of the encountered object. + * + * The encountered object name is defined only when the "start of object" + * event is raised. That name is normalised to uppercase (for ASCII letters + * only) and does not include trailing dashes. + * + * \param ctx decoder context. + * \return the current object name. + */ +static inline const char * +br_pem_decoder_name(br_pem_decoder_context *ctx) +{ + return ctx->name; +} + +/** + * \brief Encode an object in PEM. + * + * This function encodes the provided binary object (`data`, of length `len` + * bytes) into PEM. The `banner` text will be included in the header and + * footer (e.g. use `"CERTIFICATE"` to get a `"BEGIN CERTIFICATE"` header). + * + * The length (in characters) of the PEM output is returned; that length + * does NOT include the terminating zero, that this function nevertheless + * adds. If using the returned value for allocation purposes, the allocated + * buffer size MUST be at least one byte larger than the returned size. + * + * If `dest` is `NULL`, then the encoding does not happen; however, the + * length of the encoded object is still computed and returned. + * + * The `data` pointer may be `NULL` only if `len` is zero (when encoding + * an object of length zero, which is not very useful), or when `dest` + * is `NULL` (in that case, source data bytes are ignored). + * + * Some `flags` can be specified to alter the encoding behaviour: + * + * - If `BR_PEM_LINE64` is set, then line-breaking will occur after + * every 64 characters of output, instead of the default of 76. + * + * - If `BR_PEM_CRLF` is set, then end-of-line sequence will use + * CR+LF instead of a single LF. + * + * The `data` and `dest` buffers may overlap, in which case the source + * binary data is destroyed in the process. Note that the PEM-encoded output + * is always larger than the source binary. + * + * \param dest the destination buffer (or `NULL`). + * \param data the source buffer (can be `NULL` in some cases). + * \param len the source length (in bytes). + * \param banner the PEM banner expression. + * \param flags the behavioural flags. + * \return the PEM object length (in characters), EXCLUDING the final zero. + */ +size_t br_pem_encode(void *dest, const void *data, size_t len, + const char *banner, unsigned flags); + +/** + * \brief PEM encoding flag: split lines at 64 characters. + */ +#define BR_PEM_LINE64 0x0001 + +/** + * \brief PEM encoding flag: use CR+LF line endings. + */ +#define BR_PEM_CRLF 0x0002 + +#ifdef __cplusplus +} +#endif + +#endif + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/bearssl_prf.h b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/bearssl_prf.h new file mode 100644 index 000000000..f611bf937 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/bearssl_prf.h @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#ifndef BR_BEARSSL_PRF_H__ +#define BR_BEARSSL_PRF_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** \file bearssl_prf.h + * + * # The TLS PRF + * + * The "PRF" is the pseudorandom function used internally during the + * SSL/TLS handshake, notably to expand negotiated shared secrets into + * the symmetric encryption keys that will be used to process the + * application data. + * + * TLS 1.0 and 1.1 define a PRF that is based on both MD5 and SHA-1. This + * is implemented by the `br_tls10_prf()` function. + * + * TLS 1.2 redefines the PRF, using an explicit hash function. The + * `br_tls12_sha256_prf()` and `br_tls12_sha384_prf()` functions apply that + * PRF with, respectively, SHA-256 and SHA-384. Most standard cipher suites + * rely on the SHA-256 based PRF, but some use SHA-384. + * + * The PRF always uses as input three parameters: a "secret" (some + * bytes), a "label" (ASCII string), and a "seed" (again some bytes). An + * arbitrary output length can be produced. The "seed" is provided as an + * arbitrary number of binary chunks, that gets internally concatenated. + */ + +/** + * \brief Type for a seed chunk. + * + * Each chunk may have an arbitrary length, and may be empty (no byte at + * all). If the chunk length is zero, then the pointer to the chunk data + * may be `NULL`. + */ +typedef struct { + /** + * \brief Pointer to the chunk data. + */ + const void *data; + + /** + * \brief Chunk length (in bytes). + */ + size_t len; +} br_tls_prf_seed_chunk; + +/** + * \brief PRF implementation for TLS 1.0 and 1.1. + * + * This PRF is the one specified by TLS 1.0 and 1.1. It internally uses + * MD5 and SHA-1. + * + * \param dst destination buffer. + * \param len output length (in bytes). + * \param secret secret value (key) for this computation. + * \param secret_len length of "secret" (in bytes). + * \param label PRF label (zero-terminated ASCII string). + * \param seed_num number of seed chunks. + * \param seed seed chnks for this computation (usually non-secret). + */ +void br_tls10_prf(void *dst, size_t len, + const void *secret, size_t secret_len, const char *label, + size_t seed_num, const br_tls_prf_seed_chunk *seed); + +/** + * \brief PRF implementation for TLS 1.2, with SHA-256. + * + * This PRF is the one specified by TLS 1.2, when the underlying hash + * function is SHA-256. + * + * \param dst destination buffer. + * \param len output length (in bytes). + * \param secret secret value (key) for this computation. + * \param secret_len length of "secret" (in bytes). + * \param label PRF label (zero-terminated ASCII string). + * \param seed_num number of seed chunks. + * \param seed seed chnks for this computation (usually non-secret). + */ +void br_tls12_sha256_prf(void *dst, size_t len, + const void *secret, size_t secret_len, const char *label, + size_t seed_num, const br_tls_prf_seed_chunk *seed); + +/** + * \brief PRF implementation for TLS 1.2, with SHA-384. + * + * This PRF is the one specified by TLS 1.2, when the underlying hash + * function is SHA-384. + * + * \param dst destination buffer. + * \param len output length (in bytes). + * \param secret secret value (key) for this computation. + * \param secret_len length of "secret" (in bytes). + * \param label PRF label (zero-terminated ASCII string). + * \param seed_num number of seed chunks. + * \param seed seed chnks for this computation (usually non-secret). + */ +void br_tls12_sha384_prf(void *dst, size_t len, + const void *secret, size_t secret_len, const char *label, + size_t seed_num, const br_tls_prf_seed_chunk *seed); + +/** + * brief A convenient type name for a PRF implementation. + * + * \param dst destination buffer. + * \param len output length (in bytes). + * \param secret secret value (key) for this computation. + * \param secret_len length of "secret" (in bytes). + * \param label PRF label (zero-terminated ASCII string). + * \param seed_num number of seed chunks. + * \param seed seed chnks for this computation (usually non-secret). + */ +typedef void (*br_tls_prf_impl)(void *dst, size_t len, + const void *secret, size_t secret_len, const char *label, + size_t seed_num, const br_tls_prf_seed_chunk *seed); + +#ifdef __cplusplus +} +#endif + +#endif + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/bearssl_rand.h b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/bearssl_rand.h new file mode 100644 index 000000000..82c590b51 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/bearssl_rand.h @@ -0,0 +1,402 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#ifndef BR_BEARSSL_RAND_H__ +#define BR_BEARSSL_RAND_H__ + +#include +#include + +#include "bearssl_block.h" +#include "bearssl_hash.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** \file bearssl_rand.h + * + * # Pseudo-Random Generators + * + * A PRNG is a state-based engine that outputs pseudo-random bytes on + * demand. It is initialized with an initial seed, and additional seed + * bytes can be added afterwards. Bytes produced depend on the seeds and + * also on the exact sequence of calls (including sizes requested for + * each call). + * + * + * ## Procedural and OOP API + * + * For the PRNG of name "`xxx`", two API are provided. The _procedural_ + * API defined a context structure `br_xxx_context` and three functions: + * + * - `br_xxx_init()` + * + * Initialise the context with an initial seed. + * + * - `br_xxx_generate()` + * + * Produce some pseudo-random bytes. + * + * - `br_xxx_update()` + * + * Inject some additional seed. + * + * The initialisation function sets the first context field (`vtable`) + * to a pointer to the vtable that supports the OOP API. The OOP API + * provides access to the same functions through function pointers, + * named `init()`, `generate()` and `update()`. + * + * Note that the context initialisation method may accept additional + * parameters, provided as a 'const void *' pointer at API level. These + * additional parameters depend on the implemented PRNG. + * + * + * ## HMAC_DRBG + * + * HMAC_DRBG is defined in [NIST SP 800-90A Revision + * 1](http://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-90Ar1.pdf). + * It uses HMAC repeatedly, over some configurable underlying hash + * function. In BearSSL, it is implemented under the "`hmac_drbg`" name. + * The "extra parameters" pointer for context initialisation should be + * set to a pointer to the vtable for the underlying hash function (e.g. + * pointer to `br_sha256_vtable` to use HMAC_DRBG with SHA-256). + * + * According to the NIST standard, each request shall produce up to + * 219 bits (i.e. 64 kB of data); moreover, the context shall + * be reseeded at least once every 248 requests. This + * implementation does not maintain the reseed counter (the threshold is + * too high to be reached in practice) and does not object to producing + * more than 64 kB in a single request; thus, the code cannot fail, + * which corresponds to the fact that the API has no room for error + * codes. However, this implies that requesting more than 64 kB in one + * `generate()` request, or making more than 248 requests + * without reseeding, is formally out of NIST specification. There is + * no currently known security penalty for exceeding the NIST limits, + * and, in any case, HMAC_DRBG usage in implementing SSL/TLS always + * stays much below these thresholds. + * + * + * ## AESCTR_DRBG + * + * AESCTR_DRBG is a custom PRNG based on AES-128 in CTR mode. This is + * meant to be used only in situations where you are desperate for + * speed, and have an hardware-optimized AES/CTR implementation. Whether + * this will yield perceptible improvements depends on what you use the + * pseudorandom bytes for, and how many you want; for instance, RSA key + * pair generation uses a substantial amount of randomness, and using + * AESCTR_DRBG instead of HMAC_DRBG yields a 15 to 20% increase in key + * generation speed on a recent x86 CPU (Intel Core i7-6567U at 3.30 GHz). + * + * Internally, it uses CTR mode with successive counter values, starting + * at zero (counter value expressed over 128 bits, big-endian convention). + * The counter is not allowed to reach 32768; thus, every 32768*16 bytes + * at most, the `update()` function is run (on an empty seed, if none is + * provided). The `update()` function computes the new AES-128 key by + * applying a custom hash function to the concatenation of a state-dependent + * word (encryption of an all-one block with the current key) and the new + * seed. The custom hash function uses Hirose's construction over AES-256; + * see the comments in `aesctr_drbg.c` for details. + * + * This DRBG does not follow an existing standard, and thus should be + * considered as inadequate for production use until it has been properly + * analysed. + */ + +/** + * \brief Class type for PRNG implementations. + * + * A `br_prng_class` instance references the methods implementing a PRNG. + * Constant instances of this structure are defined for each implemented + * PRNG. Such instances are also called "vtables". + */ +typedef struct br_prng_class_ br_prng_class; +struct br_prng_class_ { + /** + * \brief Size (in bytes) of the context structure appropriate for + * running this PRNG. + */ + size_t context_size; + + /** + * \brief Initialisation method. + * + * The context to initialise is provided as a pointer to its + * first field (the vtable pointer); this function sets that + * first field to a pointer to the vtable. + * + * The extra parameters depend on the implementation; each + * implementation defines what kind of extra parameters it + * expects (if any). + * + * Requirements on the initial seed depend on the implemented + * PRNG. + * + * \param ctx PRNG context to initialise. + * \param params extra parameters for the PRNG. + * \param seed initial seed. + * \param seed_len initial seed length (in bytes). + */ + void (*init)(const br_prng_class **ctx, const void *params, + const void *seed, size_t seed_len); + + /** + * \brief Random bytes generation. + * + * This method produces `len` pseudorandom bytes, in the `out` + * buffer. The context is updated accordingly. + * + * \param ctx PRNG context. + * \param out output buffer. + * \param len number of pseudorandom bytes to produce. + */ + void (*generate)(const br_prng_class **ctx, void *out, size_t len); + + /** + * \brief Inject additional seed bytes. + * + * The provided seed bytes are added into the PRNG internal + * entropy pool. + * + * \param ctx PRNG context. + * \param seed additional seed. + * \param seed_len additional seed length (in bytes). + */ + void (*update)(const br_prng_class **ctx, + const void *seed, size_t seed_len); +}; + +/** + * \brief Context for HMAC_DRBG. + * + * The context contents are opaque, except the first field, which + * supports OOP. + */ +typedef struct { + /** + * \brief Pointer to the vtable. + * + * This field is set with the initialisation method/function. + */ + const br_prng_class *vtable; +#ifndef BR_DOXYGEN_IGNORE + unsigned char K[64]; + unsigned char V[64]; + const br_hash_class *digest_class; +#endif +} br_hmac_drbg_context; + +/** + * \brief Statically allocated, constant vtable for HMAC_DRBG. + */ +extern const br_prng_class br_hmac_drbg_vtable; + +/** + * \brief HMAC_DRBG initialisation. + * + * The context to initialise is provided as a pointer to its first field + * (the vtable pointer); this function sets that first field to a + * pointer to the vtable. + * + * The `seed` value is what is called, in NIST terminology, the + * concatenation of the "seed", "nonce" and "personalization string", in + * that order. + * + * The `digest_class` parameter defines the underlying hash function. + * Formally, the NIST standard specifies that the hash function shall + * be only SHA-1 or one of the SHA-2 functions. This implementation also + * works with any other implemented hash function (such as MD5), but + * this is non-standard and therefore not recommended. + * + * \param ctx HMAC_DRBG context to initialise. + * \param digest_class vtable for the underlying hash function. + * \param seed initial seed. + * \param seed_len initial seed length (in bytes). + */ +void br_hmac_drbg_init(br_hmac_drbg_context *ctx, + const br_hash_class *digest_class, const void *seed, size_t seed_len); + +/** + * \brief Random bytes generation with HMAC_DRBG. + * + * This method produces `len` pseudorandom bytes, in the `out` + * buffer. The context is updated accordingly. Formally, requesting + * more than 65536 bytes in one request falls out of specification + * limits (but it won't fail). + * + * \param ctx HMAC_DRBG context. + * \param out output buffer. + * \param len number of pseudorandom bytes to produce. + */ +void br_hmac_drbg_generate(br_hmac_drbg_context *ctx, void *out, size_t len); + +/** + * \brief Inject additional seed bytes in HMAC_DRBG. + * + * The provided seed bytes are added into the HMAC_DRBG internal + * entropy pool. The process does not _replace_ existing entropy, + * thus pushing non-random bytes (i.e. bytes which are known to the + * attackers) does not degrade the overall quality of generated bytes. + * + * \param ctx HMAC_DRBG context. + * \param seed additional seed. + * \param seed_len additional seed length (in bytes). + */ +void br_hmac_drbg_update(br_hmac_drbg_context *ctx, + const void *seed, size_t seed_len); + +/** + * \brief Get the hash function implementation used by a given instance of + * HMAC_DRBG. + * + * This calls MUST NOT be performed on a context which was not + * previously initialised. + * + * \param ctx HMAC_DRBG context. + * \return the hash function vtable. + */ +static inline const br_hash_class * +br_hmac_drbg_get_hash(const br_hmac_drbg_context *ctx) +{ + return ctx->digest_class; +} + +/** + * \brief Type for a provider of entropy seeds. + * + * A "seeder" is a function that is able to obtain random values from + * some source and inject them as entropy seed in a PRNG. A seeder + * shall guarantee that the total entropy of the injected seed is large + * enough to seed a PRNG for purposes of cryptographic key generation + * (i.e. at least 128 bits). + * + * A seeder may report a failure to obtain adequate entropy. Seeders + * shall endeavour to fix themselves transient errors by trying again; + * thus, callers may consider reported errors as permanent. + * + * \param ctx PRNG context to seed. + * \return 1 on success, 0 on error. + */ +typedef int (*br_prng_seeder)(const br_prng_class **ctx); + +/** + * \brief Get a seeder backed by the operating system or hardware. + * + * Get a seeder that feeds on RNG facilities provided by the current + * operating system or hardware. If no such facility is known, then 0 + * is returned. + * + * If `name` is not `NULL`, then `*name` is set to a symbolic string + * that identifies the seeder implementation. If no seeder is returned + * and `name` is not `NULL`, then `*name` is set to a pointer to the + * constant string `"none"`. + * + * \param name receiver for seeder name, or `NULL`. + * \return the system seeder, if available, or 0. + */ +br_prng_seeder br_prng_seeder_system(const char **name); + +/** + * \brief Context for AESCTR_DRBG. + * + * The context contents are opaque, except the first field, which + * supports OOP. + */ +typedef struct { + /** + * \brief Pointer to the vtable. + * + * This field is set with the initialisation method/function. + */ + const br_prng_class *vtable; +#ifndef BR_DOXYGEN_IGNORE + br_aes_gen_ctr_keys sk; + uint32_t cc; +#endif +} br_aesctr_drbg_context; + +/** + * \brief Statically allocated, constant vtable for AESCTR_DRBG. + */ +extern const br_prng_class br_aesctr_drbg_vtable; + +/** + * \brief AESCTR_DRBG initialisation. + * + * The context to initialise is provided as a pointer to its first field + * (the vtable pointer); this function sets that first field to a + * pointer to the vtable. + * + * The internal AES key is first set to the all-zero key; then, the + * `br_aesctr_drbg_update()` function is called with the provided `seed`. + * The call is performed even if the seed length (`seed_len`) is zero. + * + * The `aesctr` parameter defines the underlying AES/CTR implementation. + * + * \param ctx AESCTR_DRBG context to initialise. + * \param aesctr vtable for the AES/CTR implementation. + * \param seed initial seed (can be `NULL` if `seed_len` is zero). + * \param seed_len initial seed length (in bytes). + */ +void br_aesctr_drbg_init(br_aesctr_drbg_context *ctx, + const br_block_ctr_class *aesctr, const void *seed, size_t seed_len); + +/** + * \brief Random bytes generation with AESCTR_DRBG. + * + * This method produces `len` pseudorandom bytes, in the `out` + * buffer. The context is updated accordingly. + * + * \param ctx AESCTR_DRBG context. + * \param out output buffer. + * \param len number of pseudorandom bytes to produce. + */ +void br_aesctr_drbg_generate(br_aesctr_drbg_context *ctx, + void *out, size_t len); + +/** + * \brief Inject additional seed bytes in AESCTR_DRBG. + * + * The provided seed bytes are added into the AESCTR_DRBG internal + * entropy pool. The process does not _replace_ existing entropy, + * thus pushing non-random bytes (i.e. bytes which are known to the + * attackers) does not degrade the overall quality of generated bytes. + * + * \param ctx AESCTR_DRBG context. + * \param seed additional seed. + * \param seed_len additional seed length (in bytes). + */ +void br_aesctr_drbg_update(br_aesctr_drbg_context *ctx, + const void *seed, size_t seed_len); + +#ifdef __cplusplus +} +#endif + +#endif + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/bearssl_rsa.h b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/bearssl_rsa.h new file mode 100644 index 000000000..18e953bb1 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/bearssl_rsa.h @@ -0,0 +1,1660 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#ifndef BR_BEARSSL_RSA_H__ +#define BR_BEARSSL_RSA_H__ + +#include +#include + +#include "bearssl_hash.h" +#include "bearssl_rand.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** \file bearssl_rsa.h + * + * # RSA + * + * This file documents the RSA implementations provided with BearSSL. + * Note that the SSL engine accesses these implementations through a + * configurable API, so it is possible to, for instance, run a SSL + * server which uses a RSA engine which is not based on this code. + * + * ## Key Elements + * + * RSA public and private keys consist in lists of big integers. All + * such integers are represented with big-endian unsigned notation: + * first byte is the most significant, and the value is positive (so + * there is no dedicated "sign bit"). Public and private key structures + * thus contain, for each such integer, a pointer to the first value byte + * (`unsigned char *`), and a length (`size_t`) which is the number of + * relevant bytes. As a general rule, minimal-length encoding is not + * enforced: values may have extra leading bytes of value 0. + * + * RSA public keys consist in two integers: + * + * - the modulus (`n`); + * - the public exponent (`e`). + * + * RSA private keys, as defined in + * [PKCS#1](https://tools.ietf.org/html/rfc3447), contain eight integers: + * + * - the modulus (`n`); + * - the public exponent (`e`); + * - the private exponent (`d`); + * - the first prime factor (`p`); + * - the second prime factor (`q`); + * - the first reduced exponent (`dp`, which is `d` modulo `p-1`); + * - the second reduced exponent (`dq`, which is `d` modulo `q-1`); + * - the CRT coefficient (`iq`, the inverse of `q` modulo `p`). + * + * However, the implementations defined in BearSSL use only five of + * these integers: `p`, `q`, `dp`, `dq` and `iq`. + * + * ## Security Features and Limitations + * + * The implementations contained in BearSSL have the following limitations + * and features: + * + * - They are constant-time. This means that the execution time and + * memory access pattern may depend on the _lengths_ of the private + * key components, but not on their value, nor on the value of + * the operand. Note that this property is not achieved through + * random masking, but "true" constant-time code. + * + * - They support only private keys with two prime factors. RSA private + * keys with three or more prime factors are nominally supported, but + * rarely used; they may offer faster operations, at the expense of + * more code and potentially a reduction in security if there are + * "too many" prime factors. + * + * - The public exponent may have arbitrary length. Of course, it is + * a good idea to keep public exponents small, so that public key + * operations are fast; but, contrary to some widely deployed + * implementations, BearSSL has no problem with public exponents + * longer than 32 bits. + * + * - The two prime factors of the modulus need not have the same length + * (but severely imbalanced factor lengths might reduce security). + * Similarly, there is no requirement that the first factor (`p`) + * be greater than the second factor (`q`). + * + * - Prime factors and modulus must be smaller than a compile-time limit. + * This is made necessary by the use of fixed-size stack buffers, and + * the limit has been adjusted to keep stack usage under 2 kB for the + * RSA operations. Currently, the maximum modulus size is 4096 bits, + * and the maximum prime factor size is 2080 bits. + * + * - The RSA functions themselves do not enforce lower size limits, + * except that which is absolutely necessary for the operation to + * mathematically make sense (e.g. a PKCS#1 v1.5 signature with + * SHA-1 requires a modulus of at least 361 bits). It is up to users + * of this code to enforce size limitations when appropriate (e.g. + * the X.509 validation engine, by default, rejects RSA keys of + * less than 1017 bits). + * + * - Within the size constraints expressed above, arbitrary bit lengths + * are supported. There is no requirement that prime factors or + * modulus have a size multiple of 8 or 16. + * + * - When verifying PKCS#1 v1.5 signatures, both variants of the hash + * function identifying header (with and without the ASN.1 NULL) are + * supported. When producing such signatures, the variant with the + * ASN.1 NULL is used. + * + * ## Implementations + * + * Three RSA implementations are included: + * + * - The **i32** implementation internally represents big integers + * as arrays of 32-bit integers. It is perfunctory and portable, + * but not very efficient. + * + * - The **i31** implementation uses 32-bit integers, each containing + * 31 bits worth of integer data. The i31 implementation is somewhat + * faster than the i32 implementation (the reduced integer size makes + * carry propagation easier) for a similar code footprint, but uses + * very slightly larger stack buffers (about 4% bigger). + * + * - The **i62** implementation is similar to the i31 implementation, + * except that it internally leverages the 64x64->128 multiplication + * opcode. This implementation is available only on architectures + * where such an opcode exists. It is much faster than i31. + * + * - The **i15** implementation uses 16-bit integers, each containing + * 15 bits worth of integer data. Multiplication results fit on + * 32 bits, so this won't use the "widening" multiplication routine + * on ARM Cortex M0/M0+, for much better performance and constant-time + * execution. + */ + +/** + * \brief RSA public key. + * + * The structure references the modulus and the public exponent. Both + * integers use unsigned big-endian representation; extra leading bytes + * of value 0 are allowed. + */ +typedef struct { + /** \brief Modulus. */ + unsigned char *n; + /** \brief Modulus length (in bytes). */ + size_t nlen; + /** \brief Public exponent. */ + unsigned char *e; + /** \brief Public exponent length (in bytes). */ + size_t elen; +} br_rsa_public_key; + +/** + * \brief RSA private key. + * + * The structure references the private factors, reduced private + * exponents, and CRT coefficient. It also contains the bit length of + * the modulus. The big integers use unsigned big-endian representation; + * extra leading bytes of value 0 are allowed. However, the modulus bit + * length (`n_bitlen`) MUST be exact. + */ +typedef struct { + /** \brief Modulus bit length (in bits, exact value). */ + uint32_t n_bitlen; + /** \brief First prime factor. */ + unsigned char *p; + /** \brief First prime factor length (in bytes). */ + size_t plen; + /** \brief Second prime factor. */ + unsigned char *q; + /** \brief Second prime factor length (in bytes). */ + size_t qlen; + /** \brief First reduced private exponent. */ + unsigned char *dp; + /** \brief First reduced private exponent length (in bytes). */ + size_t dplen; + /** \brief Second reduced private exponent. */ + unsigned char *dq; + /** \brief Second reduced private exponent length (in bytes). */ + size_t dqlen; + /** \brief CRT coefficient. */ + unsigned char *iq; + /** \brief CRT coefficient length (in bytes). */ + size_t iqlen; +} br_rsa_private_key; + +/** + * \brief Type for a RSA public key engine. + * + * The public key engine performs the modular exponentiation of the + * provided value with the public exponent. The value is modified in + * place. + * + * The value length (`xlen`) is verified to have _exactly_ the same + * length as the modulus (actual modulus length, without extra leading + * zeros in the modulus representation in memory). If the length does + * not match, then this function returns 0 and `x[]` is unmodified. + * + * It `xlen` is correct, then `x[]` is modified. Returned value is 1 + * on success, 0 on error. Error conditions include an oversized `x[]` + * (the array has the same length as the modulus, but the numerical value + * is not lower than the modulus) and an invalid modulus (e.g. an even + * integer). If an error is reported, then the new contents of `x[]` are + * unspecified. + * + * \param x operand to exponentiate. + * \param xlen length of the operand (in bytes). + * \param pk RSA public key. + * \return 1 on success, 0 on error. + */ +typedef uint32_t (*br_rsa_public)(unsigned char *x, size_t xlen, + const br_rsa_public_key *pk); + +/** + * \brief Type for a RSA signature verification engine (PKCS#1 v1.5). + * + * Parameters are: + * + * - The signature itself. The provided array is NOT modified. + * + * - The encoded OID for the hash function. The provided array must begin + * with a single byte that contains the length of the OID value (in + * bytes), followed by exactly that many bytes. This parameter may + * also be `NULL`, in which case the raw hash value should be used + * with the PKCS#1 v1.5 "type 1" padding (as used in SSL/TLS up + * to TLS-1.1, with a 36-byte hash value). + * + * - The hash output length, in bytes. + * + * - The public key. + * + * - An output buffer for the hash value. The caller must still compare + * it with the hash of the data over which the signature is computed. + * + * **Constraints:** + * + * - Hash length MUST be no more than 64 bytes. + * + * - OID value length MUST be no more than 32 bytes (i.e. `hash_oid[0]` + * must have a value in the 0..32 range, inclusive). + * + * This function verifies that the signature length (`xlen`) matches the + * modulus length (this function returns 0 on mismatch). If the modulus + * size exceeds the maximum supported RSA size, then the function also + * returns 0. + * + * Returned value is 1 on success, 0 on error. + * + * Implementations of this type need not be constant-time. + * + * \param x signature buffer. + * \param xlen signature length (in bytes). + * \param hash_oid encoded hash algorithm OID (or `NULL`). + * \param hash_len expected hash value length (in bytes). + * \param pk RSA public key. + * \param hash_out output buffer for the hash value. + * \return 1 on success, 0 on error. + */ +typedef uint32_t (*br_rsa_pkcs1_vrfy)(const unsigned char *x, size_t xlen, + const unsigned char *hash_oid, size_t hash_len, + const br_rsa_public_key *pk, unsigned char *hash_out); + +/** + * \brief Type for a RSA signature verification engine (PSS). + * + * Parameters are: + * + * - The signature itself. The provided array is NOT modified. + * + * - The hash function which was used to hash the message. + * + * - The hash function to use with MGF1 within the PSS padding. This + * is not necessarily the same hash function as the one which was + * used to hash the signed message. + * + * - The hashed message (as an array of bytes). + * + * - The PSS salt length (in bytes). + * + * - The public key. + * + * **Constraints:** + * + * - Hash message length MUST be no more than 64 bytes. + * + * Note that, contrary to PKCS#1 v1.5 signature, the hash value of the + * signed data cannot be extracted from the signature; it must be + * provided to the verification function. + * + * This function verifies that the signature length (`xlen`) matches the + * modulus length (this function returns 0 on mismatch). If the modulus + * size exceeds the maximum supported RSA size, then the function also + * returns 0. + * + * Returned value is 1 on success, 0 on error. + * + * Implementations of this type need not be constant-time. + * + * \param x signature buffer. + * \param xlen signature length (in bytes). + * \param hf_data hash function applied on the message. + * \param hf_mgf1 hash function to use with MGF1. + * \param hash hash value of the signed message. + * \param salt_len PSS salt length (in bytes). + * \param pk RSA public key. + * \return 1 on success, 0 on error. + */ +typedef uint32_t (*br_rsa_pss_vrfy)(const unsigned char *x, size_t xlen, + const br_hash_class *hf_data, const br_hash_class *hf_mgf1, + const void *hash, size_t salt_len, const br_rsa_public_key *pk); + +/** + * \brief Type for a RSA encryption engine (OAEP). + * + * Parameters are: + * + * - A source of random bytes. The source must be already initialized. + * + * - A hash function, used internally with the mask generation function + * (MGF1). + * + * - A label. The `label` pointer may be `NULL` if `label_len` is zero + * (an empty label, which is the default in PKCS#1 v2.2). + * + * - The public key. + * + * - The destination buffer. Its maximum length (in bytes) is provided; + * if that length is lower than the public key length, then an error + * is reported. + * + * - The source message. + * + * The encrypted message output has exactly the same length as the modulus + * (mathematical length, in bytes, not counting extra leading zeros in the + * modulus representation in the public key). + * + * The source message (`src`, length `src_len`) may overlap with the + * destination buffer (`dst`, length `dst_max_len`). + * + * This function returns the actual encrypted message length, in bytes; + * on error, zero is returned. An error is reported if the output buffer + * is not large enough, or the public is invalid, or the public key + * modulus exceeds the maximum supported RSA size. + * + * \param rnd source of random bytes. + * \param dig hash function to use with MGF1. + * \param label label value (may be `NULL` if `label_len` is zero). + * \param label_len label length, in bytes. + * \param pk RSA public key. + * \param dst destination buffer. + * \param dst_max_len destination buffer length (maximum encrypted data size). + * \param src message to encrypt. + * \param src_len source message length (in bytes). + * \return encrypted message length (in bytes), or 0 on error. + */ +typedef size_t (*br_rsa_oaep_encrypt)( + const br_prng_class **rnd, const br_hash_class *dig, + const void *label, size_t label_len, + const br_rsa_public_key *pk, + void *dst, size_t dst_max_len, + const void *src, size_t src_len); + +/** + * \brief Type for a RSA private key engine. + * + * The `x[]` buffer is modified in place, and its length is inferred from + * the modulus length (`x[]` is assumed to have a length of + * `(sk->n_bitlen+7)/8` bytes). + * + * Returned value is 1 on success, 0 on error. + * + * \param x operand to exponentiate. + * \param sk RSA private key. + * \return 1 on success, 0 on error. + */ +typedef uint32_t (*br_rsa_private)(unsigned char *x, + const br_rsa_private_key *sk); + +/** + * \brief Type for a RSA signature generation engine (PKCS#1 v1.5). + * + * Parameters are: + * + * - The encoded OID for the hash function. The provided array must begin + * with a single byte that contains the length of the OID value (in + * bytes), followed by exactly that many bytes. This parameter may + * also be `NULL`, in which case the raw hash value should be used + * with the PKCS#1 v1.5 "type 1" padding (as used in SSL/TLS up + * to TLS-1.1, with a 36-byte hash value). + * + * - The hash value computes over the data to sign (its length is + * expressed in bytes). + * + * - The RSA private key. + * + * - The output buffer, that receives the signature. + * + * Returned value is 1 on success, 0 on error. Error conditions include + * a too small modulus for the provided hash OID and value, or some + * invalid key parameters. The signature length is exactly + * `(sk->n_bitlen+7)/8` bytes. + * + * This function is expected to be constant-time with regards to the + * private key bytes (lengths of the modulus and the individual factors + * may leak, though) and to the hashed data. + * + * \param hash_oid encoded hash algorithm OID (or `NULL`). + * \param hash hash value. + * \param hash_len hash value length (in bytes). + * \param sk RSA private key. + * \param x output buffer for the signature value. + * \return 1 on success, 0 on error. + */ +typedef uint32_t (*br_rsa_pkcs1_sign)(const unsigned char *hash_oid, + const unsigned char *hash, size_t hash_len, + const br_rsa_private_key *sk, unsigned char *x); + +/** + * \brief Type for a RSA signature generation engine (PSS). + * + * Parameters are: + * + * - An initialized PRNG for salt generation. If the salt length is + * zero (`salt_len` parameter), then the PRNG is optional (this is + * not the typical case, as the security proof of RSA/PSS is + * tighter when a non-empty salt is used). + * + * - The hash function which was used to hash the message. + * + * - The hash function to use with MGF1 within the PSS padding. This + * is not necessarily the same function as the one used to hash the + * message. + * + * - The hashed message. + * + * - The salt length, in bytes. + * + * - The RSA private key. + * + * - The output buffer, that receives the signature. + * + * Returned value is 1 on success, 0 on error. Error conditions include + * a too small modulus for the provided hash and salt lengths, or some + * invalid key parameters. The signature length is exactly + * `(sk->n_bitlen+7)/8` bytes. + * + * This function is expected to be constant-time with regards to the + * private key bytes (lengths of the modulus and the individual factors + * may leak, though) and to the hashed data. + * + * \param rng PRNG for salt generation (`NULL` if `salt_len` is zero). + * \param hf_data hash function used to hash the signed data. + * \param hf_mgf1 hash function to use with MGF1. + * \param hash hashed message. + * \param salt_len salt length (in bytes). + * \param sk RSA private key. + * \param x output buffer for the signature value. + * \return 1 on success, 0 on error. + */ +typedef uint32_t (*br_rsa_pss_sign)(const br_prng_class **rng, + const br_hash_class *hf_data, const br_hash_class *hf_mgf1, + const unsigned char *hash_value, size_t salt_len, + const br_rsa_private_key *sk, unsigned char *x); + +/** + * \brief Encoded OID for SHA-1 (in RSA PKCS#1 signatures). + */ +#define BR_HASH_OID_SHA1 \ + ((const unsigned char *)"\x05\x2B\x0E\x03\x02\x1A") + +/** + * \brief Encoded OID for SHA-224 (in RSA PKCS#1 signatures). + */ +#define BR_HASH_OID_SHA224 \ + ((const unsigned char *)"\x09\x60\x86\x48\x01\x65\x03\x04\x02\x04") + +/** + * \brief Encoded OID for SHA-256 (in RSA PKCS#1 signatures). + */ +#define BR_HASH_OID_SHA256 \ + ((const unsigned char *)"\x09\x60\x86\x48\x01\x65\x03\x04\x02\x01") + +/** + * \brief Encoded OID for SHA-384 (in RSA PKCS#1 signatures). + */ +#define BR_HASH_OID_SHA384 \ + ((const unsigned char *)"\x09\x60\x86\x48\x01\x65\x03\x04\x02\x02") + +/** + * \brief Encoded OID for SHA-512 (in RSA PKCS#1 signatures). + */ +#define BR_HASH_OID_SHA512 \ + ((const unsigned char *)"\x09\x60\x86\x48\x01\x65\x03\x04\x02\x03") + +/** + * \brief Type for a RSA decryption engine (OAEP). + * + * Parameters are: + * + * - A hash function, used internally with the mask generation function + * (MGF1). + * + * - A label. The `label` pointer may be `NULL` if `label_len` is zero + * (an empty label, which is the default in PKCS#1 v2.2). + * + * - The private key. + * + * - The source and destination buffer. The buffer initially contains + * the encrypted message; the buffer contents are altered, and the + * decrypted message is written at the start of that buffer + * (decrypted message is always shorter than the encrypted message). + * + * If decryption fails in any way, then `*len` is unmodified, and the + * function returns 0. Otherwise, `*len` is set to the decrypted message + * length, and 1 is returned. The implementation is responsible for + * checking that the input message length matches the key modulus length, + * and that the padding is correct. + * + * Implementations MUST use constant-time check of the validity of the + * OAEP padding, at least until the leading byte and hash value have + * been checked. Whether overall decryption worked, and the length of + * the decrypted message, may leak. + * + * \param dig hash function to use with MGF1. + * \param label label value (may be `NULL` if `label_len` is zero). + * \param label_len label length, in bytes. + * \param sk RSA private key. + * \param data input/output buffer. + * \param len encrypted/decrypted message length. + * \return 1 on success, 0 on error. + */ +typedef uint32_t (*br_rsa_oaep_decrypt)( + const br_hash_class *dig, const void *label, size_t label_len, + const br_rsa_private_key *sk, void *data, size_t *len); + +/* + * RSA "i32" engine. Integers are internally represented as arrays of + * 32-bit integers, and the core multiplication primitive is the + * 32x32->64 multiplication. + */ + +/** + * \brief RSA public key engine "i32". + * + * \see br_rsa_public + * + * \param x operand to exponentiate. + * \param xlen length of the operand (in bytes). + * \param pk RSA public key. + * \return 1 on success, 0 on error. + */ +uint32_t br_rsa_i32_public(unsigned char *x, size_t xlen, + const br_rsa_public_key *pk); + +/** + * \brief RSA signature verification engine "i32" (PKCS#1 v1.5 signatures). + * + * \see br_rsa_pkcs1_vrfy + * + * \param x signature buffer. + * \param xlen signature length (in bytes). + * \param hash_oid encoded hash algorithm OID (or `NULL`). + * \param hash_len expected hash value length (in bytes). + * \param pk RSA public key. + * \param hash_out output buffer for the hash value. + * \return 1 on success, 0 on error. + */ +uint32_t br_rsa_i32_pkcs1_vrfy(const unsigned char *x, size_t xlen, + const unsigned char *hash_oid, size_t hash_len, + const br_rsa_public_key *pk, unsigned char *hash_out); + +/** + * \brief RSA signature verification engine "i32" (PSS signatures). + * + * \see br_rsa_pss_vrfy + * + * \param x signature buffer. + * \param xlen signature length (in bytes). + * \param hf_data hash function applied on the message. + * \param hf_mgf1 hash function to use with MGF1. + * \param hash hash value of the signed message. + * \param salt_len PSS salt length (in bytes). + * \param pk RSA public key. + * \return 1 on success, 0 on error. + */ +uint32_t br_rsa_i32_pss_vrfy(const unsigned char *x, size_t xlen, + const br_hash_class *hf_data, const br_hash_class *hf_mgf1, + const void *hash, size_t salt_len, const br_rsa_public_key *pk); + +/** + * \brief RSA private key engine "i32". + * + * \see br_rsa_private + * + * \param x operand to exponentiate. + * \param sk RSA private key. + * \return 1 on success, 0 on error. + */ +uint32_t br_rsa_i32_private(unsigned char *x, + const br_rsa_private_key *sk); + +/** + * \brief RSA signature generation engine "i32" (PKCS#1 v1.5 signatures). + * + * \see br_rsa_pkcs1_sign + * + * \param hash_oid encoded hash algorithm OID (or `NULL`). + * \param hash hash value. + * \param hash_len hash value length (in bytes). + * \param sk RSA private key. + * \param x output buffer for the hash value. + * \return 1 on success, 0 on error. + */ +uint32_t br_rsa_i32_pkcs1_sign(const unsigned char *hash_oid, + const unsigned char *hash, size_t hash_len, + const br_rsa_private_key *sk, unsigned char *x); + +/** + * \brief RSA signature generation engine "i32" (PSS signatures). + * + * \see br_rsa_pss_sign + * + * \param rng PRNG for salt generation (`NULL` if `salt_len` is zero). + * \param hf_data hash function used to hash the signed data. + * \param hf_mgf1 hash function to use with MGF1. + * \param hash hashed message. + * \param salt_len salt length (in bytes). + * \param sk RSA private key. + * \param x output buffer for the signature value. + * \return 1 on success, 0 on error. + */ +uint32_t br_rsa_i32_pss_sign(const br_prng_class **rng, + const br_hash_class *hf_data, const br_hash_class *hf_mgf1, + const unsigned char *hash_value, size_t salt_len, + const br_rsa_private_key *sk, unsigned char *x); + +/* + * RSA "i31" engine. Similar to i32, but only 31 bits are used per 32-bit + * word. This uses slightly more stack space (about 4% more) and code + * space, but it quite faster. + */ + +/** + * \brief RSA public key engine "i31". + * + * \see br_rsa_public + * + * \param x operand to exponentiate. + * \param xlen length of the operand (in bytes). + * \param pk RSA public key. + * \return 1 on success, 0 on error. + */ +uint32_t br_rsa_i31_public(unsigned char *x, size_t xlen, + const br_rsa_public_key *pk); + +/** + * \brief RSA signature verification engine "i31" (PKCS#1 v1.5 signatures). + * + * \see br_rsa_pkcs1_vrfy + * + * \param x signature buffer. + * \param xlen signature length (in bytes). + * \param hash_oid encoded hash algorithm OID (or `NULL`). + * \param hash_len expected hash value length (in bytes). + * \param pk RSA public key. + * \param hash_out output buffer for the hash value. + * \return 1 on success, 0 on error. + */ +uint32_t br_rsa_i31_pkcs1_vrfy(const unsigned char *x, size_t xlen, + const unsigned char *hash_oid, size_t hash_len, + const br_rsa_public_key *pk, unsigned char *hash_out); + +/** + * \brief RSA signature verification engine "i31" (PSS signatures). + * + * \see br_rsa_pss_vrfy + * + * \param x signature buffer. + * \param xlen signature length (in bytes). + * \param hf_data hash function applied on the message. + * \param hf_mgf1 hash function to use with MGF1. + * \param hash hash value of the signed message. + * \param salt_len PSS salt length (in bytes). + * \param pk RSA public key. + * \return 1 on success, 0 on error. + */ +uint32_t br_rsa_i31_pss_vrfy(const unsigned char *x, size_t xlen, + const br_hash_class *hf_data, const br_hash_class *hf_mgf1, + const void *hash, size_t salt_len, const br_rsa_public_key *pk); + +/** + * \brief RSA private key engine "i31". + * + * \see br_rsa_private + * + * \param x operand to exponentiate. + * \param sk RSA private key. + * \return 1 on success, 0 on error. + */ +uint32_t br_rsa_i31_private(unsigned char *x, + const br_rsa_private_key *sk); + +/** + * \brief RSA signature generation engine "i31" (PKCS#1 v1.5 signatures). + * + * \see br_rsa_pkcs1_sign + * + * \param hash_oid encoded hash algorithm OID (or `NULL`). + * \param hash hash value. + * \param hash_len hash value length (in bytes). + * \param sk RSA private key. + * \param x output buffer for the hash value. + * \return 1 on success, 0 on error. + */ +uint32_t br_rsa_i31_pkcs1_sign(const unsigned char *hash_oid, + const unsigned char *hash, size_t hash_len, + const br_rsa_private_key *sk, unsigned char *x); + +/** + * \brief RSA signature generation engine "i31" (PSS signatures). + * + * \see br_rsa_pss_sign + * + * \param rng PRNG for salt generation (`NULL` if `salt_len` is zero). + * \param hf_data hash function used to hash the signed data. + * \param hf_mgf1 hash function to use with MGF1. + * \param hash hashed message. + * \param salt_len salt length (in bytes). + * \param sk RSA private key. + * \param x output buffer for the signature value. + * \return 1 on success, 0 on error. + */ +uint32_t br_rsa_i31_pss_sign(const br_prng_class **rng, + const br_hash_class *hf_data, const br_hash_class *hf_mgf1, + const unsigned char *hash_value, size_t salt_len, + const br_rsa_private_key *sk, unsigned char *x); + +/* + * RSA "i62" engine. Similar to i31, but internal multiplication use + * 64x64->128 multiplications. This is available only on architecture + * that offer such an opcode. + */ + +/** + * \brief RSA public key engine "i62". + * + * This function is defined only on architecture that offer a 64x64->128 + * opcode. Use `br_rsa_i62_public_get()` to dynamically obtain a pointer + * to that function. + * + * \see br_rsa_public + * + * \param x operand to exponentiate. + * \param xlen length of the operand (in bytes). + * \param pk RSA public key. + * \return 1 on success, 0 on error. + */ +uint32_t br_rsa_i62_public(unsigned char *x, size_t xlen, + const br_rsa_public_key *pk); + +/** + * \brief RSA signature verification engine "i62" (PKCS#1 v1.5 signatures). + * + * This function is defined only on architecture that offer a 64x64->128 + * opcode. Use `br_rsa_i62_pkcs1_vrfy_get()` to dynamically obtain a pointer + * to that function. + * + * \see br_rsa_pkcs1_vrfy + * + * \param x signature buffer. + * \param xlen signature length (in bytes). + * \param hash_oid encoded hash algorithm OID (or `NULL`). + * \param hash_len expected hash value length (in bytes). + * \param pk RSA public key. + * \param hash_out output buffer for the hash value. + * \return 1 on success, 0 on error. + */ +uint32_t br_rsa_i62_pkcs1_vrfy(const unsigned char *x, size_t xlen, + const unsigned char *hash_oid, size_t hash_len, + const br_rsa_public_key *pk, unsigned char *hash_out); + +/** + * \brief RSA signature verification engine "i62" (PSS signatures). + * + * This function is defined only on architecture that offer a 64x64->128 + * opcode. Use `br_rsa_i62_pss_vrfy_get()` to dynamically obtain a pointer + * to that function. + * + * \see br_rsa_pss_vrfy + * + * \param x signature buffer. + * \param xlen signature length (in bytes). + * \param hf_data hash function applied on the message. + * \param hf_mgf1 hash function to use with MGF1. + * \param hash hash value of the signed message. + * \param salt_len PSS salt length (in bytes). + * \param pk RSA public key. + * \return 1 on success, 0 on error. + */ +uint32_t br_rsa_i62_pss_vrfy(const unsigned char *x, size_t xlen, + const br_hash_class *hf_data, const br_hash_class *hf_mgf1, + const void *hash, size_t salt_len, const br_rsa_public_key *pk); + +/** + * \brief RSA private key engine "i62". + * + * This function is defined only on architecture that offer a 64x64->128 + * opcode. Use `br_rsa_i62_private_get()` to dynamically obtain a pointer + * to that function. + * + * \see br_rsa_private + * + * \param x operand to exponentiate. + * \param sk RSA private key. + * \return 1 on success, 0 on error. + */ +uint32_t br_rsa_i62_private(unsigned char *x, + const br_rsa_private_key *sk); + +/** + * \brief RSA signature generation engine "i62" (PKCS#1 v1.5 signatures). + * + * This function is defined only on architecture that offer a 64x64->128 + * opcode. Use `br_rsa_i62_pkcs1_sign_get()` to dynamically obtain a pointer + * to that function. + * + * \see br_rsa_pkcs1_sign + * + * \param hash_oid encoded hash algorithm OID (or `NULL`). + * \param hash hash value. + * \param hash_len hash value length (in bytes). + * \param sk RSA private key. + * \param x output buffer for the hash value. + * \return 1 on success, 0 on error. + */ +uint32_t br_rsa_i62_pkcs1_sign(const unsigned char *hash_oid, + const unsigned char *hash, size_t hash_len, + const br_rsa_private_key *sk, unsigned char *x); + +/** + * \brief RSA signature generation engine "i62" (PSS signatures). + * + * This function is defined only on architecture that offer a 64x64->128 + * opcode. Use `br_rsa_i62_pss_sign_get()` to dynamically obtain a pointer + * to that function. + * + * \see br_rsa_pss_sign + * + * \param rng PRNG for salt generation (`NULL` if `salt_len` is zero). + * \param hf_data hash function used to hash the signed data. + * \param hf_mgf1 hash function to use with MGF1. + * \param hash hashed message. + * \param salt_len salt length (in bytes). + * \param sk RSA private key. + * \param x output buffer for the signature value. + * \return 1 on success, 0 on error. + */ +uint32_t br_rsa_i62_pss_sign(const br_prng_class **rng, + const br_hash_class *hf_data, const br_hash_class *hf_mgf1, + const unsigned char *hash_value, size_t salt_len, + const br_rsa_private_key *sk, unsigned char *x); + +/** + * \brief Get the RSA "i62" implementation (public key operations), + * if available. + * + * \return the implementation, or 0. + */ +br_rsa_public br_rsa_i62_public_get(void); + +/** + * \brief Get the RSA "i62" implementation (PKCS#1 v1.5 signature verification), + * if available. + * + * \return the implementation, or 0. + */ +br_rsa_pkcs1_vrfy br_rsa_i62_pkcs1_vrfy_get(void); + +/** + * \brief Get the RSA "i62" implementation (PSS signature verification), + * if available. + * + * \return the implementation, or 0. + */ +br_rsa_pss_vrfy br_rsa_i62_pss_vrfy_get(void); + +/** + * \brief Get the RSA "i62" implementation (private key operations), + * if available. + * + * \return the implementation, or 0. + */ +br_rsa_private br_rsa_i62_private_get(void); + +/** + * \brief Get the RSA "i62" implementation (PKCS#1 v1.5 signature generation), + * if available. + * + * \return the implementation, or 0. + */ +br_rsa_pkcs1_sign br_rsa_i62_pkcs1_sign_get(void); + +/** + * \brief Get the RSA "i62" implementation (PSS signature generation), + * if available. + * + * \return the implementation, or 0. + */ +br_rsa_pss_sign br_rsa_i62_pss_sign_get(void); + +/** + * \brief Get the RSA "i62" implementation (OAEP encryption), + * if available. + * + * \return the implementation, or 0. + */ +br_rsa_oaep_encrypt br_rsa_i62_oaep_encrypt_get(void); + +/** + * \brief Get the RSA "i62" implementation (OAEP decryption), + * if available. + * + * \return the implementation, or 0. + */ +br_rsa_oaep_decrypt br_rsa_i62_oaep_decrypt_get(void); + +/* + * RSA "i15" engine. Integers are represented as 15-bit integers, so + * the code uses only 32-bit multiplication (no 64-bit result), which + * is vastly faster (and constant-time) on the ARM Cortex M0/M0+. + */ + +/** + * \brief RSA public key engine "i15". + * + * \see br_rsa_public + * + * \param x operand to exponentiate. + * \param xlen length of the operand (in bytes). + * \param pk RSA public key. + * \return 1 on success, 0 on error. + */ +uint32_t br_rsa_i15_public(unsigned char *x, size_t xlen, + const br_rsa_public_key *pk); + +/** + * \brief RSA signature verification engine "i15" (PKCS#1 v1.5 signatures). + * + * \see br_rsa_pkcs1_vrfy + * + * \param x signature buffer. + * \param xlen signature length (in bytes). + * \param hash_oid encoded hash algorithm OID (or `NULL`). + * \param hash_len expected hash value length (in bytes). + * \param pk RSA public key. + * \param hash_out output buffer for the hash value. + * \return 1 on success, 0 on error. + */ +uint32_t br_rsa_i15_pkcs1_vrfy(const unsigned char *x, size_t xlen, + const unsigned char *hash_oid, size_t hash_len, + const br_rsa_public_key *pk, unsigned char *hash_out); + +/** + * \brief RSA signature verification engine "i15" (PSS signatures). + * + * \see br_rsa_pss_vrfy + * + * \param x signature buffer. + * \param xlen signature length (in bytes). + * \param hf_data hash function applied on the message. + * \param hf_mgf1 hash function to use with MGF1. + * \param hash hash value of the signed message. + * \param salt_len PSS salt length (in bytes). + * \param pk RSA public key. + * \return 1 on success, 0 on error. + */ +uint32_t br_rsa_i15_pss_vrfy(const unsigned char *x, size_t xlen, + const br_hash_class *hf_data, const br_hash_class *hf_mgf1, + const void *hash, size_t salt_len, const br_rsa_public_key *pk); + +/** + * \brief RSA private key engine "i15". + * + * \see br_rsa_private + * + * \param x operand to exponentiate. + * \param sk RSA private key. + * \return 1 on success, 0 on error. + */ +uint32_t br_rsa_i15_private(unsigned char *x, + const br_rsa_private_key *sk); + +/** + * \brief RSA signature generation engine "i15" (PKCS#1 v1.5 signatures). + * + * \see br_rsa_pkcs1_sign + * + * \param hash_oid encoded hash algorithm OID (or `NULL`). + * \param hash hash value. + * \param hash_len hash value length (in bytes). + * \param sk RSA private key. + * \param x output buffer for the hash value. + * \return 1 on success, 0 on error. + */ +uint32_t br_rsa_i15_pkcs1_sign(const unsigned char *hash_oid, + const unsigned char *hash, size_t hash_len, + const br_rsa_private_key *sk, unsigned char *x); + +/** + * \brief RSA signature generation engine "i15" (PSS signatures). + * + * \see br_rsa_pss_sign + * + * \param rng PRNG for salt generation (`NULL` if `salt_len` is zero). + * \param hf_data hash function used to hash the signed data. + * \param hf_mgf1 hash function to use with MGF1. + * \param hash hashed message. + * \param salt_len salt length (in bytes). + * \param sk RSA private key. + * \param x output buffer for the signature value. + * \return 1 on success, 0 on error. + */ +uint32_t br_rsa_i15_pss_sign(const br_prng_class **rng, + const br_hash_class *hf_data, const br_hash_class *hf_mgf1, + const unsigned char *hash_value, size_t salt_len, + const br_rsa_private_key *sk, unsigned char *x); + +/** + * \brief Get "default" RSA implementation (public-key operations). + * + * This returns the preferred implementation of RSA (public-key operations) + * on the current system. + * + * \return the default implementation. + */ +br_rsa_public br_rsa_public_get_default(void); + +/** + * \brief Get "default" RSA implementation (private-key operations). + * + * This returns the preferred implementation of RSA (private-key operations) + * on the current system. + * + * \return the default implementation. + */ +br_rsa_private br_rsa_private_get_default(void); + +/** + * \brief Get "default" RSA implementation (PKCS#1 v1.5 signature verification). + * + * This returns the preferred implementation of RSA (signature verification) + * on the current system. + * + * \return the default implementation. + */ +br_rsa_pkcs1_vrfy br_rsa_pkcs1_vrfy_get_default(void); + +/** + * \brief Get "default" RSA implementation (PSS signature verification). + * + * This returns the preferred implementation of RSA (signature verification) + * on the current system. + * + * \return the default implementation. + */ +br_rsa_pss_vrfy br_rsa_pss_vrfy_get_default(void); + +/** + * \brief Get "default" RSA implementation (PKCS#1 v1.5 signature generation). + * + * This returns the preferred implementation of RSA (signature generation) + * on the current system. + * + * \return the default implementation. + */ +br_rsa_pkcs1_sign br_rsa_pkcs1_sign_get_default(void); + +/** + * \brief Get "default" RSA implementation (PSS signature generation). + * + * This returns the preferred implementation of RSA (signature generation) + * on the current system. + * + * \return the default implementation. + */ +br_rsa_pss_sign br_rsa_pss_sign_get_default(void); + +/** + * \brief Get "default" RSA implementation (OAEP encryption). + * + * This returns the preferred implementation of RSA (OAEP encryption) + * on the current system. + * + * \return the default implementation. + */ +br_rsa_oaep_encrypt br_rsa_oaep_encrypt_get_default(void); + +/** + * \brief Get "default" RSA implementation (OAEP decryption). + * + * This returns the preferred implementation of RSA (OAEP decryption) + * on the current system. + * + * \return the default implementation. + */ +br_rsa_oaep_decrypt br_rsa_oaep_decrypt_get_default(void); + +/** + * \brief RSA decryption helper, for SSL/TLS. + * + * This function performs the RSA decryption for a RSA-based key exchange + * in a SSL/TLS server. The provided RSA engine is used. The `data` + * parameter points to the value to decrypt, of length `len` bytes. On + * success, the 48-byte pre-master secret is copied into `data`, starting + * at the first byte of that buffer; on error, the contents of `data` + * become indeterminate. + * + * This function first checks that the provided value length (`len`) is + * not lower than 59 bytes, and matches the RSA modulus length; if neither + * of this property is met, then this function returns 0 and the buffer + * is unmodified. + * + * Otherwise, decryption and then padding verification are performed, both + * in constant-time. A decryption error, or a bad padding, or an + * incorrect decrypted value length are reported with a returned value of + * 0; on success, 1 is returned. The caller (SSL server engine) is supposed + * to proceed with a random pre-master secret in case of error. + * + * \param core RSA private key engine. + * \param sk RSA private key. + * \param data input/output buffer. + * \param len length (in bytes) of the data to decrypt. + * \return 1 on success, 0 on error. + */ +uint32_t br_rsa_ssl_decrypt(br_rsa_private core, const br_rsa_private_key *sk, + unsigned char *data, size_t len); + +/** + * \brief RSA encryption (OAEP) with the "i15" engine. + * + * \see br_rsa_oaep_encrypt + * + * \param rnd source of random bytes. + * \param dig hash function to use with MGF1. + * \param label label value (may be `NULL` if `label_len` is zero). + * \param label_len label length, in bytes. + * \param pk RSA public key. + * \param dst destination buffer. + * \param dst_max_len destination buffer length (maximum encrypted data size). + * \param src message to encrypt. + * \param src_len source message length (in bytes). + * \return encrypted message length (in bytes), or 0 on error. + */ +size_t br_rsa_i15_oaep_encrypt( + const br_prng_class **rnd, const br_hash_class *dig, + const void *label, size_t label_len, + const br_rsa_public_key *pk, + void *dst, size_t dst_max_len, + const void *src, size_t src_len); + +/** + * \brief RSA decryption (OAEP) with the "i15" engine. + * + * \see br_rsa_oaep_decrypt + * + * \param dig hash function to use with MGF1. + * \param label label value (may be `NULL` if `label_len` is zero). + * \param label_len label length, in bytes. + * \param sk RSA private key. + * \param data input/output buffer. + * \param len encrypted/decrypted message length. + * \return 1 on success, 0 on error. + */ +uint32_t br_rsa_i15_oaep_decrypt( + const br_hash_class *dig, const void *label, size_t label_len, + const br_rsa_private_key *sk, void *data, size_t *len); + +/** + * \brief RSA encryption (OAEP) with the "i31" engine. + * + * \see br_rsa_oaep_encrypt + * + * \param rnd source of random bytes. + * \param dig hash function to use with MGF1. + * \param label label value (may be `NULL` if `label_len` is zero). + * \param label_len label length, in bytes. + * \param pk RSA public key. + * \param dst destination buffer. + * \param dst_max_len destination buffer length (maximum encrypted data size). + * \param src message to encrypt. + * \param src_len source message length (in bytes). + * \return encrypted message length (in bytes), or 0 on error. + */ +size_t br_rsa_i31_oaep_encrypt( + const br_prng_class **rnd, const br_hash_class *dig, + const void *label, size_t label_len, + const br_rsa_public_key *pk, + void *dst, size_t dst_max_len, + const void *src, size_t src_len); + +/** + * \brief RSA decryption (OAEP) with the "i31" engine. + * + * \see br_rsa_oaep_decrypt + * + * \param dig hash function to use with MGF1. + * \param label label value (may be `NULL` if `label_len` is zero). + * \param label_len label length, in bytes. + * \param sk RSA private key. + * \param data input/output buffer. + * \param len encrypted/decrypted message length. + * \return 1 on success, 0 on error. + */ +uint32_t br_rsa_i31_oaep_decrypt( + const br_hash_class *dig, const void *label, size_t label_len, + const br_rsa_private_key *sk, void *data, size_t *len); + +/** + * \brief RSA encryption (OAEP) with the "i32" engine. + * + * \see br_rsa_oaep_encrypt + * + * \param rnd source of random bytes. + * \param dig hash function to use with MGF1. + * \param label label value (may be `NULL` if `label_len` is zero). + * \param label_len label length, in bytes. + * \param pk RSA public key. + * \param dst destination buffer. + * \param dst_max_len destination buffer length (maximum encrypted data size). + * \param src message to encrypt. + * \param src_len source message length (in bytes). + * \return encrypted message length (in bytes), or 0 on error. + */ +size_t br_rsa_i32_oaep_encrypt( + const br_prng_class **rnd, const br_hash_class *dig, + const void *label, size_t label_len, + const br_rsa_public_key *pk, + void *dst, size_t dst_max_len, + const void *src, size_t src_len); + +/** + * \brief RSA decryption (OAEP) with the "i32" engine. + * + * \see br_rsa_oaep_decrypt + * + * \param dig hash function to use with MGF1. + * \param label label value (may be `NULL` if `label_len` is zero). + * \param label_len label length, in bytes. + * \param sk RSA private key. + * \param data input/output buffer. + * \param len encrypted/decrypted message length. + * \return 1 on success, 0 on error. + */ +uint32_t br_rsa_i32_oaep_decrypt( + const br_hash_class *dig, const void *label, size_t label_len, + const br_rsa_private_key *sk, void *data, size_t *len); + +/** + * \brief RSA encryption (OAEP) with the "i62" engine. + * + * This function is defined only on architecture that offer a 64x64->128 + * opcode. Use `br_rsa_i62_oaep_encrypt_get()` to dynamically obtain a pointer + * to that function. + * + * \see br_rsa_oaep_encrypt + * + * \param rnd source of random bytes. + * \param dig hash function to use with MGF1. + * \param label label value (may be `NULL` if `label_len` is zero). + * \param label_len label length, in bytes. + * \param pk RSA public key. + * \param dst destination buffer. + * \param dst_max_len destination buffer length (maximum encrypted data size). + * \param src message to encrypt. + * \param src_len source message length (in bytes). + * \return encrypted message length (in bytes), or 0 on error. + */ +size_t br_rsa_i62_oaep_encrypt( + const br_prng_class **rnd, const br_hash_class *dig, + const void *label, size_t label_len, + const br_rsa_public_key *pk, + void *dst, size_t dst_max_len, + const void *src, size_t src_len); + +/** + * \brief RSA decryption (OAEP) with the "i62" engine. + * + * This function is defined only on architecture that offer a 64x64->128 + * opcode. Use `br_rsa_i62_oaep_decrypt_get()` to dynamically obtain a pointer + * to that function. + * + * \see br_rsa_oaep_decrypt + * + * \param dig hash function to use with MGF1. + * \param label label value (may be `NULL` if `label_len` is zero). + * \param label_len label length, in bytes. + * \param sk RSA private key. + * \param data input/output buffer. + * \param len encrypted/decrypted message length. + * \return 1 on success, 0 on error. + */ +uint32_t br_rsa_i62_oaep_decrypt( + const br_hash_class *dig, const void *label, size_t label_len, + const br_rsa_private_key *sk, void *data, size_t *len); + +/** + * \brief Get buffer size to hold RSA private key elements. + * + * This macro returns the length (in bytes) of the buffer needed to + * receive the elements of a RSA private key, as generated by one of + * the `br_rsa_*_keygen()` functions. If the provided size is a constant + * expression, then the whole macro evaluates to a constant expression. + * + * \param size target key size (modulus size, in bits) + * \return the length of the private key buffer, in bytes. + */ +#define BR_RSA_KBUF_PRIV_SIZE(size) (5 * (((size) + 15) >> 4)) + +/** + * \brief Get buffer size to hold RSA public key elements. + * + * This macro returns the length (in bytes) of the buffer needed to + * receive the elements of a RSA public key, as generated by one of + * the `br_rsa_*_keygen()` functions. If the provided size is a constant + * expression, then the whole macro evaluates to a constant expression. + * + * \param size target key size (modulus size, in bits) + * \return the length of the public key buffer, in bytes. + */ +#define BR_RSA_KBUF_PUB_SIZE(size) (4 + (((size) + 7) >> 3)) + +/** + * \brief Type for RSA key pair generator implementation. + * + * This function generates a new RSA key pair whose modulus has bit + * length `size` bits. The private key elements are written in the + * `kbuf_priv` buffer, and pointer values and length fields to these + * elements are populated in the provided private key structure `sk`. + * Similarly, the public key elements are written in `kbuf_pub`, with + * pointers and lengths set in `pk`. + * + * If `pk` is `NULL`, then `kbuf_pub` may be `NULL`, and only the + * private key is set. + * + * If `pubexp` is not zero, then its value will be used as public + * exponent. Valid RSA public exponent values are odd integers + * greater than 1. If `pubexp` is zero, then the public exponent will + * have value 3. + * + * The provided PRNG (`rng_ctx`) must have already been initialized + * and seeded. + * + * Returned value is 1 on success, 0 on error. An error is reported + * if the requested range is outside of the supported key sizes, or + * if an invalid non-zero public exponent value is provided. Supported + * range starts at 512 bits, and up to an implementation-defined + * maximum (by default 4096 bits). Note that key sizes up to 768 bits + * have been broken in practice, and sizes lower than 2048 bits are + * usually considered to be weak and should not be used. + * + * \param rng_ctx source PRNG context (already initialized) + * \param sk RSA private key structure (destination) + * \param kbuf_priv buffer for private key elements + * \param pk RSA public key structure (destination), or `NULL` + * \param kbuf_pub buffer for public key elements, or `NULL` + * \param size target RSA modulus size (in bits) + * \param pubexp public exponent to use, or zero + * \return 1 on success, 0 on error (invalid parameters) + */ +typedef uint32_t (*br_rsa_keygen)( + const br_prng_class **rng_ctx, + br_rsa_private_key *sk, void *kbuf_priv, + br_rsa_public_key *pk, void *kbuf_pub, + unsigned size, uint32_t pubexp); + +/** + * \brief RSA key pair generation with the "i15" engine. + * + * \see br_rsa_keygen + * + * \param rng_ctx source PRNG context (already initialized) + * \param sk RSA private key structure (destination) + * \param kbuf_priv buffer for private key elements + * \param pk RSA public key structure (destination), or `NULL` + * \param kbuf_pub buffer for public key elements, or `NULL` + * \param size target RSA modulus size (in bits) + * \param pubexp public exponent to use, or zero + * \return 1 on success, 0 on error (invalid parameters) + */ +uint32_t br_rsa_i15_keygen( + const br_prng_class **rng_ctx, + br_rsa_private_key *sk, void *kbuf_priv, + br_rsa_public_key *pk, void *kbuf_pub, + unsigned size, uint32_t pubexp); + +/** + * \brief RSA key pair generation with the "i31" engine. + * + * \see br_rsa_keygen + * + * \param rng_ctx source PRNG context (already initialized) + * \param sk RSA private key structure (destination) + * \param kbuf_priv buffer for private key elements + * \param pk RSA public key structure (destination), or `NULL` + * \param kbuf_pub buffer for public key elements, or `NULL` + * \param size target RSA modulus size (in bits) + * \param pubexp public exponent to use, or zero + * \return 1 on success, 0 on error (invalid parameters) + */ +uint32_t br_rsa_i31_keygen( + const br_prng_class **rng_ctx, + br_rsa_private_key *sk, void *kbuf_priv, + br_rsa_public_key *pk, void *kbuf_pub, + unsigned size, uint32_t pubexp); + +/** + * \brief RSA key pair generation with the "i62" engine. + * + * This function is defined only on architecture that offer a 64x64->128 + * opcode. Use `br_rsa_i62_keygen_get()` to dynamically obtain a pointer + * to that function. + * + * \see br_rsa_keygen + * + * \param rng_ctx source PRNG context (already initialized) + * \param sk RSA private key structure (destination) + * \param kbuf_priv buffer for private key elements + * \param pk RSA public key structure (destination), or `NULL` + * \param kbuf_pub buffer for public key elements, or `NULL` + * \param size target RSA modulus size (in bits) + * \param pubexp public exponent to use, or zero + * \return 1 on success, 0 on error (invalid parameters) + */ +uint32_t br_rsa_i62_keygen( + const br_prng_class **rng_ctx, + br_rsa_private_key *sk, void *kbuf_priv, + br_rsa_public_key *pk, void *kbuf_pub, + unsigned size, uint32_t pubexp); + +/** + * \brief Get the RSA "i62" implementation (key pair generation), + * if available. + * + * \return the implementation, or 0. + */ +br_rsa_keygen br_rsa_i62_keygen_get(void); + +/** + * \brief Get "default" RSA implementation (key pair generation). + * + * This returns the preferred implementation of RSA (key pair generation) + * on the current system. + * + * \return the default implementation. + */ +br_rsa_keygen br_rsa_keygen_get_default(void); + +/** + * \brief Type for a modulus computing function. + * + * Such a function computes the public modulus from the private key. The + * encoded modulus (unsigned big-endian) is written on `n`, and the size + * (in bytes) is returned. If `n` is `NULL`, then the size is returned but + * the modulus itself is not computed. + * + * If the key size exceeds an internal limit, 0 is returned. + * + * \param n destination buffer (or `NULL`). + * \param sk RSA private key. + * \return the modulus length (in bytes), or 0. + */ +typedef size_t (*br_rsa_compute_modulus)(void *n, const br_rsa_private_key *sk); + +/** + * \brief Recompute RSA modulus ("i15" engine). + * + * \see br_rsa_compute_modulus + * + * \param n destination buffer (or `NULL`). + * \param sk RSA private key. + * \return the modulus length (in bytes), or 0. + */ +size_t br_rsa_i15_compute_modulus(void *n, const br_rsa_private_key *sk); + +/** + * \brief Recompute RSA modulus ("i31" engine). + * + * \see br_rsa_compute_modulus + * + * \param n destination buffer (or `NULL`). + * \param sk RSA private key. + * \return the modulus length (in bytes), or 0. + */ +size_t br_rsa_i31_compute_modulus(void *n, const br_rsa_private_key *sk); + +/** + * \brief Get "default" RSA implementation (recompute modulus). + * + * This returns the preferred implementation of RSA (recompute modulus) + * on the current system. + * + * \return the default implementation. + */ +br_rsa_compute_modulus br_rsa_compute_modulus_get_default(void); + +/** + * \brief Type for a public exponent computing function. + * + * Such a function recomputes the public exponent from the private key. + * 0 is returned if any of the following occurs: + * + * - Either `p` or `q` is not equal to 3 modulo 4. + * + * - The public exponent does not fit on 32 bits. + * + * - An internal limit is exceeded. + * + * - The private key is invalid in some way. + * + * For all private keys produced by the key generator functions + * (`br_rsa_keygen` type), this function succeeds and returns the true + * public exponent. The public exponent is always an odd integer greater + * than 1. + * + * \return the public exponent, or 0. + */ +typedef uint32_t (*br_rsa_compute_pubexp)(const br_rsa_private_key *sk); + +/** + * \brief Recompute RSA public exponent ("i15" engine). + * + * \see br_rsa_compute_pubexp + * + * \return the public exponent, or 0. + */ +uint32_t br_rsa_i15_compute_pubexp(const br_rsa_private_key *sk); + +/** + * \brief Recompute RSA public exponent ("i31" engine). + * + * \see br_rsa_compute_pubexp + * + * \return the public exponent, or 0. + */ +uint32_t br_rsa_i31_compute_pubexp(const br_rsa_private_key *sk); + +/** + * \brief Get "default" RSA implementation (recompute public exponent). + * + * This returns the preferred implementation of RSA (recompute public + * exponent) on the current system. + * + * \return the default implementation. + */ +br_rsa_compute_pubexp br_rsa_compute_pubexp_get_default(void); + +/** + * \brief Type for a private exponent computing function. + * + * An RSA private key (`br_rsa_private_key`) contains two reduced + * private exponents, which are sufficient to perform private key + * operations. However, standard encoding formats for RSA private keys + * require also a copy of the complete private exponent (non-reduced), + * which this function recomputes. + * + * This function suceeds if all the following conditions hold: + * + * - Both private factors `p` and `q` are equal to 3 modulo 4. + * + * - The provided public exponent `pubexp` is correct, and, in particular, + * is odd, relatively prime to `p-1` and `q-1`, and greater than 1. + * + * - No internal storage limit is exceeded. + * + * For all private keys produced by the key generator functions + * (`br_rsa_keygen` type), this function succeeds. Note that the API + * restricts the public exponent to a maximum size of 32 bits. + * + * The encoded private exponent is written in `d` (unsigned big-endian + * convention), and the length (in bytes) is returned. If `d` is `NULL`, + * then the exponent is not written anywhere, but the length is still + * returned. On error, 0 is returned. + * + * Not all error conditions are detected when `d` is `NULL`; therefore, the + * returned value shall be checked also when actually producing the value. + * + * \param d destination buffer (or `NULL`). + * \param sk RSA private key. + * \param pubexp the public exponent. + * \return the private exponent length (in bytes), or 0. + */ +typedef size_t (*br_rsa_compute_privexp)(void *d, + const br_rsa_private_key *sk, uint32_t pubexp); + +/** + * \brief Recompute RSA private exponent ("i15" engine). + * + * \see br_rsa_compute_privexp + * + * \param d destination buffer (or `NULL`). + * \param sk RSA private key. + * \param pubexp the public exponent. + * \return the private exponent length (in bytes), or 0. + */ +size_t br_rsa_i15_compute_privexp(void *d, + const br_rsa_private_key *sk, uint32_t pubexp); + +/** + * \brief Recompute RSA private exponent ("i31" engine). + * + * \see br_rsa_compute_privexp + * + * \param d destination buffer (or `NULL`). + * \param sk RSA private key. + * \param pubexp the public exponent. + * \return the private exponent length (in bytes), or 0. + */ +size_t br_rsa_i31_compute_privexp(void *d, + const br_rsa_private_key *sk, uint32_t pubexp); + +/** + * \brief Get "default" RSA implementation (recompute private exponent). + * + * This returns the preferred implementation of RSA (recompute private + * exponent) on the current system. + * + * \return the default implementation. + */ +br_rsa_compute_privexp br_rsa_compute_privexp_get_default(void); + +#ifdef __cplusplus +} +#endif + +#endif + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/bearssl_ssl.h b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/bearssl_ssl.h new file mode 100644 index 000000000..8ad2d69c5 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/bearssl_ssl.h @@ -0,0 +1,4331 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#ifndef BR_BEARSSL_SSL_H__ +#define BR_BEARSSL_SSL_H__ + +#include +#include + +#include "bearssl_block.h" +#include "bearssl_hash.h" +#include "bearssl_hmac.h" +#include "bearssl_prf.h" +#include "bearssl_rand.h" +#include "bearssl_x509.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** \file bearssl_ssl.h + * + * # SSL + * + * For an overview of the SSL/TLS API, see [the BearSSL Web + * site](https://www.bearssl.org/api1.html). + * + * The `BR_TLS_*` constants correspond to the standard cipher suites and + * their values in the [IANA + * registry](http://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-4). + * + * The `BR_ALERT_*` constants are for standard TLS alert messages. When + * a fatal alert message is sent of received, then the SSL engine context + * status is set to the sum of that alert value (an integer in the 0..255 + * range) and a fixed offset (`BR_ERR_SEND_FATAL_ALERT` for a sent alert, + * `BR_ERR_RECV_FATAL_ALERT` for a received alert). + */ + +/** \brief Optimal input buffer size. */ +#define BR_SSL_BUFSIZE_INPUT (16384 + 325) + +/** \brief Optimal output buffer size. */ +#define BR_SSL_BUFSIZE_OUTPUT (16384 + 85) + +/** \brief Optimal buffer size for monodirectional engine + (shared input/output buffer). */ +#define BR_SSL_BUFSIZE_MONO BR_SSL_BUFSIZE_INPUT + +/** \brief Optimal buffer size for bidirectional engine + (single buffer split into two separate input/output buffers). */ +#define BR_SSL_BUFSIZE_BIDI (BR_SSL_BUFSIZE_INPUT + BR_SSL_BUFSIZE_OUTPUT) + +/* + * Constants for known SSL/TLS protocol versions (SSL 3.0, TLS 1.0, TLS 1.1 + * and TLS 1.2). Note that though there is a constant for SSL 3.0, that + * protocol version is not actually supported. + */ + +/** \brief Protocol version: SSL 3.0 (unsupported). */ +#define BR_SSL30 0x0300 +/** \brief Protocol version: TLS 1.0. */ +#define BR_TLS10 0x0301 +/** \brief Protocol version: TLS 1.1. */ +#define BR_TLS11 0x0302 +/** \brief Protocol version: TLS 1.2. */ +#define BR_TLS12 0x0303 + +/* + * Error constants. They are used to report the reason why a context has + * been marked as failed. + * + * Implementation note: SSL-level error codes should be in the 1..31 + * range. The 32..63 range is for certificate decoding and validation + * errors. Received fatal alerts imply an error code in the 256..511 range. + */ + +/** \brief SSL status: no error so far (0). */ +#define BR_ERR_OK 0 + +/** \brief SSL status: caller-provided parameter is incorrect. */ +#define BR_ERR_BAD_PARAM 1 + +/** \brief SSL status: operation requested by the caller cannot be applied + with the current context state (e.g. reading data while outgoing data + is waiting to be sent). */ +#define BR_ERR_BAD_STATE 2 + +/** \brief SSL status: incoming protocol or record version is unsupported. */ +#define BR_ERR_UNSUPPORTED_VERSION 3 + +/** \brief SSL status: incoming record version does not match the expected + version. */ +#define BR_ERR_BAD_VERSION 4 + +/** \brief SSL status: incoming record length is invalid. */ +#define BR_ERR_BAD_LENGTH 5 + +/** \brief SSL status: incoming record is too large to be processed, or + buffer is too small for the handshake message to send. */ +#define BR_ERR_TOO_LARGE 6 + +/** \brief SSL status: decryption found an invalid padding, or the record + MAC is not correct. */ +#define BR_ERR_BAD_MAC 7 + +/** \brief SSL status: no initial entropy was provided, and none can be + obtained from the OS. */ +#define BR_ERR_NO_RANDOM 8 + +/** \brief SSL status: incoming record type is unknown. */ +#define BR_ERR_UNKNOWN_TYPE 9 + +/** \brief SSL status: incoming record or message has wrong type with + regards to the current engine state. */ +#define BR_ERR_UNEXPECTED 10 + +/** \brief SSL status: ChangeCipherSpec message from the peer has invalid + contents. */ +#define BR_ERR_BAD_CCS 12 + +/** \brief SSL status: alert message from the peer has invalid contents + (odd length). */ +#define BR_ERR_BAD_ALERT 13 + +/** \brief SSL status: incoming handshake message decoding failed. */ +#define BR_ERR_BAD_HANDSHAKE 14 + +/** \brief SSL status: ServerHello contains a session ID which is larger + than 32 bytes. */ +#define BR_ERR_OVERSIZED_ID 15 + +/** \brief SSL status: server wants to use a cipher suite that we did + not claim to support. This is also reported if we tried to advertise + a cipher suite that we do not support. */ +#define BR_ERR_BAD_CIPHER_SUITE 16 + +/** \brief SSL status: server wants to use a compression that we did not + claim to support. */ +#define BR_ERR_BAD_COMPRESSION 17 + +/** \brief SSL status: server's max fragment length does not match + client's. */ +#define BR_ERR_BAD_FRAGLEN 18 + +/** \brief SSL status: secure renegotiation failed. */ +#define BR_ERR_BAD_SECRENEG 19 + +/** \brief SSL status: server sent an extension type that we did not + announce, or used the same extension type several times in a single + ServerHello. */ +#define BR_ERR_EXTRA_EXTENSION 20 + +/** \brief SSL status: invalid Server Name Indication contents (when + used by the server, this extension shall be empty). */ +#define BR_ERR_BAD_SNI 21 + +/** \brief SSL status: invalid ServerHelloDone from the server (length + is not 0). */ +#define BR_ERR_BAD_HELLO_DONE 22 + +/** \brief SSL status: internal limit exceeded (e.g. server's public key + is too large). */ +#define BR_ERR_LIMIT_EXCEEDED 23 + +/** \brief SSL status: Finished message from peer does not match the + expected value. */ +#define BR_ERR_BAD_FINISHED 24 + +/** \brief SSL status: session resumption attempt with distinct version + or cipher suite. */ +#define BR_ERR_RESUME_MISMATCH 25 + +/** \brief SSL status: unsupported or invalid algorithm (ECDHE curve, + signature algorithm, hash function). */ +#define BR_ERR_INVALID_ALGORITHM 26 + +/** \brief SSL status: invalid signature (on ServerKeyExchange from + server, or in CertificateVerify from client). */ +#define BR_ERR_BAD_SIGNATURE 27 + +/** \brief SSL status: peer's public key does not have the proper type + or is not allowed for requested operation. */ +#define BR_ERR_WRONG_KEY_USAGE 28 + +/** \brief SSL status: client did not send a certificate upon request, + or the client certificate could not be validated. */ +#define BR_ERR_NO_CLIENT_AUTH 29 + +/** \brief SSL status: I/O error or premature close on underlying + transport stream. This error code is set only by the simplified + I/O API ("br_sslio_*"). */ +#define BR_ERR_IO 31 + +/** \brief SSL status: base value for a received fatal alert. + + When a fatal alert is received from the peer, the alert value + is added to this constant. */ +#define BR_ERR_RECV_FATAL_ALERT 256 + +/** \brief SSL status: base value for a sent fatal alert. + + When a fatal alert is sent to the peer, the alert value is added + to this constant. */ +#define BR_ERR_SEND_FATAL_ALERT 512 + +/* ===================================================================== */ + +/** + * \brief Decryption engine for SSL. + * + * When processing incoming records, the SSL engine will use a decryption + * engine that uses a specific context structure, and has a set of + * methods (a vtable) that follows this template. + * + * The decryption engine is responsible for applying decryption, verifying + * MAC, and keeping track of the record sequence number. + */ +typedef struct br_sslrec_in_class_ br_sslrec_in_class; +struct br_sslrec_in_class_ { + /** + * \brief Context size (in bytes). + */ + size_t context_size; + + /** + * \brief Test validity of the incoming record length. + * + * This function returns 1 if the announced length for an + * incoming record is valid, 0 otherwise, + * + * \param ctx decryption engine context. + * \param record_len incoming record length. + * \return 1 of a valid length, 0 otherwise. + */ + int (*check_length)(const br_sslrec_in_class *const *ctx, + size_t record_len); + + /** + * \brief Decrypt the incoming record. + * + * This function may assume that the record length is valid + * (it has been previously tested with `check_length()`). + * Decryption is done in place; `*len` is updated with the + * cleartext length, and the address of the first plaintext + * byte is returned. If the record is correct but empty, then + * `*len` is set to 0 and a non-`NULL` pointer is returned. + * + * On decryption/MAC error, `NULL` is returned. + * + * \param ctx decryption engine context. + * \param record_type record type (23 for application data, etc). + * \param version record version. + * \param payload address of encrypted payload. + * \param len pointer to payload length (updated). + * \return pointer to plaintext, or `NULL` on error. + */ + unsigned char *(*decrypt)(const br_sslrec_in_class **ctx, + int record_type, unsigned version, + void *payload, size_t *len); +}; + +/** + * \brief Encryption engine for SSL. + * + * When building outgoing records, the SSL engine will use an encryption + * engine that uses a specific context structure, and has a set of + * methods (a vtable) that follows this template. + * + * The encryption engine is responsible for applying encryption and MAC, + * and keeping track of the record sequence number. + */ +typedef struct br_sslrec_out_class_ br_sslrec_out_class; +struct br_sslrec_out_class_ { + /** + * \brief Context size (in bytes). + */ + size_t context_size; + + /** + * \brief Compute maximum plaintext sizes and offsets. + * + * When this function is called, the `*start` and `*end` + * values contain offsets designating the free area in the + * outgoing buffer for plaintext data; that free area is + * preceded by a 5-byte space which will receive the record + * header. + * + * The `max_plaintext()` function is responsible for adjusting + * both `*start` and `*end` to make room for any record-specific + * header, MAC, padding, and possible split. + * + * \param ctx encryption engine context. + * \param start pointer to start of plaintext offset (updated). + * \param end pointer to start of plaintext offset (updated). + */ + void (*max_plaintext)(const br_sslrec_out_class *const *ctx, + size_t *start, size_t *end); + + /** + * \brief Perform record encryption. + * + * This function encrypts the record. The plaintext address and + * length are provided. Returned value is the start of the + * encrypted record (or sequence of records, if a split was + * performed), _including_ the 5-byte header, and `*len` is + * adjusted to the total size of the record(s), there again + * including the header(s). + * + * \param ctx decryption engine context. + * \param record_type record type (23 for application data, etc). + * \param version record version. + * \param plaintext address of plaintext. + * \param len pointer to plaintext length (updated). + * \return pointer to start of built record. + */ + unsigned char *(*encrypt)(const br_sslrec_out_class **ctx, + int record_type, unsigned version, + void *plaintext, size_t *len); +}; + +/** + * \brief Context for a no-encryption engine. + * + * The no-encryption engine processes outgoing records during the initial + * handshake, before encryption is applied. + */ +typedef struct { + /** \brief No-encryption engine vtable. */ + const br_sslrec_out_class *vtable; +} br_sslrec_out_clear_context; + +/** \brief Static, constant vtable for the no-encryption engine. */ +extern const br_sslrec_out_class br_sslrec_out_clear_vtable; + +/* ===================================================================== */ + +/** + * \brief Record decryption engine class, for CBC mode. + * + * This class type extends the decryption engine class with an + * initialisation method that receives the parameters needed + * for CBC processing: block cipher implementation, block cipher key, + * HMAC parameters (hash function, key, MAC length), and IV. If the + * IV is `NULL`, then a per-record IV will be used (TLS 1.1+). + */ +typedef struct br_sslrec_in_cbc_class_ br_sslrec_in_cbc_class; +struct br_sslrec_in_cbc_class_ { + /** + * \brief Superclass, as first vtable field. + */ + br_sslrec_in_class inner; + + /** + * \brief Engine initialisation method. + * + * This method sets the vtable field in the context. + * + * \param ctx context to initialise. + * \param bc_impl block cipher implementation (CBC decryption). + * \param bc_key block cipher key. + * \param bc_key_len block cipher key length (in bytes). + * \param dig_impl hash function for HMAC. + * \param mac_key HMAC key. + * \param mac_key_len HMAC key length (in bytes). + * \param mac_out_len HMAC output length (in bytes). + * \param iv initial IV (or `NULL`). + */ + void (*init)(const br_sslrec_in_cbc_class **ctx, + const br_block_cbcdec_class *bc_impl, + const void *bc_key, size_t bc_key_len, + const br_hash_class *dig_impl, + const void *mac_key, size_t mac_key_len, size_t mac_out_len, + const void *iv); +}; + +/** + * \brief Record encryption engine class, for CBC mode. + * + * This class type extends the encryption engine class with an + * initialisation method that receives the parameters needed + * for CBC processing: block cipher implementation, block cipher key, + * HMAC parameters (hash function, key, MAC length), and IV. If the + * IV is `NULL`, then a per-record IV will be used (TLS 1.1+). + */ +typedef struct br_sslrec_out_cbc_class_ br_sslrec_out_cbc_class; +struct br_sslrec_out_cbc_class_ { + /** + * \brief Superclass, as first vtable field. + */ + br_sslrec_out_class inner; + + /** + * \brief Engine initialisation method. + * + * This method sets the vtable field in the context. + * + * \param ctx context to initialise. + * \param bc_impl block cipher implementation (CBC encryption). + * \param bc_key block cipher key. + * \param bc_key_len block cipher key length (in bytes). + * \param dig_impl hash function for HMAC. + * \param mac_key HMAC key. + * \param mac_key_len HMAC key length (in bytes). + * \param mac_out_len HMAC output length (in bytes). + * \param iv initial IV (or `NULL`). + */ + void (*init)(const br_sslrec_out_cbc_class **ctx, + const br_block_cbcenc_class *bc_impl, + const void *bc_key, size_t bc_key_len, + const br_hash_class *dig_impl, + const void *mac_key, size_t mac_key_len, size_t mac_out_len, + const void *iv); +}; + +/** + * \brief Context structure for decrypting incoming records with + * CBC + HMAC. + * + * The first field points to the vtable. The other fields are opaque + * and shall not be accessed directly. + */ +typedef struct { + /** \brief Pointer to vtable. */ + const br_sslrec_in_cbc_class *vtable; +#ifndef BR_DOXYGEN_IGNORE + uint64_t seq; + union { + const br_block_cbcdec_class *vtable; + br_aes_gen_cbcdec_keys aes; + br_des_gen_cbcdec_keys des; + } bc; + br_hmac_key_context mac; + size_t mac_len; + unsigned char iv[16]; + int explicit_IV; +#endif +} br_sslrec_in_cbc_context; + +/** + * \brief Static, constant vtable for record decryption with CBC. + */ +extern const br_sslrec_in_cbc_class br_sslrec_in_cbc_vtable; + +/** + * \brief Context structure for encrypting outgoing records with + * CBC + HMAC. + * + * The first field points to the vtable. The other fields are opaque + * and shall not be accessed directly. + */ +typedef struct { + /** \brief Pointer to vtable. */ + const br_sslrec_out_cbc_class *vtable; +#ifndef BR_DOXYGEN_IGNORE + uint64_t seq; + union { + const br_block_cbcenc_class *vtable; + br_aes_gen_cbcenc_keys aes; + br_des_gen_cbcenc_keys des; + } bc; + br_hmac_key_context mac; + size_t mac_len; + unsigned char iv[16]; + int explicit_IV; +#endif +} br_sslrec_out_cbc_context; + +/** + * \brief Static, constant vtable for record encryption with CBC. + */ +extern const br_sslrec_out_cbc_class br_sslrec_out_cbc_vtable; + +/* ===================================================================== */ + +/** + * \brief Record decryption engine class, for GCM mode. + * + * This class type extends the decryption engine class with an + * initialisation method that receives the parameters needed + * for GCM processing: block cipher implementation, block cipher key, + * GHASH implementation, and 4-byte IV. + */ +typedef struct br_sslrec_in_gcm_class_ br_sslrec_in_gcm_class; +struct br_sslrec_in_gcm_class_ { + /** + * \brief Superclass, as first vtable field. + */ + br_sslrec_in_class inner; + + /** + * \brief Engine initialisation method. + * + * This method sets the vtable field in the context. + * + * \param ctx context to initialise. + * \param bc_impl block cipher implementation (CTR). + * \param key block cipher key. + * \param key_len block cipher key length (in bytes). + * \param gh_impl GHASH implementation. + * \param iv static IV (4 bytes). + */ + void (*init)(const br_sslrec_in_gcm_class **ctx, + const br_block_ctr_class *bc_impl, + const void *key, size_t key_len, + br_ghash gh_impl, + const void *iv); +}; + +/** + * \brief Record encryption engine class, for GCM mode. + * + * This class type extends the encryption engine class with an + * initialisation method that receives the parameters needed + * for GCM processing: block cipher implementation, block cipher key, + * GHASH implementation, and 4-byte IV. + */ +typedef struct br_sslrec_out_gcm_class_ br_sslrec_out_gcm_class; +struct br_sslrec_out_gcm_class_ { + /** + * \brief Superclass, as first vtable field. + */ + br_sslrec_out_class inner; + + /** + * \brief Engine initialisation method. + * + * This method sets the vtable field in the context. + * + * \param ctx context to initialise. + * \param bc_impl block cipher implementation (CTR). + * \param key block cipher key. + * \param key_len block cipher key length (in bytes). + * \param gh_impl GHASH implementation. + * \param iv static IV (4 bytes). + */ + void (*init)(const br_sslrec_out_gcm_class **ctx, + const br_block_ctr_class *bc_impl, + const void *key, size_t key_len, + br_ghash gh_impl, + const void *iv); +}; + +/** + * \brief Context structure for processing records with GCM. + * + * The same context structure is used for encrypting and decrypting. + * + * The first field points to the vtable. The other fields are opaque + * and shall not be accessed directly. + */ +typedef struct { + /** \brief Pointer to vtable. */ + union { + const void *gen; + const br_sslrec_in_gcm_class *in; + const br_sslrec_out_gcm_class *out; + } vtable; +#ifndef BR_DOXYGEN_IGNORE + uint64_t seq; + union { + const br_block_ctr_class *vtable; + br_aes_gen_ctr_keys aes; + } bc; + br_ghash gh; + unsigned char iv[4]; + unsigned char h[16]; +#endif +} br_sslrec_gcm_context; + +/** + * \brief Static, constant vtable for record decryption with GCM. + */ +extern const br_sslrec_in_gcm_class br_sslrec_in_gcm_vtable; + +/** + * \brief Static, constant vtable for record encryption with GCM. + */ +extern const br_sslrec_out_gcm_class br_sslrec_out_gcm_vtable; + +/* ===================================================================== */ + +/** + * \brief Record decryption engine class, for ChaCha20+Poly1305. + * + * This class type extends the decryption engine class with an + * initialisation method that receives the parameters needed + * for ChaCha20+Poly1305 processing: ChaCha20 implementation, + * Poly1305 implementation, key, and 12-byte IV. + */ +typedef struct br_sslrec_in_chapol_class_ br_sslrec_in_chapol_class; +struct br_sslrec_in_chapol_class_ { + /** + * \brief Superclass, as first vtable field. + */ + br_sslrec_in_class inner; + + /** + * \brief Engine initialisation method. + * + * This method sets the vtable field in the context. + * + * \param ctx context to initialise. + * \param ichacha ChaCha20 implementation. + * \param ipoly Poly1305 implementation. + * \param key secret key (32 bytes). + * \param iv static IV (12 bytes). + */ + void (*init)(const br_sslrec_in_chapol_class **ctx, + br_chacha20_run ichacha, + br_poly1305_run ipoly, + const void *key, const void *iv); +}; + +/** + * \brief Record encryption engine class, for ChaCha20+Poly1305. + * + * This class type extends the encryption engine class with an + * initialisation method that receives the parameters needed + * for ChaCha20+Poly1305 processing: ChaCha20 implementation, + * Poly1305 implementation, key, and 12-byte IV. + */ +typedef struct br_sslrec_out_chapol_class_ br_sslrec_out_chapol_class; +struct br_sslrec_out_chapol_class_ { + /** + * \brief Superclass, as first vtable field. + */ + br_sslrec_out_class inner; + + /** + * \brief Engine initialisation method. + * + * This method sets the vtable field in the context. + * + * \param ctx context to initialise. + * \param ichacha ChaCha20 implementation. + * \param ipoly Poly1305 implementation. + * \param key secret key (32 bytes). + * \param iv static IV (12 bytes). + */ + void (*init)(const br_sslrec_out_chapol_class **ctx, + br_chacha20_run ichacha, + br_poly1305_run ipoly, + const void *key, const void *iv); +}; + +/** + * \brief Context structure for processing records with ChaCha20+Poly1305. + * + * The same context structure is used for encrypting and decrypting. + * + * The first field points to the vtable. The other fields are opaque + * and shall not be accessed directly. + */ +typedef struct { + /** \brief Pointer to vtable. */ + union { + const void *gen; + const br_sslrec_in_chapol_class *in; + const br_sslrec_out_chapol_class *out; + } vtable; +#ifndef BR_DOXYGEN_IGNORE + uint64_t seq; + unsigned char key[32]; + unsigned char iv[12]; + br_chacha20_run ichacha; + br_poly1305_run ipoly; +#endif +} br_sslrec_chapol_context; + +/** + * \brief Static, constant vtable for record decryption with ChaCha20+Poly1305. + */ +extern const br_sslrec_in_chapol_class br_sslrec_in_chapol_vtable; + +/** + * \brief Static, constant vtable for record encryption with ChaCha20+Poly1305. + */ +extern const br_sslrec_out_chapol_class br_sslrec_out_chapol_vtable; + +/* ===================================================================== */ + +/** + * \brief Record decryption engine class, for CCM mode. + * + * This class type extends the decryption engine class with an + * initialisation method that receives the parameters needed + * for CCM processing: block cipher implementation, block cipher key, + * and 4-byte IV. + */ +typedef struct br_sslrec_in_ccm_class_ br_sslrec_in_ccm_class; +struct br_sslrec_in_ccm_class_ { + /** + * \brief Superclass, as first vtable field. + */ + br_sslrec_in_class inner; + + /** + * \brief Engine initialisation method. + * + * This method sets the vtable field in the context. + * + * \param ctx context to initialise. + * \param bc_impl block cipher implementation (CTR+CBC). + * \param key block cipher key. + * \param key_len block cipher key length (in bytes). + * \param iv static IV (4 bytes). + * \param tag_len tag length (in bytes) + */ + void (*init)(const br_sslrec_in_ccm_class **ctx, + const br_block_ctrcbc_class *bc_impl, + const void *key, size_t key_len, + const void *iv, size_t tag_len); +}; + +/** + * \brief Record encryption engine class, for CCM mode. + * + * This class type extends the encryption engine class with an + * initialisation method that receives the parameters needed + * for CCM processing: block cipher implementation, block cipher key, + * and 4-byte IV. + */ +typedef struct br_sslrec_out_ccm_class_ br_sslrec_out_ccm_class; +struct br_sslrec_out_ccm_class_ { + /** + * \brief Superclass, as first vtable field. + */ + br_sslrec_out_class inner; + + /** + * \brief Engine initialisation method. + * + * This method sets the vtable field in the context. + * + * \param ctx context to initialise. + * \param bc_impl block cipher implementation (CTR+CBC). + * \param key block cipher key. + * \param key_len block cipher key length (in bytes). + * \param iv static IV (4 bytes). + * \param tag_len tag length (in bytes) + */ + void (*init)(const br_sslrec_out_ccm_class **ctx, + const br_block_ctrcbc_class *bc_impl, + const void *key, size_t key_len, + const void *iv, size_t tag_len); +}; + +/** + * \brief Context structure for processing records with CCM. + * + * The same context structure is used for encrypting and decrypting. + * + * The first field points to the vtable. The other fields are opaque + * and shall not be accessed directly. + */ +typedef struct { + /** \brief Pointer to vtable. */ + union { + const void *gen; + const br_sslrec_in_ccm_class *in; + const br_sslrec_out_ccm_class *out; + } vtable; +#ifndef BR_DOXYGEN_IGNORE + uint64_t seq; + union { + const br_block_ctrcbc_class *vtable; + br_aes_gen_ctrcbc_keys aes; + } bc; + unsigned char iv[4]; + size_t tag_len; +#endif +} br_sslrec_ccm_context; + +/** + * \brief Static, constant vtable for record decryption with CCM. + */ +extern const br_sslrec_in_ccm_class br_sslrec_in_ccm_vtable; + +/** + * \brief Static, constant vtable for record encryption with CCM. + */ +extern const br_sslrec_out_ccm_class br_sslrec_out_ccm_vtable; + +/* ===================================================================== */ + +/** + * \brief Type for session parameters, to be saved for session resumption. + */ +typedef struct { + /** \brief Session ID buffer. */ + unsigned char session_id[32]; + /** \brief Session ID length (in bytes, at most 32). */ + unsigned char session_id_len; + /** \brief Protocol version. */ + uint16_t version; + /** \brief Cipher suite. */ + uint16_t cipher_suite; + /** \brief Master secret. */ + unsigned char master_secret[48]; +} br_ssl_session_parameters; + +#ifndef BR_DOXYGEN_IGNORE +/* + * Maximum number of cipher suites supported by a client or server. + */ +#define BR_MAX_CIPHER_SUITES 48 +#endif + +/** + * \brief Context structure for SSL engine. + * + * This strucuture is common to the client and server; both the client + * context (`br_ssl_client_context`) and the server context + * (`br_ssl_server_context`) include a `br_ssl_engine_context` as their + * first field. + * + * The engine context manages records, including alerts, closures, and + * transitions to new encryption/MAC algorithms. Processing of handshake + * records is delegated to externally provided code. This structure + * should not be used directly. + * + * Structure contents are opaque and shall not be accessed directly. + */ +typedef struct { +#ifndef BR_DOXYGEN_IGNORE + /* + * The error code. When non-zero, then the state is "failed" and + * no I/O may occur until reset. + */ + int err; + + /* + * Configured I/O buffers. They are either disjoint, or identical. + */ + unsigned char *ibuf, *obuf; + size_t ibuf_len, obuf_len; + + /* + * Maximum fragment length applies to outgoing records; incoming + * records can be processed as long as they fit in the input + * buffer. It is guaranteed that incoming records at least as big + * as max_frag_len can be processed. + */ + uint16_t max_frag_len; + unsigned char log_max_frag_len; + unsigned char max_frag_len_negotiated; + unsigned char peer_log_max_frag_len; + + /* + * Buffering management registers. + */ + size_t ixa, ixb, ixc; + size_t oxa, oxb, oxc; + unsigned char iomode; + unsigned char incrypt; + + /* + * Shutdown flag: when set to non-zero, incoming record bytes + * will not be accepted anymore. This is used after a close_notify + * has been received: afterwards, the engine no longer claims that + * it could receive bytes from the transport medium. + */ + unsigned char shutdown_recv; + + /* + * 'record_type_in' is set to the incoming record type when the + * record header has been received. + * 'record_type_out' is used to make the next outgoing record + * header when it is ready to go. + */ + unsigned char record_type_in, record_type_out; + + /* + * When a record is received, its version is extracted: + * -- if 'version_in' is 0, then it is set to the received version; + * -- otherwise, if the received version is not identical to + * the 'version_in' contents, then a failure is reported. + * + * This implements the SSL requirement that all records shall + * use the negotiated protocol version, once decided (in the + * ServerHello). It is up to the handshake handler to adjust this + * field when necessary. + */ + uint16_t version_in; + + /* + * 'version_out' is used when the next outgoing record is ready + * to go. + */ + uint16_t version_out; + + /* + * Record handler contexts. + */ + union { + const br_sslrec_in_class *vtable; + br_sslrec_in_cbc_context cbc; + br_sslrec_gcm_context gcm; + br_sslrec_chapol_context chapol; + br_sslrec_ccm_context ccm; + } in; + union { + const br_sslrec_out_class *vtable; + br_sslrec_out_clear_context clear; + br_sslrec_out_cbc_context cbc; + br_sslrec_gcm_context gcm; + br_sslrec_chapol_context chapol; + br_sslrec_ccm_context ccm; + } out; + + /* + * The "application data" flag. Value: + * 0 handshake is in process, no application data acceptable + * 1 application data can be sent and received + * 2 closing, no application data can be sent, but some + * can still be received (and discarded) + */ + unsigned char application_data; + + /* + * Context RNG. + * + * rng_init_done is initially 0. It is set to 1 when the + * basic structure of the RNG is set, and 2 when some + * entropy has been pushed in. The value 2 marks the RNG + * as "properly seeded". + * + * rng_os_rand_done is initially 0. It is set to 1 when + * some seeding from the OS or hardware has been attempted. + */ + br_hmac_drbg_context rng; + int rng_init_done; + int rng_os_rand_done; + + /* + * Supported minimum and maximum versions, and cipher suites. + */ + uint16_t version_min; + uint16_t version_max; + uint16_t suites_buf[BR_MAX_CIPHER_SUITES]; + unsigned char suites_num; + + /* + * For clients, the server name to send as a SNI extension. For + * servers, the name received in the SNI extension (if any). + */ + char server_name[256]; + + /* + * "Security parameters". These are filled by the handshake + * handler, and used when switching encryption state. + */ + unsigned char client_random[32]; + unsigned char server_random[32]; + br_ssl_session_parameters session; + + /* + * ECDHE elements: curve and point from the peer. The server also + * uses that buffer for the point to send to the client. + */ + unsigned char ecdhe_curve; + unsigned char ecdhe_point[133]; + unsigned char ecdhe_point_len; + + /* + * Secure renegotiation (RFC 5746): 'reneg' can be: + * 0 first handshake (server support is not known) + * 1 peer does not support secure renegotiation + * 2 peer supports secure renegotiation + * + * The saved_finished buffer contains the client and the + * server "Finished" values from the last handshake, in + * that order (12 bytes each). + */ + unsigned char reneg; + unsigned char saved_finished[24]; + + /* + * Behavioural flags. + */ + uint32_t flags; + + /* + * Context variables for the handshake processor. The 'pad' must + * be large enough to accommodate an RSA-encrypted pre-master + * secret, or an RSA signature; since we want to support up to + * RSA-4096, this means at least 512 bytes. (Other pad usages + * require its length to be at least 256.) + */ + struct { + uint32_t *dp; + uint32_t *rp; + const unsigned char *ip; + } cpu; + uint32_t dp_stack[32]; + uint32_t rp_stack[32]; + unsigned char pad[512]; + unsigned char *hbuf_in, *hbuf_out, *saved_hbuf_out; + size_t hlen_in, hlen_out; + void (*hsrun)(void *ctx); + + /* + * The 'action' value communicates OOB information between the + * engine and the handshake processor. + * + * From the engine: + * 0 invocation triggered by I/O + * 1 invocation triggered by explicit close + * 2 invocation triggered by explicit renegotiation + */ + unsigned char action; + + /* + * State for alert messages. Value is either 0, or the value of + * the alert level byte (level is either 1 for warning, or 2 for + * fatal; we convert all other values to 'fatal'). + */ + unsigned char alert; + + /* + * Closure flags. This flag is set when a close_notify has been + * received from the peer. + */ + unsigned char close_received; + + /* + * Multi-hasher for the handshake messages. The handshake handler + * is responsible for resetting it when appropriate. + */ + br_multihash_context mhash; + + /* + * Pointer to the X.509 engine. The engine is supposed to be + * already initialized. It is used to validate the peer's + * certificate. + */ + const br_x509_class **x509ctx; + + /* + * Certificate chain to send. This is used by both client and + * server, when they send their respective Certificate messages. + * If chain_len is 0, then chain may be NULL. + */ + const br_x509_certificate *chain; + size_t chain_len; + const unsigned char *cert_cur; + size_t cert_len; + + /* + * List of supported protocol names (ALPN extension). If unset, + * (number of names is 0), then: + * - the client sends no ALPN extension; + * - the server ignores any incoming ALPN extension. + * + * Otherwise: + * - the client sends an ALPN extension with all the names; + * - the server selects the first protocol in its list that + * the client also supports, or fails (fatal alert 120) + * if the client sends an ALPN extension and there is no + * match. + * + * The 'selected_protocol' field contains 1+n if the matching + * name has index n in the list (the value is 0 if no match was + * performed, e.g. the peer did not send an ALPN extension). + */ + const char **protocol_names; + uint16_t protocol_names_num; + uint16_t selected_protocol; + + /* + * Pointers to implementations; left to NULL for unsupported + * functions. For the raw hash functions, implementations are + * referenced from the multihasher (mhash field). + */ + br_tls_prf_impl prf10; + br_tls_prf_impl prf_sha256; + br_tls_prf_impl prf_sha384; + const br_block_cbcenc_class *iaes_cbcenc; + const br_block_cbcdec_class *iaes_cbcdec; + const br_block_ctr_class *iaes_ctr; + const br_block_ctrcbc_class *iaes_ctrcbc; + const br_block_cbcenc_class *ides_cbcenc; + const br_block_cbcdec_class *ides_cbcdec; + br_ghash ighash; + br_chacha20_run ichacha; + br_poly1305_run ipoly; + const br_sslrec_in_cbc_class *icbc_in; + const br_sslrec_out_cbc_class *icbc_out; + const br_sslrec_in_gcm_class *igcm_in; + const br_sslrec_out_gcm_class *igcm_out; + const br_sslrec_in_chapol_class *ichapol_in; + const br_sslrec_out_chapol_class *ichapol_out; + const br_sslrec_in_ccm_class *iccm_in; + const br_sslrec_out_ccm_class *iccm_out; + const br_ec_impl *iec; + br_rsa_pkcs1_vrfy irsavrfy; + br_ecdsa_vrfy iecdsa; +#endif +} br_ssl_engine_context; + +/** + * \brief Get currently defined engine behavioural flags. + * + * \param cc SSL engine context. + * \return the flags. + */ +static inline uint32_t +br_ssl_engine_get_flags(br_ssl_engine_context *cc) +{ + return cc->flags; +} + +/** + * \brief Set all engine behavioural flags. + * + * \param cc SSL engine context. + * \param flags new value for all flags. + */ +static inline void +br_ssl_engine_set_all_flags(br_ssl_engine_context *cc, uint32_t flags) +{ + cc->flags = flags; +} + +/** + * \brief Set some engine behavioural flags. + * + * The flags set in the `flags` parameter are set in the context; other + * flags are untouched. + * + * \param cc SSL engine context. + * \param flags additional set flags. + */ +static inline void +br_ssl_engine_add_flags(br_ssl_engine_context *cc, uint32_t flags) +{ + cc->flags |= flags; +} + +/** + * \brief Clear some engine behavioural flags. + * + * The flags set in the `flags` parameter are cleared from the context; other + * flags are untouched. + * + * \param cc SSL engine context. + * \param flags flags to remove. + */ +static inline void +br_ssl_engine_remove_flags(br_ssl_engine_context *cc, uint32_t flags) +{ + cc->flags &= ~flags; +} + +/** + * \brief Behavioural flag: enforce server preferences. + * + * If this flag is set, then the server will enforce its own cipher suite + * preference order; otherwise, it follows the client preferences. + */ +#define BR_OPT_ENFORCE_SERVER_PREFERENCES ((uint32_t)1 << 0) + +/** + * \brief Behavioural flag: disable renegotiation. + * + * If this flag is set, then renegotiations are rejected unconditionally: + * they won't be honoured if asked for programmatically, and requests from + * the peer are rejected. + */ +#define BR_OPT_NO_RENEGOTIATION ((uint32_t)1 << 1) + +/** + * \brief Behavioural flag: tolerate lack of client authentication. + * + * If this flag is set in a server and the server requests a client + * certificate, but the authentication fails (the client does not send + * a certificate, or the client's certificate chain cannot be validated), + * then the connection keeps on. Without this flag, a failed client + * authentication terminates the connection. + * + * Notes: + * + * - If the client's certificate can be validated and its public key is + * supported, then a wrong signature value terminates the connection + * regardless of that flag. + * + * - If using full-static ECDH, then a failure to validate the client's + * certificate prevents the handshake from succeeding. + */ +#define BR_OPT_TOLERATE_NO_CLIENT_AUTH ((uint32_t)1 << 2) + +/** + * \brief Behavioural flag: fail on application protocol mismatch. + * + * The ALPN extension ([RFC 7301](https://tools.ietf.org/html/rfc7301)) + * allows the client to send a list of application protocol names, and + * the server to select one. A mismatch is one of the following occurrences: + * + * - On the client: the client sends a list of names, the server + * responds with a protocol name which is _not_ part of the list of + * names sent by the client. + * + * - On the server: the client sends a list of names, and the server + * is also configured with a list of names, but there is no common + * protocol name between the two lists. + * + * Normal behaviour in case of mismatch is to report no matching name + * (`br_ssl_engine_get_selected_protocol()` returns `NULL`) and carry on. + * If the flag is set, then a mismatch implies a protocol failure (if + * the mismatch is detected by the server, it will send a fatal alert). + * + * Note: even with this flag, `br_ssl_engine_get_selected_protocol()` + * may still return `NULL` if the client or the server does not send an + * ALPN extension at all. + */ +#define BR_OPT_FAIL_ON_ALPN_MISMATCH ((uint32_t)1 << 3) + +/** + * \brief Set the minimum and maximum supported protocol versions. + * + * The two provided versions MUST be supported by the implementation + * (i.e. TLS 1.0, 1.1 and 1.2), and `version_max` MUST NOT be lower + * than `version_min`. + * + * \param cc SSL engine context. + * \param version_min minimum supported TLS version. + * \param version_max maximum supported TLS version. + */ +static inline void +br_ssl_engine_set_versions(br_ssl_engine_context *cc, + unsigned version_min, unsigned version_max) +{ + cc->version_min = (uint16_t)version_min; + cc->version_max = (uint16_t)version_max; +} + +/** + * \brief Set the list of cipher suites advertised by this context. + * + * The provided array is copied into the context. It is the caller + * responsibility to ensure that all provided suites will be supported + * by the context. The engine context has enough room to receive _all_ + * suites supported by the implementation. The provided array MUST NOT + * contain duplicates. + * + * If the engine is for a client, the "signaling" pseudo-cipher suite + * `TLS_FALLBACK_SCSV` can be added at the end of the list, if the + * calling application is performing a voluntary downgrade (voluntary + * downgrades are not recommended, but if such a downgrade is done, then + * adding the fallback pseudo-suite is a good idea). + * + * \param cc SSL engine context. + * \param suites cipher suites. + * \param suites_num number of cipher suites. + */ +void br_ssl_engine_set_suites(br_ssl_engine_context *cc, + const uint16_t *suites, size_t suites_num); + +/** + * \brief Set the X.509 engine. + * + * The caller shall ensure that the X.509 engine is properly initialised. + * + * \param cc SSL engine context. + * \param x509ctx X.509 certificate validation context. + */ +static inline void +br_ssl_engine_set_x509(br_ssl_engine_context *cc, const br_x509_class **x509ctx) +{ + cc->x509ctx = x509ctx; +} + +/** + * \brief Set the supported protocol names. + * + * Protocol names are part of the ALPN extension ([RFC + * 7301](https://tools.ietf.org/html/rfc7301)). Each protocol name is a + * character string, containing no more than 255 characters (256 with the + * terminating zero). When names are set, then: + * + * - The client will send an ALPN extension, containing the names. If + * the server responds with an ALPN extension, the client will verify + * that the response contains one of its name, and report that name + * through `br_ssl_engine_get_selected_protocol()`. + * + * - The server will parse incoming ALPN extension (from clients), and + * try to find a common protocol; if none is found, the connection + * is aborted with a fatal alert. On match, a response ALPN extension + * is sent, and name is reported through + * `br_ssl_engine_get_selected_protocol()`. + * + * The provided array is linked in, and must remain valid while the + * connection is live. + * + * Names MUST NOT be empty. Names MUST NOT be longer than 255 characters + * (excluding the terminating 0). + * + * \param ctx SSL engine context. + * \param names list of protocol names (zero-terminated). + * \param num number of protocol names (MUST be 1 or more). + */ +static inline void +br_ssl_engine_set_protocol_names(br_ssl_engine_context *ctx, + const char **names, size_t num) +{ + ctx->protocol_names = names; + ctx->protocol_names_num = (uint16_t)num; +} + +/** + * \brief Get the selected protocol. + * + * If this context was initialised with a non-empty list of protocol + * names, and both client and server sent ALPN extensions during the + * handshake, and a common name was found, then that name is returned. + * Otherwise, `NULL` is returned. + * + * The returned pointer is one of the pointers provided to the context + * with `br_ssl_engine_set_protocol_names()`. + * + * \return the selected protocol, or `NULL`. + */ +static inline const char * +br_ssl_engine_get_selected_protocol(br_ssl_engine_context *ctx) +{ + unsigned k; + + k = ctx->selected_protocol; + return (k == 0 || k == 0xFFFF) ? NULL : ctx->protocol_names[k - 1]; +} + +/** + * \brief Set a hash function implementation (by ID). + * + * Hash functions set with this call will be used for SSL/TLS specific + * usages, not X.509 certificate validation. Only "standard" hash functions + * may be set (MD5, SHA-1, SHA-224, SHA-256, SHA-384, SHA-512). If `impl` + * is `NULL`, then the hash function support is removed, not added. + * + * \param ctx SSL engine context. + * \param id hash function identifier. + * \param impl hash function implementation (or `NULL`). + */ +static inline void +br_ssl_engine_set_hash(br_ssl_engine_context *ctx, + int id, const br_hash_class *impl) +{ + br_multihash_setimpl(&ctx->mhash, id, impl); +} + +/** + * \brief Get a hash function implementation (by ID). + * + * This function retrieves a hash function implementation which was + * set with `br_ssl_engine_set_hash()`. + * + * \param ctx SSL engine context. + * \param id hash function identifier. + * \return the hash function implementation (or `NULL`). + */ +static inline const br_hash_class * +br_ssl_engine_get_hash(br_ssl_engine_context *ctx, int id) +{ + return br_multihash_getimpl(&ctx->mhash, id); +} + +/** + * \brief Set the PRF implementation (for TLS 1.0 and 1.1). + * + * This function sets (or removes, if `impl` is `NULL`) the implementation + * for the PRF used in TLS 1.0 and 1.1. + * + * \param cc SSL engine context. + * \param impl PRF implementation (or `NULL`). + */ +static inline void +br_ssl_engine_set_prf10(br_ssl_engine_context *cc, br_tls_prf_impl impl) +{ + cc->prf10 = impl; +} + +/** + * \brief Set the PRF implementation with SHA-256 (for TLS 1.2). + * + * This function sets (or removes, if `impl` is `NULL`) the implementation + * for the SHA-256 variant of the PRF used in TLS 1.2. + * + * \param cc SSL engine context. + * \param impl PRF implementation (or `NULL`). + */ +static inline void +br_ssl_engine_set_prf_sha256(br_ssl_engine_context *cc, br_tls_prf_impl impl) +{ + cc->prf_sha256 = impl; +} + +/** + * \brief Set the PRF implementation with SHA-384 (for TLS 1.2). + * + * This function sets (or removes, if `impl` is `NULL`) the implementation + * for the SHA-384 variant of the PRF used in TLS 1.2. + * + * \param cc SSL engine context. + * \param impl PRF implementation (or `NULL`). + */ +static inline void +br_ssl_engine_set_prf_sha384(br_ssl_engine_context *cc, br_tls_prf_impl impl) +{ + cc->prf_sha384 = impl; +} + +/** + * \brief Set the AES/CBC implementations. + * + * \param cc SSL engine context. + * \param impl_enc AES/CBC encryption implementation (or `NULL`). + * \param impl_dec AES/CBC decryption implementation (or `NULL`). + */ +static inline void +br_ssl_engine_set_aes_cbc(br_ssl_engine_context *cc, + const br_block_cbcenc_class *impl_enc, + const br_block_cbcdec_class *impl_dec) +{ + cc->iaes_cbcenc = impl_enc; + cc->iaes_cbcdec = impl_dec; +} + +/** + * \brief Set the "default" AES/CBC implementations. + * + * This function configures in the engine the AES implementations that + * should provide best runtime performance on the local system, while + * still being safe (in particular, constant-time). It also sets the + * handlers for CBC records. + * + * \param cc SSL engine context. + */ +void br_ssl_engine_set_default_aes_cbc(br_ssl_engine_context *cc); + +/** + * \brief Set the AES/CTR implementation. + * + * \param cc SSL engine context. + * \param impl AES/CTR encryption/decryption implementation (or `NULL`). + */ +static inline void +br_ssl_engine_set_aes_ctr(br_ssl_engine_context *cc, + const br_block_ctr_class *impl) +{ + cc->iaes_ctr = impl; +} + +/** + * \brief Set the "default" implementations for AES/GCM (AES/CTR + GHASH). + * + * This function configures in the engine the AES/CTR and GHASH + * implementation that should provide best runtime performance on the local + * system, while still being safe (in particular, constant-time). It also + * sets the handlers for GCM records. + * + * \param cc SSL engine context. + */ +void br_ssl_engine_set_default_aes_gcm(br_ssl_engine_context *cc); + +/** + * \brief Set the DES/CBC implementations. + * + * \param cc SSL engine context. + * \param impl_enc DES/CBC encryption implementation (or `NULL`). + * \param impl_dec DES/CBC decryption implementation (or `NULL`). + */ +static inline void +br_ssl_engine_set_des_cbc(br_ssl_engine_context *cc, + const br_block_cbcenc_class *impl_enc, + const br_block_cbcdec_class *impl_dec) +{ + cc->ides_cbcenc = impl_enc; + cc->ides_cbcdec = impl_dec; +} + +/** + * \brief Set the "default" DES/CBC implementations. + * + * This function configures in the engine the DES implementations that + * should provide best runtime performance on the local system, while + * still being safe (in particular, constant-time). It also sets the + * handlers for CBC records. + * + * \param cc SSL engine context. + */ +void br_ssl_engine_set_default_des_cbc(br_ssl_engine_context *cc); + +/** + * \brief Set the GHASH implementation (used in GCM mode). + * + * \param cc SSL engine context. + * \param impl GHASH implementation (or `NULL`). + */ +static inline void +br_ssl_engine_set_ghash(br_ssl_engine_context *cc, br_ghash impl) +{ + cc->ighash = impl; +} + +/** + * \brief Set the ChaCha20 implementation. + * + * \param cc SSL engine context. + * \param ichacha ChaCha20 implementation (or `NULL`). + */ +static inline void +br_ssl_engine_set_chacha20(br_ssl_engine_context *cc, + br_chacha20_run ichacha) +{ + cc->ichacha = ichacha; +} + +/** + * \brief Set the Poly1305 implementation. + * + * \param cc SSL engine context. + * \param ipoly Poly1305 implementation (or `NULL`). + */ +static inline void +br_ssl_engine_set_poly1305(br_ssl_engine_context *cc, + br_poly1305_run ipoly) +{ + cc->ipoly = ipoly; +} + +/** + * \brief Set the "default" ChaCha20 and Poly1305 implementations. + * + * This function configures in the engine the ChaCha20 and Poly1305 + * implementations that should provide best runtime performance on the + * local system, while still being safe (in particular, constant-time). + * It also sets the handlers for ChaCha20+Poly1305 records. + * + * \param cc SSL engine context. + */ +void br_ssl_engine_set_default_chapol(br_ssl_engine_context *cc); + +/** + * \brief Set the AES/CTR+CBC implementation. + * + * \param cc SSL engine context. + * \param impl AES/CTR+CBC encryption/decryption implementation (or `NULL`). + */ +static inline void +br_ssl_engine_set_aes_ctrcbc(br_ssl_engine_context *cc, + const br_block_ctrcbc_class *impl) +{ + cc->iaes_ctrcbc = impl; +} + +/** + * \brief Set the "default" implementations for AES/CCM. + * + * This function configures in the engine the AES/CTR+CBC + * implementation that should provide best runtime performance on the local + * system, while still being safe (in particular, constant-time). It also + * sets the handlers for CCM records. + * + * \param cc SSL engine context. + */ +void br_ssl_engine_set_default_aes_ccm(br_ssl_engine_context *cc); + +/** + * \brief Set the record encryption and decryption engines for CBC + HMAC. + * + * \param cc SSL engine context. + * \param impl_in record CBC decryption implementation (or `NULL`). + * \param impl_out record CBC encryption implementation (or `NULL`). + */ +static inline void +br_ssl_engine_set_cbc(br_ssl_engine_context *cc, + const br_sslrec_in_cbc_class *impl_in, + const br_sslrec_out_cbc_class *impl_out) +{ + cc->icbc_in = impl_in; + cc->icbc_out = impl_out; +} + +/** + * \brief Set the record encryption and decryption engines for GCM. + * + * \param cc SSL engine context. + * \param impl_in record GCM decryption implementation (or `NULL`). + * \param impl_out record GCM encryption implementation (or `NULL`). + */ +static inline void +br_ssl_engine_set_gcm(br_ssl_engine_context *cc, + const br_sslrec_in_gcm_class *impl_in, + const br_sslrec_out_gcm_class *impl_out) +{ + cc->igcm_in = impl_in; + cc->igcm_out = impl_out; +} + +/** + * \brief Set the record encryption and decryption engines for CCM. + * + * \param cc SSL engine context. + * \param impl_in record CCM decryption implementation (or `NULL`). + * \param impl_out record CCM encryption implementation (or `NULL`). + */ +static inline void +br_ssl_engine_set_ccm(br_ssl_engine_context *cc, + const br_sslrec_in_ccm_class *impl_in, + const br_sslrec_out_ccm_class *impl_out) +{ + cc->iccm_in = impl_in; + cc->iccm_out = impl_out; +} + +/** + * \brief Set the record encryption and decryption engines for + * ChaCha20+Poly1305. + * + * \param cc SSL engine context. + * \param impl_in record ChaCha20 decryption implementation (or `NULL`). + * \param impl_out record ChaCha20 encryption implementation (or `NULL`). + */ +static inline void +br_ssl_engine_set_chapol(br_ssl_engine_context *cc, + const br_sslrec_in_chapol_class *impl_in, + const br_sslrec_out_chapol_class *impl_out) +{ + cc->ichapol_in = impl_in; + cc->ichapol_out = impl_out; +} + +/** + * \brief Set the EC implementation. + * + * The elliptic curve implementation will be used for ECDH and ECDHE + * cipher suites, and for ECDSA support. + * + * \param cc SSL engine context. + * \param iec EC implementation (or `NULL`). + */ +static inline void +br_ssl_engine_set_ec(br_ssl_engine_context *cc, const br_ec_impl *iec) +{ + cc->iec = iec; +} + +/** + * \brief Set the "default" EC implementation. + * + * This function sets the elliptic curve implementation for ECDH and + * ECDHE cipher suites, and for ECDSA support. It selects the fastest + * implementation on the current system. + * + * \param cc SSL engine context. + */ +void br_ssl_engine_set_default_ec(br_ssl_engine_context *cc); + +/** + * \brief Get the EC implementation configured in the provided engine. + * + * \param cc SSL engine context. + * \return the EC implementation. + */ +static inline const br_ec_impl * +br_ssl_engine_get_ec(br_ssl_engine_context *cc) +{ + return cc->iec; +} + +/** + * \brief Set the RSA signature verification implementation. + * + * On the client, this is used to verify the server's signature on its + * ServerKeyExchange message (for ECDHE_RSA cipher suites). On the server, + * this is used to verify the client's CertificateVerify message (if a + * client certificate is requested, and that certificate contains a RSA key). + * + * \param cc SSL engine context. + * \param irsavrfy RSA signature verification implementation. + */ +static inline void +br_ssl_engine_set_rsavrfy(br_ssl_engine_context *cc, br_rsa_pkcs1_vrfy irsavrfy) +{ + cc->irsavrfy = irsavrfy; +} + +/** + * \brief Set the "default" RSA implementation (signature verification). + * + * This function sets the RSA implementation (signature verification) + * to the fastest implementation available on the current platform. + * + * \param cc SSL engine context. + */ +void br_ssl_engine_set_default_rsavrfy(br_ssl_engine_context *cc); + +/** + * \brief Get the RSA implementation (signature verification) configured + * in the provided engine. + * + * \param cc SSL engine context. + * \return the RSA signature verification implementation. + */ +static inline br_rsa_pkcs1_vrfy +br_ssl_engine_get_rsavrfy(br_ssl_engine_context *cc) +{ + return cc->irsavrfy; +} + +/* + * \brief Set the ECDSA implementation (signature verification). + * + * On the client, this is used to verify the server's signature on its + * ServerKeyExchange message (for ECDHE_ECDSA cipher suites). On the server, + * this is used to verify the client's CertificateVerify message (if a + * client certificate is requested, that certificate contains an EC key, + * and full-static ECDH is not used). + * + * The ECDSA implementation will use the EC core implementation configured + * in the engine context. + * + * \param cc client context. + * \param iecdsa ECDSA verification implementation. + */ +static inline void +br_ssl_engine_set_ecdsa(br_ssl_engine_context *cc, br_ecdsa_vrfy iecdsa) +{ + cc->iecdsa = iecdsa; +} + +/** + * \brief Set the "default" ECDSA implementation (signature verification). + * + * This function sets the ECDSA implementation (signature verification) + * to the fastest implementation available on the current platform. This + * call also sets the elliptic curve implementation itself, there again + * to the fastest EC implementation available. + * + * \param cc SSL engine context. + */ +void br_ssl_engine_set_default_ecdsa(br_ssl_engine_context *cc); + +/** + * \brief Get the ECDSA implementation (signature verification) configured + * in the provided engine. + * + * \param cc SSL engine context. + * \return the ECDSA signature verification implementation. + */ +static inline br_ecdsa_vrfy +br_ssl_engine_get_ecdsa(br_ssl_engine_context *cc) +{ + return cc->iecdsa; +} + +/** + * \brief Set the I/O buffer for the SSL engine. + * + * Once this call has been made, `br_ssl_client_reset()` or + * `br_ssl_server_reset()` MUST be called before using the context. + * + * The provided buffer will be used as long as the engine context is + * used. The caller is responsible for keeping it available. + * + * If `bidi` is 0, then the engine will operate in half-duplex mode + * (it won't be able to send data while there is unprocessed incoming + * data in the buffer, and it won't be able to receive data while there + * is unsent data in the buffer). The optimal buffer size in half-duplex + * mode is `BR_SSL_BUFSIZE_MONO`; if the buffer is larger, then extra + * bytes are ignored. If the buffer is smaller, then this limits the + * capacity of the engine to support all allowed record sizes. + * + * If `bidi` is 1, then the engine will split the buffer into two + * parts, for separate handling of outgoing and incoming data. This + * enables full-duplex processing, but requires more RAM. The optimal + * buffer size in full-duplex mode is `BR_SSL_BUFSIZE_BIDI`; if the + * buffer is larger, then extra bytes are ignored. If the buffer is + * smaller, then the split will favour the incoming part, so that + * interoperability is maximised. + * + * \param cc SSL engine context + * \param iobuf I/O buffer. + * \param iobuf_len I/O buffer length (in bytes). + * \param bidi non-zero for full-duplex mode. + */ +void br_ssl_engine_set_buffer(br_ssl_engine_context *cc, + void *iobuf, size_t iobuf_len, int bidi); + +/** + * \brief Set the I/O buffers for the SSL engine. + * + * Once this call has been made, `br_ssl_client_reset()` or + * `br_ssl_server_reset()` MUST be called before using the context. + * + * This function is similar to `br_ssl_engine_set_buffer()`, except + * that it enforces full-duplex mode, and the two I/O buffers are + * provided as separate chunks. + * + * The macros `BR_SSL_BUFSIZE_INPUT` and `BR_SSL_BUFSIZE_OUTPUT` + * evaluate to the optimal (maximum) sizes for the input and output + * buffer, respectively. + * + * \param cc SSL engine context + * \param ibuf input buffer. + * \param ibuf_len input buffer length (in bytes). + * \param obuf output buffer. + * \param obuf_len output buffer length (in bytes). + */ +void br_ssl_engine_set_buffers_bidi(br_ssl_engine_context *cc, + void *ibuf, size_t ibuf_len, void *obuf, size_t obuf_len); + +/** + * \brief Determine if MFLN negotiation was successful + * + * \param cc SSL engine context. + */ +static inline uint8_t +br_ssl_engine_get_mfln_negotiated(br_ssl_engine_context *cc) +{ + return cc->max_frag_len_negotiated; +} + +/** + * \brief Inject some "initial entropy" in the context. + * + * This entropy will be added to what can be obtained from the + * underlying operating system, if that OS is supported. + * + * This function may be called several times; all injected entropy chunks + * are cumulatively mixed. + * + * If entropy gathering from the OS is supported and compiled in, then this + * step is optional. Otherwise, it is mandatory to inject randomness, and + * the caller MUST take care to push (as one or several successive calls) + * enough entropy to achieve cryptographic resistance (at least 80 bits, + * preferably 128 or more). The engine will report an error if no entropy + * was provided and none can be obtained from the OS. + * + * Take care that this function cannot assess the cryptographic quality of + * the provided bytes. + * + * In all generality, "entropy" must here be considered to mean "that + * which the attacker cannot predict". If your OS/architecture does not + * have a suitable source of randomness, then you can make do with the + * combination of a large enough secret value (possibly a copy of an + * asymmetric private key that you also store on the system) AND a + * non-repeating value (e.g. current time, provided that the local clock + * cannot be reset or altered by the attacker). + * + * \param cc SSL engine context. + * \param data extra entropy to inject. + * \param len length of the extra data (in bytes). + */ +void br_ssl_engine_inject_entropy(br_ssl_engine_context *cc, + const void *data, size_t len); + +/** + * \brief Get the "server name" in this engine. + * + * For clients, this is the name provided with `br_ssl_client_reset()`; + * for servers, this is the name received from the client as part of the + * ClientHello message. If there is no such name (e.g. the client did + * not send an SNI extension) then the returned string is empty + * (returned pointer points to a byte of value 0). + * + * The returned pointer refers to a buffer inside the context, which may + * be overwritten as part of normal SSL activity (even within the same + * connection, if a renegotiation occurs). + * + * \param cc SSL engine context. + * \return the server name (possibly empty). + */ +static inline const char * +br_ssl_engine_get_server_name(const br_ssl_engine_context *cc) +{ + return cc->server_name; +} + +/** + * \brief Get the protocol version. + * + * This function returns the protocol version that is used by the + * engine. That value is set after sending (for a server) or receiving + * (for a client) the ServerHello message. + * + * \param cc SSL engine context. + * \return the protocol version. + */ +static inline unsigned +br_ssl_engine_get_version(const br_ssl_engine_context *cc) +{ + return cc->session.version; +} + +/** + * \brief Get a copy of the session parameters. + * + * The session parameters are filled during the handshake, so this + * function shall not be called before completion of the handshake. + * The initial handshake is completed when the context first allows + * application data to be injected. + * + * This function copies the current session parameters into the provided + * structure. Beware that the session parameters include the master + * secret, which is sensitive data, to handle with great care. + * + * \param cc SSL engine context. + * \param pp destination structure for the session parameters. + */ +static inline void +br_ssl_engine_get_session_parameters(const br_ssl_engine_context *cc, + br_ssl_session_parameters *pp) +{ + memcpy(pp, &cc->session, sizeof *pp); +} + +/** + * \brief Set the session parameters to the provided values. + * + * This function is meant to be used in the client, before doing a new + * handshake; a session resumption will be attempted with these + * parameters. In the server, this function has no effect. + * + * \param cc SSL engine context. + * \param pp source structure for the session parameters. + */ +static inline void +br_ssl_engine_set_session_parameters(br_ssl_engine_context *cc, + const br_ssl_session_parameters *pp) +{ + memcpy(&cc->session, pp, sizeof *pp); +} + +/** + * \brief Get identifier for the curve used for key exchange. + * + * If the cipher suite uses ECDHE, then this function returns the + * identifier for the curve used for transient parameters. This is + * defined during the course of the handshake, when the ServerKeyExchange + * is sent (on the server) or received (on the client). If the + * cipher suite does not use ECDHE (e.g. static ECDH, or RSA key + * exchange), then this value is indeterminate. + * + * @param cc SSL engine context. + * @return the ECDHE curve identifier. + */ +static inline int +br_ssl_engine_get_ecdhe_curve(br_ssl_engine_context *cc) +{ + return cc->ecdhe_curve; +} + +/** + * \brief Get the current engine state. + * + * An SSL engine (client or server) has, at any time, a state which is + * the combination of zero, one or more of these flags: + * + * - `BR_SSL_CLOSED` + * + * Engine is finished, no more I/O (until next reset). + * + * - `BR_SSL_SENDREC` + * + * Engine has some bytes to send to the peer. + * + * - `BR_SSL_RECVREC` + * + * Engine expects some bytes from the peer. + * + * - `BR_SSL_SENDAPP` + * + * Engine may receive application data to send (or flush). + * + * - `BR_SSL_RECVAPP` + * + * Engine has obtained some application data from the peer, + * that should be read by the caller. + * + * If no flag at all is set (state value is 0), then the engine is not + * fully initialised yet. + * + * The `BR_SSL_CLOSED` flag is exclusive; when it is set, no other flag + * is set. To distinguish between a normal closure and an error, use + * `br_ssl_engine_last_error()`. + * + * Generally speaking, `BR_SSL_SENDREC` and `BR_SSL_SENDAPP` are mutually + * exclusive: the input buffer, at any point, either accumulates + * plaintext data, or contains an assembled record that is being sent. + * Similarly, `BR_SSL_RECVREC` and `BR_SSL_RECVAPP` are mutually exclusive. + * This may change in a future library version. + * + * \param cc SSL engine context. + * \return the current engine state. + */ +unsigned br_ssl_engine_current_state(const br_ssl_engine_context *cc); + +/** \brief SSL engine state: closed or failed. */ +#define BR_SSL_CLOSED 0x0001 +/** \brief SSL engine state: record data is ready to be sent to the peer. */ +#define BR_SSL_SENDREC 0x0002 +/** \brief SSL engine state: engine may receive records from the peer. */ +#define BR_SSL_RECVREC 0x0004 +/** \brief SSL engine state: engine may accept application data to send. */ +#define BR_SSL_SENDAPP 0x0008 +/** \brief SSL engine state: engine has received application data. */ +#define BR_SSL_RECVAPP 0x0010 + +/** + * \brief Get the engine error indicator. + * + * The error indicator is `BR_ERR_OK` (0) if no error was encountered + * since the last call to `br_ssl_client_reset()` or + * `br_ssl_server_reset()`. Other status values are "sticky": they + * remain set, and prevent all I/O activity, until cleared. Only the + * reset calls clear the error indicator. + * + * \param cc SSL engine context. + * \return 0, or a non-zero error code. + */ +static inline int +br_ssl_engine_last_error(const br_ssl_engine_context *cc) +{ + return cc->err; +} + +/* + * There are four I/O operations, each identified by a symbolic name: + * + * sendapp inject application data in the engine + * recvapp retrieving application data from the engine + * sendrec sending records on the transport medium + * recvrec receiving records from the transport medium + * + * Terminology works thus: in a layered model where the SSL engine sits + * between the application and the network, "send" designates operations + * where bytes flow from application to network, and "recv" for the + * reverse operation. Application data (the plaintext that is to be + * conveyed through SSL) is "app", while encrypted records are "rec". + * Note that from the SSL engine point of view, "sendapp" and "recvrec" + * designate bytes that enter the engine ("inject" operation), while + * "recvapp" and "sendrec" designate bytes that exit the engine + * ("extract" operation). + * + * For the operation 'xxx', two functions are defined: + * + * br_ssl_engine_xxx_buf + * Returns a pointer and length to the buffer to use for that + * operation. '*len' is set to the number of bytes that may be read + * from the buffer (extract operation) or written to the buffer + * (inject operation). If no byte may be exchanged for that operation + * at that point, then '*len' is set to zero, and NULL is returned. + * The engine state is unmodified by this call. + * + * br_ssl_engine_xxx_ack + * Informs the engine that 'len' bytes have been read from the buffer + * (extract operation) or written to the buffer (inject operation). + * The 'len' value MUST NOT be zero. The 'len' value MUST NOT exceed + * that which was obtained from a preceding br_ssl_engine_xxx_buf() + * call. + */ + +/** + * \brief Get buffer for application data to send. + * + * If the engine is ready to accept application data to send to the + * peer, then this call returns a pointer to the buffer where such + * data shall be written, and its length is written in `*len`. + * Otherwise, `*len` is set to 0 and `NULL` is returned. + * + * \param cc SSL engine context. + * \param len receives the application data output buffer length, or 0. + * \return the application data output buffer, or `NULL`. + */ +unsigned char *br_ssl_engine_sendapp_buf( + const br_ssl_engine_context *cc, size_t *len); + +/** + * \brief Inform the engine of some new application data. + * + * After writing `len` bytes in the buffer returned by + * `br_ssl_engine_sendapp_buf()`, the application shall call this + * function to trigger any relevant processing. The `len` parameter + * MUST NOT be 0, and MUST NOT exceed the value obtained in the + * `br_ssl_engine_sendapp_buf()` call. + * + * \param cc SSL engine context. + * \param len number of bytes pushed (not zero). + */ +void br_ssl_engine_sendapp_ack(br_ssl_engine_context *cc, size_t len); + +/** + * \brief Get buffer for received application data. + * + * If the engine has received application data from the peer, then this + * call returns a pointer to the buffer from where such data shall be + * read, and its length is written in `*len`. Otherwise, `*len` is set + * to 0 and `NULL` is returned. + * + * \param cc SSL engine context. + * \param len receives the application data input buffer length, or 0. + * \return the application data input buffer, or `NULL`. + */ +unsigned char *br_ssl_engine_recvapp_buf( + const br_ssl_engine_context *cc, size_t *len); + +/** + * \brief Acknowledge some received application data. + * + * After reading `len` bytes from the buffer returned by + * `br_ssl_engine_recvapp_buf()`, the application shall call this + * function to trigger any relevant processing. The `len` parameter + * MUST NOT be 0, and MUST NOT exceed the value obtained in the + * `br_ssl_engine_recvapp_buf()` call. + * + * \param cc SSL engine context. + * \param len number of bytes read (not zero). + */ +void br_ssl_engine_recvapp_ack(br_ssl_engine_context *cc, size_t len); + +/** + * \brief Get buffer for record data to send. + * + * If the engine has prepared some records to send to the peer, then this + * call returns a pointer to the buffer from where such data shall be + * read, and its length is written in `*len`. Otherwise, `*len` is set + * to 0 and `NULL` is returned. + * + * \param cc SSL engine context. + * \param len receives the record data output buffer length, or 0. + * \return the record data output buffer, or `NULL`. + */ +unsigned char *br_ssl_engine_sendrec_buf( + const br_ssl_engine_context *cc, size_t *len); + +/** + * \brief Acknowledge some sent record data. + * + * After reading `len` bytes from the buffer returned by + * `br_ssl_engine_sendrec_buf()`, the application shall call this + * function to trigger any relevant processing. The `len` parameter + * MUST NOT be 0, and MUST NOT exceed the value obtained in the + * `br_ssl_engine_sendrec_buf()` call. + * + * \param cc SSL engine context. + * \param len number of bytes read (not zero). + */ +void br_ssl_engine_sendrec_ack(br_ssl_engine_context *cc, size_t len); + +/** + * \brief Get buffer for incoming records. + * + * If the engine is ready to accept records from the peer, then this + * call returns a pointer to the buffer where such data shall be + * written, and its length is written in `*len`. Otherwise, `*len` is + * set to 0 and `NULL` is returned. + * + * \param cc SSL engine context. + * \param len receives the record data input buffer length, or 0. + * \return the record data input buffer, or `NULL`. + */ +unsigned char *br_ssl_engine_recvrec_buf( + const br_ssl_engine_context *cc, size_t *len); + +/** + * \brief Inform the engine of some new record data. + * + * After writing `len` bytes in the buffer returned by + * `br_ssl_engine_recvrec_buf()`, the application shall call this + * function to trigger any relevant processing. The `len` parameter + * MUST NOT be 0, and MUST NOT exceed the value obtained in the + * `br_ssl_engine_recvrec_buf()` call. + * + * \param cc SSL engine context. + * \param len number of bytes pushed (not zero). + */ +void br_ssl_engine_recvrec_ack(br_ssl_engine_context *cc, size_t len); + +/** + * \brief Flush buffered application data. + * + * If some application data has been buffered in the engine, then wrap + * it into a record and mark it for sending. If no application data has + * been buffered but the engine would be ready to accept some, AND the + * `force` parameter is non-zero, then an empty record is assembled and + * marked for sending. In all other cases, this function does nothing. + * + * Empty records are technically legal, but not all existing SSL/TLS + * implementations support them. Empty records can be useful as a + * transparent "keep-alive" mechanism to maintain some low-level + * network activity. + * + * \param cc SSL engine context. + * \param force non-zero to force sending an empty record. + */ +void br_ssl_engine_flush(br_ssl_engine_context *cc, int force); + +/** + * \brief Initiate a closure. + * + * If, at that point, the context is open and in ready state, then a + * `close_notify` alert is assembled and marked for sending; this + * triggers the closure protocol. Otherwise, no such alert is assembled. + * + * \param cc SSL engine context. + */ +void br_ssl_engine_close(br_ssl_engine_context *cc); + +/** + * \brief Initiate a renegotiation. + * + * If the engine is failed or closed, or if the peer is known not to + * support secure renegotiation (RFC 5746), or if renegotiations have + * been disabled with the `BR_OPT_NO_RENEGOTIATION` flag, or if there + * is buffered incoming application data, then this function returns 0 + * and nothing else happens. + * + * Otherwise, this function returns 1, and a renegotiation attempt is + * triggered (if a handshake is already ongoing at that point, then + * no new handshake is triggered). + * + * \param cc SSL engine context. + * \return 1 on success, 0 on error. + */ +int br_ssl_engine_renegotiate(br_ssl_engine_context *cc); + +/** + * \brief Export key material from a connected SSL engine (RFC 5705). + * + * This calls compute a secret key of arbitrary length from the master + * secret of a connected SSL engine. If the provided context is not + * currently in "application data" state (initial handshake is not + * finished, another handshake is ongoing, or the connection failed or + * was closed), then this function returns 0. Otherwise, a secret key of + * length `len` bytes is computed and written in the buffer pointed to + * by `dst`, and 1 is returned. + * + * The computed key follows the specification described in RFC 5705. + * That RFC includes two key computations, with and without a "context + * value". If `context` is `NULL`, then the variant without context is + * used; otherwise, the `context_len` bytes located at the address + * pointed to by `context` are used in the computation. Note that it + * is possible to have a "with context" key with a context length of + * zero bytes, by setting `context` to a non-`NULL` value but + * `context_len` to 0. + * + * When context bytes are used, the context length MUST NOT exceed + * 65535 bytes. + * + * \param cc SSL engine context. + * \param dst destination buffer for exported key. + * \param len exported key length (in bytes). + * \param label disambiguation label. + * \param context context value (or `NULL`). + * \param context_len context length (in bytes). + * \return 1 on success, 0 on error. + */ +int br_ssl_key_export(br_ssl_engine_context *cc, + void *dst, size_t len, const char *label, + const void *context, size_t context_len); + +/* + * Pre-declaration for the SSL client context. + */ +typedef struct br_ssl_client_context_ br_ssl_client_context; + +/** + * \brief Type for the client certificate, if requested by the server. + */ +typedef struct { + /** + * \brief Authentication type. + * + * This is either `BR_AUTH_RSA` (RSA signature), `BR_AUTH_ECDSA` + * (ECDSA signature), or `BR_AUTH_ECDH` (static ECDH key exchange). + */ + int auth_type; + + /** + * \brief Hash function for computing the CertificateVerify. + * + * This is the symbolic identifier for the hash function that + * will be used to produce the hash of handshake messages, to + * be signed into the CertificateVerify. For full static ECDH + * (client and server certificates are both EC in the same + * curve, and static ECDH is used), this value is set to -1. + * + * Take care that with TLS 1.0 and 1.1, that value MUST match + * the protocol requirements: value must be 0 (MD5+SHA-1) for + * a RSA signature, or 2 (SHA-1) for an ECDSA signature. Only + * TLS 1.2 allows for other hash functions. + */ + int hash_id; + + /** + * \brief Certificate chain to send to the server. + * + * This is an array of `br_x509_certificate` objects, each + * normally containing a DER-encoded certificate. The client + * code does not try to decode these elements. If there is no + * chain to send to the server, then this pointer shall be + * set to `NULL`. + */ + const br_x509_certificate *chain; + + /** + * \brief Certificate chain length (number of certificates). + * + * If there is no chain to send to the server, then this value + * shall be set to 0. + */ + size_t chain_len; + +} br_ssl_client_certificate; + +/* + * Note: the constants below for signatures match the TLS constants. + */ + +/** \brief Client authentication type: static ECDH. */ +#define BR_AUTH_ECDH 0 +/** \brief Client authentication type: RSA signature. */ +#define BR_AUTH_RSA 1 +/** \brief Client authentication type: ECDSA signature. */ +#define BR_AUTH_ECDSA 3 + +/** + * \brief Class type for a certificate handler (client side). + * + * A certificate handler selects a client certificate chain to send to + * the server, upon explicit request from that server. It receives + * the list of trust anchor DN from the server, and supported types + * of certificates and signatures, and returns the chain to use. It + * is also invoked to perform the corresponding private key operation + * (a signature, or an ECDH computation). + * + * The SSL client engine will first push the trust anchor DN with + * `start_name_list()`, `start_name()`, `append_name()`, `end_name()` + * and `end_name_list()`. Then it will call `choose()`, to select the + * actual chain (and signature/hash algorithms). Finally, it will call + * either `do_sign()` or `do_keyx()`, depending on the algorithm choices. + */ +typedef struct br_ssl_client_certificate_class_ br_ssl_client_certificate_class; +struct br_ssl_client_certificate_class_ { + /** + * \brief Context size (in bytes). + */ + size_t context_size; + + /** + * \brief Begin reception of a list of trust anchor names. This + * is called while parsing the incoming CertificateRequest. + * + * \param pctx certificate handler context. + */ + void (*start_name_list)(const br_ssl_client_certificate_class **pctx); + + /** + * \brief Begin reception of a new trust anchor name. + * + * The total encoded name length is provided; it is less than + * 65535 bytes. + * + * \param pctx certificate handler context. + * \param len encoded name length (in bytes). + */ + void (*start_name)(const br_ssl_client_certificate_class **pctx, + size_t len); + + /** + * \brief Receive some more bytes for the current trust anchor name. + * + * The provided reference (`data`) points to a transient buffer + * they may be reused as soon as this function returns. The chunk + * length (`len`) is never zero. + * + * \param pctx certificate handler context. + * \param data anchor name chunk. + * \param len anchor name chunk length (in bytes). + */ + void (*append_name)(const br_ssl_client_certificate_class **pctx, + const unsigned char *data, size_t len); + + /** + * \brief End current trust anchor name. + * + * This function is called when all the encoded anchor name data + * has been provided. + * + * \param pctx certificate handler context. + */ + void (*end_name)(const br_ssl_client_certificate_class **pctx); + + /** + * \brief End list of trust anchor names. + * + * This function is called when all the anchor names in the + * CertificateRequest message have been obtained. + * + * \param pctx certificate handler context. + */ + void (*end_name_list)(const br_ssl_client_certificate_class **pctx); + + /** + * \brief Select client certificate and algorithms. + * + * This callback function shall fill the provided `choices` + * structure with the selected algorithms and certificate chain. + * The `hash_id`, `chain` and `chain_len` fields must be set. If + * the client cannot or does not wish to send a certificate, + * then it shall set `chain` to `NULL` and `chain_len` to 0. + * + * The `auth_types` parameter describes the authentication types, + * signature algorithms and hash functions that are supported by + * both the client context and the server, and compatible with + * the current protocol version. This is a bit field with the + * following contents: + * + * - If RSA signatures with hash function x are supported, then + * bit x is set. + * + * - If ECDSA signatures with hash function x are supported, + * then bit 8+x is set. + * + * - If static ECDH is supported, with a RSA-signed certificate, + * then bit 16 is set. + * + * - If static ECDH is supported, with an ECDSA-signed certificate, + * then bit 17 is set. + * + * Notes: + * + * - When using TLS 1.0 or 1.1, the hash function for RSA + * signatures is always the special MD5+SHA-1 (id 0), and the + * hash function for ECDSA signatures is always SHA-1 (id 2). + * + * - When using TLS 1.2, the list of hash functions is trimmed + * down to include only hash functions that the client context + * can support. The actual server list can be obtained with + * `br_ssl_client_get_server_hashes()`; that list may be used + * to select the certificate chain to send to the server. + * + * \param pctx certificate handler context. + * \param cc SSL client context. + * \param auth_types supported authentication types and algorithms. + * \param choices destination structure for the policy choices. + */ + void (*choose)(const br_ssl_client_certificate_class **pctx, + const br_ssl_client_context *cc, uint32_t auth_types, + br_ssl_client_certificate *choices); + + /** + * \brief Perform key exchange (client part). + * + * This callback is invoked in case of a full static ECDH key + * exchange: + * + * - the cipher suite uses `ECDH_RSA` or `ECDH_ECDSA`; + * + * - the server requests a client certificate; + * + * - the client has, and sends, a client certificate that + * uses an EC key in the same curve as the server's key, + * and chooses static ECDH (the `hash_id` field in the choice + * structure was set to -1). + * + * In that situation, this callback is invoked to compute the + * client-side ECDH: the provided `data` (of length `*len` bytes) + * is the server's public key point (as decoded from its + * certificate), and the client shall multiply that point with + * its own private key, and write back the X coordinate of the + * resulting point in the same buffer, starting at offset 0. + * The `*len` value shall be modified to designate the actual + * length of the X coordinate. + * + * The callback must uphold the following: + * + * - If the input array does not have the proper length for + * an encoded curve point, then an error (0) shall be reported. + * + * - If the input array has the proper length, then processing + * MUST be constant-time, even if the data is not a valid + * encoded point. + * + * - This callback MUST check that the input point is valid. + * + * Returned value is 1 on success, 0 on error. + * + * \param pctx certificate handler context. + * \param data server public key point. + * \param len public key point length / X coordinate length. + * \return 1 on success, 0 on error. + */ + uint32_t (*do_keyx)(const br_ssl_client_certificate_class **pctx, + unsigned char *data, size_t *len); + + /** + * \brief Perform a signature (client authentication). + * + * This callback is invoked when a client certificate was sent, + * and static ECDH is not used. It shall compute a signature, + * using the client's private key, over the provided hash value + * (which is the hash of all previous handshake messages). + * + * On input, the hash value to sign is in `data`, of size + * `hv_len`; the involved hash function is identified by + * `hash_id`. The signature shall be computed and written + * back into `data`; the total size of that buffer is `len` + * bytes. + * + * This callback shall verify that the signature length does not + * exceed `len` bytes, and abstain from writing the signature if + * it does not fit. + * + * For RSA signatures, the `hash_id` may be 0, in which case + * this is the special header-less signature specified in TLS 1.0 + * and 1.1, with a 36-byte hash value. Otherwise, normal PKCS#1 + * v1.5 signatures shall be computed. + * + * For ECDSA signatures, the signature value shall use the ASN.1 + * based encoding. + * + * Returned value is the signature length (in bytes), or 0 on error. + * + * \param pctx certificate handler context. + * \param hash_id hash function identifier. + * \param hv_len hash value length (in bytes). + * \param data input/output buffer (hash value, then signature). + * \param len total buffer length (in bytes). + * \return signature length (in bytes) on success, or 0 on error. + */ + size_t (*do_sign)(const br_ssl_client_certificate_class **pctx, + int hash_id, size_t hv_len, unsigned char *data, size_t len); +}; + +/** + * \brief A single-chain RSA client certificate handler. + * + * This handler uses a single certificate chain, with a RSA + * signature. The list of trust anchor DN is ignored. + * + * Apart from the first field (vtable pointer), its contents are + * opaque and shall not be accessed directly. + */ +typedef struct { + /** \brief Pointer to vtable. */ + const br_ssl_client_certificate_class *vtable; +#ifndef BR_DOXYGEN_IGNORE + const br_x509_certificate *chain; + size_t chain_len; + const br_rsa_private_key *sk; + br_rsa_pkcs1_sign irsasign; +#endif +} br_ssl_client_certificate_rsa_context; + +/** + * \brief A single-chain EC client certificate handler. + * + * This handler uses a single certificate chain, with a RSA + * signature. The list of trust anchor DN is ignored. + * + * This handler may support both static ECDH, and ECDSA signatures + * (either usage may be selectively disabled). + * + * Apart from the first field (vtable pointer), its contents are + * opaque and shall not be accessed directly. + */ +typedef struct { + /** \brief Pointer to vtable. */ + const br_ssl_client_certificate_class *vtable; +#ifndef BR_DOXYGEN_IGNORE + const br_x509_certificate *chain; + size_t chain_len; + const br_ec_private_key *sk; + unsigned allowed_usages; + unsigned issuer_key_type; + const br_multihash_context *mhash; + const br_ec_impl *iec; + br_ecdsa_sign iecdsa; +#endif +} br_ssl_client_certificate_ec_context; + +/** + * \brief Context structure for a SSL client. + * + * The first field (called `eng`) is the SSL engine; all functions that + * work on a `br_ssl_engine_context` structure shall take as parameter + * a pointer to that field. The other structure fields are opaque and + * must not be accessed directly. + */ +struct br_ssl_client_context_ { + /** + * \brief The encapsulated engine context. + */ + br_ssl_engine_context eng; + +#ifndef BR_DOXYGEN_IGNORE + /* + * Minimum ClientHello length; padding with an extension (RFC + * 7685) is added if necessary to match at least that length. + * Such padding is nominally unnecessary, but it has been used + * to work around some server implementation bugs. + */ + uint16_t min_clienthello_len; + + /* + * Bit field for algoithms (hash + signature) supported by the + * server when requesting a client certificate. + */ + uint32_t hashes; + + /* + * Server's public key curve. + */ + int server_curve; + + /* + * Context for certificate handler. + */ + const br_ssl_client_certificate_class **client_auth_vtable; + + /* + * Client authentication type. + */ + unsigned char auth_type; + + /* + * Hash function to use for the client signature. This is 0xFF + * if static ECDH is used. + */ + unsigned char hash_id; + + /* + * For the core certificate handlers, thus avoiding (in most + * cases) the need for an externally provided policy context. + */ + union { + const br_ssl_client_certificate_class *vtable; + br_ssl_client_certificate_rsa_context single_rsa; + br_ssl_client_certificate_ec_context single_ec; + } client_auth; + + /* + * Implementations. + */ + br_rsa_public irsapub; +#endif +}; + +/** + * \brief Get the hash functions and signature algorithms supported by + * the server. + * + * This value is a bit field: + * + * - If RSA (PKCS#1 v1.5) is supported with hash function of ID `x`, + * then bit `x` is set (hash function ID is 0 for the special MD5+SHA-1, + * or 2 to 6 for the SHA family). + * + * - If ECDSA is supported with hash function of ID `x`, then bit `8+x` + * is set. + * + * - Newer algorithms are symbolic 16-bit identifiers that do not + * represent signature algorithm and hash function separately. If + * the TLS-level identifier is `0x0800+x` for a `x` in the 0..15 + * range, then bit `16+x` is set. + * + * "New algorithms" are currently defined only in draft documents, so + * this support is subject to possible change. Right now (early 2017), + * this maps ed25519 (EdDSA on Curve25519) to bit 23, and ed448 (EdDSA + * on Curve448) to bit 24. If the identifiers on the wire change in + * future document, then the decoding mechanism in BearSSL will be + * amended to keep mapping ed25519 and ed448 on bits 23 and 24, + * respectively. Mapping of other new algorithms (e.g. RSA/PSS) is not + * guaranteed yet. + * + * \param cc client context. + * \return the server-supported hash functions and signature algorithms. + */ +static inline uint32_t +br_ssl_client_get_server_hashes(const br_ssl_client_context *cc) +{ + return cc->hashes; +} + +/** + * \brief Get the server key curve. + * + * This function returns the ID for the curve used by the server's public + * key. This is set when the server's certificate chain is processed; + * this value is 0 if the server's key is not an EC key. + * + * \return the server's public key curve ID, or 0. + */ +static inline int +br_ssl_client_get_server_curve(const br_ssl_client_context *cc) +{ + return cc->server_curve; +} + +/* + * Each br_ssl_client_init_xxx() function sets the list of supported + * cipher suites and used implementations, as specified by the profile + * name 'xxx'. Defined profile names are: + * + * full all supported versions and suites; constant-time implementations + * TODO: add other profiles + */ + +/** + * \brief SSL client profile: full. + * + * This function initialises the provided SSL client context with + * all supported algorithms and cipher suites. It also initialises + * a companion X.509 validation engine with all supported algorithms, + * and the provided trust anchors; the X.509 engine will be used by + * the client context to validate the server's certificate. + * + * \param cc client context to initialise. + * \param xc X.509 validation context to initialise. + * \param trust_anchors trust anchors to use. + * \param trust_anchors_num number of trust anchors. + */ +void br_ssl_client_init_full(br_ssl_client_context *cc, + br_x509_minimal_context *xc, + const br_x509_trust_anchor *trust_anchors, size_t trust_anchors_num); + +/** + * \brief SSL client profile: TLS1.2 minus weak ciphers + * + * This function initialises the provided SSL client context with + * most (see brief) supported algorithms and cipher suites. It also initialises + * a companion X.509 validation engine with most supported algorithms, + * and the provided trust anchors; the X.509 engine will be used by + * the client context to validate the server's certificate. + * + * \param cc client context to initialise. + * \param xc X.509 validation context to initialise. + * \param trust_anchors trust anchors to use. + * \param trust_anchors_num number of trust anchors. + */ +void br_client_init_TLS12_only(br_ssl_client_context *cc, + br_x509_minimal_context *xc, + const br_x509_trust_anchor *trust_anchors, size_t trust_anchors_num); + +/** + * \brief Clear the complete contents of a SSL client context. + * + * Everything is cleared, including the reference to the configured buffer, + * implementations, cipher suites and state. This is a preparatory step + * to assembling a custom profile. + * + * \param cc client context to clear. + */ +void br_ssl_client_zero(br_ssl_client_context *cc); + +/** + * \brief Set an externally provided client certificate handler context. + * + * The handler's methods are invoked when the server requests a client + * certificate. + * + * \param cc client context. + * \param pctx certificate handler context (pointer to its vtable field). + */ +static inline void +br_ssl_client_set_client_certificate(br_ssl_client_context *cc, + const br_ssl_client_certificate_class **pctx) +{ + cc->client_auth_vtable = pctx; +} + +/** + * \brief Set the RSA public-key operations implementation. + * + * This will be used to encrypt the pre-master secret with the server's + * RSA public key (RSA-encryption cipher suites only). + * + * \param cc client context. + * \param irsapub RSA public-key encryption implementation. + */ +static inline void +br_ssl_client_set_rsapub(br_ssl_client_context *cc, br_rsa_public irsapub) +{ + cc->irsapub = irsapub; +} + +/** + * \brief Set the "default" RSA implementation for public-key operations. + * + * This sets the RSA implementation in the client context (for encrypting + * the pre-master secret, in `TLS_RSA_*` cipher suites) to the fastest + * available on the current platform. + * + * \param cc client context. + */ +void br_ssl_client_set_default_rsapub(br_ssl_client_context *cc); + +/** + * \brief Set the minimum ClientHello length (RFC 7685 padding). + * + * If this value is set and the ClientHello would be shorter, then + * the Pad ClientHello extension will be added with enough padding bytes + * to reach the target size. Because of the extension header, the resulting + * size will sometimes be slightly more than `len` bytes if the target + * size cannot be exactly met. + * + * The target length relates to the _contents_ of the ClientHello, not + * counting its 4-byte header. For instance, if `len` is set to 512, + * then the padding will bring the ClientHello size to 516 bytes with its + * header, and 521 bytes when counting the 5-byte record header. + * + * \param cc client context. + * \param len minimum ClientHello length (in bytes). + */ +static inline void +br_ssl_client_set_min_clienthello_len(br_ssl_client_context *cc, uint16_t len) +{ + cc->min_clienthello_len = len; +} + +/** + * \brief Prepare or reset a client context for a new connection. + * + * The `server_name` parameter is used to fill the SNI extension; the + * X.509 "minimal" engine will also match that name against the server + * names included in the server's certificate. If the parameter is + * `NULL` then no SNI extension will be sent, and the X.509 "minimal" + * engine (if used for server certificate validation) will not check + * presence of any specific name in the received certificate. + * + * Therefore, setting the `server_name` to `NULL` shall be reserved + * to cases where alternate or additional methods are used to ascertain + * that the right server public key is used (e.g. a "known key" model). + * + * If `resume_session` is non-zero and the context was previously used + * then the session parameters may be reused (depending on whether the + * server previously sent a non-empty session ID, and accepts the session + * resumption). The session parameters for session resumption can also + * be set explicitly with `br_ssl_engine_set_session_parameters()`. + * + * On failure, the context is marked as failed, and this function + * returns 0. A possible failure condition is when no initial entropy + * was injected, and none could be obtained from the OS (either OS + * randomness gathering is not supported, or it failed). + * + * \param cc client context. + * \param server_name target server name, or `NULL`. + * \param resume_session non-zero to try session resumption. + * \return 0 on failure, 1 on success. + */ +int br_ssl_client_reset(br_ssl_client_context *cc, + const char *server_name, int resume_session); + +/** + * \brief Forget any session in the context. + * + * This means that the next handshake that uses this context will + * necessarily be a full handshake (this applies both to new connections + * and to renegotiations). + * + * \param cc client context. + */ +static inline void +br_ssl_client_forget_session(br_ssl_client_context *cc) +{ + cc->eng.session.session_id_len = 0; +} + +/** + * \brief Set client certificate chain and key (single RSA case). + * + * This function sets a client certificate chain, that the client will + * send to the server whenever a client certificate is requested. This + * certificate uses an RSA public key; the corresponding private key is + * invoked for authentication. Trust anchor names sent by the server are + * ignored. + * + * The provided chain and private key are linked in the client context; + * they must remain valid as long as they may be used, i.e. normally + * for the duration of the connection, since they might be invoked + * again upon renegotiations. + * + * \param cc SSL client context. + * \param chain client certificate chain (SSL order: EE comes first). + * \param chain_len client chain length (number of certificates). + * \param sk client private key. + * \param irsasign RSA signature implementation (PKCS#1 v1.5). + */ +void br_ssl_client_set_single_rsa(br_ssl_client_context *cc, + const br_x509_certificate *chain, size_t chain_len, + const br_rsa_private_key *sk, br_rsa_pkcs1_sign irsasign); + +/* + * \brief Set the client certificate chain and key (single EC case). + * + * This function sets a client certificate chain, that the client will + * send to the server whenever a client certificate is requested. This + * certificate uses an EC public key; the corresponding private key is + * invoked for authentication. Trust anchor names sent by the server are + * ignored. + * + * The provided chain and private key are linked in the client context; + * they must remain valid as long as they may be used, i.e. normally + * for the duration of the connection, since they might be invoked + * again upon renegotiations. + * + * The `allowed_usages` is a combination of usages, namely + * `BR_KEYTYPE_KEYX` and/or `BR_KEYTYPE_SIGN`. The `BR_KEYTYPE_KEYX` + * value allows full static ECDH, while the `BR_KEYTYPE_SIGN` value + * allows ECDSA signatures. If ECDSA signatures are used, then an ECDSA + * signature implementation must be provided; otherwise, the `iecdsa` + * parameter may be 0. + * + * The `cert_issuer_key_type` value is either `BR_KEYTYPE_RSA` or + * `BR_KEYTYPE_EC`; it is the type of the public key used the the CA + * that issued (signed) the client certificate. That value is used with + * full static ECDH: support of the certificate by the server depends + * on how the certificate was signed. (Note: when using TLS 1.2, this + * parameter is ignored; but its value matters for TLS 1.0 and 1.1.) + * + * \param cc server context. + * \param chain server certificate chain to send. + * \param chain_len chain length (number of certificates). + * \param sk server private key (EC). + * \param allowed_usages allowed private key usages. + * \param cert_issuer_key_type issuing CA's key type. + * \param iec EC core implementation. + * \param iecdsa ECDSA signature implementation ("asn1" format). + */ +void br_ssl_client_set_single_ec(br_ssl_client_context *cc, + const br_x509_certificate *chain, size_t chain_len, + const br_ec_private_key *sk, unsigned allowed_usages, + unsigned cert_issuer_key_type, + const br_ec_impl *iec, br_ecdsa_sign iecdsa); + +/** + * \brief Type for a "translated cipher suite", as an array of two + * 16-bit integers. + * + * The first element is the cipher suite identifier (as used on the wire). + * The second element is the concatenation of four 4-bit elements which + * characterise the cipher suite contents. In most to least significant + * order, these 4-bit elements are: + * + * - Bits 12 to 15: key exchange + server key type + * + * | val | symbolic constant | suite type | details | + * | :-- | :----------------------- | :---------- | :----------------------------------------------- | + * | 0 | `BR_SSLKEYX_RSA` | RSA | RSA key exchange, key is RSA (encryption) | + * | 1 | `BR_SSLKEYX_ECDHE_RSA` | ECDHE_RSA | ECDHE key exchange, key is RSA (signature) | + * | 2 | `BR_SSLKEYX_ECDHE_ECDSA` | ECDHE_ECDSA | ECDHE key exchange, key is EC (signature) | + * | 3 | `BR_SSLKEYX_ECDH_RSA` | ECDH_RSA | Key is EC (key exchange), cert signed with RSA | + * | 4 | `BR_SSLKEYX_ECDH_ECDSA` | ECDH_ECDSA | Key is EC (key exchange), cert signed with ECDSA | + * + * - Bits 8 to 11: symmetric encryption algorithm + * + * | val | symbolic constant | symmetric encryption | key strength (bits) | + * | :-- | :--------------------- | :------------------- | :------------------ | + * | 0 | `BR_SSLENC_3DES_CBC` | 3DES/CBC | 168 | + * | 1 | `BR_SSLENC_AES128_CBC` | AES-128/CBC | 128 | + * | 2 | `BR_SSLENC_AES256_CBC` | AES-256/CBC | 256 | + * | 3 | `BR_SSLENC_AES128_GCM` | AES-128/GCM | 128 | + * | 4 | `BR_SSLENC_AES256_GCM` | AES-256/GCM | 256 | + * | 5 | `BR_SSLENC_CHACHA20` | ChaCha20/Poly1305 | 256 | + * + * - Bits 4 to 7: MAC algorithm + * + * | val | symbolic constant | MAC type | details | + * | :-- | :----------------- | :----------- | :------------------------------------ | + * | 0 | `BR_SSLMAC_AEAD` | AEAD | No dedicated MAC (encryption is AEAD) | + * | 2 | `BR_SSLMAC_SHA1` | HMAC/SHA-1 | Value matches `br_sha1_ID` | + * | 4 | `BR_SSLMAC_SHA256` | HMAC/SHA-256 | Value matches `br_sha256_ID` | + * | 5 | `BR_SSLMAC_SHA384` | HMAC/SHA-384 | Value matches `br_sha384_ID` | + * + * - Bits 0 to 3: hash function for PRF when used with TLS-1.2 + * + * | val | symbolic constant | hash function | details | + * | :-- | :----------------- | :------------ | :----------------------------------- | + * | 4 | `BR_SSLPRF_SHA256` | SHA-256 | Value matches `br_sha256_ID` | + * | 5 | `BR_SSLPRF_SHA384` | SHA-384 | Value matches `br_sha384_ID` | + * + * For instance, cipher suite `TLS_RSA_WITH_AES_128_GCM_SHA256` has + * standard identifier 0x009C, and is translated to 0x0304, for, in + * that order: RSA key exchange (0), AES-128/GCM (3), AEAD integrity (0), + * SHA-256 in the TLS PRF (4). + */ +typedef uint16_t br_suite_translated[2]; + +#ifndef BR_DOXYGEN_IGNORE +/* + * Constants are already documented in the br_suite_translated type. + */ + +#define BR_SSLKEYX_RSA 0 +#define BR_SSLKEYX_ECDHE_RSA 1 +#define BR_SSLKEYX_ECDHE_ECDSA 2 +#define BR_SSLKEYX_ECDH_RSA 3 +#define BR_SSLKEYX_ECDH_ECDSA 4 + +#define BR_SSLENC_3DES_CBC 0 +#define BR_SSLENC_AES128_CBC 1 +#define BR_SSLENC_AES256_CBC 2 +#define BR_SSLENC_AES128_GCM 3 +#define BR_SSLENC_AES256_GCM 4 +#define BR_SSLENC_CHACHA20 5 + +#define BR_SSLMAC_AEAD 0 +#define BR_SSLMAC_SHA1 br_sha1_ID +#define BR_SSLMAC_SHA256 br_sha256_ID +#define BR_SSLMAC_SHA384 br_sha384_ID + +#define BR_SSLPRF_SHA256 br_sha256_ID +#define BR_SSLPRF_SHA384 br_sha384_ID + +#endif + +/* + * Pre-declaration for the SSL server context. + */ +typedef struct br_ssl_server_context_ br_ssl_server_context; + +/** + * \brief Type for the server policy choices, taken after analysis of + * the client message (ClientHello). + */ +typedef struct { + /** + * \brief Cipher suite to use with that client. + */ + uint16_t cipher_suite; + + /** + * \brief Hash function or algorithm for signing the ServerKeyExchange. + * + * This parameter is ignored for `TLS_RSA_*` and `TLS_ECDH_*` + * cipher suites; it is used only for `TLS_ECDHE_*` suites, in + * which the server _signs_ the ephemeral EC Diffie-Hellman + * parameters sent to the client. + * + * This identifier must be one of the following values: + * + * - `0xFF00 + id`, where `id` is a hash function identifier + * (0 for MD5+SHA-1, or 2 to 6 for one of the SHA functions); + * + * - a full 16-bit identifier, lower than `0xFF00`. + * + * If the first option is used, then the SSL engine will + * compute the hash of the data that is to be signed, with the + * designated hash function. The `do_sign()` method will be + * invoked with that hash value provided in the the `data` + * buffer. + * + * If the second option is used, then the SSL engine will NOT + * compute a hash on the data; instead, it will provide the + * to-be-signed data itself in `data`, i.e. the concatenation of + * the client random, server random, and encoded ECDH + * parameters. Furthermore, with TLS-1.2 and later, the 16-bit + * identifier will be used "as is" in the protocol, in the + * SignatureAndHashAlgorithm; for instance, `0x0401` stands for + * RSA PKCS#1 v1.5 signature (the `01`) with SHA-256 as hash + * function (the `04`). + * + * Take care that with TLS 1.0 and 1.1, the hash function is + * constrainted by the protocol: RSA signature must use + * MD5+SHA-1 (so use `0xFF00`), while ECDSA must use SHA-1 + * (`0xFF02`). Since TLS 1.0 and 1.1 don't include a + * SignatureAndHashAlgorithm field in their ServerKeyExchange + * messages, any value below `0xFF00` will be usable to send the + * raw ServerKeyExchange data to the `do_sign()` callback, but + * that callback must still follow the protocol requirements + * when generating the signature. + */ + unsigned algo_id; + + /** + * \brief Certificate chain to send to the client. + * + * This is an array of `br_x509_certificate` objects, each + * normally containing a DER-encoded certificate. The server + * code does not try to decode these elements. + */ + const br_x509_certificate *chain; + + /** + * \brief Certificate chain length (number of certificates). + */ + size_t chain_len; + +} br_ssl_server_choices; + +/** + * \brief Class type for a policy handler (server side). + * + * A policy handler selects the policy parameters for a connection + * (cipher suite and other algorithms, and certificate chain to send to + * the client); it also performs the server-side computations involving + * its permanent private key. + * + * The SSL server engine will invoke first `choose()`, once the + * ClientHello message has been received, then either `do_keyx()` + * `do_sign()`, depending on the cipher suite. + */ +typedef struct br_ssl_server_policy_class_ br_ssl_server_policy_class; +struct br_ssl_server_policy_class_ { + /** + * \brief Context size (in bytes). + */ + size_t context_size; + + /** + * \brief Select algorithms and certificates for this connection. + * + * This callback function shall fill the provided `choices` + * structure with the policy choices for this connection. This + * entails selecting the cipher suite, hash function for signing + * the ServerKeyExchange (applicable only to ECDHE cipher suites), + * and certificate chain to send. + * + * The callback receives a pointer to the server context that + * contains the relevant data. In particular, the functions + * `br_ssl_server_get_client_suites()`, + * `br_ssl_server_get_client_hashes()` and + * `br_ssl_server_get_client_curves()` can be used to obtain + * the cipher suites, hash functions and elliptic curves + * supported by both the client and server, respectively. The + * `br_ssl_engine_get_version()` and `br_ssl_engine_get_server_name()` + * functions yield the protocol version and requested server name + * (SNI), respectively. + * + * This function may modify its context structure (`pctx`) in + * arbitrary ways to keep track of its own choices. + * + * This function shall return 1 if appropriate policy choices + * could be made, or 0 if this connection cannot be pursued. + * + * \param pctx policy context. + * \param cc SSL server context. + * \param choices destination structure for the policy choices. + * \return 1 on success, 0 on error. + */ + int (*choose)(const br_ssl_server_policy_class **pctx, + const br_ssl_server_context *cc, + br_ssl_server_choices *choices); + + /** + * \brief Perform key exchange (server part). + * + * This callback is invoked to perform the server-side cryptographic + * operation for a key exchange that is not ECDHE. This callback + * uses the private key. + * + * **For RSA key exchange**, the provided `data` (of length `*len` + * bytes) shall be decrypted with the server's private key, and + * the 48-byte premaster secret copied back to the first 48 bytes + * of `data`. + * + * - The caller makes sure that `*len` is at least 59 bytes. + * + * - This callback MUST check that the provided length matches + * that of the key modulus; it shall report an error otherwise. + * + * - If the length matches that of the RSA key modulus, then + * processing MUST be constant-time, even if decryption fails, + * or the padding is incorrect, or the plaintext message length + * is not exactly 48 bytes. + * + * - This callback needs not check the two first bytes of the + * obtained pre-master secret (the caller will do that). + * + * - If an error is reported (0), then what the callback put + * in the first 48 bytes of `data` is unimportant (the caller + * will use random bytes instead). + * + * **For ECDH key exchange**, the provided `data` (of length `*len` + * bytes) is the elliptic curve point from the client. The + * callback shall multiply it with its private key, and store + * the resulting X coordinate in `data`, starting at offset 0, + * and set `*len` to the length of the X coordinate. + * + * - If the input array does not have the proper length for + * an encoded curve point, then an error (0) shall be reported. + * + * - If the input array has the proper length, then processing + * MUST be constant-time, even if the data is not a valid + * encoded point. + * + * - This callback MUST check that the input point is valid. + * + * Returned value is 1 on success, 0 on error. + * + * \param pctx policy context. + * \param data key exchange data from the client. + * \param len key exchange data length (in bytes). + * \return 1 on success, 0 on error. + */ + uint32_t (*do_keyx)(const br_ssl_server_policy_class **pctx, + unsigned char *data, size_t *len); + + /** + * \brief Perform a signature (for a ServerKeyExchange message). + * + * This callback function is invoked for ECDHE cipher suites. On + * input, the hash value or message to sign is in `data`, of + * size `hv_len`; the involved hash function or algorithm is + * identified by `algo_id`. The signature shall be computed and + * written back into `data`; the total size of that buffer is + * `len` bytes. + * + * This callback shall verify that the signature length does not + * exceed `len` bytes, and abstain from writing the signature if + * it does not fit. + * + * The `algo_id` value matches that which was written in the + * `choices` structures by the `choose()` callback. This will be + * one of the following: + * + * - `0xFF00 + id` for a hash function identifier `id`. In + * that case, the `data` buffer contains a hash value + * already computed over the data that is to be signed, + * of length `hv_len`. The `id` may be 0 to designate the + * special MD5+SHA-1 concatenation (old-style RSA signing). + * + * - Another value, lower than `0xFF00`. The `data` buffer + * then contains the raw, non-hashed data to be signed + * (concatenation of the client and server randoms and + * ECDH parameters). The callback is responsible to apply + * any relevant hashing as part of the signing process. + * + * Returned value is the signature length (in bytes), or 0 on error. + * + * \param pctx policy context. + * \param algo_id hash function / algorithm identifier. + * \param data input/output buffer (message/hash, then signature). + * \param hv_len hash value or message length (in bytes). + * \param len total buffer length (in bytes). + * \return signature length (in bytes) on success, or 0 on error. + */ + size_t (*do_sign)(const br_ssl_server_policy_class **pctx, + unsigned algo_id, + unsigned char *data, size_t hv_len, size_t len); +}; + +/** + * \brief A single-chain RSA policy handler. + * + * This policy context uses a single certificate chain, and a RSA + * private key. The context can be restricted to only signatures or + * only key exchange. + * + * Apart from the first field (vtable pointer), its contents are + * opaque and shall not be accessed directly. + */ +typedef struct { + /** \brief Pointer to vtable. */ + const br_ssl_server_policy_class *vtable; +#ifndef BR_DOXYGEN_IGNORE + const br_x509_certificate *chain; + size_t chain_len; + const br_rsa_private_key *sk; + unsigned allowed_usages; + br_rsa_private irsacore; + br_rsa_pkcs1_sign irsasign; +#endif +} br_ssl_server_policy_rsa_context; + +/** + * \brief A single-chain EC policy handler. + * + * This policy context uses a single certificate chain, and an EC + * private key. The context can be restricted to only signatures or + * only key exchange. + * + * Due to how TLS is defined, this context must be made aware whether + * the server certificate was itself signed with RSA or ECDSA. The code + * does not try to decode the certificate to obtain that information. + * + * Apart from the first field (vtable pointer), its contents are + * opaque and shall not be accessed directly. + */ +typedef struct { + /** \brief Pointer to vtable. */ + const br_ssl_server_policy_class *vtable; +#ifndef BR_DOXYGEN_IGNORE + const br_x509_certificate *chain; + size_t chain_len; + const br_ec_private_key *sk; + unsigned allowed_usages; + unsigned cert_issuer_key_type; + const br_multihash_context *mhash; + const br_ec_impl *iec; + br_ecdsa_sign iecdsa; +#endif +} br_ssl_server_policy_ec_context; + +/** + * \brief Class type for a session parameter cache. + * + * Session parameters are saved in the cache with `save()`, and + * retrieved with `load()`. The cache implementation can apply any + * storage and eviction strategy that it sees fit. The SSL server + * context that performs the request is provided, so that its + * functionalities may be used by the implementation (e.g. hash + * functions or random number generation). + */ +typedef struct br_ssl_session_cache_class_ br_ssl_session_cache_class; +struct br_ssl_session_cache_class_ { + /** + * \brief Context size (in bytes). + */ + size_t context_size; + + /** + * \brief Record a session. + * + * This callback should record the provided session parameters. + * The `params` structure is transient, so its contents shall + * be copied into the cache. The session ID has been randomly + * generated and always has length exactly 32 bytes. + * + * \param ctx session cache context. + * \param server_ctx SSL server context. + * \param params session parameters to save. + */ + void (*save)(const br_ssl_session_cache_class **ctx, + br_ssl_server_context *server_ctx, + const br_ssl_session_parameters *params); + + /** + * \brief Lookup a session in the cache. + * + * The session ID to lookup is in `params` and always has length + * exactly 32 bytes. If the session parameters are found in the + * cache, then the parameters shall be copied into the `params` + * structure. Returned value is 1 on successful lookup, 0 + * otherwise. + * + * \param ctx session cache context. + * \param server_ctx SSL server context. + * \param params destination for session parameters. + * \return 1 if found, 0 otherwise. + */ + int (*load)(const br_ssl_session_cache_class **ctx, + br_ssl_server_context *server_ctx, + br_ssl_session_parameters *params); +}; + +/** + * \brief Context for a basic cache system. + * + * The system stores session parameters in a buffer provided at + * initialisation time. Each entry uses exactly 100 bytes, and + * buffer sizes up to 4294967295 bytes are supported. + * + * Entries are evicted with a LRU (Least Recently Used) policy. A + * search tree is maintained to keep lookups fast even with large + * caches. + * + * Apart from the first field (vtable pointer), the structure + * contents are opaque and shall not be accessed directly. + */ +typedef struct { + /** \brief Pointer to vtable. */ + const br_ssl_session_cache_class *vtable; +#ifndef BR_DOXYGEN_IGNORE + unsigned char *store; + size_t store_len, store_ptr; + unsigned char index_key[32]; + const br_hash_class *hash; + int init_done; + uint32_t head, tail, root; +#endif +} br_ssl_session_cache_lru; + +/** + * \brief Initialise a LRU session cache with the provided storage space. + * + * The provided storage space must remain valid as long as the cache + * is used. Arbitrary lengths are supported, up to 4294967295 bytes; + * each entry uses up exactly 100 bytes. + * + * \param cc session cache context. + * \param store storage space for cached entries. + * \param store_len storage space length (in bytes). + */ +void br_ssl_session_cache_lru_init(br_ssl_session_cache_lru *cc, + unsigned char *store, size_t store_len); + +/** + * \brief Forget an entry in an LRU session cache. + * + * The session cache context must have been initialised. The entry + * with the provided session ID (of exactly 32 bytes) is looked for + * in the cache; if located, it is disabled. + * + * \param cc session cache context. + * \param id session ID to forget. + */ +void br_ssl_session_cache_lru_forget( + br_ssl_session_cache_lru *cc, const unsigned char *id); + +/** + * \brief Context structure for a SSL server. + * + * The first field (called `eng`) is the SSL engine; all functions that + * work on a `br_ssl_engine_context` structure shall take as parameter + * a pointer to that field. The other structure fields are opaque and + * must not be accessed directly. + */ +struct br_ssl_server_context_ { + /** + * \brief The encapsulated engine context. + */ + br_ssl_engine_context eng; + +#ifndef BR_DOXYGEN_IGNORE + /* + * Maximum version from the client. + */ + uint16_t client_max_version; + + /* + * Session cache. + */ + const br_ssl_session_cache_class **cache_vtable; + + /* + * Translated cipher suites supported by the client. The list + * is trimmed to include only the cipher suites that the + * server also supports; they are in the same order as in the + * client message. + */ + br_suite_translated client_suites[BR_MAX_CIPHER_SUITES]; + unsigned char client_suites_num; + + /* + * Hash functions supported by the client, with ECDSA and RSA + * (bit mask). For hash function with id 'x', set bit index is + * x for RSA, x+8 for ECDSA. For newer algorithms, with ID + * 0x08**, bit 16+k is set for algorithm 0x0800+k. + */ + uint32_t hashes; + + /* + * Curves supported by the client (bit mask, for named curves). + */ + uint32_t curves; + + /* + * Context for chain handler. + */ + const br_ssl_server_policy_class **policy_vtable; + uint16_t sign_hash_id; + + /* + * For the core handlers, thus avoiding (in most cases) the + * need for an externally provided policy context. + */ + union { + const br_ssl_server_policy_class *vtable; + br_ssl_server_policy_rsa_context single_rsa; + br_ssl_server_policy_ec_context single_ec; + } chain_handler; + + /* + * Buffer for the ECDHE private key. + */ + unsigned char ecdhe_key[70]; + size_t ecdhe_key_len; + + /* + * Trust anchor names for client authentication. "ta_names" and + * "tas" cannot be both non-NULL. + */ + const br_x500_name *ta_names; + const br_x509_trust_anchor *tas; + size_t num_tas; + size_t cur_dn_index; + const unsigned char *cur_dn; + size_t cur_dn_len; + + /* + * Buffer for the hash value computed over all handshake messages + * prior to CertificateVerify, and identifier for the hash function. + */ + unsigned char hash_CV[64]; + size_t hash_CV_len; + int hash_CV_id; + + /* + * Server-specific implementations. + * (none for now) + */ +#endif +}; + +/* + * Each br_ssl_server_init_xxx() function sets the list of supported + * cipher suites and used implementations, as specified by the profile + * name 'xxx'. Defined profile names are: + * + * full_rsa all supported algorithm, server key type is RSA + * full_ec all supported algorithm, server key type is EC + * TODO: add other profiles + * + * Naming scheme for "minimal" profiles: min123 + * + * -- character 1: key exchange + * r = RSA + * e = ECDHE_RSA + * f = ECDHE_ECDSA + * u = ECDH_RSA + * v = ECDH_ECDSA + * -- character 2: version / PRF + * 0 = TLS 1.0 / 1.1 with MD5+SHA-1 + * 2 = TLS 1.2 with SHA-256 + * 3 = TLS 1.2 with SHA-384 + * -- character 3: encryption + * a = AES/CBC + * d = 3DES/CBC + * g = AES/GCM + * c = ChaCha20+Poly1305 + */ + +/** + * \brief SSL server profile: full_rsa. + * + * This function initialises the provided SSL server context with + * all supported algorithms and cipher suites that rely on a RSA + * key pair. + * + * \param cc server context to initialise. + * \param chain server certificate chain. + * \param chain_len certificate chain length (number of certificate). + * \param sk RSA private key. + */ +void br_ssl_server_init_full_rsa(br_ssl_server_context *cc, + const br_x509_certificate *chain, size_t chain_len, + const br_rsa_private_key *sk); + +/** + * \brief SSL server profile: full_ec. + * + * This function initialises the provided SSL server context with + * all supported algorithms and cipher suites that rely on an EC + * key pair. + * + * The key type of the CA that issued the server's certificate must + * be provided, since it matters for ECDH cipher suites (ECDH_RSA + * suites require a RSA-powered CA). The key type is either + * `BR_KEYTYPE_RSA` or `BR_KEYTYPE_EC`. + * + * \param cc server context to initialise. + * \param chain server certificate chain. + * \param chain_len chain length (number of certificates). + * \param cert_issuer_key_type certificate issuer's key type. + * \param sk EC private key. + */ +void br_ssl_server_init_full_ec(br_ssl_server_context *cc, + const br_x509_certificate *chain, size_t chain_len, + unsigned cert_issuer_key_type, const br_ec_private_key *sk); + +/** + * \brief SSL server profile: minr2g. + * + * This profile uses only TLS_RSA_WITH_AES_128_GCM_SHA256. Server key is + * RSA, and RSA key exchange is used (not forward secure, but uses little + * CPU in the client). + * + * \param cc server context to initialise. + * \param chain server certificate chain. + * \param chain_len certificate chain length (number of certificate). + * \param sk RSA private key. + */ +void br_ssl_server_init_minr2g(br_ssl_server_context *cc, + const br_x509_certificate *chain, size_t chain_len, + const br_rsa_private_key *sk); + +/** + * \brief SSL server profile: mine2g. + * + * This profile uses only TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256. Server key + * is RSA, and ECDHE key exchange is used. This suite provides forward + * security, with a higher CPU expense on the client, and a somewhat + * larger code footprint (compared to "minr2g"). + * + * \param cc server context to initialise. + * \param chain server certificate chain. + * \param chain_len certificate chain length (number of certificate). + * \param sk RSA private key. + */ +void br_ssl_server_init_mine2g(br_ssl_server_context *cc, + const br_x509_certificate *chain, size_t chain_len, + const br_rsa_private_key *sk); + +/** + * \brief SSL server profile: minf2g. + * + * This profile uses only TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256. + * Server key is EC, and ECDHE key exchange is used. This suite provides + * forward security, with a higher CPU expense on the client and server + * (by a factor of about 3 to 4), and a somewhat larger code footprint + * (compared to "minu2g" and "minv2g"). + * + * \param cc server context to initialise. + * \param chain server certificate chain. + * \param chain_len certificate chain length (number of certificate). + * \param sk EC private key. + */ +void br_ssl_server_init_minf2g(br_ssl_server_context *cc, + const br_x509_certificate *chain, size_t chain_len, + const br_ec_private_key *sk); + +/** + * \brief SSL server profile: minu2g. + * + * This profile uses only TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256. + * Server key is EC, and ECDH key exchange is used; the issuing CA used + * a RSA key. + * + * The "minu2g" and "minv2g" profiles do not provide forward secrecy, + * but are the lightest on the server (for CPU usage), and are rather + * inexpensive on the client as well. + * + * \param cc server context to initialise. + * \param chain server certificate chain. + * \param chain_len certificate chain length (number of certificate). + * \param sk EC private key. + */ +void br_ssl_server_init_minu2g(br_ssl_server_context *cc, + const br_x509_certificate *chain, size_t chain_len, + const br_ec_private_key *sk); + +/** + * \brief SSL server profile: minv2g. + * + * This profile uses only TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256. + * Server key is EC, and ECDH key exchange is used; the issuing CA used + * an EC key. + * + * The "minu2g" and "minv2g" profiles do not provide forward secrecy, + * but are the lightest on the server (for CPU usage), and are rather + * inexpensive on the client as well. + * + * \param cc server context to initialise. + * \param chain server certificate chain. + * \param chain_len certificate chain length (number of certificate). + * \param sk EC private key. + */ +void br_ssl_server_init_minv2g(br_ssl_server_context *cc, + const br_x509_certificate *chain, size_t chain_len, + const br_ec_private_key *sk); + +/** + * \brief SSL server profile: mine2c. + * + * This profile uses only TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256. + * Server key is RSA, and ECDHE key exchange is used. This suite + * provides forward security. + * + * \param cc server context to initialise. + * \param chain server certificate chain. + * \param chain_len certificate chain length (number of certificate). + * \param sk RSA private key. + */ +void br_ssl_server_init_mine2c(br_ssl_server_context *cc, + const br_x509_certificate *chain, size_t chain_len, + const br_rsa_private_key *sk); + +/** + * \brief SSL server profile: minf2c. + * + * This profile uses only TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256. + * Server key is EC, and ECDHE key exchange is used. This suite provides + * forward security. + * + * \param cc server context to initialise. + * \param chain server certificate chain. + * \param chain_len certificate chain length (number of certificate). + * \param sk EC private key. + */ +void br_ssl_server_init_minf2c(br_ssl_server_context *cc, + const br_x509_certificate *chain, size_t chain_len, + const br_ec_private_key *sk); + +/** + * \brief Get the supported client suites. + * + * This function shall be called only after the ClientHello has been + * processed, typically from the policy engine. The returned array + * contains the cipher suites that are supported by both the client + * and the server; these suites are in client preference order, unless + * the `BR_OPT_ENFORCE_SERVER_PREFERENCES` flag was set, in which case + * they are in server preference order. + * + * The suites are _translated_, which means that each suite is given + * as two 16-bit integers: the standard suite identifier, and its + * translated version, broken down into its individual components, + * as explained with the `br_suite_translated` type. + * + * The returned array is allocated in the context and will be rewritten + * by each handshake. + * + * \param cc server context. + * \param num receives the array size (number of suites). + * \return the translated common cipher suites, in preference order. + */ +static inline const br_suite_translated * +br_ssl_server_get_client_suites(const br_ssl_server_context *cc, size_t *num) +{ + *num = cc->client_suites_num; + return cc->client_suites; +} + +/** + * \brief Get the hash functions and signature algorithms supported by + * the client. + * + * This value is a bit field: + * + * - If RSA (PKCS#1 v1.5) is supported with hash function of ID `x`, + * then bit `x` is set (hash function ID is 0 for the special MD5+SHA-1, + * or 2 to 6 for the SHA family). + * + * - If ECDSA is supported with hash function of ID `x`, then bit `8+x` + * is set. + * + * - Newer algorithms are symbolic 16-bit identifiers that do not + * represent signature algorithm and hash function separately. If + * the TLS-level identifier is `0x0800+x` for a `x` in the 0..15 + * range, then bit `16+x` is set. + * + * "New algorithms" are currently defined only in draft documents, so + * this support is subject to possible change. Right now (early 2017), + * this maps ed25519 (EdDSA on Curve25519) to bit 23, and ed448 (EdDSA + * on Curve448) to bit 24. If the identifiers on the wire change in + * future document, then the decoding mechanism in BearSSL will be + * amended to keep mapping ed25519 and ed448 on bits 23 and 24, + * respectively. Mapping of other new algorithms (e.g. RSA/PSS) is not + * guaranteed yet. + * + * \param cc server context. + * \return the client-supported hash functions and signature algorithms. + */ +static inline uint32_t +br_ssl_server_get_client_hashes(const br_ssl_server_context *cc) +{ + return cc->hashes; +} + +/** + * \brief Get the elliptic curves supported by the client. + * + * This is a bit field (bit x is set if curve of ID x is supported). + * + * \param cc server context. + * \return the client-supported elliptic curves. + */ +static inline uint32_t +br_ssl_server_get_client_curves(const br_ssl_server_context *cc) +{ + return cc->curves; +} + +/** + * \brief Clear the complete contents of a SSL server context. + * + * Everything is cleared, including the reference to the configured buffer, + * implementations, cipher suites and state. This is a preparatory step + * to assembling a custom profile. + * + * \param cc server context to clear. + */ +void br_ssl_server_zero(br_ssl_server_context *cc); + +/** + * \brief Set an externally provided policy context. + * + * The policy context's methods are invoked to decide the cipher suite + * and certificate chain, and to perform operations involving the server's + * private key. + * + * \param cc server context. + * \param pctx policy context (pointer to its vtable field). + */ +static inline void +br_ssl_server_set_policy(br_ssl_server_context *cc, + const br_ssl_server_policy_class **pctx) +{ + cc->policy_vtable = pctx; +} + +/** + * \brief Set the server certificate chain and key (single RSA case). + * + * This function uses a policy context included in the server context. + * It configures use of a single server certificate chain with a RSA + * private key. The `allowed_usages` is a combination of usages, namely + * `BR_KEYTYPE_KEYX` and/or `BR_KEYTYPE_SIGN`; this enables or disables + * the corresponding cipher suites (i.e. `TLS_RSA_*` use the RSA key for + * key exchange, while `TLS_ECDHE_RSA_*` use the RSA key for signatures). + * + * \param cc server context. + * \param chain server certificate chain to send to the client. + * \param chain_len chain length (number of certificates). + * \param sk server private key (RSA). + * \param allowed_usages allowed private key usages. + * \param irsacore RSA core implementation. + * \param irsasign RSA signature implementation (PKCS#1 v1.5). + */ +void br_ssl_server_set_single_rsa(br_ssl_server_context *cc, + const br_x509_certificate *chain, size_t chain_len, + const br_rsa_private_key *sk, unsigned allowed_usages, + br_rsa_private irsacore, br_rsa_pkcs1_sign irsasign); + +/** + * \brief Set the server certificate chain and key (single EC case). + * + * This function uses a policy context included in the server context. + * It configures use of a single server certificate chain with an EC + * private key. The `allowed_usages` is a combination of usages, namely + * `BR_KEYTYPE_KEYX` and/or `BR_KEYTYPE_SIGN`; this enables or disables + * the corresponding cipher suites (i.e. `TLS_ECDH_*` use the EC key for + * key exchange, while `TLS_ECDHE_ECDSA_*` use the EC key for signatures). + * + * In order to support `TLS_ECDH_*` cipher suites (non-ephemeral ECDH), + * the algorithm type of the key used by the issuing CA to sign the + * server's certificate must be provided, as `cert_issuer_key_type` + * parameter (this value is either `BR_KEYTYPE_RSA` or `BR_KEYTYPE_EC`). + * + * \param cc server context. + * \param chain server certificate chain to send. + * \param chain_len chain length (number of certificates). + * \param sk server private key (EC). + * \param allowed_usages allowed private key usages. + * \param cert_issuer_key_type issuing CA's key type. + * \param iec EC core implementation. + * \param iecdsa ECDSA signature implementation ("asn1" format). + */ +void br_ssl_server_set_single_ec(br_ssl_server_context *cc, + const br_x509_certificate *chain, size_t chain_len, + const br_ec_private_key *sk, unsigned allowed_usages, + unsigned cert_issuer_key_type, + const br_ec_impl *iec, br_ecdsa_sign iecdsa); + +/** + * \brief Activate client certificate authentication. + * + * The trust anchor encoded X.500 names (DN) to send to the client are + * provided. A client certificate will be requested and validated through + * the X.509 validator configured in the SSL engine. If `num` is 0, then + * client certificate authentication is disabled. + * + * If the client does not send a certificate, or on validation failure, + * the handshake aborts. Unauthenticated clients can be tolerated by + * setting the `BR_OPT_TOLERATE_NO_CLIENT_AUTH` flag. + * + * The provided array is linked in, not copied, so that pointer must + * remain valid as long as anchor names may be used. + * + * \param cc server context. + * \param ta_names encoded trust anchor names. + * \param num number of encoded trust anchor names. + */ +static inline void +br_ssl_server_set_trust_anchor_names(br_ssl_server_context *cc, + const br_x500_name *ta_names, size_t num) +{ + cc->ta_names = ta_names; + cc->tas = NULL; + cc->num_tas = num; +} + +/** + * \brief Activate client certificate authentication. + * + * This is a variant for `br_ssl_server_set_trust_anchor_names()`: the + * trust anchor names are provided not as an array of stand-alone names + * (`br_x500_name` structures), but as an array of trust anchors + * (`br_x509_trust_anchor` structures). The server engine itself will + * only use the `dn` field of each trust anchor. This is meant to allow + * defining a single array of trust anchors, to be used here and in the + * X.509 validation engine itself. + * + * The provided array is linked in, not copied, so that pointer must + * remain valid as long as anchor names may be used. + * + * \param cc server context. + * \param tas trust anchors (only names are used). + * \param num number of trust anchors. + */ +static inline void +br_ssl_server_set_trust_anchor_names_alt(br_ssl_server_context *cc, + const br_x509_trust_anchor *tas, size_t num) +{ + cc->ta_names = NULL; + cc->tas = tas; + cc->num_tas = num; +} + +/** + * \brief Configure the cache for session parameters. + * + * The cache context is provided as a pointer to its first field (vtable + * pointer). + * + * \param cc server context. + * \param vtable session cache context. + */ +static inline void +br_ssl_server_set_cache(br_ssl_server_context *cc, + const br_ssl_session_cache_class **vtable) +{ + cc->cache_vtable = vtable; +} + +/** + * \brief Prepare or reset a server context for handling an incoming client. + * + * \param cc server context. + * \return 1 on success, 0 on error. + */ +int br_ssl_server_reset(br_ssl_server_context *cc); + +/* ===================================================================== */ + +/* + * Context for the simplified I/O context. The transport medium is accessed + * through the low_read() and low_write() callback functions, each with + * its own opaque context pointer. + * + * low_read() read some bytes, at most 'len' bytes, into data[]. The + * returned value is the number of read bytes, or -1 on error. + * The 'len' parameter is guaranteed never to exceed 20000, + * so the length always fits in an 'int' on all platforms. + * + * low_write() write up to 'len' bytes, to be read from data[]. The + * returned value is the number of written bytes, or -1 on + * error. The 'len' parameter is guaranteed never to exceed + * 20000, so the length always fits in an 'int' on all + * parameters. + * + * A socket closure (if the transport medium is a socket) should be reported + * as an error (-1). The callbacks shall endeavour to block until at least + * one byte can be read or written; a callback returning 0 at times is + * acceptable, but this normally leads to the callback being immediately + * called again, so the callback should at least always try to block for + * some time if no I/O can take place. + * + * The SSL engine naturally applies some buffering, so the callbacks need + * not apply buffers of their own. + */ +/** + * \brief Context structure for the simplified SSL I/O wrapper. + * + * This structure is initialised with `br_sslio_init()`. Its contents + * are opaque and shall not be accessed directly. + */ +typedef struct { +#ifndef BR_DOXYGEN_IGNORE + br_ssl_engine_context *engine; + int (*low_read)(void *read_context, + unsigned char *data, size_t len); + void *read_context; + int (*low_write)(void *write_context, + const unsigned char *data, size_t len); + void *write_context; +#endif +} br_sslio_context; + +/** + * \brief Initialise a simplified I/O wrapper context. + * + * The simplified I/O wrapper offers a simpler read/write API for a SSL + * engine (client or server), using the provided callback functions for + * reading data from, or writing data to, the transport medium. + * + * The callback functions have the following semantics: + * + * - Each callback receives an opaque context value (of type `void *`) + * that the callback may use arbitrarily (or possibly ignore). + * + * - `low_read()` reads at least one byte, at most `len` bytes, from + * the transport medium. Read bytes shall be written in `data`. + * + * - `low_write()` writes at least one byte, at most `len` bytes, unto + * the transport medium. The bytes to write are read from `data`. + * + * - The `len` parameter is never zero, and is always lower than 20000. + * + * - The number of processed bytes (read or written) is returned. Since + * that number is less than 20000, it always fits on an `int`. + * + * - On error, the callbacks return -1. Reaching end-of-stream is an + * error. Errors are permanent: the SSL connection is terminated. + * + * - Callbacks SHOULD NOT return 0. This is tolerated, as long as + * callbacks endeavour to block for some non-negligible amount of + * time until at least one byte can be sent or received (if a + * callback returns 0, then the wrapper invokes it again + * immediately). + * + * - Callbacks MAY return as soon as at least one byte is processed; + * they MAY also insist on reading or writing _all_ requested bytes. + * Since SSL is a self-terminated protocol (each record has a length + * header), this does not change semantics. + * + * - Callbacks need not apply any buffering (for performance) since SSL + * itself uses buffers. + * + * \param ctx wrapper context to initialise. + * \param engine SSL engine to wrap. + * \param low_read callback for reading data from the transport. + * \param read_context context pointer for `low_read()`. + * \param low_write callback for writing data on the transport. + * \param write_context context pointer for `low_write()`. + */ +void br_sslio_init(br_sslio_context *ctx, + br_ssl_engine_context *engine, + int (*low_read)(void *read_context, + unsigned char *data, size_t len), + void *read_context, + int (*low_write)(void *write_context, + const unsigned char *data, size_t len), + void *write_context); + +/** + * \brief Read some application data from a SSL connection. + * + * If `len` is zero, then this function returns 0 immediately. In + * all other cases, it never returns 0. + * + * This call returns only when at least one byte has been obtained. + * Returned value is the number of bytes read, or -1 on error. The + * number of bytes always fits on an 'int' (data from a single SSL/TLS + * record is returned). + * + * On error or SSL closure, this function returns -1. The caller should + * inspect the error status on the SSL engine to distinguish between + * normal closure and error. + * + * \param cc SSL wrapper context. + * \param dst destination buffer for application data. + * \param len maximum number of bytes to obtain. + * \return number of bytes obtained, or -1 on error. + */ +int br_sslio_read(br_sslio_context *cc, void *dst, size_t len); + +/** + * \brief Read application data from a SSL connection. + * + * This calls returns only when _all_ requested `len` bytes are read, + * or an error is reached. Returned value is 0 on success, -1 on error. + * A normal (verified) SSL closure before that many bytes are obtained + * is reported as an error by this function. + * + * \param cc SSL wrapper context. + * \param dst destination buffer for application data. + * \param len number of bytes to obtain. + * \return 0 on success, or -1 on error. + */ +int br_sslio_read_all(br_sslio_context *cc, void *dst, size_t len); + +/** + * \brief Write some application data unto a SSL connection. + * + * If `len` is zero, then this function returns 0 immediately. In + * all other cases, it never returns 0. + * + * This call returns only when at least one byte has been written. + * Returned value is the number of bytes written, or -1 on error. The + * number of bytes always fits on an 'int' (less than 20000). + * + * On error or SSL closure, this function returns -1. The caller should + * inspect the error status on the SSL engine to distinguish between + * normal closure and error. + * + * **Important:** SSL is buffered; a "written" byte is a byte that was + * injected into the wrapped SSL engine, but this does not necessarily mean + * that it has been scheduled for sending. Use `br_sslio_flush()` to + * ensure that all pending data has been sent to the transport medium. + * + * \param cc SSL wrapper context. + * \param src source buffer for application data. + * \param len maximum number of bytes to write. + * \return number of bytes written, or -1 on error. + */ +int br_sslio_write(br_sslio_context *cc, const void *src, size_t len); + +/** + * \brief Write application data unto a SSL connection. + * + * This calls returns only when _all_ requested `len` bytes have been + * written, or an error is reached. Returned value is 0 on success, -1 + * on error. A normal (verified) SSL closure before that many bytes are + * written is reported as an error by this function. + * + * **Important:** SSL is buffered; a "written" byte is a byte that was + * injected into the wrapped SSL engine, but this does not necessarily mean + * that it has been scheduled for sending. Use `br_sslio_flush()` to + * ensure that all pending data has been sent to the transport medium. + * + * \param cc SSL wrapper context. + * \param src source buffer for application data. + * \param len number of bytes to write. + * \return 0 on success, or -1 on error. + */ +int br_sslio_write_all(br_sslio_context *cc, const void *src, size_t len); + +/** + * \brief Flush pending data. + * + * This call makes sure that any buffered application data in the + * provided context (including the wrapped SSL engine) has been sent + * to the transport medium (i.e. accepted by the `low_write()` callback + * method). If there is no such pending data, then this function does + * nothing (and returns a success, i.e. 0). + * + * If the underlying transport medium has its own buffers, then it is + * up to the caller to ensure the corresponding flushing. + * + * Returned value is 0 on success, -1 on error. + * + * \param cc SSL wrapper context. + * \return 0 on success, or -1 on error. + */ +int br_sslio_flush(br_sslio_context *cc); + +/** + * \brief Close the SSL connection. + * + * This call runs the SSL closure protocol (sending a `close_notify`, + * receiving the response `close_notify`). When it returns, the SSL + * connection is finished. It is still up to the caller to manage the + * possible transport-level termination, if applicable (alternatively, + * the underlying transport stream may be reused for non-SSL messages). + * + * Returned value is 0 on success, -1 on error. A failure by the peer + * to process the complete closure protocol (i.e. sending back the + * `close_notify`) is an error. + * + * \param cc SSL wrapper context. + * \return 0 on success, or -1 on error. + */ +int br_sslio_close(br_sslio_context *cc); + +/* ===================================================================== */ + +/* + * Symbolic constants for cipher suites. + */ + +/* From RFC 5246 */ +#define BR_TLS_NULL_WITH_NULL_NULL 0x0000 +#define BR_TLS_RSA_WITH_NULL_MD5 0x0001 +#define BR_TLS_RSA_WITH_NULL_SHA 0x0002 +#define BR_TLS_RSA_WITH_NULL_SHA256 0x003B +#define BR_TLS_RSA_WITH_RC4_128_MD5 0x0004 +#define BR_TLS_RSA_WITH_RC4_128_SHA 0x0005 +#define BR_TLS_RSA_WITH_3DES_EDE_CBC_SHA 0x000A +#define BR_TLS_RSA_WITH_AES_128_CBC_SHA 0x002F +#define BR_TLS_RSA_WITH_AES_256_CBC_SHA 0x0035 +#define BR_TLS_RSA_WITH_AES_128_CBC_SHA256 0x003C +#define BR_TLS_RSA_WITH_AES_256_CBC_SHA256 0x003D +#define BR_TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA 0x000D +#define BR_TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA 0x0010 +#define BR_TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA 0x0013 +#define BR_TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA 0x0016 +#define BR_TLS_DH_DSS_WITH_AES_128_CBC_SHA 0x0030 +#define BR_TLS_DH_RSA_WITH_AES_128_CBC_SHA 0x0031 +#define BR_TLS_DHE_DSS_WITH_AES_128_CBC_SHA 0x0032 +#define BR_TLS_DHE_RSA_WITH_AES_128_CBC_SHA 0x0033 +#define BR_TLS_DH_DSS_WITH_AES_256_CBC_SHA 0x0036 +#define BR_TLS_DH_RSA_WITH_AES_256_CBC_SHA 0x0037 +#define BR_TLS_DHE_DSS_WITH_AES_256_CBC_SHA 0x0038 +#define BR_TLS_DHE_RSA_WITH_AES_256_CBC_SHA 0x0039 +#define BR_TLS_DH_DSS_WITH_AES_128_CBC_SHA256 0x003E +#define BR_TLS_DH_RSA_WITH_AES_128_CBC_SHA256 0x003F +#define BR_TLS_DHE_DSS_WITH_AES_128_CBC_SHA256 0x0040 +#define BR_TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 0x0067 +#define BR_TLS_DH_DSS_WITH_AES_256_CBC_SHA256 0x0068 +#define BR_TLS_DH_RSA_WITH_AES_256_CBC_SHA256 0x0069 +#define BR_TLS_DHE_DSS_WITH_AES_256_CBC_SHA256 0x006A +#define BR_TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 0x006B +#define BR_TLS_DH_anon_WITH_RC4_128_MD5 0x0018 +#define BR_TLS_DH_anon_WITH_3DES_EDE_CBC_SHA 0x001B +#define BR_TLS_DH_anon_WITH_AES_128_CBC_SHA 0x0034 +#define BR_TLS_DH_anon_WITH_AES_256_CBC_SHA 0x003A +#define BR_TLS_DH_anon_WITH_AES_128_CBC_SHA256 0x006C +#define BR_TLS_DH_anon_WITH_AES_256_CBC_SHA256 0x006D + +/* From RFC 4492 */ +#define BR_TLS_ECDH_ECDSA_WITH_NULL_SHA 0xC001 +#define BR_TLS_ECDH_ECDSA_WITH_RC4_128_SHA 0xC002 +#define BR_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA 0xC003 +#define BR_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA 0xC004 +#define BR_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA 0xC005 +#define BR_TLS_ECDHE_ECDSA_WITH_NULL_SHA 0xC006 +#define BR_TLS_ECDHE_ECDSA_WITH_RC4_128_SHA 0xC007 +#define BR_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA 0xC008 +#define BR_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA 0xC009 +#define BR_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA 0xC00A +#define BR_TLS_ECDH_RSA_WITH_NULL_SHA 0xC00B +#define BR_TLS_ECDH_RSA_WITH_RC4_128_SHA 0xC00C +#define BR_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA 0xC00D +#define BR_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA 0xC00E +#define BR_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA 0xC00F +#define BR_TLS_ECDHE_RSA_WITH_NULL_SHA 0xC010 +#define BR_TLS_ECDHE_RSA_WITH_RC4_128_SHA 0xC011 +#define BR_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA 0xC012 +#define BR_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA 0xC013 +#define BR_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA 0xC014 +#define BR_TLS_ECDH_anon_WITH_NULL_SHA 0xC015 +#define BR_TLS_ECDH_anon_WITH_RC4_128_SHA 0xC016 +#define BR_TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA 0xC017 +#define BR_TLS_ECDH_anon_WITH_AES_128_CBC_SHA 0xC018 +#define BR_TLS_ECDH_anon_WITH_AES_256_CBC_SHA 0xC019 + +/* From RFC 5288 */ +#define BR_TLS_RSA_WITH_AES_128_GCM_SHA256 0x009C +#define BR_TLS_RSA_WITH_AES_256_GCM_SHA384 0x009D +#define BR_TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 0x009E +#define BR_TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 0x009F +#define BR_TLS_DH_RSA_WITH_AES_128_GCM_SHA256 0x00A0 +#define BR_TLS_DH_RSA_WITH_AES_256_GCM_SHA384 0x00A1 +#define BR_TLS_DHE_DSS_WITH_AES_128_GCM_SHA256 0x00A2 +#define BR_TLS_DHE_DSS_WITH_AES_256_GCM_SHA384 0x00A3 +#define BR_TLS_DH_DSS_WITH_AES_128_GCM_SHA256 0x00A4 +#define BR_TLS_DH_DSS_WITH_AES_256_GCM_SHA384 0x00A5 +#define BR_TLS_DH_anon_WITH_AES_128_GCM_SHA256 0x00A6 +#define BR_TLS_DH_anon_WITH_AES_256_GCM_SHA384 0x00A7 + +/* From RFC 5289 */ +#define BR_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 0xC023 +#define BR_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 0xC024 +#define BR_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 0xC025 +#define BR_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 0xC026 +#define BR_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 0xC027 +#define BR_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 0xC028 +#define BR_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 0xC029 +#define BR_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384 0xC02A +#define BR_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 0xC02B +#define BR_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 0xC02C +#define BR_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 0xC02D +#define BR_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 0xC02E +#define BR_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 0xC02F +#define BR_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 0xC030 +#define BR_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256 0xC031 +#define BR_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384 0xC032 + +/* From RFC 6655 and 7251 */ +#define BR_TLS_RSA_WITH_AES_128_CCM 0xC09C +#define BR_TLS_RSA_WITH_AES_256_CCM 0xC09D +#define BR_TLS_RSA_WITH_AES_128_CCM_8 0xC0A0 +#define BR_TLS_RSA_WITH_AES_256_CCM_8 0xC0A1 +#define BR_TLS_ECDHE_ECDSA_WITH_AES_128_CCM 0xC0AC +#define BR_TLS_ECDHE_ECDSA_WITH_AES_256_CCM 0xC0AD +#define BR_TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 0xC0AE +#define BR_TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8 0xC0AF + +/* From RFC 7905 */ +#define BR_TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 0xCCA8 +#define BR_TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 0xCCA9 +#define BR_TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256 0xCCAA +#define BR_TLS_PSK_WITH_CHACHA20_POLY1305_SHA256 0xCCAB +#define BR_TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256 0xCCAC +#define BR_TLS_DHE_PSK_WITH_CHACHA20_POLY1305_SHA256 0xCCAD +#define BR_TLS_RSA_PSK_WITH_CHACHA20_POLY1305_SHA256 0xCCAE + +/* From RFC 7507 */ +#define BR_TLS_FALLBACK_SCSV 0x5600 + +/* + * Symbolic constants for alerts. + */ +#define BR_ALERT_CLOSE_NOTIFY 0 +#define BR_ALERT_UNEXPECTED_MESSAGE 10 +#define BR_ALERT_BAD_RECORD_MAC 20 +#define BR_ALERT_RECORD_OVERFLOW 22 +#define BR_ALERT_DECOMPRESSION_FAILURE 30 +#define BR_ALERT_HANDSHAKE_FAILURE 40 +#define BR_ALERT_BAD_CERTIFICATE 42 +#define BR_ALERT_UNSUPPORTED_CERTIFICATE 43 +#define BR_ALERT_CERTIFICATE_REVOKED 44 +#define BR_ALERT_CERTIFICATE_EXPIRED 45 +#define BR_ALERT_CERTIFICATE_UNKNOWN 46 +#define BR_ALERT_ILLEGAL_PARAMETER 47 +#define BR_ALERT_UNKNOWN_CA 48 +#define BR_ALERT_ACCESS_DENIED 49 +#define BR_ALERT_DECODE_ERROR 50 +#define BR_ALERT_DECRYPT_ERROR 51 +#define BR_ALERT_PROTOCOL_VERSION 70 +#define BR_ALERT_INSUFFICIENT_SECURITY 71 +#define BR_ALERT_INTERNAL_ERROR 80 +#define BR_ALERT_USER_CANCELED 90 +#define BR_ALERT_NO_RENEGOTIATION 100 +#define BR_ALERT_UNSUPPORTED_EXTENSION 110 +#define BR_ALERT_NO_APPLICATION_PROTOCOL 120 + +#ifdef __cplusplus +} +#endif + +#endif + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/bearssl_x509.h b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/bearssl_x509.h new file mode 100644 index 000000000..34007c4b8 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/bearssl_x509.h @@ -0,0 +1,1588 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#ifndef BR_BEARSSL_X509_H__ +#define BR_BEARSSL_X509_H__ + +#include +#include + +#include "bearssl_ec.h" +#include "bearssl_hash.h" +#include "bearssl_rsa.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +/** \file bearssl_x509.h + * + * # X.509 Certificate Chain Processing + * + * An X.509 processing engine receives an X.509 chain, chunk by chunk, + * as received from a SSL/TLS client or server (the client receives the + * server's certificate chain, and the server receives the client's + * certificate chain if it requested a client certificate). The chain + * is thus injected in the engine in SSL order (end-entity first). + * + * The engine's job is to return the public key to use for SSL/TLS. + * How exactly that key is obtained and verified is entirely up to the + * engine. + * + * **The "known key" engine** returns a public key which is already known + * from out-of-band information (e.g. the client _remembers_ the key from + * a previous connection, as in the usual SSH model). This is the simplest + * engine since it simply ignores the chain, thereby avoiding the need + * for any decoding logic. + * + * **The "minimal" engine** implements minimal X.509 decoding and chain + * validation: + * + * - The provided chain should validate "as is". There is no attempt + * at reordering, skipping or downloading extra certificates. + * + * - X.509 v1, v2 and v3 certificates are supported. + * + * - Trust anchors are a DN and a public key. Each anchor is either a + * "CA" anchor, or a non-CA. + * + * - If the end-entity certificate matches a non-CA anchor (subject DN + * is equal to the non-CA name, and public key is also identical to + * the anchor key), then this is a _direct trust_ case and the + * remaining certificates are ignored. + * + * - Unless direct trust is applied, the chain must be verifiable up to + * a certificate whose issuer DN matches the DN from a "CA" trust anchor, + * and whose signature is verifiable against that anchor's public key. + * Subsequent certificates in the chain are ignored. + * + * - The engine verifies subject/issuer DN matching, and enforces + * processing of Basic Constraints and Key Usage extensions. The + * Authority Key Identifier, Subject Key Identifier, Issuer Alt Name, + * Subject Directory Attribute, CRL Distribution Points, Freshest CRL, + * Authority Info Access and Subject Info Access extensions are + * ignored. The Subject Alt Name is decoded for the end-entity + * certificate under some conditions (see below). Other extensions + * are ignored if non-critical, or imply chain rejection if critical. + * + * - The Subject Alt Name extension is parsed for names of type `dNSName` + * when decoding the end-entity certificate, and only if there is a + * server name to match. If there is no SAN extension, then the + * Common Name from the subjectDN is used. That name matching is + * case-insensitive and honours a single starting wildcard (i.e. if + * the name in the certificate starts with "`*.`" then this matches + * any word as first element). Note: this name matching is performed + * also in the "direct trust" model. + * + * - DN matching is byte-to-byte equality (a future version might + * include some limited processing for case-insensitive matching and + * whitespace normalisation). + * + * - Successful validation produces a public key type but also a set + * of allowed usages (`BR_KEYTYPE_KEYX` and/or `BR_KEYTYPE_SIGN`). + * The caller is responsible for checking that the key type and + * usages are compatible with the expected values (e.g. with the + * selected cipher suite, when the client validates the server's + * certificate). + * + * **Important caveats:** + * + * - The "minimal" engine does not check revocation status. The relevant + * extensions are ignored, and CRL or OCSP responses are not gathered + * or checked. + * + * - The "minimal" engine does not currently support Name Constraints + * (some basic functionality to handle sub-domains may be added in a + * later version). + * + * - The decoder is not "validating" in the sense that it won't reject + * some certificates with invalid field values when these fields are + * not actually processed. + */ + +/* + * X.509 error codes are in the 32..63 range. + */ + +/** \brief X.509 status: validation was successful; this is not actually + an error. */ +#define BR_ERR_X509_OK 32 + +/** \brief X.509 status: invalid value in an ASN.1 structure. */ +#define BR_ERR_X509_INVALID_VALUE 33 + +/** \brief X.509 status: truncated certificate. */ +#define BR_ERR_X509_TRUNCATED 34 + +/** \brief X.509 status: empty certificate chain (no certificate at all). */ +#define BR_ERR_X509_EMPTY_CHAIN 35 + +/** \brief X.509 status: decoding error: inner element extends beyond + outer element size. */ +#define BR_ERR_X509_INNER_TRUNC 36 + +/** \brief X.509 status: decoding error: unsupported tag class (application + or private). */ +#define BR_ERR_X509_BAD_TAG_CLASS 37 + +/** \brief X.509 status: decoding error: unsupported tag value. */ +#define BR_ERR_X509_BAD_TAG_VALUE 38 + +/** \brief X.509 status: decoding error: indefinite length. */ +#define BR_ERR_X509_INDEFINITE_LENGTH 39 + +/** \brief X.509 status: decoding error: extraneous element. */ +#define BR_ERR_X509_EXTRA_ELEMENT 40 + +/** \brief X.509 status: decoding error: unexpected element. */ +#define BR_ERR_X509_UNEXPECTED 41 + +/** \brief X.509 status: decoding error: expected constructed element, but + is primitive. */ +#define BR_ERR_X509_NOT_CONSTRUCTED 42 + +/** \brief X.509 status: decoding error: expected primitive element, but + is constructed. */ +#define BR_ERR_X509_NOT_PRIMITIVE 43 + +/** \brief X.509 status: decoding error: BIT STRING length is not multiple + of 8. */ +#define BR_ERR_X509_PARTIAL_BYTE 44 + +/** \brief X.509 status: decoding error: BOOLEAN value has invalid length. */ +#define BR_ERR_X509_BAD_BOOLEAN 45 + +/** \brief X.509 status: decoding error: value is off-limits. */ +#define BR_ERR_X509_OVERFLOW 46 + +/** \brief X.509 status: invalid distinguished name. */ +#define BR_ERR_X509_BAD_DN 47 + +/** \brief X.509 status: invalid date/time representation. */ +#define BR_ERR_X509_BAD_TIME 48 + +/** \brief X.509 status: certificate contains unsupported features that + cannot be ignored. */ +#define BR_ERR_X509_UNSUPPORTED 49 + +/** \brief X.509 status: key or signature size exceeds internal limits. */ +#define BR_ERR_X509_LIMIT_EXCEEDED 50 + +/** \brief X.509 status: key type does not match that which was expected. */ +#define BR_ERR_X509_WRONG_KEY_TYPE 51 + +/** \brief X.509 status: signature is invalid. */ +#define BR_ERR_X509_BAD_SIGNATURE 52 + +/** \brief X.509 status: validation time is unknown. */ +#define BR_ERR_X509_TIME_UNKNOWN 53 + +/** \brief X.509 status: certificate is expired or not yet valid. */ +#define BR_ERR_X509_EXPIRED 54 + +/** \brief X.509 status: issuer/subject DN mismatch in the chain. */ +#define BR_ERR_X509_DN_MISMATCH 55 + +/** \brief X.509 status: expected server name was not found in the chain. */ +#define BR_ERR_X509_BAD_SERVER_NAME 56 + +/** \brief X.509 status: unknown critical extension in certificate. */ +#define BR_ERR_X509_CRITICAL_EXTENSION 57 + +/** \brief X.509 status: not a CA, or path length constraint violation */ +#define BR_ERR_X509_NOT_CA 58 + +/** \brief X.509 status: Key Usage extension prohibits intended usage. */ +#define BR_ERR_X509_FORBIDDEN_KEY_USAGE 59 + +/** \brief X.509 status: public key found in certificate is too small. */ +#define BR_ERR_X509_WEAK_PUBLIC_KEY 60 + +/** \brief X.509 status: chain could not be linked to a trust anchor. */ +#define BR_ERR_X509_NOT_TRUSTED 62 + +/** + * \brief Aggregate structure for public keys. + */ +typedef struct { + /** \brief Key type: `BR_KEYTYPE_RSA` or `BR_KEYTYPE_EC` */ + unsigned char key_type; + /** \brief Actual public key. */ + union { + /** \brief RSA public key. */ + br_rsa_public_key rsa; + /** \brief EC public key. */ + br_ec_public_key ec; + } key; +} br_x509_pkey; + +/** + * \brief Distinguished Name (X.500) structure. + * + * The DN is DER-encoded. + */ +typedef struct { + /** \brief Encoded DN data. */ + unsigned char *data; + /** \brief Encoded DN length (in bytes). */ + size_t len; +} br_x500_name; + +/** + * \brief Trust anchor structure. + */ +typedef struct { + /** \brief Encoded DN (X.500 name). */ + br_x500_name dn; + /** \brief Anchor flags (e.g. `BR_X509_TA_CA`). */ + unsigned flags; + /** \brief Anchor public key. */ + br_x509_pkey pkey; +} br_x509_trust_anchor; + +/** + * \brief Trust anchor flag: CA. + * + * A "CA" anchor is deemed fit to verify signatures on certificates. + * A "non-CA" anchor is accepted only for direct trust (server's + * certificate name and key match the anchor). + */ +#define BR_X509_TA_CA 0x0001 + +/* + * Key type: combination of a basic key type (low 4 bits) and some + * optional flags. + * + * For a public key, the basic key type only is set. + * + * For an expected key type, the flags indicate the intended purpose(s) + * for the key; the basic key type may be set to 0 to indicate that any + * key type compatible with the indicated purpose is acceptable. + */ +/** \brief Key type: algorithm is RSA. */ +#define BR_KEYTYPE_RSA 1 +/** \brief Key type: algorithm is EC. */ +#define BR_KEYTYPE_EC 2 + +/** + * \brief Key type: usage is "key exchange". + * + * This value is combined (with bitwise OR) with the algorithm + * (`BR_KEYTYPE_RSA` or `BR_KEYTYPE_EC`) when informing the X.509 + * validation engine that it should find a public key of that type, + * fit for key exchanges (e.g. `TLS_RSA_*` and `TLS_ECDH_*` cipher + * suites). + */ +#define BR_KEYTYPE_KEYX 0x10 + +/** + * \brief Key type: usage is "signature". + * + * This value is combined (with bitwise OR) with the algorithm + * (`BR_KEYTYPE_RSA` or `BR_KEYTYPE_EC`) when informing the X.509 + * validation engine that it should find a public key of that type, + * fit for signatures (e.g. `TLS_ECDHE_*` cipher suites). + */ +#define BR_KEYTYPE_SIGN 0x20 + +/* + * start_chain Called when a new chain is started. If 'server_name' + * is not NULL and non-empty, then it is a name that + * should be looked for in the EE certificate (in the + * SAN extension as dNSName, or in the subjectDN's CN + * if there is no SAN extension). + * The caller ensures that the provided 'server_name' + * pointer remains valid throughout validation. + * + * start_cert Begins a new certificate in the chain. The provided + * length is in bytes; this is the total certificate length. + * + * append Get some additional bytes for the current certificate. + * + * end_cert Ends the current certificate. + * + * end_chain Called at the end of the chain. Returned value is + * 0 on success, or a non-zero error code. + * + * get_pkey Returns the EE certificate public key. + * + * For a complete chain, start_chain() and end_chain() are always + * called. For each certificate, start_cert(), some append() calls, then + * end_cert() are called, in that order. There may be no append() call + * at all if the certificate is empty (which is not valid but may happen + * if the peer sends exactly that). + * + * get_pkey() shall return a pointer to a structure that is valid as + * long as a new chain is not started. This may be a sub-structure + * within the context for the engine. This function MAY return a valid + * pointer to a public key even in some cases of validation failure, + * depending on the validation engine. + */ + +/** + * \brief Class type for an X.509 engine. + * + * A certificate chain validation uses a caller-allocated context, which + * contains the running state for that validation. Methods are called + * in due order: + * + * - `start_chain()` is called at the start of the validation. + * - Certificates are processed one by one, in SSL order (end-entity + * comes first). For each certificate, the following methods are + * called: + * + * - `start_cert()` at the beginning of the certificate. + * - `append()` is called zero, one or more times, to provide + * the certificate (possibly in chunks). + * - `end_cert()` at the end of the certificate. + * + * - `end_chain()` is called when the last certificate in the chain + * was processed. + * - `get_pkey()` is called after chain processing, if the chain + * validation was successful. + * + * A context structure may be reused; the `start_chain()` method shall + * ensure (re)initialisation. + */ +typedef struct br_x509_class_ br_x509_class; +struct br_x509_class_ { + /** + * \brief X.509 context size, in bytes. + */ + size_t context_size; + + /** + * \brief Start a new chain. + * + * This method shall set the vtable (first field) of the context + * structure. + * + * The `server_name`, if not `NULL`, will be considered as a + * fully qualified domain name, to be matched against the `dNSName` + * elements of the end-entity certificate's SAN extension (if there + * is no SAN, then the Common Name from the subjectDN will be used). + * If `server_name` is `NULL` then no such matching is performed. + * + * \param ctx validation context. + * \param server_name server name to match (or `NULL`). + */ + void (*start_chain)(const br_x509_class **ctx, + const char *server_name); + + /** + * \brief Start a new certificate. + * + * \param ctx validation context. + * \param length new certificate length (in bytes). + */ + void (*start_cert)(const br_x509_class **ctx, uint32_t length); + + /** + * \brief Receive some bytes for the current certificate. + * + * This function may be called several times in succession for + * a given certificate. The caller guarantees that for each + * call, `len` is not zero, and the sum of all chunk lengths + * for a certificate matches the total certificate length which + * was provided in the previous `start_cert()` call. + * + * If the new certificate is empty (no byte at all) then this + * function won't be called at all. + * + * \param ctx validation context. + * \param buf certificate data chunk. + * \param len certificate data chunk length (in bytes). + */ + void (*append)(const br_x509_class **ctx, + const unsigned char *buf, size_t len); + + /** + * \brief Finish the current certificate. + * + * This function is called when the end of the current certificate + * is reached. + * + * \param ctx validation context. + */ + void (*end_cert)(const br_x509_class **ctx); + + /** + * \brief Finish the chain. + * + * This function is called at the end of the chain. It shall + * return either 0 if the validation was successful, or a + * non-zero error code. The `BR_ERR_X509_*` constants are + * error codes, though other values may be possible. + * + * \param ctx validation context. + * \return 0 on success, or a non-zero error code. + */ + unsigned (*end_chain)(const br_x509_class **ctx); + + /** + * \brief Get the resulting end-entity public key. + * + * The decoded public key is returned. The returned pointer + * may be valid only as long as the context structure is + * unmodified, i.e. it may cease to be valid if the context + * is released or reused. + * + * This function _may_ return `NULL` if the validation failed. + * However, returning a public key does not mean that the + * validation was wholly successful; some engines may return + * a decoded public key even if the chain did not end on a + * trusted anchor. + * + * If validation succeeded and `usage` is not `NULL`, then + * `*usage` is filled with a combination of `BR_KEYTYPE_SIGN` + * and/or `BR_KEYTYPE_KEYX` that specifies the validated key + * usage types. It is the caller's responsibility to check + * that value against the intended use of the public key. + * + * \param ctx validation context. + * \return the end-entity public key, or `NULL`. + */ + const br_x509_pkey *(*get_pkey)( + const br_x509_class *const *ctx, unsigned *usages); +}; + +/** + * \brief The "known key" X.509 engine structure. + * + * The structure contents are opaque (they shall not be accessed directly), + * except for the first field (the vtable). + * + * The "known key" engine returns an externally configured public key, + * and totally ignores the certificate contents. + */ +typedef struct { + /** \brief Reference to the context vtable. */ + const br_x509_class *vtable; +#ifndef BR_DOXYGEN_IGNORE + br_x509_pkey pkey; + unsigned usages; +#endif +} br_x509_knownkey_context; + +/** + * \brief Class instance for the "known key" X.509 engine. + */ +extern const br_x509_class br_x509_knownkey_vtable; + +/** + * \brief Initialize a "known key" X.509 engine with a known RSA public key. + * + * The `usages` parameter indicates the allowed key usages for that key + * (`BR_KEYTYPE_KEYX` and/or `BR_KEYTYPE_SIGN`). + * + * The provided pointers are linked in, not copied, so they must remain + * valid while the public key may be in usage. + * + * \param ctx context to initialise. + * \param pk known public key. + * \param usages allowed key usages. + */ +void br_x509_knownkey_init_rsa(br_x509_knownkey_context *ctx, + const br_rsa_public_key *pk, unsigned usages); + +/** + * \brief Initialize a "known key" X.509 engine with a known EC public key. + * + * The `usages` parameter indicates the allowed key usages for that key + * (`BR_KEYTYPE_KEYX` and/or `BR_KEYTYPE_SIGN`). + * + * The provided pointers are linked in, not copied, so they must remain + * valid while the public key may be in usage. + * + * \param ctx context to initialise. + * \param pk known public key. + * \param usages allowed key usages. + */ +void br_x509_knownkey_init_ec(br_x509_knownkey_context *ctx, + const br_ec_public_key *pk, unsigned usages); + +#ifndef BR_DOXYGEN_IGNORE +/* + * The minimal X.509 engine has some state buffers which must be large + * enough to simultaneously accommodate: + * -- the public key extracted from the current certificate; + * -- the signature on the current certificate or on the previous + * certificate; + * -- the public key extracted from the EE certificate. + * + * We store public key elements in their raw unsigned big-endian + * encoding. We want to support up to RSA-4096 with a short (up to 64 + * bits) public exponent, thus a buffer for a public key must have + * length at least 520 bytes. Similarly, a RSA-4096 signature has length + * 512 bytes. + * + * Though RSA public exponents can formally be as large as the modulus + * (mathematically, even larger exponents would work, but PKCS#1 forbids + * them), exponents that do not fit on 32 bits are extremely rare, + * notably because some widespread implementations (e.g. Microsoft's + * CryptoAPI) don't support them. Moreover, large public exponent do not + * seem to imply any tangible security benefit, and they increase the + * cost of public key operations. The X.509 "minimal" engine will tolerate + * public exponents of arbitrary size as long as the modulus and the + * exponent can fit together in the dedicated buffer. + * + * EC public keys are shorter than RSA public keys; even with curve + * NIST P-521 (the largest curve we care to support), a public key is + * encoded over 133 bytes only. + */ +#define BR_X509_BUFSIZE_KEY 520 +#define BR_X509_BUFSIZE_SIG 512 +#endif + +/** + * \brief Type for receiving a name element. + * + * An array of such structures can be provided to the X.509 decoding + * engines. If the specified elements are found in the certificate + * subject DN or the SAN extension, then the name contents are copied + * as zero-terminated strings into the buffer. + * + * The decoder converts TeletexString and BMPString to UTF8String, and + * ensures that the resulting string is zero-terminated. If the string + * does not fit in the provided buffer, then the copy is aborted and an + * error is reported. + */ +typedef struct { + /** + * \brief Element OID. + * + * For X.500 name elements (to be extracted from the subject DN), + * this is the encoded OID for the requested name element; the + * first byte shall contain the length of the DER-encoded OID + * value, followed by the OID value (for instance, OID 2.5.4.3, + * for id-at-commonName, will be `03 55 04 03`). This is + * equivalent to full DER encoding with the length but without + * the tag. + * + * For SAN name elements, the first byte (`oid[0]`) has value 0, + * followed by another byte that matches the expected GeneralName + * tag. Allowed second byte values are then: + * + * - 1: `rfc822Name` + * + * - 2: `dNSName` + * + * - 6: `uniformResourceIdentifier` + * + * - 0: `otherName` + * + * If first and second byte are 0, then this is a SAN element of + * type `otherName`; the `oid[]` array should then contain, right + * after the two bytes of value 0, an encoded OID (with the same + * conventions as for X.500 name elements). If a match is found + * for that OID, then the corresponding name element will be + * extracted, as long as it is a supported string type. + */ + const unsigned char *oid; + + /** + * \brief Destination buffer. + */ + char *buf; + + /** + * \brief Length (in bytes) of the destination buffer. + * + * The buffer MUST NOT be smaller than 1 byte. + */ + size_t len; + + /** + * \brief Decoding status. + * + * Status is 0 if the name element was not found, 1 if it was + * found and decoded, or -1 on error. Error conditions include + * an unrecognised encoding, an invalid encoding, or a string + * too large for the destination buffer. + */ + int status; + +} br_name_element; + +/** + * \brief The "minimal" X.509 engine structure. + * + * The structure contents are opaque (they shall not be accessed directly), + * except for the first field (the vtable). + * + * The "minimal" engine performs a rudimentary but serviceable X.509 path + * validation. + */ +typedef struct { + const br_x509_class *vtable; + +#ifndef BR_DOXYGEN_IGNORE + /* Structure for returning the EE public key. */ + br_x509_pkey pkey; + + /* CPU for the T0 virtual machine. */ + struct { + uint32_t *dp; + uint32_t *rp; + const unsigned char *ip; + } cpu; + uint32_t dp_stack[32]; + uint32_t rp_stack[32]; + int err; + + /* Server name to match with the SAN / CN of the EE certificate. */ + const char *server_name; + + /* Validated key usages. */ + unsigned char key_usages; + + /* Explicitly set date and time. */ + uint32_t days, seconds; + + /* Current certificate length (in bytes). Set to 0 when the + certificate has been fully processed. */ + uint32_t cert_length; + + /* Number of certificates processed so far in the current chain. + It is incremented at the end of the processing of a certificate, + so it is 0 for the EE. */ + uint32_t num_certs; + + /* Certificate data chunk. */ + const unsigned char *hbuf; + size_t hlen; + + /* The pad serves as destination for various operations. */ + unsigned char pad[256]; + + /* Buffer for EE public key data. */ + unsigned char ee_pkey_data[BR_X509_BUFSIZE_KEY]; + + /* Buffer for currently decoded public key. */ + unsigned char pkey_data[BR_X509_BUFSIZE_KEY]; + + /* Signature type: signer key type, offset to the hash + function OID (in the T0 data block) and hash function + output length (TBS hash length). */ + unsigned char cert_signer_key_type; + uint16_t cert_sig_hash_oid; + unsigned char cert_sig_hash_len; + + /* Current/last certificate signature. */ + unsigned char cert_sig[BR_X509_BUFSIZE_SIG]; + uint16_t cert_sig_len; + + /* Minimum RSA key length (difference in bytes from 128). */ + int16_t min_rsa_size; + + /* Configured trust anchors. */ + const br_x509_trust_anchor *trust_anchors; + size_t trust_anchors_num; + + /* private context for dynamic callbacks */ + void *trust_anchor_dynamic_ctx; + /* Dynamic trust anchor, for on-the-fly loading of TAs */ + const br_x509_trust_anchor* (*trust_anchor_dynamic)(void *ctx, void *hashed_dn, size_t hashed_dn_len); + /* And a chance to free any dynamically allocated TA returned from above */ + void (*trust_anchor_dynamic_free)(void *ctx, const br_x509_trust_anchor *ta); + + /* + * Multi-hasher for the TBS. + */ + unsigned char do_mhash; + br_multihash_context mhash; + unsigned char tbs_hash[64]; + + /* + * Simple hasher for the subject/issuer DN. + */ + unsigned char do_dn_hash; + const br_hash_class *dn_hash_impl; + br_hash_compat_context dn_hash; + unsigned char current_dn_hash[64]; + unsigned char next_dn_hash[64]; + unsigned char saved_dn_hash[64]; + + /* + * Name elements to gather. + */ + br_name_element *name_elts; + size_t num_name_elts; + + /* + * Public key cryptography implementations (signature verification). + */ + br_rsa_pkcs1_vrfy irsa; + br_ecdsa_vrfy iecdsa; + const br_ec_impl *iec; +#endif + +} br_x509_minimal_context; + +/** + * \brief Class instance for the "minimal" X.509 engine. + */ +extern const br_x509_class br_x509_minimal_vtable; + +/** + * \brief Initialise a "minimal" X.509 engine. + * + * The `dn_hash_impl` parameter shall be a hash function internally used + * to match X.500 names (subject/issuer DN, and anchor names). Any standard + * hash function may be used, but a collision-resistant hash function is + * advised. + * + * After initialization, some implementations for signature verification + * (hash functions and signature algorithms) MUST be added. + * + * \param ctx context to initialise. + * \param dn_hash_impl hash function for DN comparisons. + * \param trust_anchors trust anchors. + * \param trust_anchors_num number of trust anchors. + */ +void br_x509_minimal_init(br_x509_minimal_context *ctx, + const br_hash_class *dn_hash_impl, + const br_x509_trust_anchor *trust_anchors, size_t trust_anchors_num); + +/** + * \brief Set the optional dynamic trust anchor lookup callbacks + * + * The dynamic trust anchor lookup callbacks allow an application to implement + * a non-memory resident trust anchor store. This can be useful on embedded + * systems where RAM is at a premium, but there is an external stable store, + * such as embedded flash or SD card, to keep many CA certificates. Set or + * leave these functions as NULL to not use such a feature. + * + * The dynamic routine will be passed in the hashed DN in question using the + * dn_hash_impl, and should compare this DN to its set of hashed known DNs. + * Of course, the same dn_hash_impl needs to be used in the dynamic routine. + * After the trust_anchor* is used, the dynamic_free callback is given a + * chance to deallocate its memory, if needed. + * + * \param ctx context to initialise. + * \param dynamic_ctx private context for the dynamic callback + * \param trust_anchor_dynamic provides a trust_anchor* for a hashed_dn + * \param trust_anchor_dynamic_free allows deallocation of returned TA + */ +static inline void +br_x509_minimal_set_dynamic(br_x509_minimal_context *ctx, void *dynamic_ctx, + const br_x509_trust_anchor* (*dynamic)(void *ctx, void *hashed_dn, size_t hashed_dn_len), + void (*dynamic_free)(void *ctx, const br_x509_trust_anchor *ta)) +{ + ctx->trust_anchor_dynamic_ctx = dynamic_ctx; + ctx->trust_anchor_dynamic = dynamic; + ctx->trust_anchor_dynamic_free = dynamic_free; +} + +/** + * \brief Set a supported hash function in an X.509 "minimal" engine. + * + * Hash functions are used with signature verification algorithms. + * Once initialised (with `br_x509_minimal_init()`), the context must + * be configured with the hash functions it shall support for that + * purpose. The hash function identifier MUST be one of the standard + * hash function identifiers (1 to 6, for MD5, SHA-1, SHA-224, SHA-256, + * SHA-384 and SHA-512). + * + * If `impl` is `NULL`, this _removes_ support for the designated + * hash function. + * + * \param ctx validation context. + * \param id hash function identifier (from 1 to 6). + * \param impl hash function implementation (or `NULL`). + */ +static inline void +br_x509_minimal_set_hash(br_x509_minimal_context *ctx, + int id, const br_hash_class *impl) +{ + br_multihash_setimpl(&ctx->mhash, id, impl); +} + +/** + * \brief Set a RSA signature verification implementation in the X.509 + * "minimal" engine. + * + * Once initialised (with `br_x509_minimal_init()`), the context must + * be configured with the signature verification implementations that + * it is supposed to support. If `irsa` is `0`, then the RSA support + * is disabled. + * + * \param ctx validation context. + * \param irsa RSA signature verification implementation (or `0`). + */ +static inline void +br_x509_minimal_set_rsa(br_x509_minimal_context *ctx, + br_rsa_pkcs1_vrfy irsa) +{ + ctx->irsa = irsa; +} + +/** + * \brief Set a ECDSA signature verification implementation in the X.509 + * "minimal" engine. + * + * Once initialised (with `br_x509_minimal_init()`), the context must + * be configured with the signature verification implementations that + * it is supposed to support. + * + * If `iecdsa` is `0`, then this call disables ECDSA support; in that + * case, `iec` may be `NULL`. Otherwise, `iecdsa` MUST point to a function + * that verifies ECDSA signatures with format "asn1", and it will use + * `iec` as underlying elliptic curve support. + * + * \param ctx validation context. + * \param iec elliptic curve implementation (or `NULL`). + * \param iecdsa ECDSA implementation (or `0`). + */ +static inline void +br_x509_minimal_set_ecdsa(br_x509_minimal_context *ctx, + const br_ec_impl *iec, br_ecdsa_vrfy iecdsa) +{ + ctx->iecdsa = iecdsa; + ctx->iec = iec; +} + +/** + * \brief Initialise a "minimal" X.509 engine with default algorithms. + * + * This function performs the same job as `br_x509_minimal_init()`, but + * also sets implementations for RSA, ECDSA, and the standard hash + * functions. + * + * \param ctx context to initialise. + * \param trust_anchors trust anchors. + * \param trust_anchors_num number of trust anchors. + */ +void br_x509_minimal_init_full(br_x509_minimal_context *ctx, + const br_x509_trust_anchor *trust_anchors, size_t trust_anchors_num); + +/** + * \brief Set the validation time for the X.509 "minimal" engine. + * + * The validation time is set as two 32-bit integers, for days and + * seconds since a fixed epoch: + * + * - Days are counted in a proleptic Gregorian calendar since + * January 1st, 0 AD. Year "0 AD" is the one that preceded "1 AD"; + * it is also traditionally known as "1 BC". + * + * - Seconds are counted since midnight, from 0 to 86400 (a count of + * 86400 is possible only if a leap second happened). + * + * The validation date and time is understood in the UTC time zone. + * + * If the validation date and time are not explicitly set, but BearSSL + * was compiled with support for the system clock on the underlying + * platform, then the current time will automatically be used. Otherwise, + * not setting the validation date and time implies a validation + * failure (except in case of direct trust of the EE key). + * + * \param ctx validation context. + * \param days days since January 1st, 0 AD (Gregorian calendar). + * \param seconds seconds since midnight (0 to 86400). + */ +static inline void +br_x509_minimal_set_time(br_x509_minimal_context *ctx, + uint32_t days, uint32_t seconds) +{ + ctx->days = days; + ctx->seconds = seconds; +} + +/** + * \brief Set the minimal acceptable length for RSA keys (X.509 "minimal" + * engine). + * + * The RSA key length is expressed in bytes. The default minimum key + * length is 128 bytes, corresponding to 1017 bits. RSA keys shorter + * than the configured length will be rejected, implying validation + * failure. This setting applies to keys extracted from certificates + * (both end-entity, and intermediate CA) but not to "CA" trust anchors. + * + * \param ctx validation context. + * \param byte_length minimum RSA key length, **in bytes** (not bits). + */ +static inline void +br_x509_minimal_set_minrsa(br_x509_minimal_context *ctx, int byte_length) +{ + ctx->min_rsa_size = (int16_t)(byte_length - 128); +} + +/** + * \brief Set the name elements to gather. + * + * The provided array is linked in the context. The elements are + * gathered from the EE certificate. If the same element type is + * requested several times, then the relevant structures will be filled + * in the order the matching values are encountered in the certificate. + * + * \param ctx validation context. + * \param elts array of name element structures to fill. + * \param num_elts number of name element structures to fill. + */ +static inline void +br_x509_minimal_set_name_elements(br_x509_minimal_context *ctx, + br_name_element *elts, size_t num_elts) +{ + ctx->name_elts = elts; + ctx->num_name_elts = num_elts; +} + +/** + * \brief X.509 decoder context. + * + * This structure is _not_ for X.509 validation, but for extracting + * names and public keys from encoded certificates. Intended usage is + * to use (self-signed) certificates as trust anchors. + * + * Contents are opaque and shall not be accessed directly. + */ +typedef struct { + +#ifndef BR_DOXYGEN_IGNORE + /* Structure for returning the public key. */ + br_x509_pkey pkey; + + /* CPU for the T0 virtual machine. */ + struct { + uint32_t *dp; + uint32_t *rp; + const unsigned char *ip; + } cpu; + uint32_t dp_stack[32]; + uint32_t rp_stack[32]; + int err; + + /* The pad serves as destination for various operations. */ + unsigned char pad[256]; + + /* Flag set when decoding succeeds. */ + unsigned char decoded; + + /* Validity dates. */ + uint32_t notbefore_days, notbefore_seconds; + uint32_t notafter_days, notafter_seconds; + + /* The "CA" flag. This is set to true if the certificate contains + a Basic Constraints extension that asserts CA status. */ + unsigned char isCA; + + /* DN processing: the subject DN is extracted and pushed to the + provided callback. */ + unsigned char copy_dn; + void *append_dn_ctx; + void (*append_dn)(void *ctx, const void *buf, size_t len); + + /* Certificate data chunk. */ + const unsigned char *hbuf; + size_t hlen; + + /* Buffer for decoded public key. */ + unsigned char pkey_data[BR_X509_BUFSIZE_KEY]; + + /* Type of key and hash function used in the certificate signature. */ + unsigned char signer_key_type; + unsigned char signer_hash_id; +#endif + +} br_x509_decoder_context_libmail; + +/** + * \brief Initialise an X.509 decoder context for processing a new + * certificate. + * + * The `append_dn()` callback (with opaque context `append_dn_ctx`) + * will be invoked to receive, chunk by chunk, the certificate's + * subject DN. If `append_dn` is `0` then the subject DN will be + * ignored. + * + * \param ctx X.509 decoder context to initialise. + * \param append_dn DN receiver callback (or `0`). + * \param append_dn_ctx context for the DN receiver callback. + */ +void br_x509_decoder_init(br_x509_decoder_context_libmail *ctx, + void (*append_dn)(void *ctx, const void *buf, size_t len), + void *append_dn_ctx); + +/** + * \brief Push some certificate bytes into a decoder context. + * + * If `len` is non-zero, then that many bytes are pushed, from address + * `data`, into the provided decoder context. + * + * \param ctx X.509 decoder context. + * \param data certificate data chunk. + * \param len certificate data chunk length (in bytes). + */ +void br_x509_decoder_push_libmail(br_x509_decoder_context_libmail *ctx, + const void *data, size_t len); + +/** + * \brief Obtain the decoded public key. + * + * Returned value is a pointer to a structure internal to the decoder + * context; releasing or reusing the decoder context invalidates that + * structure. + * + * If decoding was not finished, or failed, then `NULL` is returned. + * + * \param ctx X.509 decoder context. + * \return the public key, or `NULL` on unfinished/error. + */ +static inline br_x509_pkey * +br_x509_decoder_get_pkey(br_x509_decoder_context_libmail *ctx) +{ + if (ctx->decoded && ctx->err == 0) { + return &ctx->pkey; + } else { + return NULL; + } +} + +/** + * \brief Get decoder error status. + * + * If no error was reported yet but the certificate decoding is not + * finished, then the error code is `BR_ERR_X509_TRUNCATED`. If decoding + * was successful, then 0 is returned. + * + * \param ctx X.509 decoder context. + * \return 0 on successful decoding, or a non-zero error code. + */ +static inline int +br_x509_decoder_last_error(br_x509_decoder_context_libmail *ctx) +{ + if (ctx->err != 0) { + return ctx->err; + } + if (!ctx->decoded) { + return BR_ERR_X509_TRUNCATED; + } + return 0; +} + +/** + * \brief Get the "isCA" flag from an X.509 decoder context. + * + * This flag is set if the decoded certificate claims to be a CA through + * a Basic Constraints extension. This flag should not be read before + * decoding completed successfully. + * + * \param ctx X.509 decoder context. + * \return the "isCA" flag. + */ +static inline int +br_x509_decoder_isCA(br_x509_decoder_context_libmail *ctx) +{ + return ctx->isCA; +} + +/** + * \brief Get the issuing CA key type (type of algorithm used to sign the + * decoded certificate). + * + * This is `BR_KEYTYPE_RSA` or `BR_KEYTYPE_EC`. The value 0 is returned + * if the signature type was not recognised. + * + * \param ctx X.509 decoder context. + * \return the issuing CA key type. + */ +static inline int +br_x509_decoder_get_signer_key_type(br_x509_decoder_context_libmail *ctx) +{ + return ctx->signer_key_type; +} + +/** + * \brief Get the identifier for the hash function used to sign the decoded + * certificate. + * + * This is 0 if the hash function was not recognised. + * + * \param ctx X.509 decoder context. + * \return the signature hash function identifier. + */ +static inline int +br_x509_decoder_get_signer_hash_id(br_x509_decoder_context_libmail *ctx) +{ + return ctx->signer_hash_id; +} + +/** + * \brief Type for an X.509 certificate (DER-encoded). + */ +typedef struct { + /** \brief The DER-encoded certificate data. */ + unsigned char *data; + /** \brief The DER-encoded certificate length (in bytes). */ + size_t data_len; +} br_x509_certificate; + +/** + * \brief Private key decoder context. + * + * The private key decoder recognises RSA and EC private keys, either in + * their raw, DER-encoded format, or wrapped in an unencrypted PKCS#8 + * archive (again DER-encoded). + * + * Structure contents are opaque and shall not be accessed directly. + */ +typedef struct { +#ifndef BR_DOXYGEN_IGNORE + /* Structure for returning the private key. */ + union { + br_rsa_private_key rsa; + br_ec_private_key ec; + } key; + + /* CPU for the T0 virtual machine. */ + struct { + uint32_t *dp; + uint32_t *rp; + const unsigned char *ip; + } cpu; + uint32_t dp_stack[32]; + uint32_t rp_stack[32]; + int err; + + /* Private key data chunk. */ + const unsigned char *hbuf; + size_t hlen; + + /* The pad serves as destination for various operations. */ + unsigned char pad[256]; + + /* Decoded key type; 0 until decoding is complete. */ + unsigned char key_type; + + /* Buffer for the private key elements. It shall be large enough + to accommodate all elements for a RSA-4096 private key (roughly + five 2048-bit integers, possibly a bit more). */ + unsigned char key_data[3 * BR_X509_BUFSIZE_SIG]; +#endif +} br_skey_decoder_context; + +/** + * \brief Initialise a private key decoder context. + * + * \param ctx key decoder context to initialise. + */ +void br_skey_decoder_init(br_skey_decoder_context *ctx); + +/** + * \brief Push some data bytes into a private key decoder context. + * + * If `len` is non-zero, then that many data bytes, starting at address + * `data`, are pushed into the decoder. + * + * \param ctx key decoder context. + * \param data private key data chunk. + * \param len private key data chunk length (in bytes). + */ +void br_skey_decoder_push(br_skey_decoder_context *ctx, + const void *data, size_t len); + +/** + * \brief Get the decoding status for a private key. + * + * Decoding status is 0 on success, or a non-zero error code. If the + * decoding is unfinished when this function is called, then the + * status code `BR_ERR_X509_TRUNCATED` is returned. + * + * \param ctx key decoder context. + * \return 0 on successful decoding, or a non-zero error code. + */ +static inline int +br_skey_decoder_last_error(const br_skey_decoder_context *ctx) +{ + if (ctx->err != 0) { + return ctx->err; + } + if (ctx->key_type == 0) { + return BR_ERR_X509_TRUNCATED; + } + return 0; +} + +/** + * \brief Get the decoded private key type. + * + * Private key type is `BR_KEYTYPE_RSA` or `BR_KEYTYPE_EC`. If decoding is + * not finished or failed, then 0 is returned. + * + * \param ctx key decoder context. + * \return decoded private key type, or 0. + */ +static inline int +br_skey_decoder_key_type(const br_skey_decoder_context *ctx) +{ + if (ctx->err == 0) { + return ctx->key_type; + } else { + return 0; + } +} + +/** + * \brief Get the decoded RSA private key. + * + * This function returns `NULL` if the decoding failed, or is not + * finished, or the key is not RSA. The returned pointer references + * structures within the context that can become invalid if the context + * is reused or released. + * + * \param ctx key decoder context. + * \return decoded RSA private key, or `NULL`. + */ +static inline const br_rsa_private_key * +br_skey_decoder_get_rsa(const br_skey_decoder_context *ctx) +{ + if (ctx->err == 0 && ctx->key_type == BR_KEYTYPE_RSA) { + return &ctx->key.rsa; + } else { + return NULL; + } +} + +/** + * \brief Get the decoded EC private key. + * + * This function returns `NULL` if the decoding failed, or is not + * finished, or the key is not EC. The returned pointer references + * structures within the context that can become invalid if the context + * is reused or released. + * + * \param ctx key decoder context. + * \return decoded EC private key, or `NULL`. + */ +static inline const br_ec_private_key * +br_skey_decoder_get_ec(const br_skey_decoder_context *ctx) +{ + if (ctx->err == 0 && ctx->key_type == BR_KEYTYPE_EC) { + return &ctx->key.ec; + } else { + return NULL; + } +} + +/** + * \brief Public key decoder context. + * + * The public key decoder recognises RSA and EC private keys, either in + * their raw, DER-encoded format, or wrapped in an unencrypted PKCS#8 + * archive (again DER-encoded). + * + * Structure contents are opaque and shall not be accessed directly. + */ +typedef struct { +#ifndef BR_DOXYGEN_IGNORE + /* Structure for returning the private key. */ + union { + br_rsa_public_key rsa; + br_ec_public_key ec; + } key; + + /* CPU for the T0 virtual machine. */ + struct { + uint32_t *dp; + uint32_t *rp; + const unsigned char *ip; + } cpu; + uint32_t dp_stack[32]; + uint32_t rp_stack[32]; + int err; + + /* Private key data chunk. */ + const unsigned char *hbuf; + size_t hlen; + + /* The pad serves as destination for various operations. */ + unsigned char pad[256]; + + /* Decoded key type; 0 until decoding is complete. */ + unsigned char key_type; + + /* Buffer for the private key elements. It shall be large enough + to accommodate all elements for a RSA-4096 private key (roughly + five 2048-bit integers, possibly a bit more). */ + unsigned char key_data[3 * BR_X509_BUFSIZE_SIG]; +#endif +} br_pkey_decoder_context; + + +/** + * \brief Initialise a public key decoder context. + * + * \param ctx key decoder context to initialise. + */ +void br_pkey_decoder_init(br_pkey_decoder_context *ctx); + +/** + * \brief Push some data bytes into a public key decoder context. + * + * If `len` is non-zero, then that many data bytes, starting at address + * `data`, are pushed into the decoder. + * + * \param ctx key decoder context. + * \param data private key data chunk. + * \param len private key data chunk length (in bytes). + */ +void br_pkey_decoder_push(br_pkey_decoder_context *ctx, + const void *data, size_t len); + +/** + * \brief Get the decoding status for a public key. + * + * Decoding status is 0 on success, or a non-zero error code. If the + * decoding is unfinished when this function is called, then the + * status code `BR_ERR_X509_TRUNCATED` is returned. + * + * \param ctx key decoder context. + * \return 0 on successful decoding, or a non-zero error code. + */ +static inline int +br_pkey_decoder_last_error(const br_pkey_decoder_context *ctx) +{ + if (ctx->err != 0) { + return ctx->err; + } + if (ctx->key_type == 0) { + return BR_ERR_X509_TRUNCATED; + } + return 0; +} + +/** + * \brief Get the decoded public key type. + * + * Public key type is `BR_KEYTYPE_RSA` or `BR_KEYTYPE_EC`. If decoding is + * not finished or failed, then 0 is returned. + * + * \param ctx key decoder context. + * \return decoded private key type, or 0. + */ +static inline int +br_pkey_decoder_key_type(const br_pkey_decoder_context *ctx) +{ + if (ctx->err == 0) { + return ctx->key_type; + } else { + return 0; + } +} + +/** + * \brief Get the decoded RSA public key. + * + * This function returns `NULL` if the decoding failed, or is not + * finished, or the key is not RSA. The returned pointer references + * structures within the context that can become invalid if the context + * is reused or released. + * + * \param ctx key decoder context. + * \return decoded RSA public key, or `NULL`. + */ +static inline const br_rsa_public_key * +br_pkey_decoder_get_rsa(const br_pkey_decoder_context *ctx) +{ + if (ctx->err == 0 && ctx->key_type == BR_KEYTYPE_RSA) { + return &ctx->key.rsa; + } else { + return NULL; + } +} + +/** + * \brief Get the decoded EC private key. + * + * This function returns `NULL` if the decoding failed, or is not + * finished, or the key is not EC. The returned pointer references + * structures within the context that can become invalid if the context + * is reused or released. + * + * \param ctx key decoder context. + * \return decoded EC private key, or `NULL`. + */ +static inline const br_ec_public_key * +br_pkey_decoder_get_ec(const br_pkey_decoder_context *ctx) +{ + if (ctx->err == 0 && ctx->key_type == BR_KEYTYPE_EC) { + return &ctx->key.ec; + } else { + return NULL; + } +} + +/** + * \brief Encode an RSA private key (raw DER format). + * + * This function encodes the provided key into the "raw" format specified + * in PKCS#1 (RFC 8017, Appendix C, type `RSAPrivateKey`), with DER + * encoding rules. + * + * The key elements are: + * + * - `sk`: the private key (`p`, `q`, `dp`, `dq` and `iq`) + * + * - `pk`: the public key (`n` and `e`) + * + * - `d` (size: `dlen` bytes): the private exponent + * + * The public key elements, and the private exponent `d`, can be + * recomputed from the private key (see `br_rsa_compute_modulus()`, + * `br_rsa_compute_pubexp()` and `br_rsa_compute_privexp()`). + * + * If `dest` is not `NULL`, then the encoded key is written at that + * address, and the encoded length (in bytes) is returned. If `dest` is + * `NULL`, then nothing is written, but the encoded length is still + * computed and returned. + * + * \param dest the destination buffer (or `NULL`). + * \param sk the RSA private key. + * \param pk the RSA public key. + * \param d the RSA private exponent. + * \param dlen the RSA private exponent length (in bytes). + * \return the encoded key length (in bytes). + */ +size_t br_encode_rsa_raw_der(void *dest, const br_rsa_private_key *sk, + const br_rsa_public_key *pk, const void *d, size_t dlen); + +/** + * \brief Encode an RSA private key (PKCS#8 DER format). + * + * This function encodes the provided key into the PKCS#8 format + * (RFC 5958, type `OneAsymmetricKey`). It wraps around the "raw DER" + * format for the RSA key, as implemented by `br_encode_rsa_raw_der()`. + * + * The key elements are: + * + * - `sk`: the private key (`p`, `q`, `dp`, `dq` and `iq`) + * + * - `pk`: the public key (`n` and `e`) + * + * - `d` (size: `dlen` bytes): the private exponent + * + * The public key elements, and the private exponent `d`, can be + * recomputed from the private key (see `br_rsa_compute_modulus()`, + * `br_rsa_compute_pubexp()` and `br_rsa_compute_privexp()`). + * + * If `dest` is not `NULL`, then the encoded key is written at that + * address, and the encoded length (in bytes) is returned. If `dest` is + * `NULL`, then nothing is written, but the encoded length is still + * computed and returned. + * + * \param dest the destination buffer (or `NULL`). + * \param sk the RSA private key. + * \param pk the RSA public key. + * \param d the RSA private exponent. + * \param dlen the RSA private exponent length (in bytes). + * \return the encoded key length (in bytes). + */ +size_t br_encode_rsa_pkcs8_der(void *dest, const br_rsa_private_key *sk, + const br_rsa_public_key *pk, const void *d, size_t dlen); + +/** + * \brief Encode an EC private key (raw DER format). + * + * This function encodes the provided key into the "raw" format specified + * in RFC 5915 (type `ECPrivateKey`), with DER encoding rules. + * + * The private key is provided in `sk`, the public key being `pk`. If + * `pk` is `NULL`, then the encoded key will not include the public key + * in its `publicKey` field (which is nominally optional). + * + * If `dest` is not `NULL`, then the encoded key is written at that + * address, and the encoded length (in bytes) is returned. If `dest` is + * `NULL`, then nothing is written, but the encoded length is still + * computed and returned. + * + * If the key cannot be encoded (e.g. because there is no known OBJECT + * IDENTIFIER for the used curve), then 0 is returned. + * + * \param dest the destination buffer (or `NULL`). + * \param sk the EC private key. + * \param pk the EC public key (or `NULL`). + * \return the encoded key length (in bytes), or 0. + */ +size_t br_encode_ec_raw_der(void *dest, + const br_ec_private_key *sk, const br_ec_public_key *pk); + +/** + * \brief Encode an EC private key (PKCS#8 DER format). + * + * This function encodes the provided key into the PKCS#8 format + * (RFC 5958, type `OneAsymmetricKey`). The curve is identified + * by an OID provided as parameters to the `privateKeyAlgorithm` + * field. The private key value (contents of the `privateKey` field) + * contains the DER encoding of the `ECPrivateKey` type defined in + * RFC 5915, without the `parameters` field (since they would be + * redundant with the information in `privateKeyAlgorithm`). + * + * The private key is provided in `sk`, the public key being `pk`. If + * `pk` is not `NULL`, then the encoded public key is included in the + * `publicKey` field of the private key value (but not in the `publicKey` + * field of the PKCS#8 `OneAsymmetricKey` wrapper). + * + * If `dest` is not `NULL`, then the encoded key is written at that + * address, and the encoded length (in bytes) is returned. If `dest` is + * `NULL`, then nothing is written, but the encoded length is still + * computed and returned. + * + * If the key cannot be encoded (e.g. because there is no known OBJECT + * IDENTIFIER for the used curve), then 0 is returned. + * + * \param dest the destination buffer (or `NULL`). + * \param sk the EC private key. + * \param pk the EC public key (or `NULL`). + * \return the encoded key length (in bytes), or 0. + */ +size_t br_encode_ec_pkcs8_der(void *dest, + const br_ec_private_key *sk, const br_ec_public_key *pk); + +/** + * \brief PEM banner for RSA private key (raw). + */ +#define BR_ENCODE_PEM_RSA_RAW "RSA PRIVATE KEY" + +/** + * \brief PEM banner for EC private key (raw). + */ +#define BR_ENCODE_PEM_EC_RAW "EC PRIVATE KEY" + +/** + * \brief PEM banner for an RSA or EC private key in PKCS#8 format. + */ +#define BR_ENCODE_PEM_PKCS8 "PRIVATE KEY" + +#ifdef __cplusplus +} +#endif + +#endif + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ccm.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ccm.c new file mode 100644 index 000000000..ceba88d7c --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ccm.c @@ -0,0 +1,351 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* + * Implementation Notes + * ==================== + * + * The combined CTR + CBC-MAC functions can only handle full blocks, + * so some buffering is necessary. + * + * - 'ptr' contains a value from 0 to 15, which is the number of bytes + * accumulated in buf[] that still needs to be processed with the + * current CBC-MAC computation. + * + * - When processing the message itself, CTR encryption/decryption is + * also done at the same time. The first 'ptr' bytes of buf[] then + * contains the plaintext bytes, while the last '16 - ptr' bytes of + * buf[] are the remnants of the stream block, to be used against + * the next input bytes, when available. When 'ptr' is 0, the + * contents of buf[] are to be ignored. + * + * - The current counter and running CBC-MAC values are kept in 'ctr' + * and 'cbcmac', respectively. + */ + +/* see bearssl_block.h */ +void +br_ccm_init(br_ccm_context *ctx, const br_block_ctrcbc_class **bctx) +{ + ctx->bctx = bctx; +} + +/* see bearssl_block.h */ +int +br_ccm_reset(br_ccm_context *ctx, const void *nonce, size_t nonce_len, + uint64_t aad_len, uint64_t data_len, size_t tag_len) +{ + unsigned char tmp[16]; + unsigned u, q; + + if (nonce_len < 7 || nonce_len > 13) { + return 0; + } + if (tag_len < 4 || tag_len > 16 || (tag_len & 1) != 0) { + return 0; + } + q = 15 - (unsigned)nonce_len; + ctx->tag_len = tag_len; + + /* + * Block B0, to start CBC-MAC. + */ + tmp[0] = (aad_len > 0 ? 0x40 : 0x00) + | (((unsigned)tag_len - 2) << 2) + | (q - 1); + memcpy(tmp + 1, nonce, nonce_len); + for (u = 0; u < q; u ++) { + tmp[15 - u] = (unsigned char)data_len; + data_len >>= 8; + } + if (data_len != 0) { + /* + * If the data length was not entirely consumed in the + * loop above, then it exceeds the maximum limit of + * q bytes (when encoded). + */ + return 0; + } + + /* + * Start CBC-MAC. + */ + memset(ctx->cbcmac, 0, sizeof ctx->cbcmac); + (*ctx->bctx)->mac(ctx->bctx, ctx->cbcmac, tmp, sizeof tmp); + + /* + * Assemble AAD length header. + */ + if ((aad_len >> 32) != 0) { + ctx->buf[0] = 0xFF; + ctx->buf[1] = 0xFF; + br_enc64be(ctx->buf + 2, aad_len); + ctx->ptr = 10; + } else if (aad_len >= 0xFF00) { + ctx->buf[0] = 0xFF; + ctx->buf[1] = 0xFE; + br_enc32be(ctx->buf + 2, (uint32_t)aad_len); + ctx->ptr = 6; + } else if (aad_len > 0) { + br_enc16be(ctx->buf, (unsigned)aad_len); + ctx->ptr = 2; + } else { + ctx->ptr = 0; + } + + /* + * Make initial counter value and compute tag mask. + */ + ctx->ctr[0] = q - 1; + memcpy(ctx->ctr + 1, nonce, nonce_len); + memset(ctx->ctr + 1 + nonce_len, 0, q); + memset(ctx->tagmask, 0, sizeof ctx->tagmask); + (*ctx->bctx)->ctr(ctx->bctx, ctx->ctr, + ctx->tagmask, sizeof ctx->tagmask); + + return 1; +} + +/* see bearssl_block.h */ +void +br_ccm_aad_inject(br_ccm_context *ctx, const void *data, size_t len) +{ + const unsigned char *dbuf; + size_t ptr; + + dbuf = data; + + /* + * Complete partial block, if needed. + */ + ptr = ctx->ptr; + if (ptr != 0) { + size_t clen; + + clen = (sizeof ctx->buf) - ptr; + if (clen > len) { + memcpy(ctx->buf + ptr, dbuf, len); + ctx->ptr = ptr + len; + return; + } + memcpy(ctx->buf + ptr, dbuf, clen); + dbuf += clen; + len -= clen; + (*ctx->bctx)->mac(ctx->bctx, ctx->cbcmac, + ctx->buf, sizeof ctx->buf); + } + + /* + * Process complete blocks. + */ + ptr = len & 15; + len -= ptr; + (*ctx->bctx)->mac(ctx->bctx, ctx->cbcmac, dbuf, len); + dbuf += len; + + /* + * Copy last partial block in the context buffer. + */ + memcpy(ctx->buf, dbuf, ptr); + ctx->ptr = ptr; +} + +/* see bearssl_block.h */ +void +br_ccm_flip(br_ccm_context *ctx) +{ + size_t ptr; + + /* + * Complete AAD partial block with zeros, if necessary. + */ + ptr = ctx->ptr; + if (ptr != 0) { + memset(ctx->buf + ptr, 0, (sizeof ctx->buf) - ptr); + (*ctx->bctx)->mac(ctx->bctx, ctx->cbcmac, + ctx->buf, sizeof ctx->buf); + ctx->ptr = 0; + } + + /* + * Counter was already set by br_ccm_reset(). + */ +} + +/* see bearssl_block.h */ +void +br_ccm_run(br_ccm_context *ctx, int encrypt, void *data, size_t len) +{ + unsigned char *dbuf; + size_t ptr; + + dbuf = data; + + /* + * Complete a partial block, if any: ctx->buf[] contains + * ctx->ptr plaintext bytes (already reported), and the other + * bytes are CTR stream output. + */ + ptr = ctx->ptr; + if (ptr != 0) { + size_t clen; + size_t u; + + clen = (sizeof ctx->buf) - ptr; + if (clen > len) { + clen = len; + } + if (encrypt) { + for (u = 0; u < clen; u ++) { + unsigned w, x; + + w = ctx->buf[ptr + u]; + x = dbuf[u]; + ctx->buf[ptr + u] = x; + dbuf[u] = w ^ x; + } + } else { + for (u = 0; u < clen; u ++) { + unsigned w; + + w = ctx->buf[ptr + u] ^ dbuf[u]; + dbuf[u] = w; + ctx->buf[ptr + u] = w; + } + } + dbuf += clen; + len -= clen; + ptr += clen; + if (ptr < sizeof ctx->buf) { + ctx->ptr = ptr; + return; + } + (*ctx->bctx)->mac(ctx->bctx, + ctx->cbcmac, ctx->buf, sizeof ctx->buf); + } + + /* + * Process all complete blocks. Note that the ctrcbc API is for + * encrypt-then-MAC (CBC-MAC is computed over the encrypted + * blocks) while CCM uses MAC-and-encrypt (CBC-MAC is computed + * over the plaintext blocks). Therefore, we need to use the + * _decryption_ function for encryption, and the encryption + * function for decryption (this works because CTR encryption + * and decryption are identical, so the choice really is about + * computing the CBC-MAC before or after XORing with the CTR + * stream). + */ + ptr = len & 15; + len -= ptr; + if (encrypt) { + (*ctx->bctx)->decrypt(ctx->bctx, ctx->ctr, ctx->cbcmac, + dbuf, len); + } else { + (*ctx->bctx)->encrypt(ctx->bctx, ctx->ctr, ctx->cbcmac, + dbuf, len); + } + dbuf += len; + + /* + * If there is some remaining data, then we need to compute an + * extra block of CTR stream. + */ + if (ptr != 0) { + size_t u; + + memset(ctx->buf, 0, sizeof ctx->buf); + (*ctx->bctx)->ctr(ctx->bctx, ctx->ctr, + ctx->buf, sizeof ctx->buf); + if (encrypt) { + for (u = 0; u < ptr; u ++) { + unsigned w, x; + + w = ctx->buf[u]; + x = dbuf[u]; + ctx->buf[u] = x; + dbuf[u] = w ^ x; + } + } else { + for (u = 0; u < ptr; u ++) { + unsigned w; + + w = ctx->buf[u] ^ dbuf[u]; + dbuf[u] = w; + ctx->buf[u] = w; + } + } + } + ctx->ptr = ptr; +} + +/* see bearssl_block.h */ +size_t +br_ccm_get_tag(br_ccm_context *ctx, void *tag) +{ + size_t ptr; + size_t u; + + /* + * If there is some buffered data, then we need to pad it with + * zeros and finish up CBC-MAC. + */ + ptr = ctx->ptr; + if (ptr != 0) { + memset(ctx->buf + ptr, 0, (sizeof ctx->buf) - ptr); + (*ctx->bctx)->mac(ctx->bctx, ctx->cbcmac, + ctx->buf, sizeof ctx->buf); + } + + /* + * XOR the tag mask into the CBC-MAC output. + */ + for (u = 0; u < ctx->tag_len; u ++) { + ctx->cbcmac[u] ^= ctx->tagmask[u]; + } + memcpy(tag, ctx->cbcmac, ctx->tag_len); + return ctx->tag_len; +} + +/* see bearssl_block.h */ +uint32_t +br_ccm_check_tag(br_ccm_context *ctx, const void *tag) +{ + unsigned char tmp[16]; + size_t u, tag_len; + uint32_t z; + + tag_len = br_ccm_get_tag(ctx, tmp); + z = 0; + for (u = 0; u < tag_len; u ++) { + z |= tmp[u] ^ ((const unsigned char *)tag)[u]; + } + return EQ0(z); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ccopy.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ccopy.c new file mode 100644 index 000000000..cbbd5fddb --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ccopy.c @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +void +br_ccopy(uint32_t ctl, void *dst, const void *src, size_t len) +{ + unsigned char *d; + const unsigned char *s; + + d = dst; + s = src; + while (len -- > 0) { + uint32_t x, y; + + x = *s ++; + y = *d; + *d = MUX(ctl, x, y); + d ++; + } +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/chacha20_ct.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/chacha20_ct.c new file mode 100644 index 000000000..d981d12d8 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/chacha20_ct.c @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_block.h */ +uint32_t +br_chacha20_ct_run(const void *key, + const void *iv, uint32_t cc, void *data, size_t len) +{ + unsigned char *buf; + uint32_t kw[8], ivw[3]; + size_t u; + + static const uint32_t CW[] = { + 0x61707865, 0x3320646e, 0x79622d32, 0x6b206574 + }; + + buf = data; + for (u = 0; u < 8; u ++) { + kw[u] = br_dec32le((const unsigned char *)key + (u << 2)); + } + for (u = 0; u < 3; u ++) { + ivw[u] = br_dec32le((const unsigned char *)iv + (u << 2)); + } + while (len > 0) { + uint32_t state[16]; + int i; + size_t clen; + unsigned char tmp[64]; + + memcpy(&state[0], CW, sizeof CW); + memcpy(&state[4], kw, sizeof kw); + state[12] = cc; + memcpy(&state[13], ivw, sizeof ivw); + for (i = 0; i < 10; i ++) { + +#define QROUND(a, b, c, d) do { \ + state[a] += state[b]; \ + state[d] ^= state[a]; \ + state[d] = (state[d] << 16) | (state[d] >> 16); \ + state[c] += state[d]; \ + state[b] ^= state[c]; \ + state[b] = (state[b] << 12) | (state[b] >> 20); \ + state[a] += state[b]; \ + state[d] ^= state[a]; \ + state[d] = (state[d] << 8) | (state[d] >> 24); \ + state[c] += state[d]; \ + state[b] ^= state[c]; \ + state[b] = (state[b] << 7) | (state[b] >> 25); \ + } while (0) + + QROUND( 0, 4, 8, 12); + QROUND( 1, 5, 9, 13); + QROUND( 2, 6, 10, 14); + QROUND( 3, 7, 11, 15); + QROUND( 0, 5, 10, 15); + QROUND( 1, 6, 11, 12); + QROUND( 2, 7, 8, 13); + QROUND( 3, 4, 9, 14); + +#undef QROUND + + } + for (u = 0; u < 4; u ++) { + br_enc32le(&tmp[u << 2], state[u] + CW[u]); + } + for (u = 4; u < 12; u ++) { + br_enc32le(&tmp[u << 2], state[u] + kw[u - 4]); + } + br_enc32le(&tmp[48], state[12] + cc); + for (u = 13; u < 16; u ++) { + br_enc32le(&tmp[u << 2], state[u] + ivw[u - 13]); + } + + clen = len < 64 ? len : 64; + for (u = 0; u < clen; u ++) { + buf[u] ^= tmp[u]; + } + buf += clen; + len -= clen; + cc ++; + } + return cc; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/chacha20_sse2.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/chacha20_sse2.c new file mode 100644 index 000000000..0b8df1769 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/chacha20_sse2.c @@ -0,0 +1,242 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#define BR_ENABLE_INTRINSICS 1 +#include "inner.h" + +#if BR_SSE2 + +/* + * This file contains a ChaCha20 implementation that leverages SSE2 + * opcodes for better performance. + */ + +/* see bearssl_block.h */ +br_chacha20_run +br_chacha20_sse2_get(void) +{ + /* + * If using 64-bit mode, then SSE2 opcodes should be automatically + * available, since they are part of the ABI. + * + * In 32-bit mode, we use CPUID to detect the SSE2 feature. + */ + +#if BR_amd64 + return &br_chacha20_sse2_run; +#else + + /* + * SSE2 support is indicated by bit 26 in EDX. + */ + if (br_cpuid(0, 0, 0, 0x04000000)) { + return &br_chacha20_sse2_run; + } else { + return 0; + } +#endif +} + +BR_TARGETS_X86_UP + +/* see bearssl_block.h */ +BR_TARGET("sse2") +uint32_t +br_chacha20_sse2_run(const void *key, + const void *iv, uint32_t cc, void *data, size_t len) +{ + unsigned char *buf; + uint32_t ivtmp[4]; + __m128i kw0, kw1; + __m128i iw, cw; + __m128i one; + + static const uint32_t CW[] = { + 0x61707865, 0x3320646e, 0x79622d32, 0x6b206574 + }; + + buf = data; + kw0 = _mm_loadu_si128(key); + kw1 = _mm_loadu_si128((const void *)((const unsigned char *)key + 16)); + ivtmp[0] = cc; + memcpy(ivtmp + 1, iv, 12); + iw = _mm_loadu_si128((const void *)ivtmp); + cw = _mm_loadu_si128((const void *)CW); + one = _mm_set_epi32(0, 0, 0, 1); + + while (len > 0) { + /* + * sj contains state words 4*j to 4*j+3. + */ + __m128i s0, s1, s2, s3; + int i; + + s0 = cw; + s1 = kw0; + s2 = kw1; + s3 = iw; + for (i = 0; i < 10; i ++) { + /* + * Even round is straightforward application on + * the state words. + */ + s0 = _mm_add_epi32(s0, s1); + s3 = _mm_xor_si128(s3, s0); + s3 = _mm_or_si128( + _mm_slli_epi32(s3, 16), + _mm_srli_epi32(s3, 16)); + + s2 = _mm_add_epi32(s2, s3); + s1 = _mm_xor_si128(s1, s2); + s1 = _mm_or_si128( + _mm_slli_epi32(s1, 12), + _mm_srli_epi32(s1, 20)); + + s0 = _mm_add_epi32(s0, s1); + s3 = _mm_xor_si128(s3, s0); + s3 = _mm_or_si128( + _mm_slli_epi32(s3, 8), + _mm_srli_epi32(s3, 24)); + + s2 = _mm_add_epi32(s2, s3); + s1 = _mm_xor_si128(s1, s2); + s1 = _mm_or_si128( + _mm_slli_epi32(s1, 7), + _mm_srli_epi32(s1, 25)); + + /* + * For the odd round, we must rotate some state + * words so that the computations apply on the + * right combinations of words. + */ + s1 = _mm_shuffle_epi32(s1, 0x39); + s2 = _mm_shuffle_epi32(s2, 0x4E); + s3 = _mm_shuffle_epi32(s3, 0x93); + + s0 = _mm_add_epi32(s0, s1); + s3 = _mm_xor_si128(s3, s0); + s3 = _mm_or_si128( + _mm_slli_epi32(s3, 16), + _mm_srli_epi32(s3, 16)); + + s2 = _mm_add_epi32(s2, s3); + s1 = _mm_xor_si128(s1, s2); + s1 = _mm_or_si128( + _mm_slli_epi32(s1, 12), + _mm_srli_epi32(s1, 20)); + + s0 = _mm_add_epi32(s0, s1); + s3 = _mm_xor_si128(s3, s0); + s3 = _mm_or_si128( + _mm_slli_epi32(s3, 8), + _mm_srli_epi32(s3, 24)); + + s2 = _mm_add_epi32(s2, s3); + s1 = _mm_xor_si128(s1, s2); + s1 = _mm_or_si128( + _mm_slli_epi32(s1, 7), + _mm_srli_epi32(s1, 25)); + + /* + * After the odd round, we rotate back the values + * to undo the rotate at the start of the odd round. + */ + s1 = _mm_shuffle_epi32(s1, 0x93); + s2 = _mm_shuffle_epi32(s2, 0x4E); + s3 = _mm_shuffle_epi32(s3, 0x39); + } + + /* + * Addition with the initial state. + */ + s0 = _mm_add_epi32(s0, cw); + s1 = _mm_add_epi32(s1, kw0); + s2 = _mm_add_epi32(s2, kw1); + s3 = _mm_add_epi32(s3, iw); + + /* + * Increment block counter. + */ + iw = _mm_add_epi32(iw, one); + + /* + * XOR final state with the data. + */ + if (len < 64) { + unsigned char tmp[64]; + size_t u; + + _mm_storeu_si128((void *)(tmp + 0), s0); + _mm_storeu_si128((void *)(tmp + 16), s1); + _mm_storeu_si128((void *)(tmp + 32), s2); + _mm_storeu_si128((void *)(tmp + 48), s3); + for (u = 0; u < len; u ++) { + buf[u] ^= tmp[u]; + } + break; + } else { + __m128i b0, b1, b2, b3; + + b0 = _mm_loadu_si128((const void *)(buf + 0)); + b1 = _mm_loadu_si128((const void *)(buf + 16)); + b2 = _mm_loadu_si128((const void *)(buf + 32)); + b3 = _mm_loadu_si128((const void *)(buf + 48)); + b0 = _mm_xor_si128(b0, s0); + b1 = _mm_xor_si128(b1, s1); + b2 = _mm_xor_si128(b2, s2); + b3 = _mm_xor_si128(b3, s3); + _mm_storeu_si128((void *)(buf + 0), b0); + _mm_storeu_si128((void *)(buf + 16), b1); + _mm_storeu_si128((void *)(buf + 32), b2); + _mm_storeu_si128((void *)(buf + 48), b3); + buf += 64; + len -= 64; + } + } + + /* + * _mm_extract_epi32() requires SSE4.1. We prefer to stick to + * raw SSE2, thus we use _mm_extract_epi16(). + */ + return (uint32_t)_mm_extract_epi16(iw, 0) + | ((uint32_t)_mm_extract_epi16(iw, 1) << 16); +} + +BR_TARGETS_X86_DOWN + +#else + +/* see bearssl_block.h */ +br_chacha20_run +br_chacha20_sse2_get(void) +{ + return 0; +} + +#endif + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/config.h b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/config.h new file mode 100644 index 000000000..08e78dedf --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/config.h @@ -0,0 +1,252 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#ifndef CONFIG_H__ +#define CONFIG_H__ + +/* + * This file contains compile-time flags that can override the + * autodetection performed in relevant files. Each flag is a macro; it + * deactivates the feature if defined to 0, activates it if defined to a + * non-zero integer (normally 1). If the macro is not defined, then + * autodetection applies. + */ + +/* + * When BR_64 is enabled, 64-bit integer types are assumed to be + * efficient (i.e. the architecture has 64-bit registers and can + * do 64-bit operations as fast as 32-bit operations). + * +#define BR_64 1 + */ + +/* + * When BR_LOMUL is enabled, then multiplications of 32-bit values whose + * result are truncated to the low 32 bits are assumed to be + * substantially more efficient than 32-bit multiplications that yield + * 64-bit results. This is typically the case on low-end ARM Cortex M + * systems (M0, M0+, M1, and arguably M3 and M4 as well). +#define BR_LOMUL 1 + */ + +/* + * When BR_SLOW_MUL is enabled, multiplications are assumed to be + * substantially slow with regards to other integer operations, thus + * making it worth to make more operations for a given task if it allows + * using less multiplications. + * +#define BR_SLOW_MUL 1 + */ + +/* + * When BR_SLOW_MUL15 is enabled, short multplications (on 15-bit words) + * are assumed to be substantially slow with regards to other integer + * operations, thus making it worth to make more integer operations if + * it allows using less multiplications. + * +#define BR_SLOW_MUL15 1 + */ + +/* + * When BR_CT_MUL31 is enabled, multiplications of 31-bit values (used + * in the "i31" big integer implementation) use an alternate implementation + * which is slower and larger than the normal multiplication, but should + * ensure constant-time multiplications even on architectures where the + * multiplication opcode takes a variable number of cycles to complete. + * +#define BR_CT_MUL31 1 + */ + +/* + * When BR_CT_MUL15 is enabled, multiplications of 15-bit values (held + * in 32-bit words) use an alternate implementation which is slower and + * larger than the normal multiplication, but should ensure + * constant-time multiplications on most/all architectures where the + * basic multiplication is not constant-time. +#define BR_CT_MUL15 1 + */ + +/* + * When BR_NO_ARITH_SHIFT is enabled, arithmetic right shifts (with sign + * extension) are performed with a sequence of operations which is bigger + * and slower than a simple right shift on a signed value. This avoids + * relying on an implementation-defined behaviour. However, most if not + * all C compilers use sign extension for right shifts on signed values, + * so this alternate macro is disabled by default. +#define BR_NO_ARITH_SHIFT 1 + */ + +/* + * When BR_RDRAND is enabled, the SSL engine will use the RDRAND opcode + * to automatically obtain quality randomness for seeding its internal + * PRNG. Since that opcode is present only in recent x86 CPU, its + * support is dynamically tested; if the current CPU does not support + * it, then another random source will be used, such as /dev/urandom or + * CryptGenRandom(). + * +#define BR_RDRAND 1 + */ + +/* + * When BR_USE_GETENTROPY is enabled, the SSL engine will use the + * getentropy() function to obtain quality randomness for seeding its + * internal PRNG. On Linux and FreeBSD, getentropy() is implemented by + * the standard library with the system call getrandom(); on OpenBSD, + * getentropy() is the system call, and there is no getrandom() wrapper, + * hence the use of the getentropy() function for maximum portability. + * + * If the getentropy() call fails, and BR_USE_URANDOM is not explicitly + * disabled, then /dev/urandom will be used as a fallback mechanism. On + * FreeBSD and OpenBSD, this does not change much, since /dev/urandom + * will block if not enough entropy has been obtained since last boot. + * On Linux, /dev/urandom might not block, which can be troublesome in + * early boot stages, which is why getentropy() is preferred. + * +#define BR_USE_GETENTROPY 1 + */ + +/* + * When BR_USE_URANDOM is enabled, the SSL engine will use /dev/urandom + * to automatically obtain quality randomness for seeding its internal + * PRNG. + * +#define BR_USE_URANDOM 1 + */ + +/* + * When BR_USE_WIN32_RAND is enabled, the SSL engine will use the Win32 + * (CryptoAPI) functions (CryptAcquireContext(), CryptGenRandom()...) to + * automatically obtain quality randomness for seeding its internal PRNG. + * + * Note: if both BR_USE_URANDOM and BR_USE_WIN32_RAND are defined, the + * former takes precedence. + * +#define BR_USE_WIN32_RAND 1 + */ + +/* + * When BR_USE_UNIX_TIME is enabled, the X.509 validation engine obtains + * the current time from the OS by calling time(), and assuming that the + * returned value (a 'time_t') is an integer that counts time in seconds + * since the Unix Epoch (Jan 1st, 1970, 00:00 UTC). + */ +#define BR_USE_UNIX_TIME 0 + + +/* + * When BR_USE_WIN32_TIME is enabled, the X.509 validation engine obtains + * the current time from the OS by calling the Win32 function + * GetSystemTimeAsFileTime(). + * + * Note: if both BR_USE_UNIX_TIME and BR_USE_WIN32_TIME are defined, the + * former takes precedence. + * +#define BR_USE_WIN32_TIME 1 + */ + +/* + * When BR_ARMEL_CORTEXM_GCC is enabled, some operations are replaced with + * inline assembly which is shorter and/or faster. This should be used + * only when all of the following are true: + * - target architecture is ARM in Thumb mode + * - target endianness is little-endian + * - compiler is GCC (or GCC-compatible for inline assembly syntax) + * + * This is meant for the low-end cores (Cortex M0, M0+, M1, M3). + * Note: if BR_LOMUL is not explicitly enabled or disabled, then + * enabling BR_ARMEL_CORTEXM_GCC also enables BR_LOMUL. + */ +#if defined(__arm__) && defined(__thumb__) +#define BR_ARMEL_CORTEXM_GCC 1 +#endif + +/* + * When BR_AES_X86NI is enabled, the AES implementation using the x86 "NI" + * instructions (dedicated AES opcodes) will be compiled. If this is not + * enabled explicitly, then that AES implementation will be compiled only + * if a compatible compiler is detected. If set explicitly to 0, the + * implementation will not be compiled at all. + * +#define BR_AES_X86NI 1 + */ + +/* + * When BR_SSE2 is enabled, SSE2 intrinsics will be used for some + * algorithm implementations that use them (e.g. chacha20_sse2). If this + * is not enabled explicitly, then support for SSE2 intrinsics will be + * automatically detected. If set explicitly to 0, then SSE2 code will + * not be compiled at all. + * +#define BR_SSE2 1 + */ + +/* + * When BR_POWER8 is enabled, the AES implementation using the POWER ISA + * 2.07 opcodes (available on POWER8 processors and later) is compiled. + * If this is not enabled explicitly, then that implementation will be + * compiled only if a compatible compiler is detected, _and_ the target + * architecture is POWER8 or later. + * +#define BR_POWER8 1 + */ + +/* + * When BR_INT128 is enabled, then code using the 'unsigned __int64' + * and 'unsigned __int128' types will be used to leverage 64x64->128 + * unsigned multiplications. This should work with GCC and compatible + * compilers on 64-bit architectures. + * +#define BR_INT128 1 + */ + +/* + * When BR_UMUL128 is enabled, then code using the '_umul128()' and + * '_addcarry_u64()' intrinsics will be used to implement 64x64->128 + * unsigned multiplications. This should work on Visual C on x64 systems. + * +#define BR_UMUL128 1 + */ + +/* + * When BR_LE_UNALIGNED is enabled, then the current architecture is + * assumed to use little-endian encoding for integers, and to tolerate + * unaligned accesses with no or minimal time penalty. + * +#define BR_LE_UNALIGNED 1 + */ + +/* + * When BR_BE_UNALIGNED is enabled, then the current architecture is + * assumed to use big-endian encoding for integers, and to tolerate + * unaligned accesses with no or minimal time penalty. + * +#define BR_BE_UNALIGNED 1 + */ + +#endif + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/dec16be.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/dec16be.c new file mode 100644 index 000000000..8100df29d --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/dec16be.c @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +void +br_range_dec16be(uint16_t *v, size_t num, const void *src) +{ + const unsigned char *buf; + + buf = src; + while (num -- > 0) { + *v ++ = br_dec16be(buf); + buf += 2; + } +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/dec16le.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/dec16le.c new file mode 100644 index 000000000..69880c9d3 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/dec16le.c @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +void +br_range_dec16le(uint16_t *v, size_t num, const void *src) +{ + const unsigned char *buf; + + buf = src; + while (num -- > 0) { + *v ++ = br_dec16le(buf); + buf += 2; + } +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/dec32be.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/dec32be.c new file mode 100644 index 000000000..6ae08b07f --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/dec32be.c @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +void +br_range_dec32be(uint32_t *v, size_t num, const void *src) +{ + const unsigned char *buf; + + buf = src; + while (num -- > 0) { + *v ++ = br_dec32be(buf); + buf += 4; + } +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/dec32le.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/dec32le.c new file mode 100644 index 000000000..548a23520 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/dec32le.c @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +void +br_range_dec32le(uint32_t *v, size_t num, const void *src) +{ + const unsigned char *buf; + + buf = src; + while (num -- > 0) { + *v ++ = br_dec32le(buf); + buf += 4; + } +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/dec64be.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/dec64be.c new file mode 100644 index 000000000..4d9a6e63c --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/dec64be.c @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +void +br_range_dec64be(uint64_t *v, size_t num, const void *src) +{ + const unsigned char *buf; + + buf = src; + while (num -- > 0) { + *v ++ = br_dec64be(buf); + buf += 8; + } +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/dec64le.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/dec64le.c new file mode 100644 index 000000000..7a5c4a30d --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/dec64le.c @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +void +br_range_dec64le(uint64_t *v, size_t num, const void *src) +{ + const unsigned char *buf; + + buf = src; + while (num -- > 0) { + *v ++ = br_dec64le(buf); + buf += 8; + } +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/des_ct.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/des_ct.c new file mode 100644 index 000000000..842443363 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/des_ct.c @@ -0,0 +1,416 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* + * During key schedule, we need to apply bit extraction PC-2 then permute + * things into our bitslice representation. PC-2 extracts 48 bits out + * of two 28-bit words (kl and kr), and we store these bits into two + * 32-bit words sk0 and sk1. + * + * -- bit 16+x of sk0 comes from bit QL0[x] of kl + * -- bit x of sk0 comes from bit QR0[x] of kr + * -- bit 16+x of sk1 comes from bit QL1[x] of kl + * -- bit x of sk1 comes from bit QR1[x] of kr + */ + +static const unsigned char QL0[] = { + 17, 4, 27, 23, 13, 22, 7, 18, + 16, 24, 2, 20, 1, 8, 15, 26 +}; + +static const unsigned char QR0[] = { + 25, 19, 9, 1, 5, 11, 23, 8, + 17, 0, 22, 3, 6, 20, 27, 24 +}; + +static const unsigned char QL1[] = { + 28, 28, 14, 11, 28, 28, 25, 0, + 28, 28, 5, 9, 28, 28, 12, 21 +}; + +static const unsigned char QR1[] = { + 28, 28, 15, 4, 28, 28, 26, 16, + 28, 28, 12, 7, 28, 28, 10, 14 +}; + +/* + * 32-bit rotation. The C compiler is supposed to recognize it as a + * rotation and use the local architecture rotation opcode (if available). + */ +static inline uint32_t +rotl(uint32_t x, int n) +{ + return (x << n) | (x >> (32 - n)); +} + +/* + * Compute key schedule for 8 key bytes (produces 32 subkey words). + */ +static void +keysched_unit(uint32_t *skey, const void *key) +{ + int i; + + br_des_keysched_unit(skey, key); + + /* + * Apply PC-2 + bitslicing. + */ + for (i = 0; i < 16; i ++) { + uint32_t kl, kr, sk0, sk1; + int j; + + kl = skey[(i << 1) + 0]; + kr = skey[(i << 1) + 1]; + sk0 = 0; + sk1 = 0; + for (j = 0; j < 16; j ++) { + sk0 <<= 1; + sk1 <<= 1; + sk0 |= ((kl >> QL0[j]) & (uint32_t)1) << 16; + sk0 |= (kr >> QR0[j]) & (uint32_t)1; + sk1 |= ((kl >> QL1[j]) & (uint32_t)1) << 16; + sk1 |= (kr >> QR1[j]) & (uint32_t)1; + } + + skey[(i << 1) + 0] = sk0; + skey[(i << 1) + 1] = sk1; + } + +#if 0 + /* + * Speed-optimized version for PC-2 + bitslicing. + * (Unused. Kept for reference only.) + */ + sk0 = kl & (uint32_t)0x00100000; + sk0 |= (kl & (uint32_t)0x08008000) << 2; + sk0 |= (kl & (uint32_t)0x00400000) << 4; + sk0 |= (kl & (uint32_t)0x00800000) << 5; + sk0 |= (kl & (uint32_t)0x00040000) << 6; + sk0 |= (kl & (uint32_t)0x00010000) << 7; + sk0 |= (kl & (uint32_t)0x00000100) << 10; + sk0 |= (kl & (uint32_t)0x00022000) << 14; + sk0 |= (kl & (uint32_t)0x00000082) << 18; + sk0 |= (kl & (uint32_t)0x00000004) << 19; + sk0 |= (kl & (uint32_t)0x04000000) >> 10; + sk0 |= (kl & (uint32_t)0x00000010) << 26; + sk0 |= (kl & (uint32_t)0x01000000) >> 2; + + sk0 |= kr & (uint32_t)0x00000100; + sk0 |= (kr & (uint32_t)0x00000008) << 1; + sk0 |= (kr & (uint32_t)0x00000200) << 4; + sk0 |= rotl(kr & (uint32_t)0x08000021, 6); + sk0 |= (kr & (uint32_t)0x01000000) >> 24; + sk0 |= (kr & (uint32_t)0x00000002) << 11; + sk0 |= (kr & (uint32_t)0x00100000) >> 18; + sk0 |= (kr & (uint32_t)0x00400000) >> 17; + sk0 |= (kr & (uint32_t)0x00800000) >> 14; + sk0 |= (kr & (uint32_t)0x02020000) >> 10; + sk0 |= (kr & (uint32_t)0x00080000) >> 5; + sk0 |= (kr & (uint32_t)0x00000040) >> 3; + sk0 |= (kr & (uint32_t)0x00000800) >> 1; + + sk1 = kl & (uint32_t)0x02000000; + sk1 |= (kl & (uint32_t)0x00001000) << 5; + sk1 |= (kl & (uint32_t)0x00000200) << 11; + sk1 |= (kl & (uint32_t)0x00004000) << 15; + sk1 |= (kl & (uint32_t)0x00000020) << 16; + sk1 |= (kl & (uint32_t)0x00000800) << 17; + sk1 |= (kl & (uint32_t)0x00000001) << 24; + sk1 |= (kl & (uint32_t)0x00200000) >> 5; + + sk1 |= (kr & (uint32_t)0x00000010) << 8; + sk1 |= (kr & (uint32_t)0x04000000) >> 17; + sk1 |= (kr & (uint32_t)0x00004000) >> 14; + sk1 |= (kr & (uint32_t)0x00000400) >> 9; + sk1 |= (kr & (uint32_t)0x00010000) >> 8; + sk1 |= (kr & (uint32_t)0x00001000) >> 7; + sk1 |= (kr & (uint32_t)0x00000080) >> 3; + sk1 |= (kr & (uint32_t)0x00008000) >> 2; +#endif +} + +/* see inner.h */ +unsigned +br_des_ct_keysched(uint32_t *skey, const void *key, size_t key_len) +{ + switch (key_len) { + case 8: + keysched_unit(skey, key); + return 1; + case 16: + keysched_unit(skey, key); + keysched_unit(skey + 32, (const unsigned char *)key + 8); + br_des_rev_skey(skey + 32); + memcpy(skey + 64, skey, 32 * sizeof *skey); + return 3; + default: + keysched_unit(skey, key); + keysched_unit(skey + 32, (const unsigned char *)key + 8); + br_des_rev_skey(skey + 32); + keysched_unit(skey + 64, (const unsigned char *)key + 16); + return 3; + } +} + +/* + * DES confusion function. This function performs expansion E (32 to + * 48 bits), XOR with subkey, S-boxes, and permutation P. + */ +static inline uint32_t +Fconf(uint32_t r0, const uint32_t *sk) +{ + /* + * Each 6->4 S-box is virtually turned into four 6->1 boxes; we + * thus end up with 32 boxes that we call "T-boxes" here. We will + * evaluate them with bitslice code. + * + * Each T-box is a circuit of multiplexers (sort of) and thus + * takes 70 inputs: the 6 actual T-box inputs, and 64 constants + * that describe the T-box output for all combinations of the + * 6 inputs. With this model, all T-boxes are identical (with + * distinct inputs) and thus can be executed in parallel with + * bitslice code. + * + * T-boxes are numbered from 0 to 31, in least-to-most + * significant order. Thus, S-box S1 corresponds to T-boxes 31, + * 30, 29 and 28, in that order. T-box 'n' is computed with the + * bits at rank 'n' in the 32-bit words. + * + * Words x0 to x5 contain the T-box inputs 0 to 5. + */ + uint32_t x0, x1, x2, x3, x4, x5, z0; + uint32_t y0, y1, y2, y3, y4, y5, y6, y7, y8, y9; + uint32_t y10, y11, y12, y13, y14, y15, y16, y17, y18, y19; + uint32_t y20, y21, y22, y23, y24, y25, y26, y27, y28, y29; + uint32_t y30; + + /* + * Spread input bits over the 6 input words x*. + */ + x1 = r0 & (uint32_t)0x11111111; + x2 = (r0 >> 1) & (uint32_t)0x11111111; + x3 = (r0 >> 2) & (uint32_t)0x11111111; + x4 = (r0 >> 3) & (uint32_t)0x11111111; + x1 = (x1 << 4) - x1; + x2 = (x2 << 4) - x2; + x3 = (x3 << 4) - x3; + x4 = (x4 << 4) - x4; + x0 = (x4 << 4) | (x4 >> 28); + x5 = (x1 >> 4) | (x1 << 28); + + /* + * XOR with the subkey for this round. + */ + x0 ^= sk[0]; + x1 ^= sk[1]; + x2 ^= sk[2]; + x3 ^= sk[3]; + x4 ^= sk[4]; + x5 ^= sk[5]; + + /* + * The T-boxes are done in parallel, since they all use a + * "tree of multiplexer". We use "fake multiplexers": + * + * y = a ^ (x & b) + * + * computes y as either 'a' (if x == 0) or 'a ^ b' (if x == 1). + */ + y0 = (uint32_t)0xEFA72C4D ^ (x0 & (uint32_t)0xEC7AC69C); + y1 = (uint32_t)0xAEAAEDFF ^ (x0 & (uint32_t)0x500FB821); + y2 = (uint32_t)0x37396665 ^ (x0 & (uint32_t)0x40EFA809); + y3 = (uint32_t)0x68D7B833 ^ (x0 & (uint32_t)0xA5EC0B28); + y4 = (uint32_t)0xC9C755BB ^ (x0 & (uint32_t)0x252CF820); + y5 = (uint32_t)0x73FC3606 ^ (x0 & (uint32_t)0x40205801); + y6 = (uint32_t)0xA2A0A918 ^ (x0 & (uint32_t)0xE220F929); + y7 = (uint32_t)0x8222BD90 ^ (x0 & (uint32_t)0x44A3F9E1); + y8 = (uint32_t)0xD6B6AC77 ^ (x0 & (uint32_t)0x794F104A); + y9 = (uint32_t)0x3069300C ^ (x0 & (uint32_t)0x026F320B); + y10 = (uint32_t)0x6CE0D5CC ^ (x0 & (uint32_t)0x7640B01A); + y11 = (uint32_t)0x59A9A22D ^ (x0 & (uint32_t)0x238F1572); + y12 = (uint32_t)0xAC6D0BD4 ^ (x0 & (uint32_t)0x7A63C083); + y13 = (uint32_t)0x21C83200 ^ (x0 & (uint32_t)0x11CCA000); + y14 = (uint32_t)0xA0E62188 ^ (x0 & (uint32_t)0x202F69AA); + /* y15 = (uint32_t)0x00000000 ^ (x0 & (uint32_t)0x00000000); */ + y16 = (uint32_t)0xAF7D655A ^ (x0 & (uint32_t)0x51B33BE9); + y17 = (uint32_t)0xF0168AA3 ^ (x0 & (uint32_t)0x3B0FE8AE); + y18 = (uint32_t)0x90AA30C6 ^ (x0 & (uint32_t)0x90BF8816); + y19 = (uint32_t)0x5AB2750A ^ (x0 & (uint32_t)0x09E34F9B); + y20 = (uint32_t)0x5391BE65 ^ (x0 & (uint32_t)0x0103BE88); + y21 = (uint32_t)0x93372BAF ^ (x0 & (uint32_t)0x49AC8E25); + y22 = (uint32_t)0xF288210C ^ (x0 & (uint32_t)0x922C313D); + y23 = (uint32_t)0x920AF5C0 ^ (x0 & (uint32_t)0x70EF31B0); + y24 = (uint32_t)0x63D312C0 ^ (x0 & (uint32_t)0x6A707100); + y25 = (uint32_t)0x537B3006 ^ (x0 & (uint32_t)0xB97C9011); + y26 = (uint32_t)0xA2EFB0A5 ^ (x0 & (uint32_t)0xA320C959); + y27 = (uint32_t)0xBC8F96A5 ^ (x0 & (uint32_t)0x6EA0AB4A); + y28 = (uint32_t)0xFAD176A5 ^ (x0 & (uint32_t)0x6953DDF8); + y29 = (uint32_t)0x665A14A3 ^ (x0 & (uint32_t)0xF74F3E2B); + y30 = (uint32_t)0xF2EFF0CC ^ (x0 & (uint32_t)0xF0306CAD); + /* y31 = (uint32_t)0x00000000 ^ (x0 & (uint32_t)0x00000000); */ + + y0 = y0 ^ (x1 & y1); + y1 = y2 ^ (x1 & y3); + y2 = y4 ^ (x1 & y5); + y3 = y6 ^ (x1 & y7); + y4 = y8 ^ (x1 & y9); + y5 = y10 ^ (x1 & y11); + y6 = y12 ^ (x1 & y13); + y7 = y14; /* was: y14 ^ (x1 & y15) */ + y8 = y16 ^ (x1 & y17); + y9 = y18 ^ (x1 & y19); + y10 = y20 ^ (x1 & y21); + y11 = y22 ^ (x1 & y23); + y12 = y24 ^ (x1 & y25); + y13 = y26 ^ (x1 & y27); + y14 = y28 ^ (x1 & y29); + y15 = y30; /* was: y30 ^ (x1 & y31) */ + + y0 = y0 ^ (x2 & y1); + y1 = y2 ^ (x2 & y3); + y2 = y4 ^ (x2 & y5); + y3 = y6 ^ (x2 & y7); + y4 = y8 ^ (x2 & y9); + y5 = y10 ^ (x2 & y11); + y6 = y12 ^ (x2 & y13); + y7 = y14 ^ (x2 & y15); + + y0 = y0 ^ (x3 & y1); + y1 = y2 ^ (x3 & y3); + y2 = y4 ^ (x3 & y5); + y3 = y6 ^ (x3 & y7); + + y0 = y0 ^ (x4 & y1); + y1 = y2 ^ (x4 & y3); + + y0 = y0 ^ (x5 & y1); + + /* + * The P permutation: + * -- Each bit move is converted into a mask + left rotation. + * -- Rotations that use the same movement are coalesced together. + * -- Left and right shifts are used as alternatives to a rotation + * where appropriate (this will help architectures that do not have + * a rotation opcode). + */ + z0 = (y0 & (uint32_t)0x00000004) << 3; + z0 |= (y0 & (uint32_t)0x00004000) << 4; + z0 |= rotl(y0 & 0x12020120, 5); + z0 |= (y0 & (uint32_t)0x00100000) << 6; + z0 |= (y0 & (uint32_t)0x00008000) << 9; + z0 |= (y0 & (uint32_t)0x04000000) >> 22; + z0 |= (y0 & (uint32_t)0x00000001) << 11; + z0 |= rotl(y0 & 0x20000200, 12); + z0 |= (y0 & (uint32_t)0x00200000) >> 19; + z0 |= (y0 & (uint32_t)0x00000040) << 14; + z0 |= (y0 & (uint32_t)0x00010000) << 15; + z0 |= (y0 & (uint32_t)0x00000002) << 16; + z0 |= rotl(y0 & 0x40801800, 17); + z0 |= (y0 & (uint32_t)0x00080000) >> 13; + z0 |= (y0 & (uint32_t)0x00000010) << 21; + z0 |= (y0 & (uint32_t)0x01000000) >> 10; + z0 |= rotl(y0 & 0x88000008, 24); + z0 |= (y0 & (uint32_t)0x00000480) >> 7; + z0 |= (y0 & (uint32_t)0x00442000) >> 6; + return z0; +} + +/* + * Process one block through 16 successive rounds, omitting the swap + * in the final round. + */ +static void +process_block_unit(uint32_t *pl, uint32_t *pr, const uint32_t *sk_exp) +{ + int i; + uint32_t l, r; + + l = *pl; + r = *pr; + for (i = 0; i < 16; i ++) { + uint32_t t; + + t = l ^ Fconf(r, sk_exp); + l = r; + r = t; + sk_exp += 6; + } + *pl = r; + *pr = l; +} + +/* see inner.h */ +void +br_des_ct_process_block(unsigned num_rounds, + const uint32_t *sk_exp, void *block) +{ + unsigned char *buf; + uint32_t l, r; + + buf = block; + l = br_dec32be(buf); + r = br_dec32be(buf + 4); + br_des_do_IP(&l, &r); + while (num_rounds -- > 0) { + process_block_unit(&l, &r, sk_exp); + sk_exp += 96; + } + br_des_do_invIP(&l, &r); + br_enc32be(buf, l); + br_enc32be(buf + 4, r); +} + +/* see inner.h */ +void +br_des_ct_skey_expand(uint32_t *sk_exp, + unsigned num_rounds, const uint32_t *skey) +{ + num_rounds <<= 4; + while (num_rounds -- > 0) { + uint32_t v, w0, w1, w2, w3; + + v = *skey ++; + w0 = v & 0x11111111; + w1 = (v >> 1) & 0x11111111; + w2 = (v >> 2) & 0x11111111; + w3 = (v >> 3) & 0x11111111; + *sk_exp ++ = (w0 << 4) - w0; + *sk_exp ++ = (w1 << 4) - w1; + *sk_exp ++ = (w2 << 4) - w2; + *sk_exp ++ = (w3 << 4) - w3; + v = *skey ++; + w0 = v & 0x11111111; + w1 = (v >> 1) & 0x11111111; + *sk_exp ++ = (w0 << 4) - w0; + *sk_exp ++ = (w1 << 4) - w1; + } +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/des_ct_cbcdec.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/des_ct_cbcdec.c new file mode 100644 index 000000000..529dd12fc --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/des_ct_cbcdec.c @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_block.h */ +void +br_des_ct_cbcdec_init(br_des_ct_cbcdec_keys *ctx, + const void *key, size_t len) +{ + ctx->vtable = &br_des_ct_cbcdec_vtable; + ctx->num_rounds = br_des_ct_keysched(ctx->skey, key, len); + if (len == 8) { + br_des_rev_skey(ctx->skey); + } else { + int i; + + for (i = 0; i < 48; i += 2) { + uint32_t t; + + t = ctx->skey[i]; + ctx->skey[i] = ctx->skey[94 - i]; + ctx->skey[94 - i] = t; + t = ctx->skey[i + 1]; + ctx->skey[i + 1] = ctx->skey[95 - i]; + ctx->skey[95 - i] = t; + } + } +} + +/* see bearssl_block.h */ +void +br_des_ct_cbcdec_run(const br_des_ct_cbcdec_keys *ctx, + void *iv, void *data, size_t len) +{ + unsigned char *buf, *ivbuf; + uint32_t sk_exp[288]; + + br_des_ct_skey_expand(sk_exp, ctx->num_rounds, ctx->skey); + ivbuf = iv; + buf = data; + while (len > 0) { + unsigned char tmp[8]; + int i; + + memcpy(tmp, buf, 8); + br_des_ct_process_block(ctx->num_rounds, sk_exp, buf); + for (i = 0; i < 8; i ++) { + buf[i] ^= ivbuf[i]; + } + memcpy(ivbuf, tmp, 8); + buf += 8; + len -= 8; + } +} + +/* see bearssl_block.h */ +const br_block_cbcdec_class br_des_ct_cbcdec_vtable = { + sizeof(br_des_ct_cbcdec_keys), + 8, + 3, + (void (*)(const br_block_cbcdec_class **, const void *, size_t)) + &br_des_ct_cbcdec_init, + (void (*)(const br_block_cbcdec_class *const *, void *, void *, size_t)) + &br_des_ct_cbcdec_run +}; + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/des_ct_cbcenc.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/des_ct_cbcenc.c new file mode 100644 index 000000000..989097b79 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/des_ct_cbcenc.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_block.h */ +void +br_des_ct_cbcenc_init(br_des_ct_cbcenc_keys *ctx, + const void *key, size_t len) +{ + ctx->vtable = &br_des_ct_cbcenc_vtable; + ctx->num_rounds = br_des_ct_keysched(ctx->skey, key, len); +} + +/* see bearssl_block.h */ +void +br_des_ct_cbcenc_run(const br_des_ct_cbcenc_keys *ctx, + void *iv, void *data, size_t len) +{ + unsigned char *buf, *ivbuf; + uint32_t sk_exp[288]; + + br_des_ct_skey_expand(sk_exp, ctx->num_rounds, ctx->skey); + ivbuf = iv; + buf = data; + while (len > 0) { + int i; + + for (i = 0; i < 8; i ++) { + buf[i] ^= ivbuf[i]; + } + br_des_ct_process_block(ctx->num_rounds, sk_exp, buf); + memcpy(ivbuf, buf, 8); + buf += 8; + len -= 8; + } +} + +/* see bearssl_block.h */ +const br_block_cbcenc_class br_des_ct_cbcenc_vtable = { + sizeof(br_des_ct_cbcenc_keys), + 8, + 3, + (void (*)(const br_block_cbcenc_class **, const void *, size_t)) + &br_des_ct_cbcenc_init, + (void (*)(const br_block_cbcenc_class *const *, void *, void *, size_t)) + &br_des_ct_cbcenc_run +}; + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/des_support.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/des_support.c new file mode 100644 index 000000000..270352a15 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/des_support.c @@ -0,0 +1,171 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +void +br_des_do_IP(uint32_t *xl, uint32_t *xr) +{ + /* + * Permutation algorithm is initially from Richard Outerbridge; + * implementation here is adapted from Crypto++ "des.cpp" file + * (which is in public domain). + */ + uint32_t l, r, t; + + l = *xl; + r = *xr; + t = ((l >> 4) ^ r) & (uint32_t)0x0F0F0F0F; + r ^= t; + l ^= t << 4; + t = ((l >> 16) ^ r) & (uint32_t)0x0000FFFF; + r ^= t; + l ^= t << 16; + t = ((r >> 2) ^ l) & (uint32_t)0x33333333; + l ^= t; + r ^= t << 2; + t = ((r >> 8) ^ l) & (uint32_t)0x00FF00FF; + l ^= t; + r ^= t << 8; + t = ((l >> 1) ^ r) & (uint32_t)0x55555555; + r ^= t; + l ^= t << 1; + *xl = l; + *xr = r; +} + +/* see inner.h */ +void +br_des_do_invIP(uint32_t *xl, uint32_t *xr) +{ + /* + * See br_des_do_IP(). + */ + uint32_t l, r, t; + + l = *xl; + r = *xr; + t = ((l >> 1) ^ r) & 0x55555555; + r ^= t; + l ^= t << 1; + t = ((r >> 8) ^ l) & 0x00FF00FF; + l ^= t; + r ^= t << 8; + t = ((r >> 2) ^ l) & 0x33333333; + l ^= t; + r ^= t << 2; + t = ((l >> 16) ^ r) & 0x0000FFFF; + r ^= t; + l ^= t << 16; + t = ((l >> 4) ^ r) & 0x0F0F0F0F; + r ^= t; + l ^= t << 4; + *xl = l; + *xr = r; +} + +/* see inner.h */ +void +br_des_keysched_unit(uint32_t *skey, const void *key) +{ + uint32_t xl, xr, kl, kr; + int i; + + xl = br_dec32be(key); + xr = br_dec32be((const unsigned char *)key + 4); + + /* + * Permutation PC-1 is quite similar to the IP permutation. + * Definition of IP (in FIPS 46-3 notations) is: + * 58 50 42 34 26 18 10 2 + * 60 52 44 36 28 20 12 4 + * 62 54 46 38 30 22 14 6 + * 64 56 48 40 32 24 16 8 + * 57 49 41 33 25 17 9 1 + * 59 51 43 35 27 19 11 3 + * 61 53 45 37 29 21 13 5 + * 63 55 47 39 31 23 15 7 + * + * Definition of PC-1 is: + * 57 49 41 33 25 17 9 1 + * 58 50 42 34 26 18 10 2 + * 59 51 43 35 27 19 11 3 + * 60 52 44 36 + * 63 55 47 39 31 23 15 7 + * 62 54 46 38 30 22 14 6 + * 61 53 45 37 29 21 13 5 + * 28 20 12 4 + */ + br_des_do_IP(&xl, &xr); + kl = ((xr & (uint32_t)0xFF000000) >> 4) + | ((xl & (uint32_t)0xFF000000) >> 12) + | ((xr & (uint32_t)0x00FF0000) >> 12) + | ((xl & (uint32_t)0x00FF0000) >> 20); + kr = ((xr & (uint32_t)0x000000FF) << 20) + | ((xl & (uint32_t)0x0000FF00) << 4) + | ((xr & (uint32_t)0x0000FF00) >> 4) + | ((xl & (uint32_t)0x000F0000) >> 16); + + /* + * For each round, rotate the two 28-bit words kl and kr. + * The extraction of the 48-bit subkey (PC-2) is not done yet. + */ + for (i = 0; i < 16; i ++) { + if ((1 << i) & 0x8103) { + kl = (kl << 1) | (kl >> 27); + kr = (kr << 1) | (kr >> 27); + } else { + kl = (kl << 2) | (kl >> 26); + kr = (kr << 2) | (kr >> 26); + } + kl &= (uint32_t)0x0FFFFFFF; + kr &= (uint32_t)0x0FFFFFFF; + skey[(i << 1) + 0] = kl; + skey[(i << 1) + 1] = kr; + } +} + +/* see inner.h */ +void +br_des_rev_skey(uint32_t *skey) +{ + int i; + + for (i = 0; i < 16; i += 2) { + uint32_t t; + + t = skey[i + 0]; + skey[i + 0] = skey[30 - i]; + skey[30 - i] = t; + t = skey[i + 1]; + skey[i + 1] = skey[31 - i]; + skey[31 - i] = t; + } +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/des_tab.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/des_tab.c new file mode 100644 index 000000000..5fa2c3f49 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/des_tab.c @@ -0,0 +1,315 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* + * PC2left[x] tells where bit x goes when applying PC-2. 'x' is a bit + * position in the left rotated key word. Both position are in normal + * order (rightmost bit is 0). + */ +static const unsigned char PC2left[] = { + 16, 3, 7, 24, 20, 11, 24, + 13, 2, 10, 24, 22, 5, 15, + 23, 1, 9, 21, 12, 24, 6, + 4, 14, 18, 8, 17, 0, 19 +}; + +/* + * Similar to PC2left[x], for the right rotated key word. + */ +static const unsigned char PC2right[] = { + 8, 18, 24, 6, 22, 15, 3, + 10, 12, 19, 5, 14, 11, 24, + 4, 23, 16, 9, 24, 20, 2, + 24, 7, 13, 0, 21, 17, 1 +}; + +/* + * S-boxes and PC-1 merged. + */ +static const uint32_t S1[] = { + 0x00808200, 0x00000000, 0x00008000, 0x00808202, + 0x00808002, 0x00008202, 0x00000002, 0x00008000, + 0x00000200, 0x00808200, 0x00808202, 0x00000200, + 0x00800202, 0x00808002, 0x00800000, 0x00000002, + 0x00000202, 0x00800200, 0x00800200, 0x00008200, + 0x00008200, 0x00808000, 0x00808000, 0x00800202, + 0x00008002, 0x00800002, 0x00800002, 0x00008002, + 0x00000000, 0x00000202, 0x00008202, 0x00800000, + 0x00008000, 0x00808202, 0x00000002, 0x00808000, + 0x00808200, 0x00800000, 0x00800000, 0x00000200, + 0x00808002, 0x00008000, 0x00008200, 0x00800002, + 0x00000200, 0x00000002, 0x00800202, 0x00008202, + 0x00808202, 0x00008002, 0x00808000, 0x00800202, + 0x00800002, 0x00000202, 0x00008202, 0x00808200, + 0x00000202, 0x00800200, 0x00800200, 0x00000000, + 0x00008002, 0x00008200, 0x00000000, 0x00808002 +}; + +static const uint32_t S2[] = { + 0x40084010, 0x40004000, 0x00004000, 0x00084010, + 0x00080000, 0x00000010, 0x40080010, 0x40004010, + 0x40000010, 0x40084010, 0x40084000, 0x40000000, + 0x40004000, 0x00080000, 0x00000010, 0x40080010, + 0x00084000, 0x00080010, 0x40004010, 0x00000000, + 0x40000000, 0x00004000, 0x00084010, 0x40080000, + 0x00080010, 0x40000010, 0x00000000, 0x00084000, + 0x00004010, 0x40084000, 0x40080000, 0x00004010, + 0x00000000, 0x00084010, 0x40080010, 0x00080000, + 0x40004010, 0x40080000, 0x40084000, 0x00004000, + 0x40080000, 0x40004000, 0x00000010, 0x40084010, + 0x00084010, 0x00000010, 0x00004000, 0x40000000, + 0x00004010, 0x40084000, 0x00080000, 0x40000010, + 0x00080010, 0x40004010, 0x40000010, 0x00080010, + 0x00084000, 0x00000000, 0x40004000, 0x00004010, + 0x40000000, 0x40080010, 0x40084010, 0x00084000 +}; + +static const uint32_t S3[] = { + 0x00000104, 0x04010100, 0x00000000, 0x04010004, + 0x04000100, 0x00000000, 0x00010104, 0x04000100, + 0x00010004, 0x04000004, 0x04000004, 0x00010000, + 0x04010104, 0x00010004, 0x04010000, 0x00000104, + 0x04000000, 0x00000004, 0x04010100, 0x00000100, + 0x00010100, 0x04010000, 0x04010004, 0x00010104, + 0x04000104, 0x00010100, 0x00010000, 0x04000104, + 0x00000004, 0x04010104, 0x00000100, 0x04000000, + 0x04010100, 0x04000000, 0x00010004, 0x00000104, + 0x00010000, 0x04010100, 0x04000100, 0x00000000, + 0x00000100, 0x00010004, 0x04010104, 0x04000100, + 0x04000004, 0x00000100, 0x00000000, 0x04010004, + 0x04000104, 0x00010000, 0x04000000, 0x04010104, + 0x00000004, 0x00010104, 0x00010100, 0x04000004, + 0x04010000, 0x04000104, 0x00000104, 0x04010000, + 0x00010104, 0x00000004, 0x04010004, 0x00010100 +}; + +static const uint32_t S4[] = { + 0x80401000, 0x80001040, 0x80001040, 0x00000040, + 0x00401040, 0x80400040, 0x80400000, 0x80001000, + 0x00000000, 0x00401000, 0x00401000, 0x80401040, + 0x80000040, 0x00000000, 0x00400040, 0x80400000, + 0x80000000, 0x00001000, 0x00400000, 0x80401000, + 0x00000040, 0x00400000, 0x80001000, 0x00001040, + 0x80400040, 0x80000000, 0x00001040, 0x00400040, + 0x00001000, 0x00401040, 0x80401040, 0x80000040, + 0x00400040, 0x80400000, 0x00401000, 0x80401040, + 0x80000040, 0x00000000, 0x00000000, 0x00401000, + 0x00001040, 0x00400040, 0x80400040, 0x80000000, + 0x80401000, 0x80001040, 0x80001040, 0x00000040, + 0x80401040, 0x80000040, 0x80000000, 0x00001000, + 0x80400000, 0x80001000, 0x00401040, 0x80400040, + 0x80001000, 0x00001040, 0x00400000, 0x80401000, + 0x00000040, 0x00400000, 0x00001000, 0x00401040 +}; + +static const uint32_t S5[] = { + 0x00000080, 0x01040080, 0x01040000, 0x21000080, + 0x00040000, 0x00000080, 0x20000000, 0x01040000, + 0x20040080, 0x00040000, 0x01000080, 0x20040080, + 0x21000080, 0x21040000, 0x00040080, 0x20000000, + 0x01000000, 0x20040000, 0x20040000, 0x00000000, + 0x20000080, 0x21040080, 0x21040080, 0x01000080, + 0x21040000, 0x20000080, 0x00000000, 0x21000000, + 0x01040080, 0x01000000, 0x21000000, 0x00040080, + 0x00040000, 0x21000080, 0x00000080, 0x01000000, + 0x20000000, 0x01040000, 0x21000080, 0x20040080, + 0x01000080, 0x20000000, 0x21040000, 0x01040080, + 0x20040080, 0x00000080, 0x01000000, 0x21040000, + 0x21040080, 0x00040080, 0x21000000, 0x21040080, + 0x01040000, 0x00000000, 0x20040000, 0x21000000, + 0x00040080, 0x01000080, 0x20000080, 0x00040000, + 0x00000000, 0x20040000, 0x01040080, 0x20000080 +}; + +static const uint32_t S6[] = { + 0x10000008, 0x10200000, 0x00002000, 0x10202008, + 0x10200000, 0x00000008, 0x10202008, 0x00200000, + 0x10002000, 0x00202008, 0x00200000, 0x10000008, + 0x00200008, 0x10002000, 0x10000000, 0x00002008, + 0x00000000, 0x00200008, 0x10002008, 0x00002000, + 0x00202000, 0x10002008, 0x00000008, 0x10200008, + 0x10200008, 0x00000000, 0x00202008, 0x10202000, + 0x00002008, 0x00202000, 0x10202000, 0x10000000, + 0x10002000, 0x00000008, 0x10200008, 0x00202000, + 0x10202008, 0x00200000, 0x00002008, 0x10000008, + 0x00200000, 0x10002000, 0x10000000, 0x00002008, + 0x10000008, 0x10202008, 0x00202000, 0x10200000, + 0x00202008, 0x10202000, 0x00000000, 0x10200008, + 0x00000008, 0x00002000, 0x10200000, 0x00202008, + 0x00002000, 0x00200008, 0x10002008, 0x00000000, + 0x10202000, 0x10000000, 0x00200008, 0x10002008 +}; + +static const uint32_t S7[] = { + 0x00100000, 0x02100001, 0x02000401, 0x00000000, + 0x00000400, 0x02000401, 0x00100401, 0x02100400, + 0x02100401, 0x00100000, 0x00000000, 0x02000001, + 0x00000001, 0x02000000, 0x02100001, 0x00000401, + 0x02000400, 0x00100401, 0x00100001, 0x02000400, + 0x02000001, 0x02100000, 0x02100400, 0x00100001, + 0x02100000, 0x00000400, 0x00000401, 0x02100401, + 0x00100400, 0x00000001, 0x02000000, 0x00100400, + 0x02000000, 0x00100400, 0x00100000, 0x02000401, + 0x02000401, 0x02100001, 0x02100001, 0x00000001, + 0x00100001, 0x02000000, 0x02000400, 0x00100000, + 0x02100400, 0x00000401, 0x00100401, 0x02100400, + 0x00000401, 0x02000001, 0x02100401, 0x02100000, + 0x00100400, 0x00000000, 0x00000001, 0x02100401, + 0x00000000, 0x00100401, 0x02100000, 0x00000400, + 0x02000001, 0x02000400, 0x00000400, 0x00100001 +}; + +static const uint32_t S8[] = { + 0x08000820, 0x00000800, 0x00020000, 0x08020820, + 0x08000000, 0x08000820, 0x00000020, 0x08000000, + 0x00020020, 0x08020000, 0x08020820, 0x00020800, + 0x08020800, 0x00020820, 0x00000800, 0x00000020, + 0x08020000, 0x08000020, 0x08000800, 0x00000820, + 0x00020800, 0x00020020, 0x08020020, 0x08020800, + 0x00000820, 0x00000000, 0x00000000, 0x08020020, + 0x08000020, 0x08000800, 0x00020820, 0x00020000, + 0x00020820, 0x00020000, 0x08020800, 0x00000800, + 0x00000020, 0x08020020, 0x00000800, 0x00020820, + 0x08000800, 0x00000020, 0x08000020, 0x08020000, + 0x08020020, 0x08000000, 0x00020000, 0x08000820, + 0x00000000, 0x08020820, 0x00020020, 0x08000020, + 0x08020000, 0x08000800, 0x08000820, 0x00000000, + 0x08020820, 0x00020800, 0x00020800, 0x00000820, + 0x00000820, 0x00020020, 0x08000000, 0x08020800 +}; + +static inline uint32_t +Fconf(uint32_t r0, uint32_t skl, uint32_t skr) +{ + uint32_t r1; + + r1 = (r0 << 16) | (r0 >> 16); + return + S1[((r1 >> 11) ^ (skl >> 18)) & 0x3F] + | S2[((r0 >> 23) ^ (skl >> 12)) & 0x3F] + | S3[((r0 >> 19) ^ (skl >> 6)) & 0x3F] + | S4[((r0 >> 15) ^ (skl )) & 0x3F] + | S5[((r0 >> 11) ^ (skr >> 18)) & 0x3F] + | S6[((r0 >> 7) ^ (skr >> 12)) & 0x3F] + | S7[((r0 >> 3) ^ (skr >> 6)) & 0x3F] + | S8[((r1 >> 15) ^ (skr )) & 0x3F]; +} + +static void +process_block_unit(uint32_t *pl, uint32_t *pr, const uint32_t *skey) +{ + int i; + uint32_t l, r; + + l = *pl; + r = *pr; + for (i = 0; i < 16; i ++) { + uint32_t t; + + t = l ^ Fconf(r, skey[(i << 1) + 0], skey[(i << 1) + 1]); + l = r; + r = t; + } + *pl = r; + *pr = l; +} + +/* see inner.h */ +void +br_des_tab_process_block(unsigned num_rounds, const uint32_t *skey, void *block) +{ + unsigned char *buf; + uint32_t l, r; + + buf = block; + l = br_dec32be(buf); + r = br_dec32be(buf + 4); + br_des_do_IP(&l, &r); + while (num_rounds -- > 0) { + process_block_unit(&l, &r, skey); + skey += 32; + } + br_des_do_invIP(&l, &r); + br_enc32be(buf, l); + br_enc32be(buf + 4, r); +} + +static void +keysched_unit(uint32_t *skey, const void *key) +{ + int i; + + br_des_keysched_unit(skey, key); + + /* + * Apply PC-2 to get the 48-bit subkeys. + */ + for (i = 0; i < 16; i ++) { + uint32_t xl, xr, ul, ur; + int j; + + xl = skey[(i << 1) + 0]; + xr = skey[(i << 1) + 1]; + ul = 0; + ur = 0; + for (j = 0; j < 28; j ++) { + ul |= (xl & 1) << PC2left[j]; + ur |= (xr & 1) << PC2right[j]; + xl >>= 1; + xr >>= 1; + } + skey[(i << 1) + 0] = ul; + skey[(i << 1) + 1] = ur; + } +} + +/* see inner.h */ +unsigned +br_des_tab_keysched(uint32_t *skey, const void *key, size_t key_len) +{ + switch (key_len) { + case 8: + keysched_unit(skey, key); + return 1; + case 16: + keysched_unit(skey, key); + keysched_unit(skey + 32, (const unsigned char *)key + 8); + br_des_rev_skey(skey + 32); + memcpy(skey + 64, skey, 32 * sizeof *skey); + return 3; + default: + keysched_unit(skey, key); + keysched_unit(skey + 32, (const unsigned char *)key + 8); + br_des_rev_skey(skey + 32); + keysched_unit(skey + 64, (const unsigned char *)key + 16); + return 3; + } +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/des_tab_cbcdec.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/des_tab_cbcdec.c new file mode 100644 index 000000000..68ab4a8db --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/des_tab_cbcdec.c @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_block.h */ +void +br_des_tab_cbcdec_init(br_des_tab_cbcdec_keys *ctx, + const void *key, size_t len) +{ + ctx->vtable = &br_des_tab_cbcdec_vtable; + ctx->num_rounds = br_des_tab_keysched(ctx->skey, key, len); + if (len == 8) { + br_des_rev_skey(ctx->skey); + } else { + int i; + + for (i = 0; i < 48; i += 2) { + uint32_t t; + + t = ctx->skey[i]; + ctx->skey[i] = ctx->skey[94 - i]; + ctx->skey[94 - i] = t; + t = ctx->skey[i + 1]; + ctx->skey[i + 1] = ctx->skey[95 - i]; + ctx->skey[95 - i] = t; + } + } +} + +/* see bearssl_block.h */ +void +br_des_tab_cbcdec_run(const br_des_tab_cbcdec_keys *ctx, + void *iv, void *data, size_t len) +{ + unsigned char *buf, *ivbuf; + + ivbuf = iv; + buf = data; + while (len > 0) { + unsigned char tmp[8]; + int i; + + memcpy(tmp, buf, 8); + br_des_tab_process_block(ctx->num_rounds, ctx->skey, buf); + for (i = 0; i < 8; i ++) { + buf[i] ^= ivbuf[i]; + } + memcpy(ivbuf, tmp, 8); + buf += 8; + len -= 8; + } +} + +/* see bearssl_block.h */ +const br_block_cbcdec_class br_des_tab_cbcdec_vtable = { + sizeof(br_des_tab_cbcdec_keys), + 8, + 3, + (void (*)(const br_block_cbcdec_class **, const void *, size_t)) + &br_des_tab_cbcdec_init, + (void (*)(const br_block_cbcdec_class *const *, void *, void *, size_t)) + &br_des_tab_cbcdec_run +}; + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/des_tab_cbcenc.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/des_tab_cbcenc.c new file mode 100644 index 000000000..d9f2b7f85 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/des_tab_cbcenc.c @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_block.h */ +void +br_des_tab_cbcenc_init(br_des_tab_cbcenc_keys *ctx, + const void *key, size_t len) +{ + ctx->vtable = &br_des_tab_cbcenc_vtable; + ctx->num_rounds = br_des_tab_keysched(ctx->skey, key, len); +} + +/* see bearssl_block.h */ +void +br_des_tab_cbcenc_run(const br_des_tab_cbcenc_keys *ctx, + void *iv, void *data, size_t len) +{ + unsigned char *buf, *ivbuf; + + ivbuf = iv; + buf = data; + while (len > 0) { + int i; + + for (i = 0; i < 8; i ++) { + buf[i] ^= ivbuf[i]; + } + br_des_tab_process_block(ctx->num_rounds, ctx->skey, buf); + memcpy(ivbuf, buf, 8); + buf += 8; + len -= 8; + } +} + +/* see bearssl_block.h */ +const br_block_cbcenc_class br_des_tab_cbcenc_vtable = { + sizeof(br_des_tab_cbcenc_keys), + 8, + 3, + (void (*)(const br_block_cbcenc_class **, const void *, size_t)) + &br_des_tab_cbcenc_init, + (void (*)(const br_block_cbcenc_class *const *, void *, void *, size_t)) + &br_des_tab_cbcenc_run +}; + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/dig_oid.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/dig_oid.c new file mode 100644 index 000000000..ae1d9424f --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/dig_oid.c @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* + * This file contains the encoded OID for the standard hash functions. + * Such OID appear in, for instance, the PKCS#1 v1.5 padding for RSA + * signatures. + */ + +static const unsigned char md5_OID[] = { + 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x05 +}; + +static const unsigned char sha1_OID[] = { + 0x2B, 0x0E, 0x03, 0x02, 0x1A +}; + +static const unsigned char sha224_OID[] = { + 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x04 +}; + +static const unsigned char sha256_OID[] = { + 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01 +}; + +static const unsigned char sha384_OID[] = { + 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02 +}; + +static const unsigned char sha512_OID[] = { + 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03 +}; + +/* see inner.h */ +const unsigned char * +br_digest_OID(int digest_id, size_t *len) +{ + switch (digest_id) { + case br_md5_ID: + *len = sizeof md5_OID; + return md5_OID; + case br_sha1_ID: + *len = sizeof sha1_OID; + return sha1_OID; + case br_sha224_ID: + *len = sizeof sha224_OID; + return sha224_OID; + case br_sha256_ID: + *len = sizeof sha256_OID; + return sha256_OID; + case br_sha384_ID: + *len = sizeof sha384_OID; + return sha384_OID; + case br_sha512_ID: + *len = sizeof sha512_OID; + return sha512_OID; + default: + *len = 0; + return NULL; + } +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/dig_size.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/dig_size.c new file mode 100644 index 000000000..d54828c9b --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/dig_size.c @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +size_t +br_digest_size_by_ID(int digest_id) +{ + switch (digest_id) { + case br_md5sha1_ID: + return br_md5_SIZE + br_sha1_SIZE; + case br_md5_ID: + return br_md5_SIZE; + case br_sha1_ID: + return br_sha1_SIZE; + case br_sha224_ID: + return br_sha224_SIZE; + case br_sha256_ID: + return br_sha256_SIZE; + case br_sha384_ID: + return br_sha384_SIZE; + case br_sha512_ID: + return br_sha512_SIZE; + default: + /* abort(); */ + return 0; + } +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/eax.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/eax.c new file mode 100644 index 000000000..f702dc49b --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/eax.c @@ -0,0 +1,530 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* + * Implementation Notes + * ==================== + * + * The combined CTR + CBC-MAC functions can only handle full blocks, + * so some buffering is necessary. Moreover, EAX has a special padding + * rule for CBC-MAC, which implies that we cannot compute the MAC over + * the last received full block until we know whether we are at the + * end of the data or not. + * + * - 'ptr' contains a value from 1 to 16, which is the number of bytes + * accumulated in buf[] that still needs to be processed with the + * current OMAC computation. Beware that this can go to 16: a + * complete block cannot be processed until it is known whether it + * is the last block or not. However, it can never be 0, because + * OMAC^t works on an input that is at least one-block long. + * + * - When processing the message itself, CTR encryption/decryption is + * also done at the same time. The first 'ptr' bytes of buf[] then + * contains the encrypted bytes, while the last '16 - ptr' bytes of + * buf[] are the remnants of the stream block, to be used against + * the next input bytes, when available. + * + * - The current counter and running CBC-MAC values are kept in 'ctr' + * and 'cbcmac', respectively. + * + * - The derived keys for padding are kept in L2 and L4 (double and + * quadruple of Enc_K(0^n), in GF(2^128), respectively). + */ + +/* + * Start an OMAC computation; the first block is the big-endian + * representation of the provided value ('val' must fit on one byte). + * We make it a delayed block because it may also be the last one, + */ +static void +omac_start(br_eax_context *ctx, unsigned val) +{ + memset(ctx->cbcmac, 0, sizeof ctx->cbcmac); + memset(ctx->buf, 0, sizeof ctx->buf); + ctx->buf[15] = val; + ctx->ptr = 16; +} + +/* + * Double a value in finite field GF(2^128), defined with modulus + * X^128+X^7+X^2+X+1. + */ +static void +double_gf128(unsigned char *dst, const unsigned char *src) +{ + unsigned cc; + int i; + + cc = 0x87 & -((unsigned)src[0] >> 7); + for (i = 15; i >= 0; i --) { + unsigned z; + + z = (src[i] << 1) ^ cc; + cc = z >> 8; + dst[i] = (unsigned char)z; + } +} + +/* + * Apply padding to the last block, currently in ctx->buf (with + * ctx->ptr bytes), and finalize OMAC computation. + */ +static void +do_pad(br_eax_context *ctx) +{ + unsigned char *pad; + size_t ptr, u; + + ptr = ctx->ptr; + if (ptr == 16) { + pad = ctx->L2; + } else { + ctx->buf[ptr ++] = 0x80; + memset(ctx->buf + ptr, 0x00, 16 - ptr); + pad = ctx->L4; + } + for (u = 0; u < sizeof ctx->buf; u ++) { + ctx->buf[u] ^= pad[u]; + } + (*ctx->bctx)->mac(ctx->bctx, ctx->cbcmac, ctx->buf, sizeof ctx->buf); +} + +/* + * Apply CBC-MAC on the provided data, with buffering management. + * + * Upon entry, two situations are acceptable: + * + * ctx->ptr == 0: there is no data to process in ctx->buf + * ctx->ptr == 16: there is a full block of unprocessed data in ctx->buf + * + * Upon exit, ctx->ptr may be zero only if it was already zero on entry, + * and len == 0. In all other situations, ctx->ptr will be non-zero on + * exit (and may have value 16). + */ +static void +do_cbcmac_chunk(br_eax_context *ctx, const void *data, size_t len) +{ + size_t ptr; + + if (len == 0) { + return; + } + ptr = len & (size_t)15; + if (ptr == 0) { + len -= 16; + ptr = 16; + } else { + len -= ptr; + } + if (ctx->ptr == 16) { + (*ctx->bctx)->mac(ctx->bctx, ctx->cbcmac, + ctx->buf, sizeof ctx->buf); + } + (*ctx->bctx)->mac(ctx->bctx, ctx->cbcmac, data, len); + memcpy(ctx->buf, (const unsigned char *)data + len, ptr); + ctx->ptr = ptr; +} + +/* see bearssl_aead.h */ +void +br_eax_init(br_eax_context *ctx, const br_block_ctrcbc_class **bctx) +{ + unsigned char tmp[16], iv[16]; + + ctx->vtable = &br_eax_vtable; + ctx->bctx = bctx; + + /* + * Encrypt a whole-zero block to compute L2 and L4. + */ + memset(tmp, 0, sizeof tmp); + memset(iv, 0, sizeof iv); + (*bctx)->ctr(bctx, iv, tmp, sizeof tmp); + double_gf128(ctx->L2, tmp); + double_gf128(ctx->L4, ctx->L2); +} + +/* see bearssl_aead.h */ +void +br_eax_capture(const br_eax_context *ctx, br_eax_state *st) +{ + /* + * We capture the three OMAC* states _after_ processing the + * initial block (assuming that nonce, message and AAD are + * all non-empty). + */ + int i; + + memset(st->st, 0, sizeof st->st); + for (i = 0; i < 3; i ++) { + unsigned char tmp[16]; + + memset(tmp, 0, sizeof tmp); + tmp[15] = (unsigned char)i; + (*ctx->bctx)->mac(ctx->bctx, st->st[i], tmp, sizeof tmp); + } +} + +/* see bearssl_aead.h */ +void +br_eax_reset(br_eax_context *ctx, const void *nonce, size_t len) +{ + /* + * Process nonce with OMAC^0. + */ + omac_start(ctx, 0); + do_cbcmac_chunk(ctx, nonce, len); + do_pad(ctx); + memcpy(ctx->nonce, ctx->cbcmac, sizeof ctx->cbcmac); + + /* + * Start OMAC^1 for the AAD ("header" in the EAX specification). + */ + omac_start(ctx, 1); + + /* + * We use ctx->head[0] as temporary flag to mark that we are + * using a "normal" reset(). + */ + ctx->head[0] = 0; +} + +/* see bearssl_aead.h */ +void +br_eax_reset_pre_aad(br_eax_context *ctx, const br_eax_state *st, + const void *nonce, size_t len) +{ + if (len == 0) { + omac_start(ctx, 0); + } else { + memcpy(ctx->cbcmac, st->st[0], sizeof ctx->cbcmac); + ctx->ptr = 0; + do_cbcmac_chunk(ctx, nonce, len); + } + do_pad(ctx); + memcpy(ctx->nonce, ctx->cbcmac, sizeof ctx->cbcmac); + + memcpy(ctx->cbcmac, st->st[1], sizeof ctx->cbcmac); + ctx->ptr = 0; + + memcpy(ctx->ctr, st->st[2], sizeof ctx->ctr); + + /* + * We use ctx->head[0] as a flag to indicate that we use a + * a recorded state, with ctx->ctr containing the preprocessed + * first block for OMAC^2. + */ + ctx->head[0] = 1; +} + +/* see bearssl_aead.h */ +void +br_eax_reset_post_aad(br_eax_context *ctx, const br_eax_state *st, + const void *nonce, size_t len) +{ + if (len == 0) { + omac_start(ctx, 0); + } else { + memcpy(ctx->cbcmac, st->st[0], sizeof ctx->cbcmac); + ctx->ptr = 0; + do_cbcmac_chunk(ctx, nonce, len); + } + do_pad(ctx); + memcpy(ctx->nonce, ctx->cbcmac, sizeof ctx->cbcmac); + memcpy(ctx->ctr, ctx->nonce, sizeof ctx->nonce); + + memcpy(ctx->head, st->st[1], sizeof ctx->head); + + memcpy(ctx->cbcmac, st->st[2], sizeof ctx->cbcmac); + ctx->ptr = 0; +} + +/* see bearssl_aead.h */ +void +br_eax_aad_inject(br_eax_context *ctx, const void *data, size_t len) +{ + size_t ptr; + + ptr = ctx->ptr; + + /* + * If there is a partial block, first complete it. + */ + if (ptr < 16) { + size_t clen; + + clen = 16 - ptr; + if (len <= clen) { + memcpy(ctx->buf + ptr, data, len); + ctx->ptr = ptr + len; + return; + } + memcpy(ctx->buf + ptr, data, clen); + data = (const unsigned char *)data + clen; + len -= clen; + } + + /* + * We now have a full block in buf[], and this is not the last + * block. + */ + do_cbcmac_chunk(ctx, data, len); +} + +/* see bearssl_aead.h */ +void +br_eax_flip(br_eax_context *ctx) +{ + int from_capture; + + /* + * ctx->head[0] may be non-zero if the context was reset with + * a pre-AAD captured state. In that case, ctx->ctr[] contains + * the state for OMAC^2 _after_ processing the first block. + */ + from_capture = ctx->head[0]; + + /* + * Complete the OMAC computation on the AAD. + */ + do_pad(ctx); + memcpy(ctx->head, ctx->cbcmac, sizeof ctx->cbcmac); + + /* + * Start OMAC^2 for the encrypted data. + * If the context was initialized from a captured state, then + * the OMAC^2 value is in the ctr[] array. + */ + if (from_capture) { + memcpy(ctx->cbcmac, ctx->ctr, sizeof ctx->cbcmac); + ctx->ptr = 0; + } else { + omac_start(ctx, 2); + } + + /* + * Initial counter value for CTR is the processed nonce. + */ + memcpy(ctx->ctr, ctx->nonce, sizeof ctx->nonce); +} + +/* see bearssl_aead.h */ +void +br_eax_run(br_eax_context *ctx, int encrypt, void *data, size_t len) +{ + unsigned char *dbuf; + size_t ptr; + + /* + * Ensure that there is actual data to process. + */ + if (len == 0) { + return; + } + + dbuf = data; + ptr = ctx->ptr; + + /* + * We may have ptr == 0 here if we initialized from a captured + * state. In that case, there is no partially consumed block + * or unprocessed data. + */ + if (ptr != 0 && ptr != 16) { + /* + * We have a partially consumed block. + */ + size_t u, clen; + + clen = 16 - ptr; + if (len <= clen) { + clen = len; + } + if (encrypt) { + for (u = 0; u < clen; u ++) { + ctx->buf[ptr + u] ^= dbuf[u]; + } + memcpy(dbuf, ctx->buf + ptr, clen); + } else { + for (u = 0; u < clen; u ++) { + unsigned dx, sx; + + sx = ctx->buf[ptr + u]; + dx = dbuf[u]; + ctx->buf[ptr + u] = dx; + dbuf[u] = sx ^ dx; + } + } + + if (len <= clen) { + ctx->ptr = ptr + clen; + return; + } + dbuf += clen; + len -= clen; + } + + /* + * We now have a complete encrypted block in buf[] that must still + * be processed with OMAC, and this is not the final buf. + * Exception: when ptr == 0, no block has been produced yet. + */ + if (ptr != 0) { + (*ctx->bctx)->mac(ctx->bctx, ctx->cbcmac, + ctx->buf, sizeof ctx->buf); + } + + /* + * Do CTR encryption or decryption and CBC-MAC for all full blocks + * except the last. + */ + ptr = len & (size_t)15; + if (ptr == 0) { + len -= 16; + ptr = 16; + } else { + len -= ptr; + } + if (encrypt) { + (*ctx->bctx)->encrypt(ctx->bctx, ctx->ctr, ctx->cbcmac, + dbuf, len); + } else { + (*ctx->bctx)->decrypt(ctx->bctx, ctx->ctr, ctx->cbcmac, + dbuf, len); + } + dbuf += len; + + /* + * Compute next block of CTR stream, and use it to finish + * encrypting or decrypting the data. + */ + memset(ctx->buf, 0, sizeof ctx->buf); + (*ctx->bctx)->ctr(ctx->bctx, ctx->ctr, ctx->buf, sizeof ctx->buf); + if (encrypt) { + size_t u; + + for (u = 0; u < ptr; u ++) { + ctx->buf[u] ^= dbuf[u]; + } + memcpy(dbuf, ctx->buf, ptr); + } else { + size_t u; + + for (u = 0; u < ptr; u ++) { + unsigned dx, sx; + + sx = ctx->buf[u]; + dx = dbuf[u]; + ctx->buf[u] = dx; + dbuf[u] = sx ^ dx; + } + } + ctx->ptr = ptr; +} + +/* + * Complete tag computation. The final tag is written in ctx->cbcmac. + */ +static void +do_final(br_eax_context *ctx) +{ + size_t u; + + do_pad(ctx); + + /* + * Authentication tag is the XOR of the three OMAC outputs for + * the nonce, AAD and encrypted data. + */ + for (u = 0; u < 16; u ++) { + ctx->cbcmac[u] ^= ctx->nonce[u] ^ ctx->head[u]; + } +} + +/* see bearssl_aead.h */ +void +br_eax_get_tag(br_eax_context *ctx, void *tag) +{ + do_final(ctx); + memcpy(tag, ctx->cbcmac, sizeof ctx->cbcmac); +} + +/* see bearssl_aead.h */ +void +br_eax_get_tag_trunc(br_eax_context *ctx, void *tag, size_t len) +{ + do_final(ctx); + memcpy(tag, ctx->cbcmac, len); +} + +/* see bearssl_aead.h */ +uint32_t +br_eax_check_tag_trunc(br_eax_context *ctx, const void *tag, size_t len) +{ + unsigned char tmp[16]; + size_t u; + int x; + + br_eax_get_tag(ctx, tmp); + x = 0; + for (u = 0; u < len; u ++) { + x |= tmp[u] ^ ((const unsigned char *)tag)[u]; + } + return EQ0(x); +} + +/* see bearssl_aead.h */ +uint32_t +br_eax_check_tag(br_eax_context *ctx, const void *tag) +{ + return br_eax_check_tag_trunc(ctx, tag, 16); +} + +/* see bearssl_aead.h */ +const br_aead_class br_eax_vtable = { + 16, + (void (*)(const br_aead_class **, const void *, size_t)) + &br_eax_reset, + (void (*)(const br_aead_class **, const void *, size_t)) + &br_eax_aad_inject, + (void (*)(const br_aead_class **)) + &br_eax_flip, + (void (*)(const br_aead_class **, int, void *, size_t)) + &br_eax_run, + (void (*)(const br_aead_class **, void *)) + &br_eax_get_tag, + (uint32_t (*)(const br_aead_class **, const void *)) + &br_eax_check_tag, + (void (*)(const br_aead_class **, void *, size_t)) + &br_eax_get_tag_trunc, + (uint32_t (*)(const br_aead_class **, const void *, size_t)) + &br_eax_check_tag_trunc +}; + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_all_m15.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_all_m15.c new file mode 100644 index 000000000..5e26ffba2 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_all_m15.c @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +static const unsigned char * +api_generator(int curve, size_t *len) +{ + switch (curve) { + case BR_EC_secp256r1: + return br_ec_p256_m15.generator(curve, len); + case BR_EC_curve25519: + return br_ec_c25519_m15.generator(curve, len); + default: + return br_ec_prime_i15.generator(curve, len); + } +} + +static const unsigned char * +api_order(int curve, size_t *len) +{ + switch (curve) { + case BR_EC_secp256r1: + return br_ec_p256_m15.order(curve, len); + case BR_EC_curve25519: + return br_ec_c25519_m15.order(curve, len); + default: + return br_ec_prime_i15.order(curve, len); + } +} + +static size_t +api_xoff(int curve, size_t *len) +{ + switch (curve) { + case BR_EC_secp256r1: + return br_ec_p256_m15.xoff(curve, len); + case BR_EC_curve25519: + return br_ec_c25519_m15.xoff(curve, len); + default: + return br_ec_prime_i15.xoff(curve, len); + } +} + +static uint32_t +api_mul(unsigned char *G, size_t Glen, + const unsigned char *kb, size_t kblen, int curve) +{ + switch (curve) { + case BR_EC_secp256r1: + return br_ec_p256_m15.mul(G, Glen, kb, kblen, curve); + case BR_EC_curve25519: + return br_ec_c25519_m15.mul(G, Glen, kb, kblen, curve); + default: + return br_ec_prime_i15.mul(G, Glen, kb, kblen, curve); + } +} + +static size_t +api_mulgen(unsigned char *R, + const unsigned char *x, size_t xlen, int curve) +{ + switch (curve) { + case BR_EC_secp256r1: + return br_ec_p256_m15.mulgen(R, x, xlen, curve); + case BR_EC_curve25519: + return br_ec_c25519_m15.mulgen(R, x, xlen, curve); + default: + return br_ec_prime_i15.mulgen(R, x, xlen, curve); + } +} + +static uint32_t +api_muladd(unsigned char *A, const unsigned char *B, size_t len, + const unsigned char *x, size_t xlen, + const unsigned char *y, size_t ylen, int curve) +{ + switch (curve) { + case BR_EC_secp256r1: + return br_ec_p256_m15.muladd(A, B, len, + x, xlen, y, ylen, curve); + case BR_EC_curve25519: + return br_ec_c25519_m15.muladd(A, B, len, + x, xlen, y, ylen, curve); + default: + return br_ec_prime_i15.muladd(A, B, len, + x, xlen, y, ylen, curve); + } +} + +/* see bearssl_ec.h */ +const br_ec_impl br_ec_all_m15 = { + (uint32_t)0x23800000, + &api_generator, + &api_order, + &api_xoff, + &api_mul, + &api_mulgen, + &api_muladd +}; + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_all_m31.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_all_m31.c new file mode 100644 index 000000000..7e803b3dd --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_all_m31.c @@ -0,0 +1,176 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +static const unsigned char * +api_generator(int curve, size_t *len) +{ + switch (curve) { + case BR_EC_secp256r1: +#if BR_INT128 || BR_UMUL128 + return br_ec_p256_m64.generator(curve, len); +#else + return br_ec_p256_m31.generator(curve, len); +#endif + case BR_EC_curve25519: +#if BR_INT128 || BR_UMUL128 + return br_ec_c25519_m64.generator(curve, len); +#else + return br_ec_c25519_m31.generator(curve, len); +#endif + default: + return br_ec_prime_i31.generator(curve, len); + } +} + +static const unsigned char * +api_order(int curve, size_t *len) +{ + switch (curve) { + case BR_EC_secp256r1: +#if BR_INT128 || BR_UMUL128 + return br_ec_p256_m64.order(curve, len); +#else + return br_ec_p256_m31.order(curve, len); +#endif + case BR_EC_curve25519: +#if BR_INT128 || BR_UMUL128 + return br_ec_c25519_m64.order(curve, len); +#else + return br_ec_c25519_m31.order(curve, len); +#endif + default: + return br_ec_prime_i31.order(curve, len); + } +} + +static size_t +api_xoff(int curve, size_t *len) +{ + switch (curve) { + case BR_EC_secp256r1: +#if BR_INT128 || BR_UMUL128 + return br_ec_p256_m64.xoff(curve, len); +#else + return br_ec_p256_m31.xoff(curve, len); +#endif + case BR_EC_curve25519: +#if BR_INT128 || BR_UMUL128 + return br_ec_c25519_m64.xoff(curve, len); +#else + return br_ec_c25519_m31.xoff(curve, len); +#endif + default: + return br_ec_prime_i31.xoff(curve, len); + } +} + +static uint32_t +api_mul(unsigned char *G, size_t Glen, + const unsigned char *kb, size_t kblen, int curve) +{ + switch (curve) { + case BR_EC_secp256r1: +#if BR_INT128 || BR_UMUL128 + return br_ec_p256_m64.mul(G, Glen, kb, kblen, curve); +#else + return br_ec_p256_m31.mul(G, Glen, kb, kblen, curve); +#endif + case BR_EC_curve25519: +#if BR_INT128 || BR_UMUL128 + return br_ec_c25519_m64.mul(G, Glen, kb, kblen, curve); +#else + return br_ec_c25519_m31.mul(G, Glen, kb, kblen, curve); +#endif + default: + return br_ec_prime_i31.mul(G, Glen, kb, kblen, curve); + } +} + +static size_t +api_mulgen(unsigned char *R, + const unsigned char *x, size_t xlen, int curve) +{ + switch (curve) { + case BR_EC_secp256r1: +#if BR_INT128 || BR_UMUL128 + return br_ec_p256_m64.mulgen(R, x, xlen, curve); +#else + return br_ec_p256_m31.mulgen(R, x, xlen, curve); +#endif + case BR_EC_curve25519: +#if BR_INT128 || BR_UMUL128 + return br_ec_c25519_m64.mulgen(R, x, xlen, curve); +#else + return br_ec_c25519_m31.mulgen(R, x, xlen, curve); +#endif + default: + return br_ec_prime_i31.mulgen(R, x, xlen, curve); + } +} + +static uint32_t +api_muladd(unsigned char *A, const unsigned char *B, size_t len, + const unsigned char *x, size_t xlen, + const unsigned char *y, size_t ylen, int curve) +{ + switch (curve) { + case BR_EC_secp256r1: +#if BR_INT128 || BR_UMUL128 + return br_ec_p256_m64.muladd(A, B, len, + x, xlen, y, ylen, curve); +#else + return br_ec_p256_m31.muladd(A, B, len, + x, xlen, y, ylen, curve); +#endif + case BR_EC_curve25519: +#if BR_INT128 || BR_UMUL128 + return br_ec_c25519_m64.muladd(A, B, len, + x, xlen, y, ylen, curve); +#else + return br_ec_c25519_m31.muladd(A, B, len, + x, xlen, y, ylen, curve); +#endif + default: + return br_ec_prime_i31.muladd(A, B, len, + x, xlen, y, ylen, curve); + } +} + +/* see bearssl_ec.h */ +const br_ec_impl br_ec_all_m31 = { + (uint32_t)0x23800000, + &api_generator, + &api_order, + &api_xoff, + &api_mul, + &api_mulgen, + &api_muladd +}; + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_c25519_i15.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_c25519_i15.c new file mode 100644 index 000000000..e00606eb1 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_c25519_i15.c @@ -0,0 +1,403 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* + * Parameters for the field: + * - field modulus p = 2^255-19 + * - R^2 mod p (R = 2^(15k) for the smallest k such that R >= p) + */ + +static const uint16_t C255_P[] = { + 0x0110, + 0x7FED, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, + 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, + 0x7FFF +}; + +#define P0I 0x4A1B + +static const uint16_t C255_R2[] = { + 0x0110, + 0x0169, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000 +}; + +/* obsolete +#include +#include +static void +print_int_mont(const char *name, const uint16_t *x) +{ + uint16_t y[18]; + unsigned char tmp[32]; + size_t u; + + printf("%s = ", name); + memcpy(y, x, sizeof y); + br_i15_from_monty(y, C255_P, P0I); + br_i15_encode(tmp, sizeof tmp, y); + for (u = 0; u < sizeof tmp; u ++) { + printf("%02X", tmp[u]); + } + printf("\n"); +} +*/ + +static const uint16_t C255_A24[] = { + 0x0110, + 0x45D3, 0x0046, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000 +}; + +static const unsigned char GEN[] = { + 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + +static const unsigned char ORDER[] = { + 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF +}; + +static const unsigned char * +api_generator(int curve, size_t *len) +{ + (void)curve; + *len = 32; + return GEN; +} + +static const unsigned char * +api_order(int curve, size_t *len) +{ + (void)curve; + *len = 32; + return ORDER; +} + +static size_t +api_xoff(int curve, size_t *len) +{ + (void)curve; + *len = 32; + return 0; +} + +static void +cswap(uint16_t *a, uint16_t *b, uint32_t ctl) +{ + int i; + + ctl = -ctl; + for (i = 0; i < 18; i ++) { + uint32_t aw, bw, tw; + + aw = a[i]; + bw = b[i]; + tw = ctl & (aw ^ bw); + a[i] = aw ^ tw; + b[i] = bw ^ tw; + } +} + +static void +c255_add(uint16_t *d, const uint16_t *a, const uint16_t *b) +{ + uint32_t ctl; + uint16_t t[18]; + + memcpy(t, a, sizeof t); + ctl = br_i15_add(t, b, 1); + ctl |= NOT(br_i15_sub(t, C255_P, 0)); + br_i15_sub(t, C255_P, ctl); + memcpy(d, t, sizeof t); +} + +static void +c255_sub(uint16_t *d, const uint16_t *a, const uint16_t *b) +{ + uint16_t t[18]; + + memcpy(t, a, sizeof t); + br_i15_add(t, C255_P, br_i15_sub(t, b, 1)); + memcpy(d, t, sizeof t); +} + +static void +c255_mul(uint16_t *d, const uint16_t *a, const uint16_t *b) +{ + uint16_t t[18]; + + br_i15_montymul(t, a, b, C255_P, P0I); + memcpy(d, t, sizeof t); +} + +static void +byteswap(unsigned char *G) +{ + int i; + + for (i = 0; i < 16; i ++) { + unsigned char t; + + t = G[i]; + G[i] = G[31 - i]; + G[31 - i] = t; + } +} + +static uint32_t +api_mul(unsigned char *G, size_t Glen, + const unsigned char *kb, size_t kblen, int curve) +{ +#define ILEN (18 * sizeof(uint16_t)) + + /* + * The a[] and b[] arrays have an extra word to allow for + * decoding without using br_i15_decode_reduce(). + */ + uint16_t x1[18], x2[18], x3[18], z2[18], z3[18]; + uint16_t a[19], aa[18], b[19], bb[18]; + uint16_t c[18], d[18], e[18], da[18], cb[18]; + unsigned char k[32]; + uint32_t swap; + int i; + + (void)curve; + + /* + * Points are encoded over exactly 32 bytes. Multipliers must fit + * in 32 bytes as well. + * RFC 7748 mandates that the high bit of the last point byte must + * be ignored/cleared. + */ + if (Glen != 32 || kblen > 32) { + return 0; + } + G[31] &= 0x7F; + + /* + * Byteswap the point encoding, because it uses little-endian, and + * the generic decoding routine uses big-endian. + */ + byteswap(G); + + /* + * Decode the point ('u' coordinate). This should be reduced + * modulo p, but we prefer to avoid the dependency on + * br_i15_decode_reduce(). Instead, we use br_i15_decode_mod() + * with a synthetic modulus of value 2^255 (this must work + * since G was truncated to 255 bits), then use a conditional + * subtraction. We use br_i15_decode_mod() and not + * br_i15_decode(), because the ec_prime_i15 implementation uses + * the former but not the latter. + * br_i15_decode_reduce(a, G, 32, C255_P); + */ + br_i15_zero(b, 0x111); + b[18] = 1; + br_i15_decode_mod(a, G, 32, b); + a[0] = 0x110; + br_i15_sub(a, C255_P, NOT(br_i15_sub(a, C255_P, 0))); + + /* + * Initialise variables x1, x2, z2, x3 and z3. We set all of them + * into Montgomery representation. + */ + br_i15_montymul(x1, a, C255_R2, C255_P, P0I); + memcpy(x3, x1, ILEN); + br_i15_zero(z2, C255_P[0]); + memcpy(x2, z2, ILEN); + x2[1] = 19; + memcpy(z3, x2, ILEN); + + memset(k, 0, (sizeof k) - kblen); + memcpy(k + (sizeof k) - kblen, kb, kblen); + k[31] &= 0xF8; + k[0] &= 0x7F; + k[0] |= 0x40; + + /* obsolete + print_int_mont("x1", x1); + */ + + swap = 0; + for (i = 254; i >= 0; i --) { + uint32_t kt; + + kt = (k[31 - (i >> 3)] >> (i & 7)) & 1; + swap ^= kt; + cswap(x2, x3, swap); + cswap(z2, z3, swap); + swap = kt; + + /* obsolete + print_int_mont("x2", x2); + print_int_mont("z2", z2); + print_int_mont("x3", x3); + print_int_mont("z3", z3); + */ + + c255_add(a, x2, z2); + c255_mul(aa, a, a); + c255_sub(b, x2, z2); + c255_mul(bb, b, b); + c255_sub(e, aa, bb); + c255_add(c, x3, z3); + c255_sub(d, x3, z3); + c255_mul(da, d, a); + c255_mul(cb, c, b); + + /* obsolete + print_int_mont("a ", a); + print_int_mont("aa", aa); + print_int_mont("b ", b); + print_int_mont("bb", bb); + print_int_mont("e ", e); + print_int_mont("c ", c); + print_int_mont("d ", d); + print_int_mont("da", da); + print_int_mont("cb", cb); + */ + + c255_add(x3, da, cb); + c255_mul(x3, x3, x3); + c255_sub(z3, da, cb); + c255_mul(z3, z3, z3); + c255_mul(z3, z3, x1); + c255_mul(x2, aa, bb); + c255_mul(z2, C255_A24, e); + c255_add(z2, z2, aa); + c255_mul(z2, e, z2); + + /* obsolete + print_int_mont("x2", x2); + print_int_mont("z2", z2); + print_int_mont("x3", x3); + print_int_mont("z3", z3); + */ + } + cswap(x2, x3, swap); + cswap(z2, z3, swap); + + /* + * Inverse z2 with a modular exponentiation. This is a simple + * square-and-multiply algorithm; we mutualise most non-squarings + * since the exponent contains almost only ones. + */ + memcpy(a, z2, ILEN); + for (i = 0; i < 15; i ++) { + c255_mul(a, a, a); + c255_mul(a, a, z2); + } + memcpy(b, a, ILEN); + for (i = 0; i < 14; i ++) { + int j; + + for (j = 0; j < 16; j ++) { + c255_mul(b, b, b); + } + c255_mul(b, b, a); + } + for (i = 14; i >= 0; i --) { + c255_mul(b, b, b); + if ((0xFFEB >> i) & 1) { + c255_mul(b, z2, b); + } + } + c255_mul(b, x2, b); + + /* + * To avoid a dependency on br_i15_from_monty(), we use a + * Montgomery multiplication with 1. + * memcpy(x2, b, ILEN); + * br_i15_from_monty(x2, C255_P, P0I); + */ + br_i15_zero(a, C255_P[0]); + a[1] = 1; + br_i15_montymul(x2, a, b, C255_P, P0I); + + br_i15_encode(G, 32, x2); + byteswap(G); + return 1; + +#undef ILEN +} + +static size_t +api_mulgen(unsigned char *R, + const unsigned char *x, size_t xlen, int curve) +{ + const unsigned char *G; + size_t Glen; + + G = api_generator(curve, &Glen); + memcpy(R, G, Glen); + api_mul(R, Glen, x, xlen, curve); + return Glen; +} + +static uint32_t +api_muladd(unsigned char *A, const unsigned char *B, size_t len, + const unsigned char *x, size_t xlen, + const unsigned char *y, size_t ylen, int curve) +{ + /* + * We don't implement this method, since it is used for ECDSA + * only, and there is no ECDSA over Curve25519 (which instead + * uses EdDSA). + */ + (void)A; + (void)B; + (void)len; + (void)x; + (void)xlen; + (void)y; + (void)ylen; + (void)curve; + return 0; +} + +/* see bearssl_ec.h */ +const br_ec_impl br_ec_c25519_i15 = { + (uint32_t)0x20000000, + &api_generator, + &api_order, + &api_xoff, + &api_mul, + &api_mulgen, + &api_muladd +}; + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_c25519_i31.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_c25519_i31.c new file mode 100644 index 000000000..48b262176 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_c25519_i31.c @@ -0,0 +1,395 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* + * Parameters for the field: + * - field modulus p = 2^255-19 + * - R^2 mod p (R = 2^(31k) for the smallest k such that R >= p) + */ + +static const uint32_t C255_P[] = { + 0x00000107, + 0x7FFFFFED, 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, + 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, 0x0000007F +}; + +#define P0I 0x286BCA1B + +static const uint32_t C255_R2[] = { + 0x00000107, + 0x00000000, 0x02D20000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000 +}; + +static const uint32_t C255_A24[] = { + 0x00000107, + 0x53000000, 0x0000468B, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000 +}; + +/* obsolete +#include +#include +static void +print_int_mont(const char *name, const uint32_t *x) +{ + uint32_t y[10]; + unsigned char tmp[32]; + size_t u; + + printf("%s = ", name); + memcpy(y, x, sizeof y); + br_i31_from_monty(y, C255_P, P0I); + br_i31_encode(tmp, sizeof tmp, y); + for (u = 0; u < sizeof tmp; u ++) { + printf("%02X", tmp[u]); + } + printf("\n"); +} +*/ + +static const unsigned char GEN[] = { + 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + +static const unsigned char ORDER[] = { + 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF +}; + +static const unsigned char * +api_generator(int curve, size_t *len) +{ + (void)curve; + *len = 32; + return GEN; +} + +static const unsigned char * +api_order(int curve, size_t *len) +{ + (void)curve; + *len = 32; + return ORDER; +} + +static size_t +api_xoff(int curve, size_t *len) +{ + (void)curve; + *len = 32; + return 0; +} + +static void +cswap(uint32_t *a, uint32_t *b, uint32_t ctl) +{ + int i; + + ctl = -ctl; + for (i = 0; i < 10; i ++) { + uint32_t aw, bw, tw; + + aw = a[i]; + bw = b[i]; + tw = ctl & (aw ^ bw); + a[i] = aw ^ tw; + b[i] = bw ^ tw; + } +} + +static void +c255_add(uint32_t *d, const uint32_t *a, const uint32_t *b) +{ + uint32_t ctl; + uint32_t t[10]; + + memcpy(t, a, sizeof t); + ctl = br_i31_add(t, b, 1); + ctl |= NOT(br_i31_sub(t, C255_P, 0)); + br_i31_sub(t, C255_P, ctl); + memcpy(d, t, sizeof t); +} + +static void +c255_sub(uint32_t *d, const uint32_t *a, const uint32_t *b) +{ + uint32_t t[10]; + + memcpy(t, a, sizeof t); + br_i31_add(t, C255_P, br_i31_sub(t, b, 1)); + memcpy(d, t, sizeof t); +} + +static void +c255_mul(uint32_t *d, const uint32_t *a, const uint32_t *b) +{ + uint32_t t[10]; + + br_i31_montymul(t, a, b, C255_P, P0I); + memcpy(d, t, sizeof t); +} + +static void +byteswap(unsigned char *G) +{ + int i; + + for (i = 0; i < 16; i ++) { + unsigned char t; + + t = G[i]; + G[i] = G[31 - i]; + G[31 - i] = t; + } +} + +static uint32_t +api_mul(unsigned char *G, size_t Glen, + const unsigned char *kb, size_t kblen, int curve) +{ + uint32_t x1[10], x2[10], x3[10], z2[10], z3[10]; + uint32_t a[10], aa[10], b[10], bb[10]; + uint32_t c[10], d[10], e[10], da[10], cb[10]; + unsigned char k[32]; + uint32_t swap; + int i; + + (void)curve; + + /* + * Points are encoded over exactly 32 bytes. Multipliers must fit + * in 32 bytes as well. + * RFC 7748 mandates that the high bit of the last point byte must + * be ignored/cleared. + */ + if (Glen != 32 || kblen > 32) { + return 0; + } + G[31] &= 0x7F; + + /* + * Byteswap the point encoding, because it uses little-endian, and + * the generic decoding routine uses big-endian. + */ + byteswap(G); + + /* + * Decode the point ('u' coordinate). This should be reduced + * modulo p, but we prefer to avoid the dependency on + * br_i31_decode_reduce(). Instead, we use br_i31_decode_mod() + * with a synthetic modulus of value 2^255 (this must work + * since G was truncated to 255 bits), then use a conditional + * subtraction. We use br_i31_decode_mod() and not + * br_i31_decode(), because the ec_prime_i31 implementation uses + * the former but not the latter. + * br_i31_decode_reduce(a, G, 32, C255_P); + */ + br_i31_zero(b, 0x108); + b[9] = 0x0080; + br_i31_decode_mod(a, G, 32, b); + a[0] = 0x107; + br_i31_sub(a, C255_P, NOT(br_i31_sub(a, C255_P, 0))); + + /* + * Initialise variables x1, x2, z2, x3 and z3. We set all of them + * into Montgomery representation. + */ + br_i31_montymul(x1, a, C255_R2, C255_P, P0I); + memcpy(x3, x1, sizeof x1); + br_i31_zero(z2, C255_P[0]); + memcpy(x2, z2, sizeof z2); + x2[1] = 0x13000000; + memcpy(z3, x2, sizeof x2); + + /* + * kb[] is in big-endian notation, but possibly shorter than k[]. + */ + memset(k, 0, (sizeof k) - kblen); + memcpy(k + (sizeof k) - kblen, kb, kblen); + k[31] &= 0xF8; + k[0] &= 0x7F; + k[0] |= 0x40; + + /* obsolete + print_int_mont("x1", x1); + */ + + swap = 0; + for (i = 254; i >= 0; i --) { + uint32_t kt; + + kt = (k[31 - (i >> 3)] >> (i & 7)) & 1; + swap ^= kt; + cswap(x2, x3, swap); + cswap(z2, z3, swap); + swap = kt; + + /* obsolete + print_int_mont("x2", x2); + print_int_mont("z2", z2); + print_int_mont("x3", x3); + print_int_mont("z3", z3); + */ + + c255_add(a, x2, z2); + c255_mul(aa, a, a); + c255_sub(b, x2, z2); + c255_mul(bb, b, b); + c255_sub(e, aa, bb); + c255_add(c, x3, z3); + c255_sub(d, x3, z3); + c255_mul(da, d, a); + c255_mul(cb, c, b); + + /* obsolete + print_int_mont("a ", a); + print_int_mont("aa", aa); + print_int_mont("b ", b); + print_int_mont("bb", bb); + print_int_mont("e ", e); + print_int_mont("c ", c); + print_int_mont("d ", d); + print_int_mont("da", da); + print_int_mont("cb", cb); + */ + + c255_add(x3, da, cb); + c255_mul(x3, x3, x3); + c255_sub(z3, da, cb); + c255_mul(z3, z3, z3); + c255_mul(z3, z3, x1); + c255_mul(x2, aa, bb); + c255_mul(z2, C255_A24, e); + c255_add(z2, z2, aa); + c255_mul(z2, e, z2); + + /* obsolete + print_int_mont("x2", x2); + print_int_mont("z2", z2); + print_int_mont("x3", x3); + print_int_mont("z3", z3); + */ + } + cswap(x2, x3, swap); + cswap(z2, z3, swap); + + /* + * Inverse z2 with a modular exponentiation. This is a simple + * square-and-multiply algorithm; we mutualise most non-squarings + * since the exponent contains almost only ones. + */ + memcpy(a, z2, sizeof z2); + for (i = 0; i < 15; i ++) { + c255_mul(a, a, a); + c255_mul(a, a, z2); + } + memcpy(b, a, sizeof a); + for (i = 0; i < 14; i ++) { + int j; + + for (j = 0; j < 16; j ++) { + c255_mul(b, b, b); + } + c255_mul(b, b, a); + } + for (i = 14; i >= 0; i --) { + c255_mul(b, b, b); + if ((0xFFEB >> i) & 1) { + c255_mul(b, z2, b); + } + } + c255_mul(b, x2, b); + + /* + * To avoid a dependency on br_i31_from_monty(), we use + * a Montgomery multiplication with 1. + * memcpy(x2, b, sizeof b); + * br_i31_from_monty(x2, C255_P, P0I); + */ + br_i31_zero(a, C255_P[0]); + a[1] = 1; + br_i31_montymul(x2, a, b, C255_P, P0I); + + br_i31_encode(G, 32, x2); + byteswap(G); + return 1; +} + +static size_t +api_mulgen(unsigned char *R, + const unsigned char *x, size_t xlen, int curve) +{ + const unsigned char *G; + size_t Glen; + + G = api_generator(curve, &Glen); + memcpy(R, G, Glen); + api_mul(R, Glen, x, xlen, curve); + return Glen; +} + +static uint32_t +api_muladd(unsigned char *A, const unsigned char *B, size_t len, + const unsigned char *x, size_t xlen, + const unsigned char *y, size_t ylen, int curve) +{ + /* + * We don't implement this method, since it is used for ECDSA + * only, and there is no ECDSA over Curve25519 (which instead + * uses EdDSA). + */ + (void)A; + (void)B; + (void)len; + (void)x; + (void)xlen; + (void)y; + (void)ylen; + (void)curve; + return 0; +} + +/* see bearssl_ec.h */ +const br_ec_impl br_ec_c25519_i31 = { + (uint32_t)0x20000000, + &api_generator, + &api_order, + &api_xoff, + &api_mul, + &api_mulgen, + &api_muladd +}; + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_c25519_m15.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_c25519_m15.c new file mode 100644 index 000000000..3772b9ded --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_c25519_m15.c @@ -0,0 +1,1483 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* obsolete +#include +#include +static void +print_int(const char *name, const uint32_t *x) +{ + size_t u; + unsigned char tmp[36]; + + printf("%s = ", name); + for (u = 0; u < 20; u ++) { + if (x[u] > 0x1FFF) { + printf("INVALID:"); + for (u = 0; u < 20; u ++) { + printf(" %04X", x[u]); + } + printf("\n"); + return; + } + } + memset(tmp, 0, sizeof tmp); + for (u = 0; u < 20; u ++) { + uint32_t w; + int j, k; + + w = x[u]; + j = 13 * (int)u; + k = j & 7; + if (k != 0) { + w <<= k; + j -= k; + } + k = j >> 3; + tmp[35 - k] |= (unsigned char)w; + tmp[34 - k] |= (unsigned char)(w >> 8); + tmp[33 - k] |= (unsigned char)(w >> 16); + tmp[32 - k] |= (unsigned char)(w >> 24); + } + for (u = 4; u < 36; u ++) { + printf("%02X", tmp[u]); + } + printf("\n"); +} +*/ + +/* + * If BR_NO_ARITH_SHIFT is undefined, or defined to 0, then we _assume_ + * that right-shifting a signed negative integer copies the sign bit + * (arithmetic right-shift). This is "implementation-defined behaviour", + * i.e. it is not undefined, but it may differ between compilers. Each + * compiler is supposed to document its behaviour in that respect. GCC + * explicitly defines that an arithmetic right shift is used. We expect + * all other compilers to do the same, because underlying CPU offer an + * arithmetic right shift opcode that could not be used otherwise. + */ +#if BR_NO_ARITH_SHIFT +#define ARSH(x, n) (((uint32_t)(x) >> (n)) \ + | ((-((uint32_t)(x) >> 31)) << (32 - (n)))) +#else +#define ARSH(x, n) ((*(int32_t *)&(x)) >> (n)) +#endif + +/* + * Convert an integer from unsigned little-endian encoding to a sequence of + * 13-bit words in little-endian order. The final "partial" word is + * returned. + */ +static uint32_t +le8_to_le13(uint32_t *dst, const unsigned char *src, size_t len) +{ + uint32_t acc; + int acc_len; + + acc = 0; + acc_len = 0; + while (len -- > 0) { + acc |= (uint32_t)(*src ++) << acc_len; + acc_len += 8; + if (acc_len >= 13) { + *dst ++ = acc & 0x1FFF; + acc >>= 13; + acc_len -= 13; + } + } + return acc; +} + +/* + * Convert an integer (13-bit words, little-endian) to unsigned + * little-endian encoding. The total encoding length is provided; all + * the destination bytes will be filled. + */ +static void +le13_to_le8(unsigned char *dst, size_t len, const uint32_t *src) +{ + uint32_t acc; + int acc_len; + + acc = 0; + acc_len = 0; + while (len -- > 0) { + if (acc_len < 8) { + acc |= (*src ++) << acc_len; + acc_len += 13; + } + *dst ++ = (unsigned char)acc; + acc >>= 8; + acc_len -= 8; + } +} + +/* + * Normalise an array of words to a strict 13 bits per word. Returned + * value is the resulting carry. The source (w) and destination (d) + * arrays may be identical, but shall not overlap partially. + */ +static inline uint32_t +norm13(uint32_t *d, const uint32_t *w, size_t len) +{ + size_t u; + uint32_t cc; + + cc = 0; + for (u = 0; u < len; u ++) { + int32_t z; + + z = w[u] + cc; + d[u] = z & 0x1FFF; + cc = ARSH(z, 13); + } + return cc; +} + +/* + * mul20() multiplies two 260-bit integers together. Each word must fit + * on 13 bits; source operands use 20 words, destination operand + * receives 40 words. All overlaps allowed. + * + * square20() computes the square of a 260-bit integer. Each word must + * fit on 13 bits; source operand uses 20 words, destination operand + * receives 40 words. All overlaps allowed. + */ + +#if BR_SLOW_MUL15 + +static void +mul20(uint32_t *d, const uint32_t *a, const uint32_t *b) +{ + /* + * Two-level Karatsuba: turns a 20x20 multiplication into + * nine 5x5 multiplications. We use 13-bit words but do not + * propagate carries immediately, so words may expand: + * + * - First Karatsuba decomposition turns the 20x20 mul on + * 13-bit words into three 10x10 muls, two on 13-bit words + * and one on 14-bit words. + * + * - Second Karatsuba decomposition further splits these into: + * + * * four 5x5 muls on 13-bit words + * * four 5x5 muls on 14-bit words + * * one 5x5 mul on 15-bit words + * + * Highest word value is 8191, 16382 or 32764, for 13-bit, 14-bit + * or 15-bit words, respectively. + */ + uint32_t u[45], v[45], w[90]; + uint32_t cc; + int i; + +#define ZADD(dw, d_off, s1w, s1_off, s2w, s2_off) do { \ + (dw)[5 * (d_off) + 0] = (s1w)[5 * (s1_off) + 0] \ + + (s2w)[5 * (s2_off) + 0]; \ + (dw)[5 * (d_off) + 1] = (s1w)[5 * (s1_off) + 1] \ + + (s2w)[5 * (s2_off) + 1]; \ + (dw)[5 * (d_off) + 2] = (s1w)[5 * (s1_off) + 2] \ + + (s2w)[5 * (s2_off) + 2]; \ + (dw)[5 * (d_off) + 3] = (s1w)[5 * (s1_off) + 3] \ + + (s2w)[5 * (s2_off) + 3]; \ + (dw)[5 * (d_off) + 4] = (s1w)[5 * (s1_off) + 4] \ + + (s2w)[5 * (s2_off) + 4]; \ + } while (0) + +#define ZADDT(dw, d_off, sw, s_off) do { \ + (dw)[5 * (d_off) + 0] += (sw)[5 * (s_off) + 0]; \ + (dw)[5 * (d_off) + 1] += (sw)[5 * (s_off) + 1]; \ + (dw)[5 * (d_off) + 2] += (sw)[5 * (s_off) + 2]; \ + (dw)[5 * (d_off) + 3] += (sw)[5 * (s_off) + 3]; \ + (dw)[5 * (d_off) + 4] += (sw)[5 * (s_off) + 4]; \ + } while (0) + +#define ZSUB2F(dw, d_off, s1w, s1_off, s2w, s2_off) do { \ + (dw)[5 * (d_off) + 0] -= (s1w)[5 * (s1_off) + 0] \ + + (s2w)[5 * (s2_off) + 0]; \ + (dw)[5 * (d_off) + 1] -= (s1w)[5 * (s1_off) + 1] \ + + (s2w)[5 * (s2_off) + 1]; \ + (dw)[5 * (d_off) + 2] -= (s1w)[5 * (s1_off) + 2] \ + + (s2w)[5 * (s2_off) + 2]; \ + (dw)[5 * (d_off) + 3] -= (s1w)[5 * (s1_off) + 3] \ + + (s2w)[5 * (s2_off) + 3]; \ + (dw)[5 * (d_off) + 4] -= (s1w)[5 * (s1_off) + 4] \ + + (s2w)[5 * (s2_off) + 4]; \ + } while (0) + +#define CPR1(w, cprcc) do { \ + uint32_t cprz = (w) + cprcc; \ + (w) = cprz & 0x1FFF; \ + cprcc = cprz >> 13; \ + } while (0) + +#define CPR(dw, d_off) do { \ + uint32_t cprcc; \ + cprcc = 0; \ + CPR1((dw)[(d_off) + 0], cprcc); \ + CPR1((dw)[(d_off) + 1], cprcc); \ + CPR1((dw)[(d_off) + 2], cprcc); \ + CPR1((dw)[(d_off) + 3], cprcc); \ + CPR1((dw)[(d_off) + 4], cprcc); \ + CPR1((dw)[(d_off) + 5], cprcc); \ + CPR1((dw)[(d_off) + 6], cprcc); \ + CPR1((dw)[(d_off) + 7], cprcc); \ + CPR1((dw)[(d_off) + 8], cprcc); \ + (dw)[(d_off) + 9] = cprcc; \ + } while (0) + + memcpy(u, a, 20 * sizeof *a); + ZADD(u, 4, a, 0, a, 1); + ZADD(u, 5, a, 2, a, 3); + ZADD(u, 6, a, 0, a, 2); + ZADD(u, 7, a, 1, a, 3); + ZADD(u, 8, u, 6, u, 7); + + memcpy(v, b, 20 * sizeof *b); + ZADD(v, 4, b, 0, b, 1); + ZADD(v, 5, b, 2, b, 3); + ZADD(v, 6, b, 0, b, 2); + ZADD(v, 7, b, 1, b, 3); + ZADD(v, 8, v, 6, v, 7); + + /* + * Do the eight first 8x8 muls. Source words are at most 16382 + * each, so we can add product results together "as is" in 32-bit + * words. + */ + for (i = 0; i < 40; i += 5) { + w[(i << 1) + 0] = MUL15(u[i + 0], v[i + 0]); + w[(i << 1) + 1] = MUL15(u[i + 0], v[i + 1]) + + MUL15(u[i + 1], v[i + 0]); + w[(i << 1) + 2] = MUL15(u[i + 0], v[i + 2]) + + MUL15(u[i + 1], v[i + 1]) + + MUL15(u[i + 2], v[i + 0]); + w[(i << 1) + 3] = MUL15(u[i + 0], v[i + 3]) + + MUL15(u[i + 1], v[i + 2]) + + MUL15(u[i + 2], v[i + 1]) + + MUL15(u[i + 3], v[i + 0]); + w[(i << 1) + 4] = MUL15(u[i + 0], v[i + 4]) + + MUL15(u[i + 1], v[i + 3]) + + MUL15(u[i + 2], v[i + 2]) + + MUL15(u[i + 3], v[i + 1]) + + MUL15(u[i + 4], v[i + 0]); + w[(i << 1) + 5] = MUL15(u[i + 1], v[i + 4]) + + MUL15(u[i + 2], v[i + 3]) + + MUL15(u[i + 3], v[i + 2]) + + MUL15(u[i + 4], v[i + 1]); + w[(i << 1) + 6] = MUL15(u[i + 2], v[i + 4]) + + MUL15(u[i + 3], v[i + 3]) + + MUL15(u[i + 4], v[i + 2]); + w[(i << 1) + 7] = MUL15(u[i + 3], v[i + 4]) + + MUL15(u[i + 4], v[i + 3]); + w[(i << 1) + 8] = MUL15(u[i + 4], v[i + 4]); + w[(i << 1) + 9] = 0; + } + + /* + * For the 9th multiplication, source words are up to 32764, + * so we must do some carry propagation. If we add up to + * 4 products and the carry is no more than 524224, then the + * result fits in 32 bits, and the next carry will be no more + * than 524224 (because 4*(32764^2)+524224 < 8192*524225). + * + * We thus just skip one of the products in the middle word, + * then do a carry propagation (this reduces words to 13 bits + * each, except possibly the last, which may use up to 17 bits + * or so), then add the missing product. + */ + w[80 + 0] = MUL15(u[40 + 0], v[40 + 0]); + w[80 + 1] = MUL15(u[40 + 0], v[40 + 1]) + + MUL15(u[40 + 1], v[40 + 0]); + w[80 + 2] = MUL15(u[40 + 0], v[40 + 2]) + + MUL15(u[40 + 1], v[40 + 1]) + + MUL15(u[40 + 2], v[40 + 0]); + w[80 + 3] = MUL15(u[40 + 0], v[40 + 3]) + + MUL15(u[40 + 1], v[40 + 2]) + + MUL15(u[40 + 2], v[40 + 1]) + + MUL15(u[40 + 3], v[40 + 0]); + w[80 + 4] = MUL15(u[40 + 0], v[40 + 4]) + + MUL15(u[40 + 1], v[40 + 3]) + + MUL15(u[40 + 2], v[40 + 2]) + + MUL15(u[40 + 3], v[40 + 1]); + /* + MUL15(u[40 + 4], v[40 + 0]) */ + w[80 + 5] = MUL15(u[40 + 1], v[40 + 4]) + + MUL15(u[40 + 2], v[40 + 3]) + + MUL15(u[40 + 3], v[40 + 2]) + + MUL15(u[40 + 4], v[40 + 1]); + w[80 + 6] = MUL15(u[40 + 2], v[40 + 4]) + + MUL15(u[40 + 3], v[40 + 3]) + + MUL15(u[40 + 4], v[40 + 2]); + w[80 + 7] = MUL15(u[40 + 3], v[40 + 4]) + + MUL15(u[40 + 4], v[40 + 3]); + w[80 + 8] = MUL15(u[40 + 4], v[40 + 4]); + + CPR(w, 80); + + w[80 + 4] += MUL15(u[40 + 4], v[40 + 0]); + + /* + * The products on 14-bit words in slots 6 and 7 yield values + * up to 5*(16382^2) each, and we need to subtract two such + * values from the higher word. We need the subtraction to fit + * in a _signed_ 32-bit integer, i.e. 31 bits + a sign bit. + * However, 10*(16382^2) does not fit. So we must perform a + * bit of reduction here. + */ + CPR(w, 60); + CPR(w, 70); + + /* + * Recompose results. + */ + + /* 0..1*0..1 into 0..3 */ + ZSUB2F(w, 8, w, 0, w, 2); + ZSUB2F(w, 9, w, 1, w, 3); + ZADDT(w, 1, w, 8); + ZADDT(w, 2, w, 9); + + /* 2..3*2..3 into 4..7 */ + ZSUB2F(w, 10, w, 4, w, 6); + ZSUB2F(w, 11, w, 5, w, 7); + ZADDT(w, 5, w, 10); + ZADDT(w, 6, w, 11); + + /* (0..1+2..3)*(0..1+2..3) into 12..15 */ + ZSUB2F(w, 16, w, 12, w, 14); + ZSUB2F(w, 17, w, 13, w, 15); + ZADDT(w, 13, w, 16); + ZADDT(w, 14, w, 17); + + /* first-level recomposition */ + ZSUB2F(w, 12, w, 0, w, 4); + ZSUB2F(w, 13, w, 1, w, 5); + ZSUB2F(w, 14, w, 2, w, 6); + ZSUB2F(w, 15, w, 3, w, 7); + ZADDT(w, 2, w, 12); + ZADDT(w, 3, w, 13); + ZADDT(w, 4, w, 14); + ZADDT(w, 5, w, 15); + + /* + * Perform carry propagation to bring all words down to 13 bits. + */ + cc = norm13(d, w, 40); + d[39] += (cc << 13); + +#undef ZADD +#undef ZADDT +#undef ZSUB2F +#undef CPR1 +#undef CPR +} + +static inline void +square20(uint32_t *d, const uint32_t *a) +{ + mul20(d, a, a); +} + +#else + +static void +mul20(uint32_t *d, const uint32_t *a, const uint32_t *b) +{ + uint32_t t[39]; + + t[ 0] = MUL15(a[ 0], b[ 0]); + t[ 1] = MUL15(a[ 0], b[ 1]) + + MUL15(a[ 1], b[ 0]); + t[ 2] = MUL15(a[ 0], b[ 2]) + + MUL15(a[ 1], b[ 1]) + + MUL15(a[ 2], b[ 0]); + t[ 3] = MUL15(a[ 0], b[ 3]) + + MUL15(a[ 1], b[ 2]) + + MUL15(a[ 2], b[ 1]) + + MUL15(a[ 3], b[ 0]); + t[ 4] = MUL15(a[ 0], b[ 4]) + + MUL15(a[ 1], b[ 3]) + + MUL15(a[ 2], b[ 2]) + + MUL15(a[ 3], b[ 1]) + + MUL15(a[ 4], b[ 0]); + t[ 5] = MUL15(a[ 0], b[ 5]) + + MUL15(a[ 1], b[ 4]) + + MUL15(a[ 2], b[ 3]) + + MUL15(a[ 3], b[ 2]) + + MUL15(a[ 4], b[ 1]) + + MUL15(a[ 5], b[ 0]); + t[ 6] = MUL15(a[ 0], b[ 6]) + + MUL15(a[ 1], b[ 5]) + + MUL15(a[ 2], b[ 4]) + + MUL15(a[ 3], b[ 3]) + + MUL15(a[ 4], b[ 2]) + + MUL15(a[ 5], b[ 1]) + + MUL15(a[ 6], b[ 0]); + t[ 7] = MUL15(a[ 0], b[ 7]) + + MUL15(a[ 1], b[ 6]) + + MUL15(a[ 2], b[ 5]) + + MUL15(a[ 3], b[ 4]) + + MUL15(a[ 4], b[ 3]) + + MUL15(a[ 5], b[ 2]) + + MUL15(a[ 6], b[ 1]) + + MUL15(a[ 7], b[ 0]); + t[ 8] = MUL15(a[ 0], b[ 8]) + + MUL15(a[ 1], b[ 7]) + + MUL15(a[ 2], b[ 6]) + + MUL15(a[ 3], b[ 5]) + + MUL15(a[ 4], b[ 4]) + + MUL15(a[ 5], b[ 3]) + + MUL15(a[ 6], b[ 2]) + + MUL15(a[ 7], b[ 1]) + + MUL15(a[ 8], b[ 0]); + t[ 9] = MUL15(a[ 0], b[ 9]) + + MUL15(a[ 1], b[ 8]) + + MUL15(a[ 2], b[ 7]) + + MUL15(a[ 3], b[ 6]) + + MUL15(a[ 4], b[ 5]) + + MUL15(a[ 5], b[ 4]) + + MUL15(a[ 6], b[ 3]) + + MUL15(a[ 7], b[ 2]) + + MUL15(a[ 8], b[ 1]) + + MUL15(a[ 9], b[ 0]); + t[10] = MUL15(a[ 0], b[10]) + + MUL15(a[ 1], b[ 9]) + + MUL15(a[ 2], b[ 8]) + + MUL15(a[ 3], b[ 7]) + + MUL15(a[ 4], b[ 6]) + + MUL15(a[ 5], b[ 5]) + + MUL15(a[ 6], b[ 4]) + + MUL15(a[ 7], b[ 3]) + + MUL15(a[ 8], b[ 2]) + + MUL15(a[ 9], b[ 1]) + + MUL15(a[10], b[ 0]); + t[11] = MUL15(a[ 0], b[11]) + + MUL15(a[ 1], b[10]) + + MUL15(a[ 2], b[ 9]) + + MUL15(a[ 3], b[ 8]) + + MUL15(a[ 4], b[ 7]) + + MUL15(a[ 5], b[ 6]) + + MUL15(a[ 6], b[ 5]) + + MUL15(a[ 7], b[ 4]) + + MUL15(a[ 8], b[ 3]) + + MUL15(a[ 9], b[ 2]) + + MUL15(a[10], b[ 1]) + + MUL15(a[11], b[ 0]); + t[12] = MUL15(a[ 0], b[12]) + + MUL15(a[ 1], b[11]) + + MUL15(a[ 2], b[10]) + + MUL15(a[ 3], b[ 9]) + + MUL15(a[ 4], b[ 8]) + + MUL15(a[ 5], b[ 7]) + + MUL15(a[ 6], b[ 6]) + + MUL15(a[ 7], b[ 5]) + + MUL15(a[ 8], b[ 4]) + + MUL15(a[ 9], b[ 3]) + + MUL15(a[10], b[ 2]) + + MUL15(a[11], b[ 1]) + + MUL15(a[12], b[ 0]); + t[13] = MUL15(a[ 0], b[13]) + + MUL15(a[ 1], b[12]) + + MUL15(a[ 2], b[11]) + + MUL15(a[ 3], b[10]) + + MUL15(a[ 4], b[ 9]) + + MUL15(a[ 5], b[ 8]) + + MUL15(a[ 6], b[ 7]) + + MUL15(a[ 7], b[ 6]) + + MUL15(a[ 8], b[ 5]) + + MUL15(a[ 9], b[ 4]) + + MUL15(a[10], b[ 3]) + + MUL15(a[11], b[ 2]) + + MUL15(a[12], b[ 1]) + + MUL15(a[13], b[ 0]); + t[14] = MUL15(a[ 0], b[14]) + + MUL15(a[ 1], b[13]) + + MUL15(a[ 2], b[12]) + + MUL15(a[ 3], b[11]) + + MUL15(a[ 4], b[10]) + + MUL15(a[ 5], b[ 9]) + + MUL15(a[ 6], b[ 8]) + + MUL15(a[ 7], b[ 7]) + + MUL15(a[ 8], b[ 6]) + + MUL15(a[ 9], b[ 5]) + + MUL15(a[10], b[ 4]) + + MUL15(a[11], b[ 3]) + + MUL15(a[12], b[ 2]) + + MUL15(a[13], b[ 1]) + + MUL15(a[14], b[ 0]); + t[15] = MUL15(a[ 0], b[15]) + + MUL15(a[ 1], b[14]) + + MUL15(a[ 2], b[13]) + + MUL15(a[ 3], b[12]) + + MUL15(a[ 4], b[11]) + + MUL15(a[ 5], b[10]) + + MUL15(a[ 6], b[ 9]) + + MUL15(a[ 7], b[ 8]) + + MUL15(a[ 8], b[ 7]) + + MUL15(a[ 9], b[ 6]) + + MUL15(a[10], b[ 5]) + + MUL15(a[11], b[ 4]) + + MUL15(a[12], b[ 3]) + + MUL15(a[13], b[ 2]) + + MUL15(a[14], b[ 1]) + + MUL15(a[15], b[ 0]); + t[16] = MUL15(a[ 0], b[16]) + + MUL15(a[ 1], b[15]) + + MUL15(a[ 2], b[14]) + + MUL15(a[ 3], b[13]) + + MUL15(a[ 4], b[12]) + + MUL15(a[ 5], b[11]) + + MUL15(a[ 6], b[10]) + + MUL15(a[ 7], b[ 9]) + + MUL15(a[ 8], b[ 8]) + + MUL15(a[ 9], b[ 7]) + + MUL15(a[10], b[ 6]) + + MUL15(a[11], b[ 5]) + + MUL15(a[12], b[ 4]) + + MUL15(a[13], b[ 3]) + + MUL15(a[14], b[ 2]) + + MUL15(a[15], b[ 1]) + + MUL15(a[16], b[ 0]); + t[17] = MUL15(a[ 0], b[17]) + + MUL15(a[ 1], b[16]) + + MUL15(a[ 2], b[15]) + + MUL15(a[ 3], b[14]) + + MUL15(a[ 4], b[13]) + + MUL15(a[ 5], b[12]) + + MUL15(a[ 6], b[11]) + + MUL15(a[ 7], b[10]) + + MUL15(a[ 8], b[ 9]) + + MUL15(a[ 9], b[ 8]) + + MUL15(a[10], b[ 7]) + + MUL15(a[11], b[ 6]) + + MUL15(a[12], b[ 5]) + + MUL15(a[13], b[ 4]) + + MUL15(a[14], b[ 3]) + + MUL15(a[15], b[ 2]) + + MUL15(a[16], b[ 1]) + + MUL15(a[17], b[ 0]); + t[18] = MUL15(a[ 0], b[18]) + + MUL15(a[ 1], b[17]) + + MUL15(a[ 2], b[16]) + + MUL15(a[ 3], b[15]) + + MUL15(a[ 4], b[14]) + + MUL15(a[ 5], b[13]) + + MUL15(a[ 6], b[12]) + + MUL15(a[ 7], b[11]) + + MUL15(a[ 8], b[10]) + + MUL15(a[ 9], b[ 9]) + + MUL15(a[10], b[ 8]) + + MUL15(a[11], b[ 7]) + + MUL15(a[12], b[ 6]) + + MUL15(a[13], b[ 5]) + + MUL15(a[14], b[ 4]) + + MUL15(a[15], b[ 3]) + + MUL15(a[16], b[ 2]) + + MUL15(a[17], b[ 1]) + + MUL15(a[18], b[ 0]); + t[19] = MUL15(a[ 0], b[19]) + + MUL15(a[ 1], b[18]) + + MUL15(a[ 2], b[17]) + + MUL15(a[ 3], b[16]) + + MUL15(a[ 4], b[15]) + + MUL15(a[ 5], b[14]) + + MUL15(a[ 6], b[13]) + + MUL15(a[ 7], b[12]) + + MUL15(a[ 8], b[11]) + + MUL15(a[ 9], b[10]) + + MUL15(a[10], b[ 9]) + + MUL15(a[11], b[ 8]) + + MUL15(a[12], b[ 7]) + + MUL15(a[13], b[ 6]) + + MUL15(a[14], b[ 5]) + + MUL15(a[15], b[ 4]) + + MUL15(a[16], b[ 3]) + + MUL15(a[17], b[ 2]) + + MUL15(a[18], b[ 1]) + + MUL15(a[19], b[ 0]); + t[20] = MUL15(a[ 1], b[19]) + + MUL15(a[ 2], b[18]) + + MUL15(a[ 3], b[17]) + + MUL15(a[ 4], b[16]) + + MUL15(a[ 5], b[15]) + + MUL15(a[ 6], b[14]) + + MUL15(a[ 7], b[13]) + + MUL15(a[ 8], b[12]) + + MUL15(a[ 9], b[11]) + + MUL15(a[10], b[10]) + + MUL15(a[11], b[ 9]) + + MUL15(a[12], b[ 8]) + + MUL15(a[13], b[ 7]) + + MUL15(a[14], b[ 6]) + + MUL15(a[15], b[ 5]) + + MUL15(a[16], b[ 4]) + + MUL15(a[17], b[ 3]) + + MUL15(a[18], b[ 2]) + + MUL15(a[19], b[ 1]); + t[21] = MUL15(a[ 2], b[19]) + + MUL15(a[ 3], b[18]) + + MUL15(a[ 4], b[17]) + + MUL15(a[ 5], b[16]) + + MUL15(a[ 6], b[15]) + + MUL15(a[ 7], b[14]) + + MUL15(a[ 8], b[13]) + + MUL15(a[ 9], b[12]) + + MUL15(a[10], b[11]) + + MUL15(a[11], b[10]) + + MUL15(a[12], b[ 9]) + + MUL15(a[13], b[ 8]) + + MUL15(a[14], b[ 7]) + + MUL15(a[15], b[ 6]) + + MUL15(a[16], b[ 5]) + + MUL15(a[17], b[ 4]) + + MUL15(a[18], b[ 3]) + + MUL15(a[19], b[ 2]); + t[22] = MUL15(a[ 3], b[19]) + + MUL15(a[ 4], b[18]) + + MUL15(a[ 5], b[17]) + + MUL15(a[ 6], b[16]) + + MUL15(a[ 7], b[15]) + + MUL15(a[ 8], b[14]) + + MUL15(a[ 9], b[13]) + + MUL15(a[10], b[12]) + + MUL15(a[11], b[11]) + + MUL15(a[12], b[10]) + + MUL15(a[13], b[ 9]) + + MUL15(a[14], b[ 8]) + + MUL15(a[15], b[ 7]) + + MUL15(a[16], b[ 6]) + + MUL15(a[17], b[ 5]) + + MUL15(a[18], b[ 4]) + + MUL15(a[19], b[ 3]); + t[23] = MUL15(a[ 4], b[19]) + + MUL15(a[ 5], b[18]) + + MUL15(a[ 6], b[17]) + + MUL15(a[ 7], b[16]) + + MUL15(a[ 8], b[15]) + + MUL15(a[ 9], b[14]) + + MUL15(a[10], b[13]) + + MUL15(a[11], b[12]) + + MUL15(a[12], b[11]) + + MUL15(a[13], b[10]) + + MUL15(a[14], b[ 9]) + + MUL15(a[15], b[ 8]) + + MUL15(a[16], b[ 7]) + + MUL15(a[17], b[ 6]) + + MUL15(a[18], b[ 5]) + + MUL15(a[19], b[ 4]); + t[24] = MUL15(a[ 5], b[19]) + + MUL15(a[ 6], b[18]) + + MUL15(a[ 7], b[17]) + + MUL15(a[ 8], b[16]) + + MUL15(a[ 9], b[15]) + + MUL15(a[10], b[14]) + + MUL15(a[11], b[13]) + + MUL15(a[12], b[12]) + + MUL15(a[13], b[11]) + + MUL15(a[14], b[10]) + + MUL15(a[15], b[ 9]) + + MUL15(a[16], b[ 8]) + + MUL15(a[17], b[ 7]) + + MUL15(a[18], b[ 6]) + + MUL15(a[19], b[ 5]); + t[25] = MUL15(a[ 6], b[19]) + + MUL15(a[ 7], b[18]) + + MUL15(a[ 8], b[17]) + + MUL15(a[ 9], b[16]) + + MUL15(a[10], b[15]) + + MUL15(a[11], b[14]) + + MUL15(a[12], b[13]) + + MUL15(a[13], b[12]) + + MUL15(a[14], b[11]) + + MUL15(a[15], b[10]) + + MUL15(a[16], b[ 9]) + + MUL15(a[17], b[ 8]) + + MUL15(a[18], b[ 7]) + + MUL15(a[19], b[ 6]); + t[26] = MUL15(a[ 7], b[19]) + + MUL15(a[ 8], b[18]) + + MUL15(a[ 9], b[17]) + + MUL15(a[10], b[16]) + + MUL15(a[11], b[15]) + + MUL15(a[12], b[14]) + + MUL15(a[13], b[13]) + + MUL15(a[14], b[12]) + + MUL15(a[15], b[11]) + + MUL15(a[16], b[10]) + + MUL15(a[17], b[ 9]) + + MUL15(a[18], b[ 8]) + + MUL15(a[19], b[ 7]); + t[27] = MUL15(a[ 8], b[19]) + + MUL15(a[ 9], b[18]) + + MUL15(a[10], b[17]) + + MUL15(a[11], b[16]) + + MUL15(a[12], b[15]) + + MUL15(a[13], b[14]) + + MUL15(a[14], b[13]) + + MUL15(a[15], b[12]) + + MUL15(a[16], b[11]) + + MUL15(a[17], b[10]) + + MUL15(a[18], b[ 9]) + + MUL15(a[19], b[ 8]); + t[28] = MUL15(a[ 9], b[19]) + + MUL15(a[10], b[18]) + + MUL15(a[11], b[17]) + + MUL15(a[12], b[16]) + + MUL15(a[13], b[15]) + + MUL15(a[14], b[14]) + + MUL15(a[15], b[13]) + + MUL15(a[16], b[12]) + + MUL15(a[17], b[11]) + + MUL15(a[18], b[10]) + + MUL15(a[19], b[ 9]); + t[29] = MUL15(a[10], b[19]) + + MUL15(a[11], b[18]) + + MUL15(a[12], b[17]) + + MUL15(a[13], b[16]) + + MUL15(a[14], b[15]) + + MUL15(a[15], b[14]) + + MUL15(a[16], b[13]) + + MUL15(a[17], b[12]) + + MUL15(a[18], b[11]) + + MUL15(a[19], b[10]); + t[30] = MUL15(a[11], b[19]) + + MUL15(a[12], b[18]) + + MUL15(a[13], b[17]) + + MUL15(a[14], b[16]) + + MUL15(a[15], b[15]) + + MUL15(a[16], b[14]) + + MUL15(a[17], b[13]) + + MUL15(a[18], b[12]) + + MUL15(a[19], b[11]); + t[31] = MUL15(a[12], b[19]) + + MUL15(a[13], b[18]) + + MUL15(a[14], b[17]) + + MUL15(a[15], b[16]) + + MUL15(a[16], b[15]) + + MUL15(a[17], b[14]) + + MUL15(a[18], b[13]) + + MUL15(a[19], b[12]); + t[32] = MUL15(a[13], b[19]) + + MUL15(a[14], b[18]) + + MUL15(a[15], b[17]) + + MUL15(a[16], b[16]) + + MUL15(a[17], b[15]) + + MUL15(a[18], b[14]) + + MUL15(a[19], b[13]); + t[33] = MUL15(a[14], b[19]) + + MUL15(a[15], b[18]) + + MUL15(a[16], b[17]) + + MUL15(a[17], b[16]) + + MUL15(a[18], b[15]) + + MUL15(a[19], b[14]); + t[34] = MUL15(a[15], b[19]) + + MUL15(a[16], b[18]) + + MUL15(a[17], b[17]) + + MUL15(a[18], b[16]) + + MUL15(a[19], b[15]); + t[35] = MUL15(a[16], b[19]) + + MUL15(a[17], b[18]) + + MUL15(a[18], b[17]) + + MUL15(a[19], b[16]); + t[36] = MUL15(a[17], b[19]) + + MUL15(a[18], b[18]) + + MUL15(a[19], b[17]); + t[37] = MUL15(a[18], b[19]) + + MUL15(a[19], b[18]); + t[38] = MUL15(a[19], b[19]); + + d[39] = norm13(d, t, 39); +} + +static void +square20(uint32_t *d, const uint32_t *a) +{ + uint32_t t[39]; + + t[ 0] = MUL15(a[ 0], a[ 0]); + t[ 1] = ((MUL15(a[ 0], a[ 1])) << 1); + t[ 2] = MUL15(a[ 1], a[ 1]) + + ((MUL15(a[ 0], a[ 2])) << 1); + t[ 3] = ((MUL15(a[ 0], a[ 3]) + + MUL15(a[ 1], a[ 2])) << 1); + t[ 4] = MUL15(a[ 2], a[ 2]) + + ((MUL15(a[ 0], a[ 4]) + + MUL15(a[ 1], a[ 3])) << 1); + t[ 5] = ((MUL15(a[ 0], a[ 5]) + + MUL15(a[ 1], a[ 4]) + + MUL15(a[ 2], a[ 3])) << 1); + t[ 6] = MUL15(a[ 3], a[ 3]) + + ((MUL15(a[ 0], a[ 6]) + + MUL15(a[ 1], a[ 5]) + + MUL15(a[ 2], a[ 4])) << 1); + t[ 7] = ((MUL15(a[ 0], a[ 7]) + + MUL15(a[ 1], a[ 6]) + + MUL15(a[ 2], a[ 5]) + + MUL15(a[ 3], a[ 4])) << 1); + t[ 8] = MUL15(a[ 4], a[ 4]) + + ((MUL15(a[ 0], a[ 8]) + + MUL15(a[ 1], a[ 7]) + + MUL15(a[ 2], a[ 6]) + + MUL15(a[ 3], a[ 5])) << 1); + t[ 9] = ((MUL15(a[ 0], a[ 9]) + + MUL15(a[ 1], a[ 8]) + + MUL15(a[ 2], a[ 7]) + + MUL15(a[ 3], a[ 6]) + + MUL15(a[ 4], a[ 5])) << 1); + t[10] = MUL15(a[ 5], a[ 5]) + + ((MUL15(a[ 0], a[10]) + + MUL15(a[ 1], a[ 9]) + + MUL15(a[ 2], a[ 8]) + + MUL15(a[ 3], a[ 7]) + + MUL15(a[ 4], a[ 6])) << 1); + t[11] = ((MUL15(a[ 0], a[11]) + + MUL15(a[ 1], a[10]) + + MUL15(a[ 2], a[ 9]) + + MUL15(a[ 3], a[ 8]) + + MUL15(a[ 4], a[ 7]) + + MUL15(a[ 5], a[ 6])) << 1); + t[12] = MUL15(a[ 6], a[ 6]) + + ((MUL15(a[ 0], a[12]) + + MUL15(a[ 1], a[11]) + + MUL15(a[ 2], a[10]) + + MUL15(a[ 3], a[ 9]) + + MUL15(a[ 4], a[ 8]) + + MUL15(a[ 5], a[ 7])) << 1); + t[13] = ((MUL15(a[ 0], a[13]) + + MUL15(a[ 1], a[12]) + + MUL15(a[ 2], a[11]) + + MUL15(a[ 3], a[10]) + + MUL15(a[ 4], a[ 9]) + + MUL15(a[ 5], a[ 8]) + + MUL15(a[ 6], a[ 7])) << 1); + t[14] = MUL15(a[ 7], a[ 7]) + + ((MUL15(a[ 0], a[14]) + + MUL15(a[ 1], a[13]) + + MUL15(a[ 2], a[12]) + + MUL15(a[ 3], a[11]) + + MUL15(a[ 4], a[10]) + + MUL15(a[ 5], a[ 9]) + + MUL15(a[ 6], a[ 8])) << 1); + t[15] = ((MUL15(a[ 0], a[15]) + + MUL15(a[ 1], a[14]) + + MUL15(a[ 2], a[13]) + + MUL15(a[ 3], a[12]) + + MUL15(a[ 4], a[11]) + + MUL15(a[ 5], a[10]) + + MUL15(a[ 6], a[ 9]) + + MUL15(a[ 7], a[ 8])) << 1); + t[16] = MUL15(a[ 8], a[ 8]) + + ((MUL15(a[ 0], a[16]) + + MUL15(a[ 1], a[15]) + + MUL15(a[ 2], a[14]) + + MUL15(a[ 3], a[13]) + + MUL15(a[ 4], a[12]) + + MUL15(a[ 5], a[11]) + + MUL15(a[ 6], a[10]) + + MUL15(a[ 7], a[ 9])) << 1); + t[17] = ((MUL15(a[ 0], a[17]) + + MUL15(a[ 1], a[16]) + + MUL15(a[ 2], a[15]) + + MUL15(a[ 3], a[14]) + + MUL15(a[ 4], a[13]) + + MUL15(a[ 5], a[12]) + + MUL15(a[ 6], a[11]) + + MUL15(a[ 7], a[10]) + + MUL15(a[ 8], a[ 9])) << 1); + t[18] = MUL15(a[ 9], a[ 9]) + + ((MUL15(a[ 0], a[18]) + + MUL15(a[ 1], a[17]) + + MUL15(a[ 2], a[16]) + + MUL15(a[ 3], a[15]) + + MUL15(a[ 4], a[14]) + + MUL15(a[ 5], a[13]) + + MUL15(a[ 6], a[12]) + + MUL15(a[ 7], a[11]) + + MUL15(a[ 8], a[10])) << 1); + t[19] = ((MUL15(a[ 0], a[19]) + + MUL15(a[ 1], a[18]) + + MUL15(a[ 2], a[17]) + + MUL15(a[ 3], a[16]) + + MUL15(a[ 4], a[15]) + + MUL15(a[ 5], a[14]) + + MUL15(a[ 6], a[13]) + + MUL15(a[ 7], a[12]) + + MUL15(a[ 8], a[11]) + + MUL15(a[ 9], a[10])) << 1); + t[20] = MUL15(a[10], a[10]) + + ((MUL15(a[ 1], a[19]) + + MUL15(a[ 2], a[18]) + + MUL15(a[ 3], a[17]) + + MUL15(a[ 4], a[16]) + + MUL15(a[ 5], a[15]) + + MUL15(a[ 6], a[14]) + + MUL15(a[ 7], a[13]) + + MUL15(a[ 8], a[12]) + + MUL15(a[ 9], a[11])) << 1); + t[21] = ((MUL15(a[ 2], a[19]) + + MUL15(a[ 3], a[18]) + + MUL15(a[ 4], a[17]) + + MUL15(a[ 5], a[16]) + + MUL15(a[ 6], a[15]) + + MUL15(a[ 7], a[14]) + + MUL15(a[ 8], a[13]) + + MUL15(a[ 9], a[12]) + + MUL15(a[10], a[11])) << 1); + t[22] = MUL15(a[11], a[11]) + + ((MUL15(a[ 3], a[19]) + + MUL15(a[ 4], a[18]) + + MUL15(a[ 5], a[17]) + + MUL15(a[ 6], a[16]) + + MUL15(a[ 7], a[15]) + + MUL15(a[ 8], a[14]) + + MUL15(a[ 9], a[13]) + + MUL15(a[10], a[12])) << 1); + t[23] = ((MUL15(a[ 4], a[19]) + + MUL15(a[ 5], a[18]) + + MUL15(a[ 6], a[17]) + + MUL15(a[ 7], a[16]) + + MUL15(a[ 8], a[15]) + + MUL15(a[ 9], a[14]) + + MUL15(a[10], a[13]) + + MUL15(a[11], a[12])) << 1); + t[24] = MUL15(a[12], a[12]) + + ((MUL15(a[ 5], a[19]) + + MUL15(a[ 6], a[18]) + + MUL15(a[ 7], a[17]) + + MUL15(a[ 8], a[16]) + + MUL15(a[ 9], a[15]) + + MUL15(a[10], a[14]) + + MUL15(a[11], a[13])) << 1); + t[25] = ((MUL15(a[ 6], a[19]) + + MUL15(a[ 7], a[18]) + + MUL15(a[ 8], a[17]) + + MUL15(a[ 9], a[16]) + + MUL15(a[10], a[15]) + + MUL15(a[11], a[14]) + + MUL15(a[12], a[13])) << 1); + t[26] = MUL15(a[13], a[13]) + + ((MUL15(a[ 7], a[19]) + + MUL15(a[ 8], a[18]) + + MUL15(a[ 9], a[17]) + + MUL15(a[10], a[16]) + + MUL15(a[11], a[15]) + + MUL15(a[12], a[14])) << 1); + t[27] = ((MUL15(a[ 8], a[19]) + + MUL15(a[ 9], a[18]) + + MUL15(a[10], a[17]) + + MUL15(a[11], a[16]) + + MUL15(a[12], a[15]) + + MUL15(a[13], a[14])) << 1); + t[28] = MUL15(a[14], a[14]) + + ((MUL15(a[ 9], a[19]) + + MUL15(a[10], a[18]) + + MUL15(a[11], a[17]) + + MUL15(a[12], a[16]) + + MUL15(a[13], a[15])) << 1); + t[29] = ((MUL15(a[10], a[19]) + + MUL15(a[11], a[18]) + + MUL15(a[12], a[17]) + + MUL15(a[13], a[16]) + + MUL15(a[14], a[15])) << 1); + t[30] = MUL15(a[15], a[15]) + + ((MUL15(a[11], a[19]) + + MUL15(a[12], a[18]) + + MUL15(a[13], a[17]) + + MUL15(a[14], a[16])) << 1); + t[31] = ((MUL15(a[12], a[19]) + + MUL15(a[13], a[18]) + + MUL15(a[14], a[17]) + + MUL15(a[15], a[16])) << 1); + t[32] = MUL15(a[16], a[16]) + + ((MUL15(a[13], a[19]) + + MUL15(a[14], a[18]) + + MUL15(a[15], a[17])) << 1); + t[33] = ((MUL15(a[14], a[19]) + + MUL15(a[15], a[18]) + + MUL15(a[16], a[17])) << 1); + t[34] = MUL15(a[17], a[17]) + + ((MUL15(a[15], a[19]) + + MUL15(a[16], a[18])) << 1); + t[35] = ((MUL15(a[16], a[19]) + + MUL15(a[17], a[18])) << 1); + t[36] = MUL15(a[18], a[18]) + + ((MUL15(a[17], a[19])) << 1); + t[37] = ((MUL15(a[18], a[19])) << 1); + t[38] = MUL15(a[19], a[19]); + + d[39] = norm13(d, t, 39); +} + +#endif + +/* + * Perform a "final reduction" in field F255 (field for Curve25519) + * The source value must be less than twice the modulus. If the value + * is not lower than the modulus, then the modulus is subtracted and + * this function returns 1; otherwise, it leaves it untouched and it + * returns 0. + */ +static uint32_t +reduce_final_f255(uint32_t *d) +{ + uint32_t t[20]; + uint32_t cc; + int i; + + memcpy(t, d, sizeof t); + cc = 19; + for (i = 0; i < 20; i ++) { + uint32_t w; + + w = t[i] + cc; + cc = w >> 13; + t[i] = w & 0x1FFF; + } + cc = t[19] >> 8; + t[19] &= 0xFF; + CCOPY(cc, d, t, sizeof t); + return cc; +} + +static void +f255_mulgen(uint32_t *d, const uint32_t *a, const uint32_t *b, int square) +{ + uint32_t t[40], cc, w; + + /* + * Compute raw multiplication. All result words fit in 13 bits + * each; upper word (t[39]) must fit on 5 bits, since the product + * of two 256-bit integers must fit on 512 bits. + */ + if (square) { + square20(t, a); + } else { + mul20(t, a, b); + } + + /* + * Modular reduction: each high word is added where necessary. + * Since the modulus is 2^255-19 and word 20 corresponds to + * offset 20*13 = 260, word 20+k must be added to word k with + * a factor of 19*2^5 = 608. The extra bits in word 19 are also + * added that way. + */ + cc = MUL15(t[19] >> 8, 19); + t[19] &= 0xFF; + +#define MM1(x) do { \ + w = t[x] + cc + MUL15(t[(x) + 20], 608); \ + t[x] = w & 0x1FFF; \ + cc = w >> 13; \ + } while (0) + + MM1( 0); + MM1( 1); + MM1( 2); + MM1( 3); + MM1( 4); + MM1( 5); + MM1( 6); + MM1( 7); + MM1( 8); + MM1( 9); + MM1(10); + MM1(11); + MM1(12); + MM1(13); + MM1(14); + MM1(15); + MM1(16); + MM1(17); + MM1(18); + MM1(19); + +#undef MM1 + + cc = MUL15(w >> 8, 19); + t[19] &= 0xFF; + +#define MM2(x) do { \ + w = t[x] + cc; \ + d[x] = w & 0x1FFF; \ + cc = w >> 13; \ + } while (0) + + MM2( 0); + MM2( 1); + MM2( 2); + MM2( 3); + MM2( 4); + MM2( 5); + MM2( 6); + MM2( 7); + MM2( 8); + MM2( 9); + MM2(10); + MM2(11); + MM2(12); + MM2(13); + MM2(14); + MM2(15); + MM2(16); + MM2(17); + MM2(18); + MM2(19); + +#undef MM2 +} + +/* + * Perform a multiplication of two integers modulo 2^255-19. + * Operands are arrays of 20 words, each containing 13 bits of data, in + * little-endian order. Input value may be up to 2^256-1; on output, value + * fits on 256 bits and is lower than twice the modulus. + * + * f255_mul() is the general multiplication, f255_square() is specialised + * for squarings. + */ +#define f255_mul(d, a, b) f255_mulgen(d, a, b, 0) +#define f255_square(d, a) f255_mulgen(d, a, a, 1) + +/* + * Add two values in F255. Partial reduction is performed (down to less + * than twice the modulus). + */ +static void +f255_add(uint32_t *d, const uint32_t *a, const uint32_t *b) +{ + int i; + uint32_t cc, w; + + cc = 0; + for (i = 0; i < 20; i ++) { + w = a[i] + b[i] + cc; + d[i] = w & 0x1FFF; + cc = w >> 13; + } + cc = MUL15(w >> 8, 19); + d[19] &= 0xFF; + for (i = 0; i < 20; i ++) { + w = d[i] + cc; + d[i] = w & 0x1FFF; + cc = w >> 13; + } +} + +/* + * Subtract one value from another in F255. Partial reduction is + * performed (down to less than twice the modulus). + */ +static void +f255_sub(uint32_t *d, const uint32_t *a, const uint32_t *b) +{ + /* + * We actually compute a - b + 2*p, so that the final value is + * necessarily positive. + */ + int i; + uint32_t cc, w; + + cc = (uint32_t)-38; + for (i = 0; i < 20; i ++) { + w = a[i] - b[i] + cc; + d[i] = w & 0x1FFF; + cc = ARSH(w, 13); + } + cc = MUL15((w + 0x200) >> 8, 19); + d[19] &= 0xFF; + for (i = 0; i < 20; i ++) { + w = d[i] + cc; + d[i] = w & 0x1FFF; + cc = w >> 13; + } +} + +/* + * Multiply an integer by the 'A24' constant (121665). Partial reduction + * is performed (down to less than twice the modulus). + */ +static void +f255_mul_a24(uint32_t *d, const uint32_t *a) +{ + int i; + uint32_t cc, w; + + cc = 0; + for (i = 0; i < 20; i ++) { + w = MUL15(a[i], 121665) + cc; + d[i] = w & 0x1FFF; + cc = w >> 13; + } + cc = MUL15(w >> 8, 19); + d[19] &= 0xFF; + for (i = 0; i < 20; i ++) { + w = d[i] + cc; + d[i] = w & 0x1FFF; + cc = w >> 13; + } +} + +static const unsigned char GEN[] = { + 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + +static const unsigned char ORDER[] = { + 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF +}; + +static const unsigned char * +api_generator(int curve, size_t *len) +{ + (void)curve; + *len = 32; + return GEN; +} + +static const unsigned char * +api_order(int curve, size_t *len) +{ + (void)curve; + *len = 32; + return ORDER; +} + +static size_t +api_xoff(int curve, size_t *len) +{ + (void)curve; + *len = 32; + return 0; +} + +static void +cswap(uint32_t *a, uint32_t *b, uint32_t ctl) +{ + int i; + + ctl = -ctl; + for (i = 0; i < 20; i ++) { + uint32_t aw, bw, tw; + + aw = a[i]; + bw = b[i]; + tw = ctl & (aw ^ bw); + a[i] = aw ^ tw; + b[i] = bw ^ tw; + } +} + +static uint32_t +api_mul(unsigned char *G, size_t Glen, + const unsigned char *kb, size_t kblen, int curve) +{ + uint32_t x1[20], x2[20], x3[20], z2[20], z3[20]; + uint32_t a[20], aa[20], b[20], bb[20]; + uint32_t c[20], d[20], e[20], da[20], cb[20]; + unsigned char k[32]; + uint32_t swap; + int i; + + (void)curve; + + /* + * Points are encoded over exactly 32 bytes. Multipliers must fit + * in 32 bytes as well. + * RFC 7748 mandates that the high bit of the last point byte must + * be ignored/cleared. + */ + if (Glen != 32 || kblen > 32) { + return 0; + } + G[31] &= 0x7F; + + /* + * Initialise variables x1, x2, z2, x3 and z3. We set all of them + * into Montgomery representation. + */ + x1[19] = le8_to_le13(x1, G, 32); + memcpy(x3, x1, sizeof x1); + memset(z2, 0, sizeof z2); + memset(x2, 0, sizeof x2); + x2[0] = 1; + memset(z3, 0, sizeof z3); + z3[0] = 1; + + memset(k, 0, (sizeof k) - kblen); + memcpy(k + (sizeof k) - kblen, kb, kblen); + k[31] &= 0xF8; + k[0] &= 0x7F; + k[0] |= 0x40; + + /* obsolete + print_int("x1", x1); + */ + + swap = 0; + for (i = 254; i >= 0; i --) { + uint32_t kt; + + kt = (k[31 - (i >> 3)] >> (i & 7)) & 1; + swap ^= kt; + cswap(x2, x3, swap); + cswap(z2, z3, swap); + swap = kt; + + /* obsolete + print_int("x2", x2); + print_int("z2", z2); + print_int("x3", x3); + print_int("z3", z3); + */ + + f255_add(a, x2, z2); + f255_square(aa, a); + f255_sub(b, x2, z2); + f255_square(bb, b); + f255_sub(e, aa, bb); + f255_add(c, x3, z3); + f255_sub(d, x3, z3); + f255_mul(da, d, a); + f255_mul(cb, c, b); + + /* obsolete + print_int("a ", a); + print_int("aa", aa); + print_int("b ", b); + print_int("bb", bb); + print_int("e ", e); + print_int("c ", c); + print_int("d ", d); + print_int("da", da); + print_int("cb", cb); + */ + + f255_add(x3, da, cb); + f255_square(x3, x3); + f255_sub(z3, da, cb); + f255_square(z3, z3); + f255_mul(z3, z3, x1); + f255_mul(x2, aa, bb); + f255_mul_a24(z2, e); + f255_add(z2, z2, aa); + f255_mul(z2, e, z2); + + /* obsolete + print_int("x2", x2); + print_int("z2", z2); + print_int("x3", x3); + print_int("z3", z3); + */ + } + cswap(x2, x3, swap); + cswap(z2, z3, swap); + + /* + * Inverse z2 with a modular exponentiation. This is a simple + * square-and-multiply algorithm; we mutualise most non-squarings + * since the exponent contains almost only ones. + */ + memcpy(a, z2, sizeof z2); + for (i = 0; i < 15; i ++) { + f255_square(a, a); + f255_mul(a, a, z2); + } + memcpy(b, a, sizeof a); + for (i = 0; i < 14; i ++) { + int j; + + for (j = 0; j < 16; j ++) { + f255_square(b, b); + } + f255_mul(b, b, a); + } + for (i = 14; i >= 0; i --) { + f255_square(b, b); + if ((0xFFEB >> i) & 1) { + f255_mul(b, z2, b); + } + } + f255_mul(x2, x2, b); + reduce_final_f255(x2); + le13_to_le8(G, 32, x2); + return 1; +} + +static size_t +api_mulgen(unsigned char *R, + const unsigned char *x, size_t xlen, int curve) +{ + const unsigned char *G; + size_t Glen; + + G = api_generator(curve, &Glen); + memcpy(R, G, Glen); + api_mul(R, Glen, x, xlen, curve); + return Glen; +} + +static uint32_t +api_muladd(unsigned char *A, const unsigned char *B, size_t len, + const unsigned char *x, size_t xlen, + const unsigned char *y, size_t ylen, int curve) +{ + /* + * We don't implement this method, since it is used for ECDSA + * only, and there is no ECDSA over Curve25519 (which instead + * uses EdDSA). + */ + (void)A; + (void)B; + (void)len; + (void)x; + (void)xlen; + (void)y; + (void)ylen; + (void)curve; + return 0; +} + +/* see bearssl_ec.h */ +const br_ec_impl br_ec_c25519_m15 = { + (uint32_t)0x20000000, + &api_generator, + &api_order, + &api_xoff, + &api_mul, + &api_mulgen, + &api_muladd +}; + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_c25519_m31.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_c25519_m31.c new file mode 100644 index 000000000..559830cec --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_c25519_m31.c @@ -0,0 +1,805 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* obsolete +#include +#include +static void +print_int(const char *name, const uint32_t *x) +{ + size_t u; + unsigned char tmp[40]; + + printf("%s = ", name); + for (u = 0; u < 9; u ++) { + if (x[u] > 0x3FFFFFFF) { + printf("INVALID:"); + for (u = 0; u < 9; u ++) { + printf(" %08X", x[u]); + } + printf("\n"); + return; + } + } + memset(tmp, 0, sizeof tmp); + for (u = 0; u < 9; u ++) { + uint64_t w; + int j, k; + + w = x[u]; + j = 30 * (int)u; + k = j & 7; + if (k != 0) { + w <<= k; + j -= k; + } + k = j >> 3; + for (j = 0; j < 8; j ++) { + tmp[39 - k - j] |= (unsigned char)w; + w >>= 8; + } + } + for (u = 8; u < 40; u ++) { + printf("%02X", tmp[u]); + } + printf("\n"); +} +*/ + +/* + * If BR_NO_ARITH_SHIFT is undefined, or defined to 0, then we _assume_ + * that right-shifting a signed negative integer copies the sign bit + * (arithmetic right-shift). This is "implementation-defined behaviour", + * i.e. it is not undefined, but it may differ between compilers. Each + * compiler is supposed to document its behaviour in that respect. GCC + * explicitly defines that an arithmetic right shift is used. We expect + * all other compilers to do the same, because underlying CPU offer an + * arithmetic right shift opcode that could not be used otherwise. + */ +#if BR_NO_ARITH_SHIFT +#define ARSH(x, n) (((uint32_t)(x) >> (n)) \ + | ((-((uint32_t)(x) >> 31)) << (32 - (n)))) +#else +#define ARSH(x, n) ((*(int32_t *)&(x)) >> (n)) +#endif + +/* + * Convert an integer from unsigned little-endian encoding to a sequence of + * 30-bit words in little-endian order. The final "partial" word is + * returned. + */ +static uint32_t +le8_to_le30(uint32_t *dst, const unsigned char *src, size_t len) +{ + uint32_t acc; + int acc_len; + + acc = 0; + acc_len = 0; + while (len -- > 0) { + uint32_t b; + + b = *src ++; + if (acc_len < 22) { + acc |= b << acc_len; + acc_len += 8; + } else { + *dst ++ = (acc | (b << acc_len)) & 0x3FFFFFFF; + acc = b >> (30 - acc_len); + acc_len -= 22; + } + } + return acc; +} + +/* + * Convert an integer (30-bit words, little-endian) to unsigned + * little-endian encoding. The total encoding length is provided; all + * the destination bytes will be filled. + */ +static void +le30_to_le8(unsigned char *dst, size_t len, const uint32_t *src) +{ + uint32_t acc; + int acc_len; + + acc = 0; + acc_len = 0; + while (len -- > 0) { + if (acc_len < 8) { + uint32_t w; + + w = *src ++; + *dst ++ = (unsigned char)(acc | (w << acc_len)); + acc = w >> (8 - acc_len); + acc_len += 22; + } else { + *dst ++ = (unsigned char)acc; + acc >>= 8; + acc_len -= 8; + } + } +} + +/* + * Multiply two integers. Source integers are represented as arrays of + * nine 30-bit words, for values up to 2^270-1. Result is encoded over + * 18 words of 30 bits each. + */ +static void +mul9(uint32_t *d, const uint32_t *a, const uint32_t *b) +{ + /* + * Maximum intermediate result is no more than + * 10376293531797946367, which fits in 64 bits. Reason: + * + * 10376293531797946367 = 9 * (2^30-1)^2 + 9663676406 + * 10376293531797946367 < 9663676407 * 2^30 + * + * Thus, adding together 9 products of 30-bit integers, with + * a carry of at most 9663676406, yields an integer that fits + * on 64 bits and generates a carry of at most 9663676406. + */ + uint64_t t[17]; + uint64_t cc; + int i; + + t[ 0] = MUL31(a[0], b[0]); + t[ 1] = MUL31(a[0], b[1]) + + MUL31(a[1], b[0]); + t[ 2] = MUL31(a[0], b[2]) + + MUL31(a[1], b[1]) + + MUL31(a[2], b[0]); + t[ 3] = MUL31(a[0], b[3]) + + MUL31(a[1], b[2]) + + MUL31(a[2], b[1]) + + MUL31(a[3], b[0]); + t[ 4] = MUL31(a[0], b[4]) + + MUL31(a[1], b[3]) + + MUL31(a[2], b[2]) + + MUL31(a[3], b[1]) + + MUL31(a[4], b[0]); + t[ 5] = MUL31(a[0], b[5]) + + MUL31(a[1], b[4]) + + MUL31(a[2], b[3]) + + MUL31(a[3], b[2]) + + MUL31(a[4], b[1]) + + MUL31(a[5], b[0]); + t[ 6] = MUL31(a[0], b[6]) + + MUL31(a[1], b[5]) + + MUL31(a[2], b[4]) + + MUL31(a[3], b[3]) + + MUL31(a[4], b[2]) + + MUL31(a[5], b[1]) + + MUL31(a[6], b[0]); + t[ 7] = MUL31(a[0], b[7]) + + MUL31(a[1], b[6]) + + MUL31(a[2], b[5]) + + MUL31(a[3], b[4]) + + MUL31(a[4], b[3]) + + MUL31(a[5], b[2]) + + MUL31(a[6], b[1]) + + MUL31(a[7], b[0]); + t[ 8] = MUL31(a[0], b[8]) + + MUL31(a[1], b[7]) + + MUL31(a[2], b[6]) + + MUL31(a[3], b[5]) + + MUL31(a[4], b[4]) + + MUL31(a[5], b[3]) + + MUL31(a[6], b[2]) + + MUL31(a[7], b[1]) + + MUL31(a[8], b[0]); + t[ 9] = MUL31(a[1], b[8]) + + MUL31(a[2], b[7]) + + MUL31(a[3], b[6]) + + MUL31(a[4], b[5]) + + MUL31(a[5], b[4]) + + MUL31(a[6], b[3]) + + MUL31(a[7], b[2]) + + MUL31(a[8], b[1]); + t[10] = MUL31(a[2], b[8]) + + MUL31(a[3], b[7]) + + MUL31(a[4], b[6]) + + MUL31(a[5], b[5]) + + MUL31(a[6], b[4]) + + MUL31(a[7], b[3]) + + MUL31(a[8], b[2]); + t[11] = MUL31(a[3], b[8]) + + MUL31(a[4], b[7]) + + MUL31(a[5], b[6]) + + MUL31(a[6], b[5]) + + MUL31(a[7], b[4]) + + MUL31(a[8], b[3]); + t[12] = MUL31(a[4], b[8]) + + MUL31(a[5], b[7]) + + MUL31(a[6], b[6]) + + MUL31(a[7], b[5]) + + MUL31(a[8], b[4]); + t[13] = MUL31(a[5], b[8]) + + MUL31(a[6], b[7]) + + MUL31(a[7], b[6]) + + MUL31(a[8], b[5]); + t[14] = MUL31(a[6], b[8]) + + MUL31(a[7], b[7]) + + MUL31(a[8], b[6]); + t[15] = MUL31(a[7], b[8]) + + MUL31(a[8], b[7]); + t[16] = MUL31(a[8], b[8]); + + /* + * Propagate carries. + */ + cc = 0; + for (i = 0; i < 17; i ++) { + uint64_t w; + + w = t[i] + cc; + d[i] = (uint32_t)w & 0x3FFFFFFF; + cc = w >> 30; + } + d[17] = (uint32_t)cc; +} + +/* + * Square a 270-bit integer, represented as an array of nine 30-bit words. + * Result uses 18 words of 30 bits each. + */ +static void +square9(uint32_t *d, const uint32_t *a) +{ + uint64_t t[17]; + uint64_t cc; + int i; + + t[ 0] = MUL31(a[0], a[0]); + t[ 1] = ((MUL31(a[0], a[1])) << 1); + t[ 2] = MUL31(a[1], a[1]) + + ((MUL31(a[0], a[2])) << 1); + t[ 3] = ((MUL31(a[0], a[3]) + + MUL31(a[1], a[2])) << 1); + t[ 4] = MUL31(a[2], a[2]) + + ((MUL31(a[0], a[4]) + + MUL31(a[1], a[3])) << 1); + t[ 5] = ((MUL31(a[0], a[5]) + + MUL31(a[1], a[4]) + + MUL31(a[2], a[3])) << 1); + t[ 6] = MUL31(a[3], a[3]) + + ((MUL31(a[0], a[6]) + + MUL31(a[1], a[5]) + + MUL31(a[2], a[4])) << 1); + t[ 7] = ((MUL31(a[0], a[7]) + + MUL31(a[1], a[6]) + + MUL31(a[2], a[5]) + + MUL31(a[3], a[4])) << 1); + t[ 8] = MUL31(a[4], a[4]) + + ((MUL31(a[0], a[8]) + + MUL31(a[1], a[7]) + + MUL31(a[2], a[6]) + + MUL31(a[3], a[5])) << 1); + t[ 9] = ((MUL31(a[1], a[8]) + + MUL31(a[2], a[7]) + + MUL31(a[3], a[6]) + + MUL31(a[4], a[5])) << 1); + t[10] = MUL31(a[5], a[5]) + + ((MUL31(a[2], a[8]) + + MUL31(a[3], a[7]) + + MUL31(a[4], a[6])) << 1); + t[11] = ((MUL31(a[3], a[8]) + + MUL31(a[4], a[7]) + + MUL31(a[5], a[6])) << 1); + t[12] = MUL31(a[6], a[6]) + + ((MUL31(a[4], a[8]) + + MUL31(a[5], a[7])) << 1); + t[13] = ((MUL31(a[5], a[8]) + + MUL31(a[6], a[7])) << 1); + t[14] = MUL31(a[7], a[7]) + + ((MUL31(a[6], a[8])) << 1); + t[15] = ((MUL31(a[7], a[8])) << 1); + t[16] = MUL31(a[8], a[8]); + + /* + * Propagate carries. + */ + cc = 0; + for (i = 0; i < 17; i ++) { + uint64_t w; + + w = t[i] + cc; + d[i] = (uint32_t)w & 0x3FFFFFFF; + cc = w >> 30; + } + d[17] = (uint32_t)cc; +} + +/* + * Perform a "final reduction" in field F255 (field for Curve25519) + * The source value must be less than twice the modulus. If the value + * is not lower than the modulus, then the modulus is subtracted and + * this function returns 1; otherwise, it leaves it untouched and it + * returns 0. + */ +static uint32_t +reduce_final_f255(uint32_t *d) +{ + uint32_t t[9]; + uint32_t cc; + int i; + + memcpy(t, d, sizeof t); + cc = 19; + for (i = 0; i < 9; i ++) { + uint32_t w; + + w = t[i] + cc; + cc = w >> 30; + t[i] = w & 0x3FFFFFFF; + } + cc = t[8] >> 15; + t[8] &= 0x7FFF; + CCOPY(cc, d, t, sizeof t); + return cc; +} + +/* + * Perform a multiplication of two integers modulo 2^255-19. + * Operands are arrays of 9 words, each containing 30 bits of data, in + * little-endian order. Input value may be up to 2^256-1; on output, value + * fits on 256 bits and is lower than twice the modulus. + */ +static void +f255_mul(uint32_t *d, const uint32_t *a, const uint32_t *b) +{ + uint32_t t[18], cc; + int i; + + /* + * Compute raw multiplication. All result words fit in 30 bits + * each; upper word (t[17]) must fit on 2 bits, since the product + * of two 256-bit integers must fit on 512 bits. + */ + mul9(t, a, b); + + /* + * Modular reduction: each high word is added where necessary. + * Since the modulus is 2^255-19 and word 9 corresponds to + * offset 9*30 = 270, word 9+k must be added to word k with + * a factor of 19*2^15 = 622592. The extra bits in word 8 are also + * added that way. + * + * Keeping the carry on 32 bits helps with 32-bit architectures, + * and does not noticeably impact performance on 64-bit systems. + */ + cc = MUL15(t[8] >> 15, 19); /* at most 19*(2^15-1) = 622573 */ + t[8] &= 0x7FFF; + for (i = 0; i < 9; i ++) { + uint64_t w; + + w = (uint64_t)t[i] + (uint64_t)cc + MUL31(t[i + 9], 622592); + t[i] = (uint32_t)w & 0x3FFFFFFF; + cc = (uint32_t)(w >> 30); /* at most 622592 */ + } + + /* + * Original product was up to (2^256-1)^2, i.e. a 512-bit integer. + * This was split into two parts (upper of 257 bits, lower of 255 + * bits), and the upper was added to the lower with a factor 19, + * which means that the intermediate value is less than 77*2^255 + * (19*2^257 + 2^255). Therefore, the extra bits "t[8] >> 15" are + * less than 77, and the initial carry cc is at most 76*19 = 1444. + */ + cc = MUL15(t[8] >> 15, 19); + t[8] &= 0x7FFF; + for (i = 0; i < 9; i ++) { + uint32_t z; + + z = t[i] + cc; + d[i] = z & 0x3FFFFFFF; + cc = z >> 30; + } + + /* + * Final result is at most 2^255 + 1443. In particular, the last + * carry is necessarily 0, since t[8] was truncated to 15 bits. + */ +} + +/* + * Perform a squaring of an integer modulo 2^255-19. + * Operands are arrays of 9 words, each containing 30 bits of data, in + * little-endian order. Input value may be up to 2^256-1; on output, value + * fits on 256 bits and is lower than twice the modulus. + */ +static void +f255_square(uint32_t *d, const uint32_t *a) +{ + uint32_t t[18], cc; + int i; + + /* + * Compute raw squaring. All result words fit in 30 bits + * each; upper word (t[17]) must fit on 2 bits, since the square + * of a 256-bit integers must fit on 512 bits. + */ + square9(t, a); + + /* + * Modular reduction: each high word is added where necessary. + * See f255_mul() for details on the reduction and carry limits. + */ + cc = MUL15(t[8] >> 15, 19); + t[8] &= 0x7FFF; + for (i = 0; i < 9; i ++) { + uint64_t w; + + w = (uint64_t)t[i] + (uint64_t)cc + MUL31(t[i + 9], 622592); + t[i] = (uint32_t)w & 0x3FFFFFFF; + cc = (uint32_t)(w >> 30); + } + cc = MUL15(t[8] >> 15, 19); + t[8] &= 0x7FFF; + for (i = 0; i < 9; i ++) { + uint32_t z; + + z = t[i] + cc; + d[i] = z & 0x3FFFFFFF; + cc = z >> 30; + } +} + +/* + * Add two values in F255. Partial reduction is performed (down to less + * than twice the modulus). + */ +static void +f255_add(uint32_t *d, const uint32_t *a, const uint32_t *b) +{ + /* + * Since operand words fit on 30 bits, we can use 32-bit + * variables throughout. + */ + int i; + uint32_t cc, w; + + cc = 0; + for (i = 0; i < 9; i ++) { + w = a[i] + b[i] + cc; + d[i] = w & 0x3FFFFFFF; + cc = w >> 30; + } + cc = MUL15(w >> 15, 19); + d[8] &= 0x7FFF; + for (i = 0; i < 9; i ++) { + w = d[i] + cc; + d[i] = w & 0x3FFFFFFF; + cc = w >> 30; + } +} + +/* + * Subtract one value from another in F255. Partial reduction is + * performed (down to less than twice the modulus). + */ +static void +f255_sub(uint32_t *d, const uint32_t *a, const uint32_t *b) +{ + /* + * We actually compute a - b + 2*p, so that the final value is + * necessarily positive. + */ + int i; + uint32_t cc, w; + + cc = (uint32_t)-38; + for (i = 0; i < 9; i ++) { + w = a[i] - b[i] + cc; + d[i] = w & 0x3FFFFFFF; + cc = ARSH(w, 30); + } + cc = MUL15((w + 0x10000) >> 15, 19); + d[8] &= 0x7FFF; + for (i = 0; i < 9; i ++) { + w = d[i] + cc; + d[i] = w & 0x3FFFFFFF; + cc = w >> 30; + } +} + +/* + * Multiply an integer by the 'A24' constant (121665). Partial reduction + * is performed (down to less than twice the modulus). + */ +static void +f255_mul_a24(uint32_t *d, const uint32_t *a) +{ + int i; + uint64_t w; + uint32_t cc; + + /* + * a[] is over 256 bits, thus a[8] has length at most 16 bits. + * We single out the processing of the last word: intermediate + * value w is up to 121665*2^16, yielding a carry for the next + * loop of at most 19*(121665*2^16/2^15) = 4623289. + */ + cc = 0; + for (i = 0; i < 8; i ++) { + w = MUL31(a[i], 121665) + (uint64_t)cc; + d[i] = (uint32_t)w & 0x3FFFFFFF; + cc = (uint32_t)(w >> 30); + } + w = MUL31(a[8], 121665) + (uint64_t)cc; + d[8] = (uint32_t)w & 0x7FFF; + cc = MUL15((uint32_t)(w >> 15), 19); + + for (i = 0; i < 9; i ++) { + uint32_t z; + + z = d[i] + cc; + d[i] = z & 0x3FFFFFFF; + cc = z >> 30; + } +} + +static const unsigned char GEN[] = { + 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + +static const unsigned char ORDER[] = { + 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF +}; + +static const unsigned char * +api_generator(int curve, size_t *len) +{ + (void)curve; + *len = 32; + return GEN; +} + +static const unsigned char * +api_order(int curve, size_t *len) +{ + (void)curve; + *len = 32; + return ORDER; +} + +static size_t +api_xoff(int curve, size_t *len) +{ + (void)curve; + *len = 32; + return 0; +} + +static void +cswap(uint32_t *a, uint32_t *b, uint32_t ctl) +{ + int i; + + ctl = -ctl; + for (i = 0; i < 9; i ++) { + uint32_t aw, bw, tw; + + aw = a[i]; + bw = b[i]; + tw = ctl & (aw ^ bw); + a[i] = aw ^ tw; + b[i] = bw ^ tw; + } +} + +static uint32_t +api_mul(unsigned char *G, size_t Glen, + const unsigned char *kb, size_t kblen, int curve) +{ + uint32_t x1[9], x2[9], x3[9], z2[9], z3[9]; + uint32_t a[9], aa[9], b[9], bb[9]; + uint32_t c[9], d[9], e[9], da[9], cb[9]; + unsigned char k[32]; + uint32_t swap; + int i; + + (void)curve; + + /* + * Points are encoded over exactly 32 bytes. Multipliers must fit + * in 32 bytes as well. + * RFC 7748 mandates that the high bit of the last point byte must + * be ignored/cleared. + */ + if (Glen != 32 || kblen > 32) { + return 0; + } + G[31] &= 0x7F; + + /* + * Initialise variables x1, x2, z2, x3 and z3. We set all of them + * into Montgomery representation. + */ + x1[8] = le8_to_le30(x1, G, 32); + memcpy(x3, x1, sizeof x1); + memset(z2, 0, sizeof z2); + memset(x2, 0, sizeof x2); + x2[0] = 1; + memset(z3, 0, sizeof z3); + z3[0] = 1; + + memset(k, 0, (sizeof k) - kblen); + memcpy(k + (sizeof k) - kblen, kb, kblen); + k[31] &= 0xF8; + k[0] &= 0x7F; + k[0] |= 0x40; + + /* obsolete + print_int("x1", x1); + */ + + swap = 0; + for (i = 254; i >= 0; i --) { + uint32_t kt; + + kt = (k[31 - (i >> 3)] >> (i & 7)) & 1; + swap ^= kt; + cswap(x2, x3, swap); + cswap(z2, z3, swap); + swap = kt; + + /* obsolete + print_int("x2", x2); + print_int("z2", z2); + print_int("x3", x3); + print_int("z3", z3); + */ + + f255_add(a, x2, z2); + f255_square(aa, a); + f255_sub(b, x2, z2); + f255_square(bb, b); + f255_sub(e, aa, bb); + f255_add(c, x3, z3); + f255_sub(d, x3, z3); + f255_mul(da, d, a); + f255_mul(cb, c, b); + + /* obsolete + print_int("a ", a); + print_int("aa", aa); + print_int("b ", b); + print_int("bb", bb); + print_int("e ", e); + print_int("c ", c); + print_int("d ", d); + print_int("da", da); + print_int("cb", cb); + */ + + f255_add(x3, da, cb); + f255_square(x3, x3); + f255_sub(z3, da, cb); + f255_square(z3, z3); + f255_mul(z3, z3, x1); + f255_mul(x2, aa, bb); + f255_mul_a24(z2, e); + f255_add(z2, z2, aa); + f255_mul(z2, e, z2); + + /* obsolete + print_int("x2", x2); + print_int("z2", z2); + print_int("x3", x3); + print_int("z3", z3); + */ + } + cswap(x2, x3, swap); + cswap(z2, z3, swap); + + /* + * Inverse z2 with a modular exponentiation. This is a simple + * square-and-multiply algorithm; we mutualise most non-squarings + * since the exponent contains almost only ones. + */ + memcpy(a, z2, sizeof z2); + for (i = 0; i < 15; i ++) { + f255_square(a, a); + f255_mul(a, a, z2); + } + memcpy(b, a, sizeof a); + for (i = 0; i < 14; i ++) { + int j; + + for (j = 0; j < 16; j ++) { + f255_square(b, b); + } + f255_mul(b, b, a); + } + for (i = 14; i >= 0; i --) { + f255_square(b, b); + if ((0xFFEB >> i) & 1) { + f255_mul(b, z2, b); + } + } + f255_mul(x2, x2, b); + reduce_final_f255(x2); + le30_to_le8(G, 32, x2); + return 1; +} + +static size_t +api_mulgen(unsigned char *R, + const unsigned char *x, size_t xlen, int curve) +{ + const unsigned char *G; + size_t Glen; + + G = api_generator(curve, &Glen); + memcpy(R, G, Glen); + api_mul(R, Glen, x, xlen, curve); + return Glen; +} + +static uint32_t +api_muladd(unsigned char *A, const unsigned char *B, size_t len, + const unsigned char *x, size_t xlen, + const unsigned char *y, size_t ylen, int curve) +{ + /* + * We don't implement this method, since it is used for ECDSA + * only, and there is no ECDSA over Curve25519 (which instead + * uses EdDSA). + */ + (void)A; + (void)B; + (void)len; + (void)x; + (void)xlen; + (void)y; + (void)ylen; + (void)curve; + return 0; +} + +/* see bearssl_ec.h */ +const br_ec_impl br_ec_c25519_m31 = { + (uint32_t)0x20000000, + &api_generator, + &api_order, + &api_xoff, + &api_mul, + &api_mulgen, + &api_muladd +}; + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_c25519_m62.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_c25519_m62.c new file mode 100644 index 000000000..479d565bc --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_c25519_m62.c @@ -0,0 +1,610 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +#if BR_INT128 || BR_UMUL128 + +#if BR_UMUL128 +#include +#endif + +static const unsigned char GEN[] = { + 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + +static const unsigned char ORDER[] = { + 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF +}; + +static const unsigned char * +api_generator(int curve, size_t *len) +{ + (void)curve; + *len = 32; + return GEN; +} + +static const unsigned char * +api_order(int curve, size_t *len) +{ + (void)curve; + *len = 32; + return ORDER; +} + +static size_t +api_xoff(int curve, size_t *len) +{ + (void)curve; + *len = 32; + return 0; +} + +/* + * A field element is encoded as five 64-bit integers, in basis 2^51. + * Limbs may be occasionally larger than 2^51, to save on carry + * propagation costs. + */ + +#define MASK51 (((uint64_t)1 << 51) - (uint64_t)1) + +/* + * Swap two field elements, conditionally on a flag. + */ +static inline void +f255_cswap(uint64_t *a, uint64_t *b, uint32_t ctl) +{ + uint64_t m, w; + + m = -(uint64_t)ctl; + w = m & (a[0] ^ b[0]); a[0] ^= w; b[0] ^= w; + w = m & (a[1] ^ b[1]); a[1] ^= w; b[1] ^= w; + w = m & (a[2] ^ b[2]); a[2] ^= w; b[2] ^= w; + w = m & (a[3] ^ b[3]); a[3] ^= w; b[3] ^= w; + w = m & (a[4] ^ b[4]); a[4] ^= w; b[4] ^= w; +} + +/* + * Addition with no carry propagation. Limbs double in size. + */ +static inline void +f255_add(uint64_t *d, const uint64_t *a, const uint64_t *b) +{ + d[0] = a[0] + b[0]; + d[1] = a[1] + b[1]; + d[2] = a[2] + b[2]; + d[3] = a[3] + b[3]; + d[4] = a[4] + b[4]; +} + +/* + * Subtraction. + * On input, limbs must fit on 60 bits each. On output, result is + * partially reduced, with max value 2^255+19456; moreover, all + * limbs will fit on 51 bits, except the low limb, which may have + * value up to 2^51+19455. + */ +static inline void +f255_sub(uint64_t *d, const uint64_t *a, const uint64_t *b) +{ + uint64_t cc, w; + + /* + * We compute d = (2^255-19)*1024 + a - b. Since the limbs + * fit on 60 bits, the maximum value of operands are slightly + * more than 2^264, but much less than 2^265-19456. This + * ensures that the result is positive. + */ + + /* + * Initial carry is 19456, since we add 2^265-19456. Each + * individual subtraction may yield a carry up to 513. + */ + w = a[0] - b[0] - 19456; + d[0] = w & MASK51; + cc = -(w >> 51) & 0x3FF; + w = a[1] - b[1] - cc; + d[1] = w & MASK51; + cc = -(w >> 51) & 0x3FF; + w = a[2] - b[2] - cc; + d[2] = w & MASK51; + cc = -(w >> 51) & 0x3FF; + w = a[3] - b[3] - cc; + d[3] = w & MASK51; + cc = -(w >> 51) & 0x3FF; + d[4] = ((uint64_t)1 << 61) + a[4] - b[4] - cc; + + /* + * Partial reduction. The intermediate result may be up to + * slightly above 2^265, but less than 2^265+2^255. When we + * truncate to 255 bits, the upper bits will be at most 1024. + */ + d[0] += 19 * (d[4] >> 51); + d[4] &= MASK51; +} + +/* + * UMUL51(hi, lo, x, y) computes: + * + * hi = floor((x * y) / (2^51)) + * lo = x * y mod 2^51 + * + * Note that lo < 2^51, but "hi" may be larger, if the input operands are + * larger. + */ +#if BR_INT128 + +#define UMUL51(hi, lo, x, y) do { \ + unsigned __int128 umul_tmp; \ + umul_tmp = (unsigned __int128)(x) * (unsigned __int128)(y); \ + (hi) = (uint64_t)(umul_tmp >> 51); \ + (lo) = (uint64_t)umul_tmp & MASK51; \ + } while (0) + +#elif BR_UMUL128 + +#define UMUL51(hi, lo, x, y) do { \ + uint64_t umul_hi, umul_lo; \ + umul_lo = _umul128((x), (y), &umul_hi); \ + (hi) = (umul_hi << 13) | (umul_lo >> 51); \ + (lo) = umul_lo & MASK51; \ + } while (0) + +#endif + +/* + * Multiplication. + * On input, limbs must fit on 54 bits each. + * On output, limb 0 is at most 2^51 + 155647, and other limbs fit + * on 51 bits each. + */ +static inline void +f255_mul(uint64_t *d, uint64_t *a, uint64_t *b) +{ + uint64_t t[10], hi, lo, w, cc; + + /* + * Perform cross products, accumulating values without carry + * propagation. + * + * Since input limbs fit on 54 bits each, each individual + * UMUL51 will produce a "hi" of less than 2^57. The maximum + * sum will be at most 5*(2^57-1) + 4*(2^51-1) (for t[5]), + * i.e. less than 324*2^51. + */ + + UMUL51(t[1], t[0], a[0], b[0]); + + UMUL51(t[2], lo, a[1], b[0]); t[1] += lo; + UMUL51(hi, lo, a[0], b[1]); t[1] += lo; t[2] += hi; + + UMUL51(t[3], lo, a[2], b[0]); t[2] += lo; + UMUL51(hi, lo, a[1], b[1]); t[2] += lo; t[3] += hi; + UMUL51(hi, lo, a[0], b[2]); t[2] += lo; t[3] += hi; + + UMUL51(t[4], lo, a[3], b[0]); t[3] += lo; + UMUL51(hi, lo, a[2], b[1]); t[3] += lo; t[4] += hi; + UMUL51(hi, lo, a[1], b[2]); t[3] += lo; t[4] += hi; + UMUL51(hi, lo, a[0], b[3]); t[3] += lo; t[4] += hi; + + UMUL51(t[5], lo, a[4], b[0]); t[4] += lo; + UMUL51(hi, lo, a[3], b[1]); t[4] += lo; t[5] += hi; + UMUL51(hi, lo, a[2], b[2]); t[4] += lo; t[5] += hi; + UMUL51(hi, lo, a[1], b[3]); t[4] += lo; t[5] += hi; + UMUL51(hi, lo, a[0], b[4]); t[4] += lo; t[5] += hi; + + UMUL51(t[6], lo, a[4], b[1]); t[5] += lo; + UMUL51(hi, lo, a[3], b[2]); t[5] += lo; t[6] += hi; + UMUL51(hi, lo, a[2], b[3]); t[5] += lo; t[6] += hi; + UMUL51(hi, lo, a[1], b[4]); t[5] += lo; t[6] += hi; + + UMUL51(t[7], lo, a[4], b[2]); t[6] += lo; + UMUL51(hi, lo, a[3], b[3]); t[6] += lo; t[7] += hi; + UMUL51(hi, lo, a[2], b[4]); t[6] += lo; t[7] += hi; + + UMUL51(t[8], lo, a[4], b[3]); t[7] += lo; + UMUL51(hi, lo, a[3], b[4]); t[7] += lo; t[8] += hi; + + UMUL51(t[9], lo, a[4], b[4]); t[8] += lo; + + /* + * The upper words t[5]..t[9] are folded back into the lower + * words, using the rule that 2^255 = 19 in the field. + * + * Since each t[i] is less than 324*2^51, the additions below + * will yield less than 6480*2^51 in each limb; this fits in + * 64 bits (6480*2^51 < 8192*2^51 = 2^64), hence there is + * no overflow. + */ + t[0] += 19 * t[5]; + t[1] += 19 * t[6]; + t[2] += 19 * t[7]; + t[3] += 19 * t[8]; + t[4] += 19 * t[9]; + + /* + * Propagate carries. + */ + w = t[0]; + d[0] = w & MASK51; + cc = w >> 51; + w = t[1] + cc; + d[1] = w & MASK51; + cc = w >> 51; + w = t[2] + cc; + d[2] = w & MASK51; + cc = w >> 51; + w = t[3] + cc; + d[3] = w & MASK51; + cc = w >> 51; + w = t[4] + cc; + d[4] = w & MASK51; + cc = w >> 51; + + /* + * Since the limbs were 64-bit values, the top carry is at + * most 8192 (in practice, that cannot be reached). We simply + * performed a partial reduction. + */ + d[0] += 19 * cc; +} + +/* + * Multiplication by A24 = 121665. + * Input must have limbs of 60 bits at most. + */ +static inline void +f255_mul_a24(uint64_t *d, const uint64_t *a) +{ + uint64_t t[5], cc, w; + + /* + * 121665 = 15 * 8111. We first multiply by 15, with carry + * propagation and partial reduction. + */ + w = a[0] * 15; + t[0] = w & MASK51; + cc = w >> 51; + w = a[1] * 15 + cc; + t[1] = w & MASK51; + cc = w >> 51; + w = a[2] * 15 + cc; + t[2] = w & MASK51; + cc = w >> 51; + w = a[3] * 15 + cc; + t[3] = w & MASK51; + cc = w >> 51; + w = a[4] * 15 + cc; + t[4] = w & MASK51; + t[0] += 19 * (w >> 51); + + /* + * Then multiplication by 8111. At that point, we known that + * t[0] is less than 2^51 + 19*8192, and other limbs are less + * than 2^51; thus, there will be no overflow. + */ + w = t[0] * 8111; + d[0] = w & MASK51; + cc = w >> 51; + w = t[1] * 8111 + cc; + d[1] = w & MASK51; + cc = w >> 51; + w = t[2] * 8111 + cc; + d[2] = w & MASK51; + cc = w >> 51; + w = t[3] * 8111 + cc; + d[3] = w & MASK51; + cc = w >> 51; + w = t[4] * 8111 + cc; + d[4] = w & MASK51; + d[0] += 19 * (w >> 51); +} + +/* + * Finalize reduction. + * On input, limbs must fit on 51 bits, except possibly the low limb, + * which may be slightly above 2^51. + */ +static inline void +f255_final_reduce(uint64_t *a) +{ + uint64_t t[5], cc, w; + + /* + * We add 19. If the result (in t[]) is below 2^255, then a[] + * is already less than 2^255-19, thus already reduced. + * Otherwise, we subtract 2^255 from t[], in which case we + * have t = a - (2^255-19), and that's our result. + */ + w = a[0] + 19; + t[0] = w & MASK51; + cc = w >> 51; + w = a[1] + cc; + t[1] = w & MASK51; + cc = w >> 51; + w = a[2] + cc; + t[2] = w & MASK51; + cc = w >> 51; + w = a[3] + cc; + t[3] = w & MASK51; + cc = w >> 51; + w = a[4] + cc; + t[4] = w & MASK51; + cc = w >> 51; + + /* + * The bit 255 of t is in cc. If that bit is 0, when a[] must + * be unchanged; otherwise, it must be replaced with t[]. + */ + cc = -cc; + a[0] ^= cc & (a[0] ^ t[0]); + a[1] ^= cc & (a[1] ^ t[1]); + a[2] ^= cc & (a[2] ^ t[2]); + a[3] ^= cc & (a[3] ^ t[3]); + a[4] ^= cc & (a[4] ^ t[4]); +} + +static uint32_t +api_mul(unsigned char *G, size_t Glen, + const unsigned char *kb, size_t kblen, int curve) +{ + unsigned char k[32]; + uint64_t x1[5], x2[5], z2[5], x3[5], z3[5]; + uint32_t swap; + int i; + + (void)curve; + + /* + * Points are encoded over exactly 32 bytes. Multipliers must fit + * in 32 bytes as well. + */ + if (Glen != 32 || kblen > 32) { + return 0; + } + + /* + * RFC 7748 mandates that the high bit of the last point byte must + * be ignored/cleared; the "& MASK51" in the initialization for + * x1[4] clears that bit. + */ + x1[0] = br_dec64le(&G[0]) & MASK51; + x1[1] = (br_dec64le(&G[6]) >> 3) & MASK51; + x1[2] = (br_dec64le(&G[12]) >> 6) & MASK51; + x1[3] = (br_dec64le(&G[19]) >> 1) & MASK51; + x1[4] = (br_dec64le(&G[24]) >> 12) & MASK51; + + /* + * We can use memset() to clear values, because exact-width types + * like uint64_t are guaranteed to have no padding bits or + * trap representations. + */ + memset(x2, 0, sizeof x2); + x2[0] = 1; + memset(z2, 0, sizeof z2); + memcpy(x3, x1, sizeof x1); + memcpy(z3, x2, sizeof x2); + + /* + * The multiplier is provided in big-endian notation, and + * possibly shorter than 32 bytes. + */ + memset(k, 0, (sizeof k) - kblen); + memcpy(k + (sizeof k) - kblen, kb, kblen); + k[31] &= 0xF8; + k[0] &= 0x7F; + k[0] |= 0x40; + + swap = 0; + + for (i = 254; i >= 0; i --) { + uint64_t a[5], aa[5], b[5], bb[5], e[5]; + uint64_t c[5], d[5], da[5], cb[5]; + uint32_t kt; + + kt = (k[31 - (i >> 3)] >> (i & 7)) & 1; + swap ^= kt; + f255_cswap(x2, x3, swap); + f255_cswap(z2, z3, swap); + swap = kt; + + /* + * At that point, limbs of x_2 and z_2 are assumed to fit + * on at most 52 bits each. + * + * Each f255_add() adds one bit to the maximum range of + * the values, but f255_sub() and f255_mul() bring back + * the limbs into 52 bits. All f255_add() outputs are + * used only as inputs for f255_mul(), which ensures + * that limbs remain in the proper range. + */ + + /* A = x_2 + z_2 -- limbs fit on 53 bits each */ + f255_add(a, x2, z2); + + /* AA = A^2 */ + f255_mul(aa, a, a); + + /* B = x_2 - z_2 */ + f255_sub(b, x2, z2); + + /* BB = B^2 */ + f255_mul(bb, b, b); + + /* E = AA - BB */ + f255_sub(e, aa, bb); + + /* C = x_3 + z_3 -- limbs fit on 53 bits each */ + f255_add(c, x3, z3); + + /* D = x_3 - z_3 */ + f255_sub(d, x3, z3); + + /* DA = D * A */ + f255_mul(da, d, a); + + /* CB = C * B */ + f255_mul(cb, c, b); + + /* x_3 = (DA + CB)^2 */ + f255_add(x3, da, cb); + f255_mul(x3, x3, x3); + + /* z_3 = x_1 * (DA - CB)^2 */ + f255_sub(z3, da, cb); + f255_mul(z3, z3, z3); + f255_mul(z3, x1, z3); + + /* x_2 = AA * BB */ + f255_mul(x2, aa, bb); + + /* z_2 = E * (AA + a24 * E) */ + f255_mul_a24(z2, e); + f255_add(z2, aa, z2); + f255_mul(z2, e, z2); + } + + f255_cswap(x2, x3, swap); + f255_cswap(z2, z3, swap); + + /* + * Compute 1/z2 = z2^(p-2). Since p = 2^255-19, we can mutualize + * most non-squarings. We use x1 and x3, now useless, as temporaries. + */ + memcpy(x1, z2, sizeof z2); + for (i = 0; i < 15; i ++) { + f255_mul(x1, x1, x1); + f255_mul(x1, x1, z2); + } + memcpy(x3, x1, sizeof x1); + for (i = 0; i < 14; i ++) { + int j; + + for (j = 0; j < 16; j ++) { + f255_mul(x3, x3, x3); + } + f255_mul(x3, x3, x1); + } + for (i = 14; i >= 0; i --) { + f255_mul(x3, x3, x3); + if ((0xFFEB >> i) & 1) { + f255_mul(x3, z2, x3); + } + } + + /* + * Compute x2/z2. We have 1/z2 in x3. + */ + f255_mul(x2, x2, x3); + f255_final_reduce(x2); + + /* + * Encode the final x2 value in little-endian. We first assemble + * the limbs into 64-bit values. + */ + x2[0] |= x2[1] << 51; + x2[1] = (x2[1] >> 13) | (x2[2] << 38); + x2[2] = (x2[2] >> 26) | (x2[3] << 25); + x2[3] = (x2[3] >> 39) | (x2[4] << 12); + br_enc64le(G, x2[0]); + br_enc64le(G + 8, x2[1]); + br_enc64le(G + 16, x2[2]); + br_enc64le(G + 24, x2[3]); + return 1; +} + +static size_t +api_mulgen(unsigned char *R, + const unsigned char *x, size_t xlen, int curve) +{ + const unsigned char *G; + size_t Glen; + + G = api_generator(curve, &Glen); + memcpy(R, G, Glen); + api_mul(R, Glen, x, xlen, curve); + return Glen; +} + +static uint32_t +api_muladd(unsigned char *A, const unsigned char *B, size_t len, + const unsigned char *x, size_t xlen, + const unsigned char *y, size_t ylen, int curve) +{ + /* + * We don't implement this method, since it is used for ECDSA + * only, and there is no ECDSA over Curve25519 (which instead + * uses EdDSA). + */ + (void)A; + (void)B; + (void)len; + (void)x; + (void)xlen; + (void)y; + (void)ylen; + (void)curve; + return 0; +} + +/* see bearssl_ec.h */ +const br_ec_impl br_ec_c25519_m62 = { + (uint32_t)0x20000000, + &api_generator, + &api_order, + &api_xoff, + &api_mul, + &api_mulgen, + &api_muladd +}; + +/* see bearssl_ec.h */ +const br_ec_impl * +br_ec_c25519_m62_get(void) +{ + return &br_ec_c25519_m62; +} + +#else + +/* see bearssl_ec.h */ +const br_ec_impl * +br_ec_c25519_m62_get(void) +{ + return 0; +} + +#endif + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_c25519_m64.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_c25519_m64.c new file mode 100644 index 000000000..014bda9a1 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_c25519_m64.c @@ -0,0 +1,836 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +#if BR_INT128 || BR_UMUL128 + +#if BR_UMUL128 +#include +#endif + +static const unsigned char GEN[] = { + 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + +static const unsigned char ORDER[] = { + 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF +}; + +static const unsigned char * +api_generator(int curve, size_t *len) +{ + (void)curve; + *len = 32; + return GEN; +} + +static const unsigned char * +api_order(int curve, size_t *len) +{ + (void)curve; + *len = 32; + return ORDER; +} + +static size_t +api_xoff(int curve, size_t *len) +{ + (void)curve; + *len = 32; + return 0; +} + +/* + * A field element is encoded as four 64-bit integers, in basis 2^63. + * Operations return partially reduced values, which may range up to + * 2^255+37. + */ + +#define MASK63 (((uint64_t)1 << 63) - (uint64_t)1) + +/* + * Swap two field elements, conditionally on a flag. + */ +static inline void +f255_cswap(uint64_t *a, uint64_t *b, uint32_t ctl) +{ + uint64_t m, w; + + m = -(uint64_t)ctl; + w = m & (a[0] ^ b[0]); a[0] ^= w; b[0] ^= w; + w = m & (a[1] ^ b[1]); a[1] ^= w; b[1] ^= w; + w = m & (a[2] ^ b[2]); a[2] ^= w; b[2] ^= w; + w = m & (a[3] ^ b[3]); a[3] ^= w; b[3] ^= w; +} + +/* + * Addition in the field. + */ +static inline void +f255_add(uint64_t *d, const uint64_t *a, const uint64_t *b) +{ +#if BR_INT128 + + uint64_t t0, t1, t2, t3, cc; + unsigned __int128 z; + + z = (unsigned __int128)a[0] + (unsigned __int128)b[0]; + t0 = (uint64_t)z; + z = (unsigned __int128)a[1] + (unsigned __int128)b[1] + (z >> 64); + t1 = (uint64_t)z; + z = (unsigned __int128)a[2] + (unsigned __int128)b[2] + (z >> 64); + t2 = (uint64_t)z; + z = (unsigned __int128)a[3] + (unsigned __int128)b[3] + (z >> 64); + t3 = (uint64_t)z & MASK63; + cc = (uint64_t)(z >> 63); + + /* + * Since operands are at most 2^255+37, the sum is at most + * 2^256+74; thus, the carry cc is equal to 0, 1 or 2. + * + * We use: 2^255 = 19 mod p. + * Since we add 0, 19 or 38 to a value that fits on 255 bits, + * the result is at most 2^255+37. + */ + z = (unsigned __int128)t0 + (unsigned __int128)(19 * cc); + d[0] = (uint64_t)z; + z = (unsigned __int128)t1 + (z >> 64); + d[1] = (uint64_t)z; + z = (unsigned __int128)t2 + (z >> 64); + d[2] = (uint64_t)z; + d[3] = t3 + (uint64_t)(z >> 64); + +#elif BR_UMUL128 + + uint64_t t0, t1, t2, t3, cc; + unsigned char k; + + k = _addcarry_u64(0, a[0], b[0], &t0); + k = _addcarry_u64(k, a[1], b[1], &t1); + k = _addcarry_u64(k, a[2], b[2], &t2); + k = _addcarry_u64(k, a[3], b[3], &t3); + cc = (k << 1) + (t3 >> 63); + t3 &= MASK63; + + /* + * Since operands are at most 2^255+37, the sum is at most + * 2^256+74; thus, the carry cc is equal to 0, 1 or 2. + * + * We use: 2^255 = 19 mod p. + * Since we add 0, 19 or 38 to a value that fits on 255 bits, + * the result is at most 2^255+37. + */ + k = _addcarry_u64(0, t0, 19 * cc, &d[0]); + k = _addcarry_u64(k, t1, 0, &d[1]); + k = _addcarry_u64(k, t2, 0, &d[2]); + (void)_addcarry_u64(k, t3, 0, &d[3]); + +#endif +} + +/* + * Subtraction. + */ +static inline void +f255_sub(uint64_t *d, const uint64_t *a, const uint64_t *b) +{ +#if BR_INT128 + + /* + * We compute t = 2^256 - 38 + a - b, which is necessarily + * positive but lower than 2^256 + 2^255, since a <= 2^255 + 37 + * and b <= 2^255 + 37. We then subtract 0, p or 2*p, depending + * on the two upper bits of t (bits 255 and 256). + */ + + uint64_t t0, t1, t2, t3, t4, cc; + unsigned __int128 z; + + z = (unsigned __int128)a[0] - (unsigned __int128)b[0] - 38; + t0 = (uint64_t)z; + cc = -(uint64_t)(z >> 64); + z = (unsigned __int128)a[1] - (unsigned __int128)b[1] + - (unsigned __int128)cc; + t1 = (uint64_t)z; + cc = -(uint64_t)(z >> 64); + z = (unsigned __int128)a[2] - (unsigned __int128)b[2] + - (unsigned __int128)cc; + t2 = (uint64_t)z; + cc = -(uint64_t)(z >> 64); + z = (unsigned __int128)a[3] - (unsigned __int128)b[3] + - (unsigned __int128)cc; + t3 = (uint64_t)z; + t4 = 1 + (uint64_t)(z >> 64); + + /* + * We have a 257-bit result. The two top bits can be 00, 01 or 10, + * but not 11 (value t <= 2^256 - 38 + 2^255 + 37 = 2^256 + 2^255 - 1). + * Therefore, we can truncate to 255 bits, and add 0, 19 or 38. + * This guarantees that the result is at most 2^255+37. + */ + cc = (38 & -t4) + (19 & -(t3 >> 63)); + t3 &= MASK63; + z = (unsigned __int128)t0 + (unsigned __int128)cc; + d[0] = (uint64_t)z; + z = (unsigned __int128)t1 + (z >> 64); + d[1] = (uint64_t)z; + z = (unsigned __int128)t2 + (z >> 64); + d[2] = (uint64_t)z; + d[3] = t3 + (uint64_t)(z >> 64); + +#elif BR_UMUL128 + + /* + * We compute t = 2^256 - 38 + a - b, which is necessarily + * positive but lower than 2^256 + 2^255, since a <= 2^255 + 37 + * and b <= 2^255 + 37. We then subtract 0, p or 2*p, depending + * on the two upper bits of t (bits 255 and 256). + */ + + uint64_t t0, t1, t2, t3, t4; + unsigned char k; + + k = _subborrow_u64(0, a[0], b[0], &t0); + k = _subborrow_u64(k, a[1], b[1], &t1); + k = _subborrow_u64(k, a[2], b[2], &t2); + k = _subborrow_u64(k, a[3], b[3], &t3); + (void)_subborrow_u64(k, 1, 0, &t4); + + k = _subborrow_u64(0, t0, 38, &t0); + k = _subborrow_u64(k, t1, 0, &t1); + k = _subborrow_u64(k, t2, 0, &t2); + k = _subborrow_u64(k, t3, 0, &t3); + (void)_subborrow_u64(k, t4, 0, &t4); + + /* + * We have a 257-bit result. The two top bits can be 00, 01 or 10, + * but not 11 (value t <= 2^256 - 38 + 2^255 + 37 = 2^256 + 2^255 - 1). + * Therefore, we can truncate to 255 bits, and add 0, 19 or 38. + * This guarantees that the result is at most 2^255+37. + */ + t4 = (38 & -t4) + (19 & -(t3 >> 63)); + t3 &= MASK63; + k = _addcarry_u64(0, t0, t4, &d[0]); + k = _addcarry_u64(k, t1, 0, &d[1]); + k = _addcarry_u64(k, t2, 0, &d[2]); + (void)_addcarry_u64(k, t3, 0, &d[3]); + +#endif +} + +/* + * Multiplication. + */ +static inline void +f255_mul(uint64_t *d, uint64_t *a, uint64_t *b) +{ +#if BR_INT128 + + unsigned __int128 z; + uint64_t t0, t1, t2, t3, t4, t5, t6, t7, th; + + /* + * Compute the product a*b over plain integers. + */ + z = (unsigned __int128)a[0] * (unsigned __int128)b[0]; + t0 = (uint64_t)z; + z = (unsigned __int128)a[0] * (unsigned __int128)b[1] + (z >> 64); + t1 = (uint64_t)z; + z = (unsigned __int128)a[0] * (unsigned __int128)b[2] + (z >> 64); + t2 = (uint64_t)z; + z = (unsigned __int128)a[0] * (unsigned __int128)b[3] + (z >> 64); + t3 = (uint64_t)z; + t4 = (uint64_t)(z >> 64); + + z = (unsigned __int128)a[1] * (unsigned __int128)b[0] + + (unsigned __int128)t1; + t1 = (uint64_t)z; + z = (unsigned __int128)a[1] * (unsigned __int128)b[1] + + (unsigned __int128)t2 + (z >> 64); + t2 = (uint64_t)z; + z = (unsigned __int128)a[1] * (unsigned __int128)b[2] + + (unsigned __int128)t3 + (z >> 64); + t3 = (uint64_t)z; + z = (unsigned __int128)a[1] * (unsigned __int128)b[3] + + (unsigned __int128)t4 + (z >> 64); + t4 = (uint64_t)z; + t5 = (uint64_t)(z >> 64); + + z = (unsigned __int128)a[2] * (unsigned __int128)b[0] + + (unsigned __int128)t2; + t2 = (uint64_t)z; + z = (unsigned __int128)a[2] * (unsigned __int128)b[1] + + (unsigned __int128)t3 + (z >> 64); + t3 = (uint64_t)z; + z = (unsigned __int128)a[2] * (unsigned __int128)b[2] + + (unsigned __int128)t4 + (z >> 64); + t4 = (uint64_t)z; + z = (unsigned __int128)a[2] * (unsigned __int128)b[3] + + (unsigned __int128)t5 + (z >> 64); + t5 = (uint64_t)z; + t6 = (uint64_t)(z >> 64); + + z = (unsigned __int128)a[3] * (unsigned __int128)b[0] + + (unsigned __int128)t3; + t3 = (uint64_t)z; + z = (unsigned __int128)a[3] * (unsigned __int128)b[1] + + (unsigned __int128)t4 + (z >> 64); + t4 = (uint64_t)z; + z = (unsigned __int128)a[3] * (unsigned __int128)b[2] + + (unsigned __int128)t5 + (z >> 64); + t5 = (uint64_t)z; + z = (unsigned __int128)a[3] * (unsigned __int128)b[3] + + (unsigned __int128)t6 + (z >> 64); + t6 = (uint64_t)z; + t7 = (uint64_t)(z >> 64); + + /* + * Modulo p, we have: + * + * 2^255 = 19 + * 2^510 = 19*19 = 361 + * + * We split the intermediate t into three parts, in basis + * 2^255. The low one will be in t0..t3; the middle one in t4..t7. + * The upper one can only be a single bit (th), since the + * multiplication operands are at most 2^255+37 each. + */ + th = t7 >> 62; + t7 = ((t7 << 1) | (t6 >> 63)) & MASK63; + t6 = (t6 << 1) | (t5 >> 63); + t5 = (t5 << 1) | (t4 >> 63); + t4 = (t4 << 1) | (t3 >> 63); + t3 &= MASK63; + + /* + * Multiply the middle part (t4..t7) by 19. We truncate it to + * 255 bits; the extra bits will go along with th. + */ + z = (unsigned __int128)t4 * 19; + t4 = (uint64_t)z; + z = (unsigned __int128)t5 * 19 + (z >> 64); + t5 = (uint64_t)z; + z = (unsigned __int128)t6 * 19 + (z >> 64); + t6 = (uint64_t)z; + z = (unsigned __int128)t7 * 19 + (z >> 64); + t7 = (uint64_t)z & MASK63; + + th = (361 & -th) + (19 * (uint64_t)(z >> 63)); + + /* + * Add elements together. + * At this point: + * t0..t3 fits on 255 bits. + * t4..t7 fits on 255 bits. + * th <= 361 + 342 = 703. + */ + z = (unsigned __int128)t0 + (unsigned __int128)t4 + + (unsigned __int128)th; + t0 = (uint64_t)z; + z = (unsigned __int128)t1 + (unsigned __int128)t5 + (z >> 64); + t1 = (uint64_t)z; + z = (unsigned __int128)t2 + (unsigned __int128)t6 + (z >> 64); + t2 = (uint64_t)z; + z = (unsigned __int128)t3 + (unsigned __int128)t7 + (z >> 64); + t3 = (uint64_t)z & MASK63; + th = (uint64_t)(z >> 63); + + /* + * Since the sum is at most 2^256 + 703, the two upper bits, in th, + * can only have value 0, 1 or 2. We just add th*19, which + * guarantees a result of at most 2^255+37. + */ + z = (unsigned __int128)t0 + (19 * th); + d[0] = (uint64_t)z; + z = (unsigned __int128)t1 + (z >> 64); + d[1] = (uint64_t)z; + z = (unsigned __int128)t2 + (z >> 64); + d[2] = (uint64_t)z; + d[3] = t3 + (uint64_t)(z >> 64); + +#elif BR_UMUL128 + + uint64_t t0, t1, t2, t3, t4, t5, t6, t7, th; + uint64_t h0, h1, h2, h3; + unsigned char k; + + /* + * Compute the product a*b over plain integers. + */ + t0 = _umul128(a[0], b[0], &h0); + t1 = _umul128(a[0], b[1], &h1); + k = _addcarry_u64(0, t1, h0, &t1); + t2 = _umul128(a[0], b[2], &h2); + k = _addcarry_u64(k, t2, h1, &t2); + t3 = _umul128(a[0], b[3], &h3); + k = _addcarry_u64(k, t3, h2, &t3); + (void)_addcarry_u64(k, h3, 0, &t4); + + k = _addcarry_u64(0, _umul128(a[1], b[0], &h0), t1, &t1); + k = _addcarry_u64(k, _umul128(a[1], b[1], &h1), t2, &t2); + k = _addcarry_u64(k, _umul128(a[1], b[2], &h2), t3, &t3); + k = _addcarry_u64(k, _umul128(a[1], b[3], &h3), t4, &t4); + t5 = k; + k = _addcarry_u64(0, t2, h0, &t2); + k = _addcarry_u64(k, t3, h1, &t3); + k = _addcarry_u64(k, t4, h2, &t4); + (void)_addcarry_u64(k, t5, h3, &t5); + + k = _addcarry_u64(0, _umul128(a[2], b[0], &h0), t2, &t2); + k = _addcarry_u64(k, _umul128(a[2], b[1], &h1), t3, &t3); + k = _addcarry_u64(k, _umul128(a[2], b[2], &h2), t4, &t4); + k = _addcarry_u64(k, _umul128(a[2], b[3], &h3), t5, &t5); + t6 = k; + k = _addcarry_u64(0, t3, h0, &t3); + k = _addcarry_u64(k, t4, h1, &t4); + k = _addcarry_u64(k, t5, h2, &t5); + (void)_addcarry_u64(k, t6, h3, &t6); + + k = _addcarry_u64(0, _umul128(a[3], b[0], &h0), t3, &t3); + k = _addcarry_u64(k, _umul128(a[3], b[1], &h1), t4, &t4); + k = _addcarry_u64(k, _umul128(a[3], b[2], &h2), t5, &t5); + k = _addcarry_u64(k, _umul128(a[3], b[3], &h3), t6, &t6); + t7 = k; + k = _addcarry_u64(0, t4, h0, &t4); + k = _addcarry_u64(k, t5, h1, &t5); + k = _addcarry_u64(k, t6, h2, &t6); + (void)_addcarry_u64(k, t7, h3, &t7); + + /* + * Modulo p, we have: + * + * 2^255 = 19 + * 2^510 = 19*19 = 361 + * + * We split the intermediate t into three parts, in basis + * 2^255. The low one will be in t0..t3; the middle one in t4..t7. + * The upper one can only be a single bit (th), since the + * multiplication operands are at most 2^255+37 each. + */ + th = t7 >> 62; + t7 = ((t7 << 1) | (t6 >> 63)) & MASK63; + t6 = (t6 << 1) | (t5 >> 63); + t5 = (t5 << 1) | (t4 >> 63); + t4 = (t4 << 1) | (t3 >> 63); + t3 &= MASK63; + + /* + * Multiply the middle part (t4..t7) by 19. We truncate it to + * 255 bits; the extra bits will go along with th. + */ + t4 = _umul128(t4, 19, &h0); + t5 = _umul128(t5, 19, &h1); + t6 = _umul128(t6, 19, &h2); + t7 = _umul128(t7, 19, &h3); + k = _addcarry_u64(0, t5, h0, &t5); + k = _addcarry_u64(k, t6, h1, &t6); + k = _addcarry_u64(k, t7, h2, &t7); + (void)_addcarry_u64(k, h3, 0, &h3); + th = (361 & -th) + (19 * ((h3 << 1) + (t7 >> 63))); + t7 &= MASK63; + + /* + * Add elements together. + * At this point: + * t0..t3 fits on 255 bits. + * t4..t7 fits on 255 bits. + * th <= 361 + 342 = 703. + */ + k = _addcarry_u64(0, t0, t4, &t0); + k = _addcarry_u64(k, t1, t5, &t1); + k = _addcarry_u64(k, t2, t6, &t2); + k = _addcarry_u64(k, t3, t7, &t3); + t4 = k; + k = _addcarry_u64(0, t0, th, &t0); + k = _addcarry_u64(k, t1, 0, &t1); + k = _addcarry_u64(k, t2, 0, &t2); + k = _addcarry_u64(k, t3, 0, &t3); + (void)_addcarry_u64(k, t4, 0, &t4); + + th = (t4 << 1) + (t3 >> 63); + t3 &= MASK63; + + /* + * Since the sum is at most 2^256 + 703, the two upper bits, in th, + * can only have value 0, 1 or 2. We just add th*19, which + * guarantees a result of at most 2^255+37. + */ + k = _addcarry_u64(0, t0, 19 * th, &d[0]); + k = _addcarry_u64(k, t1, 0, &d[1]); + k = _addcarry_u64(k, t2, 0, &d[2]); + (void)_addcarry_u64(k, t3, 0, &d[3]); + +#endif +} + +/* + * Multiplication by A24 = 121665. + */ +static inline void +f255_mul_a24(uint64_t *d, const uint64_t *a) +{ +#if BR_INT128 + + uint64_t t0, t1, t2, t3; + unsigned __int128 z; + + z = (unsigned __int128)a[0] * 121665; + t0 = (uint64_t)z; + z = (unsigned __int128)a[1] * 121665 + (z >> 64); + t1 = (uint64_t)z; + z = (unsigned __int128)a[2] * 121665 + (z >> 64); + t2 = (uint64_t)z; + z = (unsigned __int128)a[3] * 121665 + (z >> 64); + t3 = (uint64_t)z & MASK63; + + z = (unsigned __int128)t0 + (19 * (uint64_t)(z >> 63)); + t0 = (uint64_t)z; + z = (unsigned __int128)t1 + (z >> 64); + t1 = (uint64_t)z; + z = (unsigned __int128)t2 + (z >> 64); + t2 = (uint64_t)z; + t3 = t3 + (uint64_t)(z >> 64); + + z = (unsigned __int128)t0 + (19 & -(t3 >> 63)); + d[0] = (uint64_t)z; + z = (unsigned __int128)t1 + (z >> 64); + d[1] = (uint64_t)z; + z = (unsigned __int128)t2 + (z >> 64); + d[2] = (uint64_t)z; + d[3] = (t3 & MASK63) + (uint64_t)(z >> 64); + +#elif BR_UMUL128 + + uint64_t t0, t1, t2, t3, t4, h0, h1, h2, h3; + unsigned char k; + + t0 = _umul128(a[0], 121665, &h0); + t1 = _umul128(a[1], 121665, &h1); + k = _addcarry_u64(0, t1, h0, &t1); + t2 = _umul128(a[2], 121665, &h2); + k = _addcarry_u64(k, t2, h1, &t2); + t3 = _umul128(a[3], 121665, &h3); + k = _addcarry_u64(k, t3, h2, &t3); + (void)_addcarry_u64(k, h3, 0, &t4); + + t4 = (t4 << 1) + (t3 >> 63); + t3 &= MASK63; + k = _addcarry_u64(0, t0, 19 * t4, &t0); + k = _addcarry_u64(k, t1, 0, &t1); + k = _addcarry_u64(k, t2, 0, &t2); + (void)_addcarry_u64(k, t3, 0, &t3); + + t4 = 19 & -(t3 >> 63); + t3 &= MASK63; + k = _addcarry_u64(0, t0, t4, &d[0]); + k = _addcarry_u64(k, t1, 0, &d[1]); + k = _addcarry_u64(k, t2, 0, &d[2]); + (void)_addcarry_u64(k, t3, 0, &d[3]); + +#endif +} + +/* + * Finalize reduction. + */ +static inline void +f255_final_reduce(uint64_t *a) +{ +#if BR_INT128 + + uint64_t t0, t1, t2, t3, m; + unsigned __int128 z; + + /* + * We add 19. If the result (in t) is below 2^255, then a[] + * is already less than 2^255-19, thus already reduced. + * Otherwise, we subtract 2^255 from t[], in which case we + * have t = a - (2^255-19), and that's our result. + */ + z = (unsigned __int128)a[0] + 19; + t0 = (uint64_t)z; + z = (unsigned __int128)a[1] + (z >> 64); + t1 = (uint64_t)z; + z = (unsigned __int128)a[2] + (z >> 64); + t2 = (uint64_t)z; + t3 = a[3] + (uint64_t)(z >> 64); + + m = -(t3 >> 63); + t3 &= MASK63; + a[0] ^= m & (a[0] ^ t0); + a[1] ^= m & (a[1] ^ t1); + a[2] ^= m & (a[2] ^ t2); + a[3] ^= m & (a[3] ^ t3); + +#elif BR_UMUL128 + + uint64_t t0, t1, t2, t3, m; + unsigned char k; + + /* + * We add 19. If the result (in t) is below 2^255, then a[] + * is already less than 2^255-19, thus already reduced. + * Otherwise, we subtract 2^255 from t[], in which case we + * have t = a - (2^255-19), and that's our result. + */ + k = _addcarry_u64(0, a[0], 19, &t0); + k = _addcarry_u64(k, a[1], 0, &t1); + k = _addcarry_u64(k, a[2], 0, &t2); + (void)_addcarry_u64(k, a[3], 0, &t3); + + m = -(t3 >> 63); + t3 &= MASK63; + a[0] ^= m & (a[0] ^ t0); + a[1] ^= m & (a[1] ^ t1); + a[2] ^= m & (a[2] ^ t2); + a[3] ^= m & (a[3] ^ t3); + +#endif +} + +static uint32_t +api_mul(unsigned char *G, size_t Glen, + const unsigned char *kb, size_t kblen, int curve) +{ + unsigned char k[32]; + uint64_t x1[4], x2[4], z2[4], x3[4], z3[4]; + uint32_t swap; + int i; + + (void)curve; + + /* + * Points are encoded over exactly 32 bytes. Multipliers must fit + * in 32 bytes as well. + */ + if (Glen != 32 || kblen > 32) { + return 0; + } + + /* + * RFC 7748 mandates that the high bit of the last point byte must + * be ignored/cleared. + */ + x1[0] = br_dec64le(&G[ 0]); + x1[1] = br_dec64le(&G[ 8]); + x1[2] = br_dec64le(&G[16]); + x1[3] = br_dec64le(&G[24]) & MASK63; + + /* + * We can use memset() to clear values, because exact-width types + * like uint64_t are guaranteed to have no padding bits or + * trap representations. + */ + memset(x2, 0, sizeof x2); + x2[0] = 1; + memset(z2, 0, sizeof z2); + memcpy(x3, x1, sizeof x1); + memcpy(z3, x2, sizeof x2); + + /* + * The multiplier is provided in big-endian notation, and + * possibly shorter than 32 bytes. + */ + memset(k, 0, (sizeof k) - kblen); + memcpy(k + (sizeof k) - kblen, kb, kblen); + k[31] &= 0xF8; + k[0] &= 0x7F; + k[0] |= 0x40; + + swap = 0; + + for (i = 254; i >= 0; i --) { + uint64_t a[4], aa[4], b[4], bb[4], e[4]; + uint64_t c[4], d[4], da[4], cb[4]; + uint32_t kt; + + kt = (k[31 - (i >> 3)] >> (i & 7)) & 1; + swap ^= kt; + f255_cswap(x2, x3, swap); + f255_cswap(z2, z3, swap); + swap = kt; + + /* A = x_2 + z_2 */ + f255_add(a, x2, z2); + + /* AA = A^2 */ + f255_mul(aa, a, a); + + /* B = x_2 - z_2 */ + f255_sub(b, x2, z2); + + /* BB = B^2 */ + f255_mul(bb, b, b); + + /* E = AA - BB */ + f255_sub(e, aa, bb); + + /* C = x_3 + z_3 */ + f255_add(c, x3, z3); + + /* D = x_3 - z_3 */ + f255_sub(d, x3, z3); + + /* DA = D * A */ + f255_mul(da, d, a); + + /* CB = C * B */ + f255_mul(cb, c, b); + + /* x_3 = (DA + CB)^2 */ + f255_add(x3, da, cb); + f255_mul(x3, x3, x3); + + /* z_3 = x_1 * (DA - CB)^2 */ + f255_sub(z3, da, cb); + f255_mul(z3, z3, z3); + f255_mul(z3, x1, z3); + + /* x_2 = AA * BB */ + f255_mul(x2, aa, bb); + + /* z_2 = E * (AA + a24 * E) */ + f255_mul_a24(z2, e); + f255_add(z2, aa, z2); + f255_mul(z2, e, z2); + } + + f255_cswap(x2, x3, swap); + f255_cswap(z2, z3, swap); + + /* + * Compute 1/z2 = z2^(p-2). Since p = 2^255-19, we can mutualize + * most non-squarings. We use x1 and x3, now useless, as temporaries. + */ + memcpy(x1, z2, sizeof z2); + for (i = 0; i < 15; i ++) { + f255_mul(x1, x1, x1); + f255_mul(x1, x1, z2); + } + memcpy(x3, x1, sizeof x1); + for (i = 0; i < 14; i ++) { + int j; + + for (j = 0; j < 16; j ++) { + f255_mul(x3, x3, x3); + } + f255_mul(x3, x3, x1); + } + for (i = 14; i >= 0; i --) { + f255_mul(x3, x3, x3); + if ((0xFFEB >> i) & 1) { + f255_mul(x3, z2, x3); + } + } + + /* + * Compute x2/z2. We have 1/z2 in x3. + */ + f255_mul(x2, x2, x3); + f255_final_reduce(x2); + + /* + * Encode the final x2 value in little-endian. + */ + br_enc64le(G, x2[0]); + br_enc64le(G + 8, x2[1]); + br_enc64le(G + 16, x2[2]); + br_enc64le(G + 24, x2[3]); + return 1; +} + +static size_t +api_mulgen(unsigned char *R, + const unsigned char *x, size_t xlen, int curve) +{ + const unsigned char *G; + size_t Glen; + + G = api_generator(curve, &Glen); + memcpy(R, G, Glen); + api_mul(R, Glen, x, xlen, curve); + return Glen; +} + +static uint32_t +api_muladd(unsigned char *A, const unsigned char *B, size_t len, + const unsigned char *x, size_t xlen, + const unsigned char *y, size_t ylen, int curve) +{ + /* + * We don't implement this method, since it is used for ECDSA + * only, and there is no ECDSA over Curve25519 (which instead + * uses EdDSA). + */ + (void)A; + (void)B; + (void)len; + (void)x; + (void)xlen; + (void)y; + (void)ylen; + (void)curve; + return 0; +} + +/* see bearssl_ec.h */ +const br_ec_impl br_ec_c25519_m64 = { + (uint32_t)0x20000000, + &api_generator, + &api_order, + &api_xoff, + &api_mul, + &api_mulgen, + &api_muladd +}; + +/* see bearssl_ec.h */ +const br_ec_impl * +br_ec_c25519_m64_get(void) +{ + return &br_ec_c25519_m64; +} + +#else + +/* see bearssl_ec.h */ +const br_ec_impl * +br_ec_c25519_m64_get(void) +{ + return 0; +} + +#endif + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_curve25519.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_curve25519.c new file mode 100644 index 000000000..924c3ff48 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_curve25519.c @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +static const unsigned char GEN[] = { + 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + +static const unsigned char ORDER[] = { + 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF +}; + +/* see inner.h */ +const br_ec_curve_def br_curve25519 = { + BR_EC_curve25519, + ORDER, sizeof ORDER, + GEN, sizeof GEN +}; + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_default.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_default.c new file mode 100644 index 000000000..2e12a3551 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_default.c @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_ec.h */ +const br_ec_impl * +br_ec_get_default(void) +{ +#if BR_LOMUL + return &br_ec_all_m15; +#else + return &br_ec_all_m31; +#endif +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_keygen.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_keygen.c new file mode 100644 index 000000000..ce90c4aa3 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_keygen.c @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_ec.h */ +size_t +br_ec_keygen(const br_prng_class **rng_ctx, + const br_ec_impl *impl, br_ec_private_key *sk, + void *kbuf, int curve) +{ + const unsigned char *order; + unsigned char *buf; + size_t len; + unsigned mask; + + if (curve < 0 || curve >= 32 + || ((impl->supported_curves >> curve) & 1) == 0) + { + return 0; + } + order = impl->order(curve, &len); + while (len > 0 && *order == 0) { + order ++; + len --; + } + if (kbuf == NULL || len == 0) { + return len; + } + mask = order[0]; + mask |= (mask >> 1); + mask |= (mask >> 2); + mask |= (mask >> 4); + + /* + * We generate sequences of random bits of the right size, until + * the value is strictly lower than the curve order (we also + * check for all-zero values, which are invalid). + */ + buf = kbuf; + for (;;) { + size_t u; + unsigned cc, zz; + + (*rng_ctx)->generate(rng_ctx, buf, len); + buf[0] &= mask; + cc = 0; + u = len; + zz = 0; + while (u -- > 0) { + cc = ((unsigned)(buf[u] - order[u] - cc) >> 8) & 1; + zz |= buf[u]; + } + if (cc != 0 && zz != 0) { + break; + } + } + + if (sk != NULL) { + sk->curve = curve; + sk->x = buf; + sk->xlen = len; + } + return len; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_p256_m15.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_p256_m15.c new file mode 100644 index 000000000..b88533962 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_p256_m15.c @@ -0,0 +1,2135 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* + * If BR_NO_ARITH_SHIFT is undefined, or defined to 0, then we _assume_ + * that right-shifting a signed negative integer copies the sign bit + * (arithmetic right-shift). This is "implementation-defined behaviour", + * i.e. it is not undefined, but it may differ between compilers. Each + * compiler is supposed to document its behaviour in that respect. GCC + * explicitly defines that an arithmetic right shift is used. We expect + * all other compilers to do the same, because underlying CPU offer an + * arithmetic right shift opcode that could not be used otherwise. + */ +#if BR_NO_ARITH_SHIFT +#define ARSH(x, n) (((uint32_t)(x) >> (n)) \ + | ((-((uint32_t)(x) >> 31)) << (32 - (n)))) +#else +#define ARSH(x, n) ((*(int32_t *)&(x)) >> (n)) +#endif + +/* + * Convert an integer from unsigned big-endian encoding to a sequence of + * 13-bit words in little-endian order. The final "partial" word is + * returned. + */ +static uint32_t +be8_to_le13(uint32_t *dst, const unsigned char *src, size_t len) +{ + uint32_t acc; + int acc_len; + + acc = 0; + acc_len = 0; + while (len -- > 0) { + acc |= (uint32_t)src[len] << acc_len; + acc_len += 8; + if (acc_len >= 13) { + *dst ++ = acc & 0x1FFF; + acc >>= 13; + acc_len -= 13; + } + } + return acc; +} + +/* + * Convert an integer (13-bit words, little-endian) to unsigned + * big-endian encoding. The total encoding length is provided; all + * the destination bytes will be filled. + */ +static void +le13_to_be8(unsigned char *dst, size_t len, const uint32_t *src) +{ + uint32_t acc; + int acc_len; + + acc = 0; + acc_len = 0; + while (len -- > 0) { + if (acc_len < 8) { + acc |= (*src ++) << acc_len; + acc_len += 13; + } + dst[len] = (unsigned char)acc; + acc >>= 8; + acc_len -= 8; + } +} + +/* + * Normalise an array of words to a strict 13 bits per word. Returned + * value is the resulting carry. The source (w) and destination (d) + * arrays may be identical, but shall not overlap partially. + */ +static inline uint32_t +norm13(uint32_t *d, const uint32_t *w, size_t len) +{ + size_t u; + uint32_t cc; + + cc = 0; + for (u = 0; u < len; u ++) { + int32_t z; + + z = w[u] + cc; + d[u] = z & 0x1FFF; + cc = ARSH(z, 13); + } + return cc; +} + +/* + * mul20() multiplies two 260-bit integers together. Each word must fit + * on 13 bits; source operands use 20 words, destination operand + * receives 40 words. All overlaps allowed. + * + * square20() computes the square of a 260-bit integer. Each word must + * fit on 13 bits; source operand uses 20 words, destination operand + * receives 40 words. All overlaps allowed. + */ + +#if BR_SLOW_MUL15 + +static void +mul20(uint32_t *d, const uint32_t *a, const uint32_t *b) +{ + /* + * Two-level Karatsuba: turns a 20x20 multiplication into + * nine 5x5 multiplications. We use 13-bit words but do not + * propagate carries immediately, so words may expand: + * + * - First Karatsuba decomposition turns the 20x20 mul on + * 13-bit words into three 10x10 muls, two on 13-bit words + * and one on 14-bit words. + * + * - Second Karatsuba decomposition further splits these into: + * + * * four 5x5 muls on 13-bit words + * * four 5x5 muls on 14-bit words + * * one 5x5 mul on 15-bit words + * + * Highest word value is 8191, 16382 or 32764, for 13-bit, 14-bit + * or 15-bit words, respectively. + */ + uint32_t u[45], v[45], w[90]; + uint32_t cc; + int i; + +#define ZADD(dw, d_off, s1w, s1_off, s2w, s2_off) do { \ + (dw)[5 * (d_off) + 0] = (s1w)[5 * (s1_off) + 0] \ + + (s2w)[5 * (s2_off) + 0]; \ + (dw)[5 * (d_off) + 1] = (s1w)[5 * (s1_off) + 1] \ + + (s2w)[5 * (s2_off) + 1]; \ + (dw)[5 * (d_off) + 2] = (s1w)[5 * (s1_off) + 2] \ + + (s2w)[5 * (s2_off) + 2]; \ + (dw)[5 * (d_off) + 3] = (s1w)[5 * (s1_off) + 3] \ + + (s2w)[5 * (s2_off) + 3]; \ + (dw)[5 * (d_off) + 4] = (s1w)[5 * (s1_off) + 4] \ + + (s2w)[5 * (s2_off) + 4]; \ + } while (0) + +#define ZADDT(dw, d_off, sw, s_off) do { \ + (dw)[5 * (d_off) + 0] += (sw)[5 * (s_off) + 0]; \ + (dw)[5 * (d_off) + 1] += (sw)[5 * (s_off) + 1]; \ + (dw)[5 * (d_off) + 2] += (sw)[5 * (s_off) + 2]; \ + (dw)[5 * (d_off) + 3] += (sw)[5 * (s_off) + 3]; \ + (dw)[5 * (d_off) + 4] += (sw)[5 * (s_off) + 4]; \ + } while (0) + +#define ZSUB2F(dw, d_off, s1w, s1_off, s2w, s2_off) do { \ + (dw)[5 * (d_off) + 0] -= (s1w)[5 * (s1_off) + 0] \ + + (s2w)[5 * (s2_off) + 0]; \ + (dw)[5 * (d_off) + 1] -= (s1w)[5 * (s1_off) + 1] \ + + (s2w)[5 * (s2_off) + 1]; \ + (dw)[5 * (d_off) + 2] -= (s1w)[5 * (s1_off) + 2] \ + + (s2w)[5 * (s2_off) + 2]; \ + (dw)[5 * (d_off) + 3] -= (s1w)[5 * (s1_off) + 3] \ + + (s2w)[5 * (s2_off) + 3]; \ + (dw)[5 * (d_off) + 4] -= (s1w)[5 * (s1_off) + 4] \ + + (s2w)[5 * (s2_off) + 4]; \ + } while (0) + +#define CPR1(w, cprcc) do { \ + uint32_t cprz = (w) + cprcc; \ + (w) = cprz & 0x1FFF; \ + cprcc = cprz >> 13; \ + } while (0) + +#define CPR(dw, d_off) do { \ + uint32_t cprcc; \ + cprcc = 0; \ + CPR1((dw)[(d_off) + 0], cprcc); \ + CPR1((dw)[(d_off) + 1], cprcc); \ + CPR1((dw)[(d_off) + 2], cprcc); \ + CPR1((dw)[(d_off) + 3], cprcc); \ + CPR1((dw)[(d_off) + 4], cprcc); \ + CPR1((dw)[(d_off) + 5], cprcc); \ + CPR1((dw)[(d_off) + 6], cprcc); \ + CPR1((dw)[(d_off) + 7], cprcc); \ + CPR1((dw)[(d_off) + 8], cprcc); \ + (dw)[(d_off) + 9] = cprcc; \ + } while (0) + + memcpy(u, a, 20 * sizeof *a); + ZADD(u, 4, a, 0, a, 1); + ZADD(u, 5, a, 2, a, 3); + ZADD(u, 6, a, 0, a, 2); + ZADD(u, 7, a, 1, a, 3); + ZADD(u, 8, u, 6, u, 7); + + memcpy(v, b, 20 * sizeof *b); + ZADD(v, 4, b, 0, b, 1); + ZADD(v, 5, b, 2, b, 3); + ZADD(v, 6, b, 0, b, 2); + ZADD(v, 7, b, 1, b, 3); + ZADD(v, 8, v, 6, v, 7); + + /* + * Do the eight first 8x8 muls. Source words are at most 16382 + * each, so we can add product results together "as is" in 32-bit + * words. + */ + for (i = 0; i < 40; i += 5) { + w[(i << 1) + 0] = MUL15(u[i + 0], v[i + 0]); + w[(i << 1) + 1] = MUL15(u[i + 0], v[i + 1]) + + MUL15(u[i + 1], v[i + 0]); + w[(i << 1) + 2] = MUL15(u[i + 0], v[i + 2]) + + MUL15(u[i + 1], v[i + 1]) + + MUL15(u[i + 2], v[i + 0]); + w[(i << 1) + 3] = MUL15(u[i + 0], v[i + 3]) + + MUL15(u[i + 1], v[i + 2]) + + MUL15(u[i + 2], v[i + 1]) + + MUL15(u[i + 3], v[i + 0]); + w[(i << 1) + 4] = MUL15(u[i + 0], v[i + 4]) + + MUL15(u[i + 1], v[i + 3]) + + MUL15(u[i + 2], v[i + 2]) + + MUL15(u[i + 3], v[i + 1]) + + MUL15(u[i + 4], v[i + 0]); + w[(i << 1) + 5] = MUL15(u[i + 1], v[i + 4]) + + MUL15(u[i + 2], v[i + 3]) + + MUL15(u[i + 3], v[i + 2]) + + MUL15(u[i + 4], v[i + 1]); + w[(i << 1) + 6] = MUL15(u[i + 2], v[i + 4]) + + MUL15(u[i + 3], v[i + 3]) + + MUL15(u[i + 4], v[i + 2]); + w[(i << 1) + 7] = MUL15(u[i + 3], v[i + 4]) + + MUL15(u[i + 4], v[i + 3]); + w[(i << 1) + 8] = MUL15(u[i + 4], v[i + 4]); + w[(i << 1) + 9] = 0; + } + + /* + * For the 9th multiplication, source words are up to 32764, + * so we must do some carry propagation. If we add up to + * 4 products and the carry is no more than 524224, then the + * result fits in 32 bits, and the next carry will be no more + * than 524224 (because 4*(32764^2)+524224 < 8192*524225). + * + * We thus just skip one of the products in the middle word, + * then do a carry propagation (this reduces words to 13 bits + * each, except possibly the last, which may use up to 17 bits + * or so), then add the missing product. + */ + w[80 + 0] = MUL15(u[40 + 0], v[40 + 0]); + w[80 + 1] = MUL15(u[40 + 0], v[40 + 1]) + + MUL15(u[40 + 1], v[40 + 0]); + w[80 + 2] = MUL15(u[40 + 0], v[40 + 2]) + + MUL15(u[40 + 1], v[40 + 1]) + + MUL15(u[40 + 2], v[40 + 0]); + w[80 + 3] = MUL15(u[40 + 0], v[40 + 3]) + + MUL15(u[40 + 1], v[40 + 2]) + + MUL15(u[40 + 2], v[40 + 1]) + + MUL15(u[40 + 3], v[40 + 0]); + w[80 + 4] = MUL15(u[40 + 0], v[40 + 4]) + + MUL15(u[40 + 1], v[40 + 3]) + + MUL15(u[40 + 2], v[40 + 2]) + + MUL15(u[40 + 3], v[40 + 1]); + /* + MUL15(u[40 + 4], v[40 + 0]) */ + w[80 + 5] = MUL15(u[40 + 1], v[40 + 4]) + + MUL15(u[40 + 2], v[40 + 3]) + + MUL15(u[40 + 3], v[40 + 2]) + + MUL15(u[40 + 4], v[40 + 1]); + w[80 + 6] = MUL15(u[40 + 2], v[40 + 4]) + + MUL15(u[40 + 3], v[40 + 3]) + + MUL15(u[40 + 4], v[40 + 2]); + w[80 + 7] = MUL15(u[40 + 3], v[40 + 4]) + + MUL15(u[40 + 4], v[40 + 3]); + w[80 + 8] = MUL15(u[40 + 4], v[40 + 4]); + + CPR(w, 80); + + w[80 + 4] += MUL15(u[40 + 4], v[40 + 0]); + + /* + * The products on 14-bit words in slots 6 and 7 yield values + * up to 5*(16382^2) each, and we need to subtract two such + * values from the higher word. We need the subtraction to fit + * in a _signed_ 32-bit integer, i.e. 31 bits + a sign bit. + * However, 10*(16382^2) does not fit. So we must perform a + * bit of reduction here. + */ + CPR(w, 60); + CPR(w, 70); + + /* + * Recompose results. + */ + + /* 0..1*0..1 into 0..3 */ + ZSUB2F(w, 8, w, 0, w, 2); + ZSUB2F(w, 9, w, 1, w, 3); + ZADDT(w, 1, w, 8); + ZADDT(w, 2, w, 9); + + /* 2..3*2..3 into 4..7 */ + ZSUB2F(w, 10, w, 4, w, 6); + ZSUB2F(w, 11, w, 5, w, 7); + ZADDT(w, 5, w, 10); + ZADDT(w, 6, w, 11); + + /* (0..1+2..3)*(0..1+2..3) into 12..15 */ + ZSUB2F(w, 16, w, 12, w, 14); + ZSUB2F(w, 17, w, 13, w, 15); + ZADDT(w, 13, w, 16); + ZADDT(w, 14, w, 17); + + /* first-level recomposition */ + ZSUB2F(w, 12, w, 0, w, 4); + ZSUB2F(w, 13, w, 1, w, 5); + ZSUB2F(w, 14, w, 2, w, 6); + ZSUB2F(w, 15, w, 3, w, 7); + ZADDT(w, 2, w, 12); + ZADDT(w, 3, w, 13); + ZADDT(w, 4, w, 14); + ZADDT(w, 5, w, 15); + + /* + * Perform carry propagation to bring all words down to 13 bits. + */ + cc = norm13(d, w, 40); + d[39] += (cc << 13); + +#undef ZADD +#undef ZADDT +#undef ZSUB2F +#undef CPR1 +#undef CPR +} + +static inline void +square20(uint32_t *d, const uint32_t *a) +{ + mul20(d, a, a); +} + +#else + +static void +mul20(uint32_t *d, const uint32_t *a, const uint32_t *b) +{ + uint32_t t[39]; + + t[ 0] = MUL15(a[ 0], b[ 0]); + t[ 1] = MUL15(a[ 0], b[ 1]) + + MUL15(a[ 1], b[ 0]); + t[ 2] = MUL15(a[ 0], b[ 2]) + + MUL15(a[ 1], b[ 1]) + + MUL15(a[ 2], b[ 0]); + t[ 3] = MUL15(a[ 0], b[ 3]) + + MUL15(a[ 1], b[ 2]) + + MUL15(a[ 2], b[ 1]) + + MUL15(a[ 3], b[ 0]); + t[ 4] = MUL15(a[ 0], b[ 4]) + + MUL15(a[ 1], b[ 3]) + + MUL15(a[ 2], b[ 2]) + + MUL15(a[ 3], b[ 1]) + + MUL15(a[ 4], b[ 0]); + t[ 5] = MUL15(a[ 0], b[ 5]) + + MUL15(a[ 1], b[ 4]) + + MUL15(a[ 2], b[ 3]) + + MUL15(a[ 3], b[ 2]) + + MUL15(a[ 4], b[ 1]) + + MUL15(a[ 5], b[ 0]); + t[ 6] = MUL15(a[ 0], b[ 6]) + + MUL15(a[ 1], b[ 5]) + + MUL15(a[ 2], b[ 4]) + + MUL15(a[ 3], b[ 3]) + + MUL15(a[ 4], b[ 2]) + + MUL15(a[ 5], b[ 1]) + + MUL15(a[ 6], b[ 0]); + t[ 7] = MUL15(a[ 0], b[ 7]) + + MUL15(a[ 1], b[ 6]) + + MUL15(a[ 2], b[ 5]) + + MUL15(a[ 3], b[ 4]) + + MUL15(a[ 4], b[ 3]) + + MUL15(a[ 5], b[ 2]) + + MUL15(a[ 6], b[ 1]) + + MUL15(a[ 7], b[ 0]); + t[ 8] = MUL15(a[ 0], b[ 8]) + + MUL15(a[ 1], b[ 7]) + + MUL15(a[ 2], b[ 6]) + + MUL15(a[ 3], b[ 5]) + + MUL15(a[ 4], b[ 4]) + + MUL15(a[ 5], b[ 3]) + + MUL15(a[ 6], b[ 2]) + + MUL15(a[ 7], b[ 1]) + + MUL15(a[ 8], b[ 0]); + t[ 9] = MUL15(a[ 0], b[ 9]) + + MUL15(a[ 1], b[ 8]) + + MUL15(a[ 2], b[ 7]) + + MUL15(a[ 3], b[ 6]) + + MUL15(a[ 4], b[ 5]) + + MUL15(a[ 5], b[ 4]) + + MUL15(a[ 6], b[ 3]) + + MUL15(a[ 7], b[ 2]) + + MUL15(a[ 8], b[ 1]) + + MUL15(a[ 9], b[ 0]); + t[10] = MUL15(a[ 0], b[10]) + + MUL15(a[ 1], b[ 9]) + + MUL15(a[ 2], b[ 8]) + + MUL15(a[ 3], b[ 7]) + + MUL15(a[ 4], b[ 6]) + + MUL15(a[ 5], b[ 5]) + + MUL15(a[ 6], b[ 4]) + + MUL15(a[ 7], b[ 3]) + + MUL15(a[ 8], b[ 2]) + + MUL15(a[ 9], b[ 1]) + + MUL15(a[10], b[ 0]); + t[11] = MUL15(a[ 0], b[11]) + + MUL15(a[ 1], b[10]) + + MUL15(a[ 2], b[ 9]) + + MUL15(a[ 3], b[ 8]) + + MUL15(a[ 4], b[ 7]) + + MUL15(a[ 5], b[ 6]) + + MUL15(a[ 6], b[ 5]) + + MUL15(a[ 7], b[ 4]) + + MUL15(a[ 8], b[ 3]) + + MUL15(a[ 9], b[ 2]) + + MUL15(a[10], b[ 1]) + + MUL15(a[11], b[ 0]); + t[12] = MUL15(a[ 0], b[12]) + + MUL15(a[ 1], b[11]) + + MUL15(a[ 2], b[10]) + + MUL15(a[ 3], b[ 9]) + + MUL15(a[ 4], b[ 8]) + + MUL15(a[ 5], b[ 7]) + + MUL15(a[ 6], b[ 6]) + + MUL15(a[ 7], b[ 5]) + + MUL15(a[ 8], b[ 4]) + + MUL15(a[ 9], b[ 3]) + + MUL15(a[10], b[ 2]) + + MUL15(a[11], b[ 1]) + + MUL15(a[12], b[ 0]); + t[13] = MUL15(a[ 0], b[13]) + + MUL15(a[ 1], b[12]) + + MUL15(a[ 2], b[11]) + + MUL15(a[ 3], b[10]) + + MUL15(a[ 4], b[ 9]) + + MUL15(a[ 5], b[ 8]) + + MUL15(a[ 6], b[ 7]) + + MUL15(a[ 7], b[ 6]) + + MUL15(a[ 8], b[ 5]) + + MUL15(a[ 9], b[ 4]) + + MUL15(a[10], b[ 3]) + + MUL15(a[11], b[ 2]) + + MUL15(a[12], b[ 1]) + + MUL15(a[13], b[ 0]); + t[14] = MUL15(a[ 0], b[14]) + + MUL15(a[ 1], b[13]) + + MUL15(a[ 2], b[12]) + + MUL15(a[ 3], b[11]) + + MUL15(a[ 4], b[10]) + + MUL15(a[ 5], b[ 9]) + + MUL15(a[ 6], b[ 8]) + + MUL15(a[ 7], b[ 7]) + + MUL15(a[ 8], b[ 6]) + + MUL15(a[ 9], b[ 5]) + + MUL15(a[10], b[ 4]) + + MUL15(a[11], b[ 3]) + + MUL15(a[12], b[ 2]) + + MUL15(a[13], b[ 1]) + + MUL15(a[14], b[ 0]); + t[15] = MUL15(a[ 0], b[15]) + + MUL15(a[ 1], b[14]) + + MUL15(a[ 2], b[13]) + + MUL15(a[ 3], b[12]) + + MUL15(a[ 4], b[11]) + + MUL15(a[ 5], b[10]) + + MUL15(a[ 6], b[ 9]) + + MUL15(a[ 7], b[ 8]) + + MUL15(a[ 8], b[ 7]) + + MUL15(a[ 9], b[ 6]) + + MUL15(a[10], b[ 5]) + + MUL15(a[11], b[ 4]) + + MUL15(a[12], b[ 3]) + + MUL15(a[13], b[ 2]) + + MUL15(a[14], b[ 1]) + + MUL15(a[15], b[ 0]); + t[16] = MUL15(a[ 0], b[16]) + + MUL15(a[ 1], b[15]) + + MUL15(a[ 2], b[14]) + + MUL15(a[ 3], b[13]) + + MUL15(a[ 4], b[12]) + + MUL15(a[ 5], b[11]) + + MUL15(a[ 6], b[10]) + + MUL15(a[ 7], b[ 9]) + + MUL15(a[ 8], b[ 8]) + + MUL15(a[ 9], b[ 7]) + + MUL15(a[10], b[ 6]) + + MUL15(a[11], b[ 5]) + + MUL15(a[12], b[ 4]) + + MUL15(a[13], b[ 3]) + + MUL15(a[14], b[ 2]) + + MUL15(a[15], b[ 1]) + + MUL15(a[16], b[ 0]); + t[17] = MUL15(a[ 0], b[17]) + + MUL15(a[ 1], b[16]) + + MUL15(a[ 2], b[15]) + + MUL15(a[ 3], b[14]) + + MUL15(a[ 4], b[13]) + + MUL15(a[ 5], b[12]) + + MUL15(a[ 6], b[11]) + + MUL15(a[ 7], b[10]) + + MUL15(a[ 8], b[ 9]) + + MUL15(a[ 9], b[ 8]) + + MUL15(a[10], b[ 7]) + + MUL15(a[11], b[ 6]) + + MUL15(a[12], b[ 5]) + + MUL15(a[13], b[ 4]) + + MUL15(a[14], b[ 3]) + + MUL15(a[15], b[ 2]) + + MUL15(a[16], b[ 1]) + + MUL15(a[17], b[ 0]); + t[18] = MUL15(a[ 0], b[18]) + + MUL15(a[ 1], b[17]) + + MUL15(a[ 2], b[16]) + + MUL15(a[ 3], b[15]) + + MUL15(a[ 4], b[14]) + + MUL15(a[ 5], b[13]) + + MUL15(a[ 6], b[12]) + + MUL15(a[ 7], b[11]) + + MUL15(a[ 8], b[10]) + + MUL15(a[ 9], b[ 9]) + + MUL15(a[10], b[ 8]) + + MUL15(a[11], b[ 7]) + + MUL15(a[12], b[ 6]) + + MUL15(a[13], b[ 5]) + + MUL15(a[14], b[ 4]) + + MUL15(a[15], b[ 3]) + + MUL15(a[16], b[ 2]) + + MUL15(a[17], b[ 1]) + + MUL15(a[18], b[ 0]); + t[19] = MUL15(a[ 0], b[19]) + + MUL15(a[ 1], b[18]) + + MUL15(a[ 2], b[17]) + + MUL15(a[ 3], b[16]) + + MUL15(a[ 4], b[15]) + + MUL15(a[ 5], b[14]) + + MUL15(a[ 6], b[13]) + + MUL15(a[ 7], b[12]) + + MUL15(a[ 8], b[11]) + + MUL15(a[ 9], b[10]) + + MUL15(a[10], b[ 9]) + + MUL15(a[11], b[ 8]) + + MUL15(a[12], b[ 7]) + + MUL15(a[13], b[ 6]) + + MUL15(a[14], b[ 5]) + + MUL15(a[15], b[ 4]) + + MUL15(a[16], b[ 3]) + + MUL15(a[17], b[ 2]) + + MUL15(a[18], b[ 1]) + + MUL15(a[19], b[ 0]); + t[20] = MUL15(a[ 1], b[19]) + + MUL15(a[ 2], b[18]) + + MUL15(a[ 3], b[17]) + + MUL15(a[ 4], b[16]) + + MUL15(a[ 5], b[15]) + + MUL15(a[ 6], b[14]) + + MUL15(a[ 7], b[13]) + + MUL15(a[ 8], b[12]) + + MUL15(a[ 9], b[11]) + + MUL15(a[10], b[10]) + + MUL15(a[11], b[ 9]) + + MUL15(a[12], b[ 8]) + + MUL15(a[13], b[ 7]) + + MUL15(a[14], b[ 6]) + + MUL15(a[15], b[ 5]) + + MUL15(a[16], b[ 4]) + + MUL15(a[17], b[ 3]) + + MUL15(a[18], b[ 2]) + + MUL15(a[19], b[ 1]); + t[21] = MUL15(a[ 2], b[19]) + + MUL15(a[ 3], b[18]) + + MUL15(a[ 4], b[17]) + + MUL15(a[ 5], b[16]) + + MUL15(a[ 6], b[15]) + + MUL15(a[ 7], b[14]) + + MUL15(a[ 8], b[13]) + + MUL15(a[ 9], b[12]) + + MUL15(a[10], b[11]) + + MUL15(a[11], b[10]) + + MUL15(a[12], b[ 9]) + + MUL15(a[13], b[ 8]) + + MUL15(a[14], b[ 7]) + + MUL15(a[15], b[ 6]) + + MUL15(a[16], b[ 5]) + + MUL15(a[17], b[ 4]) + + MUL15(a[18], b[ 3]) + + MUL15(a[19], b[ 2]); + t[22] = MUL15(a[ 3], b[19]) + + MUL15(a[ 4], b[18]) + + MUL15(a[ 5], b[17]) + + MUL15(a[ 6], b[16]) + + MUL15(a[ 7], b[15]) + + MUL15(a[ 8], b[14]) + + MUL15(a[ 9], b[13]) + + MUL15(a[10], b[12]) + + MUL15(a[11], b[11]) + + MUL15(a[12], b[10]) + + MUL15(a[13], b[ 9]) + + MUL15(a[14], b[ 8]) + + MUL15(a[15], b[ 7]) + + MUL15(a[16], b[ 6]) + + MUL15(a[17], b[ 5]) + + MUL15(a[18], b[ 4]) + + MUL15(a[19], b[ 3]); + t[23] = MUL15(a[ 4], b[19]) + + MUL15(a[ 5], b[18]) + + MUL15(a[ 6], b[17]) + + MUL15(a[ 7], b[16]) + + MUL15(a[ 8], b[15]) + + MUL15(a[ 9], b[14]) + + MUL15(a[10], b[13]) + + MUL15(a[11], b[12]) + + MUL15(a[12], b[11]) + + MUL15(a[13], b[10]) + + MUL15(a[14], b[ 9]) + + MUL15(a[15], b[ 8]) + + MUL15(a[16], b[ 7]) + + MUL15(a[17], b[ 6]) + + MUL15(a[18], b[ 5]) + + MUL15(a[19], b[ 4]); + t[24] = MUL15(a[ 5], b[19]) + + MUL15(a[ 6], b[18]) + + MUL15(a[ 7], b[17]) + + MUL15(a[ 8], b[16]) + + MUL15(a[ 9], b[15]) + + MUL15(a[10], b[14]) + + MUL15(a[11], b[13]) + + MUL15(a[12], b[12]) + + MUL15(a[13], b[11]) + + MUL15(a[14], b[10]) + + MUL15(a[15], b[ 9]) + + MUL15(a[16], b[ 8]) + + MUL15(a[17], b[ 7]) + + MUL15(a[18], b[ 6]) + + MUL15(a[19], b[ 5]); + t[25] = MUL15(a[ 6], b[19]) + + MUL15(a[ 7], b[18]) + + MUL15(a[ 8], b[17]) + + MUL15(a[ 9], b[16]) + + MUL15(a[10], b[15]) + + MUL15(a[11], b[14]) + + MUL15(a[12], b[13]) + + MUL15(a[13], b[12]) + + MUL15(a[14], b[11]) + + MUL15(a[15], b[10]) + + MUL15(a[16], b[ 9]) + + MUL15(a[17], b[ 8]) + + MUL15(a[18], b[ 7]) + + MUL15(a[19], b[ 6]); + t[26] = MUL15(a[ 7], b[19]) + + MUL15(a[ 8], b[18]) + + MUL15(a[ 9], b[17]) + + MUL15(a[10], b[16]) + + MUL15(a[11], b[15]) + + MUL15(a[12], b[14]) + + MUL15(a[13], b[13]) + + MUL15(a[14], b[12]) + + MUL15(a[15], b[11]) + + MUL15(a[16], b[10]) + + MUL15(a[17], b[ 9]) + + MUL15(a[18], b[ 8]) + + MUL15(a[19], b[ 7]); + t[27] = MUL15(a[ 8], b[19]) + + MUL15(a[ 9], b[18]) + + MUL15(a[10], b[17]) + + MUL15(a[11], b[16]) + + MUL15(a[12], b[15]) + + MUL15(a[13], b[14]) + + MUL15(a[14], b[13]) + + MUL15(a[15], b[12]) + + MUL15(a[16], b[11]) + + MUL15(a[17], b[10]) + + MUL15(a[18], b[ 9]) + + MUL15(a[19], b[ 8]); + t[28] = MUL15(a[ 9], b[19]) + + MUL15(a[10], b[18]) + + MUL15(a[11], b[17]) + + MUL15(a[12], b[16]) + + MUL15(a[13], b[15]) + + MUL15(a[14], b[14]) + + MUL15(a[15], b[13]) + + MUL15(a[16], b[12]) + + MUL15(a[17], b[11]) + + MUL15(a[18], b[10]) + + MUL15(a[19], b[ 9]); + t[29] = MUL15(a[10], b[19]) + + MUL15(a[11], b[18]) + + MUL15(a[12], b[17]) + + MUL15(a[13], b[16]) + + MUL15(a[14], b[15]) + + MUL15(a[15], b[14]) + + MUL15(a[16], b[13]) + + MUL15(a[17], b[12]) + + MUL15(a[18], b[11]) + + MUL15(a[19], b[10]); + t[30] = MUL15(a[11], b[19]) + + MUL15(a[12], b[18]) + + MUL15(a[13], b[17]) + + MUL15(a[14], b[16]) + + MUL15(a[15], b[15]) + + MUL15(a[16], b[14]) + + MUL15(a[17], b[13]) + + MUL15(a[18], b[12]) + + MUL15(a[19], b[11]); + t[31] = MUL15(a[12], b[19]) + + MUL15(a[13], b[18]) + + MUL15(a[14], b[17]) + + MUL15(a[15], b[16]) + + MUL15(a[16], b[15]) + + MUL15(a[17], b[14]) + + MUL15(a[18], b[13]) + + MUL15(a[19], b[12]); + t[32] = MUL15(a[13], b[19]) + + MUL15(a[14], b[18]) + + MUL15(a[15], b[17]) + + MUL15(a[16], b[16]) + + MUL15(a[17], b[15]) + + MUL15(a[18], b[14]) + + MUL15(a[19], b[13]); + t[33] = MUL15(a[14], b[19]) + + MUL15(a[15], b[18]) + + MUL15(a[16], b[17]) + + MUL15(a[17], b[16]) + + MUL15(a[18], b[15]) + + MUL15(a[19], b[14]); + t[34] = MUL15(a[15], b[19]) + + MUL15(a[16], b[18]) + + MUL15(a[17], b[17]) + + MUL15(a[18], b[16]) + + MUL15(a[19], b[15]); + t[35] = MUL15(a[16], b[19]) + + MUL15(a[17], b[18]) + + MUL15(a[18], b[17]) + + MUL15(a[19], b[16]); + t[36] = MUL15(a[17], b[19]) + + MUL15(a[18], b[18]) + + MUL15(a[19], b[17]); + t[37] = MUL15(a[18], b[19]) + + MUL15(a[19], b[18]); + t[38] = MUL15(a[19], b[19]); + d[39] = norm13(d, t, 39); +} + +static void +square20(uint32_t *d, const uint32_t *a) +{ + uint32_t t[39]; + + t[ 0] = MUL15(a[ 0], a[ 0]); + t[ 1] = ((MUL15(a[ 0], a[ 1])) << 1); + t[ 2] = MUL15(a[ 1], a[ 1]) + + ((MUL15(a[ 0], a[ 2])) << 1); + t[ 3] = ((MUL15(a[ 0], a[ 3]) + + MUL15(a[ 1], a[ 2])) << 1); + t[ 4] = MUL15(a[ 2], a[ 2]) + + ((MUL15(a[ 0], a[ 4]) + + MUL15(a[ 1], a[ 3])) << 1); + t[ 5] = ((MUL15(a[ 0], a[ 5]) + + MUL15(a[ 1], a[ 4]) + + MUL15(a[ 2], a[ 3])) << 1); + t[ 6] = MUL15(a[ 3], a[ 3]) + + ((MUL15(a[ 0], a[ 6]) + + MUL15(a[ 1], a[ 5]) + + MUL15(a[ 2], a[ 4])) << 1); + t[ 7] = ((MUL15(a[ 0], a[ 7]) + + MUL15(a[ 1], a[ 6]) + + MUL15(a[ 2], a[ 5]) + + MUL15(a[ 3], a[ 4])) << 1); + t[ 8] = MUL15(a[ 4], a[ 4]) + + ((MUL15(a[ 0], a[ 8]) + + MUL15(a[ 1], a[ 7]) + + MUL15(a[ 2], a[ 6]) + + MUL15(a[ 3], a[ 5])) << 1); + t[ 9] = ((MUL15(a[ 0], a[ 9]) + + MUL15(a[ 1], a[ 8]) + + MUL15(a[ 2], a[ 7]) + + MUL15(a[ 3], a[ 6]) + + MUL15(a[ 4], a[ 5])) << 1); + t[10] = MUL15(a[ 5], a[ 5]) + + ((MUL15(a[ 0], a[10]) + + MUL15(a[ 1], a[ 9]) + + MUL15(a[ 2], a[ 8]) + + MUL15(a[ 3], a[ 7]) + + MUL15(a[ 4], a[ 6])) << 1); + t[11] = ((MUL15(a[ 0], a[11]) + + MUL15(a[ 1], a[10]) + + MUL15(a[ 2], a[ 9]) + + MUL15(a[ 3], a[ 8]) + + MUL15(a[ 4], a[ 7]) + + MUL15(a[ 5], a[ 6])) << 1); + t[12] = MUL15(a[ 6], a[ 6]) + + ((MUL15(a[ 0], a[12]) + + MUL15(a[ 1], a[11]) + + MUL15(a[ 2], a[10]) + + MUL15(a[ 3], a[ 9]) + + MUL15(a[ 4], a[ 8]) + + MUL15(a[ 5], a[ 7])) << 1); + t[13] = ((MUL15(a[ 0], a[13]) + + MUL15(a[ 1], a[12]) + + MUL15(a[ 2], a[11]) + + MUL15(a[ 3], a[10]) + + MUL15(a[ 4], a[ 9]) + + MUL15(a[ 5], a[ 8]) + + MUL15(a[ 6], a[ 7])) << 1); + t[14] = MUL15(a[ 7], a[ 7]) + + ((MUL15(a[ 0], a[14]) + + MUL15(a[ 1], a[13]) + + MUL15(a[ 2], a[12]) + + MUL15(a[ 3], a[11]) + + MUL15(a[ 4], a[10]) + + MUL15(a[ 5], a[ 9]) + + MUL15(a[ 6], a[ 8])) << 1); + t[15] = ((MUL15(a[ 0], a[15]) + + MUL15(a[ 1], a[14]) + + MUL15(a[ 2], a[13]) + + MUL15(a[ 3], a[12]) + + MUL15(a[ 4], a[11]) + + MUL15(a[ 5], a[10]) + + MUL15(a[ 6], a[ 9]) + + MUL15(a[ 7], a[ 8])) << 1); + t[16] = MUL15(a[ 8], a[ 8]) + + ((MUL15(a[ 0], a[16]) + + MUL15(a[ 1], a[15]) + + MUL15(a[ 2], a[14]) + + MUL15(a[ 3], a[13]) + + MUL15(a[ 4], a[12]) + + MUL15(a[ 5], a[11]) + + MUL15(a[ 6], a[10]) + + MUL15(a[ 7], a[ 9])) << 1); + t[17] = ((MUL15(a[ 0], a[17]) + + MUL15(a[ 1], a[16]) + + MUL15(a[ 2], a[15]) + + MUL15(a[ 3], a[14]) + + MUL15(a[ 4], a[13]) + + MUL15(a[ 5], a[12]) + + MUL15(a[ 6], a[11]) + + MUL15(a[ 7], a[10]) + + MUL15(a[ 8], a[ 9])) << 1); + t[18] = MUL15(a[ 9], a[ 9]) + + ((MUL15(a[ 0], a[18]) + + MUL15(a[ 1], a[17]) + + MUL15(a[ 2], a[16]) + + MUL15(a[ 3], a[15]) + + MUL15(a[ 4], a[14]) + + MUL15(a[ 5], a[13]) + + MUL15(a[ 6], a[12]) + + MUL15(a[ 7], a[11]) + + MUL15(a[ 8], a[10])) << 1); + t[19] = ((MUL15(a[ 0], a[19]) + + MUL15(a[ 1], a[18]) + + MUL15(a[ 2], a[17]) + + MUL15(a[ 3], a[16]) + + MUL15(a[ 4], a[15]) + + MUL15(a[ 5], a[14]) + + MUL15(a[ 6], a[13]) + + MUL15(a[ 7], a[12]) + + MUL15(a[ 8], a[11]) + + MUL15(a[ 9], a[10])) << 1); + t[20] = MUL15(a[10], a[10]) + + ((MUL15(a[ 1], a[19]) + + MUL15(a[ 2], a[18]) + + MUL15(a[ 3], a[17]) + + MUL15(a[ 4], a[16]) + + MUL15(a[ 5], a[15]) + + MUL15(a[ 6], a[14]) + + MUL15(a[ 7], a[13]) + + MUL15(a[ 8], a[12]) + + MUL15(a[ 9], a[11])) << 1); + t[21] = ((MUL15(a[ 2], a[19]) + + MUL15(a[ 3], a[18]) + + MUL15(a[ 4], a[17]) + + MUL15(a[ 5], a[16]) + + MUL15(a[ 6], a[15]) + + MUL15(a[ 7], a[14]) + + MUL15(a[ 8], a[13]) + + MUL15(a[ 9], a[12]) + + MUL15(a[10], a[11])) << 1); + t[22] = MUL15(a[11], a[11]) + + ((MUL15(a[ 3], a[19]) + + MUL15(a[ 4], a[18]) + + MUL15(a[ 5], a[17]) + + MUL15(a[ 6], a[16]) + + MUL15(a[ 7], a[15]) + + MUL15(a[ 8], a[14]) + + MUL15(a[ 9], a[13]) + + MUL15(a[10], a[12])) << 1); + t[23] = ((MUL15(a[ 4], a[19]) + + MUL15(a[ 5], a[18]) + + MUL15(a[ 6], a[17]) + + MUL15(a[ 7], a[16]) + + MUL15(a[ 8], a[15]) + + MUL15(a[ 9], a[14]) + + MUL15(a[10], a[13]) + + MUL15(a[11], a[12])) << 1); + t[24] = MUL15(a[12], a[12]) + + ((MUL15(a[ 5], a[19]) + + MUL15(a[ 6], a[18]) + + MUL15(a[ 7], a[17]) + + MUL15(a[ 8], a[16]) + + MUL15(a[ 9], a[15]) + + MUL15(a[10], a[14]) + + MUL15(a[11], a[13])) << 1); + t[25] = ((MUL15(a[ 6], a[19]) + + MUL15(a[ 7], a[18]) + + MUL15(a[ 8], a[17]) + + MUL15(a[ 9], a[16]) + + MUL15(a[10], a[15]) + + MUL15(a[11], a[14]) + + MUL15(a[12], a[13])) << 1); + t[26] = MUL15(a[13], a[13]) + + ((MUL15(a[ 7], a[19]) + + MUL15(a[ 8], a[18]) + + MUL15(a[ 9], a[17]) + + MUL15(a[10], a[16]) + + MUL15(a[11], a[15]) + + MUL15(a[12], a[14])) << 1); + t[27] = ((MUL15(a[ 8], a[19]) + + MUL15(a[ 9], a[18]) + + MUL15(a[10], a[17]) + + MUL15(a[11], a[16]) + + MUL15(a[12], a[15]) + + MUL15(a[13], a[14])) << 1); + t[28] = MUL15(a[14], a[14]) + + ((MUL15(a[ 9], a[19]) + + MUL15(a[10], a[18]) + + MUL15(a[11], a[17]) + + MUL15(a[12], a[16]) + + MUL15(a[13], a[15])) << 1); + t[29] = ((MUL15(a[10], a[19]) + + MUL15(a[11], a[18]) + + MUL15(a[12], a[17]) + + MUL15(a[13], a[16]) + + MUL15(a[14], a[15])) << 1); + t[30] = MUL15(a[15], a[15]) + + ((MUL15(a[11], a[19]) + + MUL15(a[12], a[18]) + + MUL15(a[13], a[17]) + + MUL15(a[14], a[16])) << 1); + t[31] = ((MUL15(a[12], a[19]) + + MUL15(a[13], a[18]) + + MUL15(a[14], a[17]) + + MUL15(a[15], a[16])) << 1); + t[32] = MUL15(a[16], a[16]) + + ((MUL15(a[13], a[19]) + + MUL15(a[14], a[18]) + + MUL15(a[15], a[17])) << 1); + t[33] = ((MUL15(a[14], a[19]) + + MUL15(a[15], a[18]) + + MUL15(a[16], a[17])) << 1); + t[34] = MUL15(a[17], a[17]) + + ((MUL15(a[15], a[19]) + + MUL15(a[16], a[18])) << 1); + t[35] = ((MUL15(a[16], a[19]) + + MUL15(a[17], a[18])) << 1); + t[36] = MUL15(a[18], a[18]) + + ((MUL15(a[17], a[19])) << 1); + t[37] = ((MUL15(a[18], a[19])) << 1); + t[38] = MUL15(a[19], a[19]); + d[39] = norm13(d, t, 39); +} + +#endif + +/* + * Modulus for field F256 (field for point coordinates in curve P-256). + */ +static const uint32_t F256[] = { + 0x1FFF, 0x1FFF, 0x1FFF, 0x1FFF, 0x1FFF, 0x1FFF, 0x1FFF, 0x001F, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0400, 0x0000, + 0x0000, 0x1FF8, 0x1FFF, 0x01FF +}; + +/* + * The 'b' curve equation coefficient for P-256. + */ +static const uint32_t P256_B[] = { + 0x004B, 0x1E93, 0x0F89, 0x1C78, 0x03BC, 0x187B, 0x114E, 0x1619, + 0x1D06, 0x0328, 0x01AF, 0x0D31, 0x1557, 0x15DE, 0x1ECF, 0x127C, + 0x0A3A, 0x0EC5, 0x118D, 0x00B5 +}; + +/* + * Perform a "short reduction" in field F256 (field for curve P-256). + * The source value should be less than 262 bits; on output, it will + * be at most 257 bits, and less than twice the modulus. + */ +static void +reduce_f256(uint32_t *d) +{ + uint32_t x; + + x = d[19] >> 9; + d[19] &= 0x01FF; + d[17] += x << 3; + d[14] -= x << 10; + d[7] -= x << 5; + d[0] += x; + norm13(d, d, 20); +} + +/* + * Perform a "final reduction" in field F256 (field for curve P-256). + * The source value must be less than twice the modulus. If the value + * is not lower than the modulus, then the modulus is subtracted and + * this function returns 1; otherwise, it leaves it untouched and it + * returns 0. + */ +static uint32_t +reduce_final_f256(uint32_t *d) +{ + uint32_t t[20]; + uint32_t cc; + int i; + + memcpy(t, d, sizeof t); + cc = 0; + for (i = 0; i < 20; i ++) { + uint32_t w; + + w = t[i] - F256[i] - cc; + cc = w >> 31; + t[i] = w & 0x1FFF; + } + cc ^= 1; + CCOPY(cc, d, t, sizeof t); + return cc; +} + +/* + * Perform a multiplication of two integers modulo + * 2^256-2^224+2^192+2^96-1 (for NIST curve P-256). Operands are arrays + * of 20 words, each containing 13 bits of data, in little-endian order. + * On input, upper word may be up to 13 bits (hence value up to 2^260-1); + * on output, value fits on 257 bits and is lower than twice the modulus. + */ +static void +mul_f256(uint32_t *d, const uint32_t *a, const uint32_t *b) +{ + uint32_t t[40], cc; + int i; + + /* + * Compute raw multiplication. All result words fit in 13 bits + * each. + */ + mul20(t, a, b); + + /* + * Modular reduction: each high word in added/subtracted where + * necessary. + * + * The modulus is: + * p = 2^256 - 2^224 + 2^192 + 2^96 - 1 + * Therefore: + * 2^256 = 2^224 - 2^192 - 2^96 + 1 mod p + * + * For a word x at bit offset n (n >= 256), we have: + * x*2^n = x*2^(n-32) - x*2^(n-64) + * - x*2^(n - 160) + x*2^(n-256) mod p + * + * Thus, we can nullify the high word if we reinject it at some + * proper emplacements. + */ + for (i = 39; i >= 20; i --) { + uint32_t x; + + x = t[i]; + t[i - 2] += ARSH(x, 6); + t[i - 3] += (x << 7) & 0x1FFF; + t[i - 4] -= ARSH(x, 12); + t[i - 5] -= (x << 1) & 0x1FFF; + t[i - 12] -= ARSH(x, 4); + t[i - 13] -= (x << 9) & 0x1FFF; + t[i - 19] += ARSH(x, 9); + t[i - 20] += (x << 4) & 0x1FFF; + } + + /* + * Propagate carries. This is a signed propagation, and the + * result may be negative. The loop above may enlarge values, + * but not two much: worst case is the chain involving t[i - 3], + * in which a value may be added to itself up to 7 times. Since + * starting values are 13-bit each, all words fit on 20 bits + * (21 to account for the sign bit). + */ + cc = norm13(t, t, 20); + + /* + * Perform modular reduction again for the bits beyond 256 (the carry + * and the bits 256..259). Since the largest shift below is by 10 + * bits, and the values fit on 21 bits, values fit in 32-bit words, + * thereby allowing injecting full word values. + */ + cc = (cc << 4) | (t[19] >> 9); + t[19] &= 0x01FF; + t[17] += cc << 3; + t[14] -= cc << 10; + t[7] -= cc << 5; + t[0] += cc; + + /* + * If the carry is negative, then after carry propagation, we may + * end up with a value which is negative, and we don't want that. + * Thus, in that case, we add the modulus. Note that the subtraction + * result, when the carry is negative, is always smaller than the + * modulus, so the extra addition will not make the value exceed + * twice the modulus. + */ + cc >>= 31; + t[0] -= cc; + t[7] += cc << 5; + t[14] += cc << 10; + t[17] -= cc << 3; + t[19] += cc << 9; + + norm13(d, t, 20); +} + +/* + * Square an integer modulo 2^256-2^224+2^192+2^96-1 (for NIST curve + * P-256). Operand is an array of 20 words, each containing 13 bits of + * data, in little-endian order. On input, upper word may be up to 13 + * bits (hence value up to 2^260-1); on output, value fits on 257 bits + * and is lower than twice the modulus. + */ +static void +square_f256(uint32_t *d, const uint32_t *a) +{ + uint32_t t[40], cc; + int i; + + /* + * Compute raw square. All result words fit in 13 bits each. + */ + square20(t, a); + + /* + * Modular reduction: each high word in added/subtracted where + * necessary. + * + * The modulus is: + * p = 2^256 - 2^224 + 2^192 + 2^96 - 1 + * Therefore: + * 2^256 = 2^224 - 2^192 - 2^96 + 1 mod p + * + * For a word x at bit offset n (n >= 256), we have: + * x*2^n = x*2^(n-32) - x*2^(n-64) + * - x*2^(n - 160) + x*2^(n-256) mod p + * + * Thus, we can nullify the high word if we reinject it at some + * proper emplacements. + */ + for (i = 39; i >= 20; i --) { + uint32_t x; + + x = t[i]; + t[i - 2] += ARSH(x, 6); + t[i - 3] += (x << 7) & 0x1FFF; + t[i - 4] -= ARSH(x, 12); + t[i - 5] -= (x << 1) & 0x1FFF; + t[i - 12] -= ARSH(x, 4); + t[i - 13] -= (x << 9) & 0x1FFF; + t[i - 19] += ARSH(x, 9); + t[i - 20] += (x << 4) & 0x1FFF; + } + + /* + * Propagate carries. This is a signed propagation, and the + * result may be negative. The loop above may enlarge values, + * but not two much: worst case is the chain involving t[i - 3], + * in which a value may be added to itself up to 7 times. Since + * starting values are 13-bit each, all words fit on 20 bits + * (21 to account for the sign bit). + */ + cc = norm13(t, t, 20); + + /* + * Perform modular reduction again for the bits beyond 256 (the carry + * and the bits 256..259). Since the largest shift below is by 10 + * bits, and the values fit on 21 bits, values fit in 32-bit words, + * thereby allowing injecting full word values. + */ + cc = (cc << 4) | (t[19] >> 9); + t[19] &= 0x01FF; + t[17] += cc << 3; + t[14] -= cc << 10; + t[7] -= cc << 5; + t[0] += cc; + + /* + * If the carry is negative, then after carry propagation, we may + * end up with a value which is negative, and we don't want that. + * Thus, in that case, we add the modulus. Note that the subtraction + * result, when the carry is negative, is always smaller than the + * modulus, so the extra addition will not make the value exceed + * twice the modulus. + */ + cc >>= 31; + t[0] -= cc; + t[7] += cc << 5; + t[14] += cc << 10; + t[17] -= cc << 3; + t[19] += cc << 9; + + norm13(d, t, 20); +} + +/* + * Jacobian coordinates for a point in P-256: affine coordinates (X,Y) + * are such that: + * X = x / z^2 + * Y = y / z^3 + * For the point at infinity, z = 0. + * Each point thus admits many possible representations. + * + * Coordinates are represented in arrays of 32-bit integers, each holding + * 13 bits of data. Values may also be slightly greater than the modulus, + * but they will always be lower than twice the modulus. + */ +typedef struct { + uint32_t x[20]; + uint32_t y[20]; + uint32_t z[20]; +} p256_jacobian; + +/* + * Convert a point to affine coordinates: + * - If the point is the point at infinity, then all three coordinates + * are set to 0. + * - Otherwise, the 'z' coordinate is set to 1, and the 'x' and 'y' + * coordinates are the 'X' and 'Y' affine coordinates. + * The coordinates are guaranteed to be lower than the modulus. + */ +static void +p256_to_affine(p256_jacobian *P) +{ + uint32_t t1[20], t2[20]; + int i; + + /* + * Invert z with a modular exponentiation: the modulus is + * p = 2^256 - 2^224 + 2^192 + 2^96 - 1, and the exponent is + * p-2. Exponent bit pattern (from high to low) is: + * - 32 bits of value 1 + * - 31 bits of value 0 + * - 1 bit of value 1 + * - 96 bits of value 0 + * - 94 bits of value 1 + * - 1 bit of value 0 + * - 1 bit of value 1 + * Thus, we precompute z^(2^31-1) to speed things up. + * + * If z = 0 (point at infinity) then the modular exponentiation + * will yield 0, which leads to the expected result (all three + * coordinates set to 0). + */ + + /* + * A simple square-and-multiply for z^(2^31-1). We could save about + * two dozen multiplications here with an addition chain, but + * this would require a bit more code, and extra stack buffers. + */ + memcpy(t1, P->z, sizeof P->z); + for (i = 0; i < 30; i ++) { + square_f256(t1, t1); + mul_f256(t1, t1, P->z); + } + + /* + * Square-and-multiply. Apart from the squarings, we have a few + * multiplications to set bits to 1; we multiply by the original z + * for setting 1 bit, and by t1 for setting 31 bits. + */ + memcpy(t2, P->z, sizeof P->z); + for (i = 1; i < 256; i ++) { + square_f256(t2, t2); + switch (i) { + case 31: + case 190: + case 221: + case 252: + mul_f256(t2, t2, t1); + break; + case 63: + case 253: + case 255: + mul_f256(t2, t2, P->z); + break; + } + } + + /* + * Now that we have 1/z, multiply x by 1/z^2 and y by 1/z^3. + */ + mul_f256(t1, t2, t2); + mul_f256(P->x, t1, P->x); + mul_f256(t1, t1, t2); + mul_f256(P->y, t1, P->y); + reduce_final_f256(P->x); + reduce_final_f256(P->y); + + /* + * Multiply z by 1/z. If z = 0, then this will yield 0, otherwise + * this will set z to 1. + */ + mul_f256(P->z, P->z, t2); + reduce_final_f256(P->z); +} + +/* + * Double a point in P-256. This function works for all valid points, + * including the point at infinity. + */ +static void +p256_double(p256_jacobian *Q) +{ + /* + * Doubling formulas are: + * + * s = 4*x*y^2 + * m = 3*(x + z^2)*(x - z^2) + * x' = m^2 - 2*s + * y' = m*(s - x') - 8*y^4 + * z' = 2*y*z + * + * These formulas work for all points, including points of order 2 + * and points at infinity: + * - If y = 0 then z' = 0. But there is no such point in P-256 + * anyway. + * - If z = 0 then z' = 0. + */ + uint32_t t1[20], t2[20], t3[20], t4[20]; + int i; + + /* + * Compute z^2 in t1. + */ + square_f256(t1, Q->z); + + /* + * Compute x-z^2 in t2 and x+z^2 in t1. + */ + for (i = 0; i < 20; i ++) { + t2[i] = (F256[i] << 1) + Q->x[i] - t1[i]; + t1[i] += Q->x[i]; + } + norm13(t1, t1, 20); + norm13(t2, t2, 20); + + /* + * Compute 3*(x+z^2)*(x-z^2) in t1. + */ + mul_f256(t3, t1, t2); + for (i = 0; i < 20; i ++) { + t1[i] = MUL15(3, t3[i]); + } + norm13(t1, t1, 20); + + /* + * Compute 4*x*y^2 (in t2) and 2*y^2 (in t3). + */ + square_f256(t3, Q->y); + for (i = 0; i < 20; i ++) { + t3[i] <<= 1; + } + norm13(t3, t3, 20); + mul_f256(t2, Q->x, t3); + for (i = 0; i < 20; i ++) { + t2[i] <<= 1; + } + norm13(t2, t2, 20); + reduce_f256(t2); + + /* + * Compute x' = m^2 - 2*s. + */ + square_f256(Q->x, t1); + for (i = 0; i < 20; i ++) { + Q->x[i] += (F256[i] << 2) - (t2[i] << 1); + } + norm13(Q->x, Q->x, 20); + reduce_f256(Q->x); + + /* + * Compute z' = 2*y*z. + */ + mul_f256(t4, Q->y, Q->z); + for (i = 0; i < 20; i ++) { + Q->z[i] = t4[i] << 1; + } + norm13(Q->z, Q->z, 20); + reduce_f256(Q->z); + + /* + * Compute y' = m*(s - x') - 8*y^4. Note that we already have + * 2*y^2 in t3. + */ + for (i = 0; i < 20; i ++) { + t2[i] += (F256[i] << 1) - Q->x[i]; + } + norm13(t2, t2, 20); + mul_f256(Q->y, t1, t2); + square_f256(t4, t3); + for (i = 0; i < 20; i ++) { + Q->y[i] += (F256[i] << 2) - (t4[i] << 1); + } + norm13(Q->y, Q->y, 20); + reduce_f256(Q->y); +} + +/* + * Add point P2 to point P1. + * + * This function computes the wrong result in the following cases: + * + * - If P1 == 0 but P2 != 0 + * - If P1 != 0 but P2 == 0 + * - If P1 == P2 + * + * In all three cases, P1 is set to the point at infinity. + * + * Returned value is 0 if one of the following occurs: + * + * - P1 and P2 have the same Y coordinate + * - P1 == 0 and P2 == 0 + * - The Y coordinate of one of the points is 0 and the other point is + * the point at infinity. + * + * The third case cannot actually happen with valid points, since a point + * with Y == 0 is a point of order 2, and there is no point of order 2 on + * curve P-256. + * + * Therefore, assuming that P1 != 0 and P2 != 0 on input, then the caller + * can apply the following: + * + * - If the result is not the point at infinity, then it is correct. + * - Otherwise, if the returned value is 1, then this is a case of + * P1+P2 == 0, so the result is indeed the point at infinity. + * - Otherwise, P1 == P2, so a "double" operation should have been + * performed. + */ +static uint32_t +p256_add(p256_jacobian *P1, const p256_jacobian *P2) +{ + /* + * Addtions formulas are: + * + * u1 = x1 * z2^2 + * u2 = x2 * z1^2 + * s1 = y1 * z2^3 + * s2 = y2 * z1^3 + * h = u2 - u1 + * r = s2 - s1 + * x3 = r^2 - h^3 - 2 * u1 * h^2 + * y3 = r * (u1 * h^2 - x3) - s1 * h^3 + * z3 = h * z1 * z2 + */ + uint32_t t1[20], t2[20], t3[20], t4[20], t5[20], t6[20], t7[20]; + uint32_t ret; + int i; + + /* + * Compute u1 = x1*z2^2 (in t1) and s1 = y1*z2^3 (in t3). + */ + square_f256(t3, P2->z); + mul_f256(t1, P1->x, t3); + mul_f256(t4, P2->z, t3); + mul_f256(t3, P1->y, t4); + + /* + * Compute u2 = x2*z1^2 (in t2) and s2 = y2*z1^3 (in t4). + */ + square_f256(t4, P1->z); + mul_f256(t2, P2->x, t4); + mul_f256(t5, P1->z, t4); + mul_f256(t4, P2->y, t5); + + /* + * Compute h = h2 - u1 (in t2) and r = s2 - s1 (in t4). + * We need to test whether r is zero, so we will do some extra + * reduce. + */ + for (i = 0; i < 20; i ++) { + t2[i] += (F256[i] << 1) - t1[i]; + t4[i] += (F256[i] << 1) - t3[i]; + } + norm13(t2, t2, 20); + norm13(t4, t4, 20); + reduce_f256(t4); + reduce_final_f256(t4); + ret = 0; + for (i = 0; i < 20; i ++) { + ret |= t4[i]; + } + ret = (ret | -ret) >> 31; + + /* + * Compute u1*h^2 (in t6) and h^3 (in t5); + */ + square_f256(t7, t2); + mul_f256(t6, t1, t7); + mul_f256(t5, t7, t2); + + /* + * Compute x3 = r^2 - h^3 - 2*u1*h^2. + */ + square_f256(P1->x, t4); + for (i = 0; i < 20; i ++) { + P1->x[i] += (F256[i] << 3) - t5[i] - (t6[i] << 1); + } + norm13(P1->x, P1->x, 20); + reduce_f256(P1->x); + + /* + * Compute y3 = r*(u1*h^2 - x3) - s1*h^3. + */ + for (i = 0; i < 20; i ++) { + t6[i] += (F256[i] << 1) - P1->x[i]; + } + norm13(t6, t6, 20); + mul_f256(P1->y, t4, t6); + mul_f256(t1, t5, t3); + for (i = 0; i < 20; i ++) { + P1->y[i] += (F256[i] << 1) - t1[i]; + } + norm13(P1->y, P1->y, 20); + reduce_f256(P1->y); + + /* + * Compute z3 = h*z1*z2. + */ + mul_f256(t1, P1->z, P2->z); + mul_f256(P1->z, t1, t2); + + return ret; +} + +/* + * Add point P2 to point P1. This is a specialised function for the + * case when P2 is a non-zero point in affine coordinate. + * + * This function computes the wrong result in the following cases: + * + * - If P1 == 0 + * - If P1 == P2 + * + * In both cases, P1 is set to the point at infinity. + * + * Returned value is 0 if one of the following occurs: + * + * - P1 and P2 have the same Y coordinate + * - The Y coordinate of P2 is 0 and P1 is the point at infinity. + * + * The second case cannot actually happen with valid points, since a point + * with Y == 0 is a point of order 2, and there is no point of order 2 on + * curve P-256. + * + * Therefore, assuming that P1 != 0 on input, then the caller + * can apply the following: + * + * - If the result is not the point at infinity, then it is correct. + * - Otherwise, if the returned value is 1, then this is a case of + * P1+P2 == 0, so the result is indeed the point at infinity. + * - Otherwise, P1 == P2, so a "double" operation should have been + * performed. + */ +static uint32_t +p256_add_mixed(p256_jacobian *P1, const p256_jacobian *P2) +{ + /* + * Addtions formulas are: + * + * u1 = x1 + * u2 = x2 * z1^2 + * s1 = y1 + * s2 = y2 * z1^3 + * h = u2 - u1 + * r = s2 - s1 + * x3 = r^2 - h^3 - 2 * u1 * h^2 + * y3 = r * (u1 * h^2 - x3) - s1 * h^3 + * z3 = h * z1 + */ + uint32_t t1[20], t2[20], t3[20], t4[20], t5[20], t6[20], t7[20]; + uint32_t ret; + int i; + + /* + * Compute u1 = x1 (in t1) and s1 = y1 (in t3). + */ + memcpy(t1, P1->x, sizeof t1); + memcpy(t3, P1->y, sizeof t3); + + /* + * Compute u2 = x2*z1^2 (in t2) and s2 = y2*z1^3 (in t4). + */ + square_f256(t4, P1->z); + mul_f256(t2, P2->x, t4); + mul_f256(t5, P1->z, t4); + mul_f256(t4, P2->y, t5); + + /* + * Compute h = h2 - u1 (in t2) and r = s2 - s1 (in t4). + * We need to test whether r is zero, so we will do some extra + * reduce. + */ + for (i = 0; i < 20; i ++) { + t2[i] += (F256[i] << 1) - t1[i]; + t4[i] += (F256[i] << 1) - t3[i]; + } + norm13(t2, t2, 20); + norm13(t4, t4, 20); + reduce_f256(t4); + reduce_final_f256(t4); + ret = 0; + for (i = 0; i < 20; i ++) { + ret |= t4[i]; + } + ret = (ret | -ret) >> 31; + + /* + * Compute u1*h^2 (in t6) and h^3 (in t5); + */ + square_f256(t7, t2); + mul_f256(t6, t1, t7); + mul_f256(t5, t7, t2); + + /* + * Compute x3 = r^2 - h^3 - 2*u1*h^2. + */ + square_f256(P1->x, t4); + for (i = 0; i < 20; i ++) { + P1->x[i] += (F256[i] << 3) - t5[i] - (t6[i] << 1); + } + norm13(P1->x, P1->x, 20); + reduce_f256(P1->x); + + /* + * Compute y3 = r*(u1*h^2 - x3) - s1*h^3. + */ + for (i = 0; i < 20; i ++) { + t6[i] += (F256[i] << 1) - P1->x[i]; + } + norm13(t6, t6, 20); + mul_f256(P1->y, t4, t6); + mul_f256(t1, t5, t3); + for (i = 0; i < 20; i ++) { + P1->y[i] += (F256[i] << 1) - t1[i]; + } + norm13(P1->y, P1->y, 20); + reduce_f256(P1->y); + + /* + * Compute z3 = h*z1*z2. + */ + mul_f256(P1->z, P1->z, t2); + + return ret; +} + +/* + * Decode a P-256 point. This function does not support the point at + * infinity. Returned value is 0 if the point is invalid, 1 otherwise. + */ +static uint32_t +p256_decode(p256_jacobian *P, const void *src, size_t len) +{ + const unsigned char *buf; + uint32_t tx[20], ty[20], t1[20], t2[20]; + uint32_t bad; + int i; + + if (len != 65) { + return 0; + } + buf = src; + + /* + * First byte must be 0x04 (uncompressed format). We could support + * "hybrid format" (first byte is 0x06 or 0x07, and encodes the + * least significant bit of the Y coordinate), but it is explicitly + * forbidden by RFC 5480 (section 2.2). + */ + bad = NEQ(buf[0], 0x04); + + /* + * Decode the coordinates, and check that they are both lower + * than the modulus. + */ + tx[19] = be8_to_le13(tx, buf + 1, 32); + ty[19] = be8_to_le13(ty, buf + 33, 32); + bad |= reduce_final_f256(tx); + bad |= reduce_final_f256(ty); + + /* + * Check curve equation. + */ + square_f256(t1, tx); + mul_f256(t1, tx, t1); + square_f256(t2, ty); + for (i = 0; i < 20; i ++) { + t1[i] += (F256[i] << 3) - MUL15(3, tx[i]) + P256_B[i] - t2[i]; + } + norm13(t1, t1, 20); + reduce_f256(t1); + reduce_final_f256(t1); + for (i = 0; i < 20; i ++) { + bad |= t1[i]; + } + + /* + * Copy coordinates to the point structure. + */ + memcpy(P->x, tx, sizeof tx); + memcpy(P->y, ty, sizeof ty); + memset(P->z, 0, sizeof P->z); + P->z[0] = 1; + return EQ(bad, 0); +} + +/* + * Encode a point into a buffer. This function assumes that the point is + * valid, in affine coordinates, and not the point at infinity. + */ +static void +p256_encode(void *dst, const p256_jacobian *P) +{ + unsigned char *buf; + + buf = dst; + buf[0] = 0x04; + le13_to_be8(buf + 1, 32, P->x); + le13_to_be8(buf + 33, 32, P->y); +} + +/* + * Multiply a curve point by an integer. The integer is assumed to be + * lower than the curve order, and the base point must not be the point + * at infinity. + */ +static void +p256_mul(p256_jacobian *P, const unsigned char *x, size_t xlen) +{ + /* + * qz is a flag that is initially 1, and remains equal to 1 + * as long as the point is the point at infinity. + * + * We use a 2-bit window to handle multiplier bits by pairs. + * The precomputed window really is the points P2 and P3. + */ + uint32_t qz; + p256_jacobian P2, P3, Q, T, U; + + /* + * Compute window values. + */ + P2 = *P; + p256_double(&P2); + P3 = *P; + p256_add(&P3, &P2); + + /* + * We start with Q = 0. We process multiplier bits 2 by 2. + */ + memset(&Q, 0, sizeof Q); + qz = 1; + while (xlen -- > 0) { + int k; + + for (k = 6; k >= 0; k -= 2) { + uint32_t bits; + uint32_t bnz; + + p256_double(&Q); + p256_double(&Q); + T = *P; + U = Q; + bits = (*x >> k) & (uint32_t)3; + bnz = NEQ(bits, 0); + CCOPY(EQ(bits, 2), &T, &P2, sizeof T); + CCOPY(EQ(bits, 3), &T, &P3, sizeof T); + p256_add(&U, &T); + CCOPY(bnz & qz, &Q, &T, sizeof Q); + CCOPY(bnz & ~qz, &Q, &U, sizeof Q); + qz &= ~bnz; + } + x ++; + } + *P = Q; +} + +/* + * Precomputed window: k*G points, where G is the curve generator, and k + * is an integer from 1 to 15 (inclusive). The X and Y coordinates of + * the point are encoded as 20 words of 13 bits each (little-endian + * order); 13-bit words are then grouped 2-by-2 into 32-bit words + * (little-endian order within each word). + */ +static const uint32_t Gwin[15][20] = { + + { 0x04C60296, 0x02721176, 0x19D00F4A, 0x102517AC, + 0x13B8037D, 0x0748103C, 0x1E730E56, 0x08481FE2, + 0x0F97012C, 0x00D605F4, 0x1DFA11F5, 0x0C801A0D, + 0x0F670CBB, 0x0AED0CC5, 0x115E0E33, 0x181F0785, + 0x13F514A7, 0x0FF30E3B, 0x17171E1A, 0x009F18D0 }, + + { 0x1B341978, 0x16911F11, 0x0D9A1A60, 0x1C4E1FC8, + 0x1E040969, 0x096A06B0, 0x091C0030, 0x09EF1A29, + 0x18C40D03, 0x00F91C9E, 0x13C313D1, 0x096F0748, + 0x011419E0, 0x1CC713A6, 0x1DD31DAD, 0x1EE80C36, + 0x1ECD0C69, 0x1A0800A4, 0x08861B8E, 0x000E1DD5 }, + + { 0x173F1D6C, 0x02CC06F1, 0x14C21FB4, 0x043D1EB6, + 0x0F3606B7, 0x1A971C59, 0x1BF71951, 0x01481323, + 0x068D0633, 0x00BD12F9, 0x13EA1032, 0x136209E8, + 0x1C1E19A7, 0x06C7013E, 0x06C10AB0, 0x14C908BB, + 0x05830CE1, 0x1FEF18DD, 0x00620998, 0x010E0D19 }, + + { 0x18180852, 0x0604111A, 0x0B771509, 0x1B6F0156, + 0x00181FE2, 0x1DCC0AF4, 0x16EF0659, 0x11F70E80, + 0x11A912D0, 0x01C414D2, 0x027618C6, 0x05840FC6, + 0x100215C4, 0x187E0C3B, 0x12771C96, 0x150C0B5D, + 0x0FF705FD, 0x07981C67, 0x1AD20C63, 0x01C11C55 }, + + { 0x1E8113ED, 0x0A940370, 0x12920215, 0x1FA31D6F, + 0x1F7C0C82, 0x10CD03F7, 0x02640560, 0x081A0B5E, + 0x1BD21151, 0x00A21642, 0x0D0B0DA4, 0x0176113F, + 0x04440D1D, 0x001A1360, 0x1068012F, 0x1F141E49, + 0x10DF136B, 0x0E4F162B, 0x0D44104A, 0x01C1105F }, + + { 0x011411A9, 0x01551A4F, 0x0ADA0C6B, 0x01BD0EC8, + 0x18120C74, 0x112F1778, 0x099202CB, 0x0C05124B, + 0x195316A4, 0x01600685, 0x1E3B1FE2, 0x189014E3, + 0x0B5E1FD7, 0x0E0311F8, 0x08E000F7, 0x174E00DE, + 0x160702DF, 0x1B5A15BF, 0x03A11237, 0x01D01704 }, + + { 0x0C3D12A3, 0x0C501C0C, 0x17AD1300, 0x1715003F, + 0x03F719F8, 0x18031ED8, 0x1D980667, 0x0F681896, + 0x1B7D00BF, 0x011C14CE, 0x0FA000B4, 0x1C3501B0, + 0x0D901C55, 0x06790C10, 0x029E0736, 0x0DEB0400, + 0x034F183A, 0x030619B4, 0x0DEF0033, 0x00E71AC7 }, + + { 0x1B7D1393, 0x1B3B1076, 0x0BED1B4D, 0x13011F3A, + 0x0E0E1238, 0x156A132B, 0x013A02D3, 0x160A0D01, + 0x1CED1EE9, 0x00C5165D, 0x184C157E, 0x08141A83, + 0x153C0DA5, 0x1ED70F9D, 0x05170D51, 0x02CF13B8, + 0x18AE1771, 0x1B04113F, 0x05EC11E9, 0x015A16B3 }, + + { 0x04A41EE0, 0x1D1412E4, 0x1C591D79, 0x118511B7, + 0x14F00ACB, 0x1AE31E1C, 0x049C0D51, 0x016E061E, + 0x1DB71EDF, 0x01D41A35, 0x0E8208FA, 0x14441293, + 0x011F1E85, 0x1D54137A, 0x026B114F, 0x151D0832, + 0x00A50964, 0x1F9C1E1C, 0x064B12C9, 0x005409D1 }, + + { 0x062B123F, 0x0C0D0501, 0x183704C3, 0x08E31120, + 0x0A2E0A6C, 0x14440FED, 0x090A0D1E, 0x13271964, + 0x0B590A3A, 0x019D1D9B, 0x05780773, 0x09770A91, + 0x0F770CA3, 0x053F19D4, 0x02C80DED, 0x1A761304, + 0x091E0DD9, 0x15D201B8, 0x151109AA, 0x010F0198 }, + + { 0x05E101D1, 0x072314DD, 0x045F1433, 0x1A041541, + 0x10B3142E, 0x01840736, 0x1C1B19DB, 0x098B0418, + 0x1DBC083B, 0x007D1444, 0x01511740, 0x11DD1F3A, + 0x04ED0E2F, 0x1B4B1A62, 0x10480D04, 0x09E911A2, + 0x04211AFA, 0x19140893, 0x04D60CC4, 0x01210648 }, + + { 0x112703C4, 0x018B1BA1, 0x164C1D50, 0x05160BE0, + 0x0BCC1830, 0x01CB1554, 0x13291732, 0x1B2B1918, + 0x0DED0817, 0x00E80775, 0x0A2401D3, 0x0BFE08B3, + 0x0E531199, 0x058616E9, 0x04770B91, 0x110F0C55, + 0x19C11554, 0x0BFB1159, 0x03541C38, 0x000E1C2D }, + + { 0x10390C01, 0x02BB0751, 0x0AC5098E, 0x096C17AB, + 0x03C90E28, 0x10BD18BF, 0x002E1F2D, 0x092B0986, + 0x1BD700AC, 0x002E1F20, 0x1E3D1FD8, 0x077718BB, + 0x06F919C4, 0x187407ED, 0x11370E14, 0x081E139C, + 0x00481ADB, 0x14AB0289, 0x066A0EBE, 0x00C70ED6 }, + + { 0x0694120B, 0x124E1CC9, 0x0E2F0570, 0x17CF081A, + 0x078906AC, 0x066D17CF, 0x1B3207F4, 0x0C5705E9, + 0x10001C38, 0x00A919DE, 0x06851375, 0x0F900BD8, + 0x080401BA, 0x0EEE0D42, 0x1B8B11EA, 0x0B4519F0, + 0x090F18C0, 0x062E1508, 0x0DD909F4, 0x01EB067C }, + + { 0x0CDC1D5F, 0x0D1818F9, 0x07781636, 0x125B18E8, + 0x0D7003AF, 0x13110099, 0x1D9B1899, 0x175C1EB7, + 0x0E34171A, 0x01E01153, 0x081A0F36, 0x0B391783, + 0x1D1F147E, 0x19CE16D7, 0x11511B21, 0x1F2C10F9, + 0x12CA0E51, 0x05A31D39, 0x171A192E, 0x016B0E4F } +}; + +/* + * Lookup one of the Gwin[] values, by index. This is constant-time. + */ +static void +lookup_Gwin(p256_jacobian *T, uint32_t idx) +{ + uint32_t xy[20]; + uint32_t k; + size_t u; + + memset(xy, 0, sizeof xy); + for (k = 0; k < 15; k ++) { + uint32_t m; + + m = -EQ(idx, k + 1); + for (u = 0; u < 20; u ++) { + xy[u] |= m & Gwin[k][u]; + } + } + for (u = 0; u < 10; u ++) { + T->x[(u << 1) + 0] = xy[u] & 0xFFFF; + T->x[(u << 1) + 1] = xy[u] >> 16; + T->y[(u << 1) + 0] = xy[u + 10] & 0xFFFF; + T->y[(u << 1) + 1] = xy[u + 10] >> 16; + } + memset(T->z, 0, sizeof T->z); + T->z[0] = 1; +} + +/* + * Multiply the generator by an integer. The integer is assumed non-zero + * and lower than the curve order. + */ +static void +p256_mulgen(p256_jacobian *P, const unsigned char *x, size_t xlen) +{ + /* + * qz is a flag that is initially 1, and remains equal to 1 + * as long as the point is the point at infinity. + * + * We use a 4-bit window to handle multiplier bits by groups + * of 4. The precomputed window is constant static data, with + * points in affine coordinates; we use a constant-time lookup. + */ + p256_jacobian Q; + uint32_t qz; + + memset(&Q, 0, sizeof Q); + qz = 1; + while (xlen -- > 0) { + int k; + unsigned bx; + + bx = *x ++; + for (k = 0; k < 2; k ++) { + uint32_t bits; + uint32_t bnz; + p256_jacobian T, U; + + p256_double(&Q); + p256_double(&Q); + p256_double(&Q); + p256_double(&Q); + bits = (bx >> 4) & 0x0F; + bnz = NEQ(bits, 0); + lookup_Gwin(&T, bits); + U = Q; + p256_add_mixed(&U, &T); + CCOPY(bnz & qz, &Q, &T, sizeof Q); + CCOPY(bnz & ~qz, &Q, &U, sizeof Q); + qz &= ~bnz; + bx <<= 4; + } + } + *P = Q; +} + +static const unsigned char P256_G[] = { + 0x04, 0x6B, 0x17, 0xD1, 0xF2, 0xE1, 0x2C, 0x42, 0x47, 0xF8, + 0xBC, 0xE6, 0xE5, 0x63, 0xA4, 0x40, 0xF2, 0x77, 0x03, 0x7D, + 0x81, 0x2D, 0xEB, 0x33, 0xA0, 0xF4, 0xA1, 0x39, 0x45, 0xD8, + 0x98, 0xC2, 0x96, 0x4F, 0xE3, 0x42, 0xE2, 0xFE, 0x1A, 0x7F, + 0x9B, 0x8E, 0xE7, 0xEB, 0x4A, 0x7C, 0x0F, 0x9E, 0x16, 0x2B, + 0xCE, 0x33, 0x57, 0x6B, 0x31, 0x5E, 0xCE, 0xCB, 0xB6, 0x40, + 0x68, 0x37, 0xBF, 0x51, 0xF5 +}; + +static const unsigned char P256_N[] = { + 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xBC, 0xE6, 0xFA, 0xAD, + 0xA7, 0x17, 0x9E, 0x84, 0xF3, 0xB9, 0xCA, 0xC2, 0xFC, 0x63, + 0x25, 0x51 +}; + +static const unsigned char * +api_generator(int curve, size_t *len) +{ + (void)curve; + *len = sizeof P256_G; + return P256_G; +} + +static const unsigned char * +api_order(int curve, size_t *len) +{ + (void)curve; + *len = sizeof P256_N; + return P256_N; +} + +static size_t +api_xoff(int curve, size_t *len) +{ + (void)curve; + *len = 32; + return 1; +} + +static uint32_t +api_mul(unsigned char *G, size_t Glen, + const unsigned char *x, size_t xlen, int curve) +{ + uint32_t r; + p256_jacobian P; + + (void)curve; + r = p256_decode(&P, G, Glen); + p256_mul(&P, x, xlen); + if (Glen >= 65) { + p256_to_affine(&P); + p256_encode(G, &P); + } + return r; +} + +static size_t +api_mulgen(unsigned char *R, + const unsigned char *x, size_t xlen, int curve) +{ + p256_jacobian P; + + (void)curve; + p256_mulgen(&P, x, xlen); + p256_to_affine(&P); + p256_encode(R, &P); + return 65; + + /* + const unsigned char *G; + size_t Glen; + + G = api_generator(curve, &Glen); + memcpy(R, G, Glen); + api_mul(R, Glen, x, xlen, curve); + return Glen; + */ +} + +static uint32_t +api_muladd(unsigned char *A, const unsigned char *B, size_t len, + const unsigned char *x, size_t xlen, + const unsigned char *y, size_t ylen, int curve) +{ + p256_jacobian P, Q; + uint32_t r, t, z; + int i; + + (void)curve; + r = p256_decode(&P, A, len); + p256_mul(&P, x, xlen); + if (B == NULL) { + p256_mulgen(&Q, y, ylen); + } else { + r &= p256_decode(&Q, B, len); + p256_mul(&Q, y, ylen); + } + + /* + * The final addition may fail in case both points are equal. + */ + t = p256_add(&P, &Q); + reduce_final_f256(P.z); + z = 0; + for (i = 0; i < 20; i ++) { + z |= P.z[i]; + } + z = EQ(z, 0); + p256_double(&Q); + + /* + * If z is 1 then either P+Q = 0 (t = 1) or P = Q (t = 0). So we + * have the following: + * + * z = 0, t = 0 return P (normal addition) + * z = 0, t = 1 return P (normal addition) + * z = 1, t = 0 return Q (a 'double' case) + * z = 1, t = 1 report an error (P+Q = 0) + */ + CCOPY(z & ~t, &P, &Q, sizeof Q); + p256_to_affine(&P); + p256_encode(A, &P); + r &= ~(z & t); + return r; +} + +/* see bearssl_ec.h */ +const br_ec_impl br_ec_p256_m15 = { + (uint32_t)0x00800000, + &api_generator, + &api_order, + &api_xoff, + &api_mul, + &api_mulgen, + &api_muladd +}; + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_p256_m31.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_p256_m31.c new file mode 100644 index 000000000..9234164df --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_p256_m31.c @@ -0,0 +1,1480 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* + * If BR_NO_ARITH_SHIFT is undefined, or defined to 0, then we _assume_ + * that right-shifting a signed negative integer copies the sign bit + * (arithmetic right-shift). This is "implementation-defined behaviour", + * i.e. it is not undefined, but it may differ between compilers. Each + * compiler is supposed to document its behaviour in that respect. GCC + * explicitly defines that an arithmetic right shift is used. We expect + * all other compilers to do the same, because underlying CPU offer an + * arithmetic right shift opcode that could not be used otherwise. + */ +#if BR_NO_ARITH_SHIFT +#define ARSH(x, n) (((uint32_t)(x) >> (n)) \ + | ((-((uint32_t)(x) >> 31)) << (32 - (n)))) +#define ARSHW(x, n) (((uint64_t)(x) >> (n)) \ + | ((-((uint64_t)(x) >> 63)) << (64 - (n)))) +#else +#define ARSH(x, n) ((*(int32_t *)&(x)) >> (n)) +#define ARSHW(x, n) ((*(int64_t *)&(x)) >> (n)) +#endif + +/* + * Convert an integer from unsigned big-endian encoding to a sequence of + * 30-bit words in little-endian order. The final "partial" word is + * returned. + */ +static uint32_t +be8_to_le30(uint32_t *dst, const unsigned char *src, size_t len) +{ + uint32_t acc; + int acc_len; + + acc = 0; + acc_len = 0; + while (len -- > 0) { + uint32_t b; + + b = src[len]; + if (acc_len < 22) { + acc |= b << acc_len; + acc_len += 8; + } else { + *dst ++ = (acc | (b << acc_len)) & 0x3FFFFFFF; + acc = b >> (30 - acc_len); + acc_len -= 22; + } + } + return acc; +} + +/* + * Convert an integer (30-bit words, little-endian) to unsigned + * big-endian encoding. The total encoding length is provided; all + * the destination bytes will be filled. + */ +static void +le30_to_be8(unsigned char *dst, size_t len, const uint32_t *src) +{ + uint32_t acc; + int acc_len; + + acc = 0; + acc_len = 0; + while (len -- > 0) { + if (acc_len < 8) { + uint32_t w; + + w = *src ++; + dst[len] = (unsigned char)(acc | (w << acc_len)); + acc = w >> (8 - acc_len); + acc_len += 22; + } else { + dst[len] = (unsigned char)acc; + acc >>= 8; + acc_len -= 8; + } + } +} + +/* + * Multiply two integers. Source integers are represented as arrays of + * nine 30-bit words, for values up to 2^270-1. Result is encoded over + * 18 words of 30 bits each. + */ +static void +mul9(uint32_t *d, const uint32_t *a, const uint32_t *b) +{ + /* + * Maximum intermediate result is no more than + * 10376293531797946367, which fits in 64 bits. Reason: + * + * 10376293531797946367 = 9 * (2^30-1)^2 + 9663676406 + * 10376293531797946367 < 9663676407 * 2^30 + * + * Thus, adding together 9 products of 30-bit integers, with + * a carry of at most 9663676406, yields an integer that fits + * on 64 bits and generates a carry of at most 9663676406. + */ + uint64_t t[17]; + uint64_t cc; + int i; + + t[ 0] = MUL31(a[0], b[0]); + t[ 1] = MUL31(a[0], b[1]) + + MUL31(a[1], b[0]); + t[ 2] = MUL31(a[0], b[2]) + + MUL31(a[1], b[1]) + + MUL31(a[2], b[0]); + t[ 3] = MUL31(a[0], b[3]) + + MUL31(a[1], b[2]) + + MUL31(a[2], b[1]) + + MUL31(a[3], b[0]); + t[ 4] = MUL31(a[0], b[4]) + + MUL31(a[1], b[3]) + + MUL31(a[2], b[2]) + + MUL31(a[3], b[1]) + + MUL31(a[4], b[0]); + t[ 5] = MUL31(a[0], b[5]) + + MUL31(a[1], b[4]) + + MUL31(a[2], b[3]) + + MUL31(a[3], b[2]) + + MUL31(a[4], b[1]) + + MUL31(a[5], b[0]); + t[ 6] = MUL31(a[0], b[6]) + + MUL31(a[1], b[5]) + + MUL31(a[2], b[4]) + + MUL31(a[3], b[3]) + + MUL31(a[4], b[2]) + + MUL31(a[5], b[1]) + + MUL31(a[6], b[0]); + t[ 7] = MUL31(a[0], b[7]) + + MUL31(a[1], b[6]) + + MUL31(a[2], b[5]) + + MUL31(a[3], b[4]) + + MUL31(a[4], b[3]) + + MUL31(a[5], b[2]) + + MUL31(a[6], b[1]) + + MUL31(a[7], b[0]); + t[ 8] = MUL31(a[0], b[8]) + + MUL31(a[1], b[7]) + + MUL31(a[2], b[6]) + + MUL31(a[3], b[5]) + + MUL31(a[4], b[4]) + + MUL31(a[5], b[3]) + + MUL31(a[6], b[2]) + + MUL31(a[7], b[1]) + + MUL31(a[8], b[0]); + t[ 9] = MUL31(a[1], b[8]) + + MUL31(a[2], b[7]) + + MUL31(a[3], b[6]) + + MUL31(a[4], b[5]) + + MUL31(a[5], b[4]) + + MUL31(a[6], b[3]) + + MUL31(a[7], b[2]) + + MUL31(a[8], b[1]); + t[10] = MUL31(a[2], b[8]) + + MUL31(a[3], b[7]) + + MUL31(a[4], b[6]) + + MUL31(a[5], b[5]) + + MUL31(a[6], b[4]) + + MUL31(a[7], b[3]) + + MUL31(a[8], b[2]); + t[11] = MUL31(a[3], b[8]) + + MUL31(a[4], b[7]) + + MUL31(a[5], b[6]) + + MUL31(a[6], b[5]) + + MUL31(a[7], b[4]) + + MUL31(a[8], b[3]); + t[12] = MUL31(a[4], b[8]) + + MUL31(a[5], b[7]) + + MUL31(a[6], b[6]) + + MUL31(a[7], b[5]) + + MUL31(a[8], b[4]); + t[13] = MUL31(a[5], b[8]) + + MUL31(a[6], b[7]) + + MUL31(a[7], b[6]) + + MUL31(a[8], b[5]); + t[14] = MUL31(a[6], b[8]) + + MUL31(a[7], b[7]) + + MUL31(a[8], b[6]); + t[15] = MUL31(a[7], b[8]) + + MUL31(a[8], b[7]); + t[16] = MUL31(a[8], b[8]); + + /* + * Propagate carries. + */ + cc = 0; + for (i = 0; i < 17; i ++) { + uint64_t w; + + w = t[i] + cc; + d[i] = (uint32_t)w & 0x3FFFFFFF; + cc = w >> 30; + } + d[17] = (uint32_t)cc; +} + +/* + * Square a 270-bit integer, represented as an array of nine 30-bit words. + * Result uses 18 words of 30 bits each. + */ +static void +square9(uint32_t *d, const uint32_t *a) +{ + uint64_t t[17]; + uint64_t cc; + int i; + + t[ 0] = MUL31(a[0], a[0]); + t[ 1] = ((MUL31(a[0], a[1])) << 1); + t[ 2] = MUL31(a[1], a[1]) + + ((MUL31(a[0], a[2])) << 1); + t[ 3] = ((MUL31(a[0], a[3]) + + MUL31(a[1], a[2])) << 1); + t[ 4] = MUL31(a[2], a[2]) + + ((MUL31(a[0], a[4]) + + MUL31(a[1], a[3])) << 1); + t[ 5] = ((MUL31(a[0], a[5]) + + MUL31(a[1], a[4]) + + MUL31(a[2], a[3])) << 1); + t[ 6] = MUL31(a[3], a[3]) + + ((MUL31(a[0], a[6]) + + MUL31(a[1], a[5]) + + MUL31(a[2], a[4])) << 1); + t[ 7] = ((MUL31(a[0], a[7]) + + MUL31(a[1], a[6]) + + MUL31(a[2], a[5]) + + MUL31(a[3], a[4])) << 1); + t[ 8] = MUL31(a[4], a[4]) + + ((MUL31(a[0], a[8]) + + MUL31(a[1], a[7]) + + MUL31(a[2], a[6]) + + MUL31(a[3], a[5])) << 1); + t[ 9] = ((MUL31(a[1], a[8]) + + MUL31(a[2], a[7]) + + MUL31(a[3], a[6]) + + MUL31(a[4], a[5])) << 1); + t[10] = MUL31(a[5], a[5]) + + ((MUL31(a[2], a[8]) + + MUL31(a[3], a[7]) + + MUL31(a[4], a[6])) << 1); + t[11] = ((MUL31(a[3], a[8]) + + MUL31(a[4], a[7]) + + MUL31(a[5], a[6])) << 1); + t[12] = MUL31(a[6], a[6]) + + ((MUL31(a[4], a[8]) + + MUL31(a[5], a[7])) << 1); + t[13] = ((MUL31(a[5], a[8]) + + MUL31(a[6], a[7])) << 1); + t[14] = MUL31(a[7], a[7]) + + ((MUL31(a[6], a[8])) << 1); + t[15] = ((MUL31(a[7], a[8])) << 1); + t[16] = MUL31(a[8], a[8]); + + /* + * Propagate carries. + */ + cc = 0; + for (i = 0; i < 17; i ++) { + uint64_t w; + + w = t[i] + cc; + d[i] = (uint32_t)w & 0x3FFFFFFF; + cc = w >> 30; + } + d[17] = (uint32_t)cc; +} + +/* + * Base field modulus for P-256. + */ +static const uint32_t F256[] = { + + 0x3FFFFFFF, 0x3FFFFFFF, 0x3FFFFFFF, 0x0000003F, 0x00000000, + 0x00000000, 0x00001000, 0x3FFFC000, 0x0000FFFF +}; + +/* + * The 'b' curve equation coefficient for P-256. + */ +static const uint32_t P256_B[] = { + + 0x27D2604B, 0x2F38F0F8, 0x053B0F63, 0x0741AC33, 0x1886BC65, + 0x2EF555DA, 0x293E7B3E, 0x0D762A8E, 0x00005AC6 +}; + +/* + * Addition in the field. Source operands shall fit on 257 bits; output + * will be lower than twice the modulus. + */ +static void +add_f256(uint32_t *d, const uint32_t *a, const uint32_t *b) +{ + uint32_t w, cc; + int i; + + cc = 0; + for (i = 0; i < 9; i ++) { + w = a[i] + b[i] + cc; + d[i] = w & 0x3FFFFFFF; + cc = w >> 30; + } + w >>= 16; + d[8] &= 0xFFFF; + d[3] -= w << 6; + d[6] -= w << 12; + d[7] += w << 14; + cc = w; + for (i = 0; i < 9; i ++) { + w = d[i] + cc; + d[i] = w & 0x3FFFFFFF; + cc = ARSH(w, 30); + } +} + +/* + * Subtraction in the field. Source operands shall be smaller than twice + * the modulus; the result will fulfil the same property. + */ +static void +sub_f256(uint32_t *d, const uint32_t *a, const uint32_t *b) +{ + uint32_t w, cc; + int i; + + /* + * We really compute a - b + 2*p to make sure that the result is + * positive. + */ + w = a[0] - b[0] - 0x00002; + d[0] = w & 0x3FFFFFFF; + w = a[1] - b[1] + ARSH(w, 30); + d[1] = w & 0x3FFFFFFF; + w = a[2] - b[2] + ARSH(w, 30); + d[2] = w & 0x3FFFFFFF; + w = a[3] - b[3] + ARSH(w, 30) + 0x00080; + d[3] = w & 0x3FFFFFFF; + w = a[4] - b[4] + ARSH(w, 30); + d[4] = w & 0x3FFFFFFF; + w = a[5] - b[5] + ARSH(w, 30); + d[5] = w & 0x3FFFFFFF; + w = a[6] - b[6] + ARSH(w, 30) + 0x02000; + d[6] = w & 0x3FFFFFFF; + w = a[7] - b[7] + ARSH(w, 30) - 0x08000; + d[7] = w & 0x3FFFFFFF; + w = a[8] - b[8] + ARSH(w, 30) + 0x20000; + d[8] = w & 0xFFFF; + w >>= 16; + d[8] &= 0xFFFF; + d[3] -= w << 6; + d[6] -= w << 12; + d[7] += w << 14; + cc = w; + for (i = 0; i < 9; i ++) { + w = d[i] + cc; + d[i] = w & 0x3FFFFFFF; + cc = ARSH(w, 30); + } +} + +/* + * Compute a multiplication in F256. Source operands shall be less than + * twice the modulus. + */ +static void +mul_f256(uint32_t *d, const uint32_t *a, const uint32_t *b) +{ + uint32_t t[18]; + uint64_t s[18]; + uint64_t cc, x; + uint32_t z, c; + int i; + + mul9(t, a, b); + + /* + * Modular reduction: each high word in added/subtracted where + * necessary. + * + * The modulus is: + * p = 2^256 - 2^224 + 2^192 + 2^96 - 1 + * Therefore: + * 2^256 = 2^224 - 2^192 - 2^96 + 1 mod p + * + * For a word x at bit offset n (n >= 256), we have: + * x*2^n = x*2^(n-32) - x*2^(n-64) + * - x*2^(n - 160) + x*2^(n-256) mod p + * + * Thus, we can nullify the high word if we reinject it at some + * proper emplacements. + * + * We use 64-bit intermediate words to allow for carries to + * accumulate easily, before performing the final propagation. + */ + for (i = 0; i < 18; i ++) { + s[i] = t[i]; + } + + for (i = 17; i >= 9; i --) { + uint64_t y; + + y = s[i]; + s[i - 1] += ARSHW(y, 2); + s[i - 2] += (y << 28) & 0x3FFFFFFF; + s[i - 2] -= ARSHW(y, 4); + s[i - 3] -= (y << 26) & 0x3FFFFFFF; + s[i - 5] -= ARSHW(y, 10); + s[i - 6] -= (y << 20) & 0x3FFFFFFF; + s[i - 8] += ARSHW(y, 16); + s[i - 9] += (y << 14) & 0x3FFFFFFF; + } + + /* + * Carry propagation must be signed. Moreover, we may have overdone + * it a bit, and obtain a negative result. + * + * The loop above ran 9 times; each time, each word was augmented + * by at most one extra word (in absolute value). Thus, the top + * word must in fine fit in 39 bits, so the carry below will fit + * on 9 bits. + */ + cc = 0; + for (i = 0; i < 9; i ++) { + x = s[i] + cc; + d[i] = (uint32_t)x & 0x3FFFFFFF; + cc = ARSHW(x, 30); + } + + /* + * All nine words fit on 30 bits, but there may be an extra + * carry for a few bits (at most 9), and that carry may be + * negative. Moreover, we want the result to fit on 257 bits. + * The two lines below ensure that the word in d[] has length + * 256 bits, and the (signed) carry (beyond 2^256) is in cc. The + * significant length of cc is less than 24 bits, so we will be + * able to switch to 32-bit operations. + */ + cc = ARSHW(x, 16); + d[8] &= 0xFFFF; + + /* + * One extra round of reduction, for cc*2^256, which means + * adding cc*(2^224-2^192-2^96+1) to a 256-bit (nonnegative) + * value. If cc is negative, then it may happen (rarely, but + * not neglectibly so) that the result would be negative. In + * order to avoid that, if cc is negative, then we add the + * modulus once. Note that if cc is negative, then propagating + * that carry must yield a value lower than the modulus, so + * adding the modulus once will keep the final result under + * twice the modulus. + */ + z = (uint32_t)cc; + d[3] -= z << 6; + d[6] -= (z << 12) & 0x3FFFFFFF; + d[7] -= ARSH(z, 18); + d[7] += (z << 14) & 0x3FFFFFFF; + d[8] += ARSH(z, 16); + c = z >> 31; + d[0] -= c; + d[3] += c << 6; + d[6] += c << 12; + d[7] -= c << 14; + d[8] += c << 16; + for (i = 0; i < 9; i ++) { + uint32_t w; + + w = d[i] + z; + d[i] = w & 0x3FFFFFFF; + z = ARSH(w, 30); + } +} + +/* + * Compute a square in F256. Source operand shall be less than + * twice the modulus. + */ +static void +square_f256(uint32_t *d, const uint32_t *a) +{ + uint32_t t[18]; + uint64_t s[18]; + uint64_t cc, x; + uint32_t z, c; + int i; + + square9(t, a); + + /* + * Modular reduction: each high word in added/subtracted where + * necessary. + * + * The modulus is: + * p = 2^256 - 2^224 + 2^192 + 2^96 - 1 + * Therefore: + * 2^256 = 2^224 - 2^192 - 2^96 + 1 mod p + * + * For a word x at bit offset n (n >= 256), we have: + * x*2^n = x*2^(n-32) - x*2^(n-64) + * - x*2^(n - 160) + x*2^(n-256) mod p + * + * Thus, we can nullify the high word if we reinject it at some + * proper emplacements. + * + * We use 64-bit intermediate words to allow for carries to + * accumulate easily, before performing the final propagation. + */ + for (i = 0; i < 18; i ++) { + s[i] = t[i]; + } + + for (i = 17; i >= 9; i --) { + uint64_t y; + + y = s[i]; + s[i - 1] += ARSHW(y, 2); + s[i - 2] += (y << 28) & 0x3FFFFFFF; + s[i - 2] -= ARSHW(y, 4); + s[i - 3] -= (y << 26) & 0x3FFFFFFF; + s[i - 5] -= ARSHW(y, 10); + s[i - 6] -= (y << 20) & 0x3FFFFFFF; + s[i - 8] += ARSHW(y, 16); + s[i - 9] += (y << 14) & 0x3FFFFFFF; + } + + /* + * Carry propagation must be signed. Moreover, we may have overdone + * it a bit, and obtain a negative result. + * + * The loop above ran 9 times; each time, each word was augmented + * by at most one extra word (in absolute value). Thus, the top + * word must in fine fit in 39 bits, so the carry below will fit + * on 9 bits. + */ + cc = 0; + for (i = 0; i < 9; i ++) { + x = s[i] + cc; + d[i] = (uint32_t)x & 0x3FFFFFFF; + cc = ARSHW(x, 30); + } + + /* + * All nine words fit on 30 bits, but there may be an extra + * carry for a few bits (at most 9), and that carry may be + * negative. Moreover, we want the result to fit on 257 bits. + * The two lines below ensure that the word in d[] has length + * 256 bits, and the (signed) carry (beyond 2^256) is in cc. The + * significant length of cc is less than 24 bits, so we will be + * able to switch to 32-bit operations. + */ + cc = ARSHW(x, 16); + d[8] &= 0xFFFF; + + /* + * One extra round of reduction, for cc*2^256, which means + * adding cc*(2^224-2^192-2^96+1) to a 256-bit (nonnegative) + * value. If cc is negative, then it may happen (rarely, but + * not neglectibly so) that the result would be negative. In + * order to avoid that, if cc is negative, then we add the + * modulus once. Note that if cc is negative, then propagating + * that carry must yield a value lower than the modulus, so + * adding the modulus once will keep the final result under + * twice the modulus. + */ + z = (uint32_t)cc; + d[3] -= z << 6; + d[6] -= (z << 12) & 0x3FFFFFFF; + d[7] -= ARSH(z, 18); + d[7] += (z << 14) & 0x3FFFFFFF; + d[8] += ARSH(z, 16); + c = z >> 31; + d[0] -= c; + d[3] += c << 6; + d[6] += c << 12; + d[7] -= c << 14; + d[8] += c << 16; + for (i = 0; i < 9; i ++) { + uint32_t w; + + w = d[i] + z; + d[i] = w & 0x3FFFFFFF; + z = ARSH(w, 30); + } +} + +/* + * Perform a "final reduction" in field F256 (field for curve P-256). + * The source value must be less than twice the modulus. If the value + * is not lower than the modulus, then the modulus is subtracted and + * this function returns 1; otherwise, it leaves it untouched and it + * returns 0. + */ +static uint32_t +reduce_final_f256(uint32_t *d) +{ + uint32_t t[9]; + uint32_t cc; + int i; + + cc = 0; + for (i = 0; i < 9; i ++) { + uint32_t w; + + w = d[i] - F256[i] - cc; + cc = w >> 31; + t[i] = w & 0x3FFFFFFF; + } + cc ^= 1; + CCOPY(cc, d, t, sizeof t); + return cc; +} + +/* + * Jacobian coordinates for a point in P-256: affine coordinates (X,Y) + * are such that: + * X = x / z^2 + * Y = y / z^3 + * For the point at infinity, z = 0. + * Each point thus admits many possible representations. + * + * Coordinates are represented in arrays of 32-bit integers, each holding + * 30 bits of data. Values may also be slightly greater than the modulus, + * but they will always be lower than twice the modulus. + */ +typedef struct { + uint32_t x[9]; + uint32_t y[9]; + uint32_t z[9]; +} p256_jacobian; + +/* + * Convert a point to affine coordinates: + * - If the point is the point at infinity, then all three coordinates + * are set to 0. + * - Otherwise, the 'z' coordinate is set to 1, and the 'x' and 'y' + * coordinates are the 'X' and 'Y' affine coordinates. + * The coordinates are guaranteed to be lower than the modulus. + */ +static void +p256_to_affine(p256_jacobian *P) +{ + uint32_t t1[9], t2[9]; + int i; + + /* + * Invert z with a modular exponentiation: the modulus is + * p = 2^256 - 2^224 + 2^192 + 2^96 - 1, and the exponent is + * p-2. Exponent bit pattern (from high to low) is: + * - 32 bits of value 1 + * - 31 bits of value 0 + * - 1 bit of value 1 + * - 96 bits of value 0 + * - 94 bits of value 1 + * - 1 bit of value 0 + * - 1 bit of value 1 + * Thus, we precompute z^(2^31-1) to speed things up. + * + * If z = 0 (point at infinity) then the modular exponentiation + * will yield 0, which leads to the expected result (all three + * coordinates set to 0). + */ + + /* + * A simple square-and-multiply for z^(2^31-1). We could save about + * two dozen multiplications here with an addition chain, but + * this would require a bit more code, and extra stack buffers. + */ + memcpy(t1, P->z, sizeof P->z); + for (i = 0; i < 30; i ++) { + square_f256(t1, t1); + mul_f256(t1, t1, P->z); + } + + /* + * Square-and-multiply. Apart from the squarings, we have a few + * multiplications to set bits to 1; we multiply by the original z + * for setting 1 bit, and by t1 for setting 31 bits. + */ + memcpy(t2, P->z, sizeof P->z); + for (i = 1; i < 256; i ++) { + square_f256(t2, t2); + switch (i) { + case 31: + case 190: + case 221: + case 252: + mul_f256(t2, t2, t1); + break; + case 63: + case 253: + case 255: + mul_f256(t2, t2, P->z); + break; + } + } + + /* + * Now that we have 1/z, multiply x by 1/z^2 and y by 1/z^3. + */ + mul_f256(t1, t2, t2); + mul_f256(P->x, t1, P->x); + mul_f256(t1, t1, t2); + mul_f256(P->y, t1, P->y); + reduce_final_f256(P->x); + reduce_final_f256(P->y); + + /* + * Multiply z by 1/z. If z = 0, then this will yield 0, otherwise + * this will set z to 1. + */ + mul_f256(P->z, P->z, t2); + reduce_final_f256(P->z); +} + +/* + * Double a point in P-256. This function works for all valid points, + * including the point at infinity. + */ +static void +p256_double(p256_jacobian *Q) +{ + /* + * Doubling formulas are: + * + * s = 4*x*y^2 + * m = 3*(x + z^2)*(x - z^2) + * x' = m^2 - 2*s + * y' = m*(s - x') - 8*y^4 + * z' = 2*y*z + * + * These formulas work for all points, including points of order 2 + * and points at infinity: + * - If y = 0 then z' = 0. But there is no such point in P-256 + * anyway. + * - If z = 0 then z' = 0. + */ + uint32_t t1[9], t2[9], t3[9], t4[9]; + + /* + * Compute z^2 in t1. + */ + square_f256(t1, Q->z); + + /* + * Compute x-z^2 in t2 and x+z^2 in t1. + */ + add_f256(t2, Q->x, t1); + sub_f256(t1, Q->x, t1); + + /* + * Compute 3*(x+z^2)*(x-z^2) in t1. + */ + mul_f256(t3, t1, t2); + add_f256(t1, t3, t3); + add_f256(t1, t3, t1); + + /* + * Compute 4*x*y^2 (in t2) and 2*y^2 (in t3). + */ + square_f256(t3, Q->y); + add_f256(t3, t3, t3); + mul_f256(t2, Q->x, t3); + add_f256(t2, t2, t2); + + /* + * Compute x' = m^2 - 2*s. + */ + square_f256(Q->x, t1); + sub_f256(Q->x, Q->x, t2); + sub_f256(Q->x, Q->x, t2); + + /* + * Compute z' = 2*y*z. + */ + mul_f256(t4, Q->y, Q->z); + add_f256(Q->z, t4, t4); + + /* + * Compute y' = m*(s - x') - 8*y^4. Note that we already have + * 2*y^2 in t3. + */ + sub_f256(t2, t2, Q->x); + mul_f256(Q->y, t1, t2); + square_f256(t4, t3); + add_f256(t4, t4, t4); + sub_f256(Q->y, Q->y, t4); +} + +/* + * Add point P2 to point P1. + * + * This function computes the wrong result in the following cases: + * + * - If P1 == 0 but P2 != 0 + * - If P1 != 0 but P2 == 0 + * - If P1 == P2 + * + * In all three cases, P1 is set to the point at infinity. + * + * Returned value is 0 if one of the following occurs: + * + * - P1 and P2 have the same Y coordinate + * - P1 == 0 and P2 == 0 + * - The Y coordinate of one of the points is 0 and the other point is + * the point at infinity. + * + * The third case cannot actually happen with valid points, since a point + * with Y == 0 is a point of order 2, and there is no point of order 2 on + * curve P-256. + * + * Therefore, assuming that P1 != 0 and P2 != 0 on input, then the caller + * can apply the following: + * + * - If the result is not the point at infinity, then it is correct. + * - Otherwise, if the returned value is 1, then this is a case of + * P1+P2 == 0, so the result is indeed the point at infinity. + * - Otherwise, P1 == P2, so a "double" operation should have been + * performed. + */ +static uint32_t +p256_add(p256_jacobian *P1, const p256_jacobian *P2) +{ + /* + * Addtions formulas are: + * + * u1 = x1 * z2^2 + * u2 = x2 * z1^2 + * s1 = y1 * z2^3 + * s2 = y2 * z1^3 + * h = u2 - u1 + * r = s2 - s1 + * x3 = r^2 - h^3 - 2 * u1 * h^2 + * y3 = r * (u1 * h^2 - x3) - s1 * h^3 + * z3 = h * z1 * z2 + */ + uint32_t t1[9], t2[9], t3[9], t4[9], t5[9], t6[9], t7[9]; + uint32_t ret; + int i; + + /* + * Compute u1 = x1*z2^2 (in t1) and s1 = y1*z2^3 (in t3). + */ + square_f256(t3, P2->z); + mul_f256(t1, P1->x, t3); + mul_f256(t4, P2->z, t3); + mul_f256(t3, P1->y, t4); + + /* + * Compute u2 = x2*z1^2 (in t2) and s2 = y2*z1^3 (in t4). + */ + square_f256(t4, P1->z); + mul_f256(t2, P2->x, t4); + mul_f256(t5, P1->z, t4); + mul_f256(t4, P2->y, t5); + + /* + * Compute h = h2 - u1 (in t2) and r = s2 - s1 (in t4). + * We need to test whether r is zero, so we will do some extra + * reduce. + */ + sub_f256(t2, t2, t1); + sub_f256(t4, t4, t3); + reduce_final_f256(t4); + ret = 0; + for (i = 0; i < 9; i ++) { + ret |= t4[i]; + } + ret = (ret | -ret) >> 31; + + /* + * Compute u1*h^2 (in t6) and h^3 (in t5); + */ + square_f256(t7, t2); + mul_f256(t6, t1, t7); + mul_f256(t5, t7, t2); + + /* + * Compute x3 = r^2 - h^3 - 2*u1*h^2. + */ + square_f256(P1->x, t4); + sub_f256(P1->x, P1->x, t5); + sub_f256(P1->x, P1->x, t6); + sub_f256(P1->x, P1->x, t6); + + /* + * Compute y3 = r*(u1*h^2 - x3) - s1*h^3. + */ + sub_f256(t6, t6, P1->x); + mul_f256(P1->y, t4, t6); + mul_f256(t1, t5, t3); + sub_f256(P1->y, P1->y, t1); + + /* + * Compute z3 = h*z1*z2. + */ + mul_f256(t1, P1->z, P2->z); + mul_f256(P1->z, t1, t2); + + return ret; +} + +/* + * Add point P2 to point P1. This is a specialised function for the + * case when P2 is a non-zero point in affine coordinate. + * + * This function computes the wrong result in the following cases: + * + * - If P1 == 0 + * - If P1 == P2 + * + * In both cases, P1 is set to the point at infinity. + * + * Returned value is 0 if one of the following occurs: + * + * - P1 and P2 have the same Y coordinate + * - The Y coordinate of P2 is 0 and P1 is the point at infinity. + * + * The second case cannot actually happen with valid points, since a point + * with Y == 0 is a point of order 2, and there is no point of order 2 on + * curve P-256. + * + * Therefore, assuming that P1 != 0 on input, then the caller + * can apply the following: + * + * - If the result is not the point at infinity, then it is correct. + * - Otherwise, if the returned value is 1, then this is a case of + * P1+P2 == 0, so the result is indeed the point at infinity. + * - Otherwise, P1 == P2, so a "double" operation should have been + * performed. + */ +static uint32_t +p256_add_mixed(p256_jacobian *P1, const p256_jacobian *P2) +{ + /* + * Addtions formulas are: + * + * u1 = x1 + * u2 = x2 * z1^2 + * s1 = y1 + * s2 = y2 * z1^3 + * h = u2 - u1 + * r = s2 - s1 + * x3 = r^2 - h^3 - 2 * u1 * h^2 + * y3 = r * (u1 * h^2 - x3) - s1 * h^3 + * z3 = h * z1 + */ + uint32_t t1[9], t2[9], t3[9], t4[9], t5[9], t6[9], t7[9]; + uint32_t ret; + int i; + + /* + * Compute u1 = x1 (in t1) and s1 = y1 (in t3). + */ + memcpy(t1, P1->x, sizeof t1); + memcpy(t3, P1->y, sizeof t3); + + /* + * Compute u2 = x2*z1^2 (in t2) and s2 = y2*z1^3 (in t4). + */ + square_f256(t4, P1->z); + mul_f256(t2, P2->x, t4); + mul_f256(t5, P1->z, t4); + mul_f256(t4, P2->y, t5); + + /* + * Compute h = h2 - u1 (in t2) and r = s2 - s1 (in t4). + * We need to test whether r is zero, so we will do some extra + * reduce. + */ + sub_f256(t2, t2, t1); + sub_f256(t4, t4, t3); + reduce_final_f256(t4); + ret = 0; + for (i = 0; i < 9; i ++) { + ret |= t4[i]; + } + ret = (ret | -ret) >> 31; + + /* + * Compute u1*h^2 (in t6) and h^3 (in t5); + */ + square_f256(t7, t2); + mul_f256(t6, t1, t7); + mul_f256(t5, t7, t2); + + /* + * Compute x3 = r^2 - h^3 - 2*u1*h^2. + */ + square_f256(P1->x, t4); + sub_f256(P1->x, P1->x, t5); + sub_f256(P1->x, P1->x, t6); + sub_f256(P1->x, P1->x, t6); + + /* + * Compute y3 = r*(u1*h^2 - x3) - s1*h^3. + */ + sub_f256(t6, t6, P1->x); + mul_f256(P1->y, t4, t6); + mul_f256(t1, t5, t3); + sub_f256(P1->y, P1->y, t1); + + /* + * Compute z3 = h*z1*z2. + */ + mul_f256(P1->z, P1->z, t2); + + return ret; +} + +/* + * Decode a P-256 point. This function does not support the point at + * infinity. Returned value is 0 if the point is invalid, 1 otherwise. + */ +static uint32_t +p256_decode(p256_jacobian *P, const void *src, size_t len) +{ + const unsigned char *buf; + uint32_t tx[9], ty[9], t1[9], t2[9]; + uint32_t bad; + int i; + + if (len != 65) { + return 0; + } + buf = src; + + /* + * First byte must be 0x04 (uncompressed format). We could support + * "hybrid format" (first byte is 0x06 or 0x07, and encodes the + * least significant bit of the Y coordinate), but it is explicitly + * forbidden by RFC 5480 (section 2.2). + */ + bad = NEQ(buf[0], 0x04); + + /* + * Decode the coordinates, and check that they are both lower + * than the modulus. + */ + tx[8] = be8_to_le30(tx, buf + 1, 32); + ty[8] = be8_to_le30(ty, buf + 33, 32); + bad |= reduce_final_f256(tx); + bad |= reduce_final_f256(ty); + + /* + * Check curve equation. + */ + square_f256(t1, tx); + mul_f256(t1, tx, t1); + square_f256(t2, ty); + sub_f256(t1, t1, tx); + sub_f256(t1, t1, tx); + sub_f256(t1, t1, tx); + add_f256(t1, t1, P256_B); + sub_f256(t1, t1, t2); + reduce_final_f256(t1); + for (i = 0; i < 9; i ++) { + bad |= t1[i]; + } + + /* + * Copy coordinates to the point structure. + */ + memcpy(P->x, tx, sizeof tx); + memcpy(P->y, ty, sizeof ty); + memset(P->z, 0, sizeof P->z); + P->z[0] = 1; + return EQ(bad, 0); +} + +/* + * Encode a point into a buffer. This function assumes that the point is + * valid, in affine coordinates, and not the point at infinity. + */ +static void +p256_encode(void *dst, const p256_jacobian *P) +{ + unsigned char *buf; + + buf = dst; + buf[0] = 0x04; + le30_to_be8(buf + 1, 32, P->x); + le30_to_be8(buf + 33, 32, P->y); +} + +/* + * Multiply a curve point by an integer. The integer is assumed to be + * lower than the curve order, and the base point must not be the point + * at infinity. + */ +static void +p256_mul(p256_jacobian *P, const unsigned char *x, size_t xlen) +{ + /* + * qz is a flag that is initially 1, and remains equal to 1 + * as long as the point is the point at infinity. + * + * We use a 2-bit window to handle multiplier bits by pairs. + * The precomputed window really is the points P2 and P3. + */ + uint32_t qz; + p256_jacobian P2, P3, Q, T, U; + + /* + * Compute window values. + */ + P2 = *P; + p256_double(&P2); + P3 = *P; + p256_add(&P3, &P2); + + /* + * We start with Q = 0. We process multiplier bits 2 by 2. + */ + memset(&Q, 0, sizeof Q); + qz = 1; + while (xlen -- > 0) { + int k; + + for (k = 6; k >= 0; k -= 2) { + uint32_t bits; + uint32_t bnz; + + p256_double(&Q); + p256_double(&Q); + T = *P; + U = Q; + bits = (*x >> k) & (uint32_t)3; + bnz = NEQ(bits, 0); + CCOPY(EQ(bits, 2), &T, &P2, sizeof T); + CCOPY(EQ(bits, 3), &T, &P3, sizeof T); + p256_add(&U, &T); + CCOPY(bnz & qz, &Q, &T, sizeof Q); + CCOPY(bnz & ~qz, &Q, &U, sizeof Q); + qz &= ~bnz; + } + x ++; + } + *P = Q; +} + +/* + * Precomputed window: k*G points, where G is the curve generator, and k + * is an integer from 1 to 15 (inclusive). The X and Y coordinates of + * the point are encoded as 9 words of 30 bits each (little-endian + * order). + */ +static const uint32_t Gwin[15][18] = { + + { 0x1898C296, 0x1284E517, 0x1EB33A0F, 0x00DF604B, + 0x2440F277, 0x339B958E, 0x04247F8B, 0x347CB84B, + 0x00006B17, 0x37BF51F5, 0x2ED901A0, 0x3315ECEC, + 0x338CD5DA, 0x0F9E162B, 0x1FAD29F0, 0x27F9B8EE, + 0x10B8BF86, 0x00004FE3 }, + + { 0x07669978, 0x182D23F1, 0x3F21B35A, 0x225A789D, + 0x351AC3C0, 0x08E00C12, 0x34F7E8A5, 0x1EC62340, + 0x00007CF2, 0x227873D1, 0x3812DE74, 0x0E982299, + 0x1F6B798F, 0x3430DBBA, 0x366B1A7D, 0x2D040293, + 0x154436E3, 0x00000777 }, + + { 0x06E7FD6C, 0x2D05986F, 0x3ADA985F, 0x31ADC87B, + 0x0BF165E6, 0x1FBE5475, 0x30A44C8F, 0x3934698C, + 0x00005ECB, 0x227D5032, 0x29E6C49E, 0x04FB83D9, + 0x0AAC0D8E, 0x24A2ECD8, 0x2C1B3869, 0x0FF7E374, + 0x19031266, 0x00008734 }, + + { 0x2B030852, 0x024C0911, 0x05596EF5, 0x07F8B6DE, + 0x262BD003, 0x3779967B, 0x08FBBA02, 0x128D4CB4, + 0x0000E253, 0x184ED8C6, 0x310B08FC, 0x30EE0055, + 0x3F25B0FC, 0x062D764E, 0x3FB97F6A, 0x33CC719D, + 0x15D69318, 0x0000E0F1 }, + + { 0x03D033ED, 0x05552837, 0x35BE5242, 0x2320BF47, + 0x268FDFEF, 0x13215821, 0x140D2D78, 0x02DE9454, + 0x00005159, 0x3DA16DA4, 0x0742ED13, 0x0D80888D, + 0x004BC035, 0x0A79260D, 0x06FCDAFE, 0x2727D8AE, + 0x1F6A2412, 0x0000E0C1 }, + + { 0x3C2291A9, 0x1AC2ABA4, 0x3B215B4C, 0x131D037A, + 0x17DDE302, 0x0C90B2E2, 0x0602C92D, 0x05CA9DA9, + 0x0000B01A, 0x0FC77FE2, 0x35F1214E, 0x07E16BDF, + 0x003DDC07, 0x2703791C, 0x3038B7EE, 0x3DAD56FE, + 0x041D0C8D, 0x0000E85C }, + + { 0x3187B2A3, 0x0018A1C0, 0x00FEF5B3, 0x3E7E2E2A, + 0x01FB607E, 0x2CC199F0, 0x37B4625B, 0x0EDBE82F, + 0x00008E53, 0x01F400B4, 0x15786A1B, 0x3041B21C, + 0x31CD8CF2, 0x35900053, 0x1A7E0E9B, 0x318366D0, + 0x076F780C, 0x000073EB }, + + { 0x1B6FB393, 0x13767707, 0x3CE97DBB, 0x348E2603, + 0x354CADC1, 0x09D0B4EA, 0x1B053404, 0x1DE76FBA, + 0x000062D9, 0x0F09957E, 0x295029A8, 0x3E76A78D, + 0x3B547DAE, 0x27CEE0A2, 0x0575DC45, 0x1D8244FF, + 0x332F647A, 0x0000AD5A }, + + { 0x10949EE0, 0x1E7A292E, 0x06DF8B3D, 0x02B2E30B, + 0x31F8729E, 0x24E35475, 0x30B71878, 0x35EDBFB7, + 0x0000EA68, 0x0DD048FA, 0x21688929, 0x0DE823FE, + 0x1C53FAA9, 0x0EA0C84D, 0x052A592A, 0x1FCE7870, + 0x11325CB2, 0x00002A27 }, + + { 0x04C5723F, 0x30D81A50, 0x048306E4, 0x329B11C7, + 0x223FB545, 0x085347A8, 0x2993E591, 0x1B5ACA8E, + 0x0000CEF6, 0x04AF0773, 0x28D2EEA9, 0x2751EEEC, + 0x037B4A7F, 0x3B4C1059, 0x08F37674, 0x2AE906E1, + 0x18A88A6A, 0x00008786 }, + + { 0x34BC21D1, 0x0CCE474D, 0x15048BF4, 0x1D0BB409, + 0x021CDA16, 0x20DE76C3, 0x34C59063, 0x04EDE20E, + 0x00003ED1, 0x282A3740, 0x0BE3BBF3, 0x29889DAE, + 0x03413697, 0x34C68A09, 0x210EBE93, 0x0C8A224C, + 0x0826B331, 0x00009099 }, + + { 0x0624E3C4, 0x140317BA, 0x2F82C99D, 0x260C0A2C, + 0x25D55179, 0x194DCC83, 0x3D95E462, 0x356F6A05, + 0x0000741D, 0x0D4481D3, 0x2657FC8B, 0x1BA5CA71, + 0x3AE44B0D, 0x07B1548E, 0x0E0D5522, 0x05FDC567, + 0x2D1AA70E, 0x00000770 }, + + { 0x06072C01, 0x23857675, 0x1EAD58A9, 0x0B8A12D9, + 0x1EE2FC79, 0x0177CB61, 0x0495A618, 0x20DEB82B, + 0x0000177C, 0x2FC7BFD8, 0x310EEF8B, 0x1FB4DF39, + 0x3B8530E8, 0x0F4E7226, 0x0246B6D0, 0x2A558A24, + 0x163353AF, 0x000063BB }, + + { 0x24D2920B, 0x1C249DCC, 0x2069C5E5, 0x09AB2F9E, + 0x36DF3CF1, 0x1991FD0C, 0x062B97A7, 0x1E80070E, + 0x000054E7, 0x20D0B375, 0x2E9F20BD, 0x35090081, + 0x1C7A9DDC, 0x22E7C371, 0x087E3016, 0x03175421, + 0x3C6ECA7D, 0x0000F599 }, + + { 0x259B9D5F, 0x0D9A318F, 0x23A0EF16, 0x00EBE4B7, + 0x088265AE, 0x2CDE2666, 0x2BAE7ADF, 0x1371A5C6, + 0x0000F045, 0x0D034F36, 0x1F967378, 0x1B5FA3F4, + 0x0EC8739D, 0x1643E62A, 0x1653947E, 0x22D1F4E6, + 0x0FB8D64B, 0x0000B5B9 } +}; + +/* + * Lookup one of the Gwin[] values, by index. This is constant-time. + */ +static void +lookup_Gwin(p256_jacobian *T, uint32_t idx) +{ + uint32_t xy[18]; + uint32_t k; + size_t u; + + memset(xy, 0, sizeof xy); + for (k = 0; k < 15; k ++) { + uint32_t m; + + m = -EQ(idx, k + 1); + for (u = 0; u < 18; u ++) { + xy[u] |= m & Gwin[k][u]; + } + } + memcpy(T->x, &xy[0], sizeof T->x); + memcpy(T->y, &xy[9], sizeof T->y); + memset(T->z, 0, sizeof T->z); + T->z[0] = 1; +} + +/* + * Multiply the generator by an integer. The integer is assumed non-zero + * and lower than the curve order. + */ +static void +p256_mulgen(p256_jacobian *P, const unsigned char *x, size_t xlen) +{ + /* + * qz is a flag that is initially 1, and remains equal to 1 + * as long as the point is the point at infinity. + * + * We use a 4-bit window to handle multiplier bits by groups + * of 4. The precomputed window is constant static data, with + * points in affine coordinates; we use a constant-time lookup. + */ + p256_jacobian Q; + uint32_t qz; + + memset(&Q, 0, sizeof Q); + qz = 1; + while (xlen -- > 0) { + int k; + unsigned bx; + + bx = *x ++; + for (k = 0; k < 2; k ++) { + uint32_t bits; + uint32_t bnz; + p256_jacobian T, U; + + p256_double(&Q); + p256_double(&Q); + p256_double(&Q); + p256_double(&Q); + bits = (bx >> 4) & 0x0F; + bnz = NEQ(bits, 0); + lookup_Gwin(&T, bits); + U = Q; + p256_add_mixed(&U, &T); + CCOPY(bnz & qz, &Q, &T, sizeof Q); + CCOPY(bnz & ~qz, &Q, &U, sizeof Q); + qz &= ~bnz; + bx <<= 4; + } + } + *P = Q; +} + +static const unsigned char P256_G[] = { + 0x04, 0x6B, 0x17, 0xD1, 0xF2, 0xE1, 0x2C, 0x42, 0x47, 0xF8, + 0xBC, 0xE6, 0xE5, 0x63, 0xA4, 0x40, 0xF2, 0x77, 0x03, 0x7D, + 0x81, 0x2D, 0xEB, 0x33, 0xA0, 0xF4, 0xA1, 0x39, 0x45, 0xD8, + 0x98, 0xC2, 0x96, 0x4F, 0xE3, 0x42, 0xE2, 0xFE, 0x1A, 0x7F, + 0x9B, 0x8E, 0xE7, 0xEB, 0x4A, 0x7C, 0x0F, 0x9E, 0x16, 0x2B, + 0xCE, 0x33, 0x57, 0x6B, 0x31, 0x5E, 0xCE, 0xCB, 0xB6, 0x40, + 0x68, 0x37, 0xBF, 0x51, 0xF5 +}; + +static const unsigned char P256_N[] = { + 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xBC, 0xE6, 0xFA, 0xAD, + 0xA7, 0x17, 0x9E, 0x84, 0xF3, 0xB9, 0xCA, 0xC2, 0xFC, 0x63, + 0x25, 0x51 +}; + +static const unsigned char * +api_generator(int curve, size_t *len) +{ + (void)curve; + *len = sizeof P256_G; + return P256_G; +} + +static const unsigned char * +api_order(int curve, size_t *len) +{ + (void)curve; + *len = sizeof P256_N; + return P256_N; +} + +static size_t +api_xoff(int curve, size_t *len) +{ + (void)curve; + *len = 32; + return 1; +} + +static uint32_t +api_mul(unsigned char *G, size_t Glen, + const unsigned char *x, size_t xlen, int curve) +{ + uint32_t r; + p256_jacobian P; + + (void)curve; + r = p256_decode(&P, G, Glen); + p256_mul(&P, x, xlen); + if (Glen >= 65) { + p256_to_affine(&P); + p256_encode(G, &P); + } + return r; +} + +static size_t +api_mulgen(unsigned char *R, + const unsigned char *x, size_t xlen, int curve) +{ + p256_jacobian P; + + (void)curve; + p256_mulgen(&P, x, xlen); + p256_to_affine(&P); + p256_encode(R, &P); + return 65; + + /* + const unsigned char *G; + size_t Glen; + + G = api_generator(curve, &Glen); + memcpy(R, G, Glen); + api_mul(R, Glen, x, xlen, curve); + return Glen; + */ +} + +static uint32_t +api_muladd(unsigned char *A, const unsigned char *B, size_t len, + const unsigned char *x, size_t xlen, + const unsigned char *y, size_t ylen, int curve) +{ + p256_jacobian P, Q; + uint32_t r, t, z; + int i; + + (void)curve; + r = p256_decode(&P, A, len); + p256_mul(&P, x, xlen); + if (B == NULL) { + p256_mulgen(&Q, y, ylen); + } else { + r &= p256_decode(&Q, B, len); + p256_mul(&Q, y, ylen); + } + + /* + * The final addition may fail in case both points are equal. + */ + t = p256_add(&P, &Q); + reduce_final_f256(P.z); + z = 0; + for (i = 0; i < 9; i ++) { + z |= P.z[i]; + } + z = EQ(z, 0); + p256_double(&Q); + + /* + * If z is 1 then either P+Q = 0 (t = 1) or P = Q (t = 0). So we + * have the following: + * + * z = 0, t = 0 return P (normal addition) + * z = 0, t = 1 return P (normal addition) + * z = 1, t = 0 return Q (a 'double' case) + * z = 1, t = 1 report an error (P+Q = 0) + */ + CCOPY(z & ~t, &P, &Q, sizeof Q); + p256_to_affine(&P); + p256_encode(A, &P); + r &= ~(z & t); + return r; +} + +/* see bearssl_ec.h */ +const br_ec_impl br_ec_p256_m31 = { + (uint32_t)0x00800000, + &api_generator, + &api_order, + &api_xoff, + &api_mul, + &api_mulgen, + &api_muladd +}; + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_p256_m62.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_p256_m62.c new file mode 100644 index 000000000..1881db65f --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_p256_m62.c @@ -0,0 +1,1770 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +#if BR_INT128 || BR_UMUL128 + +#if BR_UMUL128 +#include +#endif + +static const unsigned char P256_G[] = { + 0x04, 0x6B, 0x17, 0xD1, 0xF2, 0xE1, 0x2C, 0x42, 0x47, 0xF8, + 0xBC, 0xE6, 0xE5, 0x63, 0xA4, 0x40, 0xF2, 0x77, 0x03, 0x7D, + 0x81, 0x2D, 0xEB, 0x33, 0xA0, 0xF4, 0xA1, 0x39, 0x45, 0xD8, + 0x98, 0xC2, 0x96, 0x4F, 0xE3, 0x42, 0xE2, 0xFE, 0x1A, 0x7F, + 0x9B, 0x8E, 0xE7, 0xEB, 0x4A, 0x7C, 0x0F, 0x9E, 0x16, 0x2B, + 0xCE, 0x33, 0x57, 0x6B, 0x31, 0x5E, 0xCE, 0xCB, 0xB6, 0x40, + 0x68, 0x37, 0xBF, 0x51, 0xF5 +}; + +static const unsigned char P256_N[] = { + 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xBC, 0xE6, 0xFA, 0xAD, + 0xA7, 0x17, 0x9E, 0x84, 0xF3, 0xB9, 0xCA, 0xC2, 0xFC, 0x63, + 0x25, 0x51 +}; + +static const unsigned char * +api_generator(int curve, size_t *len) +{ + (void)curve; + *len = sizeof P256_G; + return P256_G; +} + +static const unsigned char * +api_order(int curve, size_t *len) +{ + (void)curve; + *len = sizeof P256_N; + return P256_N; +} + +static size_t +api_xoff(int curve, size_t *len) +{ + (void)curve; + *len = 32; + return 1; +} + +/* + * A field element is encoded as five 64-bit integers, in basis 2^52. + * Limbs may occasionally exceed 2^52. + * + * A _partially reduced_ value is such that the following hold: + * - top limb is less than 2^48 + 2^30 + * - the other limbs fit on 53 bits each + * In particular, such a value is less than twice the modulus p. + */ + +#define BIT(n) ((uint64_t)1 << (n)) +#define MASK48 (BIT(48) - BIT(0)) +#define MASK52 (BIT(52) - BIT(0)) + +/* R = 2^260 mod p */ +static const uint64_t F256_R[] = { + 0x0000000000010, 0xF000000000000, 0xFFFFFFFFFFFFF, + 0xFFEFFFFFFFFFF, 0x00000000FFFFF +}; + +/* Curve equation is y^2 = x^3 - 3*x + B. This constant is B*R mod p + (Montgomery representation of B). */ +static const uint64_t P256_B_MONTY[] = { + 0xDF6229C4BDDFD, 0xCA8843090D89C, 0x212ED6ACF005C, + 0x83415A220ABF7, 0x0C30061DD4874 +}; + +/* + * Addition in the field. Carry propagation is not performed. + * On input, limbs may be up to 63 bits each; on output, they will + * be up to one bit more than on input. + */ +static inline void +f256_add(uint64_t *d, const uint64_t *a, const uint64_t *b) +{ + d[0] = a[0] + b[0]; + d[1] = a[1] + b[1]; + d[2] = a[2] + b[2]; + d[3] = a[3] + b[3]; + d[4] = a[4] + b[4]; +} + +/* + * Partially reduce the provided value. + * Input: limbs can go up to 61 bits each. + * Output: partially reduced. + */ +static inline void +f256_partial_reduce(uint64_t *a) +{ + uint64_t w, cc, s; + + /* + * Propagate carries. + */ + w = a[0]; + a[0] = w & MASK52; + cc = w >> 52; + w = a[1] + cc; + a[1] = w & MASK52; + cc = w >> 52; + w = a[2] + cc; + a[2] = w & MASK52; + cc = w >> 52; + w = a[3] + cc; + a[3] = w & MASK52; + cc = w >> 52; + a[4] += cc; + + s = a[4] >> 48; /* s < 2^14 */ + a[0] += s; /* a[0] < 2^52 + 2^14 */ + w = a[1] - (s << 44); + a[1] = w & MASK52; /* a[1] < 2^52 */ + cc = -(w >> 52) & 0xFFF; /* cc < 16 */ + w = a[2] - cc; + a[2] = w & MASK52; /* a[2] < 2^52 */ + cc = w >> 63; /* cc = 0 or 1 */ + w = a[3] - cc - (s << 36); + a[3] = w & MASK52; /* a[3] < 2^52 */ + cc = w >> 63; /* cc = 0 or 1 */ + w = a[4] & MASK48; + a[4] = w + (s << 16) - cc; /* a[4] < 2^48 + 2^30 */ +} + +/* + * Subtraction in the field. + * Input: limbs must fit on 60 bits each; in particular, the complete + * integer will be less than 2^268 + 2^217. + * Output: partially reduced. + */ +static inline void +f256_sub(uint64_t *d, const uint64_t *a, const uint64_t *b) +{ + uint64_t t[5], w, s, cc; + + /* + * We compute d = 2^13*p + a - b; this ensures a positive + * intermediate value. + * + * Each individual addition/subtraction may yield a positive or + * negative result; thus, we need to handle a signed carry, thus + * with sign extension. We prefer not to use signed types (int64_t) + * because conversion from unsigned to signed is cumbersome (a + * direct cast with the top bit set is undefined behavior; instead, + * we have to use pointer aliasing, using the guaranteed properties + * of exact-width types, but this requires the compiler to optimize + * away the writes and reads from RAM), and right-shifting a + * signed negative value is implementation-defined. Therefore, + * we use a custom sign extension. + */ + + w = a[0] - b[0] - BIT(13); + t[0] = w & MASK52; + cc = w >> 52; + cc |= -(cc & BIT(11)); + w = a[1] - b[1] + cc; + t[1] = w & MASK52; + cc = w >> 52; + cc |= -(cc & BIT(11)); + w = a[2] - b[2] + cc; + t[2] = (w & MASK52) + BIT(5); + cc = w >> 52; + cc |= -(cc & BIT(11)); + w = a[3] - b[3] + cc; + t[3] = (w & MASK52) + BIT(49); + cc = w >> 52; + cc |= -(cc & BIT(11)); + t[4] = (BIT(61) - BIT(29)) + a[4] - b[4] + cc; + + /* + * Perform partial reduction. Rule is: + * 2^256 = 2^224 - 2^192 - 2^96 + 1 mod p + * + * At that point: + * 0 <= t[0] <= 2^52 - 1 + * 0 <= t[1] <= 2^52 - 1 + * 2^5 <= t[2] <= 2^52 + 2^5 - 1 + * 2^49 <= t[3] <= 2^52 + 2^49 - 1 + * 2^59 < t[4] <= 2^61 + 2^60 - 2^29 + * + * Thus, the value 's' (t[4] / 2^48) will be necessarily + * greater than 2048, and less than 12288. + */ + s = t[4] >> 48; + + d[0] = t[0] + s; /* d[0] <= 2^52 + 12287 */ + w = t[1] - (s << 44); + d[1] = w & MASK52; /* d[1] <= 2^52 - 1 */ + cc = -(w >> 52) & 0xFFF; /* cc <= 48 */ + w = t[2] - cc; + cc = w >> 63; /* cc = 0 or 1 */ + d[2] = w + (cc << 52); /* d[2] <= 2^52 + 31 */ + w = t[3] - cc - (s << 36); + cc = w >> 63; /* cc = 0 or 1 */ + d[3] = w + (cc << 52); /* t[3] <= 2^52 + 2^49 - 1 */ + d[4] = (t[4] & MASK48) + (s << 16) - cc; /* d[4] < 2^48 + 2^30 */ + + /* + * If s = 0, then none of the limbs is modified, and there cannot + * be an overflow; if s != 0, then (s << 16) > cc, and there is + * no overflow either. + */ +} + +/* + * Montgomery multiplication in the field. + * Input: limbs must fit on 56 bits each. + * Output: partially reduced. + */ +static void +f256_montymul(uint64_t *d, const uint64_t *a, const uint64_t *b) +{ +#if BR_INT128 + + int i; + uint64_t t[5]; + + t[0] = 0; + t[1] = 0; + t[2] = 0; + t[3] = 0; + t[4] = 0; + for (i = 0; i < 5; i ++) { + uint64_t x, f, cc, w, s; + unsigned __int128 z; + + /* + * Since limbs of a[] and b[] fit on 56 bits each, + * each individual product fits on 112 bits. Also, + * the factor f fits on 52 bits, so f<<48 fits on + * 112 bits too. This guarantees that carries (cc) + * will fit on 62 bits, thus no overflow. + * + * The operations below compute: + * t <- (t + x*b + f*p) / 2^64 + */ + x = a[i]; + z = (unsigned __int128)b[0] * (unsigned __int128)x + + (unsigned __int128)t[0]; + f = (uint64_t)z & MASK52; + cc = (uint64_t)(z >> 52); + z = (unsigned __int128)b[1] * (unsigned __int128)x + + (unsigned __int128)t[1] + cc + + ((unsigned __int128)f << 44); + t[0] = (uint64_t)z & MASK52; + cc = (uint64_t)(z >> 52); + z = (unsigned __int128)b[2] * (unsigned __int128)x + + (unsigned __int128)t[2] + cc; + t[1] = (uint64_t)z & MASK52; + cc = (uint64_t)(z >> 52); + z = (unsigned __int128)b[3] * (unsigned __int128)x + + (unsigned __int128)t[3] + cc + + ((unsigned __int128)f << 36); + t[2] = (uint64_t)z & MASK52; + cc = (uint64_t)(z >> 52); + z = (unsigned __int128)b[4] * (unsigned __int128)x + + (unsigned __int128)t[4] + cc + + ((unsigned __int128)f << 48) + - ((unsigned __int128)f << 16); + t[3] = (uint64_t)z & MASK52; + t[4] = (uint64_t)(z >> 52); + + /* + * t[4] may be up to 62 bits here; we need to do a + * partial reduction. Note that limbs t[0] to t[3] + * fit on 52 bits each. + */ + s = t[4] >> 48; /* s < 2^14 */ + t[0] += s; /* t[0] < 2^52 + 2^14 */ + w = t[1] - (s << 44); + t[1] = w & MASK52; /* t[1] < 2^52 */ + cc = -(w >> 52) & 0xFFF; /* cc < 16 */ + w = t[2] - cc; + t[2] = w & MASK52; /* t[2] < 2^52 */ + cc = w >> 63; /* cc = 0 or 1 */ + w = t[3] - cc - (s << 36); + t[3] = w & MASK52; /* t[3] < 2^52 */ + cc = w >> 63; /* cc = 0 or 1 */ + w = t[4] & MASK48; + t[4] = w + (s << 16) - cc; /* t[4] < 2^48 + 2^30 */ + + /* + * The final t[4] cannot overflow because cc is 0 or 1, + * and cc can be 1 only if s != 0. + */ + } + + d[0] = t[0]; + d[1] = t[1]; + d[2] = t[2]; + d[3] = t[3]; + d[4] = t[4]; + +#elif BR_UMUL128 + + int i; + uint64_t t[5]; + + t[0] = 0; + t[1] = 0; + t[2] = 0; + t[3] = 0; + t[4] = 0; + for (i = 0; i < 5; i ++) { + uint64_t x, f, cc, w, s, zh, zl; + unsigned char k; + + /* + * Since limbs of a[] and b[] fit on 56 bits each, + * each individual product fits on 112 bits. Also, + * the factor f fits on 52 bits, so f<<48 fits on + * 112 bits too. This guarantees that carries (cc) + * will fit on 62 bits, thus no overflow. + * + * The operations below compute: + * t <- (t + x*b + f*p) / 2^64 + */ + x = a[i]; + zl = _umul128(b[0], x, &zh); + k = _addcarry_u64(0, t[0], zl, &zl); + (void)_addcarry_u64(k, 0, zh, &zh); + f = zl & MASK52; + cc = (zl >> 52) | (zh << 12); + + zl = _umul128(b[1], x, &zh); + k = _addcarry_u64(0, t[1], zl, &zl); + (void)_addcarry_u64(k, 0, zh, &zh); + k = _addcarry_u64(0, cc, zl, &zl); + (void)_addcarry_u64(k, 0, zh, &zh); + k = _addcarry_u64(0, f << 44, zl, &zl); + (void)_addcarry_u64(k, f >> 20, zh, &zh); + t[0] = zl & MASK52; + cc = (zl >> 52) | (zh << 12); + + zl = _umul128(b[2], x, &zh); + k = _addcarry_u64(0, t[2], zl, &zl); + (void)_addcarry_u64(k, 0, zh, &zh); + k = _addcarry_u64(0, cc, zl, &zl); + (void)_addcarry_u64(k, 0, zh, &zh); + t[1] = zl & MASK52; + cc = (zl >> 52) | (zh << 12); + + zl = _umul128(b[3], x, &zh); + k = _addcarry_u64(0, t[3], zl, &zl); + (void)_addcarry_u64(k, 0, zh, &zh); + k = _addcarry_u64(0, cc, zl, &zl); + (void)_addcarry_u64(k, 0, zh, &zh); + k = _addcarry_u64(0, f << 36, zl, &zl); + (void)_addcarry_u64(k, f >> 28, zh, &zh); + t[2] = zl & MASK52; + cc = (zl >> 52) | (zh << 12); + + zl = _umul128(b[4], x, &zh); + k = _addcarry_u64(0, t[4], zl, &zl); + (void)_addcarry_u64(k, 0, zh, &zh); + k = _addcarry_u64(0, cc, zl, &zl); + (void)_addcarry_u64(k, 0, zh, &zh); + k = _addcarry_u64(0, f << 48, zl, &zl); + (void)_addcarry_u64(k, f >> 16, zh, &zh); + k = _subborrow_u64(0, zl, f << 16, &zl); + (void)_subborrow_u64(k, zh, f >> 48, &zh); + t[3] = zl & MASK52; + t[4] = (zl >> 52) | (zh << 12); + + /* + * t[4] may be up to 62 bits here; we need to do a + * partial reduction. Note that limbs t[0] to t[3] + * fit on 52 bits each. + */ + s = t[4] >> 48; /* s < 2^14 */ + t[0] += s; /* t[0] < 2^52 + 2^14 */ + w = t[1] - (s << 44); + t[1] = w & MASK52; /* t[1] < 2^52 */ + cc = -(w >> 52) & 0xFFF; /* cc < 16 */ + w = t[2] - cc; + t[2] = w & MASK52; /* t[2] < 2^52 */ + cc = w >> 63; /* cc = 0 or 1 */ + w = t[3] - cc - (s << 36); + t[3] = w & MASK52; /* t[3] < 2^52 */ + cc = w >> 63; /* cc = 0 or 1 */ + w = t[4] & MASK48; + t[4] = w + (s << 16) - cc; /* t[4] < 2^48 + 2^30 */ + + /* + * The final t[4] cannot overflow because cc is 0 or 1, + * and cc can be 1 only if s != 0. + */ + } + + d[0] = t[0]; + d[1] = t[1]; + d[2] = t[2]; + d[3] = t[3]; + d[4] = t[4]; + +#endif +} + +/* + * Montgomery squaring in the field; currently a basic wrapper around + * multiplication (inline, should be optimized away). + * TODO: see if some extra speed can be gained here. + */ +static inline void +f256_montysquare(uint64_t *d, const uint64_t *a) +{ + f256_montymul(d, a, a); +} + +/* + * Convert to Montgomery representation. + */ +static void +f256_tomonty(uint64_t *d, const uint64_t *a) +{ + /* + * R2 = 2^520 mod p. + * If R = 2^260 mod p, then R2 = R^2 mod p; and the Montgomery + * multiplication of a by R2 is: a*R2/R = a*R mod p, i.e. the + * conversion to Montgomery representation. + */ + static const uint64_t R2[] = { + 0x0000000000300, 0xFFFFFFFF00000, 0xFFFFEFFFFFFFB, + 0xFDFFFFFFFFFFF, 0x0000004FFFFFF + }; + + f256_montymul(d, a, R2); +} + +/* + * Convert from Montgomery representation. + */ +static void +f256_frommonty(uint64_t *d, const uint64_t *a) +{ + /* + * Montgomery multiplication by 1 is division by 2^260 modulo p. + */ + static const uint64_t one[] = { 1, 0, 0, 0, 0 }; + + f256_montymul(d, a, one); +} + +/* + * Inversion in the field. If the source value is 0 modulo p, then this + * returns 0 or p. This function uses Montgomery representation. + */ +static void +f256_invert(uint64_t *d, const uint64_t *a) +{ + /* + * We compute a^(p-2) mod p. The exponent pattern (from high to + * low) is: + * - 32 bits of value 1 + * - 31 bits of value 0 + * - 1 bit of value 1 + * - 96 bits of value 0 + * - 94 bits of value 1 + * - 1 bit of value 0 + * - 1 bit of value 1 + * To speed up the square-and-multiply algorithm, we precompute + * a^(2^31-1). + */ + + uint64_t r[5], t[5]; + int i; + + memcpy(t, a, sizeof t); + for (i = 0; i < 30; i ++) { + f256_montysquare(t, t); + f256_montymul(t, t, a); + } + + memcpy(r, t, sizeof t); + for (i = 224; i >= 0; i --) { + f256_montysquare(r, r); + switch (i) { + case 0: + case 2: + case 192: + case 224: + f256_montymul(r, r, a); + break; + case 3: + case 34: + case 65: + f256_montymul(r, r, t); + break; + } + } + memcpy(d, r, sizeof r); +} + +/* + * Finalize reduction. + * Input value should be partially reduced. + * On output, limbs a[0] to a[3] fit on 52 bits each, limb a[4] fits + * on 48 bits, and the integer is less than p. + */ +static inline void +f256_final_reduce(uint64_t *a) +{ + uint64_t r[5], t[5], w, cc; + int i; + + /* + * Propagate carries to ensure that limbs 0 to 3 fit on 52 bits. + */ + cc = 0; + for (i = 0; i < 5; i ++) { + w = a[i] + cc; + r[i] = w & MASK52; + cc = w >> 52; + } + + /* + * We compute t = r + (2^256 - p) = r + 2^224 - 2^192 - 2^96 + 1. + * If t < 2^256, then r < p, and we return r. Otherwise, we + * want to return r - p = t - 2^256. + */ + + /* + * Add 2^224 + 1, and propagate carries to ensure that limbs + * t[0] to t[3] fit in 52 bits each. + */ + w = r[0] + 1; + t[0] = w & MASK52; + cc = w >> 52; + w = r[1] + cc; + t[1] = w & MASK52; + cc = w >> 52; + w = r[2] + cc; + t[2] = w & MASK52; + cc = w >> 52; + w = r[3] + cc; + t[3] = w & MASK52; + cc = w >> 52; + t[4] = r[4] + cc + BIT(16); + + /* + * Subtract 2^192 + 2^96. Since we just added 2^224 + 1, the + * result cannot be negative. + */ + w = t[1] - BIT(44); + t[1] = w & MASK52; + cc = w >> 63; + w = t[2] - cc; + t[2] = w & MASK52; + cc = w >> 63; + w = t[3] - BIT(36) - cc; + t[3] = w & MASK52; + cc = w >> 63; + t[4] -= cc; + + /* + * If the top limb t[4] fits on 48 bits, then r[] is already + * in the proper range. Otherwise, t[] is the value to return + * (truncated to 256 bits). + */ + cc = -(t[4] >> 48); + t[4] &= MASK48; + for (i = 0; i < 5; i ++) { + a[i] = r[i] ^ (cc & (r[i] ^ t[i])); + } +} + +/* + * Points in affine and Jacobian coordinates. + * + * - In affine coordinates, the point-at-infinity cannot be encoded. + * - Jacobian coordinates (X,Y,Z) correspond to affine (X/Z^2,Y/Z^3); + * if Z = 0 then this is the point-at-infinity. + */ +typedef struct { + uint64_t x[5]; + uint64_t y[5]; +} p256_affine; + +typedef struct { + uint64_t x[5]; + uint64_t y[5]; + uint64_t z[5]; +} p256_jacobian; + +/* + * Decode a field element (unsigned big endian notation). + */ +static void +f256_decode(uint64_t *a, const unsigned char *buf) +{ + uint64_t w0, w1, w2, w3; + + w3 = br_dec64be(buf + 0); + w2 = br_dec64be(buf + 8); + w1 = br_dec64be(buf + 16); + w0 = br_dec64be(buf + 24); + a[0] = w0 & MASK52; + a[1] = ((w0 >> 52) | (w1 << 12)) & MASK52; + a[2] = ((w1 >> 40) | (w2 << 24)) & MASK52; + a[3] = ((w2 >> 28) | (w3 << 36)) & MASK52; + a[4] = w3 >> 16; +} + +/* + * Encode a field element (unsigned big endian notation). The field + * element MUST be fully reduced. + */ +static void +f256_encode(unsigned char *buf, const uint64_t *a) +{ + uint64_t w0, w1, w2, w3; + + w0 = a[0] | (a[1] << 52); + w1 = (a[1] >> 12) | (a[2] << 40); + w2 = (a[2] >> 24) | (a[3] << 28); + w3 = (a[3] >> 36) | (a[4] << 16); + br_enc64be(buf + 0, w3); + br_enc64be(buf + 8, w2); + br_enc64be(buf + 16, w1); + br_enc64be(buf + 24, w0); +} + +/* + * Decode a point. The returned point is in Jacobian coordinates, but + * with z = 1. If the encoding is invalid, or encodes a point which is + * not on the curve, or encodes the point at infinity, then this function + * returns 0. Otherwise, 1 is returned. + * + * The buffer is assumed to have length exactly 65 bytes. + */ +static uint32_t +point_decode(p256_jacobian *P, const unsigned char *buf) +{ + uint64_t x[5], y[5], t[5], x3[5], tt; + uint32_t r; + + /* + * Header byte shall be 0x04. + */ + r = EQ(buf[0], 0x04); + + /* + * Decode X and Y coordinates, and convert them into + * Montgomery representation. + */ + f256_decode(x, buf + 1); + f256_decode(y, buf + 33); + f256_tomonty(x, x); + f256_tomonty(y, y); + + /* + * Verify y^2 = x^3 + A*x + B. In curve P-256, A = -3. + * Note that the Montgomery representation of 0 is 0. We must + * take care to apply the final reduction to make sure we have + * 0 and not p. + */ + f256_montysquare(t, y); + f256_montysquare(x3, x); + f256_montymul(x3, x3, x); + f256_sub(t, t, x3); + f256_add(t, t, x); + f256_add(t, t, x); + f256_add(t, t, x); + f256_sub(t, t, P256_B_MONTY); + f256_final_reduce(t); + tt = t[0] | t[1] | t[2] | t[3] | t[4]; + r &= EQ((uint32_t)(tt | (tt >> 32)), 0); + + /* + * Return the point in Jacobian coordinates (and Montgomery + * representation). + */ + memcpy(P->x, x, sizeof x); + memcpy(P->y, y, sizeof y); + memcpy(P->z, F256_R, sizeof F256_R); + return r; +} + +/* + * Final conversion for a point: + * - The point is converted back to affine coordinates. + * - Final reduction is performed. + * - The point is encoded into the provided buffer. + * + * If the point is the point-at-infinity, all operations are performed, + * but the buffer contents are indeterminate, and 0 is returned. Otherwise, + * the encoded point is written in the buffer, and 1 is returned. + */ +static uint32_t +point_encode(unsigned char *buf, const p256_jacobian *P) +{ + uint64_t t1[5], t2[5], z; + + /* Set t1 = 1/z^2 and t2 = 1/z^3. */ + f256_invert(t2, P->z); + f256_montysquare(t1, t2); + f256_montymul(t2, t2, t1); + + /* Compute affine coordinates x (in t1) and y (in t2). */ + f256_montymul(t1, P->x, t1); + f256_montymul(t2, P->y, t2); + + /* Convert back from Montgomery representation, and finalize + reductions. */ + f256_frommonty(t1, t1); + f256_frommonty(t2, t2); + f256_final_reduce(t1); + f256_final_reduce(t2); + + /* Encode. */ + buf[0] = 0x04; + f256_encode(buf + 1, t1); + f256_encode(buf + 33, t2); + + /* Return success if and only if P->z != 0. */ + z = P->z[0] | P->z[1] | P->z[2] | P->z[3] | P->z[4]; + return NEQ((uint32_t)(z | z >> 32), 0); +} + +/* + * Point doubling in Jacobian coordinates: point P is doubled. + * Note: if the source point is the point-at-infinity, then the result is + * still the point-at-infinity, which is correct. Moreover, if the three + * coordinates were zero, then they still are zero in the returned value. + */ +static void +p256_double(p256_jacobian *P) +{ + /* + * Doubling formulas are: + * + * s = 4*x*y^2 + * m = 3*(x + z^2)*(x - z^2) + * x' = m^2 - 2*s + * y' = m*(s - x') - 8*y^4 + * z' = 2*y*z + * + * These formulas work for all points, including points of order 2 + * and points at infinity: + * - If y = 0 then z' = 0. But there is no such point in P-256 + * anyway. + * - If z = 0 then z' = 0. + */ + uint64_t t1[5], t2[5], t3[5], t4[5]; + + /* + * Compute z^2 in t1. + */ + f256_montysquare(t1, P->z); + + /* + * Compute x-z^2 in t2 and x+z^2 in t1. + */ + f256_add(t2, P->x, t1); + f256_sub(t1, P->x, t1); + + /* + * Compute 3*(x+z^2)*(x-z^2) in t1. + */ + f256_montymul(t3, t1, t2); + f256_add(t1, t3, t3); + f256_add(t1, t3, t1); + + /* + * Compute 4*x*y^2 (in t2) and 2*y^2 (in t3). + */ + f256_montysquare(t3, P->y); + f256_add(t3, t3, t3); + f256_montymul(t2, P->x, t3); + f256_add(t2, t2, t2); + + /* + * Compute x' = m^2 - 2*s. + */ + f256_montysquare(P->x, t1); + f256_sub(P->x, P->x, t2); + f256_sub(P->x, P->x, t2); + + /* + * Compute z' = 2*y*z. + */ + f256_montymul(t4, P->y, P->z); + f256_add(P->z, t4, t4); + f256_partial_reduce(P->z); + + /* + * Compute y' = m*(s - x') - 8*y^4. Note that we already have + * 2*y^2 in t3. + */ + f256_sub(t2, t2, P->x); + f256_montymul(P->y, t1, t2); + f256_montysquare(t4, t3); + f256_add(t4, t4, t4); + f256_sub(P->y, P->y, t4); +} + +/* + * Point addition (Jacobian coordinates): P1 is replaced with P1+P2. + * This function computes the wrong result in the following cases: + * + * - If P1 == 0 but P2 != 0 + * - If P1 != 0 but P2 == 0 + * - If P1 == P2 + * + * In all three cases, P1 is set to the point at infinity. + * + * Returned value is 0 if one of the following occurs: + * + * - P1 and P2 have the same Y coordinate. + * - P1 == 0 and P2 == 0. + * - The Y coordinate of one of the points is 0 and the other point is + * the point at infinity. + * + * The third case cannot actually happen with valid points, since a point + * with Y == 0 is a point of order 2, and there is no point of order 2 on + * curve P-256. + * + * Therefore, assuming that P1 != 0 and P2 != 0 on input, then the caller + * can apply the following: + * + * - If the result is not the point at infinity, then it is correct. + * - Otherwise, if the returned value is 1, then this is a case of + * P1+P2 == 0, so the result is indeed the point at infinity. + * - Otherwise, P1 == P2, so a "double" operation should have been + * performed. + * + * Note that you can get a returned value of 0 with a correct result, + * e.g. if P1 and P2 have the same Y coordinate, but distinct X coordinates. + */ +static uint32_t +p256_add(p256_jacobian *P1, const p256_jacobian *P2) +{ + /* + * Addtions formulas are: + * + * u1 = x1 * z2^2 + * u2 = x2 * z1^2 + * s1 = y1 * z2^3 + * s2 = y2 * z1^3 + * h = u2 - u1 + * r = s2 - s1 + * x3 = r^2 - h^3 - 2 * u1 * h^2 + * y3 = r * (u1 * h^2 - x3) - s1 * h^3 + * z3 = h * z1 * z2 + */ + uint64_t t1[5], t2[5], t3[5], t4[5], t5[5], t6[5], t7[5], tt; + uint32_t ret; + + /* + * Compute u1 = x1*z2^2 (in t1) and s1 = y1*z2^3 (in t3). + */ + f256_montysquare(t3, P2->z); + f256_montymul(t1, P1->x, t3); + f256_montymul(t4, P2->z, t3); + f256_montymul(t3, P1->y, t4); + + /* + * Compute u2 = x2*z1^2 (in t2) and s2 = y2*z1^3 (in t4). + */ + f256_montysquare(t4, P1->z); + f256_montymul(t2, P2->x, t4); + f256_montymul(t5, P1->z, t4); + f256_montymul(t4, P2->y, t5); + + /* + * Compute h = h2 - u1 (in t2) and r = s2 - s1 (in t4). + * We need to test whether r is zero, so we will do some extra + * reduce. + */ + f256_sub(t2, t2, t1); + f256_sub(t4, t4, t3); + f256_final_reduce(t4); + tt = t4[0] | t4[1] | t4[2] | t4[3] | t4[4]; + ret = (uint32_t)(tt | (tt >> 32)); + ret = (ret | -ret) >> 31; + + /* + * Compute u1*h^2 (in t6) and h^3 (in t5); + */ + f256_montysquare(t7, t2); + f256_montymul(t6, t1, t7); + f256_montymul(t5, t7, t2); + + /* + * Compute x3 = r^2 - h^3 - 2*u1*h^2. + */ + f256_montysquare(P1->x, t4); + f256_sub(P1->x, P1->x, t5); + f256_sub(P1->x, P1->x, t6); + f256_sub(P1->x, P1->x, t6); + + /* + * Compute y3 = r*(u1*h^2 - x3) - s1*h^3. + */ + f256_sub(t6, t6, P1->x); + f256_montymul(P1->y, t4, t6); + f256_montymul(t1, t5, t3); + f256_sub(P1->y, P1->y, t1); + + /* + * Compute z3 = h*z1*z2. + */ + f256_montymul(t1, P1->z, P2->z); + f256_montymul(P1->z, t1, t2); + + return ret; +} + +/* + * Point addition (mixed coordinates): P1 is replaced with P1+P2. + * This is a specialised function for the case when P2 is a non-zero point + * in affine coordinates. + * + * This function computes the wrong result in the following cases: + * + * - If P1 == 0 + * - If P1 == P2 + * + * In both cases, P1 is set to the point at infinity. + * + * Returned value is 0 if one of the following occurs: + * + * - P1 and P2 have the same Y (affine) coordinate. + * - The Y coordinate of P2 is 0 and P1 is the point at infinity. + * + * The second case cannot actually happen with valid points, since a point + * with Y == 0 is a point of order 2, and there is no point of order 2 on + * curve P-256. + * + * Therefore, assuming that P1 != 0 on input, then the caller + * can apply the following: + * + * - If the result is not the point at infinity, then it is correct. + * - Otherwise, if the returned value is 1, then this is a case of + * P1+P2 == 0, so the result is indeed the point at infinity. + * - Otherwise, P1 == P2, so a "double" operation should have been + * performed. + * + * Again, a value of 0 may be returned in some cases where the addition + * result is correct. + */ +static uint32_t +p256_add_mixed(p256_jacobian *P1, const p256_affine *P2) +{ + /* + * Addtions formulas are: + * + * u1 = x1 + * u2 = x2 * z1^2 + * s1 = y1 + * s2 = y2 * z1^3 + * h = u2 - u1 + * r = s2 - s1 + * x3 = r^2 - h^3 - 2 * u1 * h^2 + * y3 = r * (u1 * h^2 - x3) - s1 * h^3 + * z3 = h * z1 + */ + uint64_t t1[5], t2[5], t3[5], t4[5], t5[5], t6[5], t7[5], tt; + uint32_t ret; + + /* + * Compute u1 = x1 (in t1) and s1 = y1 (in t3). + */ + memcpy(t1, P1->x, sizeof t1); + memcpy(t3, P1->y, sizeof t3); + + /* + * Compute u2 = x2*z1^2 (in t2) and s2 = y2*z1^3 (in t4). + */ + f256_montysquare(t4, P1->z); + f256_montymul(t2, P2->x, t4); + f256_montymul(t5, P1->z, t4); + f256_montymul(t4, P2->y, t5); + + /* + * Compute h = h2 - u1 (in t2) and r = s2 - s1 (in t4). + * We need to test whether r is zero, so we will do some extra + * reduce. + */ + f256_sub(t2, t2, t1); + f256_sub(t4, t4, t3); + f256_final_reduce(t4); + tt = t4[0] | t4[1] | t4[2] | t4[3] | t4[4]; + ret = (uint32_t)(tt | (tt >> 32)); + ret = (ret | -ret) >> 31; + + /* + * Compute u1*h^2 (in t6) and h^3 (in t5); + */ + f256_montysquare(t7, t2); + f256_montymul(t6, t1, t7); + f256_montymul(t5, t7, t2); + + /* + * Compute x3 = r^2 - h^3 - 2*u1*h^2. + */ + f256_montysquare(P1->x, t4); + f256_sub(P1->x, P1->x, t5); + f256_sub(P1->x, P1->x, t6); + f256_sub(P1->x, P1->x, t6); + + /* + * Compute y3 = r*(u1*h^2 - x3) - s1*h^3. + */ + f256_sub(t6, t6, P1->x); + f256_montymul(P1->y, t4, t6); + f256_montymul(t1, t5, t3); + f256_sub(P1->y, P1->y, t1); + + /* + * Compute z3 = h*z1*z2. + */ + f256_montymul(P1->z, P1->z, t2); + + return ret; +} + +#if 0 +/* unused */ +/* + * Point addition (mixed coordinates, complete): P1 is replaced with P1+P2. + * This is a specialised function for the case when P2 is a non-zero point + * in affine coordinates. + * + * This function returns the correct result in all cases. + */ +static uint32_t +p256_add_complete_mixed(p256_jacobian *P1, const p256_affine *P2) +{ + /* + * Addtions formulas, in the general case, are: + * + * u1 = x1 + * u2 = x2 * z1^2 + * s1 = y1 + * s2 = y2 * z1^3 + * h = u2 - u1 + * r = s2 - s1 + * x3 = r^2 - h^3 - 2 * u1 * h^2 + * y3 = r * (u1 * h^2 - x3) - s1 * h^3 + * z3 = h * z1 + * + * These formulas mishandle the two following cases: + * + * - If P1 is the point-at-infinity (z1 = 0), then z3 is + * incorrectly set to 0. + * + * - If P1 = P2, then u1 = u2 and s1 = s2, and x3, y3 and z3 + * are all set to 0. + * + * However, if P1 + P2 = 0, then u1 = u2 but s1 != s2, and then + * we correctly get z3 = 0 (the point-at-infinity). + * + * To fix the case P1 = 0, we perform at the end a copy of P2 + * over P1, conditional to z1 = 0. + * + * For P1 = P2: in that case, both h and r are set to 0, and + * we get x3, y3 and z3 equal to 0. We can test for that + * occurrence to make a mask which will be all-one if P1 = P2, + * or all-zero otherwise; then we can compute the double of P2 + * and add it, combined with the mask, to (x3,y3,z3). + * + * Using the doubling formulas in p256_double() on (x2,y2), + * simplifying since P2 is affine (i.e. z2 = 1, implicitly), + * we get: + * s = 4*x2*y2^2 + * m = 3*(x2 + 1)*(x2 - 1) + * x' = m^2 - 2*s + * y' = m*(s - x') - 8*y2^4 + * z' = 2*y2 + * which requires only 6 multiplications. Added to the 11 + * multiplications of the normal mixed addition in Jacobian + * coordinates, we get a cost of 17 multiplications in total. + */ + uint64_t t1[5], t2[5], t3[5], t4[5], t5[5], t6[5], t7[5], tt, zz; + int i; + + /* + * Set zz to -1 if P1 is the point at infinity, 0 otherwise. + */ + zz = P1->z[0] | P1->z[1] | P1->z[2] | P1->z[3] | P1->z[4]; + zz = ((zz | -zz) >> 63) - (uint64_t)1; + + /* + * Compute u1 = x1 (in t1) and s1 = y1 (in t3). + */ + memcpy(t1, P1->x, sizeof t1); + memcpy(t3, P1->y, sizeof t3); + + /* + * Compute u2 = x2*z1^2 (in t2) and s2 = y2*z1^3 (in t4). + */ + f256_montysquare(t4, P1->z); + f256_montymul(t2, P2->x, t4); + f256_montymul(t5, P1->z, t4); + f256_montymul(t4, P2->y, t5); + + /* + * Compute h = h2 - u1 (in t2) and r = s2 - s1 (in t4). + * reduce. + */ + f256_sub(t2, t2, t1); + f256_sub(t4, t4, t3); + + /* + * If both h = 0 and r = 0, then P1 = P2, and we want to set + * the mask tt to -1; otherwise, the mask will be 0. + */ + f256_final_reduce(t2); + f256_final_reduce(t4); + tt = t2[0] | t2[1] | t2[2] | t2[3] | t2[4] + | t4[0] | t4[1] | t4[2] | t4[3] | t4[4]; + tt = ((tt | -tt) >> 63) - (uint64_t)1; + + /* + * Compute u1*h^2 (in t6) and h^3 (in t5); + */ + f256_montysquare(t7, t2); + f256_montymul(t6, t1, t7); + f256_montymul(t5, t7, t2); + + /* + * Compute x3 = r^2 - h^3 - 2*u1*h^2. + */ + f256_montysquare(P1->x, t4); + f256_sub(P1->x, P1->x, t5); + f256_sub(P1->x, P1->x, t6); + f256_sub(P1->x, P1->x, t6); + + /* + * Compute y3 = r*(u1*h^2 - x3) - s1*h^3. + */ + f256_sub(t6, t6, P1->x); + f256_montymul(P1->y, t4, t6); + f256_montymul(t1, t5, t3); + f256_sub(P1->y, P1->y, t1); + + /* + * Compute z3 = h*z1. + */ + f256_montymul(P1->z, P1->z, t2); + + /* + * The "double" result, in case P1 = P2. + */ + + /* + * Compute z' = 2*y2 (in t1). + */ + f256_add(t1, P2->y, P2->y); + f256_partial_reduce(t1); + + /* + * Compute 2*(y2^2) (in t2) and s = 4*x2*(y2^2) (in t3). + */ + f256_montysquare(t2, P2->y); + f256_add(t2, t2, t2); + f256_add(t3, t2, t2); + f256_montymul(t3, P2->x, t3); + + /* + * Compute m = 3*(x2^2 - 1) (in t4). + */ + f256_montysquare(t4, P2->x); + f256_sub(t4, t4, F256_R); + f256_add(t5, t4, t4); + f256_add(t4, t4, t5); + + /* + * Compute x' = m^2 - 2*s (in t5). + */ + f256_montysquare(t5, t4); + f256_sub(t5, t3); + f256_sub(t5, t3); + + /* + * Compute y' = m*(s - x') - 8*y2^4 (in t6). + */ + f256_sub(t6, t3, t5); + f256_montymul(t6, t6, t4); + f256_montysquare(t7, t2); + f256_sub(t6, t6, t7); + f256_sub(t6, t6, t7); + + /* + * We now have the alternate (doubling) coordinates in (t5,t6,t1). + * We combine them with (x3,y3,z3). + */ + for (i = 0; i < 5; i ++) { + P1->x[i] |= tt & t5[i]; + P1->y[i] |= tt & t6[i]; + P1->z[i] |= tt & t1[i]; + } + + /* + * If P1 = 0, then we get z3 = 0 (which is invalid); if z1 is 0, + * then we want to replace the result with a copy of P2. The + * test on z1 was done at the start, in the zz mask. + */ + for (i = 0; i < 5; i ++) { + P1->x[i] ^= zz & (P1->x[i] ^ P2->x[i]); + P1->y[i] ^= zz & (P1->y[i] ^ P2->y[i]); + P1->z[i] ^= zz & (P1->z[i] ^ F256_R[i]); + } +} +#endif + +/* + * Inner function for computing a point multiplication. A window is + * provided, with points 1*P to 15*P in affine coordinates. + * + * Assumptions: + * - All provided points are valid points on the curve. + * - Multiplier is non-zero, and smaller than the curve order. + * - Everything is in Montgomery representation. + */ +static void +point_mul_inner(p256_jacobian *R, const p256_affine *W, + const unsigned char *k, size_t klen) +{ + p256_jacobian Q; + uint32_t qz; + + memset(&Q, 0, sizeof Q); + qz = 1; + while (klen -- > 0) { + int i; + unsigned bk; + + bk = *k ++; + for (i = 0; i < 2; i ++) { + uint32_t bits; + uint32_t bnz; + p256_affine T; + p256_jacobian U; + uint32_t n; + int j; + uint64_t m; + + p256_double(&Q); + p256_double(&Q); + p256_double(&Q); + p256_double(&Q); + bits = (bk >> 4) & 0x0F; + bnz = NEQ(bits, 0); + + /* + * Lookup point in window. If the bits are 0, + * we get something invalid, which is not a + * problem because we will use it only if the + * bits are non-zero. + */ + memset(&T, 0, sizeof T); + for (n = 0; n < 15; n ++) { + m = -(uint64_t)EQ(bits, n + 1); + T.x[0] |= m & W[n].x[0]; + T.x[1] |= m & W[n].x[1]; + T.x[2] |= m & W[n].x[2]; + T.x[3] |= m & W[n].x[3]; + T.x[4] |= m & W[n].x[4]; + T.y[0] |= m & W[n].y[0]; + T.y[1] |= m & W[n].y[1]; + T.y[2] |= m & W[n].y[2]; + T.y[3] |= m & W[n].y[3]; + T.y[4] |= m & W[n].y[4]; + } + + U = Q; + p256_add_mixed(&U, &T); + + /* + * If qz is still 1, then Q was all-zeros, and this + * is conserved through p256_double(). + */ + m = -(uint64_t)(bnz & qz); + for (j = 0; j < 5; j ++) { + Q.x[j] ^= m & (Q.x[j] ^ T.x[j]); + Q.y[j] ^= m & (Q.y[j] ^ T.y[j]); + Q.z[j] ^= m & (Q.z[j] ^ F256_R[j]); + } + CCOPY(bnz & ~qz, &Q, &U, sizeof Q); + qz &= ~bnz; + bk <<= 4; + } + } + *R = Q; +} + +/* + * Convert a window from Jacobian to affine coordinates. A single + * field inversion is used. This function works for windows up to + * 32 elements. + * + * The destination array (aff[]) and the source array (jac[]) may + * overlap, provided that the start of aff[] is not after the start of + * jac[]. Even if the arrays do _not_ overlap, the source array is + * modified. + */ +static void +window_to_affine(p256_affine *aff, p256_jacobian *jac, int num) +{ + /* + * Convert the window points to affine coordinates. We use the + * following trick to mutualize the inversion computation: if + * we have z1, z2, z3, and z4, and want to invert all of them, + * we compute u = 1/(z1*z2*z3*z4), and then we have: + * 1/z1 = u*z2*z3*z4 + * 1/z2 = u*z1*z3*z4 + * 1/z3 = u*z1*z2*z4 + * 1/z4 = u*z1*z2*z3 + * + * The partial products are computed recursively: + * + * - on input (z_1,z_2), return (z_2,z_1) and z_1*z_2 + * - on input (z_1,z_2,... z_n): + * recurse on (z_1,z_2,... z_(n/2)) -> r1 and m1 + * recurse on (z_(n/2+1),z_(n/2+2)... z_n) -> r2 and m2 + * multiply elements of r1 by m2 -> s1 + * multiply elements of r2 by m1 -> s2 + * return r1||r2 and m1*m2 + * + * In the example below, we suppose that we have 14 elements. + * Let z1, z2,... zE be the 14 values to invert (index noted in + * hexadecimal, starting at 1). + * + * - Depth 1: + * swap(z1, z2); z12 = z1*z2 + * swap(z3, z4); z34 = z3*z4 + * swap(z5, z6); z56 = z5*z6 + * swap(z7, z8); z78 = z7*z8 + * swap(z9, zA); z9A = z9*zA + * swap(zB, zC); zBC = zB*zC + * swap(zD, zE); zDE = zD*zE + * + * - Depth 2: + * z1 <- z1*z34, z2 <- z2*z34, z3 <- z3*z12, z4 <- z4*z12 + * z1234 = z12*z34 + * z5 <- z5*z78, z6 <- z6*z78, z7 <- z7*z56, z8 <- z8*z56 + * z5678 = z56*z78 + * z9 <- z9*zBC, zA <- zA*zBC, zB <- zB*z9A, zC <- zC*z9A + * z9ABC = z9A*zBC + * + * - Depth 3: + * z1 <- z1*z5678, z2 <- z2*z5678, z3 <- z3*z5678, z4 <- z4*z5678 + * z5 <- z5*z1234, z6 <- z6*z1234, z7 <- z7*z1234, z8 <- z8*z1234 + * z12345678 = z1234*z5678 + * z9 <- z9*zDE, zA <- zA*zDE, zB <- zB*zDE, zC <- zC*zDE + * zD <- zD*z9ABC, zE*z9ABC + * z9ABCDE = z9ABC*zDE + * + * - Depth 4: + * multiply z1..z8 by z9ABCDE + * multiply z9..zE by z12345678 + * final z = z12345678*z9ABCDE + */ + + uint64_t z[16][5]; + int i, k, s; +#define zt (z[15]) +#define zu (z[14]) +#define zv (z[13]) + + /* + * First recursion step (pairwise swapping and multiplication). + * If there is an odd number of elements, then we "invent" an + * extra one with coordinate Z = 1 (in Montgomery representation). + */ + for (i = 0; (i + 1) < num; i += 2) { + memcpy(zt, jac[i].z, sizeof zt); + memcpy(jac[i].z, jac[i + 1].z, sizeof zt); + memcpy(jac[i + 1].z, zt, sizeof zt); + f256_montymul(z[i >> 1], jac[i].z, jac[i + 1].z); + } + if ((num & 1) != 0) { + memcpy(z[num >> 1], jac[num - 1].z, sizeof zt); + memcpy(jac[num - 1].z, F256_R, sizeof F256_R); + } + + /* + * Perform further recursion steps. At the entry of each step, + * the process has been done for groups of 's' points. The + * integer k is the log2 of s. + */ + for (k = 1, s = 2; s < num; k ++, s <<= 1) { + int n; + + for (i = 0; i < num; i ++) { + f256_montymul(jac[i].z, jac[i].z, z[(i >> k) ^ 1]); + } + n = (num + s - 1) >> k; + for (i = 0; i < (n >> 1); i ++) { + f256_montymul(z[i], z[i << 1], z[(i << 1) + 1]); + } + if ((n & 1) != 0) { + memmove(z[n >> 1], z[n], sizeof zt); + } + } + + /* + * Invert the final result, and convert all points. + */ + f256_invert(zt, z[0]); + for (i = 0; i < num; i ++) { + f256_montymul(zv, jac[i].z, zt); + f256_montysquare(zu, zv); + f256_montymul(zv, zv, zu); + f256_montymul(aff[i].x, jac[i].x, zu); + f256_montymul(aff[i].y, jac[i].y, zv); + } +} + +/* + * Multiply the provided point by an integer. + * Assumptions: + * - Source point is a valid curve point. + * - Source point is not the point-at-infinity. + * - Integer is not 0, and is lower than the curve order. + * If these conditions are not met, then the result is indeterminate + * (but the process is still constant-time). + */ +static void +p256_mul(p256_jacobian *P, const unsigned char *k, size_t klen) +{ + union { + p256_affine aff[15]; + p256_jacobian jac[15]; + } window; + int i; + + /* + * Compute window, in Jacobian coordinates. + */ + window.jac[0] = *P; + for (i = 2; i < 16; i ++) { + window.jac[i - 1] = window.jac[(i >> 1) - 1]; + if ((i & 1) == 0) { + p256_double(&window.jac[i - 1]); + } else { + p256_add(&window.jac[i - 1], &window.jac[i >> 1]); + } + } + + /* + * Convert the window points to affine coordinates. Point + * window[0] is the source point, already in affine coordinates. + */ + window_to_affine(window.aff, window.jac, 15); + + /* + * Perform point multiplication. + */ + point_mul_inner(P, window.aff, k, klen); +} + +/* + * Precomputed window for the conventional generator: P256_Gwin[n] + * contains (n+1)*G (affine coordinates, in Montgomery representation). + */ +static const p256_affine P256_Gwin[] = { + { + { 0x30D418A9143C1, 0xC4FEDB60179E7, 0x62251075BA95F, + 0x5C669FB732B77, 0x08905F76B5375 }, + { 0x5357CE95560A8, 0x43A19E45CDDF2, 0x21F3258B4AB8E, + 0xD8552E88688DD, 0x0571FF18A5885 } + }, + { + { 0x46D410DDD64DF, 0x0B433827D8500, 0x1490D9AA6AE3C, + 0xA3A832205038D, 0x06BB32E52DCF3 }, + { 0x48D361BEE1A57, 0xB7B236FF82F36, 0x042DBE152CD7C, + 0xA3AA9A8FB0E92, 0x08C577517A5B8 } + }, + { + { 0x3F904EEBC1272, 0x9E87D81FBFFAC, 0xCBBC98B027F84, + 0x47E46AD77DD87, 0x06936A3FD6FF7 }, + { 0x5C1FC983A7EBD, 0xC3861FE1AB04C, 0x2EE98E583E47A, + 0xC06A88208311A, 0x05F06A2AB587C } + }, + { + { 0xB50D46918DCC5, 0xD7623C17374B0, 0x100AF24650A6E, + 0x76ABCDAACACE8, 0x077362F591B01 }, + { 0xF24CE4CBABA68, 0x17AD6F4472D96, 0xDDD22E1762847, + 0x862EB6C36DEE5, 0x04B14C39CC5AB } + }, + { + { 0x8AAEC45C61F5C, 0x9D4B9537DBE1B, 0x76C20C90EC649, + 0x3C7D41CB5AAD0, 0x0907960649052 }, + { 0x9B4AE7BA4F107, 0xF75EB882BEB30, 0x7A1F6873C568E, + 0x915C540A9877E, 0x03A076BB9DD1E } + }, + { + { 0x47373E77664A1, 0xF246CEE3E4039, 0x17A3AD55AE744, + 0x673C50A961A5B, 0x03074B5964213 }, + { 0x6220D377E44BA, 0x30DFF14B593D3, 0x639F11299C2B5, + 0x75F5424D44CEF, 0x04C9916DEA07F } + }, + { + { 0x354EA0173B4F1, 0x3C23C00F70746, 0x23BB082BD2021, + 0xE03E43EAAB50C, 0x03BA5119D3123 }, + { 0xD0303F5B9D4DE, 0x17DA67BDD2847, 0xC941956742F2F, + 0x8670F933BDC77, 0x0AEDD9164E240 } + }, + { + { 0x4CD19499A78FB, 0x4BF9B345527F1, 0x2CFC6B462AB5C, + 0x30CDF90F02AF0, 0x0763891F62652 }, + { 0xA3A9532D49775, 0xD7F9EBA15F59D, 0x60BBF021E3327, + 0xF75C23C7B84BE, 0x06EC12F2C706D } + }, + { + { 0x6E8F264E20E8E, 0xC79A7A84175C9, 0xC8EB00ABE6BFE, + 0x16A4CC09C0444, 0x005B3081D0C4E }, + { 0x777AA45F33140, 0xDCE5D45E31EB7, 0xB12F1A56AF7BE, + 0xF9B2B6E019A88, 0x086659CDFD835 } + }, + { + { 0xDBD19DC21EC8C, 0x94FCF81392C18, 0x250B4998F9868, + 0x28EB37D2CD648, 0x0C61C947E4B34 }, + { 0x407880DD9E767, 0x0C83FBE080C2B, 0x9BE5D2C43A899, + 0xAB4EF7D2D6577, 0x08719A555B3B4 } + }, + { + { 0x260A6245E4043, 0x53E7FDFE0EA7D, 0xAC1AB59DE4079, + 0x072EFF3A4158D, 0x0E7090F1949C9 }, + { 0x85612B944E886, 0xE857F61C81A76, 0xAD643D250F939, + 0x88DAC0DAA891E, 0x089300244125B } + }, + { + { 0x1AA7D26977684, 0x58A345A3304B7, 0x37385EABDEDEF, + 0x155E409D29DEE, 0x0EE1DF780B83E }, + { 0x12D91CBB5B437, 0x65A8956370CAC, 0xDE6D66170ED2F, + 0xAC9B8228CFA8A, 0x0FF57C95C3238 } + }, + { + { 0x25634B2ED7097, 0x9156FD30DCCC4, 0x9E98110E35676, + 0x7594CBCD43F55, 0x038477ACC395B }, + { 0x2B90C00EE17FF, 0xF842ED2E33575, 0x1F5BC16874838, + 0x7968CD06422BD, 0x0BC0876AB9E7B } + }, + { + { 0xA35BB0CF664AF, 0x68F9707E3A242, 0x832660126E48F, + 0x72D2717BF54C6, 0x0AAE7333ED12C }, + { 0x2DB7995D586B1, 0xE732237C227B5, 0x65E7DBBE29569, + 0xBBBD8E4193E2A, 0x052706DC3EAA1 } + }, + { + { 0xD8B7BC60055BE, 0xD76E27E4B72BC, 0x81937003CC23E, + 0xA090E337424E4, 0x02AA0E43EAD3D }, + { 0x524F6383C45D2, 0x422A41B2540B8, 0x8A4797D766355, + 0xDF444EFA6DE77, 0x0042170A9079A } + }, +}; + +/* + * Multiply the conventional generator of the curve by the provided + * integer. Return is written in *P. + * + * Assumptions: + * - Integer is not 0, and is lower than the curve order. + * If this conditions is not met, then the result is indeterminate + * (but the process is still constant-time). + */ +static void +p256_mulgen(p256_jacobian *P, const unsigned char *k, size_t klen) +{ + point_mul_inner(P, P256_Gwin, k, klen); +} + +/* + * Return 1 if all of the following hold: + * - klen <= 32 + * - k != 0 + * - k is lower than the curve order + * Otherwise, return 0. + * + * Constant-time behaviour: only klen may be observable. + */ +static uint32_t +check_scalar(const unsigned char *k, size_t klen) +{ + uint32_t z; + int32_t c; + size_t u; + + if (klen > 32) { + return 0; + } + z = 0; + for (u = 0; u < klen; u ++) { + z |= k[u]; + } + if (klen == 32) { + c = 0; + for (u = 0; u < klen; u ++) { + c |= -(int32_t)EQ0(c) & CMP(k[u], P256_N[u]); + } + } else { + c = -1; + } + return NEQ(z, 0) & LT0(c); +} + +static uint32_t +api_mul(unsigned char *G, size_t Glen, + const unsigned char *k, size_t klen, int curve) +{ + uint32_t r; + p256_jacobian P; + + (void)curve; + if (Glen != 65) { + return 0; + } + r = check_scalar(k, klen); + r &= point_decode(&P, G); + p256_mul(&P, k, klen); + r &= point_encode(G, &P); + return r; +} + +static size_t +api_mulgen(unsigned char *R, + const unsigned char *k, size_t klen, int curve) +{ + p256_jacobian P; + + (void)curve; + p256_mulgen(&P, k, klen); + point_encode(R, &P); + return 65; +} + +static uint32_t +api_muladd(unsigned char *A, const unsigned char *B, size_t len, + const unsigned char *x, size_t xlen, + const unsigned char *y, size_t ylen, int curve) +{ + /* + * We might want to use Shamir's trick here: make a composite + * window of u*P+v*Q points, to merge the two doubling-ladders + * into one. This, however, has some complications: + * + * - During the computation, we may hit the point-at-infinity. + * Thus, we would need p256_add_complete_mixed() (complete + * formulas for point addition), with a higher cost (17 muls + * instead of 11). + * + * - A 4-bit window would be too large, since it would involve + * 16*16-1 = 255 points. For the same window size as in the + * p256_mul() case, we would need to reduce the window size + * to 2 bits, and thus perform twice as many non-doubling + * point additions. + * + * - The window may itself contain the point-at-infinity, and + * thus cannot be in all generality be made of affine points. + * Instead, we would need to make it a window of points in + * Jacobian coordinates. Even p256_add_complete_mixed() would + * be inappropriate. + * + * For these reasons, the code below performs two separate + * point multiplications, then computes the final point addition + * (which is both a "normal" addition, and a doubling, to handle + * all cases). + */ + + p256_jacobian P, Q; + uint32_t r, t, s; + uint64_t z; + + (void)curve; + if (len != 65) { + return 0; + } + r = point_decode(&P, A); + p256_mul(&P, x, xlen); + if (B == NULL) { + p256_mulgen(&Q, y, ylen); + } else { + r &= point_decode(&Q, B); + p256_mul(&Q, y, ylen); + } + + /* + * The final addition may fail in case both points are equal. + */ + t = p256_add(&P, &Q); + f256_final_reduce(P.z); + z = P.z[0] | P.z[1] | P.z[2] | P.z[3] | P.z[4]; + s = EQ((uint32_t)(z | (z >> 32)), 0); + p256_double(&Q); + + /* + * If s is 1 then either P+Q = 0 (t = 1) or P = Q (t = 0). So we + * have the following: + * + * s = 0, t = 0 return P (normal addition) + * s = 0, t = 1 return P (normal addition) + * s = 1, t = 0 return Q (a 'double' case) + * s = 1, t = 1 report an error (P+Q = 0) + */ + CCOPY(s & ~t, &P, &Q, sizeof Q); + point_encode(A, &P); + r &= ~(s & t); + return r; +} + +/* see bearssl_ec.h */ +const br_ec_impl br_ec_p256_m62 = { + (uint32_t)0x00800000, + &api_generator, + &api_order, + &api_xoff, + &api_mul, + &api_mulgen, + &api_muladd +}; + +/* see bearssl_ec.h */ +const br_ec_impl * +br_ec_p256_m62_get(void) +{ + return &br_ec_p256_m62; +} + +#else + +/* see bearssl_ec.h */ +const br_ec_impl * +br_ec_p256_m62_get(void) +{ + return 0; +} + +#endif + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_p256_m64.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_p256_m64.c new file mode 100644 index 000000000..91035cd73 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_p256_m64.c @@ -0,0 +1,1735 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +#if BR_INT128 || BR_UMUL128 + +#if BR_UMUL128 +#include +#endif + +static const unsigned char P256_G[] = { + 0x04, 0x6B, 0x17, 0xD1, 0xF2, 0xE1, 0x2C, 0x42, 0x47, 0xF8, + 0xBC, 0xE6, 0xE5, 0x63, 0xA4, 0x40, 0xF2, 0x77, 0x03, 0x7D, + 0x81, 0x2D, 0xEB, 0x33, 0xA0, 0xF4, 0xA1, 0x39, 0x45, 0xD8, + 0x98, 0xC2, 0x96, 0x4F, 0xE3, 0x42, 0xE2, 0xFE, 0x1A, 0x7F, + 0x9B, 0x8E, 0xE7, 0xEB, 0x4A, 0x7C, 0x0F, 0x9E, 0x16, 0x2B, + 0xCE, 0x33, 0x57, 0x6B, 0x31, 0x5E, 0xCE, 0xCB, 0xB6, 0x40, + 0x68, 0x37, 0xBF, 0x51, 0xF5 +}; + +static const unsigned char P256_N[] = { + 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xBC, 0xE6, 0xFA, 0xAD, + 0xA7, 0x17, 0x9E, 0x84, 0xF3, 0xB9, 0xCA, 0xC2, 0xFC, 0x63, + 0x25, 0x51 +}; + +static const unsigned char * +api_generator(int curve, size_t *len) +{ + (void)curve; + *len = sizeof P256_G; + return P256_G; +} + +static const unsigned char * +api_order(int curve, size_t *len) +{ + (void)curve; + *len = sizeof P256_N; + return P256_N; +} + +static size_t +api_xoff(int curve, size_t *len) +{ + (void)curve; + *len = 32; + return 1; +} + +/* + * A field element is encoded as four 64-bit integers, in basis 2^64. + * Values may reach up to 2^256-1. Montgomery multiplication is used. + */ + +/* R = 2^256 mod p */ +static const uint64_t F256_R[] = { + 0x0000000000000001, 0xFFFFFFFF00000000, + 0xFFFFFFFFFFFFFFFF, 0x00000000FFFFFFFE +}; + +/* Curve equation is y^2 = x^3 - 3*x + B. This constant is B*R mod p + (Montgomery representation of B). */ +static const uint64_t P256_B_MONTY[] = { + 0xD89CDF6229C4BDDF, 0xACF005CD78843090, + 0xE5A220ABF7212ED6, 0xDC30061D04874834 +}; + +/* + * Addition in the field. + */ +static inline void +f256_add(uint64_t *d, const uint64_t *a, const uint64_t *b) +{ +#if BR_INT128 + unsigned __int128 w; + uint64_t t; + + w = (unsigned __int128)a[0] + b[0]; + d[0] = (uint64_t)w; + w = (unsigned __int128)a[1] + b[1] + (w >> 64); + d[1] = (uint64_t)w; + w = (unsigned __int128)a[2] + b[2] + (w >> 64); + d[2] = (uint64_t)w; + w = (unsigned __int128)a[3] + b[3] + (w >> 64); + d[3] = (uint64_t)w; + t = (uint64_t)(w >> 64); + + /* + * 2^256 = 2^224 - 2^192 - 2^96 + 1 in the field. + */ + w = (unsigned __int128)d[0] + t; + d[0] = (uint64_t)w; + w = (unsigned __int128)d[1] + (w >> 64) - (t << 32); + d[1] = (uint64_t)w; + /* Here, carry "w >> 64" can only be 0 or -1 */ + w = (unsigned __int128)d[2] - ((w >> 64) & 1); + d[2] = (uint64_t)w; + /* Again, carry is 0 or -1 */ + d[3] += (uint64_t)(w >> 64) + (t << 32) - t; + +#elif BR_UMUL128 + + unsigned char cc; + uint64_t t; + + cc = _addcarry_u64(0, a[0], b[0], &d[0]); + cc = _addcarry_u64(cc, a[1], b[1], &d[1]); + cc = _addcarry_u64(cc, a[2], b[2], &d[2]); + cc = _addcarry_u64(cc, a[3], b[3], &d[3]); + + /* + * If there is a carry, then we want to subtract p, which we + * do by adding 2^256 - p. + */ + t = cc; + cc = _addcarry_u64(cc, d[0], 0, &d[0]); + cc = _addcarry_u64(cc, d[1], -(t << 32), &d[1]); + cc = _addcarry_u64(cc, d[2], -t, &d[2]); + (void)_addcarry_u64(cc, d[3], (t << 32) - (t << 1), &d[3]); + +#endif +} + +/* + * Subtraction in the field. + */ +static inline void +f256_sub(uint64_t *d, const uint64_t *a, const uint64_t *b) +{ +#if BR_INT128 + + unsigned __int128 w; + uint64_t t; + + w = (unsigned __int128)a[0] - b[0]; + d[0] = (uint64_t)w; + w = (unsigned __int128)a[1] - b[1] - ((w >> 64) & 1); + d[1] = (uint64_t)w; + w = (unsigned __int128)a[2] - b[2] - ((w >> 64) & 1); + d[2] = (uint64_t)w; + w = (unsigned __int128)a[3] - b[3] - ((w >> 64) & 1); + d[3] = (uint64_t)w; + t = (uint64_t)(w >> 64) & 1; + + /* + * p = 2^256 - 2^224 + 2^192 + 2^96 - 1. + */ + w = (unsigned __int128)d[0] - t; + d[0] = (uint64_t)w; + w = (unsigned __int128)d[1] + (t << 32) - ((w >> 64) & 1); + d[1] = (uint64_t)w; + /* Here, carry "w >> 64" can only be 0 or +1 */ + w = (unsigned __int128)d[2] + (w >> 64); + d[2] = (uint64_t)w; + /* Again, carry is 0 or +1 */ + d[3] += (uint64_t)(w >> 64) - (t << 32) + t; + +#elif BR_UMUL128 + + unsigned char cc; + uint64_t t; + + cc = _subborrow_u64(0, a[0], b[0], &d[0]); + cc = _subborrow_u64(cc, a[1], b[1], &d[1]); + cc = _subborrow_u64(cc, a[2], b[2], &d[2]); + cc = _subborrow_u64(cc, a[3], b[3], &d[3]); + + /* + * If there is a carry, then we need to add p. + */ + t = cc; + cc = _addcarry_u64(0, d[0], -t, &d[0]); + cc = _addcarry_u64(cc, d[1], (-t) >> 32, &d[1]); + cc = _addcarry_u64(cc, d[2], 0, &d[2]); + (void)_addcarry_u64(cc, d[3], t - (t << 32), &d[3]); + +#endif +} + +/* + * Montgomery multiplication in the field. + */ +static void +f256_montymul(uint64_t *d, const uint64_t *a, const uint64_t *b) +{ +#if BR_INT128 + + uint64_t x, f, t0, t1, t2, t3, t4; + unsigned __int128 z, ff; + int i; + + /* + * When computing d <- d + a[u]*b, we also add f*p such + * that d + a[u]*b + f*p is a multiple of 2^64. Since + * p = -1 mod 2^64, we can compute f = d[0] + a[u]*b[0] mod 2^64. + */ + + /* + * Step 1: t <- (a[0]*b + f*p) / 2^64 + * We have f = a[0]*b[0] mod 2^64. Since p = -1 mod 2^64, this + * ensures that (a[0]*b + f*p) is a multiple of 2^64. + * + * We also have: f*p = f*2^256 - f*2^224 + f*2^192 + f*2^96 - f. + */ + x = a[0]; + z = (unsigned __int128)b[0] * x; + f = (uint64_t)z; + z = (unsigned __int128)b[1] * x + (z >> 64) + (uint64_t)(f << 32); + t0 = (uint64_t)z; + z = (unsigned __int128)b[2] * x + (z >> 64) + (uint64_t)(f >> 32); + t1 = (uint64_t)z; + z = (unsigned __int128)b[3] * x + (z >> 64) + f; + t2 = (uint64_t)z; + t3 = (uint64_t)(z >> 64); + ff = ((unsigned __int128)f << 64) - ((unsigned __int128)f << 32); + z = (unsigned __int128)t2 + (uint64_t)ff; + t2 = (uint64_t)z; + z = (unsigned __int128)t3 + (z >> 64) + (ff >> 64); + t3 = (uint64_t)z; + t4 = (uint64_t)(z >> 64); + + /* + * Steps 2 to 4: t <- (t + a[i]*b + f*p) / 2^64 + */ + for (i = 1; i < 4; i ++) { + x = a[i]; + + /* t <- (t + x*b - f) / 2^64 */ + z = (unsigned __int128)b[0] * x + t0; + f = (uint64_t)z; + z = (unsigned __int128)b[1] * x + t1 + (z >> 64); + t0 = (uint64_t)z; + z = (unsigned __int128)b[2] * x + t2 + (z >> 64); + t1 = (uint64_t)z; + z = (unsigned __int128)b[3] * x + t3 + (z >> 64); + t2 = (uint64_t)z; + z = t4 + (z >> 64); + t3 = (uint64_t)z; + t4 = (uint64_t)(z >> 64); + + /* t <- t + f*2^32, carry in the upper half of z */ + z = (unsigned __int128)t0 + (uint64_t)(f << 32); + t0 = (uint64_t)z; + z = (z >> 64) + (unsigned __int128)t1 + (uint64_t)(f >> 32); + t1 = (uint64_t)z; + + /* t <- t + f*2^192 - f*2^160 + f*2^128 */ + ff = ((unsigned __int128)f << 64) + - ((unsigned __int128)f << 32) + f; + z = (z >> 64) + (unsigned __int128)t2 + (uint64_t)ff; + t2 = (uint64_t)z; + z = (unsigned __int128)t3 + (z >> 64) + (ff >> 64); + t3 = (uint64_t)z; + t4 += (uint64_t)(z >> 64); + } + + /* + * At that point, we have computed t = (a*b + F*p) / 2^256, where + * F is a 256-bit integer whose limbs are the "f" coefficients + * in the steps above. We have: + * a <= 2^256-1 + * b <= 2^256-1 + * F <= 2^256-1 + * Hence: + * a*b + F*p <= (2^256-1)*(2^256-1) + p*(2^256-1) + * a*b + F*p <= 2^256*(2^256 - 2 + p) + 1 - p + * Therefore: + * t < 2^256 + p - 2 + * Since p < 2^256, it follows that: + * t4 can be only 0 or 1 + * t - p < 2^256 + * We can therefore subtract p from t, conditionally on t4, to + * get a nonnegative result that fits on 256 bits. + */ + z = (unsigned __int128)t0 + t4; + t0 = (uint64_t)z; + z = (unsigned __int128)t1 - (t4 << 32) + (z >> 64); + t1 = (uint64_t)z; + z = (unsigned __int128)t2 - (z >> 127); + t2 = (uint64_t)z; + t3 = t3 - (uint64_t)(z >> 127) - t4 + (t4 << 32); + + d[0] = t0; + d[1] = t1; + d[2] = t2; + d[3] = t3; + +#elif BR_UMUL128 + + uint64_t x, f, t0, t1, t2, t3, t4; + uint64_t zl, zh, ffl, ffh; + unsigned char k, m; + int i; + + /* + * When computing d <- d + a[u]*b, we also add f*p such + * that d + a[u]*b + f*p is a multiple of 2^64. Since + * p = -1 mod 2^64, we can compute f = d[0] + a[u]*b[0] mod 2^64. + */ + + /* + * Step 1: t <- (a[0]*b + f*p) / 2^64 + * We have f = a[0]*b[0] mod 2^64. Since p = -1 mod 2^64, this + * ensures that (a[0]*b + f*p) is a multiple of 2^64. + * + * We also have: f*p = f*2^256 - f*2^224 + f*2^192 + f*2^96 - f. + */ + x = a[0]; + + zl = _umul128(b[0], x, &zh); + f = zl; + t0 = zh; + + zl = _umul128(b[1], x, &zh); + k = _addcarry_u64(0, zl, t0, &zl); + (void)_addcarry_u64(k, zh, 0, &zh); + k = _addcarry_u64(0, zl, f << 32, &zl); + (void)_addcarry_u64(k, zh, 0, &zh); + t0 = zl; + t1 = zh; + + zl = _umul128(b[2], x, &zh); + k = _addcarry_u64(0, zl, t1, &zl); + (void)_addcarry_u64(k, zh, 0, &zh); + k = _addcarry_u64(0, zl, f >> 32, &zl); + (void)_addcarry_u64(k, zh, 0, &zh); + t1 = zl; + t2 = zh; + + zl = _umul128(b[3], x, &zh); + k = _addcarry_u64(0, zl, t2, &zl); + (void)_addcarry_u64(k, zh, 0, &zh); + k = _addcarry_u64(0, zl, f, &zl); + (void)_addcarry_u64(k, zh, 0, &zh); + t2 = zl; + t3 = zh; + + t4 = _addcarry_u64(0, t3, f, &t3); + k = _subborrow_u64(0, t2, f << 32, &t2); + k = _subborrow_u64(k, t3, f >> 32, &t3); + (void)_subborrow_u64(k, t4, 0, &t4); + + /* + * Steps 2 to 4: t <- (t + a[i]*b + f*p) / 2^64 + */ + for (i = 1; i < 4; i ++) { + x = a[i]; + /* f = t0 + x * b[0]; -- computed below */ + + /* t <- (t + x*b - f) / 2^64 */ + zl = _umul128(b[0], x, &zh); + k = _addcarry_u64(0, zl, t0, &f); + (void)_addcarry_u64(k, zh, 0, &t0); + + zl = _umul128(b[1], x, &zh); + k = _addcarry_u64(0, zl, t0, &zl); + (void)_addcarry_u64(k, zh, 0, &zh); + k = _addcarry_u64(0, zl, t1, &t0); + (void)_addcarry_u64(k, zh, 0, &t1); + + zl = _umul128(b[2], x, &zh); + k = _addcarry_u64(0, zl, t1, &zl); + (void)_addcarry_u64(k, zh, 0, &zh); + k = _addcarry_u64(0, zl, t2, &t1); + (void)_addcarry_u64(k, zh, 0, &t2); + + zl = _umul128(b[3], x, &zh); + k = _addcarry_u64(0, zl, t2, &zl); + (void)_addcarry_u64(k, zh, 0, &zh); + k = _addcarry_u64(0, zl, t3, &t2); + (void)_addcarry_u64(k, zh, 0, &t3); + + t4 = _addcarry_u64(0, t3, t4, &t3); + + /* t <- t + f*2^32, carry in k */ + k = _addcarry_u64(0, t0, f << 32, &t0); + k = _addcarry_u64(k, t1, f >> 32, &t1); + + /* t <- t + f*2^192 - f*2^160 + f*2^128 */ + m = _subborrow_u64(0, f, f << 32, &ffl); + (void)_subborrow_u64(m, f, f >> 32, &ffh); + k = _addcarry_u64(k, t2, ffl, &t2); + k = _addcarry_u64(k, t3, ffh, &t3); + (void)_addcarry_u64(k, t4, 0, &t4); + } + + /* + * At that point, we have computed t = (a*b + F*p) / 2^256, where + * F is a 256-bit integer whose limbs are the "f" coefficients + * in the steps above. We have: + * a <= 2^256-1 + * b <= 2^256-1 + * F <= 2^256-1 + * Hence: + * a*b + F*p <= (2^256-1)*(2^256-1) + p*(2^256-1) + * a*b + F*p <= 2^256*(2^256 - 2 + p) + 1 - p + * Therefore: + * t < 2^256 + p - 2 + * Since p < 2^256, it follows that: + * t4 can be only 0 or 1 + * t - p < 2^256 + * We can therefore subtract p from t, conditionally on t4, to + * get a nonnegative result that fits on 256 bits. + */ + k = _addcarry_u64(0, t0, t4, &t0); + k = _addcarry_u64(k, t1, -(t4 << 32), &t1); + k = _addcarry_u64(k, t2, -t4, &t2); + (void)_addcarry_u64(k, t3, (t4 << 32) - (t4 << 1), &t3); + + d[0] = t0; + d[1] = t1; + d[2] = t2; + d[3] = t3; + +#endif +} + +/* + * Montgomery squaring in the field; currently a basic wrapper around + * multiplication (inline, should be optimized away). + * TODO: see if some extra speed can be gained here. + */ +static inline void +f256_montysquare(uint64_t *d, const uint64_t *a) +{ + f256_montymul(d, a, a); +} + +/* + * Convert to Montgomery representation. + */ +static void +f256_tomonty(uint64_t *d, const uint64_t *a) +{ + /* + * R2 = 2^512 mod p. + * If R = 2^256 mod p, then R2 = R^2 mod p; and the Montgomery + * multiplication of a by R2 is: a*R2/R = a*R mod p, i.e. the + * conversion to Montgomery representation. + */ + static const uint64_t R2[] = { + 0x0000000000000003, + 0xFFFFFFFBFFFFFFFF, + 0xFFFFFFFFFFFFFFFE, + 0x00000004FFFFFFFD + }; + + f256_montymul(d, a, R2); +} + +/* + * Convert from Montgomery representation. + */ +static void +f256_frommonty(uint64_t *d, const uint64_t *a) +{ + /* + * Montgomery multiplication by 1 is division by 2^256 modulo p. + */ + static const uint64_t one[] = { 1, 0, 0, 0 }; + + f256_montymul(d, a, one); +} + +/* + * Inversion in the field. If the source value is 0 modulo p, then this + * returns 0 or p. This function uses Montgomery representation. + */ +static void +f256_invert(uint64_t *d, const uint64_t *a) +{ + /* + * We compute a^(p-2) mod p. The exponent pattern (from high to + * low) is: + * - 32 bits of value 1 + * - 31 bits of value 0 + * - 1 bit of value 1 + * - 96 bits of value 0 + * - 94 bits of value 1 + * - 1 bit of value 0 + * - 1 bit of value 1 + * To speed up the square-and-multiply algorithm, we precompute + * a^(2^31-1). + */ + + uint64_t r[4], t[4]; + int i; + + memcpy(t, a, sizeof t); + for (i = 0; i < 30; i ++) { + f256_montysquare(t, t); + f256_montymul(t, t, a); + } + + memcpy(r, t, sizeof t); + for (i = 224; i >= 0; i --) { + f256_montysquare(r, r); + switch (i) { + case 0: + case 2: + case 192: + case 224: + f256_montymul(r, r, a); + break; + case 3: + case 34: + case 65: + f256_montymul(r, r, t); + break; + } + } + memcpy(d, r, sizeof r); +} + +/* + * Finalize reduction. + * Input value fits on 256 bits. This function subtracts p if and only + * if the input is greater than or equal to p. + */ +static inline void +f256_final_reduce(uint64_t *a) +{ +#if BR_INT128 + + uint64_t t0, t1, t2, t3, cc; + unsigned __int128 z; + + /* + * We add 2^224 - 2^192 - 2^96 + 1 to a. If there is no carry, + * then a < p; otherwise, the addition result we computed is + * the value we must return. + */ + z = (unsigned __int128)a[0] + 1; + t0 = (uint64_t)z; + z = (unsigned __int128)a[1] + (z >> 64) - ((uint64_t)1 << 32); + t1 = (uint64_t)z; + z = (unsigned __int128)a[2] - (z >> 127); + t2 = (uint64_t)z; + z = (unsigned __int128)a[3] - (z >> 127) + 0xFFFFFFFF; + t3 = (uint64_t)z; + cc = -(uint64_t)(z >> 64); + + a[0] ^= cc & (a[0] ^ t0); + a[1] ^= cc & (a[1] ^ t1); + a[2] ^= cc & (a[2] ^ t2); + a[3] ^= cc & (a[3] ^ t3); + +#elif BR_UMUL128 + + uint64_t t0, t1, t2, t3, m; + unsigned char k; + + k = _addcarry_u64(0, a[0], (uint64_t)1, &t0); + k = _addcarry_u64(k, a[1], -((uint64_t)1 << 32), &t1); + k = _addcarry_u64(k, a[2], -(uint64_t)1, &t2); + k = _addcarry_u64(k, a[3], ((uint64_t)1 << 32) - 2, &t3); + m = -(uint64_t)k; + + a[0] ^= m & (a[0] ^ t0); + a[1] ^= m & (a[1] ^ t1); + a[2] ^= m & (a[2] ^ t2); + a[3] ^= m & (a[3] ^ t3); + +#endif +} + +/* + * Points in affine and Jacobian coordinates. + * + * - In affine coordinates, the point-at-infinity cannot be encoded. + * - Jacobian coordinates (X,Y,Z) correspond to affine (X/Z^2,Y/Z^3); + * if Z = 0 then this is the point-at-infinity. + */ +typedef struct { + uint64_t x[4]; + uint64_t y[4]; +} p256_affine; + +typedef struct { + uint64_t x[4]; + uint64_t y[4]; + uint64_t z[4]; +} p256_jacobian; + +/* + * Decode a point. The returned point is in Jacobian coordinates, but + * with z = 1. If the encoding is invalid, or encodes a point which is + * not on the curve, or encodes the point at infinity, then this function + * returns 0. Otherwise, 1 is returned. + * + * The buffer is assumed to have length exactly 65 bytes. + */ +static uint32_t +point_decode(p256_jacobian *P, const unsigned char *buf) +{ + uint64_t x[4], y[4], t[4], x3[4], tt; + uint32_t r; + + /* + * Header byte shall be 0x04. + */ + r = EQ(buf[0], 0x04); + + /* + * Decode X and Y coordinates, and convert them into + * Montgomery representation. + */ + x[3] = br_dec64be(buf + 1); + x[2] = br_dec64be(buf + 9); + x[1] = br_dec64be(buf + 17); + x[0] = br_dec64be(buf + 25); + y[3] = br_dec64be(buf + 33); + y[2] = br_dec64be(buf + 41); + y[1] = br_dec64be(buf + 49); + y[0] = br_dec64be(buf + 57); + f256_tomonty(x, x); + f256_tomonty(y, y); + + /* + * Verify y^2 = x^3 + A*x + B. In curve P-256, A = -3. + * Note that the Montgomery representation of 0 is 0. We must + * take care to apply the final reduction to make sure we have + * 0 and not p. + */ + f256_montysquare(t, y); + f256_montysquare(x3, x); + f256_montymul(x3, x3, x); + f256_sub(t, t, x3); + f256_add(t, t, x); + f256_add(t, t, x); + f256_add(t, t, x); + f256_sub(t, t, P256_B_MONTY); + f256_final_reduce(t); + tt = t[0] | t[1] | t[2] | t[3]; + r &= EQ((uint32_t)(tt | (tt >> 32)), 0); + + /* + * Return the point in Jacobian coordinates (and Montgomery + * representation). + */ + memcpy(P->x, x, sizeof x); + memcpy(P->y, y, sizeof y); + memcpy(P->z, F256_R, sizeof F256_R); + return r; +} + +/* + * Final conversion for a point: + * - The point is converted back to affine coordinates. + * - Final reduction is performed. + * - The point is encoded into the provided buffer. + * + * If the point is the point-at-infinity, all operations are performed, + * but the buffer contents are indeterminate, and 0 is returned. Otherwise, + * the encoded point is written in the buffer, and 1 is returned. + */ +static uint32_t +point_encode(unsigned char *buf, const p256_jacobian *P) +{ + uint64_t t1[4], t2[4], z; + + /* Set t1 = 1/z^2 and t2 = 1/z^3. */ + f256_invert(t2, P->z); + f256_montysquare(t1, t2); + f256_montymul(t2, t2, t1); + + /* Compute affine coordinates x (in t1) and y (in t2). */ + f256_montymul(t1, P->x, t1); + f256_montymul(t2, P->y, t2); + + /* Convert back from Montgomery representation, and finalize + reductions. */ + f256_frommonty(t1, t1); + f256_frommonty(t2, t2); + f256_final_reduce(t1); + f256_final_reduce(t2); + + /* Encode. */ + buf[0] = 0x04; + br_enc64be(buf + 1, t1[3]); + br_enc64be(buf + 9, t1[2]); + br_enc64be(buf + 17, t1[1]); + br_enc64be(buf + 25, t1[0]); + br_enc64be(buf + 33, t2[3]); + br_enc64be(buf + 41, t2[2]); + br_enc64be(buf + 49, t2[1]); + br_enc64be(buf + 57, t2[0]); + + /* Return success if and only if P->z != 0. */ + z = P->z[0] | P->z[1] | P->z[2] | P->z[3]; + return NEQ((uint32_t)(z | z >> 32), 0); +} + +/* + * Point doubling in Jacobian coordinates: point P is doubled. + * Note: if the source point is the point-at-infinity, then the result is + * still the point-at-infinity, which is correct. Moreover, if the three + * coordinates were zero, then they still are zero in the returned value. + * + * (Note: this is true even without the final reduction: if the three + * coordinates are encoded as four words of value zero each, then the + * result will also have all-zero coordinate encodings, not the alternate + * encoding as the integer p.) + */ +static void +p256_double(p256_jacobian *P) +{ + /* + * Doubling formulas are: + * + * s = 4*x*y^2 + * m = 3*(x + z^2)*(x - z^2) + * x' = m^2 - 2*s + * y' = m*(s - x') - 8*y^4 + * z' = 2*y*z + * + * These formulas work for all points, including points of order 2 + * and points at infinity: + * - If y = 0 then z' = 0. But there is no such point in P-256 + * anyway. + * - If z = 0 then z' = 0. + */ + uint64_t t1[4], t2[4], t3[4], t4[4]; + + /* + * Compute z^2 in t1. + */ + f256_montysquare(t1, P->z); + + /* + * Compute x-z^2 in t2 and x+z^2 in t1. + */ + f256_add(t2, P->x, t1); + f256_sub(t1, P->x, t1); + + /* + * Compute 3*(x+z^2)*(x-z^2) in t1. + */ + f256_montymul(t3, t1, t2); + f256_add(t1, t3, t3); + f256_add(t1, t3, t1); + + /* + * Compute 4*x*y^2 (in t2) and 2*y^2 (in t3). + */ + f256_montysquare(t3, P->y); + f256_add(t3, t3, t3); + f256_montymul(t2, P->x, t3); + f256_add(t2, t2, t2); + + /* + * Compute x' = m^2 - 2*s. + */ + f256_montysquare(P->x, t1); + f256_sub(P->x, P->x, t2); + f256_sub(P->x, P->x, t2); + + /* + * Compute z' = 2*y*z. + */ + f256_montymul(t4, P->y, P->z); + f256_add(P->z, t4, t4); + + /* + * Compute y' = m*(s - x') - 8*y^4. Note that we already have + * 2*y^2 in t3. + */ + f256_sub(t2, t2, P->x); + f256_montymul(P->y, t1, t2); + f256_montysquare(t4, t3); + f256_add(t4, t4, t4); + f256_sub(P->y, P->y, t4); +} + +/* + * Point addition (Jacobian coordinates): P1 is replaced with P1+P2. + * This function computes the wrong result in the following cases: + * + * - If P1 == 0 but P2 != 0 + * - If P1 != 0 but P2 == 0 + * - If P1 == P2 + * + * In all three cases, P1 is set to the point at infinity. + * + * Returned value is 0 if one of the following occurs: + * + * - P1 and P2 have the same Y coordinate. + * - P1 == 0 and P2 == 0. + * - The Y coordinate of one of the points is 0 and the other point is + * the point at infinity. + * + * The third case cannot actually happen with valid points, since a point + * with Y == 0 is a point of order 2, and there is no point of order 2 on + * curve P-256. + * + * Therefore, assuming that P1 != 0 and P2 != 0 on input, then the caller + * can apply the following: + * + * - If the result is not the point at infinity, then it is correct. + * - Otherwise, if the returned value is 1, then this is a case of + * P1+P2 == 0, so the result is indeed the point at infinity. + * - Otherwise, P1 == P2, so a "double" operation should have been + * performed. + * + * Note that you can get a returned value of 0 with a correct result, + * e.g. if P1 and P2 have the same Y coordinate, but distinct X coordinates. + */ +static uint32_t +p256_add(p256_jacobian *P1, const p256_jacobian *P2) +{ + /* + * Addtions formulas are: + * + * u1 = x1 * z2^2 + * u2 = x2 * z1^2 + * s1 = y1 * z2^3 + * s2 = y2 * z1^3 + * h = u2 - u1 + * r = s2 - s1 + * x3 = r^2 - h^3 - 2 * u1 * h^2 + * y3 = r * (u1 * h^2 - x3) - s1 * h^3 + * z3 = h * z1 * z2 + */ + uint64_t t1[4], t2[4], t3[4], t4[4], t5[4], t6[4], t7[4], tt; + uint32_t ret; + + /* + * Compute u1 = x1*z2^2 (in t1) and s1 = y1*z2^3 (in t3). + */ + f256_montysquare(t3, P2->z); + f256_montymul(t1, P1->x, t3); + f256_montymul(t4, P2->z, t3); + f256_montymul(t3, P1->y, t4); + + /* + * Compute u2 = x2*z1^2 (in t2) and s2 = y2*z1^3 (in t4). + */ + f256_montysquare(t4, P1->z); + f256_montymul(t2, P2->x, t4); + f256_montymul(t5, P1->z, t4); + f256_montymul(t4, P2->y, t5); + + /* + * Compute h = h2 - u1 (in t2) and r = s2 - s1 (in t4). + * We need to test whether r is zero, so we will do some extra + * reduce. + */ + f256_sub(t2, t2, t1); + f256_sub(t4, t4, t3); + f256_final_reduce(t4); + tt = t4[0] | t4[1] | t4[2] | t4[3]; + ret = (uint32_t)(tt | (tt >> 32)); + ret = (ret | -ret) >> 31; + + /* + * Compute u1*h^2 (in t6) and h^3 (in t5); + */ + f256_montysquare(t7, t2); + f256_montymul(t6, t1, t7); + f256_montymul(t5, t7, t2); + + /* + * Compute x3 = r^2 - h^3 - 2*u1*h^2. + */ + f256_montysquare(P1->x, t4); + f256_sub(P1->x, P1->x, t5); + f256_sub(P1->x, P1->x, t6); + f256_sub(P1->x, P1->x, t6); + + /* + * Compute y3 = r*(u1*h^2 - x3) - s1*h^3. + */ + f256_sub(t6, t6, P1->x); + f256_montymul(P1->y, t4, t6); + f256_montymul(t1, t5, t3); + f256_sub(P1->y, P1->y, t1); + + /* + * Compute z3 = h*z1*z2. + */ + f256_montymul(t1, P1->z, P2->z); + f256_montymul(P1->z, t1, t2); + + return ret; +} + +/* + * Point addition (mixed coordinates): P1 is replaced with P1+P2. + * This is a specialised function for the case when P2 is a non-zero point + * in affine coordinates. + * + * This function computes the wrong result in the following cases: + * + * - If P1 == 0 + * - If P1 == P2 + * + * In both cases, P1 is set to the point at infinity. + * + * Returned value is 0 if one of the following occurs: + * + * - P1 and P2 have the same Y (affine) coordinate. + * - The Y coordinate of P2 is 0 and P1 is the point at infinity. + * + * The second case cannot actually happen with valid points, since a point + * with Y == 0 is a point of order 2, and there is no point of order 2 on + * curve P-256. + * + * Therefore, assuming that P1 != 0 on input, then the caller + * can apply the following: + * + * - If the result is not the point at infinity, then it is correct. + * - Otherwise, if the returned value is 1, then this is a case of + * P1+P2 == 0, so the result is indeed the point at infinity. + * - Otherwise, P1 == P2, so a "double" operation should have been + * performed. + * + * Again, a value of 0 may be returned in some cases where the addition + * result is correct. + */ +static uint32_t +p256_add_mixed(p256_jacobian *P1, const p256_affine *P2) +{ + /* + * Addtions formulas are: + * + * u1 = x1 + * u2 = x2 * z1^2 + * s1 = y1 + * s2 = y2 * z1^3 + * h = u2 - u1 + * r = s2 - s1 + * x3 = r^2 - h^3 - 2 * u1 * h^2 + * y3 = r * (u1 * h^2 - x3) - s1 * h^3 + * z3 = h * z1 + */ + uint64_t t1[4], t2[4], t3[4], t4[4], t5[4], t6[4], t7[4], tt; + uint32_t ret; + + /* + * Compute u1 = x1 (in t1) and s1 = y1 (in t3). + */ + memcpy(t1, P1->x, sizeof t1); + memcpy(t3, P1->y, sizeof t3); + + /* + * Compute u2 = x2*z1^2 (in t2) and s2 = y2*z1^3 (in t4). + */ + f256_montysquare(t4, P1->z); + f256_montymul(t2, P2->x, t4); + f256_montymul(t5, P1->z, t4); + f256_montymul(t4, P2->y, t5); + + /* + * Compute h = h2 - u1 (in t2) and r = s2 - s1 (in t4). + * We need to test whether r is zero, so we will do some extra + * reduce. + */ + f256_sub(t2, t2, t1); + f256_sub(t4, t4, t3); + f256_final_reduce(t4); + tt = t4[0] | t4[1] | t4[2] | t4[3]; + ret = (uint32_t)(tt | (tt >> 32)); + ret = (ret | -ret) >> 31; + + /* + * Compute u1*h^2 (in t6) and h^3 (in t5); + */ + f256_montysquare(t7, t2); + f256_montymul(t6, t1, t7); + f256_montymul(t5, t7, t2); + + /* + * Compute x3 = r^2 - h^3 - 2*u1*h^2. + */ + f256_montysquare(P1->x, t4); + f256_sub(P1->x, P1->x, t5); + f256_sub(P1->x, P1->x, t6); + f256_sub(P1->x, P1->x, t6); + + /* + * Compute y3 = r*(u1*h^2 - x3) - s1*h^3. + */ + f256_sub(t6, t6, P1->x); + f256_montymul(P1->y, t4, t6); + f256_montymul(t1, t5, t3); + f256_sub(P1->y, P1->y, t1); + + /* + * Compute z3 = h*z1*z2. + */ + f256_montymul(P1->z, P1->z, t2); + + return ret; +} + +#if 0 +/* unused */ +/* + * Point addition (mixed coordinates, complete): P1 is replaced with P1+P2. + * This is a specialised function for the case when P2 is a non-zero point + * in affine coordinates. + * + * This function returns the correct result in all cases. + */ +static uint32_t +p256_add_complete_mixed(p256_jacobian *P1, const p256_affine *P2) +{ + /* + * Addtions formulas, in the general case, are: + * + * u1 = x1 + * u2 = x2 * z1^2 + * s1 = y1 + * s2 = y2 * z1^3 + * h = u2 - u1 + * r = s2 - s1 + * x3 = r^2 - h^3 - 2 * u1 * h^2 + * y3 = r * (u1 * h^2 - x3) - s1 * h^3 + * z3 = h * z1 + * + * These formulas mishandle the two following cases: + * + * - If P1 is the point-at-infinity (z1 = 0), then z3 is + * incorrectly set to 0. + * + * - If P1 = P2, then u1 = u2 and s1 = s2, and x3, y3 and z3 + * are all set to 0. + * + * However, if P1 + P2 = 0, then u1 = u2 but s1 != s2, and then + * we correctly get z3 = 0 (the point-at-infinity). + * + * To fix the case P1 = 0, we perform at the end a copy of P2 + * over P1, conditional to z1 = 0. + * + * For P1 = P2: in that case, both h and r are set to 0, and + * we get x3, y3 and z3 equal to 0. We can test for that + * occurrence to make a mask which will be all-one if P1 = P2, + * or all-zero otherwise; then we can compute the double of P2 + * and add it, combined with the mask, to (x3,y3,z3). + * + * Using the doubling formulas in p256_double() on (x2,y2), + * simplifying since P2 is affine (i.e. z2 = 1, implicitly), + * we get: + * s = 4*x2*y2^2 + * m = 3*(x2 + 1)*(x2 - 1) + * x' = m^2 - 2*s + * y' = m*(s - x') - 8*y2^4 + * z' = 2*y2 + * which requires only 6 multiplications. Added to the 11 + * multiplications of the normal mixed addition in Jacobian + * coordinates, we get a cost of 17 multiplications in total. + */ + uint64_t t1[4], t2[4], t3[4], t4[4], t5[4], t6[4], t7[4], tt, zz; + int i; + + /* + * Set zz to -1 if P1 is the point at infinity, 0 otherwise. + */ + zz = P1->z[0] | P1->z[1] | P1->z[2] | P1->z[3]; + zz = ((zz | -zz) >> 63) - (uint64_t)1; + + /* + * Compute u1 = x1 (in t1) and s1 = y1 (in t3). + */ + memcpy(t1, P1->x, sizeof t1); + memcpy(t3, P1->y, sizeof t3); + + /* + * Compute u2 = x2*z1^2 (in t2) and s2 = y2*z1^3 (in t4). + */ + f256_montysquare(t4, P1->z); + f256_montymul(t2, P2->x, t4); + f256_montymul(t5, P1->z, t4); + f256_montymul(t4, P2->y, t5); + + /* + * Compute h = h2 - u1 (in t2) and r = s2 - s1 (in t4). + * reduce. + */ + f256_sub(t2, t2, t1); + f256_sub(t4, t4, t3); + + /* + * If both h = 0 and r = 0, then P1 = P2, and we want to set + * the mask tt to -1; otherwise, the mask will be 0. + */ + f256_final_reduce(t2); + f256_final_reduce(t4); + tt = t2[0] | t2[1] | t2[2] | t2[3] | t4[0] | t4[1] | t4[2] | t4[3]; + tt = ((tt | -tt) >> 63) - (uint64_t)1; + + /* + * Compute u1*h^2 (in t6) and h^3 (in t5); + */ + f256_montysquare(t7, t2); + f256_montymul(t6, t1, t7); + f256_montymul(t5, t7, t2); + + /* + * Compute x3 = r^2 - h^3 - 2*u1*h^2. + */ + f256_montysquare(P1->x, t4); + f256_sub(P1->x, P1->x, t5); + f256_sub(P1->x, P1->x, t6); + f256_sub(P1->x, P1->x, t6); + + /* + * Compute y3 = r*(u1*h^2 - x3) - s1*h^3. + */ + f256_sub(t6, t6, P1->x); + f256_montymul(P1->y, t4, t6); + f256_montymul(t1, t5, t3); + f256_sub(P1->y, P1->y, t1); + + /* + * Compute z3 = h*z1. + */ + f256_montymul(P1->z, P1->z, t2); + + /* + * The "double" result, in case P1 = P2. + */ + + /* + * Compute z' = 2*y2 (in t1). + */ + f256_add(t1, P2->y, P2->y); + + /* + * Compute 2*(y2^2) (in t2) and s = 4*x2*(y2^2) (in t3). + */ + f256_montysquare(t2, P2->y); + f256_add(t2, t2, t2); + f256_add(t3, t2, t2); + f256_montymul(t3, P2->x, t3); + + /* + * Compute m = 3*(x2^2 - 1) (in t4). + */ + f256_montysquare(t4, P2->x); + f256_sub(t4, t4, F256_R); + f256_add(t5, t4, t4); + f256_add(t4, t4, t5); + + /* + * Compute x' = m^2 - 2*s (in t5). + */ + f256_montysquare(t5, t4); + f256_sub(t5, t3); + f256_sub(t5, t3); + + /* + * Compute y' = m*(s - x') - 8*y2^4 (in t6). + */ + f256_sub(t6, t3, t5); + f256_montymul(t6, t6, t4); + f256_montysquare(t7, t2); + f256_sub(t6, t6, t7); + f256_sub(t6, t6, t7); + + /* + * We now have the alternate (doubling) coordinates in (t5,t6,t1). + * We combine them with (x3,y3,z3). + */ + for (i = 0; i < 4; i ++) { + P1->x[i] |= tt & t5[i]; + P1->y[i] |= tt & t6[i]; + P1->z[i] |= tt & t1[i]; + } + + /* + * If P1 = 0, then we get z3 = 0 (which is invalid); if z1 is 0, + * then we want to replace the result with a copy of P2. The + * test on z1 was done at the start, in the zz mask. + */ + for (i = 0; i < 4; i ++) { + P1->x[i] ^= zz & (P1->x[i] ^ P2->x[i]); + P1->y[i] ^= zz & (P1->y[i] ^ P2->y[i]); + P1->z[i] ^= zz & (P1->z[i] ^ F256_R[i]); + } +} +#endif + +/* + * Inner function for computing a point multiplication. A window is + * provided, with points 1*P to 15*P in affine coordinates. + * + * Assumptions: + * - All provided points are valid points on the curve. + * - Multiplier is non-zero, and smaller than the curve order. + * - Everything is in Montgomery representation. + */ +static void +point_mul_inner(p256_jacobian *R, const p256_affine *W, + const unsigned char *k, size_t klen) +{ + p256_jacobian Q; + uint32_t qz; + + memset(&Q, 0, sizeof Q); + qz = 1; + while (klen -- > 0) { + int i; + unsigned bk; + + bk = *k ++; + for (i = 0; i < 2; i ++) { + uint32_t bits; + uint32_t bnz; + p256_affine T; + p256_jacobian U; + uint32_t n; + int j; + uint64_t m; + + p256_double(&Q); + p256_double(&Q); + p256_double(&Q); + p256_double(&Q); + bits = (bk >> 4) & 0x0F; + bnz = NEQ(bits, 0); + + /* + * Lookup point in window. If the bits are 0, + * we get something invalid, which is not a + * problem because we will use it only if the + * bits are non-zero. + */ + memset(&T, 0, sizeof T); + for (n = 0; n < 15; n ++) { + m = -(uint64_t)EQ(bits, n + 1); + T.x[0] |= m & W[n].x[0]; + T.x[1] |= m & W[n].x[1]; + T.x[2] |= m & W[n].x[2]; + T.x[3] |= m & W[n].x[3]; + T.y[0] |= m & W[n].y[0]; + T.y[1] |= m & W[n].y[1]; + T.y[2] |= m & W[n].y[2]; + T.y[3] |= m & W[n].y[3]; + } + + U = Q; + p256_add_mixed(&U, &T); + + /* + * If qz is still 1, then Q was all-zeros, and this + * is conserved through p256_double(). + */ + m = -(uint64_t)(bnz & qz); + for (j = 0; j < 4; j ++) { + Q.x[j] |= m & T.x[j]; + Q.y[j] |= m & T.y[j]; + Q.z[j] |= m & F256_R[j]; + } + CCOPY(bnz & ~qz, &Q, &U, sizeof Q); + qz &= ~bnz; + bk <<= 4; + } + } + *R = Q; +} + +/* + * Convert a window from Jacobian to affine coordinates. A single + * field inversion is used. This function works for windows up to + * 32 elements. + * + * The destination array (aff[]) and the source array (jac[]) may + * overlap, provided that the start of aff[] is not after the start of + * jac[]. Even if the arrays do _not_ overlap, the source array is + * modified. + */ +static void +window_to_affine(p256_affine *aff, p256_jacobian *jac, int num) +{ + /* + * Convert the window points to affine coordinates. We use the + * following trick to mutualize the inversion computation: if + * we have z1, z2, z3, and z4, and want to inverse all of them, + * we compute u = 1/(z1*z2*z3*z4), and then we have: + * 1/z1 = u*z2*z3*z4 + * 1/z2 = u*z1*z3*z4 + * 1/z3 = u*z1*z2*z4 + * 1/z4 = u*z1*z2*z3 + * + * The partial products are computed recursively: + * + * - on input (z_1,z_2), return (z_2,z_1) and z_1*z_2 + * - on input (z_1,z_2,... z_n): + * recurse on (z_1,z_2,... z_(n/2)) -> r1 and m1 + * recurse on (z_(n/2+1),z_(n/2+2)... z_n) -> r2 and m2 + * multiply elements of r1 by m2 -> s1 + * multiply elements of r2 by m1 -> s2 + * return r1||r2 and m1*m2 + * + * In the example below, we suppose that we have 14 elements. + * Let z1, z2,... zE be the 14 values to invert (index noted in + * hexadecimal, starting at 1). + * + * - Depth 1: + * swap(z1, z2); z12 = z1*z2 + * swap(z3, z4); z34 = z3*z4 + * swap(z5, z6); z56 = z5*z6 + * swap(z7, z8); z78 = z7*z8 + * swap(z9, zA); z9A = z9*zA + * swap(zB, zC); zBC = zB*zC + * swap(zD, zE); zDE = zD*zE + * + * - Depth 2: + * z1 <- z1*z34, z2 <- z2*z34, z3 <- z3*z12, z4 <- z4*z12 + * z1234 = z12*z34 + * z5 <- z5*z78, z6 <- z6*z78, z7 <- z7*z56, z8 <- z8*z56 + * z5678 = z56*z78 + * z9 <- z9*zBC, zA <- zA*zBC, zB <- zB*z9A, zC <- zC*z9A + * z9ABC = z9A*zBC + * + * - Depth 3: + * z1 <- z1*z5678, z2 <- z2*z5678, z3 <- z3*z5678, z4 <- z4*z5678 + * z5 <- z5*z1234, z6 <- z6*z1234, z7 <- z7*z1234, z8 <- z8*z1234 + * z12345678 = z1234*z5678 + * z9 <- z9*zDE, zA <- zA*zDE, zB <- zB*zDE, zC <- zC*zDE + * zD <- zD*z9ABC, zE*z9ABC + * z9ABCDE = z9ABC*zDE + * + * - Depth 4: + * multiply z1..z8 by z9ABCDE + * multiply z9..zE by z12345678 + * final z = z12345678*z9ABCDE + */ + + uint64_t z[16][4]; + int i, k, s; +#define zt (z[15]) +#define zu (z[14]) +#define zv (z[13]) + + /* + * First recursion step (pairwise swapping and multiplication). + * If there is an odd number of elements, then we "invent" an + * extra one with coordinate Z = 1 (in Montgomery representation). + */ + for (i = 0; (i + 1) < num; i += 2) { + memcpy(zt, jac[i].z, sizeof zt); + memcpy(jac[i].z, jac[i + 1].z, sizeof zt); + memcpy(jac[i + 1].z, zt, sizeof zt); + f256_montymul(z[i >> 1], jac[i].z, jac[i + 1].z); + } + if ((num & 1) != 0) { + memcpy(z[num >> 1], jac[num - 1].z, sizeof zt); + memcpy(jac[num - 1].z, F256_R, sizeof F256_R); + } + + /* + * Perform further recursion steps. At the entry of each step, + * the process has been done for groups of 's' points. The + * integer k is the log2 of s. + */ + for (k = 1, s = 2; s < num; k ++, s <<= 1) { + int n; + + for (i = 0; i < num; i ++) { + f256_montymul(jac[i].z, jac[i].z, z[(i >> k) ^ 1]); + } + n = (num + s - 1) >> k; + for (i = 0; i < (n >> 1); i ++) { + f256_montymul(z[i], z[i << 1], z[(i << 1) + 1]); + } + if ((n & 1) != 0) { + memmove(z[n >> 1], z[n], sizeof zt); + } + } + + /* + * Invert the final result, and convert all points. + */ + f256_invert(zt, z[0]); + for (i = 0; i < num; i ++) { + f256_montymul(zv, jac[i].z, zt); + f256_montysquare(zu, zv); + f256_montymul(zv, zv, zu); + f256_montymul(aff[i].x, jac[i].x, zu); + f256_montymul(aff[i].y, jac[i].y, zv); + } +} + +/* + * Multiply the provided point by an integer. + * Assumptions: + * - Source point is a valid curve point. + * - Source point is not the point-at-infinity. + * - Integer is not 0, and is lower than the curve order. + * If these conditions are not met, then the result is indeterminate + * (but the process is still constant-time). + */ +static void +p256_mul(p256_jacobian *P, const unsigned char *k, size_t klen) +{ + union { + p256_affine aff[15]; + p256_jacobian jac[15]; + } window; + int i; + + /* + * Compute window, in Jacobian coordinates. + */ + window.jac[0] = *P; + for (i = 2; i < 16; i ++) { + window.jac[i - 1] = window.jac[(i >> 1) - 1]; + if ((i & 1) == 0) { + p256_double(&window.jac[i - 1]); + } else { + p256_add(&window.jac[i - 1], &window.jac[i >> 1]); + } + } + + /* + * Convert the window points to affine coordinates. Point + * window[0] is the source point, already in affine coordinates. + */ + window_to_affine(window.aff, window.jac, 15); + + /* + * Perform point multiplication. + */ + point_mul_inner(P, window.aff, k, klen); +} + +/* + * Precomputed window for the conventional generator: P256_Gwin[n] + * contains (n+1)*G (affine coordinates, in Montgomery representation). + */ +static const p256_affine P256_Gwin[] = { + { + { 0x79E730D418A9143C, 0x75BA95FC5FEDB601, + 0x79FB732B77622510, 0x18905F76A53755C6 }, + { 0xDDF25357CE95560A, 0x8B4AB8E4BA19E45C, + 0xD2E88688DD21F325, 0x8571FF1825885D85 } + }, + { + { 0x850046D410DDD64D, 0xAA6AE3C1A433827D, + 0x732205038D1490D9, 0xF6BB32E43DCF3A3B }, + { 0x2F3648D361BEE1A5, 0x152CD7CBEB236FF8, + 0x19A8FB0E92042DBE, 0x78C577510A5B8A3B } + }, + { + { 0xFFAC3F904EEBC127, 0xB027F84A087D81FB, + 0x66AD77DD87CBBC98, 0x26936A3FB6FF747E }, + { 0xB04C5C1FC983A7EB, 0x583E47AD0861FE1A, + 0x788208311A2EE98E, 0xD5F06A29E587CC07 } + }, + { + { 0x74B0B50D46918DCC, 0x4650A6EDC623C173, + 0x0CDAACACE8100AF2, 0x577362F541B0176B }, + { 0x2D96F24CE4CBABA6, 0x17628471FAD6F447, + 0x6B6C36DEE5DDD22E, 0x84B14C394C5AB863 } + }, + { + { 0xBE1B8AAEC45C61F5, 0x90EC649A94B9537D, + 0x941CB5AAD076C20C, 0xC9079605890523C8 }, + { 0xEB309B4AE7BA4F10, 0x73C568EFE5EB882B, + 0x3540A9877E7A1F68, 0x73A076BB2DD1E916 } + }, + { + { 0x403947373E77664A, 0x55AE744F346CEE3E, + 0xD50A961A5B17A3AD, 0x13074B5954213673 }, + { 0x93D36220D377E44B, 0x299C2B53ADFF14B5, + 0xF424D44CEF639F11, 0xA4C9916D4A07F75F } + }, + { + { 0x0746354EA0173B4F, 0x2BD20213D23C00F7, + 0xF43EAAB50C23BB08, 0x13BA5119C3123E03 }, + { 0x2847D0303F5B9D4D, 0x6742F2F25DA67BDD, + 0xEF933BDC77C94195, 0xEAEDD9156E240867 } + }, + { + { 0x27F14CD19499A78F, 0x462AB5C56F9B3455, + 0x8F90F02AF02CFC6B, 0xB763891EB265230D }, + { 0xF59DA3A9532D4977, 0x21E3327DCF9EBA15, + 0x123C7B84BE60BBF0, 0x56EC12F27706DF76 } + }, + { + { 0x75C96E8F264E20E8, 0xABE6BFED59A7A841, + 0x2CC09C0444C8EB00, 0xE05B3080F0C4E16B }, + { 0x1EB7777AA45F3314, 0x56AF7BEDCE5D45E3, + 0x2B6E019A88B12F1A, 0x086659CDFD835F9B } + }, + { + { 0x2C18DBD19DC21EC8, 0x98F9868A0FCF8139, + 0x737D2CD648250B49, 0xCC61C94724B3428F }, + { 0x0C2B407880DD9E76, 0xC43A8991383FBE08, + 0x5F7D2D65779BE5D2, 0x78719A54EB3B4AB5 } + }, + { + { 0xEA7D260A6245E404, 0x9DE407956E7FDFE0, + 0x1FF3A4158DAC1AB5, 0x3E7090F1649C9073 }, + { 0x1A7685612B944E88, 0x250F939EE57F61C8, + 0x0C0DAA891EAD643D, 0x68930023E125B88E } + }, + { + { 0x04B71AA7D2697768, 0xABDEDEF5CA345A33, + 0x2409D29DEE37385E, 0x4EE1DF77CB83E156 }, + { 0x0CAC12D91CBB5B43, 0x170ED2F6CA895637, + 0x28228CFA8ADE6D66, 0x7FF57C9553238ACA } + }, + { + { 0xCCC425634B2ED709, 0x0E356769856FD30D, + 0xBCBCD43F559E9811, 0x738477AC5395B759 }, + { 0x35752B90C00EE17F, 0x68748390742ED2E3, + 0x7CD06422BD1F5BC1, 0xFBC08769C9E7B797 } + }, + { + { 0xA242A35BB0CF664A, 0x126E48F77F9707E3, + 0x1717BF54C6832660, 0xFAAE7332FD12C72E }, + { 0x27B52DB7995D586B, 0xBE29569E832237C2, + 0xE8E4193E2A65E7DB, 0x152706DC2EAA1BBB } + }, + { + { 0x72BCD8B7BC60055B, 0x03CC23EE56E27E4B, + 0xEE337424E4819370, 0xE2AA0E430AD3DA09 }, + { 0x40B8524F6383C45D, 0xD766355442A41B25, + 0x64EFA6DE778A4797, 0x2042170A7079ADF4 } + } +}; + +/* + * Multiply the conventional generator of the curve by the provided + * integer. Return is written in *P. + * + * Assumptions: + * - Integer is not 0, and is lower than the curve order. + * If this conditions is not met, then the result is indeterminate + * (but the process is still constant-time). + */ +static void +p256_mulgen(p256_jacobian *P, const unsigned char *k, size_t klen) +{ + point_mul_inner(P, P256_Gwin, k, klen); +} + +/* + * Return 1 if all of the following hold: + * - klen <= 32 + * - k != 0 + * - k is lower than the curve order + * Otherwise, return 0. + * + * Constant-time behaviour: only klen may be observable. + */ +static uint32_t +check_scalar(const unsigned char *k, size_t klen) +{ + uint32_t z; + int32_t c; + size_t u; + + if (klen > 32) { + return 0; + } + z = 0; + for (u = 0; u < klen; u ++) { + z |= k[u]; + } + if (klen == 32) { + c = 0; + for (u = 0; u < klen; u ++) { + c |= -(int32_t)EQ0(c) & CMP(k[u], P256_N[u]); + } + } else { + c = -1; + } + return NEQ(z, 0) & LT0(c); +} + +static uint32_t +api_mul(unsigned char *G, size_t Glen, + const unsigned char *k, size_t klen, int curve) +{ + uint32_t r; + p256_jacobian P; + + (void)curve; + if (Glen != 65) { + return 0; + } + r = check_scalar(k, klen); + r &= point_decode(&P, G); + p256_mul(&P, k, klen); + r &= point_encode(G, &P); + return r; +} + +static size_t +api_mulgen(unsigned char *R, + const unsigned char *k, size_t klen, int curve) +{ + p256_jacobian P; + + (void)curve; + p256_mulgen(&P, k, klen); + point_encode(R, &P); + return 65; +} + +static uint32_t +api_muladd(unsigned char *A, const unsigned char *B, size_t len, + const unsigned char *x, size_t xlen, + const unsigned char *y, size_t ylen, int curve) +{ + /* + * We might want to use Shamir's trick here: make a composite + * window of u*P+v*Q points, to merge the two doubling-ladders + * into one. This, however, has some complications: + * + * - During the computation, we may hit the point-at-infinity. + * Thus, we would need p256_add_complete_mixed() (complete + * formulas for point addition), with a higher cost (17 muls + * instead of 11). + * + * - A 4-bit window would be too large, since it would involve + * 16*16-1 = 255 points. For the same window size as in the + * p256_mul() case, we would need to reduce the window size + * to 2 bits, and thus perform twice as many non-doubling + * point additions. + * + * - The window may itself contain the point-at-infinity, and + * thus cannot be in all generality be made of affine points. + * Instead, we would need to make it a window of points in + * Jacobian coordinates. Even p256_add_complete_mixed() would + * be inappropriate. + * + * For these reasons, the code below performs two separate + * point multiplications, then computes the final point addition + * (which is both a "normal" addition, and a doubling, to handle + * all cases). + */ + + p256_jacobian P, Q; + uint32_t r, t, s; + uint64_t z; + + (void)curve; + if (len != 65) { + return 0; + } + r = point_decode(&P, A); + p256_mul(&P, x, xlen); + if (B == NULL) { + p256_mulgen(&Q, y, ylen); + } else { + r &= point_decode(&Q, B); + p256_mul(&Q, y, ylen); + } + + /* + * The final addition may fail in case both points are equal. + */ + t = p256_add(&P, &Q); + f256_final_reduce(P.z); + z = P.z[0] | P.z[1] | P.z[2] | P.z[3]; + s = EQ((uint32_t)(z | (z >> 32)), 0); + p256_double(&Q); + + /* + * If s is 1 then either P+Q = 0 (t = 1) or P = Q (t = 0). So we + * have the following: + * + * s = 0, t = 0 return P (normal addition) + * s = 0, t = 1 return P (normal addition) + * s = 1, t = 0 return Q (a 'double' case) + * s = 1, t = 1 report an error (P+Q = 0) + */ + CCOPY(s & ~t, &P, &Q, sizeof Q); + point_encode(A, &P); + r &= ~(s & t); + return r; +} + +/* see bearssl_ec.h */ +const br_ec_impl br_ec_p256_m64 = { + (uint32_t)0x00800000, + &api_generator, + &api_order, + &api_xoff, + &api_mul, + &api_mulgen, + &api_muladd +}; + +/* see bearssl_ec.h */ +const br_ec_impl * +br_ec_p256_m64_get(void) +{ + return &br_ec_p256_m64; +} + +#else + +/* see bearssl_ec.h */ +const br_ec_impl * +br_ec_p256_m64_get(void) +{ + return 0; +} + +#endif + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_prime_i15.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_prime_i15.c new file mode 100644 index 000000000..160048cc3 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_prime_i15.c @@ -0,0 +1,825 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* + * Parameters for supported curves: + * - field modulus p + * - R^2 mod p (R = 2^(15k) for the smallest k such that R >= p) + * - b*R mod p (b is the second curve equation parameter) + */ + +static const uint16_t P256_P[] = { + 0x0111, + 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x003F, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x1000, 0x0000, 0x4000, 0x7FFF, + 0x7FFF, 0x0001 +}; + +static const uint16_t P256_R2[] = { + 0x0111, + 0x0000, 0x6000, 0x0000, 0x0000, 0x0000, 0x0000, 0x7FFC, 0x7FFF, + 0x7FBF, 0x7FFF, 0x7FBF, 0x7FFF, 0x7FFF, 0x7FFF, 0x77FF, 0x7FFF, + 0x4FFF, 0x0000 +}; + +static const uint16_t P256_B[] = { + 0x0111, + 0x770C, 0x5EEF, 0x29C4, 0x3EC4, 0x6273, 0x0486, 0x4543, 0x3993, + 0x3C01, 0x6B56, 0x212E, 0x57EE, 0x4882, 0x204B, 0x7483, 0x3C16, + 0x0187, 0x0000 +}; + +static const uint16_t P384_P[] = { + 0x0199, + 0x7FFF, 0x7FFF, 0x0003, 0x0000, 0x0000, 0x0000, 0x7FC0, 0x7FFF, + 0x7EFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, + 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, + 0x7FFF, 0x01FF +}; + +static const uint16_t P384_R2[] = { + 0x0199, + 0x1000, 0x0000, 0x0000, 0x7FFF, 0x7FFF, 0x0001, 0x0000, 0x0010, + 0x0000, 0x0000, 0x0000, 0x7F00, 0x7FFF, 0x01FF, 0x0000, 0x1000, + 0x0000, 0x2000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000 +}; + +static const uint16_t P384_B[] = { + 0x0199, + 0x7333, 0x2096, 0x70D1, 0x2310, 0x3020, 0x6197, 0x1464, 0x35BB, + 0x70CA, 0x0117, 0x1920, 0x4136, 0x5FC8, 0x5713, 0x4938, 0x7DD2, + 0x4DD2, 0x4A71, 0x0220, 0x683E, 0x2C87, 0x4DB1, 0x7BFF, 0x6C09, + 0x0452, 0x0084 +}; + +static const uint16_t P521_P[] = { + 0x022B, + 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, + 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, + 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, + 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, + 0x7FFF, 0x7FFF, 0x07FF +}; + +static const uint16_t P521_R2[] = { + 0x022B, + 0x0100, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000 +}; + +static const uint16_t P521_B[] = { + 0x022B, + 0x7002, 0x6A07, 0x751A, 0x228F, 0x71EF, 0x5869, 0x20F4, 0x1EFC, + 0x7357, 0x37E0, 0x4EEC, 0x605E, 0x1652, 0x26F6, 0x31FA, 0x4A8F, + 0x6193, 0x3C2A, 0x3C42, 0x48C7, 0x3489, 0x6771, 0x4C57, 0x5CCD, + 0x2725, 0x545B, 0x503B, 0x5B42, 0x21A0, 0x2534, 0x687E, 0x70E4, + 0x1618, 0x27D7, 0x0465 +}; + +typedef struct { + const uint16_t *p; + const uint16_t *b; + const uint16_t *R2; + uint16_t p0i; + size_t point_len; +} curve_params; + +static inline const curve_params * +id_to_curve(int curve) +{ + static const curve_params pp[] = { + { P256_P, P256_B, P256_R2, 0x0001, 65 }, + { P384_P, P384_B, P384_R2, 0x0001, 97 }, + { P521_P, P521_B, P521_R2, 0x0001, 133 } + }; + + return &pp[curve - BR_EC_secp256r1]; +} + +#define I15_LEN ((BR_MAX_EC_SIZE + 29) / 15) + +/* + * Type for a point in Jacobian coordinates: + * -- three values, x, y and z, in Montgomery representation + * -- affine coordinates are X = x / z^2 and Y = y / z^3 + * -- for the point at infinity, z = 0 + */ +typedef struct { + uint16_t c[3][I15_LEN]; +} jacobian; + +/* + * We use a custom interpreter that uses a dozen registers, and + * only six operations: + * MSET(d, a) copy a into d + * MADD(d, a) d = d+a (modular) + * MSUB(d, a) d = d-a (modular) + * MMUL(d, a, b) d = a*b (Montgomery multiplication) + * MINV(d, a, b) invert d modulo p; a and b are used as scratch registers + * MTZ(d) clear return value if d = 0 + * Destination of MMUL (d) must be distinct from operands (a and b). + * There is no such constraint for MSUB and MADD. + * + * Registers include the operand coordinates, and temporaries. + */ +#define MSET(d, a) (0x0000 + ((d) << 8) + ((a) << 4)) +#define MADD(d, a) (0x1000 + ((d) << 8) + ((a) << 4)) +#define MSUB(d, a) (0x2000 + ((d) << 8) + ((a) << 4)) +#define MMUL(d, a, b) (0x3000 + ((d) << 8) + ((a) << 4) + (b)) +#define MINV(d, a, b) (0x4000 + ((d) << 8) + ((a) << 4) + (b)) +#define MTZ(d) (0x5000 + ((d) << 8)) +#define ENDCODE 0 + +/* + * Registers for the input operands. + */ +#define P1x 0 +#define P1y 1 +#define P1z 2 +#define P2x 3 +#define P2y 4 +#define P2z 5 + +/* + * Alternate names for the first input operand. + */ +#define Px 0 +#define Py 1 +#define Pz 2 + +/* + * Temporaries. + */ +#define t1 6 +#define t2 7 +#define t3 8 +#define t4 9 +#define t5 10 +#define t6 11 +#define t7 12 + +/* + * Extra scratch registers available when there is no second operand (e.g. + * for "double" and "affine"). + */ +#define t8 3 +#define t9 4 +#define t10 5 + +/* + * Doubling formulas are: + * + * s = 4*x*y^2 + * m = 3*(x + z^2)*(x - z^2) + * x' = m^2 - 2*s + * y' = m*(s - x') - 8*y^4 + * z' = 2*y*z + * + * If y = 0 (P has order 2) then this yields infinity (z' = 0), as it + * should. This case should not happen anyway, because our curves have + * prime order, and thus do not contain any point of order 2. + * + * If P is infinity (z = 0), then again the formulas yield infinity, + * which is correct. Thus, this code works for all points. + * + * Cost: 8 multiplications + */ +static const uint16_t code_double[] = { + /* + * Compute z^2 (in t1). + */ + MMUL(t1, Pz, Pz), + + /* + * Compute x-z^2 (in t2) and then x+z^2 (in t1). + */ + MSET(t2, Px), + MSUB(t2, t1), + MADD(t1, Px), + + /* + * Compute m = 3*(x+z^2)*(x-z^2) (in t1). + */ + MMUL(t3, t1, t2), + MSET(t1, t3), + MADD(t1, t3), + MADD(t1, t3), + + /* + * Compute s = 4*x*y^2 (in t2) and 2*y^2 (in t3). + */ + MMUL(t3, Py, Py), + MADD(t3, t3), + MMUL(t2, Px, t3), + MADD(t2, t2), + + /* + * Compute x' = m^2 - 2*s. + */ + MMUL(Px, t1, t1), + MSUB(Px, t2), + MSUB(Px, t2), + + /* + * Compute z' = 2*y*z. + */ + MMUL(t4, Py, Pz), + MSET(Pz, t4), + MADD(Pz, t4), + + /* + * Compute y' = m*(s - x') - 8*y^4. Note that we already have + * 2*y^2 in t3. + */ + MSUB(t2, Px), + MMUL(Py, t1, t2), + MMUL(t4, t3, t3), + MSUB(Py, t4), + MSUB(Py, t4), + + ENDCODE +}; + +/* + * Addtions formulas are: + * + * u1 = x1 * z2^2 + * u2 = x2 * z1^2 + * s1 = y1 * z2^3 + * s2 = y2 * z1^3 + * h = u2 - u1 + * r = s2 - s1 + * x3 = r^2 - h^3 - 2 * u1 * h^2 + * y3 = r * (u1 * h^2 - x3) - s1 * h^3 + * z3 = h * z1 * z2 + * + * If both P1 and P2 are infinity, then z1 == 0 and z2 == 0, implying that + * z3 == 0, so the result is correct. + * If either of P1 or P2 is infinity, but not both, then z3 == 0, which is + * not correct. + * h == 0 only if u1 == u2; this happens in two cases: + * -- if s1 == s2 then P1 and/or P2 is infinity, or P1 == P2 + * -- if s1 != s2 then P1 + P2 == infinity (but neither P1 or P2 is infinity) + * + * Thus, the following situations are not handled correctly: + * -- P1 = 0 and P2 != 0 + * -- P1 != 0 and P2 = 0 + * -- P1 = P2 + * All other cases are properly computed. However, even in "incorrect" + * situations, the three coordinates still are properly formed field + * elements. + * + * The returned flag is cleared if r == 0. This happens in the following + * cases: + * -- Both points are on the same horizontal line (same Y coordinate). + * -- Both points are infinity. + * -- One point is infinity and the other is on line Y = 0. + * The third case cannot happen with our curves (there is no valid point + * on line Y = 0 since that would be a point of order 2). If the two + * source points are non-infinity, then remains only the case where the + * two points are on the same horizontal line. + * + * This allows us to detect the "P1 == P2" case, assuming that P1 != 0 and + * P2 != 0: + * -- If the returned value is not the point at infinity, then it was properly + * computed. + * -- Otherwise, if the returned flag is 1, then P1+P2 = 0, and the result + * is indeed the point at infinity. + * -- Otherwise (result is infinity, flag is 0), then P1 = P2 and we should + * use the 'double' code. + * + * Cost: 16 multiplications + */ +static const uint16_t code_add[] = { + /* + * Compute u1 = x1*z2^2 (in t1) and s1 = y1*z2^3 (in t3). + */ + MMUL(t3, P2z, P2z), + MMUL(t1, P1x, t3), + MMUL(t4, P2z, t3), + MMUL(t3, P1y, t4), + + /* + * Compute u2 = x2*z1^2 (in t2) and s2 = y2*z1^3 (in t4). + */ + MMUL(t4, P1z, P1z), + MMUL(t2, P2x, t4), + MMUL(t5, P1z, t4), + MMUL(t4, P2y, t5), + + /* + * Compute h = u2 - u1 (in t2) and r = s2 - s1 (in t4). + */ + MSUB(t2, t1), + MSUB(t4, t3), + + /* + * Report cases where r = 0 through the returned flag. + */ + MTZ(t4), + + /* + * Compute u1*h^2 (in t6) and h^3 (in t5). + */ + MMUL(t7, t2, t2), + MMUL(t6, t1, t7), + MMUL(t5, t7, t2), + + /* + * Compute x3 = r^2 - h^3 - 2*u1*h^2. + * t1 and t7 can be used as scratch registers. + */ + MMUL(P1x, t4, t4), + MSUB(P1x, t5), + MSUB(P1x, t6), + MSUB(P1x, t6), + + /* + * Compute y3 = r*(u1*h^2 - x3) - s1*h^3. + */ + MSUB(t6, P1x), + MMUL(P1y, t4, t6), + MMUL(t1, t5, t3), + MSUB(P1y, t1), + + /* + * Compute z3 = h*z1*z2. + */ + MMUL(t1, P1z, P2z), + MMUL(P1z, t1, t2), + + ENDCODE +}; + +/* + * Check that the point is on the curve. This code snippet assumes the + * following conventions: + * -- Coordinates x and y have been freshly decoded in P1 (but not + * converted to Montgomery coordinates yet). + * -- P2x, P2y and P2z are set to, respectively, R^2, b*R and 1. + */ +static const uint16_t code_check[] = { + + /* Convert x and y to Montgomery representation. */ + MMUL(t1, P1x, P2x), + MMUL(t2, P1y, P2x), + MSET(P1x, t1), + MSET(P1y, t2), + + /* Compute x^3 in t1. */ + MMUL(t2, P1x, P1x), + MMUL(t1, P1x, t2), + + /* Subtract 3*x from t1. */ + MSUB(t1, P1x), + MSUB(t1, P1x), + MSUB(t1, P1x), + + /* Add b. */ + MADD(t1, P2y), + + /* Compute y^2 in t2. */ + MMUL(t2, P1y, P1y), + + /* Compare y^2 with x^3 - 3*x + b; they must match. */ + MSUB(t1, t2), + MTZ(t1), + + /* Set z to 1 (in Montgomery representation). */ + MMUL(P1z, P2x, P2z), + + ENDCODE +}; + +/* + * Conversion back to affine coordinates. This code snippet assumes that + * the z coordinate of P2 is set to 1 (not in Montgomery representation). + */ +static const uint16_t code_affine[] = { + + /* Save z*R in t1. */ + MSET(t1, P1z), + + /* Compute z^3 in t2. */ + MMUL(t2, P1z, P1z), + MMUL(t3, P1z, t2), + MMUL(t2, t3, P2z), + + /* Invert to (1/z^3) in t2. */ + MINV(t2, t3, t4), + + /* Compute y. */ + MSET(t3, P1y), + MMUL(P1y, t2, t3), + + /* Compute (1/z^2) in t3. */ + MMUL(t3, t2, t1), + + /* Compute x. */ + MSET(t2, P1x), + MMUL(P1x, t2, t3), + + ENDCODE +}; + +static uint32_t +run_code(jacobian *P1, const jacobian *P2, + const curve_params *cc, const uint16_t *code) +{ + uint32_t r; + uint16_t t[13][I15_LEN]; + size_t u; + + r = 1; + + /* + * Copy the two operands in the dedicated registers. + */ + memcpy(t[P1x], P1->c, 3 * I15_LEN * sizeof(uint16_t)); + memcpy(t[P2x], P2->c, 3 * I15_LEN * sizeof(uint16_t)); + + /* + * Run formulas. + */ + for (u = 0;; u ++) { + unsigned op, d, a, b; + + op = code[u]; + if (op == 0) { + break; + } + d = (op >> 8) & 0x0F; + a = (op >> 4) & 0x0F; + b = op & 0x0F; + op >>= 12; + switch (op) { + uint32_t ctl; + size_t plen; + unsigned char tp[(BR_MAX_EC_SIZE + 7) >> 3]; + + case 0: + memcpy(t[d], t[a], I15_LEN * sizeof(uint16_t)); + break; + case 1: + ctl = br_i15_add(t[d], t[a], 1); + ctl |= NOT(br_i15_sub(t[d], cc->p, 0)); + br_i15_sub(t[d], cc->p, ctl); + break; + case 2: + br_i15_add(t[d], cc->p, br_i15_sub(t[d], t[a], 1)); + break; + case 3: + br_i15_montymul(t[d], t[a], t[b], cc->p, cc->p0i); + break; + case 4: + plen = (cc->p[0] - (cc->p[0] >> 4) + 7) >> 3; + br_i15_encode(tp, plen, cc->p); + tp[plen - 1] -= 2; + br_i15_modpow(t[d], tp, plen, + cc->p, cc->p0i, t[a], t[b]); + break; + default: + r &= ~br_i15_iszero(t[d]); + break; + } + } + + /* + * Copy back result. + */ + memcpy(P1->c, t[P1x], 3 * I15_LEN * sizeof(uint16_t)); + return r; +} + +static void +set_one(uint16_t *x, const uint16_t *p) +{ + size_t plen; + + plen = (p[0] + 31) >> 4; + memset(x, 0, plen * sizeof *x); + x[0] = p[0]; + x[1] = 0x0001; +} + +static void +point_zero(jacobian *P, const curve_params *cc) +{ + memset(P, 0, sizeof *P); + P->c[0][0] = P->c[1][0] = P->c[2][0] = cc->p[0]; +} + +static inline void +point_double(jacobian *P, const curve_params *cc) +{ + run_code(P, P, cc, code_double); +} + +static inline uint32_t +point_add(jacobian *P1, const jacobian *P2, const curve_params *cc) +{ + return run_code(P1, P2, cc, code_add); +} + +static void +point_mul(jacobian *P, const unsigned char *x, size_t xlen, + const curve_params *cc) +{ + /* + * We do a simple double-and-add ladder with a 2-bit window + * to make only one add every two doublings. We thus first + * precompute 2P and 3P in some local buffers. + * + * We always perform two doublings and one addition; the + * addition is with P, 2P and 3P and is done in a temporary + * array. + * + * The addition code cannot handle cases where one of the + * operands is infinity, which is the case at the start of the + * ladder. We therefore need to maintain a flag that controls + * this situation. + */ + uint32_t qz; + jacobian P2, P3, Q, T, U; + + memcpy(&P2, P, sizeof P2); + point_double(&P2, cc); + memcpy(&P3, P, sizeof P3); + point_add(&P3, &P2, cc); + + point_zero(&Q, cc); + qz = 1; + while (xlen -- > 0) { + int k; + + for (k = 6; k >= 0; k -= 2) { + uint32_t bits; + uint32_t bnz; + + point_double(&Q, cc); + point_double(&Q, cc); + memcpy(&T, P, sizeof T); + memcpy(&U, &Q, sizeof U); + bits = (*x >> k) & (uint32_t)3; + bnz = NEQ(bits, 0); + CCOPY(EQ(bits, 2), &T, &P2, sizeof T); + CCOPY(EQ(bits, 3), &T, &P3, sizeof T); + point_add(&U, &T, cc); + CCOPY(bnz & qz, &Q, &T, sizeof Q); + CCOPY(bnz & ~qz, &Q, &U, sizeof Q); + qz &= ~bnz; + } + x ++; + } + memcpy(P, &Q, sizeof Q); +} + +/* + * Decode point into Jacobian coordinates. This function does not support + * the point at infinity. If the point is invalid then this returns 0, but + * the coordinates are still set to properly formed field elements. + */ +static uint32_t +point_decode(jacobian *P, const void *src, size_t len, const curve_params *cc) +{ + /* + * Points must use uncompressed format: + * -- first byte is 0x04; + * -- coordinates X and Y use unsigned big-endian, with the same + * length as the field modulus. + * + * We don't support hybrid format (uncompressed, but first byte + * has value 0x06 or 0x07, depending on the least significant bit + * of Y) because it is rather useless, and explicitly forbidden + * by PKIX (RFC 5480, section 2.2). + * + * We don't support compressed format either, because it is not + * much used in practice (there are or were patent-related + * concerns about point compression, which explains the lack of + * generalised support). Also, point compression support would + * need a bit more code. + */ + const unsigned char *buf; + size_t plen, zlen; + uint32_t r; + jacobian Q; + + buf = src; + point_zero(P, cc); + plen = (cc->p[0] - (cc->p[0] >> 4) + 7) >> 3; + if (len != 1 + (plen << 1)) { + return 0; + } + r = br_i15_decode_mod(P->c[0], buf + 1, plen, cc->p); + r &= br_i15_decode_mod(P->c[1], buf + 1 + plen, plen, cc->p); + + /* + * Check first byte. + */ + r &= EQ(buf[0], 0x04); + /* obsolete + r &= EQ(buf[0], 0x04) | (EQ(buf[0] & 0xFE, 0x06) + & ~(uint32_t)(buf[0] ^ buf[plen << 1])); + */ + + /* + * Convert coordinates and check that the point is valid. + */ + zlen = ((cc->p[0] + 31) >> 4) * sizeof(uint16_t); + memcpy(Q.c[0], cc->R2, zlen); + memcpy(Q.c[1], cc->b, zlen); + set_one(Q.c[2], cc->p); + r &= ~run_code(P, &Q, cc, code_check); + return r; +} + +/* + * Encode a point. This method assumes that the point is correct and is + * not the point at infinity. Encoded size is always 1+2*plen, where + * plen is the field modulus length, in bytes. + */ +static void +point_encode(void *dst, const jacobian *P, const curve_params *cc) +{ + unsigned char *buf; + size_t plen; + jacobian Q, T; + + buf = dst; + plen = (cc->p[0] - (cc->p[0] >> 4) + 7) >> 3; + buf[0] = 0x04; + memcpy(&Q, P, sizeof *P); + set_one(T.c[2], cc->p); + run_code(&Q, &T, cc, code_affine); + br_i15_encode(buf + 1, plen, Q.c[0]); + br_i15_encode(buf + 1 + plen, plen, Q.c[1]); +} + +static const br_ec_curve_def * +id_to_curve_def(int curve) +{ + switch (curve) { + case BR_EC_secp256r1: + return &br_secp256r1; + case BR_EC_secp384r1: + return &br_secp384r1; + case BR_EC_secp521r1: + return &br_secp521r1; + } + return NULL; +} + +static const unsigned char * +api_generator(int curve, size_t *len) +{ + const br_ec_curve_def *cd; + + cd = id_to_curve_def(curve); + *len = cd->generator_len; + return cd->generator; +} + +static const unsigned char * +api_order(int curve, size_t *len) +{ + const br_ec_curve_def *cd; + + cd = id_to_curve_def(curve); + *len = cd->order_len; + return cd->order; +} + +static size_t +api_xoff(int curve, size_t *len) +{ + api_generator(curve, len); + *len >>= 1; + return 1; +} + +static uint32_t +api_mul(unsigned char *G, size_t Glen, + const unsigned char *x, size_t xlen, int curve) +{ + uint32_t r; + const curve_params *cc; + jacobian P; + + cc = id_to_curve(curve); + r = point_decode(&P, G, Glen, cc); + point_mul(&P, x, xlen, cc); + if (Glen == cc->point_len) { + point_encode(G, &P, cc); + } + return r; +} + +static size_t +api_mulgen(unsigned char *R, + const unsigned char *x, size_t xlen, int curve) +{ + const unsigned char *G; + size_t Glen; + + G = api_generator(curve, &Glen); + memcpy(R, G, Glen); + api_mul(R, Glen, x, xlen, curve); + return Glen; +} + +static uint32_t +api_muladd(unsigned char *A, const unsigned char *B, size_t len, + const unsigned char *x, size_t xlen, + const unsigned char *y, size_t ylen, int curve) +{ + uint32_t r, t, z; + const curve_params *cc; + jacobian P, Q; + + /* + * TODO: see about merging the two ladders. Right now, we do + * two independent point multiplications, which is a bit + * wasteful of CPU resources (but yields short code). + */ + + cc = id_to_curve(curve); + r = point_decode(&P, A, len, cc); + if (B == NULL) { + size_t Glen; + + B = api_generator(curve, &Glen); + } + r &= point_decode(&Q, B, len, cc); + point_mul(&P, x, xlen, cc); + point_mul(&Q, y, ylen, cc); + + /* + * We want to compute P+Q. Since the base points A and B are distinct + * from infinity, and the multipliers are non-zero and lower than the + * curve order, then we know that P and Q are non-infinity. This + * leaves two special situations to test for: + * -- If P = Q then we must use point_double(). + * -- If P+Q = 0 then we must report an error. + */ + t = point_add(&P, &Q, cc); + point_double(&Q, cc); + z = br_i15_iszero(P.c[2]); + + /* + * If z is 1 then either P+Q = 0 (t = 1) or P = Q (t = 0). So we + * have the following: + * + * z = 0, t = 0 return P (normal addition) + * z = 0, t = 1 return P (normal addition) + * z = 1, t = 0 return Q (a 'double' case) + * z = 1, t = 1 report an error (P+Q = 0) + */ + CCOPY(z & ~t, &P, &Q, sizeof Q); + point_encode(A, &P, cc); + r &= ~(z & t); + + return r; +} + +/* see bearssl_ec.h */ +const br_ec_impl br_ec_prime_i15 = { + (uint32_t)0x03800000, + &api_generator, + &api_order, + &api_xoff, + &api_mul, + &api_mulgen, + &api_muladd +}; + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_prime_i31.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_prime_i31.c new file mode 100644 index 000000000..a37744602 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_prime_i31.c @@ -0,0 +1,824 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* + * Parameters for supported curves (field modulus, and 'b' equation + * parameter; both values use the 'i31' format, and 'b' is in Montgomery + * representation). + */ + +static const uint32_t P256_P[] = { + 0x00000108, + 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, 0x00000007, + 0x00000000, 0x00000000, 0x00000040, 0x7FFFFF80, + 0x000000FF +}; + +static const uint32_t P256_R2[] = { + 0x00000108, + 0x00014000, 0x00018000, 0x00000000, 0x7FF40000, + 0x7FEFFFFF, 0x7FF7FFFF, 0x7FAFFFFF, 0x005FFFFF, + 0x00000000 +}; + +static const uint32_t P256_B[] = { + 0x00000108, + 0x6FEE1803, 0x6229C4BD, 0x21B139BE, 0x327150AA, + 0x3567802E, 0x3F7212ED, 0x012E4355, 0x782DD38D, + 0x0000000E +}; + +static const uint32_t P384_P[] = { + 0x0000018C, + 0x7FFFFFFF, 0x00000001, 0x00000000, 0x7FFFFFF8, + 0x7FFFFFEF, 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, + 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, + 0x00000FFF +}; + +static const uint32_t P384_R2[] = { + 0x0000018C, + 0x00000000, 0x00000080, 0x7FFFFE00, 0x000001FF, + 0x00000800, 0x00000000, 0x7FFFE000, 0x00001FFF, + 0x00008000, 0x00008000, 0x00000000, 0x00000000, + 0x00000000 +}; + +static const uint32_t P384_B[] = { + 0x0000018C, + 0x6E666840, 0x070D0392, 0x5D810231, 0x7651D50C, + 0x17E218D6, 0x1B192002, 0x44EFE441, 0x3A524E2B, + 0x2719BA5F, 0x41F02209, 0x36C5643E, 0x5813EFFE, + 0x000008A5 +}; + +static const uint32_t P521_P[] = { + 0x00000219, + 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, + 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, + 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, + 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, + 0x01FFFFFF +}; + +static const uint32_t P521_R2[] = { + 0x00000219, + 0x00001000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000 +}; + +static const uint32_t P521_B[] = { + 0x00000219, + 0x540FC00A, 0x228FEA35, 0x2C34F1EF, 0x67BF107A, + 0x46FC1CD5, 0x1605E9DD, 0x6937B165, 0x272A3D8F, + 0x42785586, 0x44C8C778, 0x15F3B8B4, 0x64B73366, + 0x03BA8B69, 0x0D05B42A, 0x21F929A2, 0x2C31C393, + 0x00654FAE +}; + +typedef struct { + const uint32_t *p; + const uint32_t *b; + const uint32_t *R2; + uint32_t p0i; +} curve_params; + +static inline const curve_params * +id_to_curve(int curve) +{ + static const curve_params pp[] = { + { P256_P, P256_B, P256_R2, 0x00000001 }, + { P384_P, P384_B, P384_R2, 0x00000001 }, + { P521_P, P521_B, P521_R2, 0x00000001 } + }; + + return &pp[curve - BR_EC_secp256r1]; +} + +#define I31_LEN ((BR_MAX_EC_SIZE + 61) / 31) + +/* + * Type for a point in Jacobian coordinates: + * -- three values, x, y and z, in Montgomery representation + * -- affine coordinates are X = x / z^2 and Y = y / z^3 + * -- for the point at infinity, z = 0 + */ +typedef struct { + uint32_t c[3][I31_LEN]; +} jacobian; + +/* + * We use a custom interpreter that uses a dozen registers, and + * only six operations: + * MSET(d, a) copy a into d + * MADD(d, a) d = d+a (modular) + * MSUB(d, a) d = d-a (modular) + * MMUL(d, a, b) d = a*b (Montgomery multiplication) + * MINV(d, a, b) invert d modulo p; a and b are used as scratch registers + * MTZ(d) clear return value if d = 0 + * Destination of MMUL (d) must be distinct from operands (a and b). + * There is no such constraint for MSUB and MADD. + * + * Registers include the operand coordinates, and temporaries. + */ +#define MSET(d, a) (0x0000 + ((d) << 8) + ((a) << 4)) +#define MADD(d, a) (0x1000 + ((d) << 8) + ((a) << 4)) +#define MSUB(d, a) (0x2000 + ((d) << 8) + ((a) << 4)) +#define MMUL(d, a, b) (0x3000 + ((d) << 8) + ((a) << 4) + (b)) +#define MINV(d, a, b) (0x4000 + ((d) << 8) + ((a) << 4) + (b)) +#define MTZ(d) (0x5000 + ((d) << 8)) +#define ENDCODE 0 + +/* + * Registers for the input operands. + */ +#define P1x 0 +#define P1y 1 +#define P1z 2 +#define P2x 3 +#define P2y 4 +#define P2z 5 + +/* + * Alternate names for the first input operand. + */ +#define Px 0 +#define Py 1 +#define Pz 2 + +/* + * Temporaries. + */ +#define t1 6 +#define t2 7 +#define t3 8 +#define t4 9 +#define t5 10 +#define t6 11 +#define t7 12 + +/* + * Extra scratch registers available when there is no second operand (e.g. + * for "double" and "affine"). + */ +#define t8 3 +#define t9 4 +#define t10 5 + +/* + * Doubling formulas are: + * + * s = 4*x*y^2 + * m = 3*(x + z^2)*(x - z^2) + * x' = m^2 - 2*s + * y' = m*(s - x') - 8*y^4 + * z' = 2*y*z + * + * If y = 0 (P has order 2) then this yields infinity (z' = 0), as it + * should. This case should not happen anyway, because our curves have + * prime order, and thus do not contain any point of order 2. + * + * If P is infinity (z = 0), then again the formulas yield infinity, + * which is correct. Thus, this code works for all points. + * + * Cost: 8 multiplications + */ +static const uint16_t code_double[] = { + /* + * Compute z^2 (in t1). + */ + MMUL(t1, Pz, Pz), + + /* + * Compute x-z^2 (in t2) and then x+z^2 (in t1). + */ + MSET(t2, Px), + MSUB(t2, t1), + MADD(t1, Px), + + /* + * Compute m = 3*(x+z^2)*(x-z^2) (in t1). + */ + MMUL(t3, t1, t2), + MSET(t1, t3), + MADD(t1, t3), + MADD(t1, t3), + + /* + * Compute s = 4*x*y^2 (in t2) and 2*y^2 (in t3). + */ + MMUL(t3, Py, Py), + MADD(t3, t3), + MMUL(t2, Px, t3), + MADD(t2, t2), + + /* + * Compute x' = m^2 - 2*s. + */ + MMUL(Px, t1, t1), + MSUB(Px, t2), + MSUB(Px, t2), + + /* + * Compute z' = 2*y*z. + */ + MMUL(t4, Py, Pz), + MSET(Pz, t4), + MADD(Pz, t4), + + /* + * Compute y' = m*(s - x') - 8*y^4. Note that we already have + * 2*y^2 in t3. + */ + MSUB(t2, Px), + MMUL(Py, t1, t2), + MMUL(t4, t3, t3), + MSUB(Py, t4), + MSUB(Py, t4), + + ENDCODE +}; + +/* + * Addtions formulas are: + * + * u1 = x1 * z2^2 + * u2 = x2 * z1^2 + * s1 = y1 * z2^3 + * s2 = y2 * z1^3 + * h = u2 - u1 + * r = s2 - s1 + * x3 = r^2 - h^3 - 2 * u1 * h^2 + * y3 = r * (u1 * h^2 - x3) - s1 * h^3 + * z3 = h * z1 * z2 + * + * If both P1 and P2 are infinity, then z1 == 0 and z2 == 0, implying that + * z3 == 0, so the result is correct. + * If either of P1 or P2 is infinity, but not both, then z3 == 0, which is + * not correct. + * h == 0 only if u1 == u2; this happens in two cases: + * -- if s1 == s2 then P1 and/or P2 is infinity, or P1 == P2 + * -- if s1 != s2 then P1 + P2 == infinity (but neither P1 or P2 is infinity) + * + * Thus, the following situations are not handled correctly: + * -- P1 = 0 and P2 != 0 + * -- P1 != 0 and P2 = 0 + * -- P1 = P2 + * All other cases are properly computed. However, even in "incorrect" + * situations, the three coordinates still are properly formed field + * elements. + * + * The returned flag is cleared if r == 0. This happens in the following + * cases: + * -- Both points are on the same horizontal line (same Y coordinate). + * -- Both points are infinity. + * -- One point is infinity and the other is on line Y = 0. + * The third case cannot happen with our curves (there is no valid point + * on line Y = 0 since that would be a point of order 2). If the two + * source points are non-infinity, then remains only the case where the + * two points are on the same horizontal line. + * + * This allows us to detect the "P1 == P2" case, assuming that P1 != 0 and + * P2 != 0: + * -- If the returned value is not the point at infinity, then it was properly + * computed. + * -- Otherwise, if the returned flag is 1, then P1+P2 = 0, and the result + * is indeed the point at infinity. + * -- Otherwise (result is infinity, flag is 0), then P1 = P2 and we should + * use the 'double' code. + * + * Cost: 16 multiplications + */ +static const uint16_t code_add[] = { + /* + * Compute u1 = x1*z2^2 (in t1) and s1 = y1*z2^3 (in t3). + */ + MMUL(t3, P2z, P2z), + MMUL(t1, P1x, t3), + MMUL(t4, P2z, t3), + MMUL(t3, P1y, t4), + + /* + * Compute u2 = x2*z1^2 (in t2) and s2 = y2*z1^3 (in t4). + */ + MMUL(t4, P1z, P1z), + MMUL(t2, P2x, t4), + MMUL(t5, P1z, t4), + MMUL(t4, P2y, t5), + + /* + * Compute h = u2 - u1 (in t2) and r = s2 - s1 (in t4). + */ + MSUB(t2, t1), + MSUB(t4, t3), + + /* + * Report cases where r = 0 through the returned flag. + */ + MTZ(t4), + + /* + * Compute u1*h^2 (in t6) and h^3 (in t5). + */ + MMUL(t7, t2, t2), + MMUL(t6, t1, t7), + MMUL(t5, t7, t2), + + /* + * Compute x3 = r^2 - h^3 - 2*u1*h^2. + * t1 and t7 can be used as scratch registers. + */ + MMUL(P1x, t4, t4), + MSUB(P1x, t5), + MSUB(P1x, t6), + MSUB(P1x, t6), + + /* + * Compute y3 = r*(u1*h^2 - x3) - s1*h^3. + */ + MSUB(t6, P1x), + MMUL(P1y, t4, t6), + MMUL(t1, t5, t3), + MSUB(P1y, t1), + + /* + * Compute z3 = h*z1*z2. + */ + MMUL(t1, P1z, P2z), + MMUL(P1z, t1, t2), + + ENDCODE +}; + +/* + * Check that the point is on the curve. This code snippet assumes the + * following conventions: + * -- Coordinates x and y have been freshly decoded in P1 (but not + * converted to Montgomery coordinates yet). + * -- P2x, P2y and P2z are set to, respectively, R^2, b*R and 1. + */ +static const uint16_t code_check[] = { + + /* Convert x and y to Montgomery representation. */ + MMUL(t1, P1x, P2x), + MMUL(t2, P1y, P2x), + MSET(P1x, t1), + MSET(P1y, t2), + + /* Compute x^3 in t1. */ + MMUL(t2, P1x, P1x), + MMUL(t1, P1x, t2), + + /* Subtract 3*x from t1. */ + MSUB(t1, P1x), + MSUB(t1, P1x), + MSUB(t1, P1x), + + /* Add b. */ + MADD(t1, P2y), + + /* Compute y^2 in t2. */ + MMUL(t2, P1y, P1y), + + /* Compare y^2 with x^3 - 3*x + b; they must match. */ + MSUB(t1, t2), + MTZ(t1), + + /* Set z to 1 (in Montgomery representation). */ + MMUL(P1z, P2x, P2z), + + ENDCODE +}; + +/* + * Conversion back to affine coordinates. This code snippet assumes that + * the z coordinate of P2 is set to 1 (not in Montgomery representation). + */ +static const uint16_t code_affine[] = { + + /* Save z*R in t1. */ + MSET(t1, P1z), + + /* Compute z^3 in t2. */ + MMUL(t2, P1z, P1z), + MMUL(t3, P1z, t2), + MMUL(t2, t3, P2z), + + /* Invert to (1/z^3) in t2. */ + MINV(t2, t3, t4), + + /* Compute y. */ + MSET(t3, P1y), + MMUL(P1y, t2, t3), + + /* Compute (1/z^2) in t3. */ + MMUL(t3, t2, t1), + + /* Compute x. */ + MSET(t2, P1x), + MMUL(P1x, t2, t3), + + ENDCODE +}; + +static uint32_t +run_code(jacobian *P1, const jacobian *P2, + const curve_params *cc, const uint16_t *code) +{ + uint32_t r; + uint32_t t[13][I31_LEN]; + size_t u; + + r = 1; + + /* + * Copy the two operands in the dedicated registers. + */ + memcpy(t[P1x], P1->c, 3 * I31_LEN * sizeof(uint32_t)); + memcpy(t[P2x], P2->c, 3 * I31_LEN * sizeof(uint32_t)); + + /* + * Run formulas. + */ + for (u = 0;; u ++) { + unsigned op, d, a, b; + + op = code[u]; + if (op == 0) { + break; + } + d = (op >> 8) & 0x0F; + a = (op >> 4) & 0x0F; + b = op & 0x0F; + op >>= 12; + switch (op) { + uint32_t ctl; + size_t plen; + unsigned char tp[(BR_MAX_EC_SIZE + 7) >> 3]; + + case 0: + memcpy(t[d], t[a], I31_LEN * sizeof(uint32_t)); + break; + case 1: + ctl = br_i31_add(t[d], t[a], 1); + ctl |= NOT(br_i31_sub(t[d], cc->p, 0)); + br_i31_sub(t[d], cc->p, ctl); + break; + case 2: + br_i31_add(t[d], cc->p, br_i31_sub(t[d], t[a], 1)); + break; + case 3: + br_i31_montymul(t[d], t[a], t[b], cc->p, cc->p0i); + break; + case 4: + plen = (cc->p[0] - (cc->p[0] >> 5) + 7) >> 3; + br_i31_encode(tp, plen, cc->p); + tp[plen - 1] -= 2; + br_i31_modpow(t[d], tp, plen, + cc->p, cc->p0i, t[a], t[b]); + break; + default: + r &= ~br_i31_iszero(t[d]); + break; + } + } + + /* + * Copy back result. + */ + memcpy(P1->c, t[P1x], 3 * I31_LEN * sizeof(uint32_t)); + return r; +} + +static void +set_one(uint32_t *x, const uint32_t *p) +{ + size_t plen; + + plen = (p[0] + 63) >> 5; + memset(x, 0, plen * sizeof *x); + x[0] = p[0]; + x[1] = 0x00000001; +} + +static void +point_zero(jacobian *P, const curve_params *cc) +{ + memset(P, 0, sizeof *P); + P->c[0][0] = P->c[1][0] = P->c[2][0] = cc->p[0]; +} + +static inline void +point_double(jacobian *P, const curve_params *cc) +{ + run_code(P, P, cc, code_double); +} + +static inline uint32_t +point_add(jacobian *P1, const jacobian *P2, const curve_params *cc) +{ + return run_code(P1, P2, cc, code_add); +} + +static void +point_mul(jacobian *P, const unsigned char *x, size_t xlen, + const curve_params *cc) +{ + /* + * We do a simple double-and-add ladder with a 2-bit window + * to make only one add every two doublings. We thus first + * precompute 2P and 3P in some local buffers. + * + * We always perform two doublings and one addition; the + * addition is with P, 2P and 3P and is done in a temporary + * array. + * + * The addition code cannot handle cases where one of the + * operands is infinity, which is the case at the start of the + * ladder. We therefore need to maintain a flag that controls + * this situation. + */ + uint32_t qz; + jacobian P2, P3, Q, T, U; + + memcpy(&P2, P, sizeof P2); + point_double(&P2, cc); + memcpy(&P3, P, sizeof P3); + point_add(&P3, &P2, cc); + + point_zero(&Q, cc); + qz = 1; + while (xlen -- > 0) { + int k; + + for (k = 6; k >= 0; k -= 2) { + uint32_t bits; + uint32_t bnz; + + point_double(&Q, cc); + point_double(&Q, cc); + memcpy(&T, P, sizeof T); + memcpy(&U, &Q, sizeof U); + bits = (*x >> k) & (uint32_t)3; + bnz = NEQ(bits, 0); + CCOPY(EQ(bits, 2), &T, &P2, sizeof T); + CCOPY(EQ(bits, 3), &T, &P3, sizeof T); + point_add(&U, &T, cc); + CCOPY(bnz & qz, &Q, &T, sizeof Q); + CCOPY(bnz & ~qz, &Q, &U, sizeof Q); + qz &= ~bnz; + } + x ++; + } + memcpy(P, &Q, sizeof Q); +} + +/* + * Decode point into Jacobian coordinates. This function does not support + * the point at infinity. If the point is invalid then this returns 0, but + * the coordinates are still set to properly formed field elements. + */ +static uint32_t +point_decode(jacobian *P, const void *src, size_t len, const curve_params *cc) +{ + /* + * Points must use uncompressed format: + * -- first byte is 0x04; + * -- coordinates X and Y use unsigned big-endian, with the same + * length as the field modulus. + * + * We don't support hybrid format (uncompressed, but first byte + * has value 0x06 or 0x07, depending on the least significant bit + * of Y) because it is rather useless, and explicitly forbidden + * by PKIX (RFC 5480, section 2.2). + * + * We don't support compressed format either, because it is not + * much used in practice (there are or were patent-related + * concerns about point compression, which explains the lack of + * generalised support). Also, point compression support would + * need a bit more code. + */ + const unsigned char *buf; + size_t plen, zlen; + uint32_t r; + jacobian Q; + + buf = src; + point_zero(P, cc); + plen = (cc->p[0] - (cc->p[0] >> 5) + 7) >> 3; + if (len != 1 + (plen << 1)) { + return 0; + } + r = br_i31_decode_mod(P->c[0], buf + 1, plen, cc->p); + r &= br_i31_decode_mod(P->c[1], buf + 1 + plen, plen, cc->p); + + /* + * Check first byte. + */ + r &= EQ(buf[0], 0x04); + /* obsolete + r &= EQ(buf[0], 0x04) | (EQ(buf[0] & 0xFE, 0x06) + & ~(uint32_t)(buf[0] ^ buf[plen << 1])); + */ + + /* + * Convert coordinates and check that the point is valid. + */ + zlen = ((cc->p[0] + 63) >> 5) * sizeof(uint32_t); + memcpy(Q.c[0], cc->R2, zlen); + memcpy(Q.c[1], cc->b, zlen); + set_one(Q.c[2], cc->p); + r &= ~run_code(P, &Q, cc, code_check); + return r; +} + +/* + * Encode a point. This method assumes that the point is correct and is + * not the point at infinity. Encoded size is always 1+2*plen, where + * plen is the field modulus length, in bytes. + */ +static void +point_encode(void *dst, const jacobian *P, const curve_params *cc) +{ + unsigned char *buf; + uint32_t xbl; + size_t plen; + jacobian Q, T; + + buf = dst; + xbl = cc->p[0]; + xbl -= (xbl >> 5); + plen = (xbl + 7) >> 3; + buf[0] = 0x04; + memcpy(&Q, P, sizeof *P); + set_one(T.c[2], cc->p); + run_code(&Q, &T, cc, code_affine); + br_i31_encode(buf + 1, plen, Q.c[0]); + br_i31_encode(buf + 1 + plen, plen, Q.c[1]); +} + +static const br_ec_curve_def * +id_to_curve_def(int curve) +{ + switch (curve) { + case BR_EC_secp256r1: + return &br_secp256r1; + case BR_EC_secp384r1: + return &br_secp384r1; + case BR_EC_secp521r1: + return &br_secp521r1; + } + return NULL; +} + +static const unsigned char * +api_generator(int curve, size_t *len) +{ + const br_ec_curve_def *cd; + + cd = id_to_curve_def(curve); + *len = cd->generator_len; + return cd->generator; +} + +static const unsigned char * +api_order(int curve, size_t *len) +{ + const br_ec_curve_def *cd; + + cd = id_to_curve_def(curve); + *len = cd->order_len; + return cd->order; +} + +static size_t +api_xoff(int curve, size_t *len) +{ + api_generator(curve, len); + *len >>= 1; + return 1; +} + +static uint32_t +api_mul(unsigned char *G, size_t Glen, + const unsigned char *x, size_t xlen, int curve) +{ + uint32_t r; + const curve_params *cc; + jacobian P; + + cc = id_to_curve(curve); + r = point_decode(&P, G, Glen, cc); + point_mul(&P, x, xlen, cc); + point_encode(G, &P, cc); + return r; +} + +static size_t +api_mulgen(unsigned char *R, + const unsigned char *x, size_t xlen, int curve) +{ + const unsigned char *G; + size_t Glen; + + G = api_generator(curve, &Glen); + memcpy(R, G, Glen); + api_mul(R, Glen, x, xlen, curve); + return Glen; +} + +static uint32_t +api_muladd(unsigned char *A, const unsigned char *B, size_t len, + const unsigned char *x, size_t xlen, + const unsigned char *y, size_t ylen, int curve) +{ + uint32_t r, t, z; + const curve_params *cc; + jacobian P, Q; + + /* + * TODO: see about merging the two ladders. Right now, we do + * two independent point multiplications, which is a bit + * wasteful of CPU resources (but yields short code). + */ + + cc = id_to_curve(curve); + r = point_decode(&P, A, len, cc); + if (B == NULL) { + size_t Glen; + + B = api_generator(curve, &Glen); + } + r &= point_decode(&Q, B, len, cc); + point_mul(&P, x, xlen, cc); + point_mul(&Q, y, ylen, cc); + + /* + * We want to compute P+Q. Since the base points A and B are distinct + * from infinity, and the multipliers are non-zero and lower than the + * curve order, then we know that P and Q are non-infinity. This + * leaves two special situations to test for: + * -- If P = Q then we must use point_double(). + * -- If P+Q = 0 then we must report an error. + */ + t = point_add(&P, &Q, cc); + point_double(&Q, cc); + z = br_i31_iszero(P.c[2]); + + /* + * If z is 1 then either P+Q = 0 (t = 1) or P = Q (t = 0). So we + * have the following: + * + * z = 0, t = 0 return P (normal addition) + * z = 0, t = 1 return P (normal addition) + * z = 1, t = 0 return Q (a 'double' case) + * z = 1, t = 1 report an error (P+Q = 0) + */ + CCOPY(z & ~t, &P, &Q, sizeof Q); + point_encode(A, &P, cc); + r &= ~(z & t); + + return r; +} + +/* see bearssl_ec.h */ +const br_ec_impl br_ec_prime_i31 = { + (uint32_t)0x03800000, + &api_generator, + &api_order, + &api_xoff, + &api_mul, + &api_mulgen, + &api_muladd +}; + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_pubkey.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_pubkey.c new file mode 100644 index 000000000..dc3f11a86 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_pubkey.c @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +static const unsigned char POINT_LEN[] = { + 0, /* 0: not a valid curve ID */ + 43, /* sect163k1 */ + 43, /* sect163r1 */ + 43, /* sect163r2 */ + 51, /* sect193r1 */ + 51, /* sect193r2 */ + 61, /* sect233k1 */ + 61, /* sect233r1 */ + 61, /* sect239k1 */ + 73, /* sect283k1 */ + 73, /* sect283r1 */ + 105, /* sect409k1 */ + 105, /* sect409r1 */ + 145, /* sect571k1 */ + 145, /* sect571r1 */ + 41, /* secp160k1 */ + 41, /* secp160r1 */ + 41, /* secp160r2 */ + 49, /* secp192k1 */ + 49, /* secp192r1 */ + 57, /* secp224k1 */ + 57, /* secp224r1 */ + 65, /* secp256k1 */ + 65, /* secp256r1 */ + 97, /* secp384r1 */ + 133, /* secp521r1 */ + 65, /* brainpoolP256r1 */ + 97, /* brainpoolP384r1 */ + 129, /* brainpoolP512r1 */ + 32, /* curve25519 */ + 56, /* curve448 */ +}; + +/* see bearssl_ec.h */ +size_t +br_ec_compute_pub(const br_ec_impl *impl, br_ec_public_key *pk, + void *kbuf, const br_ec_private_key *sk) +{ + int curve; + size_t len; + + curve = sk->curve; + if (curve < 0 || curve >= 32 || curve >= (int)(sizeof POINT_LEN) + || ((impl->supported_curves >> curve) & 1) == 0) + { + return 0; + } + if (kbuf == NULL) { + return POINT_LEN[curve]; + } + len = impl->mulgen(kbuf, sk->x, sk->xlen, curve); + if (pk != NULL) { + pk->curve = curve; + pk->q = kbuf; + pk->qlen = len; + } + return len; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_secp256r1.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_secp256r1.c new file mode 100644 index 000000000..9f8339769 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_secp256r1.c @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +static const unsigned char P256_N[] = { + 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xBC, 0xE6, 0xFA, 0xAD, 0xA7, 0x17, 0x9E, 0x84, + 0xF3, 0xB9, 0xCA, 0xC2, 0xFC, 0x63, 0x25, 0x51 +}; + +static const unsigned char P256_G[] = { + 0x04, 0x6B, 0x17, 0xD1, 0xF2, 0xE1, 0x2C, 0x42, + 0x47, 0xF8, 0xBC, 0xE6, 0xE5, 0x63, 0xA4, 0x40, + 0xF2, 0x77, 0x03, 0x7D, 0x81, 0x2D, 0xEB, 0x33, + 0xA0, 0xF4, 0xA1, 0x39, 0x45, 0xD8, 0x98, 0xC2, + 0x96, 0x4F, 0xE3, 0x42, 0xE2, 0xFE, 0x1A, 0x7F, + 0x9B, 0x8E, 0xE7, 0xEB, 0x4A, 0x7C, 0x0F, 0x9E, + 0x16, 0x2B, 0xCE, 0x33, 0x57, 0x6B, 0x31, 0x5E, + 0xCE, 0xCB, 0xB6, 0x40, 0x68, 0x37, 0xBF, 0x51, + 0xF5 +}; + +/* see inner.h */ +const br_ec_curve_def br_secp256r1 = { + BR_EC_secp256r1, + P256_N, sizeof P256_N, + P256_G, sizeof P256_G +}; + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_secp384r1.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_secp384r1.c new file mode 100644 index 000000000..507991dfa --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_secp384r1.c @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +static const unsigned char P384_N[] = { + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xC7, 0x63, 0x4D, 0x81, 0xF4, 0x37, 0x2D, 0xDF, + 0x58, 0x1A, 0x0D, 0xB2, 0x48, 0xB0, 0xA7, 0x7A, + 0xEC, 0xEC, 0x19, 0x6A, 0xCC, 0xC5, 0x29, 0x73 +}; + +static const unsigned char P384_G[] = { + 0x04, 0xAA, 0x87, 0xCA, 0x22, 0xBE, 0x8B, 0x05, + 0x37, 0x8E, 0xB1, 0xC7, 0x1E, 0xF3, 0x20, 0xAD, + 0x74, 0x6E, 0x1D, 0x3B, 0x62, 0x8B, 0xA7, 0x9B, + 0x98, 0x59, 0xF7, 0x41, 0xE0, 0x82, 0x54, 0x2A, + 0x38, 0x55, 0x02, 0xF2, 0x5D, 0xBF, 0x55, 0x29, + 0x6C, 0x3A, 0x54, 0x5E, 0x38, 0x72, 0x76, 0x0A, + 0xB7, 0x36, 0x17, 0xDE, 0x4A, 0x96, 0x26, 0x2C, + 0x6F, 0x5D, 0x9E, 0x98, 0xBF, 0x92, 0x92, 0xDC, + 0x29, 0xF8, 0xF4, 0x1D, 0xBD, 0x28, 0x9A, 0x14, + 0x7C, 0xE9, 0xDA, 0x31, 0x13, 0xB5, 0xF0, 0xB8, + 0xC0, 0x0A, 0x60, 0xB1, 0xCE, 0x1D, 0x7E, 0x81, + 0x9D, 0x7A, 0x43, 0x1D, 0x7C, 0x90, 0xEA, 0x0E, + 0x5F +}; + +/* see inner.h */ +const br_ec_curve_def br_secp384r1 = { + BR_EC_secp384r1, + P384_N, sizeof P384_N, + P384_G, sizeof P384_G +}; + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_secp521r1.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_secp521r1.c new file mode 100644 index 000000000..ca4cf3111 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ec_secp521r1.c @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +static const unsigned char P521_N[] = { + 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFA, 0x51, 0x86, 0x87, 0x83, 0xBF, 0x2F, + 0x96, 0x6B, 0x7F, 0xCC, 0x01, 0x48, 0xF7, 0x09, + 0xA5, 0xD0, 0x3B, 0xB5, 0xC9, 0xB8, 0x89, 0x9C, + 0x47, 0xAE, 0xBB, 0x6F, 0xB7, 0x1E, 0x91, 0x38, + 0x64, 0x09 +}; + +static const unsigned char P521_G[] = { + 0x04, 0x00, 0xC6, 0x85, 0x8E, 0x06, 0xB7, 0x04, + 0x04, 0xE9, 0xCD, 0x9E, 0x3E, 0xCB, 0x66, 0x23, + 0x95, 0xB4, 0x42, 0x9C, 0x64, 0x81, 0x39, 0x05, + 0x3F, 0xB5, 0x21, 0xF8, 0x28, 0xAF, 0x60, 0x6B, + 0x4D, 0x3D, 0xBA, 0xA1, 0x4B, 0x5E, 0x77, 0xEF, + 0xE7, 0x59, 0x28, 0xFE, 0x1D, 0xC1, 0x27, 0xA2, + 0xFF, 0xA8, 0xDE, 0x33, 0x48, 0xB3, 0xC1, 0x85, + 0x6A, 0x42, 0x9B, 0xF9, 0x7E, 0x7E, 0x31, 0xC2, + 0xE5, 0xBD, 0x66, 0x01, 0x18, 0x39, 0x29, 0x6A, + 0x78, 0x9A, 0x3B, 0xC0, 0x04, 0x5C, 0x8A, 0x5F, + 0xB4, 0x2C, 0x7D, 0x1B, 0xD9, 0x98, 0xF5, 0x44, + 0x49, 0x57, 0x9B, 0x44, 0x68, 0x17, 0xAF, 0xBD, + 0x17, 0x27, 0x3E, 0x66, 0x2C, 0x97, 0xEE, 0x72, + 0x99, 0x5E, 0xF4, 0x26, 0x40, 0xC5, 0x50, 0xB9, + 0x01, 0x3F, 0xAD, 0x07, 0x61, 0x35, 0x3C, 0x70, + 0x86, 0xA2, 0x72, 0xC2, 0x40, 0x88, 0xBE, 0x94, + 0x76, 0x9F, 0xD1, 0x66, 0x50 +}; + +/* see inner.h */ +const br_ec_curve_def br_secp521r1 = { + BR_EC_secp521r1, + P521_N, sizeof P521_N, + P521_G, sizeof P521_G +}; + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ecdsa_atr.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ecdsa_atr.c new file mode 100644 index 000000000..22ac1853c --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ecdsa_atr.c @@ -0,0 +1,139 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_ec.h */ +size_t +br_ecdsa_asn1_to_raw(void *sig, size_t sig_len) +{ + /* + * Note: this code is a bit lenient in that it accepts a few + * deviations to DER with regards to minimality of encoding of + * lengths and integer values. These deviations are still + * unambiguous. + * + * Signature format is a SEQUENCE of two INTEGER values. We + * support only integers of less than 127 bytes each (signed + * encoding) so the resulting raw signature will have length + * at most 254 bytes. + */ + + unsigned char *buf, *r, *s; + size_t zlen, rlen, slen, off; + unsigned char tmp[254]; + + buf = sig; + if (sig_len < 8) { + return 0; + } + + /* + * First byte is SEQUENCE tag. + */ + if (buf[0] != 0x30) { + return 0; + } + + /* + * The SEQUENCE length will be encoded over one or two bytes. We + * limit the total SEQUENCE contents to 255 bytes, because it + * makes things simpler; this is enough for subgroup orders up + * to 999 bits. + */ + zlen = buf[1]; + if (zlen > 0x80) { + if (zlen != 0x81) { + return 0; + } + zlen = buf[2]; + if (zlen != sig_len - 3) { + return 0; + } + off = 3; + } else { + if (zlen != sig_len - 2) { + return 0; + } + off = 2; + } + + /* + * First INTEGER (r). + */ + if (buf[off ++] != 0x02) { + return 0; + } + rlen = buf[off ++]; + if (rlen >= 0x80) { + return 0; + } + r = buf + off; + off += rlen; + + /* + * Second INTEGER (s). + */ + if (off + 2 > sig_len) { + return 0; + } + if (buf[off ++] != 0x02) { + return 0; + } + slen = buf[off ++]; + if (slen >= 0x80 || slen != sig_len - off) { + return 0; + } + s = buf + off; + + /* + * Removing leading zeros from r and s. + */ + while (rlen > 0 && *r == 0) { + rlen --; + r ++; + } + while (slen > 0 && *s == 0) { + slen --; + s ++; + } + + /* + * Compute common length for the two integers, then copy integers + * into the temporary buffer, and finally copy it back over the + * signature buffer. + */ + zlen = rlen > slen ? rlen : slen; + sig_len = zlen << 1; + memset(tmp, 0, sig_len); + memcpy(tmp + zlen - rlen, r, rlen); + memcpy(tmp + sig_len - slen, s, slen); + memcpy(sig, tmp, sig_len); + return sig_len; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ecdsa_default_sign_asn1.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ecdsa_default_sign_asn1.c new file mode 100644 index 000000000..b42ce54e9 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ecdsa_default_sign_asn1.c @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_ec.h */ +br_ecdsa_sign +br_ecdsa_sign_asn1_get_default(void) +{ +#if BR_LOMUL + return &br_ecdsa_i15_sign_asn1; +#else + return &br_ecdsa_i31_sign_asn1; +#endif +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ecdsa_default_sign_raw.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ecdsa_default_sign_raw.c new file mode 100644 index 000000000..4f6a2af2d --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ecdsa_default_sign_raw.c @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_ec.h */ +br_ecdsa_sign +br_ecdsa_sign_raw_get_default(void) +{ +#if BR_LOMUL + return &br_ecdsa_i15_sign_raw; +#else + return &br_ecdsa_i31_sign_raw; +#endif +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ecdsa_default_vrfy_asn1.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ecdsa_default_vrfy_asn1.c new file mode 100644 index 000000000..1e6dcd3ed --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ecdsa_default_vrfy_asn1.c @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_ec.h */ +br_ecdsa_vrfy +br_ecdsa_vrfy_asn1_get_default(void) +{ +#if BR_LOMUL + return &br_ecdsa_i15_vrfy_asn1; +#else + return &br_ecdsa_i31_vrfy_asn1; +#endif +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ecdsa_default_vrfy_raw.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ecdsa_default_vrfy_raw.c new file mode 100644 index 000000000..12f41fac1 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ecdsa_default_vrfy_raw.c @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_ec.h */ +br_ecdsa_vrfy +br_ecdsa_vrfy_raw_get_default(void) +{ +#if BR_LOMUL + return &br_ecdsa_i15_vrfy_raw; +#else + return &br_ecdsa_i31_vrfy_raw; +#endif +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ecdsa_i15_bits.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ecdsa_i15_bits.c new file mode 100644 index 000000000..bd15d52f2 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ecdsa_i15_bits.c @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +void +br_ecdsa_i15_bits2int(uint16_t *x, + const void *src, size_t len, uint32_t ebitlen) +{ + uint32_t bitlen, hbitlen; + int sc; + + bitlen = ebitlen - (ebitlen >> 4); + hbitlen = (uint32_t)len << 3; + if (hbitlen > bitlen) { + len = (bitlen + 7) >> 3; + sc = (int)((hbitlen - bitlen) & 7); + } else { + sc = 0; + } + br_i15_zero(x, ebitlen); + br_i15_decode(x, src, len); + br_i15_rshift(x, sc); + x[0] = ebitlen; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ecdsa_i15_sign_asn1.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ecdsa_i15_sign_asn1.c new file mode 100644 index 000000000..c9f013b89 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ecdsa_i15_sign_asn1.c @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +#define ORDER_LEN ((BR_MAX_EC_SIZE + 7) >> 3) + +/* see bearssl_ec.h */ +size_t +br_ecdsa_i15_sign_asn1(const br_ec_impl *impl, + const br_hash_class *hf, const void *hash_value, + const br_ec_private_key *sk, void *sig) +{ + unsigned char rsig[(ORDER_LEN << 1) + 12]; + size_t sig_len; + + sig_len = br_ecdsa_i15_sign_raw(impl, hf, hash_value, sk, rsig); + if (sig_len == 0) { + return 0; + } + sig_len = br_ecdsa_raw_to_asn1(rsig, sig_len); + memcpy(sig, rsig, sig_len); + return sig_len; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ecdsa_i15_sign_raw.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ecdsa_i15_sign_raw.c new file mode 100644 index 000000000..3afbed5f6 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ecdsa_i15_sign_raw.c @@ -0,0 +1,180 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +#define I15_LEN ((BR_MAX_EC_SIZE + 29) / 15) +#define POINT_LEN (1 + (((BR_MAX_EC_SIZE + 7) >> 3) << 1)) +#define ORDER_LEN ((BR_MAX_EC_SIZE + 7) >> 3) + +/* see bearssl_ec.h */ +size_t +br_ecdsa_i15_sign_raw(const br_ec_impl *impl, + const br_hash_class *hf, const void *hash_value, + const br_ec_private_key *sk, void *sig) +{ + /* + * IMPORTANT: this code is fit only for curves with a prime + * order. This is needed so that modular reduction of the X + * coordinate of a point can be done with a simple subtraction. + * We also rely on the last byte of the curve order to be distinct + * from 0 and 1. + */ + const br_ec_curve_def *cd; + uint16_t n[I15_LEN], r[I15_LEN], s[I15_LEN], x[I15_LEN]; + uint16_t m[I15_LEN], k[I15_LEN], t1[I15_LEN], t2[I15_LEN]; + unsigned char tt[ORDER_LEN << 1]; + unsigned char eU[POINT_LEN]; + size_t hash_len, nlen, ulen; + uint16_t n0i; + uint32_t ctl; + br_hmac_drbg_context drbg; + + /* + * If the curve is not supported, then exit with an error. + */ + if (((impl->supported_curves >> sk->curve) & 1) == 0) { + return 0; + } + + /* + * Get the curve parameters (generator and order). + */ + switch (sk->curve) { + case BR_EC_secp256r1: + cd = &br_secp256r1; + break; + case BR_EC_secp384r1: + cd = &br_secp384r1; + break; + case BR_EC_secp521r1: + cd = &br_secp521r1; + break; + default: + return 0; + } + + /* + * Get modulus. + */ + nlen = cd->order_len; + br_i15_decode(n, cd->order, nlen); + n0i = br_i15_ninv15(n[1]); + + /* + * Get private key as an i15 integer. This also checks that the + * private key is well-defined (not zero, and less than the + * curve order). + */ + if (!br_i15_decode_mod(x, sk->x, sk->xlen, n)) { + return 0; + } + if (br_i15_iszero(x)) { + return 0; + } + + /* + * Get hash length. + */ + hash_len = (hf->desc >> BR_HASHDESC_OUT_OFF) & BR_HASHDESC_OUT_MASK; + + /* + * Truncate and reduce the hash value modulo the curve order. + */ + br_ecdsa_i15_bits2int(m, hash_value, hash_len, n[0]); + br_i15_sub(m, n, br_i15_sub(m, n, 0) ^ 1); + + /* + * RFC 6979 generation of the "k" value. + * + * The process uses HMAC_DRBG (with the hash function used to + * process the message that is to be signed). The seed is the + * concatenation of the encodings of the private key and + * the hash value (after truncation and modular reduction). + */ + br_i15_encode(tt, nlen, x); + br_i15_encode(tt + nlen, nlen, m); + br_hmac_drbg_init(&drbg, hf, tt, nlen << 1); + for (;;) { + br_hmac_drbg_generate(&drbg, tt, nlen); + br_ecdsa_i15_bits2int(k, tt, nlen, n[0]); + if (br_i15_iszero(k)) { + continue; + } + if (br_i15_sub(k, n, 0)) { + break; + } + } + + /* + * Compute k*G and extract the X coordinate, then reduce it + * modulo the curve order. Since we support only curves with + * prime order, that reduction is only a matter of computing + * a subtraction. + */ + br_i15_encode(tt, nlen, k); + ulen = impl->mulgen(eU, tt, nlen, sk->curve); + br_i15_zero(r, n[0]); + br_i15_decode(r, &eU[1], ulen >> 1); + r[0] = n[0]; + br_i15_sub(r, n, br_i15_sub(r, n, 0) ^ 1); + + /* + * Compute 1/k in double-Montgomery representation. We do so by + * first converting _from_ Montgomery representation (twice), + * then using a modular exponentiation. + */ + br_i15_from_monty(k, n, n0i); + br_i15_from_monty(k, n, n0i); + memcpy(tt, cd->order, nlen); + tt[nlen - 1] -= 2; + br_i15_modpow(k, tt, nlen, n, n0i, t1, t2); + + /* + * Compute s = (m+xr)/k (mod n). + * The k[] array contains R^2/k (double-Montgomery representation); + * we thus can use direct Montgomery multiplications and conversions + * from Montgomery, avoiding any call to br_i15_to_monty() (which + * is slower). + */ + br_i15_from_monty(m, n, n0i); + br_i15_montymul(t1, x, r, n, n0i); + ctl = br_i15_add(t1, m, 1); + ctl |= br_i15_sub(t1, n, 0) ^ 1; + br_i15_sub(t1, n, ctl); + br_i15_montymul(s, t1, k, n, n0i); + + /* + * Encode r and s in the signature. + */ + br_i15_encode(sig, nlen, r); + br_i15_encode((unsigned char *)sig + nlen, nlen, s); + return nlen << 1; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ecdsa_i15_vrfy_asn1.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ecdsa_i15_vrfy_asn1.c new file mode 100644 index 000000000..57a706053 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ecdsa_i15_vrfy_asn1.c @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +#define FIELD_LEN ((BR_MAX_EC_SIZE + 7) >> 3) + +/* see bearssl_ec.h */ +uint32_t +br_ecdsa_i15_vrfy_asn1(const br_ec_impl *impl, + const void *hash, size_t hash_len, + const br_ec_public_key *pk, + const void *sig, size_t sig_len) +{ + /* + * We use a double-sized buffer because a malformed ASN.1 signature + * may trigger a size expansion when converting to "raw" format. + */ + unsigned char rsig[(FIELD_LEN << 2) + 24]; + + if (sig_len > ((sizeof rsig) >> 1)) { + return 0; + } + memcpy(rsig, sig, sig_len); + sig_len = br_ecdsa_asn1_to_raw(rsig, sig_len); + return br_ecdsa_i15_vrfy_raw(impl, hash, hash_len, pk, rsig, sig_len); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ecdsa_i15_vrfy_raw.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ecdsa_i15_vrfy_raw.c new file mode 100644 index 000000000..f27d24247 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ecdsa_i15_vrfy_raw.c @@ -0,0 +1,172 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +#define I15_LEN ((BR_MAX_EC_SIZE + 29) / 15) +#define POINT_LEN (1 + (((BR_MAX_EC_SIZE + 7) >> 3) << 1)) + +/* see bearssl_ec.h */ +uint32_t +br_ecdsa_i15_vrfy_raw(const br_ec_impl *impl, + const void *hash, size_t hash_len, + const br_ec_public_key *pk, + const void *sig, size_t sig_len) +{ + /* + * IMPORTANT: this code is fit only for curves with a prime + * order. This is needed so that modular reduction of the X + * coordinate of a point can be done with a simple subtraction. + */ + const br_ec_curve_def *cd; + uint16_t n[I15_LEN], r[I15_LEN], s[I15_LEN], t1[I15_LEN], t2[I15_LEN]; + unsigned char tx[(BR_MAX_EC_SIZE + 7) >> 3]; + unsigned char ty[(BR_MAX_EC_SIZE + 7) >> 3]; + unsigned char eU[POINT_LEN]; + size_t nlen, rlen, ulen; + uint16_t n0i; + uint32_t res; + + /* + * If the curve is not supported, then report an error. + */ + if (((impl->supported_curves >> pk->curve) & 1) == 0) { + return 0; + } + + /* + * Get the curve parameters (generator and order). + */ + switch (pk->curve) { + case BR_EC_secp256r1: + cd = &br_secp256r1; + break; + case BR_EC_secp384r1: + cd = &br_secp384r1; + break; + case BR_EC_secp521r1: + cd = &br_secp521r1; + break; + default: + return 0; + } + + /* + * Signature length must be even. + */ + if (sig_len & 1) { + return 0; + } + rlen = sig_len >> 1; + + /* + * Public key point must have the proper size for this curve. + */ + if (pk->qlen != cd->generator_len) { + return 0; + } + + /* + * Get modulus; then decode the r and s values. They must be + * lower than the modulus, and s must not be null. + */ + nlen = cd->order_len; + br_i15_decode(n, cd->order, nlen); + n0i = br_i15_ninv15(n[1]); + if (!br_i15_decode_mod(r, sig, rlen, n)) { + return 0; + } + if (!br_i15_decode_mod(s, (const unsigned char *)sig + rlen, rlen, n)) { + return 0; + } + if (br_i15_iszero(s)) { + return 0; + } + + /* + * Invert s. We do that with a modular exponentiation; we use + * the fact that for all the curves we support, the least + * significant byte is not 0 or 1, so we can subtract 2 without + * any carry to process. + * We also want 1/s in Montgomery representation, which can be + * done by converting _from_ Montgomery representation before + * the inversion (because (1/s)*R = 1/(s/R)). + */ + br_i15_from_monty(s, n, n0i); + memcpy(tx, cd->order, nlen); + tx[nlen - 1] -= 2; + br_i15_modpow(s, tx, nlen, n, n0i, t1, t2); + + /* + * Truncate the hash to the modulus length (in bits) and reduce + * it modulo the curve order. The modular reduction can be done + * with a subtraction since the truncation already reduced the + * value to the modulus bit length. + */ + br_ecdsa_i15_bits2int(t1, hash, hash_len, n[0]); + br_i15_sub(t1, n, br_i15_sub(t1, n, 0) ^ 1); + + /* + * Multiply the (truncated, reduced) hash value with 1/s, result in + * t2, encoded in ty. + */ + br_i15_montymul(t2, t1, s, n, n0i); + br_i15_encode(ty, nlen, t2); + + /* + * Multiply r with 1/s, result in t1, encoded in tx. + */ + br_i15_montymul(t1, r, s, n, n0i); + br_i15_encode(tx, nlen, t1); + + /* + * Compute the point x*Q + y*G. + */ + ulen = cd->generator_len; + memcpy(eU, pk->q, ulen); + res = impl->muladd(eU, NULL, ulen, + tx, nlen, ty, nlen, cd->curve); + + /* + * Get the X coordinate, reduce modulo the curve order, and + * compare with the 'r' value. + * + * The modular reduction can be done with subtractions because + * we work with curves of prime order, so the curve order is + * close to the field order (Hasse's theorem). + */ + br_i15_zero(t1, n[0]); + br_i15_decode(t1, &eU[1], ulen >> 1); + t1[0] = n[0]; + br_i15_sub(t1, n, br_i15_sub(t1, n, 0) ^ 1); + res &= ~br_i15_sub(t1, r, 1); + res &= br_i15_iszero(t1); + return res; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ecdsa_i31_bits.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ecdsa_i31_bits.c new file mode 100644 index 000000000..e0c246111 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ecdsa_i31_bits.c @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +void +br_ecdsa_i31_bits2int(uint32_t *x, + const void *src, size_t len, uint32_t ebitlen) +{ + uint32_t bitlen, hbitlen; + int sc; + + bitlen = ebitlen - (ebitlen >> 5); + hbitlen = (uint32_t)len << 3; + if (hbitlen > bitlen) { + len = (bitlen + 7) >> 3; + sc = (int)((hbitlen - bitlen) & 7); + } else { + sc = 0; + } + br_i31_zero(x, ebitlen); + br_i31_decode(x, src, len); + br_i31_rshift(x, sc); + x[0] = ebitlen; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ecdsa_i31_sign_asn1.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ecdsa_i31_sign_asn1.c new file mode 100644 index 000000000..2fd643c5e --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ecdsa_i31_sign_asn1.c @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +#define ORDER_LEN ((BR_MAX_EC_SIZE + 7) >> 3) + +/* see bearssl_ec.h */ +size_t +br_ecdsa_i31_sign_asn1(const br_ec_impl *impl, + const br_hash_class *hf, const void *hash_value, + const br_ec_private_key *sk, void *sig) +{ + unsigned char rsig[(ORDER_LEN << 1) + 12]; + size_t sig_len; + + sig_len = br_ecdsa_i31_sign_raw(impl, hf, hash_value, sk, rsig); + if (sig_len == 0) { + return 0; + } + sig_len = br_ecdsa_raw_to_asn1(rsig, sig_len); + memcpy(sig, rsig, sig_len); + return sig_len; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ecdsa_i31_sign_raw.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ecdsa_i31_sign_raw.c new file mode 100644 index 000000000..bed256da6 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ecdsa_i31_sign_raw.c @@ -0,0 +1,179 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +#define I31_LEN ((BR_MAX_EC_SIZE + 61) / 31) +#define POINT_LEN (1 + (((BR_MAX_EC_SIZE + 7) >> 3) << 1)) +#define ORDER_LEN ((BR_MAX_EC_SIZE + 7) >> 3) + +/* see bearssl_ec.h */ +size_t +br_ecdsa_i31_sign_raw(const br_ec_impl *impl, + const br_hash_class *hf, const void *hash_value, + const br_ec_private_key *sk, void *sig) +{ + /* + * IMPORTANT: this code is fit only for curves with a prime + * order. This is needed so that modular reduction of the X + * coordinate of a point can be done with a simple subtraction. + * We also rely on the last byte of the curve order to be distinct + * from 0 and 1. + */ + const br_ec_curve_def *cd; + uint32_t n[I31_LEN], r[I31_LEN], s[I31_LEN], x[I31_LEN]; + uint32_t m[I31_LEN], k[I31_LEN], t1[I31_LEN], t2[I31_LEN]; + unsigned char tt[ORDER_LEN << 1]; + unsigned char eU[POINT_LEN]; + size_t hash_len, nlen, ulen; + uint32_t n0i, ctl; + br_hmac_drbg_context drbg; + + /* + * If the curve is not supported, then exit with an error. + */ + if (((impl->supported_curves >> sk->curve) & 1) == 0) { + return 0; + } + + /* + * Get the curve parameters (generator and order). + */ + switch (sk->curve) { + case BR_EC_secp256r1: + cd = &br_secp256r1; + break; + case BR_EC_secp384r1: + cd = &br_secp384r1; + break; + case BR_EC_secp521r1: + cd = &br_secp521r1; + break; + default: + return 0; + } + + /* + * Get modulus. + */ + nlen = cd->order_len; + br_i31_decode(n, cd->order, nlen); + n0i = br_i31_ninv31(n[1]); + + /* + * Get private key as an i31 integer. This also checks that the + * private key is well-defined (not zero, and less than the + * curve order). + */ + if (!br_i31_decode_mod(x, sk->x, sk->xlen, n)) { + return 0; + } + if (br_i31_iszero(x)) { + return 0; + } + + /* + * Get hash length. + */ + hash_len = (hf->desc >> BR_HASHDESC_OUT_OFF) & BR_HASHDESC_OUT_MASK; + + /* + * Truncate and reduce the hash value modulo the curve order. + */ + br_ecdsa_i31_bits2int(m, hash_value, hash_len, n[0]); + br_i31_sub(m, n, br_i31_sub(m, n, 0) ^ 1); + + /* + * RFC 6979 generation of the "k" value. + * + * The process uses HMAC_DRBG (with the hash function used to + * process the message that is to be signed). The seed is the + * concatenation of the encodings of the private key and + * the hash value (after truncation and modular reduction). + */ + br_i31_encode(tt, nlen, x); + br_i31_encode(tt + nlen, nlen, m); + br_hmac_drbg_init(&drbg, hf, tt, nlen << 1); + for (;;) { + br_hmac_drbg_generate(&drbg, tt, nlen); + br_ecdsa_i31_bits2int(k, tt, nlen, n[0]); + if (br_i31_iszero(k)) { + continue; + } + if (br_i31_sub(k, n, 0)) { + break; + } + } + + /* + * Compute k*G and extract the X coordinate, then reduce it + * modulo the curve order. Since we support only curves with + * prime order, that reduction is only a matter of computing + * a subtraction. + */ + br_i31_encode(tt, nlen, k); + ulen = impl->mulgen(eU, tt, nlen, sk->curve); + br_i31_zero(r, n[0]); + br_i31_decode(r, &eU[1], ulen >> 1); + r[0] = n[0]; + br_i31_sub(r, n, br_i31_sub(r, n, 0) ^ 1); + + /* + * Compute 1/k in double-Montgomery representation. We do so by + * first converting _from_ Montgomery representation (twice), + * then using a modular exponentiation. + */ + br_i31_from_monty(k, n, n0i); + br_i31_from_monty(k, n, n0i); + memcpy(tt, cd->order, nlen); + tt[nlen - 1] -= 2; + br_i31_modpow(k, tt, nlen, n, n0i, t1, t2); + + /* + * Compute s = (m+xr)/k (mod n). + * The k[] array contains R^2/k (double-Montgomery representation); + * we thus can use direct Montgomery multiplications and conversions + * from Montgomery, avoiding any call to br_i31_to_monty() (which + * is slower). + */ + br_i31_from_monty(m, n, n0i); + br_i31_montymul(t1, x, r, n, n0i); + ctl = br_i31_add(t1, m, 1); + ctl |= br_i31_sub(t1, n, 0) ^ 1; + br_i31_sub(t1, n, ctl); + br_i31_montymul(s, t1, k, n, n0i); + + /* + * Encode r and s in the signature. + */ + br_i31_encode(sig, nlen, r); + br_i31_encode((unsigned char *)sig + nlen, nlen, s); + return nlen << 1; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ecdsa_i31_vrfy_asn1.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ecdsa_i31_vrfy_asn1.c new file mode 100644 index 000000000..7d3aa585b --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ecdsa_i31_vrfy_asn1.c @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +#define FIELD_LEN ((BR_MAX_EC_SIZE + 7) >> 3) + +/* see bearssl_ec.h */ +uint32_t +br_ecdsa_i31_vrfy_asn1(const br_ec_impl *impl, + const void *hash, size_t hash_len, + const br_ec_public_key *pk, + const void *sig, size_t sig_len) +{ + /* + * We use a double-sized buffer because a malformed ASN.1 signature + * may trigger a size expansion when converting to "raw" format. + */ + unsigned char rsig[(FIELD_LEN << 2) + 24]; + + if (sig_len > ((sizeof rsig) >> 1)) { + return 0; + } + memcpy(rsig, sig, sig_len); + sig_len = br_ecdsa_asn1_to_raw(rsig, sig_len); + return br_ecdsa_i31_vrfy_raw(impl, hash, hash_len, pk, rsig, sig_len); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ecdsa_i31_vrfy_raw.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ecdsa_i31_vrfy_raw.c new file mode 100644 index 000000000..79c8e557c --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ecdsa_i31_vrfy_raw.c @@ -0,0 +1,170 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +#define I31_LEN ((BR_MAX_EC_SIZE + 61) / 31) +#define POINT_LEN (1 + (((BR_MAX_EC_SIZE + 7) >> 3) << 1)) + +/* see bearssl_ec.h */ +uint32_t +br_ecdsa_i31_vrfy_raw(const br_ec_impl *impl, + const void *hash, size_t hash_len, + const br_ec_public_key *pk, + const void *sig, size_t sig_len) +{ + /* + * IMPORTANT: this code is fit only for curves with a prime + * order. This is needed so that modular reduction of the X + * coordinate of a point can be done with a simple subtraction. + */ + const br_ec_curve_def *cd; + uint32_t n[I31_LEN], r[I31_LEN], s[I31_LEN], t1[I31_LEN], t2[I31_LEN]; + unsigned char tx[(BR_MAX_EC_SIZE + 7) >> 3]; + unsigned char ty[(BR_MAX_EC_SIZE + 7) >> 3]; + unsigned char eU[POINT_LEN]; + size_t nlen, rlen, ulen; + uint32_t n0i, res; + + /* + * If the curve is not supported, then report an error. + */ + if (((impl->supported_curves >> pk->curve) & 1) == 0) { + return 0; + } + + /* + * Get the curve parameters (generator and order). + */ + switch (pk->curve) { + case BR_EC_secp256r1: + cd = &br_secp256r1; + break; + case BR_EC_secp384r1: + cd = &br_secp384r1; + break; + case BR_EC_secp521r1: + cd = &br_secp521r1; + break; + default: + return 0; + } + + /* + * Signature length must be even. + */ + if (sig_len & 1) { + return 0; + } + rlen = sig_len >> 1; + + /* + * Public key point must have the proper size for this curve. + */ + if (pk->qlen != cd->generator_len) { + return 0; + } + + /* + * Get modulus; then decode the r and s values. They must be + * lower than the modulus, and s must not be null. + */ + nlen = cd->order_len; + br_i31_decode(n, cd->order, nlen); + n0i = br_i31_ninv31(n[1]); + if (!br_i31_decode_mod(r, sig, rlen, n)) { + return 0; + } + if (!br_i31_decode_mod(s, (const unsigned char *)sig + rlen, rlen, n)) { + return 0; + } + if (br_i31_iszero(s)) { + return 0; + } + + /* + * Invert s. We do that with a modular exponentiation; we use + * the fact that for all the curves we support, the least + * significant byte is not 0 or 1, so we can subtract 2 without + * any carry to process. + * We also want 1/s in Montgomery representation, which can be + * done by converting _from_ Montgomery representation before + * the inversion (because (1/s)*R = 1/(s/R)). + */ + br_i31_from_monty(s, n, n0i); + memcpy(tx, cd->order, nlen); + tx[nlen - 1] -= 2; + br_i31_modpow(s, tx, nlen, n, n0i, t1, t2); + + /* + * Truncate the hash to the modulus length (in bits) and reduce + * it modulo the curve order. The modular reduction can be done + * with a subtraction since the truncation already reduced the + * value to the modulus bit length. + */ + br_ecdsa_i31_bits2int(t1, hash, hash_len, n[0]); + br_i31_sub(t1, n, br_i31_sub(t1, n, 0) ^ 1); + + /* + * Multiply the (truncated, reduced) hash value with 1/s, result in + * t2, encoded in ty. + */ + br_i31_montymul(t2, t1, s, n, n0i); + br_i31_encode(ty, nlen, t2); + + /* + * Multiply r with 1/s, result in t1, encoded in tx. + */ + br_i31_montymul(t1, r, s, n, n0i); + br_i31_encode(tx, nlen, t1); + + /* + * Compute the point x*Q + y*G. + */ + ulen = cd->generator_len; + memcpy(eU, pk->q, ulen); + res = impl->muladd(eU, NULL, ulen, + tx, nlen, ty, nlen, cd->curve); + + /* + * Get the X coordinate, reduce modulo the curve order, and + * compare with the 'r' value. + * + * The modular reduction can be done with subtractions because + * we work with curves of prime order, so the curve order is + * close to the field order (Hasse's theorem). + */ + br_i31_zero(t1, n[0]); + br_i31_decode(t1, &eU[1], ulen >> 1); + t1[0] = n[0]; + br_i31_sub(t1, n, br_i31_sub(t1, n, 0) ^ 1); + res &= ~br_i31_sub(t1, r, 1); + res &= br_i31_iszero(t1); + return res; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ecdsa_rta.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ecdsa_rta.c new file mode 100644 index 000000000..8d5d20443 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ecdsa_rta.c @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* + * Compute ASN.1 encoded length for the provided integer. The ASN.1 + * encoding is signed, so its leading bit must have value 0; it must + * also be of minimal length (so leading bytes of value 0 must be + * removed, except if that would contradict the rule about the sign + * bit). + */ +static size_t +asn1_int_length(const unsigned char *x, size_t xlen) +{ + while (xlen > 0 && *x == 0) { + x ++; + xlen --; + } + if (xlen == 0 || *x >= 0x80) { + xlen ++; + } + return xlen; +} + +/* see bearssl_ec.h */ +size_t +br_ecdsa_raw_to_asn1(void *sig, size_t sig_len) +{ + /* + * Internal buffer is large enough to accommodate a signature + * such that r and s fit on 125 bytes each (signed encoding), + * meaning a curve order of up to 999 bits. This is the limit + * that ensures "simple" length encodings. + */ + unsigned char *buf; + size_t hlen, rlen, slen, zlen, off; + unsigned char tmp[257]; + + buf = sig; + if ((sig_len & 1) != 0) { + return 0; + } + + /* + * Compute lengths for the two integers. + */ + hlen = sig_len >> 1; + rlen = asn1_int_length(buf, hlen); + slen = asn1_int_length(buf + hlen, hlen); + if (rlen > 125 || slen > 125) { + return 0; + } + + /* + * SEQUENCE header. + */ + tmp[0] = 0x30; + zlen = rlen + slen + 4; + if (zlen >= 0x80) { + tmp[1] = 0x81; + tmp[2] = zlen; + off = 3; + } else { + tmp[1] = zlen; + off = 2; + } + + /* + * First INTEGER (r). + */ + tmp[off ++] = 0x02; + tmp[off ++] = rlen; + if (rlen > hlen) { + tmp[off] = 0x00; + memcpy(tmp + off + 1, buf, hlen); + } else { + memcpy(tmp + off, buf + hlen - rlen, rlen); + } + off += rlen; + + /* + * Second INTEGER (s). + */ + tmp[off ++] = 0x02; + tmp[off ++] = slen; + if (slen > hlen) { + tmp[off] = 0x00; + memcpy(tmp + off + 1, buf + hlen, hlen); + } else { + memcpy(tmp + off, buf + sig_len - slen, slen); + } + off += slen; + + /* + * Return ASN.1 signature. + */ + memcpy(sig, tmp, off); + return off; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/enc16be.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/enc16be.c new file mode 100644 index 000000000..a75356fdc --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/enc16be.c @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +void +br_range_enc16be(void *dst, const uint16_t *v, size_t num) +{ + unsigned char *buf; + + buf = dst; + while (num -- > 0) { + br_enc16be(buf, *v ++); + buf += 2; + } +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/enc16le.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/enc16le.c new file mode 100644 index 000000000..688a9c5f7 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/enc16le.c @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +void +br_range_enc16le(void *dst, const uint16_t *v, size_t num) +{ + unsigned char *buf; + + buf = dst; + while (num -- > 0) { + br_enc16le(buf, *v ++); + buf += 2; + } +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/enc32be.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/enc32be.c new file mode 100644 index 000000000..dc7f8564a --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/enc32be.c @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +void +br_range_enc32be(void *dst, const uint32_t *v, size_t num) +{ + unsigned char *buf; + + buf = dst; + while (num -- > 0) { + br_enc32be(buf, *v ++); + buf += 4; + } +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/enc32le.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/enc32le.c new file mode 100644 index 000000000..c4a24b4c6 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/enc32le.c @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +void +br_range_enc32le(void *dst, const uint32_t *v, size_t num) +{ + unsigned char *buf; + + buf = dst; + while (num -- > 0) { + br_enc32le(buf, *v ++); + buf += 4; + } +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/enc64be.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/enc64be.c new file mode 100644 index 000000000..bc831502e --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/enc64be.c @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +void +br_range_enc64be(void *dst, const uint64_t *v, size_t num) +{ + unsigned char *buf; + + buf = dst; + while (num -- > 0) { + br_enc64be(buf, *v ++); + buf += 8; + } +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/enc64le.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/enc64le.c new file mode 100644 index 000000000..e549764e7 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/enc64le.c @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +void +br_range_enc64le(void *dst, const uint64_t *v, size_t num) +{ + unsigned char *buf; + + buf = dst; + while (num -- > 0) { + br_enc64le(buf, *v ++); + buf += 8; + } +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/encode_ec_pk8der.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/encode_ec_pk8der.c new file mode 100644 index 000000000..244147b7a --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/encode_ec_pk8der.c @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_x509.h */ +size_t +br_encode_ec_pkcs8_der(void *dest, + const br_ec_private_key *sk, const br_ec_public_key *pk) +{ + /* + * ASN.1 format: + * + * OneAsymmetricKey ::= SEQUENCE { + * version Version, + * privateKeyAlgorithm PrivateKeyAlgorithmIdentifier, + * privateKey PrivateKey, + * attributes [0] Attributes OPTIONAL, + * ..., + * [[2: publicKey [1] PublicKey OPTIONAL ]], + * ... + * } + * + * We don't include attributes or public key (the public key + * is included in the private key value instead). The + * 'version' field is an INTEGER that we will set to 0 + * (meaning 'v1', compatible with previous versions of PKCS#8). + * The 'privateKeyAlgorithm' structure is an AlgorithmIdentifier + * whose OID should be id-ecPublicKey, with, as parameters, the + * curve OID. The 'privateKey' is an OCTET STRING, whose value + * is the "raw DER" encoding of the key pair. + */ + + /* + * OID id-ecPublicKey (1.2.840.10045.2.1), DER-encoded (with + * the tag). + */ + static const unsigned char OID_ECPUBKEY[] = { + 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01 + }; + + size_t len_version, len_privateKeyAlgorithm, len_privateKeyValue; + size_t len_privateKey, len_seq; + const unsigned char *oid; + + oid = br_get_curve_OID(sk->curve); + if (oid == NULL) { + return 0; + } + len_version = 3; + len_privateKeyAlgorithm = 2 + sizeof OID_ECPUBKEY + 2 + oid[0]; + len_privateKeyValue = br_encode_ec_raw_der_inner(NULL, sk, pk, 0); + len_privateKey = 1 + len_of_len(len_privateKeyValue) + + len_privateKeyValue; + len_seq = len_version + len_privateKeyAlgorithm + len_privateKey; + + if (dest == NULL) { + return 1 + len_of_len(len_seq) + len_seq; + } else { + unsigned char *buf; + size_t lenlen; + + buf = dest; + *buf ++ = 0x30; /* SEQUENCE tag */ + lenlen = br_asn1_encode_length(buf, len_seq); + buf += lenlen; + + /* version */ + *buf ++ = 0x02; + *buf ++ = 0x01; + *buf ++ = 0x00; + + /* privateKeyAlgorithm */ + *buf ++ = 0x30; + *buf ++ = (sizeof OID_ECPUBKEY) + 2 + oid[0]; + memcpy(buf, OID_ECPUBKEY, sizeof OID_ECPUBKEY); + buf += sizeof OID_ECPUBKEY; + *buf ++ = 0x06; + memcpy(buf, oid, 1 + oid[0]); + buf += 1 + oid[0]; + + /* privateKey */ + *buf ++ = 0x04; + buf += br_asn1_encode_length(buf, len_privateKeyValue); + br_encode_ec_raw_der_inner(buf, sk, pk, 0); + + return 1 + lenlen + len_seq; + } +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/encode_ec_rawder.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/encode_ec_rawder.c new file mode 100644 index 000000000..f8db1fa14 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/encode_ec_rawder.c @@ -0,0 +1,166 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +const unsigned char * +br_get_curve_OID(int curve) +{ + static const unsigned char OID_secp256r1[] = { + 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07 + }; + static const unsigned char OID_secp384r1[] = { + 0x05, 0x2b, 0x81, 0x04, 0x00, 0x22 + }; + static const unsigned char OID_secp521r1[] = { + 0x05, 0x2b, 0x81, 0x04, 0x00, 0x23 + }; + + switch (curve) { + case BR_EC_secp256r1: return OID_secp256r1; + case BR_EC_secp384r1: return OID_secp384r1; + case BR_EC_secp521r1: return OID_secp521r1; + default: + return NULL; + } +} + +/* see inner.h */ +size_t +br_encode_ec_raw_der_inner(void *dest, + const br_ec_private_key *sk, const br_ec_public_key *pk, + int include_curve_oid) +{ + /* + * ASN.1 format: + * + * ECPrivateKey ::= SEQUENCE { + * version INTEGER { ecPrivkeyVer1(1) } (ecPrivkeyVer1), + * privateKey OCTET STRING, + * parameters [0] ECParameters {{ NamedCurve }} OPTIONAL, + * publicKey [1] BIT STRING OPTIONAL + * } + * + * The tages '[0]' and '[1]' are explicit. The 'ECParameters' + * is a CHOICE; in our case, it will always be an OBJECT IDENTIFIER + * that identifies the curve. + * + * The value of the 'privateKey' field is the raw unsigned big-endian + * encoding of the private key (integer modulo the curve subgroup + * order); there is no INTEGER tag, and the leading bit may be 1. + * Also, leading bytes of value 0x00 are _not_ removed. + * + * The 'publicKey' contents are the raw encoded public key point, + * normally uncompressed (leading byte of value 0x04, followed + * by the unsigned big-endian encodings of the X and Y coordinates, + * padded to the full field length if necessary). + */ + + size_t len_version, len_privateKey, len_parameters, len_publicKey; + size_t len_publicKey_bits, len_seq; + const unsigned char *oid; + + if (include_curve_oid) { + oid = br_get_curve_OID(sk->curve); + if (oid == NULL) { + return 0; + } + } else { + oid = NULL; + } + len_version = 3; + len_privateKey = 1 + len_of_len(sk->xlen) + sk->xlen; + if (include_curve_oid) { + len_parameters = 4 + oid[0]; + } else { + len_parameters = 0; + } + if (pk == NULL) { + len_publicKey = 0; + len_publicKey_bits = 0; + } else { + len_publicKey_bits = 2 + len_of_len(pk->qlen) + pk->qlen; + len_publicKey = 1 + len_of_len(len_publicKey_bits) + + len_publicKey_bits; + } + len_seq = len_version + len_privateKey + len_parameters + len_publicKey; + if (dest == NULL) { + return 1 + len_of_len(len_seq) + len_seq; + } else { + unsigned char *buf; + size_t lenlen; + + buf = dest; + *buf ++ = 0x30; /* SEQUENCE tag */ + lenlen = br_asn1_encode_length(buf, len_seq); + buf += lenlen; + + /* version */ + *buf ++ = 0x02; + *buf ++ = 0x01; + *buf ++ = 0x01; + + /* privateKey */ + *buf ++ = 0x04; + buf += br_asn1_encode_length(buf, sk->xlen); + memcpy(buf, sk->x, sk->xlen); + buf += sk->xlen; + + /* parameters */ + if (include_curve_oid) { + *buf ++ = 0xA0; + *buf ++ = oid[0] + 2; + *buf ++ = 0x06; + memcpy(buf, oid, oid[0] + 1); + buf += oid[0] + 1; + } + + /* publicKey */ + if (pk != NULL) { + *buf ++ = 0xA1; + buf += br_asn1_encode_length(buf, len_publicKey_bits); + *buf ++ = 0x03; + buf += br_asn1_encode_length(buf, pk->qlen + 1); + *buf ++ = 0x00; + memcpy(buf, pk->q, pk->qlen); + /* buf += pk->qlen; */ + } + + return 1 + lenlen + len_seq; + } +} + +/* see bearssl_x509.h */ +size_t +br_encode_ec_raw_der(void *dest, + const br_ec_private_key *sk, const br_ec_public_key *pk) +{ + return br_encode_ec_raw_der_inner(dest, sk, pk, 1); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/encode_rsa_pk8der.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/encode_rsa_pk8der.c new file mode 100644 index 000000000..12404c928 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/encode_rsa_pk8der.c @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_x509.h */ +size_t +br_encode_rsa_pkcs8_der(void *dest, const br_rsa_private_key *sk, + const br_rsa_public_key *pk, const void *d, size_t dlen) +{ + /* + * ASN.1 format: + * + * OneAsymmetricKey ::= SEQUENCE { + * version Version, + * privateKeyAlgorithm PrivateKeyAlgorithmIdentifier, + * privateKey PrivateKey, + * attributes [0] Attributes OPTIONAL, + * ..., + * [[2: publicKey [1] PublicKey OPTIONAL ]], + * ... + * } + * + * We don't include attributes or public key. The 'version' field + * is an INTEGER that we will set to 0 (meaning 'v1', compatible + * with previous versions of PKCS#8). The 'privateKeyAlgorithm' + * structure is an AlgorithmIdentifier whose OID should be + * rsaEncryption, with NULL parameters. The 'privateKey' is an + * OCTET STRING, whose value is the "raw DER" encoding of the + * key pair. + * + * Since the private key value comes last, this function really + * adds a header, which is mostly fixed (only some lengths have + * to be modified. + */ + + /* + * Concatenation of: + * - DER encoding of an INTEGER of value 0 (the 'version' field) + * - DER encoding of a PrivateKeyAlgorithmIdentifier that uses + * the rsaEncryption OID, and NULL parameters + * - An OCTET STRING tag + */ + static const unsigned char PK8_HEAD[] = { + 0x02, 0x01, 0x00, + 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, + 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, + 0x04 + }; + + size_t len_raw, len_seq; + + len_raw = br_encode_rsa_raw_der(NULL, sk, pk, d, dlen); + len_seq = (sizeof PK8_HEAD) + len_of_len(len_raw) + len_raw; + if (dest == NULL) { + return 1 + len_of_len(len_seq) + len_seq; + } else { + unsigned char *buf; + size_t lenlen; + + buf = dest; + *buf ++ = 0x30; /* SEQUENCE tag */ + lenlen = br_asn1_encode_length(buf, len_seq); + buf += lenlen; + + /* version, privateKeyAlgorithm, privateKey tag */ + memcpy(buf, PK8_HEAD, sizeof PK8_HEAD); + buf += sizeof PK8_HEAD; + + /* privateKey */ + buf += br_asn1_encode_length(buf, len_raw); + br_encode_rsa_raw_der(buf, sk, pk, d, dlen); + + return 1 + lenlen + len_seq; + } +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/encode_rsa_rawder.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/encode_rsa_rawder.c new file mode 100644 index 000000000..686161836 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/encode_rsa_rawder.c @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_x509.h */ +size_t +br_encode_rsa_raw_der(void *dest, const br_rsa_private_key *sk, + const br_rsa_public_key *pk, const void *d, size_t dlen) +{ + /* + * ASN.1 format: + * + * RSAPrivateKey ::= SEQUENCE { + * version Version, + * modulus INTEGER, -- n + * publicExponent INTEGER, -- e + * privateExponent INTEGER, -- d + * prime1 INTEGER, -- p + * prime2 INTEGER, -- q + * exponent1 INTEGER, -- d mod (p-1) + * exponent2 INTEGER, -- d mod (q-1) + * coefficient INTEGER, -- (inverse of q) mod p + * otherPrimeInfos OtherPrimeInfos OPTIONAL + * } + * + * The 'version' field is an INTEGER of value 0 (meaning: there + * are exactly two prime factors), and 'otherPrimeInfos' will + * be absent (because there are exactly two prime factors). + */ + + br_asn1_uint num[9]; + size_t u, slen; + + /* + * For all INTEGER values, get the pointer and length for the + * data bytes. + */ + num[0] = br_asn1_uint_prepare(NULL, 0); + num[1] = br_asn1_uint_prepare(pk->n, pk->nlen); + num[2] = br_asn1_uint_prepare(pk->e, pk->elen); + num[3] = br_asn1_uint_prepare(d, dlen); + num[4] = br_asn1_uint_prepare(sk->p, sk->plen); + num[5] = br_asn1_uint_prepare(sk->q, sk->qlen); + num[6] = br_asn1_uint_prepare(sk->dp, sk->dplen); + num[7] = br_asn1_uint_prepare(sk->dq, sk->dqlen); + num[8] = br_asn1_uint_prepare(sk->iq, sk->iqlen); + + /* + * Get the length of the SEQUENCE contents. + */ + slen = 0; + for (u = 0; u < 9; u ++) { + uint32_t ilen; + + ilen = num[u].asn1len; + slen += 1 + len_of_len(ilen) + ilen; + } + + if (dest == NULL) { + return 1 + len_of_len(slen) + slen; + } else { + unsigned char *buf; + size_t lenlen; + + buf = dest; + *buf ++ = 0x30; /* SEQUENCE tag */ + lenlen = br_asn1_encode_length(buf, slen); + buf += lenlen; + for (u = 0; u < 9; u ++) { + buf += br_asn1_encode_uint(buf, num[u]); + } + return 1 + lenlen + slen; + } +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/gcm.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/gcm.c new file mode 100644 index 000000000..1ae6b0984 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/gcm.c @@ -0,0 +1,323 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* + * Implementation Notes + * ==================== + * + * Since CTR and GHASH implementations can handle only full blocks, a + * 16-byte buffer (buf[]) is maintained in the context: + * + * - When processing AAD, buf[] contains the 0-15 unprocessed bytes. + * + * - When doing CTR encryption / decryption, buf[] contains the AES output + * for the last partial block, to be used with the next few bytes of + * data, as well as the already encrypted bytes. For instance, if the + * processed data length so far is 21 bytes, then buf[0..4] contains + * the five last encrypted bytes, and buf[5..15] contains the next 11 + * AES output bytes to be XORed with the next 11 bytes of input. + * + * The recorded AES output bytes are used to complete the block when + * the corresponding bytes are obtained. Note that buf[] always + * contains the _encrypted_ bytes, whether we apply encryption or + * decryption: these bytes are used as input to GHASH when the block + * is complete. + * + * In both cases, the low bits of the data length counters (count_aad, + * count_ctr) are used to work out the current situation. + */ + +/* see bearssl_aead.h */ +void +br_gcm_init(br_gcm_context *ctx, const br_block_ctr_class **bctx, br_ghash gh) +{ + unsigned char iv[12]; + + ctx->vtable = &br_gcm_vtable; + ctx->bctx = bctx; + ctx->gh = gh; + + /* + * The GHASH key h[] is the raw encryption of the all-zero + * block. Since we only have a CTR implementation, we use it + * with an all-zero IV and a zero counter, to CTR-encrypt an + * all-zero block. + */ + memset(ctx->h, 0, sizeof ctx->h); + memset(iv, 0, sizeof iv); + (*bctx)->run(bctx, iv, 0, ctx->h, sizeof ctx->h); +} + +/* see bearssl_aead.h */ +void +br_gcm_reset(br_gcm_context *ctx, const void *iv, size_t len) +{ + /* + * If the provided nonce is 12 bytes, then this is the initial + * IV for CTR mode; it will be used with a counter that starts + * at 2 (value 1 is for encrypting the GHASH output into the tag). + * + * If the provided nonce has any other length, then it is hashed + * (with GHASH) into a 16-byte value that will be the IV for CTR + * (both 12-byte IV and 32-bit counter). + */ + if (len == 12) { + memcpy(ctx->j0_1, iv, 12); + ctx->j0_2 = 1; + } else { + unsigned char ty[16], tmp[16]; + + memset(ty, 0, sizeof ty); + ctx->gh(ty, ctx->h, iv, len); + memset(tmp, 0, 8); + br_enc64be(tmp + 8, (uint64_t)len << 3); + ctx->gh(ty, ctx->h, tmp, 16); + memcpy(ctx->j0_1, ty, 12); + ctx->j0_2 = br_dec32be(ty + 12); + } + ctx->jc = ctx->j0_2 + 1; + memset(ctx->y, 0, sizeof ctx->y); + ctx->count_aad = 0; + ctx->count_ctr = 0; +} + +/* see bearssl_aead.h */ +void +br_gcm_aad_inject(br_gcm_context *ctx, const void *data, size_t len) +{ + size_t ptr, dlen; + + ptr = (size_t)ctx->count_aad & (size_t)15; + if (ptr != 0) { + /* + * If there is a partial block, then we first try to + * complete it. + */ + size_t clen; + + clen = 16 - ptr; + if (len < clen) { + memcpy(ctx->buf + ptr, data, len); + ctx->count_aad += (uint64_t)len; + return; + } + memcpy(ctx->buf + ptr, data, clen); + ctx->gh(ctx->y, ctx->h, ctx->buf, 16); + data = (const unsigned char *)data + clen; + len -= clen; + ctx->count_aad += (uint64_t)clen; + } + + /* + * Now AAD is aligned on a 16-byte block (with regards to GHASH). + * We process all complete blocks, and save the last partial + * block. + */ + dlen = len & ~(size_t)15; + ctx->gh(ctx->y, ctx->h, data, dlen); + memcpy(ctx->buf, (const unsigned char *)data + dlen, len - dlen); + ctx->count_aad += (uint64_t)len; +} + +/* see bearssl_aead.h */ +void +br_gcm_flip(br_gcm_context *ctx) +{ + /* + * We complete the GHASH computation if there is a partial block. + * The GHASH implementation automatically applies padding with + * zeros. + */ + size_t ptr; + + ptr = (size_t)ctx->count_aad & (size_t)15; + if (ptr != 0) { + ctx->gh(ctx->y, ctx->h, ctx->buf, ptr); + } +} + +/* see bearssl_aead.h */ +void +br_gcm_run(br_gcm_context *ctx, int encrypt, void *data, size_t len) +{ + unsigned char *buf; + size_t ptr, dlen; + + buf = data; + ptr = (size_t)ctx->count_ctr & (size_t)15; + if (ptr != 0) { + /* + * If we have a partial block, then we try to complete it. + */ + size_t u, clen; + + clen = 16 - ptr; + if (len < clen) { + clen = len; + } + for (u = 0; u < clen; u ++) { + unsigned x, y; + + x = buf[u]; + y = x ^ ctx->buf[ptr + u]; + ctx->buf[ptr + u] = encrypt ? y : x; + buf[u] = y; + } + ctx->count_ctr += (uint64_t)clen; + buf += clen; + len -= clen; + if (ptr + clen < 16) { + return; + } + ctx->gh(ctx->y, ctx->h, ctx->buf, 16); + } + + /* + * Process full blocks. + */ + dlen = len & ~(size_t)15; + if (!encrypt) { + ctx->gh(ctx->y, ctx->h, buf, dlen); + } + ctx->jc = (*ctx->bctx)->run(ctx->bctx, ctx->j0_1, ctx->jc, buf, dlen); + if (encrypt) { + ctx->gh(ctx->y, ctx->h, buf, dlen); + } + buf += dlen; + len -= dlen; + ctx->count_ctr += (uint64_t)dlen; + + if (len > 0) { + /* + * There is a partial block. + */ + size_t u; + + memset(ctx->buf, 0, sizeof ctx->buf); + ctx->jc = (*ctx->bctx)->run(ctx->bctx, ctx->j0_1, + ctx->jc, ctx->buf, 16); + for (u = 0; u < len; u ++) { + unsigned x, y; + + x = buf[u]; + y = x ^ ctx->buf[u]; + ctx->buf[u] = encrypt ? y : x; + buf[u] = y; + } + ctx->count_ctr += (uint64_t)len; + } +} + +/* see bearssl_aead.h */ +void +br_gcm_get_tag(br_gcm_context *ctx, void *tag) +{ + size_t ptr; + unsigned char tmp[16]; + + ptr = (size_t)ctx->count_ctr & (size_t)15; + if (ptr > 0) { + /* + * There is a partial block: encrypted/decrypted data has + * been produced, but the encrypted bytes must still be + * processed by GHASH. + */ + ctx->gh(ctx->y, ctx->h, ctx->buf, ptr); + } + + /* + * Final block for GHASH: the AAD and plaintext lengths (in bits). + */ + br_enc64be(tmp, ctx->count_aad << 3); + br_enc64be(tmp + 8, ctx->count_ctr << 3); + ctx->gh(ctx->y, ctx->h, tmp, 16); + + /* + * Tag is the GHASH output XORed with the encryption of the + * nonce with the initial counter value. + */ + memcpy(tag, ctx->y, 16); + (*ctx->bctx)->run(ctx->bctx, ctx->j0_1, ctx->j0_2, tag, 16); +} + +/* see bearssl_aead.h */ +void +br_gcm_get_tag_trunc(br_gcm_context *ctx, void *tag, size_t len) +{ + unsigned char tmp[16]; + + br_gcm_get_tag(ctx, tmp); + memcpy(tag, tmp, len); +} + +/* see bearssl_aead.h */ +uint32_t +br_gcm_check_tag_trunc(br_gcm_context *ctx, const void *tag, size_t len) +{ + unsigned char tmp[16]; + size_t u; + int x; + + br_gcm_get_tag(ctx, tmp); + x = 0; + for (u = 0; u < len; u ++) { + x |= tmp[u] ^ ((const unsigned char *)tag)[u]; + } + return EQ0(x); +} + +/* see bearssl_aead.h */ +uint32_t +br_gcm_check_tag(br_gcm_context *ctx, const void *tag) +{ + return br_gcm_check_tag_trunc(ctx, tag, 16); +} + +/* see bearssl_aead.h */ +const br_aead_class br_gcm_vtable = { + 16, + (void (*)(const br_aead_class **, const void *, size_t)) + &br_gcm_reset, + (void (*)(const br_aead_class **, const void *, size_t)) + &br_gcm_aad_inject, + (void (*)(const br_aead_class **)) + &br_gcm_flip, + (void (*)(const br_aead_class **, int, void *, size_t)) + &br_gcm_run, + (void (*)(const br_aead_class **, void *)) + &br_gcm_get_tag, + (uint32_t (*)(const br_aead_class **, const void *)) + &br_gcm_check_tag, + (void (*)(const br_aead_class **, void *, size_t)) + &br_gcm_get_tag_trunc, + (uint32_t (*)(const br_aead_class **, const void *, size_t)) + &br_gcm_check_tag_trunc +}; + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ghash_ctmul.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ghash_ctmul.c new file mode 100644 index 000000000..009e42bc3 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ghash_ctmul.c @@ -0,0 +1,350 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* + * We compute "carryless multiplications" through normal integer + * multiplications, masking out enough bits to create "holes" in which + * carries may expand without altering our bits; we really use 8 data + * bits per 32-bit word, spaced every fourth bit. Accumulated carries + * may not exceed 8 in total, which fits in 4 bits. + * + * It would be possible to use a 3-bit spacing, allowing two operands, + * one with 7 non-zero data bits, the other one with 10 or 11 non-zero + * data bits; this asymmetric splitting makes the overall code more + * complex with thresholds and exceptions, and does not appear to be + * worth the effort. + */ + +/* + * We cannot really autodetect whether multiplications are "slow" or + * not. A typical example is the ARM Cortex M0+, which exists in two + * versions: one with a 1-cycle multiplication opcode, the other with + * a 32-cycle multiplication opcode. They both use exactly the same + * architecture and ABI, and cannot be distinguished from each other + * at compile-time. + * + * Since most modern CPU (even embedded CPU) still have fast + * multiplications, we use the "fast mul" code by default. + */ + +#if BR_SLOW_MUL + +/* + * This implementation uses Karatsuba-like reduction to make fewer + * integer multiplications (9 instead of 16), at the expense of extra + * logical operations (XOR, shifts...). On modern x86 CPU that offer + * fast, pipelined multiplications, this code is about twice slower than + * the simpler code with 16 multiplications. This tendency may be + * reversed on low-end platforms with expensive multiplications. + */ + +#define MUL32(h, l, x, y) do { \ + uint64_t mul32tmp = MUL(x, y); \ + (h) = (uint32_t)(mul32tmp >> 32); \ + (l) = (uint32_t)mul32tmp; \ + } while (0) + +static inline void +bmul(uint32_t *hi, uint32_t *lo, uint32_t x, uint32_t y) +{ + uint32_t x0, x1, x2, x3; + uint32_t y0, y1, y2, y3; + uint32_t a0, a1, a2, a3, a4, a5, a6, a7, a8; + uint32_t b0, b1, b2, b3, b4, b5, b6, b7, b8; + + x0 = x & (uint32_t)0x11111111; + x1 = x & (uint32_t)0x22222222; + x2 = x & (uint32_t)0x44444444; + x3 = x & (uint32_t)0x88888888; + y0 = y & (uint32_t)0x11111111; + y1 = y & (uint32_t)0x22222222; + y2 = y & (uint32_t)0x44444444; + y3 = y & (uint32_t)0x88888888; + + /* + * (x0+W*x1)*(y0+W*y1) -> a0:b0 + * (x2+W*x3)*(y2+W*y3) -> a3:b3 + * ((x0+x2)+W*(x1+x3))*((y0+y2)+W*(y1+y3)) -> a6:b6 + */ + a0 = x0; + b0 = y0; + a1 = x1 >> 1; + b1 = y1 >> 1; + a2 = a0 ^ a1; + b2 = b0 ^ b1; + a3 = x2 >> 2; + b3 = y2 >> 2; + a4 = x3 >> 3; + b4 = y3 >> 3; + a5 = a3 ^ a4; + b5 = b3 ^ b4; + a6 = a0 ^ a3; + b6 = b0 ^ b3; + a7 = a1 ^ a4; + b7 = b1 ^ b4; + a8 = a6 ^ a7; + b8 = b6 ^ b7; + + MUL32(b0, a0, b0, a0); + MUL32(b1, a1, b1, a1); + MUL32(b2, a2, b2, a2); + MUL32(b3, a3, b3, a3); + MUL32(b4, a4, b4, a4); + MUL32(b5, a5, b5, a5); + MUL32(b6, a6, b6, a6); + MUL32(b7, a7, b7, a7); + MUL32(b8, a8, b8, a8); + + a0 &= (uint32_t)0x11111111; + a1 &= (uint32_t)0x11111111; + a2 &= (uint32_t)0x11111111; + a3 &= (uint32_t)0x11111111; + a4 &= (uint32_t)0x11111111; + a5 &= (uint32_t)0x11111111; + a6 &= (uint32_t)0x11111111; + a7 &= (uint32_t)0x11111111; + a8 &= (uint32_t)0x11111111; + b0 &= (uint32_t)0x11111111; + b1 &= (uint32_t)0x11111111; + b2 &= (uint32_t)0x11111111; + b3 &= (uint32_t)0x11111111; + b4 &= (uint32_t)0x11111111; + b5 &= (uint32_t)0x11111111; + b6 &= (uint32_t)0x11111111; + b7 &= (uint32_t)0x11111111; + b8 &= (uint32_t)0x11111111; + + a2 ^= a0 ^ a1; + b2 ^= b0 ^ b1; + a0 ^= (a2 << 1) ^ (a1 << 2); + b0 ^= (b2 << 1) ^ (b1 << 2); + a5 ^= a3 ^ a4; + b5 ^= b3 ^ b4; + a3 ^= (a5 << 1) ^ (a4 << 2); + b3 ^= (b5 << 1) ^ (b4 << 2); + a8 ^= a6 ^ a7; + b8 ^= b6 ^ b7; + a6 ^= (a8 << 1) ^ (a7 << 2); + b6 ^= (b8 << 1) ^ (b7 << 2); + a6 ^= a0 ^ a3; + b6 ^= b0 ^ b3; + *lo = a0 ^ (a6 << 2) ^ (a3 << 4); + *hi = b0 ^ (b6 << 2) ^ (b3 << 4) ^ (a6 >> 30) ^ (a3 >> 28); +} + +#else + +/* + * Simple multiplication in GF(2)[X], using 16 integer multiplications. + */ + +static inline void +bmul(uint32_t *hi, uint32_t *lo, uint32_t x, uint32_t y) +{ + uint32_t x0, x1, x2, x3; + uint32_t y0, y1, y2, y3; + uint64_t z0, z1, z2, z3; + uint64_t z; + + x0 = x & (uint32_t)0x11111111; + x1 = x & (uint32_t)0x22222222; + x2 = x & (uint32_t)0x44444444; + x3 = x & (uint32_t)0x88888888; + y0 = y & (uint32_t)0x11111111; + y1 = y & (uint32_t)0x22222222; + y2 = y & (uint32_t)0x44444444; + y3 = y & (uint32_t)0x88888888; + z0 = MUL(x0, y0) ^ MUL(x1, y3) ^ MUL(x2, y2) ^ MUL(x3, y1); + z1 = MUL(x0, y1) ^ MUL(x1, y0) ^ MUL(x2, y3) ^ MUL(x3, y2); + z2 = MUL(x0, y2) ^ MUL(x1, y1) ^ MUL(x2, y0) ^ MUL(x3, y3); + z3 = MUL(x0, y3) ^ MUL(x1, y2) ^ MUL(x2, y1) ^ MUL(x3, y0); + z0 &= (uint64_t)0x1111111111111111; + z1 &= (uint64_t)0x2222222222222222; + z2 &= (uint64_t)0x4444444444444444; + z3 &= (uint64_t)0x8888888888888888; + z = z0 | z1 | z2 | z3; + *lo = (uint32_t)z; + *hi = (uint32_t)(z >> 32); +} + +#endif + +/* see bearssl_hash.h */ +void +br_ghash_ctmul(void *y, const void *h, const void *data, size_t len) +{ + const unsigned char *buf, *hb; + unsigned char *yb; + uint32_t yw[4]; + uint32_t hw[4]; + + /* + * Throughout the loop we handle the y and h values as arrays + * of 32-bit words. + */ + buf = data; + yb = y; + hb = h; + yw[3] = br_dec32be(yb); + yw[2] = br_dec32be(yb + 4); + yw[1] = br_dec32be(yb + 8); + yw[0] = br_dec32be(yb + 12); + hw[3] = br_dec32be(hb); + hw[2] = br_dec32be(hb + 4); + hw[1] = br_dec32be(hb + 8); + hw[0] = br_dec32be(hb + 12); + while (len > 0) { + const unsigned char *src; + unsigned char tmp[16]; + int i; + uint32_t a[9], b[9], zw[8]; + uint32_t c0, c1, c2, c3, d0, d1, d2, d3, e0, e1, e2, e3; + + /* + * Get the next 16-byte block (using zero-padding if + * necessary). + */ + if (len >= 16) { + src = buf; + buf += 16; + len -= 16; + } else { + memcpy(tmp, buf, len); + memset(tmp + len, 0, (sizeof tmp) - len); + src = tmp; + len = 0; + } + + /* + * Decode the block. The GHASH standard mandates + * big-endian encoding. + */ + yw[3] ^= br_dec32be(src); + yw[2] ^= br_dec32be(src + 4); + yw[1] ^= br_dec32be(src + 8); + yw[0] ^= br_dec32be(src + 12); + + /* + * We multiply two 128-bit field elements. We use + * Karatsuba to turn that into three 64-bit + * multiplications, which are themselves done with a + * total of nine 32-bit multiplications. + */ + + /* + * y[0,1]*h[0,1] -> 0..2 + * y[2,3]*h[2,3] -> 3..5 + * (y[0,1]+y[2,3])*(h[0,1]+h[2,3]) -> 6..8 + */ + a[0] = yw[0]; + b[0] = hw[0]; + a[1] = yw[1]; + b[1] = hw[1]; + a[2] = a[0] ^ a[1]; + b[2] = b[0] ^ b[1]; + + a[3] = yw[2]; + b[3] = hw[2]; + a[4] = yw[3]; + b[4] = hw[3]; + a[5] = a[3] ^ a[4]; + b[5] = b[3] ^ b[4]; + + a[6] = a[0] ^ a[3]; + b[6] = b[0] ^ b[3]; + a[7] = a[1] ^ a[4]; + b[7] = b[1] ^ b[4]; + a[8] = a[6] ^ a[7]; + b[8] = b[6] ^ b[7]; + + for (i = 0; i < 9; i ++) { + bmul(&b[i], &a[i], b[i], a[i]); + } + + c0 = a[0]; + c1 = b[0] ^ a[2] ^ a[0] ^ a[1]; + c2 = a[1] ^ b[2] ^ b[0] ^ b[1]; + c3 = b[1]; + d0 = a[3]; + d1 = b[3] ^ a[5] ^ a[3] ^ a[4]; + d2 = a[4] ^ b[5] ^ b[3] ^ b[4]; + d3 = b[4]; + e0 = a[6]; + e1 = b[6] ^ a[8] ^ a[6] ^ a[7]; + e2 = a[7] ^ b[8] ^ b[6] ^ b[7]; + e3 = b[7]; + + e0 ^= c0 ^ d0; + e1 ^= c1 ^ d1; + e2 ^= c2 ^ d2; + e3 ^= c3 ^ d3; + c2 ^= e0; + c3 ^= e1; + d0 ^= e2; + d1 ^= e3; + + /* + * GHASH specification has the bits "reversed" (most + * significant is in fact least significant), which does + * not matter for a carryless multiplication, except that + * the 255-bit result must be shifted by 1 bit. + */ + zw[0] = c0 << 1; + zw[1] = (c1 << 1) | (c0 >> 31); + zw[2] = (c2 << 1) | (c1 >> 31); + zw[3] = (c3 << 1) | (c2 >> 31); + zw[4] = (d0 << 1) | (c3 >> 31); + zw[5] = (d1 << 1) | (d0 >> 31); + zw[6] = (d2 << 1) | (d1 >> 31); + zw[7] = (d3 << 1) | (d2 >> 31); + + /* + * We now do the reduction modulo the field polynomial + * to get back to 128 bits. + */ + for (i = 0; i < 4; i ++) { + uint32_t lw; + + lw = zw[i]; + zw[i + 4] ^= lw ^ (lw >> 1) ^ (lw >> 2) ^ (lw >> 7); + zw[i + 3] ^= (lw << 31) ^ (lw << 30) ^ (lw << 25); + } + memcpy(yw, zw + 4, sizeof yw); + } + + /* + * Encode back the result. + */ + br_enc32be(yb, yw[3]); + br_enc32be(yb + 4, yw[2]); + br_enc32be(yb + 8, yw[1]); + br_enc32be(yb + 12, yw[0]); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ghash_ctmul32.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ghash_ctmul32.c new file mode 100644 index 000000000..8a2a3cef4 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ghash_ctmul32.c @@ -0,0 +1,256 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* + * This implementation uses 32-bit multiplications, and only the low + * 32 bits for each multiplication result. This is meant primarily for + * the ARM Cortex M0 and M0+, whose multiplication opcode does not yield + * the upper 32 bits; but it might also be useful on architectures where + * access to the upper 32 bits requires use of specific registers that + * create contention (e.g. on i386, "mul" necessarily outputs the result + * in edx:eax, while "imul" can use any registers but is limited to the + * low 32 bits). + * + * The implementation trick that is used here is bit-reversing (bit 0 + * is swapped with bit 31, bit 1 with bit 30, and so on). In GF(2)[X], + * for all values x and y, we have: + * rev32(x) * rev32(y) = rev64(x * y) + * In other words, if we bit-reverse (over 32 bits) the operands, then we + * bit-reverse (over 64 bits) the result. + */ + +/* + * Multiplication in GF(2)[X], truncated to its low 32 bits. + */ +static inline uint32_t +bmul32(uint32_t x, uint32_t y) +{ + uint32_t x0, x1, x2, x3; + uint32_t y0, y1, y2, y3; + uint32_t z0, z1, z2, z3; + + x0 = x & (uint32_t)0x11111111; + x1 = x & (uint32_t)0x22222222; + x2 = x & (uint32_t)0x44444444; + x3 = x & (uint32_t)0x88888888; + y0 = y & (uint32_t)0x11111111; + y1 = y & (uint32_t)0x22222222; + y2 = y & (uint32_t)0x44444444; + y3 = y & (uint32_t)0x88888888; + z0 = (x0 * y0) ^ (x1 * y3) ^ (x2 * y2) ^ (x3 * y1); + z1 = (x0 * y1) ^ (x1 * y0) ^ (x2 * y3) ^ (x3 * y2); + z2 = (x0 * y2) ^ (x1 * y1) ^ (x2 * y0) ^ (x3 * y3); + z3 = (x0 * y3) ^ (x1 * y2) ^ (x2 * y1) ^ (x3 * y0); + z0 &= (uint32_t)0x11111111; + z1 &= (uint32_t)0x22222222; + z2 &= (uint32_t)0x44444444; + z3 &= (uint32_t)0x88888888; + return z0 | z1 | z2 | z3; +} + +/* + * Bit-reverse a 32-bit word. + */ +static uint32_t +rev32(uint32_t x) +{ +#define RMS(m, s) do { \ + x = ((x & (uint32_t)(m)) << (s)) \ + | ((x >> (s)) & (uint32_t)(m)); \ + } while (0) + + RMS(0x55555555, 1); + RMS(0x33333333, 2); + RMS(0x0F0F0F0F, 4); + RMS(0x00FF00FF, 8); + return (x << 16) | (x >> 16); + +#undef RMS +} + +/* see bearssl_hash.h */ +void +br_ghash_ctmul32(void *y, const void *h, const void *data, size_t len) +{ + /* + * This implementation is similar to br_ghash_ctmul() except + * that we have to do the multiplication twice, with the + * "normal" and "bit reversed" operands. Hence we end up with + * eighteen 32-bit multiplications instead of nine. + */ + + const unsigned char *buf, *hb; + unsigned char *yb; + uint32_t yw[4]; + uint32_t hw[4], hwr[4]; + + buf = data; + yb = y; + hb = h; + yw[3] = br_dec32be(yb); + yw[2] = br_dec32be(yb + 4); + yw[1] = br_dec32be(yb + 8); + yw[0] = br_dec32be(yb + 12); + hw[3] = br_dec32be(hb); + hw[2] = br_dec32be(hb + 4); + hw[1] = br_dec32be(hb + 8); + hw[0] = br_dec32be(hb + 12); + hwr[3] = rev32(hw[3]); + hwr[2] = rev32(hw[2]); + hwr[1] = rev32(hw[1]); + hwr[0] = rev32(hw[0]); + while (len > 0) { + const unsigned char *src; + unsigned char tmp[16]; + int i; + uint32_t a[18], b[18], c[18]; + uint32_t d0, d1, d2, d3, d4, d5, d6, d7; + uint32_t zw[8]; + + if (len >= 16) { + src = buf; + buf += 16; + len -= 16; + } else { + memcpy(tmp, buf, len); + memset(tmp + len, 0, (sizeof tmp) - len); + src = tmp; + len = 0; + } + yw[3] ^= br_dec32be(src); + yw[2] ^= br_dec32be(src + 4); + yw[1] ^= br_dec32be(src + 8); + yw[0] ^= br_dec32be(src + 12); + + /* + * We are using Karatsuba: the 128x128 multiplication is + * reduced to three 64x64 multiplications, hence nine + * 32x32 multiplications. With the bit-reversal trick, + * we have to perform 18 32x32 multiplications. + */ + + /* + * y[0,1]*h[0,1] -> 0,1,4 + * y[2,3]*h[2,3] -> 2,3,5 + * (y[0,1]+y[2,3])*(h[0,1]+h[2,3]) -> 6,7,8 + */ + + a[0] = yw[0]; + a[1] = yw[1]; + a[2] = yw[2]; + a[3] = yw[3]; + a[4] = a[0] ^ a[1]; + a[5] = a[2] ^ a[3]; + a[6] = a[0] ^ a[2]; + a[7] = a[1] ^ a[3]; + a[8] = a[6] ^ a[7]; + + a[ 9] = rev32(yw[0]); + a[10] = rev32(yw[1]); + a[11] = rev32(yw[2]); + a[12] = rev32(yw[3]); + a[13] = a[ 9] ^ a[10]; + a[14] = a[11] ^ a[12]; + a[15] = a[ 9] ^ a[11]; + a[16] = a[10] ^ a[12]; + a[17] = a[15] ^ a[16]; + + b[0] = hw[0]; + b[1] = hw[1]; + b[2] = hw[2]; + b[3] = hw[3]; + b[4] = b[0] ^ b[1]; + b[5] = b[2] ^ b[3]; + b[6] = b[0] ^ b[2]; + b[7] = b[1] ^ b[3]; + b[8] = b[6] ^ b[7]; + + b[ 9] = hwr[0]; + b[10] = hwr[1]; + b[11] = hwr[2]; + b[12] = hwr[3]; + b[13] = b[ 9] ^ b[10]; + b[14] = b[11] ^ b[12]; + b[15] = b[ 9] ^ b[11]; + b[16] = b[10] ^ b[12]; + b[17] = b[15] ^ b[16]; + + for (i = 0; i < 18; i ++) { + c[i] = bmul32(a[i], b[i]); + } + + c[4] ^= c[0] ^ c[1]; + c[5] ^= c[2] ^ c[3]; + c[8] ^= c[6] ^ c[7]; + + c[13] ^= c[ 9] ^ c[10]; + c[14] ^= c[11] ^ c[12]; + c[17] ^= c[15] ^ c[16]; + + /* + * y[0,1]*h[0,1] -> 0,9^4,1^13,10 + * y[2,3]*h[2,3] -> 2,11^5,3^14,12 + * (y[0,1]+y[2,3])*(h[0,1]+h[2,3]) -> 6,15^8,7^17,16 + */ + d0 = c[0]; + d1 = c[4] ^ (rev32(c[9]) >> 1); + d2 = c[1] ^ c[0] ^ c[2] ^ c[6] ^ (rev32(c[13]) >> 1); + d3 = c[4] ^ c[5] ^ c[8] + ^ (rev32(c[10] ^ c[9] ^ c[11] ^ c[15]) >> 1); + d4 = c[2] ^ c[1] ^ c[3] ^ c[7] + ^ (rev32(c[13] ^ c[14] ^ c[17]) >> 1); + d5 = c[5] ^ (rev32(c[11] ^ c[10] ^ c[12] ^ c[16]) >> 1); + d6 = c[3] ^ (rev32(c[14]) >> 1); + d7 = rev32(c[12]) >> 1; + + zw[0] = d0 << 1; + zw[1] = (d1 << 1) | (d0 >> 31); + zw[2] = (d2 << 1) | (d1 >> 31); + zw[3] = (d3 << 1) | (d2 >> 31); + zw[4] = (d4 << 1) | (d3 >> 31); + zw[5] = (d5 << 1) | (d4 >> 31); + zw[6] = (d6 << 1) | (d5 >> 31); + zw[7] = (d7 << 1) | (d6 >> 31); + + for (i = 0; i < 4; i ++) { + uint32_t lw; + + lw = zw[i]; + zw[i + 4] ^= lw ^ (lw >> 1) ^ (lw >> 2) ^ (lw >> 7); + zw[i + 3] ^= (lw << 31) ^ (lw << 30) ^ (lw << 25); + } + memcpy(yw, zw + 4, sizeof yw); + } + br_enc32be(yb, yw[3]); + br_enc32be(yb + 4, yw[2]); + br_enc32be(yb + 8, yw[1]); + br_enc32be(yb + 12, yw[0]); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ghash_ctmul64.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ghash_ctmul64.c new file mode 100644 index 000000000..349868510 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ghash_ctmul64.c @@ -0,0 +1,159 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* + * This is the 64-bit variant of br_ghash_ctmul32(), with 64-bit operands + * and bit reversal of 64-bit words. + */ + +static inline uint64_t +bmul64(uint64_t x, uint64_t y) +{ + uint64_t x0, x1, x2, x3; + uint64_t y0, y1, y2, y3; + uint64_t z0, z1, z2, z3; + + x0 = x & (uint64_t)0x1111111111111111; + x1 = x & (uint64_t)0x2222222222222222; + x2 = x & (uint64_t)0x4444444444444444; + x3 = x & (uint64_t)0x8888888888888888; + y0 = y & (uint64_t)0x1111111111111111; + y1 = y & (uint64_t)0x2222222222222222; + y2 = y & (uint64_t)0x4444444444444444; + y3 = y & (uint64_t)0x8888888888888888; + z0 = (x0 * y0) ^ (x1 * y3) ^ (x2 * y2) ^ (x3 * y1); + z1 = (x0 * y1) ^ (x1 * y0) ^ (x2 * y3) ^ (x3 * y2); + z2 = (x0 * y2) ^ (x1 * y1) ^ (x2 * y0) ^ (x3 * y3); + z3 = (x0 * y3) ^ (x1 * y2) ^ (x2 * y1) ^ (x3 * y0); + z0 &= (uint64_t)0x1111111111111111; + z1 &= (uint64_t)0x2222222222222222; + z2 &= (uint64_t)0x4444444444444444; + z3 &= (uint64_t)0x8888888888888888; + return z0 | z1 | z2 | z3; +} + +static uint64_t +rev64(uint64_t x) +{ +#define RMS(m, s) do { \ + x = ((x & (uint64_t)(m)) << (s)) \ + | ((x >> (s)) & (uint64_t)(m)); \ + } while (0) + + RMS(0x5555555555555555, 1); + RMS(0x3333333333333333, 2); + RMS(0x0F0F0F0F0F0F0F0F, 4); + RMS(0x00FF00FF00FF00FF, 8); + RMS(0x0000FFFF0000FFFF, 16); + return (x << 32) | (x >> 32); + +#undef RMS +} + +/* see bearssl_ghash.h */ +void +br_ghash_ctmul64(void *y, const void *h, const void *data, size_t len) +{ + const unsigned char *buf, *hb; + unsigned char *yb; + uint64_t y0, y1; + uint64_t h0, h1, h2, h0r, h1r, h2r; + + buf = data; + yb = y; + hb = h; + y1 = br_dec64be(yb); + y0 = br_dec64be(yb + 8); + h1 = br_dec64be(hb); + h0 = br_dec64be(hb + 8); + h0r = rev64(h0); + h1r = rev64(h1); + h2 = h0 ^ h1; + h2r = h0r ^ h1r; + while (len > 0) { + const unsigned char *src; + unsigned char tmp[16]; + uint64_t y0r, y1r, y2, y2r; + uint64_t z0, z1, z2, z0h, z1h, z2h; + uint64_t v0, v1, v2, v3; + + if (len >= 16) { + src = buf; + buf += 16; + len -= 16; + } else { + memcpy(tmp, buf, len); + memset(tmp + len, 0, (sizeof tmp) - len); + src = tmp; + len = 0; + } + y1 ^= br_dec64be(src); + y0 ^= br_dec64be(src + 8); + + y0r = rev64(y0); + y1r = rev64(y1); + y2 = y0 ^ y1; + y2r = y0r ^ y1r; + + z0 = bmul64(y0, h0); + z1 = bmul64(y1, h1); + z2 = bmul64(y2, h2); + z0h = bmul64(y0r, h0r); + z1h = bmul64(y1r, h1r); + z2h = bmul64(y2r, h2r); + z2 ^= z0 ^ z1; + z2h ^= z0h ^ z1h; + z0h = rev64(z0h) >> 1; + z1h = rev64(z1h) >> 1; + z2h = rev64(z2h) >> 1; + + v0 = z0; + v1 = z0h ^ z2; + v2 = z1 ^ z2h; + v3 = z1h; + + v3 = (v3 << 1) | (v2 >> 63); + v2 = (v2 << 1) | (v1 >> 63); + v1 = (v1 << 1) | (v0 >> 63); + v0 = (v0 << 1); + + v2 ^= v0 ^ (v0 >> 1) ^ (v0 >> 2) ^ (v0 >> 7); + v1 ^= (v0 << 63) ^ (v0 << 62) ^ (v0 << 57); + v3 ^= v1 ^ (v1 >> 1) ^ (v1 >> 2) ^ (v1 >> 7); + v2 ^= (v1 << 63) ^ (v1 << 62) ^ (v1 << 57); + + y0 = v2; + y1 = v3; + } + + br_enc64be(yb, y1); + br_enc64be(yb + 8, y0); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ghash_pclmul.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ghash_pclmul.c new file mode 100644 index 000000000..3accba311 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ghash_pclmul.c @@ -0,0 +1,394 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#define BR_ENABLE_INTRINSICS 1 +#include "inner.h" + +/* + * This is the GHASH implementation that leverages the pclmulqdq opcode + * (from the AES-NI instructions). + */ + +#if BR_AES_X86NI + +/* + * Test CPU support for PCLMULQDQ. + */ +static inline int +pclmul_supported(void) +{ + /* + * Bit mask for features in ECX: + * 1 PCLMULQDQ support + */ + return br_cpuid(0, 0, 0x00000002, 0); +} + +/* see bearssl_hash.h */ +br_ghash +br_ghash_pclmul_get(void) +{ + return pclmul_supported() ? &br_ghash_pclmul : 0; +} + +BR_TARGETS_X86_UP + +/* + * GHASH is defined over elements of GF(2^128) with "full little-endian" + * representation: leftmost byte is least significant, and, within each + * byte, leftmost _bit_ is least significant. The natural ordering in + * x86 is "mixed little-endian": bytes are ordered from least to most + * significant, but bits within a byte are in most-to-least significant + * order. Going to full little-endian representation would require + * reversing bits within each byte, which is doable but expensive. + * + * Instead, we go to full big-endian representation, by swapping bytes + * around, which is done with a single _mm_shuffle_epi8() opcode (it + * comes with SSSE3; all CPU that offer pclmulqdq also have SSSE3). We + * can use a full big-endian representation because in a carryless + * multiplication, we have a nice bit reversal property: + * + * rev_128(x) * rev_128(y) = rev_255(x * y) + * + * So by using full big-endian, we still get the right result, except + * that it is right-shifted by 1 bit. The left-shift is relatively + * inexpensive, and it can be mutualised. + * + * + * Since SSE2 opcodes do not have facilities for shitfting full 128-bit + * values with bit precision, we have to break down values into 64-bit + * chunks. We number chunks from 0 to 3 in left to right order. + */ + +/* + * Byte-swap a complete 128-bit value. This normally uses + * _mm_shuffle_epi8(), which gets translated to pshufb (an SSSE3 opcode). + * However, this crashes old Clang versions, so, for Clang before 3.8, + * we use an alternate (and less efficient) version. + */ +#if BR_CLANG && !BR_CLANG_3_8 +#define BYTESWAP_DECL +#define BYTESWAP_PREP (void)0 +#define BYTESWAP(x) do { \ + __m128i byteswap1, byteswap2; \ + byteswap1 = (x); \ + byteswap2 = _mm_srli_epi16(byteswap1, 8); \ + byteswap1 = _mm_slli_epi16(byteswap1, 8); \ + byteswap1 = _mm_or_si128(byteswap1, byteswap2); \ + byteswap1 = _mm_shufflelo_epi16(byteswap1, 0x1B); \ + byteswap1 = _mm_shufflehi_epi16(byteswap1, 0x1B); \ + (x) = _mm_shuffle_epi32(byteswap1, 0x4E); \ + } while (0) +#else +#define BYTESWAP_DECL __m128i byteswap_index; +#define BYTESWAP_PREP do { \ + byteswap_index = _mm_set_epi8( \ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15); \ + } while (0) +#define BYTESWAP(x) do { \ + (x) = _mm_shuffle_epi8((x), byteswap_index); \ + } while (0) +#endif + +/* + * Call pclmulqdq. Clang appears to have trouble with the intrinsic, so, + * for that compiler, we use inline assembly. Inline assembly is + * potentially a bit slower because the compiler does not understand + * what the opcode does, and thus cannot optimize instruction + * scheduling. + * + * We use a target of "sse2" only, so that Clang may still handle the + * '__m128i' type and allocate SSE2 registers. + */ +#if BR_CLANG +BR_TARGET("sse2") +static inline __m128i +pclmulqdq00(__m128i x, __m128i y) +{ + __asm__ ("pclmulqdq $0x00, %1, %0" : "+x" (x) : "x" (y)); + return x; +} +BR_TARGET("sse2") +static inline __m128i +pclmulqdq11(__m128i x, __m128i y) +{ + __asm__ ("pclmulqdq $0x11, %1, %0" : "+x" (x) : "x" (y)); + return x; +} +#else +#define pclmulqdq00(x, y) _mm_clmulepi64_si128(x, y, 0x00) +#define pclmulqdq11(x, y) _mm_clmulepi64_si128(x, y, 0x11) +#endif + +/* + * From a 128-bit value kw, compute kx as the XOR of the two 64-bit + * halves of kw (into the right half of kx; left half is unspecified). + */ +#define BK(kw, kx) do { \ + kx = _mm_xor_si128(kw, _mm_shuffle_epi32(kw, 0x0E)); \ + } while (0) + +/* + * Combine two 64-bit values (k0:k1) into a 128-bit (kw) value and + * the XOR of the two values (kx). + */ +#define PBK(k0, k1, kw, kx) do { \ + kw = _mm_unpacklo_epi64(k1, k0); \ + kx = _mm_xor_si128(k0, k1); \ + } while (0) + +/* + * Left-shift by 1 bit a 256-bit value (in four 64-bit words). + */ +#define SL_256(x0, x1, x2, x3) do { \ + x0 = _mm_or_si128( \ + _mm_slli_epi64(x0, 1), \ + _mm_srli_epi64(x1, 63)); \ + x1 = _mm_or_si128( \ + _mm_slli_epi64(x1, 1), \ + _mm_srli_epi64(x2, 63)); \ + x2 = _mm_or_si128( \ + _mm_slli_epi64(x2, 1), \ + _mm_srli_epi64(x3, 63)); \ + x3 = _mm_slli_epi64(x3, 1); \ + } while (0) + +/* + * Perform reduction in GF(2^128). The 256-bit value is in x0..x3; + * result is written in x0..x1. + */ +#define REDUCE_F128(x0, x1, x2, x3) do { \ + x1 = _mm_xor_si128( \ + x1, \ + _mm_xor_si128( \ + _mm_xor_si128( \ + x3, \ + _mm_srli_epi64(x3, 1)), \ + _mm_xor_si128( \ + _mm_srli_epi64(x3, 2), \ + _mm_srli_epi64(x3, 7)))); \ + x2 = _mm_xor_si128( \ + _mm_xor_si128( \ + x2, \ + _mm_slli_epi64(x3, 63)), \ + _mm_xor_si128( \ + _mm_slli_epi64(x3, 62), \ + _mm_slli_epi64(x3, 57))); \ + x0 = _mm_xor_si128( \ + x0, \ + _mm_xor_si128( \ + _mm_xor_si128( \ + x2, \ + _mm_srli_epi64(x2, 1)), \ + _mm_xor_si128( \ + _mm_srli_epi64(x2, 2), \ + _mm_srli_epi64(x2, 7)))); \ + x1 = _mm_xor_si128( \ + _mm_xor_si128( \ + x1, \ + _mm_slli_epi64(x2, 63)), \ + _mm_xor_si128( \ + _mm_slli_epi64(x2, 62), \ + _mm_slli_epi64(x2, 57))); \ + } while (0) + +/* + * Square value kw into (dw,dx). + */ +#define SQUARE_F128(kw, dw, dx) do { \ + __m128i z0, z1, z2, z3; \ + z1 = pclmulqdq11(kw, kw); \ + z3 = pclmulqdq00(kw, kw); \ + z0 = _mm_shuffle_epi32(z1, 0x0E); \ + z2 = _mm_shuffle_epi32(z3, 0x0E); \ + SL_256(z0, z1, z2, z3); \ + REDUCE_F128(z0, z1, z2, z3); \ + PBK(z0, z1, dw, dx); \ + } while (0) + +/* see bearssl_hash.h */ +BR_TARGET("ssse3,pclmul") +void +br_ghash_pclmul(void *y, const void *h, const void *data, size_t len) +{ + const unsigned char *buf1, *buf2; + unsigned char tmp[64]; + size_t num4, num1; + __m128i yw, h1w, h1x; + BYTESWAP_DECL + + /* + * We split data into two chunks. First chunk starts at buf1 + * and contains num4 blocks of 64-byte values. Second chunk + * starts at buf2 and contains num1 blocks of 16-byte values. + * We want the first chunk to be as large as possible. + */ + buf1 = data; + num4 = len >> 6; + len &= 63; + buf2 = buf1 + (num4 << 6); + num1 = (len + 15) >> 4; + if ((len & 15) != 0) { + memcpy(tmp, buf2, len); + memset(tmp + len, 0, (num1 << 4) - len); + buf2 = tmp; + } + + /* + * Preparatory step for endian conversions. + */ + BYTESWAP_PREP; + + /* + * Load y and h. + */ + yw = _mm_loadu_si128(y); + h1w = _mm_loadu_si128(h); + BYTESWAP(yw); + BYTESWAP(h1w); + BK(h1w, h1x); + + if (num4 > 0) { + __m128i h2w, h2x, h3w, h3x, h4w, h4x; + __m128i t0, t1, t2, t3; + + /* + * Compute h2 = h^2. + */ + SQUARE_F128(h1w, h2w, h2x); + + /* + * Compute h3 = h^3 = h*(h^2). + */ + t1 = pclmulqdq11(h1w, h2w); + t3 = pclmulqdq00(h1w, h2w); + t2 = _mm_xor_si128(pclmulqdq00(h1x, h2x), + _mm_xor_si128(t1, t3)); + t0 = _mm_shuffle_epi32(t1, 0x0E); + t1 = _mm_xor_si128(t1, _mm_shuffle_epi32(t2, 0x0E)); + t2 = _mm_xor_si128(t2, _mm_shuffle_epi32(t3, 0x0E)); + SL_256(t0, t1, t2, t3); + REDUCE_F128(t0, t1, t2, t3); + PBK(t0, t1, h3w, h3x); + + /* + * Compute h4 = h^4 = (h^2)^2. + */ + SQUARE_F128(h2w, h4w, h4x); + + while (num4 -- > 0) { + __m128i aw0, aw1, aw2, aw3; + __m128i ax0, ax1, ax2, ax3; + + aw0 = _mm_loadu_si128((void *)(buf1 + 0)); + aw1 = _mm_loadu_si128((void *)(buf1 + 16)); + aw2 = _mm_loadu_si128((void *)(buf1 + 32)); + aw3 = _mm_loadu_si128((void *)(buf1 + 48)); + BYTESWAP(aw0); + BYTESWAP(aw1); + BYTESWAP(aw2); + BYTESWAP(aw3); + buf1 += 64; + + aw0 = _mm_xor_si128(aw0, yw); + BK(aw1, ax1); + BK(aw2, ax2); + BK(aw3, ax3); + BK(aw0, ax0); + + t1 = _mm_xor_si128( + _mm_xor_si128( + pclmulqdq11(aw0, h4w), + pclmulqdq11(aw1, h3w)), + _mm_xor_si128( + pclmulqdq11(aw2, h2w), + pclmulqdq11(aw3, h1w))); + t3 = _mm_xor_si128( + _mm_xor_si128( + pclmulqdq00(aw0, h4w), + pclmulqdq00(aw1, h3w)), + _mm_xor_si128( + pclmulqdq00(aw2, h2w), + pclmulqdq00(aw3, h1w))); + t2 = _mm_xor_si128( + _mm_xor_si128( + pclmulqdq00(ax0, h4x), + pclmulqdq00(ax1, h3x)), + _mm_xor_si128( + pclmulqdq00(ax2, h2x), + pclmulqdq00(ax3, h1x))); + t2 = _mm_xor_si128(t2, _mm_xor_si128(t1, t3)); + t0 = _mm_shuffle_epi32(t1, 0x0E); + t1 = _mm_xor_si128(t1, _mm_shuffle_epi32(t2, 0x0E)); + t2 = _mm_xor_si128(t2, _mm_shuffle_epi32(t3, 0x0E)); + SL_256(t0, t1, t2, t3); + REDUCE_F128(t0, t1, t2, t3); + yw = _mm_unpacklo_epi64(t1, t0); + } + } + + while (num1 -- > 0) { + __m128i aw, ax; + __m128i t0, t1, t2, t3; + + aw = _mm_loadu_si128((void *)buf2); + BYTESWAP(aw); + buf2 += 16; + + aw = _mm_xor_si128(aw, yw); + BK(aw, ax); + + t1 = pclmulqdq11(aw, h1w); + t3 = pclmulqdq00(aw, h1w); + t2 = pclmulqdq00(ax, h1x); + t2 = _mm_xor_si128(t2, _mm_xor_si128(t1, t3)); + t0 = _mm_shuffle_epi32(t1, 0x0E); + t1 = _mm_xor_si128(t1, _mm_shuffle_epi32(t2, 0x0E)); + t2 = _mm_xor_si128(t2, _mm_shuffle_epi32(t3, 0x0E)); + SL_256(t0, t1, t2, t3); + REDUCE_F128(t0, t1, t2, t3); + yw = _mm_unpacklo_epi64(t1, t0); + } + + BYTESWAP(yw); + _mm_storeu_si128(y, yw); +} + +BR_TARGETS_X86_DOWN + +#else + +/* see bearssl_hash.h */ +br_ghash +br_ghash_pclmul_get(void) +{ + return 0; +} + +#endif + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ghash_pwr8.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ghash_pwr8.c new file mode 100644 index 000000000..181d3193c --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ghash_pwr8.c @@ -0,0 +1,416 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#define BR_POWER_ASM_MACROS 1 +#include "inner.h" + +/* + * This is the GHASH implementation that leverages the POWER8 opcodes. + */ + +#if BR_POWER8 + +/* + * Some symbolic names for registers. + * HB0 = 16 bytes of value 0 + * HB1 = 16 bytes of value 1 + * HB2 = 16 bytes of value 2 + * HB6 = 16 bytes of value 6 + * HB7 = 16 bytes of value 7 + * TT0, TT1 and TT2 are temporaries + * + * BSW holds the pattern for byteswapping 32-bit words; this is set only + * on little-endian systems. XBSW is the same register with the +32 offset + * for access with the VSX opcodes. + */ +#define HB0 0 +#define HB1 1 +#define HB2 2 +#define HB6 3 +#define HB7 4 +#define TT0 5 +#define TT1 6 +#define TT2 7 + +#define BSW 8 +#define XBSW 40 + +/* + * Macro to initialise the constants. + */ +#define INIT \ + vxor(HB0, HB0, HB0) \ + vspltisb(HB1, 1) \ + vspltisb(HB2, 2) \ + vspltisb(HB6, 6) \ + vspltisb(HB7, 7) \ + INIT_BSW + +/* + * Fix endianness of a value after reading it or before writing it, if + * necessary. + */ +#if BR_POWER8_LE +#define INIT_BSW lxvw4x(XBSW, 0, %[idx2be]) +#define FIX_ENDIAN(xx) vperm(xx, xx, xx, BSW) +#else +#define INIT_BSW +#define FIX_ENDIAN(xx) +#endif + +/* + * Left-shift x0:x1 by one bit to the left. This is a corrective action + * needed because GHASH is defined in full little-endian specification, + * while the opcodes use full big-endian convention, so the 255-bit product + * ends up one bit to the right. + */ +#define SL_256(x0, x1) \ + vsldoi(TT0, HB0, x1, 1) \ + vsl(x0, x0, HB1) \ + vsr(TT0, TT0, HB7) \ + vsl(x1, x1, HB1) \ + vxor(x0, x0, TT0) + +/* + * Reduce x0:x1 in GF(2^128), result in xd (register xd may be the same as + * x0 or x1, or a different register). x0 and x1 are modified. + */ +#define REDUCE_F128(xd, x0, x1) \ + vxor(x0, x0, x1) \ + vsr(TT0, x1, HB1) \ + vsr(TT1, x1, HB2) \ + vsr(TT2, x1, HB7) \ + vxor(x0, x0, TT0) \ + vxor(TT1, TT1, TT2) \ + vxor(x0, x0, TT1) \ + vsldoi(x1, x1, HB0, 15) \ + vsl(TT1, x1, HB6) \ + vsl(TT2, x1, HB1) \ + vxor(x1, TT1, TT2) \ + vsr(TT0, x1, HB1) \ + vsr(TT1, x1, HB2) \ + vsr(TT2, x1, HB7) \ + vxor(x0, x0, x1) \ + vxor(x0, x0, TT0) \ + vxor(TT1, TT1, TT2) \ + vxor(xd, x0, TT1) + +/* see bearssl_hash.h */ +void +br_ghash_pwr8(void *y, const void *h, const void *data, size_t len) +{ + const unsigned char *buf1, *buf2; + size_t num4, num1; + unsigned char tmp[64]; + long cc0, cc1, cc2, cc3; + +#if BR_POWER8_LE + static const uint32_t idx2be[] = { + 0x03020100, 0x07060504, 0x0B0A0908, 0x0F0E0D0C + }; +#endif + + buf1 = data; + + /* + * Assembly code requires data into two chunks; first chunk + * must contain a number of blocks which is a multiple of 4. + * Since the processing for the first chunk is faster, we want + * to make it as big as possible. + * + * For the remainder, there are two possibilities: + * -- if the remainder size is a multiple of 16, then use it + * in place; + * -- otherwise, copy it to the tmp[] array and pad it with + * zeros. + */ + num4 = len >> 6; + buf2 = buf1 + (num4 << 6); + len &= 63; + num1 = (len + 15) >> 4; + if ((len & 15) != 0) { + memcpy(tmp, buf2, len); + memset(tmp + len, 0, (num1 << 4) - len); + buf2 = tmp; + } + + cc0 = 0; + cc1 = 16; + cc2 = 32; + cc3 = 48; + asm volatile ( + INIT + + /* + * Load current h (denoted hereafter h1) in v9. + */ + lxvw4x(41, 0, %[h]) + FIX_ENDIAN(9) + + /* + * Load current y into v28. + */ + lxvw4x(60, 0, %[y]) + FIX_ENDIAN(28) + + /* + * Split h1 into three registers: + * v17 = h1_1:h1_0 + * v18 = 0:h1_0 + * v19 = h1_1:0 + */ + xxpermdi(49, 41, 41, 2) + vsldoi(18, HB0, 9, 8) + vsldoi(19, 9, HB0, 8) + + /* + * If num4 is 0, skip directly to the second chunk. + */ + cmpldi(%[num4], 0) + beq(chunk1) + + /* + * Compute h2 = h*h in v10. + */ + vpmsumd(10, 18, 18) + vpmsumd(11, 19, 19) + SL_256(10, 11) + REDUCE_F128(10, 10, 11) + + /* + * Compute h3 = h*h*h in v11. + * We first split h2 into: + * v10 = h2_0:h2_1 + * v11 = 0:h2_0 + * v12 = h2_1:0 + * Then we do the product with h1, and reduce into v11. + */ + vsldoi(11, HB0, 10, 8) + vsldoi(12, 10, HB0, 8) + vpmsumd(13, 10, 17) + vpmsumd(11, 11, 18) + vpmsumd(12, 12, 19) + vsldoi(14, HB0, 13, 8) + vsldoi(15, 13, HB0, 8) + vxor(11, 11, 14) + vxor(12, 12, 15) + SL_256(11, 12) + REDUCE_F128(11, 11, 12) + + /* + * Compute h4 = h*h*h*h in v12. This is done by squaring h2. + */ + vsldoi(12, HB0, 10, 8) + vsldoi(13, 10, HB0, 8) + vpmsumd(12, 12, 12) + vpmsumd(13, 13, 13) + SL_256(12, 13) + REDUCE_F128(12, 12, 13) + + /* + * Repack h1, h2, h3 and h4: + * v13 = h4_0:h3_0 + * v14 = h4_1:h3_1 + * v15 = h2_0:h1_0 + * v16 = h2_1:h1_1 + */ + xxpermdi(45, 44, 43, 0) + xxpermdi(46, 44, 43, 3) + xxpermdi(47, 42, 41, 0) + xxpermdi(48, 42, 41, 3) + + /* + * Loop for each group of four blocks. + */ + mtctr(%[num4]) + label(loop4) + /* + * Read the four next blocks. + * v20 = y + a0 = b0 + * v21 = a1 = b1 + * v22 = a2 = b2 + * v23 = a3 = b3 + */ + lxvw4x(52, %[cc0], %[buf1]) + lxvw4x(53, %[cc1], %[buf1]) + lxvw4x(54, %[cc2], %[buf1]) + lxvw4x(55, %[cc3], %[buf1]) + FIX_ENDIAN(20) + FIX_ENDIAN(21) + FIX_ENDIAN(22) + FIX_ENDIAN(23) + addi(%[buf1], %[buf1], 64) + vxor(20, 20, 28) + + /* + * Repack the blocks into v9, v10, v11 and v12. + * v9 = b0_0:b1_0 + * v10 = b0_1:b1_1 + * v11 = b2_0:b3_0 + * v12 = b2_1:b3_1 + */ + xxpermdi(41, 52, 53, 0) + xxpermdi(42, 52, 53, 3) + xxpermdi(43, 54, 55, 0) + xxpermdi(44, 54, 55, 3) + + /* + * Compute the products. + * v20 = b0_0*h4_0 + b1_0*h3_0 + * v21 = b0_1*h4_0 + b1_1*h3_0 + * v22 = b0_0*h4_1 + b1_0*h3_1 + * v23 = b0_1*h4_1 + b1_1*h3_1 + * v24 = b2_0*h2_0 + b3_0*h1_0 + * v25 = b2_1*h2_0 + b3_1*h1_0 + * v26 = b2_0*h2_1 + b3_0*h1_1 + * v27 = b2_1*h2_1 + b3_1*h1_1 + */ + vpmsumd(20, 13, 9) + vpmsumd(21, 13, 10) + vpmsumd(22, 14, 9) + vpmsumd(23, 14, 10) + vpmsumd(24, 15, 11) + vpmsumd(25, 15, 12) + vpmsumd(26, 16, 11) + vpmsumd(27, 16, 12) + + /* + * Sum products into a single 256-bit result in v11:v12. + */ + vxor(11, 20, 24) + vxor(12, 23, 27) + vxor( 9, 21, 22) + vxor(10, 25, 26) + vxor(20, 9, 10) + vsldoi( 9, HB0, 20, 8) + vsldoi(10, 20, HB0, 8) + vxor(11, 11, 9) + vxor(12, 12, 10) + + /* + * Fix and reduce in GF(2^128); this is the new y (in v28). + */ + SL_256(11, 12) + REDUCE_F128(28, 11, 12) + + /* + * Loop for next group of four blocks. + */ + bdnz(loop4) + + /* + * Process second chunk, one block at a time. + */ + label(chunk1) + cmpldi(%[num1], 0) + beq(done) + + mtctr(%[num1]) + label(loop1) + /* + * Load next data block and XOR it into y. + */ + lxvw4x(41, 0, %[buf2]) +#if BR_POWER8_LE + FIX_ENDIAN(9) +#endif + addi(%[buf2], %[buf2], 16) + vxor(9, 28, 9) + + /* + * Split y into doublewords: + * v9 = y_0:y_1 + * v10 = 0:y_0 + * v11 = y_1:0 + */ + vsldoi(10, HB0, 9, 8) + vsldoi(11, 9, HB0, 8) + + /* + * Compute products with h: + * v12 = y_0 * h_0 + * v13 = y_1 * h_1 + * v14 = y_1 * h_0 + y_0 * h_1 + */ + vpmsumd(14, 9, 17) + vpmsumd(12, 10, 18) + vpmsumd(13, 11, 19) + + /* + * Propagate v14 into v12:v13 to finalise product. + */ + vsldoi(10, HB0, 14, 8) + vsldoi(11, 14, HB0, 8) + vxor(12, 12, 10) + vxor(13, 13, 11) + + /* + * Fix result and reduce into v28 (next value for y). + */ + SL_256(12, 13) + REDUCE_F128(28, 12, 13) + bdnz(loop1) + + label(done) + /* + * Write back the new y. + */ + FIX_ENDIAN(28) + stxvw4x(60, 0, %[y]) + +: [buf1] "+b" (buf1), [buf2] "+b" (buf2) +: [y] "b" (y), [h] "b" (h), [num4] "b" (num4), [num1] "b" (num1), + [cc0] "b" (cc0), [cc1] "b" (cc1), [cc2] "b" (cc2), [cc3] "b" (cc3) +#if BR_POWER8_LE + , [idx2be] "b" (idx2be) +#endif +: "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", + "v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17", "v18", "v19", + "v20", "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", + "ctr", "memory" + ); +} + +/* see bearssl_hash.h */ +br_ghash +br_ghash_pwr8_get(void) +{ + return &br_ghash_pwr8; +} + +#else + +/* see bearssl_hash.h */ +br_ghash +br_ghash_pwr8_get(void) +{ + return 0; +} + +#endif + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/hkdf.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/hkdf.c new file mode 100644 index 000000000..7db9b3780 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/hkdf.c @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +const unsigned char br_hkdf_no_salt = 0; + +/* see bearssl_kdf.h */ +void +br_hkdf_init(br_hkdf_context *hc, const br_hash_class *digest_vtable, + const void *salt, size_t salt_len) +{ + br_hmac_key_context kc; + unsigned char tmp[64]; + + if (salt == BR_HKDF_NO_SALT) { + salt = tmp; + salt_len = br_digest_size(digest_vtable); + memset(tmp, 0, salt_len); + } + br_hmac_key_init(&kc, digest_vtable, salt, salt_len); + br_hmac_init(&hc->u.hmac_ctx, &kc, 0); + hc->dig_len = br_hmac_size(&hc->u.hmac_ctx); +} + +/* see bearssl_kdf.h */ +void +br_hkdf_inject(br_hkdf_context *hc, const void *ikm, size_t ikm_len) +{ + br_hmac_update(&hc->u.hmac_ctx, ikm, ikm_len); +} + +/* see bearssl_kdf.h */ +void +br_hkdf_flip(br_hkdf_context *hc) +{ + unsigned char tmp[64]; + + br_hmac_out(&hc->u.hmac_ctx, tmp); + br_hmac_key_init(&hc->u.prk_ctx, + br_hmac_get_digest(&hc->u.hmac_ctx), tmp, hc->dig_len); + hc->ptr = hc->dig_len; + hc->chunk_num = 0; +} + +/* see bearssl_kdf.h */ +size_t +br_hkdf_produce(br_hkdf_context *hc, + const void *info, size_t info_len, void *out, size_t out_len) +{ + size_t tlen; + + tlen = 0; + while (out_len > 0) { + size_t clen; + + if (hc->ptr == hc->dig_len) { + br_hmac_context hmac_ctx; + unsigned char x; + + hc->chunk_num ++; + if (hc->chunk_num == 256) { + return tlen; + } + x = hc->chunk_num; + br_hmac_init(&hmac_ctx, &hc->u.prk_ctx, 0); + if (x != 1) { + br_hmac_update(&hmac_ctx, hc->buf, hc->dig_len); + } + br_hmac_update(&hmac_ctx, info, info_len); + br_hmac_update(&hmac_ctx, &x, 1); + br_hmac_out(&hmac_ctx, hc->buf); + hc->ptr = 0; + } + clen = hc->dig_len - hc->ptr; + if (clen > out_len) { + clen = out_len; + } + memcpy(out, hc->buf + hc->ptr, clen); + out = (unsigned char *)out + clen; + out_len -= clen; + hc->ptr += clen; + tlen += clen; + } + return tlen; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/hmac.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/hmac.c new file mode 100644 index 000000000..7b0b9941d --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/hmac.c @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +static inline size_t +block_size(const br_hash_class *dig) +{ + unsigned ls; + + ls = (unsigned)(dig->desc >> BR_HASHDESC_LBLEN_OFF) + & BR_HASHDESC_LBLEN_MASK; + return (size_t)1 << ls; +} + +static void +process_key(const br_hash_class **hc, void *ks, + const void *key, size_t key_len, unsigned bb) +{ + unsigned char tmp[256]; + size_t blen, u; + + blen = block_size(*hc); + memcpy(tmp, key, key_len); + for (u = 0; u < key_len; u ++) { + tmp[u] ^= (unsigned char)bb; + } + memset(tmp + key_len, bb, blen - key_len); + (*hc)->init(hc); + (*hc)->update(hc, tmp, blen); + (*hc)->state(hc, ks); +} + +/* see bearssl.h */ +void +br_hmac_key_init(br_hmac_key_context *kc, + const br_hash_class *dig, const void *key, size_t key_len) +{ + br_hash_compat_context hc; + unsigned char kbuf[64]; + + kc->dig_vtable = dig; + hc.vtable = dig; + if (key_len > block_size(dig)) { + dig->init(&hc.vtable); + dig->update(&hc.vtable, key, key_len); + dig->out(&hc.vtable, kbuf); + key = kbuf; + key_len = br_digest_size(dig); + } + process_key(&hc.vtable, kc->ksi, key, key_len, 0x36); + process_key(&hc.vtable, kc->kso, key, key_len, 0x5C); +} + +/* see bearssl.h */ +void +br_hmac_init(br_hmac_context *ctx, + const br_hmac_key_context *kc, size_t out_len) +{ + const br_hash_class *dig; + size_t blen, hlen; + + dig = kc->dig_vtable; + blen = block_size(dig); + dig->init(&ctx->dig.vtable); + dig->set_state(&ctx->dig.vtable, kc->ksi, (uint64_t)blen); + memcpy(ctx->kso, kc->kso, sizeof kc->kso); + hlen = br_digest_size(dig); + if (out_len > 0 && out_len < hlen) { + hlen = out_len; + } + ctx->out_len = hlen; +} + +/* see bearssl.h */ +void +br_hmac_update(br_hmac_context *ctx, const void *data, size_t len) +{ + ctx->dig.vtable->update(&ctx->dig.vtable, data, len); +} + +/* see bearssl.h */ +size_t +br_hmac_out(const br_hmac_context *ctx, void *out) +{ + const br_hash_class *dig; + br_hash_compat_context hc; + unsigned char tmp[64]; + size_t blen, hlen; + + dig = ctx->dig.vtable; + dig->out(&ctx->dig.vtable, tmp); + blen = block_size(dig); + dig->init(&hc.vtable); + dig->set_state(&hc.vtable, ctx->kso, (uint64_t)blen); + hlen = br_digest_size(dig); + dig->update(&hc.vtable, tmp, hlen); + dig->out(&hc.vtable, tmp); + memcpy(out, tmp, ctx->out_len); + return ctx->out_len; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/hmac_ct.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/hmac_ct.c new file mode 100644 index 000000000..65e4cd9ca --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/hmac_ct.c @@ -0,0 +1,198 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +static inline size_t +hash_size(const br_hash_class *dig) +{ + return (unsigned)(dig->desc >> BR_HASHDESC_OUT_OFF) + & BR_HASHDESC_OUT_MASK; +} + +static inline size_t +block_size(const br_hash_class *dig) +{ + unsigned ls; + + ls = (unsigned)(dig->desc >> BR_HASHDESC_LBLEN_OFF) + & BR_HASHDESC_LBLEN_MASK; + return (size_t)1 << ls; +} + +/* see bearssl.h */ +size_t +br_hmac_outCT(const br_hmac_context *ctx, + const void *data, size_t len, size_t min_len, size_t max_len, + void *out) +{ + /* + * Method implemented here is inspired from the descriptions on: + * https://www.imperialviolet.org/2013/02/04/luckythirteen.html + * + * Principle: we input bytes one by one. We use a MUX to push + * padding bytes instead of data bytes when appropriate. At each + * block limit, we get the current hash function state: this is + * a potential output, since we handle MD padding ourselves. + * + * be 1 for big-endian, 0 for little-endian + * po minimal MD padding length + * bs block size (always a power of 2) + * hlen hash output size + */ + + const br_hash_class *dig; + br_hash_compat_context hc; + int be; + uint32_t po, bs; + uint32_t kr, km, kl, kz, u; + uint64_t count, ncount, bit_len; + unsigned char tmp1[64], tmp2[64]; + size_t hlen; + + /* + * Copy the current hash context. + */ + hc = ctx->dig; + + /* + * Get function-specific information. + */ + dig = hc.vtable; + be = (dig->desc & BR_HASHDESC_MD_PADDING_BE) != 0; + po = 9; + if (dig->desc & BR_HASHDESC_MD_PADDING_128) { + po += 8; + } + bs = block_size(dig); + hlen = hash_size(dig); + + /* + * Get current input length and compute total bit length. + */ + count = dig->state(&hc.vtable, tmp1); + bit_len = (count + (uint64_t)len) << 3; + + /* + * We can input the blocks that we are sure we will use. + * This offers better performance (no MUX for these blocks) + * and also ensures that the remaining lengths fit on 32 bits. + */ + ncount = (count + (uint64_t)min_len) & ~(uint64_t)(bs - 1); + if (ncount > count) { + size_t zlen; + + zlen = (size_t)(ncount - count); + dig->update(&hc.vtable, data, zlen); + data = (const unsigned char *)data + zlen; + len -= zlen; + max_len -= zlen; + count = ncount; + } + + /* + * At that point: + * -- 'count' contains the number of bytes already processed + * (in total). + * -- We must input 'len' bytes. 'min_len' is unimportant: we + * used it to know how many full blocks we could process + * directly. Now only len and max_len matter. + * + * We compute kr, kl, kz and km. + * kr number of input bytes already in the current block + * km index of the first byte after the end of the last padding + * block, if length is max_len + * kz index of the last byte of the actual last padding block + * kl index of the start of the encoded length + * + * km, kz and kl are counted from the current offset in the + * input data. + */ + kr = (uint32_t)count & (bs - 1); + kz = ((kr + (uint32_t)len + po + bs - 1) & ~(bs - 1)) - 1 - kr; + kl = kz - 7; + km = ((kr + (uint32_t)max_len + po + bs - 1) & ~(bs - 1)) - kr; + + /* + * We must now process km bytes. For index u from 0 to km-1: + * d is from data[] if u < max_len, 0x00 otherwise + * e is an encoded length byte or 0x00, depending on u + * The tests for d and e need not be constant-time, since + * they relate only to u and max_len, not to the actual length. + * + * Actual input length is then: + * d if u < len + * 0x80 if u == len + * 0x00 if u > len and u < kl + * e if u >= kl + * + * Hash state is obtained whenever we reach a full block. This + * is the result we want if and only if u == kz. + */ + memset(tmp2, 0, sizeof tmp2); + for (u = 0; u < km; u ++) { + uint32_t v; + uint32_t d, e, x0, x1; + unsigned char x[1]; + + d = (u < max_len) ? ((const unsigned char *)data)[u] : 0x00; + v = (kr + u) & (bs - 1); + if (v >= (bs - 8)) { + unsigned j; + + j = (v - (bs - 8)) << 3; + if (be) { + e = (uint32_t)(bit_len >> (56 - j)); + } else { + e = (uint32_t)(bit_len >> j); + } + e &= 0xFF; + } else { + e = 0x00; + } + x0 = MUX(EQ(u, (uint32_t)len), 0x80, d); + x1 = MUX(LT(u, kl), 0x00, e); + x[0] = MUX(LE(u, (uint32_t)len), x0, x1); + dig->update(&hc.vtable, x, 1); + if (v == (bs - 1)) { + dig->state(&hc.vtable, tmp1); + CCOPY(EQ(u, kz), tmp2, tmp1, hlen); + } + } + + /* + * Inner hash output is in tmp2[]; we finish processing. + */ + dig->init(&hc.vtable); + dig->set_state(&hc.vtable, ctx->kso, (uint64_t)bs); + dig->update(&hc.vtable, tmp2, hlen); + dig->out(&hc.vtable, tmp2); + memcpy(out, tmp2, ctx->out_len); + return ctx->out_len; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/hmac_drbg.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/hmac_drbg.c new file mode 100644 index 000000000..21f25c5b5 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/hmac_drbg.c @@ -0,0 +1,162 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl.h */ +void +br_hmac_drbg_init(br_hmac_drbg_context *ctx, + const br_hash_class *digest_class, const void *seed, size_t len) +{ + size_t hlen; + + ctx->vtable = &br_hmac_drbg_vtable; + hlen = br_digest_size(digest_class); + memset(ctx->K, 0x00, hlen); + memset(ctx->V, 0x01, hlen); + ctx->digest_class = digest_class; + br_hmac_drbg_update(ctx, seed, len); +} + +/* see bearssl.h */ +void +br_hmac_drbg_generate(br_hmac_drbg_context *ctx, void *out, size_t len) +{ + const br_hash_class *dig; + br_hmac_key_context kc; + br_hmac_context hc; + size_t hlen; + unsigned char *buf; + unsigned char x; + + dig = ctx->digest_class; + hlen = br_digest_size(dig); + br_hmac_key_init(&kc, dig, ctx->K, hlen); + buf = out; + while (len > 0) { + size_t clen; + + br_hmac_init(&hc, &kc, 0); + br_hmac_update(&hc, ctx->V, hlen); + br_hmac_out(&hc, ctx->V); + clen = hlen; + if (clen > len) { + clen = len; + } + memcpy(buf, ctx->V, clen); + buf += clen; + len -= clen; + } + + /* + * To prepare the state for the next request, we should call + * br_hmac_drbg_update() with an empty additional seed. However, + * we already have an initialized HMAC context with the right + * initial key, and we don't want to push another one on the + * stack, so we inline that update() call here. + */ + br_hmac_init(&hc, &kc, 0); + br_hmac_update(&hc, ctx->V, hlen); + x = 0x00; + br_hmac_update(&hc, &x, 1); + br_hmac_out(&hc, ctx->K); + br_hmac_key_init(&kc, dig, ctx->K, hlen); + br_hmac_init(&hc, &kc, 0); + br_hmac_update(&hc, ctx->V, hlen); + br_hmac_out(&hc, ctx->V); +} + +/* see bearssl.h */ +void +br_hmac_drbg_update(br_hmac_drbg_context *ctx, const void *seed, size_t len) +{ + const br_hash_class *dig; + br_hmac_key_context kc; + br_hmac_context hc; + size_t hlen; + unsigned char x; + + dig = ctx->digest_class; + hlen = br_digest_size(dig); + + /* + * 1. K = HMAC(K, V || 0x00 || seed) + */ + br_hmac_key_init(&kc, dig, ctx->K, hlen); + br_hmac_init(&hc, &kc, 0); + br_hmac_update(&hc, ctx->V, hlen); + x = 0x00; + br_hmac_update(&hc, &x, 1); + br_hmac_update(&hc, seed, len); + br_hmac_out(&hc, ctx->K); + br_hmac_key_init(&kc, dig, ctx->K, hlen); + + /* + * 2. V = HMAC(K, V) + */ + br_hmac_init(&hc, &kc, 0); + br_hmac_update(&hc, ctx->V, hlen); + br_hmac_out(&hc, ctx->V); + + /* + * 3. If the additional seed is empty, then stop here. + */ + if (len == 0) { + return; + } + + /* + * 4. K = HMAC(K, V || 0x01 || seed) + */ + br_hmac_init(&hc, &kc, 0); + br_hmac_update(&hc, ctx->V, hlen); + x = 0x01; + br_hmac_update(&hc, &x, 1); + br_hmac_update(&hc, seed, len); + br_hmac_out(&hc, ctx->K); + br_hmac_key_init(&kc, dig, ctx->K, hlen); + + /* + * 5. V = HMAC(K, V) + */ + br_hmac_init(&hc, &kc, 0); + br_hmac_update(&hc, ctx->V, hlen); + br_hmac_out(&hc, ctx->V); +} + +/* see bearssl.h */ +const br_prng_class br_hmac_drbg_vtable = { + sizeof(br_hmac_drbg_context), + (void (*)(const br_prng_class **, const void *, const void *, size_t)) + &br_hmac_drbg_init, + (void (*)(const br_prng_class **, void *, size_t)) + &br_hmac_drbg_generate, + (void (*)(const br_prng_class **, const void *, size_t)) + &br_hmac_drbg_update +}; + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_add.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_add.c new file mode 100644 index 000000000..88f2923b4 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_add.c @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +uint32_t +br_i15_add(uint16_t *a, const uint16_t *b, uint32_t ctl) +{ + uint32_t cc; + size_t u, m; + + cc = 0; + m = (a[0] + 31) >> 4; + for (u = 1; u < m; u ++) { + uint32_t aw, bw, naw; + + aw = a[u]; + bw = b[u]; + naw = aw + bw + cc; + cc = naw >> 15; + a[u] = MUX(ctl, naw & 0x7FFF, aw); + } + return cc; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_bitlen.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_bitlen.c new file mode 100644 index 000000000..da50a3d63 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_bitlen.c @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +uint32_t +br_i15_bit_length(uint16_t *x, size_t xlen) +{ + uint32_t tw, twk; + + tw = 0; + twk = 0; + while (xlen -- > 0) { + uint32_t w, c; + + c = EQ(tw, 0); + w = x[xlen]; + tw = MUX(c, w, tw); + twk = MUX(c, (uint32_t)xlen, twk); + } + return (twk << 4) + BIT_LENGTH(tw); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_decmod.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_decmod.c new file mode 100644 index 000000000..e2a53e252 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_decmod.c @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +uint32_t +br_i15_decode_mod(uint16_t *x, const void *src, size_t len, const uint16_t *m) +{ + /* + * Two-pass algorithm: in the first pass, we determine whether the + * value fits; in the second pass, we do the actual write. + * + * During the first pass, 'r' contains the comparison result so + * far: + * 0x00000000 value is equal to the modulus + * 0x00000001 value is greater than the modulus + * 0xFFFFFFFF value is lower than the modulus + * + * Since we iterate starting with the least significant bytes (at + * the end of src[]), each new comparison overrides the previous + * except when the comparison yields 0 (equal). + * + * During the second pass, 'r' is either 0xFFFFFFFF (value fits) + * or 0x00000000 (value does not fit). + * + * We must iterate over all bytes of the source, _and_ possibly + * some extra virtual bytes (with value 0) so as to cover the + * complete modulus as well. We also add 4 such extra bytes beyond + * the modulus length because it then guarantees that no accumulated + * partial word remains to be processed. + */ + const unsigned char *buf; + size_t mlen, tlen; + int pass; + uint32_t r; + + buf = src; + mlen = (m[0] + 15) >> 4; + tlen = (mlen << 1); + if (tlen < len) { + tlen = len; + } + tlen += 4; + r = 0; + for (pass = 0; pass < 2; pass ++) { + size_t u, v; + uint32_t acc; + int acc_len; + + v = 1; + acc = 0; + acc_len = 0; + for (u = 0; u < tlen; u ++) { + uint32_t b; + + if (u < len) { + b = buf[len - 1 - u]; + } else { + b = 0; + } + acc |= (b << acc_len); + acc_len += 8; + if (acc_len >= 15) { + uint32_t xw; + + xw = acc & (uint32_t)0x7FFF; + acc_len -= 15; + acc = b >> (8 - acc_len); + if (v <= mlen) { + if (pass) { + x[v] = r & xw; + } else { + uint32_t cc; + + cc = (uint32_t)CMP(xw, m[v]); + r = MUX(EQ(cc, 0), r, cc); + } + } else { + if (!pass) { + r = MUX(EQ(xw, 0), r, 1); + } + } + v ++; + } + } + + /* + * When we reach this point at the end of the first pass: + * r is either 0, 1 or -1; we want to set r to 0 if it + * is equal to 0 or 1, and leave it to -1 otherwise. + * + * When we reach this point at the end of the second pass: + * r is either 0 or -1; we want to leave that value + * untouched. This is a subcase of the previous. + */ + r >>= 1; + r |= (r << 1); + } + + x[0] = m[0]; + return r & (uint32_t)1; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_decode.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_decode.c new file mode 100644 index 000000000..830b15a37 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_decode.c @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +void +br_i15_decode(uint16_t *x, const void *src, size_t len) +{ + const unsigned char *buf; + size_t v; + uint32_t acc; + int acc_len; + + buf = src; + v = 1; + acc = 0; + acc_len = 0; + while (len -- > 0) { + uint32_t b; + + b = buf[len]; + acc |= (b << acc_len); + acc_len += 8; + if (acc_len >= 15) { + x[v ++] = acc & 0x7FFF; + acc_len -= 15; + acc >>= 15; + } + } + if (acc_len != 0) { + x[v ++] = acc; + } + x[0] = br_i15_bit_length(x + 1, v - 1); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_decred.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_decred.c new file mode 100644 index 000000000..abb7f5d6c --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_decred.c @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +void +br_i15_decode_reduce(uint16_t *x, + const void *src, size_t len, const uint16_t *m) +{ + uint32_t m_ebitlen, m_rbitlen; + size_t mblen, k; + const unsigned char *buf; + uint32_t acc; + int acc_len; + + /* + * Get the encoded bit length. + */ + m_ebitlen = m[0]; + + /* + * Special case for an invalid (null) modulus. + */ + if (m_ebitlen == 0) { + x[0] = 0; + return; + } + + /* + * Clear the destination. + */ + br_i15_zero(x, m_ebitlen); + + /* + * First decode directly as many bytes as possible. This requires + * computing the actual bit length. + */ + m_rbitlen = m_ebitlen >> 4; + m_rbitlen = (m_ebitlen & 15) + (m_rbitlen << 4) - m_rbitlen; + mblen = (m_rbitlen + 7) >> 3; + k = mblen - 1; + if (k >= len) { + br_i15_decode(x, src, len); + x[0] = m_ebitlen; + return; + } + buf = src; + br_i15_decode(x, buf, k); + x[0] = m_ebitlen; + + /* + * Input remaining bytes, using 15-bit words. + */ + acc = 0; + acc_len = 0; + while (k < len) { + uint32_t v; + + v = buf[k ++]; + acc = (acc << 8) | v; + acc_len += 8; + if (acc_len >= 15) { + br_i15_muladd_small(x, acc >> (acc_len - 15), m); + acc_len -= 15; + acc &= ~((uint32_t)-1 << acc_len); + } + } + + /* + * We may have some bits accumulated. We then perform a shift to + * be able to inject these bits as a full 15-bit word. + */ + if (acc_len != 0) { + acc = (acc | (x[1] << acc_len)) & 0x7FFF; + br_i15_rshift(x, 15 - acc_len); + br_i15_muladd_small(x, acc, m); + } +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_encode.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_encode.c new file mode 100644 index 000000000..45063cb9f --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_encode.c @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +void +br_i15_encode(void *dst, size_t len, const uint16_t *x) +{ + unsigned char *buf; + size_t u, xlen; + uint32_t acc; + int acc_len; + + xlen = (x[0] + 15) >> 4; + if (xlen == 0) { + memset(dst, 0, len); + return; + } + u = 1; + acc = 0; + acc_len = 0; + buf = dst; + while (len -- > 0) { + if (acc_len < 8) { + if (u <= xlen) { + acc += (uint32_t)x[u ++] << acc_len; + } + acc_len += 15; + } + buf[len] = (unsigned char)acc; + acc >>= 8; + acc_len -= 8; + } +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_fmont.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_fmont.c new file mode 100644 index 000000000..c75f7b884 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_fmont.c @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +void +br_i15_from_monty(uint16_t *x, const uint16_t *m, uint16_t m0i) +{ + size_t len, u, v; + + len = (m[0] + 15) >> 4; + for (u = 0; u < len; u ++) { + uint32_t f, cc; + + f = MUL15(x[1], m0i) & 0x7FFF; + cc = 0; + for (v = 0; v < len; v ++) { + uint32_t z; + + z = (uint32_t)x[v + 1] + MUL15(f, m[v + 1]) + cc; + cc = z >> 15; + if (v != 0) { + x[v] = z & 0x7FFF; + } + } + x[len] = cc; + } + + /* + * We may have to do an extra subtraction, but only if the + * value in x[] is indeed greater than or equal to that of m[], + * which is why we must do two calls (first call computes the + * carry, second call performs the subtraction only if the carry + * is 0). + */ + br_i15_sub(x, m, NOT(br_i15_sub(x, m, 0))); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_iszero.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_iszero.c new file mode 100644 index 000000000..495e16fe8 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_iszero.c @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +uint32_t +br_i15_iszero(const uint16_t *x) +{ + uint32_t z; + size_t u; + + z = 0; + for (u = (x[0] + 15) >> 4; u > 0; u --) { + z |= x[u]; + } + return ~(z | -z) >> 31; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_moddiv.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_moddiv.c new file mode 100644 index 000000000..b4c93f37d --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_moddiv.c @@ -0,0 +1,470 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* + * In this file, we handle big integers with a custom format, i.e. + * without the usual one-word header. Value is split into 15-bit words, + * each stored in a 16-bit slot (top bit is zero) in little-endian + * order. The length (in words) is provided explicitly. In some cases, + * the value can be negative (using two's complement representation). In + * some cases, the top word is allowed to have a 16th bit. + */ + +/* + * Negate big integer conditionally. The value consists of 'len' words, + * with 15 bits in each word (the top bit of each word should be 0, + * except possibly for the last word). If 'ctl' is 1, the negation is + * computed; otherwise, if 'ctl' is 0, then the value is unchanged. + */ +static void +cond_negate(uint16_t *a, size_t len, uint32_t ctl) +{ + size_t k; + uint32_t cc, xm; + + cc = ctl; + xm = 0x7FFF & -ctl; + for (k = 0; k < len; k ++) { + uint32_t aw; + + aw = a[k]; + aw = (aw ^ xm) + cc; + a[k] = aw & 0x7FFF; + cc = (aw >> 15) & 1; + } +} + +/* + * Finish modular reduction. Rules on input parameters: + * + * if neg = 1, then -m <= a < 0 + * if neg = 0, then 0 <= a < 2*m + * + * If neg = 0, then the top word of a[] may use 16 bits. + * + * Also, modulus m must be odd. + */ +static void +finish_mod(uint16_t *a, size_t len, const uint16_t *m, uint32_t neg) +{ + size_t k; + uint32_t cc, xm, ym; + + /* + * First pass: compare a (assumed nonnegative) with m. + */ + cc = 0; + for (k = 0; k < len; k ++) { + uint32_t aw, mw; + + aw = a[k]; + mw = m[k]; + cc = (aw - mw - cc) >> 31; + } + + /* + * At this point: + * if neg = 1, then we must add m (regardless of cc) + * if neg = 0 and cc = 0, then we must subtract m + * if neg = 0 and cc = 1, then we must do nothing + */ + xm = 0x7FFF & -neg; + ym = -(neg | (1 - cc)); + cc = neg; + for (k = 0; k < len; k ++) { + uint32_t aw, mw; + + aw = a[k]; + mw = (m[k] ^ xm) & ym; + aw = aw - mw - cc; + a[k] = aw & 0x7FFF; + cc = aw >> 31; + } +} + +/* + * Compute: + * a <- (a*pa+b*pb)/(2^15) + * b <- (a*qa+b*qb)/(2^15) + * The division is assumed to be exact (i.e. the low word is dropped). + * If the final a is negative, then it is negated. Similarly for b. + * Returned value is the combination of two bits: + * bit 0: 1 if a had to be negated, 0 otherwise + * bit 1: 1 if b had to be negated, 0 otherwise + * + * Factors pa, pb, qa and qb must be at most 2^15 in absolute value. + * Source integers a and b must be nonnegative; top word is not allowed + * to contain an extra 16th bit. + */ +static uint32_t +co_reduce(uint16_t *a, uint16_t *b, size_t len, + int32_t pa, int32_t pb, int32_t qa, int32_t qb) +{ + size_t k; + int32_t cca, ccb; + uint32_t nega, negb; + + cca = 0; + ccb = 0; + for (k = 0; k < len; k ++) { + uint32_t wa, wb, za, zb; + uint16_t tta, ttb; + + /* + * Since: + * |pa| <= 2^15 + * |pb| <= 2^15 + * 0 <= wa <= 2^15 - 1 + * 0 <= wb <= 2^15 - 1 + * |cca| <= 2^16 - 1 + * Then: + * |za| <= (2^15-1)*(2^16) + (2^16-1) = 2^31 - 1 + * + * Thus, the new value of cca is such that |cca| <= 2^16 - 1. + * The same applies to ccb. + */ + wa = a[k]; + wb = b[k]; + za = wa * (uint32_t)pa + wb * (uint32_t)pb + (uint32_t)cca; + zb = wa * (uint32_t)qa + wb * (uint32_t)qb + (uint32_t)ccb; + if (k > 0) { + a[k - 1] = za & 0x7FFF; + b[k - 1] = zb & 0x7FFF; + } + tta = za >> 15; + ttb = zb >> 15; + cca = *(int16_t *)&tta; + ccb = *(int16_t *)&ttb; + } + a[len - 1] = (uint16_t)cca; + b[len - 1] = (uint16_t)ccb; + nega = (uint32_t)cca >> 31; + negb = (uint32_t)ccb >> 31; + cond_negate(a, len, nega); + cond_negate(b, len, negb); + return nega | (negb << 1); +} + +/* + * Compute: + * a <- (a*pa+b*pb)/(2^15) mod m + * b <- (a*qa+b*qb)/(2^15) mod m + * + * m0i is equal to -1/m[0] mod 2^15. + * + * Factors pa, pb, qa and qb must be at most 2^15 in absolute value. + * Source integers a and b must be nonnegative; top word is not allowed + * to contain an extra 16th bit. + */ +static void +co_reduce_mod(uint16_t *a, uint16_t *b, size_t len, + int32_t pa, int32_t pb, int32_t qa, int32_t qb, + const uint16_t *m, uint16_t m0i) +{ + size_t k; + int32_t cca, ccb, fa, fb; + + cca = 0; + ccb = 0; + fa = ((a[0] * (uint32_t)pa + b[0] * (uint32_t)pb) * m0i) & 0x7FFF; + fb = ((a[0] * (uint32_t)qa + b[0] * (uint32_t)qb) * m0i) & 0x7FFF; + for (k = 0; k < len; k ++) { + uint32_t wa, wb, za, zb; + uint32_t tta, ttb; + + /* + * In this loop, carries 'cca' and 'ccb' always fit on + * 17 bits (in absolute value). + */ + wa = a[k]; + wb = b[k]; + za = wa * (uint32_t)pa + wb * (uint32_t)pb + + m[k] * (uint32_t)fa + (uint32_t)cca; + zb = wa * (uint32_t)qa + wb * (uint32_t)qb + + m[k] * (uint32_t)fb + (uint32_t)ccb; + if (k > 0) { + a[k - 1] = za & 0x7FFF; + b[k - 1] = zb & 0x7FFF; + } + + /* + * The XOR-and-sub construction below does an arithmetic + * right shift in a portable way (technically, right-shifting + * a negative signed value is implementation-defined in C). + */ +#define M ((uint32_t)1 << 16) + tta = za >> 15; + ttb = zb >> 15; + tta = (tta ^ M) - M; + ttb = (ttb ^ M) - M; + cca = *(int32_t *)&tta; + ccb = *(int32_t *)&ttb; +#undef M + } + a[len - 1] = (uint32_t)cca; + b[len - 1] = (uint32_t)ccb; + + /* + * At this point: + * -m <= a < 2*m + * -m <= b < 2*m + * (this is a case of Montgomery reduction) + * The top word of 'a' and 'b' may have a 16-th bit set. + * We may have to add or subtract the modulus. + */ + finish_mod(a, len, m, (uint32_t)cca >> 31); + finish_mod(b, len, m, (uint32_t)ccb >> 31); +} + +/* see inner.h */ +uint32_t +br_i15_moddiv(uint16_t *x, const uint16_t *y, const uint16_t *m, uint16_t m0i, + uint16_t *t) +{ + /* + * Algorithm is an extended binary GCD. We maintain four values + * a, b, u and v, with the following invariants: + * + * a * x = y * u mod m + * b * x = y * v mod m + * + * Starting values are: + * + * a = y + * b = m + * u = x + * v = 0 + * + * The formal definition of the algorithm is a sequence of steps: + * + * - If a is even, then a <- a/2 and u <- u/2 mod m. + * - Otherwise, if b is even, then b <- b/2 and v <- v/2 mod m. + * - Otherwise, if a > b, then a <- (a-b)/2 and u <- (u-v)/2 mod m. + * - Otherwise, b <- (b-a)/2 and v <- (v-u)/2 mod m. + * + * Algorithm stops when a = b. At that point, they both are equal + * to GCD(y,m); the modular division succeeds if that value is 1. + * The result of the modular division is then u (or v: both are + * equal at that point). + * + * Each step makes either a or b shrink by at least one bit; hence, + * if m has bit length k bits, then 2k-2 steps are sufficient. + * + * + * Though complexity is quadratic in the size of m, the bit-by-bit + * processing is not very efficient. We can speed up processing by + * remarking that the decisions are taken based only on observation + * of the top and low bits of a and b. + * + * In the loop below, at each iteration, we use the two top words + * of a and b, and the low words of a and b, to compute reduction + * parameters pa, pb, qa and qb such that the new values for a + * and b are: + * + * a' = (a*pa + b*pb) / (2^15) + * b' = (a*qa + b*qb) / (2^15) + * + * the division being exact. + * + * Since the choices are based on the top words, they may be slightly + * off, requiring an optional correction: if a' < 0, then we replace + * pa with -pa, and pb with -pb. The total length of a and b is + * thus reduced by at least 14 bits at each iteration. + * + * The stopping conditions are still the same, though: when a + * and b become equal, they must be both odd (since m is odd, + * the GCD cannot be even), therefore the next operation is a + * subtraction, and one of the values becomes 0. At that point, + * nothing else happens, i.e. one value is stuck at 0, and the + * other one is the GCD. + */ + size_t len, k; + uint16_t *a, *b, *u, *v; + uint32_t num, r; + + len = (m[0] + 15) >> 4; + a = t; + b = a + len; + u = x + 1; + v = b + len; + memcpy(a, y + 1, len * sizeof *y); + memcpy(b, m + 1, len * sizeof *m); + memset(v, 0, len * sizeof *v); + + /* + * Loop below ensures that a and b are reduced by some bits each, + * for a total of at least 14 bits. + */ + for (num = ((m[0] - (m[0] >> 4)) << 1) + 14; num >= 14; num -= 14) { + size_t j; + uint32_t c0, c1; + uint32_t a0, a1, b0, b1; + uint32_t a_hi, b_hi, a_lo, b_lo; + int32_t pa, pb, qa, qb; + int i; + + /* + * Extract top words of a and b. If j is the highest + * index >= 1 such that a[j] != 0 or b[j] != 0, then we want + * (a[j] << 15) + a[j - 1], and (b[j] << 15) + b[j - 1]. + * If a and b are down to one word each, then we use a[0] + * and b[0]. + */ + c0 = (uint32_t)-1; + c1 = (uint32_t)-1; + a0 = 0; + a1 = 0; + b0 = 0; + b1 = 0; + j = len; + while (j -- > 0) { + uint32_t aw, bw; + + aw = a[j]; + bw = b[j]; + a0 ^= (a0 ^ aw) & c0; + a1 ^= (a1 ^ aw) & c1; + b0 ^= (b0 ^ bw) & c0; + b1 ^= (b1 ^ bw) & c1; + c1 = c0; + c0 &= (((aw | bw) + 0xFFFF) >> 16) - (uint32_t)1; + } + + /* + * If c1 = 0, then we grabbed two words for a and b. + * If c1 != 0 but c0 = 0, then we grabbed one word. It + * is not possible that c1 != 0 and c0 != 0, because that + * would mean that both integers are zero. + */ + a1 |= a0 & c1; + a0 &= ~c1; + b1 |= b0 & c1; + b0 &= ~c1; + a_hi = (a0 << 15) + a1; + b_hi = (b0 << 15) + b1; + a_lo = a[0]; + b_lo = b[0]; + + /* + * Compute reduction factors: + * + * a' = a*pa + b*pb + * b' = a*qa + b*qb + * + * such that a' and b' are both multiple of 2^15, but are + * only marginally larger than a and b. + */ + pa = 1; + pb = 0; + qa = 0; + qb = 1; + for (i = 0; i < 15; i ++) { + /* + * At each iteration: + * + * a <- (a-b)/2 if: a is odd, b is odd, a_hi > b_hi + * b <- (b-a)/2 if: a is odd, b is odd, a_hi <= b_hi + * a <- a/2 if: a is even + * b <- b/2 if: a is odd, b is even + * + * We multiply a_lo and b_lo by 2 at each + * iteration, thus a division by 2 really is a + * non-multiplication by 2. + */ + uint32_t r, oa, ob, cAB, cBA, cA; + + /* + * cAB = 1 if b must be subtracted from a + * cBA = 1 if a must be subtracted from b + * cA = 1 if a is divided by 2, 0 otherwise + * + * Rules: + * + * cAB and cBA cannot be both 1. + * if a is not divided by 2, b is. + */ + r = GT(a_hi, b_hi); + oa = (a_lo >> i) & 1; + ob = (b_lo >> i) & 1; + cAB = oa & ob & r; + cBA = oa & ob & NOT(r); + cA = cAB | NOT(oa); + + /* + * Conditional subtractions. + */ + a_lo -= b_lo & -cAB; + a_hi -= b_hi & -cAB; + pa -= qa & -(int32_t)cAB; + pb -= qb & -(int32_t)cAB; + b_lo -= a_lo & -cBA; + b_hi -= a_hi & -cBA; + qa -= pa & -(int32_t)cBA; + qb -= pb & -(int32_t)cBA; + + /* + * Shifting. + */ + a_lo += a_lo & (cA - 1); + pa += pa & ((int32_t)cA - 1); + pb += pb & ((int32_t)cA - 1); + a_hi ^= (a_hi ^ (a_hi >> 1)) & -cA; + b_lo += b_lo & -cA; + qa += qa & -(int32_t)cA; + qb += qb & -(int32_t)cA; + b_hi ^= (b_hi ^ (b_hi >> 1)) & (cA - 1); + } + + /* + * Replace a and b with new values a' and b'. + */ + r = co_reduce(a, b, len, pa, pb, qa, qb); + pa -= pa * ((r & 1) << 1); + pb -= pb * ((r & 1) << 1); + qa -= qa * (r & 2); + qb -= qb * (r & 2); + co_reduce_mod(u, v, len, pa, pb, qa, qb, m + 1, m0i); + } + + /* + * Now one of the arrays should be 0, and the other contains + * the GCD. If a is 0, then u is 0 as well, and v contains + * the division result. + * Result is correct if and only if GCD is 1. + */ + r = (a[0] | b[0]) ^ 1; + u[0] |= v[0]; + for (k = 1; k < len; k ++) { + r |= a[k] | b[k]; + u[k] |= v[k]; + } + return EQ0(r); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_modpow.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_modpow.c new file mode 100644 index 000000000..41cb83e91 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_modpow.c @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +void +br_i15_modpow(uint16_t *x, + const unsigned char *e, size_t elen, + const uint16_t *m, uint16_t m0i, uint16_t *t1, uint16_t *t2) +{ + size_t mlen; + unsigned k; + + mlen = ((m[0] + 31) >> 4) * sizeof m[0]; + memcpy(t1, x, mlen); + br_i15_to_monty(t1, m); + br_i15_zero(x, m[0]); + x[1] = 1; + for (k = 0; k < ((unsigned)elen << 3); k ++) { + uint32_t ctl; + + ctl = (e[elen - 1 - (k >> 3)] >> (k & 7)) & 1; + br_i15_montymul(t2, x, t1, m, m0i); + CCOPY(ctl, x, t2, mlen); + br_i15_montymul(t2, t1, t1, m, m0i); + memcpy(t1, t2, mlen); + } +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_modpow2.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_modpow2.c new file mode 100644 index 000000000..a7f2be874 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_modpow2.c @@ -0,0 +1,165 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +uint32_t +br_i15_modpow_opt(uint16_t *x, + const unsigned char *e, size_t elen, + const uint16_t *m, uint16_t m0i, uint16_t *tmp, size_t twlen) +{ + size_t mlen, mwlen; + uint16_t *t1, *t2, *base; + size_t u, v; + uint32_t acc; + int acc_len, win_len; + + /* + * Get modulus size. + */ + mwlen = (m[0] + 31) >> 4; + mlen = mwlen * sizeof m[0]; + mwlen += (mwlen & 1); + t1 = tmp; + t2 = tmp + mwlen; + + /* + * Compute possible window size, with a maximum of 5 bits. + * When the window has size 1 bit, we use a specific code + * that requires only two temporaries. Otherwise, for a + * window of k bits, we need 2^k+1 temporaries. + */ + if (twlen < (mwlen << 1)) { + return 0; + } + for (win_len = 5; win_len > 1; win_len --) { + if ((((uint32_t)1 << win_len) + 1) * mwlen <= twlen) { + break; + } + } + + /* + * Everything is done in Montgomery representation. + */ + br_i15_to_monty(x, m); + + /* + * Compute window contents. If the window has size one bit only, + * then t2 is set to x; otherwise, t2[0] is left untouched, and + * t2[k] is set to x^k (for k >= 1). + */ + if (win_len == 1) { + memcpy(t2, x, mlen); + } else { + memcpy(t2 + mwlen, x, mlen); + base = t2 + mwlen; + for (u = 2; u < ((unsigned)1 << win_len); u ++) { + br_i15_montymul(base + mwlen, base, x, m, m0i); + base += mwlen; + } + } + + /* + * We need to set x to 1, in Montgomery representation. This can + * be done efficiently by setting the high word to 1, then doing + * one word-sized shift. + */ + br_i15_zero(x, m[0]); + x[(m[0] + 15) >> 4] = 1; + br_i15_muladd_small(x, 0, m); + + /* + * We process bits from most to least significant. At each + * loop iteration, we have acc_len bits in acc. + */ + acc = 0; + acc_len = 0; + while (acc_len > 0 || elen > 0) { + int i, k; + uint32_t bits; + + /* + * Get the next bits. + */ + k = win_len; + if (acc_len < win_len) { + if (elen > 0) { + acc = (acc << 8) | *e ++; + elen --; + acc_len += 8; + } else { + k = acc_len; + } + } + bits = (acc >> (acc_len - k)) & (((uint32_t)1 << k) - 1); + acc_len -= k; + + /* + * We could get exactly k bits. Compute k squarings. + */ + for (i = 0; i < k; i ++) { + br_i15_montymul(t1, x, x, m, m0i); + memcpy(x, t1, mlen); + } + + /* + * Window lookup: we want to set t2 to the window + * lookup value, assuming the bits are non-zero. If + * the window length is 1 bit only, then t2 is + * already set; otherwise, we do a constant-time lookup. + */ + if (win_len > 1) { + br_i15_zero(t2, m[0]); + base = t2 + mwlen; + for (u = 1; u < ((uint32_t)1 << k); u ++) { + uint32_t mask; + + mask = -EQ(u, bits); + for (v = 1; v < mwlen; v ++) { + t2[v] |= mask & base[v]; + } + base += mwlen; + } + } + + /* + * Multiply with the looked-up value. We keep the + * product only if the exponent bits are not all-zero. + */ + br_i15_montymul(t1, x, t2, m, m0i); + CCOPY(NEQ(bits, 0), x, t1, mlen); + } + + /* + * Convert back from Montgomery representation, and exit. + */ + br_i15_from_monty(x, m, m0i); + return 1; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_montmul.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_montmul.c new file mode 100644 index 000000000..a04c403ee --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_montmul.c @@ -0,0 +1,189 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +void +br_i15_montymul(uint16_t *d, const uint16_t *x, const uint16_t *y, + const uint16_t *m, uint16_t m0i) +{ + size_t len, len4, u, v; + uint32_t dh; + + len = (m[0] + 15) >> 4; + len4 = len & ~(size_t)3; + br_i15_zero(d, m[0]); + dh = 0; + for (u = 0; u < len; u ++) { + uint32_t f, xu, r, zh; + + xu = x[u + 1]; + f = MUL15((d[1] + MUL15(x[u + 1], y[1])) & 0x7FFF, m0i) + & 0x7FFF; +#if BR_ARMEL_CORTEXM_GCC + if (len4 != 0) { + uint16_t *limit; + + limit = d + len4; + asm volatile ( +"\n\ + @ carry: r=r2 \n\ + @ multipliers: xu=r3 f=r4 \n\ + @ base registers: d+v=r5 y+v=r6 m+v=r7 \n\ + @ r8 contains 0x7FFF \n\ + @ r9 contains d+len4 \n\ + ldr r0, %[limit] \n\ + ldr r3, %[xu] \n\ + mov r9, r0 \n\ + ldr r4, %[f] \n\ + eor r2, r2 \n\ + ldr r5, %[d] \n\ + sub r1, r2, #1 \n\ + ldr r6, %[y] \n\ + lsr r1, r1, #17 \n\ + ldr r7, %[m] \n\ + mov r8, r1 \n\ +loop%=: \n\ + ldrh r0, [r6, #2] \n\ + ldrh r1, [r7, #2] \n\ + mul r0, r3 \n\ + mul r1, r4 \n\ + add r2, r0, r2 \n\ + ldrh r0, [r5, #2] \n\ + add r2, r1, r2 \n\ + mov r1, r8 \n\ + add r2, r0, r2 \n\ + and r1, r2 \n\ + lsr r2, r2, #15 \n\ + strh r1, [r5, #0] \n\ + \n\ + ldrh r0, [r6, #4] \n\ + ldrh r1, [r7, #4] \n\ + mul r0, r3 \n\ + mul r1, r4 \n\ + add r2, r0, r2 \n\ + ldrh r0, [r5, #4] \n\ + add r2, r1, r2 \n\ + mov r1, r8 \n\ + add r2, r0, r2 \n\ + and r1, r2 \n\ + lsr r2, r2, #15 \n\ + strh r1, [r5, #2] \n\ + \n\ + ldrh r0, [r6, #6] \n\ + ldrh r1, [r7, #6] \n\ + mul r0, r3 \n\ + mul r1, r4 \n\ + add r2, r0, r2 \n\ + ldrh r0, [r5, #6] \n\ + add r2, r1, r2 \n\ + mov r1, r8 \n\ + add r2, r0, r2 \n\ + and r1, r2 \n\ + lsr r2, r2, #15 \n\ + strh r1, [r5, #4] \n\ + \n\ + ldrh r0, [r6, #8] \n\ + ldrh r1, [r7, #8] \n\ + mul r0, r3 \n\ + mul r1, r4 \n\ + add r2, r0, r2 \n\ + ldrh r0, [r5, #8] \n\ + add r2, r1, r2 \n\ + mov r1, r8 \n\ + add r2, r0, r2 \n\ + and r1, r2 \n\ + lsr r2, r2, #15 \n\ + strh r1, [r5, #6] \n\ + \n\ + add r5, r5, #8 \n\ + add r6, r6, #8 \n\ + add r7, r7, #8 \n\ + cmp r5, r9 \n\ + bne loop%= \n\ + \n\ + str r2, %[carry] \n\ +" +: [carry] "=m" (r) +: [xu] "m" (xu), [f] "m" (f), [d] "m" (d), [y] "m" (y), + [m] "m" (m), [limit] "m" (limit) +: "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9" ); + } else { + r = 0; + } + v = len4; +#else + r = 0; + for (v = 0; v < len4; v += 4) { + uint32_t z; + + z = d[v + 1] + MUL15(xu, y[v + 1]) + + MUL15(f, m[v + 1]) + r; + r = z >> 15; + d[v + 0] = z & 0x7FFF; + z = d[v + 2] + MUL15(xu, y[v + 2]) + + MUL15(f, m[v + 2]) + r; + r = z >> 15; + d[v + 1] = z & 0x7FFF; + z = d[v + 3] + MUL15(xu, y[v + 3]) + + MUL15(f, m[v + 3]) + r; + r = z >> 15; + d[v + 2] = z & 0x7FFF; + z = d[v + 4] + MUL15(xu, y[v + 4]) + + MUL15(f, m[v + 4]) + r; + r = z >> 15; + d[v + 3] = z & 0x7FFF; + } +#endif + for (; v < len; v ++) { + uint32_t z; + + z = d[v + 1] + MUL15(xu, y[v + 1]) + + MUL15(f, m[v + 1]) + r; + r = z >> 15; + d[v + 0] = z & 0x7FFF; + } + + zh = dh + r; + d[len] = zh & 0x7FFF; + dh = zh >> 15; + } + + /* + * Restore the bit length (it was overwritten in the loop above). + */ + d[0] = m[0]; + + /* + * d[] may be greater than m[], but it is still lower than twice + * the modulus. + */ + br_i15_sub(d, m, NEQ(dh, 0) | NOT(br_i15_sub(d, m, 0))); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_mulacc.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_mulacc.c new file mode 100644 index 000000000..2ad359a5a --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_mulacc.c @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +void +br_i15_mulacc(uint16_t *d, const uint16_t *a, const uint16_t *b) +{ + size_t alen, blen, u; + unsigned dl, dh; + + alen = (a[0] + 15) >> 4; + blen = (b[0] + 15) >> 4; + + /* + * Announced bit length of d[] will be the sum of the announced + * bit lengths of a[] and b[]; but the lengths are encoded. + */ + dl = (a[0] & 15) + (b[0] & 15); + dh = (a[0] >> 4) + (b[0] >> 4); + d[0] = (dh << 4) + dl + (~(uint32_t)(dl - 15) >> 31); + + for (u = 0; u < blen; u ++) { + uint32_t f; + size_t v; + uint32_t cc; + + f = b[1 + u]; + cc = 0; + for (v = 0; v < alen; v ++) { + uint32_t z; + + z = (uint32_t)d[1 + u + v] + MUL15(f, a[1 + v]) + cc; + cc = z >> 15; + d[1 + u + v] = z & 0x7FFF; + } + d[1 + u + alen] = cc; + } +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_muladd.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_muladd.c new file mode 100644 index 000000000..bb1e572e4 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_muladd.c @@ -0,0 +1,178 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* + * Constant-time division. The divisor must not be larger than 16 bits, + * and the quotient must fit on 17 bits. + */ +static uint32_t +divrem16(uint32_t x, uint32_t d, uint32_t *r) +{ + int i; + uint32_t q; + + q = 0; + d <<= 16; + for (i = 16; i >= 0; i --) { + uint32_t ctl; + + ctl = LE(d, x); + q |= ctl << i; + x -= (-ctl) & d; + d >>= 1; + } + if (r != NULL) { + *r = x; + } + return q; +} + +/* see inner.h */ +void +br_i15_muladd_small(uint16_t *x, uint16_t z, const uint16_t *m) +{ + /* + * Constant-time: we accept to leak the exact bit length of the + * modulus m. + */ + unsigned m_bitlen, mblr; + size_t u, mlen; + uint32_t hi, a0, a, b, q; + uint32_t cc, tb, over, under; + + /* + * Simple case: the modulus fits on one word. + */ + m_bitlen = m[0]; + if (m_bitlen == 0) { + return; + } + if (m_bitlen <= 15) { + uint32_t rem; + + divrem16(((uint32_t)x[1] << 15) | z, m[1], &rem); + x[1] = rem; + return; + } + mlen = (m_bitlen + 15) >> 4; + mblr = m_bitlen & 15; + + /* + * Principle: we estimate the quotient (x*2^15+z)/m by + * doing a 30/15 division with the high words. + * + * Let: + * w = 2^15 + * a = (w*a0 + a1) * w^N + a2 + * b = b0 * w^N + b2 + * such that: + * 0 <= a0 < w + * 0 <= a1 < w + * 0 <= a2 < w^N + * w/2 <= b0 < w + * 0 <= b2 < w^N + * a < w*b + * I.e. the two top words of a are a0:a1, the top word of b is + * b0, we ensured that b0 is "full" (high bit set), and a is + * such that the quotient q = a/b fits on one word (0 <= q < w). + * + * If a = b*q + r (with 0 <= r < q), then we can estimate q by + * using a division on the top words: + * a0*w + a1 = b0*u + v (with 0 <= v < b0) + * Then the following holds: + * 0 <= u <= w + * u-2 <= q <= u + */ + hi = x[mlen]; + if (mblr == 0) { + a0 = x[mlen]; + memmove(x + 2, x + 1, (mlen - 1) * sizeof *x); + x[1] = z; + a = (a0 << 15) + x[mlen]; + b = m[mlen]; + } else { + a0 = (x[mlen] << (15 - mblr)) | (x[mlen - 1] >> mblr); + memmove(x + 2, x + 1, (mlen - 1) * sizeof *x); + x[1] = z; + a = (a0 << 15) | (((x[mlen] << (15 - mblr)) + | (x[mlen - 1] >> mblr)) & 0x7FFF); + b = (m[mlen] << (15 - mblr)) | (m[mlen - 1] >> mblr); + } + q = divrem16(a, b, NULL); + + /* + * We computed an estimate for q, but the real one may be q, + * q-1 or q-2; moreover, the division may have returned a value + * 8000 or even 8001 if the two high words were identical, and + * we want to avoid values beyond 7FFF. We thus adjust q so + * that the "true" multiplier will be q+1, q or q-1, and q is + * in the 0000..7FFF range. + */ + q = MUX(EQ(b, a0), 0x7FFF, q - 1 + ((q - 1) >> 31)); + + /* + * We subtract q*m from x (x has an extra high word of value 'hi'). + * Since q may be off by 1 (in either direction), we may have to + * add or subtract m afterwards. + * + * The 'tb' flag will be true (1) at the end of the loop if the + * result is greater than or equal to the modulus (not counting + * 'hi' or the carry). + */ + cc = 0; + tb = 1; + for (u = 1; u <= mlen; u ++) { + uint32_t mw, zl, xw, nxw; + + mw = m[u]; + zl = MUL15(mw, q) + cc; + cc = zl >> 15; + zl &= 0x7FFF; + xw = x[u]; + nxw = xw - zl; + cc += nxw >> 31; + nxw &= 0x7FFF; + x[u] = nxw; + tb = MUX(EQ(nxw, mw), tb, GT(nxw, mw)); + } + + /* + * If we underestimated q, then either cc < hi (one extra bit + * beyond the top array word), or cc == hi and tb is true (no + * extra bit, but the result is not lower than the modulus). + * + * If we overestimated q, then cc > hi. + */ + over = GT(cc, hi); + under = ~over & (tb | LT(cc, hi)); + br_i15_add(x, m, over); + br_i15_sub(x, m, under); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_ninv15.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_ninv15.c new file mode 100644 index 000000000..82f7595ce --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_ninv15.c @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +uint16_t +br_i15_ninv15(uint16_t x) +{ + uint32_t y; + + y = 2 - x; + y = MUL15(y, 2 - MUL15(x, y)); + y = MUL15(y, 2 - MUL15(x, y)); + y = MUL15(y, 2 - MUL15(x, y)); + return MUX(x & 1, -y, 0) & 0x7FFF; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_reduce.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_reduce.c new file mode 100644 index 000000000..fec4ae4f1 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_reduce.c @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +void +br_i15_reduce(uint16_t *x, const uint16_t *a, const uint16_t *m) +{ + uint32_t m_bitlen, a_bitlen; + size_t mlen, alen, u; + + m_bitlen = m[0]; + mlen = (m_bitlen + 15) >> 4; + + x[0] = m_bitlen; + if (m_bitlen == 0) { + return; + } + + /* + * If the source is shorter, then simply copy all words from a[] + * and zero out the upper words. + */ + a_bitlen = a[0]; + alen = (a_bitlen + 15) >> 4; + if (a_bitlen < m_bitlen) { + memcpy(x + 1, a + 1, alen * sizeof *a); + for (u = alen; u < mlen; u ++) { + x[u + 1] = 0; + } + return; + } + + /* + * The source length is at least equal to that of the modulus. + * We must thus copy N-1 words, and input the remaining words + * one by one. + */ + memcpy(x + 1, a + 2 + (alen - mlen), (mlen - 1) * sizeof *a); + x[mlen] = 0; + for (u = 1 + alen - mlen; u > 0; u --) { + br_i15_muladd_small(x, a[u], m); + } +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_rshift.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_rshift.c new file mode 100644 index 000000000..3e81339c2 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_rshift.c @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +void +br_i15_rshift(uint16_t *x, int count) +{ + size_t u, len; + unsigned r; + + len = (x[0] + 15) >> 4; + if (len == 0) { + return; + } + r = x[1] >> count; + for (u = 2; u <= len; u ++) { + unsigned w; + + w = x[u]; + x[u - 1] = ((w << (15 - count)) | r) & 0x7FFF; + r = w >> count; + } + x[len] = r; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_sub.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_sub.c new file mode 100644 index 000000000..cffcbcab3 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_sub.c @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +uint32_t +br_i15_sub(uint16_t *a, const uint16_t *b, uint32_t ctl) +{ + uint32_t cc; + size_t u, m; + + cc = 0; + m = (a[0] + 31) >> 4; + for (u = 1; u < m; u ++) { + uint32_t aw, bw, naw; + + aw = a[u]; + bw = b[u]; + naw = aw - bw - cc; + cc = naw >> 31; + a[u] = MUX(ctl, naw & 0x7FFF, aw); + } + return cc; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_tmont.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_tmont.c new file mode 100644 index 000000000..59b101fb0 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i15_tmont.c @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +void +br_i15_to_monty(uint16_t *x, const uint16_t *m) +{ + unsigned k; + + for (k = (m[0] + 15) >> 4; k > 0; k --) { + br_i15_muladd_small(x, 0, m); + } +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_add.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_add.c new file mode 100644 index 000000000..631c6e79a --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_add.c @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +uint32_t +br_i31_add(uint32_t *a, const uint32_t *b, uint32_t ctl) +{ + uint32_t cc; + size_t u, m; + + cc = 0; + m = (a[0] + 63) >> 5; + for (u = 1; u < m; u ++) { + uint32_t aw, bw, naw; + + aw = a[u]; + bw = b[u]; + naw = aw + bw + cc; + cc = naw >> 31; + a[u] = MUX(ctl, naw & (uint32_t)0x7FFFFFFF, aw); + } + return cc; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_bitlen.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_bitlen.c new file mode 100644 index 000000000..4086fd69a --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_bitlen.c @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +uint32_t +br_i31_bit_length(uint32_t *x, size_t xlen) +{ + uint32_t tw, twk; + + tw = 0; + twk = 0; + while (xlen -- > 0) { + uint32_t w, c; + + c = EQ(tw, 0); + w = x[xlen]; + tw = MUX(c, w, tw); + twk = MUX(c, (uint32_t)xlen, twk); + } + return (twk << 5) + BIT_LENGTH(tw); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_decmod.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_decmod.c new file mode 100644 index 000000000..5ea30d8c1 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_decmod.c @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +uint32_t +br_i31_decode_mod(uint32_t *x, const void *src, size_t len, const uint32_t *m) +{ + /* + * Two-pass algorithm: in the first pass, we determine whether the + * value fits; in the second pass, we do the actual write. + * + * During the first pass, 'r' contains the comparison result so + * far: + * 0x00000000 value is equal to the modulus + * 0x00000001 value is greater than the modulus + * 0xFFFFFFFF value is lower than the modulus + * + * Since we iterate starting with the least significant bytes (at + * the end of src[]), each new comparison overrides the previous + * except when the comparison yields 0 (equal). + * + * During the second pass, 'r' is either 0xFFFFFFFF (value fits) + * or 0x00000000 (value does not fit). + * + * We must iterate over all bytes of the source, _and_ possibly + * some extra virtual bytes (with value 0) so as to cover the + * complete modulus as well. We also add 4 such extra bytes beyond + * the modulus length because it then guarantees that no accumulated + * partial word remains to be processed. + */ + const unsigned char *buf; + size_t mlen, tlen; + int pass; + uint32_t r; + + buf = src; + mlen = (m[0] + 31) >> 5; + tlen = (mlen << 2); + if (tlen < len) { + tlen = len; + } + tlen += 4; + r = 0; + for (pass = 0; pass < 2; pass ++) { + size_t u, v; + uint32_t acc; + int acc_len; + + v = 1; + acc = 0; + acc_len = 0; + for (u = 0; u < tlen; u ++) { + uint32_t b; + + if (u < len) { + b = buf[len - 1 - u]; + } else { + b = 0; + } + acc |= (b << acc_len); + acc_len += 8; + if (acc_len >= 31) { + uint32_t xw; + + xw = acc & (uint32_t)0x7FFFFFFF; + acc_len -= 31; + acc = b >> (8 - acc_len); + if (v <= mlen) { + if (pass) { + x[v] = r & xw; + } else { + uint32_t cc; + + cc = (uint32_t)CMP(xw, m[v]); + r = MUX(EQ(cc, 0), r, cc); + } + } else { + if (!pass) { + r = MUX(EQ(xw, 0), r, 1); + } + } + v ++; + } + } + + /* + * When we reach this point at the end of the first pass: + * r is either 0, 1 or -1; we want to set r to 0 if it + * is equal to 0 or 1, and leave it to -1 otherwise. + * + * When we reach this point at the end of the second pass: + * r is either 0 or -1; we want to leave that value + * untouched. This is a subcase of the previous. + */ + r >>= 1; + r |= (r << 1); + } + + x[0] = m[0]; + return r & (uint32_t)1; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_decode.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_decode.c new file mode 100644 index 000000000..7badf15d2 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_decode.c @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +void +br_i31_decode(uint32_t *x, const void *src, size_t len) +{ + const unsigned char *buf; + size_t u, v; + uint32_t acc; + int acc_len; + + buf = src; + u = len; + v = 1; + acc = 0; + acc_len = 0; + while (u -- > 0) { + uint32_t b; + + b = buf[u]; + acc |= (b << acc_len); + acc_len += 8; + if (acc_len >= 31) { + x[v ++] = acc & (uint32_t)0x7FFFFFFF; + acc_len -= 31; + acc = b >> (8 - acc_len); + } + } + if (acc_len != 0) { + x[v ++] = acc; + } + x[0] = br_i31_bit_length(x + 1, v - 1); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_decred.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_decred.c new file mode 100644 index 000000000..7de64e03e --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_decred.c @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +void +br_i31_decode_reduce(uint32_t *x, + const void *src, size_t len, const uint32_t *m) +{ + uint32_t m_ebitlen, m_rbitlen; + size_t mblen, k; + const unsigned char *buf; + uint32_t acc; + int acc_len; + + /* + * Get the encoded bit length. + */ + m_ebitlen = m[0]; + + /* + * Special case for an invalid (null) modulus. + */ + if (m_ebitlen == 0) { + x[0] = 0; + return; + } + + /* + * Clear the destination. + */ + br_i31_zero(x, m_ebitlen); + + /* + * First decode directly as many bytes as possible. This requires + * computing the actual bit length. + */ + m_rbitlen = m_ebitlen >> 5; + m_rbitlen = (m_ebitlen & 31) + (m_rbitlen << 5) - m_rbitlen; + mblen = (m_rbitlen + 7) >> 3; + k = mblen - 1; + if (k >= len) { + br_i31_decode(x, src, len); + x[0] = m_ebitlen; + return; + } + buf = src; + br_i31_decode(x, buf, k); + x[0] = m_ebitlen; + + /* + * Input remaining bytes, using 31-bit words. + */ + acc = 0; + acc_len = 0; + while (k < len) { + uint32_t v; + + v = buf[k ++]; + if (acc_len >= 23) { + acc_len -= 23; + acc <<= (8 - acc_len); + acc |= v >> acc_len; + br_i31_muladd_small(x, acc, m); + acc = v & (0xFF >> (8 - acc_len)); + } else { + acc = (acc << 8) | v; + acc_len += 8; + } + } + + /* + * We may have some bits accumulated. We then perform a shift to + * be able to inject these bits as a full 31-bit word. + */ + if (acc_len != 0) { + acc = (acc | (x[1] << acc_len)) & 0x7FFFFFFF; + br_i31_rshift(x, 31 - acc_len); + br_i31_muladd_small(x, acc, m); + } +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_encode.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_encode.c new file mode 100644 index 000000000..6fbfaffcb --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_encode.c @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +void +br_i31_encode(void *dst, size_t len, const uint32_t *x) +{ + unsigned char *buf; + size_t k, xlen; + uint32_t acc; + int acc_len; + + xlen = (x[0] + 31) >> 5; + if (xlen == 0) { + memset(dst, 0, len); + return; + } + buf = (unsigned char *)dst + len; + k = 1; + acc = 0; + acc_len = 0; + while (len != 0) { + uint32_t w; + + w = (k <= xlen) ? x[k] : 0; + k ++; + if (acc_len == 0) { + acc = w; + acc_len = 31; + } else { + uint32_t z; + + z = acc | (w << acc_len); + acc_len --; + acc = w >> (31 - acc_len); + if (len >= 4) { + buf -= 4; + len -= 4; + br_enc32be(buf, z); + } else { + switch (len) { + case 3: + buf[-3] = (unsigned char)(z >> 16); + /* fall through */ + case 2: + buf[-2] = (unsigned char)(z >> 8); + /* fall through */ + case 1: + buf[-1] = (unsigned char)z; + break; + } + return; + } + } + } +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_fmont.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_fmont.c new file mode 100644 index 000000000..d2955af2c --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_fmont.c @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +void +br_i31_from_monty(uint32_t *x, const uint32_t *m, uint32_t m0i) +{ + size_t len, u, v; + + len = (m[0] + 31) >> 5; + for (u = 0; u < len; u ++) { + uint32_t f; + uint64_t cc; + + f = MUL31_lo(x[1], m0i); + cc = 0; + for (v = 0; v < len; v ++) { + uint64_t z; + + z = (uint64_t)x[v + 1] + MUL31(f, m[v + 1]) + cc; + cc = z >> 31; + if (v != 0) { + x[v] = (uint32_t)z & 0x7FFFFFFF; + } + } + x[len] = (uint32_t)cc; + } + + /* + * We may have to do an extra subtraction, but only if the + * value in x[] is indeed greater than or equal to that of m[], + * which is why we must do two calls (first call computes the + * carry, second call performs the subtraction only if the carry + * is 0). + */ + br_i31_sub(x, m, NOT(br_i31_sub(x, m, 0))); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_iszero.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_iszero.c new file mode 100644 index 000000000..116fd4dc2 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_iszero.c @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +uint32_t +br_i31_iszero(const uint32_t *x) +{ + uint32_t z; + size_t u; + + z = 0; + for (u = (x[0] + 31) >> 5; u > 0; u --) { + z |= x[u]; + } + return ~(z | -z) >> 31; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_moddiv.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_moddiv.c new file mode 100644 index 000000000..febf35440 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_moddiv.c @@ -0,0 +1,493 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* + * In this file, we handle big integers with a custom format, i.e. + * without the usual one-word header. Value is split into 31-bit words, + * each stored in a 32-bit slot (top bit is zero) in little-endian + * order. The length (in words) is provided explicitly. In some cases, + * the value can be negative (using two's complement representation). In + * some cases, the top word is allowed to have a 32th bit. + */ + +/* + * Negate big integer conditionally. The value consists of 'len' words, + * with 31 bits in each word (the top bit of each word should be 0, + * except possibly for the last word). If 'ctl' is 1, the negation is + * computed; otherwise, if 'ctl' is 0, then the value is unchanged. + */ +static void +cond_negate(uint32_t *a, size_t len, uint32_t ctl) +{ + size_t k; + uint32_t cc, xm; + + cc = ctl; + xm = -ctl >> 1; + for (k = 0; k < len; k ++) { + uint32_t aw; + + aw = a[k]; + aw = (aw ^ xm) + cc; + a[k] = aw & 0x7FFFFFFF; + cc = aw >> 31; + } +} + +/* + * Finish modular reduction. Rules on input parameters: + * + * if neg = 1, then -m <= a < 0 + * if neg = 0, then 0 <= a < 2*m + * + * If neg = 0, then the top word of a[] may use 32 bits. + * + * Also, modulus m must be odd. + */ +static void +finish_mod(uint32_t *a, size_t len, const uint32_t *m, uint32_t neg) +{ + size_t k; + uint32_t cc, xm, ym; + + /* + * First pass: compare a (assumed nonnegative) with m. + * Note that if the final word uses the top extra bit, then + * subtracting m must yield a value less than 2^31, since we + * assumed that a < 2*m. + */ + cc = 0; + for (k = 0; k < len; k ++) { + uint32_t aw, mw; + + aw = a[k]; + mw = m[k]; + cc = (aw - mw - cc) >> 31; + } + + /* + * At this point: + * if neg = 1, then we must add m (regardless of cc) + * if neg = 0 and cc = 0, then we must subtract m + * if neg = 0 and cc = 1, then we must do nothing + */ + xm = -neg >> 1; + ym = -(neg | (1 - cc)); + cc = neg; + for (k = 0; k < len; k ++) { + uint32_t aw, mw; + + aw = a[k]; + mw = (m[k] ^ xm) & ym; + aw = aw - mw - cc; + a[k] = aw & 0x7FFFFFFF; + cc = aw >> 31; + } +} + +/* + * Compute: + * a <- (a*pa+b*pb)/(2^31) + * b <- (a*qa+b*qb)/(2^31) + * The division is assumed to be exact (i.e. the low word is dropped). + * If the final a is negative, then it is negated. Similarly for b. + * Returned value is the combination of two bits: + * bit 0: 1 if a had to be negated, 0 otherwise + * bit 1: 1 if b had to be negated, 0 otherwise + * + * Factors pa, pb, qa and qb must be at most 2^31 in absolute value. + * Source integers a and b must be nonnegative; top word is not allowed + * to contain an extra 32th bit. + */ +static uint32_t +co_reduce(uint32_t *a, uint32_t *b, size_t len, + int64_t pa, int64_t pb, int64_t qa, int64_t qb) +{ + size_t k; + int64_t cca, ccb; + uint32_t nega, negb; + + cca = 0; + ccb = 0; + for (k = 0; k < len; k ++) { + uint32_t wa, wb; + uint64_t za, zb; + uint64_t tta, ttb; + + /* + * Since: + * |pa| <= 2^31 + * |pb| <= 2^31 + * 0 <= wa <= 2^31 - 1 + * 0 <= wb <= 2^31 - 1 + * |cca| <= 2^32 - 1 + * Then: + * |za| <= (2^31-1)*(2^32) + (2^32-1) = 2^63 - 1 + * + * Thus, the new value of cca is such that |cca| <= 2^32 - 1. + * The same applies to ccb. + */ + wa = a[k]; + wb = b[k]; + za = wa * (uint64_t)pa + wb * (uint64_t)pb + (uint64_t)cca; + zb = wa * (uint64_t)qa + wb * (uint64_t)qb + (uint64_t)ccb; + if (k > 0) { + a[k - 1] = za & 0x7FFFFFFF; + b[k - 1] = zb & 0x7FFFFFFF; + } + + /* + * For the new values of cca and ccb, we need a signed + * right-shift; since, in C, right-shifting a signed + * negative value is implementation-defined, we use a + * custom portable sign extension expression. + */ +#define M ((uint64_t)1 << 32) + tta = za >> 31; + ttb = zb >> 31; + tta = (tta ^ M) - M; + ttb = (ttb ^ M) - M; + cca = *(int64_t *)&tta; + ccb = *(int64_t *)&ttb; +#undef M + } + a[len - 1] = (uint32_t)cca; + b[len - 1] = (uint32_t)ccb; + + nega = (uint32_t)((uint64_t)cca >> 63); + negb = (uint32_t)((uint64_t)ccb >> 63); + cond_negate(a, len, nega); + cond_negate(b, len, negb); + return nega | (negb << 1); +} + +/* + * Compute: + * a <- (a*pa+b*pb)/(2^31) mod m + * b <- (a*qa+b*qb)/(2^31) mod m + * + * m0i is equal to -1/m[0] mod 2^31. + * + * Factors pa, pb, qa and qb must be at most 2^31 in absolute value. + * Source integers a and b must be nonnegative; top word is not allowed + * to contain an extra 32th bit. + */ +static void +co_reduce_mod(uint32_t *a, uint32_t *b, size_t len, + int64_t pa, int64_t pb, int64_t qa, int64_t qb, + const uint32_t *m, uint32_t m0i) +{ + size_t k; + int64_t cca, ccb; + uint32_t fa, fb; + + cca = 0; + ccb = 0; + fa = ((a[0] * (uint32_t)pa + b[0] * (uint32_t)pb) * m0i) & 0x7FFFFFFF; + fb = ((a[0] * (uint32_t)qa + b[0] * (uint32_t)qb) * m0i) & 0x7FFFFFFF; + for (k = 0; k < len; k ++) { + uint32_t wa, wb; + uint64_t za, zb; + uint64_t tta, ttb; + + /* + * In this loop, carries 'cca' and 'ccb' always fit on + * 33 bits (in absolute value). + */ + wa = a[k]; + wb = b[k]; + za = wa * (uint64_t)pa + wb * (uint64_t)pb + + m[k] * (uint64_t)fa + (uint64_t)cca; + zb = wa * (uint64_t)qa + wb * (uint64_t)qb + + m[k] * (uint64_t)fb + (uint64_t)ccb; + if (k > 0) { + a[k - 1] = (uint32_t)za & 0x7FFFFFFF; + b[k - 1] = (uint32_t)zb & 0x7FFFFFFF; + } + +#define M ((uint64_t)1 << 32) + tta = za >> 31; + ttb = zb >> 31; + tta = (tta ^ M) - M; + ttb = (ttb ^ M) - M; + cca = *(int64_t *)&tta; + ccb = *(int64_t *)&ttb; +#undef M + } + a[len - 1] = (uint32_t)cca; + b[len - 1] = (uint32_t)ccb; + + /* + * At this point: + * -m <= a < 2*m + * -m <= b < 2*m + * (this is a case of Montgomery reduction) + * The top word of 'a' and 'b' may have a 32-th bit set. + * We may have to add or subtract the modulus. + */ + finish_mod(a, len, m, (uint32_t)((uint64_t)cca >> 63)); + finish_mod(b, len, m, (uint32_t)((uint64_t)ccb >> 63)); +} + +/* see inner.h */ +uint32_t +br_i31_moddiv(uint32_t *x, const uint32_t *y, const uint32_t *m, uint32_t m0i, + uint32_t *t) +{ + /* + * Algorithm is an extended binary GCD. We maintain four values + * a, b, u and v, with the following invariants: + * + * a * x = y * u mod m + * b * x = y * v mod m + * + * Starting values are: + * + * a = y + * b = m + * u = x + * v = 0 + * + * The formal definition of the algorithm is a sequence of steps: + * + * - If a is even, then a <- a/2 and u <- u/2 mod m. + * - Otherwise, if b is even, then b <- b/2 and v <- v/2 mod m. + * - Otherwise, if a > b, then a <- (a-b)/2 and u <- (u-v)/2 mod m. + * - Otherwise, b <- (b-a)/2 and v <- (v-u)/2 mod m. + * + * Algorithm stops when a = b. At that point, they both are equal + * to GCD(y,m); the modular division succeeds if that value is 1. + * The result of the modular division is then u (or v: both are + * equal at that point). + * + * Each step makes either a or b shrink by at least one bit; hence, + * if m has bit length k bits, then 2k-2 steps are sufficient. + * + * + * Though complexity is quadratic in the size of m, the bit-by-bit + * processing is not very efficient. We can speed up processing by + * remarking that the decisions are taken based only on observation + * of the top and low bits of a and b. + * + * In the loop below, at each iteration, we use the two top words + * of a and b, and the low words of a and b, to compute reduction + * parameters pa, pb, qa and qb such that the new values for a + * and b are: + * + * a' = (a*pa + b*pb) / (2^31) + * b' = (a*qa + b*qb) / (2^31) + * + * the division being exact. + * + * Since the choices are based on the top words, they may be slightly + * off, requiring an optional correction: if a' < 0, then we replace + * pa with -pa, and pb with -pb. The total length of a and b is + * thus reduced by at least 30 bits at each iteration. + * + * The stopping conditions are still the same, though: when a + * and b become equal, they must be both odd (since m is odd, + * the GCD cannot be even), therefore the next operation is a + * subtraction, and one of the values becomes 0. At that point, + * nothing else happens, i.e. one value is stuck at 0, and the + * other one is the GCD. + */ + size_t len, k; + uint32_t *a, *b, *u, *v; + uint32_t num, r; + + len = (m[0] + 31) >> 5; + a = t; + b = a + len; + u = x + 1; + v = b + len; + memcpy(a, y + 1, len * sizeof *y); + memcpy(b, m + 1, len * sizeof *m); + memset(v, 0, len * sizeof *v); + + /* + * Loop below ensures that a and b are reduced by some bits each, + * for a total of at least 30 bits. + */ + for (num = ((m[0] - (m[0] >> 5)) << 1) + 30; num >= 30; num -= 30) { + size_t j; + uint32_t c0, c1; + uint32_t a0, a1, b0, b1; + uint64_t a_hi, b_hi; + uint32_t a_lo, b_lo; + int64_t pa, pb, qa, qb; + int i; + + /* + * Extract top words of a and b. If j is the highest + * index >= 1 such that a[j] != 0 or b[j] != 0, then we want + * (a[j] << 31) + a[j - 1], and (b[j] << 31) + b[j - 1]. + * If a and b are down to one word each, then we use a[0] + * and b[0]. + */ + c0 = (uint32_t)-1; + c1 = (uint32_t)-1; + a0 = 0; + a1 = 0; + b0 = 0; + b1 = 0; + j = len; + while (j -- > 0) { + uint32_t aw, bw; + + aw = a[j]; + bw = b[j]; + a0 ^= (a0 ^ aw) & c0; + a1 ^= (a1 ^ aw) & c1; + b0 ^= (b0 ^ bw) & c0; + b1 ^= (b1 ^ bw) & c1; + c1 = c0; + c0 &= (((aw | bw) + 0x7FFFFFFF) >> 31) - (uint32_t)1; + } + + /* + * If c1 = 0, then we grabbed two words for a and b. + * If c1 != 0 but c0 = 0, then we grabbed one word. It + * is not possible that c1 != 0 and c0 != 0, because that + * would mean that both integers are zero. + */ + a1 |= a0 & c1; + a0 &= ~c1; + b1 |= b0 & c1; + b0 &= ~c1; + a_hi = ((uint64_t)a0 << 31) + a1; + b_hi = ((uint64_t)b0 << 31) + b1; + a_lo = a[0]; + b_lo = b[0]; + + /* + * Compute reduction factors: + * + * a' = a*pa + b*pb + * b' = a*qa + b*qb + * + * such that a' and b' are both multiple of 2^31, but are + * only marginally larger than a and b. + */ + pa = 1; + pb = 0; + qa = 0; + qb = 1; + for (i = 0; i < 31; i ++) { + /* + * At each iteration: + * + * a <- (a-b)/2 if: a is odd, b is odd, a_hi > b_hi + * b <- (b-a)/2 if: a is odd, b is odd, a_hi <= b_hi + * a <- a/2 if: a is even + * b <- b/2 if: a is odd, b is even + * + * We multiply a_lo and b_lo by 2 at each + * iteration, thus a division by 2 really is a + * non-multiplication by 2. + */ + uint32_t r, oa, ob, cAB, cBA, cA; + uint64_t rz; + + /* + * r = GT(a_hi, b_hi) + * But the GT() function works on uint32_t operands, + * so we inline a 64-bit version here. + */ + rz = b_hi - a_hi; + r = (uint32_t)((rz ^ ((a_hi ^ b_hi) + & (a_hi ^ rz))) >> 63); + + /* + * cAB = 1 if b must be subtracted from a + * cBA = 1 if a must be subtracted from b + * cA = 1 if a is divided by 2, 0 otherwise + * + * Rules: + * + * cAB and cBA cannot be both 1. + * if a is not divided by 2, b is. + */ + oa = (a_lo >> i) & 1; + ob = (b_lo >> i) & 1; + cAB = oa & ob & r; + cBA = oa & ob & NOT(r); + cA = cAB | NOT(oa); + + /* + * Conditional subtractions. + */ + a_lo -= b_lo & -cAB; + a_hi -= b_hi & -(uint64_t)cAB; + pa -= qa & -(int64_t)cAB; + pb -= qb & -(int64_t)cAB; + b_lo -= a_lo & -cBA; + b_hi -= a_hi & -(uint64_t)cBA; + qa -= pa & -(int64_t)cBA; + qb -= pb & -(int64_t)cBA; + + /* + * Shifting. + */ + a_lo += a_lo & (cA - 1); + pa += pa & ((int64_t)cA - 1); + pb += pb & ((int64_t)cA - 1); + a_hi ^= (a_hi ^ (a_hi >> 1)) & -(uint64_t)cA; + b_lo += b_lo & -cA; + qa += qa & -(int64_t)cA; + qb += qb & -(int64_t)cA; + b_hi ^= (b_hi ^ (b_hi >> 1)) & ((uint64_t)cA - 1); + } + + /* + * Replace a and b with new values a' and b'. + */ + r = co_reduce(a, b, len, pa, pb, qa, qb); + pa -= pa * ((r & 1) << 1); + pb -= pb * ((r & 1) << 1); + qa -= qa * (r & 2); + qb -= qb * (r & 2); + co_reduce_mod(u, v, len, pa, pb, qa, qb, m + 1, m0i); + } + + /* + * Now one of the arrays should be 0, and the other contains + * the GCD. If a is 0, then u is 0 as well, and v contains + * the division result. + * Result is correct if and only if GCD is 1. + */ + r = (a[0] | b[0]) ^ 1; + u[0] |= v[0]; + for (k = 1; k < len; k ++) { + r |= a[k] | b[k]; + u[k] |= v[k]; + } + return EQ0(r); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_modpow.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_modpow.c new file mode 100644 index 000000000..3963284a0 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_modpow.c @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +void +br_i31_modpow(uint32_t *x, + const unsigned char *e, size_t elen, + const uint32_t *m, uint32_t m0i, uint32_t *t1, uint32_t *t2) +{ + size_t mlen; + uint32_t k; + + /* + * 'mlen' is the length of m[] expressed in bytes (including + * the "bit length" first field). + */ + mlen = ((m[0] + 63) >> 5) * sizeof m[0]; + + /* + * Throughout the algorithm: + * -- t1[] is in Montgomery representation; it contains x, x^2, + * x^4, x^8... + * -- The result is accumulated, in normal representation, in + * the x[] array. + * -- t2[] is used as destination buffer for each multiplication. + * + * Note that there is no need to call br_i32_from_monty(). + */ + memcpy(t1, x, mlen); + br_i31_to_monty(t1, m); + br_i31_zero(x, m[0]); + x[1] = 1; + for (k = 0; k < ((uint32_t)elen << 3); k ++) { + uint32_t ctl; + + ctl = (e[elen - 1 - (k >> 3)] >> (k & 7)) & 1; + br_i31_montymul(t2, x, t1, m, m0i); + CCOPY(ctl, x, t2, mlen); + br_i31_montymul(t2, t1, t1, m, m0i); + memcpy(t1, t2, mlen); + } +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_modpow2.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_modpow2.c new file mode 100644 index 000000000..40a39bdea --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_modpow2.c @@ -0,0 +1,165 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +uint32_t +br_i31_modpow_opt(uint32_t *x, + const unsigned char *e, size_t elen, + const uint32_t *m, uint32_t m0i, uint32_t *tmp, size_t twlen) +{ + size_t mlen, mwlen; + uint32_t *t1, *t2, *base; + size_t u, v; + uint32_t acc; + int acc_len, win_len; + + /* + * Get modulus size. + */ + mwlen = (m[0] + 63) >> 5; + mlen = mwlen * sizeof m[0]; + mwlen += (mwlen & 1); + t1 = tmp; + t2 = tmp + mwlen; + + /* + * Compute possible window size, with a maximum of 5 bits. + * When the window has size 1 bit, we use a specific code + * that requires only two temporaries. Otherwise, for a + * window of k bits, we need 2^k+1 temporaries. + */ + if (twlen < (mwlen << 1)) { + return 0; + } + for (win_len = 5; win_len > 1; win_len --) { + if ((((uint32_t)1 << win_len) + 1) * mwlen <= twlen) { + break; + } + } + + /* + * Everything is done in Montgomery representation. + */ + br_i31_to_monty(x, m); + + /* + * Compute window contents. If the window has size one bit only, + * then t2 is set to x; otherwise, t2[0] is left untouched, and + * t2[k] is set to x^k (for k >= 1). + */ + if (win_len == 1) { + memcpy(t2, x, mlen); + } else { + memcpy(t2 + mwlen, x, mlen); + base = t2 + mwlen; + for (u = 2; u < ((unsigned)1 << win_len); u ++) { + br_i31_montymul(base + mwlen, base, x, m, m0i); + base += mwlen; + } + } + + /* + * We need to set x to 1, in Montgomery representation. This can + * be done efficiently by setting the high word to 1, then doing + * one word-sized shift. + */ + br_i31_zero(x, m[0]); + x[(m[0] + 31) >> 5] = 1; + br_i31_muladd_small(x, 0, m); + + /* + * We process bits from most to least significant. At each + * loop iteration, we have acc_len bits in acc. + */ + acc = 0; + acc_len = 0; + while (acc_len > 0 || elen > 0) { + int i, k; + uint32_t bits; + + /* + * Get the next bits. + */ + k = win_len; + if (acc_len < win_len) { + if (elen > 0) { + acc = (acc << 8) | *e ++; + elen --; + acc_len += 8; + } else { + k = acc_len; + } + } + bits = (acc >> (acc_len - k)) & (((uint32_t)1 << k) - 1); + acc_len -= k; + + /* + * We could get exactly k bits. Compute k squarings. + */ + for (i = 0; i < k; i ++) { + br_i31_montymul(t1, x, x, m, m0i); + memcpy(x, t1, mlen); + } + + /* + * Window lookup: we want to set t2 to the window + * lookup value, assuming the bits are non-zero. If + * the window length is 1 bit only, then t2 is + * already set; otherwise, we do a constant-time lookup. + */ + if (win_len > 1) { + br_i31_zero(t2, m[0]); + base = t2 + mwlen; + for (u = 1; u < ((uint32_t)1 << k); u ++) { + uint32_t mask; + + mask = -EQ(u, bits); + for (v = 1; v < mwlen; v ++) { + t2[v] |= mask & base[v]; + } + base += mwlen; + } + } + + /* + * Multiply with the looked-up value. We keep the + * product only if the exponent bits are not all-zero. + */ + br_i31_montymul(t1, x, t2, m, m0i); + CCOPY(NEQ(bits, 0), x, t1, mlen); + } + + /* + * Convert back from Montgomery representation, and exit. + */ + br_i31_from_monty(x, m, m0i); + return 1; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_montmul.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_montmul.c new file mode 100644 index 000000000..850a15700 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_montmul.c @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +void +br_i31_montymul(uint32_t *d, const uint32_t *x, const uint32_t *y, + const uint32_t *m, uint32_t m0i) +{ + /* + * Each outer loop iteration computes: + * d <- (d + xu*y + f*m) / 2^31 + * We have xu <= 2^31-1 and f <= 2^31-1. + * Thus, if d <= 2*m-1 on input, then: + * 2*m-1 + 2*(2^31-1)*m <= (2^32)*m-1 + * and the new d value is less than 2*m. + * + * We represent d over 31-bit words, with an extra word 'dh' + * which can thus be only 0 or 1. + */ + size_t len, len4, u, v; + uint32_t dh; + + len = (m[0] + 31) >> 5; + len4 = len & ~(size_t)3; + br_i31_zero(d, m[0]); + dh = 0; + for (u = 0; u < len; u ++) { + /* + * The carry for each operation fits on 32 bits: + * d[v+1] <= 2^31-1 + * xu*y[v+1] <= (2^31-1)*(2^31-1) + * f*m[v+1] <= (2^31-1)*(2^31-1) + * r <= 2^32-1 + * (2^31-1) + 2*(2^31-1)*(2^31-1) + (2^32-1) = 2^63 - 2^31 + * After division by 2^31, the new r is then at most 2^32-1 + * + * Using a 32-bit carry has performance benefits on 32-bit + * systems; however, on 64-bit architectures, we prefer to + * keep the carry (r) in a 64-bit register, thus avoiding some + * "clear high bits" operations. + */ + uint32_t f, xu; +#if BR_64 + uint64_t r; +#else + uint32_t r; +#endif + + xu = x[u + 1]; + f = MUL31_lo((d[1] + MUL31_lo(x[u + 1], y[1])), m0i); + + r = 0; + for (v = 0; v < len4; v += 4) { + uint64_t z; + + z = (uint64_t)d[v + 1] + MUL31(xu, y[v + 1]) + + MUL31(f, m[v + 1]) + r; + r = z >> 31; + d[v + 0] = (uint32_t)z & 0x7FFFFFFF; + z = (uint64_t)d[v + 2] + MUL31(xu, y[v + 2]) + + MUL31(f, m[v + 2]) + r; + r = z >> 31; + d[v + 1] = (uint32_t)z & 0x7FFFFFFF; + z = (uint64_t)d[v + 3] + MUL31(xu, y[v + 3]) + + MUL31(f, m[v + 3]) + r; + r = z >> 31; + d[v + 2] = (uint32_t)z & 0x7FFFFFFF; + z = (uint64_t)d[v + 4] + MUL31(xu, y[v + 4]) + + MUL31(f, m[v + 4]) + r; + r = z >> 31; + d[v + 3] = (uint32_t)z & 0x7FFFFFFF; + } + for (; v < len; v ++) { + uint64_t z; + + z = (uint64_t)d[v + 1] + MUL31(xu, y[v + 1]) + + MUL31(f, m[v + 1]) + r; + r = z >> 31; + d[v] = (uint32_t)z & 0x7FFFFFFF; + } + + /* + * Since the new dh can only be 0 or 1, the addition of + * the old dh with the carry MUST fit on 32 bits, and + * thus can be done into dh itself. + */ + dh += r; + d[len] = dh & 0x7FFFFFFF; + dh >>= 31; + } + + /* + * We must write back the bit length because it was overwritten in + * the loop (not overwriting it would require a test in the loop, + * which would yield bigger and slower code). + */ + d[0] = m[0]; + + /* + * d[] may still be greater than m[] at that point; notably, the + * 'dh' word may be non-zero. + */ + br_i31_sub(d, m, NEQ(dh, 0) | NOT(br_i31_sub(d, m, 0))); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_mulacc.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_mulacc.c new file mode 100644 index 000000000..a1d39d04c --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_mulacc.c @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +void +br_i31_mulacc(uint32_t *d, const uint32_t *a, const uint32_t *b) +{ + size_t alen, blen, u; + uint32_t dl, dh; + + alen = (a[0] + 31) >> 5; + blen = (b[0] + 31) >> 5; + + /* + * We want to add the two bit lengths, but these are encoded, + * which requires some extra care. + */ + dl = (a[0] & 31) + (b[0] & 31); + dh = (a[0] >> 5) + (b[0] >> 5); + d[0] = (dh << 5) + dl + (~(uint32_t)(dl - 31) >> 31); + + for (u = 0; u < blen; u ++) { + uint32_t f; + size_t v; + + /* + * Carry always fits on 31 bits; we want to keep it in a + * 32-bit register on 32-bit architectures (on a 64-bit + * architecture, cast down from 64 to 32 bits means + * clearing the high bits, which is not free; on a 32-bit + * architecture, the same operation really means ignoring + * the top register, which has negative or zero cost). + */ +#if BR_64 + uint64_t cc; +#else + uint32_t cc; +#endif + + f = b[1 + u]; + cc = 0; + for (v = 0; v < alen; v ++) { + uint64_t z; + + z = (uint64_t)d[1 + u + v] + MUL31(f, a[1 + v]) + cc; + cc = z >> 31; + d[1 + u + v] = (uint32_t)z & 0x7FFFFFFF; + } + d[1 + u + alen] = (uint32_t)cc; + } +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_muladd.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_muladd.c new file mode 100644 index 000000000..20034b321 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_muladd.c @@ -0,0 +1,162 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +void +br_i31_muladd_small(uint32_t *x, uint32_t z, const uint32_t *m) +{ + uint32_t m_bitlen; + unsigned mblr; + size_t u, mlen; + uint32_t a0, a1, b0, hi, g, q, tb; + uint32_t under, over; + uint32_t cc; + + /* + * We can test on the modulus bit length since we accept to + * leak that length. + */ + m_bitlen = m[0]; + if (m_bitlen == 0) { + return; + } + if (m_bitlen <= 31) { + uint32_t lo; + + hi = x[1] >> 1; + lo = (x[1] << 31) | z; + x[1] = br_rem(hi, lo, m[1]); + return; + } + mlen = (m_bitlen + 31) >> 5; + mblr = (unsigned)m_bitlen & 31; + + /* + * Principle: we estimate the quotient (x*2^31+z)/m by + * doing a 64/32 division with the high words. + * + * Let: + * w = 2^31 + * a = (w*a0 + a1) * w^N + a2 + * b = b0 * w^N + b2 + * such that: + * 0 <= a0 < w + * 0 <= a1 < w + * 0 <= a2 < w^N + * w/2 <= b0 < w + * 0 <= b2 < w^N + * a < w*b + * I.e. the two top words of a are a0:a1, the top word of b is + * b0, we ensured that b0 is "full" (high bit set), and a is + * such that the quotient q = a/b fits on one word (0 <= q < w). + * + * If a = b*q + r (with 0 <= r < q), we can estimate q by + * doing an Euclidean division on the top words: + * a0*w+a1 = b0*u + v (with 0 <= v < b0) + * Then the following holds: + * 0 <= u <= w + * u-2 <= q <= u + */ + hi = x[mlen]; + if (mblr == 0) { + a0 = x[mlen]; + memmove(x + 2, x + 1, (mlen - 1) * sizeof *x); + x[1] = z; + a1 = x[mlen]; + b0 = m[mlen]; + } else { + a0 = ((x[mlen] << (31 - mblr)) | (x[mlen - 1] >> mblr)) + & 0x7FFFFFFF; + memmove(x + 2, x + 1, (mlen - 1) * sizeof *x); + x[1] = z; + a1 = ((x[mlen] << (31 - mblr)) | (x[mlen - 1] >> mblr)) + & 0x7FFFFFFF; + b0 = ((m[mlen] << (31 - mblr)) | (m[mlen - 1] >> mblr)) + & 0x7FFFFFFF; + } + + /* + * We estimate a divisor q. If the quotient returned by br_div() + * is g: + * -- If a0 == b0 then g == 0; we want q = 0x7FFFFFFF. + * -- Otherwise: + * -- if g == 0 then we set q = 0; + * -- otherwise, we set q = g - 1. + * The properties described above then ensure that the true + * quotient is q-1, q or q+1. + * + * Take care that a0, a1 and b0 are 31-bit words, not 32-bit. We + * must adjust the parameters to br_div() accordingly. + */ + g = br_div(a0 >> 1, a1 | (a0 << 31), b0); + q = MUX(EQ(a0, b0), 0x7FFFFFFF, MUX(EQ(g, 0), 0, g - 1)); + + /* + * We subtract q*m from x (with the extra high word of value 'hi'). + * Since q may be off by 1 (in either direction), we may have to + * add or subtract m afterwards. + * + * The 'tb' flag will be true (1) at the end of the loop if the + * result is greater than or equal to the modulus (not counting + * 'hi' or the carry). + */ + cc = 0; + tb = 1; + for (u = 1; u <= mlen; u ++) { + uint32_t mw, zw, xw, nxw; + uint64_t zl; + + mw = m[u]; + zl = MUL31(mw, q) + cc; + cc = (uint32_t)(zl >> 31); + zw = (uint32_t)zl & (uint32_t)0x7FFFFFFF; + xw = x[u]; + nxw = xw - zw; + cc += nxw >> 31; + nxw &= 0x7FFFFFFF; + x[u] = nxw; + tb = MUX(EQ(nxw, mw), tb, GT(nxw, mw)); + } + + /* + * If we underestimated q, then either cc < hi (one extra bit + * beyond the top array word), or cc == hi and tb is true (no + * extra bit, but the result is not lower than the modulus). In + * these cases we must subtract m once. + * + * Otherwise, we may have overestimated, which will show as + * cc > hi (thus a negative result). Correction is adding m once. + */ + over = GT(cc, hi); + under = ~over & (tb | LT(cc, hi)); + br_i31_add(x, m, over); + br_i31_sub(x, m, under); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_ninv31.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_ninv31.c new file mode 100644 index 000000000..c155527d0 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_ninv31.c @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +uint32_t +br_i31_ninv31(uint32_t x) +{ + uint32_t y; + + y = 2 - x; + y *= 2 - y * x; + y *= 2 - y * x; + y *= 2 - y * x; + y *= 2 - y * x; + return MUX(x & 1, -y, 0) & 0x7FFFFFFF; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_reduce.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_reduce.c new file mode 100644 index 000000000..7c3c116cf --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_reduce.c @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +void +br_i31_reduce(uint32_t *x, const uint32_t *a, const uint32_t *m) +{ + uint32_t m_bitlen, a_bitlen; + size_t mlen, alen, u; + + m_bitlen = m[0]; + mlen = (m_bitlen + 31) >> 5; + + x[0] = m_bitlen; + if (m_bitlen == 0) { + return; + } + + /* + * If the source is shorter, then simply copy all words from a[] + * and zero out the upper words. + */ + a_bitlen = a[0]; + alen = (a_bitlen + 31) >> 5; + if (a_bitlen < m_bitlen) { + memcpy(x + 1, a + 1, alen * sizeof *a); + for (u = alen; u < mlen; u ++) { + x[u + 1] = 0; + } + return; + } + + /* + * The source length is at least equal to that of the modulus. + * We must thus copy N-1 words, and input the remaining words + * one by one. + */ + memcpy(x + 1, a + 2 + (alen - mlen), (mlen - 1) * sizeof *a); + x[mlen] = 0; + for (u = 1 + alen - mlen; u > 0; u --) { + br_i31_muladd_small(x, a[u], m); + } +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_rshift.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_rshift.c new file mode 100644 index 000000000..4837dbdb1 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_rshift.c @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +void +br_i31_rshift(uint32_t *x, int count) +{ + size_t u, len; + uint32_t r; + + len = (x[0] + 31) >> 5; + if (len == 0) { + return; + } + r = x[1] >> count; + for (u = 2; u <= len; u ++) { + uint32_t w; + + w = x[u]; + x[u - 1] = ((w << (31 - count)) | r) & 0x7FFFFFFF; + r = w >> count; + } + x[len] = r; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_sub.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_sub.c new file mode 100644 index 000000000..49381fe86 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_sub.c @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +uint32_t +br_i31_sub(uint32_t *a, const uint32_t *b, uint32_t ctl) +{ + uint32_t cc; + size_t u, m; + + cc = 0; + m = (a[0] + 63) >> 5; + for (u = 1; u < m; u ++) { + uint32_t aw, bw, naw; + + aw = a[u]; + bw = b[u]; + naw = aw - bw - cc; + cc = naw >> 31; + a[u] = MUX(ctl, naw & 0x7FFFFFFF, aw); + } + return cc; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_tmont.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_tmont.c new file mode 100644 index 000000000..e1db68660 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i31_tmont.c @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +void +br_i31_to_monty(uint32_t *x, const uint32_t *m) +{ + uint32_t k; + + for (k = (m[0] + 31) >> 5; k > 0; k --) { + br_i31_muladd_small(x, 0, m); + } +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i32_add.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i32_add.c new file mode 100644 index 000000000..667696161 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i32_add.c @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +uint32_t +br_i32_add(uint32_t *a, const uint32_t *b, uint32_t ctl) +{ + uint32_t cc; + size_t u, m; + + cc = 0; + m = (a[0] + 63) >> 5; + for (u = 1; u < m; u ++) { + uint32_t aw, bw, naw; + + aw = a[u]; + bw = b[u]; + naw = aw + bw + cc; + + /* + * Carry is 1 if naw < aw. Carry is also 1 if naw == aw + * AND the carry was already 1. + */ + cc = (cc & EQ(naw, aw)) | LT(naw, aw); + a[u] = MUX(ctl, naw, aw); + } + return cc; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i32_bitlen.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i32_bitlen.c new file mode 100644 index 000000000..3230dea82 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i32_bitlen.c @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +uint32_t +br_i32_bit_length(uint32_t *x, size_t xlen) +{ + uint32_t tw, twk; + + tw = 0; + twk = 0; + while (xlen -- > 0) { + uint32_t w, c; + + c = EQ(tw, 0); + w = x[xlen]; + tw = MUX(c, w, tw); + twk = MUX(c, (uint32_t)xlen, twk); + } + return (twk << 5) + BIT_LENGTH(tw); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i32_decmod.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i32_decmod.c new file mode 100644 index 000000000..7fe7d7ba2 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i32_decmod.c @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +uint32_t +br_i32_decode_mod(uint32_t *x, const void *src, size_t len, const uint32_t *m) +{ + const unsigned char *buf; + uint32_t r; + size_t u, v, mlen; + + buf = src; + + /* + * First pass: determine whether the value fits. The 'r' value + * will contain the comparison result, as 0x00000000 (value is + * equal to the modulus), 0x00000001 (value is greater than the + * modulus), or 0xFFFFFFFF (value is lower than the modulus). + */ + mlen = (m[0] + 7) >> 3; + r = 0; + for (u = (mlen > len) ? mlen : len; u > 0; u --) { + uint32_t mb, xb; + + v = u - 1; + if (v >= mlen) { + mb = 0; + } else { + mb = (m[1 + (v >> 2)] >> ((v & 3) << 3)) & 0xFF; + } + if (v >= len) { + xb = 0; + } else { + xb = buf[len - u]; + } + r = MUX(EQ(r, 0), (uint32_t)CMP(xb, mb), r); + } + + /* + * Only r == 0xFFFFFFFF is acceptable. We want to set r to 0xFF if + * the value fits, 0x00 otherwise. + */ + r >>= 24; + br_i32_zero(x, m[0]); + u = (mlen > len) ? len : mlen; + while (u > 0) { + uint32_t xb; + + xb = buf[len - u] & r; + u --; + x[1 + (u >> 2)] |= xb << ((u & 3) << 3); + } + return r >> 7; +} + +#endif diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i32_decode.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i32_decode.c new file mode 100644 index 000000000..f817231f5 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i32_decode.c @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +void +br_i32_decode(uint32_t *x, const void *src, size_t len) +{ + const unsigned char *buf; + size_t u, v; + + buf = src; + u = len; + v = 1; + for (;;) { + if (u < 4) { + uint32_t w; + + if (u < 2) { + if (u == 0) { + break; + } else { + w = buf[0]; + } + } else { + if (u == 2) { + w = br_dec16be(buf); + } else { + w = ((uint32_t)buf[0] << 16) + | br_dec16be(buf + 1); + } + } + x[v ++] = w; + break; + } else { + u -= 4; + x[v ++] = br_dec32be(buf + u); + } + } + x[0] = br_i32_bit_length(x + 1, v - 1); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i32_decred.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i32_decred.c new file mode 100644 index 000000000..affe6b5a7 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i32_decred.c @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +void +br_i32_decode_reduce(uint32_t *x, + const void *src, size_t len, const uint32_t *m) +{ + uint32_t m_bitlen; + size_t mblen, k, q; + const unsigned char *buf; + + m_bitlen = m[0]; + + /* + * Special case for an invalid modulus. + */ + if (m_bitlen == 0) { + x[0] = 0; + return; + } + + /* + * Clear the destination. + */ + br_i32_zero(x, m_bitlen); + + /* + * First decode directly as many bytes as possible without + * reduction, taking care to leave a number of bytes which + * is a multiple of 4. + */ + mblen = (m_bitlen + 7) >> 3; + k = mblen - 1; + + /* + * Up to k bytes can be safely decoded. + */ + if (k >= len) { + br_i32_decode(x, src, len); + x[0] = m_bitlen; + return; + } + + /* + * We want to first inject some bytes with direct decoding, + * then extra bytes by whole 32-bit words. First compute + * the size that should be injected that way. + */ + buf = src; + q = (len - k + 3) & ~(size_t)3; + + /* + * It may happen that this is more than what we already have + * (by at most 3 bytes). Such a case may happen only with + * a very short modulus. In that case, we must process the first + * bytes "manually". + */ + if (q > len) { + int i; + uint32_t w; + + w = 0; + for (i = 0; i < 4; i ++) { + w <<= 8; + if (q <= len) { + w |= buf[len - q]; + } + q --; + } + br_i32_muladd_small(x, w, m); + } else { + br_i32_decode(x, buf, len - q); + x[0] = m_bitlen; + } + + /* + * At that point, we have exactly q bytes to inject, and q is + * a multiple of 4. + */ + for (k = len - q; k < len; k += 4) { + br_i32_muladd_small(x, br_dec32be(buf + k), m); + } +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i32_div32.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i32_div32.c new file mode 100644 index 000000000..13d04d169 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i32_div32.c @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +uint32_t +br_divrem(uint32_t hi, uint32_t lo, uint32_t d, uint32_t *r) +{ + /* TODO: optimize this */ + uint32_t q; + uint32_t ch, cf; + int k; + + q = 0; + ch = EQ(hi, d); + hi = MUX(ch, 0, hi); + for (k = 31; k > 0; k --) { + int j; + uint32_t w, ctl, hi2, lo2; + + j = 32 - k; + w = (hi << j) | (lo >> k); + ctl = GE(w, d) | (hi >> k); + hi2 = (w - d) >> j; + lo2 = lo - (d << k); + hi = MUX(ctl, hi2, hi); + lo = MUX(ctl, lo2, lo); + q |= ctl << k; + } + cf = GE(lo, d) | hi; + q |= cf; + *r = MUX(cf, lo - d, lo); + return q; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i32_encode.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i32_encode.c new file mode 100644 index 000000000..58591518e --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i32_encode.c @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +void +br_i32_encode(void *dst, size_t len, const uint32_t *x) +{ + unsigned char *buf; + size_t k; + + buf = dst; + + /* + * Compute the announced size of x in bytes; extra bytes are + * filled with zeros. + */ + k = (x[0] + 7) >> 3; + while (len > k) { + *buf ++ = 0; + len --; + } + + /* + * Now we use k as index within x[]. That index starts at 1; + * we initialize it to the topmost complete word, and process + * any remaining incomplete word. + */ + k = (len + 3) >> 2; + switch (len & 3) { + case 3: + *buf ++ = x[k] >> 16; + /* fall through */ + case 2: + *buf ++ = x[k] >> 8; + /* fall through */ + case 1: + *buf ++ = x[k]; + k --; + } + + /* + * Encode all complete words. + */ + while (k > 0) { + br_enc32be(buf, x[k]); + k --; + buf += 4; + } +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i32_fmont.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i32_fmont.c new file mode 100644 index 000000000..77bc028bd --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i32_fmont.c @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +void +br_i32_from_monty(uint32_t *x, const uint32_t *m, uint32_t m0i) +{ + size_t len, u, v; + + len = (m[0] + 31) >> 5; + for (u = 0; u < len; u ++) { + uint32_t f; + uint64_t cc; + + f = x[1] * m0i; + cc = 0; + for (v = 0; v < len; v ++) { + uint64_t z; + + z = (uint64_t)x[v + 1] + MUL(f, m[v + 1]) + cc; + cc = z >> 32; + if (v != 0) { + x[v] = (uint32_t)z; + } + } + x[len] = (uint32_t)cc; + } + + /* + * We may have to do an extra subtraction, but only if the + * value in x[] is indeed greater than or equal to that of m[], + * which is why we must do two calls (first call computes the + * carry, second call performs the subtraction only if the carry + * is 0). + */ + br_i32_sub(x, m, NOT(br_i32_sub(x, m, 0))); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i32_iszero.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i32_iszero.c new file mode 100644 index 000000000..922853812 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i32_iszero.c @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +uint32_t +br_i32_iszero(const uint32_t *x) +{ + uint32_t z; + size_t u; + + z = 0; + for (u = (x[0] + 31) >> 5; u > 0; u --) { + z |= x[u]; + } + return ~(z | -z) >> 31; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i32_modpow.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i32_modpow.c new file mode 100644 index 000000000..8d8ca49f0 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i32_modpow.c @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +void +br_i32_modpow(uint32_t *x, + const unsigned char *e, size_t elen, + const uint32_t *m, uint32_t m0i, uint32_t *t1, uint32_t *t2) +{ + size_t mlen; + uint32_t k; + + /* + * 'mlen' is the length of m[] expressed in bytes (including + * the "bit length" first field). + */ + mlen = ((m[0] + 63) >> 5) * sizeof m[0]; + + /* + * Throughout the algorithm: + * -- t1[] is in Montgomery representation; it contains x, x^2, + * x^4, x^8... + * -- The result is accumulated, in normal representation, in + * the x[] array. + * -- t2[] is used as destination buffer for each multiplication. + * + * Note that there is no need to call br_i32_from_monty(). + */ + memcpy(t1, x, mlen); + br_i32_to_monty(t1, m); + br_i32_zero(x, m[0]); + x[1] = 1; + for (k = 0; k < ((uint32_t)elen << 3); k ++) { + uint32_t ctl; + + ctl = (e[elen - 1 - (k >> 3)] >> (k & 7)) & 1; + br_i32_montymul(t2, x, t1, m, m0i); + CCOPY(ctl, x, t2, mlen); + br_i32_montymul(t2, t1, t1, m, m0i); + memcpy(t1, t2, mlen); + } +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i32_montmul.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i32_montmul.c new file mode 100644 index 000000000..b48a11d47 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i32_montmul.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +void +br_i32_montymul(uint32_t *d, const uint32_t *x, const uint32_t *y, + const uint32_t *m, uint32_t m0i) +{ + size_t len, u, v; + uint64_t dh; + + len = (m[0] + 31) >> 5; + br_i32_zero(d, m[0]); + dh = 0; + for (u = 0; u < len; u ++) { + uint32_t f, xu; + uint64_t r1, r2, zh; + + xu = x[u + 1]; + f = (d[1] + x[u + 1] * y[1]) * m0i; + r1 = 0; + r2 = 0; + for (v = 0; v < len; v ++) { + uint64_t z; + uint32_t t; + + z = (uint64_t)d[v + 1] + MUL(xu, y[v + 1]) + r1; + r1 = z >> 32; + t = (uint32_t)z; + z = (uint64_t)t + MUL(f, m[v + 1]) + r2; + r2 = z >> 32; + if (v != 0) { + d[v] = (uint32_t)z; + } + } + zh = dh + r1 + r2; + d[len] = (uint32_t)zh; + dh = zh >> 32; + } + + /* + * d[] may still be greater than m[] at that point; notably, the + * 'dh' word may be non-zero. + */ + br_i32_sub(d, m, NEQ(dh, 0) | NOT(br_i32_sub(d, m, 0))); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i32_mulacc.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i32_mulacc.c new file mode 100644 index 000000000..701336a0d --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i32_mulacc.c @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +void +br_i32_mulacc(uint32_t *d, const uint32_t *a, const uint32_t *b) +{ + size_t alen, blen, u; + + alen = (a[0] + 31) >> 5; + blen = (b[0] + 31) >> 5; + d[0] = a[0] + b[0]; + for (u = 0; u < blen; u ++) { + uint32_t f; + size_t v; +#if BR_64 + uint64_t cc; +#else + uint32_t cc; +#endif + + f = b[1 + u]; + cc = 0; + for (v = 0; v < alen; v ++) { + uint64_t z; + + z = (uint64_t)d[1 + u + v] + MUL(f, a[1 + v]) + cc; + cc = z >> 32; + d[1 + u + v] = (uint32_t)z; + } + d[1 + u + alen] = (uint32_t)cc; + } +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i32_muladd.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i32_muladd.c new file mode 100644 index 000000000..ee8c69472 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i32_muladd.c @@ -0,0 +1,143 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +void +br_i32_muladd_small(uint32_t *x, uint32_t z, const uint32_t *m) +{ + uint32_t m_bitlen; + size_t u, mlen; + uint32_t a0, a1, b0, hi, g, q, tb; + uint32_t chf, clow, under, over; + uint64_t cc; + + /* + * We can test on the modulus bit length since we accept to + * leak that length. + */ + m_bitlen = m[0]; + if (m_bitlen == 0) { + return; + } + if (m_bitlen <= 32) { + x[1] = br_rem(x[1], z, m[1]); + return; + } + mlen = (m_bitlen + 31) >> 5; + + /* + * Principle: we estimate the quotient (x*2^32+z)/m by + * doing a 64/32 division with the high words. + * + * Let: + * w = 2^32 + * a = (w*a0 + a1) * w^N + a2 + * b = b0 * w^N + b2 + * such that: + * 0 <= a0 < w + * 0 <= a1 < w + * 0 <= a2 < w^N + * w/2 <= b0 < w + * 0 <= b2 < w^N + * a < w*b + * I.e. the two top words of a are a0:a1, the top word of b is + * b0, we ensured that b0 is "full" (high bit set), and a is + * such that the quotient q = a/b fits on one word (0 <= q < w). + * + * If a = b*q + r (with 0 <= r < q), we can estimate q by + * doing an Euclidean division on the top words: + * a0*w+a1 = b0*u + v (with 0 <= v < w) + * Then the following holds: + * 0 <= u <= w + * u-2 <= q <= u + */ + a0 = br_i32_word(x, m_bitlen - 32); + hi = x[mlen]; + memmove(x + 2, x + 1, (mlen - 1) * sizeof *x); + x[1] = z; + a1 = br_i32_word(x, m_bitlen - 32); + b0 = br_i32_word(m, m_bitlen - 32); + + /* + * We estimate a divisor q. If the quotient returned by br_div() + * is g: + * -- If a0 == b0 then g == 0; we want q = 0xFFFFFFFF. + * -- Otherwise: + * -- if g == 0 then we set q = 0; + * -- otherwise, we set q = g - 1. + * The properties described above then ensure that the true + * quotient is q-1, q or q+1. + */ + g = br_div(a0, a1, b0); + q = MUX(EQ(a0, b0), 0xFFFFFFFF, MUX(EQ(g, 0), 0, g - 1)); + + /* + * We subtract q*m from x (with the extra high word of value 'hi'). + * Since q may be off by 1 (in either direction), we may have to + * add or subtract m afterwards. + * + * The 'tb' flag will be true (1) at the end of the loop if the + * result is greater than or equal to the modulus (not counting + * 'hi' or the carry). + */ + cc = 0; + tb = 1; + for (u = 1; u <= mlen; u ++) { + uint32_t mw, zw, xw, nxw; + uint64_t zl; + + mw = m[u]; + zl = MUL(mw, q) + cc; + cc = (uint32_t)(zl >> 32); + zw = (uint32_t)zl; + xw = x[u]; + nxw = xw - zw; + cc += (uint64_t)GT(nxw, xw); + x[u] = nxw; + tb = MUX(EQ(nxw, mw), tb, GT(nxw, mw)); + } + + /* + * If we underestimated q, then either cc < hi (one extra bit + * beyond the top array word), or cc == hi and tb is true (no + * extra bit, but the result is not lower than the modulus). In + * these cases we must subtract m once. + * + * Otherwise, we may have overestimated, which will show as + * cc > hi (thus a negative result). Correction is adding m once. + */ + chf = (uint32_t)(cc >> 32); + clow = (uint32_t)cc; + over = chf | GT(clow, hi); + under = ~over & (tb | (~chf & LT(clow, hi))); + br_i32_add(x, m, over); + br_i32_sub(x, m, under); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i32_ninv32.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i32_ninv32.c new file mode 100644 index 000000000..6c7c3fb45 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i32_ninv32.c @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +uint32_t +br_i32_ninv32(uint32_t x) +{ + uint32_t y; + + y = 2 - x; + y *= 2 - y * x; + y *= 2 - y * x; + y *= 2 - y * x; + y *= 2 - y * x; + return MUX(x & 1, -y, 0); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i32_reduce.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i32_reduce.c new file mode 100644 index 000000000..7d62bfaa1 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i32_reduce.c @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +void +br_i32_reduce(uint32_t *x, const uint32_t *a, const uint32_t *m) +{ + uint32_t m_bitlen, a_bitlen; + size_t mlen, alen, u; + + m_bitlen = m[0]; + mlen = (m_bitlen + 31) >> 5; + + x[0] = m_bitlen; + if (m_bitlen == 0) { + return; + } + + /* + * If the source is shorter, then simply copy all words from a[] + * and zero out the upper words. + */ + a_bitlen = a[0]; + alen = (a_bitlen + 31) >> 5; + if (a_bitlen < m_bitlen) { + memcpy(x + 1, a + 1, alen * sizeof *a); + for (u = alen; u < mlen; u ++) { + x[u + 1] = 0; + } + return; + } + + /* + * The source length is at least equal to that of the modulus. + * We must thus copy N-1 words, and input the remaining words + * one by one. + */ + memcpy(x + 1, a + 2 + (alen - mlen), (mlen - 1) * sizeof *a); + x[mlen] = 0; + for (u = 1 + alen - mlen; u > 0; u --) { + br_i32_muladd_small(x, a[u], m); + } +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i32_sub.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i32_sub.c new file mode 100644 index 000000000..e9c49c963 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i32_sub.c @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +uint32_t +br_i32_sub(uint32_t *a, const uint32_t *b, uint32_t ctl) +{ + uint32_t cc; + size_t u, m; + + cc = 0; + m = (a[0] + 63) >> 5; + for (u = 1; u < m; u ++) { + uint32_t aw, bw, naw; + + aw = a[u]; + bw = b[u]; + naw = aw - bw - cc; + + /* + * Carry is 1 if naw > aw. Carry is 1 also if naw == aw + * AND the carry was already 1. + */ + cc = (cc & EQ(naw, aw)) | GT(naw, aw); + a[u] = MUX(ctl, naw, aw); + } + return cc; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i32_tmont.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i32_tmont.c new file mode 100644 index 000000000..5c4718ce0 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i32_tmont.c @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +void +br_i32_to_monty(uint32_t *x, const uint32_t *m) +{ + uint32_t k; + + for (k = (m[0] + 31) >> 5; k > 0; k --) { + br_i32_muladd_small(x, 0, m); + } +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i62_modpow2.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i62_modpow2.c new file mode 100644 index 000000000..f79620075 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/i62_modpow2.c @@ -0,0 +1,498 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +#if BR_INT128 || BR_UMUL128 + +#if BR_INT128 + +/* + * Compute x*y+v1+v2. Operands are 64-bit, and result is 128-bit, with + * high word in "hi" and low word in "lo". + */ +#define FMA1(hi, lo, x, y, v1, v2) do { \ + unsigned __int128 fmaz; \ + fmaz = (unsigned __int128)(x) * (unsigned __int128)(y) \ + + (unsigned __int128)(v1) + (unsigned __int128)(v2); \ + (hi) = (uint64_t)(fmaz >> 64); \ + (lo) = (uint64_t)fmaz; \ + } while (0) + +/* + * Compute x1*y1+x2*y2+v1+v2. Operands are 64-bit, and result is 128-bit, + * with high word in "hi" and low word in "lo". + * + * Callers should ensure that the two inner products, and the v1 and v2 + * operands, are multiple of 4 (this is not used by this specific definition + * but may help other implementations). + */ +#define FMA2(hi, lo, x1, y1, x2, y2, v1, v2) do { \ + unsigned __int128 fmaz; \ + fmaz = (unsigned __int128)(x1) * (unsigned __int128)(y1) \ + + (unsigned __int128)(x2) * (unsigned __int128)(y2) \ + + (unsigned __int128)(v1) + (unsigned __int128)(v2); \ + (hi) = (uint64_t)(fmaz >> 64); \ + (lo) = (uint64_t)fmaz; \ + } while (0) + +#elif BR_UMUL128 + +#include + +#define FMA1(hi, lo, x, y, v1, v2) do { \ + uint64_t fmahi, fmalo; \ + unsigned char fmacc; \ + fmalo = _umul128((x), (y), &fmahi); \ + fmacc = _addcarry_u64(0, fmalo, (v1), &fmalo); \ + _addcarry_u64(fmacc, fmahi, 0, &fmahi); \ + fmacc = _addcarry_u64(0, fmalo, (v2), &(lo)); \ + _addcarry_u64(fmacc, fmahi, 0, &(hi)); \ + } while (0) + +/* + * Normally we should use _addcarry_u64() for FMA2 too, but it makes + * Visual Studio crash. Instead we use this version, which leverages + * the fact that the vx operands, and the products, are multiple of 4. + * This is unfortunately slower. + */ +#define FMA2(hi, lo, x1, y1, x2, y2, v1, v2) do { \ + uint64_t fma1hi, fma1lo; \ + uint64_t fma2hi, fma2lo; \ + uint64_t fmatt; \ + fma1lo = _umul128((x1), (y1), &fma1hi); \ + fma2lo = _umul128((x2), (y2), &fma2hi); \ + fmatt = (fma1lo >> 2) + (fma2lo >> 2) \ + + ((v1) >> 2) + ((v2) >> 2); \ + (lo) = fmatt << 2; \ + (hi) = fma1hi + fma2hi + (fmatt >> 62); \ + } while (0) + +/* + * The FMA2 macro definition we would prefer to use, but it triggers + * an internal compiler error in Visual Studio 2015. + * +#define FMA2(hi, lo, x1, y1, x2, y2, v1, v2) do { \ + uint64_t fma1hi, fma1lo; \ + uint64_t fma2hi, fma2lo; \ + unsigned char fmacc; \ + fma1lo = _umul128((x1), (y1), &fma1hi); \ + fma2lo = _umul128((x2), (y2), &fma2hi); \ + fmacc = _addcarry_u64(0, fma1lo, (v1), &fma1lo); \ + _addcarry_u64(fmacc, fma1hi, 0, &fma1hi); \ + fmacc = _addcarry_u64(0, fma2lo, (v2), &fma2lo); \ + _addcarry_u64(fmacc, fma2hi, 0, &fma2hi); \ + fmacc = _addcarry_u64(0, fma1lo, fma2lo, &(lo)); \ + _addcarry_u64(fmacc, fma1hi, fma2hi, &(hi)); \ + } while (0) + */ + +#endif + +#define MASK62 ((uint64_t)0x3FFFFFFFFFFFFFFF) +#define MUL62_lo(x, y) (((uint64_t)(x) * (uint64_t)(y)) & MASK62) + +/* + * Subtract b from a, and return the final carry. If 'ctl32' is 0, then + * a[] is kept unmodified, but the final carry is still computed and + * returned. + */ +static uint32_t +i62_sub(uint64_t *a, const uint64_t *b, size_t num, uint32_t ctl32) +{ + uint64_t cc, mask; + size_t u; + + cc = 0; + ctl32 = -ctl32; + mask = (uint64_t)ctl32 | ((uint64_t)ctl32 << 32); + for (u = 0; u < num; u ++) { + uint64_t aw, bw, dw; + + aw = a[u]; + bw = b[u]; + dw = aw - bw - cc; + cc = dw >> 63; + dw &= MASK62; + a[u] = aw ^ (mask & (dw ^ aw)); + } + return (uint32_t)cc; +} + +/* + * Montgomery multiplication, over arrays of 62-bit values. The + * destination array (d) must be distinct from the other operands + * (x, y and m). All arrays are in little-endian format (least + * significant word comes first) over 'num' words. + */ +static void +montymul(uint64_t *d, const uint64_t *x, const uint64_t *y, + const uint64_t *m, size_t num, uint64_t m0i) +{ + uint64_t dh; + size_t u, num4; + + num4 = 1 + ((num - 1) & ~(size_t)3); + memset(d, 0, num * sizeof *d); + dh = 0; + for (u = 0; u < num; u ++) { + size_t v; + uint64_t f, xu; + uint64_t r, zh; + uint64_t hi, lo; + + xu = x[u] << 2; + f = MUL62_lo(d[0] + MUL62_lo(x[u], y[0]), m0i) << 2; + + FMA2(hi, lo, xu, y[0], f, m[0], d[0] << 2, 0); + r = hi; + + for (v = 1; v < num4; v += 4) { + FMA2(hi, lo, xu, y[v + 0], + f, m[v + 0], d[v + 0] << 2, r << 2); + r = hi + (r >> 62); + d[v - 1] = lo >> 2; + FMA2(hi, lo, xu, y[v + 1], + f, m[v + 1], d[v + 1] << 2, r << 2); + r = hi + (r >> 62); + d[v + 0] = lo >> 2; + FMA2(hi, lo, xu, y[v + 2], + f, m[v + 2], d[v + 2] << 2, r << 2); + r = hi + (r >> 62); + d[v + 1] = lo >> 2; + FMA2(hi, lo, xu, y[v + 3], + f, m[v + 3], d[v + 3] << 2, r << 2); + r = hi + (r >> 62); + d[v + 2] = lo >> 2; + } + for (; v < num; v ++) { + FMA2(hi, lo, xu, y[v], f, m[v], d[v] << 2, r << 2); + r = hi + (r >> 62); + d[v - 1] = lo >> 2; + } + + zh = dh + r; + d[num - 1] = zh & MASK62; + dh = zh >> 62; + } + i62_sub(d, m, num, (uint32_t)dh | NOT(i62_sub(d, m, num, 0))); +} + +/* + * Conversion back from Montgomery representation. + */ +static void +frommonty(uint64_t *x, const uint64_t *m, size_t num, uint64_t m0i) +{ + size_t u, v; + + for (u = 0; u < num; u ++) { + uint64_t f, cc; + + f = MUL62_lo(x[0], m0i) << 2; + cc = 0; + for (v = 0; v < num; v ++) { + uint64_t hi, lo; + + FMA1(hi, lo, f, m[v], x[v] << 2, cc); + cc = hi << 2; + if (v != 0) { + x[v - 1] = lo >> 2; + } + } + x[num - 1] = cc >> 2; + } + i62_sub(x, m, num, NOT(i62_sub(x, m, num, 0))); +} + +/* see inner.h */ +uint32_t +br_i62_modpow_opt(uint32_t *x31, const unsigned char *e, size_t elen, + const uint32_t *m31, uint32_t m0i31, uint64_t *tmp, size_t twlen) +{ + size_t u, mw31num, mw62num; + uint64_t *x, *m, *t1, *t2; + uint64_t m0i; + uint32_t acc; + int win_len, acc_len; + + /* + * Get modulus size, in words. + */ + mw31num = (m31[0] + 31) >> 5; + mw62num = (mw31num + 1) >> 1; + + /* + * In order to apply this function, we must have enough room to + * copy the operand and modulus into the temporary array, along + * with at least two temporaries. If there is not enough room, + * switch to br_i31_modpow(). We also use br_i31_modpow() if the + * modulus length is not at least four words (94 bits or more). + */ + if (mw31num < 4 || (mw62num << 2) > twlen) { + /* + * We assume here that we can split an aligned uint64_t + * into two properly aligned uint32_t. Since both types + * are supposed to have an exact width with no padding, + * then this property must hold. + */ + size_t txlen; + + txlen = mw31num + 1; + if (twlen < txlen) { + return 0; + } + br_i31_modpow(x31, e, elen, m31, m0i31, + (uint32_t *)tmp, (uint32_t *)tmp + txlen); + return 1; + } + + /* + * Convert x to Montgomery representation: this means that + * we replace x with x*2^z mod m, where z is the smallest multiple + * of the word size such that 2^z >= m. We want to reuse the 31-bit + * functions here (for constant-time operation), but we need z + * for a 62-bit word size. + */ + for (u = 0; u < mw62num; u ++) { + br_i31_muladd_small(x31, 0, m31); + br_i31_muladd_small(x31, 0, m31); + } + + /* + * Assemble operands into arrays of 62-bit words. Note that + * all the arrays of 62-bit words that we will handle here + * are without any leading size word. + * + * We also adjust tmp and twlen to account for the words used + * for these extra arrays. + */ + m = tmp; + x = tmp + mw62num; + tmp += (mw62num << 1); + twlen -= (mw62num << 1); + for (u = 0; u < mw31num; u += 2) { + size_t v; + + v = u >> 1; + if ((u + 1) == mw31num) { + m[v] = (uint64_t)m31[u + 1]; + x[v] = (uint64_t)x31[u + 1]; + } else { + m[v] = (uint64_t)m31[u + 1] + + ((uint64_t)m31[u + 2] << 31); + x[v] = (uint64_t)x31[u + 1] + + ((uint64_t)x31[u + 2] << 31); + } + } + + /* + * Compute window size. We support windows up to 5 bits; for a + * window of size k bits, we need 2^k+1 temporaries (for k = 1, + * we use special code that uses only 2 temporaries). + */ + for (win_len = 5; win_len > 1; win_len --) { + if ((((uint32_t)1 << win_len) + 1) * mw62num <= twlen) { + break; + } + } + + t1 = tmp; + t2 = tmp + mw62num; + + /* + * Compute m0i, which is equal to -(1/m0) mod 2^62. We were + * provided with m0i31, which already fulfills this property + * modulo 2^31; the single expression below is then sufficient. + */ + m0i = (uint64_t)m0i31; + m0i = MUL62_lo(m0i, (uint64_t)2 + MUL62_lo(m0i, m[0])); + + /* + * Compute window contents. If the window has size one bit only, + * then t2 is set to x; otherwise, t2[0] is left untouched, and + * t2[k] is set to x^k (for k >= 1). + */ + if (win_len == 1) { + memcpy(t2, x, mw62num * sizeof *x); + } else { + uint64_t *base; + + memcpy(t2 + mw62num, x, mw62num * sizeof *x); + base = t2 + mw62num; + for (u = 2; u < ((unsigned)1 << win_len); u ++) { + montymul(base + mw62num, base, x, m, mw62num, m0i); + base += mw62num; + } + } + + /* + * Set x to 1, in Montgomery representation. We again use the + * 31-bit code. + */ + br_i31_zero(x31, m31[0]); + x31[(m31[0] + 31) >> 5] = 1; + br_i31_muladd_small(x31, 0, m31); + if (mw31num & 1) { + br_i31_muladd_small(x31, 0, m31); + } + for (u = 0; u < mw31num; u += 2) { + size_t v; + + v = u >> 1; + if ((u + 1) == mw31num) { + x[v] = (uint64_t)x31[u + 1]; + } else { + x[v] = (uint64_t)x31[u + 1] + + ((uint64_t)x31[u + 2] << 31); + } + } + + /* + * We process bits from most to least significant. At each + * loop iteration, we have acc_len bits in acc. + */ + acc = 0; + acc_len = 0; + while (acc_len > 0 || elen > 0) { + int i, k; + uint32_t bits; + uint64_t mask1, mask2; + + /* + * Get the next bits. + */ + k = win_len; + if (acc_len < win_len) { + if (elen > 0) { + acc = (acc << 8) | *e ++; + elen --; + acc_len += 8; + } else { + k = acc_len; + } + } + bits = (acc >> (acc_len - k)) & (((uint32_t)1 << k) - 1); + acc_len -= k; + + /* + * We could get exactly k bits. Compute k squarings. + */ + for (i = 0; i < k; i ++) { + montymul(t1, x, x, m, mw62num, m0i); + memcpy(x, t1, mw62num * sizeof *x); + } + + /* + * Window lookup: we want to set t2 to the window + * lookup value, assuming the bits are non-zero. If + * the window length is 1 bit only, then t2 is + * already set; otherwise, we do a constant-time lookup. + */ + if (win_len > 1) { + uint64_t *base; + + memset(t2, 0, mw62num * sizeof *t2); + base = t2 + mw62num; + for (u = 1; u < ((uint32_t)1 << k); u ++) { + uint64_t mask; + size_t v; + + mask = -(uint64_t)EQ(u, bits); + for (v = 0; v < mw62num; v ++) { + t2[v] |= mask & base[v]; + } + base += mw62num; + } + } + + /* + * Multiply with the looked-up value. We keep the product + * only if the exponent bits are not all-zero. + */ + montymul(t1, x, t2, m, mw62num, m0i); + mask1 = -(uint64_t)EQ(bits, 0); + mask2 = ~mask1; + for (u = 0; u < mw62num; u ++) { + x[u] = (mask1 & x[u]) | (mask2 & t1[u]); + } + } + + /* + * Convert back from Montgomery representation. + */ + frommonty(x, m, mw62num, m0i); + + /* + * Convert result into 31-bit words. + */ + for (u = 0; u < mw31num; u += 2) { + uint64_t zw; + + zw = x[u >> 1]; + x31[u + 1] = (uint32_t)zw & 0x7FFFFFFF; + if ((u + 1) < mw31num) { + x31[u + 2] = (uint32_t)(zw >> 31); + } + } + return 1; +} + +#else + +/* see inner.h */ +uint32_t +br_i62_modpow_opt(uint32_t *x31, const unsigned char *e, size_t elen, + const uint32_t *m31, uint32_t m0i31, uint64_t *tmp, size_t twlen) +{ + size_t mwlen; + + mwlen = (m31[0] + 63) >> 5; + if (twlen < mwlen) { + return 0; + } + return br_i31_modpow_opt(x31, e, elen, m31, m0i31, + (uint32_t *)tmp, twlen << 1); +} + +#endif + +/* see inner.h */ +uint32_t +br_i62_modpow_opt_as_i31(uint32_t *x31, const unsigned char *e, size_t elen, + const uint32_t *m31, uint32_t m0i31, uint32_t *tmp, size_t twlen) +{ + /* + * As documented, this function expects the 'tmp' argument to be + * 64-bit aligned. This is OK since this function is internal (it + * is not part of BearSSL's public API). + */ + return br_i62_modpow_opt(x31, e, elen, m31, m0i31, + (uint64_t *)tmp, twlen >> 1); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/inner.h b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/inner.h new file mode 100644 index 000000000..1c4b4f3c5 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/inner.h @@ -0,0 +1,2583 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#ifndef INNER_H__ +#define INNER_H__ + +#include +#include + +#include "config.h" +#include "bearssl.h" + +/* + * On MSVC, disable the warning about applying unary minus on an + * unsigned type: it is standard, we do it all the time, and for + * good reasons. + */ +#if _MSC_VER +#pragma warning( disable : 4146 ) +#endif + +/* + * Maximum size for a RSA modulus (in bits). Allocated stack buffers + * depend on that size, so this value should be kept small. Currently, + * 2048-bit RSA keys offer adequate security, and should still do so for + * the next few decades; however, a number of widespread PKI have + * already set their root keys to RSA-4096, so we should be able to + * process such keys. + * + * This value MUST be a multiple of 64. This value MUST NOT exceed 47666 + * (some computations in RSA key generation rely on the factor size being + * no more than 23833 bits). RSA key sizes beyond 3072 bits don't make a + * lot of sense anyway. + */ +#define BR_MAX_RSA_SIZE 4096 + +/* + * Minimum size for a RSA modulus (in bits); this value is used only to + * filter out invalid parameters for key pair generation. Normally, + * applications should not use RSA keys smaller than 2048 bits; but some + * specific cases might need shorter keys, for legacy or research + * purposes. + */ +#define BR_MIN_RSA_SIZE 512 + +/* + * Maximum size for a RSA factor (in bits). This is for RSA private-key + * operations. Default is to support factors up to a bit more than half + * the maximum modulus size. + * + * This value MUST be a multiple of 32. + */ +#define BR_MAX_RSA_FACTOR ((BR_MAX_RSA_SIZE + 64) >> 1) + +/* + * Maximum size for an EC curve (modulus or order), in bits. Size of + * stack buffers depends on that parameter. This size MUST be a multiple + * of 8 (so that decoding an integer with that many bytes does not + * overflow). + */ +#define BR_MAX_EC_SIZE 528 + +/* + * Some macros to recognize the current architecture. Right now, we are + * interested into automatically recognizing architecture with efficient + * 64-bit types so that we may automatically use implementations that + * use 64-bit registers in that case. Future versions may detect, e.g., + * availability of SSE2 intrinsics. + * + * If 'unsigned long' is a 64-bit type, then we assume that 64-bit types + * are efficient. Otherwise, we rely on macros that depend on compiler, + * OS and architecture. In any case, failure to detect the architecture + * as 64-bit means that the 32-bit code will be used, and that code + * works also on 64-bit architectures (the 64-bit code may simply be + * more efficient). + * + * The test on 'unsigned long' should already catch most cases, the one + * notable exception being Windows code where 'unsigned long' is kept to + * 32-bit for compatibility with all the legacy code that liberally uses + * the 'DWORD' type for 32-bit values. + * + * Macro names are taken from: http://nadeausoftware.com/articles/2012/02/c_c_tip_how_detect_processor_type_using_compiler_predefined_macros + */ +#ifndef BR_64 +#if ((ULONG_MAX >> 31) >> 31) == 3 +#define BR_64 1 +#elif defined(__ia64) || defined(__itanium__) || defined(_M_IA64) +#define BR_64 1 +#elif defined(__powerpc64__) || defined(__ppc64__) || defined(__PPC64__) \ + || defined(__64BIT__) || defined(_LP64) || defined(__LP64__) +#define BR_64 1 +#elif defined(__sparc64__) +#define BR_64 1 +#elif defined(__x86_64__) || defined(_M_X64) +#define BR_64 1 +#elif defined(__aarch64__) || defined(_M_ARM64) +#define BR_64 1 +#elif defined(__mips64) +#define BR_64 1 +#endif +#endif + +/* + * Set BR_LOMUL on platforms where it makes sense. + */ +#ifndef BR_LOMUL +#if BR_ARMEL_CORTEXM_GCC +#define BR_LOMUL 1 +#endif +#endif + +/* + * Architecture detection. + */ +#ifndef BR_i386 +#if __i386__ || _M_IX86 +#define BR_i386 1 +#endif +#endif + +#ifndef BR_amd64 +#if __x86_64__ || _M_X64 +#define BR_amd64 1 +#endif +#endif + +/* + * Compiler brand and version. + * + * Implementations that use intrinsics need to detect the compiler type + * and version because some specific actions may be needed to activate + * the corresponding opcodes, both for header inclusion, and when using + * them in a function. + * + * BR_GCC, BR_CLANG and BR_MSC will be set to 1 for, respectively, GCC, + * Clang and MS Visual C. For each of them, sub-macros will be defined + * for versions; each sub-macro is set whenever the compiler version is + * at least as recent as the one corresponding to the macro. + */ + +/* + * GCC thresholds are on versions 4.4 to 4.9 and 5.0. + */ +#ifndef BR_GCC +#if __GNUC__ && !__clang__ +#define BR_GCC 1 + +#if __GNUC__ > 4 +#define BR_GCC_5_0 1 +#elif __GNUC__ == 4 && __GNUC_MINOR__ >= 9 +#define BR_GCC_4_9 1 +#elif __GNUC__ == 4 && __GNUC_MINOR__ >= 8 +#define BR_GCC_4_8 1 +#elif __GNUC__ == 4 && __GNUC_MINOR__ >= 7 +#define BR_GCC_4_7 1 +#elif __GNUC__ == 4 && __GNUC_MINOR__ >= 6 +#define BR_GCC_4_6 1 +#elif __GNUC__ == 4 && __GNUC_MINOR__ >= 5 +#define BR_GCC_4_5 1 +#elif __GNUC__ == 4 && __GNUC_MINOR__ >= 4 +#define BR_GCC_4_4 1 +#endif + +#if BR_GCC_5_0 +#define BR_GCC_4_9 1 +#endif +#if BR_GCC_4_9 +#define BR_GCC_4_8 1 +#endif +#if BR_GCC_4_8 +#define BR_GCC_4_7 1 +#endif +#if BR_GCC_4_7 +#define BR_GCC_4_6 1 +#endif +#if BR_GCC_4_6 +#define BR_GCC_4_5 1 +#endif +#if BR_GCC_4_5 +#define BR_GCC_4_4 1 +#endif + +#endif +#endif + +/* + * Clang thresholds are on versions 3.7.0 and 3.8.0. + */ +#ifndef BR_CLANG +#if __clang__ +#define BR_CLANG 1 + +#if __clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 8) +#define BR_CLANG_3_8 1 +#elif __clang_major__ == 3 && __clang_minor__ >= 7 +#define BR_CLANG_3_7 1 +#endif + +#if BR_CLANG_3_8 +#define BR_CLANG_3_7 1 +#endif + +#endif +#endif + +/* + * MS Visual C thresholds are on Visual Studio 2005 to 2015. + */ +#ifndef BR_MSC +#if _MSC_VER +#define BR_MSC 1 + +#if _MSC_VER >= 1900 +#define BR_MSC_2015 1 +#elif _MSC_VER >= 1800 +#define BR_MSC_2013 1 +#elif _MSC_VER >= 1700 +#define BR_MSC_2012 1 +#elif _MSC_VER >= 1600 +#define BR_MSC_2010 1 +#elif _MSC_VER >= 1500 +#define BR_MSC_2008 1 +#elif _MSC_VER >= 1400 +#define BR_MSC_2005 1 +#endif + +#if BR_MSC_2015 +#define BR_MSC_2013 1 +#endif +#if BR_MSC_2013 +#define BR_MSC_2012 1 +#endif +#if BR_MSC_2012 +#define BR_MSC_2010 1 +#endif +#if BR_MSC_2010 +#define BR_MSC_2008 1 +#endif +#if BR_MSC_2008 +#define BR_MSC_2005 1 +#endif + +#endif +#endif + +/* + * GCC 4.4+ and Clang 3.7+ allow tagging specific functions with a + * 'target' attribute that activates support for specific opcodes. + */ +#if BR_GCC_4_4 || BR_CLANG_3_7 +#define BR_TARGET(x) __attribute__((target(x))) +#else +#define BR_TARGET(x) +#endif + +/* + * AES-NI intrinsics are available on x86 (32-bit and 64-bit) with + * GCC 4.8+, Clang 3.7+ and MSC 2012+. + */ +#ifndef BR_AES_X86NI +#if (BR_i386 || BR_amd64) && (BR_GCC_4_8 || BR_CLANG_3_7 || BR_MSC_2012) +#define BR_AES_X86NI 1 +#endif +#endif + +/* + * SSE2 intrinsics are available on x86 (32-bit and 64-bit) with + * GCC 4.4+, Clang 3.7+ and MSC 2005+. + */ +#ifndef BR_SSE2 +#if (BR_i386 || BR_amd64) && (BR_GCC_4_4 || BR_CLANG_3_7 || BR_MSC_2005) +#define BR_SSE2 1 +#endif +#endif + +/* + * RDRAND intrinsics are available on x86 (32-bit and 64-bit) with + * GCC 4.6+, Clang 3.7+ and MSC 2012+. + */ +#ifndef BR_RDRAND +#if (BR_i386 || BR_amd64) && (BR_GCC_4_6 || BR_CLANG_3_7 || BR_MSC_2012) +#define BR_RDRAND 1 +#endif +#endif + +/* + * Determine type of OS for random number generation. Macro names and + * values are documented on: + * https://sourceforge.net/p/predef/wiki/OperatingSystems/ + * + * Win32's CryptGenRandom() should be available on Windows systems. + * + * /dev/urandom should work on all Unix-like systems (including macOS X). + * + * getentropy() is present on Linux (Glibc 2.25+), FreeBSD (12.0+) and + * OpenBSD (5.6+). For OpenBSD, there does not seem to be easy to use + * macros to test the minimum version, so we just assume that it is + * recent enough (last version without getentropy() has gone out of + * support in May 2015). + * + * Ideally we should use getentropy() on macOS (10.12+) too, but I don't + * know how to test the exact OS version with preprocessor macros. + * + * TODO: enrich the list of detected system. + */ + +#ifndef BR_USE_URANDOM +#if defined _AIX \ + || defined __ANDROID__ \ + || defined __FreeBSD__ \ + || defined __NetBSD__ \ + || defined __OpenBSD__ \ + || defined __DragonFly__ \ + || defined __linux__ \ + || (defined __sun && (defined __SVR4 || defined __svr4__)) \ + || (defined __APPLE__ && defined __MACH__) +#define BR_USE_URANDOM 1 +#endif +#endif + +#ifndef BR_USE_GETENTROPY +#if (defined __linux__ \ + && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 25))) \ + || (defined __FreeBSD__ && __FreeBSD__ >= 12) \ + || defined __OpenBSD__ +#define BR_USE_GETENTROPY 1 +#endif +#endif + +#ifndef BR_USE_WIN32_RAND +#if defined _WIN32 || defined _WIN64 +#define BR_USE_WIN32_RAND 1 +#endif +#endif + +/* + * POWER8 crypto support. We rely on compiler macros for the + * architecture, since we do not have a reliable, simple way to detect + * the required support at runtime (we could try running an opcode, and + * trapping the exception or signal on illegal instruction, but this + * induces some non-trivial OS dependencies that we would prefer to + * avoid if possible). + */ +#ifndef BR_POWER8 +#if __GNUC__ && ((_ARCH_PWR8 || _ARCH_PPC) && __CRYPTO__) +#define BR_POWER8 1 +#endif +#endif + +/* + * Detect endinanness on POWER8. + */ +#if BR_POWER8 +#if defined BR_POWER8_LE +#undef BR_POWER8_BE +#if BR_POWER8_LE +#define BR_POWER8_BE 0 +#else +#define BR_POWER8_BE 1 +#endif +#elif defined BR_POWER8_BE +#undef BR_POWER8_LE +#if BR_POWER8_BE +#define BR_POWER8_LE 0 +#else +#define BR_POWER8_LE 1 +#endif +#else +#if __LITTLE_ENDIAN__ +#define BR_POWER8_LE 1 +#define BR_POWER8_BE 0 +#else +#define BR_POWER8_LE 0 +#define BR_POWER8_BE 1 +#endif +#endif +#endif + +/* + * Detect support for 128-bit integers. + */ +#if !defined BR_INT128 && !defined BR_UMUL128 +#ifdef __SIZEOF_INT128__ +#define BR_INT128 1 +#elif _M_X64 +#define BR_UMUL128 1 +#endif +#endif + +/* + * Detect support for unaligned accesses with known endianness. + * + * x86 (both 32-bit and 64-bit) is little-endian and allows unaligned + * accesses. + * + * POWER/PowerPC allows unaligned accesses when big-endian. POWER8 and + * later also allow unaligned accesses when little-endian. + */ +#if !defined BR_LE_UNALIGNED && !defined BR_BE_UNALIGNED + +#if __i386 || __i386__ || __x86_64__ || _M_IX86 || _M_X64 +#define BR_LE_UNALIGNED 1 +#elif BR_POWER8_BE +#define BR_BE_UNALIGNED 1 +#elif BR_POWER8_LE +#define BR_LE_UNALIGNED 1 +#elif (__powerpc__ || __powerpc64__ || _M_PPC || _ARCH_PPC || _ARCH_PPC64) \ + && __BIG_ENDIAN__ +#define BR_BE_UNALIGNED 1 +#endif + +#endif + +/* + * Detect support for an OS-provided time source. + */ + +#ifndef BR_USE_UNIX_TIME +#if defined __unix__ || defined __linux__ \ + || defined _POSIX_SOURCE || defined _POSIX_C_SOURCE \ + || (defined __APPLE__ && defined __MACH__) +#define BR_USE_UNIX_TIME 1 +#endif +#endif + +#ifndef BR_USE_WIN32_TIME +#if defined _WIN32 || defined _WIN64 +#define BR_USE_WIN32_TIME 1 +#endif +#endif + +/* ==================================================================== */ +/* + * Encoding/decoding functions. + * + * 32-bit and 64-bit decoding, both little-endian and big-endian, is + * implemented with the inline functions below. + * + * When allowed by some compile-time options (autodetected or provided), + * optimised code is used, to perform direct memory access when the + * underlying architecture supports it, both for endianness and + * alignment. This, however, may trigger strict aliasing issues; the + * code below uses unions to perform (supposedly) safe type punning. + * Since the C aliasing rules are relatively complex and were amended, + * or at least re-explained with different phrasing, in all successive + * versions of the C standard, it is always a bit risky to bet that any + * specific version of a C compiler got it right, for some notion of + * "right". + */ + +typedef union { + uint16_t u; + unsigned char b[sizeof(uint16_t)]; +} br_union_u16; + +typedef union { + uint32_t u; + unsigned char b[sizeof(uint32_t)]; +} br_union_u32; + +typedef union { + uint64_t u; + unsigned char b[sizeof(uint64_t)]; +} br_union_u64; + +static inline void +br_enc16le(void *dst, unsigned x) +{ +#if BR_LE_UNALIGNED + ((br_union_u16 *)dst)->u = x; +#else + unsigned char *buf; + + buf = dst; + buf[0] = (unsigned char)x; + buf[1] = (unsigned char)(x >> 8); +#endif +} + +static inline void +br_enc16be(void *dst, unsigned x) +{ +#if BR_BE_UNALIGNED + ((br_union_u16 *)dst)->u = x; +#else + unsigned char *buf; + + buf = dst; + buf[0] = (unsigned char)(x >> 8); + buf[1] = (unsigned char)x; +#endif +} + +static inline unsigned +br_dec16le(const void *src) +{ +#if BR_LE_UNALIGNED + return ((const br_union_u16 *)src)->u; +#else + const unsigned char *buf; + + buf = src; + return (unsigned)buf[0] | ((unsigned)buf[1] << 8); +#endif +} + +static inline unsigned +br_dec16be(const void *src) +{ +#if BR_BE_UNALIGNED + return ((const br_union_u16 *)src)->u; +#else + const unsigned char *buf; + + buf = src; + return ((unsigned)buf[0] << 8) | (unsigned)buf[1]; +#endif +} + +static inline void +br_enc32le(void *dst, uint32_t x) +{ +#if BR_LE_UNALIGNED + ((br_union_u32 *)dst)->u = x; +#else + unsigned char *buf; + + buf = dst; + buf[0] = (unsigned char)x; + buf[1] = (unsigned char)(x >> 8); + buf[2] = (unsigned char)(x >> 16); + buf[3] = (unsigned char)(x >> 24); +#endif +} + +static inline void +br_enc32be(void *dst, uint32_t x) +{ +#if BR_BE_UNALIGNED + ((br_union_u32 *)dst)->u = x; +#else + unsigned char *buf; + + buf = dst; + buf[0] = (unsigned char)(x >> 24); + buf[1] = (unsigned char)(x >> 16); + buf[2] = (unsigned char)(x >> 8); + buf[3] = (unsigned char)x; +#endif +} + +static inline uint32_t +br_dec32le(const void *src) +{ +#if BR_LE_UNALIGNED + return ((const br_union_u32 *)src)->u; +#else + const unsigned char *buf; + + buf = src; + return (uint32_t)buf[0] + | ((uint32_t)buf[1] << 8) + | ((uint32_t)buf[2] << 16) + | ((uint32_t)buf[3] << 24); +#endif +} + +static inline uint32_t +br_dec32be(const void *src) +{ +#if BR_BE_UNALIGNED + return ((const br_union_u32 *)src)->u; +#else + const unsigned char *buf; + + buf = src; + return ((uint32_t)buf[0] << 24) + | ((uint32_t)buf[1] << 16) + | ((uint32_t)buf[2] << 8) + | (uint32_t)buf[3]; +#endif +} + +static inline void +br_enc64le(void *dst, uint64_t x) +{ +#if BR_LE_UNALIGNED + ((br_union_u64 *)dst)->u = x; +#else + unsigned char *buf; + + buf = dst; + br_enc32le(buf, (uint32_t)x); + br_enc32le(buf + 4, (uint32_t)(x >> 32)); +#endif +} + +static inline void +br_enc64be(void *dst, uint64_t x) +{ +#if BR_BE_UNALIGNED + ((br_union_u64 *)dst)->u = x; +#else + unsigned char *buf; + + buf = dst; + br_enc32be(buf, (uint32_t)(x >> 32)); + br_enc32be(buf + 4, (uint32_t)x); +#endif +} + +static inline uint64_t +br_dec64le(const void *src) +{ +#if BR_LE_UNALIGNED + return ((const br_union_u64 *)src)->u; +#else + const unsigned char *buf; + + buf = src; + return (uint64_t)br_dec32le(buf) + | ((uint64_t)br_dec32le(buf + 4) << 32); +#endif +} + +static inline uint64_t +br_dec64be(const void *src) +{ +#if BR_BE_UNALIGNED + return ((const br_union_u64 *)src)->u; +#else + const unsigned char *buf; + + buf = src; + return ((uint64_t)br_dec32be(buf) << 32) + | (uint64_t)br_dec32be(buf + 4); +#endif +} + +/* + * Range decoding and encoding (for several successive values). + */ +void br_range_dec16le(uint16_t *v, size_t num, const void *src); +void br_range_dec16be(uint16_t *v, size_t num, const void *src); +void br_range_enc16le(void *dst, const uint16_t *v, size_t num); +void br_range_enc16be(void *dst, const uint16_t *v, size_t num); + +void br_range_dec32le(uint32_t *v, size_t num, const void *src); +void br_range_dec32be(uint32_t *v, size_t num, const void *src); +void br_range_enc32le(void *dst, const uint32_t *v, size_t num); +void br_range_enc32be(void *dst, const uint32_t *v, size_t num); + +void br_range_dec64le(uint64_t *v, size_t num, const void *src); +void br_range_dec64be(uint64_t *v, size_t num, const void *src); +void br_range_enc64le(void *dst, const uint64_t *v, size_t num); +void br_range_enc64be(void *dst, const uint64_t *v, size_t num); + +/* + * Byte-swap a 32-bit integer. + */ +static inline uint32_t +br_swap32(uint32_t x) +{ + x = ((x & (uint32_t)0x00FF00FF) << 8) + | ((x >> 8) & (uint32_t)0x00FF00FF); + return (x << 16) | (x >> 16); +} + +/* ==================================================================== */ +/* + * Support code for hash functions. + */ + +/* + * IV for MD5, SHA-1, SHA-224 and SHA-256. + */ +extern const uint32_t br_md5_IV[]; +extern const uint32_t br_sha1_IV[]; +extern const uint32_t br_sha224_IV[]; +extern const uint32_t br_sha256_IV[]; + +/* + * Round functions for MD5, SHA-1, SHA-224 and SHA-256 (SHA-224 and + * SHA-256 use the same round function). + */ +void br_md5_round(const unsigned char *buf, uint32_t *val); +void br_sha1_round(const unsigned char *buf, uint32_t *val); +void br_sha2small_round(const unsigned char *buf, uint32_t *val); + +/* + * The core function for the TLS PRF. It computes + * P_hash(secret, label + seed), and XORs the result into the dst buffer. + */ +void br_tls_phash(void *dst, size_t len, + const br_hash_class *dig, + const void *secret, size_t secret_len, const char *label, + size_t seed_num, const br_tls_prf_seed_chunk *seed); + +/* + * Copy all configured hash implementations from a multihash context + * to another. + */ +static inline void +br_multihash_copyimpl(br_multihash_context *dst, + const br_multihash_context *src) +{ + memcpy((void *)dst->impl, src->impl, sizeof src->impl); +} + +/* ==================================================================== */ +/* + * Constant-time primitives. These functions manipulate 32-bit values in + * order to provide constant-time comparisons and multiplexers. + * + * Boolean values (the "ctl" bits) MUST have value 0 or 1. + * + * Implementation notes: + * ===================== + * + * The uintN_t types are unsigned and with width exactly N bits; the C + * standard guarantees that computations are performed modulo 2^N, and + * there can be no overflow. Negation (unary '-') works on unsigned types + * as well. + * + * The intN_t types are guaranteed to have width exactly N bits, with no + * padding bit, and using two's complement representation. Casting + * intN_t to uintN_t really is conversion modulo 2^N. Beware that intN_t + * types, being signed, trigger implementation-defined behaviour on + * overflow (including raising some signal): with GCC, while modular + * arithmetics are usually applied, the optimizer may assume that + * overflows don't occur (unless the -fwrapv command-line option is + * added); Clang has the additional -ftrapv option to explicitly trap on + * integer overflow or underflow. + */ + +/* + * Negate a boolean. + */ +static inline uint32_t +NOT(uint32_t ctl) +{ + return ctl ^ 1; +} + +/* + * Multiplexer: returns x if ctl == 1, y if ctl == 0. + */ +static inline uint32_t +MUX(uint32_t ctl, uint32_t x, uint32_t y) +{ + return y ^ (-ctl & (x ^ y)); +} + +/* + * Equality check: returns 1 if x == y, 0 otherwise. + */ +static inline uint32_t +EQ(uint32_t x, uint32_t y) +{ + uint32_t q; + + q = x ^ y; + return NOT((q | -q) >> 31); +} + +/* + * Inequality check: returns 1 if x != y, 0 otherwise. + */ +static inline uint32_t +NEQ(uint32_t x, uint32_t y) +{ + uint32_t q; + + q = x ^ y; + return (q | -q) >> 31; +} + +/* + * Comparison: returns 1 if x > y, 0 otherwise. + */ +static inline uint32_t +GT(uint32_t x, uint32_t y) +{ + /* + * If both x < 2^31 and x < 2^31, then y-x will have its high + * bit set if x > y, cleared otherwise. + * + * If either x >= 2^31 or y >= 2^31 (but not both), then the + * result is the high bit of x. + * + * If both x >= 2^31 and y >= 2^31, then we can virtually + * subtract 2^31 from both, and we are back to the first case. + * Since (y-2^31)-(x-2^31) = y-x, the subtraction is already + * fine. + */ + uint32_t z; + + z = y - x; + return (z ^ ((x ^ y) & (x ^ z))) >> 31; +} + +/* + * Other comparisons (greater-or-equal, lower-than, lower-or-equal). + */ +#define GE(x, y) NOT(GT(y, x)) +#define LT(x, y) GT(y, x) +#define LE(x, y) NOT(GT(x, y)) + +/* + * General comparison: returned value is -1, 0 or 1, depending on + * whether x is lower than, equal to, or greater than y. + */ +static inline int32_t +CMP(uint32_t x, uint32_t y) +{ + return (int32_t)GT(x, y) | -(int32_t)GT(y, x); +} + +/* + * Returns 1 if x == 0, 0 otherwise. Take care that the operand is signed. + */ +static inline uint32_t +EQ0(int32_t x) +{ + uint32_t q; + + q = (uint32_t)x; + return ~(q | -q) >> 31; +} + +/* + * Returns 1 if x > 0, 0 otherwise. Take care that the operand is signed. + */ +static inline uint32_t +GT0(int32_t x) +{ + /* + * High bit of -x is 0 if x == 0, but 1 if x > 0. + */ + uint32_t q; + + q = (uint32_t)x; + return (~q & -q) >> 31; +} + +/* + * Returns 1 if x >= 0, 0 otherwise. Take care that the operand is signed. + */ +static inline uint32_t +GE0(int32_t x) +{ + return ~(uint32_t)x >> 31; +} + +/* + * Returns 1 if x < 0, 0 otherwise. Take care that the operand is signed. + */ +static inline uint32_t +LT0(int32_t x) +{ + return (uint32_t)x >> 31; +} + +/* + * Returns 1 if x <= 0, 0 otherwise. Take care that the operand is signed. + */ +static inline uint32_t +LE0(int32_t x) +{ + uint32_t q; + + /* + * ~-x has its high bit set if and only if -x is nonnegative (as + * a signed int), i.e. x is in the -(2^31-1) to 0 range. We must + * do an OR with x itself to account for x = -2^31. + */ + q = (uint32_t)x; + return (q | ~-q) >> 31; +} + +/* + * Conditional copy: src[] is copied into dst[] if and only if ctl is 1. + * dst[] and src[] may overlap completely (but not partially). + */ +void br_ccopy(uint32_t ctl, void *dst, const void *src, size_t len); + +#define CCOPY br_ccopy + +/* + * Compute the bit length of a 32-bit integer. Returned value is between 0 + * and 32 (inclusive). + */ +static inline uint32_t +BIT_LENGTH(uint32_t x) +{ + uint32_t k, c; + + k = NEQ(x, 0); + c = GT(x, 0xFFFF); x = MUX(c, x >> 16, x); k += c << 4; + c = GT(x, 0x00FF); x = MUX(c, x >> 8, x); k += c << 3; + c = GT(x, 0x000F); x = MUX(c, x >> 4, x); k += c << 2; + c = GT(x, 0x0003); x = MUX(c, x >> 2, x); k += c << 1; + k += GT(x, 0x0001); + return k; +} + +/* + * Compute the minimum of x and y. + */ +static inline uint32_t +MIN(uint32_t x, uint32_t y) +{ + return MUX(GT(x, y), y, x); +} + +/* + * Compute the maximum of x and y. + */ +static inline uint32_t +MAX(uint32_t x, uint32_t y) +{ + return MUX(GT(x, y), x, y); +} + +/* + * Multiply two 32-bit integers, with a 64-bit result. This default + * implementation assumes that the basic multiplication operator + * yields constant-time code. + */ +#define MUL(x, y) ((uint64_t)(x) * (uint64_t)(y)) + +#if BR_CT_MUL31 + +/* + * Alternate implementation of MUL31, that will be constant-time on some + * (old) platforms where the default MUL31 is not. Unfortunately, it is + * also substantially slower, and yields larger code, on more modern + * platforms, which is why it is deactivated by default. + * + * MUL31_lo() must do some extra work because on some platforms, the + * _signed_ multiplication may return early if the top bits are 1. + * Simply truncating (casting) the output of MUL31() would not be + * sufficient, because the compiler may notice that we keep only the low + * word, and then replace automatically the unsigned multiplication with + * a signed multiplication opcode. + */ +#define MUL31(x, y) ((uint64_t)((x) | (uint32_t)0x80000000) \ + * (uint64_t)((y) | (uint32_t)0x80000000) \ + - ((uint64_t)(x) << 31) - ((uint64_t)(y) << 31) \ + - ((uint64_t)1 << 62)) +static inline uint32_t +MUL31_lo(uint32_t x, uint32_t y) +{ + uint32_t xl, xh; + uint32_t yl, yh; + + xl = (x & 0xFFFF) | (uint32_t)0x80000000; + xh = (x >> 16) | (uint32_t)0x80000000; + yl = (y & 0xFFFF) | (uint32_t)0x80000000; + yh = (y >> 16) | (uint32_t)0x80000000; + return (xl * yl + ((xl * yh + xh * yl) << 16)) & (uint32_t)0x7FFFFFFF; +} + +#else + +/* + * Multiply two 31-bit integers, with a 62-bit result. This default + * implementation assumes that the basic multiplication operator + * yields constant-time code. + * The MUL31_lo() macro returns only the low 31 bits of the product. + */ +#define MUL31(x, y) ((uint64_t)(x) * (uint64_t)(y)) +#define MUL31_lo(x, y) (((uint32_t)(x) * (uint32_t)(y)) & (uint32_t)0x7FFFFFFF) + +#endif + +/* + * Multiply two words together; the sum of the lengths of the two + * operands must not exceed 31 (for instance, one operand may use 16 + * bits if the other fits on 15). If BR_CT_MUL15 is non-zero, then the + * macro will contain some extra operations that help in making the + * operation constant-time on some platforms, where the basic 32-bit + * multiplication is not constant-time. + */ +#if BR_CT_MUL15 +#define MUL15(x, y) (((uint32_t)(x) | (uint32_t)0x80000000) \ + * ((uint32_t)(y) | (uint32_t)0x80000000) \ + & (uint32_t)0x7FFFFFFF) +#else +#define MUL15(x, y) ((uint32_t)(x) * (uint32_t)(y)) +#endif + +/* + * Arithmetic right shift (sign bit is copied). What happens when + * right-shifting a negative value is _implementation-defined_, so it + * does not trigger undefined behaviour, but it is still up to each + * compiler to define (and document) what it does. Most/all compilers + * will do an arithmetic shift, the sign bit being used to fill the + * holes; this is a native operation on the underlying CPU, and it would + * make little sense for the compiler to do otherwise. GCC explicitly + * documents that it follows that convention. + * + * Still, if BR_NO_ARITH_SHIFT is defined (and non-zero), then an + * alternate version will be used, that does not rely on such + * implementation-defined behaviour. Unfortunately, it is also slower + * and yields bigger code, which is why it is deactivated by default. + */ +#if BR_NO_ARITH_SHIFT +#define ARSH(x, n) (((uint32_t)(x) >> (n)) \ + | ((-((uint32_t)(x) >> 31)) << (32 - (n)))) +#else +#define ARSH(x, n) ((*(int32_t *)&(x)) >> (n)) +#endif + +/* + * Constant-time division. The dividend hi:lo is divided by the + * divisor d; the quotient is returned and the remainder is written + * in *r. If hi == d, then the quotient does not fit on 32 bits; + * returned value is thus truncated. If hi > d, returned values are + * indeterminate. + */ +uint32_t br_divrem(uint32_t hi, uint32_t lo, uint32_t d, uint32_t *r); + +/* + * Wrapper for br_divrem(); the remainder is returned, and the quotient + * is discarded. + */ +static inline uint32_t +br_rem(uint32_t hi, uint32_t lo, uint32_t d) +{ + uint32_t r; + + br_divrem(hi, lo, d, &r); + return r; +} + +/* + * Wrapper for br_divrem(); the quotient is returned, and the remainder + * is discarded. + */ +static inline uint32_t +br_div(uint32_t hi, uint32_t lo, uint32_t d) +{ + uint32_t r; + + return br_divrem(hi, lo, d, &r); +} + +/* ==================================================================== */ + +/* + * Integers 'i32' + * -------------- + * + * The 'i32' functions implement computations on big integers using + * an internal representation as an array of 32-bit integers. For + * an array x[]: + * -- x[0] contains the "announced bit length" of the integer + * -- x[1], x[2]... contain the value in little-endian order (x[1] + * contains the least significant 32 bits) + * + * Multiplications rely on the elementary 32x32->64 multiplication. + * + * The announced bit length specifies the number of bits that are + * significant in the subsequent 32-bit words. Unused bits in the + * last (most significant) word are set to 0; subsequent words are + * uninitialized and need not exist at all. + * + * The execution time and memory access patterns of all computations + * depend on the announced bit length, but not on the actual word + * values. For modular integers, the announced bit length of any integer + * modulo n is equal to the actual bit length of n; thus, computations + * on modular integers are "constant-time" (only the modulus length may + * leak). + */ + +/* + * Compute the actual bit length of an integer. The argument x should + * point to the first (least significant) value word of the integer. + * The len 'xlen' contains the number of 32-bit words to access. + * + * CT: value or length of x does not leak. + */ +uint32_t br_i32_bit_length(uint32_t *x, size_t xlen); + +/* + * Decode an integer from its big-endian unsigned representation. The + * "true" bit length of the integer is computed, but all words of x[] + * corresponding to the full 'len' bytes of the source are set. + * + * CT: value or length of x does not leak. + */ +void br_i32_decode(uint32_t *x, const void *src, size_t len); + +/* + * Decode an integer from its big-endian unsigned representation. The + * integer MUST be lower than m[]; the announced bit length written in + * x[] will be equal to that of m[]. All 'len' bytes from the source are + * read. + * + * Returned value is 1 if the decode value fits within the modulus, 0 + * otherwise. In the latter case, the x[] buffer will be set to 0 (but + * still with the announced bit length of m[]). + * + * CT: value or length of x does not leak. Memory access pattern depends + * only of 'len' and the announced bit length of m. Whether x fits or + * not does not leak either. + */ +uint32_t br_i32_decode_mod(uint32_t *x, + const void *src, size_t len, const uint32_t *m); + +/* + * Reduce an integer (a[]) modulo another (m[]). The result is written + * in x[] and its announced bit length is set to be equal to that of m[]. + * + * x[] MUST be distinct from a[] and m[]. + * + * CT: only announced bit lengths leak, not values of x, a or m. + */ +void br_i32_reduce(uint32_t *x, const uint32_t *a, const uint32_t *m); + +/* + * Decode an integer from its big-endian unsigned representation, and + * reduce it modulo the provided modulus m[]. The announced bit length + * of the result is set to be equal to that of the modulus. + * + * x[] MUST be distinct from m[]. + */ +void br_i32_decode_reduce(uint32_t *x, + const void *src, size_t len, const uint32_t *m); + +/* + * Encode an integer into its big-endian unsigned representation. The + * output length in bytes is provided (parameter 'len'); if the length + * is too short then the integer is appropriately truncated; if it is + * too long then the extra bytes are set to 0. + */ +void br_i32_encode(void *dst, size_t len, const uint32_t *x); + +/* + * Multiply x[] by 2^32 and then add integer z, modulo m[]. This + * function assumes that x[] and m[] have the same announced bit + * length, and the announced bit length of m[] matches its true + * bit length. + * + * x[] and m[] MUST be distinct arrays. + * + * CT: only the common announced bit length of x and m leaks, not + * the values of x, z or m. + */ +void br_i32_muladd_small(uint32_t *x, uint32_t z, const uint32_t *m); + +/* + * Extract one word from an integer. The offset is counted in bits. + * The word MUST entirely fit within the word elements corresponding + * to the announced bit length of a[]. + */ +static inline uint32_t +br_i32_word(const uint32_t *a, uint32_t off) +{ + size_t u; + unsigned j; + + u = (size_t)(off >> 5) + 1; + j = (unsigned)off & 31; + if (j == 0) { + return a[u]; + } else { + return (a[u] >> j) | (a[u + 1] << (32 - j)); + } +} + +/* + * Test whether an integer is zero. + */ +uint32_t br_i32_iszero(const uint32_t *x); + +/* + * Add b[] to a[] and return the carry (0 or 1). If ctl is 0, then a[] + * is unmodified, but the carry is still computed and returned. The + * arrays a[] and b[] MUST have the same announced bit length. + * + * a[] and b[] MAY be the same array, but partial overlap is not allowed. + */ +uint32_t br_i32_add(uint32_t *a, const uint32_t *b, uint32_t ctl); + +/* + * Subtract b[] from a[] and return the carry (0 or 1). If ctl is 0, + * then a[] is unmodified, but the carry is still computed and returned. + * The arrays a[] and b[] MUST have the same announced bit length. + * + * a[] and b[] MAY be the same array, but partial overlap is not allowed. + */ +uint32_t br_i32_sub(uint32_t *a, const uint32_t *b, uint32_t ctl); + +/* + * Compute d+a*b, result in d. The initial announced bit length of d[] + * MUST match that of a[]. The d[] array MUST be large enough to + * accommodate the full result, plus (possibly) an extra word. The + * resulting announced bit length of d[] will be the sum of the announced + * bit lengths of a[] and b[] (therefore, it may be larger than the actual + * bit length of the numerical result). + * + * a[] and b[] may be the same array. d[] must be disjoint from both a[] + * and b[]. + */ +void br_i32_mulacc(uint32_t *d, const uint32_t *a, const uint32_t *b); + +/* + * Zeroize an integer. The announced bit length is set to the provided + * value, and the corresponding words are set to 0. + */ +static inline void +br_i32_zero(uint32_t *x, uint32_t bit_len) +{ + *x ++ = bit_len; + memset(x, 0, ((bit_len + 31) >> 5) * sizeof *x); +} + +/* + * Compute -(1/x) mod 2^32. If x is even, then this function returns 0. + */ +uint32_t br_i32_ninv32(uint32_t x); + +/* + * Convert a modular integer to Montgomery representation. The integer x[] + * MUST be lower than m[], but with the same announced bit length. + */ +void br_i32_to_monty(uint32_t *x, const uint32_t *m); + +/* + * Convert a modular integer back from Montgomery representation. The + * integer x[] MUST be lower than m[], but with the same announced bit + * length. The "m0i" parameter is equal to -(1/m0) mod 2^32, where m0 is + * the least significant value word of m[] (this works only if m[] is + * an odd integer). + */ +void br_i32_from_monty(uint32_t *x, const uint32_t *m, uint32_t m0i); + +/* + * Compute a modular Montgomery multiplication. d[] is filled with the + * value of x*y/R modulo m[] (where R is the Montgomery factor). The + * array d[] MUST be distinct from x[], y[] and m[]. x[] and y[] MUST be + * numerically lower than m[]. x[] and y[] MAY be the same array. The + * "m0i" parameter is equal to -(1/m0) mod 2^32, where m0 is the least + * significant value word of m[] (this works only if m[] is an odd + * integer). + */ +void br_i32_montymul(uint32_t *d, const uint32_t *x, const uint32_t *y, + const uint32_t *m, uint32_t m0i); + +/* + * Compute a modular exponentiation. x[] MUST be an integer modulo m[] + * (same announced bit length, lower value). m[] MUST be odd. The + * exponent is in big-endian unsigned notation, over 'elen' bytes. The + * "m0i" parameter is equal to -(1/m0) mod 2^32, where m0 is the least + * significant value word of m[] (this works only if m[] is an odd + * integer). The t1[] and t2[] parameters must be temporary arrays, + * each large enough to accommodate an integer with the same size as m[]. + */ +void br_i32_modpow(uint32_t *x, const unsigned char *e, size_t elen, + const uint32_t *m, uint32_t m0i, uint32_t *t1, uint32_t *t2); + +/* ==================================================================== */ + +/* + * Integers 'i31' + * -------------- + * + * The 'i31' functions implement computations on big integers using + * an internal representation as an array of 32-bit integers. For + * an array x[]: + * -- x[0] encodes the array length and the "announced bit length" + * of the integer: namely, if the announced bit length is k, + * then x[0] = ((k / 31) << 5) + (k % 31). + * -- x[1], x[2]... contain the value in little-endian order, 31 + * bits per word (x[1] contains the least significant 31 bits). + * The upper bit of each word is 0. + * + * Multiplications rely on the elementary 32x32->64 multiplication. + * + * The announced bit length specifies the number of bits that are + * significant in the subsequent 32-bit words. Unused bits in the + * last (most significant) word are set to 0; subsequent words are + * uninitialized and need not exist at all. + * + * The execution time and memory access patterns of all computations + * depend on the announced bit length, but not on the actual word + * values. For modular integers, the announced bit length of any integer + * modulo n is equal to the actual bit length of n; thus, computations + * on modular integers are "constant-time" (only the modulus length may + * leak). + */ + +/* + * Test whether an integer is zero. + */ +uint32_t br_i31_iszero(const uint32_t *x); + +/* + * Add b[] to a[] and return the carry (0 or 1). If ctl is 0, then a[] + * is unmodified, but the carry is still computed and returned. The + * arrays a[] and b[] MUST have the same announced bit length. + * + * a[] and b[] MAY be the same array, but partial overlap is not allowed. + */ +uint32_t br_i31_add(uint32_t *a, const uint32_t *b, uint32_t ctl); + +/* + * Subtract b[] from a[] and return the carry (0 or 1). If ctl is 0, + * then a[] is unmodified, but the carry is still computed and returned. + * The arrays a[] and b[] MUST have the same announced bit length. + * + * a[] and b[] MAY be the same array, but partial overlap is not allowed. + */ +uint32_t br_i31_sub(uint32_t *a, const uint32_t *b, uint32_t ctl); + +/* + * Compute the ENCODED actual bit length of an integer. The argument x + * should point to the first (least significant) value word of the + * integer. The len 'xlen' contains the number of 32-bit words to + * access. The upper bit of each value word MUST be 0. + * Returned value is ((k / 31) << 5) + (k % 31) if the bit length is k. + * + * CT: value or length of x does not leak. + */ +uint32_t br_i31_bit_length(uint32_t *x, size_t xlen); + +/* + * Decode an integer from its big-endian unsigned representation. The + * "true" bit length of the integer is computed and set in the encoded + * announced bit length (x[0]), but all words of x[] corresponding to + * the full 'len' bytes of the source are set. + * + * CT: value or length of x does not leak. + */ +void br_i31_decode(uint32_t *x, const void *src, size_t len); + +/* + * Decode an integer from its big-endian unsigned representation. The + * integer MUST be lower than m[]; the (encoded) announced bit length + * written in x[] will be equal to that of m[]. All 'len' bytes from the + * source are read. + * + * Returned value is 1 if the decode value fits within the modulus, 0 + * otherwise. In the latter case, the x[] buffer will be set to 0 (but + * still with the announced bit length of m[]). + * + * CT: value or length of x does not leak. Memory access pattern depends + * only of 'len' and the announced bit length of m. Whether x fits or + * not does not leak either. + */ +uint32_t br_i31_decode_mod(uint32_t *x, + const void *src, size_t len, const uint32_t *m); + +/* + * Zeroize an integer. The announced bit length is set to the provided + * value, and the corresponding words are set to 0. The ENCODED bit length + * is expected here. + */ +static inline void +br_i31_zero(uint32_t *x, uint32_t bit_len) +{ + *x ++ = bit_len; + memset(x, 0, ((bit_len + 31) >> 5) * sizeof *x); +} + +/* + * Right-shift an integer. The shift amount must be lower than 31 + * bits. + */ +void br_i31_rshift(uint32_t *x, int count); + +/* + * Reduce an integer (a[]) modulo another (m[]). The result is written + * in x[] and its announced bit length is set to be equal to that of m[]. + * + * x[] MUST be distinct from a[] and m[]. + * + * CT: only announced bit lengths leak, not values of x, a or m. + */ +void br_i31_reduce(uint32_t *x, const uint32_t *a, const uint32_t *m); + +/* + * Decode an integer from its big-endian unsigned representation, and + * reduce it modulo the provided modulus m[]. The announced bit length + * of the result is set to be equal to that of the modulus. + * + * x[] MUST be distinct from m[]. + */ +void br_i31_decode_reduce(uint32_t *x, + const void *src, size_t len, const uint32_t *m); + +/* + * Multiply x[] by 2^31 and then add integer z, modulo m[]. This + * function assumes that x[] and m[] have the same announced bit + * length, the announced bit length of m[] matches its true + * bit length. + * + * x[] and m[] MUST be distinct arrays. z MUST fit in 31 bits (upper + * bit set to 0). + * + * CT: only the common announced bit length of x and m leaks, not + * the values of x, z or m. + */ +void br_i31_muladd_small(uint32_t *x, uint32_t z, const uint32_t *m); + +/* + * Encode an integer into its big-endian unsigned representation. The + * output length in bytes is provided (parameter 'len'); if the length + * is too short then the integer is appropriately truncated; if it is + * too long then the extra bytes are set to 0. + */ +void br_i31_encode(void *dst, size_t len, const uint32_t *x); + +/* + * Compute -(1/x) mod 2^31. If x is even, then this function returns 0. + */ +uint32_t br_i31_ninv31(uint32_t x); + +/* + * Compute a modular Montgomery multiplication. d[] is filled with the + * value of x*y/R modulo m[] (where R is the Montgomery factor). The + * array d[] MUST be distinct from x[], y[] and m[]. x[] and y[] MUST be + * numerically lower than m[]. x[] and y[] MAY be the same array. The + * "m0i" parameter is equal to -(1/m0) mod 2^31, where m0 is the least + * significant value word of m[] (this works only if m[] is an odd + * integer). + */ +void br_i31_montymul(uint32_t *d, const uint32_t *x, const uint32_t *y, + const uint32_t *m, uint32_t m0i); + +/* + * Convert a modular integer to Montgomery representation. The integer x[] + * MUST be lower than m[], but with the same announced bit length. + */ +void br_i31_to_monty(uint32_t *x, const uint32_t *m); + +/* + * Convert a modular integer back from Montgomery representation. The + * integer x[] MUST be lower than m[], but with the same announced bit + * length. The "m0i" parameter is equal to -(1/m0) mod 2^32, where m0 is + * the least significant value word of m[] (this works only if m[] is + * an odd integer). + */ +void br_i31_from_monty(uint32_t *x, const uint32_t *m, uint32_t m0i); + +/* + * Compute a modular exponentiation. x[] MUST be an integer modulo m[] + * (same announced bit length, lower value). m[] MUST be odd. The + * exponent is in big-endian unsigned notation, over 'elen' bytes. The + * "m0i" parameter is equal to -(1/m0) mod 2^31, where m0 is the least + * significant value word of m[] (this works only if m[] is an odd + * integer). The t1[] and t2[] parameters must be temporary arrays, + * each large enough to accommodate an integer with the same size as m[]. + */ +void br_i31_modpow(uint32_t *x, const unsigned char *e, size_t elen, + const uint32_t *m, uint32_t m0i, uint32_t *t1, uint32_t *t2); + +/* + * Compute a modular exponentiation. x[] MUST be an integer modulo m[] + * (same announced bit length, lower value). m[] MUST be odd. The + * exponent is in big-endian unsigned notation, over 'elen' bytes. The + * "m0i" parameter is equal to -(1/m0) mod 2^31, where m0 is the least + * significant value word of m[] (this works only if m[] is an odd + * integer). The tmp[] array is used for temporaries, and has size + * 'twlen' words; it must be large enough to accommodate at least two + * temporary values with the same size as m[] (including the leading + * "bit length" word). If there is room for more temporaries, then this + * function may use the extra room for window-based optimisation, + * resulting in faster computations. + * + * Returned value is 1 on success, 0 on error. An error is reported if + * the provided tmp[] array is too short. + */ +uint32_t br_i31_modpow_opt(uint32_t *x, const unsigned char *e, size_t elen, + const uint32_t *m, uint32_t m0i, uint32_t *tmp, size_t twlen); + +/* + * Compute d+a*b, result in d. The initial announced bit length of d[] + * MUST match that of a[]. The d[] array MUST be large enough to + * accommodate the full result, plus (possibly) an extra word. The + * resulting announced bit length of d[] will be the sum of the announced + * bit lengths of a[] and b[] (therefore, it may be larger than the actual + * bit length of the numerical result). + * + * a[] and b[] may be the same array. d[] must be disjoint from both a[] + * and b[]. + */ +void br_i31_mulacc(uint32_t *d, const uint32_t *a, const uint32_t *b); + +/* + * Compute x/y mod m, result in x. Values x and y must be between 0 and + * m-1, and have the same announced bit length as m. Modulus m must be + * odd. The "m0i" parameter is equal to -1/m mod 2^31. The array 't' + * must point to a temporary area that can hold at least three integers + * of the size of m. + * + * m may not overlap x and y. x and y may overlap each other (this can + * be useful to test whether a value is invertible modulo m). t must be + * disjoint from all other arrays. + * + * Returned value is 1 on success, 0 otherwise. Success is attained if + * y is invertible modulo m. + */ +uint32_t br_i31_moddiv(uint32_t *x, const uint32_t *y, + const uint32_t *m, uint32_t m0i, uint32_t *t); + +/* ==================================================================== */ + +/* + * FIXME: document "i15" functions. + */ + +static inline void +br_i15_zero(uint16_t *x, uint16_t bit_len) +{ + *x ++ = bit_len; + memset(x, 0, ((bit_len + 15) >> 4) * sizeof *x); +} + +uint32_t br_i15_iszero(const uint16_t *x); + +uint16_t br_i15_ninv15(uint16_t x); + +uint32_t br_i15_add(uint16_t *a, const uint16_t *b, uint32_t ctl); + +uint32_t br_i15_sub(uint16_t *a, const uint16_t *b, uint32_t ctl); + +void br_i15_muladd_small(uint16_t *x, uint16_t z, const uint16_t *m); + +void br_i15_montymul(uint16_t *d, const uint16_t *x, const uint16_t *y, + const uint16_t *m, uint16_t m0i); + +void br_i15_to_monty(uint16_t *x, const uint16_t *m); + +void br_i15_modpow(uint16_t *x, const unsigned char *e, size_t elen, + const uint16_t *m, uint16_t m0i, uint16_t *t1, uint16_t *t2); + +uint32_t br_i15_modpow_opt(uint16_t *x, const unsigned char *e, size_t elen, + const uint16_t *m, uint16_t m0i, uint16_t *tmp, size_t twlen); + +void br_i15_encode(void *dst, size_t len, const uint16_t *x); + +uint32_t br_i15_decode_mod(uint16_t *x, + const void *src, size_t len, const uint16_t *m); + +void br_i15_rshift(uint16_t *x, int count); + +uint32_t br_i15_bit_length(uint16_t *x, size_t xlen); + +void br_i15_decode(uint16_t *x, const void *src, size_t len); + +void br_i15_from_monty(uint16_t *x, const uint16_t *m, uint16_t m0i); + +void br_i15_decode_reduce(uint16_t *x, + const void *src, size_t len, const uint16_t *m); + +void br_i15_reduce(uint16_t *x, const uint16_t *a, const uint16_t *m); + +void br_i15_mulacc(uint16_t *d, const uint16_t *a, const uint16_t *b); + +uint32_t br_i15_moddiv(uint16_t *x, const uint16_t *y, + const uint16_t *m, uint16_t m0i, uint16_t *t); + +/* + * Variant of br_i31_modpow_opt() that internally uses 64x64->128 + * multiplications. It expects the same parameters as br_i31_modpow_opt(), + * except that the temporaries should be 64-bit integers, not 32-bit + * integers. + */ +uint32_t br_i62_modpow_opt(uint32_t *x31, const unsigned char *e, size_t elen, + const uint32_t *m31, uint32_t m0i31, uint64_t *tmp, size_t twlen); + +/* + * Type for a function with the same API as br_i31_modpow_opt() (some + * implementations of this type may have stricter alignment requirements + * on the temporaries). + */ +typedef uint32_t (*br_i31_modpow_opt_type)(uint32_t *x, + const unsigned char *e, size_t elen, + const uint32_t *m, uint32_t m0i, uint32_t *tmp, size_t twlen); + +/* + * Wrapper for br_i62_modpow_opt() that uses the same type as + * br_i31_modpow_opt(); however, it requires its 'tmp' argument to the + * 64-bit aligned. + */ +uint32_t br_i62_modpow_opt_as_i31(uint32_t *x, + const unsigned char *e, size_t elen, + const uint32_t *m, uint32_t m0i, uint32_t *tmp, size_t twlen); + +/* ==================================================================== */ + +static inline size_t +br_digest_size(const br_hash_class *digest_class) +{ + return (size_t)(digest_class->desc >> BR_HASHDESC_OUT_OFF) + & BR_HASHDESC_OUT_MASK; +} + +/* + * Get the output size (in bytes) of a hash function. + */ +size_t br_digest_size_by_ID(int digest_id); + +/* + * Get the OID (encoded OBJECT IDENTIFIER value, without tag and length) + * for a hash function. If digest_id is not a supported digest identifier + * (in particular if it is equal to 0, i.e. br_md5sha1_ID), then NULL is + * returned and *len is set to 0. + */ +const unsigned char *br_digest_OID(int digest_id, size_t *len); + +/* ==================================================================== */ +/* + * DES support functions. + */ + +/* + * Apply DES Initial Permutation. + */ +void br_des_do_IP(uint32_t *xl, uint32_t *xr); + +/* + * Apply DES Final Permutation (inverse of IP). + */ +void br_des_do_invIP(uint32_t *xl, uint32_t *xr); + +/* + * Key schedule unit: for a DES key (8 bytes), compute 16 subkeys. Each + * subkey is two 28-bit words represented as two 32-bit words; the PC-2 + * bit extration is NOT applied. + */ +void br_des_keysched_unit(uint32_t *skey, const void *key); + +/* + * Reversal of 16 DES sub-keys (for decryption). + */ +void br_des_rev_skey(uint32_t *skey); + +/* + * DES/3DES key schedule for 'des_tab' (encryption direction). Returned + * value is the number of rounds. + */ +unsigned br_des_tab_keysched(uint32_t *skey, const void *key, size_t key_len); + +/* + * DES/3DES key schedule for 'des_ct' (encryption direction). Returned + * value is the number of rounds. + */ +unsigned br_des_ct_keysched(uint32_t *skey, const void *key, size_t key_len); + +/* + * DES/3DES subkey decompression (from the compressed bitsliced subkeys). + */ +void br_des_ct_skey_expand(uint32_t *sk_exp, + unsigned num_rounds, const uint32_t *skey); + +/* + * DES/3DES block encryption/decryption ('des_tab'). + */ +void br_des_tab_process_block(unsigned num_rounds, + const uint32_t *skey, void *block); + +/* + * DES/3DES block encryption/decryption ('des_ct'). + */ +void br_des_ct_process_block(unsigned num_rounds, + const uint32_t *skey, void *block); + +/* ==================================================================== */ +/* + * AES support functions. + */ + +/* + * The AES S-box (256-byte table). + */ +extern const unsigned char br_aes_S[]; + +/* + * AES key schedule. skey[] is filled with n+1 128-bit subkeys, where n + * is the number of rounds (10 to 14, depending on key size). The number + * of rounds is returned. If the key size is invalid (not 16, 24 or 32), + * then 0 is returned. + * + * This implementation uses a 256-byte table and is NOT constant-time. + */ +unsigned br_aes_keysched(uint32_t *skey, const void *key, size_t key_len); + +/* + * AES key schedule for decryption ('aes_big' implementation). + */ +unsigned br_aes_big_keysched_inv(uint32_t *skey, + const void *key, size_t key_len); + +/* + * AES block encryption with the 'aes_big' implementation (fast, but + * not constant-time). This function encrypts a single block "in place". + */ +void br_aes_big_encrypt(unsigned num_rounds, const uint32_t *skey, void *data); + +/* + * AES block decryption with the 'aes_big' implementation (fast, but + * not constant-time). This function decrypts a single block "in place". + */ +void br_aes_big_decrypt(unsigned num_rounds, const uint32_t *skey, void *data); + +/* + * AES block encryption with the 'aes_small' implementation (small, but + * slow and not constant-time). This function encrypts a single block + * "in place". + */ +void br_aes_small_encrypt(unsigned num_rounds, + const uint32_t *skey, void *data); + +/* + * AES block decryption with the 'aes_small' implementation (small, but + * slow and not constant-time). This function decrypts a single block + * "in place". + */ +void br_aes_small_decrypt(unsigned num_rounds, + const uint32_t *skey, void *data); + +/* + * The constant-time implementation is "bitsliced": the 128-bit state is + * split over eight 32-bit words q* in the following way: + * + * -- Input block consists in 16 bytes: + * a00 a10 a20 a30 a01 a11 a21 a31 a02 a12 a22 a32 a03 a13 a23 a33 + * In the terminology of FIPS 197, this is a 4x4 matrix which is read + * column by column. + * + * -- Each byte is split into eight bits which are distributed over the + * eight words, at the same rank. Thus, for a byte x at rank k, bit 0 + * (least significant) of x will be at rank k in q0 (if that bit is b, + * then it contributes "b << k" to the value of q0), bit 1 of x will be + * at rank k in q1, and so on. + * + * -- Ranks given to bits are in "row order" and are either all even, or + * all odd. Two independent AES states are thus interleaved, one using + * the even ranks, the other the odd ranks. Row order means: + * a00 a01 a02 a03 a10 a11 a12 a13 a20 a21 a22 a23 a30 a31 a32 a33 + * + * Converting input bytes from two AES blocks to bitslice representation + * is done in the following way: + * -- Decode first block into the four words q0 q2 q4 q6, in that order, + * using little-endian convention. + * -- Decode second block into the four words q1 q3 q5 q7, in that order, + * using little-endian convention. + * -- Call br_aes_ct_ortho(). + * + * Converting back to bytes is done by using the reverse operations. Note + * that br_aes_ct_ortho() is its own inverse. + */ + +/* + * Perform bytewise orthogonalization of eight 32-bit words. Bytes + * of q0..q7 are spread over all words: for a byte x that occurs + * at rank i in q[j] (byte x uses bits 8*i to 8*i+7 in q[j]), the bit + * of rank k in x (0 <= k <= 7) goes to q[k] at rank 8*i+j. + * + * This operation is an involution. + */ +void br_aes_ct_ortho(uint32_t *q); + +/* + * The AES S-box, as a bitsliced constant-time version. The input array + * consists in eight 32-bit words; 32 S-box instances are computed in + * parallel. Bits 0 to 7 of each S-box input (bit 0 is least significant) + * are spread over the words 0 to 7, at the same rank. + */ +void br_aes_ct_bitslice_Sbox(uint32_t *q); + +/* + * Like br_aes_bitslice_Sbox(), but for the inverse S-box. + */ +void br_aes_ct_bitslice_invSbox(uint32_t *q); + +/* + * Compute AES encryption on bitsliced data. Since input is stored on + * eight 32-bit words, two block encryptions are actually performed + * in parallel. + */ +void br_aes_ct_bitslice_encrypt(unsigned num_rounds, + const uint32_t *skey, uint32_t *q); + +/* + * Compute AES decryption on bitsliced data. Since input is stored on + * eight 32-bit words, two block decryptions are actually performed + * in parallel. + */ +void br_aes_ct_bitslice_decrypt(unsigned num_rounds, + const uint32_t *skey, uint32_t *q); + +/* + * AES key schedule, constant-time version. skey[] is filled with n+1 + * 128-bit subkeys, where n is the number of rounds (10 to 14, depending + * on key size). The number of rounds is returned. If the key size is + * invalid (not 16, 24 or 32), then 0 is returned. + */ +unsigned br_aes_ct_keysched(uint32_t *comp_skey, + const void *key, size_t key_len); + +/* + * Expand AES subkeys as produced by br_aes_ct_keysched(), into + * a larger array suitable for br_aes_ct_bitslice_encrypt() and + * br_aes_ct_bitslice_decrypt(). + */ +void br_aes_ct_skey_expand(uint32_t *skey, + unsigned num_rounds, const uint32_t *comp_skey); + +/* + * For the ct64 implementation, the same bitslicing technique is used, + * but four instances are interleaved. First instance uses bits 0, 4, + * 8, 12,... of each word; second instance uses bits 1, 5, 9, 13,... + * and so on. + */ + +/* + * Perform bytewise orthogonalization of eight 64-bit words. Bytes + * of q0..q7 are spread over all words: for a byte x that occurs + * at rank i in q[j] (byte x uses bits 8*i to 8*i+7 in q[j]), the bit + * of rank k in x (0 <= k <= 7) goes to q[k] at rank 8*i+j. + * + * This operation is an involution. + */ +void br_aes_ct64_ortho(uint64_t *q); + +/* + * Interleave bytes for an AES input block. If input bytes are + * denoted 0123456789ABCDEF, and have been decoded with little-endian + * convention (w[0] contains 0123, with '3' being most significant; + * w[1] contains 4567, and so on), then output word q0 will be + * set to 08192A3B (again little-endian convention) and q1 will + * be set to 4C5D6E7F. + */ +void br_aes_ct64_interleave_in(uint64_t *q0, uint64_t *q1, const uint32_t *w); + +/* + * Perform the opposite of br_aes_ct64_interleave_in(). + */ +void br_aes_ct64_interleave_out(uint32_t *w, uint64_t q0, uint64_t q1); + +/* + * The AES S-box, as a bitsliced constant-time version. The input array + * consists in eight 64-bit words; 64 S-box instances are computed in + * parallel. Bits 0 to 7 of each S-box input (bit 0 is least significant) + * are spread over the words 0 to 7, at the same rank. + */ +void br_aes_ct64_bitslice_Sbox(uint64_t *q); + +/* + * Like br_aes_bitslice_Sbox(), but for the inverse S-box. + */ +void br_aes_ct64_bitslice_invSbox(uint64_t *q); + +/* + * Compute AES encryption on bitsliced data. Since input is stored on + * eight 64-bit words, four block encryptions are actually performed + * in parallel. + */ +void br_aes_ct64_bitslice_encrypt(unsigned num_rounds, + const uint64_t *skey, uint64_t *q); + +/* + * Compute AES decryption on bitsliced data. Since input is stored on + * eight 64-bit words, four block decryptions are actually performed + * in parallel. + */ +void br_aes_ct64_bitslice_decrypt(unsigned num_rounds, + const uint64_t *skey, uint64_t *q); + +/* + * AES key schedule, constant-time version. skey[] is filled with n+1 + * 128-bit subkeys, where n is the number of rounds (10 to 14, depending + * on key size). The number of rounds is returned. If the key size is + * invalid (not 16, 24 or 32), then 0 is returned. + */ +unsigned br_aes_ct64_keysched(uint64_t *comp_skey, + const void *key, size_t key_len); + +/* + * Expand AES subkeys as produced by br_aes_ct64_keysched(), into + * a larger array suitable for br_aes_ct64_bitslice_encrypt() and + * br_aes_ct64_bitslice_decrypt(). + */ +void br_aes_ct64_skey_expand(uint64_t *skey, + unsigned num_rounds, const uint64_t *comp_skey); + +/* + * Test support for AES-NI opcodes. + */ +int br_aes_x86ni_supported(void); + +/* + * AES key schedule, using x86 AES-NI instructions. This yields the + * subkeys in the encryption direction. Number of rounds is returned. + * Key size MUST be 16, 24 or 32 bytes; otherwise, 0 is returned. + */ +unsigned br_aes_x86ni_keysched_enc(unsigned char *skni, + const void *key, size_t len); + +/* + * AES key schedule, using x86 AES-NI instructions. This yields the + * subkeys in the decryption direction. Number of rounds is returned. + * Key size MUST be 16, 24 or 32 bytes; otherwise, 0 is returned. + */ +unsigned br_aes_x86ni_keysched_dec(unsigned char *skni, + const void *key, size_t len); + +/* + * Test support for AES POWER8 opcodes. + */ +int br_aes_pwr8_supported(void); + +/* + * AES key schedule, using POWER8 instructions. This yields the + * subkeys in the encryption direction. Number of rounds is returned. + * Key size MUST be 16, 24 or 32 bytes; otherwise, 0 is returned. + */ +unsigned br_aes_pwr8_keysched(unsigned char *skni, + const void *key, size_t len); + +/* ==================================================================== */ +/* + * RSA. + */ + +/* + * Apply proper PKCS#1 v1.5 padding (for signatures). 'hash_oid' is + * the encoded hash function OID, or NULL. + */ +uint32_t br_rsa_pkcs1_sig_pad(const unsigned char *hash_oid, + const unsigned char *hash, size_t hash_len, + uint32_t n_bitlen, unsigned char *x); + +/* + * Check PKCS#1 v1.5 padding (for signatures). 'hash_oid' is the encoded + * hash function OID, or NULL. The provided 'sig' value is _after_ the + * modular exponentiation, i.e. it should be the padded hash. On + * success, the hashed message is extracted. + */ +uint32_t br_rsa_pkcs1_sig_unpad(const unsigned char *sig, size_t sig_len, + const unsigned char *hash_oid, size_t hash_len, + unsigned char *hash_out); + +/* + * Apply proper PSS padding. The 'x' buffer is output only: it + * receives the value that is to be exponentiated. + */ +uint32_t br_rsa_pss_sig_pad(const br_prng_class **rng, + const br_hash_class *hf_data, const br_hash_class *hf_mgf1, + const unsigned char *hash, size_t salt_len, + uint32_t n_bitlen, unsigned char *x); + +/* + * Check PSS padding. The provided value is the one _after_ + * the modular exponentiation; it is modified by this function. + * This function infers the signature length from the public key + * size, i.e. it assumes that this has already been verified (as + * part of the exponentiation). + */ +uint32_t br_rsa_pss_sig_unpad( + const br_hash_class *hf_data, const br_hash_class *hf_mgf1, + const unsigned char *hash, size_t salt_len, + const br_rsa_public_key *pk, unsigned char *x); + +/* + * Apply OAEP padding. Returned value is the actual padded string length, + * or zero on error. + */ +size_t br_rsa_oaep_pad(const br_prng_class **rnd, const br_hash_class *dig, + const void *label, size_t label_len, const br_rsa_public_key *pk, + void *dst, size_t dst_nax_len, const void *src, size_t src_len); + +/* + * Unravel and check OAEP padding. If the padding is correct, then 1 is + * returned, '*len' is adjusted to the length of the message, and the + * data is moved to the start of the 'data' buffer. If the padding is + * incorrect, then 0 is returned and '*len' is untouched. Either way, + * the complete buffer contents are altered. + */ +uint32_t br_rsa_oaep_unpad(const br_hash_class *dig, + const void *label, size_t label_len, void *data, size_t *len); + +/* + * Compute MGF1 for a given seed, and XOR the output into the provided + * buffer. + */ +void br_mgf1_xor(void *data, size_t len, + const br_hash_class *dig, const void *seed, size_t seed_len); + +/* + * Inner function for RSA key generation; used by the "i31" and "i62" + * implementations. + */ +uint32_t br_rsa_i31_keygen_inner(const br_prng_class **rng, + br_rsa_private_key *sk, void *kbuf_priv, + br_rsa_public_key *pk, void *kbuf_pub, + unsigned size, uint32_t pubexp, br_i31_modpow_opt_type mp31); + +/* ==================================================================== */ +/* + * Elliptic curves. + */ + +/* + * Type for generic EC parameters: curve order (unsigned big-endian + * encoding) and encoded conventional generator. + */ +typedef struct { + int curve; + const unsigned char *order; + size_t order_len; + const unsigned char *generator; + size_t generator_len; +} br_ec_curve_def; + +extern const br_ec_curve_def br_secp256r1; +extern const br_ec_curve_def br_secp384r1; +extern const br_ec_curve_def br_secp521r1; + +/* + * For Curve25519, the advertised "order" really is 2^255-1, since the + * point multipliction function really works over arbitrary 255-bit + * scalars. This value is only meant as a hint for ECDH key generation; + * only ECDSA uses the exact curve order, and ECDSA is not used with + * that specific curve. + */ +extern const br_ec_curve_def br_curve25519; + +/* + * Decode some bytes as an i31 integer, with truncation (corresponding + * to the 'bits2int' operation in RFC 6979). The target ENCODED bit + * length is provided as last parameter. The resulting value will have + * this declared bit length, and consists the big-endian unsigned decoding + * of exactly that many bits in the source (capped at the source length). + */ +void br_ecdsa_i31_bits2int(uint32_t *x, + const void *src, size_t len, uint32_t ebitlen); + +/* + * Decode some bytes as an i15 integer, with truncation (corresponding + * to the 'bits2int' operation in RFC 6979). The target ENCODED bit + * length is provided as last parameter. The resulting value will have + * this declared bit length, and consists the big-endian unsigned decoding + * of exactly that many bits in the source (capped at the source length). + */ +void br_ecdsa_i15_bits2int(uint16_t *x, + const void *src, size_t len, uint32_t ebitlen); + +/* ==================================================================== */ +/* + * ASN.1 support functions. + */ + +/* + * A br_asn1_uint structure contains encoding information about an + * INTEGER nonnegative value: pointer to the integer contents (unsigned + * big-endian representation), length of the integer contents, + * and length of the encoded value. The data shall have minimal length: + * - If the integer value is zero, then 'len' must be zero. + * - If the integer value is not zero, then data[0] must be non-zero. + * + * Under these conditions, 'asn1len' is necessarily equal to either len + * or len+1. + */ +typedef struct { + const unsigned char *data; + size_t len; + size_t asn1len; +} br_asn1_uint; + +/* + * Given an encoded integer (unsigned big-endian, with possible leading + * bytes of value 0), returned the "prepared INTEGER" structure. + */ +br_asn1_uint br_asn1_uint_prepare(const void *xdata, size_t xlen); + +/* + * Encode an ASN.1 length. The length of the encoded length is returned. + * If 'dest' is NULL, then no encoding is performed, but the length of + * the encoded length is still computed and returned. + */ +size_t br_asn1_encode_length(void *dest, size_t len); + +/* + * Convenient macro for computing lengths of lengths. + */ +#define len_of_len(len) br_asn1_encode_length(NULL, len) + +/* + * Encode a (prepared) ASN.1 INTEGER. The encoded length is returned. + * If 'dest' is NULL, then no encoding is performed, but the length of + * the encoded integer is still computed and returned. + */ +size_t br_asn1_encode_uint(void *dest, br_asn1_uint pp); + +/* + * Get the OID that identifies an elliptic curve. Returned value is + * the DER-encoded OID, with the length (always one byte) but without + * the tag. Thus, the first byte of the returned buffer contains the + * number of subsequent bytes in the value. If the curve is not + * recognised, NULL is returned. + */ +const unsigned char *br_get_curve_OID(int curve); + +/* + * Inner function for EC private key encoding. This is equivalent to + * the API function br_encode_ec_raw_der(), except for an extra + * parameter: if 'include_curve_oid' is zero, then the curve OID is + * _not_ included in the output blob (this is for PKCS#8 support). + */ +size_t br_encode_ec_raw_der_inner(void *dest, + const br_ec_private_key *sk, const br_ec_public_key *pk, + int include_curve_oid); + +/* ==================================================================== */ +/* + * SSL/TLS support functions. + */ + +/* + * Record types. + */ +#define BR_SSL_CHANGE_CIPHER_SPEC 20 +#define BR_SSL_ALERT 21 +#define BR_SSL_HANDSHAKE 22 +#define BR_SSL_APPLICATION_DATA 23 + +/* + * Handshake message types. + */ +#define BR_SSL_HELLO_REQUEST 0 +#define BR_SSL_CLIENT_HELLO 1 +#define BR_SSL_SERVER_HELLO 2 +#define BR_SSL_CERTIFICATE 11 +#define BR_SSL_SERVER_KEY_EXCHANGE 12 +#define BR_SSL_CERTIFICATE_REQUEST 13 +#define BR_SSL_SERVER_HELLO_DONE 14 +#define BR_SSL_CERTIFICATE_VERIFY 15 +#define BR_SSL_CLIENT_KEY_EXCHANGE 16 +#define BR_SSL_FINISHED 20 + +/* + * Alert levels. + */ +#define BR_LEVEL_WARNING 1 +#define BR_LEVEL_FATAL 2 + +/* + * Low-level I/O state. + */ +#define BR_IO_FAILED 0 +#define BR_IO_IN 1 +#define BR_IO_OUT 2 +#define BR_IO_INOUT 3 + +/* + * Mark a SSL engine as failed. The provided error code is recorded if + * the engine was not already marked as failed. If 'err' is 0, then the + * engine is marked as closed (without error). + */ +void br_ssl_engine_fail(br_ssl_engine_context *cc, int err); + +/* + * Test whether the engine is closed (normally or as a failure). + */ +static inline int +br_ssl_engine_closed(const br_ssl_engine_context *cc) +{ + return cc->iomode == BR_IO_FAILED; +} + +/* + * Configure a new maximum fragment length. If possible, the maximum + * length for outgoing records is immediately adjusted (if there are + * not already too many buffered bytes for that). + */ +void br_ssl_engine_new_max_frag_len( + br_ssl_engine_context *rc, unsigned max_frag_len); + +/* + * Test whether the current incoming record has been fully received + * or not. This functions returns 0 only if a complete record header + * has been received, but some of the (possibly encrypted) payload + * has not yet been obtained. + */ +int br_ssl_engine_recvrec_finished(const br_ssl_engine_context *rc); + +/* + * Flush the current record (if not empty). This is meant to be called + * from the handshake processor only. + */ +void br_ssl_engine_flush_record(br_ssl_engine_context *cc); + +/* + * Test whether there is some accumulated payload to send. + */ +static inline int +br_ssl_engine_has_pld_to_send(const br_ssl_engine_context *rc) +{ + return rc->oxa != rc->oxb && rc->oxa != rc->oxc; +} + +/* + * Initialize RNG in engine. Returned value is 1 on success, 0 on error. + * This function will try to use the OS-provided RNG, if available. If + * there is no OS-provided RNG, or if it failed, and no entropy was + * injected by the caller, then a failure will be reported. On error, + * the context error code is set. + */ +int br_ssl_engine_init_rand(br_ssl_engine_context *cc); + +/* + * Reset the handshake-related parts of the engine. + */ +void br_ssl_engine_hs_reset(br_ssl_engine_context *cc, + void (*hsinit)(void *), void (*hsrun)(void *)); + +/* + * Get the PRF to use for this context, for the provided PRF hash + * function ID. + */ +br_tls_prf_impl br_ssl_engine_get_PRF(br_ssl_engine_context *cc, int prf_id); + +/* + * Consume the provided pre-master secret and compute the corresponding + * master secret. The 'prf_id' is the ID of the hash function to use + * with the TLS 1.2 PRF (ignored if the version is TLS 1.0 or 1.1). + */ +void br_ssl_engine_compute_master(br_ssl_engine_context *cc, + int prf_id, const void *pms, size_t len); + +/* + * Switch to CBC decryption for incoming records. + * cc the engine context + * is_client non-zero for a client, zero for a server + * prf_id id of hash function for PRF (ignored if not TLS 1.2+) + * mac_id id of hash function for HMAC + * bc_impl block cipher implementation (CBC decryption) + * cipher_key_len block cipher key length (in bytes) + */ +void br_ssl_engine_switch_cbc_in(br_ssl_engine_context *cc, + int is_client, int prf_id, int mac_id, + const br_block_cbcdec_class *bc_impl, size_t cipher_key_len); + +/* + * Switch to CBC encryption for outgoing records. + * cc the engine context + * is_client non-zero for a client, zero for a server + * prf_id id of hash function for PRF (ignored if not TLS 1.2+) + * mac_id id of hash function for HMAC + * bc_impl block cipher implementation (CBC encryption) + * cipher_key_len block cipher key length (in bytes) + */ +void br_ssl_engine_switch_cbc_out(br_ssl_engine_context *cc, + int is_client, int prf_id, int mac_id, + const br_block_cbcenc_class *bc_impl, size_t cipher_key_len); + +/* + * Switch to GCM decryption for incoming records. + * cc the engine context + * is_client non-zero for a client, zero for a server + * prf_id id of hash function for PRF + * bc_impl block cipher implementation (CTR) + * cipher_key_len block cipher key length (in bytes) + */ +void br_ssl_engine_switch_gcm_in(br_ssl_engine_context *cc, + int is_client, int prf_id, + const br_block_ctr_class *bc_impl, size_t cipher_key_len); + +/* + * Switch to GCM encryption for outgoing records. + * cc the engine context + * is_client non-zero for a client, zero for a server + * prf_id id of hash function for PRF + * bc_impl block cipher implementation (CTR) + * cipher_key_len block cipher key length (in bytes) + */ +void br_ssl_engine_switch_gcm_out(br_ssl_engine_context *cc, + int is_client, int prf_id, + const br_block_ctr_class *bc_impl, size_t cipher_key_len); + +/* + * Switch to ChaCha20+Poly1305 decryption for incoming records. + * cc the engine context + * is_client non-zero for a client, zero for a server + * prf_id id of hash function for PRF + */ +void br_ssl_engine_switch_chapol_in(br_ssl_engine_context *cc, + int is_client, int prf_id); + +/* + * Switch to ChaCha20+Poly1305 encryption for outgoing records. + * cc the engine context + * is_client non-zero for a client, zero for a server + * prf_id id of hash function for PRF + */ +void br_ssl_engine_switch_chapol_out(br_ssl_engine_context *cc, + int is_client, int prf_id); + +/* + * Switch to CCM decryption for incoming records. + * cc the engine context + * is_client non-zero for a client, zero for a server + * prf_id id of hash function for PRF + * bc_impl block cipher implementation (CTR+CBC) + * cipher_key_len block cipher key length (in bytes) + * tag_len tag length (in bytes) + */ +void br_ssl_engine_switch_ccm_in(br_ssl_engine_context *cc, + int is_client, int prf_id, + const br_block_ctrcbc_class *bc_impl, + size_t cipher_key_len, size_t tag_len); + +/* + * Switch to GCM encryption for outgoing records. + * cc the engine context + * is_client non-zero for a client, zero for a server + * prf_id id of hash function for PRF + * bc_impl block cipher implementation (CTR+CBC) + * cipher_key_len block cipher key length (in bytes) + * tag_len tag length (in bytes) + */ +void br_ssl_engine_switch_ccm_out(br_ssl_engine_context *cc, + int is_client, int prf_id, + const br_block_ctrcbc_class *bc_impl, + size_t cipher_key_len, size_t tag_len); + +/* + * Calls to T0-generated code. + */ +void br_ssl_hs_client_init_main(void *ctx); +void br_ssl_hs_client_run(void *ctx); +void br_ssl_hs_server_init_main(void *ctx); +void br_ssl_hs_server_run(void *ctx); + +/* + * Get the hash function to use for signatures, given a bit mask of + * supported hash functions. This implements a strict choice order + * (namely SHA-256, SHA-384, SHA-512, SHA-224, SHA-1). If the mask + * does not document support of any of these hash functions, then this + * functions returns 0. + */ +int br_ssl_choose_hash(unsigned bf); + +/* ==================================================================== */ + +/* + * PowerPC / POWER assembly stuff. The special BR_POWER_ASM_MACROS macro + * must be defined before including this file; this is done by source + * files that use some inline assembly for PowerPC / POWER machines. + */ + +#if BR_POWER_ASM_MACROS + +#define lxvw4x(xt, ra, rb) lxvw4x_(xt, ra, rb) +#define stxvw4x(xt, ra, rb) stxvw4x_(xt, ra, rb) + +#define bdnz(foo) bdnz_(foo) +#define bdz(foo) bdz_(foo) +#define beq(foo) beq_(foo) + +#define li(rx, value) li_(rx, value) +#define addi(rx, ra, imm) addi_(rx, ra, imm) +#define cmpldi(rx, imm) cmpldi_(rx, imm) +#define mtctr(rx) mtctr_(rx) +#define vspltb(vrt, vrb, uim) vspltb_(vrt, vrb, uim) +#define vspltw(vrt, vrb, uim) vspltw_(vrt, vrb, uim) +#define vspltisb(vrt, imm) vspltisb_(vrt, imm) +#define vspltisw(vrt, imm) vspltisw_(vrt, imm) +#define vrlw(vrt, vra, vrb) vrlw_(vrt, vra, vrb) +#define vsbox(vrt, vra) vsbox_(vrt, vra) +#define vxor(vrt, vra, vrb) vxor_(vrt, vra, vrb) +#define vand(vrt, vra, vrb) vand_(vrt, vra, vrb) +#define vsro(vrt, vra, vrb) vsro_(vrt, vra, vrb) +#define vsl(vrt, vra, vrb) vsl_(vrt, vra, vrb) +#define vsldoi(vt, va, vb, sh) vsldoi_(vt, va, vb, sh) +#define vsr(vrt, vra, vrb) vsr_(vrt, vra, vrb) +#define vaddcuw(vrt, vra, vrb) vaddcuw_(vrt, vra, vrb) +#define vadduwm(vrt, vra, vrb) vadduwm_(vrt, vra, vrb) +#define vsububm(vrt, vra, vrb) vsububm_(vrt, vra, vrb) +#define vsubuwm(vrt, vra, vrb) vsubuwm_(vrt, vra, vrb) +#define vsrw(vrt, vra, vrb) vsrw_(vrt, vra, vrb) +#define vcipher(vt, va, vb) vcipher_(vt, va, vb) +#define vcipherlast(vt, va, vb) vcipherlast_(vt, va, vb) +#define vncipher(vt, va, vb) vncipher_(vt, va, vb) +#define vncipherlast(vt, va, vb) vncipherlast_(vt, va, vb) +#define vperm(vt, va, vb, vc) vperm_(vt, va, vb, vc) +#define vpmsumd(vt, va, vb) vpmsumd_(vt, va, vb) +#define xxpermdi(vt, va, vb, d) xxpermdi_(vt, va, vb, d) + +#define lxvw4x_(xt, ra, rb) "\tlxvw4x\t" #xt "," #ra "," #rb "\n" +#define stxvw4x_(xt, ra, rb) "\tstxvw4x\t" #xt "," #ra "," #rb "\n" + +#define label(foo) #foo "%=:\n" +#define bdnz_(foo) "\tbdnz\t" #foo "%=\n" +#define bdz_(foo) "\tbdz\t" #foo "%=\n" +#define beq_(foo) "\tbeq\t" #foo "%=\n" + +#define li_(rx, value) "\tli\t" #rx "," #value "\n" +#define addi_(rx, ra, imm) "\taddi\t" #rx "," #ra "," #imm "\n" +#define cmpldi_(rx, imm) "\tcmpldi\t" #rx "," #imm "\n" +#define mtctr_(rx) "\tmtctr\t" #rx "\n" +#define vspltb_(vrt, vrb, uim) "\tvspltb\t" #vrt "," #vrb "," #uim "\n" +#define vspltw_(vrt, vrb, uim) "\tvspltw\t" #vrt "," #vrb "," #uim "\n" +#define vspltisb_(vrt, imm) "\tvspltisb\t" #vrt "," #imm "\n" +#define vspltisw_(vrt, imm) "\tvspltisw\t" #vrt "," #imm "\n" +#define vrlw_(vrt, vra, vrb) "\tvrlw\t" #vrt "," #vra "," #vrb "\n" +#define vsbox_(vrt, vra) "\tvsbox\t" #vrt "," #vra "\n" +#define vxor_(vrt, vra, vrb) "\tvxor\t" #vrt "," #vra "," #vrb "\n" +#define vand_(vrt, vra, vrb) "\tvand\t" #vrt "," #vra "," #vrb "\n" +#define vsro_(vrt, vra, vrb) "\tvsro\t" #vrt "," #vra "," #vrb "\n" +#define vsl_(vrt, vra, vrb) "\tvsl\t" #vrt "," #vra "," #vrb "\n" +#define vsldoi_(vt, va, vb, sh) "\tvsldoi\t" #vt "," #va "," #vb "," #sh "\n" +#define vsr_(vrt, vra, vrb) "\tvsr\t" #vrt "," #vra "," #vrb "\n" +#define vaddcuw_(vrt, vra, vrb) "\tvaddcuw\t" #vrt "," #vra "," #vrb "\n" +#define vadduwm_(vrt, vra, vrb) "\tvadduwm\t" #vrt "," #vra "," #vrb "\n" +#define vsububm_(vrt, vra, vrb) "\tvsububm\t" #vrt "," #vra "," #vrb "\n" +#define vsubuwm_(vrt, vra, vrb) "\tvsubuwm\t" #vrt "," #vra "," #vrb "\n" +#define vsrw_(vrt, vra, vrb) "\tvsrw\t" #vrt "," #vra "," #vrb "\n" +#define vcipher_(vt, va, vb) "\tvcipher\t" #vt "," #va "," #vb "\n" +#define vcipherlast_(vt, va, vb) "\tvcipherlast\t" #vt "," #va "," #vb "\n" +#define vncipher_(vt, va, vb) "\tvncipher\t" #vt "," #va "," #vb "\n" +#define vncipherlast_(vt, va, vb) "\tvncipherlast\t" #vt "," #va "," #vb "\n" +#define vperm_(vt, va, vb, vc) "\tvperm\t" #vt "," #va "," #vb "," #vc "\n" +#define vpmsumd_(vt, va, vb) "\tvpmsumd\t" #vt "," #va "," #vb "\n" +#define xxpermdi_(vt, va, vb, d) "\txxpermdi\t" #vt "," #va "," #vb "," #d "\n" + +#endif + +/* ==================================================================== */ +/* + * Special "activate intrinsics" code, needed for some compiler versions. + * This is defined at the end of this file, so that it won't impact any + * of the inline functions defined previously; and it is controlled by + * a specific macro defined in the caller code. + * + * Calling code conventions: + * + * - Caller must define BR_ENABLE_INTRINSICS before including "inner.h". + * - Functions that use intrinsics must be enclosed in an "enabled" + * region (between BR_TARGETS_X86_UP and BR_TARGETS_X86_DOWN). + * - Functions that use intrinsics must be tagged with the appropriate + * BR_TARGET(). + */ + +#if BR_ENABLE_INTRINSICS && (BR_GCC_4_4 || BR_CLANG_3_7 || BR_MSC_2005) + +/* + * x86 intrinsics (both 32-bit and 64-bit). + */ +#if BR_i386 || BR_amd64 + +/* + * On GCC before version 5.0, we need to use the pragma to enable the + * target options globally, because the 'target' function attribute + * appears to be unreliable. Before 4.6 we must also avoid the + * push_options / pop_options mechanism, because it tends to trigger + * some internal compiler errors. + */ +#if BR_GCC && !BR_GCC_5_0 +#if BR_GCC_4_6 +#define BR_TARGETS_X86_UP \ + _Pragma("GCC push_options") \ + _Pragma("GCC target(\"sse2,ssse3,sse4.1,aes,pclmul,rdrnd\")") +#define BR_TARGETS_X86_DOWN \ + _Pragma("GCC pop_options") +#else +#define BR_TARGETS_X86_UP \ + _Pragma("GCC target(\"sse2,ssse3,sse4.1,aes,pclmul\")") +#define BR_TARGETS_X86_DOWN +#endif +#pragma GCC diagnostic ignored "-Wpsabi" +#endif + +#if BR_CLANG && !BR_CLANG_3_8 +#undef __SSE2__ +#undef __SSE3__ +#undef __SSSE3__ +#undef __SSE4_1__ +#undef __AES__ +#undef __PCLMUL__ +#undef __RDRND__ +#define __SSE2__ 1 +#define __SSE3__ 1 +#define __SSSE3__ 1 +#define __SSE4_1__ 1 +#define __AES__ 1 +#define __PCLMUL__ 1 +#define __RDRND__ 1 +#endif + +#ifndef BR_TARGETS_X86_UP +#define BR_TARGETS_X86_UP +#endif +#ifndef BR_TARGETS_X86_DOWN +#define BR_TARGETS_X86_DOWN +#endif + +#if BR_GCC || BR_CLANG +BR_TARGETS_X86_UP +#include +#include +#define br_bswap32 __builtin_bswap32 +BR_TARGETS_X86_DOWN +#endif + +#if BR_MSC +#include +#include +#include +#define br_bswap32 _byteswap_ulong +#endif + +static inline int +br_cpuid(uint32_t mask_eax, uint32_t mask_ebx, + uint32_t mask_ecx, uint32_t mask_edx) +{ +#if BR_GCC || BR_CLANG + unsigned eax, ebx, ecx, edx; + + if (__get_cpuid(1, &eax, &ebx, &ecx, &edx)) { + if ((eax & mask_eax) == mask_eax + && (ebx & mask_ebx) == mask_ebx + && (ecx & mask_ecx) == mask_ecx + && (edx & mask_edx) == mask_edx) + { + return 1; + } + } +#elif BR_MSC + int info[4]; + + __cpuid(info, 1); + if (((uint32_t)info[0] & mask_eax) == mask_eax + && ((uint32_t)info[1] & mask_ebx) == mask_ebx + && ((uint32_t)info[2] & mask_ecx) == mask_ecx + && ((uint32_t)info[3] & mask_edx) == mask_edx) + { + return 1; + } +#endif + return 0; +} + +#endif + +#endif + +/* ==================================================================== */ + +#endif + + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/md5.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/md5.c new file mode 100644 index 000000000..c7751fab1 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/md5.c @@ -0,0 +1,213 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +#define F(B, C, D) ((((C) ^ (D)) & (B)) ^ (D)) +#define G(B, C, D) ((((C) ^ (B)) & (D)) ^ (C)) +#define H(B, C, D) ((B) ^ (C) ^ (D)) +#define I(B, C, D) ((C) ^ ((B) | ~(D))) + +#define ROTL(x, n) (((x) << (n)) | ((x) >> (32 - (n)))) + +/* see inner.h */ +const uint32_t br_md5_IV[4] = { + 0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476 +}; + +static const uint32_t K[64] = { + 0xD76AA478, 0xE8C7B756, 0x242070DB, 0xC1BDCEEE, + 0xF57C0FAF, 0x4787C62A, 0xA8304613, 0xFD469501, + 0x698098D8, 0x8B44F7AF, 0xFFFF5BB1, 0x895CD7BE, + 0x6B901122, 0xFD987193, 0xA679438E, 0x49B40821, + + 0xF61E2562, 0xC040B340, 0x265E5A51, 0xE9B6C7AA, + 0xD62F105D, 0x02441453, 0xD8A1E681, 0xE7D3FBC8, + 0x21E1CDE6, 0xC33707D6, 0xF4D50D87, 0x455A14ED, + 0xA9E3E905, 0xFCEFA3F8, 0x676F02D9, 0x8D2A4C8A, + + 0xFFFA3942, 0x8771F681, 0x6D9D6122, 0xFDE5380C, + 0xA4BEEA44, 0x4BDECFA9, 0xF6BB4B60, 0xBEBFBC70, + 0x289B7EC6, 0xEAA127FA, 0xD4EF3085, 0x04881D05, + 0xD9D4D039, 0xE6DB99E5, 0x1FA27CF8, 0xC4AC5665, + + 0xF4292244, 0x432AFF97, 0xAB9423A7, 0xFC93A039, + 0x655B59C3, 0x8F0CCC92, 0xFFEFF47D, 0x85845DD1, + 0x6FA87E4F, 0xFE2CE6E0, 0xA3014314, 0x4E0811A1, + 0xF7537E82, 0xBD3AF235, 0x2AD7D2BB, 0xEB86D391 +}; + +static const unsigned char MP[48] = { + 1, 6, 11, 0, 5, 10, 15, 4, 9, 14, 3, 8, 13, 2, 7, 12, + 5, 8, 11, 14, 1, 4, 7, 10, 13, 0, 3, 6, 9, 12, 15, 2, + 0, 7, 14, 5, 12, 3, 10, 1, 8, 15, 6, 13, 4, 11, 2, 9 +}; + +/* see inner.h */ +void +br_md5_round(const unsigned char *buf, uint32_t *val) +{ + uint32_t m[16]; + uint32_t a, b, c, d; + int i; + + a = val[0]; + b = val[1]; + c = val[2]; + d = val[3]; + /* obsolete + for (i = 0; i < 16; i ++) { + m[i] = br_dec32le(buf + (i << 2)); + } + */ + br_range_dec32le(m, 16, buf); + + for (i = 0; i < 16; i += 4) { + a = b + ROTL(a + F(b, c, d) + m[i + 0] + K[i + 0], 7); + d = a + ROTL(d + F(a, b, c) + m[i + 1] + K[i + 1], 12); + c = d + ROTL(c + F(d, a, b) + m[i + 2] + K[i + 2], 17); + b = c + ROTL(b + F(c, d, a) + m[i + 3] + K[i + 3], 22); + } + for (i = 16; i < 32; i += 4) { + a = b + ROTL(a + G(b, c, d) + m[MP[i - 16]] + K[i + 0], 5); + d = a + ROTL(d + G(a, b, c) + m[MP[i - 15]] + K[i + 1], 9); + c = d + ROTL(c + G(d, a, b) + m[MP[i - 14]] + K[i + 2], 14); + b = c + ROTL(b + G(c, d, a) + m[MP[i - 13]] + K[i + 3], 20); + } + for (i = 32; i < 48; i += 4) { + a = b + ROTL(a + H(b, c, d) + m[MP[i - 16]] + K[i + 0], 4); + d = a + ROTL(d + H(a, b, c) + m[MP[i - 15]] + K[i + 1], 11); + c = d + ROTL(c + H(d, a, b) + m[MP[i - 14]] + K[i + 2], 16); + b = c + ROTL(b + H(c, d, a) + m[MP[i - 13]] + K[i + 3], 23); + } + for (i = 48; i < 64; i += 4) { + a = b + ROTL(a + I(b, c, d) + m[MP[i - 16]] + K[i + 0], 6); + d = a + ROTL(d + I(a, b, c) + m[MP[i - 15]] + K[i + 1], 10); + c = d + ROTL(c + I(d, a, b) + m[MP[i - 14]] + K[i + 2], 15); + b = c + ROTL(b + I(c, d, a) + m[MP[i - 13]] + K[i + 3], 21); + } + + val[0] += a; + val[1] += b; + val[2] += c; + val[3] += d; +} + +/* see bearssl.h */ +void +br_md5_init(br_md5_context *cc) +{ + cc->vtable = &br_md5_vtable; + memcpy(cc->val, br_md5_IV, sizeof cc->val); + cc->count = 0; +} + +/* see bearssl.h */ +void +br_md5_update(br_md5_context *cc, const void *data, size_t len) +{ + const unsigned char *buf; + size_t ptr; + + buf = data; + ptr = (size_t)cc->count & 63; + while (len > 0) { + size_t clen; + + clen = 64 - ptr; + if (clen > len) { + clen = len; + } + memcpy(cc->buf + ptr, buf, clen); + ptr += clen; + buf += clen; + len -= clen; + cc->count += (uint64_t)clen; + if (ptr == 64) { + br_md5_round(cc->buf, cc->val); + ptr = 0; + } + } +} + +/* see bearssl.h */ +void +br_md5_out(const br_md5_context *cc, void *dst) +{ + unsigned char buf[64]; + uint32_t val[4]; + size_t ptr; + + ptr = (size_t)cc->count & 63; + memcpy(buf, cc->buf, ptr); + memcpy(val, cc->val, sizeof val); + buf[ptr ++] = 0x80; + if (ptr > 56) { + memset(buf + ptr, 0, 64 - ptr); + br_md5_round(buf, val); + memset(buf, 0, 56); + } else { + memset(buf + ptr, 0, 56 - ptr); + } + br_enc64le(buf + 56, cc->count << 3); + br_md5_round(buf, val); + br_range_enc32le(dst, val, 4); +} + +/* see bearssl.h */ +uint64_t +br_md5_state(const br_md5_context *cc, void *dst) +{ + br_range_enc32le(dst, cc->val, 4); + return cc->count; +} + +/* see bearssl.h */ +void +br_md5_set_state(br_md5_context *cc, const void *stb, uint64_t count) +{ + br_range_dec32le(cc->val, 4, stb); + cc->count = count; +} + +/* see bearssl.h */ +const br_hash_class br_md5_vtable = { + sizeof(br_md5_context), + BR_HASHDESC_ID(br_md5_ID) + | BR_HASHDESC_OUT(16) + | BR_HASHDESC_STATE(16) + | BR_HASHDESC_LBLEN(6) + | BR_HASHDESC_MD_PADDING, + (void (*)(const br_hash_class **))&br_md5_init, + (void (*)(const br_hash_class **, const void *, size_t))&br_md5_update, + (void (*)(const br_hash_class *const *, void *))&br_md5_out, + (uint64_t (*)(const br_hash_class *const *, void *))&br_md5_state, + (void (*)(const br_hash_class **, const void *, uint64_t)) + &br_md5_set_state +}; + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/md5sha1.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/md5sha1.c new file mode 100644 index 000000000..aceb4ec5c --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/md5sha1.c @@ -0,0 +1,146 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl.h */ +void +br_md5sha1_init(br_md5sha1_context *cc) +{ + cc->vtable = &br_md5sha1_vtable; + memcpy(cc->val_md5, br_md5_IV, sizeof cc->val_md5); + memcpy(cc->val_sha1, br_sha1_IV, sizeof cc->val_sha1); + cc->count = 0; +} + +/* see bearssl.h */ +void +br_md5sha1_update(br_md5sha1_context *cc, const void *data, size_t len) +{ + const unsigned char *buf; + size_t ptr; + + buf = data; + ptr = (size_t)cc->count & 63; + while (len > 0) { + size_t clen; + + clen = 64 - ptr; + if (clen > len) { + clen = len; + } + memcpy(cc->buf + ptr, buf, clen); + ptr += clen; + buf += clen; + len -= clen; + cc->count += (uint64_t)clen; + if (ptr == 64) { + br_md5_round(cc->buf, cc->val_md5); + br_sha1_round(cc->buf, cc->val_sha1); + ptr = 0; + } + } +} + +/* see bearssl.h */ +void +br_md5sha1_out(const br_md5sha1_context *cc, void *dst) +{ + unsigned char buf[64]; + uint32_t val_md5[4]; + uint32_t val_sha1[5]; + size_t ptr; + unsigned char *out; + uint64_t count; + + count = cc->count; + ptr = (size_t)count & 63; + memcpy(buf, cc->buf, ptr); + memcpy(val_md5, cc->val_md5, sizeof val_md5); + memcpy(val_sha1, cc->val_sha1, sizeof val_sha1); + buf[ptr ++] = 0x80; + if (ptr > 56) { + memset(buf + ptr, 0, 64 - ptr); + br_md5_round(buf, val_md5); + br_sha1_round(buf, val_sha1); + memset(buf, 0, 56); + } else { + memset(buf + ptr, 0, 56 - ptr); + } + count <<= 3; + br_enc64le(buf + 56, count); + br_md5_round(buf, val_md5); + br_enc64be(buf + 56, count); + br_sha1_round(buf, val_sha1); + out = dst; + br_range_enc32le(out, val_md5, 4); + br_range_enc32be(out + 16, val_sha1, 5); +} + +/* see bearssl.h */ +uint64_t +br_md5sha1_state(const br_md5sha1_context *cc, void *dst) +{ + unsigned char *out; + + out = dst; + br_range_enc32le(out, cc->val_md5, 4); + br_range_enc32be(out + 16, cc->val_sha1, 5); + return cc->count; +} + +/* see bearssl.h */ +void +br_md5sha1_set_state(br_md5sha1_context *cc, const void *stb, uint64_t count) +{ + const unsigned char *buf; + + buf = stb; + br_range_dec32le(cc->val_md5, 4, buf); + br_range_dec32be(cc->val_sha1, 5, buf + 16); + cc->count = count; +} + +/* see bearssl.h */ +const br_hash_class br_md5sha1_vtable = { + sizeof(br_md5sha1_context), + BR_HASHDESC_ID(br_md5sha1_ID) + | BR_HASHDESC_OUT(36) + | BR_HASHDESC_STATE(36) + | BR_HASHDESC_LBLEN(6), + (void (*)(const br_hash_class **))&br_md5sha1_init, + (void (*)(const br_hash_class **, const void *, size_t)) + &br_md5sha1_update, + (void (*)(const br_hash_class *const *, void *)) + &br_md5sha1_out, + (uint64_t (*)(const br_hash_class *const *, void *)) + &br_md5sha1_state, + (void (*)(const br_hash_class **, const void *, uint64_t)) + &br_md5sha1_set_state +}; + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/mgf1.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/mgf1.c new file mode 100644 index 000000000..596fbc3b9 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/mgf1.c @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +void +br_mgf1_xor(void *data, size_t len, + const br_hash_class *dig, const void *seed, size_t seed_len) +{ + unsigned char *buf; + size_t u, hlen; + uint32_t c; + + buf = data; + hlen = br_digest_size(dig); + for (u = 0, c = 0; u < len; u += hlen, c ++) { + br_hash_compat_context hc; + unsigned char tmp[64]; + size_t v; + + hc.vtable = dig; + dig->init(&hc.vtable); + dig->update(&hc.vtable, seed, seed_len); + br_enc32be(tmp, c); + dig->update(&hc.vtable, tmp, 4); + dig->out(&hc.vtable, tmp); + for (v = 0; v < hlen; v ++) { + if ((u + v) >= len) { + break; + } + buf[u + v] ^= tmp[v]; + } + } +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/multihash.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/multihash.c new file mode 100644 index 000000000..9ad2567a8 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/multihash.c @@ -0,0 +1,171 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* + * An aggregate context that is large enough for all supported hash + * functions. + */ +typedef union { + const br_hash_class *vtable; + br_md5_context md5; + br_sha1_context sha1; + br_sha224_context sha224; + br_sha256_context sha256; + br_sha384_context sha384; + br_sha512_context sha512; +} gen_hash_context; + +/* + * Get the offset to the state for a specific hash function within the + * context structure. This shall be called only for the supported hash + * functions, + */ +static size_t +get_state_offset(int id) +{ + if (id >= 5) { + /* + * SHA-384 has id 5, and SHA-512 has id 6. Both use + * eight 64-bit words for their state. + */ + return offsetof(br_multihash_context, val_64) + + ((size_t)(id - 5) * (8 * sizeof(uint64_t))); + } else { + /* + * MD5 has id 1, SHA-1 has id 2, SHA-224 has id 3 and + * SHA-256 has id 4. They use 32-bit words for their + * states (4 words for MD5, 5 for SHA-1, 8 for SHA-224 + * and 8 for SHA-256). + */ + unsigned x; + + x = id - 1; + x = ((x + (x & (x >> 1))) << 2) + (x >> 1); + return offsetof(br_multihash_context, val_32) + + x * sizeof(uint32_t); + } +} + +/* see bearssl_hash.h */ +void +br_multihash_zero(br_multihash_context *ctx) +{ + /* + * This is not standard, but yields very short and efficient code, + * and it works "everywhere". + */ + memset(ctx, 0, sizeof *ctx); +} + +/* see bearssl_hash.h */ +void +br_multihash_init(br_multihash_context *ctx) +{ + int i; + + ctx->count = 0; + for (i = 1; i <= 6; i ++) { + const br_hash_class *hc; + + hc = ctx->impl[i - 1]; + if (hc != NULL) { + gen_hash_context g; + + hc->init(&g.vtable); + hc->state(&g.vtable, + (unsigned char *)ctx + get_state_offset(i)); + } + } +} + +/* see bearssl_hash.h */ +void +br_multihash_update(br_multihash_context *ctx, const void *data, size_t len) +{ + const unsigned char *buf; + size_t ptr; + + buf = data; + ptr = (size_t)ctx->count & 127; + while (len > 0) { + size_t clen; + + clen = 128 - ptr; + if (clen > len) { + clen = len; + } + memcpy(ctx->buf + ptr, buf, clen); + ptr += clen; + buf += clen; + len -= clen; + ctx->count += (uint64_t)clen; + if (ptr == 128) { + int i; + + for (i = 1; i <= 6; i ++) { + const br_hash_class *hc; + + hc = ctx->impl[i - 1]; + if (hc != NULL) { + gen_hash_context g; + unsigned char *state; + + state = (unsigned char *)ctx + + get_state_offset(i); + hc->set_state(&g.vtable, + state, ctx->count - 128); + hc->update(&g.vtable, ctx->buf, 128); + hc->state(&g.vtable, state); + } + } + ptr = 0; + } + } +} + +/* see bearssl_hash.h */ +size_t +br_multihash_out(const br_multihash_context *ctx, int id, void *dst) +{ + const br_hash_class *hc; + gen_hash_context g; + const unsigned char *state; + + hc = ctx->impl[id - 1]; + if (hc == NULL) { + return 0; + } + state = (const unsigned char *)ctx + get_state_offset(id); + hc->set_state(&g.vtable, state, ctx->count & ~(uint64_t)127); + hc->update(&g.vtable, ctx->buf, ctx->count & (uint64_t)127); + hc->out(&g.vtable, dst); + return (hc->desc >> BR_HASHDESC_OUT_OFF) & BR_HASHDESC_OUT_MASK; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/pemdec.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/pemdec.c new file mode 100644 index 000000000..7dd2c40cd --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/pemdec.c @@ -0,0 +1,531 @@ +/* Automatically generated code; do not modify directly. */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include +#include + +typedef struct { + uint32_t *dp; + uint32_t *rp; + const unsigned char *ip; +} t0_context; + +static uint32_t +t0_parse7E_unsigned(const unsigned char **p) +{ + uint32_t x; + + x = 0; + for (;;) { + unsigned y; + + y = *(*p) ++; + x = (x << 7) | (uint32_t)(y & 0x7F); + if (y < 0x80) { + return x; + } + } +} + +static int32_t +t0_parse7E_signed(const unsigned char **p) +{ + int neg; + uint32_t x; + + neg = ((**p) >> 6) & 1; + x = (uint32_t)-neg; + for (;;) { + unsigned y; + + y = *(*p) ++; + x = (x << 7) | (uint32_t)(y & 0x7F); + if (y < 0x80) { + if (neg) { + return -(int32_t)~x - 1; + } else { + return (int32_t)x; + } + } + } +} + +#define T0_VBYTE(x, n) (unsigned char)((((uint32_t)(x) >> (n)) & 0x7F) | 0x80) +#define T0_FBYTE(x, n) (unsigned char)(((uint32_t)(x) >> (n)) & 0x7F) +#define T0_SBYTE(x) (unsigned char)((((uint32_t)(x) >> 28) + 0xF8) ^ 0xF8) +#define T0_INT1(x) T0_FBYTE(x, 0) +#define T0_INT2(x) T0_VBYTE(x, 7), T0_FBYTE(x, 0) +#define T0_INT3(x) T0_VBYTE(x, 14), T0_VBYTE(x, 7), T0_FBYTE(x, 0) +#define T0_INT4(x) T0_VBYTE(x, 21), T0_VBYTE(x, 14), T0_VBYTE(x, 7), T0_FBYTE(x, 0) +#define T0_INT5(x) T0_SBYTE(x), T0_VBYTE(x, 21), T0_VBYTE(x, 14), T0_VBYTE(x, 7), T0_FBYTE(x, 0) + +/* static const unsigned char t0_datablock[]; */ + + +void br_pem_decoder_init_main(void *t0ctx); + +void br_pem_decoder_run(void *t0ctx); + + + +#include "inner.h" + +#define CTX ((br_pem_decoder_context *)(void *)((unsigned char *)t0ctx - offsetof(br_pem_decoder_context, cpu))) + +/* see bearssl_pem.h */ +void +br_pem_decoder_init(br_pem_decoder_context *ctx) +{ + memset(ctx, 0, sizeof *ctx); + ctx->cpu.dp = &ctx->dp_stack[0]; + ctx->cpu.rp = &ctx->rp_stack[0]; + br_pem_decoder_init_main(&ctx->cpu); + br_pem_decoder_run(&ctx->cpu); +} + +/* see bearssl_pem.h */ +size_t +br_pem_decoder_push(br_pem_decoder_context *ctx, + const void *data, size_t len) +{ + if (ctx->event) { + return 0; + } + ctx->hbuf = data; + ctx->hlen = len; + br_pem_decoder_run(&ctx->cpu); + return len - ctx->hlen; +} + +/* see bearssl_pem.h */ +int +br_pem_decoder_event(br_pem_decoder_context *ctx) +{ + int event; + + event = ctx->event; + ctx->event = 0; + return event; +} + + + +static const unsigned char t0_datablock[] = { + 0x00, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x42, 0x45, 0x47, 0x49, 0x4E, 0x20, + 0x00, 0x2D, 0x2D, 0x2D, 0x2D, 0x45, 0x4E, 0x44, 0x20, 0x00 +}; + +static const unsigned char t0_codeblock[] = { + 0x00, 0x01, 0x00, 0x09, 0x00, 0x00, 0x01, 0x01, 0x07, 0x00, 0x00, 0x01, + 0x01, 0x08, 0x00, 0x00, 0x13, 0x13, 0x00, 0x00, 0x01, + T0_INT2(offsetof(br_pem_decoder_context, event)), 0x00, 0x00, 0x01, + T0_INT2(offsetof(br_pem_decoder_context, name)), 0x00, 0x00, 0x05, + 0x14, 0x2C, 0x14, 0x01, 0x0A, 0x0D, 0x06, 0x03, 0x13, 0x04, 0x76, 0x01, + 0x2D, 0x0C, 0x06, 0x05, 0x2E, 0x01, 0x03, 0x2D, 0x00, 0x01, 0x0D, 0x27, + 0x05, 0x04, 0x01, 0x03, 0x2D, 0x00, 0x15, 0x2E, 0x01, 0x02, 0x2D, 0x00, + 0x01, 0x01, 0x7F, 0x03, 0x00, 0x25, 0x01, 0x00, 0x18, 0x0D, 0x06, 0x03, + 0x13, 0x04, 0x3C, 0x01, 0x7F, 0x18, 0x0D, 0x06, 0x13, 0x13, 0x02, 0x00, + 0x05, 0x06, 0x2E, 0x01, 0x03, 0x2D, 0x04, 0x03, 0x01, 0x7F, 0x23, 0x01, + 0x00, 0x00, 0x04, 0x23, 0x01, 0x01, 0x18, 0x0D, 0x06, 0x09, 0x13, 0x01, + 0x00, 0x23, 0x01, 0x00, 0x00, 0x04, 0x14, 0x01, 0x02, 0x18, 0x0D, 0x06, + 0x06, 0x13, 0x01, 0x7F, 0x00, 0x04, 0x08, 0x13, 0x01, 0x03, 0x2D, 0x01, + 0x00, 0x00, 0x13, 0x01, 0x00, 0x03, 0x00, 0x04, 0xFF, 0x33, 0x01, 0x2C, + 0x14, 0x01, 0x2D, 0x0D, 0x06, 0x04, 0x13, 0x01, 0x7F, 0x00, 0x14, 0x31, + 0x06, 0x02, 0x13, 0x29, 0x14, 0x01, 0x0A, 0x0D, 0x06, 0x04, 0x13, 0x01, + 0x02, 0x00, 0x16, 0x14, 0x1D, 0x06, 0x05, 0x13, 0x2E, 0x01, 0x03, 0x00, + 0x03, 0x00, 0x29, 0x14, 0x01, 0x0A, 0x0D, 0x06, 0x04, 0x13, 0x01, 0x03, + 0x00, 0x16, 0x14, 0x1D, 0x06, 0x05, 0x13, 0x2E, 0x01, 0x03, 0x00, 0x02, + 0x00, 0x01, 0x06, 0x0A, 0x07, 0x03, 0x00, 0x29, 0x14, 0x01, 0x0A, 0x0D, + 0x06, 0x04, 0x13, 0x01, 0x03, 0x00, 0x14, 0x01, 0x3D, 0x0D, 0x06, 0x2E, + 0x13, 0x29, 0x14, 0x01, 0x0A, 0x0D, 0x06, 0x04, 0x13, 0x01, 0x03, 0x00, + 0x2F, 0x05, 0x04, 0x13, 0x01, 0x03, 0x00, 0x01, 0x3D, 0x0C, 0x06, 0x03, + 0x01, 0x03, 0x00, 0x02, 0x00, 0x01, 0x0F, 0x10, 0x06, 0x03, 0x01, 0x03, + 0x00, 0x02, 0x00, 0x01, 0x04, 0x0F, 0x1C, 0x01, 0x01, 0x00, 0x16, 0x14, + 0x1D, 0x06, 0x05, 0x13, 0x2E, 0x01, 0x03, 0x00, 0x02, 0x00, 0x01, 0x06, + 0x0A, 0x07, 0x03, 0x00, 0x29, 0x14, 0x01, 0x0A, 0x0D, 0x06, 0x04, 0x13, + 0x01, 0x03, 0x00, 0x14, 0x01, 0x3D, 0x0D, 0x06, 0x20, 0x13, 0x2F, 0x05, + 0x03, 0x01, 0x03, 0x00, 0x02, 0x00, 0x01, 0x03, 0x10, 0x06, 0x03, 0x01, + 0x03, 0x00, 0x02, 0x00, 0x01, 0x0A, 0x0F, 0x1C, 0x02, 0x00, 0x01, 0x02, + 0x0F, 0x1C, 0x01, 0x01, 0x00, 0x16, 0x14, 0x1D, 0x06, 0x05, 0x13, 0x2E, + 0x01, 0x03, 0x00, 0x02, 0x00, 0x01, 0x06, 0x0A, 0x07, 0x03, 0x00, 0x02, + 0x00, 0x01, 0x10, 0x0F, 0x1C, 0x02, 0x00, 0x01, 0x08, 0x0F, 0x1C, 0x02, + 0x00, 0x1C, 0x01, 0x00, 0x00, 0x00, 0x28, 0x01, 0x01, 0x2D, 0x24, 0x06, + 0x02, 0x04, 0x7B, 0x04, 0x75, 0x00, 0x14, 0x12, 0x2A, 0x14, 0x05, 0x04, + 0x20, 0x01, 0x7F, 0x00, 0x2C, 0x2A, 0x14, 0x01, 0x0A, 0x0D, 0x06, 0x05, + 0x13, 0x20, 0x01, 0x00, 0x00, 0x0D, 0x05, 0x05, 0x13, 0x2E, 0x01, 0x00, + 0x00, 0x1E, 0x04, 0x5E, 0x00, 0x01, 0x01, 0x27, 0x06, 0x0B, 0x22, 0x01, + 0x80, 0x7F, 0x2B, 0x14, 0x06, 0x02, 0x30, 0x00, 0x13, 0x04, 0x6E, 0x00, + 0x2C, 0x14, 0x31, 0x05, 0x01, 0x00, 0x13, 0x04, 0x77, 0x00, 0x14, 0x14, + 0x01, 0x80, 0x61, 0x0E, 0x1B, 0x01, 0x80, 0x7A, 0x0B, 0x10, 0x06, 0x03, + 0x01, 0x20, 0x08, 0x00, 0x01, 0x14, 0x03, 0x00, 0x1B, 0x18, 0x05, 0x05, + 0x20, 0x2E, 0x01, 0x00, 0x00, 0x2C, 0x14, 0x01, 0x0A, 0x0D, 0x06, 0x06, + 0x20, 0x02, 0x00, 0x1B, 0x08, 0x00, 0x14, 0x01, 0x0D, 0x0D, 0x06, 0x03, + 0x13, 0x04, 0x03, 0x2A, 0x18, 0x1A, 0x1E, 0x1B, 0x1F, 0x1B, 0x04, 0x59, + 0x00, 0x19, 0x14, 0x1D, 0x05, 0x01, 0x00, 0x13, 0x11, 0x04, 0x76, 0x00, + 0x21, 0x1A, 0x11, 0x00, 0x00, 0x2C, 0x01, 0x0A, 0x0C, 0x06, 0x02, 0x04, + 0x78, 0x00, 0x01, 0x01, 0x7F, 0x03, 0x00, 0x2C, 0x14, 0x01, 0x0A, 0x0C, + 0x06, 0x09, 0x31, 0x05, 0x04, 0x01, 0x00, 0x03, 0x00, 0x04, 0x70, 0x13, + 0x02, 0x00, 0x00, 0x00, 0x14, 0x06, 0x14, 0x1F, 0x14, 0x22, 0x07, 0x17, + 0x01, 0x2D, 0x0C, 0x06, 0x08, 0x22, 0x07, 0x1E, 0x01, 0x00, 0x1B, 0x1A, + 0x00, 0x04, 0x69, 0x22, 0x1A, 0x00, 0x00, 0x14, 0x01, 0x0A, 0x0C, 0x1B, + 0x01, 0x20, 0x0B, 0x10, 0x00 +}; + +static const uint16_t t0_caddr[] = { + 0, + 5, + 10, + 15, + 19, + 24, + 29, + 67, + 149, + 384, + 396, + 431, + 450, + 460, + 479, + 523, + 534, + 539, + 549, + 574, + 601 +}; + +#define T0_INTERPRETED 29 + +#define T0_ENTER(ip, rp, slot) do { \ + const unsigned char *t0_newip; \ + uint32_t t0_lnum; \ + t0_newip = &t0_codeblock[t0_caddr[(slot) - T0_INTERPRETED]]; \ + t0_lnum = t0_parse7E_unsigned(&t0_newip); \ + (rp) += t0_lnum; \ + *((rp) ++) = (uint32_t)((ip) - &t0_codeblock[0]) + (t0_lnum << 16); \ + (ip) = t0_newip; \ + } while (0) + +#define T0_DEFENTRY(name, slot) \ +void \ +name(void *ctx) \ +{ \ + t0_context *t0ctx = ctx; \ + t0ctx->ip = &t0_codeblock[0]; \ + T0_ENTER(t0ctx->ip, t0ctx->rp, slot); \ +} + +T0_DEFENTRY(br_pem_decoder_init_main, 38) + +#define T0_NEXT(t0ipp) (*(*(t0ipp)) ++) + +void +br_pem_decoder_run(void *t0ctx) +{ + uint32_t *dp, *rp; + const unsigned char *ip; + +#define T0_LOCAL(x) (*(rp - 2 - (x))) +#define T0_POP() (*-- dp) +#define T0_POPi() (*(int32_t *)(-- dp)) +#define T0_PEEK(x) (*(dp - 1 - (x))) +#define T0_PEEKi(x) (*(int32_t *)(dp - 1 - (x))) +#define T0_PUSH(v) do { *dp = (v); dp ++; } while (0) +#define T0_PUSHi(v) do { *(int32_t *)dp = (v); dp ++; } while (0) +#define T0_RPOP() (*-- rp) +#define T0_RPOPi() (*(int32_t *)(-- rp)) +#define T0_RPUSH(v) do { *rp = (v); rp ++; } while (0) +#define T0_RPUSHi(v) do { *(int32_t *)rp = (v); rp ++; } while (0) +#define T0_ROLL(x) do { \ + size_t t0len = (size_t)(x); \ + uint32_t t0tmp = *(dp - 1 - t0len); \ + memmove(dp - t0len - 1, dp - t0len, t0len * sizeof *dp); \ + *(dp - 1) = t0tmp; \ +} while (0) +#define T0_SWAP() do { \ + uint32_t t0tmp = *(dp - 2); \ + *(dp - 2) = *(dp - 1); \ + *(dp - 1) = t0tmp; \ +} while (0) +#define T0_ROT() do { \ + uint32_t t0tmp = *(dp - 3); \ + *(dp - 3) = *(dp - 2); \ + *(dp - 2) = *(dp - 1); \ + *(dp - 1) = t0tmp; \ +} while (0) +#define T0_NROT() do { \ + uint32_t t0tmp = *(dp - 1); \ + *(dp - 1) = *(dp - 2); \ + *(dp - 2) = *(dp - 3); \ + *(dp - 3) = t0tmp; \ +} while (0) +#define T0_PICK(x) do { \ + uint32_t t0depth = (x); \ + T0_PUSH(T0_PEEK(t0depth)); \ +} while (0) +#define T0_CO() do { \ + goto t0_exit; \ +} while (0) +#define T0_RET() goto t0_next + + dp = ((t0_context *)t0ctx)->dp; + rp = ((t0_context *)t0ctx)->rp; + ip = ((t0_context *)t0ctx)->ip; + goto t0_next; + for (;;) { + uint32_t t0x; + + t0_next: + t0x = T0_NEXT(&ip); + if (t0x < T0_INTERPRETED) { + switch (t0x) { + int32_t t0off; + + case 0: /* ret */ + t0x = T0_RPOP(); + rp -= (t0x >> 16); + t0x &= 0xFFFF; + if (t0x == 0) { + ip = NULL; + goto t0_exit; + } + ip = &t0_codeblock[t0x]; + break; + case 1: /* literal constant */ + T0_PUSHi(t0_parse7E_signed(&ip)); + break; + case 2: /* read local */ + T0_PUSH(T0_LOCAL(t0_parse7E_unsigned(&ip))); + break; + case 3: /* write local */ + T0_LOCAL(t0_parse7E_unsigned(&ip)) = T0_POP(); + break; + case 4: /* jump */ + t0off = t0_parse7E_signed(&ip); + ip += t0off; + break; + case 5: /* jump if */ + t0off = t0_parse7E_signed(&ip); + if (T0_POP()) { + ip += t0off; + } + break; + case 6: /* jump if not */ + t0off = t0_parse7E_signed(&ip); + if (!T0_POP()) { + ip += t0off; + } + break; + case 7: { + /* + */ + + uint32_t b = T0_POP(); + uint32_t a = T0_POP(); + T0_PUSH(a + b); + + } + break; + case 8: { + /* - */ + + uint32_t b = T0_POP(); + uint32_t a = T0_POP(); + T0_PUSH(a - b); + + } + break; + case 9: { + /* < */ + + int32_t b = T0_POPi(); + int32_t a = T0_POPi(); + T0_PUSH(-(uint32_t)(a < b)); + + } + break; + case 10: { + /* << */ + + int c = (int)T0_POPi(); + uint32_t x = T0_POP(); + T0_PUSH(x << c); + + } + break; + case 11: { + /* <= */ + + int32_t b = T0_POPi(); + int32_t a = T0_POPi(); + T0_PUSH(-(uint32_t)(a <= b)); + + } + break; + case 12: { + /* <> */ + + uint32_t b = T0_POP(); + uint32_t a = T0_POP(); + T0_PUSH(-(uint32_t)(a != b)); + + } + break; + case 13: { + /* = */ + + uint32_t b = T0_POP(); + uint32_t a = T0_POP(); + T0_PUSH(-(uint32_t)(a == b)); + + } + break; + case 14: { + /* >= */ + + int32_t b = T0_POPi(); + int32_t a = T0_POPi(); + T0_PUSH(-(uint32_t)(a >= b)); + + } + break; + case 15: { + /* >> */ + + int c = (int)T0_POPi(); + int32_t x = T0_POPi(); + T0_PUSHi(x >> c); + + } + break; + case 16: { + /* and */ + + uint32_t b = T0_POP(); + uint32_t a = T0_POP(); + T0_PUSH(a & b); + + } + break; + case 17: { + /* co */ + T0_CO(); + } + break; + case 18: { + /* data-get8 */ + + size_t addr = T0_POP(); + T0_PUSH(t0_datablock[addr]); + + } + break; + case 19: { + /* drop */ + (void)T0_POP(); + } + break; + case 20: { + /* dup */ + T0_PUSH(T0_PEEK(0)); + } + break; + case 21: { + /* flush-buf */ + + if (CTX->ptr > 0) { + if (CTX->dest) { + CTX->dest(CTX->dest_ctx, CTX->buf, CTX->ptr); + } + CTX->ptr = 0; + } + + } + break; + case 22: { + /* from-base64 */ + + uint32_t c = T0_POP(); + uint32_t p, q, r, z; + p = c - 0x41; + q = c - 0x61; + r = c - 0x30; + + z = ((p + 2) & -LT(p, 26)) + | ((q + 28) & -LT(q, 26)) + | ((r + 54) & -LT(r, 10)) + | (64 & -EQ(c, 0x2B)) + | (65 & -EQ(c, 0x2F)) + | EQ(c, 0x3D); + T0_PUSHi((int32_t)z - 2); + + } + break; + case 23: { + /* get8 */ + + size_t addr = T0_POP(); + T0_PUSH(*((unsigned char *)CTX + addr)); + + } + break; + case 24: { + /* over */ + T0_PUSH(T0_PEEK(1)); + } + break; + case 25: { + /* read8-native */ + + if (CTX->hlen > 0) { + T0_PUSH(*CTX->hbuf ++); + CTX->hlen --; + } else { + T0_PUSHi(-1); + } + + } + break; + case 26: { + /* set8 */ + + size_t addr = T0_POP(); + unsigned x = T0_POP(); + *((unsigned char *)CTX + addr) = x; + + } + break; + case 27: { + /* swap */ + T0_SWAP(); + } + break; + case 28: { + /* write8 */ + + unsigned char x = (unsigned char)T0_POP(); + CTX->buf[CTX->ptr ++] = x; + if (CTX->ptr == sizeof CTX->buf) { + if (CTX->dest) { + CTX->dest(CTX->dest_ctx, CTX->buf, sizeof CTX->buf); + } + CTX->ptr = 0; + } + + } + break; + } + + } else { + T0_ENTER(ip, rp, t0x); + } + } +t0_exit: + ((t0_context *)t0ctx)->dp = dp; + ((t0_context *)t0ctx)->rp = rp; + ((t0_context *)t0ctx)->ip = ip; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/pemdec.t0 b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/pemdec.t0 new file mode 100644 index 000000000..2237abbfe --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/pemdec.t0 @@ -0,0 +1,314 @@ +\ Copyright (c) 2016 Thomas Pornin +\ +\ Permission is hereby granted, free of charge, to any person obtaining +\ a copy of this software and associated documentation files (the +\ "Software"), to deal in the Software without restriction, including +\ without limitation the rights to use, copy, modify, merge, publish, +\ distribute, sublicense, and/or sell copies of the Software, and to +\ permit persons to whom the Software is furnished to do so, subject to +\ the following conditions: +\ +\ The above copyright notice and this permission notice shall be +\ included in all copies or substantial portions of the Software. +\ +\ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +\ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +\ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +\ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +\ BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +\ ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +\ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +\ SOFTWARE. + +preamble { + +#include "inner.h" + +#define CTX ((br_pem_decoder_context *)(void *)((unsigned char *)t0ctx - offsetof(br_pem_decoder_context, cpu))) + +/* see bearssl_pem.h */ +void +br_pem_decoder_init(br_pem_decoder_context *ctx) +{ + memset(ctx, 0, sizeof *ctx); + ctx->cpu.dp = &ctx->dp_stack[0]; + ctx->cpu.rp = &ctx->rp_stack[0]; + br_pem_decoder_init_main(&ctx->cpu); + br_pem_decoder_run(&ctx->cpu); +} + +/* see bearssl_pem.h */ +size_t +br_pem_decoder_push(br_pem_decoder_context *ctx, + const void *data, size_t len) +{ + if (ctx->event) { + return 0; + } + ctx->hbuf = data; + ctx->hlen = len; + br_pem_decoder_run(&ctx->cpu); + return len - ctx->hlen; +} + +/* see bearssl_pem.h */ +int +br_pem_decoder_event(br_pem_decoder_context *ctx) +{ + int event; + + event = ctx->event; + ctx->event = 0; + return event; +} + +} + +\ Define a word that evaluates to the address of a field within the +\ decoder context. +: addr: + next-word { field } + "addr-" field + 0 1 define-word + 0 8191 "offsetof(br_pem_decoder_context, " field + ")" + make-CX + postpone literal postpone ; ; + +addr: event +addr: name +addr: buf +addr: ptr + +\ Set a byte at a specific address (offset within the context). +cc: set8 ( value addr -- ) { + size_t addr = T0_POP(); + unsigned x = T0_POP(); + *((unsigned char *)CTX + addr) = x; +} + +\ Get a byte at a specific address (offset within the context). +cc: get8 ( addr -- value ) { + size_t addr = T0_POP(); + T0_PUSH(*((unsigned char *)CTX + addr)); +} + +\ Send an event. +: send-event ( event -- ) + addr-event set8 co ; + +\ Low-level function to read a single byte. Returned value is the byte +\ (0 to 255), or -1 if there is no available data. +cc: read8-native ( -- x ) { + if (CTX->hlen > 0) { + T0_PUSH(*CTX->hbuf ++); + CTX->hlen --; + } else { + T0_PUSHi(-1); + } +} + +\ Read next byte. Block until the next byte is available. +: read8 ( -- x ) + begin read8-native dup 0< ifnot ret then drop co again ; + +\ Read bytes until next end-of-line. +: skip-newline ( -- ) + begin read8 `\n <> while repeat ; + +\ Read bytes until next end-of-line; verify that they are all whitespace. +\ This returns -1 if they were all whitespace, 0 otherwise. +: skip-newline-ws ( -- bool ) + -1 { r } + begin read8 dup `\n <> while ws? ifnot 0 >r then repeat + drop r ; + +\ Normalise a byte to uppercase (ASCII only). +: norm-upper ( x -- x ) + dup dup `a >= swap `z <= and if 32 - then ; + +\ Read bytes and compare with the provided string. On mismatch, the +\ rest of the line is consumed. Matching is not case sensitive. +: match-string ( str -- bool ) + begin + dup data-get8 norm-upper dup ifnot 2drop -1 ret then + read8 norm-upper dup `\n = if drop 2drop 0 ret then + = ifnot drop skip-newline 0 ret then + 1+ + again ; + +\ Read bytes into the provided buffer, but no more than the provided +\ count. Reading stops when end-of-line is reached. Returned value +\ is the count of bytes written to the buffer, or 0 if the buffer size +\ was exceeded. All bytes are normalised to uppercase (ASCII only). +: read-bytes ( addr len -- len ) + dup { orig-len } + swap + begin + over ifnot 2drop skip-newline 0 ret then + read8 dup `\n = if 2drop orig-len swap - ret then + dup `\r = if drop else norm-upper over set8 then + 1+ swap 1- swap + again ; + +\ Remove trailing dashes from the name buffer. +: trim-dashes ( len -- ) + begin dup while + 1- + dup addr-name + get8 `- <> if + addr-name + 1+ 0 swap set8 ret + then + repeat + addr-name set8 ; + +\ Scan input for next "begin" banner. +: next-banner-begin ( -- ) + begin + "-----BEGIN " match-string if + addr-name 127 read-bytes + dup if trim-dashes ret then + drop + then + again ; + +\ Convert a Base64 character to its numerical value. Returned value is +\ 0 to 63 for Base64 characters, -1 for '=', and -2 for all other characters. +cc: from-base64 ( char -- x ) { + uint32_t c = T0_POP(); + uint32_t p, q, r, z; + p = c - 0x41; + q = c - 0x61; + r = c - 0x30; + + z = ((p + 2) & -LT(p, 26)) + | ((q + 28) & -LT(q, 26)) + | ((r + 54) & -LT(r, 10)) + | (64 & -EQ(c, 0x2B)) + | (65 & -EQ(c, 0x2F)) + | EQ(c, 0x3D); + T0_PUSHi((int32_t)z - 2); +} + +\ Test whether a character is whitespace (but not a newline). +: ws? ( x -- bool ) + dup `\n <> swap 32 <= and ; + +\ Read next character, skipping whitespace (except newline). +: next-nonws ( -- x ) + begin + read8 dup ws? ifnot ret then + drop + again ; + +\ Write one byte in the output buffer. +cc: write8 ( x -- ) { + unsigned char x = (unsigned char)T0_POP(); + CTX->buf[CTX->ptr ++] = x; + if (CTX->ptr == sizeof CTX->buf) { + if (CTX->dest) { + CTX->dest(CTX->dest_ctx, CTX->buf, sizeof CTX->buf); + } + CTX->ptr = 0; + } +} + +\ Flush the output buffer. +cc: flush-buf ( -- ) { + if (CTX->ptr > 0) { + if (CTX->dest) { + CTX->dest(CTX->dest_ctx, CTX->buf, CTX->ptr); + } + CTX->ptr = 0; + } +} + +\ Decode the four next Base64 characters. Returned value is: +\ 0 quartet processed, three bytes produced. +\ -1 dash encountered as first character (no leading whitespace). +\ 1 quartet processed, one or two bytes produced, terminator reached. +\ 2 end-of-line reached. +\ 3 error. +\ For all positive return values, the remaining of the current line has been +\ consumed. +: decode-next-quartet ( -- r ) + \ Process first character. It may be a dash. + read8 dup `- = if drop -1 ret then + dup ws? if drop next-nonws then + dup `\n = if drop 2 ret then + from-base64 dup 0< if drop skip-newline 3 ret then + { acc } + + \ Second character. + next-nonws dup `\n = if drop 3 ret then + from-base64 dup 0< if drop skip-newline 3 ret then + acc 6 << + >acc + + \ Third character: may be an equal sign. + next-nonws dup `\n = if drop 3 ret then + dup `= = if + \ Fourth character must be an equal sign. + drop + next-nonws dup `\n = if drop 3 ret then + skip-newline-ws ifnot drop 3 ret then + `= <> if 3 ret then + acc 0x0F and if 3 ret then + acc 4 >> write8 + 1 ret + then + from-base64 dup 0< if drop skip-newline 3 ret then + acc 6 << + >acc + + \ Fourth character: may be an equal sign. + next-nonws dup `\n = if drop 3 ret then + dup `= = if + drop skip-newline-ws ifnot 3 ret then + acc 0x03 and if 3 ret then + acc 10 >> write8 + acc 2 >> write8 + 1 ret + then + from-base64 dup 0< if drop skip-newline 3 ret then + acc 6 << + >acc + acc 16 >> write8 + acc 8 >> write8 + acc write8 + 0 ; + +\ Check trailer line (possibly, the leading dash has been read). This +\ sends the appropriate event. +: check-trailer ( bool -- ) + ifnot + begin read8 dup `\n = while drop repeat + `- <> if skip-newline 3 send-event ret then + then + "----END " match-string ifnot 3 send-event ret then + flush-buf + skip-newline 2 send-event ; + +\ Decode one line worth of characters. Returned value is 0 if the end of the +\ object is reached, -1 otherwise. The end of object or error event is sent. +: decode-line ( -- bool ) + -1 { first } + begin + decode-next-quartet + case + 0 of endof + -1 of + first ifnot + skip-newline 3 send-event + else + -1 check-trailer + then + 0 ret + endof + 1 of 0 check-trailer 0 ret endof + 2 of -1 ret endof + + \ On decoding error + drop 3 send-event 0 ret + endcase + 0 >first + again ; + +: main ( -- ! ) + begin + next-banner-begin 1 send-event + begin decode-line while repeat + again ; diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/pemenc.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/pemenc.c new file mode 100644 index 000000000..03cfc2bd9 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/pemenc.c @@ -0,0 +1,178 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* + * Get the appropriate Base64 character for a numeric value in the + * 0..63 range. This is constant-time. + */ +static char +b64char(uint32_t x) +{ + /* + * Values 0 to 25 map to 0x41..0x5A ('A' to 'Z') + * Values 26 to 51 map to 0x61..0x7A ('a' to 'z') + * Values 52 to 61 map to 0x30..0x39 ('0' to '9') + * Value 62 maps to 0x2B ('+') + * Value 63 maps to 0x2F ('/') + */ + uint32_t a, b, c; + + a = x - 26; + b = x - 52; + c = x - 62; + + /* + * Looking at bits 8..15 of values a, b and c: + * + * x a b c + * --------------------- + * 0..25 FF FF FF + * 26..51 00 FF FF + * 52..61 00 00 FF + * 62..63 00 00 00 + */ + return (char)(((x + 0x41) & ((a & b & c) >> 8)) + | ((x + (0x61 - 26)) & ((~a & b & c) >> 8)) + | ((x - (52 - 0x30)) & ((~a & ~b & c) >> 8)) + | ((0x2B + ((x & 1) << 2)) & (~(a | b | c) >> 8))); +} + +/* see bearssl_pem.h */ +size_t +br_pem_encode(void *dest, const void *data, size_t len, + const char *banner, unsigned flags) +{ + size_t dlen, banner_len, lines; + char *d; + unsigned char *buf; + size_t u; + int off, lim; + + banner_len = strlen(banner); + /* FIXME: try to avoid divisions here, as they may pull + an extra libc function. */ + if ((flags & BR_PEM_LINE64) != 0) { + lines = (len + 47) / 48; + } else { + lines = (len + 56) / 57; + } + dlen = (banner_len << 1) + 30 + (((len + 2) / 3) << 2) + + lines + 2; + if ((flags & BR_PEM_CRLF) != 0) { + dlen += lines + 2; + } + + if (dest == NULL) { + return dlen; + } + + d = dest; + + /* + * We always move the source data to the end of output buffer; + * the encoding process never "catches up" except at the very + * end. This also handles all conditions of partial or total + * overlap. + */ + buf = (unsigned char *)d + dlen - len; + memmove(buf, data, len); + + memcpy(d, "-----BEGIN ", 11); + d += 11; + memcpy(d, banner, banner_len); + d += banner_len; + memcpy(d, "-----", 5); + d += 5; + if ((flags & BR_PEM_CRLF) != 0) { + *d ++ = 0x0D; + } + *d ++ = 0x0A; + + off = 0; + lim = (flags & BR_PEM_LINE64) != 0 ? 16 : 19; + for (u = 0; (u + 2) < len; u += 3) { + uint32_t w; + + w = ((uint32_t)buf[u] << 16) + | ((uint32_t)buf[u + 1] << 8) + | (uint32_t)buf[u + 2]; + *d ++ = b64char(w >> 18); + *d ++ = b64char((w >> 12) & 0x3F); + *d ++ = b64char((w >> 6) & 0x3F); + *d ++ = b64char(w & 0x3F); + if (++ off == lim) { + off = 0; + if ((flags & BR_PEM_CRLF) != 0) { + *d ++ = 0x0D; + } + *d ++ = 0x0A; + } + } + if (u < len) { + uint32_t w; + + w = (uint32_t)buf[u] << 16; + if (u + 1 < len) { + w |= (uint32_t)buf[u + 1] << 8; + } + *d ++ = b64char(w >> 18); + *d ++ = b64char((w >> 12) & 0x3F); + if (u + 1 < len) { + *d ++ = b64char((w >> 6) & 0x3F); + } else { + *d ++ = 0x3D; + } + *d ++ = 0x3D; + off ++; + } + if (off != 0) { + if ((flags & BR_PEM_CRLF) != 0) { + *d ++ = 0x0D; + } + *d ++ = 0x0A; + } + + memcpy(d, "-----END ", 9); + d += 9; + memcpy(d, banner, banner_len); + d += banner_len; + memcpy(d, "-----", 5); + d += 5; + if ((flags & BR_PEM_CRLF) != 0) { + *d ++ = 0x0D; + } + *d ++ = 0x0A; + + /* Final zero, not counted in returned length. */ + *d ++ = 0x00; + + return dlen; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/pkey_decoder.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/pkey_decoder.c new file mode 100644 index 000000000..88d001ba0 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/pkey_decoder.c @@ -0,0 +1,626 @@ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include +#include +#if defined __has_include +#if __has_include() +#include +#endif +#endif + +#if !defined(PROGMEM) +#define PROGMEM +#define PGM_READ_BYTE * +#define MEMCMP_P memcmp +#define MEMCPY_P memcpy +#else +#define PROGMEM_SUPPORTED +#define PGM_READ_BYTE pgm_read_byte +#define MEMCMP_P memcmp_P +#define MEMCPY_P memcpy_P +#endif + + + +#include "inner.h" + + +typedef struct { + uint32_t *dp; + uint32_t *rp; + const unsigned char *ip; +} t0_context; + +static uint32_t +t0_parse7E_unsigned(const unsigned char **p) +{ + uint32_t x; + + x = 0; + for (;;) { + unsigned y; + + y = PGM_READ_BYTE((*p)++); + x = (x << 7) | (uint32_t)(y & 0x7F); + if (y < 0x80) { + return x; + } + } +} + +static int32_t +t0_parse7E_signed(const unsigned char **p) +{ + int neg; + uint32_t x; + + neg = (PGM_READ_BYTE(*p) >> 6) & 1; + x = (uint32_t)-neg; + for (;;) { + unsigned y; + + y = PGM_READ_BYTE((*p)++); + x = (x << 7) | (uint32_t)(y & 0x7F); + if (y < 0x80) { + if (neg) { + return -(int32_t)~x - 1; + } else { + return (int32_t)x; + } + } + } +} + +#define T0_VBYTE(x, n) (unsigned char)((((uint32_t)(x) >> (n)) & 0x7F) | 0x80) +#define T0_FBYTE(x, n) (unsigned char)(((uint32_t)(x) >> (n)) & 0x7F) +#define T0_SBYTE(x) (unsigned char)((((uint32_t)(x) >> 28) + 0xF8) ^ 0xF8) +#define T0_INT1(x) T0_FBYTE(x, 0) +#define T0_INT2(x) T0_VBYTE(x, 7), T0_FBYTE(x, 0) +#define T0_INT3(x) T0_VBYTE(x, 14), T0_VBYTE(x, 7), T0_FBYTE(x, 0) +#define T0_INT4(x) T0_VBYTE(x, 21), T0_VBYTE(x, 14), T0_VBYTE(x, 7), T0_FBYTE(x, 0) +#define T0_INT5(x) T0_SBYTE(x), T0_VBYTE(x, 21), T0_VBYTE(x, 14), T0_VBYTE(x, 7), T0_FBYTE(x, 0) + +/* static const unsigned char t0_datablock[]; */ + + +void br_pkey_decoder_init_main(void *t0ctx); + +void br_pkey_decoder_run(void *t0ctx); + + + +#include "inner.h" + + + + + +#include "inner.h" + +#define CTX ((br_pkey_decoder_context *)(void *)((unsigned char *)t0ctx - offsetof(br_pkey_decoder_context, cpu))) +#define CONTEXT_NAME br_pkey_decoder_context + +/* see bearssl_x509.h */ +void +br_pkey_decoder_init(br_pkey_decoder_context *ctx) +{ + memset(ctx, 0, sizeof *ctx); + ctx->cpu.dp = &ctx->dp_stack[0]; + ctx->cpu.rp = &ctx->rp_stack[0]; + br_pkey_decoder_init_main(&ctx->cpu); + br_pkey_decoder_run(&ctx->cpu); +} + +/* see bearssl_x509.h */ +void +br_pkey_decoder_push(br_pkey_decoder_context *ctx, + const void *data, size_t len) +{ + ctx->hbuf = data; + ctx->hlen = len; + br_pkey_decoder_run(&ctx->cpu); +} + + + +static const unsigned char t0_datablock[] PROGMEM = { + + 0x00, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, 0x07, + 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x02, 0x01, 0x08, 0x2A, 0x86, 0x48, 0xCE, + 0x3D, 0x03, 0x01, 0x07, 0x05, 0x2B, 0x81, 0x04, 0x00, 0x22, 0x05, 0x2B, + 0x81, 0x04, 0x00, 0x23 +}; + +static const unsigned char t0_codeblock[] PROGMEM = { + + 0x00, 0x01, 0x01, 0x07, 0x00, 0x00, 0x01, 0x01, 0x08, 0x00, 0x00, 0x12, + 0x12, 0x00, 0x00, 0x01, T0_INT1(BR_ERR_X509_BAD_TAG_CLASS), 0x00, 0x00, + 0x01, T0_INT1(BR_ERR_X509_BAD_TAG_VALUE), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_X509_EXTRA_ELEMENT), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_X509_INDEFINITE_LENGTH), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_X509_INNER_TRUNC), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_X509_LIMIT_EXCEEDED), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_X509_NOT_CONSTRUCTED), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_X509_NOT_PRIMITIVE), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_X509_OVERFLOW), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_X509_UNEXPECTED), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_X509_UNSUPPORTED), 0x00, 0x00, 0x01, + T0_INT1(BR_KEYTYPE_EC), 0x00, 0x00, 0x01, T0_INT1(BR_KEYTYPE_RSA), + 0x00, 0x00, 0x01, T0_INT2(offsetof(CONTEXT_NAME, key_data)), 0x00, + 0x00, 0x01, T0_INT2(offsetof(CONTEXT_NAME, key_type)), 0x00, 0x00, + 0x2F, 0x43, 0x00, 0x00, 0x01, T0_INT2(offsetof(CONTEXT_NAME, pad)), + 0x00, 0x00, 0x01, 0x13, 0x00, 0x00, 0x01, 0x1C, 0x00, 0x00, 0x01, 0x22, + 0x00, 0x00, 0x05, 0x02, 0x28, 0x15, 0x00, 0x00, 0x06, 0x02, 0x29, 0x15, + 0x00, 0x00, 0x01, 0x10, 0x39, 0x00, 0x00, 0x0C, 0x05, 0x02, 0x2B, 0x15, + 0x36, 0x00, 0x00, 0x0C, 0x05, 0x02, 0x2B, 0x15, 0x37, 0x00, 0x00, 0x06, + 0x02, 0x24, 0x15, 0x00, 0x01, 0x03, 0x00, 0x51, 0x06, 0x02, 0x2C, 0x15, + 0x50, 0x01, 0x04, 0x3A, 0x02, 0x00, 0x3D, 0x00, 0x02, 0x03, 0x00, 0x13, + 0x03, 0x01, 0x02, 0x01, 0x43, 0x0D, 0x06, 0x02, 0x2C, 0x15, 0x02, 0x01, + 0x2F, 0x47, 0x12, 0x01, 0x00, 0x02, 0x00, 0x05, 0x02, 0x2C, 0x15, 0x02, + 0x00, 0x02, 0x01, 0x1B, 0x00, 0x02, 0x4D, 0x46, 0x05, 0x02, 0x2C, 0x15, + 0x53, 0x14, 0x06, 0x07, 0x55, 0x01, 0x7F, 0x03, 0x01, 0x04, 0x16, 0x42, + 0x14, 0x06, 0x10, 0x01, 0x00, 0x03, 0x01, 0x13, 0x06, 0x03, 0x48, 0x04, + 0x02, 0x01, 0x00, 0x03, 0x00, 0x04, 0x02, 0x2C, 0x15, 0x3B, 0x50, 0x01, + 0x03, 0x3A, 0x4D, 0x02, 0x01, 0x06, 0x03, 0x3F, 0x04, 0x03, 0x02, 0x00, + 0x3C, 0x3B, 0x55, 0x02, 0x01, 0x06, 0x03, 0x2E, 0x04, 0x01, 0x2D, 0x00, + 0x00, 0x51, 0x06, 0x02, 0x2C, 0x15, 0x4E, 0x40, 0x3B, 0x00, 0x03, 0x31, + 0x49, 0x13, 0x13, 0x03, 0x00, 0x03, 0x01, 0x4B, 0x03, 0x02, 0x02, 0x00, + 0x02, 0x02, 0x1C, 0x00, 0x00, 0x17, 0x17, 0x00, 0x00, 0x01, 0x0B, 0x00, + 0x00, 0x01, T0_INT2(3 * BR_X509_BUFSIZE_KEY), 0x00, 0x01, 0x01, 0x87, + 0xFF, 0xFF, 0x7F, 0x4E, 0x50, 0x01, 0x02, 0x17, 0x0C, 0x06, 0x06, 0x12, + 0x37, 0x40, 0x2E, 0x04, 0x1C, 0x01, 0x04, 0x17, 0x0C, 0x06, 0x08, 0x12, + 0x37, 0x01, 0x00, 0x3D, 0x2D, 0x04, 0x0E, 0x01, 0x10, 0x17, 0x0C, 0x06, + 0x05, 0x12, 0x36, 0x3E, 0x04, 0x03, 0x2C, 0x15, 0x12, 0x03, 0x00, 0x3B, + 0x02, 0x00, 0x30, 0x1D, 0x52, 0x24, 0x15, 0x00, 0x01, 0x41, 0x0A, 0x06, + 0x02, 0x26, 0x15, 0x13, 0x03, 0x00, 0x08, 0x02, 0x00, 0x00, 0x00, 0x50, + 0x01, 0x06, 0x3A, 0x4F, 0x00, 0x00, 0x1E, 0x13, 0x06, 0x07, 0x18, 0x13, + 0x06, 0x01, 0x11, 0x04, 0x76, 0x21, 0x00, 0x00, 0x46, 0x05, 0x02, 0x2C, + 0x15, 0x33, 0x14, 0x06, 0x04, 0x01, 0x17, 0x04, 0x12, 0x34, 0x14, 0x06, + 0x04, 0x01, 0x18, 0x04, 0x0A, 0x35, 0x14, 0x06, 0x04, 0x01, 0x19, 0x04, + 0x02, 0x2C, 0x15, 0x00, 0x00, 0x1A, 0x50, 0x01, 0x02, 0x3A, 0x09, 0x4A, + 0x00, 0x03, 0x13, 0x03, 0x00, 0x03, 0x01, 0x03, 0x02, 0x4D, 0x51, 0x13, + 0x01, 0x81, 0x00, 0x0E, 0x06, 0x02, 0x2A, 0x15, 0x13, 0x01, 0x00, 0x0C, + 0x06, 0x0B, 0x12, 0x13, 0x05, 0x04, 0x12, 0x01, 0x00, 0x00, 0x51, 0x04, + 0x6F, 0x02, 0x01, 0x13, 0x05, 0x02, 0x27, 0x15, 0x20, 0x03, 0x01, 0x02, + 0x02, 0x1D, 0x02, 0x02, 0x1F, 0x03, 0x02, 0x13, 0x06, 0x03, 0x51, 0x04, + 0x68, 0x12, 0x02, 0x00, 0x02, 0x01, 0x08, 0x00, 0x00, 0x13, 0x31, 0x1A, + 0x08, 0x1E, 0x1A, 0x07, 0x1E, 0x49, 0x00, 0x01, 0x51, 0x13, 0x01, 0x81, + 0x00, 0x0A, 0x06, 0x01, 0x00, 0x01, 0x81, 0x00, 0x08, 0x13, 0x05, 0x02, + 0x25, 0x15, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x0D, 0x06, + 0x19, 0x02, 0x00, 0x20, 0x03, 0x00, 0x13, 0x01, 0x83, 0xFF, 0xFF, 0x7F, + 0x0D, 0x06, 0x02, 0x26, 0x15, 0x01, 0x08, 0x0B, 0x1E, 0x51, 0x1A, 0x07, + 0x04, 0x60, 0x00, 0x00, 0x4C, 0x45, 0x00, 0x00, 0x50, 0x38, 0x4D, 0x00, + 0x00, 0x4D, 0x13, 0x01, 0x81, 0x7F, 0x0D, 0x06, 0x08, 0x54, 0x01, 0x00, + 0x32, 0x1D, 0x01, 0x00, 0x00, 0x13, 0x32, 0x1D, 0x32, 0x1F, 0x47, 0x01, + 0x7F, 0x00, 0x01, 0x51, 0x03, 0x00, 0x02, 0x00, 0x01, 0x05, 0x0F, 0x01, + 0x01, 0x10, 0x16, 0x02, 0x00, 0x01, 0x06, 0x0F, 0x13, 0x01, 0x01, 0x10, + 0x06, 0x02, 0x22, 0x15, 0x01, 0x04, 0x0B, 0x02, 0x00, 0x01, 0x1F, 0x10, + 0x13, 0x01, 0x1F, 0x0C, 0x06, 0x02, 0x23, 0x15, 0x07, 0x00, 0x00, 0x13, + 0x05, 0x02, 0x26, 0x15, 0x20, 0x52, 0x00, 0x00, 0x19, 0x13, 0x01, 0x00, + 0x0E, 0x06, 0x01, 0x00, 0x12, 0x11, 0x04, 0x74, 0x00, 0x01, 0x01, 0x00, + 0x00, 0x55, 0x12, 0x00, 0x00, 0x13, 0x06, 0x07, 0x56, 0x13, 0x06, 0x01, + 0x11, 0x04, 0x76, 0x00, 0x00, 0x01, 0x00, 0x17, 0x18, 0x09, 0x21, 0x00 +}; + +static const uint16_t t0_caddr[] PROGMEM = { + + 0, + 5, + 10, + 14, + 18, + 22, + 26, + 30, + 34, + 38, + 42, + 46, + 50, + 54, + 58, + 62, + 66, + 71, + 76, + 80, + 85, + 89, + 93, + 97, + 103, + 109, + 114, + 122, + 130, + 136, + 152, + 185, + 252, + 262, + 280, + 284, + 288, + 293, + 352, + 366, + 373, + 387, + 420, + 429, + 496, + 507, + 563, + 567, + 572, + 598, + 642, + 651, + 664, + 668, + 672, + 684 +}; + +#define T0_INTERPRETED 31 + +#if defined(PROGMEM_SUPPORTED) +#define T0_ENTER(ip, rp, slot) do { \ + const unsigned char *t0_newip; \ + uint32_t t0_lnum; \ + t0_newip = &t0_codeblock[pgm_read_word(&t0_caddr[(slot) - T0_INTERPRETED])]; \ + t0_lnum = t0_parse7E_unsigned(&t0_newip); \ + (rp) += t0_lnum; \ + *((rp) ++) = (uint32_t)((ip) - &t0_codeblock[0]) + (t0_lnum << 16); \ + (ip) = t0_newip; \ + } while (0) +#else +#define T0_ENTER(ip, rp, slot) do { \ + const unsigned char *t0_newip; \ + uint32_t t0_lnum; \ + t0_newip = &t0_codeblock[t0_caddr[(slot) - T0_INTERPRETED]]; \ + t0_lnum = t0_parse7E_unsigned(&t0_newip); \ + (rp) += t0_lnum; \ + *((rp) ++) = (uint32_t)((ip) - &t0_codeblock[0]) + (t0_lnum << 16); \ + (ip) = t0_newip; \ + } while (0) +#endif + + + +#define T0_DEFENTRY(name, slot) \ +void \ +name(void *ctx) \ +{ \ + t0_context *t0ctx = ctx; \ + t0ctx->ip = &t0_codeblock[0]; \ + T0_ENTER(t0ctx->ip, t0ctx->rp, slot); \ +} + +T0_DEFENTRY(br_pkey_decoder_init_main, 68) + +#define T0_NEXT(t0ipp) (PGM_READ_BYTE((*t0ipp)++)) + +void +br_pkey_decoder_run(void *t0ctx) +{ + uint32_t *dp, *rp; + const unsigned char *ip; + +#define T0_LOCAL(x) (*(rp - 2 - (x))) +#define T0_POP() (*-- dp) +#define T0_POPi() (*(int32_t *)(-- dp)) +#define T0_PEEK(x) (*(dp - 1 - (x))) +#define T0_PEEKi(x) (*(int32_t *)(dp - 1 - (x))) +#define T0_PUSH(v) do { *dp = (v); dp ++; } while (0) +#define T0_PUSHi(v) do { *(int32_t *)dp = (v); dp ++; } while (0) +#define T0_RPOP() (*-- rp) +#define T0_RPOPi() (*(int32_t *)(-- rp)) +#define T0_RPUSH(v) do { *rp = (v); rp ++; } while (0) +#define T0_RPUSHi(v) do { *(int32_t *)rp = (v); rp ++; } while (0) +#define T0_ROLL(x) do { \ + size_t t0len = (size_t)(x); \ + uint32_t t0tmp = *(dp - 1 - t0len); \ + memmove(dp - t0len - 1, dp - t0len, t0len * sizeof *dp); \ + *(dp - 1) = t0tmp; \ +} while (0) +#define T0_SWAP() do { \ + uint32_t t0tmp = *(dp - 2); \ + *(dp - 2) = *(dp - 1); \ + *(dp - 1) = t0tmp; \ +} while (0) +#define T0_ROT() do { \ + uint32_t t0tmp = *(dp - 3); \ + *(dp - 3) = *(dp - 2); \ + *(dp - 2) = *(dp - 1); \ + *(dp - 1) = t0tmp; \ +} while (0) +#define T0_NROT() do { \ + uint32_t t0tmp = *(dp - 1); \ + *(dp - 1) = *(dp - 2); \ + *(dp - 2) = *(dp - 3); \ + *(dp - 3) = t0tmp; \ +} while (0) +#define T0_PICK(x) do { \ + uint32_t t0depth = (x); \ + T0_PUSH(T0_PEEK(t0depth)); \ +} while (0) +#define T0_CO() do { \ + goto t0_exit; \ +} while (0) +#define T0_RET() goto t0_next + + dp = ((t0_context *)t0ctx)->dp; + rp = ((t0_context *)t0ctx)->rp; + ip = ((t0_context *)t0ctx)->ip; + goto t0_next; + for (;;) { + uint32_t t0x; + + t0_next: + t0x = T0_NEXT(&ip); + if (t0x < T0_INTERPRETED) { + switch (t0x) { + int32_t t0off; + + case 0: /* ret */ + t0x = T0_RPOP(); + rp -= (t0x >> 16); + t0x &= 0xFFFF; + if (t0x == 0) { + ip = NULL; + goto t0_exit; + } + ip = &t0_codeblock[t0x]; + break; + case 1: /* literal constant */ + T0_PUSHi(t0_parse7E_signed(&ip)); + break; + case 2: /* read local */ + T0_PUSH(T0_LOCAL(t0_parse7E_unsigned(&ip))); + break; + case 3: /* write local */ + T0_LOCAL(t0_parse7E_unsigned(&ip)) = T0_POP(); + break; + case 4: /* jump */ + t0off = t0_parse7E_signed(&ip); + ip += t0off; + break; + case 5: /* jump if */ + t0off = t0_parse7E_signed(&ip); + if (T0_POP()) { + ip += t0off; + } + break; + case 6: /* jump if not */ + t0off = t0_parse7E_signed(&ip); + if (!T0_POP()) { + ip += t0off; + } + break; + case 7: { + /* + */ + + uint32_t b = T0_POP(); + uint32_t a = T0_POP(); + T0_PUSH(a + b); + + } + break; + case 8: { + /* - */ + + uint32_t b = T0_POP(); + uint32_t a = T0_POP(); + T0_PUSH(a - b); + + } + break; + case 9: { + /* -rot */ + T0_NROT(); + } + break; + case 10: { + /* < */ + + int32_t b = T0_POPi(); + int32_t a = T0_POPi(); + T0_PUSH(-(uint32_t)(a < b)); + + } + break; + case 11: { + /* << */ + + int c = (int)T0_POPi(); + uint32_t x = T0_POP(); + T0_PUSH(x << c); + + } + break; + case 12: { + /* = */ + + uint32_t b = T0_POP(); + uint32_t a = T0_POP(); + T0_PUSH(-(uint32_t)(a == b)); + + } + break; + case 13: { + /* > */ + + int32_t b = T0_POPi(); + int32_t a = T0_POPi(); + T0_PUSH(-(uint32_t)(a > b)); + + } + break; + case 14: { + /* >= */ + + int32_t b = T0_POPi(); + int32_t a = T0_POPi(); + T0_PUSH(-(uint32_t)(a >= b)); + + } + break; + case 15: { + /* >> */ + + int c = (int)T0_POPi(); + int32_t x = T0_POPi(); + T0_PUSHi(x >> c); + + } + break; + case 16: { + /* and */ + + uint32_t b = T0_POP(); + uint32_t a = T0_POP(); + T0_PUSH(a & b); + + } + break; + case 17: { + /* co */ + T0_CO(); + } + break; + case 18: { + /* drop */ + (void)T0_POP(); + } + break; + case 19: { + /* dup */ + T0_PUSH(T0_PEEK(0)); + } + break; + case 20: { + /* eqOID */ + + const unsigned char *a2 = &t0_datablock[T0_POP()]; + const unsigned char *a1 = &CTX->pad[0]; + size_t len = a1[0]; + int x; + if (len == PGM_READ_BYTE(&a2[0])) { + x = -(MEMCMP_P(a1 + 1, a2 + 1, len) == 0); + } else { + x = 0; + } + T0_PUSH((uint32_t)x); + + } + break; + case 21: { + /* fail */ + + CTX->err = T0_POPi(); + T0_CO(); + + } + break; + case 22: { + /* neg */ + + uint32_t a = T0_POP(); + T0_PUSH(-a); + + } + break; + case 23: { + /* over */ + T0_PUSH(T0_PEEK(1)); + } + break; + case 24: { + /* read-blob-inner */ + + uint32_t len = T0_POP(); + uint32_t addr = T0_POP(); + size_t clen = CTX->hlen; + if (clen > len) { + clen = (size_t)len; + } + if (addr != 0) { + MEMCPY_P((unsigned char *)CTX + addr, CTX->hbuf, clen); + } + CTX->hbuf += clen; + CTX->hlen -= clen; + T0_PUSH(addr + clen); + T0_PUSH(len - clen); + + } + break; + case 25: { + /* read8-low */ + + if (CTX->hlen == 0) { + T0_PUSHi(-1); + } else { + CTX->hlen --; + T0_PUSH(PGM_READ_BYTE(CTX->hbuf ++)); + } + + } + break; + case 26: { + /* rot */ + T0_ROT(); + } + break; + case 27: { + /* set-ec-key */ + + size_t qlen = T0_POP(); + uint32_t curve = T0_POP(); + CTX->key.ec.curve = curve; + CTX->key.ec.q = CTX->key_data; + CTX->key.ec.qlen = qlen; + + } + break; + case 28: { + /* set-rsa-key */ + + size_t elen = T0_POP(); + size_t nlen = T0_POP(); + + CTX->key.rsa.n = CTX->key_data; + CTX->key.rsa.nlen = nlen; + CTX->key.rsa.e = CTX->key_data + nlen; + CTX->key.rsa.elen = elen; + + } + break; + case 29: { + /* set8 */ + + uint32_t addr = T0_POP(); + *((unsigned char *)CTX + addr) = (unsigned char)T0_POP(); + + } + break; + case 30: { + /* swap */ + T0_SWAP(); + } + break; + } + + } else { + T0_ENTER(ip, rp, t0x); + } + } +t0_exit: + ((t0_context *)t0ctx)->dp = dp; + ((t0_context *)t0ctx)->rp = rp; + ((t0_context *)t0ctx)->ip = ip; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/poly1305_ctmul.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/poly1305_ctmul.c new file mode 100644 index 000000000..4095c344d --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/poly1305_ctmul.c @@ -0,0 +1,265 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* + * Perform the inner processing of blocks for Poly1305. The accumulator + * and the r key are provided as arrays of 26-bit words (these words + * are allowed to have an extra bit, i.e. use 27 bits). + * + * On output, all accumulator words fit on 26 bits, except acc[1], which + * may be slightly larger (but by a very small amount only). + */ +static void +poly1305_inner(uint32_t *acc, const uint32_t *r, const void *data, size_t len) +{ + /* + * Implementation notes: we split the 130-bit values into five + * 26-bit words. This gives us some space for carries. + * + * This code is inspired from the public-domain code available + * on: + * https://github.com/floodyberry/poly1305-donna + * + * Since we compute modulo 2^130-5, the "upper words" become + * low words with a factor of 5; that is, x*2^130 = x*5 mod p. + */ + const unsigned char *buf; + uint32_t a0, a1, a2, a3, a4; + uint32_t r0, r1, r2, r3, r4; + uint32_t u1, u2, u3, u4; + + r0 = r[0]; + r1 = r[1]; + r2 = r[2]; + r3 = r[3]; + r4 = r[4]; + + u1 = r1 * 5; + u2 = r2 * 5; + u3 = r3 * 5; + u4 = r4 * 5; + + a0 = acc[0]; + a1 = acc[1]; + a2 = acc[2]; + a3 = acc[3]; + a4 = acc[4]; + + buf = data; + while (len > 0) { + uint64_t w0, w1, w2, w3, w4; + uint64_t c; + unsigned char tmp[16]; + + /* + * If there is a partial block, right-pad it with zeros. + */ + if (len < 16) { + memset(tmp, 0, sizeof tmp); + memcpy(tmp, buf, len); + buf = tmp; + len = 16; + } + + /* + * Decode next block and apply the "high bit"; that value + * is added to the accumulator. + */ + a0 += br_dec32le(buf) & 0x03FFFFFF; + a1 += (br_dec32le(buf + 3) >> 2) & 0x03FFFFFF; + a2 += (br_dec32le(buf + 6) >> 4) & 0x03FFFFFF; + a3 += (br_dec32le(buf + 9) >> 6) & 0x03FFFFFF; + a4 += (br_dec32le(buf + 12) >> 8) | 0x01000000; + + /* + * Compute multiplication. + */ +#define M(x, y) ((uint64_t)(x) * (uint64_t)(y)) + + w0 = M(a0, r0) + M(a1, u4) + M(a2, u3) + M(a3, u2) + M(a4, u1); + w1 = M(a0, r1) + M(a1, r0) + M(a2, u4) + M(a3, u3) + M(a4, u2); + w2 = M(a0, r2) + M(a1, r1) + M(a2, r0) + M(a3, u4) + M(a4, u3); + w3 = M(a0, r3) + M(a1, r2) + M(a2, r1) + M(a3, r0) + M(a4, u4); + w4 = M(a0, r4) + M(a1, r3) + M(a2, r2) + M(a3, r1) + M(a4, r0); + +#undef M + /* + * Perform some (partial) modular reduction. This step is + * enough to keep values in ranges such that there won't + * be carry overflows. Most of the reduction was done in + * the multiplication step (by using the 'u*' values, and + * using the fact that 2^130 = -5 mod p); here we perform + * some carry propagation. + */ + c = w0 >> 26; + a0 = (uint32_t)w0 & 0x3FFFFFF; + w1 += c; + c = w1 >> 26; + a1 = (uint32_t)w1 & 0x3FFFFFF; + w2 += c; + c = w2 >> 26; + a2 = (uint32_t)w2 & 0x3FFFFFF; + w3 += c; + c = w3 >> 26; + a3 = (uint32_t)w3 & 0x3FFFFFF; + w4 += c; + c = w4 >> 26; + a4 = (uint32_t)w4 & 0x3FFFFFF; + a0 += (uint32_t)c * 5; + a1 += a0 >> 26; + a0 &= 0x3FFFFFF; + + buf += 16; + len -= 16; + } + + acc[0] = a0; + acc[1] = a1; + acc[2] = a2; + acc[3] = a3; + acc[4] = a4; +} + +/* see bearssl_block.h */ +void +br_poly1305_ctmul_run(const void *key, const void *iv, + void *data, size_t len, const void *aad, size_t aad_len, + void *tag, br_chacha20_run ichacha, int encrypt) +{ + unsigned char pkey[32], foot[16]; + uint32_t r[5], acc[5], cc, ctl, hi; + uint64_t w; + int i; + + /* + * Compute the MAC key. The 'r' value is the first 16 bytes of + * pkey[]. + */ + memset(pkey, 0, sizeof pkey); + ichacha(key, iv, 0, pkey, sizeof pkey); + + /* + * If encrypting, ChaCha20 must run first, followed by Poly1305. + * When decrypting, the operations are reversed. + */ + if (encrypt) { + ichacha(key, iv, 1, data, len); + } + + /* + * Run Poly1305. We must process the AAD, then ciphertext, then + * the footer (with the lengths). Note that the AAD and ciphertext + * are meant to be padded with zeros up to the next multiple of 16, + * and the length of the footer is 16 bytes as well. + */ + + /* + * Decode the 'r' value into 26-bit words, with the "clamping" + * operation applied. + */ + r[0] = br_dec32le(pkey) & 0x03FFFFFF; + r[1] = (br_dec32le(pkey + 3) >> 2) & 0x03FFFF03; + r[2] = (br_dec32le(pkey + 6) >> 4) & 0x03FFC0FF; + r[3] = (br_dec32le(pkey + 9) >> 6) & 0x03F03FFF; + r[4] = (br_dec32le(pkey + 12) >> 8) & 0x000FFFFF; + + /* + * Accumulator is 0. + */ + memset(acc, 0, sizeof acc); + + /* + * Process the additional authenticated data, ciphertext, and + * footer in due order. + */ + br_enc64le(foot, (uint64_t)aad_len); + br_enc64le(foot + 8, (uint64_t)len); + poly1305_inner(acc, r, aad, aad_len); + poly1305_inner(acc, r, data, len); + poly1305_inner(acc, r, foot, sizeof foot); + + /* + * Finalise modular reduction. This is done with carry propagation + * and applying the '2^130 = -5 mod p' rule. Note that the output + * of poly1035_inner() is already mostly reduced, since only + * acc[1] may be (very slightly) above 2^26. A single loop back + * to acc[1] will be enough to make the value fit in 130 bits. + */ + cc = 0; + for (i = 1; i <= 6; i ++) { + int j; + + j = (i >= 5) ? i - 5 : i; + acc[j] += cc; + cc = acc[j] >> 26; + acc[j] &= 0x03FFFFFF; + } + + /* + * We may still have a value in the 2^130-5..2^130-1 range, in + * which case we must reduce it again. The code below selects, + * in constant-time, between 'acc' and 'acc-p', + */ + ctl = GT(acc[0], 0x03FFFFFA); + for (i = 1; i < 5; i ++) { + ctl &= EQ(acc[i], 0x03FFFFFF); + } + cc = 5; + for (i = 0; i < 5; i ++) { + uint32_t t; + + t = (acc[i] + cc); + cc = t >> 26; + t &= 0x03FFFFFF; + acc[i] = MUX(ctl, t, acc[i]); + } + + /* + * Convert back the accumulator to 32-bit words, and add the + * 's' value (second half of pkey[]). That addition is done + * modulo 2^128. + */ + w = (uint64_t)acc[0] + ((uint64_t)acc[1] << 26) + br_dec32le(pkey + 16); + br_enc32le((unsigned char *)tag, (uint32_t)w); + w = (w >> 32) + ((uint64_t)acc[2] << 20) + br_dec32le(pkey + 20); + br_enc32le((unsigned char *)tag + 4, (uint32_t)w); + w = (w >> 32) + ((uint64_t)acc[3] << 14) + br_dec32le(pkey + 24); + br_enc32le((unsigned char *)tag + 8, (uint32_t)w); + hi = (uint32_t)(w >> 32) + (acc[4] << 8) + br_dec32le(pkey + 28); + br_enc32le((unsigned char *)tag + 12, hi); + + /* + * If decrypting, then ChaCha20 runs _after_ Poly1305. + */ + if (!encrypt) { + ichacha(key, iv, 1, data, len); + } +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/poly1305_ctmul32.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/poly1305_ctmul32.c new file mode 100644 index 000000000..6b171ad7b --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/poly1305_ctmul32.c @@ -0,0 +1,302 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* + * Perform the inner processing of blocks for Poly1305. + */ +static void +poly1305_inner(uint32_t *a, const uint32_t *r, const void *data, size_t len) +{ + /* + * Implementation notes: we split the 130-bit values into ten + * 13-bit words. This gives us some space for carries and allows + * using only 32x32->32 multiplications, which are way faster than + * 32x32->64 multiplications on the ARM Cortex-M0/M0+, and also + * help in making constant-time code on the Cortex-M3. + * + * Since we compute modulo 2^130-5, the "upper words" become + * low words with a factor of 5; that is, x*2^130 = x*5 mod p. + * This has already been integrated in the r[] array, which + * is extended to the 0..18 range. + * + * In each loop iteration, a[] and r[] words are 13-bit each, + * except a[1] which may use 14 bits. + */ + const unsigned char *buf; + + buf = data; + while (len > 0) { + unsigned char tmp[16]; + uint32_t b[10]; + unsigned u, v; + uint32_t z, cc1, cc2; + + /* + * If there is a partial block, right-pad it with zeros. + */ + if (len < 16) { + memset(tmp, 0, sizeof tmp); + memcpy(tmp, buf, len); + buf = tmp; + len = 16; + } + + /* + * Decode next block and apply the "high bit"; that value + * is added to the accumulator. + */ + v = br_dec16le(buf); + a[0] += v & 0x01FFF; + v >>= 13; + v |= buf[2] << 3; + v |= buf[3] << 11; + a[1] += v & 0x01FFF; + v >>= 13; + v |= buf[4] << 6; + a[2] += v & 0x01FFF; + v >>= 13; + v |= buf[5] << 1; + v |= buf[6] << 9; + a[3] += v & 0x01FFF; + v >>= 13; + v |= buf[7] << 4; + v |= buf[8] << 12; + a[4] += v & 0x01FFF; + v >>= 13; + v |= buf[9] << 7; + a[5] += v & 0x01FFF; + v >>= 13; + v |= buf[10] << 2; + v |= buf[11] << 10; + a[6] += v & 0x01FFF; + v >>= 13; + v |= buf[12] << 5; + a[7] += v & 0x01FFF; + v = br_dec16le(buf + 13); + a[8] += v & 0x01FFF; + v >>= 13; + v |= buf[15] << 3; + a[9] += v | 0x00800; + + /* + * At that point, all a[] values fit on 14 bits, while + * all r[] values fit on 13 bits. Thus products fit on + * 27 bits, and we can accumulate up to 31 of them in + * a 32-bit word and still have some room for carries. + */ + + /* + * Now a[] contains words with values up to 14 bits each. + * We perform the multiplication with r[]. + * + * The extended words of r[] may be larger than 13 bits + * (they are 5 times a 13-bit word) so the full summation + * may yield values up to 46 times a 27-bit word, which + * does not fit on a 32-bit word. To avoid that issue, we + * must split the loop below in two, with a carry + * propagation operation in the middle. + */ + cc1 = 0; + for (u = 0; u < 10; u ++) { + uint32_t s; + + s = cc1 + + MUL15(a[0], r[u + 9 - 0]) + + MUL15(a[1], r[u + 9 - 1]) + + MUL15(a[2], r[u + 9 - 2]) + + MUL15(a[3], r[u + 9 - 3]) + + MUL15(a[4], r[u + 9 - 4]); + b[u] = s & 0x1FFF; + cc1 = s >> 13; + } + cc2 = 0; + for (u = 0; u < 10; u ++) { + uint32_t s; + + s = b[u] + cc2 + + MUL15(a[5], r[u + 9 - 5]) + + MUL15(a[6], r[u + 9 - 6]) + + MUL15(a[7], r[u + 9 - 7]) + + MUL15(a[8], r[u + 9 - 8]) + + MUL15(a[9], r[u + 9 - 9]); + b[u] = s & 0x1FFF; + cc2 = s >> 13; + } + memcpy(a, b, sizeof b); + + /* + * The two carries "loop back" with a factor of 5. We + * propagate them into a[0] and a[1]. + */ + z = cc1 + cc2; + z += (z << 2) + a[0]; + a[0] = z & 0x1FFF; + a[1] += z >> 13; + + buf += 16; + len -= 16; + } +} + +/* see bearssl_block.h */ +void +br_poly1305_ctmul32_run(const void *key, const void *iv, + void *data, size_t len, const void *aad, size_t aad_len, + void *tag, br_chacha20_run ichacha, int encrypt) +{ + unsigned char pkey[32], foot[16]; + uint32_t z, r[19], acc[10], cc, ctl; + int i; + + /* + * Compute the MAC key. The 'r' value is the first 16 bytes of + * pkey[]. + */ + memset(pkey, 0, sizeof pkey); + ichacha(key, iv, 0, pkey, sizeof pkey); + + /* + * If encrypting, ChaCha20 must run first, followed by Poly1305. + * When decrypting, the operations are reversed. + */ + if (encrypt) { + ichacha(key, iv, 1, data, len); + } + + /* + * Run Poly1305. We must process the AAD, then ciphertext, then + * the footer (with the lengths). Note that the AAD and ciphertext + * are meant to be padded with zeros up to the next multiple of 16, + * and the length of the footer is 16 bytes as well. + */ + + /* + * Decode the 'r' value into 13-bit words, with the "clamping" + * operation applied. + */ + z = br_dec32le(pkey) & 0x03FFFFFF; + r[9] = z & 0x1FFF; + r[10] = z >> 13; + z = (br_dec32le(pkey + 3) >> 2) & 0x03FFFF03; + r[11] = z & 0x1FFF; + r[12] = z >> 13; + z = (br_dec32le(pkey + 6) >> 4) & 0x03FFC0FF; + r[13] = z & 0x1FFF; + r[14] = z >> 13; + z = (br_dec32le(pkey + 9) >> 6) & 0x03F03FFF; + r[15] = z & 0x1FFF; + r[16] = z >> 13; + z = (br_dec32le(pkey + 12) >> 8) & 0x000FFFFF; + r[17] = z & 0x1FFF; + r[18] = z >> 13; + + /* + * Extend r[] with the 5x factor pre-applied. + */ + for (i = 0; i < 9; i ++) { + r[i] = MUL15(5, r[i + 10]); + } + + /* + * Accumulator is 0. + */ + memset(acc, 0, sizeof acc); + + /* + * Process the additional authenticated data, ciphertext, and + * footer in due order. + */ + br_enc64le(foot, (uint64_t)aad_len); + br_enc64le(foot + 8, (uint64_t)len); + poly1305_inner(acc, r, aad, aad_len); + poly1305_inner(acc, r, data, len); + poly1305_inner(acc, r, foot, sizeof foot); + + /* + * Finalise modular reduction. This is done with carry propagation + * and applying the '2^130 = -5 mod p' rule. Note that the output + * of poly1035_inner() is already mostly reduced, since only + * acc[1] may be (very slightly) above 2^13. A single loop back + * to acc[1] will be enough to make the value fit in 130 bits. + */ + cc = 0; + for (i = 1; i < 10; i ++) { + z = acc[i] + cc; + acc[i] = z & 0x1FFF; + cc = z >> 13; + } + z = acc[0] + cc + (cc << 2); + acc[0] = z & 0x1FFF; + acc[1] += z >> 13; + + /* + * We may still have a value in the 2^130-5..2^130-1 range, in + * which case we must reduce it again. The code below selects, + * in constant-time, between 'acc' and 'acc-p', + */ + ctl = GT(acc[0], 0x1FFA); + for (i = 1; i < 10; i ++) { + ctl &= EQ(acc[i], 0x1FFF); + } + acc[0] = MUX(ctl, acc[0] - 0x1FFB, acc[0]); + for (i = 1; i < 10; i ++) { + acc[i] &= ~(-ctl); + } + + /* + * Convert back the accumulator to 32-bit words, and add the + * 's' value (second half of pkey[]). That addition is done + * modulo 2^128. + */ + z = acc[0] + (acc[1] << 13) + br_dec16le(pkey + 16); + br_enc16le((unsigned char *)tag, z & 0xFFFF); + z = (z >> 16) + (acc[2] << 10) + br_dec16le(pkey + 18); + br_enc16le((unsigned char *)tag + 2, z & 0xFFFF); + z = (z >> 16) + (acc[3] << 7) + br_dec16le(pkey + 20); + br_enc16le((unsigned char *)tag + 4, z & 0xFFFF); + z = (z >> 16) + (acc[4] << 4) + br_dec16le(pkey + 22); + br_enc16le((unsigned char *)tag + 6, z & 0xFFFF); + z = (z >> 16) + (acc[5] << 1) + (acc[6] << 14) + br_dec16le(pkey + 24); + br_enc16le((unsigned char *)tag + 8, z & 0xFFFF); + z = (z >> 16) + (acc[7] << 11) + br_dec16le(pkey + 26); + br_enc16le((unsigned char *)tag + 10, z & 0xFFFF); + z = (z >> 16) + (acc[8] << 8) + br_dec16le(pkey + 28); + br_enc16le((unsigned char *)tag + 12, z & 0xFFFF); + z = (z >> 16) + (acc[9] << 5) + br_dec16le(pkey + 30); + br_enc16le((unsigned char *)tag + 14, z & 0xFFFF); + + /* + * If decrypting, then ChaCha20 runs _after_ Poly1305. + */ + if (!encrypt) { + ichacha(key, iv, 1, data, len); + } +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/poly1305_ctmulq.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/poly1305_ctmulq.c new file mode 100644 index 000000000..3415c6a48 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/poly1305_ctmulq.c @@ -0,0 +1,480 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +#if BR_INT128 || BR_UMUL128 + +#if BR_INT128 + +#define MUL128(hi, lo, x, y) do { \ + unsigned __int128 mul128tmp; \ + mul128tmp = (unsigned __int128)(x) * (unsigned __int128)(y); \ + (hi) = (uint64_t)(mul128tmp >> 64); \ + (lo) = (uint64_t)mul128tmp; \ + } while (0) + +#elif BR_UMUL128 + +#include + +#define MUL128(hi, lo, x, y) do { \ + (lo) = _umul128((x), (y), &(hi)); \ + } while (0) + +#endif + +#define MASK42 ((uint64_t)0x000003FFFFFFFFFF) +#define MASK44 ((uint64_t)0x00000FFFFFFFFFFF) + +/* + * The "accumulator" word is nominally a 130-bit value. We split it into + * words of 44 bits, each held in a 64-bit variable. + * + * If the current accumulator is a = a0 + a1*W + a2*W^2 (where W = 2^44) + * and r = r0 + r1*W + r2*W^2, then: + * + * a*r = (a0*r0) + * + (a0*r1 + a1*r0) * W + * + (a0*r2 + a1*r1 + a2*r0) * W^2 + * + (a1*r2 + a2*r1) * W^3 + * + (a2*r2) * W^4 + * + * We want to reduce that value modulo p = 2^130-5, so W^3 = 20 mod p, + * and W^4 = 20*W mod p. Thus, if we define u1 = 20*r1 and u2 = 20*r2, + * then the equations above become: + * + * b0 = a0*r0 + a1*u2 + a2*u1 + * b1 = a0*r1 + a1*r0 + a2*u2 + * b2 = a0*r2 + a1*r1 + a2*r0 + * + * In order to make u1 fit in 44 bits, we can change these equations + * into: + * + * b0 = a0*r0 + a1*u2 + a2*t1 + * b1 = a0*r1 + a1*r0 + a2*t2 + * b2 = a0*r2 + a1*r1 + a2*r0 + * + * Where t1 is u1 truncated to 44 bits, and t2 is u2 added to the extra + * bits of u1. Note that since r is clamped down to a 124-bit value, the + * values u2 and t2 fit on 44 bits too. + * + * The bx values are larger than 44 bits, so we may split them into a + * lower half (cx, 44 bits) and an upper half (dx). The new values for + * the accumulator are then: + * + * e0 = c0 + 20*d2 + * e1 = c1 + d0 + * e2 = c2 + d1 + * + * The equations allow for some room, i.e. the ax values may be larger + * than 44 bits. Similarly, the ex values will usually be larger than + * the ax. Thus, some sort of carry propagation must be done regularly, + * though not necessarily at each iteration. In particular, we do not + * need to compute the additions (for the bx values) over 128-bit + * quantities; we can stick to 64-bit computations. + * + * + * Since the 128-bit result of a 64x64 multiplication is actually + * represented over two 64-bit registers, it is cheaper to arrange for + * any split that happens between the "high" and "low" halves to be on + * that 64-bit boundary. This is done by left shifting the rx, ux and tx + * by 20 bits (since they all fit on 44 bits each, this shift is + * always possible). + */ + +static void +poly1305_inner_big(uint64_t *acc, uint64_t *r, const void *data, size_t len) +{ + +#define MX(hi, lo, m0, m1, m2) do { \ + uint64_t mxhi, mxlo; \ + MUL128(mxhi, mxlo, a0, m0); \ + (hi) = mxhi; \ + (lo) = mxlo >> 20; \ + MUL128(mxhi, mxlo, a1, m1); \ + (hi) += mxhi; \ + (lo) += mxlo >> 20; \ + MUL128(mxhi, mxlo, a2, m2); \ + (hi) += mxhi; \ + (lo) += mxlo >> 20; \ + } while (0) + + const unsigned char *buf; + uint64_t a0, a1, a2; + uint64_t r0, r1, r2, t1, t2, u2; + + r0 = r[0]; + r1 = r[1]; + r2 = r[2]; + t1 = r[3]; + t2 = r[4]; + u2 = r[5]; + a0 = acc[0]; + a1 = acc[1]; + a2 = acc[2]; + buf = data; + + while (len > 0) { + uint64_t v0, v1, v2; + uint64_t c0, c1, c2, d0, d1, d2; + + v0 = br_dec64le(buf + 0); + v1 = br_dec64le(buf + 8); + v2 = v1 >> 24; + v1 = ((v0 >> 44) | (v1 << 20)) & MASK44; + v0 &= MASK44; + a0 += v0; + a1 += v1; + a2 += v2 + ((uint64_t)1 << 40); + MX(d0, c0, r0, u2, t1); + MX(d1, c1, r1, r0, t2); + MX(d2, c2, r2, r1, r0); + a0 = c0 + 20 * d2; + a1 = c1 + d0; + a2 = c2 + d1; + + v0 = br_dec64le(buf + 16); + v1 = br_dec64le(buf + 24); + v2 = v1 >> 24; + v1 = ((v0 >> 44) | (v1 << 20)) & MASK44; + v0 &= MASK44; + a0 += v0; + a1 += v1; + a2 += v2 + ((uint64_t)1 << 40); + MX(d0, c0, r0, u2, t1); + MX(d1, c1, r1, r0, t2); + MX(d2, c2, r2, r1, r0); + a0 = c0 + 20 * d2; + a1 = c1 + d0; + a2 = c2 + d1; + + v0 = br_dec64le(buf + 32); + v1 = br_dec64le(buf + 40); + v2 = v1 >> 24; + v1 = ((v0 >> 44) | (v1 << 20)) & MASK44; + v0 &= MASK44; + a0 += v0; + a1 += v1; + a2 += v2 + ((uint64_t)1 << 40); + MX(d0, c0, r0, u2, t1); + MX(d1, c1, r1, r0, t2); + MX(d2, c2, r2, r1, r0); + a0 = c0 + 20 * d2; + a1 = c1 + d0; + a2 = c2 + d1; + + v0 = br_dec64le(buf + 48); + v1 = br_dec64le(buf + 56); + v2 = v1 >> 24; + v1 = ((v0 >> 44) | (v1 << 20)) & MASK44; + v0 &= MASK44; + a0 += v0; + a1 += v1; + a2 += v2 + ((uint64_t)1 << 40); + MX(d0, c0, r0, u2, t1); + MX(d1, c1, r1, r0, t2); + MX(d2, c2, r2, r1, r0); + a0 = c0 + 20 * d2; + a1 = c1 + d0; + a2 = c2 + d1; + + a1 += a0 >> 44; + a0 &= MASK44; + a2 += a1 >> 44; + a1 &= MASK44; + a0 += 20 * (a2 >> 44); + a2 &= MASK44; + + buf += 64; + len -= 64; + } + acc[0] = a0; + acc[1] = a1; + acc[2] = a2; + +#undef MX +} + +static void +poly1305_inner_small(uint64_t *acc, uint64_t *r, const void *data, size_t len) +{ + const unsigned char *buf; + uint64_t a0, a1, a2; + uint64_t r0, r1, r2, t1, t2, u2; + + r0 = r[0]; + r1 = r[1]; + r2 = r[2]; + t1 = r[3]; + t2 = r[4]; + u2 = r[5]; + a0 = acc[0]; + a1 = acc[1]; + a2 = acc[2]; + buf = data; + + while (len > 0) { + uint64_t v0, v1, v2; + uint64_t c0, c1, c2, d0, d1, d2; + unsigned char tmp[16]; + + if (len < 16) { + memcpy(tmp, buf, len); + memset(tmp + len, 0, (sizeof tmp) - len); + buf = tmp; + len = 16; + } + v0 = br_dec64le(buf + 0); + v1 = br_dec64le(buf + 8); + + v2 = v1 >> 24; + v1 = ((v0 >> 44) | (v1 << 20)) & MASK44; + v0 &= MASK44; + + a0 += v0; + a1 += v1; + a2 += v2 + ((uint64_t)1 << 40); + +#define MX(hi, lo, m0, m1, m2) do { \ + uint64_t mxhi, mxlo; \ + MUL128(mxhi, mxlo, a0, m0); \ + (hi) = mxhi; \ + (lo) = mxlo >> 20; \ + MUL128(mxhi, mxlo, a1, m1); \ + (hi) += mxhi; \ + (lo) += mxlo >> 20; \ + MUL128(mxhi, mxlo, a2, m2); \ + (hi) += mxhi; \ + (lo) += mxlo >> 20; \ + } while (0) + + MX(d0, c0, r0, u2, t1); + MX(d1, c1, r1, r0, t2); + MX(d2, c2, r2, r1, r0); + +#undef MX + + a0 = c0 + 20 * d2; + a1 = c1 + d0; + a2 = c2 + d1; + + a1 += a0 >> 44; + a0 &= MASK44; + a2 += a1 >> 44; + a1 &= MASK44; + a0 += 20 * (a2 >> 44); + a2 &= MASK44; + + buf += 16; + len -= 16; + } + acc[0] = a0; + acc[1] = a1; + acc[2] = a2; +} + +static inline void +poly1305_inner(uint64_t *acc, uint64_t *r, const void *data, size_t len) +{ + if (len >= 64) { + size_t len2; + + len2 = len & ~(size_t)63; + poly1305_inner_big(acc, r, data, len2); + data = (const unsigned char *)data + len2; + len -= len2; + } + if (len > 0) { + poly1305_inner_small(acc, r, data, len); + } +} + +/* see bearssl_block.h */ +void +br_poly1305_ctmulq_run(const void *key, const void *iv, + void *data, size_t len, const void *aad, size_t aad_len, + void *tag, br_chacha20_run ichacha, int encrypt) +{ + unsigned char pkey[32], foot[16]; + uint64_t r[6], acc[3], r0, r1; + uint32_t v0, v1, v2, v3, v4; + uint64_t w0, w1, w2, w3; + uint32_t ctl; + + /* + * Compute the MAC key. The 'r' value is the first 16 bytes of + * pkey[]. + */ + memset(pkey, 0, sizeof pkey); + ichacha(key, iv, 0, pkey, sizeof pkey); + + /* + * If encrypting, ChaCha20 must run first, followed by Poly1305. + * When decrypting, the operations are reversed. + */ + if (encrypt) { + ichacha(key, iv, 1, data, len); + } + + /* + * Run Poly1305. We must process the AAD, then ciphertext, then + * the footer (with the lengths). Note that the AAD and ciphertext + * are meant to be padded with zeros up to the next multiple of 16, + * and the length of the footer is 16 bytes as well. + */ + + /* + * Apply the "clamping" on r. + */ + pkey[ 3] &= 0x0F; + pkey[ 4] &= 0xFC; + pkey[ 7] &= 0x0F; + pkey[ 8] &= 0xFC; + pkey[11] &= 0x0F; + pkey[12] &= 0xFC; + pkey[15] &= 0x0F; + + /* + * Decode the 'r' value into 44-bit words, left-shifted by 20 bits. + * Also compute the u1 and u2 values. + */ + r0 = br_dec64le(pkey + 0); + r1 = br_dec64le(pkey + 8); + r[0] = r0 << 20; + r[1] = ((r0 >> 24) | (r1 << 40)) & ~(uint64_t)0xFFFFF; + r[2] = (r1 >> 4) & ~(uint64_t)0xFFFFF; + r1 = 20 * (r[1] >> 20); + r[3] = r1 << 20; + r[5] = 20 * r[2]; + r[4] = (r[5] + (r1 >> 24)) & ~(uint64_t)0xFFFFF; + + /* + * Accumulator is 0. + */ + acc[0] = 0; + acc[1] = 0; + acc[2] = 0; + + /* + * Process the additional authenticated data, ciphertext, and + * footer in due order. + */ + br_enc64le(foot, (uint64_t)aad_len); + br_enc64le(foot + 8, (uint64_t)len); + poly1305_inner(acc, r, aad, aad_len); + poly1305_inner(acc, r, data, len); + poly1305_inner_small(acc, r, foot, sizeof foot); + + /* + * Finalise modular reduction. At that point, the value consists + * in three 44-bit values (the lowest one might be slightly above + * 2^44). Two loops shall be sufficient. + */ + acc[1] += (acc[0] >> 44); + acc[0] &= MASK44; + acc[2] += (acc[1] >> 44); + acc[1] &= MASK44; + acc[0] += 5 * (acc[2] >> 42); + acc[2] &= MASK42; + acc[1] += (acc[0] >> 44); + acc[0] &= MASK44; + acc[2] += (acc[1] >> 44); + acc[1] &= MASK44; + acc[0] += 5 * (acc[2] >> 42); + acc[2] &= MASK42; + + /* + * The value may still fall in the 2^130-5..2^130-1 range, in + * which case we must reduce it again. The code below selects, + * in constant-time, between 'acc' and 'acc-p'. We encode the + * value over four 32-bit integers to finish the operation. + */ + v0 = (uint32_t)acc[0]; + v1 = (uint32_t)(acc[0] >> 32) | ((uint32_t)acc[1] << 12); + v2 = (uint32_t)(acc[1] >> 20) | ((uint32_t)acc[2] << 24); + v3 = (uint32_t)(acc[2] >> 8); + v4 = (uint32_t)(acc[2] >> 40); + + ctl = GT(v0, 0xFFFFFFFA); + ctl &= EQ(v1, 0xFFFFFFFF); + ctl &= EQ(v2, 0xFFFFFFFF); + ctl &= EQ(v3, 0xFFFFFFFF); + ctl &= EQ(v4, 0x00000003); + v0 = MUX(ctl, v0 + 5, v0); + v1 = MUX(ctl, 0, v1); + v2 = MUX(ctl, 0, v2); + v3 = MUX(ctl, 0, v3); + + /* + * Add the "s" value. This is done modulo 2^128. Don't forget + * carry propagation... + */ + w0 = (uint64_t)v0 + (uint64_t)br_dec32le(pkey + 16); + w1 = (uint64_t)v1 + (uint64_t)br_dec32le(pkey + 20) + (w0 >> 32); + w2 = (uint64_t)v2 + (uint64_t)br_dec32le(pkey + 24) + (w1 >> 32); + w3 = (uint64_t)v3 + (uint64_t)br_dec32le(pkey + 28) + (w2 >> 32); + v0 = (uint32_t)w0; + v1 = (uint32_t)w1; + v2 = (uint32_t)w2; + v3 = (uint32_t)w3; + + /* + * Encode the tag. + */ + br_enc32le((unsigned char *)tag + 0, v0); + br_enc32le((unsigned char *)tag + 4, v1); + br_enc32le((unsigned char *)tag + 8, v2); + br_enc32le((unsigned char *)tag + 12, v3); + + /* + * If decrypting, then ChaCha20 runs _after_ Poly1305. + */ + if (!encrypt) { + ichacha(key, iv, 1, data, len); + } +} + +/* see bearssl_block.h */ +br_poly1305_run +br_poly1305_ctmulq_get(void) +{ + return &br_poly1305_ctmulq_run; +} + +#else + +/* see bearssl_block.h */ +br_poly1305_run +br_poly1305_ctmulq_get(void) +{ + return 0; +} + +#endif + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/poly1305_i15.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/poly1305_i15.c new file mode 100644 index 000000000..224c1b6cd --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/poly1305_i15.c @@ -0,0 +1,226 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* + * This is a "reference" implementation of Poly1305 that uses the + * generic "i15" code for big integers. It is slow, but it handles all + * big-integer operations with generic code, thereby avoiding most + * tricky situations with carry propagation and modular reduction. + */ + +/* + * Modulus: 2^130-5. + */ +static const uint16_t P1305[] = { + 0x008A, + 0x7FFB, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x03FF +}; + +/* + * -p mod 2^15. + */ +#define P0I 0x4CCD + +/* + * R^2 mod p, for conversion to Montgomery representation (R = 2^135, + * since we use 9 words of 15 bits each, and 15*9 = 135). + */ +static const uint16_t R2[] = { + 0x008A, + 0x6400, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 +}; + +/* + * Perform the inner processing of blocks for Poly1305. The "r" array + * is in Montgomery representation, while the "a" array is not. + */ +static void +poly1305_inner(uint16_t *a, const uint16_t *r, const void *data, size_t len) +{ + const unsigned char *buf; + + buf = data; + while (len > 0) { + unsigned char tmp[16], rev[16]; + uint16_t b[10]; + uint32_t ctl; + int i; + + /* + * If there is a partial block, right-pad it with zeros. + */ + if (len < 16) { + memset(tmp, 0, sizeof tmp); + memcpy(tmp, buf, len); + buf = tmp; + len = 16; + } + + /* + * Decode next block and apply the "high bit". Since + * decoding is little-endian, we must byte-swap the buffer. + */ + for (i = 0; i < 16; i ++) { + rev[i] = buf[15 - i]; + } + br_i15_decode_mod(b, rev, sizeof rev, P1305); + b[9] |= 0x0100; + + /* + * Add the accumulator to the decoded block (modular + * addition). + */ + ctl = br_i15_add(b, a, 1); + ctl |= NOT(br_i15_sub(b, P1305, 0)); + br_i15_sub(b, P1305, ctl); + + /* + * Multiply by r, result is the new accumulator value. + */ + br_i15_montymul(a, b, r, P1305, P0I); + + buf += 16; + len -= 16; + } +} + +/* + * Byteswap a 16-byte value. + */ +static void +byteswap16(unsigned char *buf) +{ + int i; + + for (i = 0; i < 8; i ++) { + unsigned x; + + x = buf[i]; + buf[i] = buf[15 - i]; + buf[15 - i] = x; + } +} + +/* see bearssl_block.h */ +void +br_poly1305_i15_run(const void *key, const void *iv, + void *data, size_t len, const void *aad, size_t aad_len, + void *tag, br_chacha20_run ichacha, int encrypt) +{ + unsigned char pkey[32], foot[16]; + uint16_t t[10], r[10], acc[10]; + + /* + * Compute the MAC key. The 'r' value is the first 16 bytes of + * pkey[]. + */ + memset(pkey, 0, sizeof pkey); + ichacha(key, iv, 0, pkey, sizeof pkey); + + /* + * If encrypting, ChaCha20 must run first, followed by Poly1305. + * When decrypting, the operations are reversed. + */ + if (encrypt) { + ichacha(key, iv, 1, data, len); + } + + /* + * Run Poly1305. We must process the AAD, then ciphertext, then + * the footer (with the lengths). Note that the AAD and ciphertext + * are meant to be padded with zeros up to the next multiple of 16, + * and the length of the footer is 16 bytes as well. + */ + + /* + * Apply the "clamping" operation on the encoded 'r' value. + */ + pkey[ 3] &= 0x0F; + pkey[ 7] &= 0x0F; + pkey[11] &= 0x0F; + pkey[15] &= 0x0F; + pkey[ 4] &= 0xFC; + pkey[ 8] &= 0xFC; + pkey[12] &= 0xFC; + + /* + * Decode the clamped 'r' value. Decoding should use little-endian + * so we must byteswap the value first. + */ + byteswap16(pkey); + br_i15_decode_mod(t, pkey, 16, P1305); + + /* + * Convert 'r' to Montgomery representation. + */ + br_i15_montymul(r, t, R2, P1305, P0I); + + /* + * Accumulator is 0. + */ + br_i15_zero(acc, 0x8A); + + /* + * Process the additional authenticated data, ciphertext, and + * footer in due order. + */ + br_enc64le(foot, (uint64_t)aad_len); + br_enc64le(foot + 8, (uint64_t)len); + poly1305_inner(acc, r, aad, aad_len); + poly1305_inner(acc, r, data, len); + poly1305_inner(acc, r, foot, sizeof foot); + + /* + * Decode the value 's'. Again, a byteswap is needed. + */ + byteswap16(pkey + 16); + br_i15_decode_mod(t, pkey + 16, 16, P1305); + + /* + * Add the value 's' to the accumulator. That addition is done + * modulo 2^128, so we just ignore the carry. + */ + br_i15_add(acc, t, 1); + + /* + * Encode the result (128 low bits) to the tag. Encoding should + * be little-endian. + */ + br_i15_encode(tag, 16, acc); + byteswap16(tag); + + /* + * If decrypting, then ChaCha20 runs _after_ Poly1305. + */ + if (!encrypt) { + ichacha(key, iv, 1, data, len); + } +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/prf.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/prf.c new file mode 100644 index 000000000..61a0028aa --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/prf.c @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +void +br_tls_phash(void *dst, size_t len, + const br_hash_class *dig, + const void *secret, size_t secret_len, const char *label, + size_t seed_num, const br_tls_prf_seed_chunk *seed) +{ + unsigned char *buf; + unsigned char tmp[64], a[64]; + br_hmac_key_context kc; + br_hmac_context hc; + size_t label_len, hlen, u; + + if (len == 0) { + return; + } + buf = dst; + for (label_len = 0; label[label_len]; label_len ++); + hlen = br_digest_size(dig); + br_hmac_key_init(&kc, dig, secret, secret_len); + br_hmac_init(&hc, &kc, 0); + br_hmac_update(&hc, label, label_len); + for (u = 0; u < seed_num; u ++) { + br_hmac_update(&hc, seed[u].data, seed[u].len); + } + br_hmac_out(&hc, a); + for (;;) { + br_hmac_init(&hc, &kc, 0); + br_hmac_update(&hc, a, hlen); + br_hmac_update(&hc, label, label_len); + for (u = 0; u < seed_num; u ++) { + br_hmac_update(&hc, seed[u].data, seed[u].len); + } + br_hmac_out(&hc, tmp); + for (u = 0; u < hlen && u < len; u ++) { + buf[u] ^= tmp[u]; + } + buf += u; + len -= u; + if (len == 0) { + return; + } + br_hmac_init(&hc, &kc, 0); + br_hmac_update(&hc, a, hlen); + br_hmac_out(&hc, a); + } +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/prf_md5sha1.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/prf_md5sha1.c new file mode 100644 index 000000000..4651f3c52 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/prf_md5sha1.c @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl.h */ +void +br_tls10_prf(void *dst, size_t len, + const void *secret, size_t secret_len, const char *label, + size_t seed_num, const br_tls_prf_seed_chunk *seed) +{ + const unsigned char *s1; + size_t slen; + + s1 = secret; + slen = (secret_len + 1) >> 1; + memset(dst, 0, len); + br_tls_phash(dst, len, &br_md5_vtable, + s1, slen, label, seed_num, seed); + br_tls_phash(dst, len, &br_sha1_vtable, + s1 + secret_len - slen, slen, label, seed_num, seed); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/prf_sha256.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/prf_sha256.c new file mode 100644 index 000000000..7e91b9ba0 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/prf_sha256.c @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl.h */ +void +br_tls12_sha256_prf(void *dst, size_t len, + const void *secret, size_t secret_len, const char *label, + size_t seed_num, const br_tls_prf_seed_chunk *seed) +{ + memset(dst, 0, len); + br_tls_phash(dst, len, &br_sha256_vtable, + secret, secret_len, label, seed_num, seed); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/prf_sha384.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/prf_sha384.c new file mode 100644 index 000000000..6527fd603 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/prf_sha384.c @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl.h */ +void +br_tls12_sha384_prf(void *dst, size_t len, + const void *secret, size_t secret_len, const char *label, + size_t seed_num, const br_tls_prf_seed_chunk *seed) +{ + memset(dst, 0, len); + br_tls_phash(dst, len, &br_sha384_vtable, + secret, secret_len, label, seed_num, seed); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_default_keygen.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_default_keygen.c new file mode 100644 index 000000000..93c9c6100 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_default_keygen.c @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_rsa.h */ +br_rsa_keygen +br_rsa_keygen_get_default(void) +{ +#if BR_INT128 || BR_UMUL128 + return &br_rsa_i62_keygen; +#elif BR_LOMUL + return &br_rsa_i15_keygen; +#else + return &br_rsa_i31_keygen; +#endif +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_default_modulus.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_default_modulus.c new file mode 100644 index 000000000..0f79af1c1 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_default_modulus.c @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_rsa.h */ +br_rsa_compute_modulus +br_rsa_compute_modulus_get_default(void) +{ +#if BR_LOMUL + return &br_rsa_i15_compute_modulus; +#else + return &br_rsa_i31_compute_modulus; +#endif +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_default_oaep_decrypt.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_default_oaep_decrypt.c new file mode 100644 index 000000000..9b33a630d --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_default_oaep_decrypt.c @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_rsa.h */ +br_rsa_oaep_decrypt +br_rsa_oaep_decrypt_get_default(void) +{ +#if BR_INT128 || BR_UMUL128 + return &br_rsa_i62_oaep_decrypt; +#elif BR_LOMUL + return &br_rsa_i15_oaep_decrypt; +#else + return &br_rsa_i31_oaep_decrypt; +#endif +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_default_oaep_encrypt.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_default_oaep_encrypt.c new file mode 100644 index 000000000..d552c46ee --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_default_oaep_encrypt.c @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_rsa.h */ +br_rsa_oaep_encrypt +br_rsa_oaep_encrypt_get_default(void) +{ +#if BR_INT128 || BR_UMUL128 + return &br_rsa_i62_oaep_encrypt; +#elif BR_LOMUL + return &br_rsa_i15_oaep_encrypt; +#else + return &br_rsa_i31_oaep_encrypt; +#endif +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_default_pkcs1_sign.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_default_pkcs1_sign.c new file mode 100644 index 000000000..2b5ac711f --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_default_pkcs1_sign.c @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_rsa.h */ +br_rsa_pkcs1_sign +br_rsa_pkcs1_sign_get_default(void) +{ +#if BR_INT128 || BR_UMUL128 + return &br_rsa_i62_pkcs1_sign; +#elif BR_LOMUL + return &br_rsa_i15_pkcs1_sign; +#else + return &br_rsa_i31_pkcs1_sign; +#endif +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_default_pkcs1_vrfy.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_default_pkcs1_vrfy.c new file mode 100644 index 000000000..5535ee77c --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_default_pkcs1_vrfy.c @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_rsa.h */ +br_rsa_pkcs1_vrfy +br_rsa_pkcs1_vrfy_get_default(void) +{ +#if BR_INT128 || BR_UMUL128 + return &br_rsa_i62_pkcs1_vrfy; +#elif BR_LOMUL + return &br_rsa_i15_pkcs1_vrfy; +#else + return &br_rsa_i31_pkcs1_vrfy; +#endif +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_default_priv.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_default_priv.c new file mode 100644 index 000000000..137a7489c --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_default_priv.c @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_rsa.h */ +br_rsa_private +br_rsa_private_get_default(void) +{ +#if BR_INT128 || BR_UMUL128 + return &br_rsa_i62_private; +#elif BR_LOMUL + return &br_rsa_i15_private; +#else + return &br_rsa_i31_private; +#endif +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_default_privexp.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_default_privexp.c new file mode 100644 index 000000000..6ebb3f8c8 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_default_privexp.c @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_rsa.h */ +br_rsa_compute_privexp +br_rsa_compute_privexp_get_default(void) +{ +#if BR_LOMUL + return &br_rsa_i15_compute_privexp; +#else + return &br_rsa_i31_compute_privexp; +#endif +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_default_pss_sign.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_default_pss_sign.c new file mode 100644 index 000000000..23b4f9a6f --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_default_pss_sign.c @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_rsa.h */ +br_rsa_pss_sign +br_rsa_pss_sign_get_default(void) +{ +#if BR_INT128 || BR_UMUL128 + return &br_rsa_i62_pss_sign; +#elif BR_LOMUL + return &br_rsa_i15_pss_sign; +#else + return &br_rsa_i31_pss_sign; +#endif +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_default_pss_vrfy.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_default_pss_vrfy.c new file mode 100644 index 000000000..8bb02d9f8 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_default_pss_vrfy.c @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_rsa.h */ +br_rsa_pss_vrfy +br_rsa_pss_vrfy_get_default(void) +{ +#if BR_INT128 || BR_UMUL128 + return &br_rsa_i62_pss_vrfy; +#elif BR_LOMUL + return &br_rsa_i15_pss_vrfy; +#else + return &br_rsa_i31_pss_vrfy; +#endif +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_default_pub.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_default_pub.c new file mode 100644 index 000000000..c841adb99 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_default_pub.c @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_rsa.h */ +br_rsa_public +br_rsa_public_get_default(void) +{ +#if BR_INT128 || BR_UMUL128 + return &br_rsa_i62_public; +#elif BR_LOMUL + return &br_rsa_i15_public; +#else + return &br_rsa_i31_public; +#endif +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_default_pubexp.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_default_pubexp.c new file mode 100644 index 000000000..a9c194605 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_default_pubexp.c @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_rsa.h */ +br_rsa_compute_pubexp +br_rsa_compute_pubexp_get_default(void) +{ +#if BR_LOMUL + return &br_rsa_i15_compute_pubexp; +#else + return &br_rsa_i31_compute_pubexp; +#endif +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i15_keygen.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i15_keygen.c new file mode 100644 index 000000000..59c2074d1 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i15_keygen.c @@ -0,0 +1,588 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* + * Make a random integer of the provided size. The size is encoded. + * The header word is untouched. + */ +static void +mkrand(const br_prng_class **rng, uint16_t *x, uint32_t esize) +{ + size_t u, len; + unsigned m; + + len = (esize + 15) >> 4; + (*rng)->generate(rng, x + 1, len * sizeof(uint16_t)); + for (u = 1; u < len; u ++) { + x[u] &= 0x7FFF; + } + m = esize & 15; + if (m == 0) { + x[len] &= 0x7FFF; + } else { + x[len] &= 0x7FFF >> (15 - m); + } +} + +/* + * This is the big-endian unsigned representation of the product of + * all small primes from 13 to 1481. + */ +static const unsigned char SMALL_PRIMES[] = { + 0x2E, 0xAB, 0x92, 0xD1, 0x8B, 0x12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, 0x4B, 0x70, 0x80, + 0xAF, 0xCA, 0x84, 0x51, 0xD8, 0xD2, 0x26, 0x49, 0xF5, 0xA8, + 0x5E, 0x35, 0x4B, 0xAC, 0xCE, 0x29, 0x92, 0x33, 0xB7, 0xA2, + 0x69, 0x7D, 0x0C, 0xE0, 0x9C, 0xDB, 0x04, 0xD6, 0xB4, 0xBC, + 0x39, 0xD7, 0x7F, 0x9E, 0x9D, 0x78, 0x38, 0x7F, 0x51, 0x54, + 0x50, 0x8B, 0x9E, 0x9C, 0x03, 0x6C, 0xF5, 0x9D, 0x2C, 0x74, + 0x57, 0xF0, 0x27, 0x2A, 0xC3, 0x47, 0xCA, 0xB9, 0xD7, 0x5C, + 0xFF, 0xC2, 0xAC, 0x65, 0x4E, 0xBD +}; + +/* + * We need temporary values for at least 7 integers of the same size + * as a factor (including header word); more space helps with performance + * (in modular exponentiations), but we much prefer to remain under + * 2 kilobytes in total, to save stack space. The macro TEMPS below + * exceeds 1024 (which is a count in 16-bit words) when BR_MAX_RSA_SIZE + * is greater than 4350 (default value is 4096, so the 2-kB limit is + * maintained unless BR_MAX_RSA_SIZE was modified). + */ +#define MAX(x, y) ((x) > (y) ? (x) : (y)) +#define TEMPS MAX(1024, 7 * ((((BR_MAX_RSA_SIZE + 1) >> 1) + 29) / 15)) + +/* + * Perform trial division on a candidate prime. This computes + * y = SMALL_PRIMES mod x, then tries to compute y/y mod x. The + * br_i15_moddiv() function will report an error if y is not invertible + * modulo x. Returned value is 1 on success (none of the small primes + * divides x), 0 on error (a non-trivial GCD is obtained). + * + * This function assumes that x is odd. + */ +static uint32_t +trial_divisions(const uint16_t *x, uint16_t *t) +{ + uint16_t *y; + uint16_t x0i; + + y = t; + t += 1 + ((x[0] + 15) >> 4); + x0i = br_i15_ninv15(x[1]); + br_i15_decode_reduce(y, SMALL_PRIMES, sizeof SMALL_PRIMES, x); + return br_i15_moddiv(y, y, x, x0i, t); +} + +/* + * Perform n rounds of Miller-Rabin on the candidate prime x. This + * function assumes that x = 3 mod 4. + * + * Returned value is 1 on success (all rounds completed successfully), + * 0 otherwise. + */ +static uint32_t +miller_rabin(const br_prng_class **rng, const uint16_t *x, int n, + uint16_t *t, size_t tlen) +{ + /* + * Since x = 3 mod 4, the Miller-Rabin test is simple: + * - get a random base a (such that 1 < a < x-1) + * - compute z = a^((x-1)/2) mod x + * - if z != 1 and z != x-1, the number x is composite + * + * We generate bases 'a' randomly with a size which is + * one bit less than x, which ensures that a < x-1. It + * is not useful to verify that a > 1 because the probability + * that we get a value a equal to 0 or 1 is much smaller + * than the probability of our Miller-Rabin tests not to + * detect a composite, which is already quite smaller than the + * probability of the hardware misbehaving and return a + * composite integer because of some glitch (e.g. bad RAM + * or ill-timed cosmic ray). + */ + unsigned char *xm1d2; + size_t xlen, xm1d2_len, xm1d2_len_u16, u; + uint32_t asize; + unsigned cc; + uint16_t x0i; + + /* + * Compute (x-1)/2 (encoded). + */ + xm1d2 = (unsigned char *)t; + xm1d2_len = ((x[0] - (x[0] >> 4)) + 7) >> 3; + br_i15_encode(xm1d2, xm1d2_len, x); + cc = 0; + for (u = 0; u < xm1d2_len; u ++) { + unsigned w; + + w = xm1d2[u]; + xm1d2[u] = (unsigned char)((w >> 1) | cc); + cc = w << 7; + } + + /* + * We used some words of the provided buffer for (x-1)/2. + */ + xm1d2_len_u16 = (xm1d2_len + 1) >> 1; + t += xm1d2_len_u16; + tlen -= xm1d2_len_u16; + + xlen = (x[0] + 15) >> 4; + asize = x[0] - 1 - EQ0(x[0] & 15); + x0i = br_i15_ninv15(x[1]); + while (n -- > 0) { + uint16_t *a; + uint32_t eq1, eqm1; + + /* + * Generate a random base. We don't need the base to be + * really uniform modulo x, so we just get a random + * number which is one bit shorter than x. + */ + a = t; + a[0] = x[0]; + a[xlen] = 0; + mkrand(rng, a, asize); + + /* + * Compute a^((x-1)/2) mod x. We assume here that the + * function will not fail (the temporary array is large + * enough). + */ + br_i15_modpow_opt(a, xm1d2, xm1d2_len, + x, x0i, t + 1 + xlen, tlen - 1 - xlen); + + /* + * We must obtain either 1 or x-1. Note that x is odd, + * hence x-1 differs from x only in its low word (no + * carry). + */ + eq1 = a[1] ^ 1; + eqm1 = a[1] ^ (x[1] - 1); + for (u = 2; u <= xlen; u ++) { + eq1 |= a[u]; + eqm1 |= a[u] ^ x[u]; + } + + if ((EQ0(eq1) | EQ0(eqm1)) == 0) { + return 0; + } + } + return 1; +} + +/* + * Create a random prime of the provided size. 'size' is the _encoded_ + * bit length. The two top bits and the two bottom bits are set to 1. + */ +static void +mkprime(const br_prng_class **rng, uint16_t *x, uint32_t esize, + uint32_t pubexp, uint16_t *t, size_t tlen) +{ + size_t len; + + x[0] = esize; + len = (esize + 15) >> 4; + for (;;) { + size_t u; + uint32_t m3, m5, m7, m11; + int rounds; + + /* + * Generate random bits. We force the two top bits and the + * two bottom bits to 1. + */ + mkrand(rng, x, esize); + if ((esize & 15) == 0) { + x[len] |= 0x6000; + } else if ((esize & 15) == 1) { + x[len] |= 0x0001; + x[len - 1] |= 0x4000; + } else { + x[len] |= 0x0003 << ((esize & 15) - 2); + } + x[1] |= 0x0003; + + /* + * Trial division with low primes (3, 5, 7 and 11). We + * use the following properties: + * + * 2^2 = 1 mod 3 + * 2^4 = 1 mod 5 + * 2^3 = 1 mod 7 + * 2^10 = 1 mod 11 + */ + m3 = 0; + m5 = 0; + m7 = 0; + m11 = 0; + for (u = 0; u < len; u ++) { + uint32_t w; + + w = x[1 + u]; + m3 += w << (u & 1); + m3 = (m3 & 0xFF) + (m3 >> 8); + m5 += w << ((4 - u) & 3); + m5 = (m5 & 0xFF) + (m5 >> 8); + m7 += w; + m7 = (m7 & 0x1FF) + (m7 >> 9); + m11 += w << (5 & -(u & 1)); + m11 = (m11 & 0x3FF) + (m11 >> 10); + } + + /* + * Maximum values of m* at this point: + * m3: 511 + * m5: 2310 + * m7: 510 + * m11: 2047 + * We use the same properties to make further reductions. + */ + + m3 = (m3 & 0x0F) + (m3 >> 4); /* max: 46 */ + m3 = (m3 & 0x0F) + (m3 >> 4); /* max: 16 */ + m3 = ((m3 * 43) >> 5) & 3; + + m5 = (m5 & 0xFF) + (m5 >> 8); /* max: 263 */ + m5 = (m5 & 0x0F) + (m5 >> 4); /* max: 30 */ + m5 = (m5 & 0x0F) + (m5 >> 4); /* max: 15 */ + m5 -= 10 & -GT(m5, 9); + m5 -= 5 & -GT(m5, 4); + + m7 = (m7 & 0x3F) + (m7 >> 6); /* max: 69 */ + m7 = (m7 & 7) + (m7 >> 3); /* max: 14 */ + m7 = ((m7 * 147) >> 7) & 7; + + /* + * 2^5 = 32 = -1 mod 11. + */ + m11 = (m11 & 0x1F) + 66 - (m11 >> 5); /* max: 97 */ + m11 -= 88 & -GT(m11, 87); + m11 -= 44 & -GT(m11, 43); + m11 -= 22 & -GT(m11, 21); + m11 -= 11 & -GT(m11, 10); + + /* + * If any of these modulo is 0, then the candidate is + * not prime. Also, if pubexp is 3, 5, 7 or 11, and the + * corresponding modulus is 1, then the candidate must + * be rejected, because we need e to be invertible + * modulo p-1. We can use simple comparisons here + * because they won't leak information on a candidate + * that we keep, only on one that we reject (and is thus + * not secret). + */ + if (m3 == 0 || m5 == 0 || m7 == 0 || m11 == 0) { + continue; + } + if ((pubexp == 3 && m3 == 1) + || (pubexp == 5 && m5 == 1) + || (pubexp == 7 && m7 == 1) + || (pubexp == 11 && m11 == 1)) + { + continue; + } + + /* + * More trial divisions. + */ + if (!trial_divisions(x, t)) { + continue; + } + + /* + * Miller-Rabin algorithm. Since we selected a random + * integer, not a maliciously crafted integer, we can use + * relatively few rounds to lower the risk of a false + * positive (i.e. declaring prime a non-prime) under + * 2^(-80). It is not useful to lower the probability much + * below that, since that would be substantially below + * the probability of the hardware misbehaving. Sufficient + * numbers of rounds are extracted from the Handbook of + * Applied Cryptography, note 4.49 (page 149). + * + * Since we work on the encoded size (esize), we need to + * compare with encoded thresholds. + */ + if (esize < 320) { + rounds = 12; + } else if (esize < 480) { + rounds = 9; + } else if (esize < 693) { + rounds = 6; + } else if (esize < 906) { + rounds = 4; + } else if (esize < 1386) { + rounds = 3; + } else { + rounds = 2; + } + + if (miller_rabin(rng, x, rounds, t, tlen)) { + return; + } + } +} + +/* + * Let p be a prime (p > 2^33, p = 3 mod 4). Let m = (p-1)/2, provided + * as parameter (with announced bit length equal to that of p). This + * function computes d = 1/e mod p-1 (for an odd integer e). Returned + * value is 1 on success, 0 on error (an error is reported if e is not + * invertible modulo p-1). + * + * The temporary buffer (t) must have room for at least 4 integers of + * the size of p. + */ +static uint32_t +invert_pubexp(uint16_t *d, const uint16_t *m, uint32_t e, uint16_t *t) +{ + uint16_t *f; + uint32_t r; + + f = t; + t += 1 + ((m[0] + 15) >> 4); + + /* + * Compute d = 1/e mod m. Since p = 3 mod 4, m is odd. + */ + br_i15_zero(d, m[0]); + d[1] = 1; + br_i15_zero(f, m[0]); + f[1] = e & 0x7FFF; + f[2] = (e >> 15) & 0x7FFF; + f[3] = e >> 30; + r = br_i15_moddiv(d, f, m, br_i15_ninv15(m[1]), t); + + /* + * We really want d = 1/e mod p-1, with p = 2m. By the CRT, + * the result is either the d we got, or d + m. + * + * Let's write e*d = 1 + k*m, for some integer k. Integers e + * and m are odd. If d is odd, then e*d is odd, which implies + * that k must be even; in that case, e*d = 1 + (k/2)*2m, and + * thus d is already fine. Conversely, if d is even, then k + * is odd, and we must add m to d in order to get the correct + * result. + */ + br_i15_add(d, m, (uint32_t)(1 - (d[1] & 1))); + + return r; +} + +/* + * Swap two buffers in RAM. They must be disjoint. + */ +static void +bufswap(void *b1, void *b2, size_t len) +{ + size_t u; + unsigned char *buf1, *buf2; + + buf1 = b1; + buf2 = b2; + for (u = 0; u < len; u ++) { + unsigned w; + + w = buf1[u]; + buf1[u] = buf2[u]; + buf2[u] = w; + } +} + +/* see bearssl_rsa.h */ +uint32_t +br_rsa_i15_keygen(const br_prng_class **rng, + br_rsa_private_key *sk, void *kbuf_priv, + br_rsa_public_key *pk, void *kbuf_pub, + unsigned size, uint32_t pubexp) +{ + uint32_t esize_p, esize_q; + size_t plen, qlen, tlen; + uint16_t *p, *q, *t; + uint16_t tmp[TEMPS]; + uint32_t r; + + if (size < BR_MIN_RSA_SIZE || size > BR_MAX_RSA_SIZE) { + return 0; + } + if (pubexp == 0) { + pubexp = 3; + } else if (pubexp == 1 || (pubexp & 1) == 0) { + return 0; + } + + esize_p = (size + 1) >> 1; + esize_q = size - esize_p; + sk->n_bitlen = size; + sk->p = kbuf_priv; + sk->plen = (esize_p + 7) >> 3; + sk->q = sk->p + sk->plen; + sk->qlen = (esize_q + 7) >> 3; + sk->dp = sk->q + sk->qlen; + sk->dplen = sk->plen; + sk->dq = sk->dp + sk->dplen; + sk->dqlen = sk->qlen; + sk->iq = sk->dq + sk->dqlen; + sk->iqlen = sk->plen; + + if (pk != NULL) { + pk->n = kbuf_pub; + pk->nlen = (size + 7) >> 3; + pk->e = pk->n + pk->nlen; + pk->elen = 4; + br_enc32be(pk->e, pubexp); + while (*pk->e == 0) { + pk->e ++; + pk->elen --; + } + } + + /* + * We now switch to encoded sizes. + * + * floor((x * 17477) / (2^18)) is equal to floor(x/15) for all + * integers x from 0 to 23833. + */ + esize_p += MUL15(esize_p, 17477) >> 18; + esize_q += MUL15(esize_q, 17477) >> 18; + plen = (esize_p + 15) >> 4; + qlen = (esize_q + 15) >> 4; + p = tmp; + q = p + 1 + plen; + t = q + 1 + qlen; + tlen = ((sizeof tmp) / sizeof(uint16_t)) - (2 + plen + qlen); + + /* + * When looking for primes p and q, we temporarily divide + * candidates by 2, in order to compute the inverse of the + * public exponent. + */ + + for (;;) { + mkprime(rng, p, esize_p, pubexp, t, tlen); + br_i15_rshift(p, 1); + if (invert_pubexp(t, p, pubexp, t + 1 + plen)) { + br_i15_add(p, p, 1); + p[1] |= 1; + br_i15_encode(sk->p, sk->plen, p); + br_i15_encode(sk->dp, sk->dplen, t); + break; + } + } + + for (;;) { + mkprime(rng, q, esize_q, pubexp, t, tlen); + br_i15_rshift(q, 1); + if (invert_pubexp(t, q, pubexp, t + 1 + qlen)) { + br_i15_add(q, q, 1); + q[1] |= 1; + br_i15_encode(sk->q, sk->qlen, q); + br_i15_encode(sk->dq, sk->dqlen, t); + break; + } + } + + /* + * If p and q have the same size, then it is possible that q > p + * (when the target modulus size is odd, we generate p with a + * greater bit length than q). If q > p, we want to swap p and q + * (and also dp and dq) for two reasons: + * - The final step below (inversion of q modulo p) is easier if + * p > q. + * - While BearSSL's RSA code is perfectly happy with RSA keys such + * that p < q, some other implementations have restrictions and + * require p > q. + * + * Note that we can do a simple non-constant-time swap here, + * because the only information we leak here is that we insist on + * returning p and q such that p > q, which is not a secret. + */ + if (esize_p == esize_q && br_i15_sub(p, q, 0) == 1) { + bufswap(p, q, (1 + plen) * sizeof *p); + bufswap(sk->p, sk->q, sk->plen); + bufswap(sk->dp, sk->dq, sk->dplen); + } + + /* + * We have produced p, q, dp and dq. We can now compute iq = 1/d mod p. + * + * We ensured that p >= q, so this is just a matter of updating the + * header word for q (and possibly adding an extra word). + * + * Theoretically, the call below may fail, in case we were + * extraordinarily unlucky, and p = q. Another failure case is if + * Miller-Rabin failed us _twice_, and p and q are non-prime and + * have a factor is common. We report the error mostly because it + * is cheap and we can, but in practice this never happens (or, at + * least, it happens way less often than hardware glitches). + */ + q[0] = p[0]; + if (plen > qlen) { + q[plen] = 0; + t ++; + tlen --; + } + br_i15_zero(t, p[0]); + t[1] = 1; + r = br_i15_moddiv(t, q, p, br_i15_ninv15(p[1]), t + 1 + plen); + br_i15_encode(sk->iq, sk->iqlen, t); + + /* + * Compute the public modulus too, if required. + */ + if (pk != NULL) { + br_i15_zero(t, p[0]); + br_i15_mulacc(t, p, q); + br_i15_encode(pk->n, pk->nlen, t); + } + + return r; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i15_modulus.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i15_modulus.c new file mode 100644 index 000000000..e3a29e665 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i15_modulus.c @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_rsa.h */ +size_t +br_rsa_i15_compute_modulus(void *n, const br_rsa_private_key *sk) +{ + uint16_t tmp[4 * (((BR_MAX_RSA_SIZE / 2) + 14) / 15) + 5]; + uint16_t *t, *p, *q; + const unsigned char *pbuf, *qbuf; + size_t nlen, plen, qlen, tlen; + + /* + * Compute actual byte and lengths for p and q. + */ + pbuf = sk->p; + plen = sk->plen; + while (plen > 0 && *pbuf == 0) { + pbuf ++; + plen --; + } + qbuf = sk->q; + qlen = sk->qlen; + while (qlen > 0 && *qbuf == 0) { + qbuf ++; + qlen --; + } + + t = tmp; + tlen = (sizeof tmp) / (sizeof tmp[0]); + + /* + * Decode p. + */ + if ((15 * tlen) < (plen << 3) + 15) { + return 0; + } + br_i15_decode(t, pbuf, plen); + p = t; + plen = (p[0] + 31) >> 4; + t += plen; + tlen -= plen; + + /* + * Decode q. + */ + if ((15 * tlen) < (qlen << 3) + 15) { + return 0; + } + br_i15_decode(t, qbuf, qlen); + q = t; + qlen = (q[0] + 31) >> 4; + t += qlen; + tlen -= qlen; + + /* + * Computation can proceed only if we have enough room for the + * modulus. + */ + if (tlen < (plen + qlen + 1)) { + return 0; + } + + /* + * Private key already contains the modulus bit length, from which + * we can infer the output length. Even if n is NULL, we still had + * to decode p and q to make sure that the product can be computed. + */ + nlen = (sk->n_bitlen + 7) >> 3; + if (n != NULL) { + br_i15_zero(t, p[0]); + br_i15_mulacc(t, p, q); + br_i15_encode(n, nlen, t); + } + return nlen; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i15_oaep_decrypt.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i15_oaep_decrypt.c new file mode 100644 index 000000000..71f3aa362 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i15_oaep_decrypt.c @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_rsa.h */ +uint32_t +br_rsa_i15_oaep_decrypt(const br_hash_class *dig, + const void *label, size_t label_len, + const br_rsa_private_key *sk, void *data, size_t *len) +{ + uint32_t r; + + if (*len != ((sk->n_bitlen + 7) >> 3)) { + return 0; + } + r = br_rsa_i15_private(data, sk); + r &= br_rsa_oaep_unpad(dig, label, label_len, data, len); + return r; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i15_oaep_encrypt.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i15_oaep_encrypt.c new file mode 100644 index 000000000..cdbcd34b9 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i15_oaep_encrypt.c @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_rsa.h */ +size_t +br_rsa_i15_oaep_encrypt( + const br_prng_class **rnd, const br_hash_class *dig, + const void *label, size_t label_len, + const br_rsa_public_key *pk, + void *dst, size_t dst_max_len, + const void *src, size_t src_len) +{ + size_t dlen; + + dlen = br_rsa_oaep_pad(rnd, dig, label, label_len, + pk, dst, dst_max_len, src, src_len); + if (dlen == 0) { + return 0; + } + return dlen & -(size_t)br_rsa_i15_public(dst, dlen, pk); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i15_pkcs1_sign.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i15_pkcs1_sign.c new file mode 100644 index 000000000..89c649c00 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i15_pkcs1_sign.c @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_rsa.h */ +uint32_t +br_rsa_i15_pkcs1_sign(const unsigned char *hash_oid, + const unsigned char *hash, size_t hash_len, + const br_rsa_private_key *sk, unsigned char *x) +{ + if (!br_rsa_pkcs1_sig_pad(hash_oid, hash, hash_len, sk->n_bitlen, x)) { + return 0; + } + return br_rsa_i15_private(x, sk); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i15_pkcs1_vrfy.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i15_pkcs1_vrfy.c new file mode 100644 index 000000000..1be46e2e1 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i15_pkcs1_vrfy.c @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_rsa.h */ +uint32_t +br_rsa_i15_pkcs1_vrfy(const unsigned char *x, size_t xlen, + const unsigned char *hash_oid, size_t hash_len, + const br_rsa_public_key *pk, unsigned char *hash_out) +{ + unsigned char sig[BR_MAX_RSA_SIZE >> 3]; + + if (xlen > (sizeof sig)) { + return 0; + } + memcpy(sig, x, xlen); + if (!br_rsa_i15_public(sig, xlen, pk)) { + return 0; + } + return br_rsa_pkcs1_sig_unpad(sig, xlen, hash_oid, hash_len, hash_out); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i15_priv.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i15_priv.c new file mode 100644 index 000000000..9ce138197 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i15_priv.c @@ -0,0 +1,214 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +#define U (2 + ((BR_MAX_RSA_FACTOR + 14) / 15)) +#define TLEN (8 * U) + +/* see bearssl_rsa.h */ +uint32_t +br_rsa_i15_private(unsigned char *x, const br_rsa_private_key *sk) +{ + const unsigned char *p, *q; + size_t plen, qlen; + size_t fwlen; + uint16_t p0i, q0i; + size_t xlen, u; + uint16_t tmp[1 + TLEN]; + long z; + uint16_t *mp, *mq, *s1, *s2, *t1, *t2, *t3; + uint32_t r; + + /* + * Compute the actual lengths of p and q, in bytes. + * These lengths are not considered secret (we cannot really hide + * them anyway in constant-time code). + */ + p = sk->p; + plen = sk->plen; + while (plen > 0 && *p == 0) { + p ++; + plen --; + } + q = sk->q; + qlen = sk->qlen; + while (qlen > 0 && *q == 0) { + q ++; + qlen --; + } + + /* + * Compute the maximum factor length, in words. + */ + z = (long)(plen > qlen ? plen : qlen) << 3; + fwlen = 1; + while (z > 0) { + z -= 15; + fwlen ++; + } + /* + * Round up the word length to an even number. + */ + fwlen += (fwlen & 1); + + /* + * We need to fit at least 6 values in the stack buffer. + */ + if (6 * fwlen > TLEN) { + return 0; + } + + /* + * Compute signature length (in bytes). + */ + xlen = (sk->n_bitlen + 7) >> 3; + + /* + * Ensure 32-bit alignment for value words. + */ + mq = tmp; + if (((uintptr_t)mq & 2) == 0) { + mq ++; + } + + /* + * Decode q. + */ + br_i15_decode(mq, q, qlen); + + /* + * Decode p. + */ + t1 = mq + fwlen; + br_i15_decode(t1, p, plen); + + /* + * Compute the modulus (product of the two factors), to compare + * it with the source value. We use br_i15_mulacc(), since it's + * already used later on. + */ + t2 = mq + 2 * fwlen; + br_i15_zero(t2, mq[0]); + br_i15_mulacc(t2, mq, t1); + + /* + * We encode the modulus into bytes, to perform the comparison + * with bytes. We know that the product length, in bytes, is + * exactly xlen. + * The comparison actually computes the carry when subtracting + * the modulus from the source value; that carry must be 1 for + * a value in the correct range. We keep it in r, which is our + * accumulator for the error code. + */ + t3 = mq + 4 * fwlen; + br_i15_encode(t3, xlen, t2); + u = xlen; + r = 0; + while (u > 0) { + uint32_t wn, wx; + + u --; + wn = ((unsigned char *)t3)[u]; + wx = x[u]; + r = ((wx - (wn + r)) >> 8) & 1; + } + + /* + * Move the decoded p to another temporary buffer. + */ + mp = mq + 2 * fwlen; + memmove(mp, t1, fwlen * sizeof *t1); + + /* + * Compute s2 = x^dq mod q. + */ + q0i = br_i15_ninv15(mq[1]); + s2 = mq + fwlen; + br_i15_decode_reduce(s2, x, xlen, mq); + r &= br_i15_modpow_opt(s2, sk->dq, sk->dqlen, mq, q0i, + mq + 3 * fwlen, TLEN - 3 * fwlen); + + /* + * Compute s1 = x^dq mod q. + */ + p0i = br_i15_ninv15(mp[1]); + s1 = mq + 3 * fwlen; + br_i15_decode_reduce(s1, x, xlen, mp); + r &= br_i15_modpow_opt(s1, sk->dp, sk->dplen, mp, p0i, + mq + 4 * fwlen, TLEN - 4 * fwlen); + + /* + * Compute: + * h = (s1 - s2)*(1/q) mod p + * s1 is an integer modulo p, but s2 is modulo q. PKCS#1 is + * unclear about whether p may be lower than q (some existing, + * widely deployed implementations of RSA don't tolerate p < q), + * but we want to support that occurrence, so we need to use the + * reduction function. + * + * Since we use br_i15_decode_reduce() for iq (purportedly, the + * inverse of q modulo p), we also tolerate improperly large + * values for this parameter. + */ + t1 = mq + 4 * fwlen; + t2 = mq + 5 * fwlen; + br_i15_reduce(t2, s2, mp); + br_i15_add(s1, mp, br_i15_sub(s1, t2, 1)); + br_i15_to_monty(s1, mp); + br_i15_decode_reduce(t1, sk->iq, sk->iqlen, mp); + br_i15_montymul(t2, s1, t1, mp, p0i); + + /* + * h is now in t2. We compute the final result: + * s = s2 + q*h + * All these operations are non-modular. + * + * We need mq, s2 and t2. We use the t3 buffer as destination. + * The buffers mp, s1 and t1 are no longer needed, so we can + * reuse them for t3. Moreover, the first step of the computation + * is to copy s2 into t3, after which s2 is not needed. Right + * now, mq is in slot 0, s2 is in slot 1, and t2 in slot 5. + * Therefore, we have ample room for t3 by simply using s2. + */ + t3 = s2; + br_i15_mulacc(t3, mq, t2); + + /* + * Encode the result. Since we already checked the value of xlen, + * we can just use it right away. + */ + br_i15_encode(x, xlen, t3); + + /* + * The only error conditions remaining at that point are invalid + * values for p and q (even integers). + */ + return p0i & q0i & r; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i15_privexp.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i15_privexp.c new file mode 100644 index 000000000..0d6548a54 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i15_privexp.c @@ -0,0 +1,325 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_rsa.h */ +size_t +br_rsa_i15_compute_privexp(void *d, + const br_rsa_private_key *sk, uint32_t e) +{ + /* + * We want to invert e modulo phi = (p-1)(q-1). This first + * requires computing phi, which is easy since we have the factors + * p and q in the private key structure. + * + * Since p = 3 mod 4 and q = 3 mod 4, phi/4 is an odd integer. + * We could invert e modulo phi/4 then patch the result to + * modulo phi, but this would involve assembling three modulus-wide + * values (phi/4, 1 and e) and calling moddiv, that requires + * three more temporaries, for a total of six big integers, or + * slightly more than 3 kB of stack space for RSA-4096. This + * exceeds our stack requirements. + * + * Instead, we first use one step of the extended GCD: + * + * - We compute phi = k*e + r (Euclidean division of phi by e). + * If public exponent e is correct, then r != 0 (e must be + * invertible modulo phi). We also have k != 0 since we + * enforce non-ridiculously-small factors. + * + * - We find small u, v such that u*e - v*r = 1 (using a + * binary GCD; we can arrange for u < r and v < e, i.e. all + * values fit on 32 bits). + * + * - Solution is: d = u + v*k + * This last computation is exact: since u < r and v < e, + * the above implies d < r + e*((phi-r)/e) = phi + */ + + uint16_t tmp[4 * ((BR_MAX_RSA_FACTOR + 14) / 15) + 12]; + uint16_t *p, *q, *k, *m, *z, *phi; + const unsigned char *pbuf, *qbuf; + size_t plen, qlen, u, len, dlen; + uint32_t r, a, b, u0, v0, u1, v1, he, hr; + int i; + + /* + * Check that e is correct. + */ + if (e < 3 || (e & 1) == 0) { + return 0; + } + + /* + * Check lengths of p and q, and that they are both odd. + */ + pbuf = sk->p; + plen = sk->plen; + while (plen > 0 && *pbuf == 0) { + pbuf ++; + plen --; + } + if (plen < 5 || plen > (BR_MAX_RSA_FACTOR / 8) + || (pbuf[plen - 1] & 1) != 1) + { + return 0; + } + qbuf = sk->q; + qlen = sk->qlen; + while (qlen > 0 && *qbuf == 0) { + qbuf ++; + qlen --; + } + if (qlen < 5 || qlen > (BR_MAX_RSA_FACTOR / 8) + || (qbuf[qlen - 1] & 1) != 1) + { + return 0; + } + + /* + * Output length is that of the modulus. + */ + dlen = (sk->n_bitlen + 7) >> 3; + if (d == NULL) { + return dlen; + } + + p = tmp; + br_i15_decode(p, pbuf, plen); + plen = (p[0] + 15) >> 4; + q = p + 1 + plen; + br_i15_decode(q, qbuf, qlen); + qlen = (q[0] + 15) >> 4; + + /* + * Compute phi = (p-1)*(q-1), then move it over p-1 and q-1 (that + * we do not need anymore). The mulacc function sets the announced + * bit length of t to be the sum of the announced bit lengths of + * p-1 and q-1, which is usually exact but may overshoot by one 1 + * bit in some cases; we readjust it to its true length. + */ + p[1] --; + q[1] --; + phi = q + 1 + qlen; + br_i15_zero(phi, p[0]); + br_i15_mulacc(phi, p, q); + len = (phi[0] + 15) >> 4; + memmove(tmp, phi, (1 + len) * sizeof *phi); + phi = tmp; + phi[0] = br_i15_bit_length(phi + 1, len); + len = (phi[0] + 15) >> 4; + + /* + * Divide phi by public exponent e. The final remainder r must be + * non-zero (otherwise, the key is invalid). The quotient is k, + * which we write over phi, since we don't need phi after that. + */ + r = 0; + for (u = len; u >= 1; u --) { + /* + * Upon entry, r < e, and phi[u] < 2^15; hence, + * hi:lo < e*2^15. Thus, the produced word k[u] + * must be lower than 2^15, and the new remainder r + * is lower than e. + */ + uint32_t hi, lo; + + hi = r >> 17; + lo = (r << 15) + phi[u]; + phi[u] = br_divrem(hi, lo, e, &r); + } + if (r == 0) { + return 0; + } + k = phi; + + /* + * Compute u and v such that u*e - v*r = GCD(e,r). We use + * a binary GCD algorithm, with 6 extra integers a, b, + * u0, u1, v0 and v1. Initial values are: + * a = e u0 = 1 v0 = 0 + * b = r u1 = r v1 = e-1 + * The following invariants are maintained: + * a = u0*e - v0*r + * b = u1*e - v1*r + * 0 < a <= e + * 0 < b <= r + * 0 <= u0 <= r + * 0 <= v0 <= e + * 0 <= u1 <= r + * 0 <= v1 <= e + * + * At each iteration, we reduce either a or b by one bit, and + * adjust u0, u1, v0 and v1 to maintain the invariants: + * - if a is even, then a <- a/2 + * - otherwise, if b is even, then b <- b/2 + * - otherwise, if a > b, then a <- (a-b)/2 + * - otherwise, if b > a, then b <- (b-a)/2 + * Algorithm stops when a = b. At that point, the common value + * is the GCD of e and r; it must be 1 (otherwise, the private + * key or public exponent is not valid). The (u0,v0) or (u1,v1) + * pairs are the solution we are looking for. + * + * Since either a or b is reduced by at least 1 bit at each + * iteration, 62 iterations are enough to reach the end + * condition. + * + * To maintain the invariants, we must compute the same operations + * on the u* and v* values that we do on a and b: + * - When a is divided by 2, u0 and v0 must be divided by 2. + * - When b is divided by 2, u1 and v1 must be divided by 2. + * - When b is subtracted from a, u1 and v1 are subtracted from + * u0 and v0, respectively. + * - When a is subtracted from b, u0 and v0 are subtracted from + * u1 and v1, respectively. + * + * However, we want to keep the u* and v* values in their proper + * ranges. The following remarks apply: + * + * - When a is divided by 2, then a is even. Therefore: + * + * * If r is odd, then u0 and v0 must have the same parity; + * if they are both odd, then adding r to u0 and e to v0 + * makes them both even, and the division by 2 brings them + * back to the proper range. + * + * * If r is even, then u0 must be even; if v0 is odd, then + * adding r to u0 and e to v0 makes them both even, and the + * division by 2 brings them back to the proper range. + * + * Thus, all we need to do is to look at the parity of v0, + * and add (r,e) to (u0,v0) when v0 is odd. In order to avoid + * a 32-bit overflow, we can add ((r+1)/2,(e/2)+1) after the + * division (r+1 does not overflow since r < e; and (e/2)+1 + * is equal to (e+1)/2 since e is odd). + * + * - When we subtract b from a, three cases may occur: + * + * * u1 <= u0 and v1 <= v0: just do the subtractions + * + * * u1 > u0 and v1 > v0: compute: + * (u0, v0) <- (u0 + r - u1, v0 + e - v1) + * + * * u1 <= u0 and v1 > v0: compute: + * (u0, v0) <- (u0 + r - u1, v0 + e - v1) + * + * The fourth case (u1 > u0 and v1 <= v0) is not possible + * because it would contradict "b < a" (which is the reason + * why we subtract b from a). + * + * The tricky case is the third one: from the equations, it + * seems that u0 may go out of range. However, the invariants + * and ranges of other values imply that, in that case, the + * new u0 does not actually exceed the range. + * + * We can thus handle the subtraction by adding (r,e) based + * solely on the comparison between v0 and v1. + */ + a = e; + b = r; + u0 = 1; + v0 = 0; + u1 = r; + v1 = e - 1; + hr = (r + 1) >> 1; + he = (e >> 1) + 1; + for (i = 0; i < 62; i ++) { + uint32_t oa, ob, agtb, bgta; + uint32_t sab, sba, da, db; + uint32_t ctl; + + oa = a & 1; /* 1 if a is odd */ + ob = b & 1; /* 1 if b is odd */ + agtb = GT(a, b); /* 1 if a > b */ + bgta = GT(b, a); /* 1 if b > a */ + + sab = oa & ob & agtb; /* 1 if a <- a-b */ + sba = oa & ob & bgta; /* 1 if b <- b-a */ + + /* a <- a-b, u0 <- u0-u1, v0 <- v0-v1 */ + ctl = GT(v1, v0); + a -= b & -sab; + u0 -= (u1 - (r & -ctl)) & -sab; + v0 -= (v1 - (e & -ctl)) & -sab; + + /* b <- b-a, u1 <- u1-u0 mod r, v1 <- v1-v0 mod e */ + ctl = GT(v0, v1); + b -= a & -sba; + u1 -= (u0 - (r & -ctl)) & -sba; + v1 -= (v0 - (e & -ctl)) & -sba; + + da = NOT(oa) | sab; /* 1 if a <- a/2 */ + db = (oa & NOT(ob)) | sba; /* 1 if b <- b/2 */ + + /* a <- a/2, u0 <- u0/2, v0 <- v0/2 */ + ctl = v0 & 1; + a ^= (a ^ (a >> 1)) & -da; + u0 ^= (u0 ^ ((u0 >> 1) + (hr & -ctl))) & -da; + v0 ^= (v0 ^ ((v0 >> 1) + (he & -ctl))) & -da; + + /* b <- b/2, u1 <- u1/2 mod r, v1 <- v1/2 mod e */ + ctl = v1 & 1; + b ^= (b ^ (b >> 1)) & -db; + u1 ^= (u1 ^ ((u1 >> 1) + (hr & -ctl))) & -db; + v1 ^= (v1 ^ ((v1 >> 1) + (he & -ctl))) & -db; + } + + /* + * Check that the GCD is indeed 1. If not, then the key is invalid + * (and there's no harm in leaking that piece of information). + */ + if (a != 1) { + return 0; + } + + /* + * Now we have u0*e - v0*r = 1. Let's compute the result as: + * d = u0 + v0*k + * We still have k in the tmp[] array, and its announced bit + * length is that of phi. + */ + m = k + 1 + len; + m[0] = (2 << 4) + 2; /* bit length is 32 bits, encoded */ + m[1] = v0 & 0x7FFF; + m[2] = (v0 >> 15) & 0x7FFF; + m[3] = v0 >> 30; + z = m + 4; + br_i15_zero(z, k[0]); + z[1] = u0 & 0x7FFF; + z[2] = (u0 >> 15) & 0x7FFF; + z[3] = u0 >> 30; + br_i15_mulacc(z, k, m); + + /* + * Encode the result. + */ + br_i15_encode(d, dlen, z); + return dlen; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i15_pss_sign.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i15_pss_sign.c new file mode 100644 index 000000000..faf03ac10 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i15_pss_sign.c @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_rsa.h */ +uint32_t +br_rsa_i15_pss_sign(const br_prng_class **rng, + const br_hash_class *hf_data, const br_hash_class *hf_mgf1, + const unsigned char *hash, size_t salt_len, + const br_rsa_private_key *sk, unsigned char *x) +{ + if (!br_rsa_pss_sig_pad(rng, hf_data, hf_mgf1, hash, + salt_len, sk->n_bitlen, x)) + { + return 0; + } + return br_rsa_i15_private(x, sk); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i15_pss_vrfy.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i15_pss_vrfy.c new file mode 100644 index 000000000..a2664b4be --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i15_pss_vrfy.c @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_rsa.h */ +uint32_t +br_rsa_i15_pss_vrfy(const unsigned char *x, size_t xlen, + const br_hash_class *hf_data, const br_hash_class *hf_mgf1, + const void *hash, size_t salt_len, const br_rsa_public_key *pk) +{ + unsigned char sig[BR_MAX_RSA_SIZE >> 3]; + + if (xlen > (sizeof sig)) { + return 0; + } + memcpy(sig, x, xlen); + if (!br_rsa_i15_public(sig, xlen, pk)) { + return 0; + } + return br_rsa_pss_sig_unpad(hf_data, hf_mgf1, + hash, salt_len, pk, sig); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i15_pub.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i15_pub.c new file mode 100644 index 000000000..6fe3c5e27 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i15_pub.c @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* + * As a strict minimum, we need four buffers that can hold a + * modular integer. + */ +#define TLEN (4 * (2 + ((BR_MAX_RSA_SIZE + 14) / 15))) + +/* see bearssl_rsa.h */ +uint32_t +br_rsa_i15_public(unsigned char *x, size_t xlen, + const br_rsa_public_key *pk) +{ + const unsigned char *n; + size_t nlen; + uint16_t tmp[1 + TLEN]; + uint16_t *m, *a, *t; + size_t fwlen; + long z; + uint16_t m0i; + uint32_t r; + + /* + * Get the actual length of the modulus, and see if it fits within + * our stack buffer. We also check that the length of x[] is valid. + */ + n = pk->n; + nlen = pk->nlen; + while (nlen > 0 && *n == 0) { + n ++; + nlen --; + } + if (nlen == 0 || nlen > (BR_MAX_RSA_SIZE >> 3) || xlen != nlen) { + return 0; + } + z = (long)nlen << 3; + fwlen = 1; + while (z > 0) { + z -= 15; + fwlen ++; + } + /* + * Round up length to an even number. + */ + fwlen += (fwlen & 1); + + /* + * The modulus gets decoded into m[]. + * The value to exponentiate goes into a[]. + * The temporaries for modular exponentiations are in t[]. + * + * We want the first value word of each integer to be aligned + * on a 32-bit boundary. + */ + m = tmp; + if (((uintptr_t)m & 2) == 0) { + m ++; + } + a = m + fwlen; + t = m + 2 * fwlen; + + /* + * Decode the modulus. + */ + br_i15_decode(m, n, nlen); + m0i = br_i15_ninv15(m[1]); + + /* + * Note: if m[] is even, then m0i == 0. Otherwise, m0i must be + * an odd integer. + */ + r = m0i & 1; + + /* + * Decode x[] into a[]; we also check that its value is proper. + */ + r &= br_i15_decode_mod(a, x, xlen, m); + + /* + * Compute the modular exponentiation. + */ + br_i15_modpow_opt(a, pk->e, pk->elen, m, m0i, t, TLEN - 2 * fwlen); + + /* + * Encode the result. + */ + br_i15_encode(x, xlen, a); + return r; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i15_pubexp.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i15_pubexp.c new file mode 100644 index 000000000..54c49a6dc --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i15_pubexp.c @@ -0,0 +1,157 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* + * Recompute public exponent, based on factor p and reduced private + * exponent dp. + */ +static uint32_t +get_pubexp(const unsigned char *pbuf, size_t plen, + const unsigned char *dpbuf, size_t dplen) +{ + /* + * dp is the inverse of e modulo p-1. If p = 3 mod 4, then + * p-1 = 2*((p-1)/2). Taken modulo 2, e is odd and has inverse 1; + * thus, dp must be odd. + * + * We compute the inverse of dp modulo (p-1)/2. This requires + * first reducing dp modulo (p-1)/2 (this can be done with a + * conditional subtract, no need to use the generic modular + * reduction function); then, we use moddiv. + */ + + uint16_t tmp[6 * ((BR_MAX_RSA_FACTOR + 29) / 15)]; + uint16_t *p, *dp, *x; + size_t len; + uint32_t e; + + /* + * Compute actual factor length (in bytes) and check that it fits + * under our size constraints. + */ + while (plen > 0 && *pbuf == 0) { + pbuf ++; + plen --; + } + if (plen == 0 || plen < 5 || plen > (BR_MAX_RSA_FACTOR / 8)) { + return 0; + } + + /* + * Compute actual reduced exponent length (in bytes) and check that + * it is not longer than p. + */ + while (dplen > 0 && *dpbuf == 0) { + dpbuf ++; + dplen --; + } + if (dplen > plen || dplen == 0 + || (dplen == plen && dpbuf[0] > pbuf[0])) + { + return 0; + } + + /* + * Verify that p = 3 mod 4 and that dp is odd. + */ + if ((pbuf[plen - 1] & 3) != 3 || (dpbuf[dplen - 1] & 1) != 1) { + return 0; + } + + /* + * Decode p and compute (p-1)/2. + */ + p = tmp; + br_i15_decode(p, pbuf, plen); + len = (p[0] + 31) >> 4; + br_i15_rshift(p, 1); + + /* + * Decode dp and make sure its announced bit length matches that of + * p (we already know that the size of dp, in bits, does not exceed + * the size of p, so we just have to copy the header word). + */ + dp = p + len; + memset(dp, 0, len * sizeof *dp); + br_i15_decode(dp, dpbuf, dplen); + dp[0] = p[0]; + + /* + * Subtract (p-1)/2 from dp if necessary. + */ + br_i15_sub(dp, p, NOT(br_i15_sub(dp, p, 0))); + + /* + * If another subtraction is needed, then this means that the + * value was invalid. We don't care to leak information about + * invalid keys. + */ + if (br_i15_sub(dp, p, 0) == 0) { + return 0; + } + + /* + * Invert dp modulo (p-1)/2. If the inversion fails, then the + * key value was invalid. + */ + x = dp + len; + br_i15_zero(x, p[0]); + x[1] = 1; + if (br_i15_moddiv(x, dp, p, br_i15_ninv15(p[1]), x + len) == 0) { + return 0; + } + + /* + * We now have an inverse. We must set it to zero (error) if its + * length is greater than 32 bits and/or if it is an even integer. + * Take care that the bit_length function returns an encoded + * bit length. + */ + e = (uint32_t)x[1] | ((uint32_t)x[2] << 15) | ((uint32_t)x[3] << 30); + e &= -LT(br_i15_bit_length(x + 1, len - 1), 35); + e &= -(e & 1); + return e; +} + +/* see bearssl_rsa.h */ +uint32_t +br_rsa_i15_compute_pubexp(const br_rsa_private_key *sk) +{ + /* + * Get the public exponent from both p and q. This is the right + * exponent if we get twice the same value. + */ + uint32_t ep, eq; + + ep = get_pubexp(sk->p, sk->plen, sk->dp, sk->dplen); + eq = get_pubexp(sk->q, sk->qlen, sk->dq, sk->dqlen); + return ep & -EQ(ep, eq); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i31_keygen.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i31_keygen.c new file mode 100644 index 000000000..0d21fda9f --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i31_keygen.c @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_rsa.h */ +uint32_t +br_rsa_i31_keygen(const br_prng_class **rng, + br_rsa_private_key *sk, void *kbuf_priv, + br_rsa_public_key *pk, void *kbuf_pub, + unsigned size, uint32_t pubexp) +{ + return br_rsa_i31_keygen_inner(rng, + sk, kbuf_priv, pk, kbuf_pub, size, pubexp, + &br_i31_modpow_opt); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i31_keygen_inner.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i31_keygen_inner.c new file mode 100644 index 000000000..64aeb40fc --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i31_keygen_inner.c @@ -0,0 +1,613 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* + * Make a random integer of the provided size. The size is encoded. + * The header word is untouched. + */ +static void +mkrand(const br_prng_class **rng, uint32_t *x, uint32_t esize) +{ + size_t u, len; + unsigned m; + + len = (esize + 31) >> 5; + (*rng)->generate(rng, x + 1, len * sizeof(uint32_t)); + for (u = 1; u < len; u ++) { + x[u] &= 0x7FFFFFFF; + } + m = esize & 31; + if (m == 0) { + x[len] &= 0x7FFFFFFF; + } else { + x[len] &= 0x7FFFFFFF >> (31 - m); + } +} + +/* + * This is the big-endian unsigned representation of the product of + * all small primes from 13 to 1481. + */ +static const unsigned char SMALL_PRIMES[] = { + 0x2E, 0xAB, 0x92, 0xD1, 0x8B, 0x12, 0x47, 0x31, 0x54, 0x0A, + 0x99, 0x5D, 0x25, 0x5E, 0xE2, 0x14, 0x96, 0x29, 0x1E, 0xB7, + 0x78, 0x70, 0xCC, 0x1F, 0xA5, 0xAB, 0x8D, 0x72, 0x11, 0x37, + 0xFB, 0xD8, 0x1E, 0x3F, 0x5B, 0x34, 0x30, 0x17, 0x8B, 0xE5, + 0x26, 0x28, 0x23, 0xA1, 0x8A, 0xA4, 0x29, 0xEA, 0xFD, 0x9E, + 0x39, 0x60, 0x8A, 0xF3, 0xB5, 0xA6, 0xEB, 0x3F, 0x02, 0xB6, + 0x16, 0xC3, 0x96, 0x9D, 0x38, 0xB0, 0x7D, 0x82, 0x87, 0x0C, + 0xF7, 0xBE, 0x24, 0xE5, 0x5F, 0x41, 0x04, 0x79, 0x76, 0x40, + 0xE7, 0x00, 0x22, 0x7E, 0xB5, 0x85, 0x7F, 0x8D, 0x01, 0x50, + 0xE9, 0xD3, 0x29, 0x42, 0x08, 0xB3, 0x51, 0x40, 0x7B, 0xD7, + 0x8D, 0xCC, 0x10, 0x01, 0x64, 0x59, 0x28, 0xB6, 0x53, 0xF3, + 0x50, 0x4E, 0xB1, 0xF2, 0x58, 0xCD, 0x6E, 0xF5, 0x56, 0x3E, + 0x66, 0x2F, 0xD7, 0x07, 0x7F, 0x52, 0x4C, 0x13, 0x24, 0xDC, + 0x8E, 0x8D, 0xCC, 0xED, 0x77, 0xC4, 0x21, 0xD2, 0xFD, 0x08, + 0xEA, 0xD7, 0xC0, 0x5C, 0x13, 0x82, 0x81, 0x31, 0x2F, 0x2B, + 0x08, 0xE4, 0x80, 0x04, 0x7A, 0x0C, 0x8A, 0x3C, 0xDC, 0x22, + 0xE4, 0x5A, 0x7A, 0xB0, 0x12, 0x5E, 0x4A, 0x76, 0x94, 0x77, + 0xC2, 0x0E, 0x92, 0xBA, 0x8A, 0xA0, 0x1F, 0x14, 0x51, 0x1E, + 0x66, 0x6C, 0x38, 0x03, 0x6C, 0xC7, 0x4A, 0x4B, 0x70, 0x80, + 0xAF, 0xCA, 0x84, 0x51, 0xD8, 0xD2, 0x26, 0x49, 0xF5, 0xA8, + 0x5E, 0x35, 0x4B, 0xAC, 0xCE, 0x29, 0x92, 0x33, 0xB7, 0xA2, + 0x69, 0x7D, 0x0C, 0xE0, 0x9C, 0xDB, 0x04, 0xD6, 0xB4, 0xBC, + 0x39, 0xD7, 0x7F, 0x9E, 0x9D, 0x78, 0x38, 0x7F, 0x51, 0x54, + 0x50, 0x8B, 0x9E, 0x9C, 0x03, 0x6C, 0xF5, 0x9D, 0x2C, 0x74, + 0x57, 0xF0, 0x27, 0x2A, 0xC3, 0x47, 0xCA, 0xB9, 0xD7, 0x5C, + 0xFF, 0xC2, 0xAC, 0x65, 0x4E, 0xBD +}; + +/* + * We need temporary values for at least 7 integers of the same size + * as a factor (including header word); more space helps with performance + * (in modular exponentiations), but we much prefer to remain under + * 2 kilobytes in total, to save stack space. The macro TEMPS below + * exceeds 512 (which is a count in 32-bit words) when BR_MAX_RSA_SIZE + * is greater than 4464 (default value is 4096, so the 2-kB limit is + * maintained unless BR_MAX_RSA_SIZE was modified). + */ +#define MAX(x, y) ((x) > (y) ? (x) : (y)) +#define ROUND2(x) ((((x) + 1) >> 1) << 1) + +#define TEMPS MAX(512, ROUND2(7 * ((((BR_MAX_RSA_SIZE + 1) >> 1) + 61) / 31))) + +/* + * Perform trial division on a candidate prime. This computes + * y = SMALL_PRIMES mod x, then tries to compute y/y mod x. The + * br_i31_moddiv() function will report an error if y is not invertible + * modulo x. Returned value is 1 on success (none of the small primes + * divides x), 0 on error (a non-trivial GCD is obtained). + * + * This function assumes that x is odd. + */ +static uint32_t +trial_divisions(const uint32_t *x, uint32_t *t) +{ + uint32_t *y; + uint32_t x0i; + + y = t; + t += 1 + ((x[0] + 31) >> 5); + x0i = br_i31_ninv31(x[1]); + br_i31_decode_reduce(y, SMALL_PRIMES, sizeof SMALL_PRIMES, x); + return br_i31_moddiv(y, y, x, x0i, t); +} + +/* + * Perform n rounds of Miller-Rabin on the candidate prime x. This + * function assumes that x = 3 mod 4. + * + * Returned value is 1 on success (all rounds completed successfully), + * 0 otherwise. + */ +static uint32_t +miller_rabin(const br_prng_class **rng, const uint32_t *x, int n, + uint32_t *t, size_t tlen, br_i31_modpow_opt_type mp31) +{ + /* + * Since x = 3 mod 4, the Miller-Rabin test is simple: + * - get a random base a (such that 1 < a < x-1) + * - compute z = a^((x-1)/2) mod x + * - if z != 1 and z != x-1, the number x is composite + * + * We generate bases 'a' randomly with a size which is + * one bit less than x, which ensures that a < x-1. It + * is not useful to verify that a > 1 because the probability + * that we get a value a equal to 0 or 1 is much smaller + * than the probability of our Miller-Rabin tests not to + * detect a composite, which is already quite smaller than the + * probability of the hardware misbehaving and return a + * composite integer because of some glitch (e.g. bad RAM + * or ill-timed cosmic ray). + */ + unsigned char *xm1d2; + size_t xlen, xm1d2_len, xm1d2_len_u32, u; + uint32_t asize; + unsigned cc; + uint32_t x0i; + + /* + * Compute (x-1)/2 (encoded). + */ + xm1d2 = (unsigned char *)t; + xm1d2_len = ((x[0] - (x[0] >> 5)) + 7) >> 3; + br_i31_encode(xm1d2, xm1d2_len, x); + cc = 0; + for (u = 0; u < xm1d2_len; u ++) { + unsigned w; + + w = xm1d2[u]; + xm1d2[u] = (unsigned char)((w >> 1) | cc); + cc = w << 7; + } + + /* + * We used some words of the provided buffer for (x-1)/2. + */ + xm1d2_len_u32 = (xm1d2_len + 3) >> 2; + t += xm1d2_len_u32; + tlen -= xm1d2_len_u32; + + xlen = (x[0] + 31) >> 5; + asize = x[0] - 1 - EQ0(x[0] & 31); + x0i = br_i31_ninv31(x[1]); + while (n -- > 0) { + uint32_t *a, *t2; + uint32_t eq1, eqm1; + size_t t2len; + + /* + * Generate a random base. We don't need the base to be + * really uniform modulo x, so we just get a random + * number which is one bit shorter than x. + */ + a = t; + a[0] = x[0]; + a[xlen] = 0; + mkrand(rng, a, asize); + + /* + * Compute a^((x-1)/2) mod x. We assume here that the + * function will not fail (the temporary array is large + * enough). + */ + t2 = t + 1 + xlen; + t2len = tlen - 1 - xlen; + if ((t2len & 1) != 0) { + /* + * Since the source array is 64-bit aligned and + * has an even number of elements (TEMPS), we + * can use the parity of the remaining length to + * detect and adjust alignment. + */ + t2 ++; + t2len --; + } + mp31(a, xm1d2, xm1d2_len, x, x0i, t2, t2len); + + /* + * We must obtain either 1 or x-1. Note that x is odd, + * hence x-1 differs from x only in its low word (no + * carry). + */ + eq1 = a[1] ^ 1; + eqm1 = a[1] ^ (x[1] - 1); + for (u = 2; u <= xlen; u ++) { + eq1 |= a[u]; + eqm1 |= a[u] ^ x[u]; + } + + if ((EQ0(eq1) | EQ0(eqm1)) == 0) { + return 0; + } + } + return 1; +} + +/* + * Create a random prime of the provided size. 'size' is the _encoded_ + * bit length. The two top bits and the two bottom bits are set to 1. + */ +static void +mkprime(const br_prng_class **rng, uint32_t *x, uint32_t esize, + uint32_t pubexp, uint32_t *t, size_t tlen, br_i31_modpow_opt_type mp31) +{ + size_t len; + + x[0] = esize; + len = (esize + 31) >> 5; + for (;;) { + size_t u; + uint32_t m3, m5, m7, m11; + int rounds, s7, s11; + + /* + * Generate random bits. We force the two top bits and the + * two bottom bits to 1. + */ + mkrand(rng, x, esize); + if ((esize & 31) == 0) { + x[len] |= 0x60000000; + } else if ((esize & 31) == 1) { + x[len] |= 0x00000001; + x[len - 1] |= 0x40000000; + } else { + x[len] |= 0x00000003 << ((esize & 31) - 2); + } + x[1] |= 0x00000003; + + /* + * Trial division with low primes (3, 5, 7 and 11). We + * use the following properties: + * + * 2^2 = 1 mod 3 + * 2^4 = 1 mod 5 + * 2^3 = 1 mod 7 + * 2^10 = 1 mod 11 + */ + m3 = 0; + m5 = 0; + m7 = 0; + m11 = 0; + s7 = 0; + s11 = 0; + for (u = 0; u < len; u ++) { + uint32_t w, w3, w5, w7, w11; + + w = x[1 + u]; + w3 = (w & 0xFFFF) + (w >> 16); /* max: 98302 */ + w5 = (w & 0xFFFF) + (w >> 16); /* max: 98302 */ + w7 = (w & 0x7FFF) + (w >> 15); /* max: 98302 */ + w11 = (w & 0xFFFFF) + (w >> 20); /* max: 1050622 */ + + m3 += w3 << (u & 1); + m3 = (m3 & 0xFF) + (m3 >> 8); /* max: 1025 */ + + m5 += w5 << ((4 - u) & 3); + m5 = (m5 & 0xFFF) + (m5 >> 12); /* max: 4479 */ + + m7 += w7 << s7; + m7 = (m7 & 0x1FF) + (m7 >> 9); /* max: 1280 */ + if (++ s7 == 3) { + s7 = 0; + } + + m11 += w11 << s11; + if (++ s11 == 10) { + s11 = 0; + } + m11 = (m11 & 0x3FF) + (m11 >> 10); /* max: 526847 */ + } + + m3 = (m3 & 0x3F) + (m3 >> 6); /* max: 78 */ + m3 = (m3 & 0x0F) + (m3 >> 4); /* max: 18 */ + m3 = ((m3 * 43) >> 5) & 3; + + m5 = (m5 & 0xFF) + (m5 >> 8); /* max: 271 */ + m5 = (m5 & 0x0F) + (m5 >> 4); /* max: 31 */ + m5 -= 20 & -GT(m5, 19); + m5 -= 10 & -GT(m5, 9); + m5 -= 5 & -GT(m5, 4); + + m7 = (m7 & 0x3F) + (m7 >> 6); /* max: 82 */ + m7 = (m7 & 0x07) + (m7 >> 3); /* max: 16 */ + m7 = ((m7 * 147) >> 7) & 7; + + /* + * 2^5 = 32 = -1 mod 11. + */ + m11 = (m11 & 0x3FF) + (m11 >> 10); /* max: 1536 */ + m11 = (m11 & 0x3FF) + (m11 >> 10); /* max: 1023 */ + m11 = (m11 & 0x1F) + 33 - (m11 >> 5); /* max: 64 */ + m11 -= 44 & -GT(m11, 43); + m11 -= 22 & -GT(m11, 21); + m11 -= 11 & -GT(m11, 10); + + /* + * If any of these modulo is 0, then the candidate is + * not prime. Also, if pubexp is 3, 5, 7 or 11, and the + * corresponding modulus is 1, then the candidate must + * be rejected, because we need e to be invertible + * modulo p-1. We can use simple comparisons here + * because they won't leak information on a candidate + * that we keep, only on one that we reject (and is thus + * not secret). + */ + if (m3 == 0 || m5 == 0 || m7 == 0 || m11 == 0) { + continue; + } + if ((pubexp == 3 && m3 == 1) + || (pubexp == 5 && m5 == 1) + || (pubexp == 7 && m7 == 1) + || (pubexp == 11 && m11 == 1)) + { + continue; + } + + /* + * More trial divisions. + */ + if (!trial_divisions(x, t)) { + continue; + } + + /* + * Miller-Rabin algorithm. Since we selected a random + * integer, not a maliciously crafted integer, we can use + * relatively few rounds to lower the risk of a false + * positive (i.e. declaring prime a non-prime) under + * 2^(-80). It is not useful to lower the probability much + * below that, since that would be substantially below + * the probability of the hardware misbehaving. Sufficient + * numbers of rounds are extracted from the Handbook of + * Applied Cryptography, note 4.49 (page 149). + * + * Since we work on the encoded size (esize), we need to + * compare with encoded thresholds. + */ + if (esize < 309) { + rounds = 12; + } else if (esize < 464) { + rounds = 9; + } else if (esize < 670) { + rounds = 6; + } else if (esize < 877) { + rounds = 4; + } else if (esize < 1341) { + rounds = 3; + } else { + rounds = 2; + } + + if (miller_rabin(rng, x, rounds, t, tlen, mp31)) { + return; + } + } +} + +/* + * Let p be a prime (p > 2^33, p = 3 mod 4). Let m = (p-1)/2, provided + * as parameter (with announced bit length equal to that of p). This + * function computes d = 1/e mod p-1 (for an odd integer e). Returned + * value is 1 on success, 0 on error (an error is reported if e is not + * invertible modulo p-1). + * + * The temporary buffer (t) must have room for at least 4 integers of + * the size of p. + */ +static uint32_t +invert_pubexp(uint32_t *d, const uint32_t *m, uint32_t e, uint32_t *t) +{ + uint32_t *f; + uint32_t r; + + f = t; + t += 1 + ((m[0] + 31) >> 5); + + /* + * Compute d = 1/e mod m. Since p = 3 mod 4, m is odd. + */ + br_i31_zero(d, m[0]); + d[1] = 1; + br_i31_zero(f, m[0]); + f[1] = e & 0x7FFFFFFF; + f[2] = e >> 31; + r = br_i31_moddiv(d, f, m, br_i31_ninv31(m[1]), t); + + /* + * We really want d = 1/e mod p-1, with p = 2m. By the CRT, + * the result is either the d we got, or d + m. + * + * Let's write e*d = 1 + k*m, for some integer k. Integers e + * and m are odd. If d is odd, then e*d is odd, which implies + * that k must be even; in that case, e*d = 1 + (k/2)*2m, and + * thus d is already fine. Conversely, if d is even, then k + * is odd, and we must add m to d in order to get the correct + * result. + */ + br_i31_add(d, m, (uint32_t)(1 - (d[1] & 1))); + + return r; +} + +/* + * Swap two buffers in RAM. They must be disjoint. + */ +static void +bufswap(void *b1, void *b2, size_t len) +{ + size_t u; + unsigned char *buf1, *buf2; + + buf1 = b1; + buf2 = b2; + for (u = 0; u < len; u ++) { + unsigned w; + + w = buf1[u]; + buf1[u] = buf2[u]; + buf2[u] = w; + } +} + +/* see inner.h */ +uint32_t +br_rsa_i31_keygen_inner(const br_prng_class **rng, + br_rsa_private_key *sk, void *kbuf_priv, + br_rsa_public_key *pk, void *kbuf_pub, + unsigned size, uint32_t pubexp, br_i31_modpow_opt_type mp31) +{ + uint32_t esize_p, esize_q; + size_t plen, qlen, tlen; + uint32_t *p, *q, *t; + union { + uint32_t t32[TEMPS]; + uint64_t t64[TEMPS >> 1]; /* for 64-bit alignment */ + } tmp; + uint32_t r; + + if (size < BR_MIN_RSA_SIZE || size > BR_MAX_RSA_SIZE) { + return 0; + } + if (pubexp == 0) { + pubexp = 3; + } else if (pubexp == 1 || (pubexp & 1) == 0) { + return 0; + } + + esize_p = (size + 1) >> 1; + esize_q = size - esize_p; + sk->n_bitlen = size; + sk->p = kbuf_priv; + sk->plen = (esize_p + 7) >> 3; + sk->q = sk->p + sk->plen; + sk->qlen = (esize_q + 7) >> 3; + sk->dp = sk->q + sk->qlen; + sk->dplen = sk->plen; + sk->dq = sk->dp + sk->dplen; + sk->dqlen = sk->qlen; + sk->iq = sk->dq + sk->dqlen; + sk->iqlen = sk->plen; + + if (pk != NULL) { + pk->n = kbuf_pub; + pk->nlen = (size + 7) >> 3; + pk->e = pk->n + pk->nlen; + pk->elen = 4; + br_enc32be(pk->e, pubexp); + while (*pk->e == 0) { + pk->e ++; + pk->elen --; + } + } + + /* + * We now switch to encoded sizes. + * + * floor((x * 16913) / (2^19)) is equal to floor(x/31) for all + * integers x from 0 to 34966; the intermediate product fits on + * 30 bits, thus we can use MUL31(). + */ + esize_p += MUL31(esize_p, 16913) >> 19; + esize_q += MUL31(esize_q, 16913) >> 19; + plen = (esize_p + 31) >> 5; + qlen = (esize_q + 31) >> 5; + p = tmp.t32; + q = p + 1 + plen; + t = q + 1 + qlen; + tlen = ((sizeof tmp.t32) / sizeof(uint32_t)) - (2 + plen + qlen); + + /* + * When looking for primes p and q, we temporarily divide + * candidates by 2, in order to compute the inverse of the + * public exponent. + */ + + for (;;) { + mkprime(rng, p, esize_p, pubexp, t, tlen, mp31); + br_i31_rshift(p, 1); + if (invert_pubexp(t, p, pubexp, t + 1 + plen)) { + br_i31_add(p, p, 1); + p[1] |= 1; + br_i31_encode(sk->p, sk->plen, p); + br_i31_encode(sk->dp, sk->dplen, t); + break; + } + } + + for (;;) { + mkprime(rng, q, esize_q, pubexp, t, tlen, mp31); + br_i31_rshift(q, 1); + if (invert_pubexp(t, q, pubexp, t + 1 + qlen)) { + br_i31_add(q, q, 1); + q[1] |= 1; + br_i31_encode(sk->q, sk->qlen, q); + br_i31_encode(sk->dq, sk->dqlen, t); + break; + } + } + + /* + * If p and q have the same size, then it is possible that q > p + * (when the target modulus size is odd, we generate p with a + * greater bit length than q). If q > p, we want to swap p and q + * (and also dp and dq) for two reasons: + * - The final step below (inversion of q modulo p) is easier if + * p > q. + * - While BearSSL's RSA code is perfectly happy with RSA keys such + * that p < q, some other implementations have restrictions and + * require p > q. + * + * Note that we can do a simple non-constant-time swap here, + * because the only information we leak here is that we insist on + * returning p and q such that p > q, which is not a secret. + */ + if (esize_p == esize_q && br_i31_sub(p, q, 0) == 1) { + bufswap(p, q, (1 + plen) * sizeof *p); + bufswap(sk->p, sk->q, sk->plen); + bufswap(sk->dp, sk->dq, sk->dplen); + } + + /* + * We have produced p, q, dp and dq. We can now compute iq = 1/d mod p. + * + * We ensured that p >= q, so this is just a matter of updating the + * header word for q (and possibly adding an extra word). + * + * Theoretically, the call below may fail, in case we were + * extraordinarily unlucky, and p = q. Another failure case is if + * Miller-Rabin failed us _twice_, and p and q are non-prime and + * have a factor is common. We report the error mostly because it + * is cheap and we can, but in practice this never happens (or, at + * least, it happens way less often than hardware glitches). + */ + q[0] = p[0]; + if (plen > qlen) { + q[plen] = 0; + t ++; + tlen --; + } + br_i31_zero(t, p[0]); + t[1] = 1; + r = br_i31_moddiv(t, q, p, br_i31_ninv31(p[1]), t + 1 + plen); + br_i31_encode(sk->iq, sk->iqlen, t); + + /* + * Compute the public modulus too, if required. + */ + if (pk != NULL) { + br_i31_zero(t, p[0]); + br_i31_mulacc(t, p, q); + br_i31_encode(pk->n, pk->nlen, t); + } + + return r; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i31_modulus.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i31_modulus.c new file mode 100644 index 000000000..6372f5cd2 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i31_modulus.c @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_rsa.h */ +size_t +br_rsa_i31_compute_modulus(void *n, const br_rsa_private_key *sk) +{ + uint32_t tmp[4 * (((BR_MAX_RSA_SIZE / 2) + 30) / 31) + 5]; + uint32_t *t, *p, *q; + const unsigned char *pbuf, *qbuf; + size_t nlen, plen, qlen, tlen; + + /* + * Compute actual byte and lengths for p and q. + */ + pbuf = sk->p; + plen = sk->plen; + while (plen > 0 && *pbuf == 0) { + pbuf ++; + plen --; + } + qbuf = sk->q; + qlen = sk->qlen; + while (qlen > 0 && *qbuf == 0) { + qbuf ++; + qlen --; + } + + t = tmp; + tlen = (sizeof tmp) / (sizeof tmp[0]); + + /* + * Decode p. + */ + if ((31 * tlen) < (plen << 3) + 31) { + return 0; + } + br_i31_decode(t, pbuf, plen); + p = t; + plen = (p[0] + 63) >> 5; + t += plen; + tlen -= plen; + + /* + * Decode q. + */ + if ((31 * tlen) < (qlen << 3) + 31) { + return 0; + } + br_i31_decode(t, qbuf, qlen); + q = t; + qlen = (q[0] + 63) >> 5; + t += qlen; + tlen -= qlen; + + /* + * Computation can proceed only if we have enough room for the + * modulus. + */ + if (tlen < (plen + qlen + 1)) { + return 0; + } + + /* + * Private key already contains the modulus bit length, from which + * we can infer the output length. Even if n is NULL, we still had + * to decode p and q to make sure that the product can be computed. + */ + nlen = (sk->n_bitlen + 7) >> 3; + if (n != NULL) { + br_i31_zero(t, p[0]); + br_i31_mulacc(t, p, q); + br_i31_encode(n, nlen, t); + } + return nlen; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i31_oaep_decrypt.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i31_oaep_decrypt.c new file mode 100644 index 000000000..d3f14633a --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i31_oaep_decrypt.c @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_rsa.h */ +uint32_t +br_rsa_i31_oaep_decrypt(const br_hash_class *dig, + const void *label, size_t label_len, + const br_rsa_private_key *sk, void *data, size_t *len) +{ + uint32_t r; + + if (*len != ((sk->n_bitlen + 7) >> 3)) { + return 0; + } + r = br_rsa_i31_private(data, sk); + r &= br_rsa_oaep_unpad(dig, label, label_len, data, len); + return r; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i31_oaep_encrypt.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i31_oaep_encrypt.c new file mode 100644 index 000000000..413506cd2 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i31_oaep_encrypt.c @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_rsa.h */ +size_t +br_rsa_i31_oaep_encrypt( + const br_prng_class **rnd, const br_hash_class *dig, + const void *label, size_t label_len, + const br_rsa_public_key *pk, + void *dst, size_t dst_max_len, + const void *src, size_t src_len) +{ + size_t dlen; + + dlen = br_rsa_oaep_pad(rnd, dig, label, label_len, + pk, dst, dst_max_len, src, src_len); + if (dlen == 0) { + return 0; + } + return dlen & -(size_t)br_rsa_i31_public(dst, dlen, pk); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i31_pkcs1_sign.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i31_pkcs1_sign.c new file mode 100644 index 000000000..1f1f2f731 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i31_pkcs1_sign.c @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_rsa.h */ +uint32_t +br_rsa_i31_pkcs1_sign(const unsigned char *hash_oid, + const unsigned char *hash, size_t hash_len, + const br_rsa_private_key *sk, unsigned char *x) +{ + if (!br_rsa_pkcs1_sig_pad(hash_oid, hash, hash_len, sk->n_bitlen, x)) { + return 0; + } + return br_rsa_i31_private(x, sk); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i31_pkcs1_vrfy.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i31_pkcs1_vrfy.c new file mode 100644 index 000000000..dc8c809a4 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i31_pkcs1_vrfy.c @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_rsa.h */ +uint32_t +br_rsa_i31_pkcs1_vrfy(const unsigned char *x, size_t xlen, + const unsigned char *hash_oid, size_t hash_len, + const br_rsa_public_key *pk, unsigned char *hash_out) +{ + unsigned char sig[BR_MAX_RSA_SIZE >> 3]; + + if (xlen > (sizeof sig)) { + return 0; + } + memcpy(sig, x, xlen); + if (!br_rsa_i31_public(sig, xlen, pk)) { + return 0; + } + return br_rsa_pkcs1_sig_unpad(sig, xlen, hash_oid, hash_len, hash_out); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i31_priv.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i31_priv.c new file mode 100644 index 000000000..d61c5ae16 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i31_priv.c @@ -0,0 +1,208 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +#define U (2 + ((BR_MAX_RSA_FACTOR + 30) / 31)) +#define TLEN (8 * U) + +/* see bearssl_rsa.h */ +uint32_t +br_rsa_i31_private(unsigned char *x, const br_rsa_private_key *sk) +{ + const unsigned char *p, *q; + size_t plen, qlen; + size_t fwlen; + uint32_t p0i, q0i; + size_t xlen, u; + uint32_t tmp[1 + TLEN]; + long z; + uint32_t *mp, *mq, *s1, *s2, *t1, *t2, *t3; + uint32_t r; + + /* + * Compute the actual lengths of p and q, in bytes. + * These lengths are not considered secret (we cannot really hide + * them anyway in constant-time code). + */ + p = sk->p; + plen = sk->plen; + while (plen > 0 && *p == 0) { + p ++; + plen --; + } + q = sk->q; + qlen = sk->qlen; + while (qlen > 0 && *q == 0) { + q ++; + qlen --; + } + + /* + * Compute the maximum factor length, in words. + */ + z = (long)(plen > qlen ? plen : qlen) << 3; + fwlen = 1; + while (z > 0) { + z -= 31; + fwlen ++; + } + + /* + * Round up the word length to an even number. + */ + fwlen += (fwlen & 1); + + /* + * We need to fit at least 6 values in the stack buffer. + */ + if (6 * fwlen > TLEN) { + return 0; + } + + /* + * Compute modulus length (in bytes). + */ + xlen = (sk->n_bitlen + 7) >> 3; + + /* + * Decode q. + */ + mq = tmp; + br_i31_decode(mq, q, qlen); + + /* + * Decode p. + */ + t1 = mq + fwlen; + br_i31_decode(t1, p, plen); + + /* + * Compute the modulus (product of the two factors), to compare + * it with the source value. We use br_i31_mulacc(), since it's + * already used later on. + */ + t2 = mq + 2 * fwlen; + br_i31_zero(t2, mq[0]); + br_i31_mulacc(t2, mq, t1); + + /* + * We encode the modulus into bytes, to perform the comparison + * with bytes. We know that the product length, in bytes, is + * exactly xlen. + * The comparison actually computes the carry when subtracting + * the modulus from the source value; that carry must be 1 for + * a value in the correct range. We keep it in r, which is our + * accumulator for the error code. + */ + t3 = mq + 4 * fwlen; + br_i31_encode(t3, xlen, t2); + u = xlen; + r = 0; + while (u > 0) { + uint32_t wn, wx; + + u --; + wn = ((unsigned char *)t3)[u]; + wx = x[u]; + r = ((wx - (wn + r)) >> 8) & 1; + } + + /* + * Move the decoded p to another temporary buffer. + */ + mp = mq + 2 * fwlen; + memmove(mp, t1, fwlen * sizeof *t1); + + /* + * Compute s2 = x^dq mod q. + */ + q0i = br_i31_ninv31(mq[1]); + s2 = mq + fwlen; + br_i31_decode_reduce(s2, x, xlen, mq); + r &= br_i31_modpow_opt(s2, sk->dq, sk->dqlen, mq, q0i, + mq + 3 * fwlen, TLEN - 3 * fwlen); + + /* + * Compute s1 = x^dp mod p. + */ + p0i = br_i31_ninv31(mp[1]); + s1 = mq + 3 * fwlen; + br_i31_decode_reduce(s1, x, xlen, mp); + r &= br_i31_modpow_opt(s1, sk->dp, sk->dplen, mp, p0i, + mq + 4 * fwlen, TLEN - 4 * fwlen); + + /* + * Compute: + * h = (s1 - s2)*(1/q) mod p + * s1 is an integer modulo p, but s2 is modulo q. PKCS#1 is + * unclear about whether p may be lower than q (some existing, + * widely deployed implementations of RSA don't tolerate p < q), + * but we want to support that occurrence, so we need to use the + * reduction function. + * + * Since we use br_i31_decode_reduce() for iq (purportedly, the + * inverse of q modulo p), we also tolerate improperly large + * values for this parameter. + */ + t1 = mq + 4 * fwlen; + t2 = mq + 5 * fwlen; + br_i31_reduce(t2, s2, mp); + br_i31_add(s1, mp, br_i31_sub(s1, t2, 1)); + br_i31_to_monty(s1, mp); + br_i31_decode_reduce(t1, sk->iq, sk->iqlen, mp); + br_i31_montymul(t2, s1, t1, mp, p0i); + + /* + * h is now in t2. We compute the final result: + * s = s2 + q*h + * All these operations are non-modular. + * + * We need mq, s2 and t2. We use the t3 buffer as destination. + * The buffers mp, s1 and t1 are no longer needed, so we can + * reuse them for t3. Moreover, the first step of the computation + * is to copy s2 into t3, after which s2 is not needed. Right + * now, mq is in slot 0, s2 is in slot 1, and t2 is in slot 5. + * Therefore, we have ample room for t3 by simply using s2. + */ + t3 = s2; + br_i31_mulacc(t3, mq, t2); + + /* + * Encode the result. Since we already checked the value of xlen, + * we can just use it right away. + */ + br_i31_encode(x, xlen, t3); + + /* + * The only error conditions remaining at that point are invalid + * values for p and q (even integers). + */ + return p0i & q0i & r; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i31_privexp.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i31_privexp.c new file mode 100644 index 000000000..63ec682e7 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i31_privexp.c @@ -0,0 +1,323 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_rsa.h */ +size_t +br_rsa_i31_compute_privexp(void *d, + const br_rsa_private_key *sk, uint32_t e) +{ + /* + * We want to invert e modulo phi = (p-1)(q-1). This first + * requires computing phi, which is easy since we have the factors + * p and q in the private key structure. + * + * Since p = 3 mod 4 and q = 3 mod 4, phi/4 is an odd integer. + * We could invert e modulo phi/4 then patch the result to + * modulo phi, but this would involve assembling three modulus-wide + * values (phi/4, 1 and e) and calling moddiv, that requires + * three more temporaries, for a total of six big integers, or + * slightly more than 3 kB of stack space for RSA-4096. This + * exceeds our stack requirements. + * + * Instead, we first use one step of the extended GCD: + * + * - We compute phi = k*e + r (Euclidean division of phi by e). + * If public exponent e is correct, then r != 0 (e must be + * invertible modulo phi). We also have k != 0 since we + * enforce non-ridiculously-small factors. + * + * - We find small u, v such that u*e - v*r = 1 (using a + * binary GCD; we can arrange for u < r and v < e, i.e. all + * values fit on 32 bits). + * + * - Solution is: d = u + v*k + * This last computation is exact: since u < r and v < e, + * the above implies d < r + e*((phi-r)/e) = phi + */ + + uint32_t tmp[4 * ((BR_MAX_RSA_FACTOR + 30) / 31) + 12]; + uint32_t *p, *q, *k, *m, *z, *phi; + const unsigned char *pbuf, *qbuf; + size_t plen, qlen, u, len, dlen; + uint32_t r, a, b, u0, v0, u1, v1, he, hr; + int i; + + /* + * Check that e is correct. + */ + if (e < 3 || (e & 1) == 0) { + return 0; + } + + /* + * Check lengths of p and q, and that they are both odd. + */ + pbuf = sk->p; + plen = sk->plen; + while (plen > 0 && *pbuf == 0) { + pbuf ++; + plen --; + } + if (plen < 5 || plen > (BR_MAX_RSA_FACTOR / 8) + || (pbuf[plen - 1] & 1) != 1) + { + return 0; + } + qbuf = sk->q; + qlen = sk->qlen; + while (qlen > 0 && *qbuf == 0) { + qbuf ++; + qlen --; + } + if (qlen < 5 || qlen > (BR_MAX_RSA_FACTOR / 8) + || (qbuf[qlen - 1] & 1) != 1) + { + return 0; + } + + /* + * Output length is that of the modulus. + */ + dlen = (sk->n_bitlen + 7) >> 3; + if (d == NULL) { + return dlen; + } + + p = tmp; + br_i31_decode(p, pbuf, plen); + plen = (p[0] + 31) >> 5; + q = p + 1 + plen; + br_i31_decode(q, qbuf, qlen); + qlen = (q[0] + 31) >> 5; + + /* + * Compute phi = (p-1)*(q-1), then move it over p-1 and q-1 (that + * we do not need anymore). The mulacc function sets the announced + * bit length of t to be the sum of the announced bit lengths of + * p-1 and q-1, which is usually exact but may overshoot by one 1 + * bit in some cases; we readjust it to its true length. + */ + p[1] --; + q[1] --; + phi = q + 1 + qlen; + br_i31_zero(phi, p[0]); + br_i31_mulacc(phi, p, q); + len = (phi[0] + 31) >> 5; + memmove(tmp, phi, (1 + len) * sizeof *phi); + phi = tmp; + phi[0] = br_i31_bit_length(phi + 1, len); + len = (phi[0] + 31) >> 5; + + /* + * Divide phi by public exponent e. The final remainder r must be + * non-zero (otherwise, the key is invalid). The quotient is k, + * which we write over phi, since we don't need phi after that. + */ + r = 0; + for (u = len; u >= 1; u --) { + /* + * Upon entry, r < e, and phi[u] < 2^31; hence, + * hi:lo < e*2^31. Thus, the produced word k[u] + * must be lower than 2^31, and the new remainder r + * is lower than e. + */ + uint32_t hi, lo; + + hi = r >> 1; + lo = (r << 31) + phi[u]; + phi[u] = br_divrem(hi, lo, e, &r); + } + if (r == 0) { + return 0; + } + k = phi; + + /* + * Compute u and v such that u*e - v*r = GCD(e,r). We use + * a binary GCD algorithm, with 6 extra integers a, b, + * u0, u1, v0 and v1. Initial values are: + * a = e u0 = 1 v0 = 0 + * b = r u1 = r v1 = e-1 + * The following invariants are maintained: + * a = u0*e - v0*r + * b = u1*e - v1*r + * 0 < a <= e + * 0 < b <= r + * 0 <= u0 <= r + * 0 <= v0 <= e + * 0 <= u1 <= r + * 0 <= v1 <= e + * + * At each iteration, we reduce either a or b by one bit, and + * adjust u0, u1, v0 and v1 to maintain the invariants: + * - if a is even, then a <- a/2 + * - otherwise, if b is even, then b <- b/2 + * - otherwise, if a > b, then a <- (a-b)/2 + * - otherwise, if b > a, then b <- (b-a)/2 + * Algorithm stops when a = b. At that point, the common value + * is the GCD of e and r; it must be 1 (otherwise, the private + * key or public exponent is not valid). The (u0,v0) or (u1,v1) + * pairs are the solution we are looking for. + * + * Since either a or b is reduced by at least 1 bit at each + * iteration, 62 iterations are enough to reach the end + * condition. + * + * To maintain the invariants, we must compute the same operations + * on the u* and v* values that we do on a and b: + * - When a is divided by 2, u0 and v0 must be divided by 2. + * - When b is divided by 2, u1 and v1 must be divided by 2. + * - When b is subtracted from a, u1 and v1 are subtracted from + * u0 and v0, respectively. + * - When a is subtracted from b, u0 and v0 are subtracted from + * u1 and v1, respectively. + * + * However, we want to keep the u* and v* values in their proper + * ranges. The following remarks apply: + * + * - When a is divided by 2, then a is even. Therefore: + * + * * If r is odd, then u0 and v0 must have the same parity; + * if they are both odd, then adding r to u0 and e to v0 + * makes them both even, and the division by 2 brings them + * back to the proper range. + * + * * If r is even, then u0 must be even; if v0 is odd, then + * adding r to u0 and e to v0 makes them both even, and the + * division by 2 brings them back to the proper range. + * + * Thus, all we need to do is to look at the parity of v0, + * and add (r,e) to (u0,v0) when v0 is odd. In order to avoid + * a 32-bit overflow, we can add ((r+1)/2,(e/2)+1) after the + * division (r+1 does not overflow since r < e; and (e/2)+1 + * is equal to (e+1)/2 since e is odd). + * + * - When we subtract b from a, three cases may occur: + * + * * u1 <= u0 and v1 <= v0: just do the subtractions + * + * * u1 > u0 and v1 > v0: compute: + * (u0, v0) <- (u0 + r - u1, v0 + e - v1) + * + * * u1 <= u0 and v1 > v0: compute: + * (u0, v0) <- (u0 + r - u1, v0 + e - v1) + * + * The fourth case (u1 > u0 and v1 <= v0) is not possible + * because it would contradict "b < a" (which is the reason + * why we subtract b from a). + * + * The tricky case is the third one: from the equations, it + * seems that u0 may go out of range. However, the invariants + * and ranges of other values imply that, in that case, the + * new u0 does not actually exceed the range. + * + * We can thus handle the subtraction by adding (r,e) based + * solely on the comparison between v0 and v1. + */ + a = e; + b = r; + u0 = 1; + v0 = 0; + u1 = r; + v1 = e - 1; + hr = (r + 1) >> 1; + he = (e >> 1) + 1; + for (i = 0; i < 62; i ++) { + uint32_t oa, ob, agtb, bgta; + uint32_t sab, sba, da, db; + uint32_t ctl; + + oa = a & 1; /* 1 if a is odd */ + ob = b & 1; /* 1 if b is odd */ + agtb = GT(a, b); /* 1 if a > b */ + bgta = GT(b, a); /* 1 if b > a */ + + sab = oa & ob & agtb; /* 1 if a <- a-b */ + sba = oa & ob & bgta; /* 1 if b <- b-a */ + + /* a <- a-b, u0 <- u0-u1, v0 <- v0-v1 */ + ctl = GT(v1, v0); + a -= b & -sab; + u0 -= (u1 - (r & -ctl)) & -sab; + v0 -= (v1 - (e & -ctl)) & -sab; + + /* b <- b-a, u1 <- u1-u0 mod r, v1 <- v1-v0 mod e */ + ctl = GT(v0, v1); + b -= a & -sba; + u1 -= (u0 - (r & -ctl)) & -sba; + v1 -= (v0 - (e & -ctl)) & -sba; + + da = NOT(oa) | sab; /* 1 if a <- a/2 */ + db = (oa & NOT(ob)) | sba; /* 1 if b <- b/2 */ + + /* a <- a/2, u0 <- u0/2, v0 <- v0/2 */ + ctl = v0 & 1; + a ^= (a ^ (a >> 1)) & -da; + u0 ^= (u0 ^ ((u0 >> 1) + (hr & -ctl))) & -da; + v0 ^= (v0 ^ ((v0 >> 1) + (he & -ctl))) & -da; + + /* b <- b/2, u1 <- u1/2 mod r, v1 <- v1/2 mod e */ + ctl = v1 & 1; + b ^= (b ^ (b >> 1)) & -db; + u1 ^= (u1 ^ ((u1 >> 1) + (hr & -ctl))) & -db; + v1 ^= (v1 ^ ((v1 >> 1) + (he & -ctl))) & -db; + } + + /* + * Check that the GCD is indeed 1. If not, then the key is invalid + * (and there's no harm in leaking that piece of information). + */ + if (a != 1) { + return 0; + } + + /* + * Now we have u0*e - v0*r = 1. Let's compute the result as: + * d = u0 + v0*k + * We still have k in the tmp[] array, and its announced bit + * length is that of phi. + */ + m = k + 1 + len; + m[0] = (1 << 5) + 1; /* bit length is 32 bits, encoded */ + m[1] = v0 & 0x7FFFFFFF; + m[2] = v0 >> 31; + z = m + 3; + br_i31_zero(z, k[0]); + z[1] = u0 & 0x7FFFFFFF; + z[2] = u0 >> 31; + br_i31_mulacc(z, k, m); + + /* + * Encode the result. + */ + br_i31_encode(d, dlen, z); + return dlen; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i31_pss_sign.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i31_pss_sign.c new file mode 100644 index 000000000..16752291f --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i31_pss_sign.c @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_rsa.h */ +uint32_t +br_rsa_i31_pss_sign(const br_prng_class **rng, + const br_hash_class *hf_data, const br_hash_class *hf_mgf1, + const unsigned char *hash, size_t salt_len, + const br_rsa_private_key *sk, unsigned char *x) +{ + if (!br_rsa_pss_sig_pad(rng, hf_data, hf_mgf1, hash, + salt_len, sk->n_bitlen, x)) + { + return 0; + } + return br_rsa_i31_private(x, sk); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i31_pss_vrfy.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i31_pss_vrfy.c new file mode 100644 index 000000000..f3beafee0 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i31_pss_vrfy.c @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_rsa.h */ +uint32_t +br_rsa_i31_pss_vrfy(const unsigned char *x, size_t xlen, + const br_hash_class *hf_data, const br_hash_class *hf_mgf1, + const void *hash, size_t salt_len, const br_rsa_public_key *pk) +{ + unsigned char sig[BR_MAX_RSA_SIZE >> 3]; + + if (xlen > (sizeof sig)) { + return 0; + } + memcpy(sig, x, xlen); + if (!br_rsa_i31_public(sig, xlen, pk)) { + return 0; + } + return br_rsa_pss_sig_unpad(hf_data, hf_mgf1, + hash, salt_len, pk, sig); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i31_pub.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i31_pub.c new file mode 100644 index 000000000..54ead7c6e --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i31_pub.c @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* + * As a strict minimum, we need four buffers that can hold a + * modular integer. + */ +#define TLEN (4 * (2 + ((BR_MAX_RSA_SIZE + 30) / 31))) + +/* see bearssl_rsa.h */ +uint32_t +br_rsa_i31_public(unsigned char *x, size_t xlen, + const br_rsa_public_key *pk) +{ + const unsigned char *n; + size_t nlen; + uint32_t tmp[1 + TLEN]; + uint32_t *m, *a, *t; + size_t fwlen; + long z; + uint32_t m0i, r; + + /* + * Get the actual length of the modulus, and see if it fits within + * our stack buffer. We also check that the length of x[] is valid. + */ + n = pk->n; + nlen = pk->nlen; + while (nlen > 0 && *n == 0) { + n ++; + nlen --; + } + if (nlen == 0 || nlen > (BR_MAX_RSA_SIZE >> 3) || xlen != nlen) { + return 0; + } + z = (long)nlen << 3; + fwlen = 1; + while (z > 0) { + z -= 31; + fwlen ++; + } + /* + * Round up length to an even number. + */ + fwlen += (fwlen & 1); + + /* + * The modulus gets decoded into m[]. + * The value to exponentiate goes into a[]. + * The temporaries for modular exponentiation are in t[]. + */ + m = tmp; + a = m + fwlen; + t = m + 2 * fwlen; + + /* + * Decode the modulus. + */ + br_i31_decode(m, n, nlen); + m0i = br_i31_ninv31(m[1]); + + /* + * Note: if m[] is even, then m0i == 0. Otherwise, m0i must be + * an odd integer. + */ + r = m0i & 1; + + /* + * Decode x[] into a[]; we also check that its value is proper. + */ + r &= br_i31_decode_mod(a, x, xlen, m); + + /* + * Compute the modular exponentiation. + */ + br_i31_modpow_opt(a, pk->e, pk->elen, m, m0i, t, TLEN - 2 * fwlen); + + /* + * Encode the result. + */ + br_i31_encode(x, xlen, a); + return r; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i31_pubexp.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i31_pubexp.c new file mode 100644 index 000000000..662faf378 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i31_pubexp.c @@ -0,0 +1,157 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* + * Recompute public exponent, based on factor p and reduced private + * exponent dp. + */ +static uint32_t +get_pubexp(const unsigned char *pbuf, size_t plen, + const unsigned char *dpbuf, size_t dplen) +{ + /* + * dp is the inverse of e modulo p-1. If p = 3 mod 4, then + * p-1 = 2*((p-1)/2). Taken modulo 2, e is odd and has inverse 1; + * thus, dp must be odd. + * + * We compute the inverse of dp modulo (p-1)/2. This requires + * first reducing dp modulo (p-1)/2 (this can be done with a + * conditional subtract, no need to use the generic modular + * reduction function); then, we use moddiv. + */ + + uint32_t tmp[6 * ((BR_MAX_RSA_FACTOR + 61) / 31)]; + uint32_t *p, *dp, *x; + size_t len; + uint32_t e; + + /* + * Compute actual factor length (in bytes) and check that it fits + * under our size constraints. + */ + while (plen > 0 && *pbuf == 0) { + pbuf ++; + plen --; + } + if (plen == 0 || plen < 5 || plen > (BR_MAX_RSA_FACTOR / 8)) { + return 0; + } + + /* + * Compute actual reduced exponent length (in bytes) and check that + * it is not longer than p. + */ + while (dplen > 0 && *dpbuf == 0) { + dpbuf ++; + dplen --; + } + if (dplen > plen || dplen == 0 + || (dplen == plen && dpbuf[0] > pbuf[0])) + { + return 0; + } + + /* + * Verify that p = 3 mod 4 and that dp is odd. + */ + if ((pbuf[plen - 1] & 3) != 3 || (dpbuf[dplen - 1] & 1) != 1) { + return 0; + } + + /* + * Decode p and compute (p-1)/2. + */ + p = tmp; + br_i31_decode(p, pbuf, plen); + len = (p[0] + 63) >> 5; + br_i31_rshift(p, 1); + + /* + * Decode dp and make sure its announced bit length matches that of + * p (we already know that the size of dp, in bits, does not exceed + * the size of p, so we just have to copy the header word). + */ + dp = p + len; + memset(dp, 0, len * sizeof *dp); + br_i31_decode(dp, dpbuf, dplen); + dp[0] = p[0]; + + /* + * Subtract (p-1)/2 from dp if necessary. + */ + br_i31_sub(dp, p, NOT(br_i31_sub(dp, p, 0))); + + /* + * If another subtraction is needed, then this means that the + * value was invalid. We don't care to leak information about + * invalid keys. + */ + if (br_i31_sub(dp, p, 0) == 0) { + return 0; + } + + /* + * Invert dp modulo (p-1)/2. If the inversion fails, then the + * key value was invalid. + */ + x = dp + len; + br_i31_zero(x, p[0]); + x[1] = 1; + if (br_i31_moddiv(x, dp, p, br_i31_ninv31(p[1]), x + len) == 0) { + return 0; + } + + /* + * We now have an inverse. We must set it to zero (error) if its + * length is greater than 32 bits and/or if it is an even integer. + * Take care that the bit_length function returns an encoded + * bit length. + */ + e = (uint32_t)x[1] | ((uint32_t)x[2] << 31); + e &= -LT(br_i31_bit_length(x + 1, len - 1), 34); + e &= -(e & 1); + return e; +} + +/* see bearssl_rsa.h */ +uint32_t +br_rsa_i31_compute_pubexp(const br_rsa_private_key *sk) +{ + /* + * Get the public exponent from both p and q. This is the right + * exponent if we get twice the same value. + */ + uint32_t ep, eq; + + ep = get_pubexp(sk->p, sk->plen, sk->dp, sk->dplen); + eq = get_pubexp(sk->q, sk->qlen, sk->dq, sk->dqlen); + return ep & -EQ(ep, eq); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i32_oaep_decrypt.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i32_oaep_decrypt.c new file mode 100644 index 000000000..2005fcdd8 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i32_oaep_decrypt.c @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_rsa.h */ +uint32_t +br_rsa_i32_oaep_decrypt(const br_hash_class *dig, + const void *label, size_t label_len, + const br_rsa_private_key *sk, void *data, size_t *len) +{ + uint32_t r; + + if (*len != ((sk->n_bitlen + 7) >> 3)) { + return 0; + } + r = br_rsa_i32_private(data, sk); + r &= br_rsa_oaep_unpad(dig, label, label_len, data, len); + return r; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i32_oaep_encrypt.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i32_oaep_encrypt.c new file mode 100644 index 000000000..0080ce2f1 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i32_oaep_encrypt.c @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_rsa.h */ +size_t +br_rsa_i32_oaep_encrypt( + const br_prng_class **rnd, const br_hash_class *dig, + const void *label, size_t label_len, + const br_rsa_public_key *pk, + void *dst, size_t dst_max_len, + const void *src, size_t src_len) +{ + size_t dlen; + + dlen = br_rsa_oaep_pad(rnd, dig, label, label_len, + pk, dst, dst_max_len, src, src_len); + if (dlen == 0) { + return 0; + } + return dlen & -(size_t)br_rsa_i32_public(dst, dlen, pk); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i32_pkcs1_sign.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i32_pkcs1_sign.c new file mode 100644 index 000000000..b0c83983a --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i32_pkcs1_sign.c @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_rsa.h */ +uint32_t +br_rsa_i32_pkcs1_sign(const unsigned char *hash_oid, + const unsigned char *hash, size_t hash_len, + const br_rsa_private_key *sk, unsigned char *x) +{ + if (!br_rsa_pkcs1_sig_pad(hash_oid, hash, hash_len, sk->n_bitlen, x)) { + return 0; + } + return br_rsa_i32_private(x, sk); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i32_pkcs1_vrfy.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i32_pkcs1_vrfy.c new file mode 100644 index 000000000..b18afff0a --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i32_pkcs1_vrfy.c @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_rsa.h */ +uint32_t +br_rsa_i32_pkcs1_vrfy(const unsigned char *x, size_t xlen, + const unsigned char *hash_oid, size_t hash_len, + const br_rsa_public_key *pk, unsigned char *hash_out) +{ + unsigned char sig[BR_MAX_RSA_SIZE >> 3]; + + if (xlen > (sizeof sig)) { + return 0; + } + memcpy(sig, x, xlen); + if (!br_rsa_i32_public(sig, xlen, pk)) { + return 0; + } + return br_rsa_pkcs1_sig_unpad(sig, xlen, hash_oid, hash_len, hash_out); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i32_priv.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i32_priv.c new file mode 100644 index 000000000..a3ab88af2 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i32_priv.c @@ -0,0 +1,165 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +#define U (1 + (BR_MAX_RSA_FACTOR >> 5)) + +/* see bearssl_rsa.h */ +uint32_t +br_rsa_i32_private(unsigned char *x, const br_rsa_private_key *sk) +{ + const unsigned char *p, *q; + size_t plen, qlen; + uint32_t tmp[6 * U]; + uint32_t *mp, *mq, *s1, *s2, *t1, *t2, *t3; + uint32_t p0i, q0i; + size_t xlen, u; + uint32_t r; + + /* + * All our temporary buffers are from the tmp[] array. + * + * The mp, mq, s1, s2, t1 and t2 buffers are large enough to + * contain a RSA factor. The t3 buffer can contain a complete + * RSA modulus. t3 shares its storage space with s2, s1 and t1, + * in that order (this is important, see below). + */ + mq = tmp; + mp = tmp + U; + t2 = tmp + 2 * U; + s2 = tmp + 3 * U; + s1 = tmp + 4 * U; + t1 = tmp + 5 * U; + t3 = s2; + + /* + * Compute the actual lengths (in bytes) of p and q, and check + * that they fit within our stack buffers. + */ + p = sk->p; + plen = sk->plen; + while (plen > 0 && *p == 0) { + p ++; + plen --; + } + q = sk->q; + qlen = sk->qlen; + while (qlen > 0 && *q == 0) { + q ++; + qlen --; + } + if (plen > (BR_MAX_RSA_FACTOR >> 3) + || qlen > (BR_MAX_RSA_FACTOR >> 3)) + { + return 0; + } + + /* + * Decode p and q. + */ + br_i32_decode(mp, p, plen); + br_i32_decode(mq, q, qlen); + + /* + * Recompute modulus, to compare with the source value. + */ + br_i32_zero(t2, mp[0]); + br_i32_mulacc(t2, mp, mq); + xlen = (sk->n_bitlen + 7) >> 3; + br_i32_encode(t2 + 2 * U, xlen, t2); + u = xlen; + r = 0; + while (u > 0) { + uint32_t wn, wx; + + u --; + wn = ((unsigned char *)(t2 + 2 * U))[u]; + wx = x[u]; + r = ((wx - (wn + r)) >> 8) & 1; + } + + /* + * Compute s1 = x^dp mod p. + */ + p0i = br_i32_ninv32(mp[1]); + br_i32_decode_reduce(s1, x, xlen, mp); + br_i32_modpow(s1, sk->dp, sk->dplen, mp, p0i, t1, t2); + + /* + * Compute s2 = x^dq mod q. + */ + q0i = br_i32_ninv32(mq[1]); + br_i32_decode_reduce(s2, x, xlen, mq); + br_i32_modpow(s2, sk->dq, sk->dqlen, mq, q0i, t1, t2); + + /* + * Compute: + * h = (s1 - s2)*(1/q) mod p + * s1 is an integer modulo p, but s2 is modulo q. PKCS#1 is + * unclear about whether p may be lower than q (some existing, + * widely deployed implementations of RSA don't tolerate p < q), + * but we want to support that occurrence, so we need to use the + * reduction function. + * + * Since we use br_i32_decode_reduce() for iq (purportedly, the + * inverse of q modulo p), we also tolerate improperly large + * values for this parameter. + */ + br_i32_reduce(t2, s2, mp); + br_i32_add(s1, mp, br_i32_sub(s1, t2, 1)); + br_i32_to_monty(s1, mp); + br_i32_decode_reduce(t1, sk->iq, sk->iqlen, mp); + br_i32_montymul(t2, s1, t1, mp, p0i); + + /* + * h is now in t2. We compute the final result: + * s = s2 + q*h + * All these operations are non-modular. + * + * We need mq, s2 and t2. We use the t3 buffer as destination. + * The buffers mp, s1 and t1 are no longer needed. Moreover, + * the first step is to copy s2 into the destination buffer t3. + * We thus arranged for t3 to actually share space with s2, and + * to be followed by the space formerly used by s1 and t1. + */ + br_i32_mulacc(t3, mq, t2); + + /* + * Encode the result. Since we already checked the value of xlen, + * we can just use it right away. + */ + br_i32_encode(x, xlen, t3); + + /* + * The only error conditions remaining at that point are invalid + * values for p and q (even integers). + */ + return p0i & q0i & r; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i32_pss_sign.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i32_pss_sign.c new file mode 100644 index 000000000..37a389740 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i32_pss_sign.c @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_rsa.h */ +uint32_t +br_rsa_i32_pss_sign(const br_prng_class **rng, + const br_hash_class *hf_data, const br_hash_class *hf_mgf1, + const unsigned char *hash, size_t salt_len, + const br_rsa_private_key *sk, unsigned char *x) +{ + if (!br_rsa_pss_sig_pad(rng, hf_data, hf_mgf1, hash, + salt_len, sk->n_bitlen, x)) + { + return 0; + } + return br_rsa_i32_private(x, sk); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i32_pss_vrfy.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i32_pss_vrfy.c new file mode 100644 index 000000000..14c6f3529 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i32_pss_vrfy.c @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_rsa.h */ +uint32_t +br_rsa_i32_pss_vrfy(const unsigned char *x, size_t xlen, + const br_hash_class *hf_data, const br_hash_class *hf_mgf1, + const void *hash, size_t salt_len, const br_rsa_public_key *pk) +{ + unsigned char sig[BR_MAX_RSA_SIZE >> 3]; + + if (xlen > (sizeof sig)) { + return 0; + } + memcpy(sig, x, xlen); + if (!br_rsa_i32_public(sig, xlen, pk)) { + return 0; + } + return br_rsa_pss_sig_unpad(hf_data, hf_mgf1, + hash, salt_len, pk, sig); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i32_pub.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i32_pub.c new file mode 100644 index 000000000..c4adccda3 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i32_pub.c @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_rsa.h */ +uint32_t +br_rsa_i32_public(unsigned char *x, size_t xlen, + const br_rsa_public_key *pk) +{ + const unsigned char *n; + size_t nlen; + uint32_t m[1 + (BR_MAX_RSA_SIZE >> 5)]; + uint32_t a[1 + (BR_MAX_RSA_SIZE >> 5)]; + uint32_t t1[1 + (BR_MAX_RSA_SIZE >> 5)]; + uint32_t t2[1 + (BR_MAX_RSA_SIZE >> 5)]; + uint32_t m0i, r; + + /* + * Get the actual length of the modulus, and see if it fits within + * our stack buffer. We also check that the length of x[] is valid. + */ + n = pk->n; + nlen = pk->nlen; + while (nlen > 0 && *n == 0) { + n ++; + nlen --; + } + if (nlen == 0 || nlen > (BR_MAX_RSA_SIZE >> 3) || xlen != nlen) { + return 0; + } + br_i32_decode(m, n, nlen); + m0i = br_i32_ninv32(m[1]); + + /* + * Note: if m[] is even, then m0i == 0. Otherwise, m0i must be + * an odd integer. + */ + r = m0i & 1; + + /* + * Decode x[] into a[]; we also check that its value is proper. + */ + r &= br_i32_decode_mod(a, x, xlen, m); + + /* + * Compute the modular exponentiation. + */ + br_i32_modpow(a, pk->e, pk->elen, m, m0i, t1, t2); + + /* + * Encode the result. + */ + br_i32_encode(x, xlen, a); + return r; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i62_keygen.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i62_keygen.c new file mode 100644 index 000000000..38ccd88e1 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i62_keygen.c @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +#if BR_INT128 || BR_UMUL128 + +/* see bearssl_rsa.h */ +uint32_t +br_rsa_i62_keygen(const br_prng_class **rng, + br_rsa_private_key *sk, void *kbuf_priv, + br_rsa_public_key *pk, void *kbuf_pub, + unsigned size, uint32_t pubexp) +{ + return br_rsa_i31_keygen_inner(rng, + sk, kbuf_priv, pk, kbuf_pub, size, pubexp, + &br_i62_modpow_opt_as_i31); +} + +/* see bearssl_rsa.h */ +br_rsa_keygen +br_rsa_i62_keygen_get() +{ + return &br_rsa_i62_keygen; +} + +#else + +/* see bearssl_rsa.h */ +br_rsa_keygen +br_rsa_i62_keygen_get() +{ + return 0; +} + +#endif + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i62_oaep_decrypt.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i62_oaep_decrypt.c new file mode 100644 index 000000000..b8bfd6c1c --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i62_oaep_decrypt.c @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +#if BR_INT128 || BR_UMUL128 + +/* see bearssl_rsa.h */ +uint32_t +br_rsa_i62_oaep_decrypt(const br_hash_class *dig, + const void *label, size_t label_len, + const br_rsa_private_key *sk, void *data, size_t *len) +{ + uint32_t r; + + if (*len != ((sk->n_bitlen + 7) >> 3)) { + return 0; + } + r = br_rsa_i62_private(data, sk); + r &= br_rsa_oaep_unpad(dig, label, label_len, data, len); + return r; +} + +/* see bearssl_rsa.h */ +br_rsa_oaep_decrypt +br_rsa_i62_oaep_decrypt_get(void) +{ + return &br_rsa_i62_oaep_decrypt; +} + +#else + +/* see bearssl_rsa.h */ +br_rsa_oaep_decrypt +br_rsa_i62_oaep_decrypt_get(void) +{ + return 0; +} + +#endif + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i62_oaep_encrypt.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i62_oaep_encrypt.c new file mode 100644 index 000000000..9a3d286ed --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i62_oaep_encrypt.c @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +#if BR_INT128 || BR_UMUL128 + +/* see bearssl_rsa.h */ +size_t +br_rsa_i62_oaep_encrypt( + const br_prng_class **rnd, const br_hash_class *dig, + const void *label, size_t label_len, + const br_rsa_public_key *pk, + void *dst, size_t dst_max_len, + const void *src, size_t src_len) +{ + size_t dlen; + + dlen = br_rsa_oaep_pad(rnd, dig, label, label_len, + pk, dst, dst_max_len, src, src_len); + if (dlen == 0) { + return 0; + } + return dlen & -(size_t)br_rsa_i62_public(dst, dlen, pk); +} + +/* see bearssl_rsa.h */ +br_rsa_oaep_encrypt +br_rsa_i62_oaep_encrypt_get(void) +{ + return &br_rsa_i62_oaep_encrypt; +} + +#else + +/* see bearssl_rsa.h */ +br_rsa_oaep_encrypt +br_rsa_i62_oaep_encrypt_get(void) +{ + return 0; +} + +#endif + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i62_pkcs1_sign.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i62_pkcs1_sign.c new file mode 100644 index 000000000..a0d130525 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i62_pkcs1_sign.c @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +#if BR_INT128 || BR_UMUL128 + +/* see bearssl_rsa.h */ +uint32_t +br_rsa_i62_pkcs1_sign(const unsigned char *hash_oid, + const unsigned char *hash, size_t hash_len, + const br_rsa_private_key *sk, unsigned char *x) +{ + if (!br_rsa_pkcs1_sig_pad(hash_oid, hash, hash_len, sk->n_bitlen, x)) { + return 0; + } + return br_rsa_i62_private(x, sk); +} + +/* see bearssl_rsa.h */ +br_rsa_pkcs1_sign +br_rsa_i62_pkcs1_sign_get(void) +{ + return &br_rsa_i62_pkcs1_sign; +} + +#else + +/* see bearssl_rsa.h */ +br_rsa_pkcs1_sign +br_rsa_i62_pkcs1_sign_get(void) +{ + return 0; +} + +#endif + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i62_pkcs1_vrfy.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i62_pkcs1_vrfy.c new file mode 100644 index 000000000..730fa5e5a --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i62_pkcs1_vrfy.c @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +#if BR_INT128 || BR_UMUL128 + +/* see bearssl_rsa.h */ +uint32_t +br_rsa_i62_pkcs1_vrfy(const unsigned char *x, size_t xlen, + const unsigned char *hash_oid, size_t hash_len, + const br_rsa_public_key *pk, unsigned char *hash_out) +{ + unsigned char sig[BR_MAX_RSA_SIZE >> 3]; + + if (xlen > (sizeof sig)) { + return 0; + } + memcpy(sig, x, xlen); + if (!br_rsa_i62_public(sig, xlen, pk)) { + return 0; + } + return br_rsa_pkcs1_sig_unpad(sig, xlen, hash_oid, hash_len, hash_out); +} + +/* see bearssl_rsa.h */ +br_rsa_pkcs1_vrfy +br_rsa_i62_pkcs1_vrfy_get(void) +{ + return &br_rsa_i62_pkcs1_vrfy; +} + +#else + +/* see bearssl_rsa.h */ +br_rsa_pkcs1_vrfy +br_rsa_i62_pkcs1_vrfy_get(void) +{ + return 0; +} + +#endif + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i62_priv.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i62_priv.c new file mode 100644 index 000000000..4ce4e527f --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i62_priv.c @@ -0,0 +1,228 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +#if BR_INT128 || BR_UMUL128 + +#define U (2 + ((BR_MAX_RSA_FACTOR + 30) / 31)) +#define TLEN (4 * U) /* TLEN is counted in 64-bit words */ + +/* see bearssl_rsa.h */ +uint32_t +br_rsa_i62_private(unsigned char *x, const br_rsa_private_key *sk) +{ + const unsigned char *p, *q; + size_t plen, qlen; + size_t fwlen; + uint32_t p0i, q0i; + size_t xlen, u; + uint64_t tmp[TLEN]; + long z; + uint32_t *mp, *mq, *s1, *s2, *t1, *t2, *t3; + uint32_t r; + + /* + * Compute the actual lengths of p and q, in bytes. + * These lengths are not considered secret (we cannot really hide + * them anyway in constant-time code). + */ + p = sk->p; + plen = sk->plen; + while (plen > 0 && *p == 0) { + p ++; + plen --; + } + q = sk->q; + qlen = sk->qlen; + while (qlen > 0 && *q == 0) { + q ++; + qlen --; + } + + /* + * Compute the maximum factor length, in words. + */ + z = (long)(plen > qlen ? plen : qlen) << 3; + fwlen = 1; + while (z > 0) { + z -= 31; + fwlen ++; + } + + /* + * Convert size to 62-bit words. + */ + fwlen = (fwlen + 1) >> 1; + + /* + * We need to fit at least 6 values in the stack buffer. + */ + if (6 * fwlen > TLEN) { + return 0; + } + + /* + * Compute signature length (in bytes). + */ + xlen = (sk->n_bitlen + 7) >> 3; + + /* + * Decode q. + */ + mq = (uint32_t *)tmp; + br_i31_decode(mq, q, qlen); + + /* + * Decode p. + */ + t1 = (uint32_t *)(tmp + fwlen); + br_i31_decode(t1, p, plen); + + /* + * Compute the modulus (product of the two factors), to compare + * it with the source value. We use br_i31_mulacc(), since it's + * already used later on. + */ + t2 = (uint32_t *)(tmp + 2 * fwlen); + br_i31_zero(t2, mq[0]); + br_i31_mulacc(t2, mq, t1); + + /* + * We encode the modulus into bytes, to perform the comparison + * with bytes. We know that the product length, in bytes, is + * exactly xlen. + * The comparison actually computes the carry when subtracting + * the modulus from the source value; that carry must be 1 for + * a value in the correct range. We keep it in r, which is our + * accumulator for the error code. + */ + t3 = (uint32_t *)(tmp + 4 * fwlen); + br_i31_encode(t3, xlen, t2); + u = xlen; + r = 0; + while (u > 0) { + uint32_t wn, wx; + + u --; + wn = ((unsigned char *)t3)[u]; + wx = x[u]; + r = ((wx - (wn + r)) >> 8) & 1; + } + + /* + * Move the decoded p to another temporary buffer. + */ + mp = (uint32_t *)(tmp + 2 * fwlen); + memmove(mp, t1, 2 * fwlen * sizeof *t1); + + /* + * Compute s2 = x^dq mod q. + */ + q0i = br_i31_ninv31(mq[1]); + s2 = (uint32_t *)(tmp + fwlen); + br_i31_decode_reduce(s2, x, xlen, mq); + r &= br_i62_modpow_opt(s2, sk->dq, sk->dqlen, mq, q0i, + tmp + 3 * fwlen, TLEN - 3 * fwlen); + + /* + * Compute s1 = x^dp mod p. + */ + p0i = br_i31_ninv31(mp[1]); + s1 = (uint32_t *)(tmp + 3 * fwlen); + br_i31_decode_reduce(s1, x, xlen, mp); + r &= br_i62_modpow_opt(s1, sk->dp, sk->dplen, mp, p0i, + tmp + 4 * fwlen, TLEN - 4 * fwlen); + + /* + * Compute: + * h = (s1 - s2)*(1/q) mod p + * s1 is an integer modulo p, but s2 is modulo q. PKCS#1 is + * unclear about whether p may be lower than q (some existing, + * widely deployed implementations of RSA don't tolerate p < q), + * but we want to support that occurrence, so we need to use the + * reduction function. + * + * Since we use br_i31_decode_reduce() for iq (purportedly, the + * inverse of q modulo p), we also tolerate improperly large + * values for this parameter. + */ + t1 = (uint32_t *)(tmp + 4 * fwlen); + t2 = (uint32_t *)(tmp + 5 * fwlen); + br_i31_reduce(t2, s2, mp); + br_i31_add(s1, mp, br_i31_sub(s1, t2, 1)); + br_i31_to_monty(s1, mp); + br_i31_decode_reduce(t1, sk->iq, sk->iqlen, mp); + br_i31_montymul(t2, s1, t1, mp, p0i); + + /* + * h is now in t2. We compute the final result: + * s = s2 + q*h + * All these operations are non-modular. + * + * We need mq, s2 and t2. We use the t3 buffer as destination. + * The buffers mp, s1 and t1 are no longer needed, so we can + * reuse them for t3. Moreover, the first step of the computation + * is to copy s2 into t3, after which s2 is not needed. Right + * now, mq is in slot 0, s2 is in slot 1, and t2 is in slot 5. + * Therefore, we have ample room for t3 by simply using s2. + */ + t3 = s2; + br_i31_mulacc(t3, mq, t2); + + /* + * Encode the result. Since we already checked the value of xlen, + * we can just use it right away. + */ + br_i31_encode(x, xlen, t3); + + /* + * The only error conditions remaining at that point are invalid + * values for p and q (even integers). + */ + return p0i & q0i & r; +} + +/* see bearssl_rsa.h */ +br_rsa_private +br_rsa_i62_private_get(void) +{ + return &br_rsa_i62_private; +} + +#else + +/* see bearssl_rsa.h */ +br_rsa_private +br_rsa_i62_private_get(void) +{ + return 0; +} + +#endif + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i62_pss_sign.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i62_pss_sign.c new file mode 100644 index 000000000..38aed9828 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i62_pss_sign.c @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +#if BR_INT128 || BR_UMUL128 + +/* see bearssl_rsa.h */ +uint32_t +br_rsa_i62_pss_sign(const br_prng_class **rng, + const br_hash_class *hf_data, const br_hash_class *hf_mgf1, + const unsigned char *hash, size_t salt_len, + const br_rsa_private_key *sk, unsigned char *x) +{ + if (!br_rsa_pss_sig_pad(rng, hf_data, hf_mgf1, hash, + salt_len, sk->n_bitlen, x)) + { + return 0; + } + return br_rsa_i62_private(x, sk); +} + +/* see bearssl_rsa.h */ +br_rsa_pss_sign +br_rsa_i62_pss_sign_get(void) +{ + return &br_rsa_i62_pss_sign; +} + +#else + +/* see bearssl_rsa.h */ +br_rsa_pss_sign +br_rsa_i62_pss_sign_get(void) +{ + return 0; +} + +#endif + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i62_pss_vrfy.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i62_pss_vrfy.c new file mode 100644 index 000000000..7b6ce339b --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i62_pss_vrfy.c @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +#if BR_INT128 || BR_UMUL128 + +/* see bearssl_rsa.h */ +uint32_t +br_rsa_i62_pss_vrfy(const unsigned char *x, size_t xlen, + const br_hash_class *hf_data, const br_hash_class *hf_mgf1, + const void *hash, size_t salt_len, const br_rsa_public_key *pk) +{ + unsigned char sig[BR_MAX_RSA_SIZE >> 3]; + + if (xlen > (sizeof sig)) { + return 0; + } + memcpy(sig, x, xlen); + if (!br_rsa_i62_public(sig, xlen, pk)) { + return 0; + } + return br_rsa_pss_sig_unpad(hf_data, hf_mgf1, + hash, salt_len, pk, sig); +} + +/* see bearssl_rsa.h */ +br_rsa_pss_vrfy +br_rsa_i62_pss_vrfy_get(void) +{ + return &br_rsa_i62_pss_vrfy; +} + +#else + +/* see bearssl_rsa.h */ +br_rsa_pss_vrfy +br_rsa_i62_pss_vrfy_get(void) +{ + return 0; +} + +#endif + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i62_pub.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i62_pub.c new file mode 100644 index 000000000..e71b9f491 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_i62_pub.c @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +#if BR_INT128 || BR_UMUL128 + +/* + * As a strict minimum, we need four buffers that can hold a + * modular integer. But TLEN is expressed in 64-bit words. + */ +#define TLEN (2 * (2 + ((BR_MAX_RSA_SIZE + 30) / 31))) + +/* see bearssl_rsa.h */ +uint32_t +br_rsa_i62_public(unsigned char *x, size_t xlen, + const br_rsa_public_key *pk) +{ + const unsigned char *n; + size_t nlen; + uint64_t tmp[TLEN]; + uint32_t *m, *a; + size_t fwlen; + long z; + uint32_t m0i, r; + + /* + * Get the actual length of the modulus, and see if it fits within + * our stack buffer. We also check that the length of x[] is valid. + */ + n = pk->n; + nlen = pk->nlen; + while (nlen > 0 && *n == 0) { + n ++; + nlen --; + } + if (nlen == 0 || nlen > (BR_MAX_RSA_SIZE >> 3) || xlen != nlen) { + return 0; + } + z = (long)nlen << 3; + fwlen = 1; + while (z > 0) { + z -= 31; + fwlen ++; + } + /* + * Convert fwlen to a count in 62-bit words. + */ + fwlen = (fwlen + 1) >> 1; + + /* + * The modulus gets decoded into m[]. + * The value to exponentiate goes into a[]. + */ + m = (uint32_t *)tmp; + a = (uint32_t *)(tmp + fwlen); + + /* + * Decode the modulus. + */ + br_i31_decode(m, n, nlen); + m0i = br_i31_ninv31(m[1]); + + /* + * Note: if m[] is even, then m0i == 0. Otherwise, m0i must be + * an odd integer. + */ + r = m0i & 1; + + /* + * Decode x[] into a[]; we also check that its value is proper. + */ + r &= br_i31_decode_mod(a, x, xlen, m); + + /* + * Compute the modular exponentiation. + */ + br_i62_modpow_opt(a, pk->e, pk->elen, m, m0i, + tmp + 2 * fwlen, TLEN - 2 * fwlen); + + /* + * Encode the result. + */ + br_i31_encode(x, xlen, a); + return r; +} + +/* see bearssl_rsa.h */ +br_rsa_public +br_rsa_i62_public_get(void) +{ + return &br_rsa_i62_public; +} + +#else + +/* see bearssl_rsa.h */ +br_rsa_public +br_rsa_i62_public_get(void) +{ + return 0; +} + +#endif + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_oaep_pad.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_oaep_pad.c new file mode 100644 index 000000000..55db3540b --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_oaep_pad.c @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* + * Hash some data. This is put as a separate function so that stack + * allocation of the hash function context is done only for the duration + * of the hash. + */ +static void +hash_data(const br_hash_class *dig, void *dst, const void *src, size_t len) +{ + br_hash_compat_context hc; + + hc.vtable = dig; + dig->init(&hc.vtable); + dig->update(&hc.vtable, src, len); + dig->out(&hc.vtable, dst); +} + +/* see inner.h */ +size_t +br_rsa_oaep_pad(const br_prng_class **rnd, const br_hash_class *dig, + const void *label, size_t label_len, + const br_rsa_public_key *pk, + void *dst, size_t dst_max_len, + const void *src, size_t src_len) +{ + size_t k, hlen; + unsigned char *buf; + + hlen = br_digest_size(dig); + + /* + * Compute actual modulus length (in bytes). + */ + k = pk->nlen; + while (k > 0 && pk->n[k - 1] == 0) { + k --; + } + + /* + * An error is reported if: + * - the modulus is too short; + * - the source message length is too long; + * - the destination buffer is too short. + */ + if (k < ((hlen << 1) + 2) + || src_len > (k - (hlen << 1) - 2) + || dst_max_len < k) + { + return 0; + } + + /* + * Apply padding. At this point, things cannot fail. + */ + buf = dst; + + /* + * Assemble: DB = lHash || PS || 0x01 || M + * We first place the source message M with memmove(), so that + * overlaps between source and destination buffers are supported. + */ + memmove(buf + k - src_len, src, src_len); + hash_data(dig, buf + 1 + hlen, label, label_len); + memset(buf + 1 + (hlen << 1), 0, k - src_len - (hlen << 1) - 2); + buf[k - src_len - 1] = 0x01; + + /* + * Make the random seed. + */ + (*rnd)->generate(rnd, buf + 1, hlen); + + /* + * Mask DB with the mask generated from the seed. + */ + br_mgf1_xor(buf + 1 + hlen, k - hlen - 1, dig, buf + 1, hlen); + + /* + * Mask the seed with the mask generated from the masked DB. + */ + br_mgf1_xor(buf + 1, hlen, dig, buf + 1 + hlen, k - hlen - 1); + + /* + * Padding result: EM = 0x00 || maskedSeed || maskedDB. + */ + buf[0] = 0x00; + return k; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_oaep_unpad.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_oaep_unpad.c new file mode 100644 index 000000000..870da8d50 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_oaep_unpad.c @@ -0,0 +1,150 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* + * Hash some data and XOR the result into the provided buffer. This is put + * as a separate function so that stack allocation of the hash function + * context is done only for the duration of the hash. + */ +static void +xor_hash_data(const br_hash_class *dig, void *dst, const void *src, size_t len) +{ + br_hash_compat_context hc; + unsigned char tmp[64]; + unsigned char *buf; + size_t u, hlen; + + hc.vtable = dig; + dig->init(&hc.vtable); + dig->update(&hc.vtable, src, len); + dig->out(&hc.vtable, tmp); + buf = dst; + hlen = br_digest_size(dig); + for (u = 0; u < hlen; u ++) { + buf[u] ^= tmp[u]; + } +} + +/* see inner.h */ +uint32_t +br_rsa_oaep_unpad(const br_hash_class *dig, + const void *label, size_t label_len, + void *data, size_t *len) +{ + size_t u, k, hlen; + unsigned char *buf; + uint32_t r, s, zlen; + + hlen = br_digest_size(dig); + k = *len; + buf = data; + + /* + * There must be room for the padding. + */ + if (k < ((hlen << 1) + 2)) { + return 0; + } + + /* + * Unmask the seed, then the DB value. + */ + br_mgf1_xor(buf + 1, hlen, dig, buf + 1 + hlen, k - hlen - 1); + br_mgf1_xor(buf + 1 + hlen, k - hlen - 1, dig, buf + 1, hlen); + + /* + * Hash the label and XOR it with the value in the array; if + * they are equal then these should yield only zeros. + */ + xor_hash_data(dig, buf + 1 + hlen, label, label_len); + + /* + * At that point, if the padding was correct, when we should + * have: 0x00 || seed || 0x00 ... 0x00 0x01 || M + * Padding is valid as long as: + * - There is at least hlen+1 leading bytes of value 0x00. + * - There is at least one non-zero byte. + * - The first (leftmost) non-zero byte has value 0x01. + * + * Ultimately, we may leak the resulting message length, i.e. + * the position of the byte of value 0x01, but we must take care + * to do so only if the number of zero bytes has been verified + * to be at least hlen+1. + * + * The loop below counts the number of bytes of value 0x00, and + * checks that the next byte has value 0x01, in constant-time. + * + * - If the initial byte (before the seed) is not 0x00, then + * r and s are set to 0, and stay there. + * - Value r is 1 until the first non-zero byte is reached + * (after the seed); it switches to 0 at that point. + * - Value s is set to 1 if and only if the data encountered + * at the time of the transition of r from 1 to 0 has value + * exactly 0x01. + * - Value zlen counts the number of leading bytes of value zero + * (after the seed). + */ + r = 1 - ((buf[0] + 0xFF) >> 8); + s = 0; + zlen = 0; + for (u = hlen + 1; u < k; u ++) { + uint32_t w, nz; + + w = buf[u]; + + /* + * nz == 1 only for the first non-zero byte. + */ + nz = r & ((w + 0xFF) >> 8); + s |= nz & EQ(w, 0x01); + r &= NOT(nz); + zlen += r; + } + + /* + * Padding is correct only if s == 1, _and_ zlen >= hlen. + */ + s &= GE(zlen, (uint32_t)hlen); + + /* + * At that point, padding was verified, and we are now allowed + * to make conditional jumps. + */ + if (s) { + size_t plen; + + plen = 2 + hlen + zlen; + k -= plen; + memmove(buf, buf + plen, k); + *len = k; + } + return s; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_pkcs1_sig_pad.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_pkcs1_sig_pad.c new file mode 100644 index 000000000..1425af0e8 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_pkcs1_sig_pad.c @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +uint32_t +br_rsa_pkcs1_sig_pad(const unsigned char *hash_oid, + const unsigned char *hash, size_t hash_len, + uint32_t n_bitlen, unsigned char *x) +{ + size_t u, x3, xlen; + + /* + * Padded hash value has format: + * 00 01 FF .. FF 00 30 x1 30 x2 06 x3 OID 05 00 04 x4 HASH + * + * with the following rules: + * + * -- Total length is equal to the modulus length (unsigned + * encoding). + * + * -- There must be at least eight bytes of value 0xFF. + * + * -- x4 is equal to the hash length (hash_len). + * + * -- x3 is equal to the encoded OID value length (hash_oid[0]). + * + * -- x2 = x3 + 4. + * + * -- x1 = x2 + x4 + 4 = x3 + x4 + 8. + * + * Note: the "05 00" is optional (signatures with and without + * that sequence exist in practice), but notes in PKCS#1 seem to + * indicate that the presence of that sequence (specifically, + * an ASN.1 NULL value for the hash parameters) may be slightly + * more "standard" than the opposite. + */ + xlen = (n_bitlen + 7) >> 3; + + if (hash_oid == NULL) { + if (xlen < hash_len + 11) { + return 0; + } + x[0] = 0x00; + x[1] = 0x01; + u = xlen - hash_len; + memset(x + 2, 0xFF, u - 3); + x[u - 1] = 0x00; + } else { + x3 = hash_oid[0]; + + /* + * Check that there is enough room for all the elements, + * including at least eight bytes of value 0xFF. + */ + if (xlen < (x3 + hash_len + 21)) { + return 0; + } + x[0] = 0x00; + x[1] = 0x01; + u = xlen - x3 - hash_len - 11; + memset(x + 2, 0xFF, u - 2); + x[u] = 0x00; + x[u + 1] = 0x30; + x[u + 2] = x3 + hash_len + 8; + x[u + 3] = 0x30; + x[u + 4] = x3 + 4; + x[u + 5] = 0x06; + memcpy(x + u + 6, hash_oid, x3 + 1); + u += x3 + 7; + x[u ++] = 0x05; + x[u ++] = 0x00; + x[u ++] = 0x04; + x[u ++] = hash_len; + } + memcpy(x + u, hash, hash_len); + return 1; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_pkcs1_sig_unpad.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_pkcs1_sig_unpad.c new file mode 100644 index 000000000..43393968b --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_pkcs1_sig_unpad.c @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_rsa.h */ +uint32_t +br_rsa_pkcs1_sig_unpad(const unsigned char *sig, size_t sig_len, + const unsigned char *hash_oid, size_t hash_len, + unsigned char *hash_out) +{ + static const unsigned char pad1[] = { + 0x00, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF + }; + + unsigned char pad2[43]; + size_t u, x2, x3, pad_len, zlen; + + if (sig_len < 11) { + return 0; + } + + /* + * Expected format: + * 00 01 FF ... FF 00 30 x1 30 x2 06 x3 OID [ 05 00 ] 04 x4 HASH + * + * with the following rules: + * + * -- Total length is that of the modulus and the signature + * (this was already verified by br_rsa_i31_public()). + * + * -- There are at least eight bytes of value 0xFF. + * + * -- x4 is equal to the hash length (hash_len). + * + * -- x3 is equal to the encoded OID value length (so x3 is the + * first byte of hash_oid[]). + * + * -- If the "05 00" is present, then x2 == x3 + 4; otherwise, + * x2 == x3 + 2. + * + * -- x1 == x2 + x4 + 4. + * + * So the total length after the last "FF" is either x3 + x4 + 11 + * (with the "05 00") or x3 + x4 + 9 (without the "05 00"). + */ + + /* + * Check the "00 01 FF .. FF 00" with at least eight 0xFF bytes. + * The comparison is valid because we made sure that the signature + * is at least 11 bytes long. + */ + if (memcmp(sig, pad1, sizeof pad1) != 0) { + return 0; + } + for (u = sizeof pad1; u < sig_len; u ++) { + if (sig[u] != 0xFF) { + break; + } + } + + /* + * Remaining length is sig_len - u bytes (including the 00 just + * after the last FF). This must be equal to one of the two + * possible values (depending on whether the "05 00" sequence is + * present or not). + */ + if (hash_oid == NULL) { + if (sig_len - u != hash_len + 1 || sig[u] != 0x00) { + return 0; + } + } else { + x3 = hash_oid[0]; + pad_len = x3 + 9; + memset(pad2, 0, pad_len); + zlen = sig_len - u - hash_len; + if (zlen == pad_len) { + x2 = x3 + 2; + } else if (zlen == pad_len + 2) { + x2 = x3 + 4; + pad_len = zlen; + pad2[pad_len - 4] = 0x05; + } else { + return 0; + } + pad2[1] = 0x30; + pad2[2] = x2 + hash_len + 4; + pad2[3] = 0x30; + pad2[4] = x2; + pad2[5] = 0x06; + memcpy(pad2 + 6, hash_oid, x3 + 1); + pad2[pad_len - 2] = 0x04; + pad2[pad_len - 1] = hash_len; + if (memcmp(pad2, sig + u, pad_len) != 0) { + return 0; + } + } + memcpy(hash_out, sig + sig_len - hash_len, hash_len); + return 1; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_pss_sig_pad.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_pss_sig_pad.c new file mode 100644 index 000000000..c91668565 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_pss_sig_pad.c @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +uint32_t +br_rsa_pss_sig_pad(const br_prng_class **rng, + const br_hash_class *hf_data, const br_hash_class *hf_mgf1, + const unsigned char *hash, size_t salt_len, + uint32_t n_bitlen, unsigned char *x) +{ + size_t xlen, hash_len; + br_hash_compat_context hc; + unsigned char *salt, *seed; + + hash_len = br_digest_size(hf_data); + + /* + * The padded string is one bit smaller than the modulus; + * notably, if the modulus length is equal to 1 modulo 8, then + * the padded string will be one _byte_ smaller, and the first + * byte will be set to 0. We apply these transformations here. + */ + n_bitlen --; + if ((n_bitlen & 7) == 0) { + *x ++ = 0; + } + xlen = (n_bitlen + 7) >> 3; + + /* + * Check that the modulus is large enough for the hash value + * length combined with the intended salt length. + */ + if (hash_len > xlen || salt_len > xlen + || (hash_len + salt_len + 2) > xlen) + { + return 0; + } + + /* + * Produce a random salt. + */ + salt = x + xlen - hash_len - salt_len - 1; + if (salt_len != 0) { + (*rng)->generate(rng, salt, salt_len); + } + + /* + * Compute the seed for MGF1. + */ + seed = x + xlen - hash_len - 1; + hf_data->init(&hc.vtable); + memset(seed, 0, 8); + hf_data->update(&hc.vtable, seed, 8); + hf_data->update(&hc.vtable, hash, hash_len); + hf_data->update(&hc.vtable, salt, salt_len); + hf_data->out(&hc.vtable, seed); + + /* + * Prepare string PS (padded salt). The salt is already at the + * right place. + */ + memset(x, 0, xlen - salt_len - hash_len - 2); + x[xlen - salt_len - hash_len - 2] = 0x01; + + /* + * Generate the mask and XOR it into PS. + */ + br_mgf1_xor(x, xlen - hash_len - 1, hf_mgf1, seed, hash_len); + + /* + * Clear the top bits to ensure the value is lower than the + * modulus. + */ + x[0] &= 0xFF >> (((uint32_t)xlen << 3) - n_bitlen); + + /* + * The seed (H) is already in the right place. We just set the + * last byte. + */ + x[xlen - 1] = 0xBC; + + return 1; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_pss_sig_unpad.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_pss_sig_unpad.c new file mode 100644 index 000000000..06af48640 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_pss_sig_unpad.c @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +uint32_t +br_rsa_pss_sig_unpad(const br_hash_class *hf_data, + const br_hash_class *hf_mgf1, + const unsigned char *hash, size_t salt_len, + const br_rsa_public_key *pk, unsigned char *x) +{ + size_t u, xlen, hash_len; + br_hash_compat_context hc; + unsigned char *seed, *salt; + unsigned char tmp[64]; + uint32_t r, n_bitlen; + + hash_len = br_digest_size(hf_data); + + /* + * Value r will be set to a non-zero value is any test fails. + */ + r = 0; + + /* + * The value bit length (as an integer) must be strictly less than + * that of the modulus. + */ + for (u = 0; u < pk->nlen; u ++) { + if (pk->n[u] != 0) { + break; + } + } + if (u == pk->nlen) { + return 0; + } + n_bitlen = BIT_LENGTH(pk->n[u]) + ((uint32_t)(pk->nlen - u - 1) << 3); + n_bitlen --; + if ((n_bitlen & 7) == 0) { + r |= *x ++; + } else { + r |= x[0] & (0xFF << (n_bitlen & 7)); + } + xlen = (n_bitlen + 7) >> 3; + + /* + * Check that the modulus is large enough for the hash value + * length combined with the intended salt length. + */ + if (hash_len > xlen || salt_len > xlen + || (hash_len + salt_len + 2) > xlen) + { + return 0; + } + + /* + * Check value of rightmost byte. + */ + r |= x[xlen - 1] ^ 0xBC; + + /* + * Generate the mask and XOR it into the first bytes to reveal PS; + * we must also mask out the leading bits. + */ + seed = x + xlen - hash_len - 1; + br_mgf1_xor(x, xlen - hash_len - 1, hf_mgf1, seed, hash_len); + if ((n_bitlen & 7) != 0) { + x[0] &= 0xFF >> (8 - (n_bitlen & 7)); + } + + /* + * Check that all padding bytes have the expected value. + */ + for (u = 0; u < (xlen - hash_len - salt_len - 2); u ++) { + r |= x[u]; + } + r |= x[xlen - hash_len - salt_len - 2] ^ 0x01; + + /* + * Recompute H. + */ + salt = x + xlen - hash_len - salt_len - 1; + hf_data->init(&hc.vtable); + memset(tmp, 0, 8); + hf_data->update(&hc.vtable, tmp, 8); + hf_data->update(&hc.vtable, hash, hash_len); + hf_data->update(&hc.vtable, salt, salt_len); + hf_data->out(&hc.vtable, tmp); + + /* + * Check that the recomputed H value matches the one appearing + * in the string. + */ + for (u = 0; u < hash_len; u ++) { + r |= tmp[u] ^ x[(xlen - salt_len - 1) + u]; + } + + return EQ0(r); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_ssl_decrypt.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_ssl_decrypt.c new file mode 100644 index 000000000..26793f062 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/rsa_ssl_decrypt.c @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_rsa.h */ +uint32_t +br_rsa_ssl_decrypt(br_rsa_private core, const br_rsa_private_key *sk, + unsigned char *data, size_t len) +{ + uint32_t x; + size_t u; + + /* + * A first check on length. Since this test works only on the + * buffer length, it needs not (and cannot) be constant-time. + */ + if (len < 59 || len != (sk->n_bitlen + 7) >> 3) { + return 0; + } + x = core(data, sk); + + x &= EQ(data[0], 0x00); + x &= EQ(data[1], 0x02); + for (u = 2; u < (len - 49); u ++) { + x &= NEQ(data[u], 0); + } + x &= EQ(data[len - 49], 0x00); + memmove(data, data + len - 48, 48); + return x; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/settings.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/settings.c new file mode 100644 index 000000000..8baadeb8e --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/settings.c @@ -0,0 +1,311 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +static const br_config_option config[] = { + { "BR_64", +#if BR_64 + 1 +#else + 0 +#endif + }, + { "BR_AES_X86NI", +#if BR_AES_X86NI + 1 +#else + 0 +#endif + }, + { "BR_amd64", +#if BR_amd64 + 1 +#else + 0 +#endif + }, + { "BR_ARMEL_CORTEXM_GCC", +#if BR_ARMEL_CORTEXM_GCC + 1 +#else + 0 +#endif + }, + { "BR_BE_UNALIGNED", +#if BR_BE_UNALIGNED + 1 +#else + 0 +#endif + }, + { "BR_CLANG", +#if BR_CLANG + 1 +#else + 0 +#endif + }, + { "BR_CLANG_3_7", +#if BR_CLANG_3_7 + 1 +#else + 0 +#endif + }, + { "BR_CLANG_3_8", +#if BR_CLANG_3_8 + 1 +#else + 0 +#endif + }, + { "BR_CT_MUL15", +#if BR_CT_MUL15 + 1 +#else + 0 +#endif + }, + { "BR_CT_MUL31", +#if BR_CT_MUL31 + 1 +#else + 0 +#endif + }, + { "BR_GCC", +#if BR_GCC + 1 +#else + 0 +#endif + }, + { "BR_GCC_4_4", +#if BR_GCC_4_4 + 1 +#else + 0 +#endif + }, + { "BR_GCC_4_5", +#if BR_GCC_4_5 + 1 +#else + 0 +#endif + }, + { "BR_GCC_4_6", +#if BR_GCC_4_6 + 1 +#else + 0 +#endif + }, + { "BR_GCC_4_7", +#if BR_GCC_4_7 + 1 +#else + 0 +#endif + }, + { "BR_GCC_4_8", +#if BR_GCC_4_8 + 1 +#else + 0 +#endif + }, + { "BR_GCC_4_9", +#if BR_GCC_4_9 + 1 +#else + 0 +#endif + }, + { "BR_GCC_5_0", +#if BR_GCC_5_0 + 1 +#else + 0 +#endif + }, + { "BR_i386", +#if BR_i386 + 1 +#else + 0 +#endif + }, + { "BR_INT128", +#if BR_INT128 + 1 +#else + 0 +#endif + }, + { "BR_LE_UNALIGNED", +#if BR_LE_UNALIGNED + 1 +#else + 0 +#endif + }, + { "BR_LOMUL", +#if BR_LOMUL + 1 +#else + 0 +#endif + }, + { "BR_MAX_EC_SIZE", BR_MAX_EC_SIZE }, + { "BR_MAX_RSA_SIZE", BR_MAX_RSA_SIZE }, + { "BR_MAX_RSA_FACTOR", BR_MAX_RSA_FACTOR }, + { "BR_MSC", +#if BR_MSC + 1 +#else + 0 +#endif + }, + { "BR_MSC_2005", +#if BR_MSC_2005 + 1 +#else + 0 +#endif + }, + { "BR_MSC_2008", +#if BR_MSC_2008 + 1 +#else + 0 +#endif + }, + { "BR_MSC_2010", +#if BR_MSC_2010 + 1 +#else + 0 +#endif + }, + { "BR_MSC_2012", +#if BR_MSC_2012 + 1 +#else + 0 +#endif + }, + { "BR_MSC_2013", +#if BR_MSC_2013 + 1 +#else + 0 +#endif + }, + { "BR_MSC_2015", +#if BR_MSC_2015 + 1 +#else + 0 +#endif + }, + { "BR_POWER8", +#if BR_POWER8 + 1 +#else + 0 +#endif + }, + { "BR_RDRAND", +#if BR_RDRAND + 1 +#else + 0 +#endif + }, + { "BR_SLOW_MUL", +#if BR_SLOW_MUL + 1 +#else + 0 +#endif + }, + { "BR_SLOW_MUL15", +#if BR_SLOW_MUL15 + 1 +#else + 0 +#endif + }, + { "BR_SSE2", +#if BR_SSE2 + 1 +#else + 0 +#endif + }, + { "BR_UMUL128", +#if BR_UMUL128 + 1 +#else + 0 +#endif + }, + { "BR_USE_UNIX_TIME", +#if BR_USE_UNIX_TIME + 1 +#else + 0 +#endif + }, + { "BR_USE_WIN32_RAND", +#if BR_USE_WIN32_RAND + 1 +#else + 0 +#endif + }, + { "BR_USE_WIN32_TIME", +#if BR_USE_WIN32_TIME + 1 +#else + 0 +#endif + }, + + { NULL, 0 } +}; + +/* see bearssl.h */ +const br_config_option * +br_get_config(void) +{ + return config; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/sha1.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/sha1.c new file mode 100644 index 000000000..35e0895df --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/sha1.c @@ -0,0 +1,196 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +#define F(B, C, D) ((((C) ^ (D)) & (B)) ^ (D)) +#define G(B, C, D) ((B) ^ (C) ^ (D)) +#define H(B, C, D) (((D) & (C)) | (((D) | (C)) & (B))) +#define I(B, C, D) G(B, C, D) + +#define ROTL(x, n) (((x) << (n)) | ((x) >> (32 - (n)))) + +#define K1 ((uint32_t)0x5A827999) +#define K2 ((uint32_t)0x6ED9EBA1) +#define K3 ((uint32_t)0x8F1BBCDC) +#define K4 ((uint32_t)0xCA62C1D6) + +/* see inner.h */ +const uint32_t br_sha1_IV[5] = { + 0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0 +}; + +/* see inner.h */ +void +br_sha1_round(const unsigned char *buf, uint32_t *val) +{ + uint32_t m[80]; + uint32_t a, b, c, d, e; + int i; + + a = val[0]; + b = val[1]; + c = val[2]; + d = val[3]; + e = val[4]; + br_range_dec32be(m, 16, buf); + for (i = 16; i < 80; i ++) { + uint32_t x = m[i - 3] ^ m[i - 8] ^ m[i - 14] ^ m[i - 16]; + m[i] = ROTL(x, 1); + } + + for (i = 0; i < 20; i += 5) { + e += ROTL(a, 5) + F(b, c, d) + K1 + m[i + 0]; b = ROTL(b, 30); + d += ROTL(e, 5) + F(a, b, c) + K1 + m[i + 1]; a = ROTL(a, 30); + c += ROTL(d, 5) + F(e, a, b) + K1 + m[i + 2]; e = ROTL(e, 30); + b += ROTL(c, 5) + F(d, e, a) + K1 + m[i + 3]; d = ROTL(d, 30); + a += ROTL(b, 5) + F(c, d, e) + K1 + m[i + 4]; c = ROTL(c, 30); + } + for (i = 20; i < 40; i += 5) { + e += ROTL(a, 5) + G(b, c, d) + K2 + m[i + 0]; b = ROTL(b, 30); + d += ROTL(e, 5) + G(a, b, c) + K2 + m[i + 1]; a = ROTL(a, 30); + c += ROTL(d, 5) + G(e, a, b) + K2 + m[i + 2]; e = ROTL(e, 30); + b += ROTL(c, 5) + G(d, e, a) + K2 + m[i + 3]; d = ROTL(d, 30); + a += ROTL(b, 5) + G(c, d, e) + K2 + m[i + 4]; c = ROTL(c, 30); + } + for (i = 40; i < 60; i += 5) { + e += ROTL(a, 5) + H(b, c, d) + K3 + m[i + 0]; b = ROTL(b, 30); + d += ROTL(e, 5) + H(a, b, c) + K3 + m[i + 1]; a = ROTL(a, 30); + c += ROTL(d, 5) + H(e, a, b) + K3 + m[i + 2]; e = ROTL(e, 30); + b += ROTL(c, 5) + H(d, e, a) + K3 + m[i + 3]; d = ROTL(d, 30); + a += ROTL(b, 5) + H(c, d, e) + K3 + m[i + 4]; c = ROTL(c, 30); + } + for (i = 60; i < 80; i += 5) { + e += ROTL(a, 5) + I(b, c, d) + K4 + m[i + 0]; b = ROTL(b, 30); + d += ROTL(e, 5) + I(a, b, c) + K4 + m[i + 1]; a = ROTL(a, 30); + c += ROTL(d, 5) + I(e, a, b) + K4 + m[i + 2]; e = ROTL(e, 30); + b += ROTL(c, 5) + I(d, e, a) + K4 + m[i + 3]; d = ROTL(d, 30); + a += ROTL(b, 5) + I(c, d, e) + K4 + m[i + 4]; c = ROTL(c, 30); + } + + val[0] += a; + val[1] += b; + val[2] += c; + val[3] += d; + val[4] += e; +} + +/* see bearssl.h */ +void +br_sha1_init(br_sha1_context *cc) +{ + cc->vtable = &br_sha1_vtable; + memcpy(cc->val, br_sha1_IV, sizeof cc->val); + cc->count = 0; +} + +/* see bearssl.h */ +void +br_sha1_update(br_sha1_context *cc, const void *data, size_t len) +{ + const unsigned char *buf; + size_t ptr; + + buf = data; + ptr = (size_t)cc->count & 63; + while (len > 0) { + size_t clen; + + clen = 64 - ptr; + if (clen > len) { + clen = len; + } + memcpy(cc->buf + ptr, buf, clen); + ptr += clen; + buf += clen; + len -= clen; + cc->count += (uint64_t)clen; + if (ptr == 64) { + br_sha1_round(cc->buf, cc->val); + ptr = 0; + } + } +} + +/* see bearssl.h */ +void +br_sha1_out(const br_sha1_context *cc, void *dst) +{ + unsigned char buf[64]; + uint32_t val[5]; + size_t ptr; + + ptr = (size_t)cc->count & 63; + memcpy(buf, cc->buf, ptr); + memcpy(val, cc->val, sizeof val); + buf[ptr ++] = 0x80; + if (ptr > 56) { + memset(buf + ptr, 0, 64 - ptr); + br_sha1_round(buf, val); + memset(buf, 0, 56); + } else { + memset(buf + ptr, 0, 56 - ptr); + } + br_enc64be(buf + 56, cc->count << 3); + br_sha1_round(buf, val); + br_range_enc32be(dst, val, 5); +} + +/* see bearssl.h */ +uint64_t +br_sha1_state(const br_sha1_context *cc, void *dst) +{ + br_range_enc32be(dst, cc->val, 5); + return cc->count; +} + +/* see bearssl.h */ +void +br_sha1_set_state(br_sha1_context *cc, const void *stb, uint64_t count) +{ + br_range_dec32be(cc->val, 5, stb); + cc->count = count; +} + +/* see bearssl.h */ +const br_hash_class br_sha1_vtable = { + sizeof(br_sha1_context), + BR_HASHDESC_ID(br_sha1_ID) + | BR_HASHDESC_OUT(20) + | BR_HASHDESC_STATE(20) + | BR_HASHDESC_LBLEN(6) + | BR_HASHDESC_MD_PADDING + | BR_HASHDESC_MD_PADDING_BE, + (void (*)(const br_hash_class **))&br_sha1_init, + (void (*)(const br_hash_class **, const void *, size_t))&br_sha1_update, + (void (*)(const br_hash_class *const *, void *))&br_sha1_out, + (uint64_t (*)(const br_hash_class *const *, void *))&br_sha1_state, + (void (*)(const br_hash_class **, const void *, uint64_t)) + &br_sha1_set_state +}; + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/sha2big.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/sha2big.c new file mode 100644 index 000000000..5d16209ee --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/sha2big.c @@ -0,0 +1,290 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +#define CH(X, Y, Z) ((((Y) ^ (Z)) & (X)) ^ (Z)) +#define MAJ(X, Y, Z) (((Y) & (Z)) | (((Y) | (Z)) & (X))) + +#define ROTR(x, n) (((uint64_t)(x) << (64 - (n))) | ((uint64_t)(x) >> (n))) + +#define BSG5_0(x) (ROTR(x, 28) ^ ROTR(x, 34) ^ ROTR(x, 39)) +#define BSG5_1(x) (ROTR(x, 14) ^ ROTR(x, 18) ^ ROTR(x, 41)) +#define SSG5_0(x) (ROTR(x, 1) ^ ROTR(x, 8) ^ (uint64_t)((x) >> 7)) +#define SSG5_1(x) (ROTR(x, 19) ^ ROTR(x, 61) ^ (uint64_t)((x) >> 6)) + +static const uint64_t IV384[8] = { + 0xCBBB9D5DC1059ED8, 0x629A292A367CD507, + 0x9159015A3070DD17, 0x152FECD8F70E5939, + 0x67332667FFC00B31, 0x8EB44A8768581511, + 0xDB0C2E0D64F98FA7, 0x47B5481DBEFA4FA4 +}; + +static const uint64_t IV512[8] = { + 0x6A09E667F3BCC908, 0xBB67AE8584CAA73B, + 0x3C6EF372FE94F82B, 0xA54FF53A5F1D36F1, + 0x510E527FADE682D1, 0x9B05688C2B3E6C1F, + 0x1F83D9ABFB41BD6B, 0x5BE0CD19137E2179 +}; + +static const uint64_t K[80] = { + 0x428A2F98D728AE22, 0x7137449123EF65CD, + 0xB5C0FBCFEC4D3B2F, 0xE9B5DBA58189DBBC, + 0x3956C25BF348B538, 0x59F111F1B605D019, + 0x923F82A4AF194F9B, 0xAB1C5ED5DA6D8118, + 0xD807AA98A3030242, 0x12835B0145706FBE, + 0x243185BE4EE4B28C, 0x550C7DC3D5FFB4E2, + 0x72BE5D74F27B896F, 0x80DEB1FE3B1696B1, + 0x9BDC06A725C71235, 0xC19BF174CF692694, + 0xE49B69C19EF14AD2, 0xEFBE4786384F25E3, + 0x0FC19DC68B8CD5B5, 0x240CA1CC77AC9C65, + 0x2DE92C6F592B0275, 0x4A7484AA6EA6E483, + 0x5CB0A9DCBD41FBD4, 0x76F988DA831153B5, + 0x983E5152EE66DFAB, 0xA831C66D2DB43210, + 0xB00327C898FB213F, 0xBF597FC7BEEF0EE4, + 0xC6E00BF33DA88FC2, 0xD5A79147930AA725, + 0x06CA6351E003826F, 0x142929670A0E6E70, + 0x27B70A8546D22FFC, 0x2E1B21385C26C926, + 0x4D2C6DFC5AC42AED, 0x53380D139D95B3DF, + 0x650A73548BAF63DE, 0x766A0ABB3C77B2A8, + 0x81C2C92E47EDAEE6, 0x92722C851482353B, + 0xA2BFE8A14CF10364, 0xA81A664BBC423001, + 0xC24B8B70D0F89791, 0xC76C51A30654BE30, + 0xD192E819D6EF5218, 0xD69906245565A910, + 0xF40E35855771202A, 0x106AA07032BBD1B8, + 0x19A4C116B8D2D0C8, 0x1E376C085141AB53, + 0x2748774CDF8EEB99, 0x34B0BCB5E19B48A8, + 0x391C0CB3C5C95A63, 0x4ED8AA4AE3418ACB, + 0x5B9CCA4F7763E373, 0x682E6FF3D6B2B8A3, + 0x748F82EE5DEFB2FC, 0x78A5636F43172F60, + 0x84C87814A1F0AB72, 0x8CC702081A6439EC, + 0x90BEFFFA23631E28, 0xA4506CEBDE82BDE9, + 0xBEF9A3F7B2C67915, 0xC67178F2E372532B, + 0xCA273ECEEA26619C, 0xD186B8C721C0C207, + 0xEADA7DD6CDE0EB1E, 0xF57D4F7FEE6ED178, + 0x06F067AA72176FBA, 0x0A637DC5A2C898A6, + 0x113F9804BEF90DAE, 0x1B710B35131C471B, + 0x28DB77F523047D84, 0x32CAAB7B40C72493, + 0x3C9EBE0A15C9BEBC, 0x431D67C49C100D4C, + 0x4CC5D4BECB3E42B6, 0x597F299CFC657E2A, + 0x5FCB6FAB3AD6FAEC, 0x6C44198C4A475817 +}; + +static void +sha2big_round(const unsigned char *buf, uint64_t *val) +{ + +#define SHA2BIG_STEP(A, B, C, D, E, F, G, H, j) do { \ + uint64_t T1, T2; \ + T1 = H + BSG5_1(E) + CH(E, F, G) + K[j] + w[j]; \ + T2 = BSG5_0(A) + MAJ(A, B, C); \ + D += T1; \ + H = T1 + T2; \ + } while (0) + + int i; + uint64_t a, b, c, d, e, f, g, h; + uint64_t w[80]; + + br_range_dec64be(w, 16, buf); + for (i = 16; i < 80; i ++) { + w[i] = SSG5_1(w[i - 2]) + w[i - 7] + + SSG5_0(w[i - 15]) + w[i - 16]; + } + a = val[0]; + b = val[1]; + c = val[2]; + d = val[3]; + e = val[4]; + f = val[5]; + g = val[6]; + h = val[7]; + for (i = 0; i < 80; i += 8) { + SHA2BIG_STEP(a, b, c, d, e, f, g, h, i + 0); + SHA2BIG_STEP(h, a, b, c, d, e, f, g, i + 1); + SHA2BIG_STEP(g, h, a, b, c, d, e, f, i + 2); + SHA2BIG_STEP(f, g, h, a, b, c, d, e, i + 3); + SHA2BIG_STEP(e, f, g, h, a, b, c, d, i + 4); + SHA2BIG_STEP(d, e, f, g, h, a, b, c, i + 5); + SHA2BIG_STEP(c, d, e, f, g, h, a, b, i + 6); + SHA2BIG_STEP(b, c, d, e, f, g, h, a, i + 7); + } + val[0] += a; + val[1] += b; + val[2] += c; + val[3] += d; + val[4] += e; + val[5] += f; + val[6] += g; + val[7] += h; +} + +static void +sha2big_update(br_sha384_context *cc, const void *data, size_t len) +{ + const unsigned char *buf; + size_t ptr; + + buf = data; + ptr = (size_t)cc->count & 127; + cc->count += (uint64_t)len; + while (len > 0) { + size_t clen; + + clen = 128 - ptr; + if (clen > len) { + clen = len; + } + memcpy(cc->buf + ptr, buf, clen); + ptr += clen; + buf += clen; + len -= clen; + if (ptr == 128) { + sha2big_round(cc->buf, cc->val); + ptr = 0; + } + } +} + +static void +sha2big_out(const br_sha384_context *cc, void *dst, int num) +{ + unsigned char buf[128]; + uint64_t val[8]; + size_t ptr; + + ptr = (size_t)cc->count & 127; + memcpy(buf, cc->buf, ptr); + memcpy(val, cc->val, sizeof val); + buf[ptr ++] = 0x80; + if (ptr > 112) { + memset(buf + ptr, 0, 128 - ptr); + sha2big_round(buf, val); + memset(buf, 0, 112); + } else { + memset(buf + ptr, 0, 112 - ptr); + } + br_enc64be(buf + 112, cc->count >> 61); + br_enc64be(buf + 120, cc->count << 3); + sha2big_round(buf, val); + br_range_enc64be(dst, val, num); +} + +/* see bearssl.h */ +void +br_sha384_init(br_sha384_context *cc) +{ + cc->vtable = &br_sha384_vtable; + memcpy(cc->val, IV384, sizeof IV384); + cc->count = 0; +} + +/* see bearssl.h */ +void +br_sha384_update(br_sha384_context *cc, const void *data, size_t len) +{ + sha2big_update(cc, data, len); +} + +/* see bearssl.h */ +void +br_sha384_out(const br_sha384_context *cc, void *dst) +{ + sha2big_out(cc, dst, 6); +} + +/* see bearssl.h */ +uint64_t +br_sha384_state(const br_sha384_context *cc, void *dst) +{ + br_range_enc64be(dst, cc->val, 8); + return cc->count; +} + +/* see bearssl.h */ +void +br_sha384_set_state(br_sha384_context *cc, const void *stb, uint64_t count) +{ + br_range_dec64be(cc->val, 8, stb); + cc->count = count; +} + +/* see bearssl.h */ +void +br_sha512_init(br_sha512_context *cc) +{ + cc->vtable = &br_sha512_vtable; + memcpy(cc->val, IV512, sizeof IV512); + cc->count = 0; +} + +/* see bearssl.h */ +void +br_sha512_out(const br_sha512_context *cc, void *dst) +{ + sha2big_out(cc, dst, 8); +} + +/* see bearssl.h */ +const br_hash_class br_sha384_vtable = { + sizeof(br_sha384_context), + BR_HASHDESC_ID(br_sha384_ID) + | BR_HASHDESC_OUT(48) + | BR_HASHDESC_STATE(64) + | BR_HASHDESC_LBLEN(7) + | BR_HASHDESC_MD_PADDING + | BR_HASHDESC_MD_PADDING_BE + | BR_HASHDESC_MD_PADDING_128, + (void (*)(const br_hash_class **))&br_sha384_init, + (void (*)(const br_hash_class **, const void *, size_t)) + &br_sha384_update, + (void (*)(const br_hash_class *const *, void *))&br_sha384_out, + (uint64_t (*)(const br_hash_class *const *, void *))&br_sha384_state, + (void (*)(const br_hash_class **, const void *, uint64_t)) + &br_sha384_set_state +}; + +/* see bearssl.h */ +const br_hash_class br_sha512_vtable = { + sizeof(br_sha512_context), + BR_HASHDESC_ID(br_sha512_ID) + | BR_HASHDESC_OUT(64) + | BR_HASHDESC_STATE(64) + | BR_HASHDESC_LBLEN(7) + | BR_HASHDESC_MD_PADDING + | BR_HASHDESC_MD_PADDING_BE + | BR_HASHDESC_MD_PADDING_128, + (void (*)(const br_hash_class **))&br_sha512_init, + (void (*)(const br_hash_class **, const void *, size_t)) + &br_sha512_update, + (void (*)(const br_hash_class *const *, void *))&br_sha512_out, + (uint64_t (*)(const br_hash_class *const *, void *))&br_sha512_state, + (void (*)(const br_hash_class **, const void *, uint64_t)) + &br_sha512_set_state +}; + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/sha2small.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/sha2small.c new file mode 100644 index 000000000..82c598836 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/sha2small.c @@ -0,0 +1,346 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +#define CH(X, Y, Z) ((((Y) ^ (Z)) & (X)) ^ (Z)) +#define MAJ(X, Y, Z) (((Y) & (Z)) | (((Y) | (Z)) & (X))) + +#define ROTR(x, n) (((uint32_t)(x) << (32 - (n))) | ((uint32_t)(x) >> (n))) + +#define BSG2_0(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22)) +#define BSG2_1(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25)) +#define SSG2_0(x) (ROTR(x, 7) ^ ROTR(x, 18) ^ (uint32_t)((x) >> 3)) +#define SSG2_1(x) (ROTR(x, 17) ^ ROTR(x, 19) ^ (uint32_t)((x) >> 10)) + +/* see inner.h */ +const uint32_t br_sha224_IV[8] = { + 0xC1059ED8, 0x367CD507, 0x3070DD17, 0xF70E5939, + 0xFFC00B31, 0x68581511, 0x64F98FA7, 0xBEFA4FA4 +}; + +/* see inner.h */ +const uint32_t br_sha256_IV[8] = { + 0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A, + 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19 +}; + +static const uint32_t K[64] = { + 0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5, + 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5, + 0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3, + 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174, + 0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC, + 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA, + 0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7, + 0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967, + 0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13, + 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85, + 0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3, + 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070, + 0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5, + 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3, + 0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208, + 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2 +}; + +/* see inner.h */ +void +br_sha2small_round(const unsigned char *buf, uint32_t *val) +{ + +#define SHA2_STEP(A, B, C, D, E, F, G, H, j) do { \ + uint32_t T1, T2; \ + T1 = H + BSG2_1(E) + CH(E, F, G) + K[j] + w[j]; \ + T2 = BSG2_0(A) + MAJ(A, B, C); \ + D += T1; \ + H = T1 + T2; \ + } while (0) + + int i; + uint32_t a, b, c, d, e, f, g, h; + uint32_t w[64]; + + br_range_dec32be(w, 16, buf); + for (i = 16; i < 64; i ++) { + w[i] = SSG2_1(w[i - 2]) + w[i - 7] + + SSG2_0(w[i - 15]) + w[i - 16]; + } + a = val[0]; + b = val[1]; + c = val[2]; + d = val[3]; + e = val[4]; + f = val[5]; + g = val[6]; + h = val[7]; + for (i = 0; i < 64; i += 8) { + SHA2_STEP(a, b, c, d, e, f, g, h, i + 0); + SHA2_STEP(h, a, b, c, d, e, f, g, i + 1); + SHA2_STEP(g, h, a, b, c, d, e, f, i + 2); + SHA2_STEP(f, g, h, a, b, c, d, e, i + 3); + SHA2_STEP(e, f, g, h, a, b, c, d, i + 4); + SHA2_STEP(d, e, f, g, h, a, b, c, i + 5); + SHA2_STEP(c, d, e, f, g, h, a, b, i + 6); + SHA2_STEP(b, c, d, e, f, g, h, a, i + 7); + } + val[0] += a; + val[1] += b; + val[2] += c; + val[3] += d; + val[4] += e; + val[5] += f; + val[6] += g; + val[7] += h; + +#if 0 +/* obsolete */ +#define SHA2_MEXP1(pc) do { \ + W[pc] = br_dec32be(buf + ((pc) << 2)); \ + } while (0) + +#define SHA2_MEXP2(pc) do { \ + W[(pc) & 0x0F] = SSG2_1(W[((pc) - 2) & 0x0F]) \ + + W[((pc) - 7) & 0x0F] \ + + SSG2_0(W[((pc) - 15) & 0x0F]) + W[(pc) & 0x0F]; \ + } while (0) + +#define SHA2_STEPn(n, a, b, c, d, e, f, g, h, pc) do { \ + uint32_t t1, t2; \ + SHA2_MEXP ## n(pc); \ + t1 = h + BSG2_1(e) + CH(e, f, g) \ + + K[pcount + (pc)] + W[(pc) & 0x0F]; \ + t2 = BSG2_0(a) + MAJ(a, b, c); \ + d += t1; \ + h = t1 + t2; \ + } while (0) + +#define SHA2_STEP1(a, b, c, d, e, f, g, h, pc) \ + SHA2_STEPn(1, a, b, c, d, e, f, g, h, pc) +#define SHA2_STEP2(a, b, c, d, e, f, g, h, pc) \ + SHA2_STEPn(2, a, b, c, d, e, f, g, h, pc) + + uint32_t A, B, C, D, E, F, G, H; + uint32_t W[16]; + unsigned pcount; + + A = val[0]; + B = val[1]; + C = val[2]; + D = val[3]; + E = val[4]; + F = val[5]; + G = val[6]; + H = val[7]; + pcount = 0; + SHA2_STEP1(A, B, C, D, E, F, G, H, 0); + SHA2_STEP1(H, A, B, C, D, E, F, G, 1); + SHA2_STEP1(G, H, A, B, C, D, E, F, 2); + SHA2_STEP1(F, G, H, A, B, C, D, E, 3); + SHA2_STEP1(E, F, G, H, A, B, C, D, 4); + SHA2_STEP1(D, E, F, G, H, A, B, C, 5); + SHA2_STEP1(C, D, E, F, G, H, A, B, 6); + SHA2_STEP1(B, C, D, E, F, G, H, A, 7); + SHA2_STEP1(A, B, C, D, E, F, G, H, 8); + SHA2_STEP1(H, A, B, C, D, E, F, G, 9); + SHA2_STEP1(G, H, A, B, C, D, E, F, 10); + SHA2_STEP1(F, G, H, A, B, C, D, E, 11); + SHA2_STEP1(E, F, G, H, A, B, C, D, 12); + SHA2_STEP1(D, E, F, G, H, A, B, C, 13); + SHA2_STEP1(C, D, E, F, G, H, A, B, 14); + SHA2_STEP1(B, C, D, E, F, G, H, A, 15); + for (pcount = 16; pcount < 64; pcount += 16) { + SHA2_STEP2(A, B, C, D, E, F, G, H, 0); + SHA2_STEP2(H, A, B, C, D, E, F, G, 1); + SHA2_STEP2(G, H, A, B, C, D, E, F, 2); + SHA2_STEP2(F, G, H, A, B, C, D, E, 3); + SHA2_STEP2(E, F, G, H, A, B, C, D, 4); + SHA2_STEP2(D, E, F, G, H, A, B, C, 5); + SHA2_STEP2(C, D, E, F, G, H, A, B, 6); + SHA2_STEP2(B, C, D, E, F, G, H, A, 7); + SHA2_STEP2(A, B, C, D, E, F, G, H, 8); + SHA2_STEP2(H, A, B, C, D, E, F, G, 9); + SHA2_STEP2(G, H, A, B, C, D, E, F, 10); + SHA2_STEP2(F, G, H, A, B, C, D, E, 11); + SHA2_STEP2(E, F, G, H, A, B, C, D, 12); + SHA2_STEP2(D, E, F, G, H, A, B, C, 13); + SHA2_STEP2(C, D, E, F, G, H, A, B, 14); + SHA2_STEP2(B, C, D, E, F, G, H, A, 15); + } + val[0] += A; + val[1] += B; + val[2] += C; + val[3] += D; + val[4] += E; + val[5] += F; + val[6] += G; + val[7] += H; +#endif +} + +static void +sha2small_update(br_sha224_context *cc, const void *data, size_t len) +{ + const unsigned char *buf; + size_t ptr; + + buf = data; + ptr = (size_t)cc->count & 63; + cc->count += (uint64_t)len; + while (len > 0) { + size_t clen; + + clen = 64 - ptr; + if (clen > len) { + clen = len; + } + memcpy(cc->buf + ptr, buf, clen); + ptr += clen; + buf += clen; + len -= clen; + if (ptr == 64) { + br_sha2small_round(cc->buf, cc->val); + ptr = 0; + } + } +} + +static void +sha2small_out(const br_sha224_context *cc, void *dst, int num) +{ + unsigned char buf[64]; + uint32_t val[8]; + size_t ptr; + + ptr = (size_t)cc->count & 63; + memcpy(buf, cc->buf, ptr); + memcpy(val, cc->val, sizeof val); + buf[ptr ++] = 0x80; + if (ptr > 56) { + memset(buf + ptr, 0, 64 - ptr); + br_sha2small_round(buf, val); + memset(buf, 0, 56); + } else { + memset(buf + ptr, 0, 56 - ptr); + } + br_enc64be(buf + 56, cc->count << 3); + br_sha2small_round(buf, val); + br_range_enc32be(dst, val, num); +} + +/* see bearssl.h */ +void +br_sha224_init(br_sha224_context *cc) +{ + cc->vtable = &br_sha224_vtable; + memcpy(cc->val, br_sha224_IV, sizeof cc->val); + cc->count = 0; +} + +/* see bearssl.h */ +void +br_sha224_update(br_sha224_context *cc, const void *data, size_t len) +{ + sha2small_update(cc, data, len); +} + +/* see bearssl.h */ +void +br_sha224_out(const br_sha224_context *cc, void *dst) +{ + sha2small_out(cc, dst, 7); +} + +/* see bearssl.h */ +uint64_t +br_sha224_state(const br_sha224_context *cc, void *dst) +{ + br_range_enc32be(dst, cc->val, 8); + return cc->count; +} + +/* see bearssl.h */ +void +br_sha224_set_state(br_sha224_context *cc, const void *stb, uint64_t count) +{ + br_range_dec32be(cc->val, 8, stb); + cc->count = count; +} + +/* see bearssl.h */ +void +br_sha256_init(br_sha256_context *cc) +{ + cc->vtable = &br_sha256_vtable; + memcpy(cc->val, br_sha256_IV, sizeof cc->val); + cc->count = 0; +} + +/* see bearssl.h */ +void +br_sha256_out(const br_sha256_context *cc, void *dst) +{ + sha2small_out(cc, dst, 8); +} + +/* see bearssl.h */ +const br_hash_class br_sha224_vtable = { + sizeof(br_sha224_context), + BR_HASHDESC_ID(br_sha224_ID) + | BR_HASHDESC_OUT(28) + | BR_HASHDESC_STATE(32) + | BR_HASHDESC_LBLEN(6) + | BR_HASHDESC_MD_PADDING + | BR_HASHDESC_MD_PADDING_BE, + (void (*)(const br_hash_class **))&br_sha224_init, + (void (*)(const br_hash_class **, + const void *, size_t))&br_sha224_update, + (void (*)(const br_hash_class *const *, void *))&br_sha224_out, + (uint64_t (*)(const br_hash_class *const *, void *))&br_sha224_state, + (void (*)(const br_hash_class **, const void *, uint64_t)) + &br_sha224_set_state +}; + +/* see bearssl.h */ +const br_hash_class br_sha256_vtable = { + sizeof(br_sha256_context), + BR_HASHDESC_ID(br_sha256_ID) + | BR_HASHDESC_OUT(32) + | BR_HASHDESC_STATE(32) + | BR_HASHDESC_LBLEN(6) + | BR_HASHDESC_MD_PADDING + | BR_HASHDESC_MD_PADDING_BE, + (void (*)(const br_hash_class **))&br_sha256_init, + (void (*)(const br_hash_class **, + const void *, size_t))&br_sha256_update, + (void (*)(const br_hash_class *const *, void *))&br_sha256_out, + (uint64_t (*)(const br_hash_class *const *, void *))&br_sha256_state, + (void (*)(const br_hash_class **, const void *, uint64_t)) + &br_sha256_set_state +}; + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/shake.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/shake.c new file mode 100644 index 000000000..c2de3cdcc --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/shake.c @@ -0,0 +1,595 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* + * Round constants. + */ +static const uint64_t RC[] = { + 0x0000000000000001, 0x0000000000008082, + 0x800000000000808A, 0x8000000080008000, + 0x000000000000808B, 0x0000000080000001, + 0x8000000080008081, 0x8000000000008009, + 0x000000000000008A, 0x0000000000000088, + 0x0000000080008009, 0x000000008000000A, + 0x000000008000808B, 0x800000000000008B, + 0x8000000000008089, 0x8000000000008003, + 0x8000000000008002, 0x8000000000000080, + 0x000000000000800A, 0x800000008000000A, + 0x8000000080008081, 0x8000000000008080, + 0x0000000080000001, 0x8000000080008008 +}; + +/* + * XOR a block of data into the provided state. This supports only + * blocks whose length is a multiple of 64 bits. + */ +static void +xor_block(uint64_t *A, const void *data, size_t rate) +{ + size_t u; + + for (u = 0; u < rate; u += 8) { + A[u >> 3] ^= br_dec64le((const unsigned char *)data + u); + } +} + +/* + * Process a block with the provided data. The data length must be a + * multiple of 8 (in bytes); normally, this is the "rate". + */ +static void +process_block(uint64_t *A) +{ + uint64_t t0, t1, t2, t3, t4; + uint64_t tt0, tt1, tt2, tt3; + uint64_t t, kt; + uint64_t c0, c1, c2, c3, c4, bnn; + int j; + + /* + * Compute the 24 rounds. This loop is partially unrolled (each + * iteration computes two rounds). + */ + for (j = 0; j < 24; j += 2) { + + tt0 = A[ 1] ^ A[ 6]; + tt1 = A[11] ^ A[16]; + tt0 ^= A[21] ^ tt1; + tt0 = (tt0 << 1) | (tt0 >> 63); + tt2 = A[ 4] ^ A[ 9]; + tt3 = A[14] ^ A[19]; + tt0 ^= A[24]; + tt2 ^= tt3; + t0 = tt0 ^ tt2; + + tt0 = A[ 2] ^ A[ 7]; + tt1 = A[12] ^ A[17]; + tt0 ^= A[22] ^ tt1; + tt0 = (tt0 << 1) | (tt0 >> 63); + tt2 = A[ 0] ^ A[ 5]; + tt3 = A[10] ^ A[15]; + tt0 ^= A[20]; + tt2 ^= tt3; + t1 = tt0 ^ tt2; + + tt0 = A[ 3] ^ A[ 8]; + tt1 = A[13] ^ A[18]; + tt0 ^= A[23] ^ tt1; + tt0 = (tt0 << 1) | (tt0 >> 63); + tt2 = A[ 1] ^ A[ 6]; + tt3 = A[11] ^ A[16]; + tt0 ^= A[21]; + tt2 ^= tt3; + t2 = tt0 ^ tt2; + + tt0 = A[ 4] ^ A[ 9]; + tt1 = A[14] ^ A[19]; + tt0 ^= A[24] ^ tt1; + tt0 = (tt0 << 1) | (tt0 >> 63); + tt2 = A[ 2] ^ A[ 7]; + tt3 = A[12] ^ A[17]; + tt0 ^= A[22]; + tt2 ^= tt3; + t3 = tt0 ^ tt2; + + tt0 = A[ 0] ^ A[ 5]; + tt1 = A[10] ^ A[15]; + tt0 ^= A[20] ^ tt1; + tt0 = (tt0 << 1) | (tt0 >> 63); + tt2 = A[ 3] ^ A[ 8]; + tt3 = A[13] ^ A[18]; + tt0 ^= A[23]; + tt2 ^= tt3; + t4 = tt0 ^ tt2; + + A[ 0] = A[ 0] ^ t0; + A[ 5] = A[ 5] ^ t0; + A[10] = A[10] ^ t0; + A[15] = A[15] ^ t0; + A[20] = A[20] ^ t0; + A[ 1] = A[ 1] ^ t1; + A[ 6] = A[ 6] ^ t1; + A[11] = A[11] ^ t1; + A[16] = A[16] ^ t1; + A[21] = A[21] ^ t1; + A[ 2] = A[ 2] ^ t2; + A[ 7] = A[ 7] ^ t2; + A[12] = A[12] ^ t2; + A[17] = A[17] ^ t2; + A[22] = A[22] ^ t2; + A[ 3] = A[ 3] ^ t3; + A[ 8] = A[ 8] ^ t3; + A[13] = A[13] ^ t3; + A[18] = A[18] ^ t3; + A[23] = A[23] ^ t3; + A[ 4] = A[ 4] ^ t4; + A[ 9] = A[ 9] ^ t4; + A[14] = A[14] ^ t4; + A[19] = A[19] ^ t4; + A[24] = A[24] ^ t4; + A[ 5] = (A[ 5] << 36) | (A[ 5] >> (64 - 36)); + A[10] = (A[10] << 3) | (A[10] >> (64 - 3)); + A[15] = (A[15] << 41) | (A[15] >> (64 - 41)); + A[20] = (A[20] << 18) | (A[20] >> (64 - 18)); + A[ 1] = (A[ 1] << 1) | (A[ 1] >> (64 - 1)); + A[ 6] = (A[ 6] << 44) | (A[ 6] >> (64 - 44)); + A[11] = (A[11] << 10) | (A[11] >> (64 - 10)); + A[16] = (A[16] << 45) | (A[16] >> (64 - 45)); + A[21] = (A[21] << 2) | (A[21] >> (64 - 2)); + A[ 2] = (A[ 2] << 62) | (A[ 2] >> (64 - 62)); + A[ 7] = (A[ 7] << 6) | (A[ 7] >> (64 - 6)); + A[12] = (A[12] << 43) | (A[12] >> (64 - 43)); + A[17] = (A[17] << 15) | (A[17] >> (64 - 15)); + A[22] = (A[22] << 61) | (A[22] >> (64 - 61)); + A[ 3] = (A[ 3] << 28) | (A[ 3] >> (64 - 28)); + A[ 8] = (A[ 8] << 55) | (A[ 8] >> (64 - 55)); + A[13] = (A[13] << 25) | (A[13] >> (64 - 25)); + A[18] = (A[18] << 21) | (A[18] >> (64 - 21)); + A[23] = (A[23] << 56) | (A[23] >> (64 - 56)); + A[ 4] = (A[ 4] << 27) | (A[ 4] >> (64 - 27)); + A[ 9] = (A[ 9] << 20) | (A[ 9] >> (64 - 20)); + A[14] = (A[14] << 39) | (A[14] >> (64 - 39)); + A[19] = (A[19] << 8) | (A[19] >> (64 - 8)); + A[24] = (A[24] << 14) | (A[24] >> (64 - 14)); + bnn = ~A[12]; + kt = A[ 6] | A[12]; + c0 = A[ 0] ^ kt; + kt = bnn | A[18]; + c1 = A[ 6] ^ kt; + kt = A[18] & A[24]; + c2 = A[12] ^ kt; + kt = A[24] | A[ 0]; + c3 = A[18] ^ kt; + kt = A[ 0] & A[ 6]; + c4 = A[24] ^ kt; + A[ 0] = c0; + A[ 6] = c1; + A[12] = c2; + A[18] = c3; + A[24] = c4; + bnn = ~A[22]; + kt = A[ 9] | A[10]; + c0 = A[ 3] ^ kt; + kt = A[10] & A[16]; + c1 = A[ 9] ^ kt; + kt = A[16] | bnn; + c2 = A[10] ^ kt; + kt = A[22] | A[ 3]; + c3 = A[16] ^ kt; + kt = A[ 3] & A[ 9]; + c4 = A[22] ^ kt; + A[ 3] = c0; + A[ 9] = c1; + A[10] = c2; + A[16] = c3; + A[22] = c4; + bnn = ~A[19]; + kt = A[ 7] | A[13]; + c0 = A[ 1] ^ kt; + kt = A[13] & A[19]; + c1 = A[ 7] ^ kt; + kt = bnn & A[20]; + c2 = A[13] ^ kt; + kt = A[20] | A[ 1]; + c3 = bnn ^ kt; + kt = A[ 1] & A[ 7]; + c4 = A[20] ^ kt; + A[ 1] = c0; + A[ 7] = c1; + A[13] = c2; + A[19] = c3; + A[20] = c4; + bnn = ~A[17]; + kt = A[ 5] & A[11]; + c0 = A[ 4] ^ kt; + kt = A[11] | A[17]; + c1 = A[ 5] ^ kt; + kt = bnn | A[23]; + c2 = A[11] ^ kt; + kt = A[23] & A[ 4]; + c3 = bnn ^ kt; + kt = A[ 4] | A[ 5]; + c4 = A[23] ^ kt; + A[ 4] = c0; + A[ 5] = c1; + A[11] = c2; + A[17] = c3; + A[23] = c4; + bnn = ~A[ 8]; + kt = bnn & A[14]; + c0 = A[ 2] ^ kt; + kt = A[14] | A[15]; + c1 = bnn ^ kt; + kt = A[15] & A[21]; + c2 = A[14] ^ kt; + kt = A[21] | A[ 2]; + c3 = A[15] ^ kt; + kt = A[ 2] & A[ 8]; + c4 = A[21] ^ kt; + A[ 2] = c0; + A[ 8] = c1; + A[14] = c2; + A[15] = c3; + A[21] = c4; + A[ 0] = A[ 0] ^ RC[j + 0]; + + tt0 = A[ 6] ^ A[ 9]; + tt1 = A[ 7] ^ A[ 5]; + tt0 ^= A[ 8] ^ tt1; + tt0 = (tt0 << 1) | (tt0 >> 63); + tt2 = A[24] ^ A[22]; + tt3 = A[20] ^ A[23]; + tt0 ^= A[21]; + tt2 ^= tt3; + t0 = tt0 ^ tt2; + + tt0 = A[12] ^ A[10]; + tt1 = A[13] ^ A[11]; + tt0 ^= A[14] ^ tt1; + tt0 = (tt0 << 1) | (tt0 >> 63); + tt2 = A[ 0] ^ A[ 3]; + tt3 = A[ 1] ^ A[ 4]; + tt0 ^= A[ 2]; + tt2 ^= tt3; + t1 = tt0 ^ tt2; + + tt0 = A[18] ^ A[16]; + tt1 = A[19] ^ A[17]; + tt0 ^= A[15] ^ tt1; + tt0 = (tt0 << 1) | (tt0 >> 63); + tt2 = A[ 6] ^ A[ 9]; + tt3 = A[ 7] ^ A[ 5]; + tt0 ^= A[ 8]; + tt2 ^= tt3; + t2 = tt0 ^ tt2; + + tt0 = A[24] ^ A[22]; + tt1 = A[20] ^ A[23]; + tt0 ^= A[21] ^ tt1; + tt0 = (tt0 << 1) | (tt0 >> 63); + tt2 = A[12] ^ A[10]; + tt3 = A[13] ^ A[11]; + tt0 ^= A[14]; + tt2 ^= tt3; + t3 = tt0 ^ tt2; + + tt0 = A[ 0] ^ A[ 3]; + tt1 = A[ 1] ^ A[ 4]; + tt0 ^= A[ 2] ^ tt1; + tt0 = (tt0 << 1) | (tt0 >> 63); + tt2 = A[18] ^ A[16]; + tt3 = A[19] ^ A[17]; + tt0 ^= A[15]; + tt2 ^= tt3; + t4 = tt0 ^ tt2; + + A[ 0] = A[ 0] ^ t0; + A[ 3] = A[ 3] ^ t0; + A[ 1] = A[ 1] ^ t0; + A[ 4] = A[ 4] ^ t0; + A[ 2] = A[ 2] ^ t0; + A[ 6] = A[ 6] ^ t1; + A[ 9] = A[ 9] ^ t1; + A[ 7] = A[ 7] ^ t1; + A[ 5] = A[ 5] ^ t1; + A[ 8] = A[ 8] ^ t1; + A[12] = A[12] ^ t2; + A[10] = A[10] ^ t2; + A[13] = A[13] ^ t2; + A[11] = A[11] ^ t2; + A[14] = A[14] ^ t2; + A[18] = A[18] ^ t3; + A[16] = A[16] ^ t3; + A[19] = A[19] ^ t3; + A[17] = A[17] ^ t3; + A[15] = A[15] ^ t3; + A[24] = A[24] ^ t4; + A[22] = A[22] ^ t4; + A[20] = A[20] ^ t4; + A[23] = A[23] ^ t4; + A[21] = A[21] ^ t4; + A[ 3] = (A[ 3] << 36) | (A[ 3] >> (64 - 36)); + A[ 1] = (A[ 1] << 3) | (A[ 1] >> (64 - 3)); + A[ 4] = (A[ 4] << 41) | (A[ 4] >> (64 - 41)); + A[ 2] = (A[ 2] << 18) | (A[ 2] >> (64 - 18)); + A[ 6] = (A[ 6] << 1) | (A[ 6] >> (64 - 1)); + A[ 9] = (A[ 9] << 44) | (A[ 9] >> (64 - 44)); + A[ 7] = (A[ 7] << 10) | (A[ 7] >> (64 - 10)); + A[ 5] = (A[ 5] << 45) | (A[ 5] >> (64 - 45)); + A[ 8] = (A[ 8] << 2) | (A[ 8] >> (64 - 2)); + A[12] = (A[12] << 62) | (A[12] >> (64 - 62)); + A[10] = (A[10] << 6) | (A[10] >> (64 - 6)); + A[13] = (A[13] << 43) | (A[13] >> (64 - 43)); + A[11] = (A[11] << 15) | (A[11] >> (64 - 15)); + A[14] = (A[14] << 61) | (A[14] >> (64 - 61)); + A[18] = (A[18] << 28) | (A[18] >> (64 - 28)); + A[16] = (A[16] << 55) | (A[16] >> (64 - 55)); + A[19] = (A[19] << 25) | (A[19] >> (64 - 25)); + A[17] = (A[17] << 21) | (A[17] >> (64 - 21)); + A[15] = (A[15] << 56) | (A[15] >> (64 - 56)); + A[24] = (A[24] << 27) | (A[24] >> (64 - 27)); + A[22] = (A[22] << 20) | (A[22] >> (64 - 20)); + A[20] = (A[20] << 39) | (A[20] >> (64 - 39)); + A[23] = (A[23] << 8) | (A[23] >> (64 - 8)); + A[21] = (A[21] << 14) | (A[21] >> (64 - 14)); + bnn = ~A[13]; + kt = A[ 9] | A[13]; + c0 = A[ 0] ^ kt; + kt = bnn | A[17]; + c1 = A[ 9] ^ kt; + kt = A[17] & A[21]; + c2 = A[13] ^ kt; + kt = A[21] | A[ 0]; + c3 = A[17] ^ kt; + kt = A[ 0] & A[ 9]; + c4 = A[21] ^ kt; + A[ 0] = c0; + A[ 9] = c1; + A[13] = c2; + A[17] = c3; + A[21] = c4; + bnn = ~A[14]; + kt = A[22] | A[ 1]; + c0 = A[18] ^ kt; + kt = A[ 1] & A[ 5]; + c1 = A[22] ^ kt; + kt = A[ 5] | bnn; + c2 = A[ 1] ^ kt; + kt = A[14] | A[18]; + c3 = A[ 5] ^ kt; + kt = A[18] & A[22]; + c4 = A[14] ^ kt; + A[18] = c0; + A[22] = c1; + A[ 1] = c2; + A[ 5] = c3; + A[14] = c4; + bnn = ~A[23]; + kt = A[10] | A[19]; + c0 = A[ 6] ^ kt; + kt = A[19] & A[23]; + c1 = A[10] ^ kt; + kt = bnn & A[ 2]; + c2 = A[19] ^ kt; + kt = A[ 2] | A[ 6]; + c3 = bnn ^ kt; + kt = A[ 6] & A[10]; + c4 = A[ 2] ^ kt; + A[ 6] = c0; + A[10] = c1; + A[19] = c2; + A[23] = c3; + A[ 2] = c4; + bnn = ~A[11]; + kt = A[ 3] & A[ 7]; + c0 = A[24] ^ kt; + kt = A[ 7] | A[11]; + c1 = A[ 3] ^ kt; + kt = bnn | A[15]; + c2 = A[ 7] ^ kt; + kt = A[15] & A[24]; + c3 = bnn ^ kt; + kt = A[24] | A[ 3]; + c4 = A[15] ^ kt; + A[24] = c0; + A[ 3] = c1; + A[ 7] = c2; + A[11] = c3; + A[15] = c4; + bnn = ~A[16]; + kt = bnn & A[20]; + c0 = A[12] ^ kt; + kt = A[20] | A[ 4]; + c1 = bnn ^ kt; + kt = A[ 4] & A[ 8]; + c2 = A[20] ^ kt; + kt = A[ 8] | A[12]; + c3 = A[ 4] ^ kt; + kt = A[12] & A[16]; + c4 = A[ 8] ^ kt; + A[12] = c0; + A[16] = c1; + A[20] = c2; + A[ 4] = c3; + A[ 8] = c4; + A[ 0] = A[ 0] ^ RC[j + 1]; + t = A[ 5]; + A[ 5] = A[18]; + A[18] = A[11]; + A[11] = A[10]; + A[10] = A[ 6]; + A[ 6] = A[22]; + A[22] = A[20]; + A[20] = A[12]; + A[12] = A[19]; + A[19] = A[15]; + A[15] = A[24]; + A[24] = A[ 8]; + A[ 8] = t; + t = A[ 1]; + A[ 1] = A[ 9]; + A[ 9] = A[14]; + A[14] = A[ 2]; + A[ 2] = A[13]; + A[13] = A[23]; + A[23] = A[ 4]; + A[ 4] = A[21]; + A[21] = A[16]; + A[16] = A[ 3]; + A[ 3] = A[17]; + A[17] = A[ 7]; + A[ 7] = t; + } +} + +/* see bearssl_kdf.h */ +void +br_shake_init(br_shake_context *sc, int security_level) +{ + sc->rate = 200 - (size_t)(security_level >> 2); + sc->dptr = 0; + memset(sc->A, 0, sizeof sc->A); + sc->A[ 1] = ~(uint64_t)0; + sc->A[ 2] = ~(uint64_t)0; + sc->A[ 8] = ~(uint64_t)0; + sc->A[12] = ~(uint64_t)0; + sc->A[17] = ~(uint64_t)0; + sc->A[20] = ~(uint64_t)0; +} + +/* see bearssl_kdf.h */ +void +br_shake_inject(br_shake_context *sc, const void *data, size_t len) +{ + const unsigned char *buf; + size_t rate, dptr; + + buf = data; + rate = sc->rate; + dptr = sc->dptr; + while (len > 0) { + size_t clen; + + clen = rate - dptr; + if (clen > len) { + clen = len; + } + memcpy(sc->dbuf + dptr, buf, clen); + dptr += clen; + buf += clen; + len -= clen; + if (dptr == rate) { + xor_block(sc->A, sc->dbuf, rate); + process_block(sc->A); + dptr = 0; + } + } + sc->dptr = dptr; +} + +/* see bearssl_kdf.h */ +void +br_shake_flip(br_shake_context *sc) +{ + /* + * We apply padding and pre-XOR the value into the state. We + * set dptr to the end of the buffer, so that first call to + * shake_extract() will process the block. + */ + if ((sc->dptr + 1) == sc->rate) { + sc->dbuf[sc->dptr ++] = 0x9F; + } else { + sc->dbuf[sc->dptr ++] = 0x1F; + memset(sc->dbuf + sc->dptr, 0x00, sc->rate - sc->dptr - 1); + sc->dbuf[sc->rate - 1] = 0x80; + sc->dptr = sc->rate; + } + xor_block(sc->A, sc->dbuf, sc->rate); +} + +/* see bearssl_kdf.h */ +void +br_shake_produce(br_shake_context *sc, void *out, size_t len) +{ + unsigned char *buf; + size_t dptr, rate; + + buf = out; + dptr = sc->dptr; + rate = sc->rate; + while (len > 0) { + size_t clen; + + if (dptr == rate) { + unsigned char *dbuf; + uint64_t *A; + + A = sc->A; + dbuf = sc->dbuf; + process_block(A); + br_enc64le(dbuf + 0, A[ 0]); + br_enc64le(dbuf + 8, ~A[ 1]); + br_enc64le(dbuf + 16, ~A[ 2]); + br_enc64le(dbuf + 24, A[ 3]); + br_enc64le(dbuf + 32, A[ 4]); + br_enc64le(dbuf + 40, A[ 5]); + br_enc64le(dbuf + 48, A[ 6]); + br_enc64le(dbuf + 56, A[ 7]); + br_enc64le(dbuf + 64, ~A[ 8]); + br_enc64le(dbuf + 72, A[ 9]); + br_enc64le(dbuf + 80, A[10]); + br_enc64le(dbuf + 88, A[11]); + br_enc64le(dbuf + 96, ~A[12]); + br_enc64le(dbuf + 104, A[13]); + br_enc64le(dbuf + 112, A[14]); + br_enc64le(dbuf + 120, A[15]); + br_enc64le(dbuf + 128, A[16]); + br_enc64le(dbuf + 136, ~A[17]); + br_enc64le(dbuf + 144, A[18]); + br_enc64le(dbuf + 152, A[19]); + br_enc64le(dbuf + 160, ~A[20]); + br_enc64le(dbuf + 168, A[21]); + br_enc64le(dbuf + 176, A[22]); + br_enc64le(dbuf + 184, A[23]); + br_enc64le(dbuf + 192, A[24]); + dptr = 0; + } + clen = rate - dptr; + if (clen > len) { + clen = len; + } + memcpy(buf, sc->dbuf + dptr, clen); + dptr += clen; + buf += clen; + len -= clen; + } + sc->dptr = dptr; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/skey_decoder.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/skey_decoder.c new file mode 100644 index 000000000..e5bad0107 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/skey_decoder.c @@ -0,0 +1,649 @@ +/* Automatically generated code; do not modify directly. */ + + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include +#include + +typedef struct { + uint32_t *dp; + uint32_t *rp; + const unsigned char *ip; +} t0_context; + +static uint32_t +t0_parse7E_unsigned(const unsigned char **p) +{ + uint32_t x; + + x = 0; + for (;;) { + unsigned y; + + y = *(*p) ++; + x = (x << 7) | (uint32_t)(y & 0x7F); + if (y < 0x80) { + return x; + } + } +} + +static int32_t +t0_parse7E_signed(const unsigned char **p) +{ + int neg; + uint32_t x; + + neg = ((**p) >> 6) & 1; + x = (uint32_t)-neg; + for (;;) { + unsigned y; + + y = *(*p) ++; + x = (x << 7) | (uint32_t)(y & 0x7F); + if (y < 0x80) { + if (neg) { + return -(int32_t)~x - 1; + } else { + return (int32_t)x; + } + } + } +} + +#define T0_VBYTE(x, n) (unsigned char)((((uint32_t)(x) >> (n)) & 0x7F) | 0x80) +#define T0_FBYTE(x, n) (unsigned char)(((uint32_t)(x) >> (n)) & 0x7F) +#define T0_SBYTE(x) (unsigned char)((((uint32_t)(x) >> 28) + 0xF8) ^ 0xF8) +#define T0_INT1(x) T0_FBYTE(x, 0) +#define T0_INT2(x) T0_VBYTE(x, 7), T0_FBYTE(x, 0) +#define T0_INT3(x) T0_VBYTE(x, 14), T0_VBYTE(x, 7), T0_FBYTE(x, 0) +#define T0_INT4(x) T0_VBYTE(x, 21), T0_VBYTE(x, 14), T0_VBYTE(x, 7), T0_FBYTE(x, 0) +#define T0_INT5(x) T0_SBYTE(x), T0_VBYTE(x, 21), T0_VBYTE(x, 14), T0_VBYTE(x, 7), T0_FBYTE(x, 0) + +/* static const unsigned char t0_datablock[]; */ + + +void br_skey_decoder_init_main(void *t0ctx); + +void br_skey_decoder_run(void *t0ctx); + + +#include "inner.h" + +#define CTX ((br_skey_decoder_context *)(void *)((unsigned char *)t0ctx - offsetof(br_skey_decoder_context, cpu))) +#define CONTEXT_NAME br_skey_decoder_context + +/* see bearssl_x509.h */ +void +br_skey_decoder_init(br_skey_decoder_context *ctx) +{ + memset(ctx, 0, sizeof *ctx); + ctx->cpu.dp = &ctx->dp_stack[0]; + ctx->cpu.rp = &ctx->rp_stack[0]; + br_skey_decoder_init_main(&ctx->cpu); + br_skey_decoder_run(&ctx->cpu); +} + +/* see bearssl_x509.h */ +void +br_skey_decoder_push(br_skey_decoder_context *ctx, + const void *data, size_t len) +{ + ctx->hbuf = data; + ctx->hlen = len; + br_skey_decoder_run(&ctx->cpu); +} + + + +static const unsigned char t0_datablock[] = { + 0x00, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, 0x07, + 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x02, 0x01, 0x08, 0x2A, 0x86, 0x48, 0xCE, + 0x3D, 0x03, 0x01, 0x07, 0x05, 0x2B, 0x81, 0x04, 0x00, 0x22, 0x05, 0x2B, + 0x81, 0x04, 0x00, 0x23 +}; + +static const unsigned char t0_codeblock[] = { + 0x00, 0x01, 0x01, 0x07, 0x00, 0x00, 0x01, 0x01, 0x08, 0x00, 0x00, 0x13, + 0x13, 0x00, 0x00, 0x01, T0_INT1(BR_ERR_X509_BAD_TAG_CLASS), 0x00, 0x00, + 0x01, T0_INT1(BR_ERR_X509_BAD_TAG_VALUE), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_X509_EXTRA_ELEMENT), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_X509_INDEFINITE_LENGTH), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_X509_INNER_TRUNC), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_X509_INVALID_VALUE), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_X509_LIMIT_EXCEEDED), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_X509_NOT_CONSTRUCTED), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_X509_NOT_PRIMITIVE), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_X509_OVERFLOW), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_X509_UNEXPECTED), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_X509_UNSUPPORTED), 0x00, 0x00, 0x01, + T0_INT1(BR_KEYTYPE_EC), 0x00, 0x00, 0x01, T0_INT1(BR_KEYTYPE_RSA), + 0x00, 0x00, 0x01, T0_INT2(offsetof(CONTEXT_NAME, key_data)), 0x00, + 0x00, 0x01, T0_INT2(offsetof(CONTEXT_NAME, key_type)), 0x00, 0x00, + 0x33, 0x48, 0x00, 0x00, 0x01, T0_INT2(offsetof(CONTEXT_NAME, pad)), + 0x00, 0x00, 0x01, 0x13, 0x00, 0x00, 0x01, 0x1C, 0x00, 0x00, 0x01, 0x22, + 0x00, 0x00, 0x05, 0x02, 0x2C, 0x16, 0x00, 0x00, 0x06, 0x02, 0x2D, 0x16, + 0x00, 0x00, 0x01, 0x10, 0x3D, 0x00, 0x00, 0x0D, 0x05, 0x02, 0x2F, 0x16, + 0x3A, 0x00, 0x00, 0x0D, 0x05, 0x02, 0x2F, 0x16, 0x3B, 0x00, 0x00, 0x06, + 0x02, 0x27, 0x16, 0x00, 0x01, 0x03, 0x00, 0x54, 0x57, 0x01, 0x02, 0x3E, + 0x55, 0x23, 0x06, 0x02, 0x30, 0x16, 0x57, 0x01, 0x04, 0x3E, 0x02, 0x00, + 0x41, 0x3F, 0x00, 0x02, 0x03, 0x00, 0x53, 0x14, 0x14, 0x03, 0x01, 0x48, + 0x0E, 0x06, 0x02, 0x30, 0x16, 0x33, 0x4C, 0x58, 0x01, 0x7F, 0x19, 0x0D, + 0x06, 0x04, 0x13, 0x13, 0x04, 0x29, 0x01, 0x20, 0x19, 0x0D, 0x06, 0x16, + 0x13, 0x3A, 0x53, 0x4D, 0x02, 0x00, 0x06, 0x09, 0x02, 0x00, 0x0C, 0x06, + 0x02, 0x2A, 0x16, 0x04, 0x02, 0x03, 0x00, 0x3F, 0x04, 0x0D, 0x01, 0x21, + 0x19, 0x0D, 0x06, 0x04, 0x13, 0x3A, 0x04, 0x03, 0x30, 0x16, 0x13, 0x5D, + 0x02, 0x00, 0x05, 0x02, 0x30, 0x16, 0x02, 0x00, 0x02, 0x01, 0x1D, 0x00, + 0x02, 0x53, 0x4B, 0x05, 0x02, 0x30, 0x16, 0x5B, 0x15, 0x06, 0x07, 0x5D, + 0x01, 0x7F, 0x03, 0x01, 0x04, 0x16, 0x46, 0x15, 0x06, 0x10, 0x01, 0x00, + 0x03, 0x01, 0x14, 0x06, 0x03, 0x4D, 0x04, 0x02, 0x01, 0x00, 0x03, 0x00, + 0x04, 0x02, 0x30, 0x16, 0x3F, 0x57, 0x01, 0x04, 0x3E, 0x53, 0x02, 0x01, + 0x06, 0x03, 0x43, 0x04, 0x03, 0x02, 0x00, 0x40, 0x3F, 0x5D, 0x02, 0x01, + 0x06, 0x03, 0x32, 0x04, 0x01, 0x31, 0x00, 0x00, 0x54, 0x57, 0x01, 0x02, + 0x3E, 0x55, 0x06, 0x02, 0x30, 0x16, 0x57, 0x01, 0x02, 0x3E, 0x44, 0x3F, + 0x00, 0x07, 0x35, 0x50, 0x14, 0x05, 0x02, 0x2F, 0x16, 0x23, 0x01, 0x03, + 0x0B, 0x33, 0x17, 0x47, 0x07, 0x03, 0x00, 0x4F, 0x4F, 0x35, 0x4E, 0x14, + 0x14, 0x03, 0x01, 0x03, 0x02, 0x51, 0x14, 0x03, 0x03, 0x02, 0x02, 0x07, + 0x14, 0x03, 0x02, 0x51, 0x14, 0x03, 0x04, 0x02, 0x02, 0x07, 0x14, 0x03, + 0x02, 0x51, 0x14, 0x03, 0x05, 0x02, 0x02, 0x07, 0x14, 0x03, 0x02, 0x51, + 0x03, 0x06, 0x02, 0x00, 0x02, 0x01, 0x02, 0x03, 0x02, 0x04, 0x02, 0x05, + 0x02, 0x06, 0x1E, 0x00, 0x00, 0x19, 0x19, 0x00, 0x00, 0x01, 0x0B, 0x00, + 0x00, 0x01, 0x00, 0x20, 0x14, 0x06, 0x08, 0x01, 0x01, 0x21, 0x20, 0x22, + 0x20, 0x04, 0x75, 0x13, 0x00, 0x00, 0x01, + T0_INT2(3 * BR_X509_BUFSIZE_SIG), 0x00, 0x01, 0x01, 0x87, 0xFF, 0xFF, + 0x7F, 0x54, 0x57, 0x01, 0x02, 0x3E, 0x55, 0x01, 0x01, 0x0E, 0x06, 0x02, + 0x30, 0x16, 0x57, 0x01, 0x02, 0x19, 0x0D, 0x06, 0x06, 0x13, 0x3B, 0x44, + 0x32, 0x04, 0x1C, 0x01, 0x04, 0x19, 0x0D, 0x06, 0x08, 0x13, 0x3B, 0x01, + 0x00, 0x41, 0x31, 0x04, 0x0E, 0x01, 0x10, 0x19, 0x0D, 0x06, 0x05, 0x13, + 0x3A, 0x42, 0x04, 0x03, 0x30, 0x16, 0x13, 0x03, 0x00, 0x3F, 0x02, 0x00, + 0x34, 0x1F, 0x5A, 0x27, 0x16, 0x00, 0x01, 0x45, 0x0A, 0x06, 0x02, 0x29, + 0x16, 0x14, 0x03, 0x00, 0x08, 0x02, 0x00, 0x00, 0x00, 0x57, 0x01, 0x06, + 0x3E, 0x56, 0x00, 0x00, 0x20, 0x14, 0x06, 0x07, 0x1A, 0x14, 0x06, 0x01, + 0x12, 0x04, 0x76, 0x24, 0x00, 0x00, 0x4B, 0x05, 0x02, 0x30, 0x16, 0x37, + 0x15, 0x06, 0x04, 0x01, 0x17, 0x04, 0x12, 0x38, 0x15, 0x06, 0x04, 0x01, + 0x18, 0x04, 0x0A, 0x39, 0x15, 0x06, 0x04, 0x01, 0x19, 0x04, 0x02, 0x30, + 0x16, 0x00, 0x00, 0x1C, 0x57, 0x01, 0x02, 0x3E, 0x09, 0x50, 0x00, 0x00, + 0x35, 0x4E, 0x13, 0x00, 0x03, 0x14, 0x03, 0x00, 0x03, 0x01, 0x03, 0x02, + 0x53, 0x59, 0x14, 0x01, 0x81, 0x00, 0x0F, 0x06, 0x02, 0x2E, 0x16, 0x14, + 0x01, 0x00, 0x0D, 0x06, 0x0B, 0x13, 0x14, 0x05, 0x04, 0x13, 0x01, 0x00, + 0x00, 0x59, 0x04, 0x6F, 0x02, 0x01, 0x14, 0x05, 0x02, 0x2B, 0x16, 0x23, + 0x03, 0x01, 0x02, 0x02, 0x1F, 0x02, 0x02, 0x22, 0x03, 0x02, 0x14, 0x06, + 0x03, 0x59, 0x04, 0x68, 0x13, 0x02, 0x00, 0x02, 0x01, 0x08, 0x00, 0x00, + 0x14, 0x35, 0x1C, 0x08, 0x20, 0x1C, 0x07, 0x20, 0x4E, 0x00, 0x01, 0x59, + 0x14, 0x01, 0x81, 0x00, 0x0A, 0x06, 0x01, 0x00, 0x01, 0x81, 0x00, 0x08, + 0x14, 0x05, 0x02, 0x28, 0x16, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, + 0x00, 0x0E, 0x06, 0x19, 0x02, 0x00, 0x23, 0x03, 0x00, 0x14, 0x01, 0x83, + 0xFF, 0xFF, 0x7F, 0x0E, 0x06, 0x02, 0x29, 0x16, 0x01, 0x08, 0x0B, 0x20, + 0x59, 0x1C, 0x07, 0x04, 0x60, 0x00, 0x00, 0x52, 0x4A, 0x00, 0x00, 0x57, + 0x3C, 0x53, 0x00, 0x01, 0x53, 0x14, 0x05, 0x02, 0x2E, 0x16, 0x59, 0x14, + 0x01, 0x81, 0x00, 0x0F, 0x06, 0x02, 0x2E, 0x16, 0x03, 0x00, 0x14, 0x06, + 0x16, 0x59, 0x02, 0x00, 0x14, 0x01, 0x87, 0xFF, 0xFF, 0x7F, 0x0F, 0x06, + 0x02, 0x2E, 0x16, 0x01, 0x08, 0x0B, 0x07, 0x03, 0x00, 0x04, 0x67, 0x13, + 0x02, 0x00, 0x00, 0x00, 0x53, 0x14, 0x01, 0x81, 0x7F, 0x0E, 0x06, 0x08, + 0x5C, 0x01, 0x00, 0x36, 0x1F, 0x01, 0x00, 0x00, 0x14, 0x36, 0x1F, 0x36, + 0x22, 0x4C, 0x01, 0x7F, 0x00, 0x01, 0x59, 0x03, 0x00, 0x02, 0x00, 0x01, + 0x05, 0x10, 0x01, 0x01, 0x11, 0x18, 0x02, 0x00, 0x01, 0x06, 0x10, 0x14, + 0x01, 0x01, 0x11, 0x06, 0x02, 0x25, 0x16, 0x01, 0x04, 0x0B, 0x02, 0x00, + 0x01, 0x1F, 0x11, 0x14, 0x01, 0x1F, 0x0D, 0x06, 0x02, 0x26, 0x16, 0x07, + 0x00, 0x00, 0x14, 0x05, 0x05, 0x01, 0x00, 0x01, 0x7F, 0x00, 0x57, 0x00, + 0x00, 0x14, 0x05, 0x02, 0x29, 0x16, 0x23, 0x5A, 0x00, 0x00, 0x1B, 0x14, + 0x01, 0x00, 0x0F, 0x06, 0x01, 0x00, 0x13, 0x12, 0x04, 0x74, 0x00, 0x01, + 0x01, 0x00, 0x00, 0x5D, 0x13, 0x00, 0x00, 0x14, 0x06, 0x07, 0x5E, 0x14, + 0x06, 0x01, 0x12, 0x04, 0x76, 0x00, 0x00, 0x01, 0x00, 0x19, 0x1A, 0x09, + 0x24, 0x00 +}; + +static const uint16_t t0_caddr[] = { + 0, + 5, + 10, + 14, + 18, + 22, + 26, + 30, + 34, + 38, + 42, + 46, + 50, + 54, + 58, + 62, + 66, + 70, + 75, + 80, + 84, + 89, + 93, + 97, + 101, + 107, + 113, + 118, + 126, + 134, + 140, + 163, + 244, + 311, + 329, + 404, + 408, + 412, + 429, + 434, + 505, + 519, + 526, + 540, + 573, + 582, + 587, + 654, + 665, + 721, + 725, + 730, + 778, + 804, + 848, + 859, + 868, + 881, + 885, + 889, + 901 +}; + +#define T0_INTERPRETED 34 + +#define T0_ENTER(ip, rp, slot) do { \ + const unsigned char *t0_newip; \ + uint32_t t0_lnum; \ + t0_newip = &t0_codeblock[t0_caddr[(slot) - T0_INTERPRETED]]; \ + t0_lnum = t0_parse7E_unsigned(&t0_newip); \ + (rp) += t0_lnum; \ + *((rp) ++) = (uint32_t)((ip) - &t0_codeblock[0]) + (t0_lnum << 16); \ + (ip) = t0_newip; \ + } while (0) + +#define T0_DEFENTRY(name, slot) \ +void \ +name(void *ctx) \ +{ \ + t0_context *t0ctx = ctx; \ + t0ctx->ip = &t0_codeblock[0]; \ + T0_ENTER(t0ctx->ip, t0ctx->rp, slot); \ +} + +T0_DEFENTRY(br_skey_decoder_init_main, 73) + +#define T0_NEXT(t0ipp) (*(*(t0ipp)) ++) + +void +br_skey_decoder_run(void *t0ctx) +{ + uint32_t *dp, *rp; + const unsigned char *ip; + +#define T0_LOCAL(x) (*(rp - 2 - (x))) +#define T0_POP() (*-- dp) +#define T0_POPi() (*(int32_t *)(-- dp)) +#define T0_PEEK(x) (*(dp - 1 - (x))) +#define T0_PEEKi(x) (*(int32_t *)(dp - 1 - (x))) +#define T0_PUSH(v) do { *dp = (v); dp ++; } while (0) +#define T0_PUSHi(v) do { *(int32_t *)dp = (v); dp ++; } while (0) +#define T0_RPOP() (*-- rp) +#define T0_RPOPi() (*(int32_t *)(-- rp)) +#define T0_RPUSH(v) do { *rp = (v); rp ++; } while (0) +#define T0_RPUSHi(v) do { *(int32_t *)rp = (v); rp ++; } while (0) +#define T0_ROLL(x) do { \ + size_t t0len = (size_t)(x); \ + uint32_t t0tmp = *(dp - 1 - t0len); \ + memmove(dp - t0len - 1, dp - t0len, t0len * sizeof *dp); \ + *(dp - 1) = t0tmp; \ +} while (0) +#define T0_SWAP() do { \ + uint32_t t0tmp = *(dp - 2); \ + *(dp - 2) = *(dp - 1); \ + *(dp - 1) = t0tmp; \ +} while (0) +#define T0_ROT() do { \ + uint32_t t0tmp = *(dp - 3); \ + *(dp - 3) = *(dp - 2); \ + *(dp - 2) = *(dp - 1); \ + *(dp - 1) = t0tmp; \ +} while (0) +#define T0_NROT() do { \ + uint32_t t0tmp = *(dp - 1); \ + *(dp - 1) = *(dp - 2); \ + *(dp - 2) = *(dp - 3); \ + *(dp - 3) = t0tmp; \ +} while (0) +#define T0_PICK(x) do { \ + uint32_t t0depth = (x); \ + T0_PUSH(T0_PEEK(t0depth)); \ +} while (0) +#define T0_CO() do { \ + goto t0_exit; \ +} while (0) +#define T0_RET() goto t0_next + + dp = ((t0_context *)t0ctx)->dp; + rp = ((t0_context *)t0ctx)->rp; + ip = ((t0_context *)t0ctx)->ip; + goto t0_next; + for (;;) { + uint32_t t0x; + + t0_next: + t0x = T0_NEXT(&ip); + if (t0x < T0_INTERPRETED) { + switch (t0x) { + int32_t t0off; + + case 0: /* ret */ + t0x = T0_RPOP(); + rp -= (t0x >> 16); + t0x &= 0xFFFF; + if (t0x == 0) { + ip = NULL; + goto t0_exit; + } + ip = &t0_codeblock[t0x]; + break; + case 1: /* literal constant */ + T0_PUSHi(t0_parse7E_signed(&ip)); + break; + case 2: /* read local */ + T0_PUSH(T0_LOCAL(t0_parse7E_unsigned(&ip))); + break; + case 3: /* write local */ + T0_LOCAL(t0_parse7E_unsigned(&ip)) = T0_POP(); + break; + case 4: /* jump */ + t0off = t0_parse7E_signed(&ip); + ip += t0off; + break; + case 5: /* jump if */ + t0off = t0_parse7E_signed(&ip); + if (T0_POP()) { + ip += t0off; + } + break; + case 6: /* jump if not */ + t0off = t0_parse7E_signed(&ip); + if (!T0_POP()) { + ip += t0off; + } + break; + case 7: { + /* + */ + + uint32_t b = T0_POP(); + uint32_t a = T0_POP(); + T0_PUSH(a + b); + + } + break; + case 8: { + /* - */ + + uint32_t b = T0_POP(); + uint32_t a = T0_POP(); + T0_PUSH(a - b); + + } + break; + case 9: { + /* -rot */ + T0_NROT(); + } + break; + case 10: { + /* < */ + + int32_t b = T0_POPi(); + int32_t a = T0_POPi(); + T0_PUSH(-(uint32_t)(a < b)); + + } + break; + case 11: { + /* << */ + + int c = (int)T0_POPi(); + uint32_t x = T0_POP(); + T0_PUSH(x << c); + + } + break; + case 12: { + /* <> */ + + uint32_t b = T0_POP(); + uint32_t a = T0_POP(); + T0_PUSH(-(uint32_t)(a != b)); + + } + break; + case 13: { + /* = */ + + uint32_t b = T0_POP(); + uint32_t a = T0_POP(); + T0_PUSH(-(uint32_t)(a == b)); + + } + break; + case 14: { + /* > */ + + int32_t b = T0_POPi(); + int32_t a = T0_POPi(); + T0_PUSH(-(uint32_t)(a > b)); + + } + break; + case 15: { + /* >= */ + + int32_t b = T0_POPi(); + int32_t a = T0_POPi(); + T0_PUSH(-(uint32_t)(a >= b)); + + } + break; + case 16: { + /* >> */ + + int c = (int)T0_POPi(); + int32_t x = T0_POPi(); + T0_PUSHi(x >> c); + + } + break; + case 17: { + /* and */ + + uint32_t b = T0_POP(); + uint32_t a = T0_POP(); + T0_PUSH(a & b); + + } + break; + case 18: { + /* co */ + T0_CO(); + } + break; + case 19: { + /* drop */ + (void)T0_POP(); + } + break; + case 20: { + /* dup */ + T0_PUSH(T0_PEEK(0)); + } + break; + case 21: { + /* eqOID */ + + const unsigned char *a2 = &t0_datablock[T0_POP()]; + const unsigned char *a1 = &CTX->pad[0]; + size_t len = a1[0]; + int x; + if (len == a2[0]) { + x = -(memcmp(a1 + 1, a2 + 1, len) == 0); + } else { + x = 0; + } + T0_PUSH((uint32_t)x); + + } + break; + case 22: { + /* fail */ + + CTX->err = T0_POPi(); + T0_CO(); + + } + break; + case 23: { + /* get8 */ + + uint32_t addr = T0_POP(); + T0_PUSH(*((unsigned char *)CTX + addr)); + + } + break; + case 24: { + /* neg */ + + uint32_t a = T0_POP(); + T0_PUSH(-a); + + } + break; + case 25: { + /* over */ + T0_PUSH(T0_PEEK(1)); + } + break; + case 26: { + /* read-blob-inner */ + + uint32_t len = T0_POP(); + uint32_t addr = T0_POP(); + size_t clen = CTX->hlen; + if (clen > len) { + clen = (size_t)len; + } + if (addr != 0) { + memcpy((unsigned char *)CTX + addr, CTX->hbuf, clen); + } + CTX->hbuf += clen; + CTX->hlen -= clen; + T0_PUSH(addr + clen); + T0_PUSH(len - clen); + + } + break; + case 27: { + /* read8-low */ + + if (CTX->hlen == 0) { + T0_PUSHi(-1); + } else { + CTX->hlen --; + T0_PUSH(*CTX->hbuf ++); + } + + } + break; + case 28: { + /* rot */ + T0_ROT(); + } + break; + case 29: { + /* set-ec-key */ + + size_t xlen = T0_POP(); + uint32_t curve = T0_POP(); + CTX->key.ec.curve = curve; + CTX->key.ec.x = CTX->key_data; + CTX->key.ec.xlen = xlen; + + } + break; + case 30: { + /* set-rsa-key */ + + size_t iqlen = T0_POP(); + size_t dqlen = T0_POP(); + size_t dplen = T0_POP(); + size_t qlen = T0_POP(); + size_t plen = T0_POP(); + uint32_t n_bitlen = T0_POP(); + size_t off; + + CTX->key.rsa.n_bitlen = n_bitlen; + CTX->key.rsa.p = CTX->key_data; + CTX->key.rsa.plen = plen; + off = plen; + CTX->key.rsa.q = CTX->key_data + off; + CTX->key.rsa.qlen = qlen; + off += qlen; + CTX->key.rsa.dp = CTX->key_data + off; + CTX->key.rsa.dplen = dplen; + off += dplen; + CTX->key.rsa.dq = CTX->key_data + off; + CTX->key.rsa.dqlen = dqlen; + off += dqlen; + CTX->key.rsa.iq = CTX->key_data + off; + CTX->key.rsa.iqlen = iqlen; + + } + break; + case 31: { + /* set8 */ + + uint32_t addr = T0_POP(); + *((unsigned char *)CTX + addr) = (unsigned char)T0_POP(); + + } + break; + case 32: { + /* swap */ + T0_SWAP(); + } + break; + case 33: { + /* u>> */ + + int c = (int)T0_POPi(); + uint32_t x = T0_POP(); + T0_PUSH(x >> c); + + } + break; + } + + } else { + T0_ENTER(ip, rp, t0x); + } + } +t0_exit: + ((t0_context *)t0ctx)->dp = dp; + ((t0_context *)t0ctx)->rp = rp; + ((t0_context *)t0ctx)->ip = ip; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/skey_decoder.t0 b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/skey_decoder.t0 new file mode 100644 index 000000000..f00e614e2 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/skey_decoder.t0 @@ -0,0 +1,373 @@ +\ Copyright (c) 2016 Thomas Pornin +\ +\ Permission is hereby granted, free of charge, to any person obtaining +\ a copy of this software and associated documentation files (the +\ "Software"), to deal in the Software without restriction, including +\ without limitation the rights to use, copy, modify, merge, publish, +\ distribute, sublicense, and/or sell copies of the Software, and to +\ permit persons to whom the Software is furnished to do so, subject to +\ the following conditions: +\ +\ The above copyright notice and this permission notice shall be +\ included in all copies or substantial portions of the Software. +\ +\ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +\ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +\ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +\ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +\ BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +\ ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +\ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +\ SOFTWARE. + +preamble { + +#include "inner.h" + +#define CTX ((br_skey_decoder_context *)(void *)((unsigned char *)t0ctx - offsetof(br_skey_decoder_context, cpu))) +#define CONTEXT_NAME br_skey_decoder_context + +/* see bearssl_x509.h */ +void +br_skey_decoder_init(br_skey_decoder_context *ctx) +{ + memset(ctx, 0, sizeof *ctx); + ctx->cpu.dp = &ctx->dp_stack[0]; + ctx->cpu.rp = &ctx->rp_stack[0]; + br_skey_decoder_init_main(&ctx->cpu); + br_skey_decoder_run(&ctx->cpu); +} + +/* see bearssl_x509.h */ +void +br_skey_decoder_push(br_skey_decoder_context *ctx, + const void *data, size_t len) +{ + ctx->hbuf = data; + ctx->hlen = len; + br_skey_decoder_run(&ctx->cpu); +} + +} + +addr: key_type +addr: key_data + +cc: read8-low ( -- x ) { + if (CTX->hlen == 0) { + T0_PUSHi(-1); + } else { + CTX->hlen --; + T0_PUSH(*CTX->hbuf ++); + } +} + +cc: read-blob-inner ( addr len -- addr len ) { + uint32_t len = T0_POP(); + uint32_t addr = T0_POP(); + size_t clen = CTX->hlen; + if (clen > len) { + clen = (size_t)len; + } + if (addr != 0) { + memcpy((unsigned char *)CTX + addr, CTX->hbuf, clen); + } + CTX->hbuf += clen; + CTX->hlen -= clen; + T0_PUSH(addr + clen); + T0_PUSH(len - clen); +} + +\ Get the length of the key_data buffer. +: len-key_data + CX 0 8191 { 3 * BR_X509_BUFSIZE_SIG } ; + +\ Get the address and length for the key_data buffer. +: addr-len-key_data ( -- addr len ) + addr-key_data len-key_data ; + +\ Set the private key (RSA). +cc: set-rsa-key ( n_bitlen plen qlen dplen dqlen iqlen -- ) { + size_t iqlen = T0_POP(); + size_t dqlen = T0_POP(); + size_t dplen = T0_POP(); + size_t qlen = T0_POP(); + size_t plen = T0_POP(); + uint32_t n_bitlen = T0_POP(); + size_t off; + + CTX->key.rsa.n_bitlen = n_bitlen; + CTX->key.rsa.p = CTX->key_data; + CTX->key.rsa.plen = plen; + off = plen; + CTX->key.rsa.q = CTX->key_data + off; + CTX->key.rsa.qlen = qlen; + off += qlen; + CTX->key.rsa.dp = CTX->key_data + off; + CTX->key.rsa.dplen = dplen; + off += dplen; + CTX->key.rsa.dq = CTX->key_data + off; + CTX->key.rsa.dqlen = dqlen; + off += dqlen; + CTX->key.rsa.iq = CTX->key_data + off; + CTX->key.rsa.iqlen = iqlen; +} + +\ Set the private key (EC). +cc: set-ec-key ( curve xlen -- ) { + size_t xlen = T0_POP(); + uint32_t curve = T0_POP(); + CTX->key.ec.curve = curve; + CTX->key.ec.x = CTX->key_data; + CTX->key.ec.xlen = xlen; +} + +\ Get the bit length for an integer (unsigned). +: int-bit-length ( x -- bitlen ) + 0 swap + begin dup while 1 u>> swap 1+ swap repeat + drop ; + +\ Read an INTEGER into the key_data buffer, but then ignore it. +: read-integer-ignore ( lim -- lim ) + addr-len-key_data read-integer drop ; + +\ Read an INTEGER into the key_data buffer, at the provided offset. +\ Returned value is the integer length (in bytes). +: read-integer-off ( lim off -- lim dlen ) + dup addr-len-key_data rot - swap rot + swap read-integer ; + +\ Decode RSA key, starting with the SEQUENCE tag. +: decode-RSA ( lim -- lim ) + read-sequence-open + + \ Version should be 0. + read-tag 0x02 check-tag-primitive read-small-int-value if + ERR_X509_UNSUPPORTED fail + then + + \ Read tag for the modulus; should be INTEGER. Then use the + \ decode-RSA-next function for the remainder of the key. + read-tag 0x02 check-tag-primitive + decode-RSA-next + + \ Close the SEQUENCE. + close-elt ; + +\ Decode RSA key; the version, and the tag for the modulus, have been +\ read. +: decode-RSA-next ( lim -- lim ) + \ Modulus: we read it but we do not keep it; we merely gather + \ the modulus bit length. + addr-len-key_data read-integer-next + dup ifnot ERR_X509_UNEXPECTED fail then + 1- 3 << addr-key_data get8 int-bit-length + { n_bitlen } + + \ Public exponent: read but skip. + read-integer-ignore + + \ Private exponent: read but skip. + read-integer-ignore + + \ First prime factor. + addr-len-key_data read-integer dup dup { off plen } + + \ Second prime factor. + read-integer-off dup { qlen } off + dup >off + + \ First reduced private exponent. + read-integer-off dup { dplen } off + dup >off + + \ Second reduced private exponent. + read-integer-off dup { dqlen } off + dup >off + + \ CRT coefficient. + read-integer-off { iqlen } + + \ Set RSA key. + n_bitlen plen qlen dplen dqlen iqlen set-rsa-key + + \ The caller will close the sequence, thereby validating that there + \ is no extra field. + ; + +\ Decode an EC key, starting with the SEQUENCE tag. +: decode-EC ( lim curve -- lim ) + { curve } + read-sequence-open + + \ Version should be 1. + read-tag 0x02 check-tag-primitive read-small-int-value 1- if + ERR_X509_UNSUPPORTED fail + then + + \ Read tag for the private key; should be OCTET STRING. Then use the + \ decode-EC-next function for the remainder of the key. + read-tag 0x04 check-tag-primitive + curve decode-EC-next + + \ Close the SEQUENCE. + close-elt ; + +\ Decode an EC key; the version, and the tag for the OCTET STRING, have +\ already been read. The curve ID is provided (0 if unknown). +: decode-EC-next ( lim curve -- lim ) + { curve } + + \ Read the private key proper. + read-length-open-elt + dup dup { xlen } len-key_data > if ERR_X509_UNSUPPORTED fail then + addr-key_data read-blob + + \ Next element might be the curve identifier. + read-tag-or-end + case + + \ End of structure. + -1 of drop endof + + \ Curve parameters; we support only named curves. + 0x20 of + check-constructed read-length-open-elt + read-curve-ID + curve if + curve <> if ERR_X509_INVALID_VALUE fail then + else + >curve + then + close-elt + endof + + \ Public key. We ignore it. + 0x21 of check-constructed endof + + ERR_X509_UNSUPPORTED fail + endcase + skip-remaining + + \ The curve must have been defined one way or another. + curve ifnot ERR_X509_UNSUPPORTED fail then + + \ Set the EC key. + curve xlen set-ec-key + + \ The caller will close the sequence. + ; + +\ Decode a PKCS#8 object. The version and the tag for the AlgorithmIdentifier +\ structure have already been read. This function returns the key type. +: decode-PKCS8-next ( lim -- lim keytype ) + \ Decode the AlgorithmIdentifier. + read-length-open-elt + read-OID ifnot ERR_X509_UNSUPPORTED fail then + { ; is-rsa curve } + choice + rsaEncryption eqOID uf + \ RSA private key. We ignore the parameters. + skip-remaining -1 >is-rsa + enduf + id-ecPublicKey eqOID uf + \ EC private key. Parameters, if present, shall + \ identify the curve. + 0 >is-rsa + dup if read-curve-ID else 0 then >curve + enduf + + ERR_X509_UNSUPPORTED fail + endchoice + close-elt + + \ Open private key value and decode it. + read-tag 0x04 check-tag-primitive + read-length-open-elt + is-rsa if + decode-RSA + else + curve decode-EC + then + close-elt + + \ We ignore any extra field, i.e. attributes or public key. + skip-remaining + + \ Return the key type. + is-rsa if KEYTYPE_RSA else KEYTYPE_EC then + ; + +\ Decode a private key. +: main ( -- ! ) + \ RSA private key format is defined in PKCS#1 (RFC 3447): + \ RSAPrivateKey ::= SEQUENCE { + \ version INTEGER, -- 0 or 1 + \ n INTEGER, + \ e INTEGER, + \ d INTEGER, + \ p INTEGER, + \ q INTEGER, + \ dp INTEGER, + \ dq INTEGER, + \ iq INTEGER, + \ other OtherPrimeInfos OPTIONAL + \ } + \ We do not support keys with more than two primes (these have + \ version 1); thus, we expect the version field to be 0, and + \ the 'other' field to be absent. + \ + \ EC private key format is defined in RFC 5915: + \ ECPrivateKey ::= SEQUENCE { + \ version INTEGER, -- always 1 + \ privateKey OCTET STRING, + \ parameters [0] EXPLICIT OBJECT IDENTIFIER OPTIONAL, + \ publicKey [1] EXPLICIT BIT STRING OPTIONAL + \ } + \ The "parameters" might conceptually be a complex curve description + \ structure but we support only named curves. The private key + \ contents are the unsigned big-endian encoding of the key value, + \ which is exactly what we want. + \ + \ PKCS#8 (unencrypted) is: + \ OneAsymmetricKey ::= SEQUENCE { + \ version INTEGER, -- 0 or 1 + \ algorithm AlgorithmIdentifier, + \ privateKey OCTET STRING, + \ attributes [0] IMPLICIT Attributes OPTIONAL, + \ publicKey [1] IMPLICIT BIT STRING OPTIONAL + \ } + \ The 'publicKey' field is an add-on from RFC 5958 and may be + \ present only if the 'version' is v2 (i.e. has value 1). We + \ ignore it anyway. + + \ An arbitrary upper limit on the private key size. + 0xFFFFFF + + \ Open the outer SEQUENCE. + read-sequence-open + + \ All our schemas begin with a small INTEGER which is either 0 or + \ 1. We don't care which it is. + read-tag 0x02 check-tag-primitive read-small-int-value 1 > if + ERR_X509_UNSUPPORTED fail + then + + \ Get next tag: it should be either an INTEGER (RSA private key), + \ an OCTET STRING (EC private key), or a SEQUENCE (for an + \ AlgorithmIdentifier, in a PKCS#8 object). + read-tag + case + 0x02 of check-primitive decode-RSA-next KEYTYPE_RSA endof + 0x04 of check-primitive 0 decode-EC-next KEYTYPE_EC endof + 0x10 of check-constructed decode-PKCS8-next endof + ERR_X509_UNSUPPORTED fail + endcase + { key-type } + + \ Close the SEQUENCE. + close-elt + + \ Set the key type, which marks the decoding as a success. + key-type addr-key_type set8 + + \ Read one byte, then fail: if the read succeeds, then there is + \ some trailing byte. + read8-nc ERR_X509_EXTRA_ELEMENT fail + ; diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_ccert_single_ec.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_ccert_single_ec.c new file mode 100644 index 000000000..e056177e8 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_ccert_single_ec.c @@ -0,0 +1,161 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +static void +cc_none0(const br_ssl_client_certificate_class **pctx) +{ + (void)pctx; +} + +static void +cc_none1(const br_ssl_client_certificate_class **pctx, size_t len) +{ + (void)pctx; + (void)len; +} + +static void +cc_none2(const br_ssl_client_certificate_class **pctx, + const unsigned char *data, size_t len) +{ + (void)pctx; + (void)data; + (void)len; +} + +static void +cc_choose(const br_ssl_client_certificate_class **pctx, + const br_ssl_client_context *cc, uint32_t auth_types, + br_ssl_client_certificate *choices) +{ + br_ssl_client_certificate_ec_context *zc; + int x; + int scurve; + + zc = (br_ssl_client_certificate_ec_context *)pctx; + scurve = br_ssl_client_get_server_curve(cc); + + if ((zc->allowed_usages & BR_KEYTYPE_KEYX) != 0 + && scurve == zc->sk->curve) + { + int x; + + x = (zc->issuer_key_type == BR_KEYTYPE_RSA) ? 16 : 17; + if (((auth_types >> x) & 1) != 0) { + choices->auth_type = BR_AUTH_ECDH; + choices->hash_id = -1; + choices->chain = zc->chain; + choices->chain_len = zc->chain_len; + } + } + + /* + * For ECDSA authentication, we must choose an appropriate + * hash function. + */ + x = br_ssl_choose_hash((unsigned)(auth_types >> 8)); + if (x == 0 || (zc->allowed_usages & BR_KEYTYPE_SIGN) == 0) { + memset(choices, 0, sizeof *choices); + return; + } + choices->auth_type = BR_AUTH_ECDSA; + choices->hash_id = x; + choices->chain = zc->chain; + choices->chain_len = zc->chain_len; +} + +static uint32_t +cc_do_keyx(const br_ssl_client_certificate_class **pctx, + unsigned char *data, size_t *len) +{ + br_ssl_client_certificate_ec_context *zc; + uint32_t r; + size_t xoff, xlen; + + zc = (br_ssl_client_certificate_ec_context *)pctx; + r = zc->iec->mul(data, *len, zc->sk->x, zc->sk->xlen, zc->sk->curve); + xoff = zc->iec->xoff(zc->sk->curve, &xlen); + memmove(data, data + xoff, xlen); + *len = xlen; + return r; +} + +static size_t +cc_do_sign(const br_ssl_client_certificate_class **pctx, + int hash_id, size_t hv_len, unsigned char *data, size_t len) +{ + br_ssl_client_certificate_ec_context *zc; + unsigned char hv[64]; + const br_hash_class *hc; + + zc = (br_ssl_client_certificate_ec_context *)pctx; + memcpy(hv, data, hv_len); + hc = br_multihash_getimpl(zc->mhash, hash_id); + if (hc == NULL) { + return 0; + } + if (len < 139) { + return 0; + } + return zc->iecdsa(zc->iec, hc, hv, zc->sk, data); +} + +static const br_ssl_client_certificate_class ccert_vtable = { + sizeof(br_ssl_client_certificate_ec_context), + cc_none0, /* start_name_list */ + cc_none1, /* start_name */ + cc_none2, /* append_name */ + cc_none0, /* end_name */ + cc_none0, /* end_name_list */ + cc_choose, + cc_do_keyx, + cc_do_sign +}; + +/* see bearssl_ssl.h */ +void +br_ssl_client_set_single_ec(br_ssl_client_context *cc, + const br_x509_certificate *chain, size_t chain_len, + const br_ec_private_key *sk, unsigned allowed_usages, + unsigned cert_issuer_key_type, + const br_ec_impl *iec, br_ecdsa_sign iecdsa) +{ + cc->client_auth.single_ec.vtable = &ccert_vtable; + cc->client_auth.single_ec.chain = chain; + cc->client_auth.single_ec.chain_len = chain_len; + cc->client_auth.single_ec.sk = sk; + cc->client_auth.single_ec.allowed_usages = allowed_usages; + cc->client_auth.single_ec.issuer_key_type = cert_issuer_key_type; + cc->client_auth.single_ec.mhash = &cc->eng.mhash; + cc->client_auth.single_ec.iec = iec; + cc->client_auth.single_ec.iecdsa = iecdsa; + cc->client_auth_vtable = &cc->client_auth.single_ec.vtable; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_ccert_single_rsa.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_ccert_single_rsa.c new file mode 100644 index 000000000..29515c43c --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_ccert_single_rsa.c @@ -0,0 +1,154 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +static void +cc_none0(const br_ssl_client_certificate_class **pctx) +{ + (void)pctx; +} + +static void +cc_none1(const br_ssl_client_certificate_class **pctx, size_t len) +{ + (void)pctx; + (void)len; +} + +static void +cc_none2(const br_ssl_client_certificate_class **pctx, + const unsigned char *data, size_t len) +{ + (void)pctx; + (void)data; + (void)len; +} + +static void +cc_choose(const br_ssl_client_certificate_class **pctx, + const br_ssl_client_context *cc, uint32_t auth_types, + br_ssl_client_certificate *choices) +{ + br_ssl_client_certificate_rsa_context *zc; + int x; + + (void)cc; + zc = (br_ssl_client_certificate_rsa_context *)pctx; + x = br_ssl_choose_hash((unsigned)auth_types); + if (x == 0 && (auth_types & 1) == 0) { + memset(choices, 0, sizeof *choices); + } + choices->auth_type = BR_AUTH_RSA; + choices->hash_id = x; + choices->chain = zc->chain; + choices->chain_len = zc->chain_len; +} + +/* + * OID for hash functions in RSA signatures. + */ +static const unsigned char HASH_OID_SHA1[] = { + 0x05, 0x2B, 0x0E, 0x03, 0x02, 0x1A +}; + +static const unsigned char HASH_OID_SHA224[] = { + 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x04 +}; + +static const unsigned char HASH_OID_SHA256[] = { + 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01 +}; + +static const unsigned char HASH_OID_SHA384[] = { + 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02 +}; + +static const unsigned char HASH_OID_SHA512[] = { + 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03 +}; + +static const unsigned char *HASH_OID[] = { + HASH_OID_SHA1, + HASH_OID_SHA224, + HASH_OID_SHA256, + HASH_OID_SHA384, + HASH_OID_SHA512 +}; + +static size_t +cc_do_sign(const br_ssl_client_certificate_class **pctx, + int hash_id, size_t hv_len, unsigned char *data, size_t len) +{ + br_ssl_client_certificate_rsa_context *zc; + unsigned char hv[64]; + const unsigned char *hash_oid; + size_t sig_len; + + zc = (br_ssl_client_certificate_rsa_context *)pctx; + memcpy(hv, data, hv_len); + if (hash_id == 0) { + hash_oid = NULL; + } else if (hash_id >= 2 && hash_id <= 6) { + hash_oid = HASH_OID[hash_id - 2]; + } else { + return 0; + } + sig_len = (zc->sk->n_bitlen + 7) >> 3; + if (len < sig_len) { + return 0; + } + return zc->irsasign(hash_oid, hv, hv_len, zc->sk, data) ? sig_len : 0; +} + +static const br_ssl_client_certificate_class ccert_vtable = { + sizeof(br_ssl_client_certificate_rsa_context), + cc_none0, /* start_name_list */ + cc_none1, /* start_name */ + cc_none2, /* append_name */ + cc_none0, /* end_name */ + cc_none0, /* end_name_list */ + cc_choose, + 0, + cc_do_sign +}; + +/* see bearssl_ssl.h */ +void +br_ssl_client_set_single_rsa(br_ssl_client_context *cc, + const br_x509_certificate *chain, size_t chain_len, + const br_rsa_private_key *sk, br_rsa_pkcs1_sign irsasign) +{ + cc->client_auth.single_rsa.vtable = &ccert_vtable; + cc->client_auth.single_rsa.chain = chain; + cc->client_auth.single_rsa.chain_len = chain_len; + cc->client_auth.single_rsa.sk = sk; + cc->client_auth.single_rsa.irsasign = irsasign; + cc->client_auth_vtable = &cc->client_auth.single_rsa.vtable; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_client.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_client.c new file mode 100644 index 000000000..59a056c04 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_client.c @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_ssl.h */ +void +br_ssl_client_zero(br_ssl_client_context *cc) +{ + /* + * For really standard C, we should explicitly set to NULL all + * pointers, and 0 all other fields. However, on all our target + * architectures, a direct memset() will work, be faster, and + * use a lot less code. + */ + memset(cc, 0, sizeof *cc); +} + +/* see bearssl_ssl.h */ +int +br_ssl_client_reset(br_ssl_client_context *cc, + const char *server_name, int resume_session) +{ + size_t n; + + br_ssl_engine_set_buffer(&cc->eng, NULL, 0, 0); + cc->eng.version_out = cc->eng.version_min; + if (!resume_session) { + br_ssl_client_forget_session(cc); + } + if (!br_ssl_engine_init_rand(&cc->eng)) { + return 0; + } + + /* + * We always set back the "reneg" flag to 0 because we use it + * to distinguish between first handshake and renegotiation. + * Note that "renegotiation" and "session resumption" are two + * different things. + */ + cc->eng.reneg = 0; + + if (server_name == NULL) { + cc->eng.server_name[0] = 0; + } else { + n = strlen(server_name) + 1; + if (n > sizeof cc->eng.server_name) { + br_ssl_engine_fail(&cc->eng, BR_ERR_BAD_PARAM); + return 0; + } + memcpy(cc->eng.server_name, server_name, n); + } + + br_ssl_engine_hs_reset(&cc->eng, + br_ssl_hs_client_init_main, br_ssl_hs_client_run); + return br_ssl_engine_last_error(&cc->eng) == BR_ERR_OK; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_client_default_rsapub.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_client_default_rsapub.c new file mode 100644 index 000000000..6fec4b06c --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_client_default_rsapub.c @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_ssl.h */ +void +br_ssl_client_set_default_rsapub(br_ssl_client_context *cc) +{ + br_ssl_client_set_rsapub(cc, br_rsa_public_get_default()); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_client_full.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_client_full.c new file mode 100644 index 000000000..a1bf10106 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_client_full.c @@ -0,0 +1,184 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_ssl.h */ +void +br_ssl_client_init_full(br_ssl_client_context *cc, + br_x509_minimal_context *xc, + const br_x509_trust_anchor *trust_anchors, size_t trust_anchors_num) +{ + /* + * The "full" profile supports all implemented cipher suites. + * + * Rationale for suite order, from most important to least + * important rule: + * + * -- Don't use 3DES if AES or ChaCha20 is available. + * -- Try to have Forward Secrecy (ECDHE suite) if possible. + * -- When not using Forward Secrecy, ECDH key exchange is + * better than RSA key exchange (slightly more expensive on the + * client, but much cheaper on the server, and it implies smaller + * messages). + * -- ChaCha20+Poly1305 is better than AES/GCM (faster, smaller code). + * -- GCM is better than CCM and CBC. CCM is better than CBC. + * -- CCM is preferable over CCM_8 (with CCM_8, forgeries may succeed + * with probability 2^(-64)). + * -- AES-128 is preferred over AES-256 (AES-128 is already + * strong enough, and AES-256 is 40% more expensive). + */ + static const uint16_t suites[] = { + BR_TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256, + BR_TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256, + BR_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, + BR_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, + BR_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, + BR_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, + BR_TLS_ECDHE_ECDSA_WITH_AES_128_CCM, + BR_TLS_ECDHE_ECDSA_WITH_AES_256_CCM, + BR_TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8, + BR_TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8, + BR_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, + BR_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, + BR_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384, + BR_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384, + BR_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, + BR_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, + BR_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, + BR_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, + BR_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256, + BR_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256, + BR_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384, + BR_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384, + BR_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256, + BR_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256, + BR_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384, + BR_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384, + BR_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA, + BR_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA, + BR_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA, + BR_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA, + BR_TLS_RSA_WITH_AES_128_GCM_SHA256, + BR_TLS_RSA_WITH_AES_256_GCM_SHA384, + BR_TLS_RSA_WITH_AES_128_CCM, + BR_TLS_RSA_WITH_AES_256_CCM, + BR_TLS_RSA_WITH_AES_128_CCM_8, + BR_TLS_RSA_WITH_AES_256_CCM_8, + BR_TLS_RSA_WITH_AES_128_CBC_SHA256, + BR_TLS_RSA_WITH_AES_256_CBC_SHA256, + BR_TLS_RSA_WITH_AES_128_CBC_SHA, + BR_TLS_RSA_WITH_AES_256_CBC_SHA, + BR_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA, + BR_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, + BR_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA, + BR_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA, + BR_TLS_RSA_WITH_3DES_EDE_CBC_SHA + }; + + /* + * All hash functions are activated. + * Note: the X.509 validation engine will nonetheless refuse to + * validate signatures that use MD5 as hash function. + */ + static const br_hash_class *hashes[] = { + &br_md5_vtable, + &br_sha1_vtable, + &br_sha224_vtable, + &br_sha256_vtable, + &br_sha384_vtable, + &br_sha512_vtable + }; + + int id; + + /* + * Reset client context and set supported versions from TLS-1.0 + * to TLS-1.2 (inclusive). + */ + br_ssl_client_zero(cc); + br_ssl_engine_set_versions(&cc->eng, BR_TLS10, BR_TLS12); + + /* + * X.509 engine uses SHA-256 to hash certificate DN (for + * comparisons). + */ + br_x509_minimal_init(xc, &br_sha256_vtable, + trust_anchors, trust_anchors_num); + + /* + * Set suites and asymmetric crypto implementations. We use the + * "i31" code for RSA (it is somewhat faster than the "i32" + * implementation). + * TODO: change that when better implementations are made available. + */ + br_ssl_engine_set_suites(&cc->eng, suites, + (sizeof suites) / (sizeof suites[0])); + br_ssl_client_set_default_rsapub(cc); + br_ssl_engine_set_default_rsavrfy(&cc->eng); + br_ssl_engine_set_default_ecdsa(&cc->eng); + br_x509_minimal_set_rsa(xc, br_ssl_engine_get_rsavrfy(&cc->eng)); + br_x509_minimal_set_ecdsa(xc, + br_ssl_engine_get_ec(&cc->eng), + br_ssl_engine_get_ecdsa(&cc->eng)); + + /* + * Set supported hash functions, for the SSL engine and for the + * X.509 engine. + */ + for (id = br_md5_ID; id <= br_sha512_ID; id ++) { + const br_hash_class *hc; + + hc = hashes[id - 1]; + br_ssl_engine_set_hash(&cc->eng, id, hc); + br_x509_minimal_set_hash(xc, id, hc); + } + + /* + * Link the X.509 engine in the SSL engine. + */ + br_ssl_engine_set_x509(&cc->eng, &xc->vtable); + + /* + * Set the PRF implementations. + */ + br_ssl_engine_set_prf10(&cc->eng, &br_tls10_prf); + br_ssl_engine_set_prf_sha256(&cc->eng, &br_tls12_sha256_prf); + br_ssl_engine_set_prf_sha384(&cc->eng, &br_tls12_sha384_prf); + + /* + * Symmetric encryption. We use the "default" implementations + * (fastest among constant-time implementations). + */ + br_ssl_engine_set_default_aes_cbc(&cc->eng); + br_ssl_engine_set_default_aes_ccm(&cc->eng); + br_ssl_engine_set_default_aes_gcm(&cc->eng); + br_ssl_engine_set_default_des_cbc(&cc->eng); + br_ssl_engine_set_default_chapol(&cc->eng); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_engine.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_engine.c new file mode 100644 index 000000000..81dcc068a --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_engine.c @@ -0,0 +1,1589 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +#if 0 +/* obsolete */ + +/* + * If BR_USE_URANDOM is not defined, then try to autodetect its presence + * through compiler macros. + */ +#ifndef BR_USE_URANDOM + +/* + * Macro values documented on: + * https://sourceforge.net/p/predef/wiki/OperatingSystems/ + * + * Only the most common systems have been included here for now. This + * should be enriched later on. + */ +#if defined _AIX \ + || defined __ANDROID__ \ + || defined __FreeBSD__ \ + || defined __NetBSD__ \ + || defined __OpenBSD__ \ + || defined __DragonFly__ \ + || defined __linux__ \ + || (defined __sun && (defined __SVR4 || defined __svr4__)) \ + || (defined __APPLE__ && defined __MACH__) +#define BR_USE_URANDOM 1 +#endif + +#endif + +/* + * If BR_USE_WIN32_RAND is not defined, perform autodetection here. + */ +#ifndef BR_USE_WIN32_RAND + +#if defined _WIN32 || defined _WIN64 +#define BR_USE_WIN32_RAND 1 +#endif + +#endif + +#if BR_USE_URANDOM +#include +#include +#include +#include +#endif + +#if BR_USE_WIN32_RAND +#include +#include +#pragma comment(lib, "advapi32") +#endif + +#endif + +/* ==================================================================== */ +/* + * This part of the file does the low-level record management. + */ + +/* + * IMPLEMENTATION NOTES + * ==================== + * + * In this file, we designate by "input" (and the "i" letter) the "recv" + * operations: incoming records from the peer, from which payload data + * is obtained, and must be extracted by the application (or the SSL + * handshake engine). Similarly, "output" (and the "o" letter) is for + * "send": payload data injected by the application (and SSL handshake + * engine), to be wrapped into records, that are then conveyed to the + * peer over the transport medium. + * + * The input and output buffers may be distinct or shared. When + * shared, input and output cannot occur concurrently; the caller + * must make sure that it never needs to output data while input + * data has been received. In practice, a shared buffer prevents + * pipelining of HTTP requests, or similar protocols; however, a + * shared buffer saves RAM. + * + * The input buffer is pointed to by 'ibuf' and has size 'ibuf_len'; + * the output buffer is pointed to by 'obuf' and has size 'obuf_len'. + * From the size of these buffers is derived the maximum fragment + * length, which will be honoured upon sending records; regardless of + * that length, incoming records will be processed as long as they + * fit in the input buffer, and their length still complies with the + * protocol specification (maximum plaintext payload length is 16384 + * bytes). + * + * Three registers are used to manage buffering in ibuf, called ixa, + * ixb and ixc. Similarly, three registers are used to manage buffering + * in obuf, called oxa, oxb and oxc. + * + * + * At any time, the engine is in one of the following modes: + * -- Failed mode: an error occurs, no I/O can happen. + * -- Input mode: the engine can either receive record bytes from the + * transport layer, or it has some buffered payload bytes to yield. + * -- Output mode: the engine can either receive payload bytes, or it + * has some record bytes to send to the transport layer. + * -- Input/Output mode: both input and output modes are active. When + * the buffer is shared, this can happen only when the buffer is empty + * (no buffered payload bytes or record bytes in either direction). + * + * + * Failed mode: + * ------------ + * + * I/O failed for some reason (invalid received data, not enough room + * for the next record...). No I/O may ever occur again for this context, + * until an explicit reset is performed. This mode, and the error code, + * are also used for protocol errors, especially handshake errors. + * + * + * Input mode: + * ----------- + * + * ixa index within ibuf[] for the currently read data + * ixb maximum index within ibuf[] for the currently read data + * ixc number of bytes not yet received for the current record + * + * -- When ixa == ixb, there is no available data for readers. When + * ixa != ixb, there is available data and it starts at offset ixa. + * + * -- When waiting for the next record header, ixa and ixb are equal + * and contain a value ranging from 0 to 4; ixc is equal to 5-ixa. + * + * -- When the header has been received, record data is obtained. The + * ixc field records how many bytes are still needed to reach the + * end of the current record. + * + * ** If encryption is active, then ixa and ixb are kept equal, and + * point to the end of the currently received record bytes. When + * ixc reaches 0, decryption/MAC is applied, and ixa and ixb are + * adjusted. + * + * ** If encryption is not active, then ixa and ixb are distinct + * and data can be read right away. Additional record data is + * obtained only when ixa == ixb. + * + * Note: in input mode and no encryption, records larger than the buffer + * size are allowed. When encryption is active, the complete record must + * fit within the buffer, since it cannot be decrypted/MACed until it + * has been completely received. + * + * -- When receiving the next record header, 'version_in' contains the + * expected input version (0 if not expecting a specific version); on + * mismatch, the mode switches to 'failed'. + * + * -- When the header has been received, 'version_in' contains the received + * version. It is up to the caller to check and adjust the 'version_in' field + * to implement the required semantics. + * + * -- The 'record_type_in' field is updated with the incoming record type + * when the next record header has been received. + * + * + * Output mode: + * ------------ + * + * oxa index within obuf[] for the currently accumulated data + * oxb maximum index within obuf[] for record data + * oxc pointer for start of record data, and for record sending + * + * -- When oxa != oxb, more data can be accumulated into the current + * record; when oxa == oxb, a closed record is being sent. + * + * -- When accumulating data, oxc points to the start of the data. + * + * -- During record sending, oxa (and oxb) point to the next record byte + * to send, and oxc indicates the end of the current record. + * + * Note: sent records must fit within the buffer, since the header is + * adjusted only when the complete record has been assembled. + * + * -- The 'version_out' and 'record_type_out' fields are used to build the + * record header when the mode is switched to 'sending'. + * + * + * Modes: + * ------ + * + * The state register iomode contains one of the following values: + * + * BR_IO_FAILED I/O failed + * BR_IO_IN input mode + * BR_IO_OUT output mode + * BR_IO_INOUT input/output mode + * + * Whether encryption is active on incoming records is indicated by the + * incrypt flag. For outgoing records, there is no such flag; "encryption" + * is always considered active, but initially uses functions that do not + * encrypt anything. The 'incrypt' flag is needed because when there is + * no active encryption, records larger than the I/O buffer are accepted. + * + * Note: we do not support no-encryption modes (MAC only). + * + * TODO: implement GCM support + * + * + * Misc: + * ----- + * + * 'max_frag_len' is the maximum plaintext size for an outgoing record. + * By default, it is set to the maximum value that fits in the provided + * buffers, in the following list: 512, 1024, 2048, 4096, 16384. The + * caller may change it if needed, but the new value MUST still fit in + * the buffers, and it MUST be one of the list above for compatibility + * with the Maximum Fragment Length extension. + * + * For incoming records, only the total buffer length and current + * encryption mode impact the maximum length for incoming records. The + * 'max_frag_len' value is still adjusted so that records up to that + * length can be both received and sent. + * + * + * Offsets and lengths: + * -------------------- + * + * When sending fragments with TLS-1.1+, the maximum overhead is: + * 5 bytes for the record header + * 16 bytes for the explicit IV + * 48 bytes for the MAC (HMAC/SHA-384) + * 16 bytes for the padding (AES) + * so a total of 85 extra bytes. Note that we support block cipher sizes + * up to 16 bytes (AES) and HMAC output sizes up to 48 bytes (SHA-384). + * + * With TLS-1.0 and CBC mode, we apply a 1/n-1 split, for a maximum + * overhead of: + * 5 bytes for the first record header + * 32 bytes for the first record payload (AES-CBC + HMAC/SHA-1) + * 5 bytes for the second record header + * 20 bytes for the MAC (HMAC/SHA-1) + * 16 bytes for the padding (AES) + * -1 byte to account for the payload byte in the first record + * so a total of 77 extra bytes at most, less than the 85 bytes above. + * Note that with TLS-1.0, the MAC is HMAC with either MD5 or SHA-1, but + * no other hash function. + * + * The implementation does not try to send larger records when the current + * encryption mode has less overhead. + * + * Maximum input record overhead is: + * 5 bytes for the record header + * 16 bytes for the explicit IV (TLS-1.1+) + * 48 bytes for the MAC (HMAC/SHA-384) + * 256 bytes for the padding + * so a total of 325 extra bytes. + * + * When receiving the next record header, it is written into the buffer + * bytes 0 to 4 (inclusive). Record data is always written into buf[] + * starting at offset 5. When encryption is active, the plaintext data + * may start at a larger offset (e.g. because of an explicit IV). + */ + +#define MAX_OUT_OVERHEAD 85 +#define MAX_IN_OVERHEAD 325 + +/* see inner.h */ +void +br_ssl_engine_fail(br_ssl_engine_context *rc, int err) +{ + if (rc->iomode != BR_IO_FAILED) { + rc->iomode = BR_IO_FAILED; + rc->err = err; + } +} + +/* + * Adjust registers for a new incoming record. + */ +static void +make_ready_in(br_ssl_engine_context *rc) +{ + rc->ixa = rc->ixb = 0; + rc->ixc = 5; + if (rc->iomode == BR_IO_IN) { + rc->iomode = BR_IO_INOUT; + } +} + +/* + * Adjust registers for a new outgoing record. + */ +static void +make_ready_out(br_ssl_engine_context *rc) +{ + size_t a, b; + + a = 5; + b = rc->obuf_len - a; + rc->out.vtable->max_plaintext(&rc->out.vtable, &a, &b); + if ((b - a) > rc->max_frag_len) { + b = a + rc->max_frag_len; + } + rc->oxa = a; + rc->oxb = b; + rc->oxc = a; + if (rc->iomode == BR_IO_OUT) { + rc->iomode = BR_IO_INOUT; + } +} + +/* see inner.h */ +void +br_ssl_engine_new_max_frag_len(br_ssl_engine_context *rc, unsigned max_frag_len) +{ + size_t nxb; + + rc->max_frag_len = max_frag_len; + nxb = rc->oxc + max_frag_len; + if (rc->oxa < rc->oxb && rc->oxb > nxb && rc->oxa < nxb) { + rc->oxb = nxb; + } +} + +/* see bearssl_ssl.h */ +void +br_ssl_engine_set_buffer(br_ssl_engine_context *rc, + void *buf, size_t buf_len, int bidi) +{ + if (buf == NULL) { + br_ssl_engine_set_buffers_bidi(rc, NULL, 0, NULL, 0); + } else { + /* + * In bidirectional mode, we want to maximise input + * buffer size, since we support arbitrary fragmentation + * when sending, but the peer will not necessarily + * comply to any low fragment length (in particular if + * we are the server, because the maximum fragment + * length extension is under client control). + * + * We keep a minimum size of 512 bytes for the plaintext + * of our outgoing records. + * + * br_ssl_engine_set_buffers_bidi() will compute the maximum + * fragment length for outgoing records by using the minimum + * of allocated spaces for both input and output records, + * rounded down to a standard length. + */ + if (bidi) { + size_t w; + + if (buf_len < (512 + MAX_IN_OVERHEAD + + 512 + MAX_OUT_OVERHEAD)) + { + rc->iomode = BR_IO_FAILED; + rc->err = BR_ERR_BAD_PARAM; + return; + } else if (buf_len < (16384 + MAX_IN_OVERHEAD + + 512 + MAX_OUT_OVERHEAD)) + { + w = 512 + MAX_OUT_OVERHEAD; + } else { + w = buf_len - (16384 + MAX_IN_OVERHEAD); + } + br_ssl_engine_set_buffers_bidi(rc, + buf, buf_len - w, + (unsigned char *)buf + w, w); + } else { + br_ssl_engine_set_buffers_bidi(rc, + buf, buf_len, NULL, 0); + } + } +} + +/* see bearssl_ssl.h */ +void +br_ssl_engine_set_buffers_bidi(br_ssl_engine_context *rc, + void *ibuf, size_t ibuf_len, void *obuf, size_t obuf_len) +{ + rc->iomode = BR_IO_INOUT; + rc->incrypt = 0; + rc->err = BR_ERR_OK; + rc->version_in = 0; + rc->record_type_in = 0; + rc->version_out = 0; + rc->record_type_out = 0; + if (ibuf == NULL) { + if (rc->ibuf == NULL) { + br_ssl_engine_fail(rc, BR_ERR_BAD_PARAM); + } + } else { + unsigned u; + + rc->ibuf = ibuf; + rc->ibuf_len = ibuf_len; + if (obuf == NULL) { + obuf = ibuf; + obuf_len = ibuf_len; + } + rc->obuf = obuf; + rc->obuf_len = obuf_len; + + /* + * Compute the maximum fragment length, that fits for + * both incoming and outgoing records. This length will + * be used in fragment length negotiation, so we must + * honour it both ways. Regardless, larger incoming + * records will be accepted, as long as they fit in the + * actual buffer size. + */ + for (u = 14; u >= 9; u --) { + size_t flen; + + flen = (size_t)1 << u; + if (obuf_len >= flen + MAX_OUT_OVERHEAD + && ibuf_len >= flen + MAX_IN_OVERHEAD) + { + break; + } + } + if (u == 8) { + br_ssl_engine_fail(rc, BR_ERR_BAD_PARAM); + return; + } else if (u == 13) { + u = 12; + } + rc->max_frag_len = (size_t)1 << u; + rc->log_max_frag_len = u; + rc->peer_log_max_frag_len = 0; + } + rc->out.vtable = &br_sslrec_out_clear_vtable; + make_ready_in(rc); + make_ready_out(rc); +} + +/* + * Clear buffers in both directions. + */ +static void +engine_clearbuf(br_ssl_engine_context *rc) +{ + make_ready_in(rc); + make_ready_out(rc); +} + +/* + * Make sure the internal PRNG is initialised (but not necessarily + * seeded properly yet). + */ +static int +rng_init(br_ssl_engine_context *cc) +{ + const br_hash_class *h; + + if (cc->rng_init_done != 0) { + return 1; + } + + /* + * If using TLS-1.2, then SHA-256 or SHA-384 must be present (or + * both); we prefer SHA-256 which is faster for 32-bit systems. + * + * If using TLS-1.0 or 1.1 then SHA-1 must be present. + * + * Though HMAC_DRBG/SHA-1 is, as far as we know, as safe as + * these things can be, we still prefer the SHA-2 functions over + * SHA-1, if only for public relations (known theoretical + * weaknesses of SHA-1 with regards to collisions are mostly + * irrelevant here, but they still make people nervous). + */ + h = br_multihash_getimpl(&cc->mhash, br_sha256_ID); + if (!h) { + h = br_multihash_getimpl(&cc->mhash, br_sha384_ID); + if (!h) { + h = br_multihash_getimpl(&cc->mhash, + br_sha1_ID); + if (!h) { + br_ssl_engine_fail(cc, BR_ERR_BAD_STATE); + return 0; + } + } + } + br_hmac_drbg_init(&cc->rng, h, NULL, 0); + cc->rng_init_done = 1; + return 1; +} + +/* see inner.h */ +int +br_ssl_engine_init_rand(br_ssl_engine_context *cc) +{ + if (!rng_init(cc)) { + return 0; + } + + /* + * We always try OS/hardware seeding once. If it works, then + * we assume proper seeding. If not, then external entropy must + * have been injected; otherwise, we report an error. + */ + if (!cc->rng_os_rand_done) { + br_prng_seeder sd; + + sd = br_prng_seeder_system(NULL); + if (sd != 0 && sd(&cc->rng.vtable)) { + cc->rng_init_done = 2; + } + cc->rng_os_rand_done = 1; + } + if (cc->rng_init_done < 2) { + br_ssl_engine_fail(cc, BR_ERR_NO_RANDOM); + return 0; + } + return 1; +} + +/* see bearssl_ssl.h */ +void +br_ssl_engine_inject_entropy(br_ssl_engine_context *cc, + const void *data, size_t len) +{ + /* + * Externally provided entropy is assumed to be "good enough" + * (we cannot really test its quality) so if the RNG structure + * could be initialised at all, then we marked the RNG as + * "properly seeded". + */ + if (!rng_init(cc)) { + return; + } + br_hmac_drbg_update(&cc->rng, data, len); + cc->rng_init_done = 2; +} + +/* + * We define a few internal functions that implement the low-level engine + * API for I/O; the external API (br_ssl_engine_sendapp_buf() and similar + * functions) is built upon these function, with special processing for + * records which are not of type "application data". + * + * recvrec_buf, recvrec_ack receives bytes from transport medium + * sendrec_buf, sendrec_ack send bytes to transport medium + * recvpld_buf, recvpld_ack receives payload data from engine + * sendpld_buf, sendpld_ack send payload data to engine + */ + +static unsigned char * +recvrec_buf(const br_ssl_engine_context *rc, size_t *len) +{ + if (rc->shutdown_recv) { + *len = 0; + return NULL; + } + + /* + * Bytes from the transport can be injected only if the mode is + * compatible (in or in/out), and ixa == ixb; ixc then contains + * the number of bytes that are still expected (but it may + * exceed our buffer size). + * + * We cannot get "stuck" here (buffer is full, but still more + * data is expected) because oversized records are detected when + * their header is processed. + */ + switch (rc->iomode) { + case BR_IO_IN: + case BR_IO_INOUT: + if (rc->ixa == rc->ixb) { + size_t z; + + z = rc->ixc; + if (z > rc->ibuf_len - rc->ixa) { + z = rc->ibuf_len - rc->ixa; + } + *len = z; + return rc->ibuf + rc->ixa; + } + break; + } + *len = 0; + return NULL; +} + +static void +recvrec_ack(br_ssl_engine_context *rc, size_t len) +{ + unsigned char *pbuf; + size_t pbuf_len; + + /* + * Adjust state if necessary (for a shared input/output buffer): + * we got some incoming bytes, so we cannot (temporarily) handle + * outgoing data. + */ + if (rc->iomode == BR_IO_INOUT && rc->ibuf == rc->obuf) { + rc->iomode = BR_IO_IN; + } + + /* + * Adjust data pointers. + */ + rc->ixb = (rc->ixa += len); + rc->ixc -= len; + + /* + * If we are receiving a header and did not fully obtained it + * yet, then just wait for the next bytes. + */ + if (rc->ixa < 5) { + return; + } + + /* + * If we just obtained a full header, process it. + */ + if (rc->ixa == 5) { + unsigned version; + unsigned rlen; + + /* + * Get record type and version. We support only versions + * 3.x (if the version major number does not match, then + * we suppose that the record format is too alien for us + * to process it). + * + * Note: right now, we reject clients that try to send + * a ClientHello in a format compatible with SSL-2.0. It + * is unclear whether this will ever be supported; and + * if we want to support it, then this might be done in + * in the server-specific code, not here. + */ + rc->record_type_in = rc->ibuf[0]; + version = br_dec16be(rc->ibuf + 1); + if ((version >> 8) != 3) { + br_ssl_engine_fail(rc, BR_ERR_UNSUPPORTED_VERSION); + return; + } + + /* + * We ensure that successive records have the same + * version. The handshake code must check and adjust the + * variables when necessary to accommodate the protocol + * negotiation details. + */ + if (rc->version_in != 0 && rc->version_in != version) { + br_ssl_engine_fail(rc, BR_ERR_BAD_VERSION); + return; + } + rc->version_in = version; + + /* + * Decode record length. We must check that the length + * is valid (relatively to the current encryption mode) + * and also (if encryption is active) that the record + * will fit in our buffer. + * + * When no encryption is active, we can process records + * by chunks, and thus accept any record up to the + * maximum allowed plaintext length (16384 bytes). + */ + rlen = br_dec16be(rc->ibuf + 3); + if (rc->incrypt) { + if (!rc->in.vtable->check_length( + &rc->in.vtable, rlen)) + { + br_ssl_engine_fail(rc, BR_ERR_BAD_LENGTH); + return; + } + if (rlen > (rc->ibuf_len - 5)) { + br_ssl_engine_fail(rc, BR_ERR_TOO_LARGE); + return; + } + } else { + if (rlen > 16384) { + br_ssl_engine_fail(rc, BR_ERR_BAD_LENGTH); + return; + } + } + + /* + * If the record is completely empty then we must switch + * to a new record. Note that, in that case, we + * completely ignore the record type, which is fitting + * since we received no actual data of that type. + * + * A completely empty record is technically allowed as + * long as encryption/MAC is not active, i.e. before + * completion of the first handshake. It it still weird; + * it might conceptually be useful as a heartbeat or + * keep-alive mechanism while some lengthy operation is + * going on, e.g. interaction with a human user. + */ + if (rlen == 0) { + make_ready_in(rc); + } else { + rc->ixa = rc->ixb = 5; + rc->ixc = rlen; + } + return; + } + + /* + * If there is no active encryption, then the data can be read + * right away. Note that we do not receive bytes from the + * transport medium when we still have payload bytes to be + * acknowledged. + */ + if (!rc->incrypt) { + rc->ixa = 5; + return; + } + + /* + * Since encryption is active, we must wait for a full record + * before processing it. + */ + if (rc->ixc != 0) { + return; + } + + /* + * We got the full record. Decrypt it. + */ + pbuf_len = rc->ixa - 5; + pbuf = rc->in.vtable->decrypt(&rc->in.vtable, + rc->record_type_in, rc->version_in, rc->ibuf + 5, &pbuf_len); + if (pbuf == 0) { + br_ssl_engine_fail(rc, BR_ERR_BAD_MAC); + return; + } + rc->ixa = (size_t)(pbuf - rc->ibuf); + rc->ixb = rc->ixa + pbuf_len; + + /* + * Decryption may have yielded an empty record, in which case + * we get back to "ready" state immediately. + */ + if (rc->ixa == rc->ixb) { + make_ready_in(rc); + } +} + +/* see inner.h */ +int +br_ssl_engine_recvrec_finished(const br_ssl_engine_context *rc) +{ + switch (rc->iomode) { + case BR_IO_IN: + case BR_IO_INOUT: + return rc->ixc == 0 || rc->ixa < 5; + default: + return 1; + } +} + +static unsigned char * +recvpld_buf(const br_ssl_engine_context *rc, size_t *len) +{ + /* + * There is payload data to be read only if the mode is + * compatible, and ixa != ixb. + */ + switch (rc->iomode) { + case BR_IO_IN: + case BR_IO_INOUT: + *len = rc->ixb - rc->ixa; + return (*len == 0) ? NULL : (rc->ibuf + rc->ixa); + default: + *len = 0; + return NULL; + } +} + +static void +recvpld_ack(br_ssl_engine_context *rc, size_t len) +{ + rc->ixa += len; + + /* + * If we read all the available data, then we either expect + * the remainder of the current record (if the current record + * was not finished; this may happen when encryption is not + * active), or go to "ready" state. + */ + if (rc->ixa == rc->ixb) { + if (rc->ixc == 0) { + make_ready_in(rc); + } else { + rc->ixa = rc->ixb = 5; + } + } +} + +static unsigned char * +sendpld_buf(const br_ssl_engine_context *rc, size_t *len) +{ + /* + * Payload data can be injected only if the current mode is + * compatible, and oxa != oxb. + */ + switch (rc->iomode) { + case BR_IO_OUT: + case BR_IO_INOUT: + *len = rc->oxb - rc->oxa; + return (*len == 0) ? NULL : (rc->obuf + rc->oxa); + default: + *len = 0; + return NULL; + } +} + +/* + * If some payload bytes have been accumulated, then wrap them into + * an outgoing record. Otherwise, this function does nothing, unless + * 'force' is non-zero, in which case an empty record is assembled. + * + * The caller must take care not to invoke this function if the engine + * is not currently ready to receive payload bytes to send. + */ +static void +sendpld_flush(br_ssl_engine_context *rc, int force) +{ + size_t xlen; + unsigned char *buf; + + if (rc->oxa == rc->oxb) { + return; + } + xlen = rc->oxa - rc->oxc; + if (xlen == 0 && !force) { + return; + } + buf = rc->out.vtable->encrypt(&rc->out.vtable, + rc->record_type_out, rc->version_out, + rc->obuf + rc->oxc, &xlen); + rc->oxb = rc->oxa = (size_t)(buf - rc->obuf); + rc->oxc = rc->oxa + xlen; +} + +static void +sendpld_ack(br_ssl_engine_context *rc, size_t len) +{ + /* + * If using a shared buffer, then we may have to modify the + * current mode. + */ + if (rc->iomode == BR_IO_INOUT && rc->ibuf == rc->obuf) { + rc->iomode = BR_IO_OUT; + } + rc->oxa += len; + if (rc->oxa >= rc->oxb) { + /* + * Set oxb to one more than oxa so that sendpld_flush() + * does not mistakingly believe that a record is + * already prepared and being sent. + */ + rc->oxb = rc->oxa + 1; + sendpld_flush(rc, 0); + } +} + +static unsigned char * +sendrec_buf(const br_ssl_engine_context *rc, size_t *len) +{ + /* + * When still gathering payload bytes, oxc points to the start + * of the record data, so oxc <= oxa. However, when a full + * record has been completed, oxc points to the end of the record, + * so oxc > oxa. + */ + switch (rc->iomode) { + case BR_IO_OUT: + case BR_IO_INOUT: + if (rc->oxc > rc->oxa) { + *len = rc->oxc - rc->oxa; + return rc->obuf + rc->oxa; + } + break; + } + *len = 0; + return NULL; +} + +static void +sendrec_ack(br_ssl_engine_context *rc, size_t len) +{ + rc->oxb = (rc->oxa += len); + if (rc->oxa == rc->oxc) { + make_ready_out(rc); + } +} + +/* + * Test whether there is some buffered outgoing record that still must + * sent. + */ +static inline int +has_rec_tosend(const br_ssl_engine_context *rc) +{ + return rc->oxa == rc->oxb && rc->oxa != rc->oxc; +} + +/* + * The "no encryption" mode has no overhead. It limits the payload size + * to the maximum size allowed by the standard (16384 bytes); the caller + * is responsible for possibly enforcing a smaller fragment length. + */ +static void +clear_max_plaintext(const br_sslrec_out_clear_context *cc, + size_t *start, size_t *end) +{ + size_t len; + + (void)cc; + len = *end - *start; + if (len > 16384) { + *end = *start + 16384; + } +} + +/* + * In "no encryption" mode, encryption is trivial (a no-operation) so + * we just have to encode the header. + */ +static unsigned char * +clear_encrypt(br_sslrec_out_clear_context *cc, + int record_type, unsigned version, void *data, size_t *data_len) +{ + unsigned char *buf; + + (void)cc; + buf = (unsigned char *)data - 5; + buf[0] = record_type; + br_enc16be(buf + 1, version); + br_enc16be(buf + 3, *data_len); + *data_len += 5; + return buf; +} + +/* see bearssl_ssl.h */ +const br_sslrec_out_class br_sslrec_out_clear_vtable = { + sizeof(br_sslrec_out_clear_context), + (void (*)(const br_sslrec_out_class *const *, size_t *, size_t *)) + &clear_max_plaintext, + (unsigned char *(*)(const br_sslrec_out_class **, + int, unsigned, void *, size_t *)) + &clear_encrypt +}; + +/* ==================================================================== */ +/* + * In this part of the file, we handle the various record types, and + * communications with the handshake processor. + */ + +/* + * IMPLEMENTATION NOTES + * ==================== + * + * The handshake processor is written in T0 and runs as a coroutine. + * It receives the contents of all records except application data, and + * is responsible for producing the contents of all records except + * application data. + * + * A state flag is maintained, which specifies whether application data + * is acceptable or not. When it is set: + * + * -- Application data can be injected as payload data (provided that + * the output buffer is ready for that). + * + * -- Incoming application data records are accepted, and yield data + * that the caller may retrieve. + * + * When the flag is cleared, application data is not accepted from the + * application, and incoming application data records trigger an error. + * + * + * Records of type handshake, alert or change-cipher-spec are handled + * by the handshake processor. The handshake processor is written in T0 + * and runs as a coroutine; it gets invoked whenever one of the following + * situations is reached: + * + * -- An incoming record has type handshake, alert or change-cipher-spec, + * and yields data that can be read (zero-length records are thus + * ignored). + * + * -- An outgoing record has just finished being sent, and the "application + * data" flag is cleared. + * + * -- The caller wishes to perform a close (call to br_ssl_engine_close()). + * + * -- The caller wishes to perform a renegotiation (call to + * br_ssl_engine_renegotiate()). + * + * Whenever the handshake processor is entered, access to the payload + * buffers is provided, along with some information about explicit + * closures or renegotiations. + */ + +/* see bearssl_ssl.h */ +void +br_ssl_engine_set_suites(br_ssl_engine_context *cc, + const uint16_t *suites, size_t suites_num) +{ + if ((suites_num * sizeof *suites) > sizeof cc->suites_buf) { + br_ssl_engine_fail(cc, BR_ERR_BAD_PARAM); + return; + } + memcpy(cc->suites_buf, suites, suites_num * sizeof *suites); + cc->suites_num = suites_num; +} + +/* + * Give control to handshake processor. 'action' is 1 for a close, + * 2 for a renegotiation, or 0 for a jump due to I/O completion. + */ +static void +jump_handshake(br_ssl_engine_context *cc, int action) +{ + /* + * We use a loop because the handshake processor actions may + * allow for more actions; namely, if the processor reads all + * input data, then it may allow for output data to be produced, + * in case of a shared in/out buffer. + */ + for (;;) { + size_t hlen_in, hlen_out; + + /* + * Get input buffer. We do not want to provide + * application data to the handshake processor (we could + * get called with an explicit close or renegotiation + * while there is application data ready to be read). + */ + cc->hbuf_in = recvpld_buf(cc, &hlen_in); + if (cc->hbuf_in != NULL + && cc->record_type_in == BR_SSL_APPLICATION_DATA) + { + hlen_in = 0; + } + + /* + * Get output buffer. The handshake processor never + * leaves an unfinished outgoing record, so if there is + * buffered output, then it MUST be some application + * data, so the processor cannot write to it. + */ + cc->saved_hbuf_out = cc->hbuf_out = sendpld_buf(cc, &hlen_out); + if (cc->hbuf_out != NULL && br_ssl_engine_has_pld_to_send(cc)) { + hlen_out = 0; + } + + /* + * Note: hlen_in and hlen_out can be both non-zero only if + * the input and output buffers are disjoint. Thus, we can + * offer both buffers to the handshake code. + */ + + cc->hlen_in = hlen_in; + cc->hlen_out = hlen_out; + cc->action = action; + cc->hsrun(&cc->cpu); + if (br_ssl_engine_closed(cc)) { + return; + } + if (cc->hbuf_out != cc->saved_hbuf_out) { + sendpld_ack(cc, cc->hbuf_out - cc->saved_hbuf_out); + } + if (hlen_in != cc->hlen_in) { + recvpld_ack(cc, hlen_in - cc->hlen_in); + if (cc->hlen_in == 0) { + /* + * We read all data bytes, which may have + * released the output buffer in case it + * is shared with the input buffer, and + * the handshake code might be waiting for + * that. + */ + action = 0; + continue; + } + } + break; + } +} + +/* see inner.h */ +void +br_ssl_engine_flush_record(br_ssl_engine_context *cc) +{ + if (cc->hbuf_out != cc->saved_hbuf_out) { + sendpld_ack(cc, cc->hbuf_out - cc->saved_hbuf_out); + } + if (br_ssl_engine_has_pld_to_send(cc)) { + sendpld_flush(cc, 0); + } + cc->saved_hbuf_out = cc->hbuf_out = sendpld_buf(cc, &cc->hlen_out); +} + +/* see bearssl_ssl.h */ +unsigned char * +br_ssl_engine_sendapp_buf(const br_ssl_engine_context *cc, size_t *len) +{ + if (!(cc->application_data & 1)) { + *len = 0; + return NULL; + } + return sendpld_buf(cc, len); +} + +/* see bearssl_ssl.h */ +void +br_ssl_engine_sendapp_ack(br_ssl_engine_context *cc, size_t len) +{ + sendpld_ack(cc, len); +} + +/* see bearssl_ssl.h */ +unsigned char * +br_ssl_engine_recvapp_buf(const br_ssl_engine_context *cc, size_t *len) +{ + if (!(cc->application_data & 1) + || cc->record_type_in != BR_SSL_APPLICATION_DATA) + { + *len = 0; + return NULL; + } + return recvpld_buf(cc, len); +} + +/* see bearssl_ssl.h */ +void +br_ssl_engine_recvapp_ack(br_ssl_engine_context *cc, size_t len) +{ + recvpld_ack(cc, len); +} + +/* see bearssl_ssl.h */ +unsigned char * +br_ssl_engine_sendrec_buf(const br_ssl_engine_context *cc, size_t *len) +{ + return sendrec_buf(cc, len); +} + +/* see bearssl_ssl.h */ +void +br_ssl_engine_sendrec_ack(br_ssl_engine_context *cc, size_t len) +{ + sendrec_ack(cc, len); + if (len != 0 && !has_rec_tosend(cc) + && (cc->record_type_out != BR_SSL_APPLICATION_DATA + || (cc->application_data & 1) == 0)) + { + jump_handshake(cc, 0); + } +} + +/* see bearssl_ssl.h */ +unsigned char * +br_ssl_engine_recvrec_buf(const br_ssl_engine_context *cc, size_t *len) +{ + return recvrec_buf(cc, len); +} + +/* see bearssl_ssl.h */ +void +br_ssl_engine_recvrec_ack(br_ssl_engine_context *cc, size_t len) +{ + unsigned char *buf; + + recvrec_ack(cc, len); + if (br_ssl_engine_closed(cc)) { + return; + } + + /* + * We just received some bytes from the peer. This may have + * yielded some payload bytes, in which case we must process + * them according to the record type. + */ + buf = recvpld_buf(cc, &len); + if (buf != NULL) { + switch (cc->record_type_in) { + case BR_SSL_CHANGE_CIPHER_SPEC: + case BR_SSL_ALERT: + case BR_SSL_HANDSHAKE: + jump_handshake(cc, 0); + break; + case BR_SSL_APPLICATION_DATA: + if (cc->application_data == 1) { + break; + } + + /* + * If we are currently closing, and waiting for + * a close_notify from the peer, then incoming + * application data should be discarded. + */ + if (cc->application_data == 2) { + recvpld_ack(cc, len); + break; + } + + /* Fall through */ + default: + br_ssl_engine_fail(cc, BR_ERR_UNEXPECTED); + break; + } + } +} + +/* see bearssl_ssl.h */ +void +br_ssl_engine_close(br_ssl_engine_context *cc) +{ + if (!br_ssl_engine_closed(cc)) { + /* + * If we are not already closed, then we need to + * initiate the closure. Once closing, any incoming + * application data is discarded; we should also discard + * application data which is already there but has not + * been acknowledged by the application yet (this mimics + * usual semantics on BSD sockets: you cannot read() + * once you called close(), even if there was some + * unread data already buffered). + */ + size_t len; + + if (br_ssl_engine_recvapp_buf(cc, &len) != NULL && len != 0) { + br_ssl_engine_recvapp_ack(cc, len); + } + jump_handshake(cc, 1); + } +} + +/* see bearssl_ssl.h */ +int +br_ssl_engine_renegotiate(br_ssl_engine_context *cc) +{ + size_t len; + + if (br_ssl_engine_closed(cc) || cc->reneg == 1 + || (cc->flags & BR_OPT_NO_RENEGOTIATION) != 0 + || br_ssl_engine_recvapp_buf(cc, &len) != NULL) + { + return 0; + } + jump_handshake(cc, 2); + return 1; +} + +/* see bearssl.h */ +unsigned +br_ssl_engine_current_state(const br_ssl_engine_context *cc) +{ + unsigned s; + size_t len; + + if (br_ssl_engine_closed(cc)) { + return BR_SSL_CLOSED; + } + + s = 0; + if (br_ssl_engine_sendrec_buf(cc, &len) != NULL) { + s |= BR_SSL_SENDREC; + } + if (br_ssl_engine_recvrec_buf(cc, &len) != NULL) { + s |= BR_SSL_RECVREC; + } + if (br_ssl_engine_sendapp_buf(cc, &len) != NULL) { + s |= BR_SSL_SENDAPP; + } + if (br_ssl_engine_recvapp_buf(cc, &len) != NULL) { + s |= BR_SSL_RECVAPP; + } + return s; +} + +/* see bearssl_ssl.h */ +void +br_ssl_engine_flush(br_ssl_engine_context *cc, int force) +{ + if (!br_ssl_engine_closed(cc) && (cc->application_data & 1) != 0) { + sendpld_flush(cc, force); + } +} + +/* see inner.h */ +void +br_ssl_engine_hs_reset(br_ssl_engine_context *cc, + void (*hsinit)(void *), void (*hsrun)(void *)) +{ + engine_clearbuf(cc); + cc->cpu.dp = cc->dp_stack; + cc->cpu.rp = cc->rp_stack; + hsinit(&cc->cpu); + cc->hsrun = hsrun; + cc->shutdown_recv = 0; + cc->application_data = 0; + cc->alert = 0; + jump_handshake(cc, 0); +} + +/* see inner.h */ +br_tls_prf_impl +br_ssl_engine_get_PRF(br_ssl_engine_context *cc, int prf_id) +{ + if (cc->session.version >= BR_TLS12) { + if (prf_id == br_sha384_ID) { + return cc->prf_sha384; + } else { + return cc->prf_sha256; + } + } else { + return cc->prf10; + } +} + +/* see inner.h */ +void +br_ssl_engine_compute_master(br_ssl_engine_context *cc, + int prf_id, const void *pms, size_t pms_len) +{ + br_tls_prf_impl iprf; + br_tls_prf_seed_chunk seed[2] = { + { cc->client_random, sizeof cc->client_random }, + { cc->server_random, sizeof cc->server_random } + }; + + iprf = br_ssl_engine_get_PRF(cc, prf_id); + iprf(cc->session.master_secret, sizeof cc->session.master_secret, + pms, pms_len, "master secret", 2, seed); +} + +/* + * Compute key block. + */ +static void +compute_key_block(br_ssl_engine_context *cc, int prf_id, + size_t half_len, unsigned char *kb) +{ + br_tls_prf_impl iprf; + br_tls_prf_seed_chunk seed[2] = { + { cc->server_random, sizeof cc->server_random }, + { cc->client_random, sizeof cc->client_random } + }; + + iprf = br_ssl_engine_get_PRF(cc, prf_id); + iprf(kb, half_len << 1, + cc->session.master_secret, sizeof cc->session.master_secret, + "key expansion", 2, seed); +} + +/* see inner.h */ +void +br_ssl_engine_switch_cbc_in(br_ssl_engine_context *cc, + int is_client, int prf_id, int mac_id, + const br_block_cbcdec_class *bc_impl, size_t cipher_key_len) +{ + unsigned char kb[192]; + unsigned char *cipher_key, *mac_key, *iv; + const br_hash_class *imh; + size_t mac_key_len, mac_out_len, iv_len; + + imh = br_ssl_engine_get_hash(cc, mac_id); + mac_out_len = (imh->desc >> BR_HASHDESC_OUT_OFF) & BR_HASHDESC_OUT_MASK; + mac_key_len = mac_out_len; + + /* + * TLS 1.1+ uses per-record explicit IV, so no IV to generate here. + */ + if (cc->session.version >= BR_TLS11) { + iv_len = 0; + } else { + iv_len = bc_impl->block_size; + } + compute_key_block(cc, prf_id, + mac_key_len + cipher_key_len + iv_len, kb); + if (is_client) { + mac_key = &kb[mac_key_len]; + cipher_key = &kb[(mac_key_len << 1) + cipher_key_len]; + iv = &kb[((mac_key_len + cipher_key_len) << 1) + iv_len]; + } else { + mac_key = &kb[0]; + cipher_key = &kb[mac_key_len << 1]; + iv = &kb[(mac_key_len + cipher_key_len) << 1]; + } + if (iv_len == 0) { + iv = NULL; + } + cc->icbc_in->init(&cc->in.cbc.vtable, + bc_impl, cipher_key, cipher_key_len, + imh, mac_key, mac_key_len, mac_out_len, iv); + cc->incrypt = 1; +} + +/* see inner.h */ +void +br_ssl_engine_switch_cbc_out(br_ssl_engine_context *cc, + int is_client, int prf_id, int mac_id, + const br_block_cbcenc_class *bc_impl, size_t cipher_key_len) +{ + unsigned char kb[192]; + unsigned char *cipher_key, *mac_key, *iv; + const br_hash_class *imh; + size_t mac_key_len, mac_out_len, iv_len; + + imh = br_ssl_engine_get_hash(cc, mac_id); + mac_out_len = (imh->desc >> BR_HASHDESC_OUT_OFF) & BR_HASHDESC_OUT_MASK; + mac_key_len = mac_out_len; + + /* + * TLS 1.1+ uses per-record explicit IV, so no IV to generate here. + */ + if (cc->session.version >= BR_TLS11) { + iv_len = 0; + } else { + iv_len = bc_impl->block_size; + } + compute_key_block(cc, prf_id, + mac_key_len + cipher_key_len + iv_len, kb); + if (is_client) { + mac_key = &kb[0]; + cipher_key = &kb[mac_key_len << 1]; + iv = &kb[(mac_key_len + cipher_key_len) << 1]; + } else { + mac_key = &kb[mac_key_len]; + cipher_key = &kb[(mac_key_len << 1) + cipher_key_len]; + iv = &kb[((mac_key_len + cipher_key_len) << 1) + iv_len]; + } + if (iv_len == 0) { + iv = NULL; + } + cc->icbc_out->init(&cc->out.cbc.vtable, + bc_impl, cipher_key, cipher_key_len, + imh, mac_key, mac_key_len, mac_out_len, iv); +} + +/* see inner.h */ +void +br_ssl_engine_switch_gcm_in(br_ssl_engine_context *cc, + int is_client, int prf_id, + const br_block_ctr_class *bc_impl, size_t cipher_key_len) +{ + unsigned char kb[72]; + unsigned char *cipher_key, *iv; + + compute_key_block(cc, prf_id, cipher_key_len + 4, kb); + if (is_client) { + cipher_key = &kb[cipher_key_len]; + iv = &kb[(cipher_key_len << 1) + 4]; + } else { + cipher_key = &kb[0]; + iv = &kb[cipher_key_len << 1]; + } + cc->igcm_in->init(&cc->in.gcm.vtable.in, + bc_impl, cipher_key, cipher_key_len, cc->ighash, iv); + cc->incrypt = 1; +} + +/* see inner.h */ +void +br_ssl_engine_switch_gcm_out(br_ssl_engine_context *cc, + int is_client, int prf_id, + const br_block_ctr_class *bc_impl, size_t cipher_key_len) +{ + unsigned char kb[72]; + unsigned char *cipher_key, *iv; + + compute_key_block(cc, prf_id, cipher_key_len + 4, kb); + if (is_client) { + cipher_key = &kb[0]; + iv = &kb[cipher_key_len << 1]; + } else { + cipher_key = &kb[cipher_key_len]; + iv = &kb[(cipher_key_len << 1) + 4]; + } + cc->igcm_out->init(&cc->out.gcm.vtable.out, + bc_impl, cipher_key, cipher_key_len, cc->ighash, iv); +} + +/* see inner.h */ +void +br_ssl_engine_switch_chapol_in(br_ssl_engine_context *cc, + int is_client, int prf_id) +{ + unsigned char kb[88]; + unsigned char *cipher_key, *iv; + + compute_key_block(cc, prf_id, 44, kb); + if (is_client) { + cipher_key = &kb[32]; + iv = &kb[76]; + } else { + cipher_key = &kb[0]; + iv = &kb[64]; + } + cc->ichapol_in->init(&cc->in.chapol.vtable.in, + cc->ichacha, cc->ipoly, cipher_key, iv); + cc->incrypt = 1; +} + +/* see inner.h */ +void +br_ssl_engine_switch_chapol_out(br_ssl_engine_context *cc, + int is_client, int prf_id) +{ + unsigned char kb[88]; + unsigned char *cipher_key, *iv; + + compute_key_block(cc, prf_id, 44, kb); + if (is_client) { + cipher_key = &kb[0]; + iv = &kb[64]; + } else { + cipher_key = &kb[32]; + iv = &kb[76]; + } + cc->ichapol_out->init(&cc->out.chapol.vtable.out, + cc->ichacha, cc->ipoly, cipher_key, iv); +} + +/* see inner.h */ +void +br_ssl_engine_switch_ccm_in(br_ssl_engine_context *cc, + int is_client, int prf_id, + const br_block_ctrcbc_class *bc_impl, + size_t cipher_key_len, size_t tag_len) +{ + unsigned char kb[72]; + unsigned char *cipher_key, *iv; + + compute_key_block(cc, prf_id, cipher_key_len + 4, kb); + if (is_client) { + cipher_key = &kb[cipher_key_len]; + iv = &kb[(cipher_key_len << 1) + 4]; + } else { + cipher_key = &kb[0]; + iv = &kb[cipher_key_len << 1]; + } + cc->iccm_in->init(&cc->in.ccm.vtable.in, + bc_impl, cipher_key, cipher_key_len, iv, tag_len); + cc->incrypt = 1; +} + +/* see inner.h */ +void +br_ssl_engine_switch_ccm_out(br_ssl_engine_context *cc, + int is_client, int prf_id, + const br_block_ctrcbc_class *bc_impl, + size_t cipher_key_len, size_t tag_len) +{ + unsigned char kb[72]; + unsigned char *cipher_key, *iv; + + compute_key_block(cc, prf_id, cipher_key_len + 4, kb); + if (is_client) { + cipher_key = &kb[0]; + iv = &kb[cipher_key_len << 1]; + } else { + cipher_key = &kb[cipher_key_len]; + iv = &kb[(cipher_key_len << 1) + 4]; + } + cc->iccm_out->init(&cc->out.ccm.vtable.out, + bc_impl, cipher_key, cipher_key_len, iv, tag_len); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_engine_default_aescbc.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_engine_default_aescbc.c new file mode 100644 index 000000000..a751fb5a0 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_engine_default_aescbc.c @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_ssl.h */ +void +br_ssl_engine_set_default_aes_cbc(br_ssl_engine_context *cc) +{ +#if BR_AES_X86NI || BR_POWER8 + const br_block_cbcenc_class *ienc; + const br_block_cbcdec_class *idec; +#endif + + br_ssl_engine_set_cbc(cc, + &br_sslrec_in_cbc_vtable, + &br_sslrec_out_cbc_vtable); +#if BR_AES_X86NI + ienc = br_aes_x86ni_cbcenc_get_vtable(); + idec = br_aes_x86ni_cbcdec_get_vtable(); + if (ienc != NULL && idec != NULL) { + br_ssl_engine_set_aes_cbc(cc, ienc, idec); + return; + } +#endif +#if BR_POWER8 + ienc = br_aes_pwr8_cbcenc_get_vtable(); + idec = br_aes_pwr8_cbcdec_get_vtable(); + if (ienc != NULL && idec != NULL) { + br_ssl_engine_set_aes_cbc(cc, ienc, idec); + return; + } +#endif +#if BR_64 + br_ssl_engine_set_aes_cbc(cc, + &br_aes_ct64_cbcenc_vtable, + &br_aes_ct64_cbcdec_vtable); +#else + br_ssl_engine_set_aes_cbc(cc, + &br_aes_ct_cbcenc_vtable, + &br_aes_ct_cbcdec_vtable); +#endif +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_engine_default_aesccm.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_engine_default_aesccm.c new file mode 100644 index 000000000..e53fd2248 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_engine_default_aesccm.c @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_ssl.h */ +void +br_ssl_engine_set_default_aes_ccm(br_ssl_engine_context *cc) +{ +#if BR_AES_X86NI || BR_POWER8 + const br_block_ctrcbc_class *ictrcbc; +#endif + + br_ssl_engine_set_ccm(cc, + &br_sslrec_in_ccm_vtable, + &br_sslrec_out_ccm_vtable); +#if BR_AES_X86NI + ictrcbc = br_aes_x86ni_ctrcbc_get_vtable(); + if (ictrcbc != NULL) { + br_ssl_engine_set_aes_ctrcbc(cc, ictrcbc); + } else { +#if BR_64 + br_ssl_engine_set_aes_ctrcbc(cc, &br_aes_ct64_ctrcbc_vtable); +#else + br_ssl_engine_set_aes_ctrcbc(cc, &br_aes_ct_ctrcbc_vtable); +#endif + } +#elif BR_POWER8 + ictrcbc = br_aes_pwr8_ctrcbc_get_vtable(); + if (ictrcbc != NULL) { + br_ssl_engine_set_aes_ctrcbc(cc, ictrcbc); + } else { +#if BR_64 + br_ssl_engine_set_aes_ctrcbc(cc, &br_aes_ct64_ctrcbc_vtable); +#else + br_ssl_engine_set_aes_ctrcbc(cc, &br_aes_ct_ctrcbc_vtable); +#endif + } +#else +#if BR_64 + br_ssl_engine_set_aes_ctrcbc(cc, &br_aes_ct64_ctrcbc_vtable); +#else + br_ssl_engine_set_aes_ctrcbc(cc, &br_aes_ct_ctrcbc_vtable); +#endif +#endif +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_engine_default_aesgcm.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_engine_default_aesgcm.c new file mode 100644 index 000000000..c7f011166 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_engine_default_aesgcm.c @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_ssl.h */ +void +br_ssl_engine_set_default_aes_gcm(br_ssl_engine_context *cc) +{ +#if BR_AES_X86NI || BR_POWER8 + const br_block_ctr_class *ictr; + br_ghash ighash; +#endif + + br_ssl_engine_set_gcm(cc, + &br_sslrec_in_gcm_vtable, + &br_sslrec_out_gcm_vtable); +#if BR_AES_X86NI + ictr = br_aes_x86ni_ctr_get_vtable(); + if (ictr != NULL) { + br_ssl_engine_set_aes_ctr(cc, ictr); + } else { +#if BR_64 + br_ssl_engine_set_aes_ctr(cc, &br_aes_ct64_ctr_vtable); +#else + br_ssl_engine_set_aes_ctr(cc, &br_aes_ct_ctr_vtable); +#endif + } +#elif BR_POWER8 + ictr = br_aes_pwr8_ctr_get_vtable(); + if (ictr != NULL) { + br_ssl_engine_set_aes_ctr(cc, ictr); + } else { +#if BR_64 + br_ssl_engine_set_aes_ctr(cc, &br_aes_ct64_ctr_vtable); +#else + br_ssl_engine_set_aes_ctr(cc, &br_aes_ct_ctr_vtable); +#endif + } +#else +#if BR_64 + br_ssl_engine_set_aes_ctr(cc, &br_aes_ct64_ctr_vtable); +#else + br_ssl_engine_set_aes_ctr(cc, &br_aes_ct_ctr_vtable); +#endif +#endif +#if BR_AES_X86NI + ighash = br_ghash_pclmul_get(); + if (ighash != 0) { + br_ssl_engine_set_ghash(cc, ighash); + return; + } +#endif +#if BR_POWER8 + ighash = br_ghash_pwr8_get(); + if (ighash != 0) { + br_ssl_engine_set_ghash(cc, ighash); + return; + } +#endif +#if BR_LOMUL + br_ssl_engine_set_ghash(cc, &br_ghash_ctmul32); +#elif BR_64 + br_ssl_engine_set_ghash(cc, &br_ghash_ctmul64); +#else + br_ssl_engine_set_ghash(cc, &br_ghash_ctmul); +#endif +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_engine_default_chapol.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_engine_default_chapol.c new file mode 100644 index 000000000..17323fa68 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_engine_default_chapol.c @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_ssl.h */ +void +br_ssl_engine_set_default_chapol(br_ssl_engine_context *cc) +{ +#if BR_INT128 || BR_UMUL128 + br_poly1305_run bp; +#endif +#if BR_SSE2 + br_chacha20_run bc; +#endif + + br_ssl_engine_set_chapol(cc, + &br_sslrec_in_chapol_vtable, + &br_sslrec_out_chapol_vtable); +#if BR_SSE2 + bc = br_chacha20_sse2_get(); + if (bc) { + br_ssl_engine_set_chacha20(cc, bc); + } else { +#endif + br_ssl_engine_set_chacha20(cc, &br_chacha20_ct_run); +#if BR_SSE2 + } +#endif +#if BR_INT128 || BR_UMUL128 + bp = br_poly1305_ctmulq_get(); + if (bp) { + br_ssl_engine_set_poly1305(cc, bp); + } else { +#endif +#if BR_LOMUL + br_ssl_engine_set_poly1305(cc, &br_poly1305_ctmul32_run); +#else + br_ssl_engine_set_poly1305(cc, &br_poly1305_ctmul_run); +#endif +#if BR_INT128 || BR_UMUL128 + } +#endif +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_engine_default_descbc.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_engine_default_descbc.c new file mode 100644 index 000000000..5e9963a20 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_engine_default_descbc.c @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_ssl.h */ +void +br_ssl_engine_set_default_des_cbc(br_ssl_engine_context *cc) +{ + br_ssl_engine_set_cbc(cc, + &br_sslrec_in_cbc_vtable, + &br_sslrec_out_cbc_vtable); + br_ssl_engine_set_des_cbc(cc, + &br_des_ct_cbcenc_vtable, + &br_des_ct_cbcdec_vtable); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_engine_default_ec.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_engine_default_ec.c new file mode 100644 index 000000000..770a4c350 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_engine_default_ec.c @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_ssl.h */ +void +br_ssl_engine_set_default_ec(br_ssl_engine_context *cc) +{ +#if BR_LOMUL + br_ssl_engine_set_ec(cc, &br_ec_all_m15); +#else + br_ssl_engine_set_ec(cc, &br_ec_all_m31); +#endif +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_engine_default_ecdsa.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_engine_default_ecdsa.c new file mode 100644 index 000000000..daffe66b8 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_engine_default_ecdsa.c @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_ssl.h */ +void +br_ssl_engine_set_default_ecdsa(br_ssl_engine_context *cc) +{ +#if BR_LOMUL + br_ssl_engine_set_ec(cc, &br_ec_all_m15); + br_ssl_engine_set_ecdsa(cc, &br_ecdsa_i15_vrfy_asn1); +#else + br_ssl_engine_set_ec(cc, &br_ec_all_m31); + br_ssl_engine_set_ecdsa(cc, &br_ecdsa_i31_vrfy_asn1); +#endif +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_engine_default_rsavrfy.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_engine_default_rsavrfy.c new file mode 100644 index 000000000..0dbf1e77a --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_engine_default_rsavrfy.c @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_ssl.h */ +void +br_ssl_engine_set_default_rsavrfy(br_ssl_engine_context *cc) +{ + br_ssl_engine_set_rsavrfy(cc, br_rsa_pkcs1_vrfy_get_default()); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_hashes.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_hashes.c new file mode 100644 index 000000000..3db0be4e4 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_hashes.c @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see inner.h */ +int +br_ssl_choose_hash(unsigned bf) +{ + static const unsigned char pref[] = { + br_sha256_ID, br_sha384_ID, br_sha512_ID, + br_sha224_ID, br_sha1_ID + }; + size_t u; + + for (u = 0; u < sizeof pref; u ++) { + int x; + + x = pref[u]; + if ((bf >> x) & 1) { + return x; + } + } + return 0; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_hs_client.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_hs_client.c new file mode 100644 index 000000000..2f2cbab7a --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_hs_client.c @@ -0,0 +1,1921 @@ +/* Automatically generated code; do not modify directly. */ + + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include +#include + +typedef struct { + uint32_t *dp; + uint32_t *rp; + const unsigned char *ip; +} t0_context; + +static uint32_t +t0_parse7E_unsigned(const unsigned char **p) +{ + uint32_t x; + + x = 0; + for (;;) { + unsigned y; + + y = *(*p) ++; + x = (x << 7) | (uint32_t)(y & 0x7F); + if (y < 0x80) { + return x; + } + } +} + +static int32_t +t0_parse7E_signed(const unsigned char **p) +{ + int neg; + uint32_t x; + + neg = ((**p) >> 6) & 1; + x = (uint32_t)-neg; + for (;;) { + unsigned y; + + y = *(*p) ++; + x = (x << 7) | (uint32_t)(y & 0x7F); + if (y < 0x80) { + if (neg) { + return -(int32_t)~x - 1; + } else { + return (int32_t)x; + } + } + } +} + +#define T0_VBYTE(x, n) (unsigned char)((((uint32_t)(x) >> (n)) & 0x7F) | 0x80) +#define T0_FBYTE(x, n) (unsigned char)(((uint32_t)(x) >> (n)) & 0x7F) +#define T0_SBYTE(x) (unsigned char)((((uint32_t)(x) >> 28) + 0xF8) ^ 0xF8) +#define T0_INT1(x) T0_FBYTE(x, 0) +#define T0_INT2(x) T0_VBYTE(x, 7), T0_FBYTE(x, 0) +#define T0_INT3(x) T0_VBYTE(x, 14), T0_VBYTE(x, 7), T0_FBYTE(x, 0) +#define T0_INT4(x) T0_VBYTE(x, 21), T0_VBYTE(x, 14), T0_VBYTE(x, 7), T0_FBYTE(x, 0) +#define T0_INT5(x) T0_SBYTE(x), T0_VBYTE(x, 21), T0_VBYTE(x, 14), T0_VBYTE(x, 7), T0_FBYTE(x, 0) + +/* static const unsigned char t0_datablock[]; */ + + +void br_ssl_hs_client_init_main(void *t0ctx); + +void br_ssl_hs_client_run(void *t0ctx); + + + +#include +#include + +#include "inner.h" + +/* + * This macro evaluates to a pointer to the current engine context. + */ +#define ENG ((br_ssl_engine_context *)(void *)((unsigned char *)t0ctx - offsetof(br_ssl_engine_context, cpu))) + + + + + +/* + * This macro evaluates to a pointer to the client context, under that + * specific name. It must be noted that since the engine context is the + * first field of the br_ssl_client_context structure ('eng'), then + * pointers values of both types are interchangeable, modulo an + * appropriate cast. This also means that "addresses" computed as offsets + * within the structure work for both kinds of context. + */ +#define CTX ((br_ssl_client_context *)ENG) + +/* + * Generate the pre-master secret for RSA key exchange, and encrypt it + * with the server's public key. Returned value is either the encrypted + * data length (in bytes), or -x on error, with 'x' being an error code. + * + * This code assumes that the public key has been already verified (it + * was properly obtained by the X.509 engine, and it has the right type, + * i.e. it is of type RSA and suitable for encryption). + */ +static int +make_pms_rsa(br_ssl_client_context *ctx, int prf_id) +{ + const br_x509_class **xc; + const br_x509_pkey *pk; + const unsigned char *n; + unsigned char *pms; + size_t nlen, u; + + xc = ctx->eng.x509ctx; + pk = (*xc)->get_pkey(xc, NULL); + + /* + * Compute actual RSA key length, in case there are leading zeros. + */ + n = pk->key.rsa.n; + nlen = pk->key.rsa.nlen; + while (nlen > 0 && *n == 0) { + n ++; + nlen --; + } + + /* + * We need at least 59 bytes (48 bytes for pre-master secret, and + * 11 bytes for the PKCS#1 type 2 padding). Note that the X.509 + * minimal engine normally blocks RSA keys shorter than 128 bytes, + * so this is mostly for public keys provided explicitly by the + * caller. + */ + if (nlen < 59) { + return -BR_ERR_X509_WEAK_PUBLIC_KEY; + } + if (nlen > sizeof ctx->eng.pad) { + return -BR_ERR_LIMIT_EXCEEDED; + } + + /* + * Make PMS. + */ + pms = ctx->eng.pad + nlen - 48; + br_enc16be(pms, ctx->eng.version_max); + br_hmac_drbg_generate(&ctx->eng.rng, pms + 2, 46); + br_ssl_engine_compute_master(&ctx->eng, prf_id, pms, 48); + + /* + * Apply PKCS#1 type 2 padding. + */ + ctx->eng.pad[0] = 0x00; + ctx->eng.pad[1] = 0x02; + ctx->eng.pad[nlen - 49] = 0x00; + br_hmac_drbg_generate(&ctx->eng.rng, ctx->eng.pad + 2, nlen - 51); + for (u = 2; u < nlen - 49; u ++) { + while (ctx->eng.pad[u] == 0) { + br_hmac_drbg_generate(&ctx->eng.rng, + &ctx->eng.pad[u], 1); + } + } + + /* + * Compute RSA encryption. + */ + if (!ctx->irsapub(ctx->eng.pad, nlen, &pk->key.rsa)) { + return -BR_ERR_LIMIT_EXCEEDED; + } + return (int)nlen; +} + +/* + * OID for hash functions in RSA signatures. + */ +static const unsigned char *HASH_OID[] = { + BR_HASH_OID_SHA1, + BR_HASH_OID_SHA224, + BR_HASH_OID_SHA256, + BR_HASH_OID_SHA384, + BR_HASH_OID_SHA512 +}; + +/* + * Check the RSA signature on the ServerKeyExchange message. + * + * hash hash function ID (2 to 6), or 0 for MD5+SHA-1 (with RSA only) + * use_rsa non-zero for RSA signature, zero for ECDSA + * sig_len signature length (in bytes); signature value is in the pad + * + * Returned value is 0 on success, or an error code. + */ +static int +verify_SKE_sig(br_ssl_client_context *ctx, + int hash, int use_rsa, size_t sig_len) +{ + const br_x509_class **xc; + const br_x509_pkey *pk; + br_multihash_context mhc; + unsigned char hv[64], head[4]; + size_t hv_len; + + xc = ctx->eng.x509ctx; + pk = (*xc)->get_pkey(xc, NULL); + br_multihash_zero(&mhc); + br_multihash_copyimpl(&mhc, &ctx->eng.mhash); + br_multihash_init(&mhc); + br_multihash_update(&mhc, + ctx->eng.client_random, sizeof ctx->eng.client_random); + br_multihash_update(&mhc, + ctx->eng.server_random, sizeof ctx->eng.server_random); + head[0] = 3; + head[1] = 0; + head[2] = ctx->eng.ecdhe_curve; + head[3] = ctx->eng.ecdhe_point_len; + br_multihash_update(&mhc, head, sizeof head); + br_multihash_update(&mhc, + ctx->eng.ecdhe_point, ctx->eng.ecdhe_point_len); + if (hash) { + hv_len = br_multihash_out(&mhc, hash, hv); + if (hv_len == 0) { + return BR_ERR_INVALID_ALGORITHM; + } + } else { + if (!br_multihash_out(&mhc, br_md5_ID, hv) + || !br_multihash_out(&mhc, br_sha1_ID, hv + 16)) + { + return BR_ERR_INVALID_ALGORITHM; + } + hv_len = 36; + } + if (use_rsa) { + unsigned char tmp[64]; + const unsigned char *hash_oid; + + if (hash) { + hash_oid = HASH_OID[hash - 2]; + } else { + hash_oid = NULL; + } + if (!ctx->eng.irsavrfy(ctx->eng.pad, sig_len, + hash_oid, hv_len, &pk->key.rsa, tmp) + || memcmp(tmp, hv, hv_len) != 0) + { + return BR_ERR_BAD_SIGNATURE; + } + } else { + if (!ctx->eng.iecdsa(ctx->eng.iec, hv, hv_len, &pk->key.ec, + ctx->eng.pad, sig_len)) + { + return BR_ERR_BAD_SIGNATURE; + } + } + return 0; +} + +/* + * Perform client-side ECDH (or ECDHE). The point that should be sent to + * the server is written in the pad; returned value is either the point + * length (in bytes), or -x on error, with 'x' being an error code. + * + * The point _from_ the server is taken from ecdhe_point[] if 'ecdhe' + * is non-zero, or from the X.509 engine context if 'ecdhe' is zero + * (for static ECDH). + */ +static int +make_pms_ecdh(br_ssl_client_context *ctx, unsigned ecdhe, int prf_id) +{ + int curve; + unsigned char key[66], point[133]; + const unsigned char *order, *point_src; + size_t glen, olen, point_len, xoff, xlen; + unsigned char mask; + + if (ecdhe) { + curve = ctx->eng.ecdhe_curve; + point_src = ctx->eng.ecdhe_point; + point_len = ctx->eng.ecdhe_point_len; + } else { + const br_x509_class **xc; + const br_x509_pkey *pk; + + xc = ctx->eng.x509ctx; + pk = (*xc)->get_pkey(xc, NULL); + curve = pk->key.ec.curve; + point_src = pk->key.ec.q; + point_len = pk->key.ec.qlen; + } + if ((ctx->eng.iec->supported_curves & ((uint32_t)1 << curve)) == 0) { + return -BR_ERR_INVALID_ALGORITHM; + } + + /* + * We need to generate our key, as a non-zero random value which + * is lower than the curve order, in a "large enough" range. We + * force top bit to 0 and bottom bit to 1, which guarantees that + * the value is in the proper range. + */ + order = ctx->eng.iec->order(curve, &olen); + mask = 0xFF; + while (mask >= order[0]) { + mask >>= 1; + } + br_hmac_drbg_generate(&ctx->eng.rng, key, olen); + key[0] &= mask; + key[olen - 1] |= 0x01; + + /* + * Compute the common ECDH point, whose X coordinate is the + * pre-master secret. + */ + ctx->eng.iec->generator(curve, &glen); + if (glen != point_len) { + return -BR_ERR_INVALID_ALGORITHM; + } + + memcpy(point, point_src, glen); + if (!ctx->eng.iec->mul(point, glen, key, olen, curve)) { + return -BR_ERR_INVALID_ALGORITHM; + } + + /* + * The pre-master secret is the X coordinate. + */ + xoff = ctx->eng.iec->xoff(curve, &xlen); + br_ssl_engine_compute_master(&ctx->eng, prf_id, point + xoff, xlen); + + ctx->eng.iec->mulgen(point, key, olen, curve); + memcpy(ctx->eng.pad, point, glen); + return (int)glen; +} + +/* + * Perform full static ECDH. This occurs only in the context of client + * authentication with certificates: the server uses an EC public key, + * the cipher suite is of type ECDH (not ECDHE), the server requested a + * client certificate and accepts static ECDH, the client has a + * certificate with an EC public key in the same curve, and accepts + * static ECDH as well. + * + * Returned value is 0 on success, -1 on error. + */ +static int +make_pms_static_ecdh(br_ssl_client_context *ctx, int prf_id) +{ + unsigned char point[133]; + size_t point_len; + const br_x509_class **xc; + const br_x509_pkey *pk; + + xc = ctx->eng.x509ctx; + pk = (*xc)->get_pkey(xc, NULL); + point_len = pk->key.ec.qlen; + if (point_len > sizeof point) { + return -1; + } + memcpy(point, pk->key.ec.q, point_len); + if (!(*ctx->client_auth_vtable)->do_keyx( + ctx->client_auth_vtable, point, &point_len)) + { + return -1; + } + br_ssl_engine_compute_master(&ctx->eng, + prf_id, point, point_len); + return 0; +} + +/* + * Compute the client-side signature. This is invoked only when a + * signature-based client authentication was selected. The computed + * signature is in the pad; its length (in bytes) is returned. On + * error, 0 is returned. + */ +static size_t +make_client_sign(br_ssl_client_context *ctx) +{ + size_t hv_len; + + /* + * Compute hash of handshake messages so far. This "cannot" fail + * because the list of supported hash functions provided to the + * client certificate handler was trimmed to include only the + * hash functions that the multi-hasher supports. + */ + if (ctx->hash_id) { + hv_len = br_multihash_out(&ctx->eng.mhash, + ctx->hash_id, ctx->eng.pad); + } else { + br_multihash_out(&ctx->eng.mhash, + br_md5_ID, ctx->eng.pad); + br_multihash_out(&ctx->eng.mhash, + br_sha1_ID, ctx->eng.pad + 16); + hv_len = 36; + } + return (*ctx->client_auth_vtable)->do_sign( + ctx->client_auth_vtable, ctx->hash_id, hv_len, + ctx->eng.pad, sizeof ctx->eng.pad); +} + + + +static const unsigned char t0_datablock[] = { + 0x00, 0x00, 0x0A, 0x00, 0x24, 0x00, 0x2F, 0x01, 0x24, 0x00, 0x35, 0x02, + 0x24, 0x00, 0x3C, 0x01, 0x44, 0x00, 0x3D, 0x02, 0x44, 0x00, 0x9C, 0x03, + 0x04, 0x00, 0x9D, 0x04, 0x05, 0xC0, 0x03, 0x40, 0x24, 0xC0, 0x04, 0x41, + 0x24, 0xC0, 0x05, 0x42, 0x24, 0xC0, 0x08, 0x20, 0x24, 0xC0, 0x09, 0x21, + 0x24, 0xC0, 0x0A, 0x22, 0x24, 0xC0, 0x0D, 0x30, 0x24, 0xC0, 0x0E, 0x31, + 0x24, 0xC0, 0x0F, 0x32, 0x24, 0xC0, 0x12, 0x10, 0x24, 0xC0, 0x13, 0x11, + 0x24, 0xC0, 0x14, 0x12, 0x24, 0xC0, 0x23, 0x21, 0x44, 0xC0, 0x24, 0x22, + 0x55, 0xC0, 0x25, 0x41, 0x44, 0xC0, 0x26, 0x42, 0x55, 0xC0, 0x27, 0x11, + 0x44, 0xC0, 0x28, 0x12, 0x55, 0xC0, 0x29, 0x31, 0x44, 0xC0, 0x2A, 0x32, + 0x55, 0xC0, 0x2B, 0x23, 0x04, 0xC0, 0x2C, 0x24, 0x05, 0xC0, 0x2D, 0x43, + 0x04, 0xC0, 0x2E, 0x44, 0x05, 0xC0, 0x2F, 0x13, 0x04, 0xC0, 0x30, 0x14, + 0x05, 0xC0, 0x31, 0x33, 0x04, 0xC0, 0x32, 0x34, 0x05, 0xC0, 0x9C, 0x06, + 0x04, 0xC0, 0x9D, 0x07, 0x04, 0xC0, 0xA0, 0x08, 0x04, 0xC0, 0xA1, 0x09, + 0x04, 0xC0, 0xAC, 0x26, 0x04, 0xC0, 0xAD, 0x27, 0x04, 0xC0, 0xAE, 0x28, + 0x04, 0xC0, 0xAF, 0x29, 0x04, 0xCC, 0xA8, 0x15, 0x04, 0xCC, 0xA9, 0x25, + 0x04, 0x00, 0x00 +}; + +static const unsigned char t0_codeblock[] = { + 0x00, 0x01, 0x00, 0x0A, 0x00, 0x00, 0x01, 0x00, 0x0D, 0x00, 0x00, 0x01, + 0x00, 0x0E, 0x00, 0x00, 0x01, 0x00, 0x0F, 0x00, 0x00, 0x01, 0x01, 0x08, + 0x00, 0x00, 0x01, 0x01, 0x09, 0x00, 0x00, 0x01, 0x02, 0x08, 0x00, 0x00, + 0x01, 0x02, 0x09, 0x00, 0x00, 0x25, 0x25, 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_BAD_CCS), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_BAD_CIPHER_SUITE), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_BAD_COMPRESSION), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_BAD_FINISHED), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_BAD_FRAGLEN), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_BAD_HANDSHAKE), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_BAD_HELLO_DONE), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_BAD_PARAM), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_BAD_SECRENEG), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_BAD_SNI), 0x00, 0x00, 0x01, T0_INT1(BR_ERR_BAD_VERSION), + 0x00, 0x00, 0x01, T0_INT1(BR_ERR_EXTRA_EXTENSION), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_INVALID_ALGORITHM), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_LIMIT_EXCEEDED), 0x00, 0x00, 0x01, T0_INT1(BR_ERR_OK), + 0x00, 0x00, 0x01, T0_INT1(BR_ERR_OVERSIZED_ID), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_RESUME_MISMATCH), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_UNEXPECTED), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_UNSUPPORTED_VERSION), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_WRONG_KEY_USAGE), 0x00, 0x00, 0x01, + T0_INT2(offsetof(br_ssl_engine_context, action)), 0x00, 0x00, 0x01, + T0_INT2(offsetof(br_ssl_engine_context, alert)), 0x00, 0x00, 0x01, + T0_INT2(offsetof(br_ssl_engine_context, application_data)), 0x00, 0x00, + 0x01, T0_INT2(offsetof(br_ssl_client_context, auth_type)), 0x00, 0x00, + 0x01, + T0_INT2(offsetof(br_ssl_engine_context, session) + offsetof(br_ssl_session_parameters, cipher_suite)), + 0x00, 0x00, 0x01, + T0_INT2(offsetof(br_ssl_engine_context, client_random)), 0x00, 0x00, + 0x01, T0_INT2(offsetof(br_ssl_engine_context, close_received)), 0x00, + 0x00, 0x01, T0_INT2(offsetof(br_ssl_engine_context, ecdhe_curve)), + 0x00, 0x00, 0x01, + T0_INT2(offsetof(br_ssl_engine_context, ecdhe_point)), 0x00, 0x00, + 0x01, T0_INT2(offsetof(br_ssl_engine_context, ecdhe_point_len)), 0x00, + 0x00, 0x01, T0_INT2(offsetof(br_ssl_engine_context, flags)), 0x00, + 0x00, 0x01, T0_INT2(offsetof(br_ssl_client_context, hash_id)), 0x00, + 0x00, 0x01, T0_INT2(offsetof(br_ssl_client_context, hashes)), 0x00, + 0x00, 0x01, T0_INT2(offsetof(br_ssl_engine_context, log_max_frag_len)), + 0x00, 0x00, 0x01, + T0_INT2(offsetof(br_ssl_client_context, min_clienthello_len)), 0x00, + 0x00, 0x01, T0_INT2(offsetof(br_ssl_engine_context, pad)), 0x00, 0x00, + 0x01, T0_INT2(offsetof(br_ssl_engine_context, protocol_names_num)), + 0x00, 0x00, 0x01, + T0_INT2(offsetof(br_ssl_engine_context, record_type_in)), 0x00, 0x00, + 0x01, T0_INT2(offsetof(br_ssl_engine_context, record_type_out)), 0x00, + 0x00, 0x01, T0_INT2(offsetof(br_ssl_engine_context, reneg)), 0x00, + 0x00, 0x01, T0_INT2(offsetof(br_ssl_engine_context, saved_finished)), + 0x00, 0x00, 0x01, + T0_INT2(offsetof(br_ssl_engine_context, selected_protocol)), 0x00, + 0x00, 0x01, T0_INT2(offsetof(br_ssl_engine_context, server_name)), + 0x00, 0x00, 0x01, + T0_INT2(offsetof(br_ssl_engine_context, server_random)), 0x00, 0x00, + 0x01, + T0_INT2(offsetof(br_ssl_engine_context, session) + offsetof(br_ssl_session_parameters, session_id)), + 0x00, 0x00, 0x01, + T0_INT2(offsetof(br_ssl_engine_context, session) + offsetof(br_ssl_session_parameters, session_id_len)), + 0x00, 0x00, 0x01, + T0_INT2(offsetof(br_ssl_engine_context, shutdown_recv)), 0x00, 0x00, + 0x01, T0_INT2(offsetof(br_ssl_engine_context, suites_buf)), 0x00, 0x00, + 0x01, T0_INT2(offsetof(br_ssl_engine_context, suites_num)), 0x00, 0x00, + 0x01, + T0_INT2(offsetof(br_ssl_engine_context, session) + offsetof(br_ssl_session_parameters, version)), + 0x00, 0x00, 0x01, T0_INT2(offsetof(br_ssl_engine_context, version_in)), + 0x00, 0x00, 0x01, + T0_INT2(offsetof(br_ssl_engine_context, version_max)), 0x00, 0x00, + 0x01, T0_INT2(offsetof(br_ssl_engine_context, version_min)), 0x00, + 0x00, 0x01, T0_INT2(offsetof(br_ssl_engine_context, version_out)), + 0x00, 0x00, 0x09, 0x26, 0x58, 0x06, 0x02, 0x68, 0x28, 0x00, 0x00, 0x06, + 0x08, 0x2C, 0x0E, 0x05, 0x02, 0x71, 0x28, 0x04, 0x01, 0x3C, 0x00, 0x00, + 0x01, 0x01, 0x00, 0x01, 0x03, 0x00, 0x99, 0x26, 0x5E, 0x44, 0x9D, 0x26, + 0x05, 0x04, 0x60, 0x01, 0x00, 0x00, 0x02, 0x00, 0x0E, 0x06, 0x02, 0x9D, + 0x00, 0x5E, 0x04, 0x6B, 0x00, 0x06, 0x02, 0x68, 0x28, 0x00, 0x00, 0x26, + 0x89, 0x44, 0x05, 0x03, 0x01, 0x0C, 0x08, 0x44, 0x79, 0x2C, 0xAB, 0x1C, + 0x84, 0x01, 0x0C, 0x31, 0x00, 0x00, 0x26, 0x1F, 0x01, 0x08, 0x0B, 0x44, + 0x5C, 0x1F, 0x08, 0x00, 0x01, 0x03, 0x00, 0x77, 0x2E, 0x02, 0x00, 0x36, + 0x17, 0x01, 0x01, 0x0B, 0x77, 0x3E, 0x29, 0x1A, 0x36, 0x06, 0x07, 0x02, + 0x00, 0xCF, 0x03, 0x00, 0x04, 0x75, 0x01, 0x00, 0xC5, 0x02, 0x00, 0x26, + 0x1A, 0x17, 0x06, 0x02, 0x6F, 0x28, 0xCF, 0x04, 0x76, 0x01, 0x01, 0x00, + 0x77, 0x3E, 0x01, 0x16, 0x87, 0x3E, 0x01, 0x00, 0x8A, 0x3C, 0x34, 0xD5, + 0x29, 0xB4, 0x06, 0x09, 0x01, 0x7F, 0xAF, 0x01, 0x7F, 0xD2, 0x04, 0x80, + 0x53, 0xB1, 0x79, 0x2C, 0xA1, 0x01, T0_INT1(BR_KEYTYPE_SIGN), 0x17, + 0x06, 0x01, 0xB5, 0xB8, 0x26, 0x01, 0x0D, 0x0E, 0x06, 0x07, 0x25, 0xB7, + 0xB8, 0x01, 0x7F, 0x04, 0x02, 0x01, 0x00, 0x03, 0x00, 0x01, 0x0E, 0x0E, + 0x05, 0x02, 0x72, 0x28, 0x06, 0x02, 0x67, 0x28, 0x33, 0x06, 0x02, 0x72, + 0x28, 0x02, 0x00, 0x06, 0x1C, 0xD3, 0x80, 0x2E, 0x01, 0x81, 0x7F, 0x0E, + 0x06, 0x0D, 0x25, 0x01, 0x10, 0xDE, 0x01, 0x00, 0xDD, 0x79, 0x2C, 0xAB, + 0x24, 0x04, 0x04, 0xD6, 0x06, 0x01, 0xD4, 0x04, 0x01, 0xD6, 0x01, 0x7F, + 0xD2, 0x01, 0x7F, 0xAF, 0x01, 0x01, 0x77, 0x3E, 0x01, 0x17, 0x87, 0x3E, + 0x00, 0x00, 0x38, 0x38, 0x00, 0x00, 0x9A, 0x01, 0x0C, 0x11, 0x01, 0x00, + 0x38, 0x0E, 0x06, 0x05, 0x25, 0x01, + T0_INT1(BR_KEYTYPE_RSA | BR_KEYTYPE_KEYX), 0x04, 0x30, 0x01, 0x01, + 0x38, 0x0E, 0x06, 0x05, 0x25, 0x01, + T0_INT1(BR_KEYTYPE_RSA | BR_KEYTYPE_SIGN), 0x04, 0x25, 0x01, 0x02, + 0x38, 0x0E, 0x06, 0x05, 0x25, 0x01, + T0_INT1(BR_KEYTYPE_EC | BR_KEYTYPE_SIGN), 0x04, 0x1A, 0x01, 0x03, + 0x38, 0x0E, 0x06, 0x05, 0x25, 0x01, + T0_INT1(BR_KEYTYPE_EC | BR_KEYTYPE_KEYX), 0x04, 0x0F, 0x01, 0x04, + 0x38, 0x0E, 0x06, 0x05, 0x25, 0x01, + T0_INT1(BR_KEYTYPE_EC | BR_KEYTYPE_KEYX), 0x04, 0x04, 0x01, 0x00, + 0x44, 0x25, 0x00, 0x00, 0x82, 0x2E, 0x01, 0x0E, 0x0E, 0x06, 0x04, 0x01, + 0x00, 0x04, 0x02, 0x01, 0x05, 0x00, 0x00, 0x40, 0x06, 0x04, 0x01, 0x06, + 0x04, 0x02, 0x01, 0x00, 0x00, 0x00, 0x88, 0x2E, 0x26, 0x06, 0x08, 0x01, + 0x01, 0x09, 0x01, 0x11, 0x07, 0x04, 0x03, 0x25, 0x01, 0x05, 0x00, 0x01, + 0x41, 0x03, 0x00, 0x25, 0x01, 0x00, 0x43, 0x06, 0x03, 0x02, 0x00, 0x08, + 0x42, 0x06, 0x03, 0x02, 0x00, 0x08, 0x26, 0x06, 0x06, 0x01, 0x01, 0x0B, + 0x01, 0x06, 0x08, 0x00, 0x00, 0x8B, 0x3F, 0x26, 0x06, 0x03, 0x01, 0x09, + 0x08, 0x00, 0x01, 0x40, 0x26, 0x06, 0x1E, 0x01, 0x00, 0x03, 0x00, 0x26, + 0x06, 0x0E, 0x26, 0x01, 0x01, 0x17, 0x02, 0x00, 0x08, 0x03, 0x00, 0x01, + 0x01, 0x11, 0x04, 0x6F, 0x25, 0x02, 0x00, 0x01, 0x01, 0x0B, 0x01, 0x06, + 0x08, 0x00, 0x00, 0x7F, 0x2D, 0x44, 0x11, 0x01, 0x01, 0x17, 0x35, 0x00, + 0x00, 0x9F, 0xCE, 0x26, 0x01, 0x07, 0x17, 0x01, 0x00, 0x38, 0x0E, 0x06, + 0x09, 0x25, 0x01, 0x10, 0x17, 0x06, 0x01, 0x9F, 0x04, 0x35, 0x01, 0x01, + 0x38, 0x0E, 0x06, 0x2C, 0x25, 0x25, 0x01, 0x00, 0x77, 0x3E, 0xB3, 0x88, + 0x2E, 0x01, 0x01, 0x0E, 0x01, 0x01, 0xA8, 0x37, 0x06, 0x17, 0x29, 0x1A, + 0x36, 0x06, 0x04, 0xCE, 0x25, 0x04, 0x78, 0x01, 0x80, 0x64, 0xC5, 0x01, + 0x01, 0x77, 0x3E, 0x01, 0x17, 0x87, 0x3E, 0x04, 0x01, 0x9F, 0x04, 0x03, + 0x72, 0x28, 0x25, 0x04, 0xFF, 0x34, 0x01, 0x26, 0x03, 0x00, 0x09, 0x26, + 0x58, 0x06, 0x02, 0x68, 0x28, 0x02, 0x00, 0x00, 0x00, 0x9A, 0x01, 0x0F, + 0x17, 0x00, 0x00, 0x76, 0x2E, 0x01, 0x00, 0x38, 0x0E, 0x06, 0x10, 0x25, + 0x26, 0x01, 0x01, 0x0D, 0x06, 0x03, 0x25, 0x01, 0x02, 0x76, 0x3E, 0x01, + 0x00, 0x04, 0x21, 0x01, 0x01, 0x38, 0x0E, 0x06, 0x14, 0x25, 0x01, 0x00, + 0x76, 0x3E, 0x26, 0x01, 0x80, 0x64, 0x0E, 0x06, 0x05, 0x01, 0x82, 0x00, + 0x08, 0x28, 0x5A, 0x04, 0x07, 0x25, 0x01, 0x82, 0x00, 0x08, 0x28, 0x25, + 0x00, 0x00, 0x01, 0x00, 0x2F, 0x06, 0x05, 0x3A, 0xAC, 0x37, 0x04, 0x78, + 0x26, 0x06, 0x04, 0x01, 0x01, 0x8F, 0x3E, 0x00, 0x01, 0xBF, 0xAA, 0xBF, + 0xAA, 0xC1, 0x84, 0x44, 0x26, 0x03, 0x00, 0xB6, 0x9B, 0x9B, 0x02, 0x00, + 0x4D, 0x26, 0x58, 0x06, 0x0A, 0x01, 0x03, 0xA8, 0x06, 0x02, 0x72, 0x28, + 0x25, 0x04, 0x03, 0x5C, 0x8A, 0x3C, 0x00, 0x00, 0x2F, 0x06, 0x0B, 0x86, + 0x2E, 0x01, 0x14, 0x0D, 0x06, 0x02, 0x72, 0x28, 0x04, 0x11, 0xCE, 0x01, + 0x07, 0x17, 0x26, 0x01, 0x02, 0x0D, 0x06, 0x06, 0x06, 0x02, 0x72, 0x28, + 0x04, 0x70, 0x25, 0xC2, 0x01, 0x01, 0x0D, 0x33, 0x37, 0x06, 0x02, 0x61, + 0x28, 0x26, 0x01, 0x01, 0xC8, 0x36, 0xB2, 0x00, 0x01, 0xB8, 0x01, 0x0B, + 0x0E, 0x05, 0x02, 0x72, 0x28, 0x26, 0x01, 0x03, 0x0E, 0x06, 0x08, 0xC0, + 0x06, 0x02, 0x68, 0x28, 0x44, 0x25, 0x00, 0x44, 0x57, 0xC0, 0xAA, 0x26, + 0x06, 0x23, 0xC0, 0xAA, 0x26, 0x56, 0x26, 0x06, 0x18, 0x26, 0x01, 0x82, + 0x00, 0x0F, 0x06, 0x05, 0x01, 0x82, 0x00, 0x04, 0x01, 0x26, 0x03, 0x00, + 0x84, 0x02, 0x00, 0xB6, 0x02, 0x00, 0x53, 0x04, 0x65, 0x9B, 0x54, 0x04, + 0x5A, 0x9B, 0x9B, 0x55, 0x26, 0x06, 0x02, 0x35, 0x00, 0x25, 0x2B, 0x00, + 0x00, 0x79, 0x2C, 0xA1, 0x01, 0x7F, 0xB0, 0x26, 0x58, 0x06, 0x02, 0x35, + 0x28, 0x26, 0x05, 0x02, 0x72, 0x28, 0x38, 0x17, 0x0D, 0x06, 0x02, 0x74, + 0x28, 0x3B, 0x00, 0x00, 0x9C, 0xB8, 0x01, 0x14, 0x0D, 0x06, 0x02, 0x72, + 0x28, 0x84, 0x01, 0x0C, 0x08, 0x01, 0x0C, 0xB6, 0x9B, 0x84, 0x26, 0x01, + 0x0C, 0x08, 0x01, 0x0C, 0x30, 0x05, 0x02, 0x64, 0x28, 0x00, 0x00, 0xB9, + 0x06, 0x02, 0x72, 0x28, 0x06, 0x02, 0x66, 0x28, 0x00, 0x0A, 0xB8, 0x01, + 0x02, 0x0E, 0x05, 0x02, 0x72, 0x28, 0xBF, 0x03, 0x00, 0x02, 0x00, 0x95, + 0x2C, 0x0A, 0x02, 0x00, 0x94, 0x2C, 0x0F, 0x37, 0x06, 0x02, 0x73, 0x28, + 0x02, 0x00, 0x93, 0x2C, 0x0D, 0x06, 0x02, 0x6B, 0x28, 0x02, 0x00, 0x96, + 0x3C, 0x8C, 0x01, 0x20, 0xB6, 0x01, 0x00, 0x03, 0x01, 0xC1, 0x03, 0x02, + 0x02, 0x02, 0x01, 0x20, 0x0F, 0x06, 0x02, 0x70, 0x28, 0x84, 0x02, 0x02, + 0xB6, 0x02, 0x02, 0x8E, 0x2E, 0x0E, 0x02, 0x02, 0x01, 0x00, 0x0F, 0x17, + 0x06, 0x0B, 0x8D, 0x84, 0x02, 0x02, 0x30, 0x06, 0x04, 0x01, 0x7F, 0x03, + 0x01, 0x8D, 0x84, 0x02, 0x02, 0x31, 0x02, 0x02, 0x8E, 0x3E, 0x02, 0x00, + 0x92, 0x02, 0x01, 0x98, 0xBF, 0x26, 0xC3, 0x58, 0x06, 0x02, 0x62, 0x28, + 0x26, 0xCD, 0x02, 0x00, 0x01, 0x86, 0x03, 0x0A, 0x17, 0x06, 0x02, 0x62, + 0x28, 0x79, 0x02, 0x01, 0x98, 0xC1, 0x06, 0x02, 0x63, 0x28, 0x26, 0x06, + 0x81, 0x47, 0xBF, 0xAA, 0xA6, 0x03, 0x03, 0xA4, 0x03, 0x04, 0xA2, 0x03, + 0x05, 0xA5, 0x03, 0x06, 0xA7, 0x03, 0x07, 0xA3, 0x03, 0x08, 0x27, 0x03, + 0x09, 0x26, 0x06, 0x81, 0x18, 0xBF, 0x01, 0x00, 0x38, 0x0E, 0x06, 0x0F, + 0x25, 0x02, 0x03, 0x05, 0x02, 0x6C, 0x28, 0x01, 0x00, 0x03, 0x03, 0xBE, + 0x04, 0x80, 0x7F, 0x01, 0x01, 0x38, 0x0E, 0x06, 0x0F, 0x25, 0x02, 0x05, + 0x05, 0x02, 0x6C, 0x28, 0x01, 0x00, 0x03, 0x05, 0xBC, 0x04, 0x80, 0x6A, + 0x01, 0x83, 0xFE, 0x01, 0x38, 0x0E, 0x06, 0x0F, 0x25, 0x02, 0x04, 0x05, + 0x02, 0x6C, 0x28, 0x01, 0x00, 0x03, 0x04, 0xBD, 0x04, 0x80, 0x53, 0x01, + 0x0D, 0x38, 0x0E, 0x06, 0x0E, 0x25, 0x02, 0x06, 0x05, 0x02, 0x6C, 0x28, + 0x01, 0x00, 0x03, 0x06, 0xBA, 0x04, 0x3F, 0x01, 0x0A, 0x38, 0x0E, 0x06, + 0x0E, 0x25, 0x02, 0x07, 0x05, 0x02, 0x6C, 0x28, 0x01, 0x00, 0x03, 0x07, + 0xBA, 0x04, 0x2B, 0x01, 0x0B, 0x38, 0x0E, 0x06, 0x0E, 0x25, 0x02, 0x08, + 0x05, 0x02, 0x6C, 0x28, 0x01, 0x00, 0x03, 0x08, 0xBA, 0x04, 0x17, 0x01, + 0x10, 0x38, 0x0E, 0x06, 0x0E, 0x25, 0x02, 0x09, 0x05, 0x02, 0x6C, 0x28, + 0x01, 0x00, 0x03, 0x09, 0xAE, 0x04, 0x03, 0x6C, 0x28, 0x25, 0x04, 0xFE, + 0x64, 0x02, 0x04, 0x06, 0x0D, 0x02, 0x04, 0x01, 0x05, 0x0F, 0x06, 0x02, + 0x69, 0x28, 0x01, 0x01, 0x88, 0x3E, 0x9B, 0x04, 0x0C, 0xA4, 0x01, 0x05, + 0x0F, 0x06, 0x02, 0x69, 0x28, 0x01, 0x01, 0x88, 0x3E, 0x9B, 0x02, 0x01, + 0x00, 0x04, 0xB8, 0x01, 0x0C, 0x0E, 0x05, 0x02, 0x72, 0x28, 0xC1, 0x01, + 0x03, 0x0E, 0x05, 0x02, 0x6D, 0x28, 0xBF, 0x26, 0x7C, 0x3E, 0x26, 0x01, + 0x20, 0x10, 0x06, 0x02, 0x6D, 0x28, 0x40, 0x44, 0x11, 0x01, 0x01, 0x17, + 0x05, 0x02, 0x6D, 0x28, 0xC1, 0x26, 0x01, 0x81, 0x05, 0x0F, 0x06, 0x02, + 0x6D, 0x28, 0x26, 0x7E, 0x3E, 0x7D, 0x44, 0xB6, 0x92, 0x2C, 0x01, 0x86, + 0x03, 0x10, 0x03, 0x00, 0x79, 0x2C, 0xCB, 0x03, 0x01, 0x01, 0x02, 0x03, + 0x02, 0x02, 0x00, 0x06, 0x21, 0xC1, 0x26, 0x26, 0x01, 0x02, 0x0A, 0x44, + 0x01, 0x06, 0x0F, 0x37, 0x06, 0x02, 0x6D, 0x28, 0x03, 0x02, 0xC1, 0x02, + 0x01, 0x01, 0x01, 0x0B, 0x01, 0x03, 0x08, 0x0E, 0x05, 0x02, 0x6D, 0x28, + 0x04, 0x08, 0x02, 0x01, 0x06, 0x04, 0x01, 0x00, 0x03, 0x02, 0xBF, 0x26, + 0x03, 0x03, 0x26, 0x01, 0x84, 0x00, 0x0F, 0x06, 0x02, 0x6E, 0x28, 0x84, + 0x44, 0xB6, 0x02, 0x02, 0x02, 0x01, 0x02, 0x03, 0x50, 0x26, 0x06, 0x01, + 0x28, 0x25, 0x9B, 0x00, 0x02, 0x03, 0x00, 0x03, 0x01, 0x02, 0x00, 0x97, + 0x02, 0x01, 0x02, 0x00, 0x39, 0x26, 0x01, 0x00, 0x0E, 0x06, 0x02, 0x60, + 0x00, 0xD0, 0x04, 0x74, 0x02, 0x01, 0x00, 0x03, 0x00, 0xC1, 0xAA, 0x26, + 0x06, 0x80, 0x43, 0xC1, 0x01, 0x01, 0x38, 0x0E, 0x06, 0x06, 0x25, 0x01, + 0x81, 0x7F, 0x04, 0x2E, 0x01, 0x80, 0x40, 0x38, 0x0E, 0x06, 0x07, 0x25, + 0x01, 0x83, 0xFE, 0x00, 0x04, 0x20, 0x01, 0x80, 0x41, 0x38, 0x0E, 0x06, + 0x07, 0x25, 0x01, 0x84, 0x80, 0x00, 0x04, 0x12, 0x01, 0x80, 0x42, 0x38, + 0x0E, 0x06, 0x07, 0x25, 0x01, 0x88, 0x80, 0x00, 0x04, 0x04, 0x01, 0x00, + 0x44, 0x25, 0x02, 0x00, 0x37, 0x03, 0x00, 0x04, 0xFF, 0x39, 0x9B, 0x79, + 0x2C, 0xC9, 0x05, 0x09, 0x02, 0x00, 0x01, 0x83, 0xFF, 0x7F, 0x17, 0x03, + 0x00, 0x92, 0x2C, 0x01, 0x86, 0x03, 0x10, 0x06, 0x3A, 0xBB, 0x26, 0x81, + 0x3D, 0x41, 0x25, 0x26, 0x01, 0x08, 0x0B, 0x37, 0x01, 0x8C, 0x80, 0x00, + 0x37, 0x17, 0x02, 0x00, 0x17, 0x02, 0x00, 0x01, 0x8C, 0x80, 0x00, 0x17, + 0x06, 0x19, 0x26, 0x01, 0x81, 0x7F, 0x17, 0x06, 0x05, 0x01, 0x84, 0x80, + 0x00, 0x37, 0x26, 0x01, 0x83, 0xFE, 0x00, 0x17, 0x06, 0x05, 0x01, 0x88, + 0x80, 0x00, 0x37, 0x03, 0x00, 0x04, 0x09, 0x02, 0x00, 0x01, 0x8C, 0x88, + 0x01, 0x17, 0x03, 0x00, 0x16, 0xBF, 0xAA, 0x26, 0x06, 0x23, 0xBF, 0xAA, + 0x26, 0x15, 0x26, 0x06, 0x18, 0x26, 0x01, 0x82, 0x00, 0x0F, 0x06, 0x05, + 0x01, 0x82, 0x00, 0x04, 0x01, 0x26, 0x03, 0x01, 0x84, 0x02, 0x01, 0xB6, + 0x02, 0x01, 0x12, 0x04, 0x65, 0x9B, 0x13, 0x04, 0x5A, 0x9B, 0x14, 0x9B, + 0x02, 0x00, 0x2A, 0x00, 0x00, 0xB9, 0x26, 0x5A, 0x06, 0x07, 0x25, 0x06, + 0x02, 0x66, 0x28, 0x04, 0x74, 0x00, 0x00, 0xC2, 0x01, 0x03, 0xC0, 0x44, + 0x25, 0x44, 0x00, 0x00, 0xBF, 0xC6, 0x00, 0x03, 0x01, 0x00, 0x03, 0x00, + 0xBF, 0xAA, 0x26, 0x06, 0x80, 0x50, 0xC1, 0x03, 0x01, 0xC1, 0x03, 0x02, + 0x02, 0x01, 0x01, 0x08, 0x0E, 0x06, 0x16, 0x02, 0x02, 0x01, 0x0F, 0x0C, + 0x06, 0x0D, 0x01, 0x01, 0x02, 0x02, 0x01, 0x10, 0x08, 0x0B, 0x02, 0x00, + 0x37, 0x03, 0x00, 0x04, 0x2A, 0x02, 0x01, 0x01, 0x02, 0x10, 0x02, 0x01, + 0x01, 0x06, 0x0C, 0x17, 0x02, 0x02, 0x01, 0x01, 0x0E, 0x02, 0x02, 0x01, + 0x03, 0x0E, 0x37, 0x17, 0x06, 0x11, 0x02, 0x00, 0x01, 0x01, 0x02, 0x02, + 0x5D, 0x01, 0x02, 0x0B, 0x02, 0x01, 0x08, 0x0B, 0x37, 0x03, 0x00, 0x04, + 0xFF, 0x2C, 0x9B, 0x02, 0x00, 0x00, 0x00, 0xBF, 0x01, 0x01, 0x0E, 0x05, + 0x02, 0x65, 0x28, 0xC1, 0x01, 0x08, 0x08, 0x82, 0x2E, 0x0E, 0x05, 0x02, + 0x65, 0x28, 0x00, 0x00, 0xBF, 0x88, 0x2E, 0x05, 0x15, 0x01, 0x01, 0x0E, + 0x05, 0x02, 0x69, 0x28, 0xC1, 0x01, 0x00, 0x0E, 0x05, 0x02, 0x69, 0x28, + 0x01, 0x02, 0x88, 0x3E, 0x04, 0x1C, 0x01, 0x19, 0x0E, 0x05, 0x02, 0x69, + 0x28, 0xC1, 0x01, 0x18, 0x0E, 0x05, 0x02, 0x69, 0x28, 0x84, 0x01, 0x18, + 0xB6, 0x89, 0x84, 0x01, 0x18, 0x30, 0x05, 0x02, 0x69, 0x28, 0x00, 0x00, + 0xBF, 0x06, 0x02, 0x6A, 0x28, 0x00, 0x00, 0x01, 0x02, 0x97, 0xC2, 0x01, + 0x08, 0x0B, 0xC2, 0x08, 0x00, 0x00, 0x01, 0x03, 0x97, 0xC2, 0x01, 0x08, + 0x0B, 0xC2, 0x08, 0x01, 0x08, 0x0B, 0xC2, 0x08, 0x00, 0x00, 0x01, 0x01, + 0x97, 0xC2, 0x00, 0x00, 0x3A, 0x26, 0x58, 0x05, 0x01, 0x00, 0x25, 0xD0, + 0x04, 0x76, 0x02, 0x03, 0x00, 0x91, 0x2E, 0x03, 0x01, 0x01, 0x00, 0x26, + 0x02, 0x01, 0x0A, 0x06, 0x10, 0x26, 0x01, 0x01, 0x0B, 0x90, 0x08, 0x2C, + 0x02, 0x00, 0x0E, 0x06, 0x01, 0x00, 0x5C, 0x04, 0x6A, 0x25, 0x01, 0x7F, + 0x00, 0x00, 0x01, 0x15, 0x87, 0x3E, 0x44, 0x52, 0x25, 0x52, 0x25, 0x29, + 0x00, 0x00, 0x01, 0x01, 0x44, 0xC4, 0x00, 0x00, 0x44, 0x38, 0x97, 0x44, + 0x26, 0x06, 0x05, 0xC2, 0x25, 0x5D, 0x04, 0x78, 0x25, 0x00, 0x00, 0x26, + 0x01, 0x81, 0xAC, 0x00, 0x0E, 0x06, 0x04, 0x25, 0x01, 0x7F, 0x00, 0x9A, + 0x59, 0x00, 0x02, 0x03, 0x00, 0x79, 0x2C, 0x9A, 0x03, 0x01, 0x02, 0x01, + 0x01, 0x0F, 0x17, 0x02, 0x01, 0x01, 0x04, 0x11, 0x01, 0x0F, 0x17, 0x02, + 0x01, 0x01, 0x08, 0x11, 0x01, 0x0F, 0x17, 0x01, 0x00, 0x38, 0x0E, 0x06, + 0x10, 0x25, 0x01, 0x00, 0x01, 0x18, 0x02, 0x00, 0x06, 0x03, 0x49, 0x04, + 0x01, 0x4A, 0x04, 0x81, 0x0D, 0x01, 0x01, 0x38, 0x0E, 0x06, 0x10, 0x25, + 0x01, 0x01, 0x01, 0x10, 0x02, 0x00, 0x06, 0x03, 0x49, 0x04, 0x01, 0x4A, + 0x04, 0x80, 0x77, 0x01, 0x02, 0x38, 0x0E, 0x06, 0x10, 0x25, 0x01, 0x01, + 0x01, 0x20, 0x02, 0x00, 0x06, 0x03, 0x49, 0x04, 0x01, 0x4A, 0x04, 0x80, + 0x61, 0x01, 0x03, 0x38, 0x0E, 0x06, 0x0F, 0x25, 0x25, 0x01, 0x10, 0x02, + 0x00, 0x06, 0x03, 0x47, 0x04, 0x01, 0x48, 0x04, 0x80, 0x4C, 0x01, 0x04, + 0x38, 0x0E, 0x06, 0x0E, 0x25, 0x25, 0x01, 0x20, 0x02, 0x00, 0x06, 0x03, + 0x47, 0x04, 0x01, 0x48, 0x04, 0x38, 0x01, 0x05, 0x38, 0x0E, 0x06, 0x0C, + 0x25, 0x25, 0x02, 0x00, 0x06, 0x03, 0x4B, 0x04, 0x01, 0x4C, 0x04, 0x26, + 0x26, 0x01, 0x09, 0x0F, 0x06, 0x02, 0x68, 0x28, 0x44, 0x25, 0x26, 0x01, + 0x01, 0x17, 0x01, 0x04, 0x0B, 0x01, 0x10, 0x08, 0x44, 0x01, 0x08, 0x17, + 0x01, 0x10, 0x44, 0x09, 0x02, 0x00, 0x06, 0x03, 0x45, 0x04, 0x01, 0x46, + 0x00, 0x25, 0x00, 0x00, 0x9A, 0x01, 0x0C, 0x11, 0x01, 0x02, 0x0F, 0x00, + 0x00, 0x9A, 0x01, 0x0C, 0x11, 0x26, 0x5B, 0x44, 0x01, 0x03, 0x0A, 0x17, + 0x00, 0x00, 0x9A, 0x01, 0x0C, 0x11, 0x01, 0x01, 0x0E, 0x00, 0x00, 0x9A, + 0x01, 0x0C, 0x11, 0x5A, 0x00, 0x00, 0x9A, 0x01, 0x81, 0x70, 0x17, 0x01, + 0x20, 0x0D, 0x00, 0x00, 0x1B, 0x01, 0x00, 0x75, 0x2E, 0x26, 0x06, 0x22, + 0x01, 0x01, 0x38, 0x0E, 0x06, 0x06, 0x25, 0x01, 0x00, 0x9E, 0x04, 0x14, + 0x01, 0x02, 0x38, 0x0E, 0x06, 0x0D, 0x25, 0x77, 0x2E, 0x01, 0x01, 0x0E, + 0x06, 0x03, 0x01, 0x10, 0x37, 0x04, 0x01, 0x25, 0x04, 0x01, 0x25, 0x7B, + 0x2E, 0x05, 0x33, 0x2F, 0x06, 0x30, 0x86, 0x2E, 0x01, 0x14, 0x38, 0x0E, + 0x06, 0x06, 0x25, 0x01, 0x02, 0x37, 0x04, 0x22, 0x01, 0x15, 0x38, 0x0E, + 0x06, 0x09, 0x25, 0xAD, 0x06, 0x03, 0x01, 0x7F, 0x9E, 0x04, 0x13, 0x01, + 0x16, 0x38, 0x0E, 0x06, 0x06, 0x25, 0x01, 0x01, 0x37, 0x04, 0x07, 0x25, + 0x01, 0x04, 0x37, 0x01, 0x00, 0x25, 0x1A, 0x06, 0x03, 0x01, 0x08, 0x37, + 0x00, 0x00, 0x1B, 0x26, 0x05, 0x13, 0x2F, 0x06, 0x10, 0x86, 0x2E, 0x01, + 0x15, 0x0E, 0x06, 0x08, 0x25, 0xAD, 0x01, 0x00, 0x77, 0x3E, 0x04, 0x01, + 0x20, 0x00, 0x00, 0xCE, 0x01, 0x07, 0x17, 0x01, 0x01, 0x0F, 0x06, 0x02, + 0x72, 0x28, 0x00, 0x01, 0x03, 0x00, 0x29, 0x1A, 0x06, 0x05, 0x02, 0x00, + 0x87, 0x3E, 0x00, 0xCE, 0x25, 0x04, 0x74, 0x00, 0x01, 0x14, 0xD1, 0x01, + 0x01, 0xDE, 0x29, 0x26, 0x01, 0x00, 0xC8, 0x01, 0x16, 0xD1, 0xD7, 0x29, + 0x00, 0x00, 0x01, 0x0B, 0xDE, 0x4E, 0x26, 0x26, 0x01, 0x03, 0x08, 0xDD, + 0xDD, 0x18, 0x26, 0x58, 0x06, 0x02, 0x25, 0x00, 0xDD, 0x1D, 0x26, 0x06, + 0x05, 0x84, 0x44, 0xD8, 0x04, 0x77, 0x25, 0x04, 0x6C, 0x00, 0x21, 0x01, + 0x0F, 0xDE, 0x26, 0x92, 0x2C, 0x01, 0x86, 0x03, 0x10, 0x06, 0x0C, 0x01, + 0x04, 0x08, 0xDD, 0x80, 0x2E, 0xDE, 0x78, 0x2E, 0xDE, 0x04, 0x02, 0x5E, + 0xDD, 0x26, 0xDC, 0x84, 0x44, 0xD8, 0x00, 0x02, 0xA4, 0xA6, 0x08, 0xA2, + 0x08, 0xA5, 0x08, 0xA7, 0x08, 0xA3, 0x08, 0x27, 0x08, 0x03, 0x00, 0x01, + 0x01, 0xDE, 0x01, 0x27, 0x8E, 0x2E, 0x08, 0x91, 0x2E, 0x01, 0x01, 0x0B, + 0x08, 0x02, 0x00, 0x06, 0x04, 0x5E, 0x02, 0x00, 0x08, 0x83, 0x2C, 0x38, + 0x09, 0x26, 0x5B, 0x06, 0x24, 0x02, 0x00, 0x05, 0x04, 0x44, 0x5E, 0x44, + 0x5F, 0x01, 0x04, 0x09, 0x26, 0x58, 0x06, 0x03, 0x25, 0x01, 0x00, 0x26, + 0x01, 0x04, 0x08, 0x02, 0x00, 0x08, 0x03, 0x00, 0x44, 0x01, 0x04, 0x08, + 0x38, 0x08, 0x44, 0x04, 0x03, 0x25, 0x01, 0x7F, 0x03, 0x01, 0xDD, 0x94, + 0x2C, 0xDC, 0x7A, 0x01, 0x04, 0x19, 0x7A, 0x01, 0x04, 0x08, 0x01, 0x1C, + 0x32, 0x7A, 0x01, 0x20, 0xD8, 0x8D, 0x8E, 0x2E, 0xDA, 0x91, 0x2E, 0x26, + 0x01, 0x01, 0x0B, 0xDC, 0x90, 0x44, 0x26, 0x06, 0x0F, 0x5D, 0x38, 0x2C, + 0x26, 0xC7, 0x05, 0x02, 0x62, 0x28, 0xDC, 0x44, 0x5E, 0x44, 0x04, 0x6E, + 0x60, 0x01, 0x01, 0xDE, 0x01, 0x00, 0xDE, 0x02, 0x00, 0x06, 0x81, 0x5A, + 0x02, 0x00, 0xDC, 0xA4, 0x06, 0x0E, 0x01, 0x83, 0xFE, 0x01, 0xDC, 0x89, + 0xA4, 0x01, 0x04, 0x09, 0x26, 0xDC, 0x5D, 0xDA, 0xA6, 0x06, 0x16, 0x01, + 0x00, 0xDC, 0x8B, 0xA6, 0x01, 0x04, 0x09, 0x26, 0xDC, 0x01, 0x02, 0x09, + 0x26, 0xDC, 0x01, 0x00, 0xDE, 0x01, 0x03, 0x09, 0xD9, 0xA2, 0x06, 0x0C, + 0x01, 0x01, 0xDC, 0x01, 0x01, 0xDC, 0x82, 0x2E, 0x01, 0x08, 0x09, 0xDE, + 0xA5, 0x06, 0x19, 0x01, 0x0D, 0xDC, 0xA5, 0x01, 0x04, 0x09, 0x26, 0xDC, + 0x01, 0x02, 0x09, 0xDC, 0x42, 0x06, 0x03, 0x01, 0x03, 0xDB, 0x43, 0x06, + 0x03, 0x01, 0x01, 0xDB, 0xA7, 0x26, 0x06, 0x36, 0x01, 0x0A, 0xDC, 0x01, + 0x04, 0x09, 0x26, 0xDC, 0x5F, 0xDC, 0x40, 0x01, 0x00, 0x26, 0x01, 0x82, + 0x80, 0x80, 0x80, 0x00, 0x17, 0x06, 0x0A, 0x01, 0xFD, 0xFF, 0xFF, 0xFF, + 0x7F, 0x17, 0x01, 0x1D, 0xDC, 0x26, 0x01, 0x20, 0x0A, 0x06, 0x0C, 0xA0, + 0x11, 0x01, 0x01, 0x17, 0x06, 0x02, 0x26, 0xDC, 0x5C, 0x04, 0x6E, 0x60, + 0x04, 0x01, 0x25, 0xA3, 0x06, 0x0A, 0x01, 0x0B, 0xDC, 0x01, 0x02, 0xDC, + 0x01, 0x82, 0x00, 0xDC, 0x27, 0x26, 0x06, 0x1F, 0x01, 0x10, 0xDC, 0x01, + 0x04, 0x09, 0x26, 0xDC, 0x5F, 0xDC, 0x85, 0x2C, 0x01, 0x00, 0xA0, 0x0F, + 0x06, 0x0A, 0x26, 0x1E, 0x26, 0xDE, 0x84, 0x44, 0xD8, 0x5C, 0x04, 0x72, + 0x60, 0x04, 0x01, 0x25, 0x02, 0x01, 0x58, 0x05, 0x11, 0x01, 0x15, 0xDC, + 0x02, 0x01, 0x26, 0xDC, 0x26, 0x06, 0x06, 0x5D, 0x01, 0x00, 0xDE, 0x04, + 0x77, 0x25, 0x00, 0x00, 0x01, 0x10, 0xDE, 0x79, 0x2C, 0x26, 0xCC, 0x06, + 0x0C, 0xAB, 0x23, 0x26, 0x5E, 0xDD, 0x26, 0xDC, 0x84, 0x44, 0xD8, 0x04, + 0x0D, 0x26, 0xCA, 0x44, 0xAB, 0x22, 0x26, 0x5C, 0xDD, 0x26, 0xDE, 0x84, + 0x44, 0xD8, 0x00, 0x00, 0x9C, 0x01, 0x14, 0xDE, 0x01, 0x0C, 0xDD, 0x84, + 0x01, 0x0C, 0xD8, 0x00, 0x00, 0x51, 0x26, 0x01, 0x00, 0x0E, 0x06, 0x02, + 0x60, 0x00, 0xCE, 0x25, 0x04, 0x73, 0x00, 0x26, 0xDC, 0xD8, 0x00, 0x00, + 0x26, 0xDE, 0xD8, 0x00, 0x01, 0x03, 0x00, 0x41, 0x25, 0x26, 0x01, 0x10, + 0x17, 0x06, 0x06, 0x01, 0x04, 0xDE, 0x02, 0x00, 0xDE, 0x26, 0x01, 0x08, + 0x17, 0x06, 0x06, 0x01, 0x03, 0xDE, 0x02, 0x00, 0xDE, 0x26, 0x01, 0x20, + 0x17, 0x06, 0x06, 0x01, 0x05, 0xDE, 0x02, 0x00, 0xDE, 0x26, 0x01, 0x80, + 0x40, 0x17, 0x06, 0x06, 0x01, 0x06, 0xDE, 0x02, 0x00, 0xDE, 0x01, 0x04, + 0x17, 0x06, 0x06, 0x01, 0x02, 0xDE, 0x02, 0x00, 0xDE, 0x00, 0x00, 0x26, + 0x01, 0x08, 0x4F, 0xDE, 0xDE, 0x00, 0x00, 0x26, 0x01, 0x10, 0x4F, 0xDE, + 0xDC, 0x00, 0x00, 0x26, 0x52, 0x06, 0x02, 0x25, 0x00, 0xCE, 0x25, 0x04, + 0x76 +}; + +static const uint16_t t0_caddr[] = { + 0, + 5, + 10, + 15, + 20, + 25, + 30, + 35, + 40, + 44, + 48, + 52, + 56, + 60, + 64, + 68, + 72, + 76, + 80, + 84, + 88, + 92, + 96, + 100, + 104, + 108, + 112, + 116, + 120, + 124, + 129, + 134, + 139, + 144, + 149, + 154, + 159, + 164, + 169, + 174, + 179, + 184, + 189, + 194, + 199, + 204, + 209, + 214, + 219, + 224, + 229, + 234, + 239, + 244, + 249, + 254, + 259, + 264, + 269, + 274, + 279, + 284, + 289, + 294, + 303, + 316, + 320, + 345, + 351, + 370, + 381, + 422, + 542, + 546, + 611, + 626, + 637, + 655, + 684, + 694, + 730, + 740, + 818, + 832, + 838, + 897, + 916, + 951, + 1000, + 1076, + 1103, + 1134, + 1145, + 1497, + 1644, + 1668, + 1884, + 1898, + 1907, + 1911, + 2006, + 2027, + 2083, + 2090, + 2101, + 2117, + 2123, + 2134, + 2169, + 2181, + 2187, + 2202, + 2218, + 2411, + 2420, + 2433, + 2442, + 2449, + 2459, + 2565, + 2590, + 2603, + 2619, + 2637, + 2669, + 2703, + 3071, + 3107, + 3120, + 3134, + 3139, + 3144, + 3210, + 3218, + 3226 +}; + +#define T0_INTERPRETED 88 + +#define T0_ENTER(ip, rp, slot) do { \ + const unsigned char *t0_newip; \ + uint32_t t0_lnum; \ + t0_newip = &t0_codeblock[t0_caddr[(slot) - T0_INTERPRETED]]; \ + t0_lnum = t0_parse7E_unsigned(&t0_newip); \ + (rp) += t0_lnum; \ + *((rp) ++) = (uint32_t)((ip) - &t0_codeblock[0]) + (t0_lnum << 16); \ + (ip) = t0_newip; \ + } while (0) + +#define T0_DEFENTRY(name, slot) \ +void \ +name(void *ctx) \ +{ \ + t0_context *t0ctx = ctx; \ + t0ctx->ip = &t0_codeblock[0]; \ + T0_ENTER(t0ctx->ip, t0ctx->rp, slot); \ +} + +T0_DEFENTRY(br_ssl_hs_client_init_main, 169) + +#define T0_NEXT(t0ipp) (*(*(t0ipp)) ++) + +void +br_ssl_hs_client_run(void *t0ctx) +{ + uint32_t *dp, *rp; + const unsigned char *ip; + +#define T0_LOCAL(x) (*(rp - 2 - (x))) +#define T0_POP() (*-- dp) +#define T0_POPi() (*(int32_t *)(-- dp)) +#define T0_PEEK(x) (*(dp - 1 - (x))) +#define T0_PEEKi(x) (*(int32_t *)(dp - 1 - (x))) +#define T0_PUSH(v) do { *dp = (v); dp ++; } while (0) +#define T0_PUSHi(v) do { *(int32_t *)dp = (v); dp ++; } while (0) +#define T0_RPOP() (*-- rp) +#define T0_RPOPi() (*(int32_t *)(-- rp)) +#define T0_RPUSH(v) do { *rp = (v); rp ++; } while (0) +#define T0_RPUSHi(v) do { *(int32_t *)rp = (v); rp ++; } while (0) +#define T0_ROLL(x) do { \ + size_t t0len = (size_t)(x); \ + uint32_t t0tmp = *(dp - 1 - t0len); \ + memmove(dp - t0len - 1, dp - t0len, t0len * sizeof *dp); \ + *(dp - 1) = t0tmp; \ +} while (0) +#define T0_SWAP() do { \ + uint32_t t0tmp = *(dp - 2); \ + *(dp - 2) = *(dp - 1); \ + *(dp - 1) = t0tmp; \ +} while (0) +#define T0_ROT() do { \ + uint32_t t0tmp = *(dp - 3); \ + *(dp - 3) = *(dp - 2); \ + *(dp - 2) = *(dp - 1); \ + *(dp - 1) = t0tmp; \ +} while (0) +#define T0_NROT() do { \ + uint32_t t0tmp = *(dp - 1); \ + *(dp - 1) = *(dp - 2); \ + *(dp - 2) = *(dp - 3); \ + *(dp - 3) = t0tmp; \ +} while (0) +#define T0_PICK(x) do { \ + uint32_t t0depth = (x); \ + T0_PUSH(T0_PEEK(t0depth)); \ +} while (0) +#define T0_CO() do { \ + goto t0_exit; \ +} while (0) +#define T0_RET() goto t0_next + + dp = ((t0_context *)t0ctx)->dp; + rp = ((t0_context *)t0ctx)->rp; + ip = ((t0_context *)t0ctx)->ip; + goto t0_next; + for (;;) { + uint32_t t0x; + + t0_next: + t0x = T0_NEXT(&ip); + if (t0x < T0_INTERPRETED) { + switch (t0x) { + int32_t t0off; + + case 0: /* ret */ + t0x = T0_RPOP(); + rp -= (t0x >> 16); + t0x &= 0xFFFF; + if (t0x == 0) { + ip = NULL; + goto t0_exit; + } + ip = &t0_codeblock[t0x]; + break; + case 1: /* literal constant */ + T0_PUSHi(t0_parse7E_signed(&ip)); + break; + case 2: /* read local */ + T0_PUSH(T0_LOCAL(t0_parse7E_unsigned(&ip))); + break; + case 3: /* write local */ + T0_LOCAL(t0_parse7E_unsigned(&ip)) = T0_POP(); + break; + case 4: /* jump */ + t0off = t0_parse7E_signed(&ip); + ip += t0off; + break; + case 5: /* jump if */ + t0off = t0_parse7E_signed(&ip); + if (T0_POP()) { + ip += t0off; + } + break; + case 6: /* jump if not */ + t0off = t0_parse7E_signed(&ip); + if (!T0_POP()) { + ip += t0off; + } + break; + case 7: { + /* * */ + + uint32_t b = T0_POP(); + uint32_t a = T0_POP(); + T0_PUSH(a * b); + + } + break; + case 8: { + /* + */ + + uint32_t b = T0_POP(); + uint32_t a = T0_POP(); + T0_PUSH(a + b); + + } + break; + case 9: { + /* - */ + + uint32_t b = T0_POP(); + uint32_t a = T0_POP(); + T0_PUSH(a - b); + + } + break; + case 10: { + /* < */ + + int32_t b = T0_POPi(); + int32_t a = T0_POPi(); + T0_PUSH(-(uint32_t)(a < b)); + + } + break; + case 11: { + /* << */ + + int c = (int)T0_POPi(); + uint32_t x = T0_POP(); + T0_PUSH(x << c); + + } + break; + case 12: { + /* <= */ + + int32_t b = T0_POPi(); + int32_t a = T0_POPi(); + T0_PUSH(-(uint32_t)(a <= b)); + + } + break; + case 13: { + /* <> */ + + uint32_t b = T0_POP(); + uint32_t a = T0_POP(); + T0_PUSH(-(uint32_t)(a != b)); + + } + break; + case 14: { + /* = */ + + uint32_t b = T0_POP(); + uint32_t a = T0_POP(); + T0_PUSH(-(uint32_t)(a == b)); + + } + break; + case 15: { + /* > */ + + int32_t b = T0_POPi(); + int32_t a = T0_POPi(); + T0_PUSH(-(uint32_t)(a > b)); + + } + break; + case 16: { + /* >= */ + + int32_t b = T0_POPi(); + int32_t a = T0_POPi(); + T0_PUSH(-(uint32_t)(a >= b)); + + } + break; + case 17: { + /* >> */ + + int c = (int)T0_POPi(); + int32_t x = T0_POPi(); + T0_PUSHi(x >> c); + + } + break; + case 18: { + /* anchor-dn-append-name */ + + size_t len; + + len = T0_POP(); + if (CTX->client_auth_vtable != NULL) { + (*CTX->client_auth_vtable)->append_name( + CTX->client_auth_vtable, ENG->pad, len); + } + + } + break; + case 19: { + /* anchor-dn-end-name */ + + if (CTX->client_auth_vtable != NULL) { + (*CTX->client_auth_vtable)->end_name( + CTX->client_auth_vtable); + } + + } + break; + case 20: { + /* anchor-dn-end-name-list */ + + if (CTX->client_auth_vtable != NULL) { + (*CTX->client_auth_vtable)->end_name_list( + CTX->client_auth_vtable); + } + + } + break; + case 21: { + /* anchor-dn-start-name */ + + size_t len; + + len = T0_POP(); + if (CTX->client_auth_vtable != NULL) { + (*CTX->client_auth_vtable)->start_name( + CTX->client_auth_vtable, len); + } + + } + break; + case 22: { + /* anchor-dn-start-name-list */ + + if (CTX->client_auth_vtable != NULL) { + (*CTX->client_auth_vtable)->start_name_list( + CTX->client_auth_vtable); + } + + } + break; + case 23: { + /* and */ + + uint32_t b = T0_POP(); + uint32_t a = T0_POP(); + T0_PUSH(a & b); + + } + break; + case 24: { + /* begin-cert */ + + if (ENG->chain_len == 0) { + T0_PUSHi(-1); + } else { + ENG->cert_cur = ENG->chain->data; + ENG->cert_len = ENG->chain->data_len; + ENG->chain ++; + ENG->chain_len --; + T0_PUSH(ENG->cert_len); + } + + } + break; + case 25: { + /* bzero */ + + size_t len = (size_t)T0_POP(); + void *addr = (unsigned char *)ENG + (size_t)T0_POP(); + memset(addr, 0, len); + + } + break; + case 26: { + /* can-output? */ + + T0_PUSHi(-(ENG->hlen_out > 0)); + + } + break; + case 27: { + /* co */ + T0_CO(); + } + break; + case 28: { + /* compute-Finished-inner */ + + int prf_id = T0_POP(); + int from_client = T0_POPi(); + unsigned char tmp[48]; + br_tls_prf_seed_chunk seed; + + br_tls_prf_impl prf = br_ssl_engine_get_PRF(ENG, prf_id); + seed.data = tmp; + if (ENG->session.version >= BR_TLS12) { + seed.len = br_multihash_out(&ENG->mhash, prf_id, tmp); + } else { + br_multihash_out(&ENG->mhash, br_md5_ID, tmp); + br_multihash_out(&ENG->mhash, br_sha1_ID, tmp + 16); + seed.len = 36; + } + prf(ENG->pad, 12, ENG->session.master_secret, + sizeof ENG->session.master_secret, + from_client ? "client finished" : "server finished", + 1, &seed); + + } + break; + case 29: { + /* copy-cert-chunk */ + + size_t clen; + + clen = ENG->cert_len; + if (clen > sizeof ENG->pad) { + clen = sizeof ENG->pad; + } + memcpy(ENG->pad, ENG->cert_cur, clen); + ENG->cert_cur += clen; + ENG->cert_len -= clen; + T0_PUSH(clen); + + } + break; + case 30: { + /* copy-protocol-name */ + + size_t idx = T0_POP(); + size_t len = strlen(ENG->protocol_names[idx]); + memcpy(ENG->pad, ENG->protocol_names[idx], len); + T0_PUSH(len); + + } + break; + case 31: { + /* data-get8 */ + + size_t addr = T0_POP(); + T0_PUSH(t0_datablock[addr]); + + } + break; + case 32: { + /* discard-input */ + + ENG->hlen_in = 0; + + } + break; + case 33: { + /* do-client-sign */ + + size_t sig_len; + + sig_len = make_client_sign(CTX); + if (sig_len == 0) { + br_ssl_engine_fail(ENG, BR_ERR_INVALID_ALGORITHM); + T0_CO(); + } + T0_PUSH(sig_len); + + } + break; + case 34: { + /* do-ecdh */ + + unsigned prf_id = T0_POP(); + unsigned ecdhe = T0_POP(); + int x; + + x = make_pms_ecdh(CTX, ecdhe, prf_id); + if (x < 0) { + br_ssl_engine_fail(ENG, -x); + T0_CO(); + } else { + T0_PUSH(x); + } + + } + break; + case 35: { + /* do-rsa-encrypt */ + + int x; + + x = make_pms_rsa(CTX, T0_POP()); + if (x < 0) { + br_ssl_engine_fail(ENG, -x); + T0_CO(); + } else { + T0_PUSH(x); + } + + } + break; + case 36: { + /* do-static-ecdh */ + + unsigned prf_id = T0_POP(); + + if (make_pms_static_ecdh(CTX, prf_id) < 0) { + br_ssl_engine_fail(ENG, BR_ERR_INVALID_ALGORITHM); + T0_CO(); + } + + } + break; + case 37: { + /* drop */ + (void)T0_POP(); + } + break; + case 38: { + /* dup */ + T0_PUSH(T0_PEEK(0)); + } + break; + case 39: { + /* ext-ALPN-length */ + + size_t u, len; + + if (ENG->protocol_names_num == 0) { + T0_PUSH(0); + T0_RET(); + } + len = 6; + for (u = 0; u < ENG->protocol_names_num; u ++) { + len += 1 + strlen(ENG->protocol_names[u]); + } + T0_PUSH(len); + + } + break; + case 40: { + /* fail */ + + br_ssl_engine_fail(ENG, (int)T0_POPi()); + T0_CO(); + + } + break; + case 41: { + /* flush-record */ + + br_ssl_engine_flush_record(ENG); + + } + break; + case 42: { + /* get-client-chain */ + + uint32_t auth_types; + + auth_types = T0_POP(); + if (CTX->client_auth_vtable != NULL) { + br_ssl_client_certificate ux; + + (*CTX->client_auth_vtable)->choose(CTX->client_auth_vtable, + CTX, auth_types, &ux); + CTX->auth_type = (unsigned char)ux.auth_type; + CTX->hash_id = (unsigned char)ux.hash_id; + ENG->chain = ux.chain; + ENG->chain_len = ux.chain_len; + } else { + CTX->hash_id = 0; + ENG->chain_len = 0; + } + + } + break; + case 43: { + /* get-key-type-usages */ + + const br_x509_class *xc; + const br_x509_pkey *pk; + unsigned usages; + + xc = *(ENG->x509ctx); + pk = xc->get_pkey(ENG->x509ctx, &usages); + if (pk == NULL) { + T0_PUSH(0); + } else { + T0_PUSH(pk->key_type | usages); + } + + } + break; + case 44: { + /* get16 */ + + size_t addr = (size_t)T0_POP(); + T0_PUSH(*(uint16_t *)(void *)((unsigned char *)ENG + addr)); + + } + break; + case 45: { + /* get32 */ + + size_t addr = (size_t)T0_POP(); + T0_PUSH(*(uint32_t *)(void *)((unsigned char *)ENG + addr)); + + } + break; + case 46: { + /* get8 */ + + size_t addr = (size_t)T0_POP(); + T0_PUSH(*((unsigned char *)ENG + addr)); + + } + break; + case 47: { + /* has-input? */ + + T0_PUSHi(-(ENG->hlen_in != 0)); + + } + break; + case 48: { + /* memcmp */ + + size_t len = (size_t)T0_POP(); + void *addr2 = (unsigned char *)ENG + (size_t)T0_POP(); + void *addr1 = (unsigned char *)ENG + (size_t)T0_POP(); + int x = memcmp(addr1, addr2, len); + T0_PUSH((uint32_t)-(x == 0)); + + } + break; + case 49: { + /* memcpy */ + + size_t len = (size_t)T0_POP(); + void *src = (unsigned char *)ENG + (size_t)T0_POP(); + void *dst = (unsigned char *)ENG + (size_t)T0_POP(); + memcpy(dst, src, len); + + } + break; + case 50: { + /* mkrand */ + + size_t len = (size_t)T0_POP(); + void *addr = (unsigned char *)ENG + (size_t)T0_POP(); + br_hmac_drbg_generate(&ENG->rng, addr, len); + + } + break; + case 51: { + /* more-incoming-bytes? */ + + T0_PUSHi(ENG->hlen_in != 0 || !br_ssl_engine_recvrec_finished(ENG)); + + } + break; + case 52: { + /* multihash-init */ + + br_multihash_init(&ENG->mhash); + + } + break; + case 53: { + /* neg */ + + uint32_t a = T0_POP(); + T0_PUSH(-a); + + } + break; + case 54: { + /* not */ + + uint32_t a = T0_POP(); + T0_PUSH(~a); + + } + break; + case 55: { + /* or */ + + uint32_t b = T0_POP(); + uint32_t a = T0_POP(); + T0_PUSH(a | b); + + } + break; + case 56: { + /* over */ + T0_PUSH(T0_PEEK(1)); + } + break; + case 57: { + /* read-chunk-native */ + + size_t clen = ENG->hlen_in; + if (clen > 0) { + uint32_t addr, len; + + len = T0_POP(); + addr = T0_POP(); + if ((size_t)len < clen) { + clen = (size_t)len; + } + memcpy((unsigned char *)ENG + addr, ENG->hbuf_in, clen); + if (ENG->record_type_in == BR_SSL_HANDSHAKE) { + br_multihash_update(&ENG->mhash, ENG->hbuf_in, clen); + } + T0_PUSH(addr + (uint32_t)clen); + T0_PUSH(len - (uint32_t)clen); + ENG->hbuf_in += clen; + ENG->hlen_in -= clen; + } + + } + break; + case 58: { + /* read8-native */ + + if (ENG->hlen_in > 0) { + unsigned char x; + + x = *ENG->hbuf_in ++; + if (ENG->record_type_in == BR_SSL_HANDSHAKE) { + br_multihash_update(&ENG->mhash, &x, 1); + } + T0_PUSH(x); + ENG->hlen_in --; + } else { + T0_PUSHi(-1); + } + + } + break; + case 59: { + /* set-server-curve */ + + const br_x509_class *xc; + const br_x509_pkey *pk; + + xc = *(ENG->x509ctx); + pk = xc->get_pkey(ENG->x509ctx, NULL); + CTX->server_curve = + (pk->key_type == BR_KEYTYPE_EC) ? pk->key.ec.curve : 0; + + } + break; + case 60: { + /* set16 */ + + size_t addr = (size_t)T0_POP(); + *(uint16_t *)(void *)((unsigned char *)ENG + addr) = (uint16_t)T0_POP(); + + } + break; + case 61: { + /* set32 */ + + size_t addr = (size_t)T0_POP(); + *(uint32_t *)(void *)((unsigned char *)ENG + addr) = (uint32_t)T0_POP(); + + } + break; + case 62: { + /* set8 */ + + size_t addr = (size_t)T0_POP(); + *((unsigned char *)ENG + addr) = (unsigned char)T0_POP(); + + } + break; + case 63: { + /* strlen */ + + void *str = (unsigned char *)ENG + (size_t)T0_POP(); + T0_PUSH((uint32_t)strlen(str)); + + } + break; + case 64: { + /* supported-curves */ + + uint32_t x = ENG->iec == NULL ? 0 : ENG->iec->supported_curves; + T0_PUSH(x); + + } + break; + case 65: { + /* supported-hash-functions */ + + int i; + unsigned x, num; + + x = 0; + num = 0; + for (i = br_sha1_ID; i <= br_sha512_ID; i ++) { + if (br_multihash_getimpl(&ENG->mhash, i)) { + x |= 1U << i; + num ++; + } + } + T0_PUSH(x); + T0_PUSH(num); + + } + break; + case 66: { + /* supports-ecdsa? */ + + T0_PUSHi(-(ENG->iecdsa != 0)); + + } + break; + case 67: { + /* supports-rsa-sign? */ + + T0_PUSHi(-(ENG->irsavrfy != 0)); + + } + break; + case 68: { + /* swap */ + T0_SWAP(); + } + break; + case 69: { + /* switch-aesccm-in */ + + int is_client, prf_id; + unsigned cipher_key_len, tag_len; + + tag_len = T0_POP(); + cipher_key_len = T0_POP(); + prf_id = T0_POP(); + is_client = T0_POP(); + br_ssl_engine_switch_ccm_in(ENG, is_client, prf_id, + ENG->iaes_ctrcbc, cipher_key_len, tag_len); + + } + break; + case 70: { + /* switch-aesccm-out */ + + int is_client, prf_id; + unsigned cipher_key_len, tag_len; + + tag_len = T0_POP(); + cipher_key_len = T0_POP(); + prf_id = T0_POP(); + is_client = T0_POP(); + br_ssl_engine_switch_ccm_out(ENG, is_client, prf_id, + ENG->iaes_ctrcbc, cipher_key_len, tag_len); + + } + break; + case 71: { + /* switch-aesgcm-in */ + + int is_client, prf_id; + unsigned cipher_key_len; + + cipher_key_len = T0_POP(); + prf_id = T0_POP(); + is_client = T0_POP(); + br_ssl_engine_switch_gcm_in(ENG, is_client, prf_id, + ENG->iaes_ctr, cipher_key_len); + + } + break; + case 72: { + /* switch-aesgcm-out */ + + int is_client, prf_id; + unsigned cipher_key_len; + + cipher_key_len = T0_POP(); + prf_id = T0_POP(); + is_client = T0_POP(); + br_ssl_engine_switch_gcm_out(ENG, is_client, prf_id, + ENG->iaes_ctr, cipher_key_len); + + } + break; + case 73: { + /* switch-cbc-in */ + + int is_client, prf_id, mac_id, aes; + unsigned cipher_key_len; + + cipher_key_len = T0_POP(); + aes = T0_POP(); + mac_id = T0_POP(); + prf_id = T0_POP(); + is_client = T0_POP(); + br_ssl_engine_switch_cbc_in(ENG, is_client, prf_id, mac_id, + aes ? ENG->iaes_cbcdec : ENG->ides_cbcdec, cipher_key_len); + + } + break; + case 74: { + /* switch-cbc-out */ + + int is_client, prf_id, mac_id, aes; + unsigned cipher_key_len; + + cipher_key_len = T0_POP(); + aes = T0_POP(); + mac_id = T0_POP(); + prf_id = T0_POP(); + is_client = T0_POP(); + br_ssl_engine_switch_cbc_out(ENG, is_client, prf_id, mac_id, + aes ? ENG->iaes_cbcenc : ENG->ides_cbcenc, cipher_key_len); + + } + break; + case 75: { + /* switch-chapol-in */ + + int is_client, prf_id; + + prf_id = T0_POP(); + is_client = T0_POP(); + br_ssl_engine_switch_chapol_in(ENG, is_client, prf_id); + + } + break; + case 76: { + /* switch-chapol-out */ + + int is_client, prf_id; + + prf_id = T0_POP(); + is_client = T0_POP(); + br_ssl_engine_switch_chapol_out(ENG, is_client, prf_id); + + } + break; + case 77: { + /* test-protocol-name */ + + size_t len = T0_POP(); + size_t u; + + for (u = 0; u < ENG->protocol_names_num; u ++) { + const char *name; + + name = ENG->protocol_names[u]; + if (len == strlen(name) && memcmp(ENG->pad, name, len) == 0) { + T0_PUSH(u); + T0_RET(); + } + } + T0_PUSHi(-1); + + } + break; + case 78: { + /* total-chain-length */ + + size_t u; + uint32_t total; + + total = 0; + for (u = 0; u < ENG->chain_len; u ++) { + total += 3 + (uint32_t)ENG->chain[u].data_len; + } + T0_PUSH(total); + + } + break; + case 79: { + /* u>> */ + + int c = (int)T0_POPi(); + uint32_t x = T0_POP(); + T0_PUSH(x >> c); + + } + break; + case 80: { + /* verify-SKE-sig */ + + size_t sig_len = T0_POP(); + int use_rsa = T0_POPi(); + int hash = T0_POPi(); + + T0_PUSH(verify_SKE_sig(CTX, hash, use_rsa, sig_len)); + + } + break; + case 81: { + /* write-blob-chunk */ + + size_t clen = ENG->hlen_out; + if (clen > 0) { + uint32_t addr, len; + + len = T0_POP(); + addr = T0_POP(); + if ((size_t)len < clen) { + clen = (size_t)len; + } + memcpy(ENG->hbuf_out, (unsigned char *)ENG + addr, clen); + if (ENG->record_type_out == BR_SSL_HANDSHAKE) { + br_multihash_update(&ENG->mhash, ENG->hbuf_out, clen); + } + T0_PUSH(addr + (uint32_t)clen); + T0_PUSH(len - (uint32_t)clen); + ENG->hbuf_out += clen; + ENG->hlen_out -= clen; + } + + } + break; + case 82: { + /* write8-native */ + + unsigned char x; + + x = (unsigned char)T0_POP(); + if (ENG->hlen_out > 0) { + if (ENG->record_type_out == BR_SSL_HANDSHAKE) { + br_multihash_update(&ENG->mhash, &x, 1); + } + *ENG->hbuf_out ++ = x; + ENG->hlen_out --; + T0_PUSHi(-1); + } else { + T0_PUSHi(0); + } + + } + break; + case 83: { + /* x509-append */ + + const br_x509_class *xc; + size_t len; + + xc = *(ENG->x509ctx); + len = T0_POP(); + xc->append(ENG->x509ctx, ENG->pad, len); + + } + break; + case 84: { + /* x509-end-cert */ + + const br_x509_class *xc; + + xc = *(ENG->x509ctx); + xc->end_cert(ENG->x509ctx); + + } + break; + case 85: { + /* x509-end-chain */ + + const br_x509_class *xc; + + xc = *(ENG->x509ctx); + T0_PUSH(xc->end_chain(ENG->x509ctx)); + + } + break; + case 86: { + /* x509-start-cert */ + + const br_x509_class *xc; + + xc = *(ENG->x509ctx); + xc->start_cert(ENG->x509ctx, T0_POP()); + + } + break; + case 87: { + /* x509-start-chain */ + + const br_x509_class *xc; + uint32_t bc; + + bc = T0_POP(); + xc = *(ENG->x509ctx); + xc->start_chain(ENG->x509ctx, bc ? ENG->server_name : NULL); + + } + break; + } + + } else { + T0_ENTER(ip, rp, t0x); + } + } +t0_exit: + ((t0_context *)t0ctx)->dp = dp; + ((t0_context *)t0ctx)->rp = rp; + ((t0_context *)t0ctx)->ip = ip; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_hs_client.t0 b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_hs_client.t0 new file mode 100644 index 000000000..23b39e719 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_hs_client.t0 @@ -0,0 +1,1276 @@ +\ Copyright (c) 2016 Thomas Pornin +\ +\ Permission is hereby granted, free of charge, to any person obtaining +\ a copy of this software and associated documentation files (the +\ "Software"), to deal in the Software without restriction, including +\ without limitation the rights to use, copy, modify, merge, publish, +\ distribute, sublicense, and/or sell copies of the Software, and to +\ permit persons to whom the Software is furnished to do so, subject to +\ the following conditions: +\ +\ The above copyright notice and this permission notice shall be +\ included in all copies or substantial portions of the Software. +\ +\ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +\ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +\ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +\ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +\ BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +\ ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +\ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +\ SOFTWARE. + +\ ---------------------------------------------------------------------- +\ Handshake processing code, for the client. +\ The common T0 code (ssl_hs_common.t0) shall be read first. + +preamble { + +/* + * This macro evaluates to a pointer to the client context, under that + * specific name. It must be noted that since the engine context is the + * first field of the br_ssl_client_context structure ('eng'), then + * pointers values of both types are interchangeable, modulo an + * appropriate cast. This also means that "addresses" computed as offsets + * within the structure work for both kinds of context. + */ +#define CTX ((br_ssl_client_context *)ENG) + +/* + * Generate the pre-master secret for RSA key exchange, and encrypt it + * with the server's public key. Returned value is either the encrypted + * data length (in bytes), or -x on error, with 'x' being an error code. + * + * This code assumes that the public key has been already verified (it + * was properly obtained by the X.509 engine, and it has the right type, + * i.e. it is of type RSA and suitable for encryption). + */ +static int +make_pms_rsa(br_ssl_client_context *ctx, int prf_id) +{ + const br_x509_class **xc; + const br_x509_pkey *pk; + const unsigned char *n; + unsigned char *pms; + size_t nlen, u; + + xc = ctx->eng.x509ctx; + pk = (*xc)->get_pkey(xc, NULL); + + /* + * Compute actual RSA key length, in case there are leading zeros. + */ + n = pk->key.rsa.n; + nlen = pk->key.rsa.nlen; + while (nlen > 0 && *n == 0) { + n ++; + nlen --; + } + + /* + * We need at least 59 bytes (48 bytes for pre-master secret, and + * 11 bytes for the PKCS#1 type 2 padding). Note that the X.509 + * minimal engine normally blocks RSA keys shorter than 128 bytes, + * so this is mostly for public keys provided explicitly by the + * caller. + */ + if (nlen < 59) { + return -BR_ERR_X509_WEAK_PUBLIC_KEY; + } + if (nlen > sizeof ctx->eng.pad) { + return -BR_ERR_LIMIT_EXCEEDED; + } + + /* + * Make PMS. + */ + pms = ctx->eng.pad + nlen - 48; + br_enc16be(pms, ctx->eng.version_max); + br_hmac_drbg_generate(&ctx->eng.rng, pms + 2, 46); + br_ssl_engine_compute_master(&ctx->eng, prf_id, pms, 48); + + /* + * Apply PKCS#1 type 2 padding. + */ + ctx->eng.pad[0] = 0x00; + ctx->eng.pad[1] = 0x02; + ctx->eng.pad[nlen - 49] = 0x00; + br_hmac_drbg_generate(&ctx->eng.rng, ctx->eng.pad + 2, nlen - 51); + for (u = 2; u < nlen - 49; u ++) { + while (ctx->eng.pad[u] == 0) { + br_hmac_drbg_generate(&ctx->eng.rng, + &ctx->eng.pad[u], 1); + } + } + + /* + * Compute RSA encryption. + */ + if (!ctx->irsapub(ctx->eng.pad, nlen, &pk->key.rsa)) { + return -BR_ERR_LIMIT_EXCEEDED; + } + return (int)nlen; +} + +/* + * OID for hash functions in RSA signatures. + */ +static const unsigned char *HASH_OID[] = { + BR_HASH_OID_SHA1, + BR_HASH_OID_SHA224, + BR_HASH_OID_SHA256, + BR_HASH_OID_SHA384, + BR_HASH_OID_SHA512 +}; + +/* + * Check the RSA signature on the ServerKeyExchange message. + * + * hash hash function ID (2 to 6), or 0 for MD5+SHA-1 (with RSA only) + * use_rsa non-zero for RSA signature, zero for ECDSA + * sig_len signature length (in bytes); signature value is in the pad + * + * Returned value is 0 on success, or an error code. + */ +static int +verify_SKE_sig(br_ssl_client_context *ctx, + int hash, int use_rsa, size_t sig_len) +{ + const br_x509_class **xc; + const br_x509_pkey *pk; + br_multihash_context mhc; + unsigned char hv[64], head[4]; + size_t hv_len; + + xc = ctx->eng.x509ctx; + pk = (*xc)->get_pkey(xc, NULL); + br_multihash_zero(&mhc); + br_multihash_copyimpl(&mhc, &ctx->eng.mhash); + br_multihash_init(&mhc); + br_multihash_update(&mhc, + ctx->eng.client_random, sizeof ctx->eng.client_random); + br_multihash_update(&mhc, + ctx->eng.server_random, sizeof ctx->eng.server_random); + head[0] = 3; + head[1] = 0; + head[2] = ctx->eng.ecdhe_curve; + head[3] = ctx->eng.ecdhe_point_len; + br_multihash_update(&mhc, head, sizeof head); + br_multihash_update(&mhc, + ctx->eng.ecdhe_point, ctx->eng.ecdhe_point_len); + if (hash) { + hv_len = br_multihash_out(&mhc, hash, hv); + if (hv_len == 0) { + return BR_ERR_INVALID_ALGORITHM; + } + } else { + if (!br_multihash_out(&mhc, br_md5_ID, hv) + || !br_multihash_out(&mhc, br_sha1_ID, hv + 16)) + { + return BR_ERR_INVALID_ALGORITHM; + } + hv_len = 36; + } + if (use_rsa) { + unsigned char tmp[64]; + const unsigned char *hash_oid; + + if (hash) { + hash_oid = HASH_OID[hash - 2]; + } else { + hash_oid = NULL; + } + if (!ctx->eng.irsavrfy(ctx->eng.pad, sig_len, + hash_oid, hv_len, &pk->key.rsa, tmp) + || memcmp(tmp, hv, hv_len) != 0) + { + return BR_ERR_BAD_SIGNATURE; + } + } else { + if (!ctx->eng.iecdsa(ctx->eng.iec, hv, hv_len, &pk->key.ec, + ctx->eng.pad, sig_len)) + { + return BR_ERR_BAD_SIGNATURE; + } + } + return 0; +} + +/* + * Perform client-side ECDH (or ECDHE). The point that should be sent to + * the server is written in the pad; returned value is either the point + * length (in bytes), or -x on error, with 'x' being an error code. + * + * The point _from_ the server is taken from ecdhe_point[] if 'ecdhe' + * is non-zero, or from the X.509 engine context if 'ecdhe' is zero + * (for static ECDH). + */ +static int +make_pms_ecdh(br_ssl_client_context *ctx, unsigned ecdhe, int prf_id) +{ + int curve; + unsigned char key[66], point[133]; + const unsigned char *order, *point_src; + size_t glen, olen, point_len, xoff, xlen; + unsigned char mask; + + if (ecdhe) { + curve = ctx->eng.ecdhe_curve; + point_src = ctx->eng.ecdhe_point; + point_len = ctx->eng.ecdhe_point_len; + } else { + const br_x509_class **xc; + const br_x509_pkey *pk; + + xc = ctx->eng.x509ctx; + pk = (*xc)->get_pkey(xc, NULL); + curve = pk->key.ec.curve; + point_src = pk->key.ec.q; + point_len = pk->key.ec.qlen; + } + if ((ctx->eng.iec->supported_curves & ((uint32_t)1 << curve)) == 0) { + return -BR_ERR_INVALID_ALGORITHM; + } + + /* + * We need to generate our key, as a non-zero random value which + * is lower than the curve order, in a "large enough" range. We + * force top bit to 0 and bottom bit to 1, which guarantees that + * the value is in the proper range. + */ + order = ctx->eng.iec->order(curve, &olen); + mask = 0xFF; + while (mask >= order[0]) { + mask >>= 1; + } + br_hmac_drbg_generate(&ctx->eng.rng, key, olen); + key[0] &= mask; + key[olen - 1] |= 0x01; + + /* + * Compute the common ECDH point, whose X coordinate is the + * pre-master secret. + */ + ctx->eng.iec->generator(curve, &glen); + if (glen != point_len) { + return -BR_ERR_INVALID_ALGORITHM; + } + + memcpy(point, point_src, glen); + if (!ctx->eng.iec->mul(point, glen, key, olen, curve)) { + return -BR_ERR_INVALID_ALGORITHM; + } + + /* + * The pre-master secret is the X coordinate. + */ + xoff = ctx->eng.iec->xoff(curve, &xlen); + br_ssl_engine_compute_master(&ctx->eng, prf_id, point + xoff, xlen); + + ctx->eng.iec->mulgen(point, key, olen, curve); + memcpy(ctx->eng.pad, point, glen); + return (int)glen; +} + +/* + * Perform full static ECDH. This occurs only in the context of client + * authentication with certificates: the server uses an EC public key, + * the cipher suite is of type ECDH (not ECDHE), the server requested a + * client certificate and accepts static ECDH, the client has a + * certificate with an EC public key in the same curve, and accepts + * static ECDH as well. + * + * Returned value is 0 on success, -1 on error. + */ +static int +make_pms_static_ecdh(br_ssl_client_context *ctx, int prf_id) +{ + unsigned char point[133]; + size_t point_len; + const br_x509_class **xc; + const br_x509_pkey *pk; + + xc = ctx->eng.x509ctx; + pk = (*xc)->get_pkey(xc, NULL); + point_len = pk->key.ec.qlen; + if (point_len > sizeof point) { + return -1; + } + memcpy(point, pk->key.ec.q, point_len); + if (!(*ctx->client_auth_vtable)->do_keyx( + ctx->client_auth_vtable, point, &point_len)) + { + return -1; + } + br_ssl_engine_compute_master(&ctx->eng, + prf_id, point, point_len); + return 0; +} + +/* + * Compute the client-side signature. This is invoked only when a + * signature-based client authentication was selected. The computed + * signature is in the pad; its length (in bytes) is returned. On + * error, 0 is returned. + */ +static size_t +make_client_sign(br_ssl_client_context *ctx) +{ + size_t hv_len; + + /* + * Compute hash of handshake messages so far. This "cannot" fail + * because the list of supported hash functions provided to the + * client certificate handler was trimmed to include only the + * hash functions that the multi-hasher supports. + */ + if (ctx->hash_id) { + hv_len = br_multihash_out(&ctx->eng.mhash, + ctx->hash_id, ctx->eng.pad); + } else { + br_multihash_out(&ctx->eng.mhash, + br_md5_ID, ctx->eng.pad); + br_multihash_out(&ctx->eng.mhash, + br_sha1_ID, ctx->eng.pad + 16); + hv_len = 36; + } + return (*ctx->client_auth_vtable)->do_sign( + ctx->client_auth_vtable, ctx->hash_id, hv_len, + ctx->eng.pad, sizeof ctx->eng.pad); +} + +} + +\ ======================================================================= + +: addr-ctx: + next-word { field } + "addr-" field + 0 1 define-word + 0 8191 "offsetof(br_ssl_client_context, " field + ")" + make-CX + postpone literal postpone ; ; + +addr-ctx: min_clienthello_len +addr-ctx: hashes +addr-ctx: auth_type +addr-ctx: hash_id + +\ Length of the Secure Renegotiation extension. This is 5 for the +\ first handshake, 17 for a renegotiation (if the server supports the +\ extension), or 0 if we know that the server does not support the +\ extension. +: ext-reneg-length ( -- n ) + addr-reneg get8 dup if 1 - 17 * else drop 5 then ; + +\ Length of SNI extension. +: ext-sni-length ( -- len ) + addr-server_name strlen dup if 9 + then ; + +\ Length of Maximum Fragment Length extension. +: ext-frag-length ( -- len ) + addr-log_max_frag_len get8 14 = if 0 else 5 then ; + +\ Length of Signatures extension. +: ext-signatures-length ( -- len ) + supported-hash-functions { num } drop 0 + supports-rsa-sign? if num + then + supports-ecdsa? if num + then + dup if 1 << 6 + then ; + +\ Write supported hash functions ( sign -- ) +: write-hashes + { sign } + supported-hash-functions drop + \ We advertise hash functions in the following preference order: + \ SHA-256 SHA-224 SHA-384 SHA-512 SHA-1 + \ Rationale: + \ -- SHA-256 and SHA-224 are more efficient on 32-bit architectures + \ -- SHA-1 is less than ideally collision-resistant + dup 0x10 and if 4 write8 sign write8 then + dup 0x08 and if 3 write8 sign write8 then + dup 0x20 and if 5 write8 sign write8 then + dup 0x40 and if 6 write8 sign write8 then + 0x04 and if 2 write8 sign write8 then ; + +\ Length of Supported Curves extension. +: ext-supported-curves-length ( -- len ) + supported-curves dup if + 0 { x } + begin dup while + dup 1 and x + >x + 1 >> + repeat + drop x 1 << 6 + + then ; + +\ Length of Supported Point Formats extension. +: ext-point-format-length ( -- len ) + supported-curves if 6 else 0 then ; + +\ Length of ALPN extension. +cc: ext-ALPN-length ( -- len ) { + size_t u, len; + + if (ENG->protocol_names_num == 0) { + T0_PUSH(0); + T0_RET(); + } + len = 6; + for (u = 0; u < ENG->protocol_names_num; u ++) { + len += 1 + strlen(ENG->protocol_names[u]); + } + T0_PUSH(len); +} + +\ Write handshake message: ClientHello +: write-ClientHello ( -- ) + { ; total-ext-length } + + \ Compute length for extensions (without the general two-byte header). + \ This does not take padding extension into account. + ext-reneg-length ext-sni-length + ext-frag-length + + ext-signatures-length + + ext-supported-curves-length + ext-point-format-length + + ext-ALPN-length + + >total-ext-length + + \ ClientHello type + 1 write8 + + \ Compute and write length + 39 addr-session_id_len get8 + addr-suites_num get8 1 << + + total-ext-length if 2+ total-ext-length + then + \ Compute padding (if requested). + addr-min_clienthello_len get16 over - dup 0> if + \ We well add a Pad ClientHello extension, which has its + \ own header (4 bytes) and might be the only extension + \ (2 extra bytes for the extension list header). + total-ext-length ifnot swap 2+ swap 2- then + \ Account for the extension header. + 4 - dup 0< if drop 0 then + \ Adjust total extension length. + dup 4 + total-ext-length + >total-ext-length + \ Adjust ClientHello length. + swap 4 + over + swap + else + drop + -1 + then + { ext-padding-amount } + write24 + + \ Protocol version + addr-version_max get16 write16 + + \ Client random + addr-client_random 4 bzero + addr-client_random 4 + 28 mkrand + addr-client_random 32 write-blob + + \ Session ID + addr-session_id addr-session_id_len get8 write-blob-head8 + + \ Supported cipher suites. We also check here that we indeed + \ support all these suites. + addr-suites_num get8 dup 1 << write16 + addr-suites_buf swap + begin + dup while 1- + over get16 + dup suite-supported? ifnot ERR_BAD_CIPHER_SUITE fail then + write16 + swap 2+ swap + repeat + 2drop + + \ Compression methods (only "null" compression) + 1 write8 0 write8 + + \ Extensions + total-ext-length if + total-ext-length write16 + ext-reneg-length if + 0xFF01 write16 \ extension type (0xFF01) + addr-saved_finished + ext-reneg-length 4 - dup write16 \ extension length + 1- write-blob-head8 \ verify data + then + ext-sni-length if + 0x0000 write16 \ extension type (0) + addr-server_name + ext-sni-length 4 - dup write16 \ extension length + 2 - dup write16 \ ServerNameList length + 0 write8 \ name type: host_name + 3 - write-blob-head16 \ the name itself + then + ext-frag-length if + 0x0001 write16 \ extension type (1) + 0x0001 write16 \ extension length + addr-log_max_frag_len get8 8 - write8 + then + ext-signatures-length if + 0x000D write16 \ extension type (13) + ext-signatures-length 4 - dup write16 \ extension length + 2 - write16 \ list length + supports-ecdsa? if 3 write-hashes then + supports-rsa-sign? if 1 write-hashes then + then + \ TODO: add an API to specify preference order for curves. + \ Right now we send Curve25519 first, then other curves in + \ increasing ID values (hence P-256 in second). + ext-supported-curves-length dup if + 0x000A write16 \ extension type (10) + 4 - dup write16 \ extension length + 2- write16 \ list length + supported-curves 0 + dup 0x20000000 and if + 0xDFFFFFFF and 29 write16 + then + begin dup 32 < while + dup2 >> 1 and if dup write16 then + 1+ + repeat + 2drop + else + drop + then + ext-point-format-length if + 0x000B write16 \ extension type (11) + 0x0002 write16 \ extension length + 0x0100 write16 \ value: 1 format: uncompressed + then + ext-ALPN-length dup if + 0x0010 write16 \ extension type (16) + 4 - dup write16 \ extension length + 2- write16 \ list length + addr-protocol_names_num get16 0 + begin + dup2 > while + dup copy-protocol-name + dup write8 addr-pad swap write-blob + 1+ + repeat + 2drop + else + drop + then + ext-padding-amount 0< ifnot + 0x0015 write16 \ extension value (21) + ext-padding-amount + dup write16 \ extension length + begin dup while + 1- 0 write8 repeat \ value (only zeros) + drop + then + then + ; + +\ ======================================================================= + +\ Parse server SNI extension. If present, then it should be empty. +: read-server-sni ( lim -- lim ) + read16 if ERR_BAD_SNI fail then ; + +\ Parse server Max Fragment Length extension. If present, then it should +\ advertise the same length as the client. Note that whether the server +\ sends it or not changes nothing for us: we won't send any record larger +\ than the advertised value anyway, and we will accept incoming records +\ up to our input buffer length. +: read-server-frag ( lim -- lim ) + read16 1 = ifnot ERR_BAD_FRAGLEN fail then + read8 8 + addr-log_max_frag_len get8 = ifnot ERR_BAD_FRAGLEN fail then ; + +\ Parse server Secure Renegotiation extension. This is called only if +\ the client sent that extension, so we only have two cases to +\ distinguish: first handshake, and renegotiation; in the latter case, +\ we know that the server supports the extension, otherwise the client +\ would not have sent it. +: read-server-reneg ( lim -- lim ) + read16 + addr-reneg get8 ifnot + \ "reneg" is 0, so this is a first handshake. The server's + \ extension MUST be empty. We also learn that the server + \ supports the extension. + 1 = ifnot ERR_BAD_SECRENEG fail then + read8 0 = ifnot ERR_BAD_SECRENEG fail then + 2 addr-reneg set8 + else + \ "reneg" is non-zero, and we sent an extension, so it must + \ be 2 and this is a renegotiation. We must verify that + \ the extension contents have length exactly 24 bytes and + \ match the saved client and server "Finished". + 25 = ifnot ERR_BAD_SECRENEG fail then + read8 24 = ifnot ERR_BAD_SECRENEG fail then + addr-pad 24 read-blob + addr-saved_finished addr-pad 24 memcmp ifnot + ERR_BAD_SECRENEG fail + then + then ; + +\ Read the ALPN extension from the server. It must contain a single name, +\ and that name must match one of our names. +: read-ALPN-from-server ( lim -- lim ) + \ Extension contents length. + read16 open-elt + \ Length of list of names. + read16 open-elt + \ There should be a single name. + read8 addr-pad swap dup { len } read-blob + close-elt + close-elt + len test-protocol-name dup 0< if + 3 flag? if ERR_UNEXPECTED fail then + drop + else + 1+ addr-selected_protocol set16 + then ; + +\ Save a value in a 16-bit field, or check it in case of session resumption. +: check-resume ( val addr resume -- ) + if get16 = ifnot ERR_RESUME_MISMATCH fail then else set16 then ; + +cc: DEBUG-BLOB ( addr len -- ) { + extern int printf(const char *fmt, ...); + + size_t len = T0_POP(); + unsigned char *buf = (unsigned char *)CTX + T0_POP(); + size_t u; + + printf("BLOB:"); + for (u = 0; u < len; u ++) { + if (u % 16 == 0) { + printf("\n "); + } + printf(" %02x", buf[u]); + } + printf("\n"); +} + +\ Parse incoming ServerHello. Returned value is true (-1) on session +\ resumption. +: read-ServerHello ( -- bool ) + \ Get header, and check message type. + read-handshake-header 2 = ifnot ERR_UNEXPECTED fail then + + \ Get protocol version. + read16 { version } + version addr-version_min get16 < version addr-version_max get16 > or if + ERR_UNSUPPORTED_VERSION fail + then + + \ Enforce chosen version for subsequent records in both directions. + version addr-version_in get16 <> if ERR_BAD_VERSION fail then + version addr-version_out set16 + + \ Server random. + addr-server_random 32 read-blob + + \ The "session resumption" flag. + 0 { resume } + + \ Session ID. + read8 { idlen } + idlen 32 > if ERR_OVERSIZED_ID fail then + addr-pad idlen read-blob + idlen addr-session_id_len get8 = idlen 0 > and if + addr-session_id addr-pad idlen memcmp if + \ Server session ID is non-empty and matches what + \ we sent, so this is a session resumption. + -1 >resume + then + then + addr-session_id addr-pad idlen memcpy + idlen addr-session_id_len set8 + + \ Record version. + version addr-version resume check-resume + + \ Cipher suite. We check that it is part of the list of cipher + \ suites that we advertised. + read16 + dup scan-suite 0< if ERR_BAD_CIPHER_SUITE fail then + \ Also check that the cipher suite is compatible with the + \ announced version: suites that don't use HMAC/SHA-1 are + \ for TLS-1.2 only, not older versions. + dup use-tls12? version 0x0303 < and if ERR_BAD_CIPHER_SUITE fail then + addr-cipher_suite resume check-resume + + \ Compression method. Should be 0 (no compression). + read8 if ERR_BAD_COMPRESSION fail then + + \ Parse extensions (if any). If there is no extension, then the + \ read limit (on the TOS) should be 0 at that point. + dup if + \ Length of extension list. + \ message size. + read16 open-elt + + \ Enumerate extensions. For each of them, check that we + \ sent an extension of that type, and did not see it + \ yet; and then process it. + ext-sni-length { ok-sni } + ext-reneg-length { ok-reneg } + ext-frag-length { ok-frag } + ext-signatures-length { ok-signatures } + ext-supported-curves-length { ok-curves } + ext-point-format-length { ok-points } + ext-ALPN-length { ok-ALPN } + begin dup while + read16 + case + \ Server Name Indication. The server may + \ send such an extension if it uses the SNI + \ from the client, but that "response + \ extension" is supposed to be empty. + 0x0000 of + ok-sni ifnot + ERR_EXTRA_EXTENSION fail + then + 0 >ok-sni + read-server-sni + endof + + \ Max Frag Length. The contents shall be + \ a single byte whose value matches the one + \ sent by the client. + 0x0001 of + ok-frag ifnot + ERR_EXTRA_EXTENSION fail + then + 0 >ok-frag + read-server-frag + endof + + \ Secure Renegotiation. + 0xFF01 of + ok-reneg ifnot + ERR_EXTRA_EXTENSION fail + then + 0 >ok-reneg + read-server-reneg + endof + + \ Signature Algorithms. + \ Normally, the server should never send this + \ extension (so says RFC 5246 #7.4.1.4.1), + \ but some existing servers do. + 0x000D of + ok-signatures ifnot + ERR_EXTRA_EXTENSION fail + then + 0 >ok-signatures + read-ignore-16 + endof + + \ Supported Curves. + 0x000A of + ok-curves ifnot + ERR_EXTRA_EXTENSION fail + then + 0 >ok-curves + read-ignore-16 + endof + + \ Supported Point Formats. + 0x000B of + ok-points ifnot + ERR_EXTRA_EXTENSION fail + then + 0 >ok-points + read-ignore-16 + endof + + \ ALPN. + 0x0010 of + ok-ALPN ifnot + ERR_EXTRA_EXTENSION fail + then + 0 >ok-ALPN + read-ALPN-from-server + endof + + ERR_EXTRA_EXTENSION fail + endcase + repeat + + \ If we sent a secure renegotiation extension but did not + \ receive a response, then the server does not support + \ secure renegotiation. This is a hard failure if this + \ is a renegotiation. + ok-reneg if + ok-reneg 5 > if ERR_BAD_SECRENEG fail then + 1 addr-reneg set8 + then + close-elt + else + \ No extension received at all, so the server does not + \ support secure renegotiation. This is a hard failure + \ if the server was previously known to support it (i.e. + \ this is a renegotiation). + ext-reneg-length 5 > if ERR_BAD_SECRENEG fail then + 1 addr-reneg set8 + then + close-elt + resume + ; + +cc: set-server-curve ( -- ) { + const br_x509_class *xc; + const br_x509_pkey *pk; + + xc = *(ENG->x509ctx); + pk = xc->get_pkey(ENG->x509ctx, NULL); + CTX->server_curve = + (pk->key_type == BR_KEYTYPE_EC) ? pk->key.ec.curve : 0; +} + +\ Read Certificate message from server. +: read-Certificate-from-server ( -- ) + addr-cipher_suite get16 expected-key-type + -1 read-Certificate + dup 0< if neg fail then + dup ifnot ERR_UNEXPECTED fail then + over and <> if ERR_WRONG_KEY_USAGE fail then + + \ Set server curve (used for static ECDH). + set-server-curve ; + +\ Verify signature on ECDHE point sent by the server. +\ 'hash' is the hash function to use (1 to 6, or 0 for RSA with MD5+SHA-1) +\ 'use-rsa' is 0 for ECDSA, -1 for for RSA +\ 'sig-len' is the signature length (in bytes) +\ The signature itself is in the pad. +cc: verify-SKE-sig ( hash use-rsa sig-len -- err ) { + size_t sig_len = T0_POP(); + int use_rsa = T0_POPi(); + int hash = T0_POPi(); + + T0_PUSH(verify_SKE_sig(CTX, hash, use_rsa, sig_len)); +} + +\ Parse ServerKeyExchange +: read-ServerKeyExchange ( -- ) + \ Get header, and check message type. + read-handshake-header 12 = ifnot ERR_UNEXPECTED fail then + + \ We expect a named curve, and we must support it. + read8 3 = ifnot ERR_INVALID_ALGORITHM fail then + read16 dup addr-ecdhe_curve set8 + dup 32 >= if ERR_INVALID_ALGORITHM fail then + supported-curves swap >> 1 and ifnot ERR_INVALID_ALGORITHM fail then + + \ Read the server point. + read8 + dup 133 > if ERR_INVALID_ALGORITHM fail then + dup addr-ecdhe_point_len set8 + addr-ecdhe_point swap read-blob + + \ If using TLS-1.2+, then the hash function and signature algorithm + \ are explicitly provided; the signature algorithm must match what + \ the cipher suite specifies. With TLS-1.0 and 1.1, the signature + \ algorithm is inferred from the cipher suite, and the hash is + \ either MD5+SHA-1 (for RSA signatures) or SHA-1 (for ECDSA). + addr-version get16 0x0303 >= { tls1.2+ } + addr-cipher_suite get16 use-rsa-ecdhe? { use-rsa } + 2 { hash } + tls1.2+ if + \ Read hash function; accept only the SHA-* identifiers + \ (from SHA-1 to SHA-512, no MD5 here). + read8 + dup dup 2 < swap 6 > or if ERR_INVALID_ALGORITHM fail then + >hash + read8 + \ Get expected signature algorithm and compare with what + \ the server just sent. Expected value is 1 for RSA, 3 + \ for ECDSA. Note that 'use-rsa' evaluates to -1 for RSA, + \ 0 for ECDSA. + use-rsa 1 << 3 + = ifnot ERR_INVALID_ALGORITHM fail then + else + \ For MD5+SHA-1, we set 'hash' to 0. + use-rsa if 0 >hash then + then + + \ Read signature into the pad. + read16 dup { sig-len } + + dup 512 > if ERR_LIMIT_EXCEEDED fail then + addr-pad swap read-blob + + \ Verify signature. + hash use-rsa sig-len verify-SKE-sig + dup if fail then drop + + close-elt ; + +\ Client certificate: start processing of anchor names. +cc: anchor-dn-start-name-list ( -- ) { + if (CTX->client_auth_vtable != NULL) { + (*CTX->client_auth_vtable)->start_name_list( + CTX->client_auth_vtable); + } +} + +\ Client certificate: start a new anchor DN (length is 16-bit). +cc: anchor-dn-start-name ( length -- ) { + size_t len; + + len = T0_POP(); + if (CTX->client_auth_vtable != NULL) { + (*CTX->client_auth_vtable)->start_name( + CTX->client_auth_vtable, len); + } +} + +\ Client certificate: push some data for current anchor DN. +cc: anchor-dn-append-name ( length -- ) { + size_t len; + + len = T0_POP(); + if (CTX->client_auth_vtable != NULL) { + (*CTX->client_auth_vtable)->append_name( + CTX->client_auth_vtable, ENG->pad, len); + } +} + +\ Client certificate: end current anchor DN. +cc: anchor-dn-end-name ( -- ) { + if (CTX->client_auth_vtable != NULL) { + (*CTX->client_auth_vtable)->end_name( + CTX->client_auth_vtable); + } +} + +\ Client certificate: end list of anchor DN. +cc: anchor-dn-end-name-list ( -- ) { + if (CTX->client_auth_vtable != NULL) { + (*CTX->client_auth_vtable)->end_name_list( + CTX->client_auth_vtable); + } +} + +\ Client certificate: obtain the client certificate chain. +cc: get-client-chain ( auth_types -- ) { + uint32_t auth_types; + + auth_types = T0_POP(); + if (CTX->client_auth_vtable != NULL) { + br_ssl_client_certificate ux; + + (*CTX->client_auth_vtable)->choose(CTX->client_auth_vtable, + CTX, auth_types, &ux); + CTX->auth_type = (unsigned char)ux.auth_type; + CTX->hash_id = (unsigned char)ux.hash_id; + ENG->chain = ux.chain; + ENG->chain_len = ux.chain_len; + } else { + CTX->hash_id = 0; + ENG->chain_len = 0; + } +} + +\ Parse CertificateRequest. Header has already been read. +: read-contents-CertificateRequest ( lim -- ) + \ Read supported client authentication types. We keep only + \ RSA, ECDSA, and ECDH. + 0 { auth_types } + read8 open-elt + begin dup while + read8 case + 1 of 0x0000FF endof + 64 of 0x00FF00 endof + 65 of 0x010000 endof + 66 of 0x020000 endof + 0 swap + endcase + auth_types or >auth_types + repeat + close-elt + + \ Full static ECDH is allowed only if the cipher suite is ECDH + \ (not ECDHE). It would be theoretically feasible to use static + \ ECDH on the client side with an ephemeral key pair from the + \ server, but RFC 4492 (section 3) forbids it because ECDHE suites + \ are supposed to provide forward secrecy, and static ECDH would + \ negate that property. + addr-cipher_suite get16 use-ecdh? ifnot + auth_types 0xFFFF and >auth_types + then + + \ Note: if the cipher suite is ECDH, then the X.509 validation + \ engine was invoked with the BR_KEYTYPE_EC | BR_KEYTYPE_KEYX + \ combination, so the server's public key has already been + \ checked to be fit for a key exchange. + + \ With TLS 1.2: + \ - rsa_fixed_ecdh and ecdsa_fixed_ecdh are synoymous. + \ - There is an explicit list of supported sign+hash. + \ With TLS 1.0, + addr-version get16 0x0303 >= if + \ With TLS 1.2: + \ - There is an explicit list of supported sign+hash. + \ - The ECDH flags must be adjusted for RSA/ECDSA + \ support. + read-list-sign-algos dup addr-hashes set32 + + \ Trim down the list depending on what hash functions + \ we support (since the hashing itself is done by the SSL + \ engine, not by the certificate handler). + supported-hash-functions drop dup 8 << or 0x030000 or and + + auth_types and + auth_types 0x030000 and if + dup 0x0000FF and if 0x010000 or then + dup 0x00FF00 and if 0x020000 or then + then + >auth_types + else + \ TLS 1.0 or 1.1. The hash function is fixed for signatures + \ (MD5+SHA-1 for RSA, SHA-1 for ECDSA). + auth_types 0x030401 and >auth_types + then + + \ Parse list of anchor DN. + anchor-dn-start-name-list + read16 open-elt + begin dup while + read16 open-elt + dup anchor-dn-start-name + + \ We read the DN by chunks through the pad, so + \ as to use the existing reading function (read-blob) + \ that also ensures proper hashing. + begin + dup while + dup 256 > if 256 else dup then { len } + addr-pad len read-blob + len anchor-dn-append-name + repeat + close-elt + anchor-dn-end-name + repeat + close-elt + anchor-dn-end-name-list + + \ We should have reached the message end. + close-elt + + \ Obtain the client chain. + auth_types get-client-chain + ; + +\ (obsolete) +\ Write an empty Certificate message. +\ : write-empty-Certificate ( -- ) +\ 11 write8 3 write24 0 write24 ; + +cc: do-rsa-encrypt ( prf_id -- nlen ) { + int x; + + x = make_pms_rsa(CTX, T0_POP()); + if (x < 0) { + br_ssl_engine_fail(ENG, -x); + T0_CO(); + } else { + T0_PUSH(x); + } +} + +cc: do-ecdh ( echde prf_id -- ulen ) { + unsigned prf_id = T0_POP(); + unsigned ecdhe = T0_POP(); + int x; + + x = make_pms_ecdh(CTX, ecdhe, prf_id); + if (x < 0) { + br_ssl_engine_fail(ENG, -x); + T0_CO(); + } else { + T0_PUSH(x); + } +} + +cc: do-static-ecdh ( prf-id -- ) { + unsigned prf_id = T0_POP(); + + if (make_pms_static_ecdh(CTX, prf_id) < 0) { + br_ssl_engine_fail(ENG, BR_ERR_INVALID_ALGORITHM); + T0_CO(); + } +} + +cc: do-client-sign ( -- sig_len ) { + size_t sig_len; + + sig_len = make_client_sign(CTX); + if (sig_len == 0) { + br_ssl_engine_fail(ENG, BR_ERR_INVALID_ALGORITHM); + T0_CO(); + } + T0_PUSH(sig_len); +} + +\ Write ClientKeyExchange. +: write-ClientKeyExchange ( -- ) + 16 write8 + addr-cipher_suite get16 + dup use-rsa-keyx? if + prf-id do-rsa-encrypt + dup 2+ write24 + dup write16 + addr-pad swap write-blob + else + dup use-ecdhe? swap prf-id do-ecdh + dup 1+ write24 + dup write8 + addr-pad swap write-blob + then ; + +\ Write CertificateVerify. This is invoked only if a client certificate +\ was requested and sent, and the authentication is not full static ECDH. +: write-CertificateVerify ( -- ) + do-client-sign + 15 write8 dup + addr-version get16 0x0303 >= if + 4 + write24 + addr-hash_id get8 write8 + addr-auth_type get8 write8 + else + 2+ write24 + then + dup write16 addr-pad swap write-blob ; + +\ ======================================================================= + +\ Perform a handshake. +: do-handshake ( -- ) + 0 addr-application_data set8 + 22 addr-record_type_out set8 + 0 addr-selected_protocol set16 + multihash-init + + write-ClientHello + flush-record + read-ServerHello + + if + \ Session resumption. + -1 read-CCS-Finished + -1 write-CCS-Finished + + else + + \ Not a session resumption. + + \ Read certificate; then check key type and usages against + \ cipher suite. + read-Certificate-from-server + + \ Depending on cipher suite, we may now expect a + \ ServerKeyExchange. + addr-cipher_suite get16 expected-key-type + CX 0 63 { BR_KEYTYPE_SIGN } and if + read-ServerKeyExchange + then + + \ Get next header. + read-handshake-header + + \ If this is a CertificateRequest, parse it, then read + \ next header. + dup 13 = if + drop read-contents-CertificateRequest + read-handshake-header + -1 + else + 0 + then + { seen-CR } + + \ At that point, we should have a ServerHelloDone, + \ whose length must be 0. + 14 = ifnot ERR_UNEXPECTED fail then + if ERR_BAD_HELLO_DONE fail then + + \ There should not be more bytes in the record at that point. + more-incoming-bytes? if ERR_UNEXPECTED fail then + + seen-CR if + \ If the server requested a client certificate, then + \ we must write a Certificate message (it may be + \ empty). + write-Certificate + + \ If using static ECDH, then the ClientKeyExchange + \ is empty, and there is no CertificateVerify. + \ Otherwise, there is a ClientKeyExchange; there + \ will then be a CertificateVerify if a client chain + \ was indeed sent. + addr-hash_id get8 0xFF = if + drop + 16 write8 0 write24 + addr-cipher_suite get16 prf-id do-static-ecdh + else + write-ClientKeyExchange + if write-CertificateVerify then + then + else + write-ClientKeyExchange + then + + -1 write-CCS-Finished + -1 read-CCS-Finished + then + + \ Now we should be invoked only in case of renegotiation. + 1 addr-application_data set8 + 23 addr-record_type_out set8 ; + +\ Read a HelloRequest message. +: read-HelloRequest ( -- ) + \ A HelloRequest has length 0 and type 0. + read-handshake-header-core + if ERR_UNEXPECTED fail then + if ERR_BAD_HANDSHAKE fail then ; + +\ Entry point. +: main ( -- ! ) + \ Perform initial handshake. + do-handshake + + begin + \ Wait for further invocation. At that point, we should + \ get either an explicit call for renegotiation, or + \ an incoming HelloRequest handshake message. + wait-co + dup 0x07 and case + 0x00 of + 0x10 and if + do-handshake + then + endof + 0x01 of + drop + 0 addr-application_data set8 + read-HelloRequest + \ Reject renegotiations if the peer does not + \ support secure renegotiation, or if the + \ "no renegotiation" flag is set. + addr-reneg get8 1 = 1 flag? or if + flush-record + begin can-output? not while + wait-co drop + repeat + 100 send-warning + \ We rejected the renegotiation, + \ but the connection is not dead. + \ We must set back things into + \ working "application data" state. + 1 addr-application_data set8 + 23 addr-record_type_out set8 + else + do-handshake + then + endof + ERR_UNEXPECTED fail + endcase + again + ; diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_hs_common.t0 b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_hs_common.t0 new file mode 100644 index 000000000..4674891c4 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_hs_common.t0 @@ -0,0 +1,1382 @@ +\ Copyright (c) 2016 Thomas Pornin +\ +\ Permission is hereby granted, free of charge, to any person obtaining +\ a copy of this software and associated documentation files (the +\ "Software"), to deal in the Software without restriction, including +\ without limitation the rights to use, copy, modify, merge, publish, +\ distribute, sublicense, and/or sell copies of the Software, and to +\ permit persons to whom the Software is furnished to do so, subject to +\ the following conditions: +\ +\ The above copyright notice and this permission notice shall be +\ included in all copies or substantial portions of the Software. +\ +\ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +\ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +\ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +\ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +\ BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +\ ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +\ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +\ SOFTWARE. + +\ ---------------------------------------------------------------------- +\ This is the common T0 code for processing handshake messages (code that +\ is used by both client and server). + +preamble { + +#include +#include + +#include "inner.h" + +/* + * This macro evaluates to a pointer to the current engine context. + */ +#define ENG ((br_ssl_engine_context *)(void *)((unsigned char *)t0ctx - offsetof(br_ssl_engine_context, cpu))) + +} + +\ IMPLEMENTATION NOTES +\ ==================== +\ +\ This code handles all records except application data records. +\ Application data is accepted (incoming records, outgoing payload data) +\ only when the application_data flag is set, which is done at the end +\ of the handshake; and it is cleared whenever a renegotiation or a +\ closure takes place. +\ +\ Incoming alerts are processed on the fly; fatal alerts terminate the +\ context, while warnings are ignored, except for close_notify, which +\ triggers the closure procedure. That procedure never returns (it ends +\ with an 'ERR_OK fail' call). We can thus make this processing right +\ into the read functions. +\ +\ Specific actions from the caller (closure or renegotiation) may happen +\ only when jumping back into the T0 code, i.e. just after a 'co' call. +\ Similarly, incoming record type may change only while the caller has +\ control, so we need to check that type only when returning from a 'co'. +\ +\ The handshake processor needs to defer back to the caller ('co') only +\ in one of the following situations: +\ +\ -- Some handshake data is expected. +\ +\ -- The handshake is finished, and application data may flow. There may +\ be some incoming handshake data (HelloRequest from the server). This +\ is the only situation where a renegotiation call won't be ignored. +\ +\ -- Some change-cipher-spec data is expected. +\ +\ -- An alert record is expected. Other types of incoming records will be +\ skipped. +\ +\ -- Waiting for the currently accumulated record to be sent and the +\ output buffer to become free again for another record. + +\ Placeholder for handling not yet implemented functionalities. +: NYI ( -- ! ) + "NOT YET IMPLEMENTED!" puts cr -1 fail ; + +\ Debug function that prints a string (and a newline) on stderr. +cc: DBG ( addr -- ) { + extern void *stderr; + extern int fprintf(void *, const char *, ...); + fprintf(stderr, "%s\n", &t0_datablock[T0_POPi()]); +} + +\ Debug function that prints a string and an integer value (followed +\ by a newline) on stderr. +cc: DBG2 ( addr x -- ) { + extern void *stderr; + extern int fprintf(void *, const char *, ...); + int32_t x = T0_POPi(); + fprintf(stderr, "%s: %ld (0x%08lX)\n", + &t0_datablock[T0_POPi()], (long)x, (unsigned long)(uint32_t)x); +} + +\ Mark the context as failed with a specific error code. This also +\ returns control to the caller. +cc: fail ( err -- ! ) { + br_ssl_engine_fail(ENG, (int)T0_POPi()); + T0_CO(); +} + +\ Read a byte from the context (address is offset in context). +cc: get8 ( addr -- val ) { + size_t addr = (size_t)T0_POP(); + T0_PUSH(*((unsigned char *)ENG + addr)); +} + +\ Read a 16-bit word from the context (address is offset in context). +cc: get16 ( addr -- val ) { + size_t addr = (size_t)T0_POP(); + T0_PUSH(*(uint16_t *)(void *)((unsigned char *)ENG + addr)); +} + +\ Read a 32-bit word from the context (address is offset in context). +cc: get32 ( addr -- val ) { + size_t addr = (size_t)T0_POP(); + T0_PUSH(*(uint32_t *)(void *)((unsigned char *)ENG + addr)); +} + +\ Set a byte in the context (address is offset in context). +cc: set8 ( val addr -- ) { + size_t addr = (size_t)T0_POP(); + *((unsigned char *)ENG + addr) = (unsigned char)T0_POP(); +} + +\ Set a 16-bit word in the context (address is offset in context). +cc: set16 ( val addr -- ) { + size_t addr = (size_t)T0_POP(); + *(uint16_t *)(void *)((unsigned char *)ENG + addr) = (uint16_t)T0_POP(); +} + +\ Set a 32-bit word in the context (address is offset in context). +cc: set32 ( val addr -- ) { + size_t addr = (size_t)T0_POP(); + *(uint32_t *)(void *)((unsigned char *)ENG + addr) = (uint32_t)T0_POP(); +} + +\ Define a word that evaluates as an address of a field within the +\ engine context. The field name (C identifier) must follow in the +\ source. For field 'foo', the defined word is 'addr-foo'. +: addr-eng: + next-word { field } + "addr-" field + 0 1 define-word + 0 8191 "offsetof(br_ssl_engine_context, " field + ")" + make-CX + postpone literal postpone ; ; + +addr-eng: max_frag_len +addr-eng: log_max_frag_len +addr-eng: peer_log_max_frag_len +addr-eng: shutdown_recv +addr-eng: record_type_in +addr-eng: record_type_out +addr-eng: version_in +addr-eng: version_out +addr-eng: application_data +addr-eng: version_min +addr-eng: version_max +addr-eng: suites_buf +addr-eng: suites_num +addr-eng: server_name +addr-eng: client_random +addr-eng: server_random +addr-eng: ecdhe_curve +addr-eng: ecdhe_point +addr-eng: ecdhe_point_len +addr-eng: reneg +addr-eng: saved_finished +addr-eng: flags +addr-eng: pad +addr-eng: action +addr-eng: alert +addr-eng: close_received +addr-eng: protocol_names_num +addr-eng: selected_protocol + +\ Similar to 'addr-eng:', for fields in the 'session' substructure. +: addr-session-field: + next-word { field } + "addr-" field + 0 1 define-word + 0 8191 "offsetof(br_ssl_engine_context, session) + offsetof(br_ssl_session_parameters, " field + ")" + make-CX + postpone literal postpone ; ; + +addr-session-field: session_id +addr-session-field: session_id_len +addr-session-field: version +addr-session-field: cipher_suite +addr-session-field: master_secret + +\ Check a server flag by index. +: flag? ( index -- bool ) + addr-flags get32 swap >> 1 and neg ; + +\ Define a word that evaluates to an error constant. This assumes that +\ all relevant error codes are in the 0..63 range. +: err: + next-word { name } + name 0 1 define-word + 0 63 "BR_" name + make-CX postpone literal postpone ; ; + +err: ERR_OK +err: ERR_BAD_PARAM +err: ERR_BAD_STATE +err: ERR_UNSUPPORTED_VERSION +err: ERR_BAD_VERSION +err: ERR_BAD_LENGTH +err: ERR_TOO_LARGE +err: ERR_BAD_MAC +err: ERR_NO_RANDOM +err: ERR_UNKNOWN_TYPE +err: ERR_UNEXPECTED +err: ERR_BAD_CCS +err: ERR_BAD_ALERT +err: ERR_BAD_HANDSHAKE +err: ERR_OVERSIZED_ID +err: ERR_BAD_CIPHER_SUITE +err: ERR_BAD_COMPRESSION +err: ERR_BAD_FRAGLEN +err: ERR_BAD_SECRENEG +err: ERR_EXTRA_EXTENSION +err: ERR_BAD_SNI +err: ERR_BAD_HELLO_DONE +err: ERR_LIMIT_EXCEEDED +err: ERR_BAD_FINISHED +err: ERR_RESUME_MISMATCH +err: ERR_INVALID_ALGORITHM +err: ERR_BAD_SIGNATURE +err: ERR_WRONG_KEY_USAGE +err: ERR_NO_CLIENT_AUTH + +\ Get supported curves (bit mask). +cc: supported-curves ( -- x ) { + uint32_t x = ENG->iec == NULL ? 0 : ENG->iec->supported_curves; + T0_PUSH(x); +} + +\ Get supported hash functions (bit mask and number). +\ Note: this (on purpose) skips MD5. +cc: supported-hash-functions ( -- x num ) { + int i; + unsigned x, num; + + x = 0; + num = 0; + for (i = br_sha1_ID; i <= br_sha512_ID; i ++) { + if (br_multihash_getimpl(&ENG->mhash, i)) { + x |= 1U << i; + num ++; + } + } + T0_PUSH(x); + T0_PUSH(num); +} + +\ Test support for RSA signatures. +cc: supports-rsa-sign? ( -- bool ) { + T0_PUSHi(-(ENG->irsavrfy != 0)); +} + +\ Test support for ECDSA signatures. +cc: supports-ecdsa? ( -- bool ) { + T0_PUSHi(-(ENG->iecdsa != 0)); +} + +\ (Re)initialise the multihasher. +cc: multihash-init ( -- ) { + br_multihash_init(&ENG->mhash); +} + +\ Flush the current record: if some payload data has been accumulated, +\ close the record and schedule it for sending. If there is no such data, +\ this function does nothing. +cc: flush-record ( -- ) { + br_ssl_engine_flush_record(ENG); +} + +\ Yield control to the caller. +\ When the control is returned to us, react to the new context. Returned +\ value is a bitwise combination of the following: +\ 0x01 handshake data is available +\ 0x02 change-cipher-spec data is available +\ 0x04 some data other than handshake or change-cipher-spec is available +\ 0x08 output buffer is ready for a new outgoing record +\ 0x10 renegotiation is requested and not to be ignored +\ Flags 0x01, 0x02 and 0x04 are mutually exclusive. +: wait-co ( -- state ) + co + 0 + addr-action get8 dup if + case + 1 of 0 do-close endof + 2 of addr-application_data get8 1 = if + 0x10 or + then endof + endcase + else + drop + then + addr-close_received get8 ifnot + has-input? if + addr-record_type_in get8 case + + \ ChangeCipherSpec + 20 of 0x02 or endof + + \ Alert -- if close_notify received, trigger + \ the closure sequence. + 21 of process-alerts if -1 do-close then endof + + \ Handshake + 22 of 0x01 or endof + + \ Not CCS, Alert or Handshake. + drop 0x04 or 0 + endcase + then + then + can-output? if 0x08 or then ; + +\ Send an alert message. This shall be called only when there is room for +\ an outgoing record. +: send-alert ( level alert -- ) + 21 addr-record_type_out set8 + swap write8-native drop write8-native drop + flush-record ; + +\ Send an alert message of level "warning". This shall be called only when +\ there is room for an outgoing record. +: send-warning ( alert -- ) + 1 swap send-alert ; + +\ Fail by sending a fatal alert. +: fail-alert ( alert -- ! ) + { alert } + flush-record + begin can-output? not while wait-co drop repeat + 2 alert send-alert + begin can-output? not while wait-co drop repeat + alert 512 + fail ; + +\ Perform the close operation: +\ -- Prevent new application data from the caller. +\ -- Incoming data is discarded (except alerts). +\ -- Outgoing data is flushed. +\ -- A close_notify alert is sent. +\ -- If 'cnr' is zero, then incoming data is discarded until a close_notify +\ is received. +\ -- At the end, the context is terminated. +\ +\ cnr shall be either 0 or -1. +: do-close ( cnr -- ! ) + \ 'cnr' is set to non-zero when a close_notify is received from + \ the peer. + { cnr } + + \ Get out of application data state. If we were accepting + \ application data (flag is 1), and we still expect a close_notify + \ from the peer (cnr is 0), then we should set the flag to 2. + \ In all other cases, flag should be set to 0. + addr-application_data get8 cnr not and 1 << addr-application_data set8 + + \ Flush existing payload if any. + flush-record + + \ Wait for room to send the close_notify. Since individual records + \ can always hold at least 512 bytes, we know that when there is + \ room, then there is room for a complete close_notify (two bytes). + begin can-output? not while cnr wait-for-close >cnr repeat + + \ Write the close_notify and flush it. + \ 21 addr-record_type_out set8 + \ 1 write8-native 0 write8-native 2drop + \ flush-record + 0 send-warning + + \ Loop until our record has been sent (we know it's gone when + \ writing is again possible) and a close_notify has been received. + cnr + begin + dup can-output? and if ERR_OK fail then + wait-for-close + again ; + +\ Yield control to the engine, with a possible flush. If 'cnr' is 0, +\ then input is analysed: all input is discarded, until a close_notify +\ is received. +: wait-for-close ( cnr -- cnr ) + co + dup ifnot + has-input? if + addr-record_type_in get8 21 = if + drop process-alerts + \ If we received a close_notify then we + \ no longer accept incoming application + \ data records. + 0 addr-application_data set8 + else + discard-input + then + then + then ; + +\ Test whether there is some accumulated payload that still needs to be +\ sent. +cc: payload-to-send? ( -- bool ) { + T0_PUSHi(-br_ssl_engine_has_pld_to_send(ENG)); +} + +\ Test whether there is some available input data. +cc: has-input? ( -- bool ) { + T0_PUSHi(-(ENG->hlen_in != 0)); +} + +\ Test whether some payload bytes may be written. +cc: can-output? ( -- bool ) { + T0_PUSHi(-(ENG->hlen_out > 0)); +} + +\ Discard current input entirely. +cc: discard-input ( -- ) { + ENG->hlen_in = 0; +} + +\ Low-level read for one byte. If there is no available byte right +\ away, then -1 is returned. Otherwise, the byte value is returned. +\ If the current record type is "handshake" then the read byte is also +\ injected in the multi-hasher. +cc: read8-native ( -- x ) { + if (ENG->hlen_in > 0) { + unsigned char x; + + x = *ENG->hbuf_in ++; + if (ENG->record_type_in == BR_SSL_HANDSHAKE) { + br_multihash_update(&ENG->mhash, &x, 1); + } + T0_PUSH(x); + ENG->hlen_in --; + } else { + T0_PUSHi(-1); + } +} + +\ Low-level read for several bytes. On entry, this expects an address +\ (offset in the engine context) and a length; these values designate +\ where the chunk should go. Upon exit, the new address and length +\ are pushed; that output length contains how many bytes could not be +\ read. If there is no available byte for reading, the address and +\ length are unchanged. +\ If the current record type is "handshake" then the read bytes are +\ injected in the multi-hasher. +cc: read-chunk-native ( addr len -- addr len ) { + size_t clen = ENG->hlen_in; + if (clen > 0) { + uint32_t addr, len; + + len = T0_POP(); + addr = T0_POP(); + if ((size_t)len < clen) { + clen = (size_t)len; + } + memcpy((unsigned char *)ENG + addr, ENG->hbuf_in, clen); + if (ENG->record_type_in == BR_SSL_HANDSHAKE) { + br_multihash_update(&ENG->mhash, ENG->hbuf_in, clen); + } + T0_PUSH(addr + (uint32_t)clen); + T0_PUSH(len - (uint32_t)clen); + ENG->hbuf_in += clen; + ENG->hlen_in -= clen; + } +} + +\ Process available alert bytes. If a fatal alert is received, then the +\ context is terminated; otherwise, this returns either true (-1) if a +\ close_notify was received, false (0) otherwise. +: process-alerts ( -- bool ) + 0 + begin has-input? while read8-native process-alert-byte or repeat + dup if 1 addr-shutdown_recv set8 then ; + +\ Process an alert byte. Returned value is non-zero if this is a close_notify, +\ zero otherwise. +: process-alert-byte ( x -- bool ) + addr-alert get8 case + 0 of + \ 'alert' field is 0, so this byte shall be a level. + \ Levels shall be 1 (warning) or 2 (fatal); we convert + \ all other values to "fatal". + dup 1 <> if drop 2 then + addr-alert set8 0 + endof + 1 of + 0 addr-alert set8 + \ close_notify has value 0. + \ no_renegotiation has value 100, and we treat it + \ as a fatal alert. + dup 100 = if 256 + fail then + 0= + endof + \ Fatal alert implies context termination. + drop 256 + fail + endcase ; + +\ In general we only deal with handshake data here. Alerts are processed +\ in specific code right when they are received, and ChangeCipherSpec has +\ its own handling code. So we need to check that the data is "handshake" +\ only when returning from a coroutine call. + +\ Yield control to the engine. Alerts are processed; if incoming data is +\ neither handshake or alert, then an error is triggered. +: wait-for-handshake ( -- ) + wait-co 0x07 and 0x01 > if ERR_UNEXPECTED fail then ; + +\ Flush outgoing data (if any), then wait for the output buffer to be +\ clear; when this is done, set the output record type to the specified +\ value. +: wait-rectype-out ( rectype -- ) + { rectype } + flush-record + begin + can-output? if rectype addr-record_type_out set8 ret then + wait-co drop + again ; + +\ Read one byte of handshake data. Block until that byte is available. +\ This does not check any length. +: read8-nc ( -- x ) + begin + read8-native dup 0< ifnot ret then + drop wait-for-handshake + again ; + +\ Test whether there are some more bytes in the current record. These +\ bytes have not necessarily been received yet (processing of unencrypted +\ records may begin before all bytes are received). +cc: more-incoming-bytes? ( -- bool ) { + T0_PUSHi(ENG->hlen_in != 0 || !br_ssl_engine_recvrec_finished(ENG)); +} + +\ For reading functions, the TOS is supposed to contain the number of bytes +\ that can still be read (from encapsulating structure header), and it is +\ updated. + +: check-len ( lim len -- lim ) + - dup 0< if ERR_BAD_PARAM fail then ; + +\ Read one byte of handshake data. This pushes an integer in the 0..255 range. +: read8 ( lim -- lim x ) + 1 check-len read8-nc ; + +\ Read a 16-bit value (in the 0..65535 range) +: read16 ( lim -- lim n ) + 2 check-len read8-nc 8 << read8-nc + ; + +\ Read a 24-bit value (in the 0..16777215 range) +: read24 ( lim -- lim n ) + 3 check-len read8-nc 8 << read8-nc + 8 << read8-nc + ; + +\ Read some bytes. The "address" is an offset within the context +\ structure. +: read-blob ( lim addr len -- lim ) + { addr len } + len check-len + addr len + begin + read-chunk-native + dup 0 = if 2drop ret then + wait-for-handshake + again ; + +\ Read some bytes and drop them. +: skip-blob ( lim len -- lim ) + swap over check-len swap + begin dup while read8-nc drop 1- repeat + drop ; + +\ Read a 16-bit length, then skip exactly that many bytes. +: read-ignore-16 ( lim -- lim ) + read16 skip-blob ; + +\ Open a substructure: the inner structure length is checked against, +\ and subtracted, from the output structure current limit. +: open-elt ( lim len -- lim-outer lim-inner ) + dup { len } + - dup 0< if ERR_BAD_PARAM fail then + len ; + +\ Close the current structure. This checks that the limit is 0. +: close-elt ( lim -- ) + if ERR_BAD_PARAM fail then ; + +\ Write one byte of handshake data. +: write8 ( n -- ) + begin + dup write8-native if drop ret then + wait-co drop + again ; + +\ Low-level write for one byte. On exit, it pushes either -1 (byte was +\ written) or 0 (no room in output buffer). +cc: write8-native ( x -- bool ) { + unsigned char x; + + x = (unsigned char)T0_POP(); + if (ENG->hlen_out > 0) { + if (ENG->record_type_out == BR_SSL_HANDSHAKE) { + br_multihash_update(&ENG->mhash, &x, 1); + } + *ENG->hbuf_out ++ = x; + ENG->hlen_out --; + T0_PUSHi(-1); + } else { + T0_PUSHi(0); + } +} + +\ Write a 16-bit value. +: write16 ( n -- ) + dup 8 u>> write8 write8 ; + +\ Write a 24-bit value. +: write24 ( n -- ) + dup 16 u>> write8 write16 ; + +\ Write some bytes. The "address" is an offset within the context +\ structure. +: write-blob ( addr len -- ) + begin + write-blob-chunk + dup 0 = if 2drop ret then + wait-co drop + again ; + +cc: write-blob-chunk ( addr len -- addr len ) { + size_t clen = ENG->hlen_out; + if (clen > 0) { + uint32_t addr, len; + + len = T0_POP(); + addr = T0_POP(); + if ((size_t)len < clen) { + clen = (size_t)len; + } + memcpy(ENG->hbuf_out, (unsigned char *)ENG + addr, clen); + if (ENG->record_type_out == BR_SSL_HANDSHAKE) { + br_multihash_update(&ENG->mhash, ENG->hbuf_out, clen); + } + T0_PUSH(addr + (uint32_t)clen); + T0_PUSH(len - (uint32_t)clen); + ENG->hbuf_out += clen; + ENG->hlen_out -= clen; + } +} + +\ Write a blob with the length as header (over one byte) +: write-blob-head8 ( addr len -- ) + dup write8 write-blob ; + +\ Write a blob with the length as header (over two bytes) +: write-blob-head16 ( addr len -- ) + dup write16 write-blob ; + +\ Perform a byte-to-byte comparison between two blobs. Each blob is +\ provided as an "address" (offset in the context structure); the +\ length is common. Returned value is true (-1) if the two blobs are +\ equal, false (0) otherwise. +cc: memcmp ( addr1 addr2 len -- bool ) { + size_t len = (size_t)T0_POP(); + void *addr2 = (unsigned char *)ENG + (size_t)T0_POP(); + void *addr1 = (unsigned char *)ENG + (size_t)T0_POP(); + int x = memcmp(addr1, addr2, len); + T0_PUSH((uint32_t)-(x == 0)); +} + +\ Copy bytes between two areas, whose addresses are provided as +\ offsets in the context structure. +cc: memcpy ( dst src len -- ) { + size_t len = (size_t)T0_POP(); + void *src = (unsigned char *)ENG + (size_t)T0_POP(); + void *dst = (unsigned char *)ENG + (size_t)T0_POP(); + memcpy(dst, src, len); +} + +\ Get string length (zero-terminated). The string address is provided as +\ an offset relative to the context start. Returned length does not include +\ the terminated 0. +cc: strlen ( str -- len ) { + void *str = (unsigned char *)ENG + (size_t)T0_POP(); + T0_PUSH((uint32_t)strlen(str)); +} + +\ Fill a buffer with zeros. The buffer address is an offset in the context. +cc: bzero ( addr len -- ) { + size_t len = (size_t)T0_POP(); + void *addr = (unsigned char *)ENG + (size_t)T0_POP(); + memset(addr, 0, len); +} + +\ Scan the list of supported cipher suites for a given value. If found, +\ then the list index at which it was found is returned; otherwise, -1 +\ is returned. +: scan-suite ( suite -- index ) + { suite } + addr-suites_num get8 { num } + 0 + begin dup num < while + dup 1 << addr-suites_buf + get16 suite = if ret then + 1+ + repeat + drop -1 ; + +\ ======================================================================= + +\ Generate random bytes into buffer (address is offset in context). +cc: mkrand ( addr len -- ) { + size_t len = (size_t)T0_POP(); + void *addr = (unsigned char *)ENG + (size_t)T0_POP(); + br_hmac_drbg_generate(&ENG->rng, addr, len); +} + +\ Read a handshake message header: type and length. These are returned +\ in reverse order (type is TOS, length is below it). +: read-handshake-header-core ( -- lim type ) + read8-nc 3 read24 swap drop swap ; + +\ Read a handshake message header: type and length. If the header is for +\ a HelloRequest message, then it is discarded and a new header is read +\ (repeatedly if necessary). +: read-handshake-header ( -- lim type ) + begin + read-handshake-header-core dup 0= while + drop if ERR_BAD_HANDSHAKE fail then + repeat ; + +\ ======================================================================= + +\ Cipher suite processing. +\ +\ Unfortunately, cipher suite identifiers are attributed mostly arbitrary, +\ so we have to map the cipher suite numbers we support into aggregate +\ words that encode the information we need. Table below is organized +\ as a sequence of pairs of 16-bit words, the first being the cipher suite +\ identifier, the second encoding the algorithm elements. The suites are +\ ordered by increasing cipher suite ID, so that fast lookups may be +\ performed with a binary search (not implemented for the moment, since it +\ does not appear to matter much in practice). +\ +\ Algorithm elements are encoded over 4 bits each, in the following order +\ (most significant to least significant): +\ +\ -- Server key type: +\ 0 RSA (RSA key exchange) +\ 1 ECDHE-RSA (ECDHE key exchange, RSA signature) +\ 2 ECDHE-ECDSA (ECDHE key exchange, ECDSA signature) +\ 3 ECDH-RSA (ECDH key exchange, certificate is RSA-signed) +\ 4 ECDH-ECDSA (ECDH key exchange, certificate is ECDSA-signed) +\ -- Encryption algorithm: +\ 0 3DES/CBC +\ 1 AES-128/CBC +\ 2 AES-256/CBC +\ 3 AES-128/GCM +\ 4 AES-256/GCM +\ 5 ChaCha20/Poly1305 +\ 6 AES-128/CCM +\ 7 AES-256/CCM +\ 8 AES-128/CCM8 +\ 9 AES-256/CCM8 +\ -- MAC algorithm: +\ 0 none (for suites with AEAD encryption) +\ 2 HMAC/SHA-1 +\ 4 HMAC/SHA-256 +\ 5 HMAC/SHA-384 +\ -- PRF for TLS-1.2: +\ 4 with SHA-256 +\ 5 with SHA-384 +\ +\ WARNING: if adding a new cipher suite that does not use SHA-256 for the +\ PRF (with TLS 1.2), be sure to check the suites_sha384[] array defined +\ in ssl/ssl_keyexport.c + +data: cipher-suite-def + +hexb| 000A 0024 | \ TLS_RSA_WITH_3DES_EDE_CBC_SHA +hexb| 002F 0124 | \ TLS_RSA_WITH_AES_128_CBC_SHA +hexb| 0035 0224 | \ TLS_RSA_WITH_AES_256_CBC_SHA +hexb| 003C 0144 | \ TLS_RSA_WITH_AES_128_CBC_SHA256 +hexb| 003D 0244 | \ TLS_RSA_WITH_AES_256_CBC_SHA256 + +hexb| 009C 0304 | \ TLS_RSA_WITH_AES_128_GCM_SHA256 +hexb| 009D 0405 | \ TLS_RSA_WITH_AES_256_GCM_SHA384 + +hexb| C003 4024 | \ TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA +hexb| C004 4124 | \ TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA +hexb| C005 4224 | \ TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA +hexb| C008 2024 | \ TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA +hexb| C009 2124 | \ TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA +hexb| C00A 2224 | \ TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA +hexb| C00D 3024 | \ TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA +hexb| C00E 3124 | \ TLS_ECDH_RSA_WITH_AES_128_CBC_SHA +hexb| C00F 3224 | \ TLS_ECDH_RSA_WITH_AES_256_CBC_SHA +hexb| C012 1024 | \ TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA +hexb| C013 1124 | \ TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA +hexb| C014 1224 | \ TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA + +hexb| C023 2144 | \ TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 +hexb| C024 2255 | \ TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 +hexb| C025 4144 | \ TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 +hexb| C026 4255 | \ TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 +hexb| C027 1144 | \ TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 +hexb| C028 1255 | \ TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 +hexb| C029 3144 | \ TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 +hexb| C02A 3255 | \ TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384 +hexb| C02B 2304 | \ TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 +hexb| C02C 2405 | \ TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 +hexb| C02D 4304 | \ TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 +hexb| C02E 4405 | \ TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 +hexb| C02F 1304 | \ TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 +hexb| C030 1405 | \ TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 +hexb| C031 3304 | \ TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256 +hexb| C032 3405 | \ TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384 + +hexb| C09C 0604 | \ TLS_RSA_WITH_AES_128_CCM +hexb| C09D 0704 | \ TLS_RSA_WITH_AES_256_CCM +hexb| C0A0 0804 | \ TLS_RSA_WITH_AES_128_CCM_8 +hexb| C0A1 0904 | \ TLS_RSA_WITH_AES_256_CCM_8 +hexb| C0AC 2604 | \ TLS_ECDHE_ECDSA_WITH_AES_128_CCM +hexb| C0AD 2704 | \ TLS_ECDHE_ECDSA_WITH_AES_256_CCM +hexb| C0AE 2804 | \ TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 +hexb| C0AF 2904 | \ TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8 + +hexb| CCA8 1504 | \ TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 +hexb| CCA9 2504 | \ TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 + +hexb| 0000 | \ List terminator. + +\ Convert cipher suite identifier to element words. This returns 0 if +\ the cipher suite is not known. +: cipher-suite-to-elements ( suite -- elts ) + { id } + cipher-suite-def + begin + dup 2+ swap data-get16 + dup ifnot 2drop 0 ret then + id = if data-get16 ret then + 2+ + again ; + +\ Check that a given cipher suite is supported. Note that this also +\ returns true (-1) for the TLS_FALLBACK_SCSV pseudo-ciphersuite. +: suite-supported? ( suite -- bool ) + dup 0x5600 = if drop -1 ret then + cipher-suite-to-elements 0<> ; + +\ Get expected key type for cipher suite. The key type is one of +\ BR_KEYTYPE_RSA or BR_KEYTYPE_EC, combined with either BR_KEYTYPE_KEYX +\ (RSA encryption or static ECDH) or BR_KEYTYPE_SIGN (RSA or ECDSA +\ signature, for ECDHE cipher suites). +: expected-key-type ( suite -- key-type ) + cipher-suite-to-elements 12 >> + case + 0 of CX 0 63 { BR_KEYTYPE_RSA | BR_KEYTYPE_KEYX } endof + 1 of CX 0 63 { BR_KEYTYPE_RSA | BR_KEYTYPE_SIGN } endof + 2 of CX 0 63 { BR_KEYTYPE_EC | BR_KEYTYPE_SIGN } endof + 3 of CX 0 63 { BR_KEYTYPE_EC | BR_KEYTYPE_KEYX } endof + 4 of CX 0 63 { BR_KEYTYPE_EC | BR_KEYTYPE_KEYX } endof + 0 swap + endcase ; + +\ Test whether the cipher suite uses RSA key exchange. +: use-rsa-keyx? ( suite -- bool ) + cipher-suite-to-elements 12 >> 0= ; + +\ Test whether the cipher suite uses ECDHE key exchange, signed with RSA. +: use-rsa-ecdhe? ( suite -- bool ) + cipher-suite-to-elements 12 >> 1 = ; + +\ Test whether the cipher suite uses ECDHE key exchange, signed with ECDSA. +: use-ecdsa-ecdhe? ( suite -- bool ) + cipher-suite-to-elements 12 >> 2 = ; + +\ Test whether the cipher suite uses ECDHE key exchange (with RSA or ECDSA). +: use-ecdhe? ( suite -- bool ) + cipher-suite-to-elements 12 >> dup 0> swap 3 < and ; + +\ Test whether the cipher suite uses ECDH (static) key exchange. +: use-ecdh? ( suite -- bool ) + cipher-suite-to-elements 12 >> 2 > ; + +\ Get identifier for the PRF (TLS 1.2). +: prf-id ( suite -- id ) + cipher-suite-to-elements 15 and ; + +\ Test whether a cipher suite is only for TLS-1.2. Cipher suites that +\ can be used with TLS-1.0 or 1.1 use HMAC/SHA-1. RFC do not formally +\ forbid using a CBC-based TLS-1.2 cipher suite, e.g. based on HMAC/SHA-256, +\ with older protocol versions; however, servers should not do that, since +\ it may confuse clients. Since the server code does not try such games, +\ for consistency, the client should reject it as well (normal servers +\ don't do that, so any attempt is a sign of foul play). +: use-tls12? ( suite -- bool ) + cipher-suite-to-elements 0xF0 and 0x20 <> ; + +\ Switch to negotiated security parameters for input or output. +: switch-encryption ( is-client for-input -- ) + { for-input } + addr-cipher_suite get16 cipher-suite-to-elements { elts } + + \ prf_id + elts 15 and + + \ mac_id + elts 4 >> 15 and + + \ cipher type and key length + elts 8 >> 15 and case + \ 3DES/CBC + 0 of 0 24 + for-input if + switch-cbc-in + else + switch-cbc-out + then + endof + + \ AES-128/CBC + 1 of 1 16 + for-input if + switch-cbc-in + else + switch-cbc-out + then + endof + + \ AES-256/CBC + 2 of 1 32 + for-input if + switch-cbc-in + else + switch-cbc-out + then + endof + + \ AES-128/GCM + 3 of drop 16 + for-input if + switch-aesgcm-in + else + switch-aesgcm-out + then + endof + + \ AES-256/GCM + 4 of drop 32 + for-input if + switch-aesgcm-in + else + switch-aesgcm-out + then + endof + + \ ChaCha20+Poly1305 + 5 of drop + for-input if + switch-chapol-in + else + switch-chapol-out + then + endof + + \ Now we only have AES/CCM suites (6 to 9). Since the + \ input is between 0 and 15, and we checked values 0 to 5, + \ we only need to reject values larger than 9. + dup 9 > if + ERR_BAD_PARAM fail + then + + \ Stack: is_client prf_id mac_id cipher_id + \ We want to remove the mac_id (it is zero for CCM suites) + \ and replace the cipher_id with the key and tag lengths. + \ The following table applies: + \ id key length tag length + \ 6 16 16 + \ 7 32 16 + \ 8 16 8 + \ 9 32 8 + swap drop + dup 1 and 4 << 16 + swap + 8 and 16 swap - + for-input if + switch-aesccm-in + else + switch-aesccm-out + then + ret + endcase + ; + +cc: switch-cbc-out ( is_client prf_id mac_id aes cipher_key_len -- ) { + int is_client, prf_id, mac_id, aes; + unsigned cipher_key_len; + + cipher_key_len = T0_POP(); + aes = T0_POP(); + mac_id = T0_POP(); + prf_id = T0_POP(); + is_client = T0_POP(); + br_ssl_engine_switch_cbc_out(ENG, is_client, prf_id, mac_id, + aes ? ENG->iaes_cbcenc : ENG->ides_cbcenc, cipher_key_len); +} + +cc: switch-cbc-in ( is_client prf_id mac_id aes cipher_key_len -- ) { + int is_client, prf_id, mac_id, aes; + unsigned cipher_key_len; + + cipher_key_len = T0_POP(); + aes = T0_POP(); + mac_id = T0_POP(); + prf_id = T0_POP(); + is_client = T0_POP(); + br_ssl_engine_switch_cbc_in(ENG, is_client, prf_id, mac_id, + aes ? ENG->iaes_cbcdec : ENG->ides_cbcdec, cipher_key_len); +} + +cc: switch-aesgcm-out ( is_client prf_id cipher_key_len -- ) { + int is_client, prf_id; + unsigned cipher_key_len; + + cipher_key_len = T0_POP(); + prf_id = T0_POP(); + is_client = T0_POP(); + br_ssl_engine_switch_gcm_out(ENG, is_client, prf_id, + ENG->iaes_ctr, cipher_key_len); +} + +cc: switch-aesgcm-in ( is_client prf_id cipher_key_len -- ) { + int is_client, prf_id; + unsigned cipher_key_len; + + cipher_key_len = T0_POP(); + prf_id = T0_POP(); + is_client = T0_POP(); + br_ssl_engine_switch_gcm_in(ENG, is_client, prf_id, + ENG->iaes_ctr, cipher_key_len); +} + +cc: switch-chapol-out ( is_client prf_id -- ) { + int is_client, prf_id; + + prf_id = T0_POP(); + is_client = T0_POP(); + br_ssl_engine_switch_chapol_out(ENG, is_client, prf_id); +} + +cc: switch-chapol-in ( is_client prf_id -- ) { + int is_client, prf_id; + + prf_id = T0_POP(); + is_client = T0_POP(); + br_ssl_engine_switch_chapol_in(ENG, is_client, prf_id); +} + +cc: switch-aesccm-out ( is_client prf_id cipher_key_len tag_len -- ) { + int is_client, prf_id; + unsigned cipher_key_len, tag_len; + + tag_len = T0_POP(); + cipher_key_len = T0_POP(); + prf_id = T0_POP(); + is_client = T0_POP(); + br_ssl_engine_switch_ccm_out(ENG, is_client, prf_id, + ENG->iaes_ctrcbc, cipher_key_len, tag_len); +} + +cc: switch-aesccm-in ( is_client prf_id cipher_key_len tag_len -- ) { + int is_client, prf_id; + unsigned cipher_key_len, tag_len; + + tag_len = T0_POP(); + cipher_key_len = T0_POP(); + prf_id = T0_POP(); + is_client = T0_POP(); + br_ssl_engine_switch_ccm_in(ENG, is_client, prf_id, + ENG->iaes_ctrcbc, cipher_key_len, tag_len); +} + +\ Write Finished message. +: write-Finished ( from_client -- ) + compute-Finished + 20 write8 12 write24 addr-pad 12 write-blob ; + +\ Read Finished message. +: read-Finished ( from_client -- ) + compute-Finished + read-handshake-header 20 <> if ERR_UNEXPECTED fail then + addr-pad 12 + 12 read-blob + close-elt + addr-pad dup 12 + 12 memcmp ifnot ERR_BAD_FINISHED fail then ; + +\ Compute the "Finished" contents (either the value to send, or the +\ expected value). The 12-byte string is written in the pad. The +\ "from_client" value is non-zero for the Finished sent by the client. +\ The computed value is also saved in the relevant buffer for handling +\ secure renegotiation. +: compute-Finished ( from_client -- ) + dup addr-saved_finished swap ifnot 12 + then swap + addr-cipher_suite get16 prf-id compute-Finished-inner + addr-pad 12 memcpy ; + +cc: compute-Finished-inner ( from_client prf_id -- ) { + int prf_id = T0_POP(); + int from_client = T0_POPi(); + unsigned char tmp[48]; + br_tls_prf_seed_chunk seed; + + br_tls_prf_impl prf = br_ssl_engine_get_PRF(ENG, prf_id); + seed.data = tmp; + if (ENG->session.version >= BR_TLS12) { + seed.len = br_multihash_out(&ENG->mhash, prf_id, tmp); + } else { + br_multihash_out(&ENG->mhash, br_md5_ID, tmp); + br_multihash_out(&ENG->mhash, br_sha1_ID, tmp + 16); + seed.len = 36; + } + prf(ENG->pad, 12, ENG->session.master_secret, + sizeof ENG->session.master_secret, + from_client ? "client finished" : "server finished", + 1, &seed); +} + +\ Receive ChangeCipherSpec and Finished from the peer. +: read-CCS-Finished ( is-client -- ) + has-input? if + addr-record_type_in get8 20 <> if ERR_UNEXPECTED fail then + else + begin + wait-co 0x07 and dup 0x02 <> while + if ERR_UNEXPECTED fail then + repeat + drop + then + read8-nc 1 <> more-incoming-bytes? or if ERR_BAD_CCS fail then + dup 1 switch-encryption + + \ Read and verify Finished from peer. + not read-Finished ; + +\ Send ChangeCipherSpec and Finished to the peer. +: write-CCS-Finished ( is-client -- ) + \ Flush and wait for output buffer to be clear, so that we may + \ write our ChangeCipherSpec. We must switch immediately after + \ triggering the flush. + 20 wait-rectype-out + 1 write8 + flush-record + dup 0 switch-encryption + 22 wait-rectype-out + write-Finished + flush-record ; + +\ Read and parse a list of supported signature algorithms (with hash +\ functions). The resulting bit field is returned. +: read-list-sign-algos ( lim -- lim value ) + 0 { hashes } + read16 open-elt + begin dup while + read8 { hash } read8 { sign } + + \ If hash is 0x08 then this is a "new algorithm" identifier, + \ and we set the corresponding bit if it is in the 0..15 + \ range. Otherwise, we keep the value only if the signature + \ is either 1 (RSA) or 3 (ECDSA), and the hash is one of the + \ SHA-* functions (2 to 6). Note that we reject MD5. + hash 8 = if + sign 15 <= if + 1 sign 16 + << hashes or >hashes + then + else + hash 2 >= hash 6 <= and + sign 1 = sign 3 = or + and if + hashes 1 sign 1- 2 << hash + << or >hashes + then + then + repeat + close-elt + hashes ; + +\ ======================================================================= + +\ Compute total chain length. This includes the individual certificate +\ headers, but not the total chain header. This also sets the cert_cur, +\ cert_len and chain_len context fields. +cc: total-chain-length ( -- len ) { + size_t u; + uint32_t total; + + total = 0; + for (u = 0; u < ENG->chain_len; u ++) { + total += 3 + (uint32_t)ENG->chain[u].data_len; + } + T0_PUSH(total); +} + +\ Get length for current certificate in the chain; if the chain end was +\ reached, then this returns -1. +cc: begin-cert ( -- len ) { + if (ENG->chain_len == 0) { + T0_PUSHi(-1); + } else { + ENG->cert_cur = ENG->chain->data; + ENG->cert_len = ENG->chain->data_len; + ENG->chain ++; + ENG->chain_len --; + T0_PUSH(ENG->cert_len); + } +} + +\ Copy a chunk of certificate data into the pad. Returned value is the +\ chunk length, or 0 if the certificate end is reached. +cc: copy-cert-chunk ( -- len ) { + size_t clen; + + clen = ENG->cert_len; + if (clen > sizeof ENG->pad) { + clen = sizeof ENG->pad; + } + memcpy(ENG->pad, ENG->cert_cur, clen); + ENG->cert_cur += clen; + ENG->cert_len -= clen; + T0_PUSH(clen); +} + +\ Write a Certificate message. Total chain length (excluding the 3-byte +\ header) is returned; it is 0 if the chain is empty. +: write-Certificate ( -- total_chain_len ) + 11 write8 + total-chain-length dup + dup 3 + write24 write24 + begin + begin-cert + dup 0< if drop ret then write24 + begin copy-cert-chunk dup while + addr-pad swap write-blob + repeat + drop + again ; + +cc: x509-start-chain ( by_client -- ) { + const br_x509_class *xc; + uint32_t bc; + + bc = T0_POP(); + xc = *(ENG->x509ctx); + xc->start_chain(ENG->x509ctx, bc ? ENG->server_name : NULL); +} + +cc: x509-start-cert ( length -- ) { + const br_x509_class *xc; + + xc = *(ENG->x509ctx); + xc->start_cert(ENG->x509ctx, T0_POP()); +} + +cc: x509-append ( length -- ) { + const br_x509_class *xc; + size_t len; + + xc = *(ENG->x509ctx); + len = T0_POP(); + xc->append(ENG->x509ctx, ENG->pad, len); +} + +cc: x509-end-cert ( -- ) { + const br_x509_class *xc; + + xc = *(ENG->x509ctx); + xc->end_cert(ENG->x509ctx); +} + +cc: x509-end-chain ( -- err ) { + const br_x509_class *xc; + + xc = *(ENG->x509ctx); + T0_PUSH(xc->end_chain(ENG->x509ctx)); +} + +cc: get-key-type-usages ( -- key-type-usages ) { + const br_x509_class *xc; + const br_x509_pkey *pk; + unsigned usages; + + xc = *(ENG->x509ctx); + pk = xc->get_pkey(ENG->x509ctx, &usages); + if (pk == NULL) { + T0_PUSH(0); + } else { + T0_PUSH(pk->key_type | usages); + } +} + +\ Read a Certificate message. +\ Parameter: non-zero if this is a read by the client of a certificate +\ sent by the server; zero otherwise. +\ Returned value: +\ - Empty: 0 +\ - Valid: combination of key type and allowed key usages. +\ - Invalid: negative (-x for error code x) +: read-Certificate ( by_client -- key-type-usages ) + \ Get header, and check message type. + read-handshake-header 11 = ifnot ERR_UNEXPECTED fail then + + \ If the chain is empty, do some special processing. + dup 3 = if + read24 if ERR_BAD_PARAM fail then + swap drop ret + then + + \ Start processing the chain through the X.509 engine. + swap x509-start-chain + + \ Total chain length is a 24-bit integer. + read24 open-elt + begin + dup while + read24 open-elt + dup x509-start-cert + + \ We read the certificate by chunks through the pad, so + \ as to use the existing reading function (read-blob) + \ that also ensures proper hashing. + begin + dup while + dup 256 > if 256 else dup then { len } + addr-pad len read-blob + len x509-append + repeat + close-elt + x509-end-cert + repeat + + \ We must close the chain AND the handshake message. + close-elt + close-elt + + \ Chain processing is finished; get the error code. + x509-end-chain + dup if neg ret then drop + + \ Return key type and usages. + get-key-type-usages ; + +\ ======================================================================= + +\ Copy a specific protocol name from the list to the pad. The byte +\ length is returned. +cc: copy-protocol-name ( idx -- len ) { + size_t idx = T0_POP(); + size_t len = strlen(ENG->protocol_names[idx]); + memcpy(ENG->pad, ENG->protocol_names[idx], len); + T0_PUSH(len); +} + +\ Compare name in pad with the configured list of protocol names. +\ If a match is found, then the index is returned; otherwise, -1 +\ is returned. +cc: test-protocol-name ( len -- n ) { + size_t len = T0_POP(); + size_t u; + + for (u = 0; u < ENG->protocol_names_num; u ++) { + const char *name; + + name = ENG->protocol_names[u]; + if (len == strlen(name) && memcmp(ENG->pad, name, len) == 0) { + T0_PUSH(u); + T0_RET(); + } + } + T0_PUSHi(-1); +} diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_hs_server.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_hs_server.c new file mode 100644 index 000000000..79ab84920 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_hs_server.c @@ -0,0 +1,2015 @@ +/* Automatically generated code; do not modify directly. */ + + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include +#include + +typedef struct { + uint32_t *dp; + uint32_t *rp; + const unsigned char *ip; +} t0_context; + +static uint32_t +t0_parse7E_unsigned(const unsigned char **p) +{ + uint32_t x; + + x = 0; + for (;;) { + unsigned y; + + y = *(*p) ++; + x = (x << 7) | (uint32_t)(y & 0x7F); + if (y < 0x80) { + return x; + } + } +} + +static int32_t +t0_parse7E_signed(const unsigned char **p) +{ + int neg; + uint32_t x; + + neg = ((**p) >> 6) & 1; + x = (uint32_t)-neg; + for (;;) { + unsigned y; + + y = *(*p) ++; + x = (x << 7) | (uint32_t)(y & 0x7F); + if (y < 0x80) { + if (neg) { + return -(int32_t)~x - 1; + } else { + return (int32_t)x; + } + } + } +} + +#define T0_VBYTE(x, n) (unsigned char)((((uint32_t)(x) >> (n)) & 0x7F) | 0x80) +#define T0_FBYTE(x, n) (unsigned char)(((uint32_t)(x) >> (n)) & 0x7F) +#define T0_SBYTE(x) (unsigned char)((((uint32_t)(x) >> 28) + 0xF8) ^ 0xF8) +#define T0_INT1(x) T0_FBYTE(x, 0) +#define T0_INT2(x) T0_VBYTE(x, 7), T0_FBYTE(x, 0) +#define T0_INT3(x) T0_VBYTE(x, 14), T0_VBYTE(x, 7), T0_FBYTE(x, 0) +#define T0_INT4(x) T0_VBYTE(x, 21), T0_VBYTE(x, 14), T0_VBYTE(x, 7), T0_FBYTE(x, 0) +#define T0_INT5(x) T0_SBYTE(x), T0_VBYTE(x, 21), T0_VBYTE(x, 14), T0_VBYTE(x, 7), T0_FBYTE(x, 0) + +/* static const unsigned char t0_datablock[]; */ + + +void br_ssl_hs_server_init_main(void *t0ctx); + +void br_ssl_hs_server_run(void *t0ctx); + + + +#include +#include + +#include "inner.h" + +/* + * This macro evaluates to a pointer to the current engine context. + */ +#define ENG ((br_ssl_engine_context *)(void *)((unsigned char *)t0ctx - offsetof(br_ssl_engine_context, cpu))) + + + + + +/* + * This macro evaluates to a pointer to the server context, under that + * specific name. It must be noted that since the engine context is the + * first field of the br_ssl_server_context structure ('eng'), then + * pointers values of both types are interchangeable, modulo an + * appropriate cast. This also means that "addresses" computed as offsets + * within the structure work for both kinds of context. + */ +#define CTX ((br_ssl_server_context *)ENG) + +/* + * Decrypt the pre-master secret (RSA key exchange). + */ +static void +do_rsa_decrypt(br_ssl_server_context *ctx, int prf_id, + unsigned char *epms, size_t len) +{ + uint32_t x; + unsigned char rpms[48]; + + /* + * Decrypt the PMS. + */ + x = (*ctx->policy_vtable)->do_keyx(ctx->policy_vtable, epms, &len); + + /* + * Set the first two bytes to the maximum supported client + * protocol version. These bytes are used for version rollback + * detection; forceing the two bytes will make the master secret + * wrong if the bytes are not correct. This process is + * recommended by RFC 5246 (section 7.4.7.1). + */ + br_enc16be(epms, ctx->client_max_version); + + /* + * Make a random PMS and copy it above the decrypted value if the + * decryption failed. Note that we use a constant-time conditional + * copy. + */ + br_hmac_drbg_generate(&ctx->eng.rng, rpms, sizeof rpms); + br_ccopy(x ^ 1, epms, rpms, sizeof rpms); + + /* + * Compute master secret. + */ + br_ssl_engine_compute_master(&ctx->eng, prf_id, epms, 48); + + /* + * Clear the pre-master secret from RAM: it is normally a buffer + * in the context, hence potentially long-lived. + */ + memset(epms, 0, len); +} + +/* + * Common part for ECDH and ECDHE. + */ +static void +ecdh_common(br_ssl_server_context *ctx, int prf_id, + unsigned char *xcoor, size_t xcoor_len, uint32_t ctl) +{ + unsigned char rpms[80]; + + if (xcoor_len > sizeof rpms) { + xcoor_len = sizeof rpms; + ctl = 0; + } + + /* + * Make a random PMS and copy it above the decrypted value if the + * decryption failed. Note that we use a constant-time conditional + * copy. + */ + br_hmac_drbg_generate(&ctx->eng.rng, rpms, xcoor_len); + br_ccopy(ctl ^ 1, xcoor, rpms, xcoor_len); + + /* + * Compute master secret. + */ + br_ssl_engine_compute_master(&ctx->eng, prf_id, xcoor, xcoor_len); + + /* + * Clear the pre-master secret from RAM: it is normally a buffer + * in the context, hence potentially long-lived. + */ + memset(xcoor, 0, xcoor_len); +} + +/* + * Do the ECDH key exchange (not ECDHE). + */ +static void +do_ecdh(br_ssl_server_context *ctx, int prf_id, + unsigned char *cpoint, size_t cpoint_len) +{ + uint32_t x; + + /* + * Finalise the key exchange. + */ + x = (*ctx->policy_vtable)->do_keyx(ctx->policy_vtable, + cpoint, &cpoint_len); + ecdh_common(ctx, prf_id, cpoint, cpoint_len, x); +} + +/* + * Do the full static ECDH key exchange. When this function is called, + * it has already been verified that the cipher suite uses ECDH (not ECDHE), + * and the client's public key (from its certificate) has type EC and is + * apt for key exchange. + */ +static void +do_static_ecdh(br_ssl_server_context *ctx, int prf_id) +{ + unsigned char cpoint[133]; + size_t cpoint_len; + const br_x509_class **xc; + const br_x509_pkey *pk; + + xc = ctx->eng.x509ctx; + pk = (*xc)->get_pkey(xc, NULL); + cpoint_len = pk->key.ec.qlen; + if (cpoint_len > sizeof cpoint) { + /* + * If the point is larger than our buffer then we need to + * restrict it. Length 2 is not a valid point length, so + * the ECDH will fail. + */ + cpoint_len = 2; + } + memcpy(cpoint, pk->key.ec.q, cpoint_len); + do_ecdh(ctx, prf_id, cpoint, cpoint_len); +} + +static size_t +hash_data(br_ssl_server_context *ctx, + void *dst, int hash_id, const void *src, size_t len) +{ + const br_hash_class *hf; + br_hash_compat_context hc; + + if (hash_id == 0) { + unsigned char tmp[36]; + + hf = br_multihash_getimpl(&ctx->eng.mhash, br_md5_ID); + if (hf == NULL) { + return 0; + } + hf->init(&hc.vtable); + hf->update(&hc.vtable, src, len); + hf->out(&hc.vtable, tmp); + hf = br_multihash_getimpl(&ctx->eng.mhash, br_sha1_ID); + if (hf == NULL) { + return 0; + } + hf->init(&hc.vtable); + hf->update(&hc.vtable, src, len); + hf->out(&hc.vtable, tmp + 16); + memcpy(dst, tmp, 36); + return 36; + } else { + hf = br_multihash_getimpl(&ctx->eng.mhash, hash_id); + if (hf == NULL) { + return 0; + } + hf->init(&hc.vtable); + hf->update(&hc.vtable, src, len); + hf->out(&hc.vtable, dst); + return (hf->desc >> BR_HASHDESC_OUT_OFF) & BR_HASHDESC_OUT_MASK; + } +} + +/* + * Do the ECDHE key exchange (part 1: generation of transient key, and + * computing of the point to send to the client). Returned value is the + * signature length (in bytes), or -x on error (with x being an error + * code). The encoded point is written in the ecdhe_point[] context buffer + * (length in ecdhe_point_len). + */ +static int +do_ecdhe_part1(br_ssl_server_context *ctx, int curve) +{ + unsigned algo_id; + unsigned mask; + const unsigned char *order; + size_t olen, glen; + size_t hv_len, sig_len; + + if (!((ctx->eng.iec->supported_curves >> curve) & 1)) { + return -BR_ERR_INVALID_ALGORITHM; + } + ctx->eng.ecdhe_curve = curve; + + /* + * Generate our private key. We need a non-zero random value + * which is lower than the curve order, in a "large enough" + * range. We force the top bit to 0 and bottom bit to 1, which + * does the trick. Note that contrary to what happens in ECDSA, + * this is not a problem if we do not cover the full range of + * possible values. + */ + order = ctx->eng.iec->order(curve, &olen); + mask = 0xFF; + while (mask >= order[0]) { + mask >>= 1; + } + br_hmac_drbg_generate(&ctx->eng.rng, ctx->ecdhe_key, olen); + ctx->ecdhe_key[0] &= mask; + ctx->ecdhe_key[olen - 1] |= 0x01; + ctx->ecdhe_key_len = olen; + + /* + * Compute our ECDH point. + */ + glen = ctx->eng.iec->mulgen(ctx->eng.ecdhe_point, + ctx->ecdhe_key, olen, curve); + ctx->eng.ecdhe_point_len = glen; + + /* + * Assemble the message to be signed, and possibly hash it. + */ + memcpy(ctx->eng.pad, ctx->eng.client_random, 32); + memcpy(ctx->eng.pad + 32, ctx->eng.server_random, 32); + ctx->eng.pad[64 + 0] = 0x03; + ctx->eng.pad[64 + 1] = 0x00; + ctx->eng.pad[64 + 2] = curve; + ctx->eng.pad[64 + 3] = ctx->eng.ecdhe_point_len; + memcpy(ctx->eng.pad + 64 + 4, + ctx->eng.ecdhe_point, ctx->eng.ecdhe_point_len); + hv_len = 64 + 4 + ctx->eng.ecdhe_point_len; + algo_id = ctx->sign_hash_id; + if (algo_id >= (unsigned)0xFF00) { + hv_len = hash_data(ctx, ctx->eng.pad, algo_id & 0xFF, + ctx->eng.pad, hv_len); + if (hv_len == 0) { + return -BR_ERR_INVALID_ALGORITHM; + } + } + + sig_len = (*ctx->policy_vtable)->do_sign(ctx->policy_vtable, + algo_id, ctx->eng.pad, hv_len, sizeof ctx->eng.pad); + return sig_len ? (int)sig_len : -BR_ERR_INVALID_ALGORITHM; +} + +/* + * Do the ECDHE key exchange (part 2: computation of the shared secret + * from the point sent by the client). + */ +static void +do_ecdhe_part2(br_ssl_server_context *ctx, int prf_id, + unsigned char *cpoint, size_t cpoint_len) +{ + int curve; + uint32_t ctl; + size_t xoff, xlen; + + curve = ctx->eng.ecdhe_curve; + + /* + * Finalise the key exchange. + */ + ctl = ctx->eng.iec->mul(cpoint, cpoint_len, + ctx->ecdhe_key, ctx->ecdhe_key_len, curve); + xoff = ctx->eng.iec->xoff(curve, &xlen); + ecdh_common(ctx, prf_id, cpoint + xoff, xlen, ctl); + + /* + * Clear the ECDHE private key. Forward Secrecy is achieved insofar + * as that key does not get stolen, so we'd better destroy it + * as soon as it ceases to be useful. + */ + memset(ctx->ecdhe_key, 0, ctx->ecdhe_key_len); +} + +/* + * Offset for hash value within the pad (when obtaining all hash values, + * in preparation for verification of the CertificateVerify message). + * Order is MD5, SHA-1, SHA-224, SHA-256, SHA-384, SHA-512; last value + * is used to get the total length. + */ +static const unsigned char HASH_PAD_OFF[] = { 0, 16, 36, 64, 96, 144, 208 }; + +/* + * OID for hash functions in RSA signatures. + */ +static const unsigned char HASH_OID_SHA1[] = { + 0x05, 0x2B, 0x0E, 0x03, 0x02, 0x1A +}; + +static const unsigned char HASH_OID_SHA224[] = { + 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x04 +}; + +static const unsigned char HASH_OID_SHA256[] = { + 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01 +}; + +static const unsigned char HASH_OID_SHA384[] = { + 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02 +}; + +static const unsigned char HASH_OID_SHA512[] = { + 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03 +}; + +static const unsigned char *HASH_OID[] = { + HASH_OID_SHA1, + HASH_OID_SHA224, + HASH_OID_SHA256, + HASH_OID_SHA384, + HASH_OID_SHA512 +}; + +/* + * Verify the signature in CertificateVerify. Returned value is 0 on + * success, or a non-zero error code. Lack of implementation of the + * designated signature algorithm is reported as a "bad signature" + * error (because it means that the peer did not honour our advertised + * set of supported signature algorithms). + */ +static int +verify_CV_sig(br_ssl_server_context *ctx, size_t sig_len) +{ + const br_x509_class **xc; + const br_x509_pkey *pk; + int id; + + id = ctx->hash_CV_id; + xc = ctx->eng.x509ctx; + pk = (*xc)->get_pkey(xc, NULL); + if (pk->key_type == BR_KEYTYPE_RSA) { + unsigned char tmp[64]; + const unsigned char *hash_oid; + + if (id == 0) { + hash_oid = NULL; + } else { + hash_oid = HASH_OID[id - 2]; + } + if (ctx->eng.irsavrfy == 0) { + return BR_ERR_BAD_SIGNATURE; + } + if (!ctx->eng.irsavrfy(ctx->eng.pad, sig_len, + hash_oid, ctx->hash_CV_len, &pk->key.rsa, tmp) + || memcmp(tmp, ctx->hash_CV, ctx->hash_CV_len) != 0) + { + return BR_ERR_BAD_SIGNATURE; + } + } else { + if (ctx->eng.iecdsa == 0) { + return BR_ERR_BAD_SIGNATURE; + } + if (!ctx->eng.iecdsa(ctx->eng.iec, + ctx->hash_CV, ctx->hash_CV_len, + &pk->key.ec, ctx->eng.pad, sig_len)) + { + return BR_ERR_BAD_SIGNATURE; + } + } + return 0; +} + + + +static const unsigned char t0_datablock[] = { + 0x00, 0x00, 0x0A, 0x00, 0x24, 0x00, 0x2F, 0x01, 0x24, 0x00, 0x35, 0x02, + 0x24, 0x00, 0x3C, 0x01, 0x44, 0x00, 0x3D, 0x02, 0x44, 0x00, 0x9C, 0x03, + 0x04, 0x00, 0x9D, 0x04, 0x05, 0xC0, 0x03, 0x40, 0x24, 0xC0, 0x04, 0x41, + 0x24, 0xC0, 0x05, 0x42, 0x24, 0xC0, 0x08, 0x20, 0x24, 0xC0, 0x09, 0x21, + 0x24, 0xC0, 0x0A, 0x22, 0x24, 0xC0, 0x0D, 0x30, 0x24, 0xC0, 0x0E, 0x31, + 0x24, 0xC0, 0x0F, 0x32, 0x24, 0xC0, 0x12, 0x10, 0x24, 0xC0, 0x13, 0x11, + 0x24, 0xC0, 0x14, 0x12, 0x24, 0xC0, 0x23, 0x21, 0x44, 0xC0, 0x24, 0x22, + 0x55, 0xC0, 0x25, 0x41, 0x44, 0xC0, 0x26, 0x42, 0x55, 0xC0, 0x27, 0x11, + 0x44, 0xC0, 0x28, 0x12, 0x55, 0xC0, 0x29, 0x31, 0x44, 0xC0, 0x2A, 0x32, + 0x55, 0xC0, 0x2B, 0x23, 0x04, 0xC0, 0x2C, 0x24, 0x05, 0xC0, 0x2D, 0x43, + 0x04, 0xC0, 0x2E, 0x44, 0x05, 0xC0, 0x2F, 0x13, 0x04, 0xC0, 0x30, 0x14, + 0x05, 0xC0, 0x31, 0x33, 0x04, 0xC0, 0x32, 0x34, 0x05, 0xC0, 0x9C, 0x06, + 0x04, 0xC0, 0x9D, 0x07, 0x04, 0xC0, 0xA0, 0x08, 0x04, 0xC0, 0xA1, 0x09, + 0x04, 0xC0, 0xAC, 0x26, 0x04, 0xC0, 0xAD, 0x27, 0x04, 0xC0, 0xAE, 0x28, + 0x04, 0xC0, 0xAF, 0x29, 0x04, 0xCC, 0xA8, 0x15, 0x04, 0xCC, 0xA9, 0x25, + 0x04, 0x00, 0x00 +}; + +static const unsigned char t0_codeblock[] = { + 0x00, 0x01, 0x00, 0x0B, 0x00, 0x00, 0x01, 0x00, 0x0E, 0x00, 0x00, 0x01, + 0x00, 0x0F, 0x00, 0x00, 0x01, 0x00, 0x10, 0x00, 0x00, 0x01, 0x01, 0x08, + 0x00, 0x00, 0x01, 0x01, 0x09, 0x00, 0x00, 0x01, 0x02, 0x08, 0x00, 0x00, + 0x01, 0x02, 0x09, 0x00, 0x00, 0x29, 0x29, 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_BAD_CCS), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_BAD_FINISHED), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_BAD_FRAGLEN), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_BAD_HANDSHAKE), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_BAD_PARAM), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_BAD_SECRENEG), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_BAD_SIGNATURE), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_BAD_VERSION), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_INVALID_ALGORITHM), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_LIMIT_EXCEEDED), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_NO_CLIENT_AUTH), 0x00, 0x00, 0x01, T0_INT1(BR_ERR_OK), + 0x00, 0x00, 0x01, T0_INT1(BR_ERR_OVERSIZED_ID), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_UNEXPECTED), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_WRONG_KEY_USAGE), 0x00, 0x00, 0x01, + T0_INT2(offsetof(br_ssl_engine_context, action)), 0x00, 0x00, 0x01, + T0_INT2(offsetof(br_ssl_engine_context, alert)), 0x00, 0x00, 0x01, + T0_INT2(offsetof(br_ssl_engine_context, application_data)), 0x00, 0x00, + 0x01, + T0_INT2(offsetof(br_ssl_engine_context, session) + offsetof(br_ssl_session_parameters, cipher_suite)), + 0x00, 0x00, 0x01, + T0_INT2(offsetof(br_ssl_server_context, client_max_version)), 0x00, + 0x00, 0x01, T0_INT2(offsetof(br_ssl_engine_context, client_random)), + 0x00, 0x00, 0x01, + T0_INT2(offsetof(br_ssl_server_context, client_suites)), 0x00, 0x00, + 0x01, T0_INT2(offsetof(br_ssl_server_context, client_suites_num)), + 0x00, 0x00, 0x01, + T0_INT2(offsetof(br_ssl_engine_context, close_received)), 0x00, 0x00, + 0x01, T0_INT2(offsetof(br_ssl_server_context, curves)), 0x00, 0x00, + 0x01, T0_INT2(offsetof(br_ssl_engine_context, ecdhe_point)), 0x00, + 0x00, 0x01, T0_INT2(offsetof(br_ssl_engine_context, ecdhe_point_len)), + 0x00, 0x00, 0x01, T0_INT2(offsetof(br_ssl_engine_context, flags)), + 0x00, 0x00, 0x01, T0_INT2(offsetof(br_ssl_server_context, hashes)), + 0x00, 0x00, 0x7B, 0x01, + T0_INT2(BR_MAX_CIPHER_SUITES * sizeof(br_suite_translated)), 0x00, + 0x00, 0x01, T0_INT2(offsetof(br_ssl_engine_context, log_max_frag_len)), + 0x00, 0x00, 0x01, T0_INT2(offsetof(br_ssl_engine_context, pad)), 0x00, + 0x00, 0x01, + T0_INT2(offsetof(br_ssl_engine_context, peer_log_max_frag_len)), 0x00, + 0x00, 0x01, + T0_INT2(offsetof(br_ssl_engine_context, protocol_names_num)), 0x00, + 0x00, 0x01, T0_INT2(offsetof(br_ssl_engine_context, record_type_in)), + 0x00, 0x00, 0x01, + T0_INT2(offsetof(br_ssl_engine_context, record_type_out)), 0x00, 0x00, + 0x01, T0_INT2(offsetof(br_ssl_engine_context, reneg)), 0x00, 0x00, + 0x01, T0_INT2(offsetof(br_ssl_engine_context, saved_finished)), 0x00, + 0x00, 0x01, + T0_INT2(offsetof(br_ssl_engine_context, selected_protocol)), 0x00, + 0x00, 0x01, T0_INT2(offsetof(br_ssl_engine_context, server_name)), + 0x00, 0x00, 0x01, + T0_INT2(offsetof(br_ssl_engine_context, server_random)), 0x00, 0x00, + 0x01, + T0_INT2(offsetof(br_ssl_engine_context, session) + offsetof(br_ssl_session_parameters, session_id)), + 0x00, 0x00, 0x01, + T0_INT2(offsetof(br_ssl_engine_context, session) + offsetof(br_ssl_session_parameters, session_id_len)), + 0x00, 0x00, 0x01, + T0_INT2(offsetof(br_ssl_engine_context, shutdown_recv)), 0x00, 0x00, + 0x01, T0_INT2(offsetof(br_ssl_server_context, sign_hash_id)), 0x00, + 0x00, 0x01, T0_INT2(offsetof(br_ssl_engine_context, suites_buf)), 0x00, + 0x00, 0x01, T0_INT2(offsetof(br_ssl_engine_context, suites_num)), 0x00, + 0x00, 0x01, + T0_INT2(offsetof(br_ssl_engine_context, session) + offsetof(br_ssl_session_parameters, version)), + 0x00, 0x00, 0x01, T0_INT2(offsetof(br_ssl_engine_context, version_in)), + 0x00, 0x00, 0x01, + T0_INT2(offsetof(br_ssl_engine_context, version_max)), 0x00, 0x00, + 0x01, T0_INT2(offsetof(br_ssl_engine_context, version_min)), 0x00, + 0x00, 0x01, T0_INT2(offsetof(br_ssl_engine_context, version_out)), + 0x00, 0x00, 0x09, 0x2A, 0x5D, 0x06, 0x02, 0x6A, 0x2B, 0x00, 0x00, 0x01, + 0x01, 0x00, 0x01, 0x03, 0x00, 0x9B, 0x2A, 0x63, 0x47, 0x9F, 0x2A, 0x05, + 0x04, 0x65, 0x01, 0x00, 0x00, 0x02, 0x00, 0x0F, 0x06, 0x02, 0x9F, 0x00, + 0x63, 0x04, 0x6B, 0x00, 0x06, 0x02, 0x6A, 0x2B, 0x00, 0x00, 0x2A, 0x8B, + 0x47, 0x05, 0x03, 0x01, 0x0C, 0x08, 0x47, 0x78, 0x2E, 0xA8, 0x1C, 0x85, + 0x01, 0x0C, 0x33, 0x00, 0x00, 0x2A, 0x22, 0x01, 0x08, 0x0C, 0x47, 0x61, + 0x22, 0x08, 0x00, 0x01, 0x03, 0x00, 0x77, 0x30, 0x02, 0x00, 0x38, 0x13, + 0x01, 0x01, 0x0C, 0x77, 0x42, 0x2C, 0x19, 0x38, 0x06, 0x07, 0x02, 0x00, + 0xD0, 0x03, 0x00, 0x04, 0x75, 0x01, 0x00, 0xC7, 0x02, 0x00, 0x2A, 0x19, + 0x13, 0x06, 0x02, 0x71, 0x2B, 0xD0, 0x04, 0x76, 0x00, 0x01, 0x00, 0x77, + 0x42, 0x01, 0x16, 0x89, 0x42, 0x01, 0x00, 0x8C, 0x40, 0x36, 0xB1, 0x35, + 0x06, 0x02, 0x73, 0x2B, 0x06, 0x0A, 0xD7, 0x01, 0x00, 0xD3, 0x01, 0x00, + 0xAD, 0x04, 0x80, 0x46, 0xD7, 0xD4, 0x29, 0xD9, 0x50, 0x06, 0x01, 0xD5, + 0xD8, 0x2C, 0x50, 0x06, 0x31, 0x01, 0x00, 0xAE, 0x2A, 0x5D, 0x06, 0x0F, + 0x01, 0x02, 0xA4, 0x05, 0x02, 0x37, 0x2B, 0x29, 0xB2, 0xB0, 0x2A, 0xC9, + 0x29, 0x04, 0x19, 0x2A, 0x5F, 0x06, 0x0B, 0x29, 0x01, 0x02, 0xA4, 0x05, + 0x02, 0x70, 0x2B, 0xB2, 0x04, 0x0A, 0xB4, 0x2A, 0x05, 0x04, 0x29, 0xAB, + 0x04, 0x02, 0xB3, 0xAF, 0x04, 0x01, 0xB2, 0x01, 0x00, 0xAD, 0x01, 0x00, + 0xD3, 0x3E, 0x01, 0x01, 0x77, 0x42, 0x01, 0x17, 0x89, 0x42, 0x00, 0x00, + 0x3A, 0x3A, 0x00, 0x01, 0x03, 0x00, 0x2C, 0x19, 0x38, 0x06, 0x04, 0xCF, + 0x29, 0x04, 0x78, 0x01, 0x02, 0x02, 0x00, 0xC6, 0x19, 0x38, 0x06, 0x04, + 0xCF, 0x29, 0x04, 0x78, 0x02, 0x00, 0x01, 0x84, 0x00, 0x08, 0x2B, 0x00, + 0x00, 0x81, 0x2F, 0x47, 0x12, 0x01, 0x01, 0x13, 0x37, 0x00, 0x00, 0x2A, + 0x05, 0x04, 0x29, 0x01, 0x7F, 0x00, 0x01, 0x00, 0xA2, 0x12, 0x01, 0x01, + 0x13, 0x5F, 0x06, 0x03, 0x61, 0x04, 0x75, 0x47, 0x29, 0x00, 0x00, 0x01, + 0x7F, 0xA1, 0xCF, 0x2A, 0x01, 0x07, 0x13, 0x01, 0x00, 0x3A, 0x0F, 0x06, + 0x0D, 0x29, 0x01, 0x10, 0x13, 0x06, 0x05, 0x01, 0x00, 0x77, 0x42, 0xC5, + 0x04, 0x33, 0x01, 0x01, 0x3A, 0x0F, 0x06, 0x2A, 0x29, 0x29, 0x8A, 0x30, + 0x01, 0x01, 0x0F, 0x01, 0x01, 0xA4, 0x39, 0x06, 0x18, 0xC8, 0x2C, 0x19, + 0x38, 0x06, 0x04, 0xCF, 0x29, 0x04, 0x78, 0x01, 0x80, 0x64, 0xC7, 0x01, + 0x01, 0x77, 0x42, 0x01, 0x17, 0x89, 0x42, 0x04, 0x03, 0x01, 0x00, 0xA1, + 0x04, 0x03, 0x73, 0x2B, 0x29, 0x04, 0xFF, 0x32, 0x01, 0x2A, 0x03, 0x00, + 0x09, 0x2A, 0x5D, 0x06, 0x02, 0x6A, 0x2B, 0x02, 0x00, 0x00, 0x00, 0x9C, + 0x01, 0x0F, 0x13, 0x00, 0x00, 0x76, 0x30, 0x01, 0x00, 0x3A, 0x0F, 0x06, + 0x10, 0x29, 0x2A, 0x01, 0x01, 0x0E, 0x06, 0x03, 0x29, 0x01, 0x02, 0x76, + 0x42, 0x01, 0x00, 0x04, 0x21, 0x01, 0x01, 0x3A, 0x0F, 0x06, 0x14, 0x29, + 0x01, 0x00, 0x76, 0x42, 0x2A, 0x01, 0x80, 0x64, 0x0F, 0x06, 0x05, 0x01, + 0x82, 0x00, 0x08, 0x2B, 0x5F, 0x04, 0x07, 0x29, 0x01, 0x82, 0x00, 0x08, + 0x2B, 0x29, 0x00, 0x00, 0x01, 0x00, 0x31, 0x06, 0x05, 0x3D, 0xA9, 0x39, + 0x04, 0x78, 0x2A, 0x06, 0x04, 0x01, 0x01, 0x91, 0x42, 0x00, 0x00, 0x01, + 0x1F, 0x13, 0x01, 0x12, 0x0F, 0x05, 0x02, 0x74, 0x2B, 0x78, 0x2E, 0x2A, + 0xCB, 0x05, 0x02, 0x73, 0x2B, 0xA8, 0x28, 0x00, 0x02, 0x87, 0x2E, 0x05, + 0x02, 0xBC, 0x00, 0xC0, 0xA7, 0xC0, 0xA7, 0x01, 0x7E, 0x03, 0x00, 0x2A, + 0x06, 0x17, 0xC2, 0x2A, 0x03, 0x01, 0x85, 0x47, 0xB6, 0x02, 0x01, 0x51, + 0x2A, 0x02, 0x00, 0x53, 0x06, 0x04, 0x03, 0x00, 0x04, 0x01, 0x29, 0x04, + 0x66, 0x9D, 0x9D, 0x02, 0x00, 0x61, 0x8C, 0x40, 0x00, 0x00, 0x31, 0x06, + 0x0B, 0x88, 0x30, 0x01, 0x14, 0x0E, 0x06, 0x02, 0x73, 0x2B, 0x04, 0x11, + 0xCF, 0x01, 0x07, 0x13, 0x2A, 0x01, 0x02, 0x0E, 0x06, 0x06, 0x06, 0x02, + 0x73, 0x2B, 0x04, 0x70, 0x29, 0xC3, 0x01, 0x01, 0x0E, 0x35, 0x39, 0x06, + 0x02, 0x66, 0x2B, 0x2A, 0x01, 0x01, 0xCA, 0x38, 0xB5, 0x00, 0x01, 0xBA, + 0x01, 0x0B, 0x0F, 0x05, 0x02, 0x73, 0x2B, 0x2A, 0x01, 0x03, 0x0F, 0x06, + 0x08, 0xC1, 0x06, 0x02, 0x6A, 0x2B, 0x47, 0x29, 0x00, 0x47, 0x5C, 0xC1, + 0xA7, 0x2A, 0x06, 0x23, 0xC1, 0xA7, 0x2A, 0x5B, 0x2A, 0x06, 0x18, 0x2A, + 0x01, 0x82, 0x00, 0x10, 0x06, 0x05, 0x01, 0x82, 0x00, 0x04, 0x01, 0x2A, + 0x03, 0x00, 0x85, 0x02, 0x00, 0xB6, 0x02, 0x00, 0x58, 0x04, 0x65, 0x9D, + 0x59, 0x04, 0x5A, 0x9D, 0x9D, 0x5A, 0x2A, 0x06, 0x02, 0x37, 0x00, 0x29, + 0x2D, 0x00, 0x02, 0x2A, 0x01, 0x20, 0x13, 0x05, 0x02, 0x74, 0x2B, 0x01, + 0x0F, 0x13, 0x03, 0x00, 0xB0, 0x95, 0x2E, 0x01, 0x86, 0x03, 0x11, 0x06, + 0x23, 0xC0, 0x2A, 0x01, 0x81, 0x7F, 0x13, 0x61, 0x01, 0x01, 0x12, 0x02, + 0x00, 0x0F, 0x05, 0x02, 0x6C, 0x2B, 0x01, 0x08, 0x12, 0x2A, 0x01, 0x02, + 0x0B, 0x3A, 0x01, 0x06, 0x10, 0x39, 0x06, 0x02, 0x6E, 0x2B, 0x04, 0x0D, + 0x02, 0x00, 0x01, 0x01, 0x0F, 0x06, 0x04, 0x01, 0x00, 0x04, 0x02, 0x01, + 0x02, 0x20, 0x05, 0x02, 0x6E, 0x2B, 0xC0, 0x2A, 0x03, 0x01, 0x2A, 0x01, + 0x84, 0x00, 0x10, 0x06, 0x02, 0x6F, 0x2B, 0x85, 0x47, 0xB6, 0x02, 0x01, + 0x55, 0x2A, 0x06, 0x01, 0x2B, 0x29, 0x9D, 0x00, 0x00, 0x1D, 0xBA, 0x01, + 0x0F, 0x0F, 0x05, 0x02, 0x73, 0x2B, 0x00, 0x0A, 0xBA, 0x01, 0x01, 0x0F, + 0x05, 0x02, 0x73, 0x2B, 0xC0, 0x2A, 0x03, 0x00, 0x79, 0x40, 0x7A, 0x01, + 0x20, 0xB6, 0xC2, 0x2A, 0x01, 0x20, 0x10, 0x06, 0x02, 0x72, 0x2B, 0x2A, + 0x90, 0x42, 0x8F, 0x47, 0xB6, 0x1A, 0x03, 0x01, 0xC0, 0xA7, 0x01, 0x00, + 0x03, 0x02, 0x01, 0x00, 0x03, 0x03, 0x83, 0xA2, 0x17, 0x3A, 0x08, 0x03, + 0x04, 0x03, 0x05, 0x2A, 0x06, 0x80, 0x6D, 0xC0, 0x2A, 0x03, 0x06, 0x02, + 0x01, 0x06, 0x0A, 0x2A, 0x78, 0x2E, 0x0F, 0x06, 0x04, 0x01, 0x7F, 0x03, + 0x03, 0x2A, 0x01, 0x81, 0x7F, 0x0F, 0x06, 0x0A, 0x8A, 0x30, 0x06, 0x02, + 0x6B, 0x2B, 0x01, 0x7F, 0x03, 0x02, 0x2A, 0x01, 0x81, 0xAC, 0x00, 0x0F, + 0x06, 0x11, 0x02, 0x00, 0x98, 0x2E, 0x11, 0x02, 0x00, 0x97, 0x2E, 0x0B, + 0x13, 0x06, 0x04, 0x01, 0x7F, 0x03, 0x00, 0xC4, 0x2A, 0x5D, 0x06, 0x03, + 0x29, 0x04, 0x26, 0x01, 0x00, 0xA4, 0x06, 0x0B, 0x01, 0x02, 0x0C, 0x7B, + 0x08, 0x02, 0x06, 0x47, 0x40, 0x04, 0x16, 0x29, 0x02, 0x05, 0x02, 0x04, + 0x11, 0x06, 0x02, 0x69, 0x2B, 0x02, 0x06, 0x02, 0x05, 0x40, 0x02, 0x05, + 0x01, 0x04, 0x08, 0x03, 0x05, 0x04, 0xFF, 0x0F, 0x29, 0x01, 0x00, 0x03, + 0x07, 0xC2, 0xA7, 0x2A, 0x06, 0x09, 0xC2, 0x05, 0x04, 0x01, 0x7F, 0x03, + 0x07, 0x04, 0x74, 0x9D, 0x01, 0x00, 0x8D, 0x42, 0x01, 0x88, 0x04, 0x82, + 0x41, 0x01, 0x84, 0x80, 0x80, 0x00, 0x7E, 0x41, 0x2A, 0x06, 0x80, 0x4E, + 0xC0, 0xA7, 0x2A, 0x06, 0x80, 0x47, 0xC0, 0x01, 0x00, 0x3A, 0x0F, 0x06, + 0x04, 0x29, 0xB9, 0x04, 0x39, 0x01, 0x01, 0x3A, 0x0F, 0x06, 0x04, 0x29, + 0xB7, 0x04, 0x2F, 0x01, 0x83, 0xFE, 0x01, 0x3A, 0x0F, 0x06, 0x04, 0x29, + 0xB8, 0x04, 0x23, 0x01, 0x0D, 0x3A, 0x0F, 0x06, 0x04, 0x29, 0xBE, 0x04, + 0x19, 0x01, 0x0A, 0x3A, 0x0F, 0x06, 0x04, 0x29, 0xBF, 0x04, 0x0F, 0x01, + 0x10, 0x3A, 0x0F, 0x06, 0x04, 0x29, 0xAC, 0x04, 0x05, 0x29, 0xBC, 0x01, + 0x00, 0x29, 0x04, 0xFF, 0x35, 0x9D, 0x9D, 0x02, 0x01, 0x02, 0x03, 0x13, + 0x03, 0x01, 0x02, 0x00, 0x5D, 0x06, 0x08, 0x79, 0x2E, 0x99, 0x40, 0x01, + 0x80, 0x56, 0xA3, 0x97, 0x2E, 0x2A, 0x02, 0x00, 0x10, 0x06, 0x03, 0x29, + 0x02, 0x00, 0x2A, 0x01, 0x86, 0x00, 0x0B, 0x06, 0x02, 0x6D, 0x2B, 0x02, + 0x00, 0x98, 0x2E, 0x0B, 0x06, 0x04, 0x01, 0x80, 0x46, 0xA3, 0x02, 0x01, + 0x06, 0x10, 0x95, 0x2E, 0x02, 0x00, 0x0D, 0x06, 0x05, 0x29, 0x95, 0x2E, + 0x04, 0x04, 0x01, 0x00, 0x03, 0x01, 0x2A, 0x95, 0x40, 0x2A, 0x96, 0x40, + 0x2A, 0x99, 0x40, 0x01, 0x86, 0x03, 0x11, 0x03, 0x08, 0x02, 0x02, 0x06, + 0x04, 0x01, 0x02, 0x8A, 0x42, 0x8A, 0x30, 0x05, 0x04, 0x01, 0x01, 0x8A, + 0x42, 0x02, 0x07, 0x05, 0x03, 0x01, 0x28, 0xA3, 0x44, 0x29, 0x01, 0x82, + 0x01, 0x07, 0x01, 0xFC, 0x80, 0x00, 0x39, 0x82, 0x2F, 0x13, 0x2A, 0x82, + 0x41, 0x2A, 0x01, 0x81, 0x7F, 0x13, 0x5E, 0x37, 0x47, 0x01, 0x08, 0x12, + 0x5E, 0x01, 0x02, 0x13, 0x39, 0x01, 0x0C, 0x0C, 0x03, 0x09, 0x7E, 0x2F, + 0x43, 0x13, 0x2A, 0x7E, 0x41, 0x05, 0x04, 0x01, 0x00, 0x03, 0x09, 0x02, + 0x01, 0x06, 0x03, 0x01, 0x7F, 0x00, 0x8F, 0x01, 0x20, 0x34, 0x01, 0x20, + 0x90, 0x42, 0x7B, 0x2A, 0x03, 0x05, 0x2A, 0x02, 0x04, 0x0B, 0x06, 0x80, + 0x49, 0x2A, 0x2E, 0x2A, 0x9C, 0x2A, 0x01, 0x0C, 0x12, 0x2A, 0x01, 0x01, + 0x0F, 0x47, 0x01, 0x02, 0x0F, 0x39, 0x06, 0x0A, 0x2A, 0x02, 0x09, 0x13, + 0x05, 0x04, 0x65, 0x01, 0x00, 0x2A, 0x02, 0x08, 0x05, 0x0E, 0x2A, 0x01, + 0x81, 0x70, 0x13, 0x01, 0x20, 0x0E, 0x06, 0x04, 0x65, 0x01, 0x00, 0x2A, + 0x2A, 0x06, 0x10, 0x02, 0x05, 0x63, 0x40, 0x02, 0x05, 0x40, 0x02, 0x05, + 0x01, 0x04, 0x08, 0x03, 0x05, 0x04, 0x01, 0x65, 0x01, 0x04, 0x08, 0x04, + 0xFF, 0x30, 0x29, 0x02, 0x05, 0x7B, 0x09, 0x01, 0x02, 0x12, 0x2A, 0x05, + 0x03, 0x01, 0x28, 0xA3, 0x7C, 0x42, 0x8C, 0x2E, 0x01, 0x83, 0xFF, 0x7F, + 0x0F, 0x06, 0x0D, 0x01, 0x03, 0xA4, 0x06, 0x04, 0x01, 0x80, 0x78, 0xA3, + 0x01, 0x00, 0x8C, 0x40, 0x18, 0x05, 0x03, 0x01, 0x28, 0xA3, 0x01, 0x00, + 0x00, 0x00, 0xB4, 0xB3, 0x00, 0x04, 0x78, 0x2E, 0xCE, 0x06, 0x16, 0xC0, + 0x2A, 0x01, 0x84, 0x00, 0x10, 0x06, 0x02, 0x6F, 0x2B, 0x2A, 0x03, 0x00, + 0x85, 0x47, 0xB6, 0x02, 0x00, 0x78, 0x2E, 0xA8, 0x27, 0x78, 0x2E, 0x2A, + 0xCC, 0x47, 0xCB, 0x03, 0x01, 0x03, 0x02, 0x02, 0x01, 0x02, 0x02, 0x39, + 0x06, 0x14, 0xC2, 0x2A, 0x03, 0x03, 0x85, 0x47, 0xB6, 0x02, 0x03, 0x78, + 0x2E, 0xA8, 0x02, 0x02, 0x06, 0x03, 0x26, 0x04, 0x01, 0x24, 0x9D, 0x00, + 0x00, 0xBA, 0x01, 0x10, 0x0F, 0x05, 0x02, 0x73, 0x2B, 0x00, 0x00, 0x9E, + 0xBA, 0x01, 0x14, 0x0E, 0x06, 0x02, 0x73, 0x2B, 0x85, 0x01, 0x0C, 0x08, + 0x01, 0x0C, 0xB6, 0x9D, 0x85, 0x2A, 0x01, 0x0C, 0x08, 0x01, 0x0C, 0x32, + 0x05, 0x02, 0x67, 0x2B, 0x00, 0x02, 0x03, 0x00, 0x03, 0x01, 0x02, 0x00, + 0x9A, 0x02, 0x01, 0x02, 0x00, 0x3C, 0x2A, 0x01, 0x00, 0x0F, 0x06, 0x02, + 0x65, 0x00, 0xD1, 0x04, 0x74, 0x00, 0xC0, 0x01, 0x01, 0x0E, 0x06, 0x02, + 0x68, 0x2B, 0xC2, 0x2A, 0x2A, 0x5F, 0x47, 0x01, 0x05, 0x11, 0x39, 0x06, + 0x02, 0x68, 0x2B, 0x01, 0x08, 0x08, 0x2A, 0x84, 0x30, 0x0B, 0x06, 0x0D, + 0x2A, 0x01, 0x01, 0x47, 0x0C, 0x3F, 0x2A, 0x84, 0x42, 0x86, 0x42, 0x04, + 0x01, 0x29, 0x00, 0x00, 0xC0, 0x8A, 0x30, 0x01, 0x00, 0x3A, 0x0F, 0x06, + 0x13, 0x29, 0x01, 0x01, 0x0F, 0x05, 0x02, 0x6B, 0x2B, 0xC2, 0x06, 0x02, + 0x6B, 0x2B, 0x01, 0x02, 0x8A, 0x42, 0x04, 0x28, 0x01, 0x02, 0x3A, 0x0F, + 0x06, 0x1F, 0x29, 0x01, 0x0D, 0x0F, 0x05, 0x02, 0x6B, 0x2B, 0xC2, 0x01, + 0x0C, 0x0F, 0x05, 0x02, 0x6B, 0x2B, 0x85, 0x01, 0x0C, 0xB6, 0x8B, 0x85, + 0x01, 0x0C, 0x32, 0x05, 0x02, 0x6B, 0x2B, 0x04, 0x03, 0x6B, 0x2B, 0x29, + 0x00, 0x00, 0xC0, 0xA7, 0xC0, 0xA7, 0x2A, 0x06, 0x1D, 0xC2, 0x06, 0x03, + 0xBC, 0x04, 0x15, 0xC0, 0x2A, 0x01, 0x81, 0x7F, 0x0D, 0x06, 0x0C, 0x2A, + 0x8D, 0x08, 0x01, 0x00, 0x47, 0x42, 0x8D, 0x47, 0xB6, 0x04, 0x01, 0xC9, + 0x04, 0x60, 0x9D, 0x9D, 0x00, 0x00, 0xBB, 0x2A, 0x5F, 0x06, 0x07, 0x29, + 0x06, 0x02, 0x69, 0x2B, 0x04, 0x74, 0x00, 0x00, 0xC3, 0x01, 0x03, 0xC1, + 0x47, 0x29, 0x47, 0x00, 0x00, 0xC0, 0xC9, 0x00, 0x03, 0x01, 0x00, 0x03, + 0x00, 0xC0, 0xA7, 0x2A, 0x06, 0x80, 0x50, 0xC2, 0x03, 0x01, 0xC2, 0x03, + 0x02, 0x02, 0x01, 0x01, 0x08, 0x0F, 0x06, 0x16, 0x02, 0x02, 0x01, 0x0F, + 0x0D, 0x06, 0x0D, 0x01, 0x01, 0x02, 0x02, 0x01, 0x10, 0x08, 0x0C, 0x02, + 0x00, 0x39, 0x03, 0x00, 0x04, 0x2A, 0x02, 0x01, 0x01, 0x02, 0x11, 0x02, + 0x01, 0x01, 0x06, 0x0D, 0x13, 0x02, 0x02, 0x01, 0x01, 0x0F, 0x02, 0x02, + 0x01, 0x03, 0x0F, 0x39, 0x13, 0x06, 0x11, 0x02, 0x00, 0x01, 0x01, 0x02, + 0x02, 0x62, 0x01, 0x02, 0x0C, 0x02, 0x01, 0x08, 0x0C, 0x39, 0x03, 0x00, + 0x04, 0xFF, 0x2C, 0x9D, 0x02, 0x00, 0x00, 0x00, 0xC0, 0xA7, 0xBD, 0x82, + 0x41, 0x9D, 0x00, 0x00, 0xC0, 0xA7, 0xC0, 0xA7, 0x01, 0x00, 0x7E, 0x41, + 0x2A, 0x06, 0x15, 0xC0, 0x2A, 0x01, 0x20, 0x0B, 0x06, 0x0B, 0x01, 0x01, + 0x47, 0x0C, 0x7E, 0x2F, 0x39, 0x7E, 0x41, 0x04, 0x01, 0x29, 0x04, 0x68, + 0x9D, 0x9D, 0x00, 0x00, 0x01, 0x02, 0x9A, 0xC3, 0x01, 0x08, 0x0C, 0xC3, + 0x08, 0x00, 0x00, 0x01, 0x03, 0x9A, 0xC3, 0x01, 0x08, 0x0C, 0xC3, 0x08, + 0x01, 0x08, 0x0C, 0xC3, 0x08, 0x00, 0x00, 0x01, 0x01, 0x9A, 0xC3, 0x00, + 0x00, 0x3D, 0x2A, 0x5D, 0x05, 0x01, 0x00, 0x29, 0xD1, 0x04, 0x76, 0x02, + 0x03, 0x00, 0x94, 0x30, 0x03, 0x01, 0x01, 0x00, 0x2A, 0x02, 0x01, 0x0B, + 0x06, 0x10, 0x2A, 0x01, 0x01, 0x0C, 0x93, 0x08, 0x2E, 0x02, 0x00, 0x0F, + 0x06, 0x01, 0x00, 0x61, 0x04, 0x6A, 0x29, 0x01, 0x7F, 0x00, 0x00, 0x2C, + 0x19, 0x38, 0x06, 0x04, 0xCF, 0x29, 0x04, 0x78, 0x01, 0x16, 0x89, 0x42, + 0x01, 0x00, 0xE2, 0x01, 0x00, 0xE1, 0x2C, 0x01, 0x17, 0x89, 0x42, 0x00, + 0x00, 0x01, 0x15, 0x89, 0x42, 0x47, 0x57, 0x29, 0x57, 0x29, 0x2C, 0x00, + 0x00, 0x01, 0x01, 0x47, 0xC6, 0x00, 0x00, 0xBB, 0x01, 0x01, 0x0F, 0x05, + 0x02, 0x73, 0x2B, 0x2A, 0xC9, 0x29, 0x00, 0x00, 0x47, 0x3A, 0x9A, 0x47, + 0x2A, 0x06, 0x05, 0xC3, 0x29, 0x62, 0x04, 0x78, 0x29, 0x00, 0x02, 0x03, + 0x00, 0x78, 0x2E, 0x9C, 0x03, 0x01, 0x02, 0x01, 0x01, 0x0F, 0x13, 0x02, + 0x01, 0x01, 0x04, 0x12, 0x01, 0x0F, 0x13, 0x02, 0x01, 0x01, 0x08, 0x12, + 0x01, 0x0F, 0x13, 0x01, 0x00, 0x3A, 0x0F, 0x06, 0x10, 0x29, 0x01, 0x00, + 0x01, 0x18, 0x02, 0x00, 0x06, 0x03, 0x4C, 0x04, 0x01, 0x4D, 0x04, 0x81, + 0x0D, 0x01, 0x01, 0x3A, 0x0F, 0x06, 0x10, 0x29, 0x01, 0x01, 0x01, 0x10, + 0x02, 0x00, 0x06, 0x03, 0x4C, 0x04, 0x01, 0x4D, 0x04, 0x80, 0x77, 0x01, + 0x02, 0x3A, 0x0F, 0x06, 0x10, 0x29, 0x01, 0x01, 0x01, 0x20, 0x02, 0x00, + 0x06, 0x03, 0x4C, 0x04, 0x01, 0x4D, 0x04, 0x80, 0x61, 0x01, 0x03, 0x3A, + 0x0F, 0x06, 0x0F, 0x29, 0x29, 0x01, 0x10, 0x02, 0x00, 0x06, 0x03, 0x4A, + 0x04, 0x01, 0x4B, 0x04, 0x80, 0x4C, 0x01, 0x04, 0x3A, 0x0F, 0x06, 0x0E, + 0x29, 0x29, 0x01, 0x20, 0x02, 0x00, 0x06, 0x03, 0x4A, 0x04, 0x01, 0x4B, + 0x04, 0x38, 0x01, 0x05, 0x3A, 0x0F, 0x06, 0x0C, 0x29, 0x29, 0x02, 0x00, + 0x06, 0x03, 0x4E, 0x04, 0x01, 0x4F, 0x04, 0x26, 0x2A, 0x01, 0x09, 0x10, + 0x06, 0x02, 0x6A, 0x2B, 0x47, 0x29, 0x2A, 0x01, 0x01, 0x13, 0x01, 0x04, + 0x0C, 0x01, 0x10, 0x08, 0x47, 0x01, 0x08, 0x13, 0x01, 0x10, 0x47, 0x09, + 0x02, 0x00, 0x06, 0x03, 0x48, 0x04, 0x01, 0x49, 0x00, 0x29, 0x00, 0x00, + 0x9C, 0x01, 0x0C, 0x12, 0x01, 0x02, 0x10, 0x00, 0x00, 0x9C, 0x01, 0x0C, + 0x12, 0x2A, 0x60, 0x47, 0x01, 0x03, 0x0B, 0x13, 0x00, 0x00, 0x9C, 0x01, + 0x0C, 0x12, 0x01, 0x01, 0x0F, 0x00, 0x00, 0x9C, 0x01, 0x0C, 0x12, 0x5F, + 0x00, 0x00, 0x1B, 0x01, 0x00, 0x75, 0x30, 0x2A, 0x06, 0x22, 0x01, 0x01, + 0x3A, 0x0F, 0x06, 0x06, 0x29, 0x01, 0x00, 0xA0, 0x04, 0x14, 0x01, 0x02, + 0x3A, 0x0F, 0x06, 0x0D, 0x29, 0x77, 0x30, 0x01, 0x01, 0x0F, 0x06, 0x03, + 0x01, 0x10, 0x39, 0x04, 0x01, 0x29, 0x04, 0x01, 0x29, 0x7D, 0x30, 0x05, + 0x33, 0x31, 0x06, 0x30, 0x88, 0x30, 0x01, 0x14, 0x3A, 0x0F, 0x06, 0x06, + 0x29, 0x01, 0x02, 0x39, 0x04, 0x22, 0x01, 0x15, 0x3A, 0x0F, 0x06, 0x09, + 0x29, 0xAA, 0x06, 0x03, 0x01, 0x7F, 0xA0, 0x04, 0x13, 0x01, 0x16, 0x3A, + 0x0F, 0x06, 0x06, 0x29, 0x01, 0x01, 0x39, 0x04, 0x07, 0x29, 0x01, 0x04, + 0x39, 0x01, 0x00, 0x29, 0x19, 0x06, 0x03, 0x01, 0x08, 0x39, 0x00, 0x00, + 0x1B, 0x2A, 0x05, 0x13, 0x31, 0x06, 0x10, 0x88, 0x30, 0x01, 0x15, 0x0F, + 0x06, 0x08, 0x29, 0xAA, 0x01, 0x00, 0x77, 0x42, 0x04, 0x01, 0x23, 0x00, + 0x00, 0xCF, 0x01, 0x07, 0x13, 0x01, 0x01, 0x10, 0x06, 0x02, 0x73, 0x2B, + 0x00, 0x01, 0x03, 0x00, 0x2C, 0x19, 0x06, 0x05, 0x02, 0x00, 0x89, 0x42, + 0x00, 0xCF, 0x29, 0x04, 0x74, 0x00, 0x01, 0x14, 0xD2, 0x01, 0x01, 0xE2, + 0x2C, 0x2A, 0x01, 0x00, 0xCA, 0x01, 0x16, 0xD2, 0xD6, 0x2C, 0x00, 0x00, + 0x01, 0x0B, 0xE2, 0x52, 0x2A, 0x2A, 0x01, 0x03, 0x08, 0xE1, 0xE1, 0x14, + 0x2A, 0x5D, 0x06, 0x02, 0x29, 0x00, 0xE1, 0x1E, 0x2A, 0x06, 0x05, 0x85, + 0x47, 0xDA, 0x04, 0x77, 0x29, 0x04, 0x6C, 0x00, 0x01, 0x00, 0xDC, 0x95, + 0x2E, 0x01, 0x86, 0x03, 0x11, 0x06, 0x05, 0x63, 0x01, 0x00, 0xDD, 0x08, + 0x50, 0x08, 0x01, 0x03, 0x08, 0x01, 0x0D, 0xE2, 0xE1, 0x01, 0x00, 0xDC, + 0xE2, 0x01, 0x01, 0xDC, 0x29, 0x95, 0x2E, 0x01, 0x86, 0x03, 0x11, 0x06, + 0x08, 0x01, 0x00, 0xDD, 0xE0, 0x01, 0x01, 0xDD, 0x29, 0x50, 0xE0, 0x16, + 0x15, 0x2A, 0x5D, 0x06, 0x02, 0x29, 0x00, 0xE0, 0x1F, 0x2A, 0x06, 0x05, + 0x85, 0x47, 0xDA, 0x04, 0x77, 0x29, 0x04, 0x6C, 0x00, 0x9E, 0x01, 0x14, + 0xE2, 0x01, 0x0C, 0xE1, 0x85, 0x01, 0x0C, 0xDA, 0x00, 0x04, 0x03, 0x00, + 0x01, 0x02, 0xE2, 0x01, 0x80, 0x46, 0x8A, 0x30, 0x01, 0x02, 0x0F, 0x06, + 0x0C, 0x02, 0x00, 0x06, 0x04, 0x01, 0x05, 0x04, 0x02, 0x01, 0x1D, 0x04, + 0x02, 0x01, 0x00, 0x03, 0x01, 0x86, 0x30, 0x06, 0x04, 0x01, 0x05, 0x04, + 0x02, 0x01, 0x00, 0x03, 0x02, 0x8C, 0x2E, 0x2A, 0x06, 0x05, 0x62, 0x21, + 0x01, 0x07, 0x08, 0x03, 0x03, 0x02, 0x01, 0x02, 0x02, 0x08, 0x02, 0x03, + 0x08, 0x2A, 0x06, 0x03, 0x01, 0x02, 0x08, 0x08, 0xE1, 0x95, 0x2E, 0xE0, + 0x8E, 0x01, 0x04, 0x17, 0x8E, 0x01, 0x04, 0x08, 0x01, 0x1C, 0x34, 0x8E, + 0x01, 0x20, 0xDA, 0x01, 0x20, 0xE2, 0x8F, 0x01, 0x20, 0xDA, 0x78, 0x2E, + 0xE0, 0x01, 0x00, 0xE2, 0x02, 0x01, 0x02, 0x02, 0x08, 0x02, 0x03, 0x08, + 0x2A, 0x06, 0x80, 0x40, 0xE0, 0x02, 0x01, 0x2A, 0x06, 0x10, 0x01, 0x83, + 0xFE, 0x01, 0xE0, 0x01, 0x04, 0x09, 0x2A, 0xE0, 0x62, 0x8B, 0x47, 0xDB, + 0x04, 0x01, 0x29, 0x02, 0x02, 0x06, 0x0C, 0x01, 0x01, 0xE0, 0x01, 0x01, + 0xE0, 0x86, 0x30, 0x01, 0x08, 0x09, 0xE2, 0x02, 0x03, 0x2A, 0x06, 0x11, + 0x01, 0x10, 0xE0, 0x01, 0x04, 0x09, 0x2A, 0xE0, 0x64, 0x2A, 0xE0, 0x62, + 0x85, 0x47, 0xDB, 0x04, 0x01, 0x29, 0x04, 0x01, 0x29, 0x00, 0x00, 0x01, + 0x0E, 0xE2, 0x01, 0x00, 0xE1, 0x00, 0x03, 0x78, 0x2E, 0xCC, 0x05, 0x01, + 0x00, 0x7E, 0x2F, 0x2A, 0x01, 0x82, 0x80, 0x80, 0x80, 0x00, 0x13, 0x06, + 0x05, 0x29, 0x01, 0x1D, 0x04, 0x0E, 0x2A, 0x01, 0x83, 0xC0, 0x80, 0x80, + 0x00, 0x13, 0x2A, 0x06, 0x01, 0x47, 0x29, 0xA5, 0x03, 0x00, 0x02, 0x00, + 0x25, 0x2A, 0x5D, 0x06, 0x02, 0x37, 0x2B, 0x03, 0x01, 0x95, 0x2E, 0x01, + 0x86, 0x03, 0x11, 0x03, 0x02, 0x01, 0x0C, 0xE2, 0x02, 0x01, 0x80, 0x30, + 0x08, 0x02, 0x02, 0x01, 0x02, 0x13, 0x08, 0x01, 0x06, 0x08, 0xE1, 0x01, + 0x03, 0xE2, 0x02, 0x00, 0xE0, 0x7F, 0x80, 0x30, 0xDB, 0x02, 0x02, 0x06, + 0x1C, 0x92, 0x2E, 0x2A, 0x01, 0x83, 0xFE, 0x00, 0x0B, 0x06, 0x03, 0xE0, + 0x04, 0x0F, 0x01, 0x81, 0x7F, 0x13, 0xE2, 0x78, 0x2E, 0xCD, 0x01, 0x01, + 0x0C, 0x01, 0x03, 0x08, 0xE2, 0x02, 0x01, 0xE0, 0x85, 0x02, 0x01, 0xDA, + 0x00, 0x00, 0x56, 0x2A, 0x01, 0x00, 0x0F, 0x06, 0x02, 0x65, 0x00, 0xCF, + 0x29, 0x04, 0x73, 0x00, 0x2A, 0xE2, 0xDA, 0x00, 0x00, 0x01, 0x00, 0x78, + 0x2E, 0xCB, 0x06, 0x0C, 0x63, 0x3A, 0x06, 0x08, 0x01, 0x80, 0x41, 0xE2, + 0x01, 0x80, 0x42, 0xE2, 0x46, 0x06, 0x07, 0x61, 0x3A, 0x06, 0x03, 0x01, + 0x01, 0xE2, 0x45, 0x06, 0x08, 0x61, 0x3A, 0x06, 0x04, 0x01, 0x80, 0x40, + 0xE2, 0x47, 0x29, 0x00, 0x01, 0x01, 0x00, 0x03, 0x00, 0x46, 0x45, 0x39, + 0x05, 0x14, 0x01, 0x01, 0x01, 0x80, 0x7C, 0xDE, 0x03, 0x00, 0x01, 0x03, + 0x01, 0x80, 0x7C, 0xDE, 0x02, 0x00, 0x08, 0x47, 0x29, 0x00, 0x46, 0x06, + 0x07, 0x01, 0x01, 0x44, 0x29, 0xDE, 0x03, 0x00, 0x45, 0x06, 0x0A, 0x01, + 0x03, 0x44, 0x29, 0xDE, 0x02, 0x00, 0x08, 0x03, 0x00, 0x29, 0x02, 0x00, + 0x00, 0x00, 0x01, 0x00, 0x01, 0x04, 0xDF, 0x01, 0x05, 0xDF, 0x01, 0x06, + 0xDF, 0x01, 0x03, 0xDF, 0x01, 0x02, 0xDF, 0x0A, 0x65, 0x00, 0x01, 0x03, + 0x00, 0x3A, 0x01, 0x01, 0x02, 0x00, 0x0C, 0x13, 0x05, 0x01, 0x00, 0x63, + 0x01, 0x03, 0x3B, 0x06, 0x07, 0x02, 0x00, 0xE2, 0x01, 0x02, 0x3B, 0xE2, + 0x00, 0x00, 0x2A, 0x01, 0x08, 0x54, 0xE2, 0xE2, 0x00, 0x00, 0x2A, 0x01, + 0x10, 0x54, 0xE2, 0xE0, 0x00, 0x00, 0x2A, 0x57, 0x06, 0x02, 0x29, 0x00, + 0xCF, 0x29, 0x04, 0x76 +}; + +static const uint16_t t0_caddr[] = { + 0, + 5, + 10, + 15, + 20, + 25, + 30, + 35, + 40, + 44, + 48, + 52, + 56, + 60, + 64, + 68, + 72, + 76, + 80, + 84, + 88, + 92, + 96, + 100, + 104, + 109, + 114, + 119, + 124, + 129, + 134, + 139, + 144, + 149, + 154, + 159, + 164, + 169, + 174, + 180, + 185, + 190, + 195, + 200, + 205, + 210, + 215, + 220, + 225, + 230, + 235, + 240, + 245, + 250, + 255, + 260, + 265, + 270, + 275, + 280, + 285, + 290, + 299, + 303, + 328, + 334, + 353, + 364, + 405, + 516, + 520, + 553, + 563, + 587, + 669, + 683, + 689, + 748, + 767, + 789, + 838, + 887, + 963, + 1065, + 1076, + 1670, + 1674, + 1741, + 1751, + 1782, + 1806, + 1852, + 1922, + 1962, + 1976, + 1985, + 1989, + 2084, + 2092, + 2128, + 2139, + 2155, + 2161, + 2172, + 2207, + 2233, + 2245, + 2251, + 2264, + 2279, + 2472, + 2481, + 2494, + 2503, + 2510, + 2616, + 2641, + 2654, + 2670, + 2688, + 2720, + 2793, + 2806, + 2987, + 2995, + 3122, + 3136, + 3141, + 3185, + 3242, + 3263, + 3290, + 3298, + 3306 +}; + +#define T0_INTERPRETED 93 + +#define T0_ENTER(ip, rp, slot) do { \ + const unsigned char *t0_newip; \ + uint32_t t0_lnum; \ + t0_newip = &t0_codeblock[t0_caddr[(slot) - T0_INTERPRETED]]; \ + t0_lnum = t0_parse7E_unsigned(&t0_newip); \ + (rp) += t0_lnum; \ + *((rp) ++) = (uint32_t)((ip) - &t0_codeblock[0]) + (t0_lnum << 16); \ + (ip) = t0_newip; \ + } while (0) + +#define T0_DEFENTRY(name, slot) \ +void \ +name(void *ctx) \ +{ \ + t0_context *t0ctx = ctx; \ + t0ctx->ip = &t0_codeblock[0]; \ + T0_ENTER(t0ctx->ip, t0ctx->rp, slot); \ +} + +T0_DEFENTRY(br_ssl_hs_server_init_main, 166) + +#define T0_NEXT(t0ipp) (*(*(t0ipp)) ++) + +void +br_ssl_hs_server_run(void *t0ctx) +{ + uint32_t *dp, *rp; + const unsigned char *ip; + +#define T0_LOCAL(x) (*(rp - 2 - (x))) +#define T0_POP() (*-- dp) +#define T0_POPi() (*(int32_t *)(-- dp)) +#define T0_PEEK(x) (*(dp - 1 - (x))) +#define T0_PEEKi(x) (*(int32_t *)(dp - 1 - (x))) +#define T0_PUSH(v) do { *dp = (v); dp ++; } while (0) +#define T0_PUSHi(v) do { *(int32_t *)dp = (v); dp ++; } while (0) +#define T0_RPOP() (*-- rp) +#define T0_RPOPi() (*(int32_t *)(-- rp)) +#define T0_RPUSH(v) do { *rp = (v); rp ++; } while (0) +#define T0_RPUSHi(v) do { *(int32_t *)rp = (v); rp ++; } while (0) +#define T0_ROLL(x) do { \ + size_t t0len = (size_t)(x); \ + uint32_t t0tmp = *(dp - 1 - t0len); \ + memmove(dp - t0len - 1, dp - t0len, t0len * sizeof *dp); \ + *(dp - 1) = t0tmp; \ +} while (0) +#define T0_SWAP() do { \ + uint32_t t0tmp = *(dp - 2); \ + *(dp - 2) = *(dp - 1); \ + *(dp - 1) = t0tmp; \ +} while (0) +#define T0_ROT() do { \ + uint32_t t0tmp = *(dp - 3); \ + *(dp - 3) = *(dp - 2); \ + *(dp - 2) = *(dp - 1); \ + *(dp - 1) = t0tmp; \ +} while (0) +#define T0_NROT() do { \ + uint32_t t0tmp = *(dp - 1); \ + *(dp - 1) = *(dp - 2); \ + *(dp - 2) = *(dp - 3); \ + *(dp - 3) = t0tmp; \ +} while (0) +#define T0_PICK(x) do { \ + uint32_t t0depth = (x); \ + T0_PUSH(T0_PEEK(t0depth)); \ +} while (0) +#define T0_CO() do { \ + goto t0_exit; \ +} while (0) +#define T0_RET() goto t0_next + + dp = ((t0_context *)t0ctx)->dp; + rp = ((t0_context *)t0ctx)->rp; + ip = ((t0_context *)t0ctx)->ip; + goto t0_next; + for (;;) { + uint32_t t0x; + + t0_next: + t0x = T0_NEXT(&ip); + if (t0x < T0_INTERPRETED) { + switch (t0x) { + int32_t t0off; + + case 0: /* ret */ + t0x = T0_RPOP(); + rp -= (t0x >> 16); + t0x &= 0xFFFF; + if (t0x == 0) { + ip = NULL; + goto t0_exit; + } + ip = &t0_codeblock[t0x]; + break; + case 1: /* literal constant */ + T0_PUSHi(t0_parse7E_signed(&ip)); + break; + case 2: /* read local */ + T0_PUSH(T0_LOCAL(t0_parse7E_unsigned(&ip))); + break; + case 3: /* write local */ + T0_LOCAL(t0_parse7E_unsigned(&ip)) = T0_POP(); + break; + case 4: /* jump */ + t0off = t0_parse7E_signed(&ip); + ip += t0off; + break; + case 5: /* jump if */ + t0off = t0_parse7E_signed(&ip); + if (T0_POP()) { + ip += t0off; + } + break; + case 6: /* jump if not */ + t0off = t0_parse7E_signed(&ip); + if (!T0_POP()) { + ip += t0off; + } + break; + case 7: { + /* * */ + + uint32_t b = T0_POP(); + uint32_t a = T0_POP(); + T0_PUSH(a * b); + + } + break; + case 8: { + /* + */ + + uint32_t b = T0_POP(); + uint32_t a = T0_POP(); + T0_PUSH(a + b); + + } + break; + case 9: { + /* - */ + + uint32_t b = T0_POP(); + uint32_t a = T0_POP(); + T0_PUSH(a - b); + + } + break; + case 10: { + /* -rot */ + T0_NROT(); + } + break; + case 11: { + /* < */ + + int32_t b = T0_POPi(); + int32_t a = T0_POPi(); + T0_PUSH(-(uint32_t)(a < b)); + + } + break; + case 12: { + /* << */ + + int c = (int)T0_POPi(); + uint32_t x = T0_POP(); + T0_PUSH(x << c); + + } + break; + case 13: { + /* <= */ + + int32_t b = T0_POPi(); + int32_t a = T0_POPi(); + T0_PUSH(-(uint32_t)(a <= b)); + + } + break; + case 14: { + /* <> */ + + uint32_t b = T0_POP(); + uint32_t a = T0_POP(); + T0_PUSH(-(uint32_t)(a != b)); + + } + break; + case 15: { + /* = */ + + uint32_t b = T0_POP(); + uint32_t a = T0_POP(); + T0_PUSH(-(uint32_t)(a == b)); + + } + break; + case 16: { + /* > */ + + int32_t b = T0_POPi(); + int32_t a = T0_POPi(); + T0_PUSH(-(uint32_t)(a > b)); + + } + break; + case 17: { + /* >= */ + + int32_t b = T0_POPi(); + int32_t a = T0_POPi(); + T0_PUSH(-(uint32_t)(a >= b)); + + } + break; + case 18: { + /* >> */ + + int c = (int)T0_POPi(); + int32_t x = T0_POPi(); + T0_PUSHi(x >> c); + + } + break; + case 19: { + /* and */ + + uint32_t b = T0_POP(); + uint32_t a = T0_POP(); + T0_PUSH(a & b); + + } + break; + case 20: { + /* begin-cert */ + + if (ENG->chain_len == 0) { + T0_PUSHi(-1); + } else { + ENG->cert_cur = ENG->chain->data; + ENG->cert_len = ENG->chain->data_len; + ENG->chain ++; + ENG->chain_len --; + T0_PUSH(ENG->cert_len); + } + + } + break; + case 21: { + /* begin-ta-name */ + + const br_x500_name *dn; + if (CTX->cur_dn_index >= CTX->num_tas) { + T0_PUSHi(-1); + } else { + if (CTX->ta_names == NULL) { + dn = &CTX->tas[CTX->cur_dn_index].dn; + } else { + dn = &CTX->ta_names[CTX->cur_dn_index]; + } + CTX->cur_dn_index ++; + CTX->cur_dn = dn->data; + CTX->cur_dn_len = dn->len; + T0_PUSH(CTX->cur_dn_len); + } + + } + break; + case 22: { + /* begin-ta-name-list */ + + CTX->cur_dn_index = 0; + + } + break; + case 23: { + /* bzero */ + + size_t len = (size_t)T0_POP(); + void *addr = (unsigned char *)ENG + (size_t)T0_POP(); + memset(addr, 0, len); + + } + break; + case 24: { + /* call-policy-handler */ + + int x; + br_ssl_server_choices choices; + + x = (*CTX->policy_vtable)->choose( + CTX->policy_vtable, CTX, &choices); + ENG->session.cipher_suite = choices.cipher_suite; + CTX->sign_hash_id = choices.algo_id; + ENG->chain = choices.chain; + ENG->chain_len = choices.chain_len; + T0_PUSHi(-(x != 0)); + + } + break; + case 25: { + /* can-output? */ + + T0_PUSHi(-(ENG->hlen_out > 0)); + + } + break; + case 26: { + /* check-resume */ + + if (ENG->session.session_id_len == 32 + && CTX->cache_vtable != NULL && (*CTX->cache_vtable)->load( + CTX->cache_vtable, CTX, &ENG->session)) + { + T0_PUSHi(-1); + } else { + T0_PUSH(0); + } + + } + break; + case 27: { + /* co */ + T0_CO(); + } + break; + case 28: { + /* compute-Finished-inner */ + + int prf_id = T0_POP(); + int from_client = T0_POPi(); + unsigned char tmp[48]; + br_tls_prf_seed_chunk seed; + + br_tls_prf_impl prf = br_ssl_engine_get_PRF(ENG, prf_id); + seed.data = tmp; + if (ENG->session.version >= BR_TLS12) { + seed.len = br_multihash_out(&ENG->mhash, prf_id, tmp); + } else { + br_multihash_out(&ENG->mhash, br_md5_ID, tmp); + br_multihash_out(&ENG->mhash, br_sha1_ID, tmp + 16); + seed.len = 36; + } + prf(ENG->pad, 12, ENG->session.master_secret, + sizeof ENG->session.master_secret, + from_client ? "client finished" : "server finished", + 1, &seed); + + } + break; + case 29: { + /* compute-hash-CV */ + + int i; + + for (i = 1; i <= 6; i ++) { + br_multihash_out(&ENG->mhash, i, + ENG->pad + HASH_PAD_OFF[i - 1]); + } + + } + break; + case 30: { + /* copy-cert-chunk */ + + size_t clen; + + clen = ENG->cert_len; + if (clen > sizeof ENG->pad) { + clen = sizeof ENG->pad; + } + memcpy(ENG->pad, ENG->cert_cur, clen); + ENG->cert_cur += clen; + ENG->cert_len -= clen; + T0_PUSH(clen); + + } + break; + case 31: { + /* copy-dn-chunk */ + + size_t clen; + + clen = CTX->cur_dn_len; + if (clen > sizeof ENG->pad) { + clen = sizeof ENG->pad; + } + memcpy(ENG->pad, CTX->cur_dn, clen); + CTX->cur_dn += clen; + CTX->cur_dn_len -= clen; + T0_PUSH(clen); + + } + break; + case 32: { + /* copy-hash-CV */ + + int id = T0_POP(); + size_t off, len; + + if (id == 0) { + off = 0; + len = 36; + } else { + if (br_multihash_getimpl(&ENG->mhash, id) == 0) { + T0_PUSH(0); + T0_RET(); + } + off = HASH_PAD_OFF[id - 1]; + len = HASH_PAD_OFF[id] - off; + } + memcpy(CTX->hash_CV, ENG->pad + off, len); + CTX->hash_CV_len = len; + CTX->hash_CV_id = id; + T0_PUSHi(-1); + + } + break; + case 33: { + /* copy-protocol-name */ + + size_t idx = T0_POP(); + size_t len = strlen(ENG->protocol_names[idx]); + memcpy(ENG->pad, ENG->protocol_names[idx], len); + T0_PUSH(len); + + } + break; + case 34: { + /* data-get8 */ + + size_t addr = T0_POP(); + T0_PUSH(t0_datablock[addr]); + + } + break; + case 35: { + /* discard-input */ + + ENG->hlen_in = 0; + + } + break; + case 36: { + /* do-ecdh */ + + int prf_id = T0_POPi(); + size_t len = T0_POP(); + do_ecdh(CTX, prf_id, ENG->pad, len); + + } + break; + case 37: { + /* do-ecdhe-part1 */ + + int curve = T0_POPi(); + T0_PUSHi(do_ecdhe_part1(CTX, curve)); + + } + break; + case 38: { + /* do-ecdhe-part2 */ + + int prf_id = T0_POPi(); + size_t len = T0_POP(); + do_ecdhe_part2(CTX, prf_id, ENG->pad, len); + + } + break; + case 39: { + /* do-rsa-decrypt */ + + int prf_id = T0_POPi(); + size_t len = T0_POP(); + do_rsa_decrypt(CTX, prf_id, ENG->pad, len); + + } + break; + case 40: { + /* do-static-ecdh */ + + do_static_ecdh(CTX, T0_POP()); + + } + break; + case 41: { + /* drop */ + (void)T0_POP(); + } + break; + case 42: { + /* dup */ + T0_PUSH(T0_PEEK(0)); + } + break; + case 43: { + /* fail */ + + br_ssl_engine_fail(ENG, (int)T0_POPi()); + T0_CO(); + + } + break; + case 44: { + /* flush-record */ + + br_ssl_engine_flush_record(ENG); + + } + break; + case 45: { + /* get-key-type-usages */ + + const br_x509_class *xc; + const br_x509_pkey *pk; + unsigned usages; + + xc = *(ENG->x509ctx); + pk = xc->get_pkey(ENG->x509ctx, &usages); + if (pk == NULL) { + T0_PUSH(0); + } else { + T0_PUSH(pk->key_type | usages); + } + + } + break; + case 46: { + /* get16 */ + + size_t addr = (size_t)T0_POP(); + T0_PUSH(*(uint16_t *)(void *)((unsigned char *)ENG + addr)); + + } + break; + case 47: { + /* get32 */ + + size_t addr = (size_t)T0_POP(); + T0_PUSH(*(uint32_t *)(void *)((unsigned char *)ENG + addr)); + + } + break; + case 48: { + /* get8 */ + + size_t addr = (size_t)T0_POP(); + T0_PUSH(*((unsigned char *)ENG + addr)); + + } + break; + case 49: { + /* has-input? */ + + T0_PUSHi(-(ENG->hlen_in != 0)); + + } + break; + case 50: { + /* memcmp */ + + size_t len = (size_t)T0_POP(); + void *addr2 = (unsigned char *)ENG + (size_t)T0_POP(); + void *addr1 = (unsigned char *)ENG + (size_t)T0_POP(); + int x = memcmp(addr1, addr2, len); + T0_PUSH((uint32_t)-(x == 0)); + + } + break; + case 51: { + /* memcpy */ + + size_t len = (size_t)T0_POP(); + void *src = (unsigned char *)ENG + (size_t)T0_POP(); + void *dst = (unsigned char *)ENG + (size_t)T0_POP(); + memcpy(dst, src, len); + + } + break; + case 52: { + /* mkrand */ + + size_t len = (size_t)T0_POP(); + void *addr = (unsigned char *)ENG + (size_t)T0_POP(); + br_hmac_drbg_generate(&ENG->rng, addr, len); + + } + break; + case 53: { + /* more-incoming-bytes? */ + + T0_PUSHi(ENG->hlen_in != 0 || !br_ssl_engine_recvrec_finished(ENG)); + + } + break; + case 54: { + /* multihash-init */ + + br_multihash_init(&ENG->mhash); + + } + break; + case 55: { + /* neg */ + + uint32_t a = T0_POP(); + T0_PUSH(-a); + + } + break; + case 56: { + /* not */ + + uint32_t a = T0_POP(); + T0_PUSH(~a); + + } + break; + case 57: { + /* or */ + + uint32_t b = T0_POP(); + uint32_t a = T0_POP(); + T0_PUSH(a | b); + + } + break; + case 58: { + /* over */ + T0_PUSH(T0_PEEK(1)); + } + break; + case 59: { + /* pick */ + T0_PICK(T0_POP()); + } + break; + case 60: { + /* read-chunk-native */ + + size_t clen = ENG->hlen_in; + if (clen > 0) { + uint32_t addr, len; + + len = T0_POP(); + addr = T0_POP(); + if ((size_t)len < clen) { + clen = (size_t)len; + } + memcpy((unsigned char *)ENG + addr, ENG->hbuf_in, clen); + if (ENG->record_type_in == BR_SSL_HANDSHAKE) { + br_multihash_update(&ENG->mhash, ENG->hbuf_in, clen); + } + T0_PUSH(addr + (uint32_t)clen); + T0_PUSH(len - (uint32_t)clen); + ENG->hbuf_in += clen; + ENG->hlen_in -= clen; + } + + } + break; + case 61: { + /* read8-native */ + + if (ENG->hlen_in > 0) { + unsigned char x; + + x = *ENG->hbuf_in ++; + if (ENG->record_type_in == BR_SSL_HANDSHAKE) { + br_multihash_update(&ENG->mhash, &x, 1); + } + T0_PUSH(x); + ENG->hlen_in --; + } else { + T0_PUSHi(-1); + } + + } + break; + case 62: { + /* save-session */ + + if (CTX->cache_vtable != NULL) { + (*CTX->cache_vtable)->save( + CTX->cache_vtable, CTX, &ENG->session); + } + + } + break; + case 63: { + /* set-max-frag-len */ + + size_t max_frag_len = T0_POP(); + + br_ssl_engine_new_max_frag_len(ENG, max_frag_len); + + /* + * We must adjust our own output limit. Since we call this only + * after receiving a ClientHello and before beginning to send + * the ServerHello, the next output record should be empty at + * that point, so we can use max_frag_len as a limit. + */ + if (ENG->hlen_out > max_frag_len) { + ENG->hlen_out = max_frag_len; + } + + } + break; + case 64: { + /* set16 */ + + size_t addr = (size_t)T0_POP(); + *(uint16_t *)(void *)((unsigned char *)ENG + addr) = (uint16_t)T0_POP(); + + } + break; + case 65: { + /* set32 */ + + size_t addr = (size_t)T0_POP(); + *(uint32_t *)(void *)((unsigned char *)ENG + addr) = (uint32_t)T0_POP(); + + } + break; + case 66: { + /* set8 */ + + size_t addr = (size_t)T0_POP(); + *((unsigned char *)ENG + addr) = (unsigned char)T0_POP(); + + } + break; + case 67: { + /* supported-curves */ + + uint32_t x = ENG->iec == NULL ? 0 : ENG->iec->supported_curves; + T0_PUSH(x); + + } + break; + case 68: { + /* supported-hash-functions */ + + int i; + unsigned x, num; + + x = 0; + num = 0; + for (i = br_sha1_ID; i <= br_sha512_ID; i ++) { + if (br_multihash_getimpl(&ENG->mhash, i)) { + x |= 1U << i; + num ++; + } + } + T0_PUSH(x); + T0_PUSH(num); + + } + break; + case 69: { + /* supports-ecdsa? */ + + T0_PUSHi(-(ENG->iecdsa != 0)); + + } + break; + case 70: { + /* supports-rsa-sign? */ + + T0_PUSHi(-(ENG->irsavrfy != 0)); + + } + break; + case 71: { + /* swap */ + T0_SWAP(); + } + break; + case 72: { + /* switch-aesccm-in */ + + int is_client, prf_id; + unsigned cipher_key_len, tag_len; + + tag_len = T0_POP(); + cipher_key_len = T0_POP(); + prf_id = T0_POP(); + is_client = T0_POP(); + br_ssl_engine_switch_ccm_in(ENG, is_client, prf_id, + ENG->iaes_ctrcbc, cipher_key_len, tag_len); + + } + break; + case 73: { + /* switch-aesccm-out */ + + int is_client, prf_id; + unsigned cipher_key_len, tag_len; + + tag_len = T0_POP(); + cipher_key_len = T0_POP(); + prf_id = T0_POP(); + is_client = T0_POP(); + br_ssl_engine_switch_ccm_out(ENG, is_client, prf_id, + ENG->iaes_ctrcbc, cipher_key_len, tag_len); + + } + break; + case 74: { + /* switch-aesgcm-in */ + + int is_client, prf_id; + unsigned cipher_key_len; + + cipher_key_len = T0_POP(); + prf_id = T0_POP(); + is_client = T0_POP(); + br_ssl_engine_switch_gcm_in(ENG, is_client, prf_id, + ENG->iaes_ctr, cipher_key_len); + + } + break; + case 75: { + /* switch-aesgcm-out */ + + int is_client, prf_id; + unsigned cipher_key_len; + + cipher_key_len = T0_POP(); + prf_id = T0_POP(); + is_client = T0_POP(); + br_ssl_engine_switch_gcm_out(ENG, is_client, prf_id, + ENG->iaes_ctr, cipher_key_len); + + } + break; + case 76: { + /* switch-cbc-in */ + + int is_client, prf_id, mac_id, aes; + unsigned cipher_key_len; + + cipher_key_len = T0_POP(); + aes = T0_POP(); + mac_id = T0_POP(); + prf_id = T0_POP(); + is_client = T0_POP(); + br_ssl_engine_switch_cbc_in(ENG, is_client, prf_id, mac_id, + aes ? ENG->iaes_cbcdec : ENG->ides_cbcdec, cipher_key_len); + + } + break; + case 77: { + /* switch-cbc-out */ + + int is_client, prf_id, mac_id, aes; + unsigned cipher_key_len; + + cipher_key_len = T0_POP(); + aes = T0_POP(); + mac_id = T0_POP(); + prf_id = T0_POP(); + is_client = T0_POP(); + br_ssl_engine_switch_cbc_out(ENG, is_client, prf_id, mac_id, + aes ? ENG->iaes_cbcenc : ENG->ides_cbcenc, cipher_key_len); + + } + break; + case 78: { + /* switch-chapol-in */ + + int is_client, prf_id; + + prf_id = T0_POP(); + is_client = T0_POP(); + br_ssl_engine_switch_chapol_in(ENG, is_client, prf_id); + + } + break; + case 79: { + /* switch-chapol-out */ + + int is_client, prf_id; + + prf_id = T0_POP(); + is_client = T0_POP(); + br_ssl_engine_switch_chapol_out(ENG, is_client, prf_id); + + } + break; + case 80: { + /* ta-names-total-length */ + + size_t u, len; + + len = 0; + if (CTX->ta_names != NULL) { + for (u = 0; u < CTX->num_tas; u ++) { + len += CTX->ta_names[u].len + 2; + } + } else if (CTX->tas != NULL) { + for (u = 0; u < CTX->num_tas; u ++) { + len += CTX->tas[u].dn.len + 2; + } + } + T0_PUSH(len); + + } + break; + case 81: { + /* test-protocol-name */ + + size_t len = T0_POP(); + size_t u; + + for (u = 0; u < ENG->protocol_names_num; u ++) { + const char *name; + + name = ENG->protocol_names[u]; + if (len == strlen(name) && memcmp(ENG->pad, name, len) == 0) { + T0_PUSH(u); + T0_RET(); + } + } + T0_PUSHi(-1); + + } + break; + case 82: { + /* total-chain-length */ + + size_t u; + uint32_t total; + + total = 0; + for (u = 0; u < ENG->chain_len; u ++) { + total += 3 + (uint32_t)ENG->chain[u].data_len; + } + T0_PUSH(total); + + } + break; + case 83: { + /* u< */ + + uint32_t b = T0_POP(); + uint32_t a = T0_POP(); + T0_PUSH(-(uint32_t)(a < b)); + + } + break; + case 84: { + /* u>> */ + + int c = (int)T0_POPi(); + uint32_t x = T0_POP(); + T0_PUSH(x >> c); + + } + break; + case 85: { + /* verify-CV-sig */ + + int err; + + err = verify_CV_sig(CTX, T0_POP()); + T0_PUSHi(err); + + } + break; + case 86: { + /* write-blob-chunk */ + + size_t clen = ENG->hlen_out; + if (clen > 0) { + uint32_t addr, len; + + len = T0_POP(); + addr = T0_POP(); + if ((size_t)len < clen) { + clen = (size_t)len; + } + memcpy(ENG->hbuf_out, (unsigned char *)ENG + addr, clen); + if (ENG->record_type_out == BR_SSL_HANDSHAKE) { + br_multihash_update(&ENG->mhash, ENG->hbuf_out, clen); + } + T0_PUSH(addr + (uint32_t)clen); + T0_PUSH(len - (uint32_t)clen); + ENG->hbuf_out += clen; + ENG->hlen_out -= clen; + } + + } + break; + case 87: { + /* write8-native */ + + unsigned char x; + + x = (unsigned char)T0_POP(); + if (ENG->hlen_out > 0) { + if (ENG->record_type_out == BR_SSL_HANDSHAKE) { + br_multihash_update(&ENG->mhash, &x, 1); + } + *ENG->hbuf_out ++ = x; + ENG->hlen_out --; + T0_PUSHi(-1); + } else { + T0_PUSHi(0); + } + + } + break; + case 88: { + /* x509-append */ + + const br_x509_class *xc; + size_t len; + + xc = *(ENG->x509ctx); + len = T0_POP(); + xc->append(ENG->x509ctx, ENG->pad, len); + + } + break; + case 89: { + /* x509-end-cert */ + + const br_x509_class *xc; + + xc = *(ENG->x509ctx); + xc->end_cert(ENG->x509ctx); + + } + break; + case 90: { + /* x509-end-chain */ + + const br_x509_class *xc; + + xc = *(ENG->x509ctx); + T0_PUSH(xc->end_chain(ENG->x509ctx)); + + } + break; + case 91: { + /* x509-start-cert */ + + const br_x509_class *xc; + + xc = *(ENG->x509ctx); + xc->start_cert(ENG->x509ctx, T0_POP()); + + } + break; + case 92: { + /* x509-start-chain */ + + const br_x509_class *xc; + uint32_t bc; + + bc = T0_POP(); + xc = *(ENG->x509ctx); + xc->start_chain(ENG->x509ctx, bc ? ENG->server_name : NULL); + + } + break; + } + + } else { + T0_ENTER(ip, rp, t0x); + } + } +t0_exit: + ((t0_context *)t0ctx)->dp = dp; + ((t0_context *)t0ctx)->rp = rp; + ((t0_context *)t0ctx)->ip = ip; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_hs_server.t0 b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_hs_server.t0 new file mode 100644 index 000000000..9f6e934e1 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_hs_server.t0 @@ -0,0 +1,1510 @@ +\ Copyright (c) 2016 Thomas Pornin +\ +\ Permission is hereby granted, free of charge, to any person obtaining +\ a copy of this software and associated documentation files (the +\ "Software"), to deal in the Software without restriction, including +\ without limitation the rights to use, copy, modify, merge, publish, +\ distribute, sublicense, and/or sell copies of the Software, and to +\ permit persons to whom the Software is furnished to do so, subject to +\ the following conditions: +\ +\ The above copyright notice and this permission notice shall be +\ included in all copies or substantial portions of the Software. +\ +\ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +\ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +\ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +\ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +\ BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +\ ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +\ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +\ SOFTWARE. + +\ ---------------------------------------------------------------------- +\ Handshake processing code, for the server. +\ The common T0 code (ssl_hs_common.t0) shall be read first. + +preamble { + +/* + * This macro evaluates to a pointer to the server context, under that + * specific name. It must be noted that since the engine context is the + * first field of the br_ssl_server_context structure ('eng'), then + * pointers values of both types are interchangeable, modulo an + * appropriate cast. This also means that "addresses" computed as offsets + * within the structure work for both kinds of context. + */ +#define CTX ((br_ssl_server_context *)ENG) + +/* + * Decrypt the pre-master secret (RSA key exchange). + */ +static void +do_rsa_decrypt(br_ssl_server_context *ctx, int prf_id, + unsigned char *epms, size_t len) +{ + uint32_t x; + unsigned char rpms[48]; + + /* + * Decrypt the PMS. + */ + x = (*ctx->policy_vtable)->do_keyx(ctx->policy_vtable, epms, &len); + + /* + * Set the first two bytes to the maximum supported client + * protocol version. These bytes are used for version rollback + * detection; forceing the two bytes will make the master secret + * wrong if the bytes are not correct. This process is + * recommended by RFC 5246 (section 7.4.7.1). + */ + br_enc16be(epms, ctx->client_max_version); + + /* + * Make a random PMS and copy it above the decrypted value if the + * decryption failed. Note that we use a constant-time conditional + * copy. + */ + br_hmac_drbg_generate(&ctx->eng.rng, rpms, sizeof rpms); + br_ccopy(x ^ 1, epms, rpms, sizeof rpms); + + /* + * Compute master secret. + */ + br_ssl_engine_compute_master(&ctx->eng, prf_id, epms, 48); + + /* + * Clear the pre-master secret from RAM: it is normally a buffer + * in the context, hence potentially long-lived. + */ + memset(epms, 0, len); +} + +/* + * Common part for ECDH and ECDHE. + */ +static void +ecdh_common(br_ssl_server_context *ctx, int prf_id, + unsigned char *xcoor, size_t xcoor_len, uint32_t ctl) +{ + unsigned char rpms[80]; + + if (xcoor_len > sizeof rpms) { + xcoor_len = sizeof rpms; + ctl = 0; + } + + /* + * Make a random PMS and copy it above the decrypted value if the + * decryption failed. Note that we use a constant-time conditional + * copy. + */ + br_hmac_drbg_generate(&ctx->eng.rng, rpms, xcoor_len); + br_ccopy(ctl ^ 1, xcoor, rpms, xcoor_len); + + /* + * Compute master secret. + */ + br_ssl_engine_compute_master(&ctx->eng, prf_id, xcoor, xcoor_len); + + /* + * Clear the pre-master secret from RAM: it is normally a buffer + * in the context, hence potentially long-lived. + */ + memset(xcoor, 0, xcoor_len); +} + +/* + * Do the ECDH key exchange (not ECDHE). + */ +static void +do_ecdh(br_ssl_server_context *ctx, int prf_id, + unsigned char *cpoint, size_t cpoint_len) +{ + uint32_t x; + + /* + * Finalise the key exchange. + */ + x = (*ctx->policy_vtable)->do_keyx(ctx->policy_vtable, + cpoint, &cpoint_len); + ecdh_common(ctx, prf_id, cpoint, cpoint_len, x); +} + +/* + * Do the full static ECDH key exchange. When this function is called, + * it has already been verified that the cipher suite uses ECDH (not ECDHE), + * and the client's public key (from its certificate) has type EC and is + * apt for key exchange. + */ +static void +do_static_ecdh(br_ssl_server_context *ctx, int prf_id) +{ + unsigned char cpoint[133]; + size_t cpoint_len; + const br_x509_class **xc; + const br_x509_pkey *pk; + + xc = ctx->eng.x509ctx; + pk = (*xc)->get_pkey(xc, NULL); + cpoint_len = pk->key.ec.qlen; + if (cpoint_len > sizeof cpoint) { + /* + * If the point is larger than our buffer then we need to + * restrict it. Length 2 is not a valid point length, so + * the ECDH will fail. + */ + cpoint_len = 2; + } + memcpy(cpoint, pk->key.ec.q, cpoint_len); + do_ecdh(ctx, prf_id, cpoint, cpoint_len); +} + +static size_t +hash_data(br_ssl_server_context *ctx, + void *dst, int hash_id, const void *src, size_t len) +{ + const br_hash_class *hf; + br_hash_compat_context hc; + + if (hash_id == 0) { + unsigned char tmp[36]; + + hf = br_multihash_getimpl(&ctx->eng.mhash, br_md5_ID); + if (hf == NULL) { + return 0; + } + hf->init(&hc.vtable); + hf->update(&hc.vtable, src, len); + hf->out(&hc.vtable, tmp); + hf = br_multihash_getimpl(&ctx->eng.mhash, br_sha1_ID); + if (hf == NULL) { + return 0; + } + hf->init(&hc.vtable); + hf->update(&hc.vtable, src, len); + hf->out(&hc.vtable, tmp + 16); + memcpy(dst, tmp, 36); + return 36; + } else { + hf = br_multihash_getimpl(&ctx->eng.mhash, hash_id); + if (hf == NULL) { + return 0; + } + hf->init(&hc.vtable); + hf->update(&hc.vtable, src, len); + hf->out(&hc.vtable, dst); + return (hf->desc >> BR_HASHDESC_OUT_OFF) & BR_HASHDESC_OUT_MASK; + } +} + +/* + * Do the ECDHE key exchange (part 1: generation of transient key, and + * computing of the point to send to the client). Returned value is the + * signature length (in bytes), or -x on error (with x being an error + * code). The encoded point is written in the ecdhe_point[] context buffer + * (length in ecdhe_point_len). + */ +static int +do_ecdhe_part1(br_ssl_server_context *ctx, int curve) +{ + unsigned algo_id; + unsigned mask; + const unsigned char *order; + size_t olen, glen; + size_t hv_len, sig_len; + + if (!((ctx->eng.iec->supported_curves >> curve) & 1)) { + return -BR_ERR_INVALID_ALGORITHM; + } + ctx->eng.ecdhe_curve = curve; + + /* + * Generate our private key. We need a non-zero random value + * which is lower than the curve order, in a "large enough" + * range. We force the top bit to 0 and bottom bit to 1, which + * does the trick. Note that contrary to what happens in ECDSA, + * this is not a problem if we do not cover the full range of + * possible values. + */ + order = ctx->eng.iec->order(curve, &olen); + mask = 0xFF; + while (mask >= order[0]) { + mask >>= 1; + } + br_hmac_drbg_generate(&ctx->eng.rng, ctx->ecdhe_key, olen); + ctx->ecdhe_key[0] &= mask; + ctx->ecdhe_key[olen - 1] |= 0x01; + ctx->ecdhe_key_len = olen; + + /* + * Compute our ECDH point. + */ + glen = ctx->eng.iec->mulgen(ctx->eng.ecdhe_point, + ctx->ecdhe_key, olen, curve); + ctx->eng.ecdhe_point_len = glen; + + /* + * Assemble the message to be signed, and possibly hash it. + */ + memcpy(ctx->eng.pad, ctx->eng.client_random, 32); + memcpy(ctx->eng.pad + 32, ctx->eng.server_random, 32); + ctx->eng.pad[64 + 0] = 0x03; + ctx->eng.pad[64 + 1] = 0x00; + ctx->eng.pad[64 + 2] = curve; + ctx->eng.pad[64 + 3] = ctx->eng.ecdhe_point_len; + memcpy(ctx->eng.pad + 64 + 4, + ctx->eng.ecdhe_point, ctx->eng.ecdhe_point_len); + hv_len = 64 + 4 + ctx->eng.ecdhe_point_len; + algo_id = ctx->sign_hash_id; + if (algo_id >= (unsigned)0xFF00) { + hv_len = hash_data(ctx, ctx->eng.pad, algo_id & 0xFF, + ctx->eng.pad, hv_len); + if (hv_len == 0) { + return -BR_ERR_INVALID_ALGORITHM; + } + } + + sig_len = (*ctx->policy_vtable)->do_sign(ctx->policy_vtable, + algo_id, ctx->eng.pad, hv_len, sizeof ctx->eng.pad); + return sig_len ? (int)sig_len : -BR_ERR_INVALID_ALGORITHM; +} + +/* + * Do the ECDHE key exchange (part 2: computation of the shared secret + * from the point sent by the client). + */ +static void +do_ecdhe_part2(br_ssl_server_context *ctx, int prf_id, + unsigned char *cpoint, size_t cpoint_len) +{ + int curve; + uint32_t ctl; + size_t xoff, xlen; + + curve = ctx->eng.ecdhe_curve; + + /* + * Finalise the key exchange. + */ + ctl = ctx->eng.iec->mul(cpoint, cpoint_len, + ctx->ecdhe_key, ctx->ecdhe_key_len, curve); + xoff = ctx->eng.iec->xoff(curve, &xlen); + ecdh_common(ctx, prf_id, cpoint + xoff, xlen, ctl); + + /* + * Clear the ECDHE private key. Forward Secrecy is achieved insofar + * as that key does not get stolen, so we'd better destroy it + * as soon as it ceases to be useful. + */ + memset(ctx->ecdhe_key, 0, ctx->ecdhe_key_len); +} + +/* + * Offset for hash value within the pad (when obtaining all hash values, + * in preparation for verification of the CertificateVerify message). + * Order is MD5, SHA-1, SHA-224, SHA-256, SHA-384, SHA-512; last value + * is used to get the total length. + */ +static const unsigned char HASH_PAD_OFF[] = { 0, 16, 36, 64, 96, 144, 208 }; + +/* + * OID for hash functions in RSA signatures. + */ +static const unsigned char HASH_OID_SHA1[] = { + 0x05, 0x2B, 0x0E, 0x03, 0x02, 0x1A +}; + +static const unsigned char HASH_OID_SHA224[] = { + 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x04 +}; + +static const unsigned char HASH_OID_SHA256[] = { + 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01 +}; + +static const unsigned char HASH_OID_SHA384[] = { + 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02 +}; + +static const unsigned char HASH_OID_SHA512[] = { + 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03 +}; + +static const unsigned char *HASH_OID[] = { + HASH_OID_SHA1, + HASH_OID_SHA224, + HASH_OID_SHA256, + HASH_OID_SHA384, + HASH_OID_SHA512 +}; + +/* + * Verify the signature in CertificateVerify. Returned value is 0 on + * success, or a non-zero error code. Lack of implementation of the + * designated signature algorithm is reported as a "bad signature" + * error (because it means that the peer did not honour our advertised + * set of supported signature algorithms). + */ +static int +verify_CV_sig(br_ssl_server_context *ctx, size_t sig_len) +{ + const br_x509_class **xc; + const br_x509_pkey *pk; + int id; + + id = ctx->hash_CV_id; + xc = ctx->eng.x509ctx; + pk = (*xc)->get_pkey(xc, NULL); + if (pk->key_type == BR_KEYTYPE_RSA) { + unsigned char tmp[64]; + const unsigned char *hash_oid; + + if (id == 0) { + hash_oid = NULL; + } else { + hash_oid = HASH_OID[id - 2]; + } + if (ctx->eng.irsavrfy == 0) { + return BR_ERR_BAD_SIGNATURE; + } + if (!ctx->eng.irsavrfy(ctx->eng.pad, sig_len, + hash_oid, ctx->hash_CV_len, &pk->key.rsa, tmp) + || memcmp(tmp, ctx->hash_CV, ctx->hash_CV_len) != 0) + { + return BR_ERR_BAD_SIGNATURE; + } + } else { + if (ctx->eng.iecdsa == 0) { + return BR_ERR_BAD_SIGNATURE; + } + if (!ctx->eng.iecdsa(ctx->eng.iec, + ctx->hash_CV, ctx->hash_CV_len, + &pk->key.ec, ctx->eng.pad, sig_len)) + { + return BR_ERR_BAD_SIGNATURE; + } + } + return 0; +} + +} + +\ ======================================================================= + +: addr-ctx: + next-word { field } + "addr-" field + 0 1 define-word + 0 8191 "offsetof(br_ssl_server_context, " field + ")" + make-CX + postpone literal postpone ; ; + +addr-ctx: client_max_version +addr-ctx: client_suites +addr-ctx: client_suites_num +addr-ctx: hashes +addr-ctx: curves +addr-ctx: sign_hash_id + +\ Get address and length of the client_suites[] buffer. Length is expressed +\ in bytes. +: addr-len-client_suites ( -- addr len ) + addr-client_suites + CX 0 1023 { BR_MAX_CIPHER_SUITES * sizeof(br_suite_translated) } ; + +\ Read the client SNI extension. +: read-client-sni ( lim -- lim ) + \ Open extension value. + read16 open-elt + + \ Open ServerNameList. + read16 open-elt + + \ Find if there is a name of type 0 (host_name) with a length + \ that fits in our dedicated buffer. + begin dup while + read8 if + read-ignore-16 + else + read16 + dup 255 <= if + dup addr-server_name + 0 swap set8 + addr-server_name swap read-blob + else + skip-blob + then + then + repeat + + \ Close ServerNameList. + close-elt + + \ Close extension value. + close-elt ; + +\ Set the new maximum fragment length. BEWARE: this shall be called only +\ after reading the ClientHello and before writing the ServerHello. +cc: set-max-frag-len ( len -- ) { + size_t max_frag_len = T0_POP(); + + br_ssl_engine_new_max_frag_len(ENG, max_frag_len); + + /* + * We must adjust our own output limit. Since we call this only + * after receiving a ClientHello and before beginning to send + * the ServerHello, the next output record should be empty at + * that point, so we can use max_frag_len as a limit. + */ + if (ENG->hlen_out > max_frag_len) { + ENG->hlen_out = max_frag_len; + } +} + +\ Read the client Max Frag Length extension. +: read-client-frag ( lim -- lim ) + \ Extension value must have length exactly 1 byte. + read16 1 <> if ERR_BAD_FRAGLEN fail then + read8 + + \ The byte value must be 1, 2, 3 or 4. + dup dup 0= swap 5 >= or if ERR_BAD_FRAGLEN fail then + + \ If our own maximum fragment length is greater, then we reduce + \ our length. + 8 + dup addr-log_max_frag_len get8 < if + dup 1 swap << set-max-frag-len + dup addr-log_max_frag_len set8 + addr-peer_log_max_frag_len set8 + else + drop + then ; + +\ Read the Secure Renegotiation extension from the client. +: read-client-reneg ( lim -- lim ) + \ Get value length. + read16 + + \ The "reneg" value is one of: + \ 0 on first handshake, client support is unknown + \ 1 client does not support secure renegotiation + \ 2 client supports secure renegotiation + addr-reneg get8 case + 0 of + \ First handshake, value length shall be 1. + 1 = ifnot ERR_BAD_SECRENEG fail then + read8 if ERR_BAD_SECRENEG fail then + 2 addr-reneg set8 + endof + 2 of + \ Renegotiation, value shall consist of 13 bytes + \ (header + copy of the saved client "Finished"). + 13 = ifnot ERR_BAD_SECRENEG fail then + read8 12 = ifnot ERR_BAD_SECRENEG fail then + addr-pad 12 read-blob + addr-saved_finished addr-pad 12 memcmp ifnot + ERR_BAD_SECRENEG fail + then + endof + + \ If "reneg" is 1 then the client is not supposed to support + \ the extension, and it sends it nonetheless, which means + \ foul play. + ERR_BAD_SECRENEG fail + endcase ; + +\ Read the Signature Algorithms extension. +: read-signatures ( lim -- lim ) + \ Open extension value. + read16 open-elt + + read-list-sign-algos addr-hashes set32 + + \ Close extension value. + close-elt ; + +\ Read the Supported Curves extension. +: read-supported-curves ( lim -- lim ) + \ Open extension value. + read16 open-elt + + \ Open list of curve identifiers. + read16 open-elt + + \ Get all supported curves. + 0 addr-curves set32 + begin dup while + read16 dup 32 < if + 1 swap << addr-curves get32 or addr-curves set32 + else + drop + then + repeat + close-elt + close-elt ; + +\ Read the ALPN extension from client. +: read-ALPN-from-client ( lim -- lim ) + \ If we do not have configured names, then we just ignore the + \ extension. + addr-protocol_names_num get16 ifnot read-ignore-16 ret then + + \ Open extension value. + read16 open-elt + + \ Open list of protocol names. + read16 open-elt + + \ Get all names and test for their support. We keep the one with + \ the lowest index (because we apply server's preferences, as + \ recommended by RFC 7301, section 3.2. We set the 'found' variable + \ to -2 and use an unsigned comparison, making -2 a huge value. + -2 { found } + begin dup while + read8 dup { len } addr-pad swap read-blob + len test-protocol-name dup found u< if + >found + else + drop + then + repeat + + \ End of extension. + close-elt + close-elt + + \ Write back found name index (or not). If no match was found, + \ then we write -1 (0xFFFF) in the index value, not 0, so that + \ the caller knows that we tried to match, and failed. + found 1+ addr-selected_protocol set16 ; + +\ Call policy handler to get cipher suite, hash function identifier and +\ certificate chain. Returned value is 0 (false) on failure. +cc: call-policy-handler ( -- bool ) { + int x; + br_ssl_server_choices choices; + + x = (*CTX->policy_vtable)->choose( + CTX->policy_vtable, CTX, &choices); + ENG->session.cipher_suite = choices.cipher_suite; + CTX->sign_hash_id = choices.algo_id; + ENG->chain = choices.chain; + ENG->chain_len = choices.chain_len; + T0_PUSHi(-(x != 0)); +} + +\ Check for a remembered session. +cc: check-resume ( -- bool ) { + if (ENG->session.session_id_len == 32 + && CTX->cache_vtable != NULL && (*CTX->cache_vtable)->load( + CTX->cache_vtable, CTX, &ENG->session)) + { + T0_PUSHi(-1); + } else { + T0_PUSH(0); + } +} + +\ Save the current session. +cc: save-session ( -- ) { + if (CTX->cache_vtable != NULL) { + (*CTX->cache_vtable)->save( + CTX->cache_vtable, CTX, &ENG->session); + } +} + +\ Read and drop ClientHello. This is used when a client-triggered +\ renegotiation attempt is rejected. +: skip-ClientHello ( -- ) + read-handshake-header-core + 1 = ifnot ERR_UNEXPECTED fail then + dup skip-blob drop ; + +\ Read ClientHello. If the session is resumed, then -1 is returned. +: read-ClientHello ( -- resume ) + \ Get header, and check message type. + read-handshake-header 1 = ifnot ERR_UNEXPECTED fail then + + \ Get maximum protocol version from client. + read16 dup { client-version-max } addr-client_max_version set16 + + \ Client random. + addr-client_random 32 read-blob + + \ Client session ID. + read8 dup 32 > if ERR_OVERSIZED_ID fail then + dup addr-session_id_len set8 + addr-session_id swap read-blob + + \ Lookup session for resumption. We should do that here because + \ we need to verify that the remembered cipher suite is still + \ matched by this ClientHello. + check-resume { resume } + + \ Cipher suites. We read all cipher suites from client, each time + \ matching against our own list. We accumulate suites in the + \ client_suites[] context buffer: we keep suites that are + \ supported by both the client and the server (so the list size + \ cannot exceed that of the server list), and we keep them in + \ either client or server preference order (depending on the + \ relevant flag). + \ + \ We also need to identify the pseudo cipher suite for secure + \ renegotiation here. + read16 open-elt + 0 { reneg-scsv } + 0 { resume-suite } + addr-len-client_suites dup2 bzero + over + { css-off css-max } + begin + dup while + read16 dup { suite } + + \ Check that when resuming a session, the requested + \ suite is still valid. + resume if + dup addr-cipher_suite get16 = if + -1 >resume-suite + then + then + + \ Special handling for TLS_EMPTY_RENEGOTIATION_INFO_SCSV. + \ This fake cipher suite may occur only in the first + \ handshake. + dup 0x00FF = if + addr-reneg get8 if ERR_BAD_SECRENEG fail then + -1 >reneg-scsv + then + + \ Special handling for TLS_FALLBACK_SCSV. If the client + \ maximum version is less than our own maximum version, + \ then this is an undue downgrade. We mark it by setting + \ the client max version to 0x10000. + dup 0x5600 = if + client-version-max addr-version_min get16 >= + client-version-max addr-version_max get16 < and if + -1 >client-version-max + then + then + + \ Test whether the suite is supported by the server. + scan-suite dup 0< if + \ We do not support this cipher suite. Note + \ that this also covers the case of pseudo + \ cipher suites. + drop + else + \ If we use server order, then we place the + \ suite at the computed offset; otherwise, we + \ append it to the list at the current place. + 0 flag? if + 2 << addr-client_suites + suite swap set16 + else + drop + \ We need to test for list length because + \ the client list may have duplicates, + \ that we do not filter. Duplicates are + \ invalid so this is not a problem if we + \ reject such clients. + css-off css-max >= if + ERR_BAD_HANDSHAKE fail + then + suite css-off set16 + css-off 4 + >css-off + then + then + repeat + drop + + \ Compression methods. We need method 0 (no compression). + 0 { ok-compression } + read8 open-elt + begin dup while + read8 ifnot -1 >ok-compression then + repeat + close-elt + + \ Set default values for parameters that may be affected by + \ extensions: + \ -- server name is empty + \ -- client is reputed to know RSA and ECDSA, both with SHA-1 + \ -- the default elliptic curve is P-256 (secp256r1, id = 23) + 0 addr-server_name set8 + 0x0404 addr-hashes set32 + 0x800000 addr-curves set32 + + \ Process extensions, if any. + dup if + read16 open-elt + begin dup while + read16 case + \ Server Name Indication. + 0x0000 of + read-client-sni + endof + \ Max Frag Length. + 0x0001 of + read-client-frag + endof + \ Secure Renegotiation. + 0xFF01 of + read-client-reneg + endof + \ Signature Algorithms. + 0x000D of + read-signatures + endof + \ Supported Curves. + 0x000A of + read-supported-curves + endof + \ Supported Point Formats. + \ We only support "uncompressed", that all + \ implementations are supposed to support, + \ so we can simply ignore that extension. + \ 0x000B of + \ read-ignore-16 + \ endof + + \ ALPN + 0x0010 of + read-ALPN-from-client + endof + + \ Other extensions are ignored. + drop read-ignore-16 0 + endcase + repeat + close-elt + then + + \ Close message. + close-elt + + \ Cancel session resumption if the cipher suite was not found. + resume resume-suite and >resume + + \ Now check the received data. Since the client is expecting an + \ answer, we can send an appropriate fatal alert on any error. + + \ Compute protocol version as the minimum of our maximum version, + \ and the maximum version sent by the client. If that is less than + \ 0x0300 (SSL-3.0), then fail. Otherwise, we may at least send an + \ alert with that version. We still reject versions lower than our + \ configured minimum. + \ As a special case, in case of undue downgrade, we send a specific + \ alert (see RFC 7507). Note that this case may happen only if + \ we would otherwise accept the client's version. + client-version-max 0< if + addr-client_max_version get16 addr-version_out set16 + 86 fail-alert + then + addr-version_max get16 + dup client-version-max > if drop client-version-max then + dup 0x0300 < if ERR_BAD_VERSION fail then + client-version-max addr-version_min get16 < if + 70 fail-alert + then + \ If resuming the session, then enforce the previously negotiated + \ version (if still possible). + resume if + addr-version get16 client-version-max <= if + drop addr-version get16 + else + 0 >resume + then + then + dup addr-version set16 + dup addr-version_in set16 + dup addr-version_out set16 + 0x0303 >= { can-tls12 } + + \ If the client sent TLS_EMPTY_RENEGOTIATION_INFO_SCSV, then + \ we should mark the client as "supporting secure renegotiation". + reneg-scsv if 2 addr-reneg set8 then + + \ If, at that point, the 'reneg' value is still 0, then the client + \ did not send the extension or the SCSV, so we have to assume + \ that secure renegotiation is not supported by that client. + addr-reneg get8 ifnot 1 addr-reneg set8 then + + \ Check compression. + ok-compression ifnot 40 fail-alert then + + \ Filter hash function support by what the server also supports. + \ If no common hash function remains with RSA and/or ECDSA, then + \ the corresponding ECDHE suites are not possible. + supported-hash-functions drop 257 * 0xFFFF0000 or + addr-hashes get32 and dup addr-hashes set32 + \ In 'can-ecdhe', bit 12 is set if ECDHE_RSA is possible, bit 13 is + \ set if ECDHE_ECDSA is possible. + dup 0xFF and 0<> neg + swap 8 >> 0<> 2 and or 12 << { can-ecdhe } + + \ Filter supported curves. If there is no common curve between + \ client and us, then ECDHE suites cannot be used. Note that we + \ may still allow ECDH, depending on the EC key handler. + addr-curves get32 supported-curves and dup addr-curves set32 + ifnot 0 >can-ecdhe then + + \ If resuming a session, then the next steps are not necessary; + \ we won't invoke the policy handler. + resume if -1 ret then + + \ We are not resuming, so a new session ID should be generated. + \ We don't check that the new ID is distinct from the one sent + \ by the client because probability of such an event is 2^(-256), + \ i.e. much (much) lower than that of an undetected transmission + \ error or hardware miscomputation, and with similar consequences + \ (handshake simply fails). + addr-session_id 32 mkrand + 32 addr-session_id_len set8 + + \ Translate common cipher suites, then squeeze out holes: there + \ may be holes because of the way we fill the list when the + \ server preference order is enforced, and also in case some + \ suites are filtered out. In particular: + \ -- ECDHE suites are removed if there is no common hash function + \ (for the relevant signature algorithm) or no common curve. + \ -- TLS-1.2-only suites are removed if the negotiated version is + \ TLS-1.1 or lower. + addr-client_suites dup >css-off + begin dup css-max < while + dup get16 dup cipher-suite-to-elements + dup 12 >> dup 1 = swap 2 = or if + dup can-ecdhe and ifnot + 2drop 0 dup + then + then + can-tls12 ifnot + \ Suites compatible with TLS-1.0 and TLS-1.1 are + \ exactly the ones that use HMAC/SHA-1. + dup 0xF0 and 0x20 <> if + 2drop 0 dup + then + then + dup if + css-off 2+ set16 css-off set16 + css-off 4 + >css-off + else + 2drop + then + 4 + + repeat + drop + css-off addr-client_suites - 2 >> + dup ifnot + \ No common cipher suite: handshake failure. + 40 fail-alert + then + addr-client_suites_num set8 + + \ Check ALPN. + addr-selected_protocol get16 0xFFFF = if + 3 flag? if 120 fail-alert then + 0 addr-selected_protocol set16 + then + + \ Call policy handler to obtain the cipher suite and other + \ parameters. + call-policy-handler ifnot 40 fail-alert then + + \ We are not resuming a session. + 0 ; + +\ Write ServerHello. +: write-ServerHello ( initial -- ) + { initial } + \ Compute ServerHello length. + 2 write8 70 + + \ Compute length of Secure Renegotiation extension. + addr-reneg get8 2 = if + initial if 5 else 29 then + else + 0 + then + { ext-reneg-len } + + \ Compute length of Max Fragment Length extension. + addr-peer_log_max_frag_len get8 if 5 else 0 then + { ext-max-frag-len } + + \ Compute length of ALPN extension. This also copy the + \ selected protocol name into the pad. + addr-selected_protocol get16 dup if 1- copy-protocol-name 7 + then + { ext-ALPN-len } + + \ Adjust ServerHello length to account for the extensions. + ext-reneg-len ext-max-frag-len + ext-ALPN-len + dup if 2 + then + + write24 + + \ Protocol version + addr-version get16 write16 + + \ Server random + addr-server_random 4 bzero + addr-server_random 4 + 28 mkrand + addr-server_random 32 write-blob + + \ Session ID + \ TODO: if we have no session cache at all, we might send here + \ an empty session ID. This would save a bit of network + \ bandwidth. + 32 write8 + addr-session_id 32 write-blob + + \ Cipher suite + addr-cipher_suite get16 write16 + + \ Compression method + 0 write8 + + \ Extensions + ext-reneg-len ext-max-frag-len + ext-ALPN-len + dup if + write16 + ext-reneg-len dup if + 0xFF01 write16 + 4 - dup write16 + 1- addr-saved_finished swap write-blob-head8 + else + drop + then + ext-max-frag-len if + 0x0001 write16 + 1 write16 addr-peer_log_max_frag_len get8 8 - write8 + then + ext-ALPN-len dup if + \ Note: the selected protocol name was previously + \ copied into the pad. + 0x0010 write16 + 4 - dup write16 + 2- dup write16 + 1- addr-pad swap write-blob-head8 + else + drop + then + else + drop + then ; + +\ Do the first part of ECDHE. Returned value is the computed signature +\ length, or a negative error code on error. +cc: do-ecdhe-part1 ( curve -- len ) { + int curve = T0_POPi(); + T0_PUSHi(do_ecdhe_part1(CTX, curve)); +} + +\ Get index of first bit set to 1 (in low to high order). +: lowest-1 ( bits -- n ) + dup ifnot drop -1 ret then + 0 begin dup2 >> 1 and 0= while 1+ repeat + swap drop ; + +\ Write the Server Key Exchange message (if applicable). +: write-ServerKeyExchange ( -- ) + addr-cipher_suite get16 use-ecdhe? ifnot ret then + + \ We must select an appropriate curve among the curves that + \ are supported both by us and the peer. Right now, we apply + \ a fixed preference order: Curve25519, P-256, P-384, P-521, + \ then the common curve with the lowest ID. + \ (TODO: add some option to make that behaviour configurable.) + \ + \ This loop always terminates because previous processing made + \ sure that ECDHE suites are not selectable if there is no common + \ curve. + addr-curves get32 + dup 0x20000000 and if + drop 29 + else + dup 0x38000000 and dup if swap then + drop lowest-1 + then + { curve-id } + + \ Compute the signed curve point to send. + curve-id do-ecdhe-part1 dup 0< if neg fail then { sig-len } + + \ If using TLS-1.2+, then the hash function and signature + \ algorithm are explicitly encoded in the message. + addr-version get16 0x0303 >= { tls1.2+ } + + 12 write8 + sig-len addr-ecdhe_point_len get8 + tls1.2+ 2 and + 6 + write24 + + \ Curve parameters: named curve with 16-bit ID. + 3 write8 curve-id write16 + + \ Public point. + addr-ecdhe_point addr-ecdhe_point_len get8 write-blob-head8 + + \ If TLS-1.2+, write hash and signature identifiers. + tls1.2+ if + \ sign_hash_id contains either a hash identifier, + \ or the complete 16-bit value to write. + addr-sign_hash_id get16 + dup 0xFF00 < if + write16 + else + 0xFF and write8 + \ 'use-rsa-ecdhe?' returns -1 for RSA, 0 for + \ ECDSA. The byte on the wire shall be 1 for RSA, + \ 3 for ECDSA. + addr-cipher_suite get16 use-rsa-ecdhe? 1 << 3 + write8 + then + then + + \ Signature. + sig-len write16 + addr-pad sig-len write-blob ; + +\ Get length of the list of anchor names to send to the client. The length +\ includes the per-name 2-byte header, but _not_ the 2-byte header for +\ the list itself. If no client certificate is requested, then this +\ returns 0. +cc: ta-names-total-length ( -- len ) { + size_t u, len; + + len = 0; + if (CTX->ta_names != NULL) { + for (u = 0; u < CTX->num_tas; u ++) { + len += CTX->ta_names[u].len + 2; + } + } else if (CTX->tas != NULL) { + for (u = 0; u < CTX->num_tas; u ++) { + len += CTX->tas[u].dn.len + 2; + } + } + T0_PUSH(len); +} + +\ Compute length and optionally write the contents of the list of +\ supported client authentication methods. +: write-list-auth ( do_write -- len ) + 0 + addr-cipher_suite get16 use-ecdh? if + 2+ over if 65 write8 66 write8 then + then + supports-rsa-sign? if 1+ over if 1 write8 then then + supports-ecdsa? if 1+ over if 64 write8 then then + swap drop ; + +: write-signhash-inner2 ( dow algo hashes len id -- dow algo hashes len ) + { id } + over 1 id << and ifnot ret then + 2+ + 3 pick if id write8 2 pick write8 then ; + +: write-signhash-inner1 ( dow algo hashes -- dow len ) + 0 + 4 write-signhash-inner2 + 5 write-signhash-inner2 + 6 write-signhash-inner2 + 3 write-signhash-inner2 + 2 write-signhash-inner2 + -rot 2drop ; + +\ Compute length and optionally write the contents of the list of +\ supported sign+hash algorithms. +: write-list-signhash ( do_write -- len ) + 0 { len } + \ If supporting neither RSA nor ECDSA in the engine, then we + \ will do only static ECDH, and thus we claim support for + \ everything (for the X.509 validator). + supports-rsa-sign? supports-ecdsa? or ifnot + 1 0x7C write-signhash-inner1 >len + 3 0x7C write-signhash-inner1 len + + swap drop ret + then + supports-rsa-sign? if + 1 supported-hash-functions drop + write-signhash-inner1 >len + then + supports-ecdsa? if + 3 supported-hash-functions drop + write-signhash-inner1 len + >len + then + drop len ; + +\ Initialise index for sending the list of anchor DN. +cc: begin-ta-name-list ( -- ) { + CTX->cur_dn_index = 0; +} + +\ Switch to next DN in the list. Returned value is the DN length, or -1 +\ if the end of the list was reached. +cc: begin-ta-name ( -- len ) { + const br_x500_name *dn; + if (CTX->cur_dn_index >= CTX->num_tas) { + T0_PUSHi(-1); + } else { + if (CTX->ta_names == NULL) { + dn = &CTX->tas[CTX->cur_dn_index].dn; + } else { + dn = &CTX->ta_names[CTX->cur_dn_index]; + } + CTX->cur_dn_index ++; + CTX->cur_dn = dn->data; + CTX->cur_dn_len = dn->len; + T0_PUSH(CTX->cur_dn_len); + } +} + +\ Copy a chunk of the current DN into the pad. Returned value is the +\ chunk length; this is 0 when the end of the current DN is reached. +cc: copy-dn-chunk ( -- len ) { + size_t clen; + + clen = CTX->cur_dn_len; + if (clen > sizeof ENG->pad) { + clen = sizeof ENG->pad; + } + memcpy(ENG->pad, CTX->cur_dn, clen); + CTX->cur_dn += clen; + CTX->cur_dn_len -= clen; + T0_PUSH(clen); +} + +\ Write a CertificateRequest message. +: write-CertificateRequest ( -- ) + \ The list of client authentication types includes: + \ rsa_sign (1) + \ ecdsa_sign (64) + \ rsa_fixed_ecdh (65) + \ ecdsa_fixed_ecdh (66) + \ rsa_sign and ecdsa_sign require, respectively, RSA and ECDSA + \ support. Static ECDH requires that the cipher suite is ECDH. + \ When we ask for static ECDH, we always send both rsa_fixed_ecdh + \ and ecdsa_fixed_ecdh because what matters there is what the + \ X.509 engine may support, and we do not control that. + \ + \ With TLS 1.2, we must also send a list of supported signature + \ and hash algorithms. That list is supposed to qualify both + \ the engine itself, and the X.509 validator, which are separate + \ in BearSSL. There again, we use the engine capabilities in that + \ list, and resort to a generic all-support list if only + \ static ECDH is accepted. + \ + \ (In practice, client implementations tend to have at most one + \ or two certificates, and send the chain regardless of what + \ algorithms are used in it.) + + 0 write-list-auth + addr-version get16 0x0303 >= if + 2+ 0 write-list-signhash + + then + ta-names-total-length + 3 + + + \ Message header + 13 write8 write24 + + \ List of authentication methods + 0 write-list-auth write8 1 write-list-auth drop + + \ For TLS 1.2+, list of sign+hash + addr-version get16 0x0303 >= if + 0 write-list-signhash write16 1 write-list-signhash drop + then + + \ Trust anchor names + ta-names-total-length write16 + begin-ta-name-list + begin + begin-ta-name + dup 0< if drop ret then write16 + begin copy-dn-chunk dup while + addr-pad swap write-blob + repeat + drop + again ; + +\ Write the Server Hello Done message. +: write-ServerHelloDone ( -- ) + 14 write8 0 write24 ; + +\ Perform RSA decryption of the client-sent pre-master secret. The value +\ is in the pad, and its length is provided as parameter. +cc: do-rsa-decrypt ( len prf_id -- ) { + int prf_id = T0_POPi(); + size_t len = T0_POP(); + do_rsa_decrypt(CTX, prf_id, ENG->pad, len); +} + +\ Perform ECDH (not ECDHE). The point from the client is in the pad, and +\ its length is provided as parameter. +cc: do-ecdh ( len prf_id -- ) { + int prf_id = T0_POPi(); + size_t len = T0_POP(); + do_ecdh(CTX, prf_id, ENG->pad, len); +} + +\ Do the second part of ECDHE. +cc: do-ecdhe-part2 ( len prf_id -- ) { + int prf_id = T0_POPi(); + size_t len = T0_POP(); + do_ecdhe_part2(CTX, prf_id, ENG->pad, len); +} + +\ Perform static ECDH. The point from the client is the public key +\ extracted from its certificate. +cc: do-static-ecdh ( prf_id -- ) { + do_static_ecdh(CTX, T0_POP()); +} + +\ Read a ClientKeyExchange header. +: read-ClientKeyExchange-header ( -- len ) + read-handshake-header 16 = ifnot ERR_UNEXPECTED fail then ; + +\ Read the Client Key Exchange contents (non-empty case). +: read-ClientKeyExchange-contents ( lim -- ) + \ What we should get depends on the cipher suite. + addr-cipher_suite get16 use-rsa-keyx? if + \ RSA key exchange: we expect a RSA-encrypted value. + read16 + dup 512 > if ERR_LIMIT_EXCEEDED fail then + dup { enc-rsa-len } + addr-pad swap read-blob + enc-rsa-len addr-cipher_suite get16 prf-id do-rsa-decrypt + then + addr-cipher_suite get16 dup use-ecdhe? swap use-ecdh? { ecdhe ecdh } + ecdh ecdhe or if + \ ECDH or ECDHE key exchange: we expect an EC point. + read8 dup { ec-point-len } + addr-pad swap read-blob + ec-point-len addr-cipher_suite get16 prf-id + ecdhe if do-ecdhe-part2 else do-ecdh then + then + close-elt ; + +\ Read the Client Key Exchange (normal case). +: read-ClientKeyExchange ( -- ) + read-ClientKeyExchange-header + read-ClientKeyExchange-contents ; + +\ Obtain all possible hash values for handshake messages so far. This +\ is done because we need the hash value for the CertificateVerify +\ _before_ knowing which hash function will actually be used, as this +\ information is obtained from decoding the message header itself. +\ All hash values are stored in the pad (208 bytes in total). +cc: compute-hash-CV ( -- ) { + int i; + + for (i = 1; i <= 6; i ++) { + br_multihash_out(&ENG->mhash, i, + ENG->pad + HASH_PAD_OFF[i - 1]); + } +} + +\ Copy the proper hash value from the pad into the dedicated buffer. +\ Returned value is true (-1) on success, false (0) on error (error +\ being an unimplemented hash function). The id has already been verified +\ to be either 0 (for MD5+SHA-1) or one of the SHA-* functions. +cc: copy-hash-CV ( hash_id -- bool ) { + int id = T0_POP(); + size_t off, len; + + if (id == 0) { + off = 0; + len = 36; + } else { + if (br_multihash_getimpl(&ENG->mhash, id) == 0) { + T0_PUSH(0); + T0_RET(); + } + off = HASH_PAD_OFF[id - 1]; + len = HASH_PAD_OFF[id] - off; + } + memcpy(CTX->hash_CV, ENG->pad + off, len); + CTX->hash_CV_len = len; + CTX->hash_CV_id = id; + T0_PUSHi(-1); +} + +\ Verify signature in CertificateVerify. Output is 0 on success, or a +\ non-zero error code. +cc: verify-CV-sig ( sig-len -- err ) { + int err; + + err = verify_CV_sig(CTX, T0_POP()); + T0_PUSHi(err); +} + +\ Process static ECDH. +: process-static-ECDH ( ktu -- ) + \ Static ECDH is allowed only if the cipher suite uses ECDH, and + \ the client's public key has type EC and allows key exchange. + \ BR_KEYTYPE_KEYX is 0x10, and BR_KEYTYPE_EC is 2. + 0x1F and 0x12 = ifnot ERR_WRONG_KEY_USAGE fail then + addr-cipher_suite get16 + dup use-ecdh? ifnot ERR_UNEXPECTED fail then + prf-id + do-static-ecdh ; + +\ Read CertificateVerify header. +: read-CertificateVerify-header ( -- lim ) + compute-hash-CV + read-handshake-header 15 = ifnot ERR_UNEXPECTED fail then ; + +\ Read CertificateVerify. The client key type + usage is expected on the +\ stack. +: read-CertificateVerify ( ktu -- ) + \ Check that the key allows for signatures. + dup 0x20 and ifnot ERR_WRONG_KEY_USAGE fail then + 0x0F and { key-type } + + \ Get header. + read-CertificateVerify-header + + \ With TLS 1.2+, there is an explicit hash + signature indication, + \ which must be compatible with the key type. + addr-version get16 0x0303 >= if + \ Get hash function, then signature algorithm. The + \ signature algorithm is 1 (RSA) or 3 (ECDSA) while our + \ symbolic constants for key types are 1 (RSA) or 2 (EC). + read16 + dup 0xFF and 1+ 1 >> key-type = ifnot + ERR_BAD_SIGNATURE fail + then + 8 >> + + \ We support only SHA-1, SHA-224, SHA-256, SHA-384 + \ and SHA-512. We explicitly reject MD5. + dup 2 < over 6 > or if ERR_INVALID_ALGORITHM fail then + else + \ With TLS 1.0 and 1.1, hash is MD5+SHA-1 (0) for RSA, + \ SHA-1 (2) for ECDSA. + key-type 0x01 = if 0 else 2 then + then + copy-hash-CV ifnot ERR_INVALID_ALGORITHM fail then + + \ Read signature. + read16 dup { sig-len } + dup 512 > if ERR_LIMIT_EXCEEDED fail then + addr-pad swap read-blob + sig-len verify-CV-sig + dup if fail then drop + + close-elt ; + +\ Send a HelloRequest. +: send-HelloRequest ( -- ) + flush-record + begin can-output? not while wait-co drop repeat + 22 addr-record_type_out set8 + 0 write8 0 write24 flush-record + 23 addr-record_type_out set8 ; + +\ Make a handshake. +: do-handshake ( initial -- ) + 0 addr-application_data set8 + 22 addr-record_type_out set8 + 0 addr-selected_protocol set16 + multihash-init + read-ClientHello + more-incoming-bytes? if ERR_UNEXPECTED fail then + if + \ Session resumption + write-ServerHello + 0 write-CCS-Finished + 0 read-CCS-Finished + else + \ Not a session resumption + write-ServerHello + write-Certificate drop + write-ServerKeyExchange + ta-names-total-length if + write-CertificateRequest + then + write-ServerHelloDone + flush-record + + \ If we sent a CertificateRequest then we expect a + \ Certificate message. + ta-names-total-length if + \ Read client certificate. + 0 read-Certificate + + choice + dup 0< uf + \ Client certificate validation failed. + 2 flag? ifnot neg fail then + drop + read-ClientKeyExchange + read-CertificateVerify-header + dup skip-blob drop + enduf + dup 0= uf + \ Client sent no certificate at all. + drop + 2 flag? ifnot + ERR_NO_CLIENT_AUTH fail + then + read-ClientKeyExchange + enduf + + \ Client certificate was validated. + read-ClientKeyExchange-header + dup ifnot + \ Empty ClientKeyExchange. + drop + process-static-ECDH + else + read-ClientKeyExchange-contents + read-CertificateVerify + then + endchoice + else + \ No client certificate request, we just expect + \ a non-empty ClientKeyExchange. + read-ClientKeyExchange + then + 0 read-CCS-Finished + 0 write-CCS-Finished + save-session + then + 1 addr-application_data set8 + 23 addr-record_type_out set8 ; + +\ Entry point. +: main ( -- ! ) + \ Perform initial handshake. + -1 do-handshake + + begin + \ Wait for further invocation. At that point, we should + \ get either an explicit call for renegotiation, or + \ an incoming ClientHello handshake message. + wait-co + dup 0x07 and case + 0x00 of + 0x10 and if + \ The best we can do is ask for a + \ renegotiation, then wait for it + \ to happen. + 0 addr-application_data set8 + send-HelloRequest + then + endof + 0x01 of + \ Reject renegotiations if the peer does not + \ support secure renegotiation, or if the + \ "no renegotiation" flag is set. + drop + addr-reneg get8 1 = 1 flag? or if + skip-ClientHello + flush-record + begin can-output? not while + wait-co drop + repeat + 100 send-warning + \ Put back connection in "application + \ data" state: it's not dead yet. + 1 addr-application_data set8 + 23 addr-record_type_out set8 + else + 0 do-handshake + then + endof + ERR_UNEXPECTED fail + endcase + again + ; diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_io.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_io.c new file mode 100644 index 000000000..73dce37bc --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_io.c @@ -0,0 +1,266 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_ssl.h */ +void +br_sslio_init(br_sslio_context *ctx, + br_ssl_engine_context *engine, + int (*low_read)(void *read_context, + unsigned char *data, size_t len), + void *read_context, + int (*low_write)(void *write_context, + const unsigned char *data, size_t len), + void *write_context) +{ + ctx->engine = engine; + ctx->low_read = low_read; + ctx->read_context = read_context; + ctx->low_write = low_write; + ctx->write_context = write_context; +} + +/* + * Run the engine, until the specified target state is achieved, or + * an error occurs. The target state is SENDAPP, RECVAPP, or the + * combination of both (the combination matches either). When a match is + * achieved, this function returns 0. On error, it returns -1. + */ +static int +run_until(br_sslio_context *ctx, unsigned target) +{ + for (;;) { + unsigned state; + + state = br_ssl_engine_current_state(ctx->engine); + if (state & BR_SSL_CLOSED) { + return -1; + } + + /* + * If there is some record data to send, do it. This takes + * precedence over everything else. + */ + if (state & BR_SSL_SENDREC) { + unsigned char *buf; + size_t len; + int wlen; + + buf = br_ssl_engine_sendrec_buf(ctx->engine, &len); + wlen = ctx->low_write(ctx->write_context, buf, len); + if (wlen < 0) { + /* + * If we received a close_notify and we + * still send something, then we have our + * own response close_notify to send, and + * the peer is allowed by RFC 5246 not to + * wait for it. + */ + if (!ctx->engine->shutdown_recv) { + br_ssl_engine_fail( + ctx->engine, BR_ERR_IO); + } + return -1; + } + if (wlen > 0) { + br_ssl_engine_sendrec_ack(ctx->engine, wlen); + } + continue; + } + + /* + * If we reached our target, then we are finished. + */ + if (state & target) { + return 0; + } + + /* + * If some application data must be read, and we did not + * exit, then this means that we are trying to write data, + * and that's not possible until the application data is + * read. This may happen if using a shared in/out buffer, + * and the underlying protocol is not strictly half-duplex. + * This is unrecoverable here, so we report an error. + */ + if (state & BR_SSL_RECVAPP) { + return -1; + } + + /* + * If we reached that point, then either we are trying + * to read data and there is some, or the engine is stuck + * until a new record is obtained. + */ + if (state & BR_SSL_RECVREC) { + unsigned char *buf; + size_t len; + int rlen; + + buf = br_ssl_engine_recvrec_buf(ctx->engine, &len); + rlen = ctx->low_read(ctx->read_context, buf, len); + if (rlen < 0) { + br_ssl_engine_fail(ctx->engine, BR_ERR_IO); + return -1; + } + if (rlen > 0) { + br_ssl_engine_recvrec_ack(ctx->engine, rlen); + } + continue; + } + + /* + * We can reach that point if the target RECVAPP, and + * the state contains SENDAPP only. This may happen with + * a shared in/out buffer. In that case, we must flush + * the buffered data to "make room" for a new incoming + * record. + */ + br_ssl_engine_flush(ctx->engine, 0); + } +} + +/* see bearssl_ssl.h */ +int +br_sslio_read(br_sslio_context *ctx, void *dst, size_t len) +{ + unsigned char *buf; + size_t alen; + + if (len == 0) { + return 0; + } + if (run_until(ctx, BR_SSL_RECVAPP) < 0) { + return -1; + } + buf = br_ssl_engine_recvapp_buf(ctx->engine, &alen); + if (alen > len) { + alen = len; + } + memcpy(dst, buf, alen); + br_ssl_engine_recvapp_ack(ctx->engine, alen); + return (int)alen; +} + +/* see bearssl_ssl.h */ +int +br_sslio_read_all(br_sslio_context *ctx, void *dst, size_t len) +{ + unsigned char *buf; + + buf = dst; + while (len > 0) { + int rlen; + + rlen = br_sslio_read(ctx, buf, len); + if (rlen < 0) { + return -1; + } + buf += rlen; + len -= (size_t)rlen; + } + return 0; +} + +/* see bearssl_ssl.h */ +int +br_sslio_write(br_sslio_context *ctx, const void *src, size_t len) +{ + unsigned char *buf; + size_t alen; + + if (len == 0) { + return 0; + } + if (run_until(ctx, BR_SSL_SENDAPP) < 0) { + return -1; + } + buf = br_ssl_engine_sendapp_buf(ctx->engine, &alen); + if (alen > len) { + alen = len; + } + memcpy(buf, src, alen); + br_ssl_engine_sendapp_ack(ctx->engine, alen); + return (int)alen; +} + +/* see bearssl_ssl.h */ +int +br_sslio_write_all(br_sslio_context *ctx, const void *src, size_t len) +{ + const unsigned char *buf; + + buf = src; + while (len > 0) { + int wlen; + + wlen = br_sslio_write(ctx, buf, len); + if (wlen < 0) { + return -1; + } + buf += wlen; + len -= (size_t)wlen; + } + return 0; +} + +/* see bearssl_ssl.h */ +int +br_sslio_flush(br_sslio_context *ctx) +{ + /* + * We trigger a flush. We know the data is gone when there is + * no longer any record data to send, and we can either read + * or write application data. The call to run_until() does the + * job because it ensures that any assembled record data is + * first sent down the wire before considering anything else. + */ + br_ssl_engine_flush(ctx->engine, 0); + return run_until(ctx, BR_SSL_SENDAPP | BR_SSL_RECVAPP); +} + +/* see bearssl_ssl.h */ +int +br_sslio_close(br_sslio_context *ctx) +{ + br_ssl_engine_close(ctx->engine); + while (br_ssl_engine_current_state(ctx->engine) != BR_SSL_CLOSED) { + /* + * Discard any incoming application data. + */ + size_t len; + + run_until(ctx, BR_SSL_RECVAPP); + if (br_ssl_engine_recvapp_buf(ctx->engine, &len) != NULL) { + br_ssl_engine_recvapp_ack(ctx->engine, len); + } + } + return br_ssl_engine_last_error(ctx->engine) == BR_ERR_OK; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_keyexport.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_keyexport.c new file mode 100644 index 000000000..1efaa960e --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_keyexport.c @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* + * Supported cipher suites that use SHA-384 for the PRF when selected + * for TLS 1.2. All other cipher suites are deemed to use SHA-256. + */ +static const uint16_t suites_sha384[] = { + BR_TLS_RSA_WITH_AES_256_GCM_SHA384, + BR_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384, + BR_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384, + BR_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384, + BR_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384, + BR_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, + BR_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384, + BR_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, + BR_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384 +}; + +/* see bearssl_ssl.h */ +int +br_ssl_key_export(br_ssl_engine_context *cc, + void *dst, size_t len, const char *label, + const void *context, size_t context_len) +{ + br_tls_prf_seed_chunk chunks[4]; + br_tls_prf_impl iprf; + size_t num_chunks, u; + unsigned char tmp[2]; + int prf_id; + + if (cc->application_data != 1) { + return 0; + } + chunks[0].data = cc->client_random; + chunks[0].len = sizeof cc->client_random; + chunks[1].data = cc->server_random; + chunks[1].len = sizeof cc->server_random; + if (context != NULL) { + br_enc16be(tmp, (unsigned)context_len); + chunks[2].data = tmp; + chunks[2].len = 2; + chunks[3].data = context; + chunks[3].len = context_len; + num_chunks = 4; + } else { + num_chunks = 2; + } + prf_id = BR_SSLPRF_SHA256; + for (u = 0; u < (sizeof suites_sha384) / sizeof(uint16_t); u ++) { + if (suites_sha384[u] == cc->session.cipher_suite) { + prf_id = BR_SSLPRF_SHA384; + } + } + iprf = br_ssl_engine_get_PRF(cc, prf_id); + iprf(dst, len, + cc->session.master_secret, sizeof cc->session.master_secret, + label, num_chunks, chunks); + return 1; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_lru.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_lru.c new file mode 100644 index 000000000..d211c7658 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_lru.c @@ -0,0 +1,542 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* + * Each entry consists in a fixed number of bytes. Entries are concatenated + * in the store block. "Addresses" are really offsets in the block, + * expressed over 32 bits (so the cache may have size at most 4 GB, which + * "ought to be enough for everyone"). The "null address" is 0xFFFFFFFF. + * Note that since the storage block alignment is in no way guaranteed, we + * perform only accesses that can handle unaligned data. + * + * Two concurrent data structures are maintained: + * + * -- Entries are organised in a doubly-linked list; saved entries are added + * at the head, and loaded entries are moved to the head. Eviction uses + * the list tail (this is the LRU algorithm). + * + * -- Entries are indexed with a binary tree: all left descendants of a + * node have a lower session ID (in lexicographic order), while all + * right descendants have a higher session ID. The tree is heuristically + * balanced. + * + * Entry format: + * + * session ID 32 bytes + * master secret 48 bytes + * protocol version 2 bytes (big endian) + * cipher suite 2 bytes (big endian) + * list prev 4 bytes (big endian) + * list next 4 bytes (big endian) + * tree left child 4 bytes (big endian) + * tree right child 4 bytes (big endian) + * + * If an entry has a protocol version set to 0, then it is "disabled": + * it was a session pushed to the cache at some point, but it has + * been explicitly removed. + * + * We need to keep the tree balanced because an attacker could make + * handshakes, selecting some specific sessions (by reusing them) to + * try to make us make an imbalanced tree that makes lookups expensive + * (a denial-of-service attack that would persist as long as the cache + * remains, i.e. even after the attacker made all his connections). + * To do that, we replace the session ID (or the start of the session ID) + * with a HMAC value computed over the replaced part; the hash function + * implementation and the key are obtained from the server context upon + * first save() call. + * + * Theoretically, an attacker could use the exact timing of the lookup + * to infer the current tree topology, and try to revive entries to make + * it as unbalanced as possible. However, since the session ID are + * chosen randomly by the server, and the attacker cannot see the + * indexing values and must thus rely on blind selection, it should be + * exponentially difficult for the attacker to maintain a large + * imbalance. + */ +#define SESSION_ID_LEN 32 +#define MASTER_SECRET_LEN 48 + +#define SESSION_ID_OFF 0 +#define MASTER_SECRET_OFF 32 +#define VERSION_OFF 80 +#define CIPHER_SUITE_OFF 82 +#define LIST_PREV_OFF 84 +#define LIST_NEXT_OFF 88 +#define TREE_LEFT_OFF 92 +#define TREE_RIGHT_OFF 96 + +#define LRU_ENTRY_LEN 100 + +#define ADDR_NULL ((uint32_t)-1) + +#define GETSET(name, off) \ +static inline uint32_t get_ ## name(br_ssl_session_cache_lru *cc, uint32_t x) \ +{ \ + return br_dec32be(cc->store + x + (off)); \ +} \ +static inline void set_ ## name(br_ssl_session_cache_lru *cc, \ + uint32_t x, uint32_t val) \ +{ \ + br_enc32be(cc->store + x + (off), val); \ +} + +GETSET(prev, LIST_PREV_OFF) +GETSET(next, LIST_NEXT_OFF) +GETSET(left, TREE_LEFT_OFF) +GETSET(right, TREE_RIGHT_OFF) + +/* + * Transform the session ID by replacing the first N bytes with a HMAC + * value computed over these bytes, using the random key K (the HMAC + * value is truncated if needed). HMAC will use the same hash function + * as the DRBG in the SSL server context, so with SHA-256, SHA-384, + * or SHA-1, depending on what is available. + * + * The risk of collision is considered too small to be a concern; and + * the impact of a collision is low (the handshake won't succeed). This + * risk is much lower than any transmission error, which would lead to + * the same consequences. + * + * Source and destination arrays msut be disjoint. + */ +static void +mask_id(br_ssl_session_cache_lru *cc, + const unsigned char *src, unsigned char *dst) +{ + br_hmac_key_context hkc; + br_hmac_context hc; + + memcpy(dst, src, SESSION_ID_LEN); + br_hmac_key_init(&hkc, cc->hash, cc->index_key, sizeof cc->index_key); + br_hmac_init(&hc, &hkc, SESSION_ID_LEN); + br_hmac_update(&hc, src, SESSION_ID_LEN); + br_hmac_out(&hc, dst); +} + +/* + * Find a node by ID. Returned value is the node address, or ADDR_NULL if + * the node is not found. + * + * If addr_link is not NULL, then '*addr_link' is set to the address of the + * last followed link. If the found node is the root, or if the tree is + * empty, then '*addr_link' is set to ADDR_NULL. + */ +static uint32_t +find_node(br_ssl_session_cache_lru *cc, const unsigned char *id, + uint32_t *addr_link) +{ + uint32_t x, y; + + x = cc->root; + y = ADDR_NULL; + while (x != ADDR_NULL) { + int r; + + r = memcmp(id, cc->store + x + SESSION_ID_OFF, SESSION_ID_LEN); + if (r < 0) { + y = x + TREE_LEFT_OFF; + x = get_left(cc, x); + } else if (r == 0) { + if (addr_link != NULL) { + *addr_link = y; + } + return x; + } else { + y = x + TREE_RIGHT_OFF; + x = get_right(cc, x); + } + } + if (addr_link != NULL) { + *addr_link = y; + } + return ADDR_NULL; +} + +/* + * For node x, find its replacement upon removal. + * + * -- If node x has no child, then this returns ADDR_NULL. + * -- Otherwise, if node x has a left child, then the replacement is the + * rightmost left-descendent. + * -- Otherwise, the replacement is the leftmost right-descendent. + * + * If a node is returned, then '*al' is set to the address of the field + * that points to that node. Otherwise (node x has no child), '*al' is + * set to ADDR_NULL. + * + * Note that the replacement node, when found, is always a descendent + * of node 'x', so it cannot be the tree root. Thus, '*al' can be set + * to ADDR_NULL only when no node is found and ADDR_NULL is returned. + */ +static uint32_t +find_replacement_node(br_ssl_session_cache_lru *cc, uint32_t x, uint32_t *al) +{ + uint32_t y1, y2; + + y1 = get_left(cc, x); + if (y1 != ADDR_NULL) { + y2 = x + TREE_LEFT_OFF; + for (;;) { + uint32_t z; + + z = get_right(cc, y1); + if (z == ADDR_NULL) { + *al = y2; + return y1; + } + y2 = y1 + TREE_RIGHT_OFF; + y1 = z; + } + } + y1 = get_right(cc, x); + if (y1 != ADDR_NULL) { + y2 = x + TREE_RIGHT_OFF; + for (;;) { + uint32_t z; + + z = get_left(cc, y1); + if (z == ADDR_NULL) { + *al = y2; + return y1; + } + y2 = y1 + TREE_LEFT_OFF; + y1 = z; + } + } + *al = ADDR_NULL; + return ADDR_NULL; +} + +/* + * Set the link at address 'alx' to point to node 'x'. If 'alx' is + * ADDR_NULL, then this sets the tree root to 'x'. + */ +static inline void +set_link(br_ssl_session_cache_lru *cc, uint32_t alx, uint32_t x) +{ + if (alx == ADDR_NULL) { + cc->root = x; + } else { + br_enc32be(cc->store + alx, x); + } +} + +/* + * Remove node 'x' from the tree. This function shall not be called if + * node 'x' is not part of the tree. + */ +static void +remove_node(br_ssl_session_cache_lru *cc, uint32_t x) +{ + uint32_t alx, y, aly; + + /* + * Removal algorithm: + * ------------------ + * + * - If we remove the root, then the tree becomes empty. + * + * - If the removed node has no child, then we can simply remove + * it, with nothing else to do. + * + * - Otherwise, the removed node must be replaced by either its + * rightmost left-descendent, or its leftmost right-descendent. + * The replacement node itself must be removed from its current + * place. By definition, that replacement node has either no + * child, or at most a single child that will replace it in the + * tree. + */ + + /* + * Find node back and its ancestor link. If the node was the + * root, then alx is set to ADDR_NULL. + */ + find_node(cc, cc->store + x + SESSION_ID_OFF, &alx); + + /* + * Find replacement node 'y', and 'aly' is set to the address of + * the link to that replacement node. If the removed node has no + * child, then both 'y' and 'aly' are set to ADDR_NULL. + */ + y = find_replacement_node(cc, x, &aly); + + if (y != ADDR_NULL) { + uint32_t z; + + /* + * The unlinked replacement node may have one child (but + * not two) that takes its place. + */ + z = get_left(cc, y); + if (z == ADDR_NULL) { + z = get_right(cc, y); + } + set_link(cc, aly, z); + + /* + * Link the replacement node in its new place, overwriting + * the current link to the node 'x' (which removes 'x'). + */ + set_link(cc, alx, y); + + /* + * The replacement node adopts the left and right children + * of the removed node. Note that this also works even if + * the replacement node was a direct descendent of the + * removed node, since we unlinked it previously. + */ + set_left(cc, y, get_left(cc, x)); + set_right(cc, y, get_right(cc, x)); + } else { + /* + * No replacement, we simply unlink the node 'x'. + */ + set_link(cc, alx, ADDR_NULL); + } +} + +static void +lru_save(const br_ssl_session_cache_class **ctx, + br_ssl_server_context *server_ctx, + const br_ssl_session_parameters *params) +{ + br_ssl_session_cache_lru *cc; + unsigned char id[SESSION_ID_LEN]; + uint32_t x, alx; + + cc = (br_ssl_session_cache_lru *)ctx; + + /* + * If the buffer is too small, we don't record anything. This + * test avoids problems in subsequent code. + */ + if (cc->store_len < LRU_ENTRY_LEN) { + return; + } + + /* + * Upon the first save in a session cache instance, we obtain + * a random key for our indexing. + */ + if (!cc->init_done) { + br_hmac_drbg_generate(&server_ctx->eng.rng, + cc->index_key, sizeof cc->index_key); + cc->hash = br_hmac_drbg_get_hash(&server_ctx->eng.rng); + cc->init_done = 1; + } + mask_id(cc, params->session_id, id); + + /* + * Look for the node in the tree. If the same ID is already used, + * then reject it. This is a collision event, which should be + * exceedingly rare. + * Note: we do NOT record the emplacement here, because the + * removal of an entry may change the tree topology. + */ + if (find_node(cc, id, NULL) != ADDR_NULL) { + return; + } + + /* + * Find some room for the new parameters. If the cache is not + * full yet, add it to the end of the area and bump the pointer up. + * Otherwise, evict the list tail entry. Note that we already + * filtered out the case of a ridiculously small buffer that + * cannot hold any entry at all; thus, if there is no room for an + * extra entry, then the cache cannot be empty. + */ + if (cc->store_ptr > (cc->store_len - LRU_ENTRY_LEN)) { + /* + * Evict tail. If the buffer has room for a single entry, + * then this may also be the head. + */ + x = cc->tail; + cc->tail = get_prev(cc, x); + if (cc->tail == ADDR_NULL) { + cc->head = ADDR_NULL; + } else { + set_next(cc, cc->tail, ADDR_NULL); + } + + /* + * Remove the node from the tree. + */ + remove_node(cc, x); + } else { + /* + * Allocate room for new node. + */ + x = cc->store_ptr; + cc->store_ptr += LRU_ENTRY_LEN; + } + + /* + * Find the emplacement for the new node, and link it. + */ + find_node(cc, id, &alx); + set_link(cc, alx, x); + set_left(cc, x, ADDR_NULL); + set_right(cc, x, ADDR_NULL); + + /* + * New entry becomes new list head. It may also become the list + * tail if the cache was empty at that point. + */ + if (cc->head == ADDR_NULL) { + cc->tail = x; + } else { + set_prev(cc, cc->head, x); + } + set_prev(cc, x, ADDR_NULL); + set_next(cc, x, cc->head); + cc->head = x; + + /* + * Fill data in the entry. + */ + memcpy(cc->store + x + SESSION_ID_OFF, id, SESSION_ID_LEN); + memcpy(cc->store + x + MASTER_SECRET_OFF, + params->master_secret, MASTER_SECRET_LEN); + br_enc16be(cc->store + x + VERSION_OFF, params->version); + br_enc16be(cc->store + x + CIPHER_SUITE_OFF, params->cipher_suite); +} + +static int +lru_load(const br_ssl_session_cache_class **ctx, + br_ssl_server_context *server_ctx, + br_ssl_session_parameters *params) +{ + br_ssl_session_cache_lru *cc; + unsigned char id[SESSION_ID_LEN]; + uint32_t x; + + (void)server_ctx; + cc = (br_ssl_session_cache_lru *)ctx; + if (!cc->init_done) { + return 0; + } + mask_id(cc, params->session_id, id); + x = find_node(cc, id, NULL); + if (x != ADDR_NULL) { + unsigned version; + + version = br_dec16be(cc->store + x + VERSION_OFF); + if (version == 0) { + /* + * Entry is disabled, we pretend we did not find it. + * Notably, we don't move it to the front of the + * LRU list. + */ + return 0; + } + params->version = version; + params->cipher_suite = br_dec16be( + cc->store + x + CIPHER_SUITE_OFF); + memcpy(params->master_secret, + cc->store + x + MASTER_SECRET_OFF, + MASTER_SECRET_LEN); + if (x != cc->head) { + /* + * Found node is not at list head, so move + * it to the head. + */ + uint32_t p, n; + + p = get_prev(cc, x); + n = get_next(cc, x); + set_next(cc, p, n); + if (n == ADDR_NULL) { + cc->tail = p; + } else { + set_prev(cc, n, p); + } + set_prev(cc, cc->head, x); + set_next(cc, x, cc->head); + set_prev(cc, x, ADDR_NULL); + cc->head = x; + } + return 1; + } + return 0; +} + +static const br_ssl_session_cache_class lru_class = { + sizeof(br_ssl_session_cache_lru), + &lru_save, + &lru_load +}; + +/* see inner.h */ +void +br_ssl_session_cache_lru_init(br_ssl_session_cache_lru *cc, + unsigned char *store, size_t store_len) +{ + cc->vtable = &lru_class; + cc->store = store; + cc->store_len = store_len; + cc->store_ptr = 0; + cc->init_done = 0; + cc->head = ADDR_NULL; + cc->tail = ADDR_NULL; + cc->root = ADDR_NULL; +} + +/* see bearssl_ssl.h */ +void br_ssl_session_cache_lru_forget( + br_ssl_session_cache_lru *cc, const unsigned char *id) +{ + unsigned char mid[SESSION_ID_LEN]; + uint32_t addr; + + /* + * If the cache is not initialised yet, then it is empty, and + * there is nothing to forget. + */ + if (!cc->init_done) { + return; + } + + /* + * Look for the node in the tree. If found, the entry is marked + * as "disabled"; it will be reused in due course, as it ages + * through the list. + * + * We do not go through the complex moves of actually releasing + * the entry right away because explicitly forgetting sessions + * should be a rare event, meant mostly for testing purposes, + * so this is not worth the extra code size. + */ + mask_id(cc, id, mid); + addr = find_node(cc, mid, NULL); + if (addr != ADDR_NULL) { + br_enc16be(cc->store + addr + VERSION_OFF, 0); + } +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_rec_cbc.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_rec_cbc.c new file mode 100644 index 000000000..3b4d0d0f7 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_rec_cbc.c @@ -0,0 +1,445 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +static void +in_cbc_init(br_sslrec_in_cbc_context *cc, + const br_block_cbcdec_class *bc_impl, + const void *bc_key, size_t bc_key_len, + const br_hash_class *dig_impl, + const void *mac_key, size_t mac_key_len, size_t mac_out_len, + const void *iv) +{ + cc->vtable = &br_sslrec_in_cbc_vtable; + cc->seq = 0; + bc_impl->init(&cc->bc.vtable, bc_key, bc_key_len); + br_hmac_key_init(&cc->mac, dig_impl, mac_key, mac_key_len); + cc->mac_len = mac_out_len; + if (iv == NULL) { + memset(cc->iv, 0, sizeof cc->iv); + cc->explicit_IV = 1; + } else { + memcpy(cc->iv, iv, bc_impl->block_size); + cc->explicit_IV = 0; + } +} + +static int +cbc_check_length(const br_sslrec_in_cbc_context *cc, size_t rlen) +{ + /* + * Plaintext size: at most 16384 bytes + * Padding: at most 256 bytes + * MAC: mac_len extra bytes + * TLS 1.1+: each record has an explicit IV + * + * Minimum length includes at least one byte of padding, and the + * MAC. + * + * Total length must be a multiple of the block size. + */ + size_t blen; + size_t min_len, max_len; + + blen = cc->bc.vtable->block_size; + min_len = (blen + cc->mac_len) & ~(blen - 1); + max_len = (16384 + 256 + cc->mac_len) & ~(blen - 1); + if (cc->explicit_IV) { + min_len += blen; + max_len += blen; + } + return min_len <= rlen && rlen <= max_len; +} + +/* + * Rotate array buf[] of length 'len' to the left (towards low indices) + * by 'num' bytes if ctl is 1; otherwise, leave it unchanged. This is + * constant-time. 'num' MUST be lower than 'len'. 'len' MUST be lower + * than or equal to 64. + */ +static void +cond_rotate(uint32_t ctl, unsigned char *buf, size_t len, size_t num) +{ + unsigned char tmp[64]; + size_t u, v; + + for (u = 0, v = num; u < len; u ++) { + tmp[u] = MUX(ctl, buf[v], buf[u]); + if (++ v == len) { + v = 0; + } + } + memcpy(buf, tmp, len); +} + +static unsigned char * +cbc_decrypt(br_sslrec_in_cbc_context *cc, + int record_type, unsigned version, void *data, size_t *data_len) +{ + /* + * We represent all lengths on 32-bit integers, because: + * -- SSL record lengths always fit in 32 bits; + * -- our constant-time primitives operate on 32-bit integers. + */ + unsigned char *buf; + uint32_t u, v, len, blen, min_len, max_len; + uint32_t good, pad_len, rot_count, len_withmac, len_nomac; + unsigned char tmp1[64], tmp2[64]; + int i; + br_hmac_context hc; + + buf = data; + len = *data_len; + blen = cc->bc.vtable->block_size; + + /* + * Decrypt data, and skip the explicit IV (if applicable). Note + * that the total length is supposed to have been verified by + * the caller. If there is an explicit IV, then we actually + * "decrypt" it using the implicit IV (from previous record), + * which is useless but harmless. + */ + cc->bc.vtable->run(&cc->bc.vtable, cc->iv, data, len); + if (cc->explicit_IV) { + buf += blen; + len -= blen; + } + + /* + * Compute minimum and maximum length of plaintext + MAC. These + * lengths can be inferred from the outside: they are not secret. + */ + min_len = (cc->mac_len + 256 < len) ? len - 256 : cc->mac_len; + max_len = len - 1; + + /* + * Use the last decrypted byte to compute the actual payload + * length. Take care not to underflow (we use unsigned types). + */ + pad_len = buf[max_len]; + good = LE(pad_len, (uint32_t)(max_len - min_len)); + len = MUX(good, (uint32_t)(max_len - pad_len), min_len); + + /* + * Check padding contents: all padding bytes must be equal to + * the value of pad_len. + */ + for (u = min_len; u < max_len; u ++) { + good &= LT(u, len) | EQ(buf[u], pad_len); + } + + /* + * Extract the MAC value. This is done in one pass, but results + * in a "rotated" MAC value depending on where it actually + * occurs. The 'rot_count' value is set to the offset of the + * first MAC byte within tmp1[]. + * + * min_len and max_len are also adjusted to the minimum and + * maximum lengths of the plaintext alone (without the MAC). + */ + len_withmac = (uint32_t)len; + len_nomac = len_withmac - cc->mac_len; + min_len -= cc->mac_len; + rot_count = 0; + memset(tmp1, 0, cc->mac_len); + v = 0; + for (u = min_len; u < max_len; u ++) { + tmp1[v] |= MUX(GE(u, len_nomac) & LT(u, len_withmac), + buf[u], 0x00); + rot_count = MUX(EQ(u, len_nomac), v, rot_count); + if (++ v == cc->mac_len) { + v = 0; + } + } + max_len -= cc->mac_len; + + /* + * Rotate back the MAC value. The loop below does the constant-time + * rotation in time n*log n for a MAC output of length n. We assume + * that the MAC output length is no more than 64 bytes, so the + * rotation count fits on 6 bits. + */ + for (i = 5; i >= 0; i --) { + uint32_t rc; + + rc = (uint32_t)1 << i; + cond_rotate(rot_count >> i, tmp1, cc->mac_len, rc); + rot_count &= ~rc; + } + + /* + * Recompute the HMAC value. The input is the concatenation of + * the sequence number (8 bytes), the record header (5 bytes), + * and the payload. + * + * At that point, min_len is the minimum plaintext length, but + * max_len still includes the MAC length. + */ + br_enc64be(tmp2, cc->seq ++); + tmp2[8] = (unsigned char)record_type; + br_enc16be(tmp2 + 9, version); + br_enc16be(tmp2 + 11, len_nomac); + br_hmac_init(&hc, &cc->mac, cc->mac_len); + br_hmac_update(&hc, tmp2, 13); + br_hmac_outCT(&hc, buf, len_nomac, min_len, max_len, tmp2); + + /* + * Compare the extracted and recomputed MAC values. + */ + for (u = 0; u < cc->mac_len; u ++) { + good &= EQ0(tmp1[u] ^ tmp2[u]); + } + + /* + * Check that the plaintext length is valid. The previous + * check was on the encrypted length, but the padding may have + * turned shorter than expected. + * + * Once this final test is done, the critical "constant-time" + * section ends and we can make conditional jumps again. + */ + good &= LE(len_nomac, 16384); + + if (!good) { + return 0; + } + *data_len = len_nomac; + return buf; +} + +/* see bearssl_ssl.h */ +const br_sslrec_in_cbc_class br_sslrec_in_cbc_vtable = { + { + sizeof(br_sslrec_in_cbc_context), + (int (*)(const br_sslrec_in_class *const *, size_t)) + &cbc_check_length, + (unsigned char *(*)(const br_sslrec_in_class **, + int, unsigned, void *, size_t *)) + &cbc_decrypt + }, + (void (*)(const br_sslrec_in_cbc_class **, + const br_block_cbcdec_class *, const void *, size_t, + const br_hash_class *, const void *, size_t, size_t, + const void *)) + &in_cbc_init +}; + +/* + * For CBC output: + * + * -- With TLS 1.1+, there is an explicit IV. Generation method uses + * HMAC, computed over the current sequence number, and the current MAC + * key. The resulting value is truncated to the size of a block, and + * added at the head of the plaintext; it will get encrypted along with + * the data. This custom generation mechanism is "safe" under the + * assumption that HMAC behaves like a random oracle; since the MAC for + * a record is computed over the concatenation of the sequence number, + * the record header and the plaintext, the HMAC-for-IV will not collide + * with the normal HMAC. + * + * -- With TLS 1.0, for application data, we want to enforce a 1/n-1 + * split, as a countermeasure against chosen-plaintext attacks. We thus + * need to leave some room in the buffer for that extra record. + */ + +static void +out_cbc_init(br_sslrec_out_cbc_context *cc, + const br_block_cbcenc_class *bc_impl, + const void *bc_key, size_t bc_key_len, + const br_hash_class *dig_impl, + const void *mac_key, size_t mac_key_len, size_t mac_out_len, + const void *iv) +{ + cc->vtable = &br_sslrec_out_cbc_vtable; + cc->seq = 0; + bc_impl->init(&cc->bc.vtable, bc_key, bc_key_len); + br_hmac_key_init(&cc->mac, dig_impl, mac_key, mac_key_len); + cc->mac_len = mac_out_len; + if (iv == NULL) { + memset(cc->iv, 0, sizeof cc->iv); + cc->explicit_IV = 1; + } else { + memcpy(cc->iv, iv, bc_impl->block_size); + cc->explicit_IV = 0; + } +} + +static void +cbc_max_plaintext(const br_sslrec_out_cbc_context *cc, + size_t *start, size_t *end) +{ + size_t blen, len; + + blen = cc->bc.vtable->block_size; + if (cc->explicit_IV) { + *start += blen; + } else { + *start += 4 + ((cc->mac_len + blen + 1) & ~(blen - 1)); + } + len = (*end - *start) & ~(blen - 1); + len -= 1 + cc->mac_len; + if (len > 16384) { + len = 16384; + } + *end = *start + len; +} + +static unsigned char * +cbc_encrypt(br_sslrec_out_cbc_context *cc, + int record_type, unsigned version, void *data, size_t *data_len) +{ + unsigned char *buf, *rbuf; + size_t len, blen, plen; + unsigned char tmp[13]; + br_hmac_context hc; + + buf = data; + len = *data_len; + blen = cc->bc.vtable->block_size; + + /* + * If using TLS 1.0, with more than one byte of plaintext, and + * the record is application data, then we need to compute + * a "split". We do not perform the split on other record types + * because it turned out that some existing, deployed + * implementations of SSL/TLS do not tolerate the splitting of + * some message types (in particular the Finished message). + * + * If using TLS 1.1+, then there is an explicit IV. We produce + * that IV by adding an extra initial plaintext block, whose + * value is computed with HMAC over the record sequence number. + */ + if (cc->explicit_IV) { + /* + * We use here the fact that all the HMAC variants we + * support can produce at least 16 bytes, while all the + * block ciphers we support have blocks of no more than + * 16 bytes. Thus, we can always truncate the HMAC output + * down to the block size. + */ + br_enc64be(tmp, cc->seq); + br_hmac_init(&hc, &cc->mac, blen); + br_hmac_update(&hc, tmp, 8); + br_hmac_out(&hc, buf - blen); + rbuf = buf - blen - 5; + } else { + if (len > 1 && record_type == BR_SSL_APPLICATION_DATA) { + /* + * To do the split, we use a recursive invocation; + * since we only give one byte to the inner call, + * the recursion stops there. + * + * We need to compute the exact size of the extra + * record, so that the two resulting records end up + * being sequential in RAM. + * + * We use here the fact that cbc_max_plaintext() + * adjusted the start offset to leave room for the + * initial fragment. + */ + size_t xlen; + + rbuf = buf - 4 + - ((cc->mac_len + blen + 1) & ~(blen - 1)); + rbuf[0] = buf[0]; + xlen = 1; + rbuf = cbc_encrypt(cc, record_type, + version, rbuf, &xlen); + buf ++; + len --; + } else { + rbuf = buf - 5; + } + } + + /* + * Compute MAC. + */ + br_enc64be(tmp, cc->seq ++); + tmp[8] = record_type; + br_enc16be(tmp + 9, version); + br_enc16be(tmp + 11, len); + br_hmac_init(&hc, &cc->mac, cc->mac_len); + br_hmac_update(&hc, tmp, 13); + br_hmac_update(&hc, buf, len); + br_hmac_out(&hc, buf + len); + len += cc->mac_len; + + /* + * Add padding. + */ + plen = blen - (len & (blen - 1)); + memset(buf + len, (unsigned)plen - 1, plen); + len += plen; + + /* + * If an explicit IV is used, the corresponding extra block was + * already put in place earlier; we just have to account for it + * here. + */ + if (cc->explicit_IV) { + buf -= blen; + len += blen; + } + + /* + * Encrypt the whole thing. If there is an explicit IV, we also + * encrypt it, which is fine (encryption of a uniformly random + * block is still a uniformly random block). + */ + cc->bc.vtable->run(&cc->bc.vtable, cc->iv, buf, len); + + /* + * Add the header and return. + */ + buf[-5] = record_type; + br_enc16be(buf - 4, version); + br_enc16be(buf - 2, len); + *data_len = (size_t)((buf + len) - rbuf); + return rbuf; +} + +/* see bearssl_ssl.h */ +const br_sslrec_out_cbc_class br_sslrec_out_cbc_vtable = { + { + sizeof(br_sslrec_out_cbc_context), + (void (*)(const br_sslrec_out_class *const *, + size_t *, size_t *)) + &cbc_max_plaintext, + (unsigned char *(*)(const br_sslrec_out_class **, + int, unsigned, void *, size_t *)) + &cbc_encrypt + }, + (void (*)(const br_sslrec_out_cbc_class **, + const br_block_cbcenc_class *, const void *, size_t, + const br_hash_class *, const void *, size_t, size_t, + const void *)) + &out_cbc_init +}; + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_rec_ccm.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_rec_ccm.c new file mode 100644 index 000000000..d2bc724a9 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_rec_ccm.c @@ -0,0 +1,218 @@ +/* + * Copyright (c) 2018 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* + * CCM initialisation. This does everything except setting the vtable, + * which depends on whether this is a context for encrypting or for + * decrypting. + */ +static void +gen_ccm_init(br_sslrec_ccm_context *cc, + const br_block_ctrcbc_class *bc_impl, + const void *key, size_t key_len, + const void *iv, size_t tag_len) +{ + cc->seq = 0; + bc_impl->init(&cc->bc.vtable, key, key_len); + memcpy(cc->iv, iv, sizeof cc->iv); + cc->tag_len = tag_len; +} + +static void +in_ccm_init(br_sslrec_ccm_context *cc, + const br_block_ctrcbc_class *bc_impl, + const void *key, size_t key_len, + const void *iv, size_t tag_len) +{ + cc->vtable.in = &br_sslrec_in_ccm_vtable; + gen_ccm_init(cc, bc_impl, key, key_len, iv, tag_len); +} + +static int +ccm_check_length(const br_sslrec_ccm_context *cc, size_t rlen) +{ + /* + * CCM overhead is 8 bytes for nonce_explicit, and the tag + * (normally 8 or 16 bytes, depending on cipher suite). + */ + size_t over; + + over = 8 + cc->tag_len; + return rlen >= over && rlen <= (16384 + over); +} + +static unsigned char * +ccm_decrypt(br_sslrec_ccm_context *cc, + int record_type, unsigned version, void *data, size_t *data_len) +{ + br_ccm_context zc; + unsigned char *buf; + unsigned char nonce[12], header[13]; + size_t len; + + buf = (unsigned char *)data + 8; + len = *data_len - (8 + cc->tag_len); + + /* + * Make nonce (implicit + explicit parts). + */ + memcpy(nonce, cc->iv, sizeof cc->iv); + memcpy(nonce + 4, data, 8); + + /* + * Assemble synthetic header for the AAD. + */ + br_enc64be(header, cc->seq ++); + header[8] = (unsigned char)record_type; + br_enc16be(header + 9, version); + br_enc16be(header + 11, len); + + /* + * Perform CCM decryption. + */ + br_ccm_init(&zc, &cc->bc.vtable); + br_ccm_reset(&zc, nonce, sizeof nonce, sizeof header, len, cc->tag_len); + br_ccm_aad_inject(&zc, header, sizeof header); + br_ccm_flip(&zc); + br_ccm_run(&zc, 0, buf, len); + if (!br_ccm_check_tag(&zc, buf + len)) { + return NULL; + } + *data_len = len; + return buf; +} + +/* see bearssl_ssl.h */ +const br_sslrec_in_ccm_class br_sslrec_in_ccm_vtable = { + { + sizeof(br_sslrec_ccm_context), + (int (*)(const br_sslrec_in_class *const *, size_t)) + &ccm_check_length, + (unsigned char *(*)(const br_sslrec_in_class **, + int, unsigned, void *, size_t *)) + &ccm_decrypt + }, + (void (*)(const br_sslrec_in_ccm_class **, + const br_block_ctrcbc_class *, const void *, size_t, + const void *, size_t)) + &in_ccm_init +}; + +static void +out_ccm_init(br_sslrec_ccm_context *cc, + const br_block_ctrcbc_class *bc_impl, + const void *key, size_t key_len, + const void *iv, size_t tag_len) +{ + cc->vtable.out = &br_sslrec_out_ccm_vtable; + gen_ccm_init(cc, bc_impl, key, key_len, iv, tag_len); +} + +static void +ccm_max_plaintext(const br_sslrec_ccm_context *cc, + size_t *start, size_t *end) +{ + size_t len; + + *start += 8; + len = *end - *start - cc->tag_len; + if (len > 16384) { + len = 16384; + } + *end = *start + len; +} + +static unsigned char * +ccm_encrypt(br_sslrec_ccm_context *cc, + int record_type, unsigned version, void *data, size_t *data_len) +{ + br_ccm_context zc; + unsigned char *buf; + unsigned char nonce[12], header[13]; + size_t len; + + buf = (unsigned char *)data; + len = *data_len; + + /* + * Make nonce; the explicit part is an encoding of the sequence + * number. + */ + memcpy(nonce, cc->iv, sizeof cc->iv); + br_enc64be(nonce + 4, cc->seq); + + /* + * Assemble synthetic header for the AAD. + */ + br_enc64be(header, cc->seq ++); + header[8] = (unsigned char)record_type; + br_enc16be(header + 9, version); + br_enc16be(header + 11, len); + + /* + * Perform CCM encryption. + */ + br_ccm_init(&zc, &cc->bc.vtable); + br_ccm_reset(&zc, nonce, sizeof nonce, sizeof header, len, cc->tag_len); + br_ccm_aad_inject(&zc, header, sizeof header); + br_ccm_flip(&zc); + br_ccm_run(&zc, 1, buf, len); + br_ccm_get_tag(&zc, buf + len); + + /* + * Assemble header and adjust pointer/length. + */ + len += 8 + cc->tag_len; + buf -= 13; + memcpy(buf + 5, nonce + 4, 8); + buf[0] = (unsigned char)record_type; + br_enc16be(buf + 1, version); + br_enc16be(buf + 3, len); + *data_len = len + 5; + return buf; +} + +/* see bearssl_ssl.h */ +const br_sslrec_out_ccm_class br_sslrec_out_ccm_vtable = { + { + sizeof(br_sslrec_ccm_context), + (void (*)(const br_sslrec_out_class *const *, + size_t *, size_t *)) + &ccm_max_plaintext, + (unsigned char *(*)(const br_sslrec_out_class **, + int, unsigned, void *, size_t *)) + &ccm_encrypt + }, + (void (*)(const br_sslrec_out_ccm_class **, + const br_block_ctrcbc_class *, const void *, size_t, + const void *, size_t)) + &out_ccm_init +}; + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_rec_chapol.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_rec_chapol.c new file mode 100644 index 000000000..fb7fcb146 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_rec_chapol.c @@ -0,0 +1,182 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +static void +gen_chapol_init(br_sslrec_chapol_context *cc, + br_chacha20_run ichacha, br_poly1305_run ipoly, + const void *key, const void *iv) +{ + cc->seq = 0; + cc->ichacha = ichacha; + cc->ipoly = ipoly; + memcpy(cc->key, key, sizeof cc->key); + memcpy(cc->iv, iv, sizeof cc->iv); +} + +static void +gen_chapol_process(br_sslrec_chapol_context *cc, + int record_type, unsigned version, void *data, size_t len, + void *tag, int encrypt) +{ + unsigned char header[13]; + unsigned char nonce[12]; + uint64_t seq; + size_t u; + + seq = cc->seq ++; + br_enc64be(header, seq); + header[8] = (unsigned char)record_type; + br_enc16be(header + 9, version); + br_enc16be(header + 11, len); + memcpy(nonce, cc->iv, 12); + for (u = 0; u < 8; u ++) { + nonce[11 - u] ^= (unsigned char)seq; + seq >>= 8; + } + cc->ipoly(cc->key, nonce, data, len, header, sizeof header, + tag, cc->ichacha, encrypt); +} + +static void +in_chapol_init(br_sslrec_chapol_context *cc, + br_chacha20_run ichacha, br_poly1305_run ipoly, + const void *key, const void *iv) +{ + cc->vtable.in = &br_sslrec_in_chapol_vtable; + gen_chapol_init(cc, ichacha, ipoly, key, iv); +} + +static int +chapol_check_length(const br_sslrec_chapol_context *cc, size_t rlen) +{ + /* + * Overhead is just the authentication tag (16 bytes). + */ + (void)cc; + return rlen >= 16 && rlen <= (16384 + 16); +} + +static unsigned char * +chapol_decrypt(br_sslrec_chapol_context *cc, + int record_type, unsigned version, void *data, size_t *data_len) +{ + unsigned char *buf; + size_t u, len; + unsigned char tag[16]; + unsigned bad; + + buf = data; + len = *data_len - 16; + gen_chapol_process(cc, record_type, version, buf, len, tag, 0); + bad = 0; + for (u = 0; u < 16; u ++) { + bad |= tag[u] ^ buf[len + u]; + } + if (bad) { + return NULL; + } + *data_len = len; + return buf; +} + +/* see bearssl_ssl.h */ +const br_sslrec_in_chapol_class br_sslrec_in_chapol_vtable = { + { + sizeof(br_sslrec_chapol_context), + (int (*)(const br_sslrec_in_class *const *, size_t)) + &chapol_check_length, + (unsigned char *(*)(const br_sslrec_in_class **, + int, unsigned, void *, size_t *)) + &chapol_decrypt + }, + (void (*)(const br_sslrec_in_chapol_class **, + br_chacha20_run, br_poly1305_run, + const void *, const void *)) + &in_chapol_init +}; + +static void +out_chapol_init(br_sslrec_chapol_context *cc, + br_chacha20_run ichacha, br_poly1305_run ipoly, + const void *key, const void *iv) +{ + cc->vtable.out = &br_sslrec_out_chapol_vtable; + gen_chapol_init(cc, ichacha, ipoly, key, iv); +} + +static void +chapol_max_plaintext(const br_sslrec_chapol_context *cc, + size_t *start, size_t *end) +{ + size_t len; + + (void)cc; + len = *end - *start - 16; + if (len > 16384) { + len = 16384; + } + *end = *start + len; +} + +static unsigned char * +chapol_encrypt(br_sslrec_chapol_context *cc, + int record_type, unsigned version, void *data, size_t *data_len) +{ + unsigned char *buf; + size_t len; + + buf = data; + len = *data_len; + gen_chapol_process(cc, record_type, version, buf, len, buf + len, 1); + buf -= 5; + buf[0] = (unsigned char)record_type; + br_enc16be(buf + 1, version); + br_enc16be(buf + 3, len + 16); + *data_len = len + 21; + return buf; +} + +/* see bearssl_ssl.h */ +const br_sslrec_out_chapol_class br_sslrec_out_chapol_vtable = { + { + sizeof(br_sslrec_chapol_context), + (void (*)(const br_sslrec_out_class *const *, + size_t *, size_t *)) + &chapol_max_plaintext, + (unsigned char *(*)(const br_sslrec_out_class **, + int, unsigned, void *, size_t *)) + &chapol_encrypt + }, + (void (*)(const br_sslrec_out_chapol_class **, + br_chacha20_run, br_poly1305_run, + const void *, const void *)) + &out_chapol_init +}; + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_rec_gcm.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_rec_gcm.c new file mode 100644 index 000000000..885e6342a --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_rec_gcm.c @@ -0,0 +1,240 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* + * GCM initialisation. This does everything except setting the vtable, + * which depends on whether this is a context for encrypting or for + * decrypting. + */ +static void +gen_gcm_init(br_sslrec_gcm_context *cc, + const br_block_ctr_class *bc_impl, + const void *key, size_t key_len, + br_ghash gh_impl, + const void *iv) +{ + unsigned char tmp[12]; + + cc->seq = 0; + bc_impl->init(&cc->bc.vtable, key, key_len); + cc->gh = gh_impl; + memcpy(cc->iv, iv, sizeof cc->iv); + memset(cc->h, 0, sizeof cc->h); + memset(tmp, 0, sizeof tmp); + bc_impl->run(&cc->bc.vtable, tmp, 0, cc->h, sizeof cc->h); +} + +static void +in_gcm_init(br_sslrec_gcm_context *cc, + const br_block_ctr_class *bc_impl, + const void *key, size_t key_len, + br_ghash gh_impl, + const void *iv) +{ + cc->vtable.in = &br_sslrec_in_gcm_vtable; + gen_gcm_init(cc, bc_impl, key, key_len, gh_impl, iv); +} + +static int +gcm_check_length(const br_sslrec_gcm_context *cc, size_t rlen) +{ + /* + * GCM adds a fixed overhead: + * 8 bytes for the nonce_explicit (before the ciphertext) + * 16 bytes for the authentication tag (after the ciphertext) + */ + (void)cc; + return rlen >= 24 && rlen <= (16384 + 24); +} + +/* + * Compute the authentication tag. The value written in 'tag' must still + * be CTR-encrypted. + */ +static void +do_tag(br_sslrec_gcm_context *cc, + int record_type, unsigned version, + void *data, size_t len, void *tag) +{ + unsigned char header[13]; + unsigned char footer[16]; + + /* + * Compute authentication tag. Three elements must be injected in + * sequence, each possibly 0-padded to reach a length multiple + * of the block size: the 13-byte header (sequence number, record + * type, protocol version, record length), the cipher text, and + * the word containing the encodings of the bit lengths of the two + * other elements. + */ + br_enc64be(header, cc->seq ++); + header[8] = (unsigned char)record_type; + br_enc16be(header + 9, version); + br_enc16be(header + 11, len); + br_enc64be(footer, (uint64_t)(sizeof header) << 3); + br_enc64be(footer + 8, (uint64_t)len << 3); + memset(tag, 0, 16); + cc->gh(tag, cc->h, header, sizeof header); + cc->gh(tag, cc->h, data, len); + cc->gh(tag, cc->h, footer, sizeof footer); +} + +/* + * Do CTR encryption. This also does CTR encryption of a single block at + * address 'xortag' with the counter value appropriate for the final + * processing of the authentication tag. + */ +static void +do_ctr(br_sslrec_gcm_context *cc, const void *nonce, void *data, size_t len, + void *xortag) +{ + unsigned char iv[12]; + + memcpy(iv, cc->iv, 4); + memcpy(iv + 4, nonce, 8); + cc->bc.vtable->run(&cc->bc.vtable, iv, 2, data, len); + cc->bc.vtable->run(&cc->bc.vtable, iv, 1, xortag, 16); +} + +static unsigned char * +gcm_decrypt(br_sslrec_gcm_context *cc, + int record_type, unsigned version, void *data, size_t *data_len) +{ + unsigned char *buf; + size_t len, u; + uint32_t bad; + unsigned char tag[16]; + + buf = (unsigned char *)data + 8; + len = *data_len - 24; + do_tag(cc, record_type, version, buf, len, tag); + do_ctr(cc, data, buf, len, tag); + + /* + * Compare the computed tag with the value from the record. It + * is possibly useless to do a constant-time comparison here, + * but it does not hurt. + */ + bad = 0; + for (u = 0; u < 16; u ++) { + bad |= tag[u] ^ buf[len + u]; + } + if (bad) { + return NULL; + } + *data_len = len; + return buf; +} + +/* see bearssl_ssl.h */ +const br_sslrec_in_gcm_class br_sslrec_in_gcm_vtable = { + { + sizeof(br_sslrec_gcm_context), + (int (*)(const br_sslrec_in_class *const *, size_t)) + &gcm_check_length, + (unsigned char *(*)(const br_sslrec_in_class **, + int, unsigned, void *, size_t *)) + &gcm_decrypt + }, + (void (*)(const br_sslrec_in_gcm_class **, + const br_block_ctr_class *, const void *, size_t, + br_ghash, const void *)) + &in_gcm_init +}; + +static void +out_gcm_init(br_sslrec_gcm_context *cc, + const br_block_ctr_class *bc_impl, + const void *key, size_t key_len, + br_ghash gh_impl, + const void *iv) +{ + cc->vtable.out = &br_sslrec_out_gcm_vtable; + gen_gcm_init(cc, bc_impl, key, key_len, gh_impl, iv); +} + +static void +gcm_max_plaintext(const br_sslrec_gcm_context *cc, + size_t *start, size_t *end) +{ + size_t len; + + (void)cc; + *start += 8; + len = *end - *start - 16; + if (len > 16384) { + len = 16384; + } + *end = *start + len; +} + +static unsigned char * +gcm_encrypt(br_sslrec_gcm_context *cc, + int record_type, unsigned version, void *data, size_t *data_len) +{ + unsigned char *buf; + size_t u, len; + unsigned char tmp[16]; + + buf = (unsigned char *)data; + len = *data_len; + memset(tmp, 0, sizeof tmp); + br_enc64be(buf - 8, cc->seq); + do_ctr(cc, buf - 8, buf, len, tmp); + do_tag(cc, record_type, version, buf, len, buf + len); + for (u = 0; u < 16; u ++) { + buf[len + u] ^= tmp[u]; + } + len += 24; + buf -= 13; + buf[0] = (unsigned char)record_type; + br_enc16be(buf + 1, version); + br_enc16be(buf + 3, len); + *data_len = len + 5; + return buf; +} + +/* see bearssl_ssl.h */ +const br_sslrec_out_gcm_class br_sslrec_out_gcm_vtable = { + { + sizeof(br_sslrec_gcm_context), + (void (*)(const br_sslrec_out_class *const *, + size_t *, size_t *)) + &gcm_max_plaintext, + (unsigned char *(*)(const br_sslrec_out_class **, + int, unsigned, void *, size_t *)) + &gcm_encrypt + }, + (void (*)(const br_sslrec_out_gcm_class **, + const br_block_ctr_class *, const void *, size_t, + br_ghash, const void *)) + &out_gcm_init +}; + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_scert_single_ec.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_scert_single_ec.c new file mode 100644 index 000000000..0c8702cdb --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_scert_single_ec.c @@ -0,0 +1,147 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +static int +se_choose(const br_ssl_server_policy_class **pctx, + const br_ssl_server_context *cc, + br_ssl_server_choices *choices) +{ + br_ssl_server_policy_ec_context *pc; + const br_suite_translated *st; + size_t u, st_num; + unsigned hash_id; + + pc = (br_ssl_server_policy_ec_context *)pctx; + st = br_ssl_server_get_client_suites(cc, &st_num); + hash_id = br_ssl_choose_hash(br_ssl_server_get_client_hashes(cc) >> 8); + if (cc->eng.session.version < BR_TLS12) { + hash_id = br_sha1_ID; + } + choices->chain = pc->chain; + choices->chain_len = pc->chain_len; + for (u = 0; u < st_num; u ++) { + unsigned tt; + + tt = st[u][1]; + switch (tt >> 12) { + case BR_SSLKEYX_ECDH_RSA: + if ((pc->allowed_usages & BR_KEYTYPE_KEYX) != 0 + && pc->cert_issuer_key_type == BR_KEYTYPE_RSA) + { + choices->cipher_suite = st[u][0]; + return 1; + } + break; + case BR_SSLKEYX_ECDH_ECDSA: + if ((pc->allowed_usages & BR_KEYTYPE_KEYX) != 0 + && pc->cert_issuer_key_type == BR_KEYTYPE_EC) + { + choices->cipher_suite = st[u][0]; + return 1; + } + break; + case BR_SSLKEYX_ECDHE_ECDSA: + if ((pc->allowed_usages & BR_KEYTYPE_SIGN) != 0 + && hash_id != 0) + { + choices->cipher_suite = st[u][0]; + choices->algo_id = hash_id + 0xFF00; + return 1; + } + break; + } + } + return 0; +} + +static uint32_t +se_do_keyx(const br_ssl_server_policy_class **pctx, + unsigned char *data, size_t *len) +{ + br_ssl_server_policy_ec_context *pc; + uint32_t r; + size_t xoff, xlen; + + pc = (br_ssl_server_policy_ec_context *)pctx; + r = pc->iec->mul(data, *len, pc->sk->x, pc->sk->xlen, pc->sk->curve); + xoff = pc->iec->xoff(pc->sk->curve, &xlen); + memmove(data, data + xoff, xlen); + *len = xlen; + return r; +} + +static size_t +se_do_sign(const br_ssl_server_policy_class **pctx, + unsigned algo_id, unsigned char *data, size_t hv_len, size_t len) +{ + br_ssl_server_policy_ec_context *pc; + unsigned char hv[64]; + const br_hash_class *hc; + + algo_id &= 0xFF; + pc = (br_ssl_server_policy_ec_context *)pctx; + hc = br_multihash_getimpl(pc->mhash, algo_id); + if (hc == NULL) { + return 0; + } + memcpy(hv, data, hv_len); + if (len < 139) { + return 0; + } + return pc->iecdsa(pc->iec, hc, hv, pc->sk, data); +} + +static const br_ssl_server_policy_class se_policy_vtable = { + sizeof(br_ssl_server_policy_ec_context), + se_choose, + se_do_keyx, + se_do_sign +}; + +/* see bearssl_ssl.h */ +void +br_ssl_server_set_single_ec(br_ssl_server_context *cc, + const br_x509_certificate *chain, size_t chain_len, + const br_ec_private_key *sk, unsigned allowed_usages, + unsigned cert_issuer_key_type, + const br_ec_impl *iec, br_ecdsa_sign iecdsa) +{ + cc->chain_handler.single_ec.vtable = &se_policy_vtable; + cc->chain_handler.single_ec.chain = chain; + cc->chain_handler.single_ec.chain_len = chain_len; + cc->chain_handler.single_ec.sk = sk; + cc->chain_handler.single_ec.allowed_usages = allowed_usages; + cc->chain_handler.single_ec.cert_issuer_key_type = cert_issuer_key_type; + cc->chain_handler.single_ec.mhash = &cc->eng.mhash; + cc->chain_handler.single_ec.iec = iec; + cc->chain_handler.single_ec.iecdsa = iecdsa; + cc->policy_vtable = &cc->chain_handler.single_ec.vtable; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_scert_single_rsa.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_scert_single_rsa.c new file mode 100644 index 000000000..600695bb7 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_scert_single_rsa.c @@ -0,0 +1,167 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +static int +sr_choose(const br_ssl_server_policy_class **pctx, + const br_ssl_server_context *cc, + br_ssl_server_choices *choices) +{ + br_ssl_server_policy_rsa_context *pc; + const br_suite_translated *st; + size_t u, st_num; + unsigned hash_id; + int fh; + + pc = (br_ssl_server_policy_rsa_context *)pctx; + st = br_ssl_server_get_client_suites(cc, &st_num); + if (cc->eng.session.version < BR_TLS12) { + hash_id = 0; + fh = 1; + } else { + hash_id = br_ssl_choose_hash( + br_ssl_server_get_client_hashes(cc)); + fh = (hash_id != 0); + } + choices->chain = pc->chain; + choices->chain_len = pc->chain_len; + for (u = 0; u < st_num; u ++) { + unsigned tt; + + tt = st[u][1]; + switch (tt >> 12) { + case BR_SSLKEYX_RSA: + if ((pc->allowed_usages & BR_KEYTYPE_KEYX) != 0) { + choices->cipher_suite = st[u][0]; + return 1; + } + break; + case BR_SSLKEYX_ECDHE_RSA: + if ((pc->allowed_usages & BR_KEYTYPE_SIGN) != 0 && fh) { + choices->cipher_suite = st[u][0]; + choices->algo_id = hash_id + 0xFF00; + return 1; + } + break; + } + } + return 0; +} + +static uint32_t +sr_do_keyx(const br_ssl_server_policy_class **pctx, + unsigned char *data, size_t *len) +{ + br_ssl_server_policy_rsa_context *pc; + + pc = (br_ssl_server_policy_rsa_context *)pctx; + return br_rsa_ssl_decrypt(pc->irsacore, pc->sk, data, *len); +} + +/* + * OID for hash functions in RSA signatures. + */ +static const unsigned char HASH_OID_SHA1[] = { + 0x05, 0x2B, 0x0E, 0x03, 0x02, 0x1A +}; + +static const unsigned char HASH_OID_SHA224[] = { + 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x04 +}; + +static const unsigned char HASH_OID_SHA256[] = { + 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01 +}; + +static const unsigned char HASH_OID_SHA384[] = { + 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02 +}; + +static const unsigned char HASH_OID_SHA512[] = { + 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03 +}; + +static const unsigned char *HASH_OID[] = { + HASH_OID_SHA1, + HASH_OID_SHA224, + HASH_OID_SHA256, + HASH_OID_SHA384, + HASH_OID_SHA512 +}; + +static size_t +sr_do_sign(const br_ssl_server_policy_class **pctx, + unsigned algo_id, unsigned char *data, size_t hv_len, size_t len) +{ + br_ssl_server_policy_rsa_context *pc; + unsigned char hv[64]; + size_t sig_len; + const unsigned char *hash_oid; + + pc = (br_ssl_server_policy_rsa_context *)pctx; + memcpy(hv, data, hv_len); + algo_id &= 0xFF; + if (algo_id == 0) { + hash_oid = NULL; + } else if (algo_id >= 2 && algo_id <= 6) { + hash_oid = HASH_OID[algo_id - 2]; + } else { + return 0; + } + sig_len = (pc->sk->n_bitlen + 7) >> 3; + if (len < sig_len) { + return 0; + } + return pc->irsasign(hash_oid, hv, hv_len, pc->sk, data) ? sig_len : 0; +} + +static const br_ssl_server_policy_class sr_policy_vtable = { + sizeof(br_ssl_server_policy_rsa_context), + sr_choose, + sr_do_keyx, + sr_do_sign +}; + +/* see bearssl_ssl.h */ +void +br_ssl_server_set_single_rsa(br_ssl_server_context *cc, + const br_x509_certificate *chain, size_t chain_len, + const br_rsa_private_key *sk, unsigned allowed_usages, + br_rsa_private irsacore, br_rsa_pkcs1_sign irsasign) +{ + cc->chain_handler.single_rsa.vtable = &sr_policy_vtable; + cc->chain_handler.single_rsa.chain = chain; + cc->chain_handler.single_rsa.chain_len = chain_len; + cc->chain_handler.single_rsa.sk = sk; + cc->chain_handler.single_rsa.allowed_usages = allowed_usages; + cc->chain_handler.single_rsa.irsacore = irsacore; + cc->chain_handler.single_rsa.irsasign = irsasign; + cc->policy_vtable = &cc->chain_handler.single_rsa.vtable; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_server.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_server.c new file mode 100644 index 000000000..636734af5 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_server.c @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_ssl.h */ +void +br_ssl_server_zero(br_ssl_server_context *cc) +{ + /* + * For really standard C, we should explicitly set to NULL all + * pointers, and 0 all other fields. However, on all our target + * architectures, a direct memset() will work, be faster, and + * use a lot less code. + */ + memset(cc, 0, sizeof *cc); +} + +/* see bearssl_ssl.h */ +int +br_ssl_server_reset(br_ssl_server_context *cc) +{ + br_ssl_engine_set_buffer(&cc->eng, NULL, 0, 0); + if (!br_ssl_engine_init_rand(&cc->eng)) { + return 0; + } + cc->eng.reneg = 0; + br_ssl_engine_hs_reset(&cc->eng, + br_ssl_hs_server_init_main, br_ssl_hs_server_run); + return br_ssl_engine_last_error(&cc->eng) == BR_ERR_OK; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_server_full_ec.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_server_full_ec.c new file mode 100644 index 000000000..352951cc4 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_server_full_ec.c @@ -0,0 +1,154 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_ssl.h */ +void +br_ssl_server_init_full_ec(br_ssl_server_context *cc, + const br_x509_certificate *chain, size_t chain_len, + unsigned cert_issuer_key_type, const br_ec_private_key *sk) +{ + /* + * The "full" profile supports all implemented cipher suites. + * + * Rationale for suite order, from most important to least + * important rule: + * + * -- Don't use 3DES if AES is available. + * -- Try to have Forward Secrecy (ECDHE suite) if possible. + * -- ChaCha20+Poly1305 is better than AES/GCM (faster, smaller). + * -- GCM is better than CCM and CBC. CCM is better than CBC. + * -- CCM is better than CCM_8. + * -- AES-128 is preferred over AES-256 (AES-128 is already + * strong enough, and AES-256 is 40% more expensive). + * + * Note that for ECDH suites, the list will be automatically + * filtered based on the issuing CA key type. + */ + static const uint16_t suites[] = { + BR_TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256, + BR_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, + BR_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, + BR_TLS_ECDHE_ECDSA_WITH_AES_128_CCM, + BR_TLS_ECDHE_ECDSA_WITH_AES_256_CCM, + BR_TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8, + BR_TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8, + BR_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, + BR_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384, + BR_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, + BR_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, + BR_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256, + BR_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256, + BR_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384, + BR_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384, + BR_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256, + BR_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256, + BR_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384, + BR_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384, + BR_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA, + BR_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA, + BR_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA, + BR_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA, + BR_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA, + BR_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA, + BR_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA + }; + + /* + * All hash functions are activated. + * Note: the X.509 validation engine will nonetheless refuse to + * validate signatures that use MD5 as hash function. + */ + static const br_hash_class *hashes[] = { + &br_md5_vtable, + &br_sha1_vtable, + &br_sha224_vtable, + &br_sha256_vtable, + &br_sha384_vtable, + &br_sha512_vtable + }; + + int id; + + /* + * Reset server context and set supported versions from TLS-1.0 + * to TLS-1.2 (inclusive). + */ + br_ssl_server_zero(cc); + br_ssl_engine_set_versions(&cc->eng, BR_TLS10, BR_TLS12); + + /* + * Set suites and elliptic curve implementation (for ECDHE). + */ + br_ssl_engine_set_suites(&cc->eng, suites, + (sizeof suites) / (sizeof suites[0])); + br_ssl_engine_set_default_ec(&cc->eng); + + /* + * Set the "server policy": handler for the certificate chain + * and private key operations. + */ + br_ssl_server_set_single_ec(cc, chain, chain_len, sk, + BR_KEYTYPE_KEYX | BR_KEYTYPE_SIGN, + cert_issuer_key_type, + br_ssl_engine_get_ec(&cc->eng), +#if BR_LOMUL + br_ecdsa_i15_sign_asn1 +#else + br_ecdsa_i31_sign_asn1 +#endif + ); + + /* + * Set supported hash functions. + */ + for (id = br_md5_ID; id <= br_sha512_ID; id ++) { + const br_hash_class *hc; + + hc = hashes[id - 1]; + br_ssl_engine_set_hash(&cc->eng, id, hc); + } + + /* + * Set the PRF implementations. + */ + br_ssl_engine_set_prf10(&cc->eng, &br_tls10_prf); + br_ssl_engine_set_prf_sha256(&cc->eng, &br_tls12_sha256_prf); + br_ssl_engine_set_prf_sha384(&cc->eng, &br_tls12_sha384_prf); + + /* + * Symmetric encryption. + */ + br_ssl_engine_set_default_aes_cbc(&cc->eng); + br_ssl_engine_set_default_aes_ccm(&cc->eng); + br_ssl_engine_set_default_aes_gcm(&cc->eng); + br_ssl_engine_set_default_des_cbc(&cc->eng); + br_ssl_engine_set_default_chapol(&cc->eng); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_server_full_rsa.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_server_full_rsa.c new file mode 100644 index 000000000..2acc66bd7 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_server_full_rsa.c @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_ssl.h */ +void +br_ssl_server_init_full_rsa(br_ssl_server_context *cc, + const br_x509_certificate *chain, size_t chain_len, + const br_rsa_private_key *sk) +{ + /* + * The "full" profile supports all implemented cipher suites. + * + * Rationale for suite order, from most important to least + * important rule: + * + * -- Don't use 3DES if AES is available. + * -- Try to have Forward Secrecy (ECDHE suite) if possible. + * -- ChaCha20+Poly1305 is better than AES/GCM (faster, smaller). + * -- GCM is better than CBC. + * -- AES-128 is preferred over AES-256 (AES-128 is already + * strong enough, and AES-256 is 40% more expensive). + */ + static const uint16_t suites[] = { + BR_TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256, + BR_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, + BR_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, + BR_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, + BR_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384, + BR_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, + BR_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, + BR_TLS_RSA_WITH_AES_128_GCM_SHA256, + BR_TLS_RSA_WITH_AES_256_GCM_SHA384, + BR_TLS_RSA_WITH_AES_128_CCM, + BR_TLS_RSA_WITH_AES_256_CCM, + BR_TLS_RSA_WITH_AES_128_CCM_8, + BR_TLS_RSA_WITH_AES_256_CCM_8, + BR_TLS_RSA_WITH_AES_128_CBC_SHA256, + BR_TLS_RSA_WITH_AES_256_CBC_SHA256, + BR_TLS_RSA_WITH_AES_128_CBC_SHA, + BR_TLS_RSA_WITH_AES_256_CBC_SHA, + BR_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, + BR_TLS_RSA_WITH_3DES_EDE_CBC_SHA + }; + + /* + * All hash functions are activated. + * Note: the X.509 validation engine will nonetheless refuse to + * validate signatures that use MD5 as hash function. + */ + static const br_hash_class *hashes[] = { + &br_md5_vtable, + &br_sha1_vtable, + &br_sha224_vtable, + &br_sha256_vtable, + &br_sha384_vtable, + &br_sha512_vtable + }; + + int id; + + /* + * Reset server context and set supported versions from TLS-1.0 + * to TLS-1.2 (inclusive). + */ + br_ssl_server_zero(cc); + br_ssl_engine_set_versions(&cc->eng, BR_TLS10, BR_TLS12); + + /* + * Set suites and elliptic curve implementation (for ECDHE). + */ + br_ssl_engine_set_suites(&cc->eng, suites, + (sizeof suites) / (sizeof suites[0])); + br_ssl_engine_set_default_ec(&cc->eng); + + /* + * Set the "server policy": handler for the certificate chain + * and private key operations. + */ + br_ssl_server_set_single_rsa(cc, chain, chain_len, sk, + BR_KEYTYPE_KEYX | BR_KEYTYPE_SIGN, + br_rsa_private_get_default(), + br_rsa_pkcs1_sign_get_default()); + + /* + * Set supported hash functions. + */ + for (id = br_md5_ID; id <= br_sha512_ID; id ++) { + const br_hash_class *hc; + + hc = hashes[id - 1]; + br_ssl_engine_set_hash(&cc->eng, id, hc); + } + + /* + * Set the PRF implementations. + */ + br_ssl_engine_set_prf10(&cc->eng, &br_tls10_prf); + br_ssl_engine_set_prf_sha256(&cc->eng, &br_tls12_sha256_prf); + br_ssl_engine_set_prf_sha384(&cc->eng, &br_tls12_sha384_prf); + + /* + * Symmetric encryption. + */ + br_ssl_engine_set_default_aes_cbc(&cc->eng); + br_ssl_engine_set_default_aes_ccm(&cc->eng); + br_ssl_engine_set_default_aes_gcm(&cc->eng); + br_ssl_engine_set_default_des_cbc(&cc->eng); + br_ssl_engine_set_default_chapol(&cc->eng); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_server_mine2c.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_server_mine2c.c new file mode 100644 index 000000000..8b3aa08d2 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_server_mine2c.c @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_ssl.h */ +void +br_ssl_server_init_mine2c(br_ssl_server_context *cc, + const br_x509_certificate *chain, size_t chain_len, + const br_rsa_private_key *sk) +{ + static const uint16_t suites[] = { + BR_TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 + }; + + /* + * Reset server context and set supported versions to TLS-1.2 (only). + */ + br_ssl_server_zero(cc); + br_ssl_engine_set_versions(&cc->eng, BR_TLS12, BR_TLS12); + + /* + * Set suites and elliptic curve implementation (for ECDHE). + */ + br_ssl_engine_set_suites(&cc->eng, suites, + (sizeof suites) / (sizeof suites[0])); + br_ssl_engine_set_ec(&cc->eng, &br_ec_all_m15); + + /* + * Set the "server policy": handler for the certificate chain + * and private key operations. + */ + br_ssl_server_set_single_rsa(cc, chain, chain_len, sk, + BR_KEYTYPE_SIGN, 0, br_rsa_i31_pkcs1_sign); + + /* + * Set supported hash functions. + */ + br_ssl_engine_set_hash(&cc->eng, br_sha256_ID, &br_sha256_vtable); + + /* + * Set the PRF implementations. + */ + br_ssl_engine_set_prf_sha256(&cc->eng, &br_tls12_sha256_prf); + + /* + * Symmetric encryption. + */ + br_ssl_engine_set_default_chapol(&cc->eng); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_server_mine2g.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_server_mine2g.c new file mode 100644 index 000000000..07e6e95f5 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_server_mine2g.c @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_ssl.h */ +void +br_ssl_server_init_mine2g(br_ssl_server_context *cc, + const br_x509_certificate *chain, size_t chain_len, + const br_rsa_private_key *sk) +{ + static const uint16_t suites[] = { + BR_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 + }; + + /* + * Reset server context and set supported versions to TLS-1.2 (only). + */ + br_ssl_server_zero(cc); + br_ssl_engine_set_versions(&cc->eng, BR_TLS12, BR_TLS12); + + /* + * Set suites and elliptic curve implementation (for ECDHE). + */ + br_ssl_engine_set_suites(&cc->eng, suites, + (sizeof suites) / (sizeof suites[0])); + br_ssl_engine_set_ec(&cc->eng, &br_ec_all_m15); + + /* + * Set the "server policy": handler for the certificate chain + * and private key operations. + */ + br_ssl_server_set_single_rsa(cc, chain, chain_len, sk, + BR_KEYTYPE_SIGN, 0, br_rsa_i31_pkcs1_sign); + + /* + * Set supported hash functions. + */ + br_ssl_engine_set_hash(&cc->eng, br_sha256_ID, &br_sha256_vtable); + + /* + * Set the PRF implementations. + */ + br_ssl_engine_set_prf_sha256(&cc->eng, &br_tls12_sha256_prf); + + /* + * Symmetric encryption. + */ + br_ssl_engine_set_default_aes_gcm(&cc->eng); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_server_minf2c.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_server_minf2c.c new file mode 100644 index 000000000..e58c8c079 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_server_minf2c.c @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_ssl.h */ +void +br_ssl_server_init_minf2c(br_ssl_server_context *cc, + const br_x509_certificate *chain, size_t chain_len, + const br_ec_private_key *sk) +{ + static const uint16_t suites[] = { + BR_TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 + }; + + /* + * Reset server context and set supported versions to TLS-1.2 (only). + */ + br_ssl_server_zero(cc); + br_ssl_engine_set_versions(&cc->eng, BR_TLS12, BR_TLS12); + + /* + * Set suites and elliptic curve implementation (for ECDHE). + */ + br_ssl_engine_set_suites(&cc->eng, suites, + (sizeof suites) / (sizeof suites[0])); + br_ssl_engine_set_ec(&cc->eng, &br_ec_all_m15); + + /* + * Set the "server policy": handler for the certificate chain + * and private key operations. + */ + br_ssl_server_set_single_ec(cc, chain, chain_len, sk, + BR_KEYTYPE_SIGN, 0, &br_ec_all_m15, br_ecdsa_i31_sign_asn1); + + /* + * Set supported hash functions. + */ + br_ssl_engine_set_hash(&cc->eng, br_sha256_ID, &br_sha256_vtable); + + /* + * Set the PRF implementations. + */ + br_ssl_engine_set_prf_sha256(&cc->eng, &br_tls12_sha256_prf); + + /* + * Symmetric encryption. + */ + br_ssl_engine_set_default_chapol(&cc->eng); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_server_minf2g.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_server_minf2g.c new file mode 100644 index 000000000..0f6eead27 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_server_minf2g.c @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_ssl.h */ +void +br_ssl_server_init_minf2g(br_ssl_server_context *cc, + const br_x509_certificate *chain, size_t chain_len, + const br_ec_private_key *sk) +{ + static const uint16_t suites[] = { + BR_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 + }; + + /* + * Reset server context and set supported versions to TLS-1.2 (only). + */ + br_ssl_server_zero(cc); + br_ssl_engine_set_versions(&cc->eng, BR_TLS12, BR_TLS12); + + /* + * Set suites and elliptic curve implementation (for ECDHE). + */ + br_ssl_engine_set_suites(&cc->eng, suites, + (sizeof suites) / (sizeof suites[0])); + br_ssl_engine_set_ec(&cc->eng, &br_ec_all_m15); + + /* + * Set the "server policy": handler for the certificate chain + * and private key operations. + */ + br_ssl_server_set_single_ec(cc, chain, chain_len, sk, + BR_KEYTYPE_SIGN, 0, &br_ec_all_m15, br_ecdsa_i31_sign_asn1); + + /* + * Set supported hash functions. + */ + br_ssl_engine_set_hash(&cc->eng, br_sha256_ID, &br_sha256_vtable); + + /* + * Set the PRF implementations. + */ + br_ssl_engine_set_prf_sha256(&cc->eng, &br_tls12_sha256_prf); + + /* + * Symmetric encryption. + */ + br_ssl_engine_set_default_aes_gcm(&cc->eng); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_server_minr2g.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_server_minr2g.c new file mode 100644 index 000000000..64e4b041c --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_server_minr2g.c @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_ssl.h */ +void +br_ssl_server_init_minr2g(br_ssl_server_context *cc, + const br_x509_certificate *chain, size_t chain_len, + const br_rsa_private_key *sk) +{ + static const uint16_t suites[] = { + BR_TLS_RSA_WITH_AES_128_GCM_SHA256 + }; + + /* + * Reset server context and set supported versions to TLS-1.2 (only). + */ + br_ssl_server_zero(cc); + br_ssl_engine_set_versions(&cc->eng, BR_TLS12, BR_TLS12); + + /* + * Set suites. + */ + br_ssl_engine_set_suites(&cc->eng, suites, + (sizeof suites) / (sizeof suites[0])); + + /* + * Set the "server policy": handler for the certificate chain + * and private key operations. + */ + br_ssl_server_set_single_rsa(cc, chain, chain_len, sk, + BR_KEYTYPE_KEYX, br_rsa_i31_private, 0); + + /* + * Set supported hash functions. + */ + br_ssl_engine_set_hash(&cc->eng, br_sha256_ID, &br_sha256_vtable); + + /* + * Set the PRF implementations. + */ + br_ssl_engine_set_prf_sha256(&cc->eng, &br_tls12_sha256_prf); + + /* + * Symmetric encryption. + */ + br_ssl_engine_set_default_aes_gcm(&cc->eng); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_server_minu2g.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_server_minu2g.c new file mode 100644 index 000000000..ca38c7cc4 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_server_minu2g.c @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_ssl.h */ +void +br_ssl_server_init_minu2g(br_ssl_server_context *cc, + const br_x509_certificate *chain, size_t chain_len, + const br_ec_private_key *sk) +{ + static const uint16_t suites[] = { + BR_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256 + }; + + /* + * Reset server context and set supported versions to TLS-1.2 (only). + */ + br_ssl_server_zero(cc); + br_ssl_engine_set_versions(&cc->eng, BR_TLS12, BR_TLS12); + + /* + * Set suites. + */ + br_ssl_engine_set_suites(&cc->eng, suites, + (sizeof suites) / (sizeof suites[0])); + + /* + * Set the "server policy": handler for the certificate chain + * and private key operations. + */ + br_ssl_server_set_single_ec(cc, chain, chain_len, sk, + BR_KEYTYPE_KEYX, BR_KEYTYPE_RSA, &br_ec_all_m15, 0); + + /* + * Set supported hash functions. + */ + br_ssl_engine_set_hash(&cc->eng, br_sha256_ID, &br_sha256_vtable); + + /* + * Set the PRF implementations. + */ + br_ssl_engine_set_prf_sha256(&cc->eng, &br_tls12_sha256_prf); + + /* + * Symmetric encryption. + */ + br_ssl_engine_set_default_aes_gcm(&cc->eng); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_server_minv2g.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_server_minv2g.c new file mode 100644 index 000000000..ad5687b3e --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/ssl_server_minv2g.c @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_ssl.h */ +void +br_ssl_server_init_minv2g(br_ssl_server_context *cc, + const br_x509_certificate *chain, size_t chain_len, + const br_ec_private_key *sk) +{ + static const uint16_t suites[] = { + BR_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 + }; + + /* + * Reset server context and set supported versions to TLS-1.2 (only). + */ + br_ssl_server_zero(cc); + br_ssl_engine_set_versions(&cc->eng, BR_TLS12, BR_TLS12); + + /* + * Set suites. + */ + br_ssl_engine_set_suites(&cc->eng, suites, + (sizeof suites) / (sizeof suites[0])); + + /* + * Set the "server policy": handler for the certificate chain + * and private key operations. + */ + br_ssl_server_set_single_ec(cc, chain, chain_len, sk, + BR_KEYTYPE_KEYX, BR_KEYTYPE_EC, &br_ec_all_m15, 0); + + /* + * Set supported hash functions. + */ + br_ssl_engine_set_hash(&cc->eng, br_sha256_ID, &br_sha256_vtable); + + /* + * Set the PRF implementations. + */ + br_ssl_engine_set_prf_sha256(&cc->eng, &br_tls12_sha256_prf); + + /* + * Symmetric encryption. + */ + br_ssl_engine_set_default_aes_gcm(&cc->eng); +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/sysrng.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/sysrng.c new file mode 100644 index 000000000..9533079e0 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/sysrng.c @@ -0,0 +1,257 @@ +/* + * Copyright (c) 2017 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#define BR_ENABLE_INTRINSICS 1 +#include "inner.h" + +#if BR_USE_GETENTROPY +#include +#endif + +#if BR_USE_URANDOM +#include +#include +#include +#include +#endif + +#if BR_USE_WIN32_RAND +#include +#include +#pragma comment(lib, "advapi32") +#endif + +/* + * Seeder that uses the RDRAND opcodes (on x86 CPU). + */ +#if BR_RDRAND +BR_TARGETS_X86_UP +BR_TARGET("rdrnd") +static int +seeder_rdrand(const br_prng_class **ctx) +{ + unsigned char tmp[32]; + size_t u; + + for (u = 0; u < sizeof tmp; u += sizeof(uint32_t)) { + int j; + uint32_t x; + + /* + * We use the 32-bit intrinsic so that code is compatible + * with both 32-bit and 64-bit architectures. + * + * Intel recommends trying at least 10 times in case of + * failure. + * + * AMD bug: there are reports that some AMD processors + * have a bug that makes them fail silently after a + * suspend/resume cycle, in which case RDRAND will report + * a success but always return 0xFFFFFFFF. + * see: https://bugzilla.kernel.org/show_bug.cgi?id=85911 + * + * As a mitigation, if the 32-bit value is 0 or -1, then + * it is considered a failure and tried again. This should + * reliably detect the buggy case, at least. This also + * implies that the selected seed values can never be + * 0x00000000 or 0xFFFFFFFF, which is not a problem since + * we are generating a seed for a PRNG, and we overdo it + * a bit (we generate 32 bytes of randomness, and 256 bits + * of entropy are really overkill). + */ + for (j = 0; j < 10; j ++) { + if (_rdrand32_step(&x) && x != 0 && x != (uint32_t)-1) { + goto next_word; + } + } + return 0; + next_word: + br_enc32le(tmp + u, x); + } + (*ctx)->update(ctx, tmp, sizeof tmp); + return 1; +} +BR_TARGETS_X86_DOWN + +static int +rdrand_supported(void) +{ + /* + * The RDRND support is bit 30 of ECX, as returned by CPUID. + */ + return br_cpuid(0, 0, 0x40000000, 0); +} +#endif + +/* + * Seeder that uses /dev/urandom (on Unix-like systems). + */ +#if BR_USE_URANDOM +static int +seeder_urandom(const br_prng_class **ctx) +{ + int f; + + f = open("/dev/urandom", O_RDONLY); + if (f >= 0) { + unsigned char tmp[32]; + size_t u; + + for (u = 0; u < sizeof tmp;) { + ssize_t len; + + len = read(f, tmp + u, (sizeof tmp) - u); + if (len < 0) { + if (errno == EINTR) { + continue; + } + break; + } + u += (size_t)len; + } + close(f); + if (u == sizeof tmp) { + (*ctx)->update(ctx, tmp, sizeof tmp); + return 1; + } + } + return 0; +} +#endif + +/* + * Seeder that uses getentropy() (backed by getrandom() on some systems, + * e.g. Linux). On failure, it will use the /dev/urandom seeder (if + * enabled). + */ +#if BR_USE_GETENTROPY +static int +seeder_getentropy(const br_prng_class **ctx) +{ + unsigned char tmp[32]; + + if (getentropy(tmp, sizeof tmp) == 0) { + (*ctx)->update(ctx, tmp, sizeof tmp); + return 1; + } +#if BR_USE_URANDOM + return seeder_urandom(ctx); +#else + return 0; +#endif +} +#endif + +/* + * Seeder that uses CryptGenRandom() (on Windows). + */ +#if BR_USE_WIN32_RAND +static int +seeder_win32(const br_prng_class **ctx) +{ + HCRYPTPROV hp; + + if (CryptAcquireContext(&hp, 0, 0, PROV_RSA_FULL, + CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) + { + BYTE buf[32]; + BOOL r; + + r = CryptGenRandom(hp, sizeof buf, buf); + CryptReleaseContext(hp, 0); + if (r) { + (*ctx)->update(ctx, buf, sizeof buf); + return 1; + } + } + return 0; +} +#endif + +/* + * An aggregate seeder that uses RDRAND, and falls back to an OS-provided + * source if RDRAND fails. + */ +#if BR_RDRAND && (BR_USE_GETENTROPY || BR_USE_URANDOM || BR_USE_WIN32_RAND) +static int +seeder_rdrand_with_fallback(const br_prng_class **ctx) +{ + if (!seeder_rdrand(ctx)) { +#if BR_USE_GETENTROPY + return seeder_getentropy(ctx); +#elif BR_USE_URANDOM + return seeder_urandom(ctx); +#elif BR_USE_WIN32_RAND + return seeder_win32(ctx); +#else +#error "macro selection has gone wrong" +#endif + } + return 1; +} +#endif + +/* see bearssl_rand.h */ +br_prng_seeder +br_prng_seeder_system(const char **name) +{ +#if BR_RDRAND + if (rdrand_supported()) { + if (name != NULL) { + *name = "rdrand"; + } +#if BR_USE_GETENTROPY || BR_USE_URANDOM || BR_USE_WIN32_RAND + return &seeder_rdrand_with_fallback; +#else + return &seeder_rdrand; +#endif + } +#endif +#if BR_USE_GETENTROPY + if (name != NULL) { + *name = "getentropy"; + } + return &seeder_getentropy; +#elif BR_USE_URANDOM + if (name != NULL) { + *name = "urandom"; + } + return &seeder_urandom; +#elif BR_USE_WIN32_RAND + if (name != NULL) { + *name = "win32"; + } + return &seeder_win32; +#else + if (name != NULL) { + *name = "none"; + } + return 0; +#endif +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/x509_decoder.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/x509_decoder.c new file mode 100644 index 000000000..37cfcfcf0 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/x509_decoder.c @@ -0,0 +1,779 @@ +/* Automatically generated code; do not modify directly. */ + + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include +#include + +typedef struct { + uint32_t *dp; + uint32_t *rp; + const unsigned char *ip; +} t0_context; + +static uint32_t +t0_parse7E_unsigned(const unsigned char **p) +{ + uint32_t x; + + x = 0; + for (;;) { + unsigned y; + + y = *(*p) ++; + x = (x << 7) | (uint32_t)(y & 0x7F); + if (y < 0x80) { + return x; + } + } +} + +static int32_t +t0_parse7E_signed(const unsigned char **p) +{ + int neg; + uint32_t x; + + neg = ((**p) >> 6) & 1; + x = (uint32_t)-neg; + for (;;) { + unsigned y; + + y = *(*p) ++; + x = (x << 7) | (uint32_t)(y & 0x7F); + if (y < 0x80) { + if (neg) { + return -(int32_t)~x - 1; + } else { + return (int32_t)x; + } + } + } +} + +#define T0_VBYTE(x, n) (unsigned char)((((uint32_t)(x) >> (n)) & 0x7F) | 0x80) +#define T0_FBYTE(x, n) (unsigned char)(((uint32_t)(x) >> (n)) & 0x7F) +#define T0_SBYTE(x) (unsigned char)((((uint32_t)(x) >> 28) + 0xF8) ^ 0xF8) +#define T0_INT1(x) T0_FBYTE(x, 0) +#define T0_INT2(x) T0_VBYTE(x, 7), T0_FBYTE(x, 0) +#define T0_INT3(x) T0_VBYTE(x, 14), T0_VBYTE(x, 7), T0_FBYTE(x, 0) +#define T0_INT4(x) T0_VBYTE(x, 21), T0_VBYTE(x, 14), T0_VBYTE(x, 7), T0_FBYTE(x, 0) +#define T0_INT5(x) T0_SBYTE(x), T0_VBYTE(x, 21), T0_VBYTE(x, 14), T0_VBYTE(x, 7), T0_FBYTE(x, 0) + +/* static const unsigned char t0_datablock[]; */ + + +void br_x509_decoder_init_main_libmail(void *t0ctx); + +void br_x509_decoder_run_libmail(void *t0ctx); + + + +#include "inner.h" + + + + + +#include "inner.h" + +#define CTX ((br_x509_decoder_context_libmail *)(void *)((unsigned char *)t0ctx - offsetof(br_x509_decoder_context_libmail, cpu))) +#define CONTEXT_NAME br_x509_decoder_context_libmail + +/* see bearssl_x509.h */ +void +br_x509_decoder_init(br_x509_decoder_context_libmail *ctx, + void (*append_dn)(void *ctx, const void *buf, size_t len), + void *append_dn_ctx) +{ + memset(ctx, 0, sizeof *ctx); + /* obsolete + ctx->err = 0; + ctx->hbuf = NULL; + ctx->hlen = 0; + */ + ctx->append_dn = append_dn; + ctx->append_dn_ctx = append_dn_ctx; + ctx->cpu.dp = &ctx->dp_stack[0]; + ctx->cpu.rp = &ctx->rp_stack[0]; + br_x509_decoder_init_main_libmail(&ctx->cpu); + br_x509_decoder_run_libmail(&ctx->cpu); +} + +/* see bearssl_x509.h */ +void +br_x509_decoder_push_libmail(br_x509_decoder_context_libmail *ctx, + const void *data, size_t len) +{ + ctx->hbuf = data; + ctx->hlen = len; + br_x509_decoder_run_libmail(&ctx->cpu); +} + + + +static const unsigned char t0_datablock[] = { + 0x00, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, 0x09, + 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x05, 0x09, 0x2A, 0x86, + 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0E, 0x09, 0x2A, 0x86, 0x48, 0x86, + 0xF7, 0x0D, 0x01, 0x01, 0x0B, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, + 0x01, 0x01, 0x0C, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, + 0x0D, 0x07, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x02, 0x01, 0x08, 0x2A, 0x86, + 0x48, 0xCE, 0x3D, 0x03, 0x01, 0x07, 0x05, 0x2B, 0x81, 0x04, 0x00, 0x22, + 0x05, 0x2B, 0x81, 0x04, 0x00, 0x23, 0x07, 0x2A, 0x86, 0x48, 0xCE, 0x3D, + 0x04, 0x01, 0x08, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x04, 0x03, 0x01, 0x08, + 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x04, 0x03, 0x02, 0x08, 0x2A, 0x86, 0x48, + 0xCE, 0x3D, 0x04, 0x03, 0x03, 0x08, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x04, + 0x03, 0x04, 0x00, 0x1F, 0x03, 0xFC, 0x07, 0x7F, 0x0B, 0x5E, 0x0F, 0x1F, + 0x12, 0xFE, 0x16, 0xBF, 0x1A, 0x9F, 0x1E, 0x7E, 0x22, 0x3F, 0x26, 0x1E, + 0x29, 0xDF, 0x00, 0x1F, 0x03, 0xFD, 0x07, 0x9F, 0x0B, 0x7E, 0x0F, 0x3F, + 0x13, 0x1E, 0x16, 0xDF, 0x1A, 0xBF, 0x1E, 0x9E, 0x22, 0x5F, 0x26, 0x3E, + 0x29, 0xFF, 0x03, 0x55, 0x1D, 0x13 +}; + +static const unsigned char t0_codeblock[] = { + 0x00, 0x01, 0x00, 0x10, 0x00, 0x00, 0x01, 0x00, 0x11, 0x00, 0x00, 0x01, + 0x01, 0x09, 0x00, 0x00, 0x01, 0x01, 0x0A, 0x00, 0x00, 0x1A, 0x1A, 0x00, + 0x00, 0x01, T0_INT1(BR_ERR_X509_BAD_BOOLEAN), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_X509_BAD_TAG_CLASS), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_X509_BAD_TAG_VALUE), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_X509_BAD_TIME), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_X509_EXTRA_ELEMENT), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_X509_INDEFINITE_LENGTH), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_X509_INNER_TRUNC), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_X509_LIMIT_EXCEEDED), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_X509_NOT_CONSTRUCTED), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_X509_NOT_PRIMITIVE), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_X509_OVERFLOW), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_X509_PARTIAL_BYTE), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_X509_UNEXPECTED), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_X509_UNSUPPORTED), 0x00, 0x00, 0x01, + T0_INT1(BR_KEYTYPE_EC), 0x00, 0x00, 0x01, T0_INT1(BR_KEYTYPE_RSA), + 0x00, 0x00, 0x01, T0_INT2(offsetof(CONTEXT_NAME, copy_dn)), 0x00, 0x00, + 0x01, T0_INT2(offsetof(CONTEXT_NAME, decoded)), 0x00, 0x00, 0x01, + T0_INT2(offsetof(CONTEXT_NAME, isCA)), 0x00, 0x00, 0x01, + T0_INT2(offsetof(br_x509_decoder_context_libmail, pkey_data)), 0x01, + T0_INT2(BR_X509_BUFSIZE_KEY), 0x00, 0x00, 0x01, + T0_INT2(offsetof(CONTEXT_NAME, notafter_days)), 0x00, 0x00, 0x01, + T0_INT2(offsetof(CONTEXT_NAME, notafter_seconds)), 0x00, 0x00, 0x01, + T0_INT2(offsetof(CONTEXT_NAME, notbefore_days)), 0x00, 0x00, 0x01, + T0_INT2(offsetof(CONTEXT_NAME, notbefore_seconds)), 0x00, 0x00, 0x01, + T0_INT2(offsetof(CONTEXT_NAME, pad)), 0x00, 0x00, 0x01, + T0_INT2(offsetof(CONTEXT_NAME, signer_hash_id)), 0x00, 0x00, 0x01, + T0_INT2(offsetof(CONTEXT_NAME, signer_key_type)), 0x00, 0x00, 0x01, + 0x80, 0x45, 0x00, 0x00, 0x01, 0x80, 0x4E, 0x00, 0x00, 0x01, 0x80, 0x54, + 0x00, 0x00, 0x01, 0x81, 0x36, 0x00, 0x02, 0x03, 0x00, 0x03, 0x01, 0x1B, + 0x02, 0x01, 0x13, 0x26, 0x02, 0x00, 0x0F, 0x15, 0x00, 0x00, 0x05, 0x02, + 0x34, 0x1D, 0x00, 0x00, 0x06, 0x02, 0x35, 0x1D, 0x00, 0x00, 0x01, 0x10, + 0x4F, 0x00, 0x00, 0x11, 0x05, 0x02, 0x38, 0x1D, 0x4C, 0x00, 0x00, 0x11, + 0x05, 0x02, 0x38, 0x1D, 0x4D, 0x00, 0x00, 0x06, 0x02, 0x30, 0x1D, 0x00, + 0x00, 0x1B, 0x19, 0x01, 0x08, 0x0E, 0x26, 0x29, 0x19, 0x09, 0x00, 0x00, + 0x01, 0x30, 0x0A, 0x1B, 0x01, 0x00, 0x01, 0x09, 0x4B, 0x05, 0x02, 0x2F, + 0x1D, 0x00, 0x00, 0x20, 0x20, 0x00, 0x00, 0x01, 0x80, 0x5A, 0x00, 0x00, + 0x01, 0x80, 0x62, 0x00, 0x00, 0x01, 0x80, 0x6B, 0x00, 0x00, 0x01, 0x80, + 0x74, 0x00, 0x00, 0x01, 0x80, 0x7D, 0x00, 0x00, 0x01, 0x3D, 0x00, 0x00, + 0x20, 0x11, 0x06, 0x04, 0x2B, 0x6B, 0x7A, 0x71, 0x00, 0x04, 0x01, 0x00, + 0x3D, 0x25, 0x01, 0x00, 0x3C, 0x25, 0x01, 0x87, 0xFF, 0xFF, 0x7F, 0x6D, + 0x6D, 0x70, 0x1B, 0x01, 0x20, 0x11, 0x06, 0x11, 0x1A, 0x4C, 0x6B, 0x70, + 0x01, 0x02, 0x50, 0x6E, 0x01, 0x02, 0x12, 0x06, 0x02, 0x39, 0x1D, 0x51, + 0x70, 0x01, 0x02, 0x50, 0x6C, 0x6D, 0x7A, 0x6D, 0x7A, 0x6D, 0x65, 0x43, + 0x24, 0x42, 0x24, 0x65, 0x41, 0x24, 0x40, 0x24, 0x51, 0x01, 0x01, 0x3C, + 0x25, 0x6D, 0x7A, 0x01, 0x00, 0x3C, 0x25, 0x6D, 0x6D, 0x60, 0x05, 0x02, + 0x39, 0x1D, 0x74, 0x1C, 0x06, 0x1C, 0x7A, 0x61, 0x6D, 0x3F, 0x68, 0x03, + 0x00, 0x3F, 0x26, 0x02, 0x00, 0x09, 0x26, 0x02, 0x00, 0x0A, 0x68, 0x03, + 0x01, 0x51, 0x51, 0x02, 0x00, 0x02, 0x01, 0x18, 0x04, 0x1E, 0x5A, 0x1C, + 0x06, 0x18, 0x64, 0x03, 0x02, 0x51, 0x61, 0x1B, 0x03, 0x03, 0x1B, 0x3F, + 0x23, 0x0D, 0x06, 0x02, 0x33, 0x1D, 0x62, 0x02, 0x02, 0x02, 0x03, 0x17, + 0x04, 0x02, 0x39, 0x1D, 0x51, 0x01, 0x00, 0x3E, 0x25, 0x71, 0x01, 0x21, + 0x5B, 0x01, 0x22, 0x5B, 0x1B, 0x01, 0x23, 0x11, 0x06, 0x28, 0x1A, 0x4C, + 0x6B, 0x6D, 0x1B, 0x06, 0x1D, 0x6D, 0x60, 0x1A, 0x70, 0x1B, 0x01, 0x01, + 0x11, 0x06, 0x03, 0x63, 0x1A, 0x70, 0x01, 0x04, 0x50, 0x6B, 0x4A, 0x1C, + 0x06, 0x03, 0x5F, 0x04, 0x01, 0x7B, 0x51, 0x51, 0x04, 0x60, 0x51, 0x51, + 0x04, 0x08, 0x01, 0x7F, 0x11, 0x05, 0x02, 0x38, 0x1D, 0x1A, 0x51, 0x6D, + 0x60, 0x06, 0x80, 0x63, 0x75, 0x1C, 0x06, 0x06, 0x01, 0x02, 0x3B, 0x04, + 0x80, 0x57, 0x76, 0x1C, 0x06, 0x06, 0x01, 0x03, 0x3B, 0x04, 0x80, 0x4D, + 0x77, 0x1C, 0x06, 0x06, 0x01, 0x04, 0x3B, 0x04, 0x80, 0x43, 0x78, 0x1C, + 0x06, 0x05, 0x01, 0x05, 0x3B, 0x04, 0x3A, 0x79, 0x1C, 0x06, 0x05, 0x01, + 0x06, 0x3B, 0x04, 0x31, 0x55, 0x1C, 0x06, 0x05, 0x01, 0x02, 0x3A, 0x04, + 0x28, 0x56, 0x1C, 0x06, 0x05, 0x01, 0x03, 0x3A, 0x04, 0x1F, 0x57, 0x1C, + 0x06, 0x05, 0x01, 0x04, 0x3A, 0x04, 0x16, 0x58, 0x1C, 0x06, 0x05, 0x01, + 0x05, 0x3A, 0x04, 0x0D, 0x59, 0x1C, 0x06, 0x05, 0x01, 0x06, 0x3A, 0x04, + 0x04, 0x01, 0x00, 0x01, 0x00, 0x04, 0x04, 0x01, 0x00, 0x01, 0x00, 0x46, + 0x25, 0x45, 0x25, 0x7A, 0x61, 0x7A, 0x51, 0x1A, 0x01, 0x01, 0x3D, 0x25, + 0x73, 0x30, 0x1D, 0x00, 0x00, 0x01, 0x81, 0x06, 0x00, 0x01, 0x54, 0x0D, + 0x06, 0x02, 0x32, 0x1D, 0x1B, 0x03, 0x00, 0x0A, 0x02, 0x00, 0x00, 0x00, + 0x6D, 0x71, 0x1B, 0x01, 0x01, 0x11, 0x06, 0x08, 0x63, 0x01, 0x01, 0x15, + 0x3E, 0x25, 0x04, 0x01, 0x2B, 0x7A, 0x00, 0x00, 0x70, 0x01, 0x06, 0x50, + 0x6F, 0x00, 0x00, 0x70, 0x01, 0x03, 0x50, 0x6B, 0x72, 0x06, 0x02, 0x37, + 0x1D, 0x00, 0x00, 0x26, 0x1B, 0x06, 0x07, 0x21, 0x1B, 0x06, 0x01, 0x16, + 0x04, 0x76, 0x2B, 0x00, 0x00, 0x01, 0x01, 0x50, 0x6A, 0x01, 0x01, 0x10, + 0x06, 0x02, 0x2C, 0x1D, 0x72, 0x27, 0x00, 0x00, 0x60, 0x05, 0x02, 0x39, + 0x1D, 0x47, 0x1C, 0x06, 0x04, 0x01, 0x17, 0x04, 0x12, 0x48, 0x1C, 0x06, + 0x04, 0x01, 0x18, 0x04, 0x0A, 0x49, 0x1C, 0x06, 0x04, 0x01, 0x19, 0x04, + 0x02, 0x39, 0x1D, 0x00, 0x04, 0x70, 0x1B, 0x01, 0x17, 0x01, 0x18, 0x4B, + 0x05, 0x02, 0x2F, 0x1D, 0x01, 0x18, 0x11, 0x03, 0x00, 0x4D, 0x6B, 0x66, + 0x02, 0x00, 0x06, 0x0C, 0x01, 0x80, 0x64, 0x08, 0x03, 0x01, 0x66, 0x02, + 0x01, 0x09, 0x04, 0x0E, 0x1B, 0x01, 0x32, 0x0D, 0x06, 0x04, 0x01, 0x80, + 0x64, 0x09, 0x01, 0x8E, 0x6C, 0x09, 0x03, 0x01, 0x02, 0x01, 0x01, 0x82, + 0x6D, 0x08, 0x02, 0x01, 0x01, 0x03, 0x09, 0x01, 0x04, 0x0C, 0x09, 0x02, + 0x01, 0x01, 0x80, 0x63, 0x09, 0x01, 0x80, 0x64, 0x0C, 0x0A, 0x02, 0x01, + 0x01, 0x83, 0x0F, 0x09, 0x01, 0x83, 0x10, 0x0C, 0x09, 0x03, 0x03, 0x01, + 0x01, 0x01, 0x0C, 0x67, 0x2A, 0x01, 0x01, 0x0E, 0x02, 0x01, 0x01, 0x04, + 0x07, 0x28, 0x02, 0x01, 0x01, 0x80, 0x64, 0x07, 0x27, 0x02, 0x01, 0x01, + 0x83, 0x10, 0x07, 0x28, 0x1F, 0x15, 0x06, 0x03, 0x01, 0x18, 0x09, 0x5D, + 0x09, 0x52, 0x1B, 0x01, 0x05, 0x14, 0x02, 0x03, 0x09, 0x03, 0x03, 0x01, + 0x1F, 0x15, 0x01, 0x01, 0x26, 0x67, 0x02, 0x03, 0x09, 0x2A, 0x03, 0x03, + 0x01, 0x00, 0x01, 0x17, 0x67, 0x01, 0x9C, 0x10, 0x08, 0x03, 0x02, 0x01, + 0x00, 0x01, 0x3B, 0x67, 0x01, 0x3C, 0x08, 0x02, 0x02, 0x09, 0x03, 0x02, + 0x01, 0x00, 0x01, 0x3C, 0x67, 0x02, 0x02, 0x09, 0x03, 0x02, 0x72, 0x1B, + 0x01, 0x2E, 0x11, 0x06, 0x0D, 0x1A, 0x72, 0x1B, 0x01, 0x30, 0x01, 0x39, + 0x4B, 0x06, 0x03, 0x1A, 0x04, 0x74, 0x01, 0x80, 0x5A, 0x10, 0x06, 0x02, + 0x2F, 0x1D, 0x51, 0x02, 0x03, 0x02, 0x02, 0x00, 0x01, 0x72, 0x53, 0x01, + 0x0A, 0x08, 0x03, 0x00, 0x72, 0x53, 0x02, 0x00, 0x09, 0x00, 0x02, 0x03, + 0x00, 0x03, 0x01, 0x66, 0x1B, 0x02, 0x01, 0x02, 0x00, 0x4B, 0x05, 0x02, + 0x2F, 0x1D, 0x00, 0x00, 0x23, 0x70, 0x01, 0x02, 0x50, 0x0B, 0x69, 0x00, + 0x03, 0x1B, 0x03, 0x00, 0x03, 0x01, 0x03, 0x02, 0x6B, 0x72, 0x1B, 0x01, + 0x81, 0x00, 0x13, 0x06, 0x02, 0x36, 0x1D, 0x1B, 0x01, 0x00, 0x11, 0x06, + 0x0B, 0x1A, 0x1B, 0x05, 0x04, 0x1A, 0x01, 0x00, 0x00, 0x72, 0x04, 0x6F, + 0x02, 0x01, 0x1B, 0x05, 0x02, 0x33, 0x1D, 0x2A, 0x03, 0x01, 0x02, 0x02, + 0x25, 0x02, 0x02, 0x29, 0x03, 0x02, 0x1B, 0x06, 0x03, 0x72, 0x04, 0x68, + 0x1A, 0x02, 0x00, 0x02, 0x01, 0x0A, 0x00, 0x01, 0x72, 0x1B, 0x01, 0x81, + 0x00, 0x0D, 0x06, 0x01, 0x00, 0x01, 0x81, 0x00, 0x0A, 0x1B, 0x05, 0x02, + 0x31, 0x1D, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x12, 0x06, + 0x19, 0x02, 0x00, 0x2A, 0x03, 0x00, 0x1B, 0x01, 0x83, 0xFF, 0xFF, 0x7F, + 0x12, 0x06, 0x02, 0x32, 0x1D, 0x01, 0x08, 0x0E, 0x26, 0x72, 0x23, 0x09, + 0x04, 0x60, 0x00, 0x00, 0x6A, 0x5E, 0x00, 0x00, 0x6B, 0x7A, 0x00, 0x00, + 0x70, 0x4E, 0x6B, 0x00, 0x01, 0x6B, 0x1B, 0x05, 0x02, 0x36, 0x1D, 0x72, + 0x1B, 0x01, 0x81, 0x00, 0x13, 0x06, 0x02, 0x36, 0x1D, 0x03, 0x00, 0x1B, + 0x06, 0x16, 0x72, 0x02, 0x00, 0x1B, 0x01, 0x87, 0xFF, 0xFF, 0x7F, 0x13, + 0x06, 0x02, 0x36, 0x1D, 0x01, 0x08, 0x0E, 0x09, 0x03, 0x00, 0x04, 0x67, + 0x1A, 0x02, 0x00, 0x00, 0x00, 0x6B, 0x1B, 0x01, 0x81, 0x7F, 0x12, 0x06, + 0x08, 0x7A, 0x01, 0x00, 0x44, 0x25, 0x01, 0x00, 0x00, 0x1B, 0x44, 0x25, + 0x44, 0x29, 0x62, 0x01, 0x7F, 0x00, 0x01, 0x72, 0x03, 0x00, 0x02, 0x00, + 0x01, 0x05, 0x14, 0x01, 0x01, 0x15, 0x1E, 0x02, 0x00, 0x01, 0x06, 0x14, + 0x1B, 0x01, 0x01, 0x15, 0x06, 0x02, 0x2D, 0x1D, 0x01, 0x04, 0x0E, 0x02, + 0x00, 0x01, 0x1F, 0x15, 0x1B, 0x01, 0x1F, 0x11, 0x06, 0x02, 0x2E, 0x1D, + 0x09, 0x00, 0x00, 0x1B, 0x05, 0x05, 0x01, 0x00, 0x01, 0x7F, 0x00, 0x70, + 0x00, 0x00, 0x1B, 0x05, 0x02, 0x32, 0x1D, 0x2A, 0x73, 0x00, 0x00, 0x22, + 0x1B, 0x01, 0x00, 0x13, 0x06, 0x01, 0x00, 0x1A, 0x16, 0x04, 0x74, 0x00, + 0x01, 0x01, 0x00, 0x00, 0x01, 0x0B, 0x00, 0x00, 0x01, 0x15, 0x00, 0x00, + 0x01, 0x1F, 0x00, 0x00, 0x01, 0x29, 0x00, 0x00, 0x01, 0x33, 0x00, 0x00, + 0x7B, 0x1A, 0x00, 0x00, 0x1B, 0x06, 0x07, 0x7C, 0x1B, 0x06, 0x01, 0x16, + 0x04, 0x76, 0x00, 0x00, 0x01, 0x00, 0x20, 0x21, 0x0B, 0x2B, 0x00 +}; + +static const uint16_t t0_caddr[] = { + 0, + 5, + 10, + 15, + 20, + 24, + 28, + 32, + 36, + 40, + 44, + 48, + 52, + 56, + 60, + 64, + 68, + 72, + 76, + 80, + 84, + 88, + 93, + 98, + 103, + 111, + 116, + 121, + 126, + 131, + 136, + 141, + 146, + 151, + 156, + 161, + 166, + 181, + 187, + 193, + 198, + 206, + 214, + 220, + 231, + 246, + 250, + 255, + 260, + 265, + 270, + 275, + 279, + 289, + 620, + 625, + 639, + 659, + 666, + 678, + 692, + 707, + 740, + 960, + 974, + 991, + 1000, + 1067, + 1123, + 1127, + 1131, + 1136, + 1184, + 1210, + 1254, + 1265, + 1274, + 1287, + 1291, + 1295, + 1299, + 1303, + 1307, + 1311, + 1315, + 1327 +}; + +#define T0_INTERPRETED 39 + +#define T0_ENTER(ip, rp, slot) do { \ + const unsigned char *t0_newip; \ + uint32_t t0_lnum; \ + t0_newip = &t0_codeblock[t0_caddr[(slot) - T0_INTERPRETED]]; \ + t0_lnum = t0_parse7E_unsigned(&t0_newip); \ + (rp) += t0_lnum; \ + *((rp) ++) = (uint32_t)((ip) - &t0_codeblock[0]) + (t0_lnum << 16); \ + (ip) = t0_newip; \ + } while (0) + +#define T0_DEFENTRY(name, slot) \ +void \ +name(void *ctx) \ +{ \ + t0_context *t0ctx = ctx; \ + t0ctx->ip = &t0_codeblock[0]; \ + T0_ENTER(t0ctx->ip, t0ctx->rp, slot); \ +} + +T0_DEFENTRY(br_x509_decoder_init_main_libmail, 92) + +#define T0_NEXT(t0ipp) (*(*(t0ipp)) ++) + +void +br_x509_decoder_run_libmail(void *t0ctx) +{ + uint32_t *dp, *rp; + const unsigned char *ip; + +#define T0_LOCAL(x) (*(rp - 2 - (x))) +#define T0_POP() (*-- dp) +#define T0_POPi() (*(int32_t *)(-- dp)) +#define T0_PEEK(x) (*(dp - 1 - (x))) +#define T0_PEEKi(x) (*(int32_t *)(dp - 1 - (x))) +#define T0_PUSH(v) do { *dp = (v); dp ++; } while (0) +#define T0_PUSHi(v) do { *(int32_t *)dp = (v); dp ++; } while (0) +#define T0_RPOP() (*-- rp) +#define T0_RPOPi() (*(int32_t *)(-- rp)) +#define T0_RPUSH(v) do { *rp = (v); rp ++; } while (0) +#define T0_RPUSHi(v) do { *(int32_t *)rp = (v); rp ++; } while (0) +#define T0_ROLL(x) do { \ + size_t t0len = (size_t)(x); \ + uint32_t t0tmp = *(dp - 1 - t0len); \ + memmove(dp - t0len - 1, dp - t0len, t0len * sizeof *dp); \ + *(dp - 1) = t0tmp; \ +} while (0) +#define T0_SWAP() do { \ + uint32_t t0tmp = *(dp - 2); \ + *(dp - 2) = *(dp - 1); \ + *(dp - 1) = t0tmp; \ +} while (0) +#define T0_ROT() do { \ + uint32_t t0tmp = *(dp - 3); \ + *(dp - 3) = *(dp - 2); \ + *(dp - 2) = *(dp - 1); \ + *(dp - 1) = t0tmp; \ +} while (0) +#define T0_NROT() do { \ + uint32_t t0tmp = *(dp - 1); \ + *(dp - 1) = *(dp - 2); \ + *(dp - 2) = *(dp - 3); \ + *(dp - 3) = t0tmp; \ +} while (0) +#define T0_PICK(x) do { \ + uint32_t t0depth = (x); \ + T0_PUSH(T0_PEEK(t0depth)); \ +} while (0) +#define T0_CO() do { \ + goto t0_exit; \ +} while (0) +#define T0_RET() goto t0_next + + dp = ((t0_context *)t0ctx)->dp; + rp = ((t0_context *)t0ctx)->rp; + ip = ((t0_context *)t0ctx)->ip; + goto t0_next; + for (;;) { + uint32_t t0x; + + t0_next: + t0x = T0_NEXT(&ip); + if (t0x < T0_INTERPRETED) { + switch (t0x) { + int32_t t0off; + + case 0: /* ret */ + t0x = T0_RPOP(); + rp -= (t0x >> 16); + t0x &= 0xFFFF; + if (t0x == 0) { + ip = NULL; + goto t0_exit; + } + ip = &t0_codeblock[t0x]; + break; + case 1: /* literal constant */ + T0_PUSHi(t0_parse7E_signed(&ip)); + break; + case 2: /* read local */ + T0_PUSH(T0_LOCAL(t0_parse7E_unsigned(&ip))); + break; + case 3: /* write local */ + T0_LOCAL(t0_parse7E_unsigned(&ip)) = T0_POP(); + break; + case 4: /* jump */ + t0off = t0_parse7E_signed(&ip); + ip += t0off; + break; + case 5: /* jump if */ + t0off = t0_parse7E_signed(&ip); + if (T0_POP()) { + ip += t0off; + } + break; + case 6: /* jump if not */ + t0off = t0_parse7E_signed(&ip); + if (!T0_POP()) { + ip += t0off; + } + break; + case 7: { + /* %25 */ + + int32_t b = T0_POPi(); + int32_t a = T0_POPi(); + T0_PUSHi(a % b); + + } + break; + case 8: { + /* * */ + + uint32_t b = T0_POP(); + uint32_t a = T0_POP(); + T0_PUSH(a * b); + + } + break; + case 9: { + /* + */ + + uint32_t b = T0_POP(); + uint32_t a = T0_POP(); + T0_PUSH(a + b); + + } + break; + case 10: { + /* - */ + + uint32_t b = T0_POP(); + uint32_t a = T0_POP(); + T0_PUSH(a - b); + + } + break; + case 11: { + /* -rot */ + T0_NROT(); + } + break; + case 12: { + /* / */ + + int32_t b = T0_POPi(); + int32_t a = T0_POPi(); + T0_PUSHi(a / b); + + } + break; + case 13: { + /* < */ + + int32_t b = T0_POPi(); + int32_t a = T0_POPi(); + T0_PUSH(-(uint32_t)(a < b)); + + } + break; + case 14: { + /* << */ + + int c = (int)T0_POPi(); + uint32_t x = T0_POP(); + T0_PUSH(x << c); + + } + break; + case 15: { + /* <= */ + + int32_t b = T0_POPi(); + int32_t a = T0_POPi(); + T0_PUSH(-(uint32_t)(a <= b)); + + } + break; + case 16: { + /* <> */ + + uint32_t b = T0_POP(); + uint32_t a = T0_POP(); + T0_PUSH(-(uint32_t)(a != b)); + + } + break; + case 17: { + /* = */ + + uint32_t b = T0_POP(); + uint32_t a = T0_POP(); + T0_PUSH(-(uint32_t)(a == b)); + + } + break; + case 18: { + /* > */ + + int32_t b = T0_POPi(); + int32_t a = T0_POPi(); + T0_PUSH(-(uint32_t)(a > b)); + + } + break; + case 19: { + /* >= */ + + int32_t b = T0_POPi(); + int32_t a = T0_POPi(); + T0_PUSH(-(uint32_t)(a >= b)); + + } + break; + case 20: { + /* >> */ + + int c = (int)T0_POPi(); + int32_t x = T0_POPi(); + T0_PUSHi(x >> c); + + } + break; + case 21: { + /* and */ + + uint32_t b = T0_POP(); + uint32_t a = T0_POP(); + T0_PUSH(a & b); + + } + break; + case 22: { + /* co */ + T0_CO(); + } + break; + case 23: { + /* copy-ec-pkey */ + + size_t qlen = T0_POP(); + uint32_t curve = T0_POP(); + CTX->pkey.key_type = BR_KEYTYPE_EC; + CTX->pkey.key.ec.curve = curve; + CTX->pkey.key.ec.q = CTX->pkey_data; + CTX->pkey.key.ec.qlen = qlen; + + } + break; + case 24: { + /* copy-rsa-pkey */ + + size_t elen = T0_POP(); + size_t nlen = T0_POP(); + CTX->pkey.key_type = BR_KEYTYPE_RSA; + CTX->pkey.key.rsa.n = CTX->pkey_data; + CTX->pkey.key.rsa.nlen = nlen; + CTX->pkey.key.rsa.e = CTX->pkey_data + nlen; + CTX->pkey.key.rsa.elen = elen; + + } + break; + case 25: { + /* data-get8 */ + + size_t addr = T0_POP(); + T0_PUSH(t0_datablock[addr]); + + } + break; + case 26: { + /* drop */ + (void)T0_POP(); + } + break; + case 27: { + /* dup */ + T0_PUSH(T0_PEEK(0)); + } + break; + case 28: { + /* eqOID */ + + const unsigned char *a2 = &t0_datablock[T0_POP()]; + const unsigned char *a1 = &CTX->pad[0]; + size_t len = a1[0]; + int x; + if (len == a2[0]) { + x = -(memcmp(a1 + 1, a2 + 1, len) == 0); + } else { + x = 0; + } + T0_PUSH((uint32_t)x); + + } + break; + case 29: { + /* fail */ + + CTX->err = T0_POPi(); + T0_CO(); + + } + break; + case 30: { + /* neg */ + + uint32_t a = T0_POP(); + T0_PUSH(-a); + + } + break; + case 31: { + /* or */ + + uint32_t b = T0_POP(); + uint32_t a = T0_POP(); + T0_PUSH(a | b); + + } + break; + case 32: { + /* over */ + T0_PUSH(T0_PEEK(1)); + } + break; + case 33: { + /* read-blob-inner */ + + uint32_t len = T0_POP(); + uint32_t addr = T0_POP(); + size_t clen = CTX->hlen; + if (clen > len) { + clen = (size_t)len; + } + if (addr != 0) { + memcpy((unsigned char *)CTX + addr, CTX->hbuf, clen); + } + if (CTX->copy_dn && CTX->append_dn) { + CTX->append_dn(CTX->append_dn_ctx, CTX->hbuf, clen); + } + CTX->hbuf += clen; + CTX->hlen -= clen; + T0_PUSH(addr + clen); + T0_PUSH(len - clen); + + } + break; + case 34: { + /* read8-low */ + + if (CTX->hlen == 0) { + T0_PUSHi(-1); + } else { + unsigned char x = *CTX->hbuf ++; + if (CTX->copy_dn && CTX->append_dn) { + CTX->append_dn(CTX->append_dn_ctx, &x, 1); + } + CTX->hlen --; + T0_PUSH(x); + } + + } + break; + case 35: { + /* rot */ + T0_ROT(); + } + break; + case 36: { + /* set32 */ + + uint32_t addr = T0_POP(); + *(uint32_t *)(void *)((unsigned char *)CTX + addr) = T0_POP(); + + } + break; + case 37: { + /* set8 */ + + uint32_t addr = T0_POP(); + *((unsigned char *)CTX + addr) = (unsigned char)T0_POP(); + + } + break; + case 38: { + /* swap */ + T0_SWAP(); + } + break; + } + + } else { + T0_ENTER(ip, rp, t0x); + } + } +t0_exit: + ((t0_context *)t0ctx)->dp = dp; + ((t0_context *)t0ctx)->rp = rp; + ((t0_context *)t0ctx)->ip = ip; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/x509_decoder.t0 b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/x509_decoder.t0 new file mode 100644 index 000000000..1bb3d4e81 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/x509_decoder.t0 @@ -0,0 +1,321 @@ +\ Copyright (c) 2016 Thomas Pornin +\ +\ Permission is hereby granted, free of charge, to any person obtaining +\ a copy of this software and associated documentation files (the +\ "Software"), to deal in the Software without restriction, including +\ without limitation the rights to use, copy, modify, merge, publish, +\ distribute, sublicense, and/or sell copies of the Software, and to +\ permit persons to whom the Software is furnished to do so, subject to +\ the following conditions: +\ +\ The above copyright notice and this permission notice shall be +\ included in all copies or substantial portions of the Software. +\ +\ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +\ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +\ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +\ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +\ BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +\ ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +\ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +\ SOFTWARE. + +preamble { + +#include "inner.h" + +#define CTX ((br_x509_decoder_context_libmail *)(void *)((unsigned char *)t0ctx - offsetof(br_x509_decoder_context_libmail, cpu))) +#define CONTEXT_NAME br_x509_decoder_context_libmail + +/* see bearssl_x509.h */ +void +br_x509_decoder_init(br_x509_decoder_context_libmail *ctx, + void (*append_dn)(void *ctx, const void *buf, size_t len), + void *append_dn_ctx) +{ + memset(ctx, 0, sizeof *ctx); + /* obsolete + ctx->err = 0; + ctx->hbuf = NULL; + ctx->hlen = 0; + */ + ctx->append_dn = append_dn; + ctx->append_dn_ctx = append_dn_ctx; + ctx->cpu.dp = &ctx->dp_stack[0]; + ctx->cpu.rp = &ctx->rp_stack[0]; + br_x509_decoder_init_main_libmail(&ctx->cpu); + br_x509_decoder_run_libmail(&ctx->cpu); +} + +/* see bearssl_x509.h */ +void +br_x509_decoder_push_libmail(br_x509_decoder_context_libmail *ctx, + const void *data, size_t len) +{ + ctx->hbuf = data; + ctx->hlen = len; + br_x509_decoder_run_libmail(&ctx->cpu); +} + +} + +addr: decoded +addr: notbefore_days +addr: notbefore_seconds +addr: notafter_days +addr: notafter_seconds +addr: isCA +addr: copy_dn +addr: signer_key_type +addr: signer_hash_id + +cc: read8-low ( -- x ) { + if (CTX->hlen == 0) { + T0_PUSHi(-1); + } else { + unsigned char x = *CTX->hbuf ++; + if (CTX->copy_dn && CTX->append_dn) { + CTX->append_dn(CTX->append_dn_ctx, &x, 1); + } + CTX->hlen --; + T0_PUSH(x); + } +} + +cc: read-blob-inner ( addr len -- addr len ) { + uint32_t len = T0_POP(); + uint32_t addr = T0_POP(); + size_t clen = CTX->hlen; + if (clen > len) { + clen = (size_t)len; + } + if (addr != 0) { + memcpy((unsigned char *)CTX + addr, CTX->hbuf, clen); + } + if (CTX->copy_dn && CTX->append_dn) { + CTX->append_dn(CTX->append_dn_ctx, CTX->hbuf, clen); + } + CTX->hbuf += clen; + CTX->hlen -= clen; + T0_PUSH(addr + clen); + T0_PUSH(len - clen); +} + +\ Get the address and length for the pkey_data buffer. +: addr-len-pkey_data ( -- addr len ) + CX 0 8191 { offsetof(br_x509_decoder_context_libmail, pkey_data) } + CX 0 8191 { BR_X509_BUFSIZE_KEY } ; + +\ Copy the public key (RSA) to the permanent buffer. +cc: copy-rsa-pkey ( nlen elen -- ) { + size_t elen = T0_POP(); + size_t nlen = T0_POP(); + CTX->pkey.key_type = BR_KEYTYPE_RSA; + CTX->pkey.key.rsa.n = CTX->pkey_data; + CTX->pkey.key.rsa.nlen = nlen; + CTX->pkey.key.rsa.e = CTX->pkey_data + nlen; + CTX->pkey.key.rsa.elen = elen; +} + +\ Copy the public key (EC) to the permanent buffer. +cc: copy-ec-pkey ( curve qlen -- ) { + size_t qlen = T0_POP(); + uint32_t curve = T0_POP(); + CTX->pkey.key_type = BR_KEYTYPE_EC; + CTX->pkey.key.ec.curve = curve; + CTX->pkey.key.ec.q = CTX->pkey_data; + CTX->pkey.key.ec.qlen = qlen; +} + +\ Extensions with specific processing. +OID: basicConstraints 2.5.29.19 + +\ Process a Basic Constraints extension. We want the "CA" flag only. +: process-basicConstraints ( lim -- lim ) + read-sequence-open + read-tag-or-end dup 0x01 = if + read-boolean 1 and addr-isCA set8 + else + 2drop + then + skip-close-elt + ; + +\ Decode a certificate. +: main ( -- ! ) + + \ Initialise state flags. + 0 addr-decoded set8 + 0 addr-copy_dn set8 + + \ An arbitrary limit for the total certificate size. + 0xFFFFFF + + \ Open the outer SEQUENCE. + read-sequence-open + + \ TBS + read-sequence-open + + \ First element may be an explicit version. We accept only + \ versions 0 to 2 (certificates v1 to v3). + read-tag dup 0x20 = if + drop check-constructed read-length-open-elt + read-tag + 0x02 check-tag-primitive + read-small-int-value + 2 > if ERR_X509_UNSUPPORTED fail then + close-elt + read-tag + then + + \ Serial number. We just check that the tag is correct. + 0x02 check-tag-primitive read-length-skip + + \ Signature algorithm. + read-sequence-open skip-close-elt + + \ Issuer name. + read-sequence-open skip-close-elt + + \ Validity dates. + read-sequence-open + read-date addr-notbefore_seconds set32 addr-notbefore_days set32 + read-date addr-notafter_seconds set32 addr-notafter_days set32 + close-elt + + \ Subject name. + 1 addr-copy_dn set8 + read-sequence-open skip-close-elt + 0 addr-copy_dn set8 + + \ Public Key. + read-sequence-open + \ Algorithm Identifier. Right now we are only interested in the + \ OID, since we only support RSA keys. + \ TODO: support EC keys + read-sequence-open + read-OID ifnot ERR_X509_UNSUPPORTED fail then + choice + \ RSA public key. + rsaEncryption eqOID uf + skip-close-elt + \ Public key itself: the BIT STRING contains bytes + \ (no partial byte) and these bytes encode the + \ actual value. + read-bits-open + \ RSA public key is a SEQUENCE of two + \ INTEGER. We get both INTEGER values into + \ the pkey_data[] buffer, if they fit. + read-sequence-open + addr-len-pkey_data + read-integer { nlen } + addr-len-pkey_data swap nlen + swap nlen - + read-integer { elen } + close-elt + close-elt + nlen elen copy-rsa-pkey + enduf + + \ EC public key. + id-ecPublicKey eqOID uf + \ We support only named curves, for which the + \ "parameters" field in the AlgorithmIdentifier + \ field should be an OID. + read-curve-ID { curve } + close-elt + read-bits-open + dup { qlen } + dup addr-len-pkey_data rot < if + ERR_X509_LIMIT_EXCEEDED fail + then + read-blob + curve qlen copy-ec-pkey + enduf + ERR_X509_UNSUPPORTED fail + endchoice + close-elt + + \ This flag will be set to true if the Basic Constraints extension + \ is encountered. + 0 addr-isCA set8 + + \ Skip issuerUniqueID and subjectUniqueID, and process extensions + \ if present. Extensions are an explicit context tag of value 3 + \ around a SEQUENCE OF extensions. Each extension is a SEQUENCE + \ with an OID, an optional boolean, and a value; the value is + \ an OCTET STRING. + read-tag-or-end + 0x21 iftag-skip + 0x22 iftag-skip + dup 0x23 = if + drop + check-constructed read-length-open-elt + read-sequence-open + begin dup while + read-sequence-open + read-OID drop + read-tag dup 0x01 = if + read-boolean drop + read-tag + then + 0x04 check-tag-primitive read-length-open-elt + choice + \ Extensions with specific processing. + basicConstraints eqOID uf + process-basicConstraints + enduf + skip-remaining + endchoice + close-elt + close-elt + repeat + close-elt + close-elt + else + -1 = ifnot ERR_X509_UNEXPECTED fail then + drop + then + + close-elt + + \ signature algorithm + read-sequence-open + read-OID if + choice + sha1WithRSAEncryption eqOID uf 2 KEYTYPE_RSA enduf + sha224WithRSAEncryption eqOID uf 3 KEYTYPE_RSA enduf + sha256WithRSAEncryption eqOID uf 4 KEYTYPE_RSA enduf + sha384WithRSAEncryption eqOID uf 5 KEYTYPE_RSA enduf + sha512WithRSAEncryption eqOID uf 6 KEYTYPE_RSA enduf + + ecdsa-with-SHA1 eqOID uf 2 KEYTYPE_EC enduf + ecdsa-with-SHA224 eqOID uf 3 KEYTYPE_EC enduf + ecdsa-with-SHA256 eqOID uf 4 KEYTYPE_EC enduf + ecdsa-with-SHA384 eqOID uf 5 KEYTYPE_EC enduf + ecdsa-with-SHA512 eqOID uf 6 KEYTYPE_EC enduf + + 0 0 + endchoice + else + 0 0 + then + addr-signer_key_type set8 + addr-signer_hash_id set8 + skip-close-elt + \ read-sequence-open skip-close-elt + + \ signature value + read-bits-open skip-close-elt + + \ Close the outer SEQUENCE. + close-elt + drop + + \ Mark the decoding as successful. + 1 addr-decoded set8 + + \ Read one byte, then fail: if the read succeeds, then there is + \ some trailing byte. + read8-nc ERR_X509_EXTRA_ELEMENT fail + ; diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/x509_knownkey.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/x509_knownkey.c new file mode 100644 index 000000000..f1f5af1bc --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/x509_knownkey.c @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_x509.h */ +void +br_x509_knownkey_init_rsa(br_x509_knownkey_context *ctx, + const br_rsa_public_key *pk, unsigned usages) +{ + ctx->vtable = &br_x509_knownkey_vtable; + ctx->pkey.key_type = BR_KEYTYPE_RSA; + ctx->pkey.key.rsa = *pk; + ctx->usages = usages; +} + +/* see bearssl_x509.h */ +void +br_x509_knownkey_init_ec(br_x509_knownkey_context *ctx, + const br_ec_public_key *pk, unsigned usages) +{ + ctx->vtable = &br_x509_knownkey_vtable; + ctx->pkey.key_type = BR_KEYTYPE_EC; + ctx->pkey.key.ec = *pk; + ctx->usages = usages; +} + +static void +kk_start_chain(const br_x509_class **ctx, const char *server_name) +{ + (void)ctx; + (void)server_name; +} + +static void +kk_start_cert(const br_x509_class **ctx, uint32_t length) +{ + (void)ctx; + (void)length; +} + +static void +kk_append(const br_x509_class **ctx, const unsigned char *buf, size_t len) +{ + (void)ctx; + (void)buf; + (void)len; +} + +static void +kk_end_cert(const br_x509_class **ctx) +{ + (void)ctx; +} + +static unsigned +kk_end_chain(const br_x509_class **ctx) +{ + (void)ctx; + return 0; +} + +static const br_x509_pkey * +kk_get_pkey(const br_x509_class *const *ctx, unsigned *usages) +{ + const br_x509_knownkey_context *xc; + + xc = (const br_x509_knownkey_context *)ctx; + if (usages != NULL) { + *usages = xc->usages; + } + return &xc->pkey; +} + +/* see bearssl_x509.h */ +const br_x509_class br_x509_knownkey_vtable = { + sizeof(br_x509_knownkey_context), + kk_start_chain, + kk_start_cert, + kk_append, + kk_end_cert, + kk_end_chain, + kk_get_pkey +}; + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/x509_minimal.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/x509_minimal.c new file mode 100644 index 000000000..36c712446 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/x509_minimal.c @@ -0,0 +1,1719 @@ +/* Automatically generated code; do not modify directly. */ + + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include +#include + +typedef struct { + uint32_t *dp; + uint32_t *rp; + const unsigned char *ip; +} t0_context; + +static uint32_t +t0_parse7E_unsigned(const unsigned char **p) +{ + uint32_t x; + + x = 0; + for (;;) { + unsigned y; + + y = *(*p) ++; + x = (x << 7) | (uint32_t)(y & 0x7F); + if (y < 0x80) { + return x; + } + } +} + +static int32_t +t0_parse7E_signed(const unsigned char **p) +{ + int neg; + uint32_t x; + + neg = ((**p) >> 6) & 1; + x = (uint32_t)-neg; + for (;;) { + unsigned y; + + y = *(*p) ++; + x = (x << 7) | (uint32_t)(y & 0x7F); + if (y < 0x80) { + if (neg) { + return -(int32_t)~x - 1; + } else { + return (int32_t)x; + } + } + } +} + +#define T0_VBYTE(x, n) (unsigned char)((((uint32_t)(x) >> (n)) & 0x7F) | 0x80) +#define T0_FBYTE(x, n) (unsigned char)(((uint32_t)(x) >> (n)) & 0x7F) +#define T0_SBYTE(x) (unsigned char)((((uint32_t)(x) >> 28) + 0xF8) ^ 0xF8) +#define T0_INT1(x) T0_FBYTE(x, 0) +#define T0_INT2(x) T0_VBYTE(x, 7), T0_FBYTE(x, 0) +#define T0_INT3(x) T0_VBYTE(x, 14), T0_VBYTE(x, 7), T0_FBYTE(x, 0) +#define T0_INT4(x) T0_VBYTE(x, 21), T0_VBYTE(x, 14), T0_VBYTE(x, 7), T0_FBYTE(x, 0) +#define T0_INT5(x) T0_SBYTE(x), T0_VBYTE(x, 21), T0_VBYTE(x, 14), T0_VBYTE(x, 7), T0_FBYTE(x, 0) + +/* static const unsigned char t0_datablock[]; */ + + +void br_x509_minimal_init_main(void *t0ctx); + +void br_x509_minimal_run(void *t0ctx); + + + +#include "inner.h" + + + + + +#include "inner.h" + +/* + * Implementation Notes + * -------------------- + * + * The C code pushes the data by chunks; all decoding is done in the + * T0 code. The cert_length value is set to the certificate length when + * a new certificate is started; the T0 code picks it up as outer limit, + * and decoding functions use it to ensure that no attempt is made at + * reading past it. The T0 code also checks that once the certificate is + * decoded, there are no trailing bytes. + * + * The T0 code sets cert_length to 0 when the certificate is fully + * decoded. + * + * The C code must still perform two checks: + * + * -- If the certificate length is 0, then the T0 code will not be + * invoked at all. This invalid condition must thus be reported by the + * C code. + * + * -- When reaching the end of certificate, the C code must verify that + * the certificate length has been set to 0, thereby signaling that + * the T0 code properly decoded a certificate. + * + * Processing of a chain works in the following way: + * + * -- The error flag is set to a non-zero value when validation is + * finished. The value is either BR_ERR_X509_OK (validation is + * successful) or another non-zero error code. When a non-zero error + * code is obtained, the remaining bytes in the current certificate and + * the subsequent certificates (if any) are completely ignored. + * + * -- Each certificate is decoded in due course, with the following + * "interesting points": + * + * -- Start of the TBS: the multihash engine is reset and activated. + * + * -- Start of the issuer DN: the secondary hash engine is started, + * to process the encoded issuer DN. + * + * -- End of the issuer DN: the secondary hash engine is stopped. The + * resulting hash value is computed and then copied into the + * next_dn_hash[] buffer. + * + * -- Start of the subject DN: the secondary hash engine is started, + * to process the encoded subject DN. + * + * -- For the EE certificate only: the Common Name, if any, is matched + * against the expected server name. + * + * -- End of the subject DN: the secondary hash engine is stopped. The + * resulting hash value is computed into the pad. It is then processed: + * + * -- If this is the EE certificate, then the hash is ignored + * (except for direct trust processing, see later; the hash is + * simply left in current_dn_hash[]). + * + * -- Otherwise, the hashed subject DN is compared with the saved + * hash value (in saved_dn_hash[]). They must match. + * + * Either way, the next_dn_hash[] value is then copied into the + * saved_dn_hash[] value. Thus, at that point, saved_dn_hash[] + * contains the hash of the issuer DN for the current certificate, + * and current_dn_hash[] contains the hash of the subject DN for the + * current certificate. + * + * -- Public key: it is decoded into the cert_pkey[] buffer. Unknown + * key types are reported at that point. + * + * -- If this is the EE certificate, then the key type is compared + * with the expected key type (initialization parameter). The public + * key data is copied to ee_pkey_data[]. The key and hashed subject + * DN are also compared with the "direct trust" keys; if the key + * and DN are matched, then validation ends with a success. + * + * -- Otherwise, the saved signature (cert_sig[]) is verified + * against the saved TBS hash (tbs_hash[]) and that freshly + * decoded public key. Failure here ends validation with an error. + * + * -- Extensions: extension values are processed in due order. + * + * -- Basic Constraints: for all certificates except EE, must be + * present, indicate a CA, and have a path legnth compatible with + * the chain length so far. + * + * -- Key Usage: for the EE, if present, must allow signatures + * or encryption/key exchange, as required for the cipher suite. + * For non-EE, if present, must have the "certificate sign" bit. + * + * -- Subject Alt Name: for the EE, dNSName names are matched + * against the server name. Ignored for non-EE. + * + * -- Authority Key Identifier, Subject Key Identifier, Issuer + * Alt Name, Subject Directory Attributes, CRL Distribution Points + * Freshest CRL, Authority Info Access and Subject Info Access + * extensions are always ignored: they either contain only + * informative data, or they relate to revocation processing, which + * we explicitly do not support. + * + * -- All other extensions are ignored if non-critical. If a + * critical extension other than the ones above is encountered, + * then a failure is reported. + * + * -- End of the TBS: the multihash engine is stopped. + * + * -- Signature algorithm: the signature algorithm on the + * certificate is decoded. A failure is reported if that algorithm + * is unknown. The hashed TBS corresponding to the signature hash + * function is computed and stored in tbs_hash[] (if not supported, + * then a failure is reported). The hash OID and length are stored + * in cert_sig_hash_oid and cert_sig_hash_len. + * + * -- Signature value: the signature value is copied into the + * cert_sig[] array. + * + * -- Certificate end: the hashed issuer DN (saved_dn_hash[]) is + * looked up in the trust store (CA trust anchors only); for all + * that match, the signature (cert_sig[]) is verified against the + * anchor public key (hashed TBS is in tbs_hash[]). If one of these + * signatures is valid, then validation ends with a success. + * + * -- If the chain end is reached without obtaining a validation success, + * then validation is reported as failed. + */ + +#if BR_USE_UNIX_TIME +#include +#endif + +#if BR_USE_WIN32_TIME +#include +#endif + +/* + * The T0 compiler will produce these prototypes declarations in the + * header. + * +void br_x509_minimal_init_main(void *ctx); +void br_x509_minimal_run(void *ctx); + */ + +/* see bearssl_x509.h */ +void +br_x509_minimal_init(br_x509_minimal_context *ctx, + const br_hash_class *dn_hash_impl, + const br_x509_trust_anchor *trust_anchors, size_t trust_anchors_num) +{ + memset(ctx, 0, sizeof *ctx); + ctx->vtable = &br_x509_minimal_vtable; + ctx->dn_hash_impl = dn_hash_impl; + ctx->trust_anchors = trust_anchors; + ctx->trust_anchors_num = trust_anchors_num; +} + +static void +xm_start_chain(const br_x509_class **ctx, const char *server_name) +{ + br_x509_minimal_context *cc; + size_t u; + + cc = (br_x509_minimal_context *)(void *)ctx; + for (u = 0; u < cc->num_name_elts; u ++) { + cc->name_elts[u].status = 0; + cc->name_elts[u].buf[0] = 0; + } + memset(&cc->pkey, 0, sizeof cc->pkey); + cc->num_certs = 0; + cc->err = 0; + cc->cpu.dp = cc->dp_stack; + cc->cpu.rp = cc->rp_stack; + br_x509_minimal_init_main(&cc->cpu); + if (server_name == NULL || *server_name == 0) { + cc->server_name = NULL; + } else { + cc->server_name = server_name; + } +} + +static void +xm_start_cert(const br_x509_class **ctx, uint32_t length) +{ + br_x509_minimal_context *cc; + + cc = (br_x509_minimal_context *)(void *)ctx; + if (cc->err != 0) { + return; + } + if (length == 0) { + cc->err = BR_ERR_X509_TRUNCATED; + return; + } + cc->cert_length = length; +} + +static void +xm_append(const br_x509_class **ctx, const unsigned char *buf, size_t len) +{ + br_x509_minimal_context *cc; + + cc = (br_x509_minimal_context *)(void *)ctx; + if (cc->err != 0) { + return; + } + cc->hbuf = buf; + cc->hlen = len; + br_x509_minimal_run(&cc->cpu); +} + +static void +xm_end_cert(const br_x509_class **ctx) +{ + br_x509_minimal_context *cc; + + cc = (br_x509_minimal_context *)(void *)ctx; + if (cc->err == 0 && cc->cert_length != 0) { + cc->err = BR_ERR_X509_TRUNCATED; + } + cc->num_certs ++; +} + +static unsigned +xm_end_chain(const br_x509_class **ctx) +{ + br_x509_minimal_context *cc; + + cc = (br_x509_minimal_context *)(void *)ctx; + if (cc->err == 0) { + if (cc->num_certs == 0) { + cc->err = BR_ERR_X509_EMPTY_CHAIN; + } else { + cc->err = BR_ERR_X509_NOT_TRUSTED; + } + } else if (cc->err == BR_ERR_X509_OK) { + return 0; + } + return (unsigned)cc->err; +} + +static const br_x509_pkey * +xm_get_pkey(const br_x509_class *const *ctx, unsigned *usages) +{ + br_x509_minimal_context *cc; + + cc = (br_x509_minimal_context *)(void *)ctx; + if (cc->err == BR_ERR_X509_OK + || cc->err == BR_ERR_X509_NOT_TRUSTED) + { + if (usages != NULL) { + *usages = cc->key_usages; + } + return &((br_x509_minimal_context *)(void *)ctx)->pkey; + } else { + return NULL; + } +} + +/* see bearssl_x509.h */ +const br_x509_class br_x509_minimal_vtable = { + sizeof(br_x509_minimal_context), + xm_start_chain, + xm_start_cert, + xm_append, + xm_end_cert, + xm_end_chain, + xm_get_pkey +}; + +#define CTX ((br_x509_minimal_context *)(void *)((unsigned char *)t0ctx - offsetof(br_x509_minimal_context, cpu))) +#define CONTEXT_NAME br_x509_minimal_context + +#define DNHASH_LEN ((CTX->dn_hash_impl->desc >> BR_HASHDESC_OUT_OFF) & BR_HASHDESC_OUT_MASK) + +/* + * Hash a DN (from a trust anchor) into the provided buffer. This uses the + * DN hash implementation and context structure from the X.509 engine + * context. + */ +static void +hash_dn(br_x509_minimal_context *ctx, const void *dn, size_t len, + unsigned char *out) +{ + ctx->dn_hash_impl->init(&ctx->dn_hash.vtable); + ctx->dn_hash_impl->update(&ctx->dn_hash.vtable, dn, len); + ctx->dn_hash_impl->out(&ctx->dn_hash.vtable, out); +} + +/* + * Compare two big integers for equality. The integers use unsigned big-endian + * encoding; extra leading bytes (of value 0) are allowed. + */ +static int +eqbigint(const unsigned char *b1, size_t len1, + const unsigned char *b2, size_t len2) +{ + while (len1 > 0 && *b1 == 0) { + b1 ++; + len1 --; + } + while (len2 > 0 && *b2 == 0) { + b2 ++; + len2 --; + } + if (len1 != len2) { + return 0; + } + return memcmp(b1, b2, len1) == 0; +} + +/* + * Compare two strings for equality, in a case-insensitive way. This + * function handles casing only for ASCII letters. + */ +static int +eqnocase(const void *s1, const void *s2, size_t len) +{ + const unsigned char *buf1, *buf2; + + buf1 = s1; + buf2 = s2; + while (len -- > 0) { + int x1, x2; + + x1 = *buf1 ++; + x2 = *buf2 ++; + if (x1 >= 'A' && x1 <= 'Z') { + x1 += 'a' - 'A'; + } + if (x2 >= 'A' && x2 <= 'Z') { + x2 += 'a' - 'A'; + } + if (x1 != x2) { + return 0; + } + } + return 1; +} + +static int verify_signature(br_x509_minimal_context *ctx, + const br_x509_pkey *pk); + + + +static const unsigned char t0_datablock[] = { + 0x00, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, 0x09, + 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x05, 0x09, 0x2A, 0x86, + 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0E, 0x09, 0x2A, 0x86, 0x48, 0x86, + 0xF7, 0x0D, 0x01, 0x01, 0x0B, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, + 0x01, 0x01, 0x0C, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, + 0x0D, 0x05, 0x2B, 0x0E, 0x03, 0x02, 0x1A, 0x09, 0x60, 0x86, 0x48, 0x01, + 0x65, 0x03, 0x04, 0x02, 0x04, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, + 0x04, 0x02, 0x01, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, + 0x02, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03, 0x07, + 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x02, 0x01, 0x08, 0x2A, 0x86, 0x48, 0xCE, + 0x3D, 0x03, 0x01, 0x07, 0x05, 0x2B, 0x81, 0x04, 0x00, 0x22, 0x05, 0x2B, + 0x81, 0x04, 0x00, 0x23, 0x07, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x04, 0x01, + 0x08, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x04, 0x03, 0x01, 0x08, 0x2A, 0x86, + 0x48, 0xCE, 0x3D, 0x04, 0x03, 0x02, 0x08, 0x2A, 0x86, 0x48, 0xCE, 0x3D, + 0x04, 0x03, 0x03, 0x08, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x04, 0x03, 0x04, + 0x03, 0x55, 0x04, 0x03, 0x00, 0x1F, 0x03, 0xFC, 0x07, 0x7F, 0x0B, 0x5E, + 0x0F, 0x1F, 0x12, 0xFE, 0x16, 0xBF, 0x1A, 0x9F, 0x1E, 0x7E, 0x22, 0x3F, + 0x26, 0x1E, 0x29, 0xDF, 0x00, 0x1F, 0x03, 0xFD, 0x07, 0x9F, 0x0B, 0x7E, + 0x0F, 0x3F, 0x13, 0x1E, 0x16, 0xDF, 0x1A, 0xBF, 0x1E, 0x9E, 0x22, 0x5F, + 0x26, 0x3E, 0x29, 0xFF, 0x03, 0x55, 0x1D, 0x13, 0x03, 0x55, 0x1D, 0x0F, + 0x03, 0x55, 0x1D, 0x11, 0x03, 0x55, 0x1D, 0x20, 0x08, 0x2B, 0x06, 0x01, + 0x05, 0x05, 0x07, 0x02, 0x01, 0x03, 0x55, 0x1D, 0x23, 0x03, 0x55, 0x1D, + 0x0E, 0x03, 0x55, 0x1D, 0x12, 0x03, 0x55, 0x1D, 0x09, 0x03, 0x55, 0x1D, + 0x1F, 0x03, 0x55, 0x1D, 0x2E, 0x08, 0x2B, 0x06, 0x01, 0x05, 0x05, 0x07, + 0x01, 0x01, 0x08, 0x2B, 0x06, 0x01, 0x05, 0x05, 0x07, 0x01, 0x0B +}; + +static const unsigned char t0_codeblock[] = { + 0x00, 0x01, 0x00, 0x0D, 0x00, 0x00, 0x01, 0x00, 0x10, 0x00, 0x00, 0x01, + 0x00, 0x11, 0x00, 0x00, 0x01, 0x01, 0x09, 0x00, 0x00, 0x01, 0x01, 0x0A, + 0x00, 0x00, 0x24, 0x24, 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_X509_BAD_BOOLEAN), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_X509_BAD_DN), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_X509_BAD_SERVER_NAME), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_X509_BAD_TAG_CLASS), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_X509_BAD_TAG_VALUE), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_X509_BAD_TIME), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_X509_CRITICAL_EXTENSION), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_X509_DN_MISMATCH), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_X509_EXPIRED), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_X509_EXTRA_ELEMENT), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_X509_FORBIDDEN_KEY_USAGE), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_X509_INDEFINITE_LENGTH), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_X509_INNER_TRUNC), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_X509_LIMIT_EXCEEDED), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_X509_NOT_CA), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_X509_NOT_CONSTRUCTED), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_X509_NOT_PRIMITIVE), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_X509_OVERFLOW), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_X509_PARTIAL_BYTE), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_X509_UNEXPECTED), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_X509_UNSUPPORTED), 0x00, 0x00, 0x01, + T0_INT1(BR_ERR_X509_WEAK_PUBLIC_KEY), 0x00, 0x00, 0x01, + T0_INT1(BR_KEYTYPE_EC), 0x00, 0x00, 0x01, T0_INT1(BR_KEYTYPE_RSA), + 0x00, 0x00, 0x01, T0_INT2(offsetof(CONTEXT_NAME, cert_length)), 0x00, + 0x00, 0x01, T0_INT2(offsetof(CONTEXT_NAME, cert_sig)), 0x00, 0x00, + 0x01, T0_INT2(offsetof(CONTEXT_NAME, cert_sig_hash_len)), 0x00, 0x00, + 0x01, T0_INT2(offsetof(CONTEXT_NAME, cert_sig_hash_oid)), 0x00, 0x00, + 0x01, T0_INT2(offsetof(CONTEXT_NAME, cert_sig_len)), 0x00, 0x00, 0x01, + T0_INT2(offsetof(CONTEXT_NAME, cert_signer_key_type)), 0x00, 0x00, + 0x01, T0_INT2(offsetof(CONTEXT_NAME, current_dn_hash)), 0x00, 0x00, + 0x01, T0_INT2(offsetof(CONTEXT_NAME, key_usages)), 0x00, 0x00, 0x01, + T0_INT2(offsetof(br_x509_minimal_context, pkey_data)), 0x01, + T0_INT2(BR_X509_BUFSIZE_KEY), 0x00, 0x00, 0x01, + T0_INT2(offsetof(CONTEXT_NAME, min_rsa_size)), 0x00, 0x00, 0x01, + T0_INT2(offsetof(CONTEXT_NAME, next_dn_hash)), 0x00, 0x00, 0x01, + T0_INT2(offsetof(CONTEXT_NAME, num_certs)), 0x00, 0x00, 0x01, + T0_INT2(offsetof(CONTEXT_NAME, pad)), 0x00, 0x00, 0x01, + T0_INT2(offsetof(CONTEXT_NAME, saved_dn_hash)), 0x00, 0x00, 0xC9, 0x71, + 0x00, 0x00, 0x01, 0x80, 0x73, 0x00, 0x00, 0x01, 0x80, 0x7C, 0x00, 0x00, + 0x01, 0x81, 0x02, 0x00, 0x00, 0x92, 0x05, 0x05, 0x34, 0x42, 0x01, 0x00, + 0x00, 0x34, 0x01, 0x0A, 0x0E, 0x09, 0x01, 0x9A, 0xFF, 0xB8, 0x00, 0x0A, + 0x00, 0x00, 0x01, 0x82, 0x19, 0x00, 0x00, 0x01, 0x82, 0x01, 0x00, 0x00, + 0x01, 0x81, 0x68, 0x00, 0x04, 0x03, 0x00, 0x03, 0x01, 0x03, 0x02, 0x03, + 0x03, 0x02, 0x03, 0x02, 0x01, 0x11, 0x06, 0x07, 0x02, 0x02, 0x02, 0x00, + 0x0D, 0x04, 0x05, 0x02, 0x03, 0x02, 0x01, 0x0D, 0x00, 0x02, 0x03, 0x00, + 0x03, 0x01, 0x25, 0x02, 0x01, 0x13, 0x3B, 0x02, 0x00, 0x0F, 0x15, 0x00, + 0x00, 0x01, 0x81, 0x74, 0x00, 0x00, 0x05, 0x02, 0x52, 0x28, 0x00, 0x00, + 0x06, 0x02, 0x53, 0x28, 0x00, 0x00, 0x01, 0x10, 0x77, 0x00, 0x00, 0x11, + 0x05, 0x02, 0x56, 0x28, 0x74, 0x00, 0x00, 0x11, 0x05, 0x02, 0x56, 0x28, + 0x75, 0x00, 0x00, 0x06, 0x02, 0x4C, 0x28, 0x00, 0x00, 0x01, 0x82, 0x11, + 0x00, 0x00, 0x25, 0x20, 0x01, 0x08, 0x0E, 0x3B, 0x40, 0x20, 0x09, 0x00, + 0x09, 0x03, 0x00, 0x5B, 0x2B, 0xAF, 0x39, 0xAF, 0xB3, 0x25, 0x01, 0x20, + 0x11, 0x06, 0x11, 0x24, 0x74, 0xAD, 0xB3, 0x01, 0x02, 0x78, 0xB0, 0x01, + 0x02, 0x12, 0x06, 0x02, 0x57, 0x28, 0x79, 0xB3, 0x01, 0x02, 0x78, 0xAE, + 0xAF, 0xC2, 0x9C, 0x65, 0x61, 0x21, 0x16, 0xAF, 0xA7, 0x29, 0x69, 0x06, + 0x02, 0x4B, 0x28, 0xA7, 0x29, 0x71, 0x06, 0x02, 0x4B, 0x28, 0x79, 0x02, + 0x00, 0x06, 0x05, 0x9D, 0x03, 0x01, 0x04, 0x09, 0x9C, 0x61, 0x68, 0x21, + 0x27, 0x05, 0x02, 0x4A, 0x28, 0x68, 0x65, 0x21, 0x16, 0xAF, 0xAF, 0x9E, + 0x05, 0x02, 0x57, 0x28, 0xBC, 0x26, 0x06, 0x27, 0xC2, 0xA4, 0xAF, 0x63, + 0xAA, 0x03, 0x03, 0x63, 0x3B, 0x02, 0x03, 0x09, 0x3B, 0x02, 0x03, 0x0A, + 0xAA, 0x03, 0x04, 0x79, 0x64, 0x2A, 0x01, 0x81, 0x00, 0x09, 0x02, 0x03, + 0x12, 0x06, 0x02, 0x58, 0x28, 0x79, 0x5A, 0x03, 0x02, 0x04, 0x3A, 0x88, + 0x26, 0x06, 0x34, 0x9E, 0x05, 0x02, 0x57, 0x28, 0x6A, 0x26, 0x06, 0x04, + 0x01, 0x17, 0x04, 0x12, 0x6B, 0x26, 0x06, 0x04, 0x01, 0x18, 0x04, 0x0A, + 0x6C, 0x26, 0x06, 0x04, 0x01, 0x19, 0x04, 0x02, 0x57, 0x28, 0x03, 0x05, + 0x79, 0xA4, 0x25, 0x03, 0x06, 0x25, 0x63, 0x34, 0x0D, 0x06, 0x02, 0x50, + 0x28, 0xA5, 0x59, 0x03, 0x02, 0x04, 0x02, 0x57, 0x28, 0x79, 0x02, 0x00, + 0x06, 0x21, 0x02, 0x02, 0x5A, 0x30, 0x11, 0x06, 0x08, 0x24, 0x02, 0x03, + 0x02, 0x04, 0x1D, 0x04, 0x10, 0x59, 0x30, 0x11, 0x06, 0x08, 0x24, 0x02, + 0x05, 0x02, 0x06, 0x1C, 0x04, 0x03, 0x57, 0x28, 0x24, 0x04, 0x24, 0x02, + 0x02, 0x5A, 0x30, 0x11, 0x06, 0x08, 0x24, 0x02, 0x03, 0x02, 0x04, 0x23, + 0x04, 0x10, 0x59, 0x30, 0x11, 0x06, 0x08, 0x24, 0x02, 0x05, 0x02, 0x06, + 0x22, 0x04, 0x03, 0x57, 0x28, 0x24, 0x25, 0x06, 0x01, 0x28, 0x24, 0x01, + 0x00, 0x03, 0x07, 0xB4, 0x01, 0x21, 0x8F, 0x01, 0x22, 0x8F, 0x25, 0x01, + 0x23, 0x11, 0x06, 0x81, 0x26, 0x24, 0x74, 0xAD, 0xAF, 0x25, 0x06, 0x81, + 0x1A, 0x01, 0x00, 0x03, 0x08, 0xAF, 0x9E, 0x24, 0xB3, 0x25, 0x01, 0x01, + 0x11, 0x06, 0x04, 0xA6, 0x03, 0x08, 0xB3, 0x01, 0x04, 0x78, 0xAD, 0x70, + 0x26, 0x06, 0x0F, 0x02, 0x00, 0x06, 0x03, 0xC3, 0x04, 0x05, 0x99, 0x01, + 0x7F, 0x03, 0x07, 0x04, 0x80, 0x6C, 0x91, 0x26, 0x06, 0x06, 0x02, 0x00, + 0x9B, 0x04, 0x80, 0x62, 0xC5, 0x26, 0x06, 0x11, 0x02, 0x00, 0x06, 0x09, + 0x01, 0x00, 0x03, 0x01, 0x98, 0x03, 0x01, 0x04, 0x01, 0xC3, 0x04, 0x80, + 0x4D, 0x73, 0x26, 0x06, 0x0A, 0x02, 0x08, 0x06, 0x03, 0x9A, 0x04, 0x01, + 0xC3, 0x04, 0x3F, 0x6F, 0x26, 0x06, 0x03, 0xC3, 0x04, 0x38, 0xC8, 0x26, + 0x06, 0x03, 0xC3, 0x04, 0x31, 0x90, 0x26, 0x06, 0x03, 0xC3, 0x04, 0x2A, + 0xC6, 0x26, 0x06, 0x03, 0xC3, 0x04, 0x23, 0x7A, 0x26, 0x06, 0x03, 0xC3, + 0x04, 0x1C, 0x85, 0x26, 0x06, 0x03, 0xC3, 0x04, 0x15, 0x6E, 0x26, 0x06, + 0x03, 0xC3, 0x04, 0x0E, 0xC7, 0x26, 0x06, 0x03, 0xC3, 0x04, 0x07, 0x02, + 0x08, 0x06, 0x02, 0x49, 0x28, 0xC3, 0x79, 0x79, 0x04, 0xFE, 0x62, 0x79, + 0x79, 0x04, 0x08, 0x01, 0x7F, 0x11, 0x05, 0x02, 0x56, 0x28, 0x24, 0x79, + 0x3A, 0x02, 0x00, 0x06, 0x08, 0x02, 0x01, 0x3C, 0x2F, 0x05, 0x02, 0x45, + 0x28, 0x02, 0x00, 0x06, 0x01, 0x17, 0x02, 0x00, 0x02, 0x07, 0x2F, 0x05, + 0x02, 0x51, 0x28, 0xB3, 0x76, 0xAD, 0x9E, 0x06, 0x80, 0x77, 0xBD, 0x26, + 0x06, 0x07, 0x01, 0x02, 0x5A, 0x8A, 0x04, 0x80, 0x5E, 0xBE, 0x26, 0x06, + 0x07, 0x01, 0x03, 0x5A, 0x8B, 0x04, 0x80, 0x53, 0xBF, 0x26, 0x06, 0x07, + 0x01, 0x04, 0x5A, 0x8C, 0x04, 0x80, 0x48, 0xC0, 0x26, 0x06, 0x06, 0x01, + 0x05, 0x5A, 0x8D, 0x04, 0x3E, 0xC1, 0x26, 0x06, 0x06, 0x01, 0x06, 0x5A, + 0x8E, 0x04, 0x34, 0x7F, 0x26, 0x06, 0x06, 0x01, 0x02, 0x59, 0x8A, 0x04, + 0x2A, 0x80, 0x26, 0x06, 0x06, 0x01, 0x03, 0x59, 0x8B, 0x04, 0x20, 0x81, + 0x26, 0x06, 0x06, 0x01, 0x04, 0x59, 0x8C, 0x04, 0x16, 0x82, 0x26, 0x06, + 0x06, 0x01, 0x05, 0x59, 0x8D, 0x04, 0x0C, 0x83, 0x26, 0x06, 0x06, 0x01, + 0x06, 0x59, 0x8E, 0x04, 0x02, 0x57, 0x28, 0x5E, 0x35, 0x60, 0x37, 0x1B, + 0x25, 0x05, 0x02, 0x57, 0x28, 0x5D, 0x37, 0x04, 0x02, 0x57, 0x28, 0xC2, + 0xA4, 0x25, 0x01, T0_INT2(BR_X509_BUFSIZE_SIG), 0x12, 0x06, 0x02, 0x50, + 0x28, 0x25, 0x5F, 0x35, 0x5C, 0xA5, 0x79, 0x79, 0x01, 0x00, 0x5B, 0x36, + 0x18, 0x00, 0x00, 0x01, 0x30, 0x0A, 0x25, 0x01, 0x00, 0x01, 0x09, 0x72, + 0x05, 0x02, 0x48, 0x28, 0x00, 0x00, 0x30, 0x30, 0x00, 0x00, 0x01, 0x81, + 0x08, 0x00, 0x00, 0x01, 0x81, 0x10, 0x00, 0x00, 0x01, 0x81, 0x19, 0x00, + 0x00, 0x01, 0x81, 0x22, 0x00, 0x00, 0x01, 0x81, 0x2B, 0x00, 0x01, 0x7E, + 0x01, 0x01, 0x11, 0x3B, 0x01, 0x83, 0xFD, 0x7F, 0x11, 0x15, 0x06, 0x03, + 0x3B, 0x24, 0x00, 0x3B, 0x25, 0x03, 0x00, 0x25, 0xCA, 0x05, 0x04, 0x42, + 0x01, 0x00, 0x00, 0x25, 0x01, 0x81, 0x00, 0x0D, 0x06, 0x04, 0x96, 0x04, + 0x80, 0x49, 0x25, 0x01, 0x90, 0x00, 0x0D, 0x06, 0x0F, 0x01, 0x06, 0x14, + 0x01, 0x81, 0x40, 0x2F, 0x96, 0x02, 0x00, 0x01, 0x00, 0x97, 0x04, 0x33, + 0x25, 0x01, 0x83, 0xFF, 0x7F, 0x0D, 0x06, 0x14, 0x01, 0x0C, 0x14, 0x01, + 0x81, 0x60, 0x2F, 0x96, 0x02, 0x00, 0x01, 0x06, 0x97, 0x02, 0x00, 0x01, + 0x00, 0x97, 0x04, 0x17, 0x01, 0x12, 0x14, 0x01, 0x81, 0x70, 0x2F, 0x96, + 0x02, 0x00, 0x01, 0x0C, 0x97, 0x02, 0x00, 0x01, 0x06, 0x97, 0x02, 0x00, + 0x01, 0x00, 0x97, 0x00, 0x00, 0x01, 0x82, 0x15, 0x00, 0x00, 0x25, 0x01, + 0x83, 0xB0, 0x00, 0x01, 0x83, 0xB7, 0x7F, 0x72, 0x00, 0x00, 0x01, 0x81, + 0x34, 0x00, 0x00, 0x01, 0x80, 0x6B, 0x00, 0x00, 0x01, 0x81, 0x78, 0x00, + 0x00, 0x01, 0x3D, 0x00, 0x00, 0x01, 0x80, 0x43, 0x00, 0x00, 0x01, 0x80, + 0x4D, 0x00, 0x00, 0x01, 0x80, 0x57, 0x00, 0x00, 0x01, 0x80, 0x61, 0x00, + 0x00, 0x30, 0x11, 0x06, 0x04, 0x42, 0xAD, 0xC2, 0xB4, 0x00, 0x00, 0x01, + 0x82, 0x09, 0x00, 0x00, 0x01, 0x81, 0x6C, 0x00, 0x00, 0x25, 0x01, 0x83, + 0xB8, 0x00, 0x01, 0x83, 0xBF, 0x7F, 0x72, 0x00, 0x00, 0x01, 0x30, 0x62, + 0x37, 0x01, 0x7F, 0x7C, 0x19, 0x01, 0x00, 0x7C, 0x19, 0x04, 0x7A, 0x00, + 0x01, 0x81, 0x38, 0x00, 0x01, 0x7E, 0x0D, 0x06, 0x02, 0x4F, 0x28, 0x25, + 0x03, 0x00, 0x0A, 0x02, 0x00, 0x00, 0x00, 0x30, 0x25, 0x3F, 0x3B, 0x01, + 0x82, 0x00, 0x13, 0x2F, 0x06, 0x04, 0x42, 0x01, 0x00, 0x00, 0x30, 0x67, + 0x09, 0x37, 0x40, 0x00, 0x00, 0x14, 0x01, 0x3F, 0x15, 0x01, 0x81, 0x00, + 0x2F, 0x96, 0x00, 0x02, 0x01, 0x00, 0x03, 0x00, 0xAF, 0x25, 0x06, 0x80, + 0x59, 0xB3, 0x01, 0x20, 0x30, 0x11, 0x06, 0x17, 0x24, 0x74, 0xAD, 0x9E, + 0x24, 0x01, 0x7F, 0x2E, 0x03, 0x01, 0xB3, 0x01, 0x20, 0x77, 0xAD, 0xB2, + 0x02, 0x01, 0x1F, 0x79, 0x79, 0x04, 0x38, 0x01, 0x21, 0x30, 0x11, 0x06, + 0x08, 0x24, 0x75, 0xB6, 0x01, 0x01, 0x1E, 0x04, 0x2A, 0x01, 0x22, 0x30, + 0x11, 0x06, 0x11, 0x24, 0x75, 0xB6, 0x25, 0x06, 0x06, 0x2C, 0x02, 0x00, + 0x2F, 0x03, 0x00, 0x01, 0x02, 0x1E, 0x04, 0x13, 0x01, 0x26, 0x30, 0x11, + 0x06, 0x08, 0x24, 0x75, 0xB6, 0x01, 0x06, 0x1E, 0x04, 0x05, 0x42, 0xAE, + 0x01, 0x00, 0x24, 0x04, 0xFF, 0x23, 0x79, 0x02, 0x00, 0x00, 0x00, 0xAF, + 0xB4, 0x25, 0x01, 0x01, 0x11, 0x06, 0x08, 0xA6, 0x05, 0x02, 0x51, 0x28, + 0xB4, 0x04, 0x02, 0x51, 0x28, 0x25, 0x01, 0x02, 0x11, 0x06, 0x0C, 0x24, + 0x75, 0xB0, 0x66, 0x2B, 0x41, 0x0D, 0x06, 0x02, 0x51, 0x28, 0xB4, 0x01, + 0x7F, 0x10, 0x06, 0x02, 0x56, 0x28, 0x24, 0x79, 0x00, 0x00, 0xAF, 0x25, + 0x06, 0x1A, 0xAF, 0x9E, 0x24, 0x25, 0x06, 0x11, 0xAF, 0x25, 0x06, 0x0C, + 0xAF, 0x9E, 0x24, 0x89, 0x26, 0x05, 0x02, 0x49, 0x28, 0xC2, 0x04, 0x71, + 0x79, 0x79, 0x04, 0x63, 0x79, 0x00, 0x02, 0x03, 0x00, 0xB3, 0x01, 0x03, + 0x78, 0xAD, 0xBA, 0x03, 0x01, 0x02, 0x01, 0x01, 0x07, 0x12, 0x06, 0x02, + 0x56, 0x28, 0x25, 0x01, 0x00, 0x30, 0x11, 0x06, 0x05, 0x24, 0x4D, 0x28, + 0x04, 0x15, 0x01, 0x01, 0x30, 0x11, 0x06, 0x0A, 0x24, 0xBA, 0x02, 0x01, + 0x14, 0x02, 0x01, 0x0E, 0x04, 0x05, 0x24, 0xBA, 0x01, 0x00, 0x24, 0x02, + 0x00, 0x06, 0x19, 0x01, 0x00, 0x30, 0x01, 0x38, 0x15, 0x06, 0x03, 0x01, + 0x10, 0x2F, 0x3B, 0x01, 0x81, 0x40, 0x15, 0x06, 0x03, 0x01, 0x20, 0x2F, + 0x62, 0x37, 0x04, 0x07, 0x01, 0x04, 0x15, 0x05, 0x02, 0x4D, 0x28, 0xC2, + 0x00, 0x00, 0x38, 0xAF, 0xC2, 0x1A, 0x00, 0x03, 0x01, 0x00, 0x03, 0x00, + 0x38, 0xAF, 0x25, 0x06, 0x30, 0xB3, 0x01, 0x11, 0x77, 0xAD, 0x25, 0x05, + 0x02, 0x44, 0x28, 0x25, 0x06, 0x20, 0xAF, 0x9E, 0x24, 0x87, 0x26, 0x03, + 0x01, 0x01, 0x00, 0x2E, 0x03, 0x02, 0xB2, 0x25, 0x02, 0x01, 0x15, 0x06, + 0x07, 0x2C, 0x06, 0x04, 0x01, 0x7F, 0x03, 0x00, 0x02, 0x02, 0x1F, 0x79, + 0x04, 0x5D, 0x79, 0x04, 0x4D, 0x79, 0x1A, 0x02, 0x00, 0x00, 0x00, 0xB3, + 0x01, 0x06, 0x78, 0xB1, 0x00, 0x00, 0xB8, 0x86, 0x06, 0x0E, 0x3B, 0x25, + 0x05, 0x06, 0x42, 0x01, 0x00, 0x01, 0x00, 0x00, 0xB8, 0x6D, 0x04, 0x08, + 0x92, 0x06, 0x05, 0x24, 0x01, 0x00, 0x04, 0x00, 0x00, 0x00, 0xB9, 0x86, + 0x06, 0x0E, 0x3B, 0x25, 0x05, 0x06, 0x42, 0x01, 0x00, 0x01, 0x00, 0x00, + 0xB9, 0x6D, 0x04, 0x08, 0x92, 0x06, 0x05, 0x24, 0x01, 0x00, 0x04, 0x00, + 0x00, 0x00, 0xBA, 0x25, 0x01, 0x81, 0x00, 0x0D, 0x06, 0x04, 0x00, 0x04, + 0x80, 0x55, 0x25, 0x01, 0x81, 0x40, 0x0D, 0x06, 0x07, 0x24, 0x01, 0x00, + 0x00, 0x04, 0x80, 0x47, 0x25, 0x01, 0x81, 0x60, 0x0D, 0x06, 0x0E, 0x01, + 0x1F, 0x15, 0x01, 0x01, 0xA3, 0x01, 0x81, 0x00, 0x01, 0x8F, 0x7F, 0x04, + 0x32, 0x25, 0x01, 0x81, 0x70, 0x0D, 0x06, 0x0F, 0x01, 0x0F, 0x15, 0x01, + 0x02, 0xA3, 0x01, 0x90, 0x00, 0x01, 0x83, 0xFF, 0x7F, 0x04, 0x1C, 0x25, + 0x01, 0x81, 0x78, 0x0D, 0x06, 0x11, 0x01, 0x07, 0x15, 0x01, 0x03, 0xA3, + 0x01, 0x84, 0x80, 0x00, 0x01, 0x80, 0xC3, 0xFF, 0x7F, 0x04, 0x04, 0x24, + 0x01, 0x00, 0x00, 0x72, 0x05, 0x03, 0x24, 0x01, 0x00, 0x00, 0x00, 0x3B, + 0x25, 0x05, 0x06, 0x42, 0x01, 0x00, 0x01, 0x7F, 0x00, 0xBA, 0x34, 0x25, + 0x3D, 0x06, 0x03, 0x3B, 0x24, 0x00, 0x01, 0x06, 0x0E, 0x3B, 0x25, 0x01, + 0x06, 0x14, 0x01, 0x02, 0x10, 0x06, 0x04, 0x42, 0x01, 0x7F, 0x00, 0x01, + 0x3F, 0x15, 0x09, 0x00, 0x00, 0x25, 0x06, 0x06, 0x0B, 0xA2, 0x34, 0x41, + 0x04, 0x77, 0x24, 0x25, 0x00, 0x00, 0xB3, 0x01, 0x03, 0x78, 0xAD, 0xBA, + 0x06, 0x02, 0x55, 0x28, 0x00, 0x00, 0x3B, 0x25, 0x06, 0x07, 0x31, 0x25, + 0x06, 0x01, 0x19, 0x04, 0x76, 0x42, 0x00, 0x00, 0x01, 0x01, 0x78, 0xAC, + 0x01, 0x01, 0x10, 0x06, 0x02, 0x43, 0x28, 0xBA, 0x3E, 0x00, 0x04, 0xB3, + 0x25, 0x01, 0x17, 0x01, 0x18, 0x72, 0x05, 0x02, 0x48, 0x28, 0x01, 0x18, + 0x11, 0x03, 0x00, 0x75, 0xAD, 0xA8, 0x02, 0x00, 0x06, 0x0C, 0x01, 0x80, + 0x64, 0x08, 0x03, 0x01, 0xA8, 0x02, 0x01, 0x09, 0x04, 0x0E, 0x25, 0x01, + 0x32, 0x0D, 0x06, 0x04, 0x01, 0x80, 0x64, 0x09, 0x01, 0x8E, 0x6C, 0x09, + 0x03, 0x01, 0x02, 0x01, 0x01, 0x82, 0x6D, 0x08, 0x02, 0x01, 0x01, 0x03, + 0x09, 0x01, 0x04, 0x0C, 0x09, 0x02, 0x01, 0x01, 0x80, 0x63, 0x09, 0x01, + 0x80, 0x64, 0x0C, 0x0A, 0x02, 0x01, 0x01, 0x83, 0x0F, 0x09, 0x01, 0x83, + 0x10, 0x0C, 0x09, 0x03, 0x03, 0x01, 0x01, 0x01, 0x0C, 0xA9, 0x41, 0x01, + 0x01, 0x0E, 0x02, 0x01, 0x01, 0x04, 0x07, 0x3F, 0x02, 0x01, 0x01, 0x80, + 0x64, 0x07, 0x3E, 0x02, 0x01, 0x01, 0x83, 0x10, 0x07, 0x3F, 0x2F, 0x15, + 0x06, 0x03, 0x01, 0x18, 0x09, 0x94, 0x09, 0x7B, 0x25, 0x01, 0x05, 0x14, + 0x02, 0x03, 0x09, 0x03, 0x03, 0x01, 0x1F, 0x15, 0x01, 0x01, 0x3B, 0xA9, + 0x02, 0x03, 0x09, 0x41, 0x03, 0x03, 0x01, 0x00, 0x01, 0x17, 0xA9, 0x01, + 0x9C, 0x10, 0x08, 0x03, 0x02, 0x01, 0x00, 0x01, 0x3B, 0xA9, 0x01, 0x3C, + 0x08, 0x02, 0x02, 0x09, 0x03, 0x02, 0x01, 0x00, 0x01, 0x3C, 0xA9, 0x02, + 0x02, 0x09, 0x03, 0x02, 0xBA, 0x25, 0x01, 0x2E, 0x11, 0x06, 0x0D, 0x24, + 0xBA, 0x25, 0x01, 0x30, 0x01, 0x39, 0x72, 0x06, 0x03, 0x24, 0x04, 0x74, + 0x01, 0x80, 0x5A, 0x10, 0x06, 0x02, 0x48, 0x28, 0x79, 0x02, 0x03, 0x02, + 0x02, 0x00, 0x01, 0xBA, 0x7D, 0x01, 0x0A, 0x08, 0x03, 0x00, 0xBA, 0x7D, + 0x02, 0x00, 0x09, 0x00, 0x02, 0x03, 0x00, 0x03, 0x01, 0xA8, 0x25, 0x02, + 0x01, 0x02, 0x00, 0x72, 0x05, 0x02, 0x48, 0x28, 0x00, 0x00, 0x34, 0xB3, + 0x01, 0x02, 0x78, 0x0B, 0xAB, 0x00, 0x03, 0x25, 0x03, 0x00, 0x03, 0x01, + 0x03, 0x02, 0xAD, 0xBA, 0x25, 0x01, 0x81, 0x00, 0x13, 0x06, 0x02, 0x54, + 0x28, 0x25, 0x01, 0x00, 0x11, 0x06, 0x0B, 0x24, 0x25, 0x05, 0x04, 0x24, + 0x01, 0x00, 0x00, 0xBA, 0x04, 0x6F, 0x02, 0x01, 0x25, 0x05, 0x02, 0x50, + 0x28, 0x41, 0x03, 0x01, 0x02, 0x02, 0x37, 0x02, 0x02, 0x40, 0x03, 0x02, + 0x25, 0x06, 0x03, 0xBA, 0x04, 0x68, 0x24, 0x02, 0x00, 0x02, 0x01, 0x0A, + 0x00, 0x01, 0xBA, 0x25, 0x01, 0x81, 0x00, 0x0D, 0x06, 0x01, 0x00, 0x01, + 0x81, 0x00, 0x0A, 0x25, 0x05, 0x02, 0x4E, 0x28, 0x03, 0x00, 0x01, 0x00, + 0x02, 0x00, 0x01, 0x00, 0x12, 0x06, 0x19, 0x02, 0x00, 0x41, 0x03, 0x00, + 0x25, 0x01, 0x83, 0xFF, 0xFF, 0x7F, 0x12, 0x06, 0x02, 0x4F, 0x28, 0x01, + 0x08, 0x0E, 0x3B, 0xBA, 0x34, 0x09, 0x04, 0x60, 0x00, 0x00, 0xAC, 0x95, + 0x00, 0x00, 0xAD, 0xC2, 0x00, 0x00, 0xB3, 0x76, 0xAD, 0x00, 0x01, 0xAD, + 0x25, 0x05, 0x02, 0x54, 0x28, 0xBA, 0x25, 0x01, 0x81, 0x00, 0x13, 0x06, + 0x02, 0x54, 0x28, 0x03, 0x00, 0x25, 0x06, 0x16, 0xBA, 0x02, 0x00, 0x25, + 0x01, 0x87, 0xFF, 0xFF, 0x7F, 0x13, 0x06, 0x02, 0x54, 0x28, 0x01, 0x08, + 0x0E, 0x09, 0x03, 0x00, 0x04, 0x67, 0x24, 0x02, 0x00, 0x00, 0x00, 0xAD, + 0x25, 0x01, 0x81, 0x7F, 0x12, 0x06, 0x08, 0xC2, 0x01, 0x00, 0x67, 0x37, + 0x01, 0x00, 0x00, 0x25, 0x67, 0x37, 0x67, 0x40, 0xA5, 0x01, 0x7F, 0x00, + 0x00, 0xB3, 0x01, 0x0C, 0x30, 0x11, 0x06, 0x05, 0x24, 0x75, 0xB6, 0x04, + 0x3E, 0x01, 0x12, 0x30, 0x11, 0x06, 0x05, 0x24, 0x75, 0xB7, 0x04, 0x33, + 0x01, 0x13, 0x30, 0x11, 0x06, 0x05, 0x24, 0x75, 0xB7, 0x04, 0x28, 0x01, + 0x14, 0x30, 0x11, 0x06, 0x05, 0x24, 0x75, 0xB7, 0x04, 0x1D, 0x01, 0x16, + 0x30, 0x11, 0x06, 0x05, 0x24, 0x75, 0xB7, 0x04, 0x12, 0x01, 0x1E, 0x30, + 0x11, 0x06, 0x05, 0x24, 0x75, 0xB5, 0x04, 0x07, 0x42, 0xAE, 0x01, 0x00, + 0x01, 0x00, 0x24, 0x00, 0x01, 0xBA, 0x03, 0x00, 0x02, 0x00, 0x01, 0x05, + 0x14, 0x01, 0x01, 0x15, 0x2D, 0x02, 0x00, 0x01, 0x06, 0x14, 0x25, 0x01, + 0x01, 0x15, 0x06, 0x02, 0x46, 0x28, 0x01, 0x04, 0x0E, 0x02, 0x00, 0x01, + 0x1F, 0x15, 0x25, 0x01, 0x1F, 0x11, 0x06, 0x02, 0x47, 0x28, 0x09, 0x00, + 0x00, 0x25, 0x05, 0x05, 0x01, 0x00, 0x01, 0x7F, 0x00, 0xB3, 0x00, 0x01, + 0xAD, 0x25, 0x05, 0x05, 0x67, 0x37, 0x01, 0x7F, 0x00, 0x01, 0x01, 0x03, + 0x00, 0x9F, 0x25, 0x01, 0x83, 0xFF, 0x7E, 0x11, 0x06, 0x16, 0x24, 0x25, + 0x06, 0x10, 0xA0, 0x25, 0x05, 0x05, 0x24, 0xC2, 0x01, 0x00, 0x00, 0x02, + 0x00, 0x84, 0x03, 0x00, 0x04, 0x6D, 0x04, 0x1B, 0x25, 0x05, 0x05, 0x24, + 0xC2, 0x01, 0x00, 0x00, 0x02, 0x00, 0x84, 0x03, 0x00, 0x25, 0x06, 0x0B, + 0x9F, 0x25, 0x05, 0x05, 0x24, 0xC2, 0x01, 0x00, 0x00, 0x04, 0x6D, 0x24, + 0x02, 0x00, 0x25, 0x05, 0x01, 0x00, 0x41, 0x67, 0x37, 0x01, 0x7F, 0x00, + 0x01, 0xAD, 0x01, 0x01, 0x03, 0x00, 0x25, 0x06, 0x10, 0xA1, 0x25, 0x05, + 0x05, 0x24, 0xC2, 0x01, 0x00, 0x00, 0x02, 0x00, 0x84, 0x03, 0x00, 0x04, + 0x6D, 0x24, 0x02, 0x00, 0x25, 0x05, 0x01, 0x00, 0x41, 0x67, 0x37, 0x01, + 0x7F, 0x00, 0x01, 0xAD, 0x01, 0x01, 0x03, 0x00, 0x25, 0x06, 0x10, 0xBA, + 0x25, 0x05, 0x05, 0x24, 0xC2, 0x01, 0x00, 0x00, 0x02, 0x00, 0x84, 0x03, + 0x00, 0x04, 0x6D, 0x24, 0x02, 0x00, 0x25, 0x05, 0x01, 0x00, 0x41, 0x67, + 0x37, 0x01, 0x7F, 0x00, 0x00, 0xBA, 0x01, 0x08, 0x0E, 0x3B, 0xBA, 0x34, + 0x09, 0x00, 0x00, 0xBA, 0x3B, 0xBA, 0x01, 0x08, 0x0E, 0x34, 0x09, 0x00, + 0x00, 0x25, 0x05, 0x02, 0x4F, 0x28, 0x41, 0xBB, 0x00, 0x00, 0x32, 0x25, + 0x01, 0x00, 0x13, 0x06, 0x01, 0x00, 0x24, 0x19, 0x04, 0x74, 0x00, 0x01, + 0x01, 0x00, 0x00, 0x01, 0x0B, 0x00, 0x00, 0x01, 0x15, 0x00, 0x00, 0x01, + 0x1F, 0x00, 0x00, 0x01, 0x29, 0x00, 0x00, 0x01, 0x33, 0x00, 0x00, 0xC3, + 0x24, 0x00, 0x00, 0x25, 0x06, 0x07, 0xC4, 0x25, 0x06, 0x01, 0x19, 0x04, + 0x76, 0x00, 0x00, 0x01, 0x00, 0x30, 0x31, 0x0B, 0x42, 0x00, 0x00, 0x01, + 0x81, 0x70, 0x00, 0x00, 0x01, 0x82, 0x0D, 0x00, 0x00, 0x01, 0x82, 0x22, + 0x00, 0x00, 0x01, 0x82, 0x05, 0x00, 0x00, 0x01, 0x03, 0x33, 0x01, 0x03, + 0x33, 0x00, 0x00, 0x25, 0x01, 0x83, 0xFB, 0x50, 0x01, 0x83, 0xFB, 0x6F, + 0x72, 0x06, 0x04, 0x24, 0x01, 0x00, 0x00, 0x25, 0x01, 0x83, 0xB0, 0x00, + 0x01, 0x83, 0xBF, 0x7F, 0x72, 0x06, 0x04, 0x24, 0x01, 0x00, 0x00, 0x01, + 0x83, 0xFF, 0x7F, 0x15, 0x01, 0x83, 0xFF, 0x7E, 0x0D, 0x00 +}; + +static const uint16_t t0_caddr[] = { + 0, + 5, + 10, + 15, + 20, + 25, + 29, + 33, + 37, + 41, + 45, + 49, + 53, + 57, + 61, + 65, + 69, + 73, + 77, + 81, + 85, + 89, + 93, + 97, + 101, + 105, + 109, + 113, + 117, + 121, + 125, + 130, + 135, + 140, + 145, + 150, + 155, + 160, + 165, + 173, + 178, + 183, + 188, + 193, + 198, + 202, + 207, + 212, + 217, + 238, + 243, + 248, + 253, + 282, + 297, + 302, + 308, + 314, + 319, + 327, + 335, + 341, + 346, + 357, + 992, + 1007, + 1011, + 1016, + 1021, + 1026, + 1031, + 1036, + 1150, + 1155, + 1167, + 1172, + 1177, + 1182, + 1186, + 1191, + 1196, + 1201, + 1206, + 1216, + 1221, + 1226, + 1238, + 1253, + 1258, + 1272, + 1294, + 1305, + 1408, + 1455, + 1488, + 1579, + 1585, + 1648, + 1655, + 1683, + 1711, + 1816, + 1858, + 1871, + 1883, + 1897, + 1912, + 2132, + 2146, + 2163, + 2172, + 2239, + 2295, + 2299, + 2303, + 2308, + 2356, + 2382, + 2458, + 2502, + 2513, + 2598, + 2636, + 2674, + 2684, + 2694, + 2703, + 2716, + 2720, + 2724, + 2728, + 2732, + 2736, + 2740, + 2744, + 2756, + 2764, + 2769, + 2774, + 2779, + 2784, + 2792 +}; + +#define T0_INTERPRETED 61 + +#define T0_ENTER(ip, rp, slot) do { \ + const unsigned char *t0_newip; \ + uint32_t t0_lnum; \ + t0_newip = &t0_codeblock[t0_caddr[(slot) - T0_INTERPRETED]]; \ + t0_lnum = t0_parse7E_unsigned(&t0_newip); \ + (rp) += t0_lnum; \ + *((rp) ++) = (uint32_t)((ip) - &t0_codeblock[0]) + (t0_lnum << 16); \ + (ip) = t0_newip; \ + } while (0) + +#define T0_DEFENTRY(name, slot) \ +void \ +name(void *ctx) \ +{ \ + t0_context *t0ctx = ctx; \ + t0ctx->ip = &t0_codeblock[0]; \ + T0_ENTER(t0ctx->ip, t0ctx->rp, slot); \ +} + +T0_DEFENTRY(br_x509_minimal_init_main, 147) + +#define T0_NEXT(t0ipp) (*(*(t0ipp)) ++) + +void +br_x509_minimal_run(void *t0ctx) +{ + uint32_t *dp, *rp; + const unsigned char *ip; + +#define T0_LOCAL(x) (*(rp - 2 - (x))) +#define T0_POP() (*-- dp) +#define T0_POPi() (*(int32_t *)(-- dp)) +#define T0_PEEK(x) (*(dp - 1 - (x))) +#define T0_PEEKi(x) (*(int32_t *)(dp - 1 - (x))) +#define T0_PUSH(v) do { *dp = (v); dp ++; } while (0) +#define T0_PUSHi(v) do { *(int32_t *)dp = (v); dp ++; } while (0) +#define T0_RPOP() (*-- rp) +#define T0_RPOPi() (*(int32_t *)(-- rp)) +#define T0_RPUSH(v) do { *rp = (v); rp ++; } while (0) +#define T0_RPUSHi(v) do { *(int32_t *)rp = (v); rp ++; } while (0) +#define T0_ROLL(x) do { \ + size_t t0len = (size_t)(x); \ + uint32_t t0tmp = *(dp - 1 - t0len); \ + memmove(dp - t0len - 1, dp - t0len, t0len * sizeof *dp); \ + *(dp - 1) = t0tmp; \ +} while (0) +#define T0_SWAP() do { \ + uint32_t t0tmp = *(dp - 2); \ + *(dp - 2) = *(dp - 1); \ + *(dp - 1) = t0tmp; \ +} while (0) +#define T0_ROT() do { \ + uint32_t t0tmp = *(dp - 3); \ + *(dp - 3) = *(dp - 2); \ + *(dp - 2) = *(dp - 1); \ + *(dp - 1) = t0tmp; \ +} while (0) +#define T0_NROT() do { \ + uint32_t t0tmp = *(dp - 1); \ + *(dp - 1) = *(dp - 2); \ + *(dp - 2) = *(dp - 3); \ + *(dp - 3) = t0tmp; \ +} while (0) +#define T0_PICK(x) do { \ + uint32_t t0depth = (x); \ + T0_PUSH(T0_PEEK(t0depth)); \ +} while (0) +#define T0_CO() do { \ + goto t0_exit; \ +} while (0) +#define T0_RET() goto t0_next + + dp = ((t0_context *)t0ctx)->dp; + rp = ((t0_context *)t0ctx)->rp; + ip = ((t0_context *)t0ctx)->ip; + goto t0_next; + for (;;) { + uint32_t t0x; + + t0_next: + t0x = T0_NEXT(&ip); + if (t0x < T0_INTERPRETED) { + switch (t0x) { + int32_t t0off; + + case 0: /* ret */ + t0x = T0_RPOP(); + rp -= (t0x >> 16); + t0x &= 0xFFFF; + if (t0x == 0) { + ip = NULL; + goto t0_exit; + } + ip = &t0_codeblock[t0x]; + break; + case 1: /* literal constant */ + T0_PUSHi(t0_parse7E_signed(&ip)); + break; + case 2: /* read local */ + T0_PUSH(T0_LOCAL(t0_parse7E_unsigned(&ip))); + break; + case 3: /* write local */ + T0_LOCAL(t0_parse7E_unsigned(&ip)) = T0_POP(); + break; + case 4: /* jump */ + t0off = t0_parse7E_signed(&ip); + ip += t0off; + break; + case 5: /* jump if */ + t0off = t0_parse7E_signed(&ip); + if (T0_POP()) { + ip += t0off; + } + break; + case 6: /* jump if not */ + t0off = t0_parse7E_signed(&ip); + if (!T0_POP()) { + ip += t0off; + } + break; + case 7: { + /* %25 */ + + int32_t b = T0_POPi(); + int32_t a = T0_POPi(); + T0_PUSHi(a % b); + + } + break; + case 8: { + /* * */ + + uint32_t b = T0_POP(); + uint32_t a = T0_POP(); + T0_PUSH(a * b); + + } + break; + case 9: { + /* + */ + + uint32_t b = T0_POP(); + uint32_t a = T0_POP(); + T0_PUSH(a + b); + + } + break; + case 10: { + /* - */ + + uint32_t b = T0_POP(); + uint32_t a = T0_POP(); + T0_PUSH(a - b); + + } + break; + case 11: { + /* -rot */ + T0_NROT(); + } + break; + case 12: { + /* / */ + + int32_t b = T0_POPi(); + int32_t a = T0_POPi(); + T0_PUSHi(a / b); + + } + break; + case 13: { + /* < */ + + int32_t b = T0_POPi(); + int32_t a = T0_POPi(); + T0_PUSH(-(uint32_t)(a < b)); + + } + break; + case 14: { + /* << */ + + int c = (int)T0_POPi(); + uint32_t x = T0_POP(); + T0_PUSH(x << c); + + } + break; + case 15: { + /* <= */ + + int32_t b = T0_POPi(); + int32_t a = T0_POPi(); + T0_PUSH(-(uint32_t)(a <= b)); + + } + break; + case 16: { + /* <> */ + + uint32_t b = T0_POP(); + uint32_t a = T0_POP(); + T0_PUSH(-(uint32_t)(a != b)); + + } + break; + case 17: { + /* = */ + + uint32_t b = T0_POP(); + uint32_t a = T0_POP(); + T0_PUSH(-(uint32_t)(a == b)); + + } + break; + case 18: { + /* > */ + + int32_t b = T0_POPi(); + int32_t a = T0_POPi(); + T0_PUSH(-(uint32_t)(a > b)); + + } + break; + case 19: { + /* >= */ + + int32_t b = T0_POPi(); + int32_t a = T0_POPi(); + T0_PUSH(-(uint32_t)(a >= b)); + + } + break; + case 20: { + /* >> */ + + int c = (int)T0_POPi(); + int32_t x = T0_POPi(); + T0_PUSHi(x >> c); + + } + break; + case 21: { + /* and */ + + uint32_t b = T0_POP(); + uint32_t a = T0_POP(); + T0_PUSH(a & b); + + } + break; + case 22: { + /* blobcopy */ + + size_t len = T0_POP(); + unsigned char *src = (unsigned char *)CTX + T0_POP(); + unsigned char *dst = (unsigned char *)CTX + T0_POP(); + memcpy(dst, src, len); + + } + break; + case 23: { + /* check-direct-trust */ + + size_t u; + + for (u = 0; u < CTX->trust_anchors_num; u ++) { + const br_x509_trust_anchor *ta; + unsigned char hashed_DN[64]; + int kt; + + ta = &CTX->trust_anchors[u]; + if (ta->flags & BR_X509_TA_CA) { + continue; + } + hash_dn(CTX, ta->dn.data, ta->dn.len, hashed_DN); + if (memcmp(hashed_DN, CTX->current_dn_hash, DNHASH_LEN)) { + continue; + } + kt = CTX->pkey.key_type; + if ((ta->pkey.key_type & 0x0F) != kt) { + continue; + } + switch (kt) { + + case BR_KEYTYPE_RSA: + if (!eqbigint(CTX->pkey.key.rsa.n, + CTX->pkey.key.rsa.nlen, + ta->pkey.key.rsa.n, + ta->pkey.key.rsa.nlen) + || !eqbigint(CTX->pkey.key.rsa.e, + CTX->pkey.key.rsa.elen, + ta->pkey.key.rsa.e, + ta->pkey.key.rsa.elen)) + { + continue; + } + break; + + case BR_KEYTYPE_EC: + if (CTX->pkey.key.ec.curve != ta->pkey.key.ec.curve + || CTX->pkey.key.ec.qlen != ta->pkey.key.ec.qlen + || memcmp(CTX->pkey.key.ec.q, + ta->pkey.key.ec.q, + ta->pkey.key.ec.qlen) != 0) + { + continue; + } + break; + + default: + continue; + } + + /* + * Direct trust match! + */ + CTX->err = BR_ERR_X509_OK; + T0_CO(); + } + + } + break; + case 24: { + /* check-trust-anchor-CA */ + + size_t u; + + for (u = 0; u < CTX->trust_anchors_num; u ++) { + const br_x509_trust_anchor *ta; + unsigned char hashed_DN[64]; + + ta = &CTX->trust_anchors[u]; + if (!(ta->flags & BR_X509_TA_CA)) { + continue; + } + hash_dn(CTX, ta->dn.data, ta->dn.len, hashed_DN); + if (memcmp(hashed_DN, CTX->saved_dn_hash, DNHASH_LEN)) { + continue; + } + if (verify_signature(CTX, &ta->pkey) == 0) { + CTX->err = BR_ERR_X509_OK; + T0_CO(); + } + } + + } + break; + case 25: { + /* co */ + T0_CO(); + } + break; + case 26: { + /* compute-dn-hash */ + + CTX->dn_hash_impl->out(&CTX->dn_hash.vtable, CTX->current_dn_hash); + CTX->do_dn_hash = 0; + + } + break; + case 27: { + /* compute-tbs-hash */ + + int id = T0_POPi(); + size_t len; + len = br_multihash_out(&CTX->mhash, id, CTX->tbs_hash); + T0_PUSH(len); + + } + break; + case 28: { + /* copy-ee-ec-pkey */ + + size_t qlen = T0_POP(); + uint32_t curve = T0_POP(); + memcpy(CTX->ee_pkey_data, CTX->pkey_data, qlen); + CTX->pkey.key_type = BR_KEYTYPE_EC; + CTX->pkey.key.ec.curve = curve; + CTX->pkey.key.ec.q = CTX->ee_pkey_data; + CTX->pkey.key.ec.qlen = qlen; + + } + break; + case 29: { + /* copy-ee-rsa-pkey */ + + size_t elen = T0_POP(); + size_t nlen = T0_POP(); + memcpy(CTX->ee_pkey_data, CTX->pkey_data, nlen + elen); + CTX->pkey.key_type = BR_KEYTYPE_RSA; + CTX->pkey.key.rsa.n = CTX->ee_pkey_data; + CTX->pkey.key.rsa.nlen = nlen; + CTX->pkey.key.rsa.e = CTX->ee_pkey_data + nlen; + CTX->pkey.key.rsa.elen = elen; + + } + break; + case 30: { + /* copy-name-SAN */ + + unsigned tag = T0_POP(); + unsigned ok = T0_POP(); + size_t u, len; + + len = CTX->pad[0]; + for (u = 0; u < CTX->num_name_elts; u ++) { + br_name_element *ne; + + ne = &CTX->name_elts[u]; + if (ne->status == 0 && ne->oid[0] == 0 && ne->oid[1] == tag) { + if (ok && ne->len > len) { + memcpy(ne->buf, CTX->pad + 1, len); + ne->buf[len] = 0; + ne->status = 1; + } else { + ne->status = -1; + } + break; + } + } + + } + break; + case 31: { + /* copy-name-element */ + + size_t len; + int32_t off = T0_POPi(); + int ok = T0_POPi(); + + if (off >= 0) { + br_name_element *ne = &CTX->name_elts[off]; + + if (ok) { + len = CTX->pad[0]; + if (len < ne->len) { + memcpy(ne->buf, CTX->pad + 1, len); + ne->buf[len] = 0; + ne->status = 1; + } else { + ne->status = -1; + } + } else { + ne->status = -1; + } + } + + } + break; + case 32: { + /* data-get8 */ + + size_t addr = T0_POP(); + T0_PUSH(t0_datablock[addr]); + + } + break; + case 33: { + /* dn-hash-length */ + + T0_PUSH(DNHASH_LEN); + + } + break; + case 34: { + /* do-ecdsa-vrfy */ + + size_t qlen = T0_POP(); + int curve = T0_POP(); + br_x509_pkey pk; + + pk.key_type = BR_KEYTYPE_EC; + pk.key.ec.curve = curve; + pk.key.ec.q = CTX->pkey_data; + pk.key.ec.qlen = qlen; + T0_PUSH(verify_signature(CTX, &pk)); + + } + break; + case 35: { + /* do-rsa-vrfy */ + + size_t elen = T0_POP(); + size_t nlen = T0_POP(); + br_x509_pkey pk; + + pk.key_type = BR_KEYTYPE_RSA; + pk.key.rsa.n = CTX->pkey_data; + pk.key.rsa.nlen = nlen; + pk.key.rsa.e = CTX->pkey_data + nlen; + pk.key.rsa.elen = elen; + T0_PUSH(verify_signature(CTX, &pk)); + + } + break; + case 36: { + /* drop */ + (void)T0_POP(); + } + break; + case 37: { + /* dup */ + T0_PUSH(T0_PEEK(0)); + } + break; + case 38: { + /* eqOID */ + + const unsigned char *a2 = &t0_datablock[T0_POP()]; + const unsigned char *a1 = &CTX->pad[0]; + size_t len = a1[0]; + int x; + if (len == a2[0]) { + x = -(memcmp(a1 + 1, a2 + 1, len) == 0); + } else { + x = 0; + } + T0_PUSH((uint32_t)x); + + } + break; + case 39: { + /* eqblob */ + + size_t len = T0_POP(); + const unsigned char *a2 = (const unsigned char *)CTX + T0_POP(); + const unsigned char *a1 = (const unsigned char *)CTX + T0_POP(); + T0_PUSHi(-(memcmp(a1, a2, len) == 0)); + + } + break; + case 40: { + /* fail */ + + CTX->err = T0_POPi(); + T0_CO(); + + } + break; + case 41: { + /* get-system-date */ + + if (CTX->days == 0 && CTX->seconds == 0) { +#if BR_USE_UNIX_TIME + time_t x = time(NULL); + + T0_PUSH((uint32_t)(x / 86400) + 719528); + T0_PUSH((uint32_t)(x % 86400)); +#elif BR_USE_WIN32_TIME + FILETIME ft; + uint64_t x; + + GetSystemTimeAsFileTime(&ft); + x = ((uint64_t)ft.dwHighDateTime << 32) + + (uint64_t)ft.dwLowDateTime; + x = (x / 10000000); + T0_PUSH((uint32_t)(x / 86400) + 584754); + T0_PUSH((uint32_t)(x % 86400)); +#else + CTX->err = BR_ERR_X509_TIME_UNKNOWN; + T0_CO(); +#endif + } else { + T0_PUSH(CTX->days); + T0_PUSH(CTX->seconds); + } + + } + break; + case 42: { + /* get16 */ + + uint32_t addr = T0_POP(); + T0_PUSH(*(uint16_t *)(void *)((unsigned char *)CTX + addr)); + + } + break; + case 43: { + /* get32 */ + + uint32_t addr = T0_POP(); + T0_PUSH(*(uint32_t *)(void *)((unsigned char *)CTX + addr)); + + } + break; + case 44: { + /* match-server-name */ + + size_t n1, n2; + + if (CTX->server_name == NULL) { + T0_PUSH(0); + T0_RET(); + } + n1 = strlen(CTX->server_name); + n2 = CTX->pad[0]; + if (n1 == n2 && eqnocase(&CTX->pad[1], CTX->server_name, n1)) { + T0_PUSHi(-1); + T0_RET(); + } + if (n2 >= 2 && CTX->pad[1] == '*' && CTX->pad[2] == '.') { + size_t u; + + u = 0; + while (u < n1 && CTX->server_name[u] != '.') { + u ++; + } + u ++; + n1 -= u; + if ((n2 - 2) == n1 + && eqnocase(&CTX->pad[3], CTX->server_name + u, n1)) + { + T0_PUSHi(-1); + T0_RET(); + } + } + T0_PUSH(0); + + } + break; + case 45: { + /* neg */ + + uint32_t a = T0_POP(); + T0_PUSH(-a); + + } + break; + case 46: { + /* offset-name-element */ + + unsigned san = T0_POP(); + size_t u; + + for (u = 0; u < CTX->num_name_elts; u ++) { + if (CTX->name_elts[u].status == 0) { + const unsigned char *oid; + size_t len, off; + + oid = CTX->name_elts[u].oid; + if (san) { + if (oid[0] != 0 || oid[1] != 0) { + continue; + } + off = 2; + } else { + off = 0; + } + len = oid[off]; + if (len != 0 && len == CTX->pad[0] + && memcmp(oid + off + 1, + CTX->pad + 1, len) == 0) + { + T0_PUSH(u); + T0_RET(); + } + } + } + T0_PUSHi(-1); + + } + break; + case 47: { + /* or */ + + uint32_t b = T0_POP(); + uint32_t a = T0_POP(); + T0_PUSH(a | b); + + } + break; + case 48: { + /* over */ + T0_PUSH(T0_PEEK(1)); + } + break; + case 49: { + /* read-blob-inner */ + + uint32_t len = T0_POP(); + uint32_t addr = T0_POP(); + size_t clen = CTX->hlen; + if (clen > len) { + clen = (size_t)len; + } + if (addr != 0) { + memcpy((unsigned char *)CTX + addr, CTX->hbuf, clen); + } + if (CTX->do_mhash) { + br_multihash_update(&CTX->mhash, CTX->hbuf, clen); + } + if (CTX->do_dn_hash) { + CTX->dn_hash_impl->update( + &CTX->dn_hash.vtable, CTX->hbuf, clen); + } + CTX->hbuf += clen; + CTX->hlen -= clen; + T0_PUSH(addr + clen); + T0_PUSH(len - clen); + + } + break; + case 50: { + /* read8-low */ + + if (CTX->hlen == 0) { + T0_PUSHi(-1); + } else { + unsigned char x = *CTX->hbuf ++; + if (CTX->do_mhash) { + br_multihash_update(&CTX->mhash, &x, 1); + } + if (CTX->do_dn_hash) { + CTX->dn_hash_impl->update(&CTX->dn_hash.vtable, &x, 1); + } + CTX->hlen --; + T0_PUSH(x); + } + + } + break; + case 51: { + /* roll */ + T0_ROLL(T0_POP()); + } + break; + case 52: { + /* rot */ + T0_ROT(); + } + break; + case 53: { + /* set16 */ + + uint32_t addr = T0_POP(); + *(uint16_t *)(void *)((unsigned char *)CTX + addr) = T0_POP(); + + } + break; + case 54: { + /* set32 */ + + uint32_t addr = T0_POP(); + *(uint32_t *)(void *)((unsigned char *)CTX + addr) = T0_POP(); + + } + break; + case 55: { + /* set8 */ + + uint32_t addr = T0_POP(); + *((unsigned char *)CTX + addr) = (unsigned char)T0_POP(); + + } + break; + case 56: { + /* start-dn-hash */ + + CTX->dn_hash_impl->init(&CTX->dn_hash.vtable); + CTX->do_dn_hash = 1; + + } + break; + case 57: { + /* start-tbs-hash */ + + br_multihash_init(&CTX->mhash); + CTX->do_mhash = 1; + + } + break; + case 58: { + /* stop-tbs-hash */ + + CTX->do_mhash = 0; + + } + break; + case 59: { + /* swap */ + T0_SWAP(); + } + break; + case 60: { + /* zero-server-name */ + + T0_PUSHi(-(CTX->server_name == NULL)); + + } + break; + } + + } else { + T0_ENTER(ip, rp, t0x); + } + } +t0_exit: + ((t0_context *)t0ctx)->dp = dp; + ((t0_context *)t0ctx)->rp = rp; + ((t0_context *)t0ctx)->ip = ip; +} + + + +/* + * Verify the signature on the certificate with the provided public key. + * This function checks the public key type with regards to the expected + * type. Returned value is either 0 on success, or a non-zero error code. + */ +static int +verify_signature(br_x509_minimal_context *ctx, const br_x509_pkey *pk) +{ + int kt; + + kt = ctx->cert_signer_key_type; + if ((pk->key_type & 0x0F) != kt) { + return BR_ERR_X509_WRONG_KEY_TYPE; + } + switch (kt) { + unsigned char tmp[64]; + + case BR_KEYTYPE_RSA: + if (ctx->irsa == 0) { + return BR_ERR_X509_UNSUPPORTED; + } + if (!ctx->irsa(ctx->cert_sig, ctx->cert_sig_len, + &t0_datablock[ctx->cert_sig_hash_oid], + ctx->cert_sig_hash_len, &pk->key.rsa, tmp)) + { + return BR_ERR_X509_BAD_SIGNATURE; + } + if (memcmp(ctx->tbs_hash, tmp, ctx->cert_sig_hash_len) != 0) { + return BR_ERR_X509_BAD_SIGNATURE; + } + return 0; + + case BR_KEYTYPE_EC: + if (ctx->iecdsa == 0) { + return BR_ERR_X509_UNSUPPORTED; + } + if (!ctx->iecdsa(ctx->iec, ctx->tbs_hash, + ctx->cert_sig_hash_len, &pk->key.ec, + ctx->cert_sig, ctx->cert_sig_len)) + { + return BR_ERR_X509_BAD_SIGNATURE; + } + return 0; + + default: + return BR_ERR_X509_UNSUPPORTED; + } +} + + + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/x509_minimal.t0 b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/x509_minimal.t0 new file mode 100644 index 000000000..50995dcb9 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/x509_minimal.t0 @@ -0,0 +1,1508 @@ +\ Copyright (c) 2016 Thomas Pornin +\ +\ Permission is hereby granted, free of charge, to any person obtaining +\ a copy of this software and associated documentation files (the +\ "Software"), to deal in the Software without restriction, including +\ without limitation the rights to use, copy, modify, merge, publish, +\ distribute, sublicense, and/or sell copies of the Software, and to +\ permit persons to whom the Software is furnished to do so, subject to +\ the following conditions: +\ +\ The above copyright notice and this permission notice shall be +\ included in all copies or substantial portions of the Software. +\ +\ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +\ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +\ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +\ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +\ BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +\ ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +\ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +\ SOFTWARE. + +preamble { + +#include "inner.h" + +/* + * Implementation Notes + * -------------------- + * + * The C code pushes the data by chunks; all decoding is done in the + * T0 code. The cert_length value is set to the certificate length when + * a new certificate is started; the T0 code picks it up as outer limit, + * and decoding functions use it to ensure that no attempt is made at + * reading past it. The T0 code also checks that once the certificate is + * decoded, there are no trailing bytes. + * + * The T0 code sets cert_length to 0 when the certificate is fully + * decoded. + * + * The C code must still perform two checks: + * + * -- If the certificate length is 0, then the T0 code will not be + * invoked at all. This invalid condition must thus be reported by the + * C code. + * + * -- When reaching the end of certificate, the C code must verify that + * the certificate length has been set to 0, thereby signaling that + * the T0 code properly decoded a certificate. + * + * Processing of a chain works in the following way: + * + * -- The error flag is set to a non-zero value when validation is + * finished. The value is either BR_ERR_X509_OK (validation is + * successful) or another non-zero error code. When a non-zero error + * code is obtained, the remaining bytes in the current certificate and + * the subsequent certificates (if any) are completely ignored. + * + * -- Each certificate is decoded in due course, with the following + * "interesting points": + * + * -- Start of the TBS: the multihash engine is reset and activated. + * + * -- Start of the issuer DN: the secondary hash engine is started, + * to process the encoded issuer DN. + * + * -- End of the issuer DN: the secondary hash engine is stopped. The + * resulting hash value is computed and then copied into the + * next_dn_hash[] buffer. + * + * -- Start of the subject DN: the secondary hash engine is started, + * to process the encoded subject DN. + * + * -- For the EE certificate only: the Common Name, if any, is matched + * against the expected server name. + * + * -- End of the subject DN: the secondary hash engine is stopped. The + * resulting hash value is computed into the pad. It is then processed: + * + * -- If this is the EE certificate, then the hash is ignored + * (except for direct trust processing, see later; the hash is + * simply left in current_dn_hash[]). + * + * -- Otherwise, the hashed subject DN is compared with the saved + * hash value (in saved_dn_hash[]). They must match. + * + * Either way, the next_dn_hash[] value is then copied into the + * saved_dn_hash[] value. Thus, at that point, saved_dn_hash[] + * contains the hash of the issuer DN for the current certificate, + * and current_dn_hash[] contains the hash of the subject DN for the + * current certificate. + * + * -- Public key: it is decoded into the cert_pkey[] buffer. Unknown + * key types are reported at that point. + * + * -- If this is the EE certificate, then the key type is compared + * with the expected key type (initialization parameter). The public + * key data is copied to ee_pkey_data[]. The key and hashed subject + * DN are also compared with the "direct trust" keys; if the key + * and DN are matched, then validation ends with a success. + * + * -- Otherwise, the saved signature (cert_sig[]) is verified + * against the saved TBS hash (tbs_hash[]) and that freshly + * decoded public key. Failure here ends validation with an error. + * + * -- Extensions: extension values are processed in due order. + * + * -- Basic Constraints: for all certificates except EE, must be + * present, indicate a CA, and have a path length compatible with + * the chain length so far. + * + * -- Key Usage: for the EE, if present, must allow signatures + * or encryption/key exchange, as required for the cipher suite. + * For non-EE, if present, must have the "certificate sign" bit. + * + * -- Subject Alt Name: for the EE, dNSName names are matched + * against the server name. Ignored for non-EE. + * + * -- Authority Key Identifier, Subject Key Identifier, Issuer + * Alt Name, Subject Directory Attributes, CRL Distribution Points + * Freshest CRL, Authority Info Access and Subject Info Access + * extensions are always ignored: they either contain only + * informative data, or they relate to revocation processing, which + * we explicitly do not support. + * + * -- All other extensions are ignored if non-critical. If a + * critical extension other than the ones above is encountered, + * then a failure is reported. + * + * -- End of the TBS: the multihash engine is stopped. + * + * -- Signature algorithm: the signature algorithm on the + * certificate is decoded. A failure is reported if that algorithm + * is unknown. The hashed TBS corresponding to the signature hash + * function is computed and stored in tbs_hash[] (if not supported, + * then a failure is reported). The hash OID and length are stored + * in cert_sig_hash_oid and cert_sig_hash_len. + * + * -- Signature value: the signature value is copied into the + * cert_sig[] array. + * + * -- Certificate end: the hashed issuer DN (saved_dn_hash[]) is + * looked up in the trust store (CA trust anchors only); for all + * that match, the signature (cert_sig[]) is verified against the + * anchor public key (hashed TBS is in tbs_hash[]). If one of these + * signatures is valid, then validation ends with a success. + * + * -- If the chain end is reached without obtaining a validation success, + * then validation is reported as failed. + */ + +#if BR_USE_UNIX_TIME +#include +#endif + +#if BR_USE_WIN32_TIME +#include +#endif + +/* + * The T0 compiler will produce these prototypes declarations in the + * header. + * +void br_x509_minimal_init_main(void *ctx); +void br_x509_minimal_run(void *ctx); + */ + +/* see bearssl_x509.h */ +void +br_x509_minimal_init(br_x509_minimal_context *ctx, + const br_hash_class *dn_hash_impl, + const br_x509_trust_anchor *trust_anchors, size_t trust_anchors_num) +{ + memset(ctx, 0, sizeof *ctx); + ctx->vtable = &br_x509_minimal_vtable; + ctx->dn_hash_impl = dn_hash_impl; + ctx->trust_anchors = trust_anchors; + ctx->trust_anchors_num = trust_anchors_num; +} + +static void +xm_start_chain(const br_x509_class **ctx, const char *server_name) +{ + br_x509_minimal_context *cc; + size_t u; + + cc = (br_x509_minimal_context *)(void *)ctx; + for (u = 0; u < cc->num_name_elts; u ++) { + cc->name_elts[u].status = 0; + cc->name_elts[u].buf[0] = 0; + } + memset(&cc->pkey, 0, sizeof cc->pkey); + cc->num_certs = 0; + cc->err = 0; + cc->cpu.dp = cc->dp_stack; + cc->cpu.rp = cc->rp_stack; + br_x509_minimal_init_main(&cc->cpu); + if (server_name == NULL || *server_name == 0) { + cc->server_name = NULL; + } else { + cc->server_name = server_name; + } +} + +static void +xm_start_cert(const br_x509_class **ctx, uint32_t length) +{ + br_x509_minimal_context *cc; + + cc = (br_x509_minimal_context *)(void *)ctx; + if (cc->err != 0) { + return; + } + if (length == 0) { + cc->err = BR_ERR_X509_TRUNCATED; + return; + } + cc->cert_length = length; +} + +static void +xm_append(const br_x509_class **ctx, const unsigned char *buf, size_t len) +{ + br_x509_minimal_context *cc; + + cc = (br_x509_minimal_context *)(void *)ctx; + if (cc->err != 0) { + return; + } + cc->hbuf = buf; + cc->hlen = len; + br_x509_minimal_run(&cc->cpu); +} + +static void +xm_end_cert(const br_x509_class **ctx) +{ + br_x509_minimal_context *cc; + + cc = (br_x509_minimal_context *)(void *)ctx; + if (cc->err == 0 && cc->cert_length != 0) { + cc->err = BR_ERR_X509_TRUNCATED; + } + cc->num_certs ++; +} + +static unsigned +xm_end_chain(const br_x509_class **ctx) +{ + br_x509_minimal_context *cc; + + cc = (br_x509_minimal_context *)(void *)ctx; + if (cc->err == 0) { + if (cc->num_certs == 0) { + cc->err = BR_ERR_X509_EMPTY_CHAIN; + } else { + cc->err = BR_ERR_X509_NOT_TRUSTED; + } + } else if (cc->err == BR_ERR_X509_OK) { + return 0; + } + return (unsigned)cc->err; +} + +static const br_x509_pkey * +xm_get_pkey(const br_x509_class *const *ctx, unsigned *usages) +{ + br_x509_minimal_context *cc; + + cc = (br_x509_minimal_context *)(void *)ctx; + if (cc->err == BR_ERR_X509_OK + || cc->err == BR_ERR_X509_NOT_TRUSTED) + { + if (usages != NULL) { + *usages = cc->key_usages; + } + return &((br_x509_minimal_context *)(void *)ctx)->pkey; + } else { + return NULL; + } +} + +/* see bearssl_x509.h */ +const br_x509_class br_x509_minimal_vtable = { + sizeof(br_x509_minimal_context), + xm_start_chain, + xm_start_cert, + xm_append, + xm_end_cert, + xm_end_chain, + xm_get_pkey +}; + +#define CTX ((br_x509_minimal_context *)(void *)((unsigned char *)t0ctx - offsetof(br_x509_minimal_context, cpu))) +#define CONTEXT_NAME br_x509_minimal_context + +#define DNHASH_LEN ((CTX->dn_hash_impl->desc >> BR_HASHDESC_OUT_OFF) & BR_HASHDESC_OUT_MASK) + +/* + * Hash a DN (from a trust anchor) into the provided buffer. This uses the + * DN hash implementation and context structure from the X.509 engine + * context. + */ +static void +hash_dn(br_x509_minimal_context *ctx, const void *dn, size_t len, + unsigned char *out) +{ + ctx->dn_hash_impl->init(&ctx->dn_hash.vtable); + ctx->dn_hash_impl->update(&ctx->dn_hash.vtable, dn, len); + ctx->dn_hash_impl->out(&ctx->dn_hash.vtable, out); +} + +/* + * Compare two big integers for equality. The integers use unsigned big-endian + * encoding; extra leading bytes (of value 0) are allowed. + */ +static int +eqbigint(const unsigned char *b1, size_t len1, + const unsigned char *b2, size_t len2) +{ + while (len1 > 0 && *b1 == 0) { + b1 ++; + len1 --; + } + while (len2 > 0 && *b2 == 0) { + b2 ++; + len2 --; + } + if (len1 != len2) { + return 0; + } + return memcmp(b1, b2, len1) == 0; +} + +/* + * Compare two strings for equality, in a case-insensitive way. This + * function handles casing only for ASCII letters. + */ +static int +eqnocase(const void *s1, const void *s2, size_t len) +{ + const unsigned char *buf1, *buf2; + + buf1 = s1; + buf2 = s2; + while (len -- > 0) { + int x1, x2; + + x1 = *buf1 ++; + x2 = *buf2 ++; + if (x1 >= 'A' && x1 <= 'Z') { + x1 += 'a' - 'A'; + } + if (x2 >= 'A' && x2 <= 'Z') { + x2 += 'a' - 'A'; + } + if (x1 != x2) { + return 0; + } + } + return 1; +} + +static int verify_signature(br_x509_minimal_context *ctx, + const br_x509_pkey *pk); + +} + +postamble { + +/* + * Verify the signature on the certificate with the provided public key. + * This function checks the public key type with regards to the expected + * type. Returned value is either 0 on success, or a non-zero error code. + */ +static int +verify_signature(br_x509_minimal_context *ctx, const br_x509_pkey *pk) +{ + int kt; + + kt = ctx->cert_signer_key_type; + if ((pk->key_type & 0x0F) != kt) { + return BR_ERR_X509_WRONG_KEY_TYPE; + } + switch (kt) { + unsigned char tmp[64]; + + case BR_KEYTYPE_RSA: + if (ctx->irsa == 0) { + return BR_ERR_X509_UNSUPPORTED; + } + if (!ctx->irsa(ctx->cert_sig, ctx->cert_sig_len, + &t0_datablock[ctx->cert_sig_hash_oid], + ctx->cert_sig_hash_len, &pk->key.rsa, tmp)) + { + return BR_ERR_X509_BAD_SIGNATURE; + } + if (memcmp(ctx->tbs_hash, tmp, ctx->cert_sig_hash_len) != 0) { + return BR_ERR_X509_BAD_SIGNATURE; + } + return 0; + + case BR_KEYTYPE_EC: + if (ctx->iecdsa == 0) { + return BR_ERR_X509_UNSUPPORTED; + } + if (!ctx->iecdsa(ctx->iec, ctx->tbs_hash, + ctx->cert_sig_hash_len, &pk->key.ec, + ctx->cert_sig, ctx->cert_sig_len)) + { + return BR_ERR_X509_BAD_SIGNATURE; + } + return 0; + + default: + return BR_ERR_X509_UNSUPPORTED; + } +} + +} + +cc: read8-low ( -- x ) { + if (CTX->hlen == 0) { + T0_PUSHi(-1); + } else { + unsigned char x = *CTX->hbuf ++; + if (CTX->do_mhash) { + br_multihash_update(&CTX->mhash, &x, 1); + } + if (CTX->do_dn_hash) { + CTX->dn_hash_impl->update(&CTX->dn_hash.vtable, &x, 1); + } + CTX->hlen --; + T0_PUSH(x); + } +} + +addr: cert_length +addr: num_certs + +cc: read-blob-inner ( addr len -- addr len ) { + uint32_t len = T0_POP(); + uint32_t addr = T0_POP(); + size_t clen = CTX->hlen; + if (clen > len) { + clen = (size_t)len; + } + if (addr != 0) { + memcpy((unsigned char *)CTX + addr, CTX->hbuf, clen); + } + if (CTX->do_mhash) { + br_multihash_update(&CTX->mhash, CTX->hbuf, clen); + } + if (CTX->do_dn_hash) { + CTX->dn_hash_impl->update( + &CTX->dn_hash.vtable, CTX->hbuf, clen); + } + CTX->hbuf += clen; + CTX->hlen -= clen; + T0_PUSH(addr + clen); + T0_PUSH(len - clen); +} + +\ Compute the TBS hash, using the provided hash ID. The hash value is +\ written in the tbs_hash[] array, and the hash length is returned. If +\ the requested hash function is not supported, then 0 is returned. +cc: compute-tbs-hash ( id -- hashlen ) { + int id = T0_POPi(); + size_t len; + len = br_multihash_out(&CTX->mhash, id, CTX->tbs_hash); + T0_PUSH(len); +} + +\ Push true (-1) if no server name is expected in the EE certificate. +cc: zero-server-name ( -- bool ) { + T0_PUSHi(-(CTX->server_name == NULL)); +} + +addr: key_usages +addr: cert_sig +addr: cert_sig_len +addr: cert_signer_key_type +addr: cert_sig_hash_oid +addr: cert_sig_hash_len +addr: tbs_hash +addr: min_rsa_size + +\ Start TBS hash computation. The hash functions are reinitialised. +cc: start-tbs-hash ( -- ) { + br_multihash_init(&CTX->mhash); + CTX->do_mhash = 1; +} + +\ Stop TBS hash computation. +cc: stop-tbs-hash ( -- ) { + CTX->do_mhash = 0; +} + +\ Start DN hash computation. +cc: start-dn-hash ( -- ) { + CTX->dn_hash_impl->init(&CTX->dn_hash.vtable); + CTX->do_dn_hash = 1; +} + +\ Terminate DN hash computation and write the DN hash into the +\ current_dn_hash buffer. +cc: compute-dn-hash ( -- ) { + CTX->dn_hash_impl->out(&CTX->dn_hash.vtable, CTX->current_dn_hash); + CTX->do_dn_hash = 0; +} + +\ Get the length of hash values obtained with the DN hasher. +cc: dn-hash-length ( -- len ) { + T0_PUSH(DNHASH_LEN); +} + +\ Copy data between two areas in the context. +cc: blobcopy ( addr-dst addr-src len -- ) { + size_t len = T0_POP(); + unsigned char *src = (unsigned char *)CTX + T0_POP(); + unsigned char *dst = (unsigned char *)CTX + T0_POP(); + memcpy(dst, src, len); +} + +addr: current_dn_hash +addr: next_dn_hash +addr: saved_dn_hash + +\ Read a DN, hashing it into current_dn_hash. The DN contents are not +\ inspected (only the outer tag, for SEQUENCE, is checked). +: read-DN ( lim -- lim ) + start-dn-hash + read-sequence-open skip-close-elt + compute-dn-hash ; + +cc: offset-name-element ( san -- n ) { + unsigned san = T0_POP(); + size_t u; + + for (u = 0; u < CTX->num_name_elts; u ++) { + if (CTX->name_elts[u].status == 0) { + const unsigned char *oid; + size_t len, off; + + oid = CTX->name_elts[u].oid; + if (san) { + if (oid[0] != 0 || oid[1] != 0) { + continue; + } + off = 2; + } else { + off = 0; + } + len = oid[off]; + if (len != 0 && len == CTX->pad[0] + && memcmp(oid + off + 1, + CTX->pad + 1, len) == 0) + { + T0_PUSH(u); + T0_RET(); + } + } + } + T0_PUSHi(-1); +} + +cc: copy-name-element ( bool offbuf -- ) { + size_t len; + int32_t off = T0_POPi(); + int ok = T0_POPi(); + + if (off >= 0) { + br_name_element *ne = &CTX->name_elts[off]; + + if (ok) { + len = CTX->pad[0]; + if (len < ne->len) { + memcpy(ne->buf, CTX->pad + 1, len); + ne->buf[len] = 0; + ne->status = 1; + } else { + ne->status = -1; + } + } else { + ne->status = -1; + } + } +} + +cc: copy-name-SAN ( bool tag -- ) { + unsigned tag = T0_POP(); + unsigned ok = T0_POP(); + size_t u, len; + + len = CTX->pad[0]; + for (u = 0; u < CTX->num_name_elts; u ++) { + br_name_element *ne; + + ne = &CTX->name_elts[u]; + if (ne->status == 0 && ne->oid[0] == 0 && ne->oid[1] == tag) { + if (ok && ne->len > len) { + memcpy(ne->buf, CTX->pad + 1, len); + ne->buf[len] = 0; + ne->status = 1; + } else { + ne->status = -1; + } + break; + } + } +} + +\ Read a value, decoding string types. If the string type is recognised +\ and the value could be converted to UTF-8 into the pad, then true (-1) +\ is returned; in all other cases, false (0) is returned. Either way, the +\ object is consumed. +: read-string ( lim -- lim bool ) + read-tag case + \ UTF8String + 12 of check-primitive read-value-UTF8 endof + \ NumericString + 18 of check-primitive read-value-latin1 endof + \ PrintableString + 19 of check-primitive read-value-latin1 endof + \ TeletexString + 20 of check-primitive read-value-latin1 endof + \ IA5String + 22 of check-primitive read-value-latin1 endof + \ BMPString + 30 of check-primitive read-value-UTF16 endof + 2drop read-length-skip 0 0 + endcase ; + +\ Read a DN for the EE. The normalized DN hash is computed and stored in the +\ current_dn_hash. +\ Name elements are gathered. Also, the Common Name is matched against the +\ intended server name. +\ Returned value is true (-1) if the CN matches the intended server name, +\ false (0) otherwise. +: read-DN-EE ( lim -- lim bool ) + \ Flag will be set to true if there is a CN and it matches the + \ intended server name. + 0 { eename-matches } + + \ Activate DN hashing. + start-dn-hash + + \ Parse the DN structure: it is a SEQUENCE of SET of + \ AttributeTypeAndValue. Each AttributeTypeAndValue is a + \ SEQUENCE { OBJECT IDENTIFIER, ANY }. + read-sequence-open + begin + dup while + + read-tag 0x11 check-tag-constructed read-length-open-elt + dup ifnot ERR_X509_BAD_DN fail then + begin + dup while + + read-sequence-open + + \ Read the OID. If the OID could not be read (too + \ long) then the first pad byte will be 0. + read-OID drop + + \ If it is the Common Name then we'll need to + \ match it against the intended server name (if + \ applicable). + id-at-commonName eqOID { isCN } + + \ Get offset for reception buffer for that element + \ (or -1). + 0 offset-name-element { offbuf } + + \ Try to read the value as a string. + read-string + + \ If the value could be decoded as a string, + \ copy it and/or match it, as appropriate. + dup isCN and if + match-server-name if + -1 >eename-matches + then + then + offbuf copy-name-element + + \ Close the SEQUENCE + close-elt + + repeat + close-elt + repeat + close-elt + + \ Compute DN hash and deactivate DN hashing. + compute-dn-hash + + \ Return the CN match flag. + eename-matches ; + +\ Get the validation date and time from the context or system. +cc: get-system-date ( -- days seconds ) { + if (CTX->days == 0 && CTX->seconds == 0) { +#if BR_USE_UNIX_TIME + time_t x = time(NULL); + + T0_PUSH((uint32_t)(x / 86400) + 719528); + T0_PUSH((uint32_t)(x % 86400)); +#elif BR_USE_WIN32_TIME + FILETIME ft; + uint64_t x; + + GetSystemTimeAsFileTime(&ft); + x = ((uint64_t)ft.dwHighDateTime << 32) + + (uint64_t)ft.dwLowDateTime; + x = (x / 10000000); + T0_PUSH((uint32_t)(x / 86400) + 584754); + T0_PUSH((uint32_t)(x % 86400)); +#else + CTX->err = BR_ERR_X509_TIME_UNKNOWN; + T0_CO(); +#endif + } else { + T0_PUSH(CTX->days); + T0_PUSH(CTX->seconds); + } +} + +\ Compare two dates (days+seconds) together. +: before ( days1 seconds1 days2 seconds2 -- bool ) + { d1 s1 d2 s2 } + d1 d2 = if s1 s2 < else d1 d2 < then ; + +: after ( days1 seconds1 days2 seconds2 -- bool ) + swap2 before ; + +\ Swap the top two elements with the two elements immediately below. +: swap2 ( a b c d -- c d a b ) + 3 roll 3 roll ; + +\ Match the name in the pad with the expected server name. Returned value +\ is true (-1) on match, false (0) otherwise. If there is no expected +\ server name, then 0 is returned. +\ Match conditions: either an exact match (case insensitive), or a +\ wildcard match, if the found name starts with "*.". We only match a +\ starting wildcard, and only against a complete DN name component. +cc: match-server-name ( -- bool ) { + size_t n1, n2; + + if (CTX->server_name == NULL) { + T0_PUSH(0); + T0_RET(); + } + n1 = strlen(CTX->server_name); + n2 = CTX->pad[0]; + if (n1 == n2 && eqnocase(&CTX->pad[1], CTX->server_name, n1)) { + T0_PUSHi(-1); + T0_RET(); + } + if (n2 >= 2 && CTX->pad[1] == '*' && CTX->pad[2] == '.') { + size_t u; + + u = 0; + while (u < n1 && CTX->server_name[u] != '.') { + u ++; + } + u ++; + n1 -= u; + if ((n2 - 2) == n1 + && eqnocase(&CTX->pad[3], CTX->server_name + u, n1)) + { + T0_PUSHi(-1); + T0_RET(); + } + } + T0_PUSH(0); +} + +\ Get the address and length for the pkey_data buffer. +: addr-len-pkey_data ( -- addr len ) + CX 0 8191 { offsetof(br_x509_minimal_context, pkey_data) } + CX 0 8191 { BR_X509_BUFSIZE_KEY } ; + +\ Copy the EE public key to the permanent buffer (RSA). +cc: copy-ee-rsa-pkey ( nlen elen -- ) { + size_t elen = T0_POP(); + size_t nlen = T0_POP(); + memcpy(CTX->ee_pkey_data, CTX->pkey_data, nlen + elen); + CTX->pkey.key_type = BR_KEYTYPE_RSA; + CTX->pkey.key.rsa.n = CTX->ee_pkey_data; + CTX->pkey.key.rsa.nlen = nlen; + CTX->pkey.key.rsa.e = CTX->ee_pkey_data + nlen; + CTX->pkey.key.rsa.elen = elen; +} + +\ Copy the EE public key to the permanent buffer (EC). +cc: copy-ee-ec-pkey ( curve qlen -- ) { + size_t qlen = T0_POP(); + uint32_t curve = T0_POP(); + memcpy(CTX->ee_pkey_data, CTX->pkey_data, qlen); + CTX->pkey.key_type = BR_KEYTYPE_EC; + CTX->pkey.key.ec.curve = curve; + CTX->pkey.key.ec.q = CTX->ee_pkey_data; + CTX->pkey.key.ec.qlen = qlen; +} + +\ Check whether the current certificate (EE) is directly trusted. +cc: check-direct-trust ( -- ) { + size_t u; + + for (u = 0; u < CTX->trust_anchors_num; u ++) { + const br_x509_trust_anchor *ta; + unsigned char hashed_DN[64]; + int kt; + + ta = &CTX->trust_anchors[u]; + if (ta->flags & BR_X509_TA_CA) { + continue; + } + hash_dn(CTX, ta->dn.data, ta->dn.len, hashed_DN); + if (memcmp(hashed_DN, CTX->current_dn_hash, DNHASH_LEN)) { + continue; + } + kt = CTX->pkey.key_type; + if ((ta->pkey.key_type & 0x0F) != kt) { + continue; + } + switch (kt) { + + case BR_KEYTYPE_RSA: + if (!eqbigint(CTX->pkey.key.rsa.n, + CTX->pkey.key.rsa.nlen, + ta->pkey.key.rsa.n, + ta->pkey.key.rsa.nlen) + || !eqbigint(CTX->pkey.key.rsa.e, + CTX->pkey.key.rsa.elen, + ta->pkey.key.rsa.e, + ta->pkey.key.rsa.elen)) + { + continue; + } + break; + + case BR_KEYTYPE_EC: + if (CTX->pkey.key.ec.curve != ta->pkey.key.ec.curve + || CTX->pkey.key.ec.qlen != ta->pkey.key.ec.qlen + || memcmp(CTX->pkey.key.ec.q, + ta->pkey.key.ec.q, + ta->pkey.key.ec.qlen) != 0) + { + continue; + } + break; + + default: + continue; + } + + /* + * Direct trust match! + */ + CTX->err = BR_ERR_X509_OK; + T0_CO(); + } +} + +\ Check the signature on the certificate with regards to all trusted CA. +\ We use the issuer hash (in saved_dn_hash[]) as CA identifier. +cc: check-trust-anchor-CA ( -- ) { + size_t u; + + for (u = 0; u < CTX->trust_anchors_num; u ++) { + const br_x509_trust_anchor *ta; + unsigned char hashed_DN[64]; + + ta = &CTX->trust_anchors[u]; + if (!(ta->flags & BR_X509_TA_CA)) { + continue; + } + hash_dn(CTX, ta->dn.data, ta->dn.len, hashed_DN); + if (memcmp(hashed_DN, CTX->saved_dn_hash, DNHASH_LEN)) { + continue; + } + if (verify_signature(CTX, &ta->pkey) == 0) { + CTX->err = BR_ERR_X509_OK; + T0_CO(); + } + } +} + +\ Verify RSA signature. This uses the public key that was just decoded +\ into CTX->pkey_data; the modulus and exponent length are provided as +\ parameters. The resulting hash value is compared with the one in +\ tbs_hash. Returned value is 0 on success, or a non-zero error code. +cc: do-rsa-vrfy ( nlen elen -- err ) { + size_t elen = T0_POP(); + size_t nlen = T0_POP(); + br_x509_pkey pk; + + pk.key_type = BR_KEYTYPE_RSA; + pk.key.rsa.n = CTX->pkey_data; + pk.key.rsa.nlen = nlen; + pk.key.rsa.e = CTX->pkey_data + nlen; + pk.key.rsa.elen = elen; + T0_PUSH(verify_signature(CTX, &pk)); +} + +\ Verify ECDSA signature. This uses the public key that was just decoded +\ into CTX->pkey_dayta; the curve ID and public point length are provided +\ as parameters. The hash value in tbs_hash is used. Returned value is 0 +\ on success, or non-zero error code. +cc: do-ecdsa-vrfy ( curve qlen -- err ) { + size_t qlen = T0_POP(); + int curve = T0_POP(); + br_x509_pkey pk; + + pk.key_type = BR_KEYTYPE_EC; + pk.key.ec.curve = curve; + pk.key.ec.q = CTX->pkey_data; + pk.key.ec.qlen = qlen; + T0_PUSH(verify_signature(CTX, &pk)); +} + +cc: print-bytes ( addr len -- ) { + extern int printf(const char *fmt, ...); + size_t len = T0_POP(); + unsigned char *buf = (unsigned char *)CTX + T0_POP(); + size_t u; + + for (u = 0; u < len; u ++) { + printf("%02X", buf[u]); + } +} + +cc: printOID ( -- ) { + extern int printf(const char *fmt, ...); + size_t u, len; + + len = CTX->pad[0]; + if (len == 0) { + printf("*"); + T0_RET(); + } + printf("%u.%u", CTX->pad[1] / 40, CTX->pad[1] % 40); + u = 2; + while (u <= len) { + unsigned long ul; + + ul = 0; + for (;;) { + int x; + + if (u > len) { + printf("BAD"); + T0_RET(); + } + x = CTX->pad[u ++]; + ul = (ul << 7) + (x & 0x7F); + if (!(x & 0x80)) { + break; + } + } + printf(".%lu", ul); + } +} + +\ Extensions with specific processing. +OID: basicConstraints 2.5.29.19 +OID: keyUsage 2.5.29.15 +OID: subjectAltName 2.5.29.17 +OID: certificatePolicies 2.5.29.32 + +\ Policy qualifier "pointer to CPS" +OID: id-qt-cps 1.3.6.1.5.5.7.2.1 + +\ Extensions which are ignored when encountered, even if critical. +OID: authorityKeyIdentifier 2.5.29.35 +OID: subjectKeyIdentifier 2.5.29.14 +OID: issuerAltName 2.5.29.18 +OID: subjectDirectoryAttributes 2.5.29.9 +OID: crlDistributionPoints 2.5.29.31 +OID: freshestCRL 2.5.29.46 +OID: authorityInfoAccess 1.3.6.1.5.5.7.1.1 +OID: subjectInfoAccess 1.3.6.1.5.5.7.1.11 + +\ Process a Basic Constraints extension. This should be called only if +\ the certificate is not the EE. We check that the extension contains +\ the "CA" flag, and that the path length, if specified, is compatible +\ with the current chain length. +: process-basicConstraints ( lim -- lim ) + read-sequence-open + read-tag-or-end + dup 0x01 = if + read-boolean ifnot ERR_X509_NOT_CA fail then + read-tag-or-end + else + ERR_X509_NOT_CA fail + then + dup 0x02 = if + drop check-primitive read-small-int-value + addr-num_certs get32 1- < if ERR_X509_NOT_CA fail then + read-tag-or-end + then + -1 <> if ERR_X509_UNEXPECTED fail then + drop + close-elt + ; + +\ Process a Key Usage extension. +\ For the EE certificate: +\ -- if the key usage contains keyEncipherment (2), dataEncipherment (3) +\ or keyAgreement (4), then the "key exchange" usage is allowed; +\ -- if the key usage contains digitalSignature (0) or nonRepudiation (1), +\ then the "signature" usage is allowed. +\ For CA certificates, the extension must contain keyCertSign (5). +: process-keyUsage ( lim ee -- lim ) + { ee } + + \ Read tag for the BIT STRING and open it. + read-tag 0x03 check-tag-primitive + read-length-open-elt + \ First byte indicates number of ignored bits in the last byte. It + \ must be between 0 and 7. + read8 { ign } + ign 7 > if ERR_X509_UNEXPECTED fail then + \ Depending on length, we have either 0, 1 or more bytes to read. + dup case + 0 of ERR_X509_FORBIDDEN_KEY_USAGE fail endof + 1 of read8 ign >> ign << endof + drop read8 0 + endcase + + \ Check bits. + ee if + \ EE: get usages. + 0 + over 0x38 and if 0x10 or then + swap 0xC0 and if 0x20 or then + addr-key_usages set8 + else + \ Not EE: keyCertSign must be set. + 0x04 and ifnot ERR_X509_FORBIDDEN_KEY_USAGE fail then + then + + \ We don't care about subsequent bytes. + skip-close-elt ; + +\ Process a Certificate Policies extension. +\ +\ Since we don't actually support full policies processing, this function +\ only checks that the extension contents can be safely ignored. Indeed, +\ we don't validate against a specific set of policies (in RFC 5280 +\ terminology, user-initial-policy-set only contains the special value +\ any-policy). Moreover, we don't support policy constraints (if a +\ critical Policy Constraints extension is encountered, the validation +\ will fail). Therefore, we can safely ignore the contents of this +\ extension, except if it is critical AND one of the policy OID has a +\ qualifier which is distinct from id-qt-cps (because id-qt-cps is +\ specially designated by RFC 5280 has having no mandated action). +\ +\ This function is called only if the extension is critical. +: process-certPolicies ( lim -- lim ) + \ Extension value is a SEQUENCE OF PolicyInformation. + read-sequence-open + begin dup while + \ PolicyInformation ::= SEQUENCE { + \ policyIdentifier OBJECT IDENTIFIER, + \ policyQualifiers SEQUENCE OF PolicyQualifierInfo OPTIONAL + \ } + read-sequence-open + read-OID drop + dup if + read-sequence-open + begin dup while + \ PolicyQualifierInfo ::= SEQUENCE { + \ policyQualifierId OBJECT IDENTIFIER, + \ qualifier ANY + \ } + read-sequence-open + read-OID drop id-qt-cps eqOID ifnot + ERR_X509_CRITICAL_EXTENSION fail + then + skip-close-elt + repeat + close-elt + then + close-elt + repeat + close-elt ; + +\ Process a Subject Alt Name extension. Returned value is a boolean set +\ to true if the expected server name was matched against a dNSName in +\ the extension. +: process-SAN ( lim -- lim bool ) + 0 { m } + read-sequence-open + begin dup while + \ Read the tag. If the tag is context-0, then parse an + \ 'otherName'. If the tag is context-2, then parse a + \ dNSName. If the tag is context-1 or context-6, + \ parse + read-tag case + \ OtherName + 0x20 of + \ OtherName ::= SEQUENCE { + \ type-id OBJECT IDENTIFIER, + \ value [0] EXPLICIT ANY + \ } + check-constructed read-length-open-elt + read-OID drop + -1 offset-name-element { offbuf } + read-tag 0x20 check-tag-constructed + read-length-open-elt + read-string offbuf copy-name-element + close-elt + close-elt + endof + \ rfc822Name (IA5String) + 0x21 of + check-primitive + read-value-UTF8 1 copy-name-SAN + endof + \ dNSName (IA5String) + 0x22 of + check-primitive + read-value-UTF8 + dup if match-server-name m or >m then + 2 copy-name-SAN + endof + \ uniformResourceIdentifier (IA5String) + 0x26 of + check-primitive + read-value-UTF8 6 copy-name-SAN + endof + 2drop read-length-skip 0 + endcase + + \ We check only names of type dNSName; they use IA5String, + \ which is basically ASCII. + \ read-tag 0x22 = if + \ check-primitive + \ read-small-value drop + \ match-server-name m or >m + \ else + \ drop read-length-skip + \ then + repeat + close-elt + m ; + +\ Decode a certificate. The "ee" boolean must be true for the EE. +: decode-certificate ( ee -- ) + { ee } + + \ Obtain the total certificate length. + addr-cert_length get32 + + \ Open the outer SEQUENCE. + read-sequence-open + + \ TBS + \ Activate hashing. + start-tbs-hash + read-sequence-open + + \ First element may be an explicit version. We accept only + \ versions 0 to 2 (certificates v1 to v3). + read-tag dup 0x20 = if + drop check-constructed read-length-open-elt + read-tag + 0x02 check-tag-primitive + read-small-int-value + 2 > if ERR_X509_UNSUPPORTED fail then + close-elt + read-tag + then + + \ Serial number. We just check that the tag is correct. + 0x02 check-tag-primitive + read-length-skip + + \ Signature algorithm. This structure is redundant with the one + \ on the outside; we just skip it. + read-sequence-open skip-close-elt + + \ Issuer name: hashed, then copied into next_dn_hash[]. + read-DN + addr-next_dn_hash addr-current_dn_hash dn-hash-length blobcopy + + \ Validity dates. + read-sequence-open + read-date get-system-date after if ERR_X509_EXPIRED fail then + read-date get-system-date before if ERR_X509_EXPIRED fail then + close-elt + + \ Subject name. + ee if + \ For the EE, we must check whether the Common Name, if + \ any, matches the expected server name. + read-DN-EE { eename } + else + \ For a non-EE certificate, the hashed subject DN must match + \ the saved hashed issuer DN from the previous certificate. + read-DN + addr-current_dn_hash addr-saved_dn_hash dn-hash-length eqblob + ifnot ERR_X509_DN_MISMATCH fail then + then + \ Move the hashed issuer DN for this certificate into the + \ saved_dn_hash[] array. + addr-saved_dn_hash addr-next_dn_hash dn-hash-length blobcopy + + \ Public Key. + read-sequence-open + \ Algorithm Identifier. Right now we are only interested in the + \ OID, since we only support RSA keys. + read-sequence-open + read-OID ifnot ERR_X509_UNSUPPORTED fail then + { ; pkey-type } + choice + \ RSA public key. + rsaEncryption eqOID uf + skip-close-elt + \ Public key itself: the BIT STRING contains bytes + \ (no partial byte) and these bytes encode the + \ actual value. + read-bits-open + \ RSA public key is a SEQUENCE of two + \ INTEGER. We get both INTEGER values into + \ the pkey_data[] buffer, if they fit. + read-sequence-open + addr-len-pkey_data + read-integer { nlen } + addr-len-pkey_data swap nlen + swap nlen - + read-integer { elen } + close-elt + + \ Check that the public key fits our minimal + \ size requirements. Note that the integer + \ decoder already skipped the leading bytes + \ of value 0, so we are working on the true + \ modulus length here. + addr-min_rsa_size get16 128 + nlen > if + ERR_X509_WEAK_PUBLIC_KEY fail + then + close-elt + KEYTYPE_RSA >pkey-type + enduf + + \ EC public key. + id-ecPublicKey eqOID uf + \ We support only named curves, for which the + \ "parameters" field in the AlgorithmIdentifier + \ field should be an OID. + read-OID ifnot ERR_X509_UNSUPPORTED fail then + choice + ansix9p256r1 eqOID uf 23 enduf + ansix9p384r1 eqOID uf 24 enduf + ansix9p521r1 eqOID uf 25 enduf + ERR_X509_UNSUPPORTED fail + endchoice + { curve } + close-elt + read-bits-open + dup { qlen } + dup addr-len-pkey_data rot < if + ERR_X509_LIMIT_EXCEEDED fail + then + read-blob + KEYTYPE_EC >pkey-type + enduf + + \ Not a recognised public key type. + ERR_X509_UNSUPPORTED fail + endchoice + close-elt + + \ Process public key. + ee if + \ For the EE certificate, copy the key data to the + \ relevant buffer. + pkey-type case + KEYTYPE_RSA of nlen elen copy-ee-rsa-pkey endof + KEYTYPE_EC of curve qlen copy-ee-ec-pkey endof + ERR_X509_UNSUPPORTED fail + endcase + else + \ Verify signature on previous certificate. We invoke + \ the RSA implementation. + pkey-type case + KEYTYPE_RSA of nlen elen do-rsa-vrfy endof + KEYTYPE_EC of curve qlen do-ecdsa-vrfy endof + ERR_X509_UNSUPPORTED fail + endcase + dup if fail then + drop + then + + \ This flag will be set to true if the Basic Constraints extension + \ is encountered. + 0 { seenBC } + + \ Skip issuerUniqueID and subjectUniqueID, and process extensions + \ if present. Extensions are an explicit context tag of value 3 + \ around a SEQUENCE OF extensions. Each extension is a SEQUENCE + \ with an OID, an optional boolean, and a value; the value is + \ an OCTET STRING. + read-tag-or-end + 0x21 iftag-skip + 0x22 iftag-skip + dup 0x23 = if + drop + check-constructed read-length-open-elt + read-sequence-open + begin dup while + 0 { critical } + read-sequence-open + read-OID drop + read-tag dup 0x01 = if + read-boolean >critical + read-tag + then + 0x04 check-tag-primitive read-length-open-elt + choice + \ Extensions with specific processing. + basicConstraints eqOID uf + ee if + skip-remaining + else + process-basicConstraints + -1 >seenBC + then + enduf + keyUsage eqOID uf + ee process-keyUsage + enduf + subjectAltName eqOID uf + ee if + 0 >eename + process-SAN >eename + else + skip-remaining + then + enduf + + \ We don't implement full processing of + \ policies. The call below mostly checks + \ that the contents of the Certificate + \ Policies extension can be safely ignored. + certificatePolicies eqOID uf + critical if + process-certPolicies + else + skip-remaining + then + enduf + + \ Extensions which are always ignored, + \ even if critical. + authorityKeyIdentifier eqOID uf + skip-remaining + enduf + subjectKeyIdentifier eqOID uf + skip-remaining + enduf + issuerAltName eqOID uf + skip-remaining + enduf + subjectDirectoryAttributes eqOID uf + skip-remaining + enduf + crlDistributionPoints eqOID uf + skip-remaining + enduf + freshestCRL eqOID uf + skip-remaining + enduf + authorityInfoAccess eqOID uf + skip-remaining + enduf + subjectInfoAccess eqOID uf + skip-remaining + enduf + + \ Unrecognized extensions trigger a failure + \ if critical; otherwise, they are just + \ ignored. + critical if + ERR_X509_CRITICAL_EXTENSION fail + then + skip-remaining + endchoice + close-elt + close-elt + repeat + close-elt + close-elt + else + -1 = ifnot ERR_X509_UNEXPECTED fail then + drop + then + + close-elt + \ Terminate hashing. + stop-tbs-hash + + \ For the EE certificate, verify that the intended server name + \ was matched. + ee if + eename zero-server-name or ifnot + ERR_X509_BAD_SERVER_NAME fail + then + then + + \ If this is the EE certificate, then direct trust may apply. + \ Note: we do this at this point, not immediately after decoding + \ the public key, because even in case of direct trust we still + \ want to check the server name with regards to the SAN extension. + \ However, we want to check direct trust before trying to decode + \ the signature algorithm, because it should work even if that + \ algorithm is not supported. + ee if check-direct-trust then + + \ Non-EE certificates MUST have a Basic Constraints extension + \ (that marks them as being CA). + ee seenBC or ifnot ERR_X509_NOT_CA fail then + + \ signature algorithm + read-tag check-sequence read-length-open-elt + \ Read and understand the OID. Right now, we support only + \ RSA with PKCS#1 v1.5 padding, and hash functions SHA-1, + \ SHA-224, SHA-256, SHA-384 and SHA-512. We purposely do NOT + \ support MD5 here. + \ TODO: add support for RSA/PSS + read-OID if + \ Based on the signature OID, we get: + \ -- the signing key type + \ -- the hash function numeric identifier + \ -- the hash function OID + choice + sha1WithRSAEncryption eqOID + uf 2 KEYTYPE_RSA id-sha1 enduf + sha224WithRSAEncryption eqOID + uf 3 KEYTYPE_RSA id-sha224 enduf + sha256WithRSAEncryption eqOID + uf 4 KEYTYPE_RSA id-sha256 enduf + sha384WithRSAEncryption eqOID + uf 5 KEYTYPE_RSA id-sha384 enduf + sha512WithRSAEncryption eqOID + uf 6 KEYTYPE_RSA id-sha512 enduf + + ecdsa-with-SHA1 eqOID + uf 2 KEYTYPE_EC id-sha1 enduf + ecdsa-with-SHA224 eqOID + uf 3 KEYTYPE_EC id-sha224 enduf + ecdsa-with-SHA256 eqOID + uf 4 KEYTYPE_EC id-sha256 enduf + ecdsa-with-SHA384 eqOID + uf 5 KEYTYPE_EC id-sha384 enduf + ecdsa-with-SHA512 eqOID + uf 6 KEYTYPE_EC id-sha512 enduf + ERR_X509_UNSUPPORTED fail + endchoice + addr-cert_sig_hash_oid set16 + addr-cert_signer_key_type set8 + + \ Compute the TBS hash into tbs_hash. + compute-tbs-hash + dup ifnot ERR_X509_UNSUPPORTED fail then + addr-cert_sig_hash_len set8 + else + ERR_X509_UNSUPPORTED fail + then + \ We ignore the parameters, whether they are present or not, + \ because we got all the information from the OID. + skip-close-elt + + \ signature value + read-bits-open + dup CX 0 8191 { BR_X509_BUFSIZE_SIG } > if + ERR_X509_LIMIT_EXCEEDED fail + then + dup addr-cert_sig_len set16 + addr-cert_sig read-blob + + \ Close the outer SEQUENCE. + close-elt + + \ Close the advertised total certificate length. This checks that + \ there is no trailing garbage after the certificate. + close-elt + + \ Flag the certificate as fully processed. + 0 addr-cert_length set32 + + \ Check whether the issuer for the current certificate is known + \ as a trusted CA; in which case, verify the signature. + check-trust-anchor-CA ; + +: main + \ Unless restricted by a Key Usage extension, all usages are + \ deemed allowed. + 0x30 addr-key_usages set8 + -1 decode-certificate + co + begin + 0 decode-certificate co + again + ; diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/x509_minimal_full.c b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/x509_minimal_full.c new file mode 100644 index 000000000..9ca15d263 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/bssl/x509_minimal_full.c @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2016 Thomas Pornin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "../ESP_SSLClient_FS.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "inner.h" + +/* see bearssl_x509.h */ +void +br_x509_minimal_init_full(br_x509_minimal_context *xc, + const br_x509_trust_anchor *trust_anchors, size_t trust_anchors_num) +{ + /* + * All hash functions are activated. + * Note: the X.509 validation engine will nonetheless refuse to + * validate signatures that use MD5 as hash function. + */ + static const br_hash_class *hashes[] = { + &br_md5_vtable, + &br_sha1_vtable, + &br_sha224_vtable, + &br_sha256_vtable, + &br_sha384_vtable, + &br_sha512_vtable + }; + + int id; + + br_x509_minimal_init(xc, &br_sha256_vtable, + trust_anchors, trust_anchors_num); + br_x509_minimal_set_rsa(xc, &br_rsa_i31_pkcs1_vrfy); + br_x509_minimal_set_ecdsa(xc, + &br_ec_prime_i31, &br_ecdsa_i31_vrfy_asn1); + for (id = br_md5_ID; id <= br_sha512_ID; id ++) { + const br_hash_class *hc; + + hc = hashes[id - 1]; + br_x509_minimal_set_hash(xc, id, hc); + } +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/client/BSSL_CertStore.cpp b/lib/libesp32/ESP-Mail-Client/src/SSLClient/client/BSSL_CertStore.cpp new file mode 100644 index 000000000..50c6069a2 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/client/BSSL_CertStore.cpp @@ -0,0 +1,282 @@ +/* + CertStoreBearSSL.cpp - Library for Arduino ESP8266 + Copyright (c) 2018 Earle F. Philhower, III + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ +#ifndef BSSL_CERTSTORE_CPP +#define BSSL_CERTSTORE_CPP + +#pragma GCC diagnostic ignored "-Wunused-function" +#pragma GCC diagnostic ignored "-Wvla" + +#include +#include "../ESP_SSLClient_FS.h" +#include "../ESP_SSLClient_Const.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "BSSL_CertStore.h" + +#if defined(ESP_SSL_FS_SUPPORTED) + +#include + +#if defined(DEBUG_ESP_SSL) && defined(DEBUG_ESP_PORT) +#define DEBUG_BSSL(fmt, ...) DEBUG_ESP_PORT.printf_P((PGM_P)PSTR("BSSL:" fmt), ##__VA_ARGS__) +#else +#define DEBUG_BSSL(...) +#endif + +namespace bssl +{ + + extern "C" + { + // Callback for the x509 decoder + static void dn_append(void *ctx, const void *buf, size_t len) + { + br_sha256_context *sha1 = (br_sha256_context *)ctx; + br_sha256_update(sha1, buf, len); + } + } + + CertStore::~CertStore() + { + free(_indexName); + free(_dataName); + } + + CertStore::CertInfo CertStore::_preprocessCert(uint32_t length, uint32_t offset, const void *raw) + { + CertStore::CertInfo ci; + + // Clear the CertInfo + memset(&ci, 0, sizeof(ci)); + + // Process it using SHA256, same as the hashed_dn + br_x509_decoder_context_libmail *ctx = new (std::nothrow) br_x509_decoder_context_libmail; + br_sha256_context *sha256 = new (std::nothrow) br_sha256_context; + if (!ctx || !sha256) + { + if (ctx) + delete ctx; + if (sha256) + delete sha256; + DEBUG_BSSL("CertStore::_preprocessCert: OOM\n"); + return ci; + } + + br_sha256_init(sha256); + br_x509_decoder_init(ctx, dn_append, sha256); + br_x509_decoder_push_libmail(ctx, (const void *)raw, length); + + // Copy result to structure + br_sha256_out(sha256, &ci.sha256); + ci.length = length; + ci.offset = offset; + + // Clean up allocated memory + delete sha256; + delete ctx; + + // Return result + return ci; + } + + // The certs.ar file is a UNIX ar format file, concatenating all the + // individual certificates into a single blob in a space-efficient way. + int CertStore::initCertStore(FS &fs, const char *indexFileName, const char *dataFileName) + { + int count = 0; + uint32_t offset = 0; + + _fs = &fs; + + // In case initCertStore called multiple times, don't leak old filenames + free(_indexName); + free(_dataName); + + // No strdup_P, so manually do it + _indexName = (char *)malloc(strlen_P(indexFileName) + 1); + _dataName = (char *)malloc(strlen_P(dataFileName) + 1); + if (!_indexName || !_dataName) + { + free(_indexName); + free(_dataName); + return 0; + } + memcpy_P(_indexName, indexFileName, strlen_P(indexFileName) + 1); + memcpy_P(_dataName, dataFileName, strlen_P(dataFileName) + 1); + + File index = _fs->open(_indexName, FILE_WRITE); + if (!index) + { + return 0; + } + + File data = _fs->open(_dataName, FILE_READ); + if (!data) + { + index.close(); + return 0; + } + + uint8_t magic[8]; + if (data.read(magic, sizeof(magic)) != sizeof(magic) || + memcmp(magic, "!\n", sizeof(magic))) + { + data.close(); + index.close(); + return 0; + } + offset += sizeof(magic); + + while (true) + { + uint8_t fileHeader[60]; + // 0..15 = filename in ASCII + // 48...57 = length in decimal ASCII + int32_t length; + if (data.read(fileHeader, sizeof(fileHeader)) != sizeof(fileHeader)) + { + break; + } + offset += sizeof(fileHeader); + fileHeader[58] = 0; + if (1 != sscanf((char *)(fileHeader + 48), "%d", (int *)(&length)) || !length) + { + break; + } + + void *raw = malloc(length); + if (!raw) + { + break; + } + if ((int)data.read((uint8_t *)raw, length) != length) + { + free(raw); + break; + } + + // If the filename starts with "//" then this is a rename file, skip it + if (fileHeader[0] != '/' || fileHeader[1] != '/') + { + CertStore::CertInfo ci = _preprocessCert(length, offset, raw); + if (index.write((uint8_t *)&ci, sizeof(ci)) != (ssize_t)sizeof(ci)) + { + free(raw); + break; + } + count++; + } + + offset += length; + free(raw); + if (offset & 1) + { + uint8_t x; + data.read(&x, 1); + offset++; + } + } + data.close(); + index.close(); + return count; + } + + void CertStore::installCertStore(br_x509_minimal_context *ctx) + { + br_x509_minimal_set_dynamic(ctx, (void *)this, findHashedTA, freeHashedTA); + } + + const br_x509_trust_anchor *CertStore::findHashedTA(void *ctx, void *hashed_dn, size_t len) + { + CertStore *cs = static_cast(ctx); + CertStore::CertInfo ci; + + if (!cs || len != sizeof(ci.sha256) || !cs->_indexName || !cs->_dataName || !cs->_fs) + { + return nullptr; + } + + File index = cs->_fs->open(cs->_indexName, FILE_READ); + if (!index) + { + return nullptr; + } + + while (index.read((uint8_t *)&ci, sizeof(ci)) == sizeof(ci)) + { + if (!memcmp(ci.sha256, hashed_dn, sizeof(ci.sha256))) + { + index.close(); + uint8_t *der = (uint8_t *)malloc(ci.length); + if (!der) + { + return nullptr; + } + File data = cs->_fs->open(cs->_dataName, FILE_READ); + if (!data) + { + free(der); + return nullptr; + } + if (!data.seek(ci.offset, SeekSet)) + { + data.close(); + free(der); + return nullptr; + } + if ((int)data.read(der, ci.length) != (int)ci.length) + { + free(der); + return nullptr; + } + data.close(); + cs->_x509 = new (std::nothrow) X509List(der, ci.length); + free(der); + if (!cs->_x509) + { + DEBUG_BSSL("CertStore::findHashedTA: OOM\n"); + return nullptr; + } + + br_x509_trust_anchor *ta = (br_x509_trust_anchor *)cs->_x509->getTrustAnchors(); + memcpy(ta->dn.data, ci.sha256, sizeof(ci.sha256)); + ta->dn.len = sizeof(ci.sha256); + + return ta; + } + } + index.close(); + return nullptr; + } + + void CertStore::freeHashedTA(void *ctx, const br_x509_trust_anchor *ta) + { + CertStore *cs = static_cast(ctx); + (void)ta; // Unused + delete cs->_x509; + cs->_x509 = nullptr; + } + +} + +#endif + +#endif + +#endif \ No newline at end of file diff --git a/lib/libesp32/lib_mail/src/wcs/esp8266/ESP_Mail_CertStoreBearSSL.h b/lib/libesp32/ESP-Mail-Client/src/SSLClient/client/BSSL_CertStore.h similarity index 62% rename from lib/libesp32/lib_mail/src/wcs/esp8266/ESP_Mail_CertStoreBearSSL.h rename to lib/libesp32/ESP-Mail-Client/src/SSLClient/client/BSSL_CertStore.h index fd9f8c537..42b963340 100644 --- a/lib/libesp32/lib_mail/src/wcs/esp8266/ESP_Mail_CertStoreBearSSL.h +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/client/BSSL_CertStore.h @@ -1,5 +1,5 @@ /* - Copy of CertStoreBearSSL.h - Library for Arduino ESP8266 + CertStoreBearSSL.h - Library for Arduino ESP8266 Copyright (c) 2018 Earle F. Philhower, III This library is free software; you can redistribute it and/or @@ -16,27 +16,54 @@ License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#ifndef BSSL_CERTSTORE_H +#define BSSL_CERTSTORE_H -#ifndef ESP_Mail_CertStoreBearSSL_H -#define ESP_Mail_CertStoreBearSSL_H - -#ifdef ESP8266 +#pragma GCC diagnostic ignored "-Wunused-function" +#pragma GCC diagnostic ignored "-Wvla" #include -#include "ESP_Mail_BearSSLHelpers.h" -#include +#include "../ESP_SSLClient_FS.h" +#include "../ESP_SSLClient_Const.h" +#if defined(USE_LIB_SSL_ENGINE) + + +#if defined __has_include +#if __has_include() && defined(ESP_SSLCLIENT_USE_FILESYSTEM) #include +#define ESP_SSL_FS_SUPPORTED +#endif +#endif + +#if defined(ESP_SSL_FS_SUPPORTED) + + +#include "../bssl/bearssl.h" +#include "BSSL_Helper.h" + +using namespace bssl; // Base class for the certificate stores, which allow use // of a large set of certificates stored on FS or SD card to // be dynamically used when validating a X509 certificate -namespace ESP_Mail { +namespace bssl +{ -class ESP_Mail_CertStore { + class CertStoreBase + { public: - ESP_Mail_CertStore() { }; - ~ESP_Mail_CertStore(); + virtual ~CertStoreBase() {} + + // Installs the cert store into the X509 decoder (normally via static function callbacks) + virtual void installCertStore(br_x509_minimal_context *ctx) = 0; + }; + + class CertStore : public CertStoreBase + { + public: + CertStore(){}; + ~CertStore(); // Set the file interface instances, do preprocessing int initCertStore(FS &fs, const char *indexFileName, const char *dataFileName); @@ -48,25 +75,27 @@ class ESP_Mail_CertStore { FS *_fs = nullptr; char *_indexName = nullptr; char *_dataName = nullptr; - ESP_Mail_X509List *_x509 = nullptr; + X509List *_x509 = nullptr; // These need to be static as they are callbacks from BearSSL C code static const br_x509_trust_anchor *findHashedTA(void *ctx, void *hashed_dn, size_t len); static void freeHashedTA(void *ctx, const br_x509_trust_anchor *ta); // The binary format of the index file - class ESP_Mail_CertInfo { + class CertInfo + { public: uint8_t sha256[32]; uint32_t offset; uint32_t length; }; - static ESP_Mail_CertInfo _preprocessCert(uint32_t length, uint32_t offset, const void *raw); + static CertInfo _preprocessCert(uint32_t length, uint32_t offset, const void *raw); + }; }; -}; +#endif -#endif /* ESP8266 */ +#endif -#endif /* ESP_Mail_CertStoreBearSSL_H */ +#endif diff --git a/lib/libesp32/lib_mail/src/wcs/esp8266/ESP_Mail_BearSSLHelpers.cpp b/lib/libesp32/ESP-Mail-Client/src/SSLClient/client/BSSL_Helper.cpp similarity index 83% rename from lib/libesp32/lib_mail/src/wcs/esp8266/ESP_Mail_BearSSLHelpers.cpp rename to lib/libesp32/ESP-Mail-Client/src/SSLClient/client/BSSL_Helper.cpp index 9c44c94ce..a8a105737 100644 --- a/lib/libesp32/lib_mail/src/wcs/esp8266/ESP_Mail_BearSSLHelpers.cpp +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/client/BSSL_Helper.cpp @@ -1,1108 +1,1053 @@ -/* - Copy of BearSSLHelpers.cpp - - WiFiClientBearSSL- SSL client/server for esp8266 using BearSSL libraries - - Mostly compatible with Arduino WiFi shield library and standard - WiFiClient/ServerSecure (except for certificate handling). - - Copyright (c) 2018 Earle F. Philhower, III - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ -#ifndef ESP_Mail_BearSSLHelpers_CPP -#define ESP_Mail_BearSSLHelpers_CPP - -#ifdef ESP8266 - -#include "ESP_Mail_BearSSLHelpers.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifndef ARDUINO_SIGNING -#define ARDUINO_SIGNING 0 -#endif - -namespace ESP_Mail_brssl -{ - // Code here is pulled from brssl sources, with the copyright and license - // shown below. I've rewritten things using C++ semantics and removed - // custom VEC_* calls (std::vector to the rescue) and adjusted things to - // allow for long-running operation (i.e. some memory issues when DERs - // passed into the decoders). Bugs are most likely my fault. - - // Original (c) message follows: - /* - Copyright (c) 2016 Thomas Pornin - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. - */ - - class private_key - { - public: - int key_type; /* BR_KEYTYPE_RSA or BR_KEYTYPE_EC */ - union - { - br_rsa_private_key rsa; - br_ec_private_key ec; - } key; - }; - - class public_key - { - public: - int key_type; /* BR_KEYTYPE_RSA or BR_KEYTYPE_EC */ - union - { - br_rsa_public_key rsa; - br_ec_public_key ec; - } key; - }; - - class pem_object - { - public: - char *name; - unsigned char *data; - size_t data_len; - }; - - // Forward definitions - void free_ta_contents(br_x509_trust_anchor *ta); - void free_public_key(public_key *pk); - void free_private_key(private_key *sk); - bool looks_like_DER(const unsigned char *buf, size_t len); - pem_object *decode_pem(const void *src, size_t len, size_t *num); - void free_pem_object_contents(pem_object *po); - - // Used as callback multiple places to append a string to a vector - static void byte_vector_append(void *ctx, const void *buff, size_t len) - { - std::vector *vec = static_cast *>(ctx); - vec->reserve(vec->size() + len); // Allocate extra space all at once - for (size_t i = 0; i < len; i++) - { - vec->push_back(((uint8_t *)buff)[i]); - } - } - - static bool certificate_to_trust_anchor_inner(br_x509_trust_anchor *ta, const br_x509_certificate *xc) - { - std::unique_ptr dc(new br_x509_decoder_context); // auto-delete on exit - std::vector vdn; - br_x509_pkey *pk; - - // Clear everything in the Trust Anchor - memset(ta, 0, sizeof(*ta)); - - br_x509_decoder_init(dc.get(), byte_vector_append, (void *)&vdn, 0, 0); - br_x509_decoder_push(dc.get(), xc->data, xc->data_len); - pk = br_x509_decoder_get_pkey(dc.get()); - if (pk == nullptr) - { - return false; // No key present, something broken in the cert! - } - - // Copy the raw certificate data - ta->dn.data = (uint8_t *)malloc(vdn.size()); - if (!ta->dn.data) - { - return false; // OOM, but nothing yet allocated - } - memcpy(ta->dn.data, &vdn[0], vdn.size()); - ta->dn.len = vdn.size(); - ta->flags = 0; - if (br_x509_decoder_isCA(dc.get())) - { - ta->flags |= BR_X509_TA_CA; - } - - // Extract the public key - switch (pk->key_type) - { - case BR_KEYTYPE_RSA: - ta->pkey.key_type = BR_KEYTYPE_RSA; - ta->pkey.key.rsa.n = (uint8_t *)malloc(pk->key.rsa.nlen); - ta->pkey.key.rsa.e = (uint8_t *)malloc(pk->key.rsa.elen); - if ((ta->pkey.key.rsa.n == nullptr) || (ta->pkey.key.rsa.e == nullptr)) - { - free_ta_contents(ta); // OOM, so clean up - return false; - } - memcpy(ta->pkey.key.rsa.n, pk->key.rsa.n, pk->key.rsa.nlen); - ta->pkey.key.rsa.nlen = pk->key.rsa.nlen; - memcpy(ta->pkey.key.rsa.e, pk->key.rsa.e, pk->key.rsa.elen); - ta->pkey.key.rsa.elen = pk->key.rsa.elen; - return true; - case BR_KEYTYPE_EC: - ta->pkey.key_type = BR_KEYTYPE_EC; - ta->pkey.key.ec.curve = pk->key.ec.curve; - ta->pkey.key.ec.q = (uint8_t *)malloc(pk->key.ec.qlen); - if (ta->pkey.key.ec.q == nullptr) - { - free_ta_contents(ta); // OOM, so clean up - return false; - } - memcpy(ta->pkey.key.ec.q, pk->key.ec.q, pk->key.ec.qlen); - ta->pkey.key.ec.qlen = pk->key.ec.qlen; - return true; - default: - free_ta_contents(ta); // Unknown key type - return false; - } - - // Should never get here, if so there was an unknown error - return false; - } - - br_x509_trust_anchor *certificate_to_trust_anchor(const br_x509_certificate *xc) - { - br_x509_trust_anchor *ta = (br_x509_trust_anchor *)malloc(sizeof(br_x509_trust_anchor)); - if (!ta) - { - return nullptr; - } - - if (!certificate_to_trust_anchor_inner(ta, xc)) - { - free(ta); - return nullptr; - } - return ta; - } - - void free_ta_contents(br_x509_trust_anchor *ta) - { - if (ta) - { - free(ta->dn.data); - if (ta->pkey.key_type == BR_KEYTYPE_RSA) - { - free(ta->pkey.key.rsa.n); - free(ta->pkey.key.rsa.e); - } - else if (ta->pkey.key_type == BR_KEYTYPE_EC) - { - free(ta->pkey.key.ec.q); - } - memset(ta, 0, sizeof(*ta)); - } - } - - // Checks if a bitstream looks like a valid DER(binary) encoding. - // Basically tries to verify the length of all included segments - // matches the length of the input buffer. Does not actually - // validate any contents. - bool looks_like_DER(const unsigned char *buff, size_t len) - { - if (len < 2) - { - return false; - } - if (pgm_read_byte(buff++) != 0x30) - { - return false; - } - int fb = pgm_read_byte(buff++); - len -= 2; - if (fb < 0x80) - { - return (size_t)fb == len; - } - else if (fb == 0x80) - { - return false; - } - else - { - fb -= 0x80; - if (len < (size_t)fb + 2) - { - return false; - } - len -= (size_t)fb; - size_t dlen = 0; - while (fb-- > 0) - { - if (dlen > (len >> 8)) - { - return false; - } - dlen = (dlen << 8) + (size_t)pgm_read_byte(buff++); - } - return dlen == len; - } - } - - void free_pem_object_contents(pem_object *po) - { - if (po) - { - free(po->name); - free(po->data); - po->name = nullptr; - po->data = nullptr; - } - } - - // Converts a PEM (~=base64) source into a set of DER-encoded binary blobs. - // Each blob is named by the ---- BEGIN xxx ---- field, and multiple - // blobs may be returned. - pem_object *decode_pem(const void *src, size_t len, size_t *num) - { - std::vector pem_list; - std::unique_ptr pc(new br_pem_decoder_context); // auto-delete on exit - if (!pc.get()) - { - return nullptr; - } - pem_object po, *pos; - const unsigned char *buff; - std::vector bv; - - *num = 0; - br_pem_decoder_init(pc.get()); - buff = (const unsigned char *)src; - po.name = nullptr; - po.data = nullptr; - po.data_len = 0; - bool inobj = false; - bool extra_nl = true; - - while (len > 0) - { - size_t tlen; - - tlen = br_pem_decoder_push(pc.get(), buff, len); - buff += tlen; - len -= tlen; - switch (br_pem_decoder_event(pc.get())) - { - case BR_PEM_BEGIN_OBJ: - po.name = strdup(br_pem_decoder_name(pc.get())); - br_pem_decoder_setdest(pc.get(), byte_vector_append, &bv); - inobj = true; - break; - - case BR_PEM_END_OBJ: - if (inobj) - { - // Stick data into the vector - po.data = (uint8_t *)malloc(bv.size()); - if (po.data) - { - memcpy(po.data, &bv[0], bv.size()); - po.data_len = bv.size(); - pem_list.push_back(po); - } - // Clean up state for next blob processing - bv.clear(); - po.name = nullptr; - po.data = nullptr; - po.data_len = 0; - inobj = false; - } - break; - - case BR_PEM_ERROR: - free(po.name); - for (size_t i = 0; i < pem_list.size(); i++) - { - free_pem_object_contents(&pem_list[i]); - } - return nullptr; - - default: - // Do nothing here, the parser is still working on things - break; - } - - if (len == 0 && extra_nl) - { - extra_nl = false; - buff = (const unsigned char *)"\n"; - len = 1; - } - } - - if (inobj) - { - free(po.name); - for (size_t i = 0; i < pem_list.size(); i++) - { - free_pem_object_contents(&pem_list[i]); - } - return nullptr; - } - - pos = (pem_object *)malloc((1 + pem_list.size()) * sizeof(*pos)); - if (pos) - { - *num = pem_list.size(); - pem_list.push_back(po); // Null-terminate list - memcpy(pos, &pem_list[0], pem_list.size() * sizeof(*pos)); - } - return pos; - } - - // Parse out DER or PEM encoded certificates from a binary buffer, - // potentially stored in PROGMEM. - br_x509_certificate *read_certificates(const char *buff, size_t len, size_t *num) - { - std::vector cert_list; - pem_object *pos; - size_t u, num_pos; - br_x509_certificate *xcs; - br_x509_certificate dummy; - - *num = 0; - - if (looks_like_DER((const unsigned char *)buff, len)) - { - xcs = (br_x509_certificate *)malloc(2 * sizeof(*xcs)); - if (!xcs) - { - return nullptr; - } - xcs[0].data = (uint8_t *)malloc(len); - if (!xcs[0].data) - { - free(xcs); - return nullptr; - } - memcpy_P(xcs[0].data, buff, len); - xcs[0].data_len = len; - xcs[1].data = nullptr; - xcs[1].data_len = 0; - *num = 1; - return xcs; - } - - pos = decode_pem(buff, len, &num_pos); - if (!pos) - { - return nullptr; - } - for (u = 0; u < num_pos; u++) - { - if (!strcmp_P(pos[u].name, PSTR("CERTIFICATE")) || !strcmp_P(pos[u].name, PSTR("X509 CERTIFICATE"))) - { - br_x509_certificate xc; - xc.data = pos[u].data; - xc.data_len = pos[u].data_len; - pos[u].data = nullptr; // Don't free the data we moved to the xc vector! - cert_list.push_back(xc); - } - } - for (u = 0; u < num_pos; u++) - { - free_pem_object_contents(&pos[u]); - } - free(pos); - - if (cert_list.size() == 0) - { - return nullptr; - } - *num = cert_list.size(); - dummy.data = nullptr; - dummy.data_len = 0; - cert_list.push_back(dummy); - xcs = (br_x509_certificate *)malloc(cert_list.size() * sizeof(*xcs)); - if (!xcs) - { - for (size_t i = 0; i < cert_list.size(); i++) - { - free(cert_list[i].data); // Clean up any captured data blobs - } - return nullptr; - } - memcpy(xcs, &cert_list[0], cert_list.size() * sizeof(br_x509_certificate)); - // XCS now has [].data pointing to the previously allocated blobs, so don't - // want to free anything in cert_list[]. - return xcs; - } - - void free_certificates(br_x509_certificate *certs, size_t num) - { - if (certs) - { - for (size_t u = 0; u < num; u++) - { - free(certs[u].data); - } - free(certs); - } - } - - static public_key *decode_public_key(const unsigned char *buff, size_t len) - { - std::unique_ptr dc(new br_pkey_decoder_context); // auto-delete on exit - if (!dc.get()) - { - return nullptr; - } - - public_key *pk = nullptr; - - br_pkey_decoder_init(dc.get()); - br_pkey_decoder_push(dc.get(), buff, len); - int err = br_pkey_decoder_last_error(dc.get()); - if (err != 0) - { - return nullptr; - } - - const br_rsa_public_key *rk = nullptr; - const br_ec_public_key *ek = nullptr; - switch (br_pkey_decoder_key_type(dc.get())) - { - case BR_KEYTYPE_RSA: - rk = br_pkey_decoder_get_rsa(dc.get()); - pk = (public_key *)malloc(sizeof *pk); - if (!pk) - { - return nullptr; - } - pk->key_type = BR_KEYTYPE_RSA; - pk->key.rsa.n = (uint8_t *)malloc(rk->nlen); - pk->key.rsa.e = (uint8_t *)malloc(rk->elen); - if (!pk->key.rsa.n || !pk->key.rsa.e) - { - free(pk->key.rsa.n); - free(pk->key.rsa.e); - free(pk); - return nullptr; - } - memcpy(pk->key.rsa.n, rk->n, rk->nlen); - pk->key.rsa.nlen = rk->nlen; - memcpy(pk->key.rsa.e, rk->e, rk->elen); - pk->key.rsa.elen = rk->elen; - return pk; - - case BR_KEYTYPE_EC: - ek = br_pkey_decoder_get_ec(dc.get()); - pk = (public_key *)malloc(sizeof *pk); - if (!pk) - { - return nullptr; - } - pk->key_type = BR_KEYTYPE_EC; - pk->key.ec.q = (uint8_t *)malloc(ek->qlen); - if (!pk->key.ec.q) - { - free(pk); - return nullptr; - } - memcpy(pk->key.ec.q, ek->q, ek->qlen); - pk->key.ec.qlen = ek->qlen; - return pk; - - default: - return nullptr; - } - } - - void free_public_key(public_key *pk) - { - if (pk) - { - if (pk->key_type == BR_KEYTYPE_RSA) - { - free(pk->key.rsa.n); - free(pk->key.rsa.e); - } - else if (pk->key_type == BR_KEYTYPE_EC) - { - free(pk->key.ec.q); - } - free(pk); - } - } - - static private_key *decode_private_key(const unsigned char *buff, size_t len) - { - std::unique_ptr dc(new br_skey_decoder_context); // auto-delete on exit - if (!dc.get()) - { - return nullptr; - } - - private_key *sk = nullptr; - - br_skey_decoder_init(dc.get()); - br_skey_decoder_push(dc.get(), buff, len); - int err = br_skey_decoder_last_error(dc.get()); - if (err != 0) - { - return nullptr; - } - - const br_rsa_private_key *rk = nullptr; - const br_ec_private_key *ek = nullptr; - switch (br_skey_decoder_key_type(dc.get())) - { - case BR_KEYTYPE_RSA: - rk = br_skey_decoder_get_rsa(dc.get()); - sk = (private_key *)malloc(sizeof *sk); - if (!sk) - { - return nullptr; - } - sk->key_type = BR_KEYTYPE_RSA; - sk->key.rsa.p = (uint8_t *)malloc(rk->plen); - sk->key.rsa.q = (uint8_t *)malloc(rk->qlen); - sk->key.rsa.dp = (uint8_t *)malloc(rk->dplen); - sk->key.rsa.dq = (uint8_t *)malloc(rk->dqlen); - sk->key.rsa.iq = (uint8_t *)malloc(rk->iqlen); - if (!sk->key.rsa.p || !sk->key.rsa.q || !sk->key.rsa.dp || !sk->key.rsa.dq || !sk->key.rsa.iq) - { - free_private_key(sk); - return nullptr; - } - sk->key.rsa.n_bitlen = rk->n_bitlen; - memcpy(sk->key.rsa.p, rk->p, rk->plen); - sk->key.rsa.plen = rk->plen; - memcpy(sk->key.rsa.q, rk->q, rk->qlen); - sk->key.rsa.qlen = rk->qlen; - memcpy(sk->key.rsa.dp, rk->dp, rk->dplen); - sk->key.rsa.dplen = rk->dplen; - memcpy(sk->key.rsa.dq, rk->dq, rk->dqlen); - sk->key.rsa.dqlen = rk->dqlen; - memcpy(sk->key.rsa.iq, rk->iq, rk->iqlen); - sk->key.rsa.iqlen = rk->iqlen; - return sk; - - case BR_KEYTYPE_EC: - ek = br_skey_decoder_get_ec(dc.get()); - sk = (private_key *)malloc(sizeof *sk); - sk->key_type = BR_KEYTYPE_EC; - sk->key.ec.curve = ek->curve; - sk->key.ec.x = (uint8_t *)malloc(ek->xlen); - if (!sk->key.ec.x) - { - free_private_key(sk); - return nullptr; - } - memcpy(sk->key.ec.x, ek->x, ek->xlen); - sk->key.ec.xlen = ek->xlen; - return sk; - - default: - return nullptr; - } - } - - void free_private_key(private_key *sk) - { - if (sk) - { - switch (sk->key_type) - { - case BR_KEYTYPE_RSA: - free(sk->key.rsa.p); - free(sk->key.rsa.q); - free(sk->key.rsa.dp); - free(sk->key.rsa.dq); - free(sk->key.rsa.iq); - break; - case BR_KEYTYPE_EC: - free(sk->key.ec.x); - break; - default: - // Could be an uninitted key, no sub elements to free - break; - } - free(sk); - } - } - - void free_pem_object(pem_object *pos) - { - if (pos != nullptr) - { - for (size_t u = 0; pos[u].name; u++) - { - free_pem_object_contents(&pos[u]); - } - free(pos); - } - } - - private_key *read_private_key(const char *buff, size_t len) - { - private_key *sk = nullptr; - pem_object *pos = nullptr; - - if (looks_like_DER((const unsigned char *)buff, len)) - { - sk = decode_private_key((const unsigned char *)buff, len); - return sk; - } - - size_t num; - pos = decode_pem(buff, len, &num); - if (pos == nullptr) - { - return nullptr; // PEM decode error - } - for (size_t u = 0; pos[u].name; u++) - { - const char *name = pos[u].name; - if (!strcmp_P(name, PSTR("RSA PRIVATE KEY")) || !strcmp_P(name, PSTR("EC PRIVATE KEY")) || !strcmp_P(name, PSTR("PRIVATE KEY"))) - { - sk = decode_private_key(pos[u].data, pos[u].data_len); - free_pem_object(pos); - return sk; - } - } - // If we hit here, no match - free_pem_object(pos); - return nullptr; - } - - public_key *read_public_key(const char *buff, size_t len) - { - public_key *pk = nullptr; - pem_object *pos = nullptr; - - if (looks_like_DER((const unsigned char *)buff, len)) - { - pk = decode_public_key((const unsigned char *)buff, len); - return pk; - } - size_t num; - pos = decode_pem(buff, len, &num); - if (pos == nullptr) - { - return nullptr; // PEM decode error - } - for (size_t u = 0; pos[u].name; u++) - { - const char *name = pos[u].name; - if (!strcmp_P(name, PSTR("RSA PUBLIC KEY")) || !strcmp_P(name, PSTR("EC PUBLIC KEY")) || !strcmp_P(name, PSTR("PUBLIC KEY"))) - { - pk = decode_public_key(pos[u].data, pos[u].data_len); - free_pem_object(pos); - return pk; - } - } - - // We hit here == no key found - free_pem_object(pos); - return pk; - } - -}; // namespace ESP_Mail_brssl - -namespace ESP_Mail -{ - - // ----- Public Key ----- - - PublicKey::PublicKey() - { - _key = nullptr; - } - - PublicKey::PublicKey(const char *pemKey) - { - _key = nullptr; - parse(pemKey); - } - - PublicKey::PublicKey(const uint8_t *derKey, size_t derLen) - { - _key = nullptr; - parse(derKey, derLen); - } - - PublicKey::~PublicKey() - { - if (_key) - { - ESP_Mail_brssl::free_public_key(_key); - } - } - - bool PublicKey::parse(const char *pemKey) - { - return parse((const uint8_t *)pemKey, strlen_P(pemKey)); - } - - bool PublicKey::parse(const uint8_t *derKey, size_t derLen) - { - if (_key) - { - ESP_Mail_brssl::free_public_key(_key); - _key = nullptr; - } - _key = ESP_Mail_brssl::read_public_key((const char *)derKey, derLen); - return _key ? true : false; - } - - bool PublicKey::isRSA() const - { - if (!_key || _key->key_type != BR_KEYTYPE_RSA) - { - return false; - } - return true; - } - - bool PublicKey::isEC() const - { - if (!_key || _key->key_type != BR_KEYTYPE_EC) - { - return false; - } - return true; - } - - const br_rsa_public_key *PublicKey::getRSA() const - { - if (!_key || _key->key_type != BR_KEYTYPE_RSA) - { - return nullptr; - } - return &_key->key.rsa; - } - - const br_ec_public_key *PublicKey::getEC() const - { - if (!_key || _key->key_type != BR_KEYTYPE_EC) - { - return nullptr; - } - return &_key->key.ec; - } - - // ----- Private Key ----- - - PrivateKey::PrivateKey() - { - _key = nullptr; - } - - PrivateKey::PrivateKey(const char *pemKey) - { - _key = nullptr; - parse(pemKey); - } - - PrivateKey::PrivateKey(const uint8_t *derKey, size_t derLen) - { - _key = nullptr; - parse(derKey, derLen); - } - - PrivateKey::~PrivateKey() - { - if (_key) - { - ESP_Mail_brssl::free_private_key(_key); - } - } - - bool PrivateKey::parse(const char *pemKey) - { - return parse((const uint8_t *)pemKey, strlen_P(pemKey)); - } - - bool PrivateKey::parse(const uint8_t *derKey, size_t derLen) - { - if (_key) - { - ESP_Mail_brssl::free_private_key(_key); - _key = nullptr; - } - _key = ESP_Mail_brssl::read_private_key((const char *)derKey, derLen); - return _key ? true : false; - } - - bool PrivateKey::isRSA() const - { - if (!_key || _key->key_type != BR_KEYTYPE_RSA) - { - return false; - } - return true; - } - - bool PrivateKey::isEC() const - { - if (!_key || _key->key_type != BR_KEYTYPE_EC) - { - return false; - } - return true; - } - - const br_rsa_private_key *PrivateKey::getRSA() const - { - if (!_key || _key->key_type != BR_KEYTYPE_RSA) - { - return nullptr; - } - return &_key->key.rsa; - } - - const br_ec_private_key *PrivateKey::getEC() const - { - if (!_key || _key->key_type != BR_KEYTYPE_EC) - { - return nullptr; - } - return &_key->key.ec; - } - - // ----- Certificate Lists ----- - - ESP_Mail_X509List::ESP_Mail_X509List() - { - _count = 0; - _cert = nullptr; - _ta = nullptr; - } - - ESP_Mail_X509List::ESP_Mail_X509List(const char *pemCert) - { - _count = 0; - _cert = nullptr; - _ta = nullptr; - append(pemCert); - } - - ESP_Mail_X509List::ESP_Mail_X509List(const uint8_t *derCert, size_t derLen) - { - _count = 0; - _cert = nullptr; - _ta = nullptr; - append(derCert, derLen); - } - - ESP_Mail_X509List::~ESP_Mail_X509List() - { - ESP_Mail_brssl::free_certificates(_cert, _count); // also frees cert - for (size_t i = 0; i < _count; i++) - { - ESP_Mail_brssl::free_ta_contents(&_ta[i]); - } - free(_ta); - } - - bool ESP_Mail_X509List::append(const char *pemCert) - { - return append((const uint8_t *)pemCert, strlen_P(pemCert)); - } - - bool ESP_Mail_X509List::append(const uint8_t *derCert, size_t derLen) - { - size_t numCerts; - br_x509_certificate *newCerts = ESP_Mail_brssl::read_certificates((const char *)derCert, derLen, &numCerts); - if (!newCerts) - { - return false; - } - - // Add in the certificates - br_x509_certificate *saveCert = _cert; - _cert = (br_x509_certificate *)realloc(_cert, (numCerts + _count) * sizeof(br_x509_certificate)); - if (!_cert) - { - free(newCerts); - _cert = saveCert; - return false; - } - memcpy(&_cert[_count], newCerts, numCerts * sizeof(br_x509_certificate)); - free(newCerts); - - // Build TAs for each certificate - br_x509_trust_anchor *saveTa = _ta; - _ta = (br_x509_trust_anchor *)realloc(_ta, (numCerts + _count) * sizeof(br_x509_trust_anchor)); - if (!_ta) - { - _ta = saveTa; - return false; - } - for (size_t i = 0; i < numCerts; i++) - { - br_x509_trust_anchor *newTa = ESP_Mail_brssl::certificate_to_trust_anchor(&_cert[_count + i]); - if (newTa) - { - _ta[_count + i] = *newTa; - free(newTa); - } - else - { - return false; // OOM - } - } - _count += numCerts; - - return true; - } - - // SHA256 hash for updater - void HashSHA256::begin() - { - br_sha256_init(&_cc); - memset(_sha256, 0, sizeof(_sha256)); - } - - void HashSHA256::add(const void *data, uint32_t len) - { - br_sha256_update(&_cc, data, len); - } - - void HashSHA256::end() - { - br_sha256_out(&_cc, _sha256); - } - - int HashSHA256::len() - { - return sizeof(_sha256); - } - - const void *HashSHA256::hash() - { - return (const void *)_sha256; - } - - const unsigned char *HashSHA256::oid() - { - return BR_HASH_OID_SHA256; - } - - // SHA256 verifier - uint32_t SigningVerifier::length() - { - if (!_pubKey) - { - return 0; - } - else if (_pubKey->isRSA()) - { - return _pubKey->getRSA()->nlen; - } - else if (_pubKey->isEC()) - { - return _pubKey->getEC()->qlen; - } - else - { - return 0; - } - } - /* - -// We need to use the 2nd stack to do a verification, so do the thunk -// directly inside the class function for ease of use. -extern "C" bool SigningVerifier_verify(PublicKey *_pubKey, UpdaterHashClass *hash, const void *signature, uint32_t signatureLen) { - if (_pubKey->isRSA()) { - bool ret; - unsigned char vrf[hash->len()]; - br_rsa_pkcs1_vrfy vrfy = br_rsa_pkcs1_vrfy_get_default(); - ret = vrfy((const unsigned char *)signature, signatureLen, hash->oid(), sizeof(vrf), _pubKey->getRSA(), vrf); - if (!ret || memcmp(vrf, hash->hash(), sizeof(vrf)) ) { - return false; - } else { - return true; - } - } else { - br_ecdsa_vrfy vrfy = br_ecdsa_vrfy_raw_get_default(); - // The EC verifier actually does the compare, unlike the RSA one - return vrfy(br_ec_get_default(), hash->hash(), hash->len(), _pubKey->getEC(), (const unsigned char *)signature, signatureLen); - } -}; - - - -#if !CORE_MOCK -make_stack_thunk(SigningVerifier_verify); -extern "C" bool thunk_SigningVerifier_verify(PublicKey *_pubKey, UpdaterHashClass *hash, const void *signature, uint32_t signatureLen); -#endif - -bool SigningVerifier::verify(UpdaterHashClass *hash, const void *signature, uint32_t signatureLen) { - if (!_pubKey || !hash || !signature || signatureLen != length()) return false; -#if !CORE_MOCK - return thunk_SigningVerifier_verify(_pubKey, hash, signature, signatureLen); -#else - return SigningVerifier_verify(_pubKey, hash, signature, signatureLen); -#endif -} - - - -#if !CORE_MOCK - -// Second stack thunked helpers -make_stack_thunk(br_ssl_engine_recvapp_ack); -make_stack_thunk(br_ssl_engine_recvapp_buf); -make_stack_thunk(br_ssl_engine_recvrec_ack); -make_stack_thunk(br_ssl_engine_recvrec_buf); -make_stack_thunk(br_ssl_engine_sendapp_ack); -make_stack_thunk(br_ssl_engine_sendapp_buf); -make_stack_thunk(br_ssl_engine_sendrec_ack); -make_stack_thunk(br_ssl_engine_sendrec_buf); - -#endif -*/ - -}; // namespace ESP_Mail - -#if ARDUINO_SIGNING -namespace -{ - static ESP_Mail::PublicKey signingPubKey(signing_pubkey); - static ESP_Mail::HashSHA256 __signingHash; - static ESP_Mail::SigningVerifier __signingVerifier(&signingPubKey); -}; // namespace - -namespace esp8266 -{ - UpdaterHashClass &updaterSigningHash = __signingHash; - UpdaterVerifyClass &updaterSigningVerifier = __signingVerifier; -}; // namespace esp8266 -#endif - -#endif /* ESP8266 */ - -#endif /* ESP_Mail_BearSSLHelpers_CPP */ \ No newline at end of file +/* + WiFiClientBearSSL- SSL client/server for esp8266 using BearSSL libraries + - Mostly compatible with Arduino WiFi shield library and standard + WiFiClient/ServerSecure (except for certificate handling). + + Copyright (c) 2018 Earle F. Philhower, III + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ +#ifndef BSSL_HELPER_CPP +#define BSSL_HELPER_CPP + +#pragma GCC diagnostic ignored "-Wunused-function" +#pragma GCC diagnostic ignored "-Wvla" + +#include +#include "../ESP_SSLClient_FS.h" +#include "../ESP_SSLClient_Const.h" +#if defined(USE_LIB_SSL_ENGINE) + +#include "BSSL_Helper.h" +#include +#include +#include "../bssl/bearssl.h" +#include +#include +#if defined __has_include +#if __has_include() +#include +#endif +#endif + +namespace key_bssl +{ + // Code here is pulled from brssl sources, with the copyright and license + // shown below. I've rewritten things using C++ semantics and removed + // custom VEC_* calls (std::vector to the rescue) and adjusted things to + // allow for long-running operation (i.e. some memory issues when DERs + // passed into the decoders). Bugs are most likely my fault. + + // Original (c) message follows: + /* + Copyright (c) 2016 Thomas Pornin + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ + + class private_key + { + public: + int key_type; /* BR_KEYTYPE_RSA or BR_KEYTYPE_EC */ + union + { + br_rsa_private_key rsa; + br_ec_private_key ec; + } key; + }; + + class public_key + { + public: + int key_type; /* BR_KEYTYPE_RSA or BR_KEYTYPE_EC */ + union + { + br_rsa_public_key rsa; + br_ec_public_key ec; + } key; + }; + + class pem_object + { + public: + char *name; + unsigned char *data; + size_t data_len; + }; + + // Forward definitions + void free_ta_contents(br_x509_trust_anchor *ta); + void free_public_key(public_key *pk); + void free_private_key(private_key *sk); + bool looks_like_DER(const unsigned char *buf, size_t len); + pem_object *decode_pem(const void *src, size_t len, size_t *num); + void free_pem_object_contents(pem_object *po); + char *strdupImpl(const char *s); + + // Used as callback multiple places to append a string to a vector + static void byte_vector_append(void *ctx, const void *buff, size_t len) + { + std::vector *vec = static_cast *>(ctx); + vec->reserve(vec->size() + len); // Allocate extra space all at once + for (size_t i = 0; i < len; i++) + { + vec->push_back(((uint8_t *)buff)[i]); + } + } + + static bool certificate_to_trust_anchor_inner(br_x509_trust_anchor *ta, const br_x509_certificate *xc) + { + std::unique_ptr dc(new br_x509_decoder_context_libmail); // auto-delete on exit + std::vector vdn; + br_x509_pkey *pk; + + // Clear everything in the Trust Anchor + memset(ta, 0, sizeof(*ta)); + + br_x509_decoder_init(dc.get(), byte_vector_append, (void *)&vdn); + br_x509_decoder_push_libmail(dc.get(), xc->data, xc->data_len); + pk = br_x509_decoder_get_pkey(dc.get()); + if (pk == nullptr) + { + return false; // No key present, something broken in the cert! + } + + // Copy the raw certificate data + ta->dn.data = (uint8_t *)malloc(vdn.size()); + if (!ta->dn.data) + { + return false; // OOM, but nothing yet allocated + } + memcpy(ta->dn.data, &vdn[0], vdn.size()); + ta->dn.len = vdn.size(); + ta->flags = 0; + if (br_x509_decoder_isCA(dc.get())) + { + ta->flags |= BR_X509_TA_CA; + } + + // Extract the public key + switch (pk->key_type) + { + case BR_KEYTYPE_RSA: + ta->pkey.key_type = BR_KEYTYPE_RSA; + ta->pkey.key.rsa.n = (uint8_t *)malloc(pk->key.rsa.nlen); + ta->pkey.key.rsa.e = (uint8_t *)malloc(pk->key.rsa.elen); + if ((ta->pkey.key.rsa.n == nullptr) || (ta->pkey.key.rsa.e == nullptr)) + { + free_ta_contents(ta); // OOM, so clean up + return false; + } + memcpy(ta->pkey.key.rsa.n, pk->key.rsa.n, pk->key.rsa.nlen); + ta->pkey.key.rsa.nlen = pk->key.rsa.nlen; + memcpy(ta->pkey.key.rsa.e, pk->key.rsa.e, pk->key.rsa.elen); + ta->pkey.key.rsa.elen = pk->key.rsa.elen; + return true; + case BR_KEYTYPE_EC: + ta->pkey.key_type = BR_KEYTYPE_EC; + ta->pkey.key.ec.curve = pk->key.ec.curve; + ta->pkey.key.ec.q = (uint8_t *)malloc(pk->key.ec.qlen); + if (ta->pkey.key.ec.q == nullptr) + { + free_ta_contents(ta); // OOM, so clean up + return false; + } + memcpy(ta->pkey.key.ec.q, pk->key.ec.q, pk->key.ec.qlen); + ta->pkey.key.ec.qlen = pk->key.ec.qlen; + return true; + default: + free_ta_contents(ta); // Unknown key type + return false; + } + + // Should never get here, if so there was an unknown error + return false; + } + + br_x509_trust_anchor *certificate_to_trust_anchor(const br_x509_certificate *xc) + { + br_x509_trust_anchor *ta = (br_x509_trust_anchor *)malloc(sizeof(br_x509_trust_anchor)); + if (!ta) + { + return nullptr; + } + + if (!certificate_to_trust_anchor_inner(ta, xc)) + { + free(ta); + return nullptr; + } + return ta; + } + + void free_ta_contents(br_x509_trust_anchor *ta) + { + if (ta) + { + free(ta->dn.data); + if (ta->pkey.key_type == BR_KEYTYPE_RSA) + { + free(ta->pkey.key.rsa.n); + free(ta->pkey.key.rsa.e); + } + else if (ta->pkey.key_type == BR_KEYTYPE_EC) + { + free(ta->pkey.key.ec.q); + } + memset(ta, 0, sizeof(*ta)); + } + } + + // Checks if a bitstream looks like a valid DER(binary) encoding. + // Basically tries to verify the length of all included segments + // matches the length of the input buffer. Does not actually + // validate any contents. + bool looks_like_DER(const unsigned char *buff, size_t len) + { + if (len < 2) + { + return false; + } + if (pgm_read_byte(buff++) != 0x30) + { + return false; + } + int fb = pgm_read_byte(buff++); + len -= 2; + if (fb < 0x80) + { + return (size_t)fb == len; + } + else if (fb == 0x80) + { + return false; + } + else + { + fb -= 0x80; + if (len < (size_t)fb + 2) + { + return false; + } + len -= (size_t)fb; + size_t dlen = 0; + while (fb-- > 0) + { + if (dlen > (len >> 8)) + { + return false; + } + dlen = (dlen << 8) + (size_t)pgm_read_byte(buff++); + } + return dlen == len; + } + } + + void free_pem_object_contents(pem_object *po) + { + if (po) + { + free(po->name); + free(po->data); + po->name = nullptr; + po->data = nullptr; + } + } + + char *strdupImpl(const char *s) + { + size_t slen = strlen(s); + char *result = (char *)malloc(slen + 1); + if (!result) + return NULL; + memcpy(result, s, slen + 1); + return result; + } + + // Converts a PEM (~=base64) source into a set of DER-encoded binary blobs. + // Each blob is named by the ---- BEGIN xxx ---- field, and multiple + // blobs may be returned. + pem_object *decode_pem(const void *src, size_t len, size_t *num) + { + std::vector pem_list; + std::unique_ptr pc(new br_pem_decoder_context); // auto-delete on exit + if (!pc.get()) + { + return nullptr; + } + pem_object po, *pos; + const unsigned char *buff; + std::vector bv; + + *num = 0; + br_pem_decoder_init(pc.get()); + buff = (const unsigned char *)src; + po.name = nullptr; + po.data = nullptr; + po.data_len = 0; + bool inobj = false; + bool extra_nl = true; + + while (len > 0) + { + size_t tlen; + + tlen = br_pem_decoder_push(pc.get(), buff, len); + buff += tlen; + len -= tlen; + switch (br_pem_decoder_event(pc.get())) + { + case BR_PEM_BEGIN_OBJ: + po.name = strdupImpl(br_pem_decoder_name(pc.get())); + br_pem_decoder_setdest(pc.get(), byte_vector_append, &bv); + inobj = true; + break; + + case BR_PEM_END_OBJ: + if (inobj) + { + // Stick data into the vector + po.data = (uint8_t *)malloc(bv.size()); + if (po.data) + { + memcpy(po.data, &bv[0], bv.size()); + po.data_len = bv.size(); + pem_list.push_back(po); + } + // Clean up state for next blob processing + bv.clear(); + po.name = nullptr; + po.data = nullptr; + po.data_len = 0; + inobj = false; + } + break; + + case BR_PEM_ERROR: + free(po.name); + for (size_t i = 0; i < pem_list.size(); i++) + { + free_pem_object_contents(&pem_list[i]); + } + return nullptr; + + default: + // Do nothing here, the parser is still working on things + break; + } + + if (len == 0 && extra_nl) + { + extra_nl = false; + buff = (const unsigned char *)"\n"; + len = 1; + } + } + + if (inobj) + { + free(po.name); + for (size_t i = 0; i < pem_list.size(); i++) + { + free_pem_object_contents(&pem_list[i]); + } + return nullptr; + } + + pos = (pem_object *)malloc((1 + pem_list.size()) * sizeof(*pos)); + if (pos) + { + *num = pem_list.size(); + pem_list.push_back(po); // Null-terminate list + memcpy(pos, &pem_list[0], pem_list.size() * sizeof(*pos)); + } + return pos; + } + + // Parse out DER or PEM encoded certificates from a binary buffer, + // potentially stored in PROGMEM. + br_x509_certificate *read_certificates(const char *buff, size_t len, size_t *num) + { + std::vector cert_list; + pem_object *pos; + size_t u, num_pos; + br_x509_certificate *xcs; + br_x509_certificate dummy; + + *num = 0; + + if (looks_like_DER((const unsigned char *)buff, len)) + { + xcs = (br_x509_certificate *)malloc(2 * sizeof(*xcs)); + if (!xcs) + { + return nullptr; + } + xcs[0].data = (uint8_t *)malloc(len); + if (!xcs[0].data) + { + free(xcs); + return nullptr; + } + memcpy_P(xcs[0].data, buff, len); + xcs[0].data_len = len; + xcs[1].data = nullptr; + xcs[1].data_len = 0; + *num = 1; + return xcs; + } + + pos = decode_pem(buff, len, &num_pos); + if (!pos) + { + return nullptr; + } + for (u = 0; u < num_pos; u++) + { + if (!strcmp_P(pos[u].name, PSTR("CERTIFICATE")) || !strcmp_P(pos[u].name, PSTR("X509 CERTIFICATE"))) + { + br_x509_certificate xc; + xc.data = pos[u].data; + xc.data_len = pos[u].data_len; + pos[u].data = nullptr; // Don't free the data we moved to the xc vector! + cert_list.push_back(xc); + } + } + for (u = 0; u < num_pos; u++) + { + free_pem_object_contents(&pos[u]); + } + free(pos); + + if (cert_list.size() == 0) + { + return nullptr; + } + *num = cert_list.size(); + dummy.data = nullptr; + dummy.data_len = 0; + cert_list.push_back(dummy); + xcs = (br_x509_certificate *)malloc(cert_list.size() * sizeof(*xcs)); + if (!xcs) + { + for (size_t i = 0; i < cert_list.size(); i++) + { + free(cert_list[i].data); // Clean up any captured data blobs + } + return nullptr; + } + memcpy(xcs, &cert_list[0], cert_list.size() * sizeof(br_x509_certificate)); + // XCS now has [].data pointing to the previously allocated blobs, so don't + // want to free anything in cert_list[]. + return xcs; + } + + void free_certificates(br_x509_certificate *certs, size_t num) + { + if (certs) + { + for (size_t u = 0; u < num; u++) + { + free(certs[u].data); + } + free(certs); + } + } + + static public_key *decode_public_key(const unsigned char *buff, size_t len) + { + std::unique_ptr dc(new br_pkey_decoder_context); // auto-delete on exit + if (!dc.get()) + { + return nullptr; + } + + public_key *pk = nullptr; + // https://github.com/yglukhov/bearssl_pkey_decoder + br_pkey_decoder_init(dc.get()); + br_pkey_decoder_push(dc.get(), buff, len); + int err = br_pkey_decoder_last_error(dc.get()); + if (err != 0) + { + return nullptr; + } + + const br_rsa_public_key *rk = nullptr; + const br_ec_public_key *ek = nullptr; + switch (br_pkey_decoder_key_type(dc.get())) + { + case BR_KEYTYPE_RSA: + rk = br_pkey_decoder_get_rsa(dc.get()); + pk = (public_key *)malloc(sizeof *pk); + if (!pk) + { + return nullptr; + } + pk->key_type = BR_KEYTYPE_RSA; + pk->key.rsa.n = (uint8_t *)malloc(rk->nlen); + pk->key.rsa.e = (uint8_t *)malloc(rk->elen); + if (!pk->key.rsa.n || !pk->key.rsa.e) + { + free(pk->key.rsa.n); + free(pk->key.rsa.e); + free(pk); + return nullptr; + } + memcpy(pk->key.rsa.n, rk->n, rk->nlen); + pk->key.rsa.nlen = rk->nlen; + memcpy(pk->key.rsa.e, rk->e, rk->elen); + pk->key.rsa.elen = rk->elen; + return pk; + + case BR_KEYTYPE_EC: + ek = br_pkey_decoder_get_ec(dc.get()); + pk = (public_key *)malloc(sizeof *pk); + if (!pk) + { + return nullptr; + } + pk->key_type = BR_KEYTYPE_EC; + pk->key.ec.q = (uint8_t *)malloc(ek->qlen); + if (!pk->key.ec.q) + { + free(pk); + return nullptr; + } + memcpy(pk->key.ec.q, ek->q, ek->qlen); + pk->key.ec.qlen = ek->qlen; + pk->key.ec.curve = ek->curve; + return pk; + + default: + return nullptr; + } + } + + void free_public_key(public_key *pk) + { + if (pk) + { + if (pk->key_type == BR_KEYTYPE_RSA) + { + free(pk->key.rsa.n); + free(pk->key.rsa.e); + } + else if (pk->key_type == BR_KEYTYPE_EC) + { + free(pk->key.ec.q); + } + free(pk); + } + } + + static private_key *decode_private_key(const unsigned char *buff, size_t len) + { + std::unique_ptr dc(new br_skey_decoder_context); // auto-delete on exit + if (!dc.get()) + { + return nullptr; + } + + private_key *sk = nullptr; + + br_skey_decoder_init(dc.get()); + br_skey_decoder_push(dc.get(), buff, len); + int err = br_skey_decoder_last_error(dc.get()); + if (err != 0) + { + return nullptr; + } + + const br_rsa_private_key *rk = nullptr; + const br_ec_private_key *ek = nullptr; + switch (br_skey_decoder_key_type(dc.get())) + { + case BR_KEYTYPE_RSA: + rk = br_skey_decoder_get_rsa(dc.get()); + sk = (private_key *)malloc(sizeof *sk); + if (!sk) + { + return nullptr; + } + sk->key_type = BR_KEYTYPE_RSA; + sk->key.rsa.p = (uint8_t *)malloc(rk->plen); + sk->key.rsa.q = (uint8_t *)malloc(rk->qlen); + sk->key.rsa.dp = (uint8_t *)malloc(rk->dplen); + sk->key.rsa.dq = (uint8_t *)malloc(rk->dqlen); + sk->key.rsa.iq = (uint8_t *)malloc(rk->iqlen); + if (!sk->key.rsa.p || !sk->key.rsa.q || !sk->key.rsa.dp || !sk->key.rsa.dq || !sk->key.rsa.iq) + { + free_private_key(sk); + return nullptr; + } + sk->key.rsa.n_bitlen = rk->n_bitlen; + memcpy(sk->key.rsa.p, rk->p, rk->plen); + sk->key.rsa.plen = rk->plen; + memcpy(sk->key.rsa.q, rk->q, rk->qlen); + sk->key.rsa.qlen = rk->qlen; + memcpy(sk->key.rsa.dp, rk->dp, rk->dplen); + sk->key.rsa.dplen = rk->dplen; + memcpy(sk->key.rsa.dq, rk->dq, rk->dqlen); + sk->key.rsa.dqlen = rk->dqlen; + memcpy(sk->key.rsa.iq, rk->iq, rk->iqlen); + sk->key.rsa.iqlen = rk->iqlen; + return sk; + + case BR_KEYTYPE_EC: + ek = br_skey_decoder_get_ec(dc.get()); + sk = (private_key *)malloc(sizeof *sk); + if (!sk) + { + return nullptr; + } + sk->key_type = BR_KEYTYPE_EC; + sk->key.ec.curve = ek->curve; + sk->key.ec.x = (uint8_t *)malloc(ek->xlen); + if (!sk->key.ec.x) + { + free_private_key(sk); + return nullptr; + } + memcpy(sk->key.ec.x, ek->x, ek->xlen); + sk->key.ec.xlen = ek->xlen; + return sk; + + default: + return nullptr; + } + } + + void free_private_key(private_key *sk) + { + if (sk) + { + switch (sk->key_type) + { + case BR_KEYTYPE_RSA: + free(sk->key.rsa.p); + free(sk->key.rsa.q); + free(sk->key.rsa.dp); + free(sk->key.rsa.dq); + free(sk->key.rsa.iq); + break; + case BR_KEYTYPE_EC: + free(sk->key.ec.x); + break; + default: + // Could be an uninitted key, no sub elements to free + break; + } + free(sk); + } + } + + void free_pem_object(pem_object *pos) + { + if (pos != nullptr) + { + for (size_t u = 0; pos[u].name; u++) + { + free_pem_object_contents(&pos[u]); + } + free(pos); + } + } + + private_key *read_private_key(const char *buff, size_t len) + { + private_key *sk = nullptr; + pem_object *pos = nullptr; + + if (looks_like_DER((const unsigned char *)buff, len)) + { + sk = decode_private_key((const unsigned char *)buff, len); + return sk; + } + + size_t num; + pos = decode_pem(buff, len, &num); + if (pos == nullptr) + { + return nullptr; // PEM decode error + } + for (size_t u = 0; pos[u].name; u++) + { + const char *name = pos[u].name; + if (!strcmp_P(name, PSTR("RSA PRIVATE KEY")) || !strcmp_P(name, PSTR("EC PRIVATE KEY")) || !strcmp_P(name, PSTR("PRIVATE KEY"))) + { + sk = decode_private_key(pos[u].data, pos[u].data_len); + free_pem_object(pos); + return sk; + } + } + // If we hit here, no match + free_pem_object(pos); + return nullptr; + } + + public_key *read_public_key(const char *buff, size_t len) + { + public_key *pk = nullptr; + pem_object *pos = nullptr; + + if (looks_like_DER((const unsigned char *)buff, len)) + { + pk = decode_public_key((const unsigned char *)buff, len); + return pk; + } + size_t num; + pos = decode_pem(buff, len, &num); + if (pos == nullptr) + { + return nullptr; // PEM decode error + } + for (size_t u = 0; pos[u].name; u++) + { + const char *name = pos[u].name; + if (!strcmp_P(name, PSTR("RSA PUBLIC KEY")) || !strcmp_P(name, PSTR("EC PUBLIC KEY")) || !strcmp_P(name, PSTR("PUBLIC KEY"))) + { + pk = decode_public_key(pos[u].data, pos[u].data_len); + free_pem_object(pos); + return pk; + } + } + + // We hit here == no key found + free_pem_object(pos); + return pk; + } + + static uint8_t *loadStream(Stream &stream, size_t size) + { + uint8_t *dest = (uint8_t *)malloc(size); + if (!dest) + { + return nullptr; // OOM error + } + if (size != stream.readBytes(dest, size)) + { + free(dest); // Error during read + return nullptr; + } + return dest; + } +}; + +namespace bssl +{ + + // ----- Public Key ----- + + PublicKey::PublicKey() + { + _key = nullptr; + } + + PublicKey::PublicKey(const char *pemKey) + { + _key = nullptr; + parse(pemKey); + } + + PublicKey::PublicKey(const uint8_t *derKey, size_t derLen) + { + _key = nullptr; + parse(derKey, derLen); + } + + PublicKey::PublicKey(Stream &stream, size_t size) + { + _key = nullptr; + auto buff = key_bssl::loadStream(stream, size); + if (buff) + { + parse(buff, size); + free(buff); + } + } + + PublicKey::~PublicKey() + { + if (_key) + { + key_bssl::free_public_key(_key); + } + } + + bool PublicKey::parse(const char *pemKey) + { + return parse((const uint8_t *)pemKey, strlen_P(pemKey)); + } + + bool PublicKey::parse(const uint8_t *derKey, size_t derLen) + { + if (_key) + { + key_bssl::free_public_key(_key); + _key = nullptr; + } + _key = key_bssl::read_public_key((const char *)derKey, derLen); + return _key ? true : false; + } + + bool PublicKey::isRSA() const + { + if (!_key || _key->key_type != BR_KEYTYPE_RSA) + { + return false; + } + return true; + } + + bool PublicKey::isEC() const + { + if (!_key || _key->key_type != BR_KEYTYPE_EC) + { + return false; + } + return true; + } + + const br_rsa_public_key *PublicKey::getRSA() const + { + if (!_key || _key->key_type != BR_KEYTYPE_RSA) + { + return nullptr; + } + return &_key->key.rsa; + } + + const br_ec_public_key *PublicKey::getEC() const + { + if (!_key || _key->key_type != BR_KEYTYPE_EC) + { + return nullptr; + } + return &_key->key.ec; + } + + // ----- Private Key ----- + + PrivateKey::PrivateKey() + { + _key = nullptr; + } + + PrivateKey::PrivateKey(const char *pemKey) + { + _key = nullptr; + parse(pemKey); + } + + PrivateKey::PrivateKey(const uint8_t *derKey, size_t derLen) + { + _key = nullptr; + parse(derKey, derLen); + } + + PrivateKey::PrivateKey(Stream &stream, size_t size) + { + _key = nullptr; + auto buff = key_bssl::loadStream(stream, size); + if (buff) + { + parse(buff, size); + free(buff); + } + } + + PrivateKey::~PrivateKey() + { + if (_key) + { + key_bssl::free_private_key(_key); + } + } + + bool PrivateKey::parse(const char *pemKey) + { + return parse((const uint8_t *)pemKey, strlen_P(pemKey)); + } + + bool PrivateKey::parse(const uint8_t *derKey, size_t derLen) + { + if (_key) + { + key_bssl::free_private_key(_key); + _key = nullptr; + } + _key = key_bssl::read_private_key((const char *)derKey, derLen); + return _key ? true : false; + } + + bool PrivateKey::isRSA() const + { + if (!_key || _key->key_type != BR_KEYTYPE_RSA) + { + return false; + } + return true; + } + + bool PrivateKey::isEC() const + { + if (!_key || _key->key_type != BR_KEYTYPE_EC) + { + return false; + } + return true; + } + + const br_rsa_private_key *PrivateKey::getRSA() const + { + if (!_key || _key->key_type != BR_KEYTYPE_RSA) + { + return nullptr; + } + return &_key->key.rsa; + } + + const br_ec_private_key *PrivateKey::getEC() const + { + if (!_key || _key->key_type != BR_KEYTYPE_EC) + { + return nullptr; + } + return &_key->key.ec; + } + + // ----- Certificate Lists ----- + + X509List::X509List() + { + _count = 0; + _cert = nullptr; + _ta = nullptr; + } + + X509List::X509List(const char *pemCert) + { + _count = 0; + _cert = nullptr; + _ta = nullptr; + append(pemCert); + } + + X509List::X509List(const uint8_t *derCert, size_t derLen) + { + _count = 0; + _cert = nullptr; + _ta = nullptr; + append(derCert, derLen); + } + + X509List::X509List(Stream &stream, size_t size) + { + _count = 0; + _cert = nullptr; + _ta = nullptr; + auto buff = key_bssl::loadStream(stream, size); + if (buff) + { + append(buff, size); + free(buff); + } + } + + X509List::~X509List() + { + key_bssl::free_certificates(_cert, _count); // also frees cert + for (size_t i = 0; i < _count; i++) + { + key_bssl::free_ta_contents(&_ta[i]); + } + free(_ta); + } + + bool X509List::append(const char *pemCert) + { + return append((const uint8_t *)pemCert, strlen_P(pemCert)); + } + + bool X509List::append(const uint8_t *derCert, size_t derLen) + { + size_t numCerts; + br_x509_certificate *newCerts = key_bssl::read_certificates((const char *)derCert, derLen, &numCerts); + if (!newCerts) + { + return false; + } + + // Add in the certificates + br_x509_certificate *saveCert = _cert; + _cert = (br_x509_certificate *)realloc(_cert, (numCerts + _count) * sizeof(br_x509_certificate)); + if (!_cert) + { + free(newCerts); + _cert = saveCert; + return false; + } + memcpy(&_cert[_count], newCerts, numCerts * sizeof(br_x509_certificate)); + free(newCerts); + + // Build TAs for each certificate + br_x509_trust_anchor *saveTa = _ta; + _ta = (br_x509_trust_anchor *)realloc(_ta, (numCerts + _count) * sizeof(br_x509_trust_anchor)); + if (!_ta) + { + _ta = saveTa; + return false; + } + for (size_t i = 0; i < numCerts; i++) + { + br_x509_trust_anchor *newTa = key_bssl::certificate_to_trust_anchor(&_cert[_count + i]); + if (newTa) + { + _ta[_count + i] = *newTa; + free(newTa); + } + else + { + return false; // OOM + } + } + _count += numCerts; + + return true; + } + +}; + +#endif + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/client/BSSL_Helper.h b/lib/libesp32/ESP-Mail-Client/src/SSLClient/client/BSSL_Helper.h new file mode 100644 index 000000000..509b7a856 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/client/BSSL_Helper.h @@ -0,0 +1,447 @@ + +/* + WiFiClientBearSSL- SSL client/server for esp8266 using BearSSL libraries + - Mostly compatible with Arduino WiFi shield library and standard + WiFiClient/ServerSecure (except for certificate handling). + + Copyright (c) 2018 Earle F. Philhower, III + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ +#ifndef BSSL_HELPER_H +#define BSSL_HELPER_H + +#pragma GCC diagnostic ignored "-Wunused-function" +#pragma GCC diagnostic ignored "-Wvla" + +#include +#include "../ESP_SSLClient_FS.h" +#include "../ESP_SSLClient_Const.h" + +#if defined(USE_EMBED_SSL_ENGINE) + +#if defined(ESP8266) + +#ifdef __GNUC__ +#if __GNUC__ > 4 || __GNUC__ == 10 +#if defined(ARDUINO_ESP8266_GIT_VER) +#if ARDUINO_ESP8266_GIT_VER > 0 +#define ESP8266_CORE_SDK_V3_X_X +#endif +#endif +#endif +#endif + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#else + +#include +#include +#include +#include + +#endif + +#elif defined(USE_LIB_SSL_ENGINE) + +#include "../bssl/bearssl.h" + +#endif + +#if defined(USE_LIB_SSL_ENGINE) || defined(USE_EMBED_SSL_ENGINE) +// Cache for a TLS session with a server +// Use with BearSSL::WiFiClientSecure::setSession +// to accelerate the TLS handshake +class BearSSL_Session +{ + friend class BSSL_SSL_Client; + +public: + BearSSL_Session() + { + memset(&_session, 0, sizeof(_session)); + } + + br_ssl_session_parameters *getSession() + { + return &_session; + } + +private: + // The actual BearSSL session information + br_ssl_session_parameters _session; +}; + +static const uint16_t suites_P[] PROGMEM = { +#ifndef BEARSSL_SSL_BASIC + BR_TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256, + BR_TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256, + BR_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, + BR_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, + BR_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, + BR_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, + BR_TLS_ECDHE_ECDSA_WITH_AES_128_CCM, + BR_TLS_ECDHE_ECDSA_WITH_AES_256_CCM, + BR_TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8, + BR_TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8, + BR_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, + BR_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, + BR_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384, + BR_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384, + BR_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, + BR_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, + BR_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, + BR_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, + BR_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256, + BR_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256, + BR_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384, + BR_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384, + BR_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256, + BR_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256, + BR_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384, + BR_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384, + BR_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA, + BR_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA, + BR_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA, + BR_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA, + BR_TLS_RSA_WITH_AES_128_GCM_SHA256, + BR_TLS_RSA_WITH_AES_256_GCM_SHA384, + BR_TLS_RSA_WITH_AES_128_CCM, + BR_TLS_RSA_WITH_AES_256_CCM, + BR_TLS_RSA_WITH_AES_128_CCM_8, + BR_TLS_RSA_WITH_AES_256_CCM_8, +#endif + BR_TLS_RSA_WITH_AES_128_CBC_SHA256, + BR_TLS_RSA_WITH_AES_256_CBC_SHA256, + BR_TLS_RSA_WITH_AES_128_CBC_SHA, + BR_TLS_RSA_WITH_AES_256_CBC_SHA, +#ifndef BEARSSL_SSL_BASIC + BR_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA, + BR_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, + BR_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA, + BR_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA, + BR_TLS_RSA_WITH_3DES_EDE_CBC_SHA +#endif +}; + +// For apps which want to use less secure but faster ciphers, only +static const uint16_t faster_suites_P[] PROGMEM = { + BR_TLS_RSA_WITH_AES_256_CBC_SHA256, + BR_TLS_RSA_WITH_AES_128_CBC_SHA256, + BR_TLS_RSA_WITH_AES_256_CBC_SHA, + BR_TLS_RSA_WITH_AES_128_CBC_SHA}; + +// Internal opaque structures, not needed by user applications +namespace key_bssl +{ + class public_key; + class private_key; +}; + +namespace bssl +{ + + // Holds either a single public RSA or EC key for use when BearSSL wants a pubkey. + // Copies all associated data so no need to keep input PEM/DER keys. + // All inputs can be either in RAM or PROGMEM. + class PublicKey + { + public: + PublicKey(); + PublicKey(const char *pemKey); + PublicKey(const uint8_t *derKey, size_t derLen); + PublicKey(Stream &stream, size_t size); + PublicKey(Stream &stream) : PublicKey(stream, stream.available()){}; + ~PublicKey(); + + bool parse(const char *pemKey); + bool parse(const uint8_t *derKey, size_t derLen); + + // Accessors for internal use, not needed by apps + bool isRSA() const; + bool isEC() const; + const br_rsa_public_key *getRSA() const; + const br_ec_public_key *getEC() const; + + // Disable the copy constructor, we're pointer based + PublicKey(const PublicKey &that) = delete; + PublicKey &operator=(const PublicKey &that) = delete; + + private: + key_bssl::public_key *_key; + }; + + // Holds either a single private RSA or EC key for use when BearSSL wants a secretkey. + // Copies all associated data so no need to keep input PEM/DER keys. + // All inputs can be either in RAM or PROGMEM. + class PrivateKey + { + public: + PrivateKey(); + PrivateKey(const char *pemKey); + PrivateKey(const uint8_t *derKey, size_t derLen); + PrivateKey(Stream &stream, size_t size); + PrivateKey(Stream &stream) : PrivateKey(stream, stream.available()){}; + ~PrivateKey(); + + bool parse(const char *pemKey); + bool parse(const uint8_t *derKey, size_t derLen); + + // Accessors for internal use, not needed by apps + bool isRSA() const; + bool isEC() const; + const br_rsa_private_key *getRSA() const; + const br_ec_private_key *getEC() const; + + // Disable the copy constructor, we're pointer based + PrivateKey(const PrivateKey &that) = delete; + PrivateKey &operator=(const PrivateKey &that) = delete; + + private: + key_bssl::private_key *_key; + }; + + // Holds one or more X.509 certificates and associated trust anchors for + // use whenever BearSSL needs a cert or TA. May want to have multiple + // certs for things like a series of trusted CAs (but check the CertStore class + // for a more memory efficient way). + // Copies all associated data so no need to keep input PEM/DER certs. + // All inputs can be either in RAM or PROGMEM. + class X509List + { + public: + X509List(); + X509List(const char *pemCert); + X509List(const uint8_t *derCert, size_t derLen); + X509List(Stream &stream, size_t size); + X509List(Stream &stream) : X509List(stream, stream.available()){}; + ~X509List(); + + bool append(const char *pemCert); + bool append(const uint8_t *derCert, size_t derLen); + + // Accessors + size_t getCount() const + { + return _count; + } + const br_x509_certificate *getX509Certs() const + { + return _cert; + } + const br_x509_trust_anchor *getTrustAnchors() const + { + return _ta; + } + + // Disable the copy constructor, we're pointer based + X509List(const X509List &that) = delete; + X509List &operator=(const X509List &that) = delete; + + private: + size_t _count; + br_x509_certificate *_cert; + br_x509_trust_anchor *_ta; + }; + + extern "C" + { + + // Install hashes into the SSL engine + static void br_ssl_client_install_hashes(br_ssl_engine_context *eng) + { + br_ssl_engine_set_hash(eng, br_md5_ID, &br_md5_vtable); + br_ssl_engine_set_hash(eng, br_sha1_ID, &br_sha1_vtable); + br_ssl_engine_set_hash(eng, br_sha224_ID, &br_sha224_vtable); + br_ssl_engine_set_hash(eng, br_sha256_ID, &br_sha256_vtable); + br_ssl_engine_set_hash(eng, br_sha384_ID, &br_sha384_vtable); + br_ssl_engine_set_hash(eng, br_sha512_ID, &br_sha512_vtable); + } + + static void br_x509_minimal_install_hashes(br_x509_minimal_context *x509) + { + br_x509_minimal_set_hash(x509, br_md5_ID, &br_md5_vtable); + br_x509_minimal_set_hash(x509, br_sha1_ID, &br_sha1_vtable); + br_x509_minimal_set_hash(x509, br_sha224_ID, &br_sha224_vtable); + br_x509_minimal_set_hash(x509, br_sha256_ID, &br_sha256_vtable); + br_x509_minimal_set_hash(x509, br_sha384_ID, &br_sha384_vtable); + br_x509_minimal_set_hash(x509, br_sha512_ID, &br_sha512_vtable); + } + + // Default initializion for our SSL clients + static void br_ssl_client_base_init(br_ssl_client_context *cc, const uint16_t *cipher_list, int cipher_cnt) + { + uint16_t suites[cipher_cnt]; + memcpy_P(suites, cipher_list, cipher_cnt * sizeof(cipher_list[0])); + br_ssl_client_zero(cc); + br_ssl_engine_add_flags(&cc->eng, BR_OPT_NO_RENEGOTIATION); // forbid SSL renegotiation, as we free the Private Key after handshake + br_ssl_engine_set_versions(&cc->eng, BR_TLS10, BR_TLS12); + br_ssl_engine_set_suites(&cc->eng, suites, (sizeof suites) / (sizeof suites[0])); + br_ssl_client_set_default_rsapub(cc); + br_ssl_engine_set_default_rsavrfy(&cc->eng); +#ifndef BEARSSL_SSL_BASIC + br_ssl_engine_set_default_ecdsa(&cc->eng); +#endif + br_ssl_client_install_hashes(&cc->eng); + br_ssl_engine_set_prf10(&cc->eng, &br_tls10_prf); + br_ssl_engine_set_prf_sha256(&cc->eng, &br_tls12_sha256_prf); + br_ssl_engine_set_prf_sha384(&cc->eng, &br_tls12_sha384_prf); + br_ssl_engine_set_default_aes_cbc(&cc->eng); +#ifndef BEARSSL_SSL_BASIC + br_ssl_engine_set_default_aes_gcm(&cc->eng); + br_ssl_engine_set_default_aes_ccm(&cc->eng); + br_ssl_engine_set_default_des_cbc(&cc->eng); + br_ssl_engine_set_default_chapol(&cc->eng); +#endif + } + + // BearSSL doesn't define a true insecure decoder, so we make one ourselves + // from the simple parser. It generates the issuer and subject hashes and + // the SHA1 fingerprint, only one (or none!) of which will be used to + // "verify" the certificate. + + // Private x509 decoder state + struct br_x509_insecure_context + { + const br_x509_class *vtable; + bool done_cert; + const uint8_t *match_fingerprint; + br_sha1_context sha1_cert; + bool allow_self_signed; + br_sha256_context sha256_subject; + br_sha256_context sha256_issuer; + br_x509_decoder_context_libmail ctx; + }; + + // Callback for the x509_minimal subject DN + static void insecure_subject_dn_append(void *ctx, const void *buf, size_t len) + { + br_x509_insecure_context *xc = (br_x509_insecure_context *)ctx; + br_sha256_update(&xc->sha256_subject, buf, len); + } + + // Callback for the x509_minimal issuer DN + static void insecure_issuer_dn_append(void *ctx, const void *buf, size_t len) + { + br_x509_insecure_context *xc = (br_x509_insecure_context *)ctx; + br_sha256_update(&xc->sha256_issuer, buf, len); + } + + // Callback for each certificate present in the chain (but only operates + // on the first one by design). + static void insecure_start_cert(const br_x509_class **ctx, uint32_t length) + { + (void)ctx; + (void)length; + } + + // Callback for each byte stream in the chain. Only process first cert. + static void insecure_append(const br_x509_class **ctx, const unsigned char *buf, size_t len) + { + br_x509_insecure_context *xc = (br_x509_insecure_context *)ctx; + // Don't process anything but the first certificate in the chain + if (!xc->done_cert) + { + br_sha1_update(&xc->sha1_cert, buf, len); + br_x509_decoder_push_libmail(&xc->ctx, (const void *)buf, len); + } + } + // Callback on the first byte of any certificate + static void insecure_start_chain(const br_x509_class **ctx, const char *server_name) + { + br_x509_insecure_context *xc = (br_x509_insecure_context *)ctx; +#if defined(USE_EMBED_SSL_ENGINE) + br_x509_decoder_init(&xc->ctx, insecure_subject_dn_append, xc, insecure_issuer_dn_append, xc); +#elif defined(ESP32) || defined(USE_LIB_SSL_ENGINE) + br_x509_decoder_init(&xc->ctx, insecure_subject_dn_append, xc); +#endif + xc->done_cert = false; + br_sha1_init(&xc->sha1_cert); + br_sha256_init(&xc->sha256_subject); + br_sha256_init(&xc->sha256_issuer); + (void)server_name; + } + + // Callback on individual cert end. + static void insecure_end_cert(const br_x509_class **ctx) + { + br_x509_insecure_context *xc = (br_x509_insecure_context *)ctx; + xc->done_cert = true; + } + + // Callback when complete chain has been parsed. + // Return 0 on validation success, !0 on validation error + static unsigned insecure_end_chain(const br_x509_class **ctx) + { + const br_x509_insecure_context *xc = (const br_x509_insecure_context *)ctx; + if (!xc->done_cert) + { + // BSSL_BSSL_SSL_Client_DEBUG_PRINTF("insecure_end_chain: No cert seen\n"); + return 1; // error + } + + // Handle SHA1 fingerprint matching + char res[20]; + br_sha1_out(&xc->sha1_cert, res); + if (xc->match_fingerprint && memcmp(res, xc->match_fingerprint, sizeof(res))) + { + + return BR_ERR_X509_NOT_TRUSTED; + } + + // Handle self-signer certificate acceptance + char res_issuer[32]; + char res_subject[32]; + br_sha256_out(&xc->sha256_issuer, res_issuer); + br_sha256_out(&xc->sha256_subject, res_subject); + if (xc->allow_self_signed && memcmp(res_subject, res_issuer, sizeof(res_issuer))) + { + // BSSL_BSSL_SSL_Client_DEBUG_PRINTF("insecure_end_chain: Didn't get self-signed cert\n"); + return BR_ERR_X509_NOT_TRUSTED; + } + + // Default (no validation at all) or no errors in prior checks = success. + return 0; + } + + // Return the public key from the validator (set by x509_minimal) + static const br_x509_pkey *insecure_get_pkey(const br_x509_class *const *ctx, unsigned *usages) + { + const br_x509_insecure_context *xc = (const br_x509_insecure_context *)ctx; + if (usages != nullptr) + { + *usages = BR_KEYTYPE_KEYX | BR_KEYTYPE_SIGN; // I said we were insecure! + } + return &xc->ctx.pkey; + } + } + +}; +#endif + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/client/BSSL_SSL_Client.cpp b/lib/libesp32/ESP-Mail-Client/src/SSLClient/client/BSSL_SSL_Client.cpp new file mode 100644 index 000000000..2b90a1859 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/client/BSSL_SSL_Client.cpp @@ -0,0 +1,2203 @@ +/** + * BSSL_SSL_Client library v1.0.11 for Arduino devices. + * + * Created August 27, 2003 + * + * This work contains codes based on WiFiClientSecure from Earle F. Philhower and SSLClient from OSU OPEnS Lab. + * + * Copyright (c) 2018 Earle F. Philhower, III + * + * Copyright 2019 OSU OPEnS Lab + * + * The MIT License (MIT) + * Copyright (c) 2023 K. Suwatchai (Mobizt) + * + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef BSSL_SSL_CLIENT_CPP +#define BSSL_SSL_CLIENT_CPP + +#pragma GCC diagnostic ignored "-Wunused-function" +#pragma GCC diagnostic ignored "-Wunused-variable" +#pragma GCC diagnostic ignored "-Wvla" + +#include +#include "../ESP_SSLClient_FS.h" +#include "../ESP_SSLClient_Const.h" +#if defined(USE_LIB_SSL_ENGINE) || defined(USE_EMBED_SSL_ENGINE) + +#include "BSSL_Helper.h" +#include "BSSL_SSL_Client.h" + +#if defined(ESP8266) && defined(MMU_EXTERNAL_HEAP) && defined(ESP_SSLCLIENT_USE_PSRAM) +#include +#include +#define ESP_SSLCLIENT_ESP8266_USE_EXTERNAL_HEAP +#endif + +#if defined(USE_EMBED_SSL_ENGINE) +#include +#include +#include +#include "StackThunk.h" +#include "lwip/opt.h" +#include "lwip/ip.h" +#include "lwip/tcp.h" +#include "lwip/inet.h" +#include "lwip/netif.h" + +#if 1 +#if !CORE_MOCK + +// The BearSSL thunks in use for now +#define br_ssl_engine_recvapp_ack thunk_br_ssl_engine_recvapp_ack +#define br_ssl_engine_recvapp_buf thunk_br_ssl_engine_recvapp_buf +#define br_ssl_engine_recvrec_ack thunk_br_ssl_engine_recvrec_ack +#define br_ssl_engine_recvrec_buf thunk_br_ssl_engine_recvrec_buf +#define br_ssl_engine_sendapp_ack thunk_br_ssl_engine_sendapp_ack +#define br_ssl_engine_sendapp_buf thunk_br_ssl_engine_sendapp_buf +#define br_ssl_engine_sendrec_ack thunk_br_ssl_engine_sendrec_ack +#define br_ssl_engine_sendrec_buf thunk_br_ssl_engine_sendrec_buf + +#endif +#endif + +#endif + +BSSL_SSL_Client::BSSL_SSL_Client(Client *client) +{ + setClient(client); + mClear(); + mClearAuthenticationSettings(); +#if defined(ESP_SSL_FS_SUPPORTED) + _certStore = nullptr; // Don't want to remove cert store on a clear, should be long lived +#endif + _sk = nullptr; +#if defined(USE_EMBED_SSL_ENGINE) + stack_thunk_add_ref(); +#endif +} + +BSSL_SSL_Client::~BSSL_SSL_Client() +{ + if (_basic_client) + { + if (_basic_client->connected()) + _basic_client->stop(); + _basic_client = nullptr; + } + freeImpl(&_cipher_list); + mFreeSSL(); +#if defined(USE_EMBED_SSL_ENGINE) + stack_thunk_del_ref(); +#endif +} + +void BSSL_SSL_Client::setClient(Client *client, bool ssl) +{ + _basic_client = client; + _isSSLEnabled = ssl; +} + +void BSSL_SSL_Client::setDebugLevel(int level) +{ + if (level < esp_ssl_debug_none || level > esp_ssl_debug_dump) + _debug_level = esp_ssl_debug_none; + else + _debug_level = level; +} + +int BSSL_SSL_Client::connect(IPAddress ip, uint16_t port) +{ + if (_isSSLEnabled && mIsSecurePort(port)) // SSL connect + return connectSSL(ip, port); + + if (!mConnectBasicClient(nullptr, ip, port)) + return 0; + + return 1; +} + +int BSSL_SSL_Client::connect(const char *host, uint16_t port) +{ + if (_isSSLEnabled && mIsSecurePort(port)) + return connectSSL(host, port); + + if (!mConnectBasicClient(host, IPAddress(), port)) + return 0; + + return 1; +} + +uint8_t BSSL_SSL_Client::connected() +{ + if (!mIsClientInitialized(false)) + return 0; + + if (!_secure) + return _basic_client->connected(); + + // check all of the error cases + const auto c_con = _basic_client->connected(); + const auto br_con = br_ssl_engine_current_state(_eng) != BR_SSL_CLOSED && _is_connected; + const auto wr_ok = getWriteError() == 0; + // if we're in an error state, close the connection and set a write error + if (br_con && !c_con) + { + // If we've got a write error, the client probably failed for some reason + if (_basic_client->getWriteError()) + { +#if defined(ESP_SSLCLIENT_ENABLE_DEBUG) + String s = PSTR("Socket was unexpectedly interrupted. m_client error: "); + s += _basic_client->getWriteError(); + esp_ssl_debug_print(s.c_str(), _debug_level, esp_ssl_debug_info, __func__); +#endif + setWriteError(esp_ssl_write_error); + } + // Else tell the user the endpoint closed the socket on us (ouch) + else + { +#if defined(ESP_SSLCLIENT_ENABLE_DEBUG) + // esp_ssl_debug_print(PSTR("Socket was dropped unexpectedly (this can be an alternative to closing the connection)."), _debug_level, esp_ssl_debug_warn, func_name); +#endif + } + + // set the write error so the engine doesn't try to close the connection + _is_connected = false; + stop(); + } + else if (!wr_ok) + { +#if defined(ESP_SSLCLIENT_ENABLE_DEBUG) + esp_ssl_debug_print(PSTR("Not connected because write error is set."), _debug_level, esp_ssl_debug_error, __func__); + mPrintClientError(getWriteError(), esp_ssl_debug_error, __func__); +#endif + } + + return c_con && br_con; +} + +void BSSL_SSL_Client::validate(const char *host, uint16_t port) +{ + mConnectionValidate(host, IPAddress(), port); +} + +void BSSL_SSL_Client::validate(IPAddress ip, uint16_t port) +{ + mConnectionValidate(nullptr, ip, port); +} + +int BSSL_SSL_Client::available() +{ + if (!mIsClientInitialized(false)) + return 0; + + if (!_secure) + return _basic_client->available(); + + // connection check + if (!mSoftConnected(__func__)) + return 0; + + // run the SSL engine until we are waiting for either user input or a server response + unsigned state = mUpdateEngine(); + if (state == 0) + { +#if defined(ESP_SSLCLIENT_ENABLE_DEBUG) + esp_ssl_debug_print(PSTR("SSL engine failed to update."), _debug_level, esp_ssl_debug_error, __func__); +#endif + } + else if (state & BR_SSL_RECVAPP) + { + // return how many received bytes we have + _recvapp_buf = br_ssl_engine_recvapp_buf(_eng, &_recvapp_len); + return (int)(_recvapp_len); + } + else if (state == BR_SSL_CLOSED) + { +#if defined(ESP_SSLCLIENT_ENABLE_DEBUG) + esp_ssl_debug_print(PSTR("SSL Engine closed after update."), _debug_level, esp_ssl_debug_info, __func__); +#endif + } + // flush the buffer if it's stuck in the SENDAPP state + else if (state & BR_SSL_SENDAPP) + br_ssl_engine_flush(_eng, 0); + // other state, or client is closed + return 0; +} + +int BSSL_SSL_Client::read() +{ + uint8_t read_val; + return read(&read_val, 1) > 0 ? read_val : -1; +}; + +int BSSL_SSL_Client::read(uint8_t *buf, size_t size) +{ + if (!mIsClientInitialized(false)) + return 0; + + if (!_secure) + return _basic_client->read(buf, size); + + // check that the engine is ready to read + if (available() <= 0 || !size) + return -1; + // read the buffer, send the ack, and return the bytes read + _recvapp_buf = br_ssl_engine_recvapp_buf(_eng, &_recvapp_len); + const size_t read_amount = size > _recvapp_len ? _recvapp_len : size; + if (buf) + memcpy(buf, _recvapp_buf, read_amount); + // tell engine we read that many bytes + br_ssl_engine_recvapp_ack(_eng, read_amount); + // tell the user we read that many bytes + return read_amount; +} + +size_t BSSL_SSL_Client::write(const uint8_t *buf, size_t size) +{ + if (!mIsClientInitialized(false)) + return 0; + + if (!_secure) + return _basic_client->write(buf, size); + + const char *func_name = __func__; +#if defined(ESP_SSLCLIENT_ENABLE_DEBUG) + // super debug + if (_debug_level >= esp_ssl_debug_dump) + ESP_SSLCLIENT_DEBUG_PORT.write(buf, size); +#endif + // check if the socket is still open and such + if (!mSoftConnected(func_name) || !buf || !size) + return 0; + // wait until bearssl is ready to send + if (mRunUntil(BR_SSL_SENDAPP) < 0) + { +#if defined(ESP_SSLCLIENT_ENABLE_DEBUG) + esp_ssl_debug_print(PSTR("Failed while waiting for the engine to enter BR_SSL_SENDAPP."), _debug_level, esp_ssl_debug_error, func_name); +#endif + return 0; + } + // add to the bearssl io buffer, simply appending whatever we want to write + size_t alen; + unsigned char *br_buf = br_ssl_engine_sendapp_buf(_eng, &alen); + size_t cur_idx = 0; + if (alen == 0) + { +#if defined(ESP_SSLCLIENT_ENABLE_DEBUG) + esp_ssl_debug_print(PSTR("BearSSL returned zero length buffer for sending, did an internal error occur?"), _debug_level, esp_ssl_debug_error, func_name); +#endif + return 0; + } + // while there are still elements to write + while (cur_idx < size) + { + // if we're about to fill the buffer, we need to send the data and then wait + // for another oppurtinity to send + // so we only send the smallest of the buffer size or our data size - how much we've already sent + const size_t cpamount = size - cur_idx >= alen - _write_idx ? alen - _write_idx : size - cur_idx; + memcpy(br_buf + _write_idx, buf + cur_idx, cpamount); + // increment write idx + _write_idx += cpamount; + // increment the buffer pointer + cur_idx += cpamount; + // if we filled the buffer, reset _write_idx, and mark the data for sending + if (_write_idx == alen) + { + // indicate to bearssl that we are done writing + br_ssl_engine_sendapp_ack(_eng, _write_idx); + // reset the write index + _write_idx = 0; + // write to the socket immediatly + if (mRunUntil(BR_SSL_SENDAPP) < 0) + { +#if defined(ESP_SSLCLIENT_ENABLE_DEBUG) + esp_ssl_debug_print(PSTR("Failed while waiting for the engine to enter BR_SSL_SENDAPP."), _debug_level, esp_ssl_debug_error, func_name); +#endif + return 0; + } + // reset the buffer pointer + br_buf = br_ssl_engine_sendapp_buf(_eng, &alen); + } + } + // works oky + return size; +} + +size_t BSSL_SSL_Client::write(uint8_t b) +{ + return write(&b, 1); +} + +size_t BSSL_SSL_Client::write_P(PGM_P buf, size_t size) +{ + char dest[size]; + memcpy_P((void *)dest, buf, size); + return write((const uint8_t *)dest, size); +} + +size_t BSSL_SSL_Client::write(Stream &stream) +{ + if (!mIsClientInitialized(false)) + return 0; + + if (!connected()) + { +#if defined(ESP_SSLCLIENT_ENABLE_DEBUG) + esp_ssl_debug_print(PSTR("Connect not completed yet."), _debug_level, esp_ssl_debug_error, __func__); +#endif + return 0; + } + + size_t dl = stream.available(); + uint8_t buf[dl]; + stream.readBytes(buf, dl); + return write(buf, dl); +} + +int BSSL_SSL_Client::peek() +{ + + if (!_sc || !available()) + { +#if defined(ESP_SSLCLIENT_ENABLE_DEBUG) + esp_ssl_debug_print(PSTR("Not connected, none left available."), _debug_level, esp_ssl_debug_error, __func__); +#endif + return -1; + } + + if (!_secure) + return _basic_client->peek(); + + _recvapp_buf = br_ssl_engine_recvapp_buf(_eng, &_recvapp_len); + if (_recvapp_buf && _recvapp_len) + return _recvapp_buf[0]; + +#if defined(ESP_SSLCLIENT_ENABLE_DEBUG) + esp_ssl_debug_print(PSTR("No data left."), _debug_level, esp_ssl_debug_error, __func__); +#endif + return -1; +} + +size_t BSSL_SSL_Client::peekBytes(uint8_t *buffer, size_t length) +{ + if (!mIsClientInitialized(false) || !_secure) + return 0; + + size_t to_copy = 0; + if (!_sc) + return 0; + + unsigned long _startMillis = millis(); + while ((available() < (int)length) && ((millis() - _startMillis) < 5000)) + { + yield(); + } + + to_copy = _recvapp_len < length ? _recvapp_len : length; + memcpy(buffer, _recvapp_buf, to_copy); + return to_copy; +} + +// Don't validate the chain, just accept whatever is given. VERY INSECURE! +void BSSL_SSL_Client::setInsecure() +{ + mClearAuthenticationSettings(); + _use_insecure = true; +} + +void BSSL_SSL_Client::enableSSL(bool enable) +{ + _isSSLEnabled = enable; +} + +int BSSL_SSL_Client::connectSSL(IPAddress ip, uint16_t port) +{ + + if (!mIsClientInitialized(true)) + return 0; + + if (!_basic_client->connected() && !mConnectBasicClient(nullptr, ip, port)) + return 0; + + _ip = ip; + _port = port; + + return mConnectSSL(nullptr); +} + +int BSSL_SSL_Client::connectSSL(const char *host, uint16_t port) +{ + + if (!mIsClientInitialized(true)) + return 0; + + if (!_basic_client->connected() && !mConnectBasicClient(host, IPAddress(), port)) + return 0; + + _host = host; + _port = port; + + return mConnectSSL(host); +} + +void BSSL_SSL_Client::stop() +{ + if (!_secure) + return; + + // Only if we've already connected, store session params and clear the connection options + if (_session) + br_ssl_engine_get_session_parameters(_eng, _session->getSession()); + + // tell the SSL connection to gracefully close + // Disabled to prevent close_notify from hanging BSSL_SSL_Client + // br_ssl_engine_close(_eng); + // if the engine isn't closed, and the socket is still open + auto state = br_ssl_engine_current_state(_eng); + if (state != BR_SSL_CLOSED && state != 0 && connected()) + { + // Discard any incoming application data. + _recvapp_buf = br_ssl_engine_recvapp_buf(_eng, &_recvapp_len); + if (_recvapp_buf != nullptr) + br_ssl_engine_recvapp_ack(_eng, _recvapp_len); + // run SSL to finish any existing transactions + flush(); + } + + // close the socket + if (_basic_client) + { + _basic_client->flush(); + _basic_client->stop(); + } + + mFreeSSL(); +} + +void BSSL_SSL_Client::setTimeout(unsigned int timeoutMs) { _timeout = timeoutMs; } + +void BSSL_SSL_Client::setHandshakeTimeout(unsigned int timeoutMs) { _handshake_timeout = timeoutMs; } + +void BSSL_SSL_Client::flush() +{ + if (!_secure && _basic_client) + { + _basic_client->flush(); + return; + } + + if (_write_idx > 0) + { + if (mRunUntil(BR_SSL_RECVAPP) < 0) + { +#if defined(ESP_SSLCLIENT_ENABLE_DEBUG) + esp_ssl_debug_print(PSTR("Could not flush write buffer!"), _debug_level, esp_ssl_debug_error, __func__); + int error = br_ssl_engine_last_error(_eng); + if (error != BR_ERR_OK) + mPrintSSLError(error, esp_ssl_debug_error, __func__); + if (getWriteError()) + mPrintClientError(getWriteError(), esp_ssl_debug_error, __func__); +#endif + } + } +} + +void BSSL_SSL_Client::setBufferSizes(int recv, int xmit) +{ + // Following constants taken from bearssl/src/ssl/ssl_engine.c (not exported unfortunately) + const int MAX_OUT_OVERHEAD = 85; + const int MAX_IN_OVERHEAD = 325; + + // The data buffers must be between 512B and 16KB + recv = std::max(512, std::min(16384, recv)); + xmit = std::max(512, std::min(16384, xmit)); + + // Add in overhead for SSL protocol + recv += MAX_IN_OVERHEAD; + xmit += MAX_OUT_OVERHEAD; + _iobuf_in_size = recv; + _iobuf_out_size = xmit; +} + +int BSSL_SSL_Client::availableForWrite() +{ + if (!mIsClientInitialized(false) || !_secure) + return 0; + + // code taken from ::write() + if (!connected() || !_handshake_done) + { + return 0; + } + // Get BearSSL to a state where we can send + if (mRunUntil(BR_SSL_SENDAPP) < 0) + { + return 0; + } + if (br_ssl_engine_current_state(_eng) & BR_SSL_SENDAPP) + { + size_t sendapp_len; + (void)br_ssl_engine_sendapp_buf(_eng, &sendapp_len); + // We want to call br_ssl_engine_sendapp_ack(0) but 0 is forbidden (bssl doc). + // After checking br_ssl_engine_sendapp_buf() src code, + // it seems that it is OK to not call ack when the buffer is left untouched. + // forbidden: br_ssl_engine_sendapp_ack(_eng, 0); + return (int)sendapp_len; + } + return 0; +} + +void BSSL_SSL_Client::setSession(BearSSL_Session *session) { _session = session; }; + +// Assume a given public key, don't validate or use cert info at all +void BSSL_SSL_Client::setKnownKey(const PublicKey *pk, unsigned usages) +{ + mClearAuthenticationSettings(); + _knownkey = pk; + _knownkey_usages = usages; +} + +// Only check SHA1 fingerprint of certificate +bool BSSL_SSL_Client::setFingerprint(const uint8_t fingerprint[20]) +{ + mClearAuthenticationSettings(); + _use_fingerprint = true; + memcpy_P(_fingerprint, fingerprint, 20); + return true; +} + +// Set a fingerprint by parsing an ASCII string +bool BSSL_SSL_Client::setFingerprint(const char *fpStr) +{ + int idx = 0; + uint8_t c, d; + uint8_t fp[20]; + + while (idx < 20) + { + c = pgm_read_byte(fpStr++); + if (!c) + { + break; // String ended, done processing + } + d = pgm_read_byte(fpStr++); + if (!d) + { +#if defined(ESP_SSLCLIENT_ENABLE_DEBUG) + esp_ssl_debug_print(PSTR("FP too short"), _debug_level, esp_ssl_debug_error, __func__); +#endif + return false; // Only half of the last hex digit, error + } + c = htoi(c); + d = htoi(d); + if ((c > 15) || (d > 15)) + { +#if defined(ESP_SSLCLIENT_ENABLE_DEBUG) + esp_ssl_debug_print(PSTR("Invalid char"), _debug_level, esp_ssl_debug_error, __func__); +#endif + return false; // Error in one of the hex characters + } + fp[idx++] = (c << 4) | d; + + // Skip 0 or more spaces or colons + while (pgm_read_byte(fpStr) && (pgm_read_byte(fpStr) == ' ' || pgm_read_byte(fpStr) == ':')) + { + fpStr++; + } + } + if ((idx != 20) || pgm_read_byte(fpStr)) + { +#if defined(ESP_SSLCLIENT_ENABLE_DEBUG) + esp_ssl_debug_print(PSTR("Garbage at end of fp"), _debug_level, esp_ssl_debug_error, __func__); +#endif + return false; // Garbage at EOL or we didn't have enough hex digits + } + return setFingerprint(fp); +} + +// Accept any certificate that's self-signed +void BSSL_SSL_Client::allowSelfSignedCerts() +{ + mClearAuthenticationSettings(); + _use_self_signed = true; +} + +// Install certificates of trusted CAs or specific site +void BSSL_SSL_Client::setTrustAnchors(const X509List *ta) +{ + mClearAuthenticationSettings(); + _ta = ta; +} + +// In cases when NTP is not used, app must set a time manually to check cert validity +void BSSL_SSL_Client::setX509Time(time_t now) +{ + _now = now; +} + +void BSSL_SSL_Client::setClientRSACert(const X509List *chain, const PrivateKey *sk) +{ + if (_esp32_chain) + { + delete _esp32_chain; + _esp32_chain = nullptr; + } + if (_esp32_sk) + { + delete _esp32_sk; + _esp32_sk = nullptr; + } + _chain = chain; + _sk = sk; +} + +void BSSL_SSL_Client::setClientECCert(const X509List *chain, const PrivateKey *sk, unsigned allowed_usages, unsigned cert_issuer_key_type) +{ + if (_esp32_chain) + { + delete _esp32_chain; + _esp32_chain = nullptr; + } + if (_esp32_sk) + { + delete _esp32_sk; + _esp32_sk = nullptr; + } + _chain = chain; + _sk = sk; + _allowed_usages = allowed_usages; + _cert_issuer_key_type = cert_issuer_key_type; +} + +// Returns whether MFLN negotiation for the above buffer sizes succeeded (after connection) +int BSSL_SSL_Client::getMFLNStatus() +{ + return connected() && br_ssl_engine_get_mfln_negotiated(_eng); +} + +// Returns an error ID and possibly a string (if dest != null) of the last +// BearSSL reported error. +int BSSL_SSL_Client::getLastSSLError(char *dest, size_t len) +{ + int err = 0; + const char *t = ""; + const char *recv_fatal = ""; + const char *send_fatal = ""; + if (_sc) + err = br_ssl_engine_last_error(_eng); + + if (_oom_err) + err = -1000; + else + { + if (err & BR_ERR_RECV_FATAL_ALERT) + { +#if defined(ESP_SSLCLIENT_ENABLE_SSL_ERROR_STRING) + recv_fatal = PSTR("SSL received fatal alert - "); +#endif + err &= ~BR_ERR_RECV_FATAL_ALERT; + } + if (err & BR_ERR_SEND_FATAL_ALERT) + { +#if defined(ESP_SSLCLIENT_ENABLE_SSL_ERROR_STRING) + send_fatal = PSTR("SSL sent fatal alert - "); +#endif + err &= ~BR_ERR_SEND_FATAL_ALERT; + } + } +#if defined(ESP_SSLCLIENT_ENABLE_SSL_ERROR_STRING) + switch (err) + { + case -1000: + t = PSTR("Unable to allocate memory for SSL structures and buffers."); + break; + case BR_ERR_BAD_PARAM: + t = PSTR("Caller-provided parameter is incorrect."); + break; + case BR_ERR_BAD_STATE: + t = PSTR("Operation requested by the caller cannot be applied with the current context state (e.g. reading data while outgoing data is waiting to be sent)."); + break; + case BR_ERR_UNSUPPORTED_VERSION: + t = PSTR("Incoming protocol or record version is unsupported."); + break; + case BR_ERR_BAD_VERSION: + t = PSTR("Incoming record version does not match the expected version."); + break; + case BR_ERR_BAD_LENGTH: + t = PSTR("Incoming record length is invalid."); + break; + case BR_ERR_TOO_LARGE: + t = PSTR("Incoming record is too large to be processed, or buffer is too small for the handshake message to send."); + break; + case BR_ERR_BAD_MAC: + t = PSTR("Decryption found an invalid padding, or the record MAC is not correct."); + break; + case BR_ERR_NO_RANDOM: + t = PSTR("No initial entropy was provided, and none can be obtained from the OS."); + break; + case BR_ERR_UNKNOWN_TYPE: + t = PSTR("Incoming record type is unknown."); + break; + case BR_ERR_UNEXPECTED: + t = PSTR("Incoming record or message has wrong type with regards to the current engine state."); + break; + case BR_ERR_BAD_CCS: + t = PSTR("ChangeCipherSpec message from the peer has invalid contents."); + break; + case BR_ERR_BAD_ALERT: + t = PSTR("Alert message from the peer has invalid contents (odd length)."); + break; + case BR_ERR_BAD_HANDSHAKE: + t = PSTR("Incoming handshake message decoding failed."); + break; + case BR_ERR_OVERSIZED_ID: + t = PSTR("ServerHello contains a session ID which is larger than 32 bytes."); + break; + case BR_ERR_BAD_CIPHER_SUITE: + t = PSTR("Server wants to use a cipher suite that we did not claim to support. This is also reported if we tried to advertise a cipher suite that we do not support."); + break; + case BR_ERR_BAD_COMPRESSION: + t = PSTR("Server wants to use a compression that we did not claim to support."); + break; + case BR_ERR_BAD_FRAGLEN: + t = PSTR("Server's max fragment length does not match client's."); + break; + case BR_ERR_BAD_SECRENEG: + t = PSTR("Secure renegotiation failed."); + break; + case BR_ERR_EXTRA_EXTENSION: + t = PSTR("Server sent an extension type that we did not announce, or used the same extension type several times in a single ServerHello."); + break; + case BR_ERR_BAD_SNI: + t = PSTR("Invalid Server Name Indication contents (when used by the server, this extension shall be empty)."); + break; + case BR_ERR_BAD_HELLO_DONE: + t = PSTR("Invalid ServerHelloDone from the server (length is not 0)."); + break; + case BR_ERR_LIMIT_EXCEEDED: + t = PSTR("Internal limit exceeded (e.g. server's public key is too large)."); + break; + case BR_ERR_BAD_FINISHED: + t = PSTR("Finished message from peer does not match the expected value."); + break; + case BR_ERR_RESUME_MISMATCH: + t = PSTR("Session resumption attempt with distinct version or cipher suite."); + break; + case BR_ERR_INVALID_ALGORITHM: + t = PSTR("Unsupported or invalid algorithm (ECDHE curve, signature algorithm, hash function)."); + break; + case BR_ERR_BAD_SIGNATURE: + t = PSTR("Invalid signature in ServerKeyExchange or CertificateVerify message."); + break; + case BR_ERR_WRONG_KEY_USAGE: + t = PSTR("Peer's public key does not have the proper type or is not allowed for the requested operation."); + break; + case BR_ERR_NO_CLIENT_AUTH: + t = PSTR("Client did not send a certificate upon request, or the client certificate could not be validated."); + break; + case BR_ERR_IO: + t = PSTR("I/O error or premature close on transport stream."); + break; + case BR_ERR_X509_INVALID_VALUE: + t = PSTR("Invalid value in an ASN.1 structure."); + break; + case BR_ERR_X509_TRUNCATED: + t = PSTR("Truncated certificate or other ASN.1 object."); + break; + case BR_ERR_X509_EMPTY_CHAIN: + t = PSTR("Empty certificate chain (no certificate at all)."); + break; + case BR_ERR_X509_INNER_TRUNC: + t = PSTR("Decoding error: inner element extends beyond outer element size."); + break; + case BR_ERR_X509_BAD_TAG_CLASS: + t = PSTR("Decoding error: unsupported tag class (application or private)."); + break; + case BR_ERR_X509_BAD_TAG_VALUE: + t = PSTR("Decoding error: unsupported tag value."); + break; + case BR_ERR_X509_INDEFINITE_LENGTH: + t = PSTR("Decoding error: indefinite length."); + break; + case BR_ERR_X509_EXTRA_ELEMENT: + t = PSTR("Decoding error: extraneous element."); + break; + case BR_ERR_X509_UNEXPECTED: + t = PSTR("Decoding error: unexpected element."); + break; + case BR_ERR_X509_NOT_CONSTRUCTED: + t = PSTR("Decoding error: expected constructed element, but is primitive."); + break; + case BR_ERR_X509_NOT_PRIMITIVE: + t = PSTR("Decoding error: expected primitive element, but is constructed."); + break; + case BR_ERR_X509_PARTIAL_BYTE: + t = PSTR("Decoding error: BIT STRING length is not multiple of 8."); + break; + case BR_ERR_X509_BAD_BOOLEAN: + t = PSTR("Decoding error: BOOLEAN value has invalid length."); + break; + case BR_ERR_X509_OVERFLOW: + t = PSTR("Decoding error: value is off-limits."); + break; + case BR_ERR_X509_BAD_DN: + t = PSTR("Invalid distinguished name."); + break; + case BR_ERR_X509_BAD_TIME: + t = PSTR("Invalid date/time representation."); + break; + case BR_ERR_X509_UNSUPPORTED: + t = PSTR("Certificate contains unsupported features that cannot be ignored."); + break; + case BR_ERR_X509_LIMIT_EXCEEDED: + t = PSTR("Key or signature size exceeds internal limits."); + break; + case BR_ERR_X509_WRONG_KEY_TYPE: + t = PSTR("Key type does not match that which was expected."); + break; + case BR_ERR_X509_BAD_SIGNATURE: + t = PSTR("Signature is invalid."); + break; + case BR_ERR_X509_TIME_UNKNOWN: + t = PSTR("Validation time is unknown."); + break; + case BR_ERR_X509_EXPIRED: + t = PSTR("Certificate is expired or not yet valid."); + break; + case BR_ERR_X509_DN_MISMATCH: + t = PSTR("Issuer/Subject DN mismatch in the chain."); + break; + case BR_ERR_X509_BAD_SERVER_NAME: + t = PSTR("Expected server name was not found in the chain."); + break; + case BR_ERR_X509_CRITICAL_EXTENSION: + t = PSTR("Unknown critical extension in certificate."); + break; + case BR_ERR_X509_NOT_CA: + t = PSTR("Not a CA, or path length constraint violation."); + break; + case BR_ERR_X509_FORBIDDEN_KEY_USAGE: + t = PSTR("Key Usage extension prohibits intended usage."); + break; + case BR_ERR_X509_WEAK_PUBLIC_KEY: + t = PSTR("Public key found in certificate is too small."); + break; + case BR_ERR_X509_NOT_TRUSTED: + t = PSTR("Chain could not be linked to a trust anchor."); + break; + default: + t = PSTR("Unknown error code."); + break; + } + + if (dest) + { + // snprintf is PSTR safe and guaranteed to 0-terminate + snprintf(dest, len, "%s%s%s", recv_fatal, send_fatal, t); + } + +#endif + + return err; +} + +// Attach a preconfigured certificate store +#if defined(ESP_SSL_FS_SUPPORTED) +void BSSL_SSL_Client::setCertStore(CertStoreBase *certStore) +{ + _certStore = certStore; +} +#endif + +// Set custom list of ciphers +bool BSSL_SSL_Client::setCiphers(const uint16_t *cipherAry, int cipherCount) +{ + _cipher_list = (uint16_t *)mallocImpl(cipherCount); + if (!_cipher_list) + { +#if defined(ESP_SSLCLIENT_ENABLE_DEBUG) + esp_ssl_debug_print(PSTR("list empty"), _debug_level, esp_ssl_debug_error, __func__); +#endif + return false; + } + memcpy_P(_cipher_list, cipherAry, cipherCount * sizeof(uint16_t)); + _cipher_cnt = cipherCount; + return true; +} + +bool BSSL_SSL_Client::setCiphers(const std::vector &list) +{ + return setCiphers(&list[0], list.size()); +} + +bool BSSL_SSL_Client::setCiphersLessSecure() +{ + return setCiphers(faster_suites_P, sizeof(faster_suites_P) / sizeof(faster_suites_P[0])); +} + +bool BSSL_SSL_Client::setSSLVersion(uint32_t min, uint32_t max) +{ + if (((min != BR_TLS10) && (min != BR_TLS11) && (min != BR_TLS12)) || + ((max != BR_TLS10) && (max != BR_TLS11) && (max != BR_TLS12)) || + (max < min)) + { + return false; // Invalid options + } + _tls_min = min; + _tls_max = max; + return true; +} + +// Checks for support of Maximum Frame Length Negotiation at the given +// blocksize. Note that, per spec, only 512, 1024, 2048, and 4096 are +// supported. Many servers today do not support this negotiation. + +// TODO - Allow for fragmentation...but not very critical as the ServerHello +// we use comes to < 80 bytes which has no reason to ever be fragmented. +// TODO - Check the type of returned extensions and that the MFL is the exact +// same one we sent. Not critical as only horribly broken servers would +// return changed or add their own extensions. +bool BSSL_SSL_Client::probeMaxFragmentLength(IPAddress ip, uint16_t port, uint16_t len) +{ + return mProbeMaxFragmentLength(nullptr, ip, port, len); +} + +bool BSSL_SSL_Client::probeMaxFragmentLength(const char *name, uint16_t port, uint16_t len) +{ + return mProbeMaxFragmentLength(name, IPAddress(), port, len); +} + +bool BSSL_SSL_Client::probeMaxFragmentLength(const String &host, uint16_t port, uint16_t len) +{ + return BSSL_SSL_Client::probeMaxFragmentLength(host.c_str(), port, len); +} + +size_t BSSL_SSL_Client::peekAvailable() +{ + return available(); +} + +// return a pointer to available data buffer (size = peekAvailable()) +// semantic forbids any kind of read() before calling peekConsume() +const char *BSSL_SSL_Client::peekBuffer() +{ + return (const char *)_recvapp_buf; +} + +// consume bytes after use (see peekBuffer) +void BSSL_SSL_Client::peekConsume(size_t consume) +{ + // according to BSSL_SSL_Client::read: + br_ssl_engine_recvapp_ack(_eng, consume); + _recvapp_buf = nullptr; + _recvapp_len = 0; +} + +void BSSL_SSL_Client::setCACert(const char *rootCA) +{ + if (_esp32_ta) + delete _esp32_ta; + _esp32_ta = new X509List(rootCA); +} + +void BSSL_SSL_Client::setCertificate(const char *client_ca) +{ + if (_esp32_chain) + delete _esp32_chain; + _esp32_chain = new X509List(client_ca); +} + +void BSSL_SSL_Client::setPrivateKey(const char *private_key) +{ + if (_esp32_sk) + delete _esp32_sk; + _esp32_sk = new PrivateKey(private_key); +} + +bool BSSL_SSL_Client::loadCACert(Stream &stream, size_t size) +{ + bool ret = false; + auto buff = (char *)mallocImpl(size); + if (size == stream.readBytes(buff, size)) + { + setCACert(buff); + ret = true; + } + freeImpl(&buff); + return ret; +} + +bool BSSL_SSL_Client::loadCertificate(Stream &stream, size_t size) +{ + bool ret = false; + auto buff = (char *)mallocImpl(size); + if (size == stream.readBytes(buff, size)) + { + setCertificate(buff); + ret = true; + } + freeImpl(&buff); + return ret; +} + +bool BSSL_SSL_Client::loadPrivateKey(Stream &stream, size_t size) +{ + bool ret = false; + auto buff = (char *)mallocImpl(size); + if (size == stream.readBytes(buff, size)) + { + setPrivateKey(buff); + ret = true; + } + freeImpl(&buff); + return ret; +} + +int BSSL_SSL_Client::connect(IPAddress ip, uint16_t port, const char *rootCABuff, const char *cli_cert, const char *cli_key) +{ + setSecure(rootCABuff, cli_cert, cli_key); + return connect(ip, port); +} + +int BSSL_SSL_Client::connect(const char *host, uint16_t port, const char *rootCABuff, const char *cli_cert, const char *cli_key) +{ + setSecure(rootCABuff, cli_cert, cli_key); + return connect(host, port); +} + +BSSL_SSL_Client &BSSL_SSL_Client::operator=(const BSSL_SSL_Client &other) +{ + stop(); + setClient(other._basic_client); + _use_insecure = other._use_insecure; + _timeout = other._timeout; + _handshake_timeout = other._handshake_timeout; + return *this; +} + +bool BSSL_SSL_Client::operator==(const BSSL_SSL_Client &rhs) +{ + return _basic_client == rhs._basic_client; +} + +unsigned int BSSL_SSL_Client::getTimeout() const { return _timeout; } + +void BSSL_SSL_Client::setSecure(const char *rootCABuff, const char *cli_cert, const char *cli_key) +{ + if (_esp32_ta) + { + delete _esp32_ta; + _esp32_ta = nullptr; + } + if (_esp32_chain) + { + delete _esp32_chain; + _esp32_chain = nullptr; + } + if (_esp32_sk) + { + delete _esp32_sk; + _esp32_sk = nullptr; + } + if (rootCABuff) + { + setCertificate(rootCABuff); + } + if (cli_cert && cli_key) + { + setCertificate(cli_cert); + setPrivateKey(cli_key); + } +} + +////////////////////////////////////////////////////// +// Private access +////////////////////////////////////////////////////// + +bool BSSL_SSL_Client::mProbeMaxFragmentLength(Client *probe, uint16_t len) +{ + + // Hardcoded TLS 1.2 packets used throughout + static const uint8_t clientHelloHead_P[] PROGMEM = { + 0x16, 0x03, 0x03, 0x00, 0, // TLS header, change last 2 bytes to len + 0x01, 0x00, 0x00, 0, // Last 3 bytes == length + 0x03, 0x03, // Proto version TLS 1.2 + 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, // Random (gmtime + rand[28]) + 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, + 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, + 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, + 0x00, // Session ID + }; + // Followed by our cipher-suite, generated on-the-fly + // 0x00, 0x02, // cipher suite len + // 0xc0, 0x13, // BR_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA + static const uint8_t clientHelloTail_P[] PROGMEM = { + 0x01, 0x00, // No compression + 0x00, 26 + 14 + 6 + 5, // Extension length + 0x00, 0x0d, 0x00, 0x16, 0x00, 0x14, 0x04, 0x03, 0x03, 0x03, 0x05, 0x03, + 0x06, 0x03, 0x02, 0x03, 0x04, 0x01, 0x03, 0x01, 0x05, 0x01, 0x06, + 0x01, 0x02, 0x01, // Supported signature algorithms + 0x00, 0x0a, 0x00, 0x0a, 0x00, 0x08, 0x00, 0x17, 0x00, 0x18, 0x00, 0x19, + 0x00, 0x1d, // Supported groups + 0x00, 0x0b, 0x00, 0x02, 0x01, 0x00, // Supported EC formats + 0x00, 0x01, // Max Frag Len + 0x00, 0x01, // len of MaxFragLen + }; + // Followed by a 1-byte MFLN size requesst + // 0x04 // 2^12 = 4K + uint8_t mfl; + + switch (len) + { + case 512: + mfl = 1; + break; + case 1024: + mfl = 2; + break; + case 2048: + mfl = 3; + break; + case 4096: + mfl = 4; + break; + default: + return false; // Invalid size + } + int ttlLen = sizeof(clientHelloHead_P) + (2 + sizeof(suites_P)) + (sizeof(clientHelloTail_P) + 1); + uint8_t *clientHello = (uint8_t *)mallocImpl(ttlLen); + if (!clientHello) + { +#if defined(ESP_SSLCLIENT_ENABLE_DEBUG) + esp_ssl_debug_print(PSTR("OOM error."), _debug_level, esp_ssl_debug_error, __func__); +#endif + return false; + } + memcpy_P(clientHello, clientHelloHead_P, sizeof(clientHelloHead_P)); + clientHello[sizeof(clientHelloHead_P) + 0] = sizeof(suites_P) >> 8; // MSB byte len + clientHello[sizeof(clientHelloHead_P) + 1] = sizeof(suites_P) & 0xff; // LSB byte len + for (size_t i = 0; i < sizeof(suites_P) / sizeof(suites_P[0]); i++) + { + uint16_t flip = pgm_read_word(&suites_P[i]); + // Swap to network byte order + flip = ((flip >> 8) & 0xff) | ((flip & 0xff) << 8); + memcpy(clientHello + sizeof(clientHelloHead_P) + 2 + 2 * i, &flip, 2); + } + memcpy_P(clientHello + sizeof(clientHelloHead_P) + 2 + sizeof(suites_P), clientHelloTail_P, sizeof(clientHelloTail_P)); + clientHello[sizeof(clientHelloHead_P) + 2 + sizeof(suites_P) + sizeof(clientHelloTail_P)] = mfl; + + // Fix up TLS fragment length + clientHello[3] = (ttlLen - 5) >> 8; + clientHello[4] = (ttlLen - 5) & 0xff; + // Fix up ClientHello message length + clientHello[7] = (ttlLen - 5 - 4) >> 8; + clientHello[8] = (ttlLen - 5 - 4) & 0xff; + + int ret = probe->write(clientHello, ttlLen); + freeImpl(&clientHello); // We're done w/the hello message + if (!probe->connected() || (ret != ttlLen)) + { +#if defined(ESP_SSLCLIENT_ENABLE_DEBUG) + esp_ssl_debug_print(PSTR("Protocol error."), _debug_level, esp_ssl_debug_error, __func__); +#endif + return false; + } + + bool supportsLen = false; + uint8_t fragResp[5]; + int fragLen; + uint8_t hand[4]; + int handLen; + uint8_t protoVer[2]; + uint8_t rand[32]; + uint8_t sessionLen; + uint8_t cipher[2]; + uint8_t comp; + uint8_t extBytes[2]; + uint16_t extLen; + + ret = probe->readBytes(fragResp, 5); + if (!probe->connected() || (ret != 5) || (fragResp[0] != 0x16) || (fragResp[1] != 0x03) || (fragResp[2] != 0x03)) + { + // Short read, not a HANDSHAKE or not TLS 1.2, so it's not supported + return send_abort(probe, supportsLen); + } + fragLen = (fragResp[3] << 8) | fragResp[4]; + if (fragLen < 4 + 2 + 32 + 1 + 2 + 1) + { + // Too short to have an extension + return send_abort(probe, supportsLen); + } + + ret = probe->readBytes(hand, 4); + fragLen -= ret; + if ((ret != 4) || (hand[0] != 2)) + { + // Short read or not server_hello + return send_abort(probe, supportsLen); + } + handLen = (hand[1] << 16) | (hand[2] << 8) | hand[3]; + if (handLen != fragLen) + { + // Got some weird mismatch, this is invalid + return send_abort(probe, supportsLen); + } + + ret = probe->readBytes(protoVer, 2); + handLen -= ret; + if ((ret != 2) || (protoVer[0] != 0x03) || (protoVer[1] != 0x03)) + { + // Short read or not tls 1.2, so can't do MFLN + return send_abort(probe, supportsLen); + } + + ret = probe->readBytes(rand, 32); + handLen -= ret; + if (ret != 32) + { + // short read of random data + return send_abort(probe, supportsLen); + } + + ret = probe->readBytes(&sessionLen, 1); + handLen -= ret; + if ((ret != 1) || (sessionLen > 32)) + { + // short read of session len or invalid size + return send_abort(probe, supportsLen); + } + if (sessionLen) + { + ret = probe->readBytes(rand, sessionLen); + handLen -= ret; + if (ret != sessionLen) + { + // short session id read + return send_abort(probe, supportsLen); + } + } + + ret = probe->readBytes(cipher, 2); + handLen -= ret; + if (ret != 2) + { + // Short read...we don't check the cipher here + return send_abort(probe, supportsLen); + } + + ret = probe->readBytes(&comp, 1); + handLen -= ret; + if ((ret != 1) || comp != 0) + { + // short read or invalid compression + return send_abort(probe, supportsLen); + } + + ret = probe->readBytes(extBytes, 2); + handLen -= ret; + extLen = extBytes[1] | (extBytes[0] << 8); + if ((extLen == 0) || (ret != 2)) + { + return send_abort(probe, supportsLen); + } + + while (handLen > 0) + { + // Parse each extension and look for MFLN + uint8_t typeBytes[2]; + ret = probe->readBytes(typeBytes, 2); + handLen -= 2; + if ((ret != 2) || (handLen <= 0)) + { + return send_abort(probe, supportsLen); + } + uint8_t lenBytes[2]; + ret = probe->readBytes(lenBytes, 2); + handLen -= 2; + uint16_t extLen = lenBytes[1] | (lenBytes[0] << 8); + if ((ret != 2) || (handLen <= 0) || (extLen > 32) || (extLen > handLen)) + { + return send_abort(probe, supportsLen); + } + if ((typeBytes[0] == 0x00) && (typeBytes[1] == 0x01)) + { // MFLN extension! + // If present and 1-byte in length, it's supported + return send_abort(probe, extLen == 1 ? true : false); + } + // Skip the extension, move to next one + uint8_t junk[32]; + ret = probe->readBytes(junk, extLen); + handLen -= extLen; + if (ret != extLen) + { + return send_abort(probe, supportsLen); + } + } + return send_abort(probe, supportsLen); +} + +bool BSSL_SSL_Client::mProbeMaxFragmentLength(const char *name, IPAddress ip, uint16_t port, uint16_t len) +{ + if (!mIsClientInitialized(false)) + return false; + + _basic_client->stop(); + + if (!(name ? _basic_client->connect(name, port) : _basic_client->connect(ip, port))) + { +#if defined(ESP_SSLCLIENT_ENABLE_DEBUG) + esp_ssl_debug_print(PSTR("Can't connect."), _debug_level, esp_ssl_debug_error, __func__); +#endif + return false; + } + + bool ret = mProbeMaxFragmentLength(_basic_client, len); + _basic_client->stop(); + return ret; +} + +int BSSL_SSL_Client::mIsClientInitialized(bool notify) +{ + if (!_basic_client) + { +#if defined(ESP_SSLCLIENT_ENABLE_DEBUG) + if (notify) + esp_ssl_debug_print(PSTR("Basic client is not yet initialized."), _debug_level, esp_ssl_debug_error, __func__); +#endif + return 0; + } + return 1; +} + +int BSSL_SSL_Client::mConnectBasicClient(const char *host, IPAddress ip, uint16_t port) +{ + + if (!mConnectionValidate(host, ip, port)) + return 0; + + if (!(host ? _basic_client->connect(host, port) : _basic_client->connect(ip, port))) + { +#if defined(ESP_SSLCLIENT_ENABLE_DEBUG) + esp_ssl_debug_print(PSTR("Failed to connect to server using basic client."), _debug_level, esp_ssl_debug_error, __func__); +#endif + setWriteError(esp_ssl_connection_fail); + mFreeSSL(); + return 0; + } + + _secure = false; + _write_idx = 0; +#if defined(ESP_SSLCLIENT_ENABLE_DEBUG) + esp_ssl_debug_print(PSTR("Basic client connected!"), _debug_level, esp_ssl_debug_info, __func__); +#endif + return 1; +} + +bool BSSL_SSL_Client::mSoftConnected(const char *func_name) +{ + // check if the socket is still open and such + if (getWriteError()) + { +#if defined(ESP_SSLCLIENT_ENABLE_DEBUG) + esp_ssl_debug_print(PSTR("Cannot operate if the write error is not reset."), _debug_level, esp_ssl_debug_error, func_name); + mPrintClientError(getWriteError(), esp_ssl_debug_error, func_name); +#endif + return false; + } + // check if the ssl engine is still open + if (!_is_connected || br_ssl_engine_current_state(_eng) == BR_SSL_CLOSED) + { +#if defined(ESP_SSLCLIENT_ENABLE_DEBUG) + esp_ssl_debug_print(PSTR("Cannot operate on a closed SSL connection."), _debug_level, esp_ssl_debug_error, func_name); + int error = br_ssl_engine_last_error(_eng); + if (error != BR_ERR_OK) + mPrintSSLError(error, esp_ssl_debug_error, func_name); +#endif + return false; + } + return true; +} + +int BSSL_SSL_Client::mConnectSSL(const char *host) +{ + +#if defined(ESP_SSLCLIENT_ENABLE_DEBUG) + esp_ssl_debug_print(PSTR("Start connection."), _debug_level, esp_ssl_debug_info, __func__); +#endif + mFreeSSL(); + _oom_err = false; + +#if defined(ESP_SSLCLIENT_ENABLE_DEBUG) + // BearSSL will reject all connections unless an authentication option is set, warn in DEBUG builds +#if defined(ESP_SSL_FS_SUPPORTED) +#define CRTSTORECOND &&!_certStore +#else +#define CRTSTORECOND +#endif + if (!_use_insecure && !_use_fingerprint && !_use_self_signed && !_knownkey CRTSTORECOND && !_ta) + { + esp_ssl_debug_print(PSTR("Connection *will* fail, no authentication method is setup."), _debug_level, esp_ssl_debug_warn, __func__); + } +#endif + + _sc = std::make_shared(); + _eng = &_sc->eng; // Allocation/deallocation taken care of by the _sc shared_ptr + + _iobuf_in = (unsigned char *)mallocImpl(_iobuf_in_size); + _iobuf_out = (unsigned char *)mallocImpl(_iobuf_out_size); + + if (!_sc || !_iobuf_in || !_iobuf_out) + { + mFreeSSL(); // Frees _sc, _iobuf* + _oom_err = true; +#if defined(ESP_SSLCLIENT_ENABLE_DEBUG) + esp_ssl_debug_print(PSTR("OOM error."), _debug_level, esp_ssl_debug_error, __func__); +#endif + return 0; + } + + // If no cipher list yet set, use defaults + if (!_cipher_list) + bssl::br_ssl_client_base_init(_sc.get(), suites_P, sizeof(suites_P) / sizeof(suites_P[0])); + else + bssl::br_ssl_client_base_init(_sc.get(), _cipher_list, _cipher_cnt); + + // Only failure possible in the installation is OOM + if (!mInstallClientX509Validator()) + { + mFreeSSL(); + _oom_err = true; +#if defined(ESP_SSLCLIENT_ENABLE_DEBUG) + esp_ssl_debug_print(PSTR("Can't install x509 validator."), _debug_level, esp_ssl_debug_error, __func__); +#endif + return 0; + } + + br_ssl_engine_set_buffers_bidi(_eng, _iobuf_in, _iobuf_in_size, _iobuf_out, _iobuf_out_size); + br_ssl_engine_set_versions(_eng, _tls_min, _tls_max); + + // Apply any client certificates, if supplied. + if (_sk && _sk->isRSA()) + { + br_ssl_client_set_single_rsa(_sc.get(), _chain ? _chain->getX509Certs() : nullptr, _chain ? _chain->getCount() : 0, + _sk->getRSA(), br_rsa_pkcs1_sign_get_default()); + } + else if (_sk && _sk->isEC()) + { +#ifndef BEARSSL_SSL_BASIC + br_ssl_client_set_single_ec(_sc.get(), _chain ? _chain->getX509Certs() : nullptr, _chain ? _chain->getCount() : 0, + _sk->getEC(), _allowed_usages, + _cert_issuer_key_type, br_ec_get_default(), br_ecdsa_sign_asn1_get_default()); +#else + mFreeSSL(); +#if defined(ESP_SSLCLIENT_ENABLE_DEBUG) + esp_ssl_debug_print(PSTR("Attempting to use EC cert in minimal cipher mode (no EC)."), _debug_level, esp_ssl_debug_error, __func__); +#endif + return 0; +#endif + } + else if (_esp32_sk && _esp32_chain) + { + br_ssl_client_set_single_rsa(_sc.get(), _esp32_chain->getX509Certs(), _esp32_chain->getCount(), + _esp32_sk->getRSA(), br_rsa_pkcs1_sign_get_default()); + } + + // clear the write error + setWriteError(esp_ssl_ok); + + // we want 128 bits to be safe, as recommended by the bearssl docs + uint8_t rng_seeds[16]; + + // prng + for (uint8_t i = 0; i < sizeof rng_seeds; i++) + rng_seeds[i] = static_cast(random(256)); + + br_ssl_engine_inject_entropy(_eng, rng_seeds, sizeof rng_seeds); + + // Restore session from the storage spot, if present + if (_session) + { +#if defined(ESP_SSLCLIENT_ENABLE_DEBUG) + esp_ssl_debug_print(PSTR("Set SSL session!"), _debug_level, esp_ssl_debug_info, __func__); +#endif + br_ssl_engine_set_session_parameters(_eng, _session->getSession()); + } + + if (!br_ssl_client_reset(_sc.get(), host, _session ? 1 : 0)) + { +#if defined(ESP_SSLCLIENT_ENABLE_DEBUG) + esp_ssl_debug_print(PSTR("Can't reset client."), _debug_level, esp_ssl_debug_error, __func__); + mPrintSSLError(br_ssl_engine_last_error(_eng), esp_ssl_debug_error, __func__); +#endif + setWriteError(esp_ssl_connection_fail); + mFreeSSL(); + return 0; + } + +// SSL/TLS handshake +#if defined(ESP_SSLCLIENT_ENABLE_DEBUG) + esp_ssl_debug_print(PSTR("Wait for SSL handshake."), _debug_level, esp_ssl_debug_info, __func__); +#endif + + if (mRunUntil(BR_SSL_SENDAPP, _handshake_timeout) < 0) + { +#if defined(ESP_SSLCLIENT_ENABLE_DEBUG) + esp_ssl_debug_print(PSTR("Failed to initlalize the SSL layer."), _debug_level, esp_ssl_debug_error, __func__); + mPrintSSLError(br_ssl_engine_last_error(_eng), esp_ssl_debug_error, __func__); +#endif + mFreeSSL(); + return 0; + } + +#if defined(ESP_SSLCLIENT_ENABLE_DEBUG) + esp_ssl_debug_print(PSTR("Connection successful!"), _debug_level, esp_ssl_debug_info, __func__); +#endif + _handshake_done = true; + _is_connected = true; + _secure = true; + + // Save session + if (_session) + br_ssl_engine_get_session_parameters(_eng, _session->getSession()); + + // Session is already validated here, there is no need to keep following + _x509_minimal = nullptr; + _x509_insecure = nullptr; + _x509_knownkey = nullptr; + + return 1; +} + +bool BSSL_SSL_Client::mConnectionValidate(const char *host, IPAddress ip, uint16_t port) +{ + if (!mIsClientInitialized(true)) + return false; + + if (_basic_client && _basic_client->connected() && + host + ? (strcasecmp(host, _host.c_str()) != 0 || port != _port) + : (ip != _ip || port != _port)) + { + _basic_client->stop(); + } + + return true; +} + +int BSSL_SSL_Client::mRunUntil(const unsigned target, unsigned long timeout) +{ + unsigned lastState = 0; + size_t lastLen = 0; + const unsigned long start = millis(); + for (;;) + { + unsigned state = mUpdateEngine(); + // error check + if (state == BR_SSL_CLOSED || getWriteError() != esp_ssl_ok) + { +#if defined(ESP_SSLCLIENT_ENABLE_DEBUG) + if (state == BR_SSL_CLOSED) + esp_ssl_debug_print(PSTR("Terminating because the ssl engine closed."), _debug_level, esp_ssl_debug_warn, __func__); + else + esp_ssl_debug_print(PSTR("Terminating with write error."), _debug_level, esp_ssl_debug_warn, __func__); +#endif + return -1; + } + // timeout check + if (millis() - start > ((timeout > 0) ? timeout : getTimeout())) + { +#if defined(ESP_SSLCLIENT_ENABLE_DEBUG) + esp_ssl_debug_print(PSTR("SSL internals timed out!"), _debug_level, esp_ssl_debug_error, __func__); +#endif + setWriteError(esp_ssl_write_error); + stop(); + return -1; + } + // debug + if (state != lastState || lastState == 0) + { + lastState = state; +#if defined(ESP_SSLCLIENT_ENABLE_DEBUG) + esp_ssl_debug_print(PSTR("SSL state changed."), _debug_level, esp_ssl_debug_info, __func__); + mPrintSSLState(state, esp_ssl_debug_info, __func__); +#endif + } + if (state & BR_SSL_RECVREC) + { + size_t len; + br_ssl_engine_recvrec_buf(_eng, &len); + if (lastLen != len) + { + lastLen = len; +#if defined(ESP_SSLCLIENT_ENABLE_DEBUG) + String s = PSTR("Expected bytes count: "); + s += len; + esp_ssl_debug_print(s.c_str(), _debug_level, esp_ssl_debug_info, __func__); +#endif + } + } + /* + * If we reached our target, then we are finished. + */ + if (state & target || (target == 0 && state == 0)) + return 0; + + /* + * If some application data must be read, and we did not + * exit, then this means that we are trying to write data, + * and that's not possible until the application data is + * read. This may happen if using a shared in/out buffer, + * and the underlying protocol is not strictly half-duplex. + * Normally this would be unrecoverable, however we can attempt + * to remedy the problem by telling the engine to discard + * the data. + */ + if (state & BR_SSL_RECVAPP) + { + _recvapp_buf = br_ssl_engine_recvapp_buf(_eng, &_recvapp_len); + if (_recvapp_buf != nullptr) + { + // if application data is ready in buffer, don't ignore, just return. + + // _write_idx = 0; + // esp_ssl_debug_print(PSTR("Discarded unread data to favor a write operation."), _debug_level, esp_ssl_debug_warn, __func__); + // br_ssl_engine_recvapp_ack(_eng, len); + // continue; + return 0; + } + else + { +#if defined(ESP_SSLCLIENT_ENABLE_DEBUG) + esp_ssl_debug_print(PSTR("SSL engine state is RECVAPP, however the buffer was null! (This is a problem with BearSSL internals)."), _debug_level, esp_ssl_debug_error, __func__); +#endif + setWriteError(esp_ssl_write_error); + stop(); + return -1; + } + } + + if (target & BR_SSL_SENDAPP) + { + // reset the write index + _write_idx = 0; + continue; + } + + /* + * We can reach that point if the target RECVAPP, and + * the state contains SENDAPP only. This may happen with + * a shared in/out buffer. In that case, we must flush + * the buffered data to "make room" for a new incoming + * record. + */ + if (state & BR_SSL_SENDAPP && target & BR_SSL_RECVAPP) + br_ssl_engine_flush(_eng, 0); + } +} + +unsigned BSSL_SSL_Client::mUpdateEngine() +{ + for (;;) + { + // get the state + unsigned state = br_ssl_engine_current_state(_eng); + // debug + if (_bssl_last_state == 0 || state != _bssl_last_state) + { + _bssl_last_state = state; +#if defined(ESP_SSLCLIENT_ENABLE_DEBUG) + mPrintSSLState(state, esp_ssl_debug_info, __func__); +#endif + } + if (state & BR_SSL_CLOSED) + return state; + /* + * If there is some record data to send, do it. This takes + * precedence over everything else. + */ + if (state & BR_SSL_SENDREC) + { + unsigned char *buf; + size_t len; + int wlen; + + buf = br_ssl_engine_sendrec_buf(_eng, &len); + wlen = _basic_client->write(buf, len); + _basic_client->flush(); + if (wlen <= 0) + { + // if the arduino client encountered an error + if (_basic_client->getWriteError() || !_basic_client->connected()) + { +#if defined(ESP_SSLCLIENT_ENABLE_DEBUG) + esp_ssl_debug_print(PSTR("Error writing to basic client."), _debug_level, esp_ssl_debug_error, __func__); +#endif + setWriteError(esp_ssl_write_error); + } + // else presumably the socket just closed itself, so just stop the engine + stop(); + return 0; + } + if (wlen > 0) + { + br_ssl_engine_sendrec_ack(_eng, wlen); + } + continue; + } + + /* + * If the client has specified there is client data to send, and + * the engine is ready to handle it, send it along. + */ + if (_write_idx > 0) + { + // if we've reached the point where BR_SSL_SENDAPP is off but + // data has been written to the io buffer, something is wrong + if (!(state & BR_SSL_SENDAPP)) + { +#if defined(ESP_SSLCLIENT_ENABLE_DEBUG) + esp_ssl_debug_print(PSTR("Error _write_idx > 0 but the ssl engine is not ready for data."), _debug_level, esp_ssl_debug_error, __func__); +#endif + setWriteError(esp_ssl_write_error); + stop(); + return 0; + } + // else time to send the application data + else if (state & BR_SSL_SENDAPP) + { + size_t alen; + unsigned char *buf = br_ssl_engine_sendapp_buf(_eng, &alen); + // engine check + if (alen == 0 || buf == nullptr) + { +#if defined(ESP_SSLCLIENT_ENABLE_DEBUG) + esp_ssl_debug_print(PSTR("Engine set write flag but returned null buffer."), _debug_level, esp_ssl_debug_error, __func__); +#endif + setWriteError(esp_ssl_write_error); + stop(); + return 0; + } + // sanity check + if (alen < _write_idx) + { +#if defined(ESP_SSLCLIENT_ENABLE_DEBUG) + esp_ssl_debug_print(PSTR("Alen is less than _write_idx."), _debug_level, esp_ssl_debug_error, __func__); +#endif + setWriteError(esp_ssl_internal_error); + stop(); + return 0; + } + // all good? lets send the data + // presumably the BSSL_SSL_Client::write function has already added + // data to *buf, so now we tell bearssl it's time for the + // encryption step. + // this will encrypt the data and presumably spit it out + // for BR_SSL_SENDREC to send over ethernet. + br_ssl_engine_sendapp_ack(_eng, _write_idx); + // reset the iobuffer index + _write_idx = 0; + // loop again! + continue; + } + } + + /* + * If there is some record data to recieve, check if we've + * recieved it so far. If we have, then we can update the state. + * else we can return that we're still waiting for the server. + */ + if (state & BR_SSL_RECVREC) + { + size_t len; + unsigned char *buf = br_ssl_engine_recvrec_buf(_eng, &len); + // do we have the record you're looking for? + const auto avail = _basic_client->available(); + if (avail > 0) + { + // I suppose so! + int rlen = _basic_client->read(buf, avail < (int)len ? avail : (int)len); + if (rlen <= 0) + { +#if defined(ESP_SSLCLIENT_ENABLE_DEBUG) + String s = PSTR("Error reading bytes from basic client. Write Error: "); + s += _basic_client->getWriteError(); + esp_ssl_debug_print(s.c_str(), _debug_level, esp_ssl_debug_error, __func__); +#endif + setWriteError(esp_ssl_write_error); + stop(); + return 0; + } + if (rlen > 0) + { + br_ssl_engine_recvrec_ack(_eng, rlen); + } + continue; + } + // guess not, tell the state we're waiting still + else + { + +#if defined __has_include +#if __has_include() + // Add a delay since spamming _basic_client->availible breaks the poor wiz chip + delay(10); +#endif +#endif + return state; + } + } + // if it's not any of the above states, then it must be waiting to send or recieve app data + // in which case we return + return state; + } +} + +void BSSL_SSL_Client::mPrintClientError(const int ssl_error, int level, const char *func_name) +{ +#if defined(ESP_SSLCLIENT_ENABLE_DEBUG) + const char *msg = nullptr; + + switch (ssl_error) + { + case esp_ssl_ok: + msg = PSTR("SSL OK"); + break; + case esp_ssl_connection_fail: + msg = PSTR("SSL Connection fail"); + break; + case esp_ssl_write_error: + msg = PSTR("SSL Write error"); + break; + case esp_ssl_read_error: + msg = PSTR("SSL Read error"); + break; + case esp_ssl_out_of_memory: + msg = PSTR("SSL OOM error"); + break; + case esp_ssl_internal_error: + msg = PSTR("SSL Internal error"); + break; + } + + esp_ssl_debug_print(msg, _debug_level, level, func_name); +#endif +} + +void BSSL_SSL_Client::mPrintSSLError(const unsigned br_error_code, int level, const char *func_name) +{ +#if defined(ESP_SSLCLIENT_ENABLE_DEBUG) + char dest[300]; + getLastSSLError(dest, 300); + esp_ssl_debug_print(dest, _debug_level, level, func_name); +#endif +} + +void BSSL_SSL_Client::mPrintSSLState(const unsigned state, int level, const char *func_name) +{ +#if defined(ESP_SSLCLIENT_ENABLE_DEBUG) + const char *msg = nullptr; + + if (state == 0) + msg = PSTR("State Invalid"); + else if (state & BR_SSL_CLOSED) + msg = PSTR("State Connection close"); + else + { + if (state & BR_SSL_SENDREC) + msg = PSTR("State SENDREC"); + if (state & BR_SSL_RECVREC) + msg = PSTR("State RECVREC"); + if (state & BR_SSL_SENDAPP) + msg = PSTR("State SENDAPP"); + if (state & BR_SSL_RECVAPP) + msg = PSTR("State RECVAPP"); + } + + esp_ssl_debug_print(msg, _debug_level, level, func_name); +#endif +} + +bool BSSL_SSL_Client::mIsSecurePort(uint16_t port) +{ + int size = *(&_secure_ports + 1) - _secure_ports; + for (int i = 0; i < size; i++) + { + if (port == _secure_ports[i]) + return true; + } + + return false; +} + +void BSSL_SSL_Client::mBSSLX509InsecureInit(bssl::br_x509_insecure_context *ctx, int _use_fingerprint, const uint8_t _fingerprint[20], int _allow_self_signed) +{ + static const br_x509_class br_x509_insecure_vtable PROGMEM = { + sizeof(bssl::br_x509_insecure_context), + bssl::insecure_start_chain, + bssl::insecure_start_cert, + bssl::insecure_append, + bssl::insecure_end_cert, + bssl::insecure_end_chain, + bssl::insecure_get_pkey}; + + memset(ctx, 0, sizeof *ctx); + ctx->vtable = &br_x509_insecure_vtable; + ctx->done_cert = false; + ctx->match_fingerprint = _use_fingerprint ? _fingerprint : nullptr; + ctx->allow_self_signed = _allow_self_signed ? 1 : 0; +} + +void BSSL_SSL_Client::mClearAuthenticationSettings() +{ + _use_insecure = false; + _use_fingerprint = false; + _use_self_signed = false; + _knownkey = nullptr; + _ta = nullptr; + if (_esp32_ta) + { + delete _esp32_ta; + _esp32_ta = nullptr; + } +} + +void BSSL_SSL_Client::mClear() +{ + _timeout = 15000; + _sc = nullptr; + _eng = nullptr; + _x509_minimal = nullptr; + _x509_insecure = nullptr; + _x509_knownkey = nullptr; + + freeImpl(&_iobuf_in); + freeImpl(&_iobuf_out); + _now = 0; // You can override or ensure time() is correct w/configTime + _ta = nullptr; + setBufferSizes(16384, 512); // Minimum safe + _secure = false; + _recvapp_buf = nullptr; + _recvapp_len = 0; + _oom_err = false; + _session = nullptr; + freeImpl(&_cipher_list); + _cipher_cnt = 0; + _tls_min = BR_TLS10; + _tls_max = BR_TLS12; + if (_esp32_ta) + { + delete _esp32_ta; + _esp32_ta = nullptr; + } +} + +// X.509 validators differ from server to client +// Installs the appropriate X509 cert validation method for a client connection +bool BSSL_SSL_Client::mInstallClientX509Validator() +{ + + if (_use_insecure || _use_fingerprint || _use_self_signed) + { + // Use common insecure x509 authenticator + _x509_insecure = std::make_shared(); + if (!_x509_insecure) + { +#if defined(ESP_SSLCLIENT_ENABLE_DEBUG) + esp_ssl_debug_print(PSTR("OOM for _x509_insecure"), _debug_level, esp_ssl_debug_error, __func__); +#endif + return false; + } + mBSSLX509InsecureInit(_x509_insecure.get(), _use_fingerprint, _fingerprint, _use_self_signed); + br_ssl_engine_set_x509(_eng, &_x509_insecure->vtable); + } + else if (_knownkey) + { + // Simple, pre-known public key authenticator, ignores cert completely. + _x509_knownkey = std::make_shared(); + if (!_x509_knownkey) + { +#if defined(ESP_SSLCLIENT_ENABLE_DEBUG) + esp_ssl_debug_print(PSTR("OOM for _x509_knownkey"), _debug_level, esp_ssl_debug_error, __func__); +#endif + return false; + } + if (_knownkey->isRSA()) + { + br_x509_knownkey_init_rsa(_x509_knownkey.get(), _knownkey->getRSA(), _knownkey_usages); + } + else if (_knownkey->isEC()) + { +#ifndef BEARSSL_SSL_BASIC + br_x509_knownkey_init_ec(_x509_knownkey.get(), _knownkey->getEC(), _knownkey_usages); +#else + (void)_knownkey; + (void)_knownkey_usages; + esp_ssl_debug_print(PSTR("Attempting to use EC keys in minimal cipher mode (no EC)"), _debug_level, esp_ssl_debug_error, __func__); + return false; +#endif + } + br_ssl_engine_set_x509(_eng, &_x509_knownkey->vtable); + } + else + { + // X509 minimal validator. Checks dates, cert chain for trusted CA, etc. + _x509_minimal = std::make_shared(); + if (!_x509_minimal) + { +#if defined(ESP_SSLCLIENT_ENABLE_DEBUG) + esp_ssl_debug_print(PSTR("OOM for _x509_minimal"), _debug_level, esp_ssl_debug_error, __func__); +#endif + return false; + } + if (_esp32_ta) + { + br_x509_minimal_init(_x509_minimal.get(), &br_sha256_vtable, _esp32_ta->getTrustAnchors(), _esp32_ta->getCount()); + } + else + { + br_x509_minimal_init(_x509_minimal.get(), &br_sha256_vtable, _ta ? _ta->getTrustAnchors() : nullptr, _ta ? _ta->getCount() : 0); + } + br_x509_minimal_set_rsa(_x509_minimal.get(), br_ssl_engine_get_rsavrfy(_eng)); +#ifndef BEARSSL_SSL_BASIC + br_x509_minimal_set_ecdsa(_x509_minimal.get(), br_ssl_engine_get_ec(_eng), br_ssl_engine_get_ecdsa(_eng)); +#endif + bssl::br_x509_minimal_install_hashes(_x509_minimal.get()); + +#if (defined(ESP32) || defined(ESP8266) || defined(ARDUINO_ARCH_RP2040)) && !defined(ARDUINO_NANO_RP2040_CONNECT) + if (_now < ESP_SSLCLIENT_VALID_TIMESTAMP) + _now = time(nullptr); +#endif + if (_now) + { + // Magic constants convert to x509 times + br_x509_minimal_set_time(_x509_minimal.get(), ((uint32_t)_now) / 86400 + 719528, ((uint32_t)_now) % 86400); + } +#if defined(ESP_SSL_FS_SUPPORTED) + if (_certStore) + { + _certStore->installCertStore(_x509_minimal.get()); + } +#endif + br_ssl_engine_set_x509(_eng, &_x509_minimal->vtable); + } + return true; +} + +void BSSL_SSL_Client::mFreeSSL() +{ + // These are smart pointers and will free if refcnt==0 + _sc = nullptr; + _x509_minimal = nullptr; + _x509_insecure = nullptr; + _x509_knownkey = nullptr; + freeImpl(&_iobuf_in); + freeImpl(&_iobuf_out); + // Reset non-allocated ptrs (pointing to bits potentially free'd above) + _recvapp_buf = nullptr; + _recvapp_len = 0; + // This connection is toast + _handshake_done = false; + _timeout = 15000; + _secure = false; + _is_connected = false; +} + +uint8_t *BSSL_SSL_Client::mStreamLoad(Stream &stream, size_t size) +{ + uint8_t *dest = (uint8_t *)malloc(size + 1); + if (!dest) + { + return nullptr; + } + if (size != stream.readBytes(dest, size)) + { + free(dest); + dest = nullptr; + return nullptr; + } + dest[size] = '\0'; + return dest; +} + +// Allocate memory +void *BSSL_SSL_Client::mallocImpl(size_t len, bool clear) +{ + void *p; + size_t newLen = getReservedLen(len); +#if defined(BOARD_HAS_PSRAM) && defined(ESP_SSLCLIENT_USE_PSRAM) + + if (ESP.getPsramSize() > 0) + p = (void *)ps_malloc(newLen); + else + p = (void *)malloc(newLen); + + if (!p) + return NULL; + +#else + +#if defined(ESP_SSLCLIENT_ESP8266_USE_EXTERNAL_HEAP) + ESP.setExternalHeap(); +#endif + + p = (void *)malloc(newLen); + bool nn = p ? true : false; + +#if defined(ESP_SSLCLIENT_ESP8266_USE_EXTERNAL_HEAP) + ESP.resetHeap(); +#endif + + if (!nn) + return NULL; + +#endif + if (clear) + memset(p, 0, newLen); + return p; +} + +// Free reserved memory at pointer. +void BSSL_SSL_Client::freeImpl(void *ptr) +{ + void **p = (void **)ptr; + if (*p) + { + free(*p); + *p = 0; + } +} + +size_t BSSL_SSL_Client::getReservedLen(size_t len) +{ + int blen = len + 1; + + int newlen = (blen / 4) * 4; + + if (newlen < blen) + newlen += 4; + + return (size_t)newlen; +} + +#endif + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/client/BSSL_SSL_Client.h b/lib/libesp32/ESP-Mail-Client/src/SSLClient/client/BSSL_SSL_Client.h new file mode 100644 index 000000000..98a42685d --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/client/BSSL_SSL_Client.h @@ -0,0 +1,349 @@ +/** + * BSSL_SSL_Client library v1.0.11 for Arduino devices. + * + * Created August 27, 2003 + * + * This work contains codes based on WiFiClientSecure from Earle F. Philhower and SSLClient from OSU OPEnS Lab. + * + * Copyright (c) 2018 Earle F. Philhower, III + * + * Copyright 2019 OSU OPEnS Lab + * + * The MIT License (MIT) + * Copyright (c) 2023 K. Suwatchai (Mobizt) + * + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +#ifndef BSSL_SSL_CLIENT_H +#define BSSL_SSL_CLIENT_H + +#pragma GCC diagnostic ignored "-Wunused-function" +#pragma GCC diagnostic ignored "-Wvla" + +#include +#include "../ESP_SSLClient_FS.h" +#include "../ESP_SSLClient_Const.h" +#if defined(USE_LIB_SSL_ENGINE) || defined(USE_EMBED_SSL_ENGINE) + +#include +#include +#if defined __has_include +#if __has_include() +#include +#endif +#endif + +#if defined(USE_LIB_SSL_ENGINE) + +#include "BSSL_Helper.h" +#include "BSSL_CertStore.h" + +using namespace bssl; + +#elif defined(USE_EMBED_SSL_ENGINE) + +#include "BearSSLHelpers.h" +#include "BSSL_Helper.h" +#include "CertStoreBearSSL.h" + +using namespace BearSSL; + +#include + +#if defined(ESP8266) + +#include "PolledTimeout.h" +#if defined(ESP8266_CORE_SDK_V3_X_X) +#include +#endif + +#if __has_include() +#include +#endif + +#endif + +#endif + +class BSSL_SSL_Client : public Client +{ +public: + explicit BSSL_SSL_Client(Client *client = nullptr); + + ~BSSL_SSL_Client(); + + void setClient(Client *client, bool ssl = false); + + void setDebugLevel(int level); + + int connect(IPAddress ip, uint16_t port) override; + + int connect(const char *host, uint16_t port) override; + + uint8_t connected() override; + + void validate(const char *host, uint16_t port); + + void validate(IPAddress ip, uint16_t port); + + int available() override; + + int read() override; + + int read(uint8_t *buf, size_t size) override; + + size_t write(const uint8_t *buf, size_t size) override; + + size_t write(uint8_t b) override; + + size_t write_P(PGM_P buf, size_t size); + + size_t write(Stream &stream); + + int peek() override; + + size_t peekBytes(uint8_t *buffer, size_t length); + + void setInsecure(); + + void enableSSL(bool enable); + + int connectSSL(IPAddress ip, uint16_t port); + + int connectSSL(const char *host, uint16_t port); + + void stop() override; + + void setTimeout(unsigned int timeoutMs); + + void setHandshakeTimeout(unsigned int timeoutMs); + + void flush() override; + + void setBufferSizes(int recv, int xmit); + + operator bool() { return connected() > 0; } + + int availableForWrite(); + + void setSession(BearSSL_Session *session); + + void setKnownKey(const PublicKey *pk, unsigned usages = BR_KEYTYPE_KEYX | BR_KEYTYPE_SIGN); + + bool setFingerprint(const uint8_t fingerprint[20]); + + bool setFingerprint(const char *fpStr); + + void allowSelfSignedCerts(); + + void setTrustAnchors(const X509List *ta); + + void setX509Time(time_t now); + + void setClientRSACert(const X509List *chain, const PrivateKey *sk); + + void setClientECCert(const X509List *chain, const PrivateKey *sk, unsigned allowed_usages, unsigned cert_issuer_key_type); + + int getMFLNStatus(); + + int getLastSSLError(char *dest, size_t len); +#if defined(ESP_SSL_FS_SUPPORTED) + void setCertStore(CertStoreBase *certStore); +#endif + bool setCiphers(const uint16_t *cipherAry, int cipherCount); + + bool setCiphers(const std::vector &list); + + bool setCiphersLessSecure(); + + bool setSSLVersion(uint32_t min, uint32_t max); + + bool probeMaxFragmentLength(IPAddress ip, uint16_t port, uint16_t len); + + bool probeMaxFragmentLength(const char *hostname, uint16_t port, uint16_t len); + + bool probeMaxFragmentLength(const String &host, uint16_t port, uint16_t len); + + size_t peekAvailable(); + + const char *peekBuffer(); + + void peekConsume(size_t consume); + + void setCACert(const char *rootCA); + + void setCertificate(const char *client_ca); + + void setPrivateKey(const char *private_key); + + bool loadCACert(Stream &stream, size_t size); + + bool loadCertificate(Stream &stream, size_t size); + + bool loadPrivateKey(Stream &stream, size_t size); + + int connect(IPAddress ip, uint16_t port, const char *rootCABuff, const char *cli_cert, const char *cli_key); + + int connect(const char *host, uint16_t port, const char *rootCABuff, const char *cli_cert, const char *cli_key); + + BSSL_SSL_Client &operator=(const BSSL_SSL_Client &other); + + bool operator==(const bool value) { return bool() == value; } + + bool operator!=(const bool value) { return bool() != value; } + + bool operator==(const BSSL_SSL_Client &); + + bool operator!=(const BSSL_SSL_Client &rhs) { return !this->operator==(rhs); }; + + unsigned int getTimeout() const; + + void setSecure(const char *rootCABuff, const char *cli_cert, const char *cli_key); + +private: + // Checks for support of Maximum Frame Length Negotiation at the given + // blocksize. Note that, per spec, only 512, 1024, 2048, and 4096 are + // supported. Many servers today do not support this negotiation. + + // TODO - Allow for fragmentation...but not very critical as the ServerHello + // we use comes to < 80 bytes which has no reason to ever be fragmented. + // TODO - Check the type of returned extensions and that the MFL is the exact + // same one we sent. Not critical as only horribly broken servers would + // return changed or add their own extensions. + bool mProbeMaxFragmentLength(Client *probe, uint16_t len); + + bool mProbeMaxFragmentLength(const char *name, IPAddress ip, uint16_t port, uint16_t len); + + int mIsClientInitialized(bool notify); + + int mConnectBasicClient(const char *host, IPAddress ip, uint16_t port); + // Returns whether or not the engine is connected, without polling the client over SPI or other (as opposed to connected()) + bool mSoftConnected(const char *func_name); + + int mConnectSSL(const char *host = nullptr); + + bool mConnectionValidate(const char *host, IPAddress ip, uint16_t port); + + int mRunUntil(const unsigned target, unsigned long timeout = 0); + + unsigned mUpdateEngine(); + + void mPrintClientError(const int ssl_error, int level, const char *func_name); + + void mPrintSSLError(const unsigned br_error_code, int level, const char *func_name); + + void mPrintSSLState(const unsigned br_state, int level, const char *func_name); + + bool mIsSecurePort(uint16_t port); + + void mBSSLX509InsecureInit(bssl::br_x509_insecure_context *ctx, int _use_fingerprint, const uint8_t _fingerprint[20], int _allow_self_signed); + + void mClearAuthenticationSettings(); + + void mClear(); + + bool mInstallClientX509Validator(); + + void mFreeSSL(); + + uint8_t *mStreamLoad(Stream &stream, size_t size); + + void *mallocImpl(size_t len, bool clear = true); + + void freeImpl(void *ptr); + + size_t getReservedLen(size_t len); + + // store whether to enable debug logging + int _debug_level = 0; + + bool _is_connected; + + // store the index of where we are writing in the buffer + // so we can send our records all at once to prevent + // weird timing issues + size_t _write_idx; + + // store the last BearSSL state so we can print changes to the console + unsigned _bssl_last_state; + + bool _secure = false; + + Client *_basic_client = nullptr; + + std::shared_ptr _sc; + br_ssl_engine_context *_eng = nullptr; // &_sc->eng, to allow for client or server contexts + std::shared_ptr _x509_minimal; + std::shared_ptr _x509_insecure; + std::shared_ptr _x509_knownkey; + + unsigned char *_iobuf_in = nullptr; + unsigned char *_iobuf_out = nullptr; + int _iobuf_in_size = 512; + int _iobuf_out_size = 512; + + time_t _now = 0; + const X509List *_ta = nullptr; +#if defined(ESP_SSL_FS_SUPPORTED) + CertStoreBase *_certStore = 0; +#endif + // Optional client certificate + const X509List *_chain = nullptr; + const PrivateKey *_sk = nullptr; + unsigned int _allowed_usages = 0; + unsigned int _cert_issuer_key_type = 0; + + // Optional storage space pointer for session parameters + // Will be used on connect and updated on close + BearSSL_Session *_session = nullptr; + + bool _use_insecure = false; + bool _use_fingerprint = false; + uint8_t _fingerprint[20]; + bool _use_self_signed = false; + const PublicKey *_knownkey; + unsigned int _knownkey_usages = 0; + + // Custom cipher list pointer or nullptr if default + uint16_t *_cipher_list = nullptr; + uint8_t _cipher_cnt = 0; + + // TLS ciphers allowed + uint32_t _tls_min = BR_TLS10; + uint32_t _tls_max = BR_TLS12; + + X509List *_esp32_ta = nullptr; + X509List *_esp32_chain = nullptr; + PrivateKey *_esp32_sk = nullptr; + + bool _handshake_done = false; + bool _oom_err = false; + unsigned char *_recvapp_buf = nullptr; + size_t _recvapp_len; + unsigned long _timeout = 15000; + unsigned long _handshake_timeout = 60000; + bool _isSSLEnabled = false; + String _host; + uint16_t _port = 0; + IPAddress _ip; +}; + +#endif + +#endif /** BSSL_SSL_Client_H */ diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/client/BSSL_TCP_Client.cpp b/lib/libesp32/ESP-Mail-Client/src/SSLClient/client/BSSL_TCP_Client.cpp new file mode 100644 index 000000000..f9f90075f --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/client/BSSL_TCP_Client.cpp @@ -0,0 +1,461 @@ +/** + * BSSL_TCP_Client v2.0.12 for Arduino devices. + * + * Created August 27, 2023 + * + * The MIT License (MIT) + * Copyright (c) 2023 K. Suwatchai (Mobizt) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* + WiFiClientSecure.cpp - Client Secure class for ESP32 + Copyright (c) 2016 Hristo Gochkov All right reserved. + Additions Copyright (C) 2017 Evandro Luis Copercini. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ +#ifndef BSSL_TCP_CLIENT_CPP +#define BSSL_TCP_CLIENT_CPP + +#pragma GCC diagnostic ignored "-Wunused-function" +#pragma GCC diagnostic ignored "-Wvla" + +#include +#include "../ESP_SSLClient_FS.h" +#include "../ESP_SSLClient_Const.h" +#if defined(USE_LIB_SSL_ENGINE) || defined(USE_EMBED_SSL_ENGINE) + +#include "BSSL_TCP_Client.h" +// #include +// #include +// #include + +#undef connect +#undef write +#undef read + +BSSL_TCP_Client::BSSL_TCP_Client() +{ + setClient(nullptr); + _ssl_client.setTimeout(120000); + _use_insecure = false; +} + +BSSL_TCP_Client::~BSSL_TCP_Client() +{ + stop(); + setClient(nullptr); +} + +void BSSL_TCP_Client::setClient(Client *client, bool enableSSL) +{ + _basic_client = client; + _ssl_client.setClient(_basic_client, enableSSL); +} + +void BSSL_TCP_Client::setDebugLevel(int level) +{ + _ssl_client.setDebugLevel(level); +} + +int BSSL_TCP_Client::connect(IPAddress ip, uint16_t port) +{ + return connect(ip, port, 0); +} + +int BSSL_TCP_Client::connect(IPAddress ip, uint16_t port, int32_t timeout) +{ + _port = port; + + if (timeout > 0) + { + _timeout = timeout; + if (_basic_client) + _basic_client->setTimeout(_timeout); + _ssl_client.setTimeout(_timeout); + } + + return _ssl_client.connect(ip, port); +} + +int BSSL_TCP_Client::connect(const char *host, uint16_t port) +{ + return connect(host, port, 0); +} + +int BSSL_TCP_Client::connect(const char *host, uint16_t port, int32_t timeout) +{ + + _host = host; + _port = port; + + if (timeout > 0) + { + _timeout = timeout; + if (_basic_client) + _basic_client->setTimeout(_timeout); + _ssl_client.setTimeout(_timeout); + } + + return _ssl_client.connect(host, port); +} + +uint8_t BSSL_TCP_Client::connected() +{ + return _ssl_client.connected(); +} + +void BSSL_TCP_Client::validate(const char *host, uint16_t port) +{ + _ssl_client.validate(host, port); +} + +void BSSL_TCP_Client::validate(IPAddress ip, uint16_t port) +{ + _ssl_client.validate(ip, port); +} + +int BSSL_TCP_Client::available() +{ + return _ssl_client.available(); +} + +int BSSL_TCP_Client::read() +{ + uint8_t data = -1; + int res = read(&data, 1); + if (res < 0) + return res; + return data; +} + +int BSSL_TCP_Client::read(uint8_t *buf, size_t size) +{ + if (!_ssl_client.connected()) + return 0; + return _ssl_client.read(buf, size); +} + +int BSSL_TCP_Client::send(const char *data) +{ + return write((uint8_t *)data, strlen(data)); +} + +int BSSL_TCP_Client::print(const char *data) +{ + return send(data); +} + +int BSSL_TCP_Client::print(const String &data) +{ + return print(data.c_str()); +} + +int BSSL_TCP_Client::print(int data) +{ + char buf[64]; + memset(buf, 0, 64); + sprintf(buf, (const char *)FPSTR("%d"), data); + int ret = send(buf); + return ret; +} + +int BSSL_TCP_Client::println(const char *data) +{ + int len = send(data); + if (len < 0) + return len; + int sz = send((const char *)FPSTR("\r\n")); + if (sz < 0) + return sz; + return len + sz; +} + +int BSSL_TCP_Client::println(const String &data) +{ + return println(data.c_str()); +} + +int BSSL_TCP_Client::println(int data) +{ + char buf[64]; + memset(buf, 0, 64); + sprintf(buf, (const char *)FPSTR("%d\r\n"), data); + int ret = send(buf); + return ret; +} + +size_t BSSL_TCP_Client::write(const uint8_t *buf, size_t size) +{ + if (!_ssl_client.connected()) + return 0; + return _ssl_client.write(buf, size); +} + +size_t BSSL_TCP_Client::write(uint8_t data) +{ + return write(&data, 1); +} + +size_t BSSL_TCP_Client::write_P(PGM_P buf, size_t size) { return _ssl_client.write_P(buf, size); } + +size_t BSSL_TCP_Client::write(const char *buf) { return write((const uint8_t *)buf, strlen(buf)); } + +size_t BSSL_TCP_Client::write(Stream &stream) { return _ssl_client.write(stream); } + +int BSSL_TCP_Client::peek() +{ + return _ssl_client.peek(); +} + +void BSSL_TCP_Client::setInsecure() +{ + _ssl_client.setInsecure(); + _use_insecure = true; +} + +void BSSL_TCP_Client::enableSSL(bool enable) +{ + _ssl_client.enableSSL(enable); +} + +bool BSSL_TCP_Client::connectSSL() +{ + if (!_ssl_client.connectSSL(_host.c_str(), _port)) + { + stop(); + return 0; + } + return 1; +} + +bool BSSL_TCP_Client::connectSSL(const String host, uint16_t port) { return connectSSL(); } + +void BSSL_TCP_Client::stop() +{ + _ssl_client.stop(); +} + +int BSSL_TCP_Client::setTimeout(uint32_t seconds) +{ + _timeout = seconds * 1000; + _ssl_client.setTimeout(_timeout); + return 1; +} + +int BSSL_TCP_Client::getTimeout() { return _ssl_client.getTimeout() / 1000; } + +void BSSL_TCP_Client::setHandshakeTimeout(unsigned long handshake_timeout) +{ + _handshake_timeout = handshake_timeout * 1000; + _ssl_client.setHandshakeTimeout(_handshake_timeout); +} + +void BSSL_TCP_Client::flush() +{ + if (!_basic_client) + return; + + while (available() > 0) + read(); +} + +void BSSL_TCP_Client::setBufferSizes(int recv, int xmit) +{ + _ssl_client.setBufferSizes(recv, xmit); +} + +int BSSL_TCP_Client::availableForWrite() { return _ssl_client.availableForWrite(); }; + +void BSSL_TCP_Client::setSession(BearSSL_Session *session) { _ssl_client.setSession(session); }; + +void BSSL_TCP_Client::setKnownKey(const PublicKey *pk, unsigned usages) +{ + _ssl_client.setKnownKey(pk, usages); +} + +bool BSSL_TCP_Client::setFingerprint(const uint8_t fingerprint[20]) +{ + return _ssl_client.setFingerprint(fingerprint); +} + +bool BSSL_TCP_Client::setFingerprint(const char *fpStr) +{ + return _ssl_client.setFingerprint(fpStr); +} + +void BSSL_TCP_Client::allowSelfSignedCerts() +{ + _ssl_client.allowSelfSignedCerts(); +} + +void BSSL_TCP_Client::setTrustAnchors(const X509List *ta) +{ + _ssl_client.setTrustAnchors(ta); +} + +void BSSL_TCP_Client::setX509Time(time_t now) +{ + _ssl_client.setX509Time(now); +} + +void BSSL_TCP_Client::setClientRSACert(const X509List *cert, const PrivateKey *sk) +{ + _ssl_client.setClientRSACert(cert, sk); +} + +void BSSL_TCP_Client::setClientECCert(const X509List *cert, const PrivateKey *sk, unsigned allowed_usages, unsigned cert_issuer_key_type) +{ + _ssl_client.setClientECCert(cert, sk, allowed_usages, cert_issuer_key_type); +} + +int BSSL_TCP_Client::getMFLNStatus() { return _ssl_client.getMFLNStatus(); }; + +int BSSL_TCP_Client::getLastSSLError(char *dest, size_t len) +{ + return _ssl_client.getLastSSLError(dest, len); +} + +#if defined(ESP_SSL_FS_SUPPORTED) +void BSSL_TCP_Client::setCertStore(CertStoreBase *certStore) +{ + _ssl_client.setCertStore(certStore); +} +#endif + +bool BSSL_TCP_Client::setCiphers(const uint16_t *cipherAry, int cipherCount) +{ + return _ssl_client.setCiphers(cipherAry, cipherCount); +} + +bool BSSL_TCP_Client::setCiphers(const std::vector &list) +{ + return _ssl_client.setCiphers(list); +} + +bool BSSL_TCP_Client::setCiphersLessSecure() +{ + return _ssl_client.setCiphersLessSecure(); +} + +bool BSSL_TCP_Client::setSSLVersion(uint32_t min, uint32_t max) +{ + return _ssl_client.setSSLVersion(min, max); +} + +bool BSSL_TCP_Client::probeMaxFragmentLength(IPAddress ip, uint16_t port, uint16_t len) { return _ssl_client.probeMaxFragmentLength(ip, port, len); }; + +bool BSSL_TCP_Client::probeMaxFragmentLength(const char *hostname, uint16_t port, uint16_t len) { return _ssl_client.probeMaxFragmentLength(hostname, port, len); }; + +bool BSSL_TCP_Client::probeMaxFragmentLength(const String &host, uint16_t port, uint16_t len) { return _ssl_client.probeMaxFragmentLength(host, port, len); }; + +// peek buffer API is present +bool BSSL_TCP_Client::hasPeekBufferAPI() const { return true; } + +// return number of byte accessible by peekBuffer() +size_t BSSL_TCP_Client::peekAvailable() { return _ssl_client.peekAvailable(); } + +// return a pointer to available data buffer (size = peekAvailable()) +// semantic forbids any kind of read() before calling peekConsume() +const char *BSSL_TCP_Client::peekBuffer() { return _ssl_client.peekBuffer(); } + +// consume bytes after use (see peekBuffer) +void BSSL_TCP_Client::peekConsume(size_t consume) { return _ssl_client.peekConsume(consume); } + +void BSSL_TCP_Client::setCACert(const char *rootCA) +{ + _ssl_client.setCACert(rootCA); +} + +void BSSL_TCP_Client::setCertificate(const char *client_ca) { return _ssl_client.setCertificate(client_ca); } + +void BSSL_TCP_Client::setPrivateKey(const char *private_key) { return _ssl_client.setPrivateKey(private_key); } + +bool BSSL_TCP_Client::loadCACert(Stream &stream, size_t size) +{ + char *dest = mStreamLoad(stream, size); + bool ret = false; + if (dest) + { + setCACert(dest); + ret = true; + } + return ret; +} + +bool BSSL_TCP_Client::loadCertificate(Stream &stream, size_t size) { return _ssl_client.loadCertificate(stream, size); } + +bool BSSL_TCP_Client::loadPrivateKey(Stream &stream, size_t size) { return _ssl_client.loadPrivateKey(stream, size); } + +int BSSL_TCP_Client::connect(IPAddress ip, uint16_t port, const char *rootCABuff, const char *cli_cert, const char *cli_key) { return _ssl_client.connect(ip, port, rootCABuff, cli_cert, cli_key); } + +int BSSL_TCP_Client::connect(const char *host, uint16_t port, const char *rootCABuff, const char *cli_cert, const char *cli_key) { return _ssl_client.connect(host, port, rootCABuff, cli_cert, cli_key); } + +BSSL_TCP_Client &BSSL_TCP_Client::operator=(const BSSL_TCP_Client &other) +{ + stop(); + setClient(other._basic_client); + _use_insecure = other._use_insecure; + _timeout = other._timeout; + _handshake_timeout = other._handshake_timeout; + _ssl_client.setTimeout(_timeout); + _ssl_client.setHandshakeTimeout(_handshake_timeout); + if (_use_insecure) + _ssl_client.setInsecure(); + return *this; +} + +char *BSSL_TCP_Client::mStreamLoad(Stream &stream, size_t size) +{ + char *dest = (char *)malloc(size + 1); + if (!dest) + { + return nullptr; + } + if (size != stream.readBytes(dest, size)) + { + free(dest); + dest = nullptr; + return nullptr; + } + dest[size] = '\0'; + return dest; +} + +bool BSSL_TCP_Client::operator==(const BSSL_TCP_Client &rhs) +{ + return _basic_client == rhs._basic_client && _port == rhs._port && _host == rhs._host; +} + +#endif + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/SSLClient/client/BSSL_TCP_Client.h b/lib/libesp32/ESP-Mail-Client/src/SSLClient/client/BSSL_TCP_Client.h new file mode 100644 index 000000000..f70dbddfb --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/SSLClient/client/BSSL_TCP_Client.h @@ -0,0 +1,437 @@ +/** + * BSSL_TCP_Client v2.0.12 for Arduino devices. + * + * Created August 27, 2023 + * + * The MIT License (MIT) + * Copyright (c) 2023 K. Suwatchai (Mobizt) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* + WiFiClientSecure.h - Base class that provides Client SSL to ESP32 + Copyright (c) 2011 Adrian McEwen. All right reserved. + Additions Copyright (C) 2017 Evandro Luis Copercini. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef BSSL_TCP_CLIENT_H +#define BSSL_TCP_CLIENT_H + +#pragma GCC diagnostic ignored "-Wunused-function" +#pragma GCC diagnostic ignored "-Wvla" + +#include +#include "../ESP_SSLClient_FS.h" +#include "../ESP_SSLClient_Const.h" +#if defined(USE_LIB_SSL_ENGINE) || defined(USE_EMBED_SSL_ENGINE) + +#include "BSSL_SSL_Client.h" + +#include + +class BSSL_TCP_Client : public Client +{ + +protected: + bool _use_insecure; + +public: + BSSL_TCP_Client *next; + + // The default class constructor + BSSL_TCP_Client(); + + // The class deconstructor + ~BSSL_TCP_Client(); + + /** + * Set the client. + * @param client The pointer to Client interface. + * @param enableSSL The ssl option; true for enable, false for disable. + * + * Due to the client pointer is assigned, to avoid dangling pointer, + * client should be existed as long as it was used for transportation. + */ + void setClient(Client *client, bool enableSSL = true); + + /** + * Set debug level. + * @param level The debug level or esp_ssl_client_debug_level. + * esp_ssl_debug_none = 0 + * esp_ssl_debug_error = 1 + * esp_ssl_debug_warn = 2 + * esp_ssl_debug_info = 3 + * esp_ssl_debug_dump = 4 + */ + void setDebugLevel(int level); + + /** + * Connect to server. + * @param ip The server IP to connect. + * @param port The server port to connecte. + * @return 1 for success or 0 for error. + */ + int connect(IPAddress ip, uint16_t port) override; + + /** + * Connect to server. + * @param ip The server IP to connect. + * @param port The server port to connect. + * @param timeout The connection time out in miiliseconds. + * @return 1 for success or 0 for error. + */ + int connect(IPAddress ip, uint16_t port, int32_t timeout); + + /** + * Connect to server. + * @param host The server host name. + * @param port The server port to connect. + * @return 1 for success or 0 for error. + */ + int connect(const char *host, uint16_t port) override; + + /** + * Connect to server. + * @param host The server host name. + * @param port The server port to connect. + * @param timeout The connection time out in miiliseconds. + * @return 1 for success or 0 for error. + */ + int connect(const char *host, uint16_t port, int32_t timeout); + + /** + * Get TCP connection status. + * @return 1 for connected or 0 for not connected. + */ + uint8_t connected() override; + + /** + * Validate the last Client connection with these host and port. + * @param host The server host name. + * @param port The server port to connect. + * The Client connection will be closed when the provided host or port is not match with that of last connection. + */ + void validate(const char *host, uint16_t port); + + /** + * Validate the last Client connection with these IP and port. + * @param ip The server IP to connect. + * @param port The server port to connect. + * The Client connection will be closed when the provided IP or port is not match with that of last connection. + */ + void validate(IPAddress ip, uint16_t port); + + /** + * Get available data size to read. + * @return The avaiable data size. + * @note Get available data directly via lwIP for non-secure mode or via mbedTLS for secure mode. + */ + int available() override; + + /** + * The TCP data read function. + * @return A byte data that was successfully read or -1 for error. + * @note Get data directly via lwIP for non-secure mode or via mbedTLS to deccrypt data for secure mode. + */ + int read() override; + + /** + * The TCP data read function. + * @param buf The data buffer. + * @param size The length of data that read. + * @return The size of data that was successfully read or 0 for error. + * @note Get data directly via lwIP for non-secure mode or via mbedTLS to deccrypt data for secure mode. + */ + int read(uint8_t *buf, size_t size) override; + + /** + * The TCP data send function. + * @param data The data to send. + * @return The size of data that was successfully sent or 0 for error. + */ + int send(const char *data); + + /** + * The TCP data print function. + * @param data The data to print. + * @return The size of data that was successfully print or 0 for error. + */ + int print(const char *data); + + /** + * The TCP data print function. + * @param data The data to print. + * @return The size of data that was successfully print or 0 for error. + */ + int print(const String &data); + + /** + * The TCP data print function. + * @param data The data to print. + * @return The size of data that was successfully print or 0 for error. + */ + int print(int data); + + /** + * The TCP data print with new line function. + * @param data The data to print. + * @return The size of data that was successfully print or 0 for error. + */ + int println(const char *data); + + /** + * The TCP data print with new line function. + * @param data The data to print. + * @return The size of data that was successfully print or 0 for error. + */ + int println(const String &data); + + /** + * The TCP data print with new line function. + * @param data The data to print. + * @return The size of data that was successfully print or 0 for error. + */ + int println(int data); + + /** + * The TCP data write function. + * @param buf The data to write. + * @param size The length of data to write. + * @return The size of data that was successfully written or 0 for error. + * @note Send data directly via lwIP for non-secure mode or via mbedTLS to encrypt for secure mode. + */ + size_t write(const uint8_t *buf, size_t size) override; + + /** + * The TCP data write function. + * @param data The byte of data to write. + * @return The size of data that was successfully written (1) or 0 for error. + * @note Send data directly via lwIP for non-secure mode or via mbedTLS to encrypt for secure mode. + */ + size_t write(uint8_t data) override; + + /** + * The TCP data write function. + * @param buf The PGM data to write. + * @param size The length of data to write. + * @return The size of data that was successfully written or 0 for error. + */ + size_t write_P(PGM_P buf, size_t size); + + /** + * The TCP data write function. + * @param buf The string data to write. + * @return The size of data that was successfully written or 0 for error. + */ + size_t write(const char *buf); + + /** + * The TCP data write function. + * @param stream The stream data to write. + * @return The size of data that was successfully written or 0 for error. + */ + size_t write(Stream &stream); + + /** + * Read one byte from Stream with time out. + * @return The byte of data that was successfully read or -1 for timed out. + */ + int peek() override; + + /** + * Disable certificate verification and ignore the authentication. + */ + void setInsecure(); // Don't validate the chain, just accept whatever is given. VERY INSECURE! + + /** + * Enable/disable the SSL layer transport. + * @param enable The enable option; true for enable, false to disable. + */ + void enableSSL(bool enable); + + /** + * Upgrade the current connection by setting up the SSL and perform the SSL handshake. + * + * @return operating result. + */ + bool connectSSL(); + + /** + * Upgrade the current connection by setting up the SSL and perform the SSL handshake. + * @param host The host to connect (unused). + * @param port The port to connect (unused). + * @return operating result. + */ + bool connectSSL(const String host, uint16_t port); + + /** + * Stop the TCP connection and release resources. + */ + void stop() override; + + /** + * Set the TCP timeout in seconds. + * @param seconds The TCP timeout in seconds. + */ + int setTimeout(uint32_t seconds); + + /** + * Get the TCP timeout in seconds. + * @return The TCP timeout in seconds. + */ + int getTimeout(); + + /** + * Set the SSL handshake timeout in seconds. + * @param handshake_timeout The SSL handshake timeout in seconds. + */ + void setHandshakeTimeout(unsigned long handshake_timeout); + + /** + * Wait for all receive buffer data read. + */ + void flush() override; + + /** + * Sets the requested buffer size for transmit and receive + * @param recv The receive buffer size. + * @param xmit The transmit buffer size. + */ + void setBufferSizes(int recv, int xmit); + + operator bool() { return connected(); } + + int availableForWrite(); + + void setSession(BearSSL_Session *session); + + void setKnownKey(const PublicKey *pk, unsigned usages = BR_KEYTYPE_KEYX | BR_KEYTYPE_SIGN); + + /** + * Verify certificate's SHA256 fingerprint. + * + * @param fingerprint The certificate's SHA256 fingerprint data to compare with server certificate's SHA256 fingerprint. + * @return verification result. + */ + bool setFingerprint(const uint8_t fingerprint[20]); + + bool setFingerprint(const char *fpStr); + + void allowSelfSignedCerts(); + + void setTrustAnchors(const X509List *ta); + + void setX509Time(time_t now); + + void setClientRSACert(const X509List *cert, const PrivateKey *sk); + + void setClientECCert(const X509List *cert, const PrivateKey *sk, unsigned allowed_usages, unsigned cert_issuer_key_type); + + int getMFLNStatus(); + + int getLastSSLError(char *dest = NULL, size_t len = 0); +#if defined(ESP_SSL_FS_SUPPORTED) + void setCertStore(CertStoreBase *certStore); +#endif + bool setCiphers(const uint16_t *cipherAry, int cipherCount); + + bool setCiphers(const std::vector &list); + + bool setCiphersLessSecure(); + + bool setSSLVersion(uint32_t min = BR_TLS10, uint32_t max = BR_TLS12); + + bool probeMaxFragmentLength(IPAddress ip, uint16_t port, uint16_t len); + + bool probeMaxFragmentLength(const char *hostname, uint16_t port, uint16_t len); + + bool probeMaxFragmentLength(const String &host, uint16_t port, uint16_t len); + + bool hasPeekBufferAPI() const; + + size_t peekAvailable(); + + const char *peekBuffer(); + + void peekConsume(size_t consume); + + /** + * Set the Root CA or CA certificate. + * @param rootCA The Root CA or CA certificate. + */ + void setCACert(const char *rootCA); + + void setCertificate(const char *client_ca); + + void setPrivateKey(const char *private_key); + + /** + * Read and set CA cert from file (Stream). + * @param stream The Stream interface. + * @param size The size of data to read. + * @return The operating result. + */ + bool loadCACert(Stream &stream, size_t size); + + bool loadCertificate(Stream &stream, size_t size); + + bool loadPrivateKey(Stream &stream, size_t size); + + int connect(IPAddress ip, uint16_t port, const char *rootCABuff, const char *cli_cert, const char *cli_key); + + int connect(const char *host, uint16_t port, const char *rootCABuff, const char *cli_cert, const char *cli_key); + + BSSL_TCP_Client &operator=(const BSSL_TCP_Client &other); + + bool operator==(const bool value) { return bool() == value; } + + bool operator!=(const bool value) { return bool() != value; } + + bool operator==(const BSSL_TCP_Client &); + + bool operator!=(const BSSL_TCP_Client &rhs) { return !this->operator==(rhs); }; + +private: + String _host; + uint16_t _port; + BSSL_SSL_Client _ssl_client; + Client *_basic_client = nullptr; + unsigned long _timeout = 15000; + unsigned long _handshake_timeout = 60000; + + char *mStreamLoad(Stream &stream, size_t size); +}; + +#endif + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/extras/Build_Options.h b/lib/libesp32/ESP-Mail-Client/src/extras/Build_Options.h new file mode 100644 index 000000000..a2251f896 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/extras/Build_Options.h @@ -0,0 +1,52 @@ +#ifndef BUILD_OPTIONS_H +#define BUILD_OPTIONS_H + +#if defined(DISABLE_ALL_OPTIONS) +#undef ENABLE_NTP_TIME +#undef ENABLE_ERROR_STRING +#undef ENABLE_IMAP +#undef ENABLE_SMTP +#undef ESP_MAIL_USE_PSRAM +#undef ESP_MAIL_DEFAULT_SD_FS +#undef ESP_MAIL_CARD_TYPE_SD +#undef ESP_MAIL_CARD_TYPE_SD_MMC +#undef ESP_MAIL_DEFAULT_FLASH_FS +#undef ESP_MAIL_DEFAULT_DEBUG_PORT +#endif + +#if defined(DISABLE_NTP_TIME) +#undef ENABLE_NTP_TIME +#endif + +#if defined(DISABLE_ERROR_STRING) +#undef ENABLE_ERROR_STRING +#endif + +#if defined(DISABLE_IMAP) +#undef ENABLE_IMAP +#endif + +#if defined(DISABLE_SMTP) +#undef ENABLE_SMTP +#endif + +#if defined(DISABLE_PSRAM) +#undef ESP_MAIL_USE_PSRAM +#endif + +#if defined(DISABLE_SD) +#undef ESP_MAIL_DEFAULT_SD_FS +#undef ESP_MAIL_CARD_TYPE_SD_MMC +#undef ESP_MAIL_DEFAULT_FLASH_FS +#endif + +#if defined(DISABLE_FLASH) +#undef ESP_MAIL_DEFAULT_FLASH_FS +#undef ESP_MAIL_FORMAT_FLASH_IF_MOUNT_FAILED +#endif + +#if defined(ESP_MAIL_DEFAULT_DEBUG_PORT) +#undef ESP_MAIL_DEFAULT_DEBUG_PORT +#endif + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/extras/ESP8266_Supports.h b/lib/libesp32/ESP-Mail-Client/src/extras/ESP8266_Supports.h new file mode 100644 index 000000000..5604690c6 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/extras/ESP8266_Supports.h @@ -0,0 +1,52 @@ +#ifndef ESP8266_SUPPORTS_H +#define ESP8266_SUPPORTS_H +#include +#include "MB_MCU.h" +#if defined(ESP8266) || defined(MB_ARDUINO_PICO) + +#include + +//__GNUC__ +//__GNUC_MINOR__ +//__GNUC_PATCHLEVEL__ + +#ifdef __GNUC__ +#if __GNUC__ > 4 || __GNUC__ == 10 +#if defined(ARDUINO_ESP8266_GIT_VER) +#if ARDUINO_ESP8266_GIT_VER > 0 +#define ESP8266_CORE_SDK_V3_X_X +#endif +#endif +#endif +#endif + +#if defined __has_include + +#if __has_include() +#include +#endif + +#if __has_include()&& defined(ENABLE_ESP8266_ENC28J60_ETH) +#define INC_ENC28J60_LWIP +#include +#endif + +#if __has_include() && defined(ENABLE_ESP8266_W5100_ETH) +#define INC_W5100_LWIP +#include +#endif + +#if __has_include()&& defined(ENABLE_ESP8266_W5500_ETH) +#define INC_W5500_LWIP +#include +#endif + +#if defined(MB_ARDUINO_PICO) + +#endif + +#endif + +#endif + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/extras/MB_FS.h b/lib/libesp32/ESP-Mail-Client/src/extras/MB_FS.h new file mode 100644 index 000000000..96740627b --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/extras/MB_FS.h @@ -0,0 +1,1137 @@ +/** + * The MB_FS, filesystems wrapper class v1.0.16 + * + * This wrapper class is for SD and Flash filesystems interface which supports SdFat (//https://github.com/greiman/SdFat) + * + * Created June 14, 2023 + * + * The MIT License (MIT) + * Copyright (c) 2023 K. Suwatchai (Mobizt) + * + * + * Permission is hereby granted, free of charge, to any person returning a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef MBFS_CLASS_H +#define MBFS_CLASS_H + +#include +#include "MB_MCU.h" + +#define FS_NO_GLOBALS +#if defined(ESP32) || defined(ESP8266) || defined(MB_ARDUINO_PICO) +#if defined(MBFS_FLASH_FS) || defined(MBFS_SD_FS) +#include +#endif +#endif +#include "MB_FS_Interfaces.h" +#include MB_STRING_INCLUDE_CLASS + +#if defined(MBFS_FLASH_FS) || defined(MBFS_SD_FS) +#include "SPI.h" +#endif + +#if defined(ESP32) && __has_include() +#ifdef _LITTLEFS_H_ +#define MB_FS_USE_POSIX_STAT +#include +namespace mb_fs_ns +{ + inline bool exists(const char *mountPoint, const char *filename) + { + MB_String path = mountPoint; + path += filename; + struct stat st; + return stat(path.c_str(), &st) == 0; + } +}; +#endif +#endif + +using namespace mb_string; + +#if defined(BOARD_HAS_PSRAM) && defined(MB_STRING_USE_PSRAM) +#include +#endif + +#define MB_FS_ERROR_FILE_IO_ERROR -300 +#define MB_FS_ERROR_FILE_NOT_FOUND -301 +#define MB_FS_ERROR_FLASH_STORAGE_IS_NOT_READY -302 +#define MB_FS_ERROR_SD_STORAGE_IS_NOT_READY -303 +#define MB_FS_ERROR_FILE_STILL_OPENED -304 + +typedef enum +{ + mb_fs_mem_storage_type_undefined, + mb_fs_mem_storage_type_flash, + mb_fs_mem_storage_type_sd +} mb_fs_mem_storage_type; + +typedef enum +{ + mb_fs_open_mode_undefined = -1, + mb_fs_open_mode_read = 0, + mb_fs_open_mode_write, + mb_fs_open_mode_append +} mb_fs_open_mode; + +#define mbfs_file_type mb_fs_mem_storage_type +#define mbfs_flash mb_fs_mem_storage_type_flash +#define mbfs_sd mb_fs_mem_storage_type_sd +#define mbfs_undefined mb_fs_mem_storage_type_undefined + +#define mbfs_type (mbfs_file_type) + +#if defined(ARDUINO_ARCH_SAMD) || defined(__AVR_ATmega4809__) || defined(ARDUINO_NANO_RP2040_CONNECT) +#if !defined(MBFS_SDFAT_ENABLED) +struct mbfs_sd_config_info_t +{ + int ss = -1; +}; +#endif +#elif defined(ESP32) || defined(MBFS_SDFAT_ENABLED) + +#if defined(ESP32) +struct mbfs_sd_mmc_config_info_t +{ + const char *mountpoint = ""; + bool mode1bit = false; + bool format_if_mount_failed = false; +}; +#endif + +struct mbfs_sd_config_info_t +{ + int ss = -1; + int sck = -1; + int miso = -1; + int mosi = -1; + uint32_t frequency = 4000000; + +#if defined(MBFS_ESP32_SDFAT_ENABLED) || defined(MBFS_SDFAT_ENABLED) + + SdSpiConfig *sdFatSPIConfig = nullptr; + SdioConfig *sdFatSDIOConfig = nullptr; + +#endif + +#if defined(ESP32) + +#if defined(MBFS_SD_FS) + SPIClass *spiConfig = nullptr; +#endif + mbfs_sd_mmc_config_info_t sdMMCConfig; +#endif + +#if defined(MBFS_SDFAT_ENABLED) + SPIClass *spiConfig = nullptr; +#endif +}; + +#elif defined(ESP8266) || defined(MB_ARDUINO_PICO) +struct mbfs_sd_config_info_t +{ + int ss = -1; +#if defined(MBFS_SD_FS) + SDFSConfig *sdFSConfig = nullptr; +#endif +}; +#else +struct mbfs_sd_config_info_t +{ + int ss = -1; +}; +#endif + +class MB_FS +{ + +public: + MB_FS() {} + ~MB_FS() {} + + struct mbfs_sd_config_info_t sd_config; + + // Assign the SD card interfaces with GPIO pins. + bool sdBegin(int ss = -1, int sck = -1, int miso = -1, int mosi = -1, uint32_t frequency = 4000000) + { + if (sd_rdy) + return true; + +#if defined(MBFS_SD_FS) && defined(MBFS_CARD_TYPE_SD) + sd_config.ss = ss; +#if defined(ESP32) + sd_config.sck = sck; + sd_config.miso = miso; + sd_config.mosi = mosi; + SPI.begin(sck, miso, mosi, ss); + sd_config.frequency = frequency; + return sdSPIBegin(ss, &SPI, frequency); +#elif defined(ESP8266) || defined(ARDUINO_ARCH_SAMD) || defined(__AVR_ATmega4809__) || defined(ARDUINO_NANO_RP2040_CONNECT) + sd_rdy = MBFS_SD_FS.begin(ss); + return sd_rdy; +#elif defined(MB_ARDUINO_PICO) + SDFSConfig c; + c.setCSPin(ss); + c.setSPISpeed(frequency); + MBFS_SD_FS.setConfig(c); + sd_rdy = MBFS_SD_FS.begin(); + return sd_rdy; +#endif + +#endif + return false; + } + +#if defined(ESP32) && defined(MBFS_SD_FS) && defined(MBFS_CARD_TYPE_SD) + + // Assign the SD card interfaces with SPIClass object pointer (ESP32 only). + bool sdSPIBegin(int ss, SPIClass *spiConfig, uint32_t frequency) + { + + if (sd_rdy) + return true; + + sd_config.frequency = frequency; + +#if defined(ESP32) + + sd_config.ss = ss; + + if (spiConfig) + sd_config.spiConfig = spiConfig; + else + sd_config.spiConfig = &SPI; + +#if !defined(MBFS_ESP32_SDFAT_ENABLED) || defined(MBFS_SDFAT_ENABLED) + if (ss > -1) + sd_rdy = MBFS_SD_FS.begin(ss, *sd_config.spiConfig, frequency); + else + sd_rdy = MBFS_SD_FS.begin(); +#endif + +#elif defined(ESP8266) || defined(MB_ARDUINO_PICO) + + cfg->_int.sd_config.sck = sck; + + if (ss > -1) + sd_rdy = MBFS_SD_FS.begin(ss); + else + sd_rdy = MBFS_SD_FS.begin(SD_CS_PIN); +#endif + + return sd_rdy; + } + +#endif + +#if defined(MBFS_ESP32_SDFAT_ENABLED) || defined(MBFS_SDFAT_ENABLED) + + // Assign the SD card interfaces with SdSpiConfig object pointer and SPI pins assignment. + bool sdFatBegin(SdSpiConfig *sdFatSPIConfig, int ss, int sck, int miso, int mosi) + { + + if (sd_rdy) + return true; + + if (sdFatSPIConfig) + { + sd_config.sdFatSPIConfig = sdFatSPIConfig; + sd_config.spiConfig = &SPI; + sd_config.ss = ss; + +#if defined(ESP32) + if (ss > -1) + sd_config.spiConfig->begin(sck, miso, mosi, ss); +#endif + + sd_rdy = MBFS_SD_FS.begin(*sd_config.sdFatSPIConfig); + return sd_rdy; + } + + return false; + } + + // Assign the SD card interfaces with SdioConfig object pointer. + bool sdFatBegin(SdioConfig *sdFatSDIOConfig) + { + + if (sd_rdy) + return true; + +#if defined(HAS_SDIO_CLASS) // Default is 0 (no SDIO) in SdFatConfig.h + +#if HAS_SDIO_CLASS + + if (sdFatSDIOConfig) + { + sd_config.sdFatSDIOConfig = sdFatSDIOConfig; + + sd_rdy = MBFS_SD_FS.begin(*sd_config.sdFatSDIOConfig); + return sd_rdy; + } +#endif + +#endif + + return false; + } +#endif + +#if (defined(ESP8266) || defined(MB_ARDUINO_PICO)) && defined(MBFS_SD_FS) + // Assign the SD card interfaces with SDFSConfig object pointer (ESP8266 and Pico only). + bool sdFatBegin(SDFSConfig *sdFSConfig) + { + + if (sd_rdy) + return true; + + if (sdFSConfig) + { + sd_config.sdFSConfig = sdFSConfig; + SDFS.setConfig(*sd_config.sdFSConfig); + sd_rdy = SDFS.begin(); + return sd_rdy; + } + + return false; + } +#endif + + // Assign the SD_MMC card interfaces (ESP32 only). + bool sdMMCBegin(const char *mountpoint, bool mode1bit, bool format_if_mount_failed) + { + + if (sd_rdy) + return true; + +#if defined(ESP32) +#if defined(MBFS_CARD_TYPE_SD_MMC) + + sd_config.sdMMCConfig.mountpoint = mountpoint; + sd_config.sdMMCConfig.mode1bit = mode1bit; + sd_config.sdMMCConfig.format_if_mount_failed = format_if_mount_failed; + + sd_rdy = MBFS_SD_FS.begin(mountpoint, mode1bit, format_if_mount_failed); + return sd_rdy; +#endif +#endif + return false; + } + + // Check the mounting status of Flash storage. + bool flashReady() + { +#if defined MBFS_FLASH_FS + + if (flash_rdy) + return true; + +#if defined(ESP32) + +#if defined(MBFS_FORMAT_FLASH) + flash_rdy = MBFS_FLASH_FS.begin(true); +#else + flash_rdy = MBFS_FLASH_FS.begin(); +#endif + +#elif defined(ESP8266) || defined(MB_ARDUINO_PICO) + flash_rdy = MBFS_FLASH_FS.begin(); +#endif + +#endif + + return flash_rdy; + } + + // Check the mounting status of SD storage. + bool sdReady() + { + +#if defined(MBFS_SD_FS) + + if (sd_rdy) + return true; + +#if defined(ESP32) + +#if defined(MBFS_CARD_TYPE_SD) + + if (!sd_config.spiConfig) + { + if (sd_config.ss > -1) + SPI.begin(sd_config.sck, sd_config.miso, sd_config.mosi, sd_config.ss); + sd_config.spiConfig = &SPI; + } + +#if defined(MBFS_ESP32_SDFAT_ENABLED) || defined(MBFS_SDFAT_ENABLED) + + if (!sd_rdy) + { + if (sd_config.sdFatSPIConfig) + sd_rdy = MBFS_SD_FS.begin(*sd_config.sdFatSPIConfig); + else if (sd_config.sdFatSDIOConfig) + sd_rdy = MBFS_SD_FS.begin(*sd_config.sdFatSDIOConfig); + } + +#else + if (!sd_rdy) + sd_rdy = sdSPIBegin(sd_config.ss, sd_config.spiConfig, sd_config.frequency); + +#endif + +#elif defined(MBFS_CARD_TYPE_SD_MMC) + if (!sd_rdy) + sd_rdy = sdMMCBegin(sd_config.sdMMCConfig.mountpoint, sd_config.sdMMCConfig.mode1bit, sd_config.sdMMCConfig.format_if_mount_failed); +#endif + +#elif defined(ESP8266) || defined(MB_ARDUINO_PICO) + if (!sd_rdy) + { + if (sd_config.sdFSConfig) + sd_rdy = sdFatBegin(sd_config.sdFSConfig); + else + sd_rdy = sdBegin(sd_config.ss); + } + +#elif defined(ARDUINO_ARCH_SAMD) || defined(__AVR_ATmega4809__) || defined(ARDUINO_NANO_RP2040_CONNECT) + if (!sd_rdy) + sd_rdy = sdBegin(sd_config.ss); +#endif + +#endif + + return sd_rdy; + } + + // Check the mounting status of Flash or SD storage with mb_fs_mem_storage_type. + bool checkStorageReady(mbfs_file_type type) + { + +#if defined(MBFS_USE_FILE_STORAGE) + if (type == mbfs_flash) + { + if (!flash_rdy) + flashReady(); + return flash_rdy; + } + else if (type == mbfs_sd) + { + if (!sd_rdy) + sdReady(); + return sd_rdy; + } +#endif + + return false; + } + + // Open file for read or write with file name, mb_fs_mem_storage_type and mb_fs_open_mode. + // return size of file (read) or 0 (write) or negative value for error + int open(const MB_String &filename, mbfs_file_type type, mb_fs_open_mode mode) + { + +#if defined(MBFS_USE_FILE_STORAGE) + + if (!checkStorageReady(type)) + { + if (type == mbfs_flash) + return MB_FS_ERROR_FLASH_STORAGE_IS_NOT_READY; + else if (type == mbfs_sd) + return MB_FS_ERROR_SD_STORAGE_IS_NOT_READY; + else + return MB_FS_ERROR_FILE_IO_ERROR; + } + + if (mode == mb_fs_open_mode_read) + { + if (!existed(filename.c_str(), type)) + return MB_FS_ERROR_FILE_NOT_FOUND; + } + + int ret = openFile(filename, type, mode); + + if (ret < 0) + return ret; + + if (ready(type)) + return ret; + +#endif + return MB_FS_ERROR_FILE_IO_ERROR; + } + + // Check if file is already open. + bool ready(mbfs_file_type type) + { +#if defined(MBFS_FLASH_FS) + if (type == mbfs_flash && mb_flashFs) + return true; +#endif +#if defined(MBFS_SD_FS) + if (type == mbfs_sd && mb_sdFs) + return true; +#endif + return false; + } + + // Get file for read/write with file name, mb_fs_mem_storage_type and mb_fs_open_mode. + int size(mbfs_file_type type) + { + int size = 0; + +#if defined(MBFS_FLASH_FS) + if (type == mbfs_flash && mb_flashFs) + size = mb_flashFs.size(); +#endif +#if defined(MBFS_SD_FS) + if (type == mbfs_sd && mb_sdFs) + size = mb_sdFs.size(); +#endif + return size; + } + + // Check if file is ready to read/write. + int available(mbfs_file_type type) + { + int available = 0; + +#if defined(MBFS_FLASH_FS) + if (type == mbfs_flash && mb_flashFs) + available = mb_flashFs.available(); +#endif +#if defined(MBFS_SD_FS) + if (type == mbfs_sd && mb_sdFs) + available = mb_sdFs.available(); +#endif + return available; + } + + // Read byte array. Return the number of bytes that completed read or negative value for error. + int read(mbfs_file_type type, uint8_t *buf, size_t len) + { + int read = 0; +#if defined(MBFS_FLASH_FS) + if (type == mbfs_flash && mb_flashFs) + read = mb_flashFs.read(buf, len); +#endif +#if defined(MBFS_SD_FS) + if (type == mbfs_sd && mb_sdFs) + read = mb_sdFs.read(buf, len); +#endif + return read; + } + + // Print char array. Return the number of bytes that completed write or negative value for error. + int print(mbfs_file_type type, const char *str) + { + int write = 0; +#if defined(MBFS_FLASH_FS) + if (type == mbfs_flash && mb_flashFs) + write = mb_flashFs.print(str); +#endif +#if defined(MBFS_SD_FS) + + if (type == mbfs_sd && mb_sdFs) + write = mb_sdFs.print(str); +#endif + return write; + } + + // Print char array with new line. Return the number of bytes that completed write or negative value for error. + int println(mbfs_file_type type, const char *str) + { + int write = print(type, str); + if (write == (int)strlen(str)) + write += print(type, (const char *)MBSTRING_FLASH_MCR("\n")); + return write; + } + + // Print integer. Return the number of bytes that completed write or negative value for error. + int print(mbfs_file_type type, int v) + { + int write = 0; +#if defined(MBFS_FLASH_FS) + if (type == mbfs_flash && mb_flashFs) + write = mb_flashFs.print(v); +#endif +#if defined(MBFS_SD_FS) + + if (type == mbfs_sd && mb_sdFs) + write = mb_sdFs.print(v); +#endif + return write; + } + + // Print integer with newline. Return the number of bytes that completed write or negative value for error. + int println(mbfs_file_type type, int v) + { + int write = print(type, v); + if (write > 0) + write += print(type, (const char *)MBSTRING_FLASH_MCR("\n")); + return write; + } + + int print(mbfs_file_type type, unsigned int v) + { + int write = 0; +#if defined(MBFS_FLASH_FS) + if (type == mbfs_flash && mb_flashFs) + write = mb_flashFs.print(v); +#endif +#if defined(MBFS_SD_FS) + + if (type == mbfs_sd && mb_sdFs) + write = mb_sdFs.print(v); +#endif + return write; + } + + // Print integer with newline. Return the number of bytes that completed write or negative value for error. + int println(mbfs_file_type type, unsigned int v) + { + int write = print(type, v); + if (write > 0) + write += print(type, (const char *)MBSTRING_FLASH_MCR("\n")); + return write; + } + + // Write byte array. Return the number of bytes that completed write or negative value for error. + int write(mbfs_file_type type, uint8_t *buf, size_t len) + { + int write = 0; +#if defined(MBFS_FLASH_FS) + if (type == mbfs_flash && mb_flashFs) + write = mb_flashFs.write(buf, len); +#endif +#if defined(MBFS_SD_FS) + + if (type == mbfs_sd && mb_sdFs) + write = mb_sdFs.write(buf, len); +#endif + return write; + } + + // Close file. + void close(mbfs_file_type type) + { + +#if defined(MBFS_FLASH_FS) + if (type == mbfs_flash && mb_flashFs && flash_opened) + { + mb_flashFs.close(); + flash_filename_crc = 0; + flash_opened = false; + flash_open_mode = mb_fs_open_mode_undefined; + } +#endif + +#if defined(MBFS_SD_FS) + if (type == mbfs_sd && mb_sdFs && sd_opened) + { + mb_sdFs.close(); + sd_filename_crc = 0; + sd_opened = false; + sd_open_mode = mb_fs_open_mode_undefined; + } +#endif + } + + // Check file existence. + bool existed(const MB_String &filename, mbfs_file_type type) + { + + if (!checkStorageReady(type)) + return false; + +#if defined(MBFS_FLASH_FS) + if (type == mbfs_flash) + { + +// The workaround for ESP32 LittleFS when calling vfs_api.cpp open() issue. +// See https://github.com/espressif/arduino-esp32/issues/7615 +#if defined(MB_FS_USE_POSIX_STAT) + return mb_fs_ns::exists("/littlefs", filename.c_str()); +#else + return MBFS_FLASH_FS.exists(filename.c_str()); +#endif + } + +#endif + +#if defined(MBFS_SD_FS) + if (type == mbfs_sd) + { +#if defined(MBFS_ESP32_SDFAT_ENABLED) || defined(MBFS_SDFAT_ENABLED) + MBFS_SD_FILE file; + bool ret = file.open(filename.c_str(), O_RDONLY); + file.close(); + return ret; +#else + return MBFS_SD_FS.exists(filename.c_str()); +#endif + } +#endif + + return false; + } + + // Seek to position in file. + bool seek(mbfs_file_type type, int pos) + { + +#if defined(MBFS_FLASH_FS) + if (type == mbfs_flash && mb_flashFs) + return mb_flashFs.seek(pos); +#endif +#if defined(MBFS_SD_FS) + if (type == mbfs_sd && mb_sdFs) + return mb_sdFs.seek(pos); +#endif + + return false; + } + + // Read byte. Return the 1 for completed read or negative value for error. + int read(mbfs_file_type type) + { +#if defined(MBFS_FLASH_FS) + if (type == mbfs_flash && mb_flashFs) + return mb_flashFs.read(); +#endif +#if defined(MBFS_SD_FS) + if (type == mbfs_sd && mb_sdFs) + return mb_sdFs.read(); +#endif + return -1; + } + + // Write byte. Return the 1 for completed write or negative value for error. + int write(mbfs_file_type type, uint8_t v) + { +#if defined(MBFS_FLASH_FS) + if (type == mbfs_flash && mb_flashFs) + return mb_flashFs.write(v); +#endif +#if defined(MBFS_SD_FS) + if (type == mbfs_sd && mb_sdFs) + return mb_sdFs.write(v); +#endif + return -1; + } + + bool remove(const MB_String &filename, mbfs_file_type type) + { + if (!checkStorageReady(type)) + return false; + +#if defined(MBFS_FLASH_FS) + if (type == mbfs_flash && !flashReady()) + return false; +#endif + +#if defined(MBFS_SD_FS) + if (type == mbfs_sd && !sdReady()) + return false; +#endif + + if (!existed(filename, type)) + return true; + +#if defined(MBFS_FLASH_FS) + if (type == mbfs_flash) + return MBFS_FLASH_FS.remove(filename.c_str()); +#endif +#if defined(MBFS_SD_FS) + if (type == mbfs_sd) + { +#if defined(MBFS_ESP32_SDFAT_ENABLED) || defined(MBFS_SDFAT_ENABLED) + if (mb_sdFs.open(filename.c_str(), O_RDWR | O_CREAT | O_APPEND)) + { + mb_sdFs.remove(); + mb_sdFs.close(); + return true; + } +#else + return MBFS_SD_FS.remove(filename.c_str()); +#endif + } + +#endif + return false; + } + +// Get the Flash file instance. +#if defined(MBFS_FLASH_FS) + fs::File &getFlashFile() + { + return mb_flashFs; + } +#endif + +// Get the SD file instance. +#if defined(MBFS_SD_FS) + MBFS_SD_FILE &getSDFile() + { + return mb_sdFs; + } +#endif + + // Get name of opened file. + const char *name(mbfs_file_type type) + { +#if defined(MBFS_FLASH_FS) + if (type == mbfs_flash && mb_flashFs) + return flash_file.c_str(); +#endif +#if defined(MBFS_SD_FS) + if (type == mbfs_sd && mb_sdFs) + return sd_file.c_str(); +#endif + + return ""; + } + + // Calculate CRC16 of byte array. + uint16_t calCRC(const char *buf) + { + uint8_t x; + uint16_t crc = 0xFFFF; + + int length = (int)strlen(buf); + + while (length--) + { + x = crc >> 8 ^ *buf++; + x ^= x >> 4; + crc = (crc << 8) ^ ((uint16_t)(x << 12)) ^ ((uint16_t)(x << 5)) ^ ((uint16_t)x); + } + return crc; + } + + // Free reserved memory at pointer. + void delP(void *ptr) + { + void **p = (void **)ptr; + if (*p) + { + free(*p); + *p = 0; + } + } + + // Allocate memory + void *newP(size_t len, bool clear = true) + { + void *p; + size_t newLen = getReservedLen(len); +#if defined(BOARD_HAS_PSRAM) && defined(MB_STRING_USE_PSRAM) + + if (ESP.getPsramSize() > 0) + p = (void *)ps_malloc(newLen); + else + p = (void *)malloc(newLen); + + if (!p) + return NULL; + +#else + +#if defined(ESP8266_USE_EXTERNAL_HEAP) + ESP.setExternalHeap(); +#endif + + p = (void *)malloc(newLen); + bool nn = p ? true : false; + +#if defined(ESP8266_USE_EXTERNAL_HEAP) + ESP.resetHeap(); +#endif + + if (!nn) + return NULL; + +#endif + if (clear) + memset(p, 0, newLen); + return p; + } + + size_t getReservedLen(size_t len) + { + int blen = len + 1; + + int newlen = (blen / 4) * 4; + + if (newlen < blen) + newlen += 4; + + return (size_t)newlen; + } + + void createDirs(MB_String dirs, mbfs_file_type type) + { + if (!longNameSupported()) + return; + + MB_String dir; + int count = 0; + int lastPos = 0; + for (size_t i = 0; i < dirs.length(); i++) + { + dir.append(1, dirs[i]); + count++; + if (dirs[i] == '/' && i > 0) + { + if (dir.length() > 0) + { + + lastPos = dir.length() - 1; + +#if defined(MBFS_FLASH_FS) + if (type == mbfs_flash) + MBFS_FLASH_FS.mkdir(dir.substr(0, dir.length() - 1).c_str()); +#endif + +#if defined(MBFS_SD_FS) + if (type == mbfs_sd) + MBFS_SD_FS.mkdir(dir.substr(0, dir.length() - 1).c_str()); +#endif + } + count = 0; + } + } + + if (count > 0) + { + if (dir.find('.', lastPos) == MB_String::npos) + { +#if defined(MBFS_FLASH_FS) + if (type == mbfs_flash) + MBFS_FLASH_FS.mkdir(dir.c_str()); +#endif + +#if defined(MBFS_SD_FS) + if (type == mbfs_sd) + MBFS_SD_FS.mkdir(dir.c_str()); +#endif + } + } + + dir.clear(); + } + + bool longNameSupported() + { + +#if defined(MBFS_SDFAT_ENABLED) || defined(MBFS_FLASH_FS) + return true; +#endif + +#if defined(MBFS_SD_FS) && (defined(ESP32) || defined(ESP8266) || defined(MB_ARDUINO_PICO)) + return true; +#endif + + return false; + } + +private: + uint16_t flash_filename_crc = 0; + uint16_t sd_filename_crc = 0; + MB_String flash_file, sd_file; + mb_fs_open_mode flash_open_mode = mb_fs_open_mode_undefined; + mb_fs_open_mode sd_open_mode = mb_fs_open_mode_undefined; + bool flash_opened = false; + bool sd_opened = false; + bool sd_rdy = false; + bool flash_rdy = false; + uint16_t loopCount = 0; + +#if defined(MBFS_FLASH_FS) + fs::File mb_flashFs; +#endif +#if defined(MBFS_SD_FS) + MBFS_SD_FILE mb_sdFs; +#endif + + int openFile(const MB_String &filename, mb_fs_mem_storage_type type, mb_fs_open_mode mode) + { + +#if defined(MBFS_FLASH_FS) + if (type == mbfs_flash) + return openFlashFile(filename, mode); +#endif +#if defined(MBFS_SD_FS) + if (type == mbfs_sd) + return openSDFile(filename, mode); +#endif + return MB_FS_ERROR_FILE_IO_ERROR; + } + + int openSDFile(const MB_String &filename, mb_fs_open_mode mode) + { + int ret = MB_FS_ERROR_FILE_IO_ERROR; + +#if defined(MBFS_SD_FS) + + if (mode == mb_fs_open_mode_read || mode == mb_fs_open_mode_write || mode == mb_fs_open_mode_append) + { + uint16_t crc = calCRC(filename.c_str()); + + if (mode == sd_open_mode && flash_filename_crc == crc && sd_opened) // same sd file opened, leave it + return MB_FS_ERROR_FILE_STILL_OPENED; + + if (sd_opened) + close(mbfs_sd); // sd file opened, close it + + flash_filename_crc = crc; + } + +#if defined(MBFS_ESP32_SDFAT_ENABLED) || defined(MBFS_SDFAT_ENABLED) + + if (mode == mb_fs_open_mode_read) + { + if (mb_sdFs.open(filename.c_str(), O_RDONLY)) + { + sd_file = filename; + sd_opened = true; + sd_open_mode = mode; + ret = mb_sdFs.size(); + } + } + else if (mode == mb_fs_open_mode_write || mode == mb_fs_open_mode_append) + { + if (mode == mb_fs_open_mode_write) + remove(filename, mb_fs_mem_storage_type_sd); + + createDirs(filename, mb_fs_mem_storage_type_sd); + if (mb_sdFs.open(filename.c_str(), O_RDWR | O_CREAT | O_APPEND)) + { + sd_file = filename; + sd_opened = true; + sd_open_mode = mode; + ret = 0; + } + } + +#else + + if (mode == mb_fs_open_mode_read) + { +#if defined(ESP32) || defined(ESP8266) + mb_sdFs = MBFS_SD_FS.open(filename.c_str(), FILE_READ); +#else + mb_sdFs = MBFS_SD_FS.open(filename.c_str(), "r"); +#endif + if (mb_sdFs) + { + sd_file = filename; + sd_opened = true; + sd_open_mode = mode; + ret = mb_sdFs.size(); + } + } + else if (mode == mb_fs_open_mode_write || mode == mb_fs_open_mode_append) + { + if (mode == mb_fs_open_mode_write) + remove(filename, mb_fs_mem_storage_type_sd); + + createDirs(filename, mb_fs_mem_storage_type_sd); +#if defined(ESP32) + if (mode == mb_fs_open_mode_write) + mb_sdFs = MBFS_SD_FS.open(filename.c_str(), FILE_WRITE); + else + mb_sdFs = MBFS_SD_FS.open(filename.c_str(), FILE_APPEND); +#elif defined(ESP8266) + mb_sdFs = MBFS_SD_FS.open(filename.c_str(), FILE_WRITE); +#else + if (mode == mb_fs_open_mode_write) + mb_sdFs = MBFS_SD_FS.open(filename.c_str(), "w"); + else + mb_sdFs = MBFS_SD_FS.open(filename.c_str(), "a"); +#endif + + if (mb_sdFs) + { + sd_file = filename; + sd_opened = true; + sd_open_mode = mode; + ret = 0; + } + } +#endif + +#endif + return ret; + } + + int openFlashFile(const MB_String &filename, mb_fs_open_mode mode) + { + int ret = MB_FS_ERROR_FILE_IO_ERROR; + +#if defined(MBFS_FLASH_FS) + + if (mode == mb_fs_open_mode_read || mode == mb_fs_open_mode_write || mode == mb_fs_open_mode_append) + { + uint16_t crc = calCRC(filename.c_str()); + if (mode == flash_open_mode && sd_filename_crc == crc && flash_opened) // same flash file opened, leave it + return MB_FS_ERROR_FILE_STILL_OPENED; + + if (flash_opened) + close(mbfs_flash); // flash file opened, close it + + sd_filename_crc = crc; + } + + if (mode == mb_fs_open_mode_read) + { + mb_flashFs = MBFS_FLASH_FS.open(filename.c_str(), "r"); + if (mb_flashFs) + { + flash_file = filename; + flash_opened = true; + flash_open_mode = mode; + ret = mb_flashFs.size(); + } + } + else if (mode == mb_fs_open_mode_write || mode == mb_fs_open_mode_append) + { + if (mode == mb_fs_open_mode_write) + remove(filename, mb_fs_mem_storage_type_flash); + + createDirs(filename, mb_fs_mem_storage_type_flash); + if (mode == mb_fs_open_mode_write) + mb_flashFs = MBFS_FLASH_FS.open(filename.c_str(), "w"); + else + mb_flashFs = MBFS_FLASH_FS.open(filename.c_str(), "a"); + + if (mb_flashFs) + { + flash_file = filename; + flash_opened = true; + flash_open_mode = mode; + ret = 0; + } + } + +#endif + return ret; + } +}; + +#endif diff --git a/lib/libesp32/ESP-Mail-Client/src/extras/MB_FS_Interfaces.h b/lib/libesp32/ESP-Mail-Client/src/extras/MB_FS_Interfaces.h new file mode 100644 index 000000000..9bdc1e75d --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/extras/MB_FS_Interfaces.h @@ -0,0 +1,94 @@ +#pragma once + +/* Convert specific definitions to MB_FS definitions */ +#ifndef MB_FS_INTERFACES_H +#define MB_FS_INTERFACES_H + +#include + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + +// include definitions file +#include "./ESP_Mail_FS.h" + +// 1. ESP_MAIL_DEFAULT_FLASH_FS -> MBFS_FLASH_FS +#if defined ESP_MAIL_DEFAULT_FLASH_FS +#define MBFS_FLASH_FS ESP_MAIL_DEFAULT_FLASH_FS +#endif + +// 2. ESP_MAIL_DEFAULT_SD_FS -> MBFS_SD_FS +#if defined ESP_MAIL_DEFAULT_SD_FS +#define MBFS_SD_FS ESP_MAIL_DEFAULT_SD_FS +#endif + +// 3. ESP_MAIL_CARD_TYPE_SD -> MBFS_CARD_TYPE_SD +#if defined(ESP_MAIL_CARD_TYPE_SD) +#define MBFS_CARD_TYPE_SD /* */ ESP_MAIL_CARD_TYPE_SD +#endif + +// 4. ESP_MAIL_CARD_TYPE_SD_MMC -> MBFS_CARD_TYPE_SD_MMC +#if defined(ESP_MAIL_CARD_TYPE_SD_MMC) +#define MBFS_CARD_TYPE_SD_MMC /* */ ESP_MAIL_CARD_TYPE_SD_MMC +#endif + +// 5. ESP_MAIL_FORMAT_FLASH_IF_MOUNT_FAILED -> MBFS_FORMAT_FLASH +#if defined(ESP_MAIL_FORMAT_FLASH_IF_MOUNT_FAILED) +#define MBFS_FORMAT_FLASH /* */ ESP_MAIL_FORMAT_FLASH_IF_MOUNT_FAILED +#endif + +#if defined(MBFS_SD_FS) || defined(MBFS_FLASH_FS) +#define MBFS_USE_FILE_STORAGE +#endif + +// Only SdFat library from Bill Greiman +#if defined(ESP32) && defined(SD_FAT_VERSION) && defined(SD_FAT_VERSION_STR) && defined(MBFS_SD_FS) && defined(MBFS_CARD_TYPE_SD) +#define MBFS_ESP32_SDFAT_ENABLED +#ifndef ESP_MAIL_USE_SDFAT +#define ESP_MAIL_USE_SDFAT +#endif +#endif + +// Only SdFat library from Bill Greiman +#if !defined(ESP32) && !defined(ESP8266) && !defined(ARDUINO_ARCH_RP2040) && defined(SD_FAT_VERSION) && defined(SD_FAT_VERSION_STR) && defined(MBFS_SD_FS) && defined(MBFS_CARD_TYPE_SD) +#define MBFS_SDFAT_ENABLED +#ifndef ESP_MAIL_USE_SDFAT +#define ESP_MAIL_USE_SDFAT +#endif +#endif + +// For MB_String +#if defined(ESP_MAIL_USE_PSRAM) +#define MB_STRING_USE_PSRAM +#endif + +#if defined(MBFS_SD_FS) + +#if !defined(ESP_MAIL_SD_FILE) + +#if defined(MBFS_ESP32_SDFAT_ENABLED) +#define MBFS_SD_FILE SdFile +#else +#if defined(ESP32) || defined(ESP8266) || defined(ARDUINO_ARCH_RP2040) +#define MBFS_SD_FILE fs::File +#else +#define MBFS_SD_FILE File +#endif + +#endif + +#else + +#define MBFS_SD_FILE ESP_MAIL_SD_FILE + +#endif + +#endif + +#ifndef MB_STRING_INCLUDE_CLASS +#define MB_STRING_INCLUDE_CLASS "MB_String.h" +#endif + + + +#endif /* MB_FS_INTERFACES_H */ diff --git a/lib/libesp32/ESP-Mail-Client/src/extras/MB_MCU.h b/lib/libesp32/ESP-Mail-Client/src/extras/MB_MCU.h new file mode 100644 index 000000000..3009e67bb --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/extras/MB_MCU.h @@ -0,0 +1,67 @@ +#pragma once + +#ifndef MB_MCU_H +#define MB_MCU_H + + +#if defined(ESP8266) || defined(ESP32) +#ifndef MB_ARDUINO_ESP +#define MB_ARDUINO_ESP +#endif +#endif + +#if defined(__arm__) +#ifndef MB_ARDUINO_ARM +#define MB_ARDUINO_ARM +#endif +#endif + +// Renesas +#if defined(ARDUINO_PORTENTA_C33) + +#endif + +// Renesas +#if defined(ARDUINO_UNOWIFIR4) + +#endif + +// Renesas +#if defined(ARDUINO_MINIMA) + +#endif + +#if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_X8) + +#endif + + +#if defined(ARDUINO_ARCH_SAMD) +#ifndef MB_ARDUINO_ARCH_SAMD +#define MB_ARDUINO_ARCH_SAMD +#endif +#endif + +#if defined(ARDUINO_ARCH_RP2040) + +#if defined(ARDUINO_NANO_RP2040_CONNECT) +#ifndef MB_ARDUINO_NANO_RP2040_CONNECT +#define MB_ARDUINO_NANO_RP2040_CONNECT +#endif +#else +#ifndef MB_ARDUINO_PICO +#define MB_ARDUINO_PICO +#endif +#endif + +#endif + + +#if defined(TEENSYDUINO) +#ifndef MB_ARDUINO_TEENSY +#define MB_ARDUINO_TEENSY +#endif +#endif + + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/extras/MB_String.h b/lib/libesp32/ESP-Mail-Client/src/extras/MB_String.h new file mode 100644 index 000000000..775ade48d --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/extras/MB_String.h @@ -0,0 +1,2075 @@ + +/** + * Mobizt's SRAM/PSRAM supported String, version 1.2.9 + * + * Created December 3, 2022 + * + * Changes Log + * + * v1.2.9 + * - substring optimization + * + * v1.2.8 + * - Add support StringSumHelper class in Arduino + * + * v1.2.7 + * - Fix string sub type checking issue + * + * v1.2.6 + * - Update trim() function + * + * v1.2.5 + * - Fixed double string issue and add support long double + * + * v1.2.4 + * - Check PSRAM availability before allocating the memory + * + * v1.2.3 + * - Fixed flash string F and PSTR handle + * + * v1.2.2 + * - Add supports more MCUs. + * + * v1.2.1 + * - Add flash string manipulation functions. + * + * v1.2.0 + * - Add supports bool, integer and float manipulation. + * + * v1.1.2 + * - Fix substring with zero length returns the original string issue. + * + * v1.1.1 + * - Fix possible ESP8266 code exit without resetting the external heap stack + * + * v1.1.0 + * - Add support ESP8266 external virtual RAM (SRAM or PSRAM) + * + * v1.0.1 + * - Add trim function + * - Add version enum + * + * v1.0.0 + * - Initial release + * + * The MIT License (MIT) + * Copyright (c) 2023 K. Suwatchai (Mobizt) + * + * + * Permission is hereby granted, free of charge, to any person returning a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef MB_String_H +#define MB_String_H + +#include +#if !defined(__AVR__) +#include +#include +#include +#endif + +#define MB_STRING_MAJOR 1 +#define MB_STRING_MINOR 2 +#define MB_STRING_PATCH 5 + +#if defined(ESP8266) && defined(MMU_EXTERNAL_HEAP) && defined(MB_STRING_USE_PSRAM) +#include +#include +#define ESP8266_USE_EXTERNAL_HEAP +#endif + +#if defined(ESP8266) || defined(ESP32) +#define MBSTRING_FLASH_MCR FPSTR +#elif defined(ARDUINO_ARCH_SAMD) || defined(__AVR_ATmega4809__) || defined(ARDUINO_NANO_RP2040_CONNECT) +#define MBSTRING_FLASH_MCR PSTR +#else +#define MBSTRING_FLASH_MCR(s) (s) +#endif + +class MB_String; + +#define pgm2Str(p) (MB_String().appendP(p).c_str()) +#define num2Str(v, p) (MB_String().appendNum(v, p).c_str()) + +#if defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F4) +#define MB_IS_SAME std::is_same +#define MB_ENABLE_IF std::enable_if +#else +#define MB_IS_SAME is_same +#define MB_ENABLE_IF enable_if +#endif + +namespace mb_string +{ + enum mb_string_sub_type + { + mb_string_sub_type_none, + mb_string_sub_type_bool, + mb_string_sub_type_float, + mb_string_sub_type_double, + mb_string_sub_type_int8, + mb_string_sub_type_uint8, + mb_string_sub_type_int16, + mb_string_sub_type_uint16, + mb_string_sub_type_int32, + mb_string_sub_type_uint32, + mb_string_sub_type_int64, + mb_string_sub_type_uint64, + mb_string_sub_type_cstring, + mb_string_sub_type_chars, + mb_string_sub_type_mb_string, + mb_string_sub_type_arduino_string, + mb_string_sub_type_std_string, + mb_string_sub_type_fptr, + mb_string_sub_type_string_sum_helper + + }; + + typedef struct mb_string_ptr_t + { + + public: + mb_string_ptr_t(uint32_t addr = 0, mb_string_sub_type type = mb_string_sub_type_cstring, int precision = -1, const StringSumHelper *s = nullptr) + { + _addr = addr; + _type = type; + _precision = precision; + _ssh = s; + } + int precision() { return _precision; } + mb_string_sub_type type() { return _type; } + uint32_t address() { return _addr; } + const StringSumHelper *stringsumhelper() { return _ssh; } + + private: + mb_string_sub_type _type = mb_string_sub_type_none; + int _precision = -1; + uint32_t _addr = 0; + const StringSumHelper *_ssh = nullptr; + + } MB_StringPtr; + + template + struct enable_if + { + }; + template + struct enable_if + { + typedef T type; + }; + template + struct is_same + { + static bool const value = false; + }; + template + struct is_same + { + static bool const value = true; + }; + + template + struct is_num_int8 + { + static bool const value = MB_IS_SAME::value || MB_IS_SAME::value; + }; + + template + struct is_num_uint8 + { + static bool const value = MB_IS_SAME::value || MB_IS_SAME::value; + }; + + template + struct is_num_int16 + { + static bool const value = MB_IS_SAME::value || MB_IS_SAME::value; + }; + + template + struct is_num_uint16 + { + static bool const value = MB_IS_SAME::value || MB_IS_SAME::value; + }; + + template + struct is_num_int32 + { + static bool const value = MB_IS_SAME::value || MB_IS_SAME::value || + MB_IS_SAME::value || MB_IS_SAME::value || + MB_IS_SAME::value; + }; + + template + struct is_num_uint32 + { + static bool const value = MB_IS_SAME::value || MB_IS_SAME::value || + MB_IS_SAME::value; + }; + + template + struct is_num_int64 + { + static bool const value = MB_IS_SAME::value || MB_IS_SAME::value; + }; + + template + struct is_num_uint64 + { + static bool const value = MB_IS_SAME::value || MB_IS_SAME::value; + }; + + template + struct is_num_neg_int + { + static bool const value = is_num_int8::value || is_num_int16::value || + is_num_int32::value || is_num_int64::value; + }; + + template + struct is_num_pos_int + { + static bool const value = is_num_uint8::value || is_num_uint16::value || + is_num_uint32::value || is_num_uint64::value; + }; + + template + struct is_num_int + { + static bool const value = is_num_pos_int::value || is_num_neg_int::value; + }; + + template + struct is_num_float + { + static bool const value = MB_IS_SAME::value || MB_IS_SAME::value || MB_IS_SAME::value; + }; + + template + struct is_bool + { + static bool const value = MB_IS_SAME::value; + }; + + template + struct cs_t + { + static bool const value = MB_IS_SAME::value; + }; + + template + struct ccs_t + { + static bool const value = MB_IS_SAME::value; + }; + + template + struct as_t + { + static bool const value = MB_IS_SAME::value; + }; + + template + struct cas_t + { + static bool const value = MB_IS_SAME::value; + }; + + template + struct ss_t + { +#if !defined(__AVR__) + static bool const value = MB_IS_SAME::value; +#else + static bool const value = false; +#endif + }; + + template + struct css_t + { +#if !defined(__AVR__) + static bool const value = MB_IS_SAME::value; +#else + static bool const value = false; +#endif + }; + + template + struct ssh_t + { + static bool const value = MB_IS_SAME::value; + }; + + template + struct fs_t + { + static bool const value = MB_IS_SAME::value; + }; + + template + struct mbs_t + { + static bool const value = MB_IS_SAME::value; + }; + + template + struct cmbs_t + { + static bool const value = MB_IS_SAME::value; + }; + + template + struct pgm_t + { + static bool const value = MB_IS_SAME::value; + }; + + template + struct is_const_chars + { + static bool const value = cs_t::value || ccs_t::value; + }; + + template + struct is_arduino_string + { + static bool const value = as_t::value || cas_t::value; + }; + + template + struct is_std_string + { + static bool const value = ss_t::value || css_t::value; + }; + + template + struct is_mb_string + { + static bool const value = mbs_t::value || cmbs_t::value; + }; + + template + struct is_arduino_string_sum_helper + { + static bool const value = ssh_t::value; + }; + + template + struct is_arduino_flash_string_helper + { + static bool const value = fs_t::value; + }; + + template + struct is_string + { + static bool const value = is_const_chars::value || is_arduino_string::value || + is_arduino_string_sum_helper::value || is_arduino_flash_string_helper::value || + is_std_string::value || is_mb_string::value; + }; + + template + uint32_t toAddr(T &v) { return reinterpret_cast(&v); } + +#if defined(__AVR__) + template + T addrTo(int address) + { + return reinterpret_cast(address); + } +#else + template + auto addrTo(int address) -> typename MB_ENABLE_IF::value, T>::type + { + return reinterpret_cast(address); + } +#endif + + template + auto getSubType(T val) -> typename MB_ENABLE_IF::value || is_num_float::value || MB_IS_SAME::value || is_const_chars::value || is_arduino_flash_string_helper::value || is_arduino_string::value || is_std_string::value || is_mb_string::value || MB_IS_SAME::value, mb_string_sub_type>::type + { + if (is_num_uint64::value) + return mb_string_sub_type_uint64; + else if (is_num_int64::value) + return mb_string_sub_type_int64; + else if (is_num_uint32::value) + return mb_string_sub_type_uint32; + else if (is_num_int32::value) + return mb_string_sub_type_int32; + else if (is_num_uint16::value) + return mb_string_sub_type_uint16; + else if (is_num_int16::value) + return mb_string_sub_type_int16; + else if (is_num_uint8::value) + return mb_string_sub_type_uint8; + else if (is_num_int8::value) + return mb_string_sub_type_int8; + else if (MB_IS_SAME::value) + return mb_string_sub_type_bool; + else if (MB_IS_SAME::value) + return mb_string_sub_type_float; + else if (MB_IS_SAME::value) + return mb_string_sub_type_double; + else if (is_arduino_string::value) + return mb_string_sub_type_arduino_string; + else if (is_std_string::value) + return mb_string_sub_type_std_string; + else if (is_mb_string::value) + return mb_string_sub_type_mb_string; + else if (is_arduino_flash_string_helper::value) + return mb_string_sub_type_fptr; + else if (MB_IS_SAME::value) + return mb_string_sub_type_string_sum_helper; + else if (ccs_t::value) + return mb_string_sub_type_cstring; + else if (cs_t::value) + return mb_string_sub_type_chars; + + return mb_string_sub_type_int8; + } + + template + auto getSubType(T *val) -> typename MB_ENABLE_IF::value || is_num_float::value || MB_IS_SAME::value || is_const_chars::value || is_arduino_flash_string_helper::value || is_arduino_string::value || is_std_string::value || is_mb_string::value || MB_IS_SAME::value, mb_string_sub_type>::type + { + return getSubType(*val); + } + + template + auto toStringPtr(const T &val) -> typename MB_ENABLE_IF::value || is_arduino_string::value || is_mb_string::value, MB_StringPtr>::type + { + return MB_StringPtr(reinterpret_cast(&val), getSubType(val)); + } + + template + auto toStringPtr(const T &val) -> typename MB_ENABLE_IF::value, MB_StringPtr>::type + { +#if defined(ESP8266) + return MB_StringPtr(reinterpret_cast(&val), getSubType(val), -1); + +#else + return MB_StringPtr(reinterpret_cast(&val), getSubType(val), -1, &val); +#endif + } + + template + auto toStringPtr(T val) -> typename MB_ENABLE_IF::value, MB_StringPtr>::type { return MB_StringPtr(reinterpret_cast(val), getSubType(val)); } + + template + auto toStringPtr(T &val) -> typename MB_ENABLE_IF::value, MB_StringPtr>::type { return MB_StringPtr(reinterpret_cast(val), getSubType(val)); } + +#if !defined(__AVR__) + template + auto toStringPtr(T val) -> typename MB_ENABLE_IF::value, MB_StringPtr>::type + { + return MB_StringPtr(); + } +#endif + + template + auto toStringPtr(T val) -> typename MB_ENABLE_IF::value, MB_StringPtr>::type + { + return val; + } + + template + auto toStringPtr(T &val, int precision = -1) -> typename MB_ENABLE_IF::value || is_num_float::value || MB_IS_SAME::value, MB_StringPtr>::type { return MB_StringPtr(reinterpret_cast(&val), getSubType(val), precision); } +} + +using namespace mb_string; + +class MB_String +{ +public: + MB_String() + { +#if defined(ESP8266_USE_EXTERNAL_HEAP) + // reserve default 1 byte external heap to refer to its pointer later + reset(1); +#endif + }; + + ~MB_String() + { + allocate(0, false); + }; + + MB_String(const char *cstr) + { + if (cstr) + copy(cstr, strlen_P(cstr)); + } + + MB_String(const MB_String &value) + { + *this = value; + } + + MB_String(const __FlashStringHelper *str) + { + *this = str; + } + +#if !defined(ESP8266) + MB_String(StringSumHelper rval) + { + *this = rval; + } +#endif + + MB_String(MB_StringPtr value) + { + *this = value; + } + + MB_String(String value) + { + *this = value; + } + + MB_String(bool value) + { + appendNum(value); + } + + MB_String(unsigned char value, unsigned char base = 10) + { + int len = 1 + 8 * sizeof(unsigned char); + reserve(len); + + if (bufLen > 0) + utoa(value, buf, base); + } + + MB_String(int value, unsigned char base = 10) + { + int len = 2 + 8 * sizeof(int); + reserve(len); + + if (bufLen > 0) + { + if (base == 10) + sprintf(buf, (const char *)MBSTRING_FLASH_MCR("%d"), value); + else + itoa(value, buf, base); + } + } + + MB_String(unsigned int value, unsigned char base = 10) + { + int len = 1 + 8 * sizeof(unsigned int); + reserve(len); + + if (bufLen > 0) + utoa(value, buf, base); + } + + MB_String(long value, unsigned char base = 10) + { + int len = 2 + 8 * sizeof(long); + reserve(len); + + if (bufLen > 0) + { + if (base == 10) + sprintf(buf, (const char *)MBSTRING_FLASH_MCR("%ld"), value); + else + ltoa(value, buf, base); + } + } + + MB_String(unsigned long value, unsigned char base = 10) + { + int len = 1 + 8 * sizeof(unsigned long); + reserve(len); + + if (bufLen > 0) + ultoa(value, buf, base); + } + + MB_String(float value, unsigned char decimalPlaces = 2) + { + reserve(33); + if (bufLen > 0) + { + char *v = toFloatStr(value, 0, decimalPlaces); + if (v) + { + strcpy(buf, v); + delP(&v); + } + } + } + + MB_String(double value, unsigned char decimalPlaces = 3) + { + reserve(33); + + if (bufLen > 0) + { + char *v = toFloatStr(value, 1, decimalPlaces); + if (v) + { + strcpy(buf, v); + delP(&v); + } + } + } + + MB_String(long double value, unsigned char decimalPlaces = 3) + { + reserve(65); + if (bufLen > 0) + { + char *v = toFloatStr(value, 2, decimalPlaces); + if (v) + { + strcpy(buf, v); + delP(&v); + } + } + } + +#if !defined(__AVR__) + MB_String &operator=(const std::string &rhs) + { + if (rhs.length() > 0) + copy(rhs.c_str(), rhs.length()); + else + clear(); + + return *this; + } +#endif + MB_String &operator=(const String &rhs) + { + + if (rhs.length() > 0) + copy(rhs.c_str(), rhs.length()); + else + clear(); + + return *this; + } + + MB_String &operator=(const __FlashStringHelper *str) + { + if (str) + appendF(str, true); + + return *this; + } + +#if !defined(ESP8266) + MB_String &operator=(StringSumHelper rval) + { + String temp = rval; + *this = temp; + return *this; + } + + MB_String &operator+=(StringSumHelper rval) + { + String temp = rval; + *this += temp; + return *this; + } +#endif + + MB_String &operator+=(const __FlashStringHelper *str) + { + if (str) + appendF(str); + + return *this; + } + + unsigned char operator==(const MB_String &rhs) const + { + return equals(rhs); + } + + unsigned char operator==(const char *cstr) const + { + return equals(cstr); + } + + unsigned char operator!=(const MB_String &rhs) const + { + return !equals(rhs); + } + + unsigned char operator!=(const char *cstr) const + { + return !equals(cstr); + } +#if !defined(__AVR__) + MB_String &operator+=(const std::string &rhs) + { + concat(rhs.c_str()); + return (*this); + } +#endif + MB_String &operator+=(const String &rhs) + { + concat(rhs.c_str()); + return (*this); + } + + MB_String &operator=(const MB_String &rhs) + { + if (this == &rhs) + return *this; + + if (rhs.length() > 0) + copy(rhs.buf, rhs.length()); + else + clear(); + + return *this; + } + + MB_String &operator+=(const MB_String &rhs) + { + concat(rhs); + return (*this); + } + + MB_String &operator+=(const char *cstr) + { + size_t len = strlen_P(cstr); + size_t slen = length(); + + if (_reserve(slen + len, false)) + { + strcat_P(buf, (PGM_P)cstr); + *(buf + slen + len) = '\0'; + } + + return (*this); + } + + MB_String &operator+=(char cstr) + { + append(1, cstr); + return (*this); + } + + MB_String &operator+=(bool value) + { + appendNum(value); + return (*this); + } + + MB_String &operator=(MB_StringPtr ptr) + { + setPtr(ptr); + return (*this); + } + + MB_String &operator+=(MB_StringPtr ptr) + { + appendPtr(ptr); + return (*this); + } + + template + auto operator=(T value) -> typename MB_ENABLE_IF::value || is_num_float::value || is_bool::value, MB_String &>::type + { + clear(); + appendNum(value); + return (*this); + } + + template + auto operator+=(T value) -> typename MB_ENABLE_IF::value || is_num_float::value || is_bool::value, MB_String &>::type + { + appendNum(value); + return (*this); + } + + MB_String &appendP(PGM_P pgms, bool clear = false) + { + if (clear) + this->clear(); + + char *t = pgmStr(pgms); + if (t) + { + *this += t; + delP(&t); + } + + return (*this); + } + + MB_String &appendF(const __FlashStringHelper *pstr, bool clear = false) + { + if (clear) + this->clear(); + + int len = strlen_P((PGM_P)pstr); + if (len > 0) + { + unsigned int newlen = length() + len; + reserve(newlen); + + if (bufLen > 0) + memcpy_P(buf + length(), (PGM_P)pstr, len + 1); + } + + return (*this); + } + + MB_String &setPtr(MB_StringPtr src) + { + clear(); + appendPtr(src); + return (*this); + }; + + MB_String &appendPtr(MB_StringPtr src) + { + if (src.type() == mb_string_sub_type_fptr) + appendF(addrTo(src.address())); + else if (src.type() == mb_string_sub_type_cstring || src.type() == mb_string_sub_type_chars) + *this += addrTo(src.address()); + else if (src.type() == mb_string_sub_type_arduino_string) + *this += *addrTo(src.address()); + else if (src.type() == mb_string_sub_type_string_sum_helper) +#if !defined(ESP8266) + *this += *src.stringsumhelper(); +#else + *this += *addrTo(src.address()); +#endif +#if !defined(__AVR__) + else if (src.type() == mb_string_sub_type_std_string) + *this += *addrTo(src.address()); +#endif + else if (src.type() == mb_string_sub_type_mb_string) + *this += *addrTo(src.address()); + else if (src.type() == mb_string_sub_type_uint64) + appendNum(*addrTo(src.address())); + else if (src.type() == mb_string_sub_type_int64) + appendNum(*addrTo(src.address())); + else if (src.type() == mb_string_sub_type_uint32) + appendNum(*addrTo(src.address())); + else if (src.type() == mb_string_sub_type_int32) + appendNum(*addrTo(src.address())); + else if (src.type() == mb_string_sub_type_uint16) + appendNum(*addrTo(src.address())); + else if (src.type() == mb_string_sub_type_int16) + appendNum(*addrTo(src.address())); + else if (src.type() == mb_string_sub_type_uint8) + appendNum(*addrTo(src.address())); + else if (src.type() == mb_string_sub_type_int8) + appendNum(*addrTo(src.address())); + else if (src.type() == mb_string_sub_type_bool) + appendNum(*addrTo(src.address())); + else if (src.type() == mb_string_sub_type_float) + appendNum(*addrTo(src.address()), src.precision()); + else if (src.type() == mb_string_sub_type_double) + appendNum(*addrTo(src.address()), src.precision()); + + return (*this); + }; + + template + auto appendNum(T value, int precision = 0) -> typename MB_ENABLE_IF::value || is_bool::value, MB_String &>::type + { + char *s = NULL; + + if (is_bool::value) + s = boolStr(value); + else if (is_num_neg_int::value) + { +#if defined(ARDUINO_ARCH_SAMD) || defined(__AVR_ATmega4809__) || defined(ARDUINO_NANO_RP2040_CONNECT) + s = int32Str(value); +#else + s = int64Str(value); +#endif + } + else if (is_num_pos_int::value) + { +#if defined(ARDUINO_ARCH_SAMD) || defined(__AVR_ATmega4809__) || defined(ARDUINO_NANO_RP2040_CONNECT) + s = uint32Str(value); +#else + s = uint64Str(value); +#endif + } + + if (s) + { + *this += s; + delP(&s); + } + + return (*this); + } + + MB_String &appendNum(float value, int precision = 5) + { + if (precision < 0) + precision = 5; + + char *s = toFloatStr(value, 0, precision); + if (s) + { + *this += s; + delP(&s); + } + return (*this); + } + + MB_String &appendNum(double value, int precision = 9) + { + if (precision < 0) + precision = 9; + + char *s = toFloatStr(value, 1, precision); + if (s) + { + *this += s; + delP(&s); + } + return (*this); + } + + MB_String &appendNum(long double value, int precision = 9) + { + if (precision < 0) + precision = 9; + + char *s = toFloatStr(value, 2, precision); + if (s) + { + *this += s; + delP(&s); + } + return (*this); + } + + MB_String &operator=(const char *cstr) + { + if (cstr) + copy(cstr, strlen_P(cstr)); + else + clear(); + + return *this; + } + + MB_String &operator=(char c) + { + clear(); + if (_reserve(1, false)) + { + *(buf) = c; + *(buf + 1) = '\0'; + } + + return *this; + } + + void trim() + { + int p1 = 0, p2 = length() - 1; + while (p1 < (int)length()) + { + if (buf[p1] > 32) + break; + p1++; + } + + while (p2 >= 0) + { + if (buf[p2] > 32) + break; + p2--; + } + + if (p1 == (int)length() && p2 < 0) + { + clear(); + return; + } + + if (p2 >= p1 && p2 >= 0 && p1 < (int)length()) + { + memmove(buf, buf + p1, p2 - p1 + 1); + buf[p2 - p1 + 1] = '\0'; + _reserve(p2 - p1 + 1, true); + } + } + + void append(const char *cstr, size_t n) + { + if (!cstr) + return; + + size_t slen = length(); + + if (n > strlen(cstr)) + n = strlen(cstr); + + if (_reserve(slen + n, false)) + { + memmove(buf + slen, cstr, n); + *(buf + slen + n) = '\0'; + } + } + + void append(size_t n, char c) + { + size_t slen = length(); + + if (_reserve(slen + n, false)) + { + for (size_t i = 0; i < n; i++) + *(buf + slen + i) = c; + *(buf + slen + n) = '\0'; + } + } + + void prepend(char c) + { + size_t slen = length(); + size_t len = 1; + + if (maxLength() < slen + len) + _reserve(slen + len, false); + + memmove(buf + len, buf, slen); + buf[0] = c; + buf[len + slen] = '\0'; + } + + void prepend(const char *cstr) + { + size_t slen = length(); + size_t len = strlen(cstr); + + if (maxLength() < slen + len) + _reserve(slen + len, false); + + memmove(buf + len, buf, slen); + memmove(buf, cstr, len); + buf[len + slen] = '\0'; + } + + const char *c_str() const + { + if (!buf) + return ""; + return (const char *)buf; + } + + char operator[](size_t index) const + { + if (index >= bufLen || !buf) + return 0; + return buf[index]; + } + + char &operator[](size_t index) + { + static char c; + if (index >= bufLen || !buf) + { + c = '\0'; + return c; + } + return buf[index]; + } + + void swap(MB_String &rhs) + { + rhs.clear(); + } + + void shrink_to_fit() + { + size_t slen = length(); + _reserve(slen, true); + } + + void pop_back() + { + if (length() > 0) + { + size_t slen = length(); + if (slen > 0) + buf[slen - 1] = '\0'; + _reserve(slen, true); + } + } + + size_t size() const + { + return length(); + } + + size_t bufferLength() const + { + return bufLen; + } + + size_t find(const MB_String &s, size_t index = 0) const + { + if (!s.buf) + return -1; + return strpos(buf, s.buf, index); + } + + size_t find(const char *s, size_t index = 0) const + { + return strpos(buf, s, index); + } + + size_t find(char c, size_t index = 0) const + { + return strpos(buf, c, index); + } + + size_t rfind(const char *s, size_t index = npos) const + { + return rstrpos(buf, s, index); + } + + size_t rfind(char c, size_t index = npos) const + { + return rstrpos(buf, c, index); + } + + void erase(size_t index = 0, size_t len = npos) + { + + if (!buf || index >= length()) + return; + + if (index + len > length() || len == npos) + len = length() - index; + + int rightLen = length() - index - len; + + memmove(buf + index, buf + index + len, rightLen); + + buf[index + rightLen] = '\0'; + + _reserve(length(), true); + } + + size_t length() const + { + if (!buf) + return 0; + return strlen(buf); + } + + MB_String substr(size_t offset, size_t len = npos) const + { + MB_String out; + substr(out, offset, len); + return out; + } + + void substr(MB_String &out, size_t offset, size_t len = npos) const + { + if (len > 0 && length() > 0 && offset < length()) + { + if (len > length() - offset) + len = length() - offset; + out.copy(buf + offset, len); + } + } + + void clear() + { +#if defined(ESP8266_USE_EXTERNAL_HEAP) + reset(1); +#else + allocate(0, false); +#endif + } + +#if defined(ESP8266_USE_EXTERNAL_HEAP) + void reset(size_t len) + { + if (len == 0) + len = 4; + ESP.setExternalHeap(); + if (buf) + buf = (char *)realloc(buf, len); + else + buf = (char *)malloc(len); + ESP.resetHeap(); + + if (buf) + { + bufLen = len; + memset(buf, 0, len); + } + } +#endif + + void resize(size_t len) + { + if (_reserve(len, true)) + buf[len] = '\0'; + } + + MB_String &replace(size_t pos, size_t len, const char *replace) + { + size_t repLen = strlen(replace); + + if (length() > 0 && length() > pos && repLen > 0) + { + if (pos + len > length()) + len = length() - pos; + + if (repLen > len) + { + size_t rightLen = length() - pos - len; + + if (maxLength() < length() + repLen - len) + _reserve(length() + repLen - len, false); + + memmove(buf + pos + repLen, buf + pos + len, rightLen); + buf[pos + repLen + rightLen] = '\0'; + } + + memmove(buf + pos, replace, repLen); + } + + return *this; + } + + MB_String &replace(size_t pos, size_t len, const MB_String &replace) + { + return this->replace(pos, len, replace.c_str()); + } + + MB_String &insert(size_t pos, size_t n, char c) + { + size_t slen = length(); + + size_t rightLen = slen - pos; + + if (maxLength() < slen + n) + _reserve(slen + n, false); + + if (maxLength() >= slen + n) + { + memmove(buf + pos + n, buf + pos, rightLen); + + for (size_t i = 0; i < n; i++) + *(buf + pos + i) = c; + + buf[pos + n + rightLen] = '\0'; + } + + return *this; + } + + MB_String &insert(size_t pos, const char *cstr) + { + size_t insLen = strlen(cstr); + + if (length() > 0 && length() > pos && insLen > 0) + { + + size_t rightLen = length() - pos; + + if (maxLength() < length() + insLen) + _reserve(length() + insLen, false); + + memmove(buf + pos + insLen, buf + pos, rightLen); + buf[pos + insLen + rightLen] = '\0'; + memmove(buf + pos, cstr, insLen); + } + + return *this; + } + + MB_String &insert(size_t pos, const MB_String &str) + { + return insert(pos, str.c_str()); + } + + MB_String &insert(size_t pos, char c) + { + char temp[2]{c, '\0'}; + return insert(pos, temp); + } + + size_t find_first_of(const char *cstr, size_t pos = 0) const + { + if (!cstr) + return -1; + + return strpos(buf, cstr, pos); + } + + size_t find_first_of(const MB_String &str, size_t pos = 0) const + { + if (length() == 0 || pos >= length()) + return -1; + + return find_first_of(str.buf, pos); + } + + size_t find_first_not_of(const char *cstr, size_t pos = 0) const + { + if (length() == 0 || pos >= length()) + return -1; + + int size = strcspn(buf + pos, cstr); + if (size == 0) + { + while (size == 0 && pos < length()) + { + size = strcspn(buf + pos, cstr); + pos++; + } + + if (pos > 0) + pos--; + } + + return pos; + } + + size_t find_first_not_of(const MB_String &str, size_t pos = 0) const + { + if (length() == 0 || pos >= length() || str.length() == 0) + return -1; + + return find_first_not_of(str.buf, pos); + } + + size_t find_last_of(const char *cstr, size_t pos = npos) const + { + if (!cstr) + return -1; + + return rstrpos(buf, cstr, pos); + } + + size_t find_last_of(const MB_String &str, size_t pos = npos) const + { + if (str.length() == 0) + return -1; + + return find_last_of(str.buf, pos); + } + + size_t find_last_not_of(const char *cstr, size_t pos = npos) const + { + if (length() == 0) + return -1; + + if (pos >= length()) + pos = length() - 1; + + int p = length() - 1; + int size = strcspn(buf + p, cstr); + if (size == 0) + { + while (size == 0 && p > 0) + { + size = strcspn(buf + p, cstr); + p--; + } + p++; + } + + return p; + } + + size_t find_last_not_of(const MB_String &str, size_t pos = npos) const + { + if (str.length() == 0) + return -1; + + return find_last_not_of(str.buf, pos); + } + + MB_String & replaceAll(const char *find, const char *replace) + { + if (length() == 0) + return *this;; + + int i, cnt = 0; + int repLen = strlen(replace); + int findLen = strlen(find); + + MB_String temp = buf; + char *s = temp.buf; + clear(); + + for (i = 0; s[i] != '\0'; i++) + { + if (strstr(&s[i], find) == &s[i]) + { + cnt++; + i += findLen - 1; + } + } + + if (_reserve(i + cnt * (repLen - findLen) + 1, false)) + { + i = 0; + while (*s) + { + if (strstr(s, find) == s) + { + strcpy(&buf[i], replace); + i += repLen; + s += findLen; + } + else + buf[i++] = *s++; + } + + buf[i] = '\0'; + } + + temp.clear(); + + return *this; + } + + void replaceAll(const MB_String &find, const MB_String &replace) + { + replaceAll(find.c_str(), replace.c_str()); + } + + bool empty() const + { + return length() == 0; + } + + void reserve(size_t len) + { + if (_reserve(len, false)) + buf[len] = '\0'; + } + + static const size_t npos = -1; + +private: +#if defined(ARDUINO_ARCH_SAMD) || defined(__AVR_ATmega4809__) || defined(ARDUINO_NANO_RP2040_CONNECT) + + char *int32Str(signed long value) + { + char *t = (char *)newP(64); + sprintf(t, (const char *)MBSTRING_FLASH_MCR("%ld"), value); + return t; + } + + char *uint32Str(unsigned long value) + { + char *t = (char *)newP(64); + sprintf(t, (const char *)MBSTRING_FLASH_MCR("%lu"), value); + return t; + } + +#endif + + char *int64Str(signed long long value) + { + char *t = (char *)newP(64); + sprintf(t, (const char *)MBSTRING_FLASH_MCR("%lld"), value); + return t; + } + + char *uint64Str(unsigned long long value) + { + char *t = (char *)newP(64); + sprintf(t, (const char *)MBSTRING_FLASH_MCR("%llu"), value); + return t; + } + + char *boolStr(bool value) + { + char *t = (char *)newP(8); + value ? strcpy(t, (const char *)MBSTRING_FLASH_MCR("true")) : strcpy(t, (const char *)MBSTRING_FLASH_MCR("false")); + return t; + } + + char *toFloatStr(long double value, int type, int precision) + { + int width = type == 0 ? 32 : 64; + + char *t = (char *)newP(width); + + if (t) + { + MB_String fmt = MBSTRING_FLASH_MCR("%."); + fmt += precision; + if (type == 2) + fmt += MBSTRING_FLASH_MCR("L"); + fmt += MBSTRING_FLASH_MCR("f"); + sprintf(t, fmt.c_str(), value); + trim(t); + } + + return t; + } + + char *nullStr() + { + char *t = (char *)newP(6); + strcpy(t, (const char *)MBSTRING_FLASH_MCR("null")); + return t; + } + + char *pgmStr(PGM_P p) + { + char *t = (char *)newP(strlen_P(p)); + strcpy_P(t, p); + return t; + } + + void trim(char *s) + { + if (!s) + return; + size_t i = strlen(s) - 1; + while (s[i] == '0' && i > 0) + { + if (s[i - 1] == '.') + { + i--; + break; + } + if (s[i - 1] != '0') + break; + i--; + } + if (i < strlen(s) - 1) + s[i] = '\0'; + } + + void *newP(size_t len) + { + void *p; + size_t newLen = getReservedLen(len); +#if defined(BOARD_HAS_PSRAM) && defined(MB_STRING_USE_PSRAM) + if (ESP.getPsramSize() > 0) + p = (void *)ps_malloc(newLen); + else + p = (void *)malloc(newLen); + if (!p) + return NULL; + +#else + +#if defined(ESP8266_USE_EXTERNAL_HEAP) + ESP.setExternalHeap(); +#endif + + p = (void *)malloc(newLen); + bool nn = p ? true : false; + +#if defined(ESP8266_USE_EXTERNAL_HEAP) + ESP.resetHeap(); +#endif + + if (!nn) + return NULL; + +#endif + memset(p, 0, newLen); + return p; + } + + void delP(void *ptr) + { + void **p = (void **)ptr; + if (*p) + { + free(*p); + *p = 0; + } + } + + size_t getReservedLen(size_t len) + { + int blen = len + 1; + + int newlen = (blen / 4) * 4; + + if (newlen < blen) + newlen += 4; + + return (size_t)newlen; + } + + size_t maxLength() const + { + if (bufferLength() == 0) + return 0; + return bufferLength() - 1; + } + + void concat(const MB_String &s) + { + if (s.length() == 0) + return; + + if (&s == this) + { + size_t slen = length(); + + if (2 * slen > maxLength()) + { + if (!_reserve(2 * slen, false)) + return; + } + + memmove(buf + slen, buf, slen); + buf[2 * slen] = '\0'; + } + else + { + concat(s.buf, s.length()); + } + } + + void concat(const char *cstr, size_t len) + { + if (!cstr) + return; + + size_t slen = length(); + + if (slen + len > maxLength()) + { + if (!_reserve(slen + len, false)) + return; + } + + memmove(buf + slen, cstr, len); + buf[slen + len] = '\0'; + } + + void concat(const char *cstr) + { + if (!cstr) + return; + + concat(cstr, strlen(cstr)); + } + + void move(MB_String &rhs) + { + if (buf) + { + if (bufLen >= rhs.bufLen) + { + strcpy(buf, rhs.buf); + bufLen = rhs.bufLen; + rhs.bufLen = 0; + return; + } + else + { + free(buf); + } + } + buf = rhs.buf; + bufLen = rhs.bufLen; + rhs.buf = NULL; + } + + void allocate(size_t len, bool shrink) + { + + if (len == 0) + { + if (buf) + free(buf); + buf = NULL; + bufLen = 0; + return; + } + + if (len > bufLen || shrink) + { + +#if defined(ESP8266_USE_EXTERNAL_HEAP) + ESP.setExternalHeap(); +#endif + + if (shrink || (bufLen > 0 && buf)) + { + int slen = length(); + +#if defined(BOARD_HAS_PSRAM) && defined(MB_STRING_USE_PSRAM) + if (ESP.getPsramSize() > 0) + buf = (char *)ps_realloc(buf, len); + else + buf = (char *)realloc(buf, len); +#else + buf = (char *)realloc(buf, len); +#endif + if (buf) + { + buf[slen] = '\0'; + bufLen = len; + } + } + else + { +#if defined(BOARD_HAS_PSRAM) && defined(MB_STRING_USE_PSRAM) + if (ESP.getPsramSize() > 0) + buf = (char *)ps_malloc(len); + else + buf = (char *)malloc(len); +#else + buf = (char *)malloc(len); +#endif + if (buf) + { + buf[0] = '\0'; + bufLen = len; + } + } + +#if defined(ESP8266_USE_EXTERNAL_HEAP) + ESP.resetHeap(); +#endif + } + } + + MB_String ©(const char *cstr, size_t length) + { + + if (!_reserve(length, false)) + { + clear(); + return *this; + } + + memcpy_P(buf, (PGM_P)cstr, length); + buf[length] = '\0'; + + return *this; + } + + bool _reserve(size_t len, bool shrink) + { + + size_t newlen = getReservedLen(len); + if (shrink) + allocate(newlen, true); + else if (newlen > bufLen) + allocate(newlen, false); + + return newlen <= bufLen; + } + + int strpos(const char *haystack, const char *needle, int offset) const + { + if (!haystack || !needle) + return -1; + + int hlen = strlen(haystack); + int nlen = strlen(needle); + + if (hlen == 0 || nlen == 0) + return -1; + + int hidx = offset, nidx = 0; + while ((*(haystack + hidx) != '\0') && (*(needle + nidx) != '\0') && hidx < hlen) + { + if (*(needle + nidx) != *(haystack + hidx)) + { + hidx++; + nidx = 0; + } + else + { + nidx++; + hidx++; + if (nidx == nlen) + return hidx - nidx; + } + } + + return -1; + } + + int strpos(const char *haystack, char needle, int offset) const + { + if (!haystack || needle == 0) + return -1; + + int hlen = strlen(haystack); + + if (hlen == 0) + return -1; + + int hidx = offset; + while ((*(haystack + hidx) != '\0') && hidx < hlen) + { + if (needle == *(haystack + hidx)) + return hidx; + hidx++; + } + + return -1; + } + + int rstrpos(const char *haystack, const char *needle, int offset /* start search from this offset to the left string */) const + { + if (!haystack || !needle) + return -1; + + int hlen = strlen(haystack); + int nlen = strlen(needle); + + if (hlen == 0 || nlen == 0) + return -1; + + int hidx = offset; + + if (hidx >= hlen || (size_t)offset == npos) + hidx = hlen - 1; + + int nidx = nlen - 1; + + while (hidx >= 0) + { + if (*(needle + nidx) != *(haystack + hidx)) + { + hidx--; + nidx = nlen - 1; + } + else + { + if (nidx == 0) + return hidx + nidx; + nidx--; + hidx--; + } + } + + return -1; + } + + int rstrpos(const char *haystack, char needle, int offset /* start search from this offset to the left char */) const + { + if (!haystack || needle == 0) + return -1; + + int hlen = strlen(haystack); + + if (hlen == 0) + return -1; + + int hidx = offset; + + if (hidx >= hlen || (size_t)offset == npos) + hidx = hlen - 1; + + while (hidx >= 0) + { + if (needle == *(haystack + hidx)) + return hidx; + hidx--; + } + + return -1; + } + + int compareTo(const MB_String &s) const + { + if (!buf || !s.buf) + { + if (s.buf && s.length() > 0) + return 0 - *(unsigned char *)s.buf; + if (buf && length() > 0) + return *(unsigned char *)buf; + return 0; + } + return strcmp(buf, s.buf); + } + + unsigned char equals(const MB_String &s2) const + { + return (length() == s2.length() && compareTo(s2) == 0); + } + + unsigned char equals(const char *cstr) const + { + if (length() == 0) + return (cstr == NULL || *cstr == 0); + if (cstr == NULL) + return buf[0] == 0; + return strcmp(buf, cstr) == 0; + } + + char *ultoa(unsigned long value, char *str, int radix) + { + const char *format = NULL; + + switch (radix) + { + case 8: + format = "%o"; + break; + case 10: + format = "%ul"; + break; + case 16: + format = "%x"; + break; + } + + if (format == NULL) + return str; + + int size = sprintf(str, format, value); + return &str[size]; + } + +#if (!defined(ESP32) && !defined(ESP8266) && !defined(ARDUINO_ARCH_STM32) && !defined(ARDUINO_ARCH_SAMD)) || defined(ARDUINO_NANO_RP2040_CONNECT) + char *ltoa(long value, char *str, int radix) + { + const char *format = NULL; + + switch (radix) + { + case 8: + format = "%o"; + break; + case 10: + format = "%l"; + break; + case 16: + format = "%x"; + break; + } + + if (format == NULL) + return str; + + int size = sprintf(str, format, value); + return &str[size]; + } + + char *utoa(unsigned int value, char *str, int radix) + { + const char *format = NULL; + + switch (radix) + { + case 8: + format = "%o"; + break; + case 10: + format = "%u"; + break; + case 16: + format = "%x"; + break; + } + + if (format == NULL) + return str; + + int size = sprintf(str, format, value); + return &str[size]; + } + + char *itoa(int value, char *str, int radix) + { + const char *format = NULL; + + switch (radix) + { + case 8: + format = "%o"; + break; + case 10: + format = "%d"; + break; + case 16: + format = "%x"; + break; + } + + if (format == NULL) + return str; + + int size = sprintf(str, format, value); + return &str[size]; + } +#endif + + char *buf = NULL; + size_t bufLen = 0; +}; + +inline MB_String operator+(const MB_String &lhs, const MB_String &rhs) +{ + MB_String res; + res.reserve(lhs.length() + rhs.length()); + res += lhs; + res += rhs; + return res; +} + +#if !defined(__AVR__) + +inline MB_String operator+(MB_String &&lhs, const MB_String &rhs) +{ + lhs += rhs; + return std::move(lhs); +} + +inline MB_String operator+(MB_String &lhs, MB_String &&rhs) +{ + lhs += rhs; + return std::move(lhs); +} + +inline MB_String operator+(MB_String &lhs, char rhs) +{ + lhs += rhs; + return std::move(lhs); +} + +inline MB_String operator+(char lhs, MB_String &rhs) +{ + rhs.insert(0, lhs); + return rhs; +} + +inline MB_String operator+(MB_String &&lhs, char rhs) +{ + return std::move(lhs.insert(0, rhs)); +} + +#endif + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/extras/MB_Time.h b/lib/libesp32/ESP-Mail-Client/src/extras/MB_Time.h new file mode 100644 index 000000000..73d84ac2b --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/extras/MB_Time.h @@ -0,0 +1,435 @@ +#ifndef MB_Time_H +#define MB_Time_H + +#include "ESP_Mail_Client_Version.h" +#if !VALID_VERSION_CHECK(30409) +#error "Mixed versions compilation." +#endif + +/* + * Time helper class v1.0.7 + * + * Created August 28, 2023 + * + * Do not remove or modify this file as it required for AVR, ARM, SAMD devices and external client to work. + * + * The MIT License (MIT) + * Copyright (c) 2022 K. Suwatchai (Mobizt) + * + * + * Permission is hereby granted, free of charge, to any person returning a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include +#include "Networks_Provider.h" + +#define ESP_TIME_DEFAULT_TS 1577836800 +#define ESP_TIME_NON_TS -1000 + +#include +#include + +#if defined(ESP32) && !defined(ESP_ARDUINO_VERSION) /* ESP32 core < v2.0.x */ +#include +#else +#include +#endif + +#if defined(ESP_MAIL_USE_PSRAM) +#define MB_STRING_USE_PSRAM +#endif + +#include "MB_String.h" +#include "MB_MCU.h" + +#if defined(ESP8266) +#include "user_interface.h" +#endif + +#if defined(__AVR__) || defined(MB_ARDUINO_TEENSY) +#define MB_TIME_PGM_ATTR +#else +#define MB_TIME_PGM_ATTR PROGMEM +#endif + +#if !defined(MB_ARDUINO_ESP) +static const char *mb_months[12] MB_TIME_PGM_ATTR = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; +#endif + +enum base_time_type_t +{ + base_time_type_undefined = -1, + base_time_type_unset = 0, + base_time_type_auto = 1, + base_time_type_user = 2 +}; + +class MB_Time +{ +public: + MB_Time() + { + } + + ~MB_Time() + { + clear(); + } + + void clear() + { +#if defined(ENABLE_NTP_TIME) + if (_sv1.length()) + { + _sv1.clear(); + _sv2.clear(); + _sv3.clear(); + } +#endif + } + + void readNTPTime(unsigned long waitMs, bool debugProgress) + { + if (!timeReady()) + { + if (WiFI_CONNECTED) + { + +#if defined(ENABLE_NTP_TIME) +#if (defined(ESP32) || defined(ESP8266)) + configTime(_gmt_offset * 3600, _daylight_offset * 60, _sv1.c_str(), _sv2.c_str(), _sv3.c_str()); +#elif defined(ARDUINO_RASPBERRY_PI_PICO_W) + NTP.begin(_sv1.c_str(), _sv2.c_str()); + NTP.waitSet(); +#endif +#endif + unsigned long ms = millis(); + +#if !defined(SILENT_MODE) + unsigned long pgms = 0; +#endif + do + { +#if defined(ESP_MAIL_HAS_WIFI_TIME) + _base_ts = WiFi.getTime() > ESP_TIME_DEFAULT_TS ? WiFi.getTime() : _base_ts; +#elif defined(ENABLE_NTP_TIME) + _base_ts = time(nullptr) > ESP_TIME_DEFAULT_TS ? time(nullptr) : _base_ts; +#else + break; +#endif + +#if !defined(SILENT_MODE) + if (debugProgress && millis() - pgms > 50) + { + pgms = millis(); + esp_mail_debug_print(".", false); + } +#endif + + yield_impl(); + } while (millis() - ms < waitMs && _base_ts < ESP_TIME_DEFAULT_TS); +#if !defined(SILENT_MODE) + if (debugProgress) + esp_mail_debug_print("", true); +#endif + } + } + } + + int setTimestamp(time_t ts, float gmtOffset) + { + _gmt_offset = gmtOffset; + _base_time_type = ts > ESP_TIME_DEFAULT_TS ? base_time_type_user : base_time_type_unset; +#if defined(MB_ARDUINO_ESP) + struct timeval tm; // sec, us + tm.tv_sec = ts; + tm.tv_usec = 0; + return settimeofday((const struct timeval *)&tm, 0); +#else + _ts_offset = ts - millis() / 1000; + return 1; +#endif + } + + /** Get the timestamp from the year, month, date, hour, minute, + * and second provided. + * + * @param year The year. + * @param mon The month from 1 to 12. + * @param date The dates. + * @param hour The hours. + * @param mins The minutes. + * @param sec The seconds. + * @return time_t The value of timestamp. + */ + time_t getTimestamp(int year, int mon, int date, int hour, int mins, int sec) + { + struct tm timeinfo; + timeinfo.tm_year = year - 1900; + timeinfo.tm_mon = mon - 1; + timeinfo.tm_mday = date; + timeinfo.tm_hour = hour; + timeinfo.tm_min = mins; + timeinfo.tm_sec = sec; + time_t ts = mktime(&timeinfo); + return ts; + } + + /** Get the timestamp from the RFC 2822 time string. + * e.g. Mon, 02 May 2022 00:30:00 +0000 or 02 May 2022 00:30:00 +0000 + * + * @param gmt Return the GMT time. + * @return timestamp of time string. + */ + time_t getTimestamp(const char *timeString, bool gmt = false) + { +#if defined(MB_ARDUINO_ESP) + struct tm timeinfo; + + if (strstr(timeString, ",") != NULL) + strptime(timeString, "%a, %d %b %Y %H:%M:%S %z", &timeinfo); + else + strptime(timeString, "%d %b %Y %H:%M:%S %z", &timeinfo); + + time_t ts = mktime(&timeinfo); + return ts; + +#else + + time_t ts = 0; + _vectorImpl tk; + MB_String s1 = timeString; + + splitToken(s1, tk, ' '); + int day = 0, mon = 0, year = 0, hr = 0, mins = 0, sec = 0, tz_h = 0, tz_m = 0; + + int tkindex = tk.size() == 5 ? -1 : 0; // No week days? + + // some response may include (UTC) and (ICT) + if (tk.size() >= 5) + { + day = atoi(tk[tkindex + 1].c_str()); + for (size_t i = 0; i < 12; i++) + { + if (strcmp_P(mb_months[i], tk[tkindex + 2].c_str()) == 0) + mon = i; + } + + // RFC 822 year to RFC 2822 + if (tk[tkindex + 3].length() == 2) + tk[tkindex + 3].prepend("20"); + + year = atoi(tk[tkindex + 3].c_str()); + + _vectorImpl tk2; + splitToken(tk[tkindex + 4], tk2, ':'); + if (tk2.size() == 3) + { + hr = atoi(tk2[0].c_str()); + mins = atoi(tk2[1].c_str()); + sec = atoi(tk2[2].c_str()); + } + + ts = getTimestamp(year, mon + 1, day, hr, mins, sec); + + if (tk[tkindex + 5].length() == 5 && gmt) + { + char tmp[6]; + memset(tmp, 0, 6); + strncpy(tmp, tk[tkindex + 5].c_str() + 1, 2); + tz_h = atoi(tmp); + + memset(tmp, 0, 6); + strncpy(tmp, tk[tkindex + 5].c_str() + 3, 2); + tz_m = atoi(tmp); + + time_t tz = tz_h * 60 * 60 + tz_m * 60; + if (tk[tkindex + 5][0] == '+') + ts -= tz; // remove time zone offset + else + ts += tz; + } + } + return ts; +#endif + } + + /** Get the current timestamp. + * + * @return uint64_t The value of current timestamp. + */ + uint64_t getCurrentTimestamp() + { + getBaseTime(); + return _base_ts; + } + + /** Get the current rfc822 date time string that valid for Email. + * @return String The current date time string. + */ + String getDateTimeString() + { + getBaseTime(); + + char tbuf[40]; + strftime(tbuf, 40, "%a, %d %b %Y %H:%M:%S %z", &_time_info); + MB_String tStr = tbuf, tzStr; + + int p = _gmt_offset < 0 ? -1 : 1; + float dif = (p * (_gmt_offset * 10 - (int)_gmt_offset * 10)) * 60.0 / 10; + tzStr = (_gmt_offset < 0) ? '-' : '+'; + + if ((int)_gmt_offset < 10) + tzStr += 0; + + tzStr += (int)_gmt_offset; + + if (dif < 10) + tzStr += 0; + + tzStr += (int)dif; + + // replace for valid timezone + tStr.replaceAll("+0000", tzStr); + return tStr.c_str(); + } + + String getDateTimeString(time_t ts, const char *format) + { + char tbuf[100]; + strftime(tbuf, 100, format, localtime(&ts)); + return tbuf; + } + + void begin(float gmtOffset, float daylightOffset, const char *servers) + { + if (timeReady() && _base_time_type == base_time_type_undefined) + _base_time_type = base_time_type_auto; + else if (_base_time_type == base_time_type_undefined) + _base_time_type = base_time_type_unset; + +#if defined(ENABLE_NTP_TIME) && (defined(ESP32) || defined(ESP8266) || defined(ARDUINO_RASPBERRY_PI_PICO_W)) + + _vectorImpl tk; + MB_String sv = servers; + + clear(); + + splitToken(sv, tk, ','); + + if (tk.size() > 0) + _sv1 = tk[0]; + if (tk.size() > 1) + _sv2 = tk[1]; + if (tk.size() > 2) + _sv3 = tk[2]; + +#endif + + if ((gmtOffset > ESP_TIME_NON_TS && _gmt_offset != gmtOffset) || (daylightOffset > ESP_TIME_NON_TS && _daylight_offset != daylightOffset)) + { + // Reset system timestamp when config changed + _base_ts = 0; + if (gmtOffset > ESP_TIME_NON_TS) + _gmt_offset = gmtOffset; + if (daylightOffset > ESP_TIME_NON_TS) + _daylight_offset = daylightOffset; + + if (_base_time_type == base_time_type_unset) + setTimestamp(millis(), _gmt_offset); + } + } + + /** get the clock ready state + */ + bool timeReady() + { + getBaseTime(); + return _time_ready; + } + +private: + time_t _base_ts = 0; + struct tm _time_info; + float _gmt_offset = ESP_TIME_NON_TS; + float _daylight_offset = ESP_TIME_NON_TS; + void splitToken(MB_String &str, _vectorImpl &tk, char delim) + { + size_t current, previous = 0; + current = str.find(delim, previous); + MB_String s; + while (current != MB_String::npos) + { + + s = str.substr(previous, current - previous); + s.trim(); + + if (s.length() > 0) + tk.push_back(s); + previous = current + 1; + current = str.find(delim, previous); + } + + s = str.substr(previous, current - previous); + + s.trim(); + + if (s.length() > 0) + tk.push_back(s); + + s.clear(); + } + + // 9Safe) Get base timestamp + void getBaseTime() + { + +#if defined(ESP32) || defined(ESP8266) || defined(MB_ARDUINO_PICO) + + if (_base_ts < time(nullptr) && time(nullptr) > ESP_TIME_DEFAULT_TS) + _base_ts = time(nullptr); + +#if defined(ESP32) + getLocalTime(&_time_info); +#elif defined(ESP8266) || defined(MB_ARDUINO_PICO) + localtime_r(&_base_ts, &_time_info); +#endif + +#elif defined(ESP_MAIL_HAS_WIFI_TIME) + if (WiFI_CONNECTED) + _base_ts = WiFi.getTime() > ESP_TIME_DEFAULT_TS ? WiFi.getTime() : _base_ts; +#else + _base_ts = _ts_offset + millis() / 1000; +#endif + + _time_ready = _base_ts > ESP_TIME_DEFAULT_TS; + if (_time_ready) + _ts_offset = _base_ts - millis() / 1000; + } + +#if defined(ENABLE_NTP_TIME) + // in ESP8266 these NTP sever strings should be existed during configuring time. + MB_String _sv1, _sv2, _sv3; +#endif + + uint32_t _ts_offset = 0; + bool _time_ready = false; + base_time_type_t _base_time_type = base_time_type_undefined; +}; + +#endif // MB_Time_H diff --git a/lib/libesp32/ESP-Mail-Client/src/extras/Networks_Provider.h b/lib/libesp32/ESP-Mail-Client/src/extras/Networks_Provider.h new file mode 100644 index 000000000..fd523be67 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/extras/Networks_Provider.h @@ -0,0 +1,131 @@ +#ifndef ESP_MAIL_NETWORKS_PROVIDER_H +#define ESP_MAIL_NETWORKS_PROVIDER_H + +#include "../ESP_Mail_FS.h" + +#include "../ESP_Mail_Client_Version.h" +#if !VALID_VERSION_CHECK(30409) +#error "Mixed versions compilation." +#endif + +#if __has_include() +#include +#endif + +#include "ESP8266_Supports.h" + +// Renesas devices +#if defined(ARDUINO_UNOWIFIR4) || defined(ARDUINO_MINIMA) || defined(ARDUINO_PORTENTA_C33) +#define ESP_MAIL_STRSEP strsepImpl +#define ESP_MAIL_USE_STRSEP_IMPL +#else +#define ESP_MAIL_STRSEP strsep +#endif + +#if defined(ESP32) || defined(ESP8266) || defined(ARDUINO_RASPBERRY_PI_PICO_W) || \ + defined(ARDUINO_UNOWIFIR4) || defined(ARDUINO_PORTENTA_C33) || \ + defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) || \ + __has_include() ||__has_include() + +#if !defined(ESP_MAIL_DISABLE_ONBOARD_WIFI) + +#define ESP_MAIL_WIFI_IS_AVAILABLE + +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) +#include +#elif defined(ESP8266) +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#elif __has_include() +#include +#endif + +#if !defined(ARDUINO_RASPBERRY_PI_PICO_W) && \ + !defined(MB_ARDUINO_ARCH_SAMD) && \ + !defined(MB_ARDUINO_MBED_PORTENTA) && \ + !defined(ARDUINO_UNOWIFIR4) && \ + !defined(ARDUINO_PORTENTA_C33) && \ + !defined(ARDUINO_NANO_RP2040_CONNECT) +#define ESP_MAIL_HAS_WIFI_DISCONNECT +#endif + +#if defined(ARDUINO_PORTENTA_C33) +#define CONST_STRING_CAST char * // C33 WiFi library SSID is char array +#else +#define CONST_STRING_CAST const char * +#endif + +// WiFiS3 getTime is currently return 0 (not implemented) +#if __has_include() || __has_include() +#define ESP_MAIL_HAS_WIFI_TIME +#endif + +#if defined(MB_ARDUINO_PICO) && __has_include() +#define ESP_MAIL_HAS_WIFIMULTI +#endif + +#endif + +#endif + +#if !defined(ESP_MAIL_DISABLE_NATIVE_ETHERNET) + +#if defined(ESP32) && __has_include() +#include +#define ESP_MAIL_ETH_IS_AVAILABLE +#elif defined(ESP8266) && defined(ESP8266_CORE_SDK_V3_X_X) +#if defined(INC_ENC28J60_LWIP) || defined(INC_W5100_LWIP) || defined(INC_W5500_LWIP) +#define ESP_MAIL_ETH_IS_AVAILABLE +#endif +#endif + +#endif + +#if defined(TINY_GSM_MODEM_SIM800) || \ + defined(TINY_GSM_MODEM_SIM808) || \ + defined(TINY_GSM_MODEM_SIM868) || \ + defined(TINY_GSM_MODEM_SIM900) || \ + defined(TINY_GSM_MODEM_SIM7000) || \ + defined(TINY_GSM_MODEM_SIM7000) || \ + defined(TINY_GSM_MODEM_SIM7000SSL) || \ + defined(TINY_GSM_MODEM_SIM7070) || \ + defined(TINY_GSM_MODEM_SIM7080) || \ + defined(TINY_GSM_MODEM_SIM7090) || \ + defined(TINY_GSM_MODEM_SIM5320) || \ + defined(TINY_GSM_MODEM_SIM5360) || \ + defined(TINY_GSM_MODEM_SIM5300) || \ + defined(TINY_GSM_MODEM_SIM7100) || \ + defined(TINY_GSM_MODEM_SIM7600) || \ + defined(TINY_GSM_MODEM_SIM7800) || \ + defined(TINY_GSM_MODEM_SIM7500) || \ + defined(TINY_GSM_MODEM_UBLOX) || \ + defined(TINY_GSM_MODEM_SARAR4) || \ + defined(TINY_GSM_MODEM_M95) || \ + defined(TINY_GSM_MODEM_BG96) || \ + defined(TINY_GSM_MODEM_A6) || \ + defined(TINY_GSM_MODEM_A7) || \ + defined(TINY_GSM_MODEM_M590) || \ + defined(TINY_GSM_MODEM_MC60) || \ + defined(TINY_GSM_MODEM_MC60E) || \ + defined(TINY_GSM_MODEM_XBEE) || \ + defined(TINY_GSM_MODEM_SEQUANS_MONARCH) +#define ESP_MAIL_TINYGSM_IS_AVAILABLE +#endif + +#if defined(ESP_MAIL_TINYGSM_IS_AVAILABLE) && __has_include() +#include +#define ESP_MAIL_GSM_MODEM_IS_AVAILABLE +#endif + +#if defined(ESP_MAIL_WIFI_IS_AVAILABLE) +#define WiFI_CONNECTED (WiFi.status() == WL_CONNECTED) +#else +#define WiFI_CONNECTED false +#endif + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/extras/RFC2047.cpp b/lib/libesp32/ESP-Mail-Client/src/extras/RFC2047.cpp new file mode 100644 index 000000000..95e5ac140 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/extras/RFC2047.cpp @@ -0,0 +1,192 @@ +#ifndef RFC2047_CPP +#define RFC2047_CPP + +#include "ESP_Mail_Client_Version.h" +#if !VALID_VERSION_CHECK(30409) +#error "Mixed versions compilation." +#endif + +#include "RFC2047.h" + +RFC2047_Decoder::RFC2047_Decoder() {} +RFC2047_Decoder::~RFC2047_Decoder() {} + +void RFC2047_Decoder::decode(MB_FS *mbfs, char *d, const char *s, size_t dlen) +{ + if (!mbfs) + return; + + this->mbfs = mbfs; + + const char *p, *q; + size_t n; + int found_encoded = 0; + + dlen--; /* save room for the terminal nul */ + + while (*s && dlen > 0) + { + if ((p = strstr(s, "=?")) == NULL || + (q = strchr(p + 2, '?')) == NULL || + (q = strchr(q + 1, '?')) == NULL || + (q = strstr(q + 1, "?=")) == NULL) + { + /* no encoded words */ + if (d != s) + strfcpy(d, s, dlen + 1); + return; + } + + if (p != s) + { + n = (size_t)(p - s); + /* ignore spaces between encoded words */ + if (!found_encoded || strspn(s, " \t\r\n") != n) + { + if (n > dlen) + n = dlen; + if (d != s) + memcpy(d, s, n); + d += n; + dlen -= n; + } + } + + rfc2047DecodeWord(d, p, dlen); + found_encoded = 1; + s = q + 2; + n = strlen(d); + dlen -= n; + d += n; + } + *d = 0; +} + +void RFC2047_Decoder::rfc2047DecodeWord(char *d, const char *s, size_t dlen) +{ + + if (!mbfs) + return; + + char *p = safe_strdup(s); + char *pp = p; + char *end = p; + char *pd = d; + size_t len = dlen; + int enc = 0, filter = 0, count = 0, c1, c2, c3, c4; + + while (pp != NULL) + { + // See RFC2047.h + ESP_MAIL_STRSEP(&end, "?"); + count++; + switch (count) + { + case 2: + if (strcasecmp(pp, Charset) != 0) + { + filter = 1; + } + break; + case 3: + if (toupper(*pp) == 'Q') + enc = ENCQUOTEDPRINTABLE; + else if (toupper(*pp) == 'B') + enc = ENCBASE64; + else + return; + break; + case 4: + if (enc == ENCQUOTEDPRINTABLE) + { + while (*pp && len > 0) + { + if (*pp == '_') + { + *pd++ = ' '; + len--; + } + else if (*pp == '=') + { + *pd++ = (hexval(pp[1]) << 4) | hexval(pp[2]); + len--; + pp += 2; + } + else + { + *pd++ = *pp; + len--; + } + pp++; + } + *pd = 0; + } + else if (enc == ENCBASE64) + { + while (*pp && len > 0) + { + c1 = base64val(pp[0]); + c2 = base64val(pp[1]); + *pd++ = (c1 << 2) | ((c2 >> 4) & 0x3); + if (--len == 0) + break; + + if (pp[2] == '=') + break; + + c3 = base64val(pp[2]); + *pd++ = ((c2 & 0xf) << 4) | ((c3 >> 2) & 0xf); + if (--len == 0) + break; + + if (pp[3] == '=') + break; + + c4 = base64val(pp[3]); + *pd++ = ((c3 & 0x3) << 6) | c4; + if (--len == 0) + break; + + pp += 4; + } + *pd = 0; + } + break; + } + + pp = end; + } + + mbfs->delP(&p); + + if (filter) + { + pd = d; + while (*pd) + { + if (!IsPrint(*pd)) + *pd = '?'; + pd++; + } + } + return; +} + +char *RFC2047_Decoder::safe_strdup(const char *s) +{ + + if (!mbfs) + return 0; + + char *p; + size_t l; + + if (!s || !*s) + return 0; + l = strlen(s) + 1; + p = (char *)mbfs->newP(l); + memcpy(p, s, l); + return (p); +} + +#endif // RFC2047_CPP \ No newline at end of file diff --git a/lib/libesp32/lib_mail/src/extras/RFC2047.h b/lib/libesp32/ESP-Mail-Client/src/extras/RFC2047.h similarity index 58% rename from lib/libesp32/lib_mail/src/extras/RFC2047.h rename to lib/libesp32/ESP-Mail-Client/src/extras/RFC2047.h index 1753a2119..baadaa672 100644 --- a/lib/libesp32/lib_mail/src/extras/RFC2047.h +++ b/lib/libesp32/ESP-Mail-Client/src/extras/RFC2047.h @@ -1,12 +1,43 @@ +#pragma once #ifndef RFC2047_H #define RFC2047_H +#include "ESP_Mail_Client_Version.h" +#if !VALID_VERSION_CHECK(30409) +#error "Mixed versions compilation." +#endif #include +#include "ESP_Mail_FS.h" +#include "MB_FS.h" +#include "Networks_Provider.h" +#if defined(ESP32) +#if defined(BOARD_HAS_PSRAM) && defined(ESP_Mail_USE_PSRAM) +#include +#endif +#endif -#define strfcpy(A,B,C) strncpy(A,B,C), *(A+(C)-1)=0 +#define strfcpy(A, B, C) strncpy(A, B, C), *(A + (C)-1) = 0 + +#if defined(ESP_MAIL_USE_STRSEP_IMPL) +// This is strsep implementation because strdup may not available in some platform. +static char *__attribute__((used)) strsepImpl(char **stringp, const char *delim) +{ + char *rv = *stringp; + if (rv) + { + *stringp += strcspn(*stringp, delim); + if (**stringp) + *(*stringp)++ = '\0'; + else + *stringp = 0; + } + return rv; +} + +#endif enum { @@ -41,29 +72,23 @@ __attribute__((used)) static int Index_64[128] = { 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1}; #define IsPrint(c) (isprint((unsigned char)(c)) || \ - ((unsigned char)(c) >= 0xa0)) + ((unsigned char)(c) >= 0xa0)) #define hexval(c) Index_hex[(unsigned int)(c)] #define base64val(c) Index_64[(unsigned int)(c)] -class RFC2047_Decoder{ - - public: - RFC2047_Decoder(); - ~RFC2047_Decoder(); - void rfc2047Decode(char *d, const char *s, size_t dlen); - - - private: - void rfc2047DecodeWord(char *d, const char *s, size_t dlen); - void *safe_calloc (size_t nmemb, size_t size); - void *safe_malloc (unsigned int siz); - void safe_realloc (void **p, size_t siz); - void safe_free (void *ptr); - char *safe_strdup (const char *s); +class RFC2047_Decoder +{ +public: + RFC2047_Decoder(); + ~RFC2047_Decoder(); + void decode(MB_FS *mbfs, char *d, const char *s, size_t dlen); +private: + void rfc2047DecodeWord(char *d, const char *s, size_t dlen); + char *safe_strdup(const char *s); + MB_FS *mbfs = nullptr; }; - -#endif //RFC2047_H \ No newline at end of file +#endif // RFC2047_H \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/extras/SDHelper.h b/lib/libesp32/ESP-Mail-Client/src/extras/SDHelper.h new file mode 100644 index 000000000..48490c473 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/extras/SDHelper.h @@ -0,0 +1,163 @@ +#pragma once + +#ifndef SD_HELPER_H_ +#define SD_HELPER_H_ + +#include +#include + +// If SD Card used for storage, assign SD card type and FS used in src/ESP_Mail_FS.h and +// change the config for that card interfaces in this file (src/extras/SDHelper.h) + +#if defined(MBFS_SD_FS) && defined(MBFS_CARD_TYPE_SD) + +#if defined(ESP32) + +#define SPI_CS_PIN 13 +#define SPI_SCK_PIN 14 +#define SPI_MISO_PIN 2 +#define SPI_MOSI_PIN 15 +#define SPI_CLOCK_IN_MHz 16 + +// #define SPI_CS_PIN 5 +// #define SPI_SCK_PIN 18 +// #define SPI_MISO_PIN 19 +// #define SPI_MOSI_PIN 23 +// #define SPI_CLOCK_IN_MHz 4 // may work on lower clock rate + +#elif defined(ESP8266) +#define SPI_CS_PIN 15 +#elif defined(MB_ARDUINO_PICO) +// Use SPI 1's SS (GPIO 13) port as CS for SPI +#define SPI_CS_PIN PIN_SPI1_SS +#elif defined(MB_ARDUINO_ARCH_SAMD) || defined(MB_ARDUINO_NANO_RP2040_CONNECT) || defined(MB_ARDUINO_TEENSY) + +#define SPI_CS_PIN 4 + +#if defined(MBFS_SDFAT_ENABLED) +#define SPI_SCK_PIN -1 +#define SPI_MISO_PIN -1 +#define SPI_MOSI_PIN -1 +#define SPI_CLOCK_IN_MHz 4 // works on lower clock rate +#endif + +#endif + +// if SdFat library installed and ESP_Mail_FS.h was set to use it (for ESP32 only) +#if defined(MBFS_ESP32_SDFAT_ENABLED) || defined(MBFS_SDFAT_ENABLED) + +// https://github.com/greiman/SdFat +SdSpiConfig sdFatSPIConfig(SPI_CS_PIN, DEDICATED_SPI, SD_SCK_MHZ(SPI_CLOCK_IN_MHz)); + +#elif defined(ESP32) // if ESP32 and no SdFat library installed + +SPIClass spi; + +#elif defined(ESP8266) + +SDFSConfig sdFSConfig(SPI_CS_PIN, SPI_HALF_SPEED); + +#elif defined(MB_ARDUINO_PICO) + +/** Use Pico SPI 1 for SPI + * MISO GPIO 12 + * MOSI GPIO 15 + * SCK GPIO 14 + * SS GPIO 13 + */ +SDFSConfig sdFSConfig(SPI_CS_PIN, SPI_HALF_SPEED, SPI1); + +#endif + +#endif + +bool SD_Card_Mounting() +{ + +#if defined(MBFS_SD_FS) && defined(MBFS_CARD_TYPE_SD) + +#if defined(MBFS_ESP32_SDFAT_ENABLED) || defined(MBFS_SDFAT_ENABLED) + + Serial.print("\nMounting SD Card... "); + + if (!MailClient.sdBegin(&sdFatSPIConfig, SPI_CS_PIN, SPI_SCK_PIN, SPI_MISO_PIN, SPI_MOSI_PIN)) // pointer to SdSpiConfig, SS, SCK,MISO, MOSI + { + Serial.println("failed\n"); + return false; + } + else + { + Serial.println("success\n"); + return true; + } + +#elif defined(ESP32) // if ESP32 and no SdFat library installed + + Serial.print("\nMounting SD Card... "); + + spi.begin(SPI_SCK_PIN, SPI_MISO_PIN, SPI_MOSI_PIN, SPI_CS_PIN); // SPI pins config -> SCK,MISO, MOSI, SS + if (!MailClient.sdBegin(SPI_CS_PIN, &spi)) // SS, pointer to SPIClass <- SPIClass object should defined as static or global + { + Serial.println("failed\n"); + return false; + } + else + { + Serial.println("success\n"); + return true; + } +#elif defined(ESP8266) + + Serial.print("\nMounting SD Card... "); + + if (!MailClient.sdBegin(SPI_CS_PIN)) // or Firebase.sdBegin(&sdFSConfig) + { + Serial.println("failed\n"); + return false; + } + else + { + Serial.println("success\n"); + return true; + } + +#elif defined(MB_ARDUINO_PICO) + + Serial.print("\nMounting SD Card... "); + + if (!MailClient.sdBegin(&sdFSConfig)) // We begin with the SDFSConfig to use SPI 1 port + { + Serial.println("failed\n"); + return false; + } + else + { + Serial.println("success\n"); + return true; + } + +#endif + +#endif + +#if defined(MBFS_SD_FS) && defined(MBFS_CARD_TYPE_SD_MMC) + + Serial.print("\nMounting SD_MMC Card... "); + + if (!MailClient.sdMMCBegin("/sdcard", false, true)) + { + Serial.println("failed\n"); + return false; + } + else + { + Serial.println("success\n"); + return true; + } +#endif + + Serial.println("\nSD filesystem was not setup yet."); + return false; +} + +#endif diff --git a/lib/libesp32/ESP-Mail-Client/src/extras/WiFiClientImpl.h b/lib/libesp32/ESP-Mail-Client/src/extras/WiFiClientImpl.h new file mode 100644 index 000000000..99be542a3 --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/extras/WiFiClientImpl.h @@ -0,0 +1,565 @@ +/** + * WiFiClientImpl v1.0.1 + * + * This library provides the base client in replacement of ESP32 WiFiClient. + * + * The WiFiClient in ESP32 cannot be used in multithreading environment as in FreeRTOS task + * which can (always) lead to the assetion error "pbuf_free: p->ref > 0". + * + * Created August 20, 2023 + * + * The MIT License (MIT) + * Copyright (c) 2022 K. Suwatchai (Mobizt) + * + * + * Permission is hereby granted, free of charge, to any person returning a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#if !defined(WIFICLIENT_IMPL_H) && defined(ESP32) +#define WIFICLIENT_IMPL_H + +#include +class WiFiClientImpl : public Client +{ +public: + WiFiClientImpl(){}; + virtual ~WiFiClientImpl() { tcpClose(); }; + int connect(IPAddress ip, uint16_t port) { return tcpConnect(ip, port, _timeout); } + int connect(IPAddress ip, uint16_t port, int32_t timeout_ms) { return tcpConnect(ip, port, timeout_ms); } + int connect(const char *host, uint16_t port) + { + IPAddress address((uint32_t)0); +#if defined(WIFI_HAS_HOST_BY_NAME) + if (!WiFiGenericClass::hostByName(host, address)) + return -1; +#endif + return tcpConnect(address, port, _timeout); + } + int connect(const char *host, uint16_t port, int32_t timeout_ms) + { + _timeout = timeout_ms; + return connect(host, port); + } + size_t write(uint8_t data) { return write(&data, 1); } + size_t write(const uint8_t *buf, size_t size) { return tcpWrite(buf, size); } + size_t write_P(PGM_P buf, size_t size) { return write(buf, size); } + size_t write(Stream &stream) + { + uint8_t *buf = (uint8_t *)malloc(1360); + if (!buf) + { + return 0; + } + size_t toRead = 0, toWrite = 0, written = 0; + size_t available = stream.available(); + while (available) + { + toRead = (available > 1360) ? 1360 : available; + toWrite = stream.readBytes(buf, toRead); + written += write(buf, toWrite); + available = stream.available(); + } + free(buf); + buf = nullptr; + return written; + } + int available() { return tcpAavailable(); } + int read() + { + uint8_t data = 0; + int res = read(&data, 1); + if (res < 0) + { + return res; + } + if (res == 0) + { // No data available. + return -1; + } + return data; + } + int read(uint8_t *buf, size_t size) { return tcpRead(buf, size); } + int peek() { return tcpPeek(); } + void flush() + { + if (r_available()) + fillRxBuffer(); + _fillPos = _fillSize; + } + + void stop() { tcpClose(); } + uint8_t connected() { return tcpConnected(); } + + operator bool() + { + return connected(); + } + WiFiClientImpl &operator=(const WiFiClientImpl &other); + bool operator==(const bool value) + { + return bool() == value; + } + bool operator!=(const bool value) + { + return bool() != value; + } + bool operator==(const WiFiClientImpl &); + bool operator!=(const WiFiClientImpl &rhs) + { + return !this->operator==(rhs); + }; + + virtual int fd() const { return _socket; } + + int setSocketOption(int option, char *value, size_t len) + { + return setSocketOption(SOL_SOCKET, option, (const void *)value, len); + } + int setSocketOption(int level, int option, const void *value, size_t len) + { + int res = setsockopt(_socket, level, option, value, len); + if (res < 0) + { + log_e("fail on %d, errno: %d, \"%s\"", _socket, errno, strerror(errno)); + } + return res; + } + int setOption(int option, int *value) + { + return setSocketOption(IPPROTO_TCP, option, (const void *)value, sizeof(int)); + } + int getOption(int option, int *value) + { + socklen_t size = sizeof(int); + int res = getsockopt(_socket, IPPROTO_TCP, option, (char *)value, &size); + if (res < 0) + { + log_e("fail on fd %d, errno: %d, \"%s\"", _socket, errno, strerror(errno)); + } + return res; + } + + int setTimeout(uint32_t seconds) + { + Client::setTimeout(seconds * 1000); // This should be here? + _timeout = seconds * 1000; + if (_socket >= 0) + { + struct timeval tv; + tv.tv_sec = seconds; + tv.tv_usec = 0; + if (setSocketOption(SO_RCVTIMEO, (char *)&tv, sizeof(struct timeval)) < 0) + { + return -1; + } + return setSocketOption(SO_SNDTIMEO, (char *)&tv, sizeof(struct timeval)); + } + else + { + return 0; + } + } + + int setNoDelay(bool nodelay) + { + int flag = nodelay; + return setOption(TCP_NODELAY, &flag); + } + + bool getNoDelay() + { + int flag = 0; + getOption(TCP_NODELAY, &flag); + return flag; + } + + IPAddress remoteIP() const + { + return remoteIP(_socket); + } + + IPAddress remoteIP(int fd) const + { + struct sockaddr_storage addr; + socklen_t len = sizeof addr; + getpeername(fd, (struct sockaddr *)&addr, &len); + struct sockaddr_in *s = (struct sockaddr_in *)&addr; + return IPAddress((uint32_t)(s->sin_addr.s_addr)); + } + + uint16_t remotePort() const + { + return remotePort(_socket); + } + + uint16_t remotePort(int fd) const + { + struct sockaddr_storage addr; + socklen_t len = sizeof addr; + getpeername(fd, (struct sockaddr *)&addr, &len); + struct sockaddr_in *s = (struct sockaddr_in *)&addr; + return ntohs(s->sin_port); + } + + IPAddress localIP() const + { + return localIP(_socket); + } + + IPAddress localIP(int fd) const + { + struct sockaddr_storage addr; + socklen_t len = sizeof addr; + getsockname(fd, (struct sockaddr *)&addr, &len); + struct sockaddr_in *s = (struct sockaddr_in *)&addr; + return IPAddress((uint32_t)(s->sin_addr.s_addr)); + } + + uint16_t localPort() const + { + return localPort(_socket); + } + + uint16_t localPort(int fd) const + { + struct sockaddr_storage addr; + socklen_t len = sizeof addr; + getsockname(fd, (struct sockaddr *)&addr, &len); + struct sockaddr_in *s = (struct sockaddr_in *)&addr; + return ntohs(s->sin_port); + } + + // friend class WiFiServer; + using Print::write; + +private: + int _socket = -1; + int _timeout = 30000; + size_t _rxBuffSize = 2048; + uint8_t *_rxBuff = nullptr; + size_t _fillPos = 0; + size_t _fillSize = 0; + bool _failed = false; + bool _connected = false; + + size_t r_available() + { + if (_socket < 0) + { + return 0; + } + int count; +#ifdef ESP_IDF_VERSION_MAJOR + int res = lwip_ioctl(_socket, FIONREAD, &count); +#else + int res = lwip_ioctl_r(_socket, FIONREAD, &count); +#endif + if (res < 0) + { + _failed = true; + return 0; + } + return count; + } + + size_t fillRxBuffer() + { + if (!_rxBuff && !allocRxBuffer(_rxBuffSize)) + return 0; + + if (_fillSize && _fillPos == _fillSize) + { + _fillSize = 0; + _fillPos = 0; + } + + if (!_rxBuff || _rxBuffSize <= _fillSize || !r_available()) + { + return 0; + } + int res = recv(_socket, _rxBuff + _fillSize, _rxBuffSize - _fillSize, MSG_DONTWAIT); + if (res < 0) + { + if (errno != EWOULDBLOCK) + { + _failed = true; + } + return 0; + } + _fillSize += res; + return res; + } + + bool failed() + { + return _failed; + } + + int tcpConnect(const IPAddress &ip, uint32_t port, int timeout) + { + int enable = 1; + + log_v("Starting socket"); + + _socket = -1; + + _socket = lwip_socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + if (_socket < 0) + { + return _socket; + } + + struct sockaddr_in serv_addr; + memset(&serv_addr, 0, sizeof(serv_addr)); + serv_addr.sin_family = AF_INET; + serv_addr.sin_addr.s_addr = ip; + serv_addr.sin_port = htons(port); + + if (timeout <= 0) + timeout = 30000; // Milli seconds. + + fd_set fdset; + struct timeval tv; + FD_ZERO(&fdset); + FD_SET(_socket, &fdset); + tv.tv_sec = timeout / 1000; + tv.tv_usec = (timeout % 1000) * 1000; + + int res = lwip_connect(_socket, (struct sockaddr *)&serv_addr, sizeof(serv_addr)); + + if (res < 0 && errno != EINPROGRESS) + { + log_e("connect on fd %d, errno: %d, \"%s\"", _socket, errno, strerror(errno)); + tcpClose(); + return -1; + } + + res = select(_socket + 1, nullptr, &fdset, nullptr, timeout < 0 ? nullptr : &tv); + if (res < 0) + { + log_e("select on fd %d, errno: %d, \"%s\"", _socket, errno, strerror(errno)); + tcpClose(); + return -1; + } + else if (res == 0) + { + log_i("select returned due to timeout %d ms for fd %d", timeout, _socket); + tcpClose(); + return -1; + } + else + { + int sockerr; + socklen_t len = (socklen_t)sizeof(int); + res = getsockopt(_socket, SOL_SOCKET, SO_ERROR, &sockerr, &len); + + if (res < 0) + { + log_e("getsockopt on fd %d, errno: %d, \"%s\"", _socket, errno, strerror(errno)); + tcpClose(); + return -1; + } + + if (sockerr != 0) + { + log_e("socket error on fd %d, errno: %d, \"%s\"", _socket, sockerr, strerror(sockerr)); + tcpClose(); + return -1; + } + } + + lwip_setsockopt(_socket, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)); + lwip_setsockopt(_socket, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)); + + lwip_setsockopt(_socket, IPPROTO_TCP, TCP_NODELAY, &enable, sizeof(enable)); + lwip_setsockopt(_socket, SOL_SOCKET, SO_KEEPALIVE, &enable, sizeof(enable)); + + fcntl(_socket, F_SETFL, fcntl(_socket, F_GETFL, 0) | O_NONBLOCK); + + _connected = true; + + return 1; + } + + void tcpClose() + { + lwip_close(_socket); + _socket = -1; + _connected = false; + freeRxBuffer(); + } + + int tcpAavailable() + { + return _fillSize - _fillPos + r_available(); + } + + int tcpPeek() + { + if (!_rxBuff || _fillPos == _fillSize && !fillRxBuffer()) + { + return -1; + } + return _rxBuff[_fillPos]; + } + + size_t tcpWrite(const uint8_t *buf, size_t size) + { + if (!tcpConnected() || !size) + return 0; + + int res = 0; + int retry = 10; + int socketFileDescriptor = _socket; + size_t totalBytesSent = 0; + size_t bytesRemaining = size; + + while (retry) + { + // use select to make sure the socket is ready for writing + fd_set set; + struct timeval tv; + FD_ZERO(&set); // empties the set + FD_SET(socketFileDescriptor, &set); // adds FD to the set + tv.tv_sec = 0; + tv.tv_usec = 1000000; + retry--; + + if (select(socketFileDescriptor + 1, NULL, &set, NULL, &tv) < 0) + { + return 0; + } + + if (FD_ISSET(socketFileDescriptor, &set)) + { + res = send(socketFileDescriptor, (void *)buf, bytesRemaining, MSG_DONTWAIT); + if (res > 0) + { + totalBytesSent += res; + if (totalBytesSent >= size) + { + // completed successfully + retry = 0; + } + else + { + buf += res; + bytesRemaining -= res; + retry = 10; + } + } + else if (res < 0) + { + log_e("fail on fd %d, errno: %d, \"%s\"", _socket, errno, strerror(errno)); + if (errno != EAGAIN) + { + // if resource was busy, can try again, otherwise give up + res = 0; + retry = 0; + } + } + else + { + // Try again + } + } + } + return totalBytesSent; + + // return ssize_t or signed size_t for error + return lwip_write(_socket, buf, size); + } + + size_t tcpRead(uint8_t *dst, size_t len) + { + + if (!dst || !len || (_fillPos == _fillSize && !fillRxBuffer())) + { + return _failed ? -1 : 0; + } + + int remain = _fillSize - _fillPos; + if (len <= remain || ((len - remain) <= (_rxBuffSize - _fillSize) && fillRxBuffer() >= (len - remain))) + { + if (len == 1) + { + *dst = _rxBuff[_fillPos]; + } + else + { + memcpy(dst, _rxBuff + _fillPos, len); + } + _fillPos += len; + return len; + } + + size_t left = len; + size_t toRead = remain; + uint8_t *buf = dst; + memcpy(buf, _rxBuff + _fillPos, toRead); + _fillPos += toRead; + left -= toRead; + buf += toRead; + while (left) + { + if (!fillRxBuffer()) + { + return len - left; + } + remain = _fillSize - _fillPos; + toRead = (remain > left) ? left : remain; + memcpy(buf, _rxBuff + _fillPos, toRead); + _fillPos += toRead; + left -= toRead; + buf += toRead; + } + return len; + } + + int tcpConnected() + { + return _socket >= 0; + } + + bool allocRxBuffer(size_t size) + { + if (_rxBuff) + freeRxBuffer(); + + _rxBuff = (uint8_t *)malloc(size); + if (!_rxBuff) + { + + log_e("Not enough memory to allocate buffer"); + _failed = true; + return false; + } + + return true; + } + + void freeRxBuffer() + { + if (_rxBuff) + free(_rxBuff); + + _rxBuff = nullptr; + } +}; + +#endif /* WIFICLIENT_IMPL_H */ diff --git a/lib/libesp32/ESP-Mail-Client/src/extras/mb_print/mb_print.c b/lib/libesp32/ESP-Mail-Client/src/extras/mb_print/mb_print.c new file mode 100644 index 000000000..1a595f4fc --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/extras/mb_print/mb_print.c @@ -0,0 +1,1048 @@ +/////////////////////////////////////////////////////////////////////////////// +// \author (c) Marco Paland (info@paland.com) +// 2014-2019, PALANDesign Hannover, Germany +// +// \license The MIT License (MIT) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// +// \brief Tiny printf, sprintf and (v)snprintf implementation, optimized for speed on +// embedded systems with a very limited resources. These routines are thread +// safe and reentrant! +// Use this instead of the bloated standard/newlib printf cause these use +// malloc for printf (and may not be thread safe). +// +/////////////////////////////////////////////////////////////////////////////// + +#ifndef MB_PRINT_C +#define MB_PRINT_C + +#include +#include + +#include "mb_print.h" + +// define this globally (e.g. gcc -DMB_PRINT_INCLUDE_CONFIG_H ...) to include the +// printf_config.h header file +// default: undefined +#ifdef MB_PRINT_INCLUDE_CONFIG_H +#include "printf_config.h" +#endif + +// 'ntoa' conversion buffer size, this must be big enough to hold one converted +// numeric number including padded zeros (dynamically created on stack) +// default: 32 byte +#ifndef MB_PRINT_NTOA_BUFFER_SIZE +#define MB_PRINT_NTOA_BUFFER_SIZE 32U +#endif + +// 'ftoa' conversion buffer size, this must be big enough to hold one converted +// float number including padded zeros (dynamically created on stack) +// default: 32 byte +#ifndef MB_PRINT_FTOA_BUFFER_SIZE +#define MB_PRINT_FTOA_BUFFER_SIZE 32U +#endif + +// support for the floating point type (%f) +// default: activated +#ifndef MB_PRINT_DISABLE_SUPPORT_FLOAT +#define MB_PRINT_SUPPORT_FLOAT +#endif + +// support for exponential floating point notation (%e/%g) +// default: activated +#ifndef MB_PRINT_DISABLE_SUPPORT_EXPONENTIAL +#define MB_PRINT_SUPPORT_EXPONENTIAL +#endif + +// define the default floating point precision +// default: 6 digits +#ifndef MB_PRINT_DEFAULT_FLOAT_PRECISION +#define MB_PRINT_DEFAULT_FLOAT_PRECISION 6U +#endif + +// define the largest float suitable to print with %f +// default: 1e9 +#ifndef MB_PRINT_MAX_FLOAT +#define MB_PRINT_MAX_FLOAT 1e9 +#endif + +// support for the long long types (%llu or %p) +// default: activated +#ifndef MB_PRINT_DISABLE_SUPPORT_LONG_LONG +#define MB_PRINT_SUPPORT_LONG_LONG +#endif + +// support for the ptrdiff_t type (%t) +// ptrdiff_t is normally defined in as long or long long type +// default: activated +#ifndef MB_PRINT_DISABLE_SUPPORT_PTRDIFF_T +#define MB_PRINT_SUPPORT_PTRDIFF_T +#endif + +/////////////////////////////////////////////////////////////////////////////// + +// internal flag definitions +#define MB_PRINT_FLAGS_ZEROPAD (1U << 0U) +#define MB_PRINT_FLAGS_LEFT (1U << 1U) +#define MB_PRINT_FLAGS_PLUS (1U << 2U) +#define MB_PRINT_FLAGS_SPACE (1U << 3U) +#define MB_PRINT_FLAGS_HASH (1U << 4U) +#define MB_PRINT_FLAGS_UPPERCASE (1U << 5U) +#define MB_PRINT_FLAGS_CHAR (1U << 6U) +#define MB_PRINT_FLAGS_SHORT (1U << 7U) +#define MB_PRINT_FLAGS_LONG (1U << 8U) +#define MB_PRINT_FLAGS_LONG_LONG (1U << 9U) +#define MB_PRINT_FLAGS_PRECISION (1U << 10U) +#define MB_PRINT_FLAGS_ADAPT_EXP (1U << 11U) + +// import float.h for DBL_MAX +#if defined(MB_PRINT_SUPPORT_FLOAT) +#include +#endif + +// output function type +typedef void (*mb_print_out_fn_type)(char character, void *buffer, size_t idx, size_t maxlen); + +// wrapper (used as buffer) for output function type +typedef struct +{ + void (*fct)(char character, void *arg); + void *arg; +} mb_print_out_fn_wrap_type; + +// internal buffer output +static inline void mb_print_out_buffer(char character, void *buffer, size_t idx, size_t maxlen) +{ + if (idx < maxlen) + { + ((char *)buffer)[idx] = character; + } +} + +// internal null output +static inline void mb_print_out_null(char character, void *buffer, size_t idx, size_t maxlen) +{ + (void)character; + (void)buffer; + (void)idx; + (void)maxlen; +} + +// internal _putchar wrapper +static inline void mb_print_out_char(char character, void *buffer, size_t idx, size_t maxlen) +{ + (void)buffer; + (void)idx; + (void)maxlen; + if (character) + { + mb_print_putchar(character); + } +} + +// internal output function wrapper +static inline void mb_print_out_fn(char character, void *buffer, size_t idx, size_t maxlen) +{ + (void)idx; + (void)maxlen; + if (character) + { + // buffer is the output fct pointer + ((mb_print_out_fn_wrap_type *)buffer)->fct(character, ((mb_print_out_fn_wrap_type *)buffer)->arg); + } +} + +// internal secure strlen +// \return The length of the string (excluding the terminating 0) limited by 'maxsize' +static inline unsigned int mb_print_strlen(const char *str, size_t maxsize) +{ + const char *s; + for (s = str; *s && maxsize--; ++s) + ; + return (unsigned int)(s - str); +} + +// internal test if char is a digit (0-9) +// \return true if char is a digit +static inline bool mb_print_is_digit(char ch) +{ + return (ch >= '0') && (ch <= '9'); +} + +// internal ASCII string to unsigned int conversion +static unsigned int mb_print_atoi(const char **str) +{ + unsigned int i = 0U; + while (mb_print_is_digit(**str)) + { + i = i * 10U + (unsigned int)(*((*str)++) - '0'); + } + return i; +} + +// output the specified string in reverse, taking care of any zero-padding +static size_t mb_print_out_rev(mb_print_out_fn_type out, char *buffer, size_t idx, size_t maxlen, const char *buf, size_t len, unsigned int width, unsigned int flags) +{ + const size_t start_idx = idx; + + // pad spaces up to given width + if (!(flags & MB_PRINT_FLAGS_LEFT) && !(flags & MB_PRINT_FLAGS_ZEROPAD)) + { + for (size_t i = len; i < width; i++) + { + out(' ', buffer, idx++, maxlen); + } + } + + // reverse string + while (len) + { + out(buf[--len], buffer, idx++, maxlen); + } + + // append pad spaces up to given width + if (flags & MB_PRINT_FLAGS_LEFT) + { + while (idx - start_idx < width) + { + out(' ', buffer, idx++, maxlen); + } + } + + return idx; +} + +// internal itoa format +static size_t mb_print_itoa_format(mb_print_out_fn_type out, char *buffer, size_t idx, size_t maxlen, char *buf, size_t len, bool negative, unsigned int base, unsigned int prec, unsigned int width, unsigned int flags) +{ + // pad leading zeros + if (!(flags & MB_PRINT_FLAGS_LEFT)) + { + if (width && (flags & MB_PRINT_FLAGS_ZEROPAD) && (negative || (flags & (MB_PRINT_FLAGS_PLUS | MB_PRINT_FLAGS_SPACE)))) + { + width--; + } + while ((len < prec) && (len < MB_PRINT_NTOA_BUFFER_SIZE)) + { + buf[len++] = '0'; + } + while ((flags & MB_PRINT_FLAGS_ZEROPAD) && (len < width) && (len < MB_PRINT_NTOA_BUFFER_SIZE)) + { + buf[len++] = '0'; + } + } + + // handle hash + if (flags & MB_PRINT_FLAGS_HASH) + { + if (!(flags & MB_PRINT_FLAGS_PRECISION) && len && ((len == prec) || (len == width))) + { + len--; + if (len && (base == 16U)) + { + len--; + } + } + if ((base == 16U) && !(flags & MB_PRINT_FLAGS_UPPERCASE) && (len < MB_PRINT_NTOA_BUFFER_SIZE)) + { + buf[len++] = 'x'; + } + else if ((base == 16U) && (flags & MB_PRINT_FLAGS_UPPERCASE) && (len < MB_PRINT_NTOA_BUFFER_SIZE)) + { + buf[len++] = 'X'; + } + else if ((base == 2U) && (len < MB_PRINT_NTOA_BUFFER_SIZE)) + { + buf[len++] = 'b'; + } + if (len < MB_PRINT_NTOA_BUFFER_SIZE) + { + buf[len++] = '0'; + } + } + + if (len < MB_PRINT_NTOA_BUFFER_SIZE) + { + if (negative) + { + buf[len++] = '-'; + } + else if (flags & MB_PRINT_FLAGS_PLUS) + { + buf[len++] = '+'; // ignore the space if the '+' exists + } + else if (flags & MB_PRINT_FLAGS_SPACE) + { + buf[len++] = ' '; + } + } + + return mb_print_out_rev(out, buffer, idx, maxlen, buf, len, width, flags); +} + +// internal itoa for 'long' type +static size_t mb_print_itoa_long(mb_print_out_fn_type out, char *buffer, size_t idx, size_t maxlen, unsigned long value, bool negative, unsigned long base, unsigned int prec, unsigned int width, unsigned int flags) +{ + char buf[MB_PRINT_NTOA_BUFFER_SIZE]; + size_t len = 0U; + + // no hash for 0 values + if (!value) + { + flags &= ~MB_PRINT_FLAGS_HASH; + } + + // write if precision != 0 and value is != 0 + if (!(flags & MB_PRINT_FLAGS_PRECISION) || value) + { + do + { + const char digit = (char)(value % base); + buf[len++] = digit < 10 ? '0' + digit : (flags & MB_PRINT_FLAGS_UPPERCASE ? 'A' : 'a') + digit - 10; + value /= base; + } while (value && (len < MB_PRINT_NTOA_BUFFER_SIZE)); + } + + return mb_print_itoa_format(out, buffer, idx, maxlen, buf, len, negative, (unsigned int)base, prec, width, flags); +} + +// internal itoa for 'long long' type +#if defined(MB_PRINT_SUPPORT_LONG_LONG) +static size_t mb_print_itoa_long_long(mb_print_out_fn_type out, char *buffer, size_t idx, size_t maxlen, unsigned long long value, bool negative, unsigned long long base, unsigned int prec, unsigned int width, unsigned int flags) +{ + char buf[MB_PRINT_NTOA_BUFFER_SIZE]; + size_t len = 0U; + + // no hash for 0 values + if (!value) + { + flags &= ~MB_PRINT_FLAGS_HASH; + } + + // write if precision != 0 and value is != 0 + if (!(flags & MB_PRINT_FLAGS_PRECISION) || value) + { + do + { + const char digit = (char)(value % base); + buf[len++] = digit < 10 ? '0' + digit : (flags & MB_PRINT_FLAGS_UPPERCASE ? 'A' : 'a') + digit - 10; + value /= base; + } while (value && (len < MB_PRINT_NTOA_BUFFER_SIZE)); + } + + return mb_print_itoa_format(out, buffer, idx, maxlen, buf, len, negative, (unsigned int)base, prec, width, flags); +} +#endif // MB_PRINT_SUPPORT_LONG_LONG + +#if defined(MB_PRINT_SUPPORT_FLOAT) + +#if defined(MB_PRINT_SUPPORT_EXPONENTIAL) +// forward declaration so that mb_print_ftoa can switch to exp notation for values > MB_PRINT_MAX_FLOAT +static size_t mb_print_ftoa_exp(mb_print_out_fn_type out, char *buffer, size_t idx, size_t maxlen, double value, unsigned int prec, unsigned int width, unsigned int flags); +#endif + +// internal ftoa for fixed decimal floating point +static size_t mb_print_ftoa(mb_print_out_fn_type out, char *buffer, size_t idx, size_t maxlen, double value, unsigned int prec, unsigned int width, unsigned int flags) +{ + char buf[MB_PRINT_FTOA_BUFFER_SIZE]; + size_t len = 0U; + double diff = 0.0; + + // powers of 10 + static const double pow10[] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000}; + + // test for special values + if (value != value) + return mb_print_out_rev(out, buffer, idx, maxlen, "nan", 3, width, flags); + if (value < -DBL_MAX) + return mb_print_out_rev(out, buffer, idx, maxlen, "fni-", 4, width, flags); + if (value > DBL_MAX) + return mb_print_out_rev(out, buffer, idx, maxlen, (flags & MB_PRINT_FLAGS_PLUS) ? "fni+" : "fni", (flags & MB_PRINT_FLAGS_PLUS) ? 4U : 3U, width, flags); + + // test for very large values + // standard printf behavior is to print EVERY whole number digit -- which could be 100s of characters overflowing your buffers == bad + if ((value > MB_PRINT_MAX_FLOAT) || (value < -MB_PRINT_MAX_FLOAT)) + { +#if defined(MB_PRINT_SUPPORT_EXPONENTIAL) + return mb_print_ftoa_exp(out, buffer, idx, maxlen, value, prec, width, flags); +#else + return 0U; +#endif + } + + // test for negative + bool negative = false; + if (value < 0) + { + negative = true; + value = 0 - value; + } + + // set default precision, if not set explicitly + if (!(flags & MB_PRINT_FLAGS_PRECISION)) + { + prec = MB_PRINT_DEFAULT_FLOAT_PRECISION; + } + // limit precision to 9, cause a prec >= 10 can lead to overflow errors + while ((len < MB_PRINT_FTOA_BUFFER_SIZE) && (prec > 9U)) + { + buf[len++] = '0'; + prec--; + } + + int whole = (int)value; + double tmp = (value - whole) * pow10[prec]; + unsigned long frac = (unsigned long)tmp; + diff = tmp - frac; + + if (diff > 0.5) + { + ++frac; + // handle rollover, e.g. case 0.99 with prec 1 is 1.0 + if (frac >= pow10[prec]) + { + frac = 0; + ++whole; + } + } + else if (diff < 0.5) + { + } + else if ((frac == 0U) || (frac & 1U)) + { + // if halfway, round up if odd OR if last digit is 0 + ++frac; + } + + if (prec == 0U) + { + diff = value - (double)whole; + if ((!(diff < 0.5) || (diff > 0.5)) && (whole & 1)) + { + // exactly 0.5 and ODD, then round up + // 1.5 -> 2, but 2.5 -> 2 + ++whole; + } + } + else + { + unsigned int count = prec; + // now do fractional part, as an unsigned number + while (len < MB_PRINT_FTOA_BUFFER_SIZE) + { + --count; + buf[len++] = (char)(48U + (frac % 10U)); + if (!(frac /= 10U)) + { + break; + } + } + // add extra 0s + while ((len < MB_PRINT_FTOA_BUFFER_SIZE) && (count-- > 0U)) + { + buf[len++] = '0'; + } + if (len < MB_PRINT_FTOA_BUFFER_SIZE) + { + // add decimal + buf[len++] = '.'; + } + } + + // do whole part, number is reversed + while (len < MB_PRINT_FTOA_BUFFER_SIZE) + { + buf[len++] = (char)(48 + (whole % 10)); + if (!(whole /= 10)) + { + break; + } + } + + // pad leading zeros + if (!(flags & MB_PRINT_FLAGS_LEFT) && (flags & MB_PRINT_FLAGS_ZEROPAD)) + { + if (width && (negative || (flags & (MB_PRINT_FLAGS_PLUS | MB_PRINT_FLAGS_SPACE)))) + { + width--; + } + while ((len < width) && (len < MB_PRINT_FTOA_BUFFER_SIZE)) + { + buf[len++] = '0'; + } + } + + if (len < MB_PRINT_FTOA_BUFFER_SIZE) + { + if (negative) + { + buf[len++] = '-'; + } + else if (flags & MB_PRINT_FLAGS_PLUS) + { + buf[len++] = '+'; // ignore the space if the '+' exists + } + else if (flags & MB_PRINT_FLAGS_SPACE) + { + buf[len++] = ' '; + } + } + + return mb_print_out_rev(out, buffer, idx, maxlen, buf, len, width, flags); +} + +#if defined(MB_PRINT_SUPPORT_EXPONENTIAL) +// internal ftoa variant for exponential floating-point type, contributed by Martijn Jasperse +static size_t mb_print_ftoa_exp(mb_print_out_fn_type out, char *buffer, size_t idx, size_t maxlen, double value, unsigned int prec, unsigned int width, unsigned int flags) +{ + // check for NaN and special values + if ((value != value) || (value > DBL_MAX) || (value < -DBL_MAX)) + { + return mb_print_ftoa(out, buffer, idx, maxlen, value, prec, width, flags); + } + + // determine the sign + const bool negative = value < 0; + if (negative) + { + value = -value; + } + + // default precision + if (!(flags & MB_PRINT_FLAGS_PRECISION)) + { + prec = MB_PRINT_DEFAULT_FLOAT_PRECISION; + } + + // determine the decimal exponent + // based on the algorithm by David Gay (https://www.ampl.com/netlib/fp/dtoa.c) + union + { + uint64_t U; + double F; + } conv; + + conv.F = value; + int exp2 = (int)((conv.U >> 52U) & 0x07FFU) - 1023; // effectively log2 + conv.U = (conv.U & ((1ULL << 52U) - 1U)) | (1023ULL << 52U); // drop the exponent so conv.F is now in [1,2) + // now approximate log10 from the log2 integer part and an expansion of ln around 1.5 + int expval = (int)(0.1760912590558 + exp2 * 0.301029995663981 + (conv.F - 1.5) * 0.289529654602168); + // now we want to compute 10^expval but we want to be sure it won't overflow + exp2 = (int)(expval * 3.321928094887362 + 0.5); + const double z = expval * 2.302585092994046 - exp2 * 0.6931471805599453; + const double z2 = z * z; + conv.U = (uint64_t)(exp2 + 1023) << 52U; + // compute exp(z) using continued fractions, see https://en.wikipedia.org/wiki/Exponential_function#Continued_fractions_for_ex + conv.F *= 1 + 2 * z / (2 - z + (z2 / (6 + (z2 / (10 + z2 / 14))))); + // correct for rounding errors + if (value < conv.F) + { + expval--; + conv.F /= 10; + } + + // the exponent format is "%+03d" and largest value is "307", so set aside 4-5 characters + unsigned int minwidth = ((expval < 100) && (expval > -100)) ? 4U : 5U; + + // in "%g" mode, "prec" is the number of *significant figures* not decimals + if (flags & MB_PRINT_FLAGS_ADAPT_EXP) + { + // do we want to fall-back to "%f" mode? + if ((value >= 1e-4) && (value < 1e6)) + { + if ((int)prec > expval) + { + prec = (unsigned)((int)prec - expval - 1); + } + else + { + prec = 0; + } + flags |= MB_PRINT_FLAGS_PRECISION; // make sure mb_print_ftoa respects precision + // no characters in exponent + minwidth = 0U; + expval = 0; + } + else + { + // we use one sigfig for the whole part + if ((prec > 0) && (flags & MB_PRINT_FLAGS_PRECISION)) + { + --prec; + } + } + } + + // will everything fit? + unsigned int fwidth = width; + if (width > minwidth) + { + // we didn't fall-back so subtract the characters required for the exponent + fwidth -= minwidth; + } + else + { + // not enough characters, so go back to default sizing + fwidth = 0U; + } + if ((flags & MB_PRINT_FLAGS_LEFT) && minwidth) + { + // if we're padding on the right, DON'T pad the floating part + fwidth = 0U; + } + + // rescale the float value + if (expval) + { + value /= conv.F; + } + + // output the floating part + const size_t start_idx = idx; + idx = mb_print_ftoa(out, buffer, idx, maxlen, negative ? -value : value, prec, fwidth, flags & ~MB_PRINT_FLAGS_ADAPT_EXP); + + // output the exponent part + if (minwidth) + { + // output the exponential symbol + out((flags & MB_PRINT_FLAGS_UPPERCASE) ? 'E' : 'e', buffer, idx++, maxlen); + // output the exponent value + idx = mb_print_itoa_long(out, buffer, idx, maxlen, (expval < 0) ? -expval : expval, expval < 0, 10, 0, minwidth - 1, MB_PRINT_FLAGS_ZEROPAD | MB_PRINT_FLAGS_PLUS); + // might need to right-pad spaces + if (flags & MB_PRINT_FLAGS_LEFT) + { + while (idx - start_idx < width) + out(' ', buffer, idx++, maxlen); + } + } + return idx; +} +#endif // MB_PRINT_SUPPORT_EXPONENTIAL +#endif // MB_PRINT_SUPPORT_FLOAT + +// internal vsnprintf +static int mb_print_vsnprintf_int(mb_print_out_fn_type out, char *buffer, const size_t maxlen, const char *format, va_list va) +{ + unsigned int flags, width, precision, n; + size_t idx = 0U; + + if (!buffer) + { + // use null output function + out = mb_print_out_null; + } + + while (*format) + { + // format specifier? %[flags][width][.precision][length] + if (*format != '%') + { + // no + out(*format, buffer, idx++, maxlen); + format++; + continue; + } + else + { + // yes, evaluate it + format++; + } + + // evaluate flags + flags = 0U; + do + { + switch (*format) + { + case '0': + flags |= MB_PRINT_FLAGS_ZEROPAD; + format++; + n = 1U; + break; + case '-': + flags |= MB_PRINT_FLAGS_LEFT; + format++; + n = 1U; + break; + case '+': + flags |= MB_PRINT_FLAGS_PLUS; + format++; + n = 1U; + break; + case ' ': + flags |= MB_PRINT_FLAGS_SPACE; + format++; + n = 1U; + break; + case '#': + flags |= MB_PRINT_FLAGS_HASH; + format++; + n = 1U; + break; + default: + n = 0U; + break; + } + } while (n); + + // evaluate width field + width = 0U; + if (mb_print_is_digit(*format)) + { + width = mb_print_atoi(&format); + } + else if (*format == '*') + { + const int w = va_arg(va, int); + if (w < 0) + { + flags |= MB_PRINT_FLAGS_LEFT; // reverse padding + width = (unsigned int)-w; + } + else + { + width = (unsigned int)w; + } + format++; + } + + // evaluate precision field + precision = 0U; + if (*format == '.') + { + flags |= MB_PRINT_FLAGS_PRECISION; + format++; + if (mb_print_is_digit(*format)) + { + precision = mb_print_atoi(&format); + } + else if (*format == '*') + { + const int prec = (int)va_arg(va, int); + precision = prec > 0 ? (unsigned int)prec : 0U; + format++; + } + } + + // evaluate length field + switch (*format) + { + case 'l': + flags |= MB_PRINT_FLAGS_LONG; + format++; + if (*format == 'l') + { + flags |= MB_PRINT_FLAGS_LONG_LONG; + format++; + } + break; + case 'h': + flags |= MB_PRINT_FLAGS_SHORT; + format++; + if (*format == 'h') + { + flags |= MB_PRINT_FLAGS_CHAR; + format++; + } + break; +#if defined(MB_PRINT_SUPPORT_PTRDIFF_T) + case 't': + flags |= (sizeof(ptrdiff_t) == sizeof(long) ? MB_PRINT_FLAGS_LONG : MB_PRINT_FLAGS_LONG_LONG); + format++; + break; +#endif + case 'j': + flags |= (sizeof(intmax_t) == sizeof(long) ? MB_PRINT_FLAGS_LONG : MB_PRINT_FLAGS_LONG_LONG); + format++; + break; + case 'z': + flags |= (sizeof(size_t) == sizeof(long) ? MB_PRINT_FLAGS_LONG : MB_PRINT_FLAGS_LONG_LONG); + format++; + break; + default: + break; + } + + // evaluate specifier + switch (*format) + { + case 'd': + case 'i': + case 'u': + case 'x': + case 'X': + case 'o': + case 'b': + { + // set the base + unsigned int base; + if (*format == 'x' || *format == 'X') + { + base = 16U; + } + else if (*format == 'o') + { + base = 8U; + } + else if (*format == 'b') + { + base = 2U; + } + else + { + base = 10U; + flags &= ~MB_PRINT_FLAGS_HASH; // no hash for dec format + } + // uppercase + if (*format == 'X') + { + flags |= MB_PRINT_FLAGS_UPPERCASE; + } + + // no plus or space flag for u, x, X, o, b + if ((*format != 'i') && (*format != 'd')) + { + flags &= ~(MB_PRINT_FLAGS_PLUS | MB_PRINT_FLAGS_SPACE); + } + + // ignore '0' flag when precision is given + if (flags & MB_PRINT_FLAGS_PRECISION) + { + flags &= ~MB_PRINT_FLAGS_ZEROPAD; + } + + // convert the integer + if ((*format == 'i') || (*format == 'd')) + { + // signed + if (flags & MB_PRINT_FLAGS_LONG_LONG) + { +#if defined(MB_PRINT_SUPPORT_LONG_LONG) + const long long value = va_arg(va, long long); + idx = mb_print_itoa_long_long(out, buffer, idx, maxlen, (unsigned long long)(value > 0 ? value : 0 - value), value < 0, base, precision, width, flags); +#endif + } + else if (flags & MB_PRINT_FLAGS_LONG) + { + const long value = va_arg(va, long); + idx = mb_print_itoa_long(out, buffer, idx, maxlen, (unsigned long)(value > 0 ? value : 0 - value), value < 0, base, precision, width, flags); + } + else + { + const int value = (flags & MB_PRINT_FLAGS_CHAR) ? (char)va_arg(va, int) : (flags & MB_PRINT_FLAGS_SHORT) ? (short int)va_arg(va, int) + : va_arg(va, int); + idx = mb_print_itoa_long(out, buffer, idx, maxlen, (unsigned int)(value > 0 ? value : 0 - value), value < 0, base, precision, width, flags); + } + } + else + { + // unsigned + if (flags & MB_PRINT_FLAGS_LONG_LONG) + { +#if defined(MB_PRINT_SUPPORT_LONG_LONG) + idx = mb_print_itoa_long_long(out, buffer, idx, maxlen, va_arg(va, unsigned long long), false, base, precision, width, flags); +#endif + } + else if (flags & MB_PRINT_FLAGS_LONG) + { + idx = mb_print_itoa_long(out, buffer, idx, maxlen, va_arg(va, unsigned long), false, base, precision, width, flags); + } + else + { + const unsigned int value = (flags & MB_PRINT_FLAGS_CHAR) ? (unsigned char)va_arg(va, unsigned int) : (flags & MB_PRINT_FLAGS_SHORT) ? (unsigned short int)va_arg(va, unsigned int) + : va_arg(va, unsigned int); + idx = mb_print_itoa_long(out, buffer, idx, maxlen, value, false, base, precision, width, flags); + } + } + format++; + break; + } +#if defined(MB_PRINT_SUPPORT_FLOAT) + case 'f': + case 'F': + if (*format == 'F') + flags |= MB_PRINT_FLAGS_UPPERCASE; + idx = mb_print_ftoa(out, buffer, idx, maxlen, va_arg(va, double), precision, width, flags); + format++; + break; +#if defined(MB_PRINT_SUPPORT_EXPONENTIAL) + case 'e': + case 'E': + case 'g': + case 'G': + if ((*format == 'g') || (*format == 'G')) + flags |= MB_PRINT_FLAGS_ADAPT_EXP; + if ((*format == 'E') || (*format == 'G')) + flags |= MB_PRINT_FLAGS_UPPERCASE; + idx = mb_print_ftoa_exp(out, buffer, idx, maxlen, va_arg(va, double), precision, width, flags); + format++; + break; +#endif // MB_PRINT_SUPPORT_EXPONENTIAL +#endif // MB_PRINT_SUPPORT_FLOAT + case 'c': + { + unsigned int l = 1U; + // pre padding + if (!(flags & MB_PRINT_FLAGS_LEFT)) + { + while (l++ < width) + { + out(' ', buffer, idx++, maxlen); + } + } + // char output + out((char)va_arg(va, int), buffer, idx++, maxlen); + // post padding + if (flags & MB_PRINT_FLAGS_LEFT) + { + while (l++ < width) + { + out(' ', buffer, idx++, maxlen); + } + } + format++; + break; + } + + case 's': + { + const char *p = va_arg(va, char *); + unsigned int l = mb_print_strlen(p, precision ? precision : (size_t)-1); + // pre padding + if (flags & MB_PRINT_FLAGS_PRECISION) + { + l = (l < precision ? l : precision); + } + if (!(flags & MB_PRINT_FLAGS_LEFT)) + { + while (l++ < width) + { + out(' ', buffer, idx++, maxlen); + } + } + // string output + while ((*p != 0) && (!(flags & MB_PRINT_FLAGS_PRECISION) || precision--)) + { + out(*(p++), buffer, idx++, maxlen); + } + // post padding + if (flags & MB_PRINT_FLAGS_LEFT) + { + while (l++ < width) + { + out(' ', buffer, idx++, maxlen); + } + } + format++; + break; + } + + case 'p': + { + width = sizeof(void *) * 2U; + flags |= MB_PRINT_FLAGS_ZEROPAD | MB_PRINT_FLAGS_UPPERCASE; +#if defined(MB_PRINT_SUPPORT_LONG_LONG) + const bool is_ll = sizeof(uintptr_t) == sizeof(long long); + if (is_ll) + { + idx = mb_print_itoa_long_long(out, buffer, idx, maxlen, (uintptr_t)va_arg(va, void *), false, 16U, precision, width, flags); + } + else + { +#endif + idx = mb_print_itoa_long(out, buffer, idx, maxlen, (unsigned long)((uintptr_t)va_arg(va, void *)), false, 16U, precision, width, flags); +#if defined(MB_PRINT_SUPPORT_LONG_LONG) + } +#endif + format++; + break; + } + + case '%': + out('%', buffer, idx++, maxlen); + format++; + break; + + default: + out(*format, buffer, idx++, maxlen); + format++; + break; + } + } + + // termination + out((char)0, buffer, idx < maxlen ? idx : maxlen - 1U, maxlen); + + // return written chars without terminating \0 + return (int)idx; +} + +/////////////////////////////////////////////////////////////////////////////// + +int mb_print_printf(const char *format, ...) +{ + va_list va; + va_start(va, format); + char buffer[1]; + const int ret = mb_print_vsnprintf_int(mb_print_out_char, buffer, (size_t)-1, format, va); + va_end(va); + return ret; +} + +int mb_print_sprintf(char *buffer, const char *format, ...) +{ + va_list va; + va_start(va, format); + const int ret = mb_print_vsnprintf_int(mb_print_out_buffer, buffer, (size_t)-1, format, va); + va_end(va); + return ret; +} + +int mb_print_snprintf_(char *buffer, size_t count, const char *format, ...) +{ + va_list va; + va_start(va, format); + const int ret = mb_print_vsnprintf_int(mb_print_out_buffer, buffer, count, format, va); + va_end(va); + return ret; +} + +int mb_print_vprintf(const char *format, va_list va) +{ + char buffer[1]; + return mb_print_vsnprintf_int(mb_print_out_char, buffer, (size_t)-1, format, va); +} + +int mb_print_vsnprintf_(char *buffer, size_t count, const char *format, va_list va) +{ + return mb_print_vsnprintf_int(mb_print_out_buffer, buffer, count, format, va); +} + +int mb_print_fnprintf(void (*out)(char character, void *arg), void *arg, const char *format, ...) +{ + va_list va; + va_start(va, format); + const mb_print_out_fn_wrap_type out_fct_wrap = {out, arg}; + const int ret = mb_print_vsnprintf_int(mb_print_out_fn, (char *)(uintptr_t)&out_fct_wrap, (size_t)-1, format, va); + va_end(va); + return ret; +} + +#endif \ No newline at end of file diff --git a/lib/libesp32/ESP-Mail-Client/src/extras/mb_print/mb_print.h b/lib/libesp32/ESP-Mail-Client/src/extras/mb_print/mb_print.h new file mode 100644 index 000000000..5ec3727bd --- /dev/null +++ b/lib/libesp32/ESP-Mail-Client/src/extras/mb_print/mb_print.h @@ -0,0 +1,108 @@ +/////////////////////////////////////////////////////////////////////////////// +// \author (c) Marco Paland (info@paland.com) +// 2014-2019, PALANDesign Hannover, Germany +// +// \license The MIT License (MIT) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// +// \brief Tiny printf, sprintf and snprintf implementation, optimized for speed on +// embedded systems with a very limited resources. +// Use this instead of bloated standard/newlib printf. +// These routines are thread safe and reentrant. +// +/////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#ifndef _PRINTF_H_ +#define _PRINTF_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * Output a character to a custom device like UART, used by the printf() function + * This function is declared here only. You have to write your custom implementation somewhere + * \param character Character to output + */ + void mb_print_putchar(char character) __attribute__((used)); + + /** + * Tiny printf implementation + * You have to implement _putchar if you use printf() + * To avoid conflicts with the regular printf() API it is overridden by macro defines + * and internal underscore-appended functions like printf_() are used + * \param format A string that specifies the format of the output + * \return The number of characters that are written into the array, not counting the terminating null character + */ + int mb_print_printf(const char *format, ...) __attribute__((used)); + + /** + * Tiny sprintf implementation + * Due to security reasons (buffer overflow) YOU SHOULD CONSIDER USING (V)SNPRINTF INSTEAD! + * \param buffer A pointer to the buffer where to store the formatted string. MUST be big enough to store the output! + * \param format A string that specifies the format of the output + * \return The number of characters that are WRITTEN into the buffer, not counting the terminating null character + */ + int mb_print_sprintf(char *buffer, const char *format, ...) __attribute__((used)); + + /** + * Tiny snprintf/vsnprintf implementation + * \param buffer A pointer to the buffer where to store the formatted string + * \param count The maximum number of characters to store in the buffer, including a terminating null character + * \param format A string that specifies the format of the output + * \param va A value identifying a variable arguments list + * \return The number of characters that COULD have been written into the buffer, not counting the terminating + * null character. A value equal or larger than count indicates truncation. Only when the returned value + * is non-negative and less than count, the string has been completely written. + */ +#define mb_print_snprintf mb_print_snprintf_ +#define mb_print_vsnprintf mb_print_vsnprintf_ + int mb_print_snprintf_(char *buffer, size_t count, const char *format, ...) __attribute__((used)); + int mb_print_vsnprintf_(char *buffer, size_t count, const char *format, va_list va) __attribute__((used)); + + /** + * Tiny vprintf implementation + * \param format A string that specifies the format of the output + * \param va A value identifying a variable arguments list + * \return The number of characters that are WRITTEN into the buffer, not counting the terminating null character + */ + int mb_print_vprintf(const char *format, va_list va) __attribute__((used)); + + /** + * printf with output function + * You may use this as dynamic alternative to printf() with its fixed _putchar() output + * \param out An output function which takes one character and an argument pointer + * \param arg An argument pointer for user data passed to output function + * \param format A string that specifies the format of the output + * \return The number of characters that are sent to the output function, not counting the terminating null character + */ + int mb_print_fnprintf(void (*out)(char character, void *arg), void *arg, const char *format, ...) __attribute__((used)); + +#ifdef __cplusplus +} +#endif + +#endif // _PRINTF_H_ \ No newline at end of file diff --git a/lib/libesp32/lib_mail/.github/FUNDING.yml b/lib/libesp32/lib_mail/.github/FUNDING.yml deleted file mode 100644 index c6f438926..000000000 --- a/lib/libesp32/lib_mail/.github/FUNDING.yml +++ /dev/null @@ -1,12 +0,0 @@ -# These are supported funding model platforms - -github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] -patreon: # Replace with a single Patreon username -open_collective: # Replace with a single Open Collective username -ko_fi: # Replace with a single Ko-fi username -tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel -community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry -liberapay: # Replace with a single Liberapay username -issuehunt: # Replace with a single IssueHunt username -otechie: # Replace with a single Otechie username -custom: ["https://www.paypal.me/mobizt"] # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] diff --git a/lib/libesp32/lib_mail/.github/stale.yml b/lib/libesp32/lib_mail/.github/stale.yml deleted file mode 100644 index 73494a333..000000000 --- a/lib/libesp32/lib_mail/.github/stale.yml +++ /dev/null @@ -1,17 +0,0 @@ -# Number of days of inactivity before an issue becomes stale -daysUntilStale: 20 -# Number of days of inactivity before a stale issue is closed -daysUntilClose: 5 -# Issues with these labels will never be considered stale -exemptLabels: - - pinned - - security -# Label to use when marking an issue as stale -staleLabel: wontfix -# Comment to post when marking an issue as stale. Set to `false` to disable -markComment: > - This issue has been automatically marked as stale because it has not had - recent activity. It will be closed if no further activity occurs. Thank you - for your contributions. -# Comment to post when closing a stale issue. Set to `false` to disable -closeComment: false diff --git a/lib/libesp32/lib_mail/README.md b/lib/libesp32/lib_mail/README.md deleted file mode 100644 index 6025aec0e..000000000 --- a/lib/libesp32/lib_mail/README.md +++ /dev/null @@ -1,385 +0,0 @@ -# Mail Client Arduino Library for ESP32 and ESP8266 v 1.2.0 - -[![Join the chat at https://gitter.im/mobizt/ESP_Mail_Client](https://badges.gitter.im/mobizt/ESP_Mail_Client.svg)](https://gitter.im/mobizt/ESP_Mail_Client?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) - -The complete and secure Mail Client for ESP32 and ESP8266 devices for sending and reading the Email through the SMTP and IMAP servers. - -With this library, the devices can both send and read the Email with many types of attachments supported and provides more reliable and flexibilities of usages. - -The library was tested and work well with ESP32s and ESP8266s based modules. - -This library was developed to replace the deprecated ESP32 Mail Client library with more options and features, better reliability and also conforms to the RFC standards. - -![ESP Mail](/media/images/esp-mail-client.svg) - -Copyright (c) 2021 K. Suwatchai (Mobizt). - -# Features - -* Support Espressif ESP32 and ESP8266 MCUs based devices. -* Support TCP session reusage. -* Support PLAIN, LOGIN and XOAUTH2 authentication mechanisms. -* Support secured (with SSL and TLS) and non-secure ports. -* Support mailbox selection for Email reading and searching. -* Support the content encodings e.g. quoted-printable and base64. -* Support the content decodings e.g. base64, UTF-8, UTF-7, quoted-printable, ISO-8859-1 (latin1) and ISO-8859-11 (Thai). -* Support many types of embedded contents e.g. inline images, attachments, parallel media attachments and RFC822 message. -* Support full debuging. -* Support flash memory and SD card for file storages which can be changed in [**ESP_Mail_FS.h**](/src/ESP_Mail_FS.h). -* Support Ethernet (ESP32 using LAN8720, TLK110 and IP101 Ethernet boards). ESP8266 Ethernet is not yet supported. -* Customizable operating configurations (see the examples for the usages) - -## Tested Devices - -This following devices were tested. - - * Sparkfun ESP32 Thing - * NodeMCU-32 - * WEMOS LOLIN32 - * TTGO T8 V1.8 - * M5Stack ESP32 - * NodeMCU ESP8266 - * Wemos D1 Mini (ESP8266) - - - -## Prerequisites - - -The library requires Arduino's ESP32 or ESP8266 Core SDK to be installed based on the platform. - -The latest Core SDK is recommended. For ESP8266, the Core SDK version 2.6.3 or later is recommended. - -The ESP8266 Core SDK version 2.5.x and earlier are not supported. - - - -## Instalation - - -Click on **Clone or download** dropdown at the top of repository, select **Download ZIP** and save file on your computer. - -From Arduino IDE, goto menu **Sketch** -> **Include Library** -> **Add .ZIP Library...** and choose **ESP-Mail-Client-master.zip** that previously downloaded. - -Go to menu **Files** -> **Examples** -> **ESP-Mail-Client-master** and choose one from examples - - - - - - -## IDE Configuaration for ESP8266 MMU - Adjust the Ratio of ICACHE to IRAM - -### Arduino IDE - -When you update the ESP8266 Arduino Core SDK to v3.0.0, the memory can be configurable from Arduino IDE board settings. - -By default MMU **option 1** was selected, the free Heap can be low and may not suitable for the SSL client usage in this library. - -To increase the Heap, choose the MMU **option 3**, 16KB cache + 48KB IRAM and 2nd Heap (shared). - -![Arduino IDE config](/media/images/ArduinoIDE.png) - - -More about MMU settings. -https://arduino-esp8266.readthedocs.io/en/latest/mmu.html - -### PlatformIO IDE - -When Core SDK v3.0.0 becomes available in PlatformIO, - -By default the balanced ratio (32KB cache + 32KB IRAM) configuration is used. - -To increase the heap, **PIO_FRAMEWORK_ARDUINO_MMU_CACHE16_IRAM48_SECHEAP_SHARED** build flag should be assigned in platformio.ini. - -At the time of writing, to update SDK to v3.0.0 you can follow these steps. - -1. In platformio.ini, edit the config as the following - -```ini -[env:d1_mini] -platform = https://github.com/platformio/platform-espressif8266.git -build_flags = -D PIO_FRAMEWORK_ARDUINO_MMU_CACHE16_IRAM48_SECHEAP_SHARED -board = d1_mini -framework = arduino -monitor_speed = 115200 -``` - -2. Delete this folder **C:\Users\UserName\\.platformio\platforms\espressif8266@src-?????????????** -3. Delete .pio and .vscode folders in your project. -4. Clean and Compile the project. - - - -The supportedd MMU build flags in PlatformIO. - -- **PIO_FRAMEWORK_ARDUINO_MMU_CACHE16_IRAM48** - - 16KB cache + 48KB IRAM (IRAM) - -- **PIO_FRAMEWORK_ARDUINO_MMU_CACHE16_IRAM48_SECHEAP_SHARED** - - 16KB cache + 48KB IRAM and 2nd Heap (shared) - -- **PIO_FRAMEWORK_ARDUINO_MMU_CACHE16_IRAM32_SECHEAP_NOTSHARED** - - 16KB cache + 32KB IRAM + 16KB 2nd Heap (not shared) - -- **PIO_FRAMEWORK_ARDUINO_MMU_EXTERNAL_128K** - - 128K External 23LC1024 - -- **PIO_FRAMEWORK_ARDUINO_MMU_EXTERNAL_1024K** - - 1M External 64 MBit PSRAM - -- **PIO_FRAMEWORK_ARDUINO_MMU_CUSTOM** - - Disables default configuration and expects user-specified flags - - -### Test code for MMU - -```cpp - -#include -#include - -void setup() -{ - Serial.begin(74880); - HeapSelectIram ephemeral; - Serial.printf("IRAM free: %6d bytes\r\n", ESP.getFreeHeap()); - { - HeapSelectDram ephemeral; - Serial.printf("DRAM free: %6d bytes\r\n", ESP.getFreeHeap()); - } -} - -void loop() { - // put your main code here, to run repeatedly: -} - -``` - - - - - - -## Usage - - -See [Full Examples](/examples) for complete usages. - -See [Function Description](/src/README.md) for all available functions. - - -The following examples showed the minimum usage which many options are not configured. - -The examples in the examples folder provide the full options usages. - -## Notes - -The string in the function's parameters or properties of structured data is the pointer to constant char or char array. - -You need to assign the string literal or char array or pointer to constant char to it. - -#### Ex. - -```cpp -message.sender.name = "My Mail"; -message.sender.email = "sender or your Email address"; -``` - -Or using String class - -```cpp -String name = "John"; -String email = "john@mail.com"; - -message.sender.name = name.c_str(); -message.sender.email = email.c_str(); -``` - - - - -### Send the Email - - -```C++ - -// Include ESP Mail Client library (this library) -#include - - -// Define the SMTP Session object which used for SMTP transsport -SMTPSession smtp; - -// Define the session config data which used to store the TCP session configuration -ESP_Mail_Session session; - -// Set the session config -session.server.host_name = "smtp.office365.com"; //for outlook.com -session.server.port = 587; -session.login.email = "your Email address"; //set to empty for no SMTP Authentication -session.login.password = "your Email password"; //set to empty for no SMTP Authentication -session.login.user_domain = "client domain or ip e.g. mydomain.com"; - -// Define the SMTP_Message class variable to handle to message being transport -SMTP_Message message; - -// Set the message headers -message.sender.name = "My Mail"; -message.sender.email = "sender or your Email address"; -message.subject = "Test sending Email"; -message.addRecipient("name1", "email1"); -message.addRecipient("name2", "email2"); - -message.addCc("email3"); -message.addBcc("email4"); - -// Set the message content -message.text.content = "This is simple plain text message"; - -//Base64 data of image -const char *greenImg = "iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAAoUlEQVR42u3RAQ0AMAgAoJviyWxtAtNYwzmoQGT/eqwRQoQgRAhChCBECEKECBGCECEIEYIQIQgRghCECEGIEIQIQYgQhCBECEKEIEQIQoQgBCFCECIEIUIQIgQhCBGCECEIEYIQIQhBiBCECEGIEIQIQQhChCBECEKEIEQIQhAiBCFCECIEIUIQghAhCBGCECEIEYIQIUKEIEQIQoQg5LoBBaDPbQYiMoMAAAAASUVORK5CYII="; - -// Define the attachment data -SMTP_Attachment att; - -// Set the attatchment info -att.descr.filename = "green.png"; -att.descr.mime = "image/png"; -att.blob.data = (uint8_t *)greenImg; -att.blob.size = strlen(greenImg); -// Set the transfer encoding to base64 -att.descr.transfer_encoding = Content_Transfer_Encoding::enc_base64; -// We set the content encoding to match the above greenImage data -att.descr.content_encoding = Content_Transfer_Encoding::enc_base64; - -// Add attachment to the message -message.addAttachment(att); - -// Connect to server with the session config -smtp.connect(&session); - -// Start sending Email and close the session -if (!MailClient.sendMail(&smtp, &message)) - Serial.println("Error sending Email, " + smtp.errorReason()); - - -``` - - -### Read the Email - - -```C++ - -// Include ESP Mail Client library (this library) -#include - - -// Define the IMAP Session object which used for IMAP transsport -IMAP_Config config; - - -// Define the session config data which used to store the TCP session configuration -ESP_Mail_Session session; - -// Set the session config -session.server.host_name = "outlook.office365.com"; //for outlook.com -session.server.port = 993; -session.login.email = "your Email address"; -session.login.password = "your Email password"; - -// Define the config class variable for searching or fetching operation and store the messsagess data -IMAP_Config config; - -// Define the message UID which required to fetch or read the message -config.fetch.uid = "100"; - -// Define the empty search criteria to disable the messsage search -config.search.criteria = ""; - -// Set to enable the message content which will be stored in the IMAP_Config data -config.enable.html = true; -config.enable.text = true; - - -// Connect to the server with the defined session and options -imap.connect(&session, &config); - -// Open or select the mailbox folder to read the message -imap.selectFolder("INBOX"); - - -// Read the Email and close the session -MailClient.readMail(&imap); - - -// Get the message(s) list -IMAP_MSG_List msgList = imap.data(); - -for (size_t i = 0; i < msgList.msgItems.size(); i++) -{ - // Iterate to get each message data through the message item data - IMAP_MSG_Item msg = msgList.msgItems[i]; - - Serial.println("################################"); - Serial.printf("Messsage Number: %s\n", msg.msgNo); - Serial.printf("Messsage UID: %s\n", msg.UID); - Serial.printf("Messsage ID: %s\n", msg.ID); - Serial.printf("Accept Language: %s\n", msg.acceptLang); - Serial.printf("Content Language: %s\n", msg.contentLang); - Serial.printf("From: %s\n", msg.from); - Serial.printf("From Charset: %s\n", msg.fromCharset); - Serial.printf("To: %s\n", msg.to); - Serial.printf("To Charset: %s\n", msg.toCharset); - Serial.printf("CC: %s\n", msg.cc); - Serial.printf("CC Charset: %s\n", msg.ccCharset); - Serial.printf("Date: %s\n", msg.date); - Serial.printf("Subject: %s\n", msg.subject); - Serial.printf("Subject Charset: %s\n", msg.subjectCharset); - - // If the message body is available - if (!imap.headerOnly()) - { - Serial.printf("Text Message: %s\n", msg.text.content); - Serial.printf("Text Message Charset: %s\n", msg.text.charSet); - Serial.printf("Text Message Transfer Encoding: %s\n", msg.text.transfer_encoding); - Serial.printf("HTML Message: %s\n", msg.html.content); - Serial.printf("HTML Message Charset: %s\n", msg.html.charSet); - Serial.printf("HTML Message Transfer Encoding: %s\n\n", msg.html.transfer_encoding); - } -} - -``` - - - -## License - -The MIT License (MIT) - -Copyright (c) 2021 K. Suwatchai (Mobizt) - - -Permission is hereby granted, free of charge, to any person returning a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software is furnished to do so, -subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/lib/libesp32/lib_mail/examples/Copy_Messages/Copy_Messsages.ino b/lib/libesp32/lib_mail/examples/Copy_Messages/Copy_Messsages.ino deleted file mode 100644 index 539a0956a..000000000 --- a/lib/libesp32/lib_mail/examples/Copy_Messages/Copy_Messsages.ino +++ /dev/null @@ -1,147 +0,0 @@ -/** - * This example showed how to copy messages from the opened mailbox folder to other folder. - * - * Email: suwatchai@outlook.com - * - * Github: https://github.com/mobizt/ESP-Mail-Client - * - * Copyright (c) 2021 mobizt - * -*/ - -/** To receive Email using Gmail, IMAP option should be enabled. https://support.google.com/mail/answer/7126229?hl=en - * and also https://accounts.google.com/b/0/DisplayUnlockCaptcha - * -*/ - -/** For ESP8266, with BearSSL WiFi Client - * The memory reserved for completed valid SSL response from IMAP is 16 kbytes which - * may cause your device out of memory reset in case the memory - * allocation error. -*/ - -#include -#if defined(ESP32) -#include -#elif defined(ESP8266) -#include -#endif -#include - -#define WIFI_SSID "################" -#define WIFI_PASSWORD "################" - -/* The imap host name e.g. imap.gmail.com for GMail or outlook.office365.com for Outlook */ -#define IMAP_HOST "################" - -/** The imap port e.g. - * 143 or esp_mail_imap_port_143 - * 993 or esp_mail_imap_port_993 -*/ -#define IMAP_PORT 993 - -/* The log in credentials */ -#define AUTHOR_EMAIL "################" -#define AUTHOR_PASSWORD "################" - -/* Print the list of mailbox folders */ -void printAllMailboxesInfo(IMAPSession &imap); - -/* Print the selected folder info */ -void printSelectedMailboxInfo(IMAPSession &imap); - -/* The IMAP Session object used for Email reading */ -IMAPSession imap; - - -void setup() -{ - - Serial.begin(115200); - Serial.println(); - - Serial.print("Connecting to AP"); - - WiFi.begin(WIFI_SSID, WIFI_PASSWORD); - while (WiFi.status() != WL_CONNECTED) - { - Serial.print("."); - delay(200); - } - - Serial.println(""); - Serial.println("WiFi connected."); - Serial.println("IP address: "); - Serial.println(WiFi.localIP()); - Serial.println(); - - /** Enable the debug via Serial port - * none debug or 0 - * basic debug or 1 - */ - imap.debug(1); - - /* Declare the session config data */ - ESP_Mail_Session session; - - /* Set the session config */ - session.server.host_name = IMAP_HOST; - session.server.port = IMAP_PORT; - session.login.email = AUTHOR_EMAIL; - session.login.password = AUTHOR_PASSWORD; - - - /* Setup the configuration for searching or fetching operation and its result */ - IMAP_Config config; - - /* Connect to server with the session and config */ - if (!imap.connect(&session, &config)) - return; - - /* {Optional] */ - printAllMailboxesInfo(imap); - - /* Open or select the mailbox folder to read or search the message */ - if (!imap.selectFolder("INBOX")) - return; - - /* Define the MessageList class to add the message to copy */ - MessageList toCopy; - - /* Add message uid to copy to the list */ - toCopy.add(3); - toCopy.add(4); - - //imap.createFolder("test"); - - /* Copy all messages in the list to the folder "test" */ - if (imap.deleteMessages(&toCopy, "test")) - Serial.println("Messages copied"); - - /* Delete all messages in the list from the opened folder (move to trash) */ - //imap.deleteMessages(&toCopy); - - //imap.deleteolder("test"); -} - -void loop() -{ - -} - -void printAllMailboxesInfo(IMAPSession &imap) -{ - /* Declare the folder collection class to get the list of mailbox folders */ - FoldersCollection folders; - - /* Get the mailbox folders */ - if (imap.getFolders(folders)) - { - for (size_t i = 0; i < folders.size(); i++) - { - /* Iterate each folder info using the folder info item data */ - FolderInfo folderInfo = folders.info(i); - Serial.printf("%s%s%s", i == 0 ? "\nAvailable folders: " : ", ", folderInfo.name, i == folders.size() - 1 ? "\n" : ""); - } - } -} diff --git a/lib/libesp32/lib_mail/examples/Delete_Messages/Delete_Messsages.ino b/lib/libesp32/lib_mail/examples/Delete_Messages/Delete_Messsages.ino deleted file mode 100644 index f52e3c708..000000000 --- a/lib/libesp32/lib_mail/examples/Delete_Messages/Delete_Messsages.ino +++ /dev/null @@ -1,142 +0,0 @@ -/** - * This example showed how to delete messages from the opened mailbox folder. - * - * Email: suwatchai@outlook.com - * - * Github: https://github.com/mobizt/ESP-Mail-Client - * - * Copyright (c) 2021 mobizt - * -*/ - -/** To receive Email using Gmail, IMAP option should be enabled. https://support.google.com/mail/answer/7126229?hl=en - * and also https://accounts.google.com/b/0/DisplayUnlockCaptcha - * -*/ - -/** For ESP8266, with BearSSL WiFi Client - * The memory reserved for completed valid SSL response from IMAP is 16 kbytes which - * may cause your device out of memory reset in case the memory - * allocation error. -*/ - -#include -#if defined(ESP32) -#include -#elif defined(ESP8266) -#include -#endif -#include - -#define WIFI_SSID "################" -#define WIFI_PASSWORD "################" - -/* The imap host name e.g. imap.gmail.com for GMail or outlook.office365.com for Outlook */ -#define IMAP_HOST "################" - -/** The imap port e.g. - * 143 or esp_mail_imap_port_143 - * 993 or esp_mail_imap_port_993 -*/ -#define IMAP_PORT 993 - -/* The log in credentials */ -#define AUTHOR_EMAIL "################" -#define AUTHOR_PASSWORD "################" - -/* Print the list of mailbox folders */ -void printAllMailboxesInfo(IMAPSession &imap); - -/* Print the selected folder info */ -void printSelectedMailboxInfo(IMAPSession &imap); - -/* The IMAP Session object used for Email reading */ -IMAPSession imap; - - -void setup() -{ - - Serial.begin(115200); - Serial.println(); - - Serial.print("Connecting to AP"); - - WiFi.begin(WIFI_SSID, WIFI_PASSWORD); - while (WiFi.status() != WL_CONNECTED) - { - Serial.print("."); - delay(200); - } - - Serial.println(""); - Serial.println("WiFi connected."); - Serial.println("IP address: "); - Serial.println(WiFi.localIP()); - Serial.println(); - - /** Enable the debug via Serial port - * none debug or 0 - * basic debug or 1 - */ - imap.debug(1); - - /* Declare the session config data */ - ESP_Mail_Session session; - - /* Set the session config */ - session.server.host_name = IMAP_HOST; - session.server.port = IMAP_PORT; - session.login.email = AUTHOR_EMAIL; - session.login.password = AUTHOR_PASSWORD; - - - /* Setup the configuration for searching or fetching operation and its result */ - IMAP_Config config; - - /* Connect to server with the session and config */ - if (!imap.connect(&session, &config)) - return; - - /* {Optional] */ - printAllMailboxesInfo(imap); - - /* Open or select the mailbox folder to read or search the message */ - if (!imap.selectFolder("INBOX")) - return; - - /* Define the MessageList class to add the message to delete */ - MessageList toDelete; - /* Add message uid to delete to the list */ - toDelete.add(10); - toDelete.add(12); - - /* Delete all messages in the list (move to trash) */ - if(imap.deleteMessages(&toDelete)) - Serial.println("Messages deeted"); - - /* Delete all messages permanently by assign the second param to true*/ - //imap.deleteMessages(&toDelete, true); -} - -void loop() -{ - -} - -void printAllMailboxesInfo(IMAPSession &imap) -{ - /* Declare the folder collection class to get the list of mailbox folders */ - FoldersCollection folders; - - /* Get the mailbox folders */ - if (imap.getFolders(folders)) - { - for (size_t i = 0; i < folders.size(); i++) - { - /* Iterate each folder info using the folder info item data */ - FolderInfo folderInfo = folders.info(i); - Serial.printf("%s%s%s", i == 0 ? "\nAvailable folders: " : ", ", folderInfo.name, i == folders.size() - 1 ? "\n" : ""); - } - } -} diff --git a/lib/libesp32/lib_mail/examples/ESP32_Ethernet_Send_Text/ESP32_Ethernet_Send_Text.ino b/lib/libesp32/lib_mail/examples/ESP32_Ethernet_Send_Text/ESP32_Ethernet_Send_Text.ino deleted file mode 100644 index 3dc3192de..000000000 --- a/lib/libesp32/lib_mail/examples/ESP32_Ethernet_Send_Text/ESP32_Ethernet_Send_Text.ino +++ /dev/null @@ -1,307 +0,0 @@ - - -/** - * This example will send the Email in plain text version using ESP32 and LAN8720 Ethernet module. - * - * Created by K. Suwatchai (Mobizt) - * - * Email: suwatchai@outlook.com - * - * Github: https://github.com/mobizt/ESP-Mail-Client - * - * Copyright (c) 2021 mobizt - * -*/ - -/** - * There are many sources for LAN8720 and ESP32 interconnection on the internet which may - * work for your LAN8720 board. - * - * Some methods worked unless no IP is available. - * - * This modification and interconnection provided in this example are mostly worked as - * the 50 MHz clock was created internally in ESP32 which GPIO 17 is set to be output of this clock - * and feeds to the LAN8720 chip XTAL input. - * - * The on-board LAN8720 50 MHz XTAL chip will be disabled by connect its enable pin or pin 1 to GND. - * - * Please see the images in the folder "modified_LAN8720_board_images" for how to modify the LAN8720 board. - * - * The LAN8720 Ethernet modified board and ESP32 board wiring connection. - * - * ESP32 LAN8720 - * - * GPIO17 - EMAC_CLK_OUT_180 nINT/REFCLK - LAN8720 XTAL1/CLKIN 4k7 Pulldown - * GPIO22 - EMAC_TXD1 TX1 - * GPIO19 - EMAC_TXD0 TX0 - * GPIO21 - EMAC_TX_EN TX_EN - * GPIO26 - EMAC_RXD1 RX1 - * GPIO25 - EMAC_RXD0 RX0 - * GPIO27 - EMAC_RX_DV CRS - * GPIO23 - MDC MDC - * GPIO18 - MDIO MDIO - * GND GND - * 3V3 VCC - * -*/ - -//In case of Gmail, to send the Email via port 465 (SSL), less secure app option should be enabled in the account settings. https://myaccount.google.com/lesssecureapps?pli=1 - -#include -#include - -#ifdef ETH_CLK_MODE -#undef ETH_CLK_MODE -#endif -#define ETH_CLK_MODE ETH_CLOCK_GPIO17_OUT //RMII clock output from GPIO17 - -// Pin# of the enable signal for the external crystal oscillator (-1 to disable) -#define ETH_POWER_PIN -1 - -// Type of the Ethernet PHY (LAN8720 or TLK110) -#define ETH_TYPE ETH_PHY_LAN8720 - -// I²C-address of Ethernet PHY (0 or 1 for LAN8720, 31 for TLK110) -#define ETH_ADDR 1 - -// Pin# of the I²C clock signal for the Ethernet PHY -#define ETH_MDC_PIN 23 - -// Pin# of the I²C IO signal for the Ethernet PHY -#define ETH_MDIO_PIN 18 - -static bool eth_connected = false; - - -/** The smtp host name e.g. smtp.gmail.com for GMail or smtp.office365.com for Outlook or smtp.mail.yahoo.com - * For yahoo mail, log in to your yahoo mail in web browser and generate app password by go to - * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc - * and use the app password as password with your yahoo mail account to login. - * The google app password signin is also available https://support.google.com/mail/answer/185833?hl=en -*/ -#define SMTP_HOST "################" - -/** The smtp port e.g. - * 25 or esp_mail_smtp_port_25 - * 465 or esp_mail_smtp_port_465 - * 587 or esp_mail_smtp_port_587 -*/ -#define SMTP_PORT 25 - -/* The sign in credentials */ -#define AUTHOR_EMAIL "################" -#define AUTHOR_PASSWORD "################" - -/* The SMTP Session object used for Email sending */ -SMTPSession smtp; - -/* Callback function to get the Email sending status */ -void smtpCallback(SMTP_Status status); - -unsigned long sendMillis = 0; - -void WiFiEvent(WiFiEvent_t event) -{ - //Do not run any function here to prevent stack overflow or nested interrupt - switch (event) - { - case SYSTEM_EVENT_ETH_START: - Serial.println("ETH Started"); - //set eth hostname here - ETH.setHostname("esp32-ethernet"); - - break; - case SYSTEM_EVENT_ETH_CONNECTED: - Serial.println("ETH Connected"); - break; - case SYSTEM_EVENT_ETH_GOT_IP: - Serial.print("ETH MAC: "); - Serial.print(ETH.macAddress()); - Serial.print(", IPv4: "); - Serial.print(ETH.localIP()); - if (ETH.fullDuplex()) - { - Serial.print(", FULL_DUPLEX"); - } - Serial.print(", "); - Serial.print(ETH.linkSpeed()); - Serial.println("Mbps"); - eth_connected = true; - - break; - case SYSTEM_EVENT_ETH_DISCONNECTED: - Serial.println("ETH Disconnected"); - eth_connected = false; - break; - case SYSTEM_EVENT_ETH_STOP: - Serial.println("ETH Stopped"); - eth_connected = false; - break; - default: - break; - } -} - -void sendMail() -{ - - /** Enable the debug via Serial port - * none debug or 0 - * basic debug or 1 - */ - smtp.debug(1); - - /* Set the callback function to get the sending results */ - smtp.callback(smtpCallback); - - /* Declare the session config data */ - ESP_Mail_Session session; - - /** ######################################################## - * Some properties of SMTPSession data and parameters pass to - * SMTP_Message class accept the pointer to constant char - * i.e. const char*. - * - * You may assign a string literal to that properties or function - * like below example. - * - * session.login.user_domain = "mydomain.net"; - * session.login.user_domain = String("mydomain.net").c_str(); - * - * or - * - * String doman = "mydomain.net"; - * session.login.user_domain = domain.c_str(); - * - * And - * - * String name = "Jack " + String("dawson"); - * String email = "jack_dawson" + String(123) + "@mail.com"; - * - * message.addRecipient(name.c_str(), email.c_str()); - * - * message.addHeader(String("Message-ID: ").c_str()); - * - * or - * - * String header = "Message-ID: "; - * message.addHeader(header.c_str()); - * - * ########################################################### - */ - - /* Set the session config */ - session.server.host_name = SMTP_HOST; - session.server.port = SMTP_PORT; - session.login.email = AUTHOR_EMAIL; - session.login.password = AUTHOR_PASSWORD; - session.login.user_domain = "mydomain.net"; - - /* Declare the message class */ - SMTP_Message message; - - /* Set the message headers */ - message.sender.name = "ESP Mail"; - message.sender.email = AUTHOR_EMAIL; - message.subject = "Test sending plain text Email"; - message.addRecipient("Someone", "####@#####_dot_com"); - - String textMsg = "This is simple plain text message"; - message.text.content = textMsg.c_str(); - - /** The Plain text message character set e.g. - * us-ascii - * utf-8 - * utf-7 - * The default value is utf-8 - */ - message.text.charSet = "us-ascii"; - - /** The content transfer encoding e.g. - * enc_7bit or "7bit" (not encoded) - * enc_qp or "quoted-printable" (encoded) - * enc_base64 or "base64" (encoded) - * enc_binary or "binary" (not encoded) - * enc_8bit or "8bit" (not encoded) - * The default value is "7bit" - */ - message.text.transfer_encoding = Content_Transfer_Encoding::enc_7bit; - - /** The message priority - * esp_mail_smtp_priority_high or 1 - * esp_mail_smtp_priority_normal or 3 - * esp_mail_smtp_priority_low or 5 - * The default value is esp_mail_smtp_priority_low - */ - message.priority = esp_mail_smtp_priority::esp_mail_smtp_priority_low; - - /** The Delivery Status Notifications e.g. - * esp_mail_smtp_notify_never - * esp_mail_smtp_notify_success - * esp_mail_smtp_notify_failure - * esp_mail_smtp_notify_delay - * The default value is esp_mail_smtp_notify_never - */ - message.response.notify = esp_mail_smtp_notify_success | esp_mail_smtp_notify_failure | esp_mail_smtp_notify_delay; - - /* Set the custom message header */ - message.addHeader("Message-ID: "); - - /* Connect to server with the session config */ - if (!smtp.connect(&session)) - return; - - /* Start sending Email and close the session */ - if (!MailClient.sendMail(&smtp, &message)) - Serial.println("Error sending Email, " + smtp.errorReason()); -} - -void setup() -{ - Serial.begin(115200); - Serial.println(); - - WiFi.onEvent(WiFiEvent); - - ETH.begin(ETH_ADDR, ETH_POWER_PIN, ETH_MDC_PIN, ETH_MDIO_PIN, ETH_TYPE, ETH_CLK_MODE); -} - -void loop() -{ - if (eth_connected && (millis() - sendMillis > 300000 || sendMillis == 0)) - { - sendMillis = millis(); - sendMail(); - } -} - -/* Callback function to get the Email sending status */ -void smtpCallback(SMTP_Status status) -{ - /* Print the current status */ - Serial.println(status.info()); - - /* Print the sending result */ - if (status.success()) - { - Serial.println("----------------"); - Serial.printf("Message sent success: %d\n", status.completedCount()); - Serial.printf("Message sent failled: %d\n", status.failedCount()); - Serial.println("----------------\n"); - struct tm dt; - - for (size_t i = 0; i < smtp.sendingResult.size(); i++) - { - /* Get the result item */ - SMTP_Result result = smtp.sendingResult.getItem(i); - localtime_r(&result.timesstamp, &dt); - - Serial.printf("Message No: %d\n", i + 1); - Serial.printf("Status: %s\n", result.completed ? "success" : "failed"); - Serial.printf("Date/Time: %d/%d/%d %d:%d:%d\n", dt.tm_year + 1900, dt.tm_mon + 1, dt.tm_mday, dt.tm_hour, dt.tm_min, dt.tm_sec); - Serial.printf("Recipient: %s\n", result.recipients); - Serial.printf("Subject: %s\n", result.subject); - } - Serial.println("----------------\n"); - } -} diff --git a/lib/libesp32/lib_mail/examples/Read_Email_Access_Token/Read_Email_Access_Token.ino b/lib/libesp32/lib_mail/examples/Read_Email_Access_Token/Read_Email_Access_Token.ino deleted file mode 100644 index 6778e6cbe..000000000 --- a/lib/libesp32/lib_mail/examples/Read_Email_Access_Token/Read_Email_Access_Token.ino +++ /dev/null @@ -1,370 +0,0 @@ -/** - * This example will log in with the SASL XOAUTH2 mechanisme using OAuth2.0 access token. - * - * Created by K. Suwatchai (Mobizt) - * - * Email: suwatchai@outlook.com - * - * Github: https://github.com/mobizt/ESP-Mail-Client - * - * Copyright (c) 2021 mobizt - * -*/ - -/** To receive Email using Gmail, IMAP option should be enabled. https://support.google.com/mail/answer/7126229?hl=en - * and also https://accounts.google.com/b/0/DisplayUnlockCaptcha - * -*/ - -/** For ESP8266, with BearSSL WiFi Client - * The memory reserved for completed valid SSL response from IMAP is 16 kbytes which - * may cause your device out of memory reset in case the memory - * allocation error. -*/ - -#include -#if defined(ESP32) -#include -#elif defined(ESP8266) -#include -#endif -#include - -#define WIFI_SSID "################" -#define WIFI_PASSWORD "################" - -/* The imap host name e.g. imap.gmail.com for GMail or outlook.office365.com for Outlook */ -#define IMAP_HOST "################" - -/** The imap port e.g. - * 143 or esp_mail_imap_port_143 - * 993 or esp_mail_imap_port_993 -*/ -#define IMAP_PORT 993 - -/* The user Email for OAuth2.0 access token */ -#define AUTHOR_EMAIL "################" - -/** The OAuth2.0 access token - * The generation, exchange and refresh of the access token are not available - * in this library. - * - * To test this using GMail, get the OAuth2.0 access token from this web site - * https://developers.google.com/oauthplayground/ - * - * 1. Select the following scope (in Step 1) from Gmail API V1 - * https://mail.google.com/ - * https://mail.google.com/ - * - * 2. Click Authorize APIs button. - * 3. Cick Exchangeauthorization code for tokens. - * 4. From the response, look at access_token from the JSON payload node. - * 5. Copy that access token and paste to the AUTHOR_ACCESS_TOKEN value. - * - * The token will be expired in 3600 seconds (1 Hr). - * The AUTHOR_EMAIL above is the Email address that you granted to access the Gmail services. -*/ -#define AUTHOR_ACCESS_TOKEN "################" - -/* Callback function to get the Email reading status */ -void imapCallback(IMAP_Status status); - -/* Print the list of mailbox folders */ -void printAllMailboxesInfo(IMAPSession &imap); - -/* Print the selected folder info */ -void printSelectedMailboxInfo(IMAPSession &imap); - -/* Print all messages from the message list */ -void printMessages(IMAPSession &imap); - -/* Print all rfc822 messages included in the message */ -void printRFC822Messages(IMAP_MSG_Item &msg); - -/* Print all attachments info from the message */ -void printAttacements(IMAP_MSG_Item &msg); - -/* The IMAP Session object used for Email reading */ -IMAPSession imap; - - -void setup() -{ - - Serial.begin(115200); - Serial.println(); - - Serial.print("Connecting to AP"); - - WiFi.begin(WIFI_SSID, WIFI_PASSWORD); - while (WiFi.status() != WL_CONNECTED) - { - Serial.print("."); - delay(200); - } - - Serial.println(""); - Serial.println("WiFi connected."); - Serial.println("IP address: "); - Serial.println(WiFi.localIP()); - Serial.println(); - - /** Enable the debug via Serial port - * none debug or 0 - * basic debug or 1 - */ - imap.debug(1); - - /* Set the callback function to get the reading results */ - imap.callback(imapCallback); - - /** In case the SD card/adapter was used for the file storagge, the SPI pins can be configure from - * MailClient.sdBegin function which may be different for ESP32 and ESP8266 - * For ESP32, assign all of SPI pins - * MailClient.sdBegin(14,2,15,13) - * Which SCK = 14, MISO = 2, MOSI = 15 and SS = 13 - * And for ESP8266, assign the CS pins of SPI port - * MailClient.sdBegin(15) - * Which pin 15 is the CS pin of SD card adapter - */ - - /* Declare the session config data */ - ESP_Mail_Session session; - - /* Set the session config */ - session.server.host_name = IMAP_HOST; - session.server.port = IMAP_PORT; - session.login.email = AUTHOR_EMAIL; - session.login.accessToken = AUTHOR_ACCESS_TOKEN; - - - /* Setup the configuration for searching or fetching operation and its result */ - IMAP_Config config; - - /* Message UID to fetch or read e.g. 100 */ - config.fetch.uid = "100"; - - /* Set seen flag*/ - //config.fetch.set_seen = true; - - /* Search criteria */ - config.search.criteria = ""; - - /* Also search the unseen message */ - config.search.unseen_msg = true; - - /* Set the storage to save the downloaded files and attachments */ - config.storage.saved_path = "/email_data"; - - /** The file storage type e.g. - * esp_mail_file_storage_type_none, - * esp_mail_file_storage_type_flash, and - * esp_mail_file_storage_type_sd - */ - config.storage.type = esp_mail_file_storage_type_flash; - - /** Set to download heades, text and html messaeges, - * attachments and inline images respectively. - */ - config.download.header = true; - config.download.text = true; - config.download.html = true; - config.download.attachment = true; - config.download.inlineImg = true; - - /** Set to enable the results i.e. html and text messaeges - * which the content stored in the IMAPSession object is limited - * by the option config.limit.msg_size. - * The whole message can be download through config.download.text - * or config.download.html which not depends on these enable options. - */ - config.enable.html = true; - config.enable.text = true; - - /* Set to enable the sort the result by message UID in the ascending order */ - config.enable.recent_sort = true; - - /* Set to report the download progress via the default serial port */ - config.enable.download_status = true; - - /* Set the limit of number of messages in the search results */ - config.limit.search = 5; - - /** Set the maximum size of message stored in - * IMAPSession object in byte - */ - config.limit.msg_size = 512; - - /** Set the maximum attachments and inline images files size - * that can be downloaded in byte. - * The file which its size is largger than this limit may be saved - * as truncated file. - */ - config.limit.attachment_size = 1024 * 1024 * 5; - - - /* Connect to server with the session and config */ - if (!imap.connect(&session, &config)) - return; - - /* {Optional] */ - printAllMailboxesInfo(imap); - - /* Open or select the mailbox folder to read or search the message */ - if (!imap.selectFolder("INBOX")) - return; - - /* {Optional] */ - printSelectedMailboxInfo(imap); - - /* Read or search the Email and close the session */ - MailClient.readMail(&imap); - - /* Clear all stored data in IMAPSession object */ - imap.empty(); -} - -void loop() -{ - -} - -/* Callback function to get the Email reading status */ -void imapCallback(IMAP_Status status) -{ - /* Print the current status */ - Serial.println(status.info()); - - /* Show the result when reading finished */ - if (status.success()) - { - /* Print the result */ - printMessages(imap); - - /* Clear all stored data in IMAPSession object */ - imap.empty(); - Serial.printf("Free Heap: %d", ESP.getFreeHeap()); - } -} - -void printAllMailboxesInfo(IMAPSession &imap) -{ - /* Declare the folder collection class to get the list of mailbox folders */ - FoldersCollection folders; - - /* Get the mailbox folders */ - if (imap.getFolders(folders)) - { - for (size_t i = 0; i < folders.size(); i++) - { - /* Iterate each folder info using the folder info item data */ - FolderInfo folderInfo = folders.info(i); - Serial.printf("%s%s%s", i == 0 ? "\nAvailable folders: " : ", ", folderInfo.name, i == folders.size() - 1 ? "\n" : ""); - } - } -} - -void printSelectedMailboxInfo(IMAPSession &imap) -{ - /* Declare the selected folder info class to get the info of selected mailbox folder */ - SelectedFolderInfo sFolder = imap.selectedFolder(); - - /* Show the mailbox info */ - Serial.printf("\nInfo of the selected folder\nTotal Messages: %d\n", sFolder.msgCount()); - Serial.printf("Predicted next UID: %d\n", sFolder.nextUID()); - for (size_t i = 0; i < sFolder.flagCount(); i++) - Serial.printf("%s%s%s", i == 0 ? "Flags: " : ", ", sFolder.flag(i).c_str(), i == sFolder.flagCount() - 1 ? "\n" : ""); -} - -void printRFC822Messages(IMAP_MSG_Item &msg) -{ - Serial.printf("RFC822 Messages: %d message(s)\n****************************\n", msg.rfc822.size()); - for (size_t j = 0; j < msg.rfc822.size(); j++) - { - IMAP_MSG_Item rfc822 = msg.rfc822[j]; - Serial.printf("%d. \n", j + 1); - Serial.printf("Messsage ID: %s\n", rfc822.messageID); - Serial.printf("From: %s\n", rfc822.from); - Serial.printf("Sender: %s\n", rfc822.sender); - Serial.printf("To: %s\n", rfc822.to); - Serial.printf("CC: %s\n", rfc822.cc); - Serial.printf("Subject: %s\n", rfc822.subject); - Serial.printf("Date: %s\n", rfc822.date); - Serial.printf("Reply-To: %s\n", rfc822.reply_to); - Serial.printf("Return-Path: %s\n", rfc822.return_path); - Serial.printf("Comment: %s\n", rfc822.comment); - Serial.printf("Keyword: %s\n", rfc822.keyword); - Serial.printf("Text Message: %s\n", rfc822.text.content); - Serial.printf("Text Message Charset: %s\n", rfc822.text.charSet); - Serial.printf("Text Message Transfer Encoding: %s\n", rfc822.text.transfer_encoding); - Serial.printf("HTML Message: %s\n", rfc822.html.content); - Serial.printf("HTML Message Charset: %s\n", rfc822.html.charSet); - Serial.printf("HTML Message Transfer Encoding: %s\n\n", rfc822.html.transfer_encoding); - - if (rfc822.attachments.size() > 0) - printAttacements(rfc822); - } -} - -void printAttacements(IMAP_MSG_Item &msg) -{ - Serial.printf("Attachment: %d file(s)\n****************************\n", msg.attachments.size()); - for (size_t j = 0; j < msg.attachments.size(); j++) - { - IMAP_Attach_Item att = msg.attachments[j]; - /** att.type can be - * esp_mail_att_type_none or 0 - * esp_mail_att_type_attachment or 1 - * esp_mail_att_type_inline or 2 - */ - Serial.printf("%d. Filename: %s, Name: %s, Size: %d, MIME: %s, Type: %s, Creation Date: %s\n", j + 1, att.filename, att.name, att.size, att.mime, att.type == esp_mail_att_type_attachment ? "attachment" : "inline", att.creationDate); - } - Serial.println(); -} - -void printMessages(IMAPSession &imap) -{ - /* Get the message list from the message list data */ - IMAP_MSG_List msgList = imap.data(); - - for (size_t i = 0; i < msgList.msgItems.size(); i++) - { - /* Iterate to get each message data through the message item data */ - IMAP_MSG_Item msg = msgList.msgItems[i]; - - Serial.println("################################"); - Serial.printf("Messsage Number: %s\n", msg.msgNo); - Serial.printf("Messsage UID: %s\n", msg.UID); - Serial.printf("Messsage ID: %s\n", msg.ID); - Serial.printf("Accept Language: %s\n", msg.acceptLang); - Serial.printf("Content Language: %s\n", msg.contentLang); - Serial.printf("From: %s\n", msg.from); - Serial.printf("From Charset: %s\n", msg.fromCharset); - Serial.printf("To: %s\n", msg.to); - Serial.printf("To Charset: %s\n", msg.toCharset); - Serial.printf("CC: %s\n", msg.cc); - Serial.printf("CC Charset: %s\n", msg.ccCharset); - Serial.printf("Date: %s\n", msg.date); - Serial.printf("Subject: %s\n", msg.subject); - Serial.printf("Subject Charset: %s\n", msg.subjectCharset); - - /* If the result contains the message info (Fetch mode) */ - if (!imap.headerOnly()) - { - Serial.printf("Text Message: %s\n", msg.text.content); - Serial.printf("Text Message Charset: %s\n", msg.text.charSet); - Serial.printf("Text Message Transfer Encoding: %s\n", msg.text.transfer_encoding); - Serial.printf("HTML Message: %s\n", msg.html.content); - Serial.printf("HTML Message Charset: %s\n", msg.html.charSet); - Serial.printf("HTML Message Transfer Encoding: %s\n\n", msg.html.transfer_encoding); - - if (msg.attachments.size() > 0) - printAttacements(msg); - - if (msg.rfc822.size() > 0) - printRFC822Messages(msg); - } - - Serial.println(); - } -} diff --git a/lib/libesp32/lib_mail/examples/Read_Single_Email/Read_Single_Email.ino b/lib/libesp32/lib_mail/examples/Read_Single_Email/Read_Single_Email.ino deleted file mode 100644 index 31fa6348c..000000000 --- a/lib/libesp32/lib_mail/examples/Read_Single_Email/Read_Single_Email.ino +++ /dev/null @@ -1,364 +0,0 @@ -/** - * This example will fetch or read the Email which the known message UID - * was used for fetching. - * - * Email: suwatchai@outlook.com - * - * Github: https://github.com/mobizt/ESP-Mail-Client - * - * Copyright (c) 2021 mobizt - * -*/ - -/** To receive Email using Gmail, IMAP option should be enabled. https://support.google.com/mail/answer/7126229?hl=en - * and also https://accounts.google.com/b/0/DisplayUnlockCaptcha - * -*/ - -/** For ESP8266, with BearSSL WiFi Client - * The memory reserved for completed valid SSL response from IMAP is 16 kbytes which - * may cause your device out of memory reset in case the memory - * allocation error. -*/ - -#include -#if defined(ESP32) -#include -#elif defined(ESP8266) -#include -#endif -#include - -#define WIFI_SSID "################" -#define WIFI_PASSWORD "################" - -/* The imap host name e.g. imap.gmail.com for GMail or outlook.office365.com for Outlook */ -#define IMAP_HOST "################" - -/** The imap port e.g. - * 143 or esp_mail_imap_port_143 - * 993 or esp_mail_imap_port_993 -*/ -#define IMAP_PORT 993 - -/* The log in credentials */ -#define AUTHOR_EMAIL "################" -#define AUTHOR_PASSWORD "################" - -/* Callback function to get the Email reading status */ -void imapCallback(IMAP_Status status); - -/* Print the list of mailbox folders */ -void printAllMailboxesInfo(IMAPSession &imap); - -/* Print the selected folder info */ -void printSelectedMailboxInfo(IMAPSession &imap); - -/* Print all messages from the message list */ -void printMessages(IMAPSession &imap); - -/* Print all rfc822 messages included in the message */ -void printRFC822Messages(IMAP_MSG_Item &msg); - -/* Print all attachments info from the message */ -void printAttacements(IMAP_MSG_Item &msg); - -/* The IMAP Session object used for Email reading */ -IMAPSession imap; - - -void setup() -{ - - Serial.begin(115200); - Serial.println(); - - Serial.print("Connecting to AP"); - - WiFi.begin(WIFI_SSID, WIFI_PASSWORD); - while (WiFi.status() != WL_CONNECTED) - { - Serial.print("."); - delay(200); - } - - Serial.println(""); - Serial.println("WiFi connected."); - Serial.println("IP address: "); - Serial.println(WiFi.localIP()); - Serial.println(); - - /** Enable the debug via Serial port - * none debug or 0 - * basic debug or 1 - */ - imap.debug(1); - - /* Set the callback function to get the reading results */ - imap.callback(imapCallback); - - /** In case the SD card/adapter was used for the file storagge, the SPI pins can be configure from - * MailClient.sdBegin function which may be different for ESP32 and ESP8266 - * For ESP32, assign all of SPI pins - * MailClient.sdBegin(14,2,15,13) - * Which SCK = 14, MISO = 2, MOSI = 15 and SS = 13 - * And for ESP8266, assign the CS pins of SPI port - * MailClient.sdBegin(15) - * Which pin 15 is the CS pin of SD card adapter - */ - - /* Declare the session config data */ - ESP_Mail_Session session; - - /** ######################################################## - * Some properties of IMAP_Config and ESP_Mail_Session data - * accept the pointer to constant char i.e. const char*. - * - * You may assign a string literal to that properties like - * below example. - * - * config.storage.saved_path = String("/email_data").c_str(); - * - * String folder = "INBOX"; - * imap.selectFolder(folder.c_str()); - * - * ########################################################### - */ - - /* Set the session config */ - session.server.host_name = IMAP_HOST; - session.server.port = IMAP_PORT; - session.login.email = AUTHOR_EMAIL; - session.login.password = AUTHOR_PASSWORD; - - - /* Setup the configuration for searching or fetching operation and its result */ - IMAP_Config config; - - /* Message UID to fetch or read e.g. 100 */ - config.fetch.uid = "100"; - - /* Set seen flag */ - //config.fetch.set_seen = true; - - /* Search criteria */ - config.search.criteria = ""; - - /* Also search the unseen message */ - config.search.unseen_msg = true; - - /* Set the storage to save the downloaded files and attachments */ - config.storage.saved_path = "/email_data"; - - /** The file storage type e.g. - * esp_mail_file_storage_type_none, - * esp_mail_file_storage_type_flash, and - * esp_mail_file_storage_type_sd - */ - config.storage.type = esp_mail_file_storage_type_flash; - - /** Set to download heades, text and html messaeges, - * attachments and inline images respectively. - */ - config.download.header = true; - config.download.text = true; - config.download.html = true; - config.download.attachment = true; - config.download.inlineImg = true; - - /** Set to enable the results i.e. html and text messaeges - * which the content stored in the IMAPSession object is limited - * by the option config.limit.msg_size. - * The whole message can be download through config.download.text - * or config.download.html which not depends on these enable options. - */ - config.enable.html = true; - config.enable.text = true; - - /* Set to enable the sort the result by message UID in the ascending order */ - config.enable.recent_sort = true; - - /* Set to report the download progress via the default serial port */ - config.enable.download_status = true; - - /* Set the limit of number of messages in the search results */ - config.limit.search = 5; - - /** Set the maximum size of message stored in - * IMAPSession object in byte - */ - config.limit.msg_size = 512; - - /** Set the maximum attachments and inline images files size - * that can be downloaded in byte. - * The file which its size is largger than this limit may be saved - * as truncated file. - */ - config.limit.attachment_size = 1024 * 1024 * 5; - - - /* Connect to server with the session and config */ - if (!imap.connect(&session, &config)) - return; - - /* {Optional] */ - printAllMailboxesInfo(imap); - - /* Open or select the mailbox folder to read or search the message */ - if (!imap.selectFolder("INBOX")) - return; - - /* {Optional] */ - printSelectedMailboxInfo(imap); - - /* Read or search the Email and close the session */ - MailClient.readMail(&imap); - - /* Clear all stored data in IMAPSession object */ - imap.empty(); -} - -void loop() -{ - -} - -/* Callback function to get the Email reading status */ -void imapCallback(IMAP_Status status) -{ - /* Print the current status */ - Serial.println(status.info()); - - /* Show the result when reading finished */ - if (status.success()) - { - /* Print the result */ - printMessages(imap); - - /* Clear all stored data in IMAPSession object */ - imap.empty(); - Serial.printf("Free Heap: %d", ESP.getFreeHeap()); - } -} - -void printAllMailboxesInfo(IMAPSession &imap) -{ - /* Declare the folder collection class to get the list of mailbox folders */ - FoldersCollection folders; - - /* Get the mailbox folders */ - if (imap.getFolders(folders)) - { - for (size_t i = 0; i < folders.size(); i++) - { - /* Iterate each folder info using the folder info item data */ - FolderInfo folderInfo = folders.info(i); - Serial.printf("%s%s%s", i == 0 ? "\nAvailable folders: " : ", ", folderInfo.name, i == folders.size() - 1 ? "\n" : ""); - } - } -} - -void printSelectedMailboxInfo(IMAPSession &imap) -{ - /* Declare the selected folder info class to get the info of selected mailbox folder */ - SelectedFolderInfo sFolder = imap.selectedFolder(); - - /* Show the mailbox info */ - Serial.printf("\nInfo of the selected folder\nTotal Messages: %d\n", sFolder.msgCount()); - Serial.printf("Predicted next UID: %d\n", sFolder.nextUID()); - for (size_t i = 0; i < sFolder.flagCount(); i++) - Serial.printf("%s%s%s", i == 0 ? "Flags: " : ", ", sFolder.flag(i).c_str(), i == sFolder.flagCount() - 1 ? "\n" : ""); -} - -void printRFC822Messages(IMAP_MSG_Item &msg) -{ - Serial.printf("RFC822 Messages: %d message(s)\n****************************\n", msg.rfc822.size()); - for (size_t j = 0; j < msg.rfc822.size(); j++) - { - IMAP_MSG_Item rfc822 = msg.rfc822[j]; - Serial.printf("%d. \n", j + 1); - Serial.printf("Messsage ID: %s\n", rfc822.messageID); - Serial.printf("From: %s\n", rfc822.from); - Serial.printf("Sender: %s\n", rfc822.sender); - Serial.printf("To: %s\n", rfc822.to); - Serial.printf("CC: %s\n", rfc822.cc); - Serial.printf("Subject: %s\n", rfc822.subject); - Serial.printf("Date: %s\n", rfc822.date); - Serial.printf("Reply-To: %s\n", rfc822.reply_to); - Serial.printf("Return-Path: %s\n", rfc822.return_path); - Serial.printf("Comment: %s\n", rfc822.comment); - Serial.printf("Keyword: %s\n", rfc822.keyword); - Serial.printf("Text Message: %s\n", rfc822.text.content); - Serial.printf("Text Message Charset: %s\n", rfc822.text.charSet); - Serial.printf("Text Message Transfer Encoding: %s\n", rfc822.text.transfer_encoding); - Serial.printf("HTML Message: %s\n", rfc822.html.content); - Serial.printf("HTML Message Charset: %s\n", rfc822.html.charSet); - Serial.printf("HTML Message Transfer Encoding: %s\n\n", rfc822.html.transfer_encoding); - - if (rfc822.attachments.size() > 0) - printAttacements(rfc822); - } -} - -void printAttacements(IMAP_MSG_Item &msg) -{ - Serial.printf("Attachment: %d file(s)\n****************************\n", msg.attachments.size()); - for (size_t j = 0; j < msg.attachments.size(); j++) - { - IMAP_Attach_Item att = msg.attachments[j]; - /** att.type can be - * esp_mail_att_type_none or 0 - * esp_mail_att_type_attachment or 1 - * esp_mail_att_type_inline or 2 - */ - Serial.printf("%d. Filename: %s, Name: %s, Size: %d, MIME: %s, Type: %s, Creation Date: %s\n", j + 1, att.filename, att.name, att.size, att.mime, att.type == esp_mail_att_type_attachment ? "attachment" : "inline", att.creationDate); - } - Serial.println(); -} - -void printMessages(IMAPSession &imap) -{ - /* Get the message list from the message list data */ - IMAP_MSG_List msgList = imap.data(); - - for (size_t i = 0; i < msgList.msgItems.size(); i++) - { - /* Iterate to get each message data through the message item data */ - IMAP_MSG_Item msg = msgList.msgItems[i]; - - Serial.println("################################"); - Serial.printf("Messsage Number: %s\n", msg.msgNo); - Serial.printf("Messsage UID: %s\n", msg.UID); - Serial.printf("Messsage ID: %s\n", msg.ID); - Serial.printf("Accept Language: %s\n", msg.acceptLang); - Serial.printf("Content Language: %s\n", msg.contentLang); - Serial.printf("From: %s\n", msg.from); - Serial.printf("From Charset: %s\n", msg.fromCharset); - Serial.printf("To: %s\n", msg.to); - Serial.printf("To Charset: %s\n", msg.toCharset); - Serial.printf("CC: %s\n", msg.cc); - Serial.printf("CC Charset: %s\n", msg.ccCharset); - Serial.printf("Date: %s\n", msg.date); - Serial.printf("Subject: %s\n", msg.subject); - Serial.printf("Subject Charset: %s\n", msg.subjectCharset); - - /* If the result contains the message info (Fetch mode) */ - if (!imap.headerOnly()) - { - Serial.printf("Text Message: %s\n", msg.text.content); - Serial.printf("Text Message Charset: %s\n", msg.text.charSet); - Serial.printf("Text Message Transfer Encoding: %s\n", msg.text.transfer_encoding); - Serial.printf("HTML Message: %s\n", msg.html.content); - Serial.printf("HTML Message Charset: %s\n", msg.html.charSet); - Serial.printf("HTML Message Transfer Encoding: %s\n\n", msg.html.transfer_encoding); - - if (msg.attachments.size() > 0) - printAttacements(msg); - - if (msg.rfc822.size() > 0) - printRFC822Messages(msg); - } - - Serial.println(); - } -} diff --git a/lib/libesp32/lib_mail/examples/Read_Single_Email_Loop/Read_Single_Email_Loop.ino b/lib/libesp32/lib_mail/examples/Read_Single_Email_Loop/Read_Single_Email_Loop.ino deleted file mode 100644 index b6b484a29..000000000 --- a/lib/libesp32/lib_mail/examples/Read_Single_Email_Loop/Read_Single_Email_Loop.ino +++ /dev/null @@ -1,376 +0,0 @@ -/** - * This example will repeatedly fetch or read the Email via the loop function - * using the predict next message UID as the starting count down message UID. - * - * Created by K. Suwatchai (Mobizt) - * - * Email: suwatchai@outlook.com - * - * Github: https://github.com/mobizt/ESP-Mail-Client - * - * Copyright (c) 2021 mobizt - * -*/ - -/** To receive Email using Gmail, IMAP option should be enabled. https://support.google.com/mail/answer/7126229?hl=en - * and also https://accounts.google.com/b/0/DisplayUnlockCaptcha - * -*/ - -/** For ESP8266, with BearSSL WiFi Client - * The memory reserved for completed valid SSL response from IMAP is 16 kbytes which - * may cause your device out of memory reset in case the memory - * allocation error. -*/ - -#include -#if defined(ESP32) -#include -#elif defined(ESP8266) -#include -#endif -#include - -#define WIFI_SSID "################" -#define WIFI_PASSWORD "################" - -/* The imap host name e.g. imap.gmail.com for GMail or outlook.office365.com for Outlook */ -#define IMAP_HOST "################" - -/** The imap port e.g. - * 143 or esp_mail_imap_port_143 - * 993 or esp_mail_imap_port_993 -*/ -#define IMAP_PORT 993 - -/* The log in credentials */ -#define AUTHOR_EMAIL "################" -#define AUTHOR_PASSWORD "################" - -/* Callback function to get the Email reading status */ -void imapCallback(IMAP_Status status); - -/* Print the list of mailbox folders */ -void printAllMailboxesInfo(IMAPSession &imap); - -/* Print the selected folder info */ -void printSelectedMailboxInfo(IMAPSession &imap); - -/* Print all messages from the message list */ -void printMessages(IMAPSession &imap); - -/* Print all rfc822 messages included in the message */ -void printRFC822Messages(IMAP_MSG_Item &msg); - -/* Print all attachments info from the message */ -void printAttacements(IMAP_MSG_Item &msg); - -/* The IMAP Session object used for Email reading */ -IMAPSession imap; - -unsigned long readMillis = 0; - -int nextMsgUID = 0; -int msgUID = 0; -int sign = -1; - -/* Declare the session config data */ -ESP_Mail_Session session; - -/* Setup the configuration for searching or fetching operation and its result */ -IMAP_Config config; - -void setup() -{ - - Serial.begin(115200); - Serial.println(); - - Serial.print("Connecting to AP"); - - WiFi.begin(WIFI_SSID, WIFI_PASSWORD); - while (WiFi.status() != WL_CONNECTED) - { - Serial.print("."); - delay(200); - } - - Serial.println(""); - Serial.println("WiFi connected."); - Serial.println("IP address: "); - Serial.println(WiFi.localIP()); - Serial.println(); - - /** Enable the debug via Serial port - * none debug or 0 - * basic debug or 1 - */ - imap.debug(1); - - /* Set the callback function to get the reading results */ - imap.callback(imapCallback); - - /** In case the SD card/adapter was used for the file storagge, the SPI pins can be configure from - * MailClient.sdBegin function which may be different for ESP32 and ESP8266 - * For ESP32, assign all of SPI pins - * MailClient.sdBegin(14,2,15,13) - * Which SCK = 14, MISO = 2, MOSI = 15 and SS = 13 - * And for ESP8266, assign the CS pins of SPI port - * MailClient.sdBegin(15) - * Which pin 15 is the CS pin of SD card adapter - */ - - /* Set the session config */ - session.server.host_name = IMAP_HOST; - session.server.port = IMAP_PORT; - session.login.email = AUTHOR_EMAIL; - session.login.password = AUTHOR_PASSWORD; - - - /* Message UID to fetch or read */ - config.fetch.uid = ""; - - /* Search criteria */ - config.search.criteria = ""; - - /* Also search the unseen message */ - config.search.unseen_msg = true; - - /* Set the storage to save the downloaded files and attachments */ - config.storage.saved_path = "/email_data"; - - /** The file storage type e.g. - * esp_mail_file_storage_type_none, - * esp_mail_file_storage_type_flash, and - * esp_mail_file_storage_type_sd - */ - config.storage.type = esp_mail_file_storage_type_flash; - - /** Set to download heades, text and html messaeges, - * attachments and inline images respectively. - */ - config.download.header = false; - config.download.text = false; - config.download.html = false; - config.download.attachment = false; - config.download.inlineImg = false; - - /** Set to enable the results i.e. html and text messaeges - * which the content stored in the IMAPSession object is limited - * by the option config.limit.msg_size. - * The whole message can be download through config.download.text - * or config.download.html which not depends on these enable options. - */ - config.enable.html = true; - config.enable.text = true; - - /* Set to enable the sort the result by message UID in the ascending order */ - config.enable.recent_sort = true; - - /* Set to report the download progress via the default serial port */ - config.enable.download_status = true; - - /* Set the limit of number of messages in the search results */ - config.limit.search = 5; - - /** Set the maximum size of message stored in - * IMAPSession object in byte - */ - config.limit.msg_size = 512; - - /** Set the maximum attachments and inline images files size - * that can be downloaded in byte. - * The file which its size is largger than this limit may be saved - * as truncated file. - */ - config.limit.attachment_size = 1024 * 1024 * 5; - - - /* Connect to server with the session and config */ - if (!imap.connect(&session, &config)) - return; - - /* {Optional] */ - printAllMailboxesInfo(imap); - - /* Open or select the mailbox folder to read or search the message */ - if (!imap.selectFolder("INBOX")) - return; - - /* {Optional] */ - printSelectedMailboxInfo(imap); -} - -void loop() -{ - if (millis() - readMillis > 10000 || readMillis == 0) - { - readMillis = millis(); - - if (msgUID == 0) - sign = 1; - else if (msgUID >= nextMsgUID) - sign = -1; - - msgUID += sign; - - String uid = String(msgUID); - - /* Message UID to fetch or read */ - config.fetch.uid = uid.c_str(); - - /* Set seen flag */ - //config.fetch.set_seen = true; - - /** Read or search the Email and keep the TCP session to open - * The second parameter is for close the session. - */ - MailClient.readMail(&imap, false); - - /* Clear all stored data in IMAPSession object */ - imap.empty(); - } -} - -/* Callback function to get the Email reading status */ -void imapCallback(IMAP_Status status) -{ - /* Print the current status */ - Serial.println(status.info()); - - /* Show the result when reading finished */ - if (status.success()) - { - /* Print the result */ - printMessages(imap); - - /* Clear all stored data in IMAPSession object */ - imap.empty(); - Serial.printf("Free Heap: %d", ESP.getFreeHeap()); - } -} - -void printAllMailboxesInfo(IMAPSession &imap) -{ - /* Declare the folder collection class to get the list of mailbox folders */ - FoldersCollection folders; - - /* Get the mailbox folders */ - if (imap.getFolders(folders)) - { - for (size_t i = 0; i < folders.size(); i++) - { - /* Iterate each folder info using the folder info item data */ - FolderInfo folderInfo = folders.info(i); - Serial.printf("%s%s%s", i == 0 ? "\nAvailable folders: " : ", ", folderInfo.name, i == folders.size() - 1 ? "\n" : ""); - } - } -} - -void printSelectedMailboxInfo(IMAPSession &imap) -{ - /* Declare the selected folder info class to get the info of selected mailbox folder */ - SelectedFolderInfo sFolder = imap.selectedFolder(); - - nextMsgUID = sFolder.nextUID(); - msgUID = nextMsgUID; - - /* Show the mailbox info */ - Serial.printf("\nInfo of the selected folder\nTotal Messages: %d\n", sFolder.msgCount()); - Serial.printf("Predicted next UID: %d\n", sFolder.nextUID()); - for (size_t i = 0; i < sFolder.flagCount(); i++) - Serial.printf("%s%s%s", i == 0 ? "Flags: " : ", ", sFolder.flag(i).c_str(), i == sFolder.flagCount() - 1 ? "\n" : ""); -} - -void printRFC822Messages(IMAP_MSG_Item &msg) -{ - Serial.printf("RFC822 Messages: %d message(s)\n****************************\n", msg.rfc822.size()); - for (size_t j = 0; j < msg.rfc822.size(); j++) - { - IMAP_MSG_Item rfc822 = msg.rfc822[j]; - Serial.printf("%d. \n", j + 1); - Serial.printf("Messsage ID: %s\n", rfc822.messageID); - Serial.printf("From: %s\n", rfc822.from); - Serial.printf("Sender: %s\n", rfc822.sender); - Serial.printf("To: %s\n", rfc822.to); - Serial.printf("CC: %s\n", rfc822.cc); - Serial.printf("Subject: %s\n", rfc822.subject); - Serial.printf("Date: %s\n", rfc822.date); - Serial.printf("Reply-To: %s\n", rfc822.reply_to); - Serial.printf("Return-Path: %s\n", rfc822.return_path); - Serial.printf("Comment: %s\n", rfc822.comment); - Serial.printf("Keyword: %s\n", rfc822.keyword); - Serial.printf("Text Message: %s\n", rfc822.text.content); - Serial.printf("Text Message Charset: %s\n", rfc822.text.charSet); - Serial.printf("Text Message Transfer Encoding: %s\n", rfc822.text.transfer_encoding); - Serial.printf("HTML Message: %s\n", rfc822.html.content); - Serial.printf("HTML Message Charset: %s\n", rfc822.html.charSet); - Serial.printf("HTML Message Transfer Encoding: %s\n\n", rfc822.html.transfer_encoding); - - if (rfc822.attachments.size() > 0) - printAttacements(rfc822); - } -} - -void printAttacements(IMAP_MSG_Item &msg) -{ - Serial.printf("Attachment: %d file(s)\n****************************\n", msg.attachments.size()); - for (size_t j = 0; j < msg.attachments.size(); j++) - { - IMAP_Attach_Item att = msg.attachments[j]; - /** att.type can be - * esp_mail_att_type_none or 0 - * esp_mail_att_type_attachment or 1 - * esp_mail_att_type_inline or 2 - */ - Serial.printf("%d. Filename: %s, Name: %s, Size: %d, MIME: %s, Type: %s, Creation Date: %s\n", j + 1, att.filename, att.name, att.size, att.mime, att.type == esp_mail_att_type_attachment ? "attachment" : "inline", att.creationDate); - } - Serial.println(); -} - -void printMessages(IMAPSession &imap) -{ - /* Get the message list from the message list data */ - IMAP_MSG_List msgList = imap.data(); - - for (size_t i = 0; i < msgList.msgItems.size(); i++) - { - /* Iterate to get each message data through the message item data */ - IMAP_MSG_Item msg = msgList.msgItems[i]; - - Serial.println("################################"); - Serial.printf("Messsage Number: %s\n", msg.msgNo); - Serial.printf("Messsage UID: %s\n", msg.UID); - Serial.printf("Messsage ID: %s\n", msg.ID); - Serial.printf("Accept Language: %s\n", msg.acceptLang); - Serial.printf("Content Language: %s\n", msg.contentLang); - Serial.printf("From: %s\n", msg.from); - Serial.printf("From Charset: %s\n", msg.fromCharset); - Serial.printf("To: %s\n", msg.to); - Serial.printf("To Charset: %s\n", msg.toCharset); - Serial.printf("CC: %s\n", msg.cc); - Serial.printf("CC Charset: %s\n", msg.ccCharset); - Serial.printf("Date: %s\n", msg.date); - Serial.printf("Subject: %s\n", msg.subject); - Serial.printf("Subject Charset: %s\n", msg.subjectCharset); - - /* If the result contains the message info (Fetch mode) */ - if (!imap.headerOnly()) - { - Serial.printf("Text Message: %s\n", msg.text.content); - Serial.printf("Text Message Charset: %s\n", msg.text.charSet); - Serial.printf("Text Message Transfer Encoding: %s\n", msg.text.transfer_encoding); - Serial.printf("HTML Message: %s\n", msg.html.content); - Serial.printf("HTML Message Charset: %s\n", msg.html.charSet); - Serial.printf("HTML Message Transfer Encoding: %s\n\n", msg.html.transfer_encoding); - - if (msg.attachments.size() > 0) - printAttacements(msg); - - if (msg.rfc822.size() > 0) - printRFC822Messages(msg); - } - - Serial.println(); - } -} diff --git a/lib/libesp32/lib_mail/examples/Search_Emails/Search_Emails.ino b/lib/libesp32/lib_mail/examples/Search_Emails/Search_Emails.ino deleted file mode 100644 index e82c84b6f..000000000 --- a/lib/libesp32/lib_mail/examples/Search_Emails/Search_Emails.ino +++ /dev/null @@ -1,402 +0,0 @@ -/** - * This example will search all Emails in the opened mailbox folder. - * - * Created by K. Suwatchai (Mobizt) - * - * Email: suwatchai@outlook.com - * - * Github: https://github.com/mobizt/ESP-Mail-Client - * - * Copyright (c) 2021 mobizt - * -*/ - -/** To receive Email using Gmail, IMAP option should be enabled. https://support.google.com/mail/answer/7126229?hl=en - * and also https://accounts.google.com/b/0/DisplayUnlockCaptcha - * -*/ - -/** For ESP8266, with BearSSL WiFi Client - * The memory reserved for completed valid SSL response from IMAP is 16 kbytes which - * may cause your device out of memory reset in case the memory - * allocation error. -*/ - -#include -#if defined(ESP32) -#include -#elif defined(ESP8266) -#include -#endif -#include - -#define WIFI_SSID "################" -#define WIFI_PASSWORD "################" - -/* The imap host name e.g. imap.gmail.com for GMail or outlook.office365.com for Outlook */ -#define IMAP_HOST "################" - -/** The imap port e.g. - * 143 or esp_mail_imap_port_143 - * 993 or esp_mail_imap_port_993 -*/ -#define IMAP_PORT 993 - -/* The log in credentials */ -#define AUTHOR_EMAIL "################" -#define AUTHOR_PASSWORD "################" - - -/* Callback function to get the Email reading status */ -void imapCallback(IMAP_Status status); - -/* Print the list of mailbox folders */ -void printAllMailboxesInfo(IMAPSession &imap); - -/* Print the selected folder info */ -void printSelectedMailboxInfo(IMAPSession &imap); - -/* Print all messages from the message list */ -void printMessages(IMAPSession &imap); - -/* Print all rfc822 messages included in the message */ -void printRFC822Messages(IMAP_MSG_Item &msg); - -/* Print all attachments info from the message */ -void printAttacements(IMAP_MSG_Item &msg); - -/* The IMAP Session object used for Email reading */ -IMAPSession imap; - -void setup() -{ - - Serial.begin(115200); - Serial.println(); - - Serial.print("Connecting to AP"); - - WiFi.begin(WIFI_SSID, WIFI_PASSWORD); - while (WiFi.status() != WL_CONNECTED) - { - Serial.print("."); - delay(200); - } - - Serial.println(""); - Serial.println("WiFi connected."); - Serial.println("IP address: "); - Serial.println(WiFi.localIP()); - Serial.println(); - - /** Enable the debug via Serial port - * none debug or 0 - * basic debug or 1 - */ - imap.debug(1); - - /* Set the callback function to get the reading results */ - imap.callback(imapCallback); - - /* Declare the session config data */ - ESP_Mail_Session session; - - /** In case the SD card/adapter was used for the file storagge, the SPI pins can be configure from - * MailClient.sdBegin function which may be different for ESP32 and ESP8266 - * For ESP32, assign all of SPI pins - * MailClient.sdBegin(14,2,15,13) - * Which SCK = 14, MISO = 2, MOSI = 15 and SS = 13 - * And for ESP8266, assign the CS pins of SPI port - * MailClient.sdBegin(15) - * Which pin 15 is the CS pin of SD card adapter - */ - - /** ######################################################## - * Some properties of IMAP_Config and ESP_Mail_Session data - * accept the pointer to constant char i.e. const char*. - * - * You may assign a string literal to that properties like - * below example. - * - * config.search.criteria = String("UID SEARCH ALL").c_str(); - * - * String folder = "INBOX"; - * imap.selectFolder(folder.c_str()); - * - * ########################################################### - */ - - /* Set the session config */ - session.server.host_name = IMAP_HOST; - session.server.port = IMAP_PORT; - session.login.email = AUTHOR_EMAIL; - session.login.password = AUTHOR_PASSWORD; - - /* Setup the configuration for searching or fetching operation and its result */ - IMAP_Config config; - - /* Message UID to fetch or read */ - config.fetch.uid = ""; - - /** Search criteria - * - * A search key can also be a parenthesized list of one or more search keys - * (e.g., for use with the OR and NOT keys). - * - * Since IMAP protocol uses Polish notation, the search criteria which in the polish notation form can be. - * - * To search the message from "someone@email.com" with the subject "my subject" since 1 Jan 2021, your search criteria can be - * UID SEARCH (OR SUBJECT "my subject" FROM "someone@email.com") SINCE "Fri, 1 Jan 2021 21:52:25 -0800" - * - * To search the message from "mail1@domain.com" or from "mail2@domain.com", the search criteria will be - * UID SEARCH OR FROM mail1@domain.com FROM mail2@domain.com - * - * For more details on using parentheses, AND, OR and NOT search keys in search criteria. - * https://www.limilabs.com/blog/imap-search-requires-parentheses - * - * - */ - config.search.criteria = "UID SEARCH ALL"; - - /* Also search the unseen message */ - config.search.unseen_msg = true; - - /* Set the storage to save the downloaded files and attachments */ - config.storage.saved_path = "/email_data"; - - /** The file storage type e.g. - * esp_mail_file_storage_type_none, - * esp_mail_file_storage_type_flash, and - * esp_mail_file_storage_type_sd - */ - config.storage.type = esp_mail_file_storage_type_flash; - - /** Set to download heades, text and html messaeges, - * attachments and inline images respectively. - */ - config.download.header = true; - config.download.text = true; - config.download.html = true; - config.download.attachment = true; - config.download.inlineImg = true; - - /** Set to enable the results i.e. html and text messaeges - * which the content stored in the IMAPSession object is limited - * by the option config.limit.msg_size. - * The whole message can be download through config.download.text - * or config.download.html which not depends on these enable options. - */ - config.enable.html = true; - config.enable.text = true; - - /* Set to enable the sort the result by message UID in the ascending order */ - config.enable.recent_sort = true; - - /* Set to report the download progress via the default serial port */ - config.enable.download_status = true; - - /* Set the limit of number of messages in the search results */ - config.limit.search = 5; - - /** Set the maximum size of message stored in - * IMAPSession object in byte - */ - config.limit.msg_size = 512; - - /** Set the maximum attachments and inline images files size - * that can be downloaded in byte. - * The file which its size is largger than this limit may be saved - * as truncated file. - */ - config.limit.attachment_size = 1024 * 1024 * 5; - - - /* Connect to server with the session and config */ - if (!imap.connect(&session, &config)) - return; - - /* {Optional] */ - printAllMailboxesInfo(imap); - - /* Open or select the mailbox folder to read or search the message */ - if (!imap.selectFolder("INBOX")) - return; - - /* {Optional] */ - printSelectedMailboxInfo(imap); - - /** Read or search the Email and keep the TCP session to open - * The second parameter is for close the session. - */ - MailClient.readMail(&imap, false); - - /* Clear all stored data in IMAPSession object */ - imap.empty(); - - /** Open or select other mailbox folder - * The folder that previousely opened will be closed - */ - if (imap.selectFolder("Junk")) - { - /* {Optional] */ - printSelectedMailboxInfo(imap); - - /* Config to search all messages in the opened mailboax (Search mode) */ - config.search.criteria = "UID SEARCH ALL"; // or "UID SEARCH NEW" for recent received messages - - /* No message UID provide for fetching */ - config.fetch.uid = ""; - - /* Search the Email and close the session */ - MailClient.readMail(&imap); - } - - /* Close the seeion in case the session is still open */ - imap.closeSession(); - - /* Clear all stored data in IMAPSession object */ - imap.empty(); -} - -void loop() -{ -} - -/* Callback function to get the Email reading status */ -void imapCallback(IMAP_Status status) -{ - /* Print the current status */ - Serial.println(status.info()); - - /* Show the result when reading finished */ - if (status.success()) - { - /* Print the result */ - printMessages(imap); - - /* Clear all stored data in IMAPSession object */ - imap.empty(); - } -} - -void printAllMailboxesInfo(IMAPSession &imap) -{ - /* Declare the folder collection class to get the list of mailbox folders */ - FoldersCollection folders; - - /* Get the mailbox folders */ - if (imap.getFolders(folders)) - { - for (size_t i = 0; i < folders.size(); i++) - { - /* Iterate each folder info using the folder info item data */ - FolderInfo folderInfo = folders.info(i); - Serial.printf("%s%s%s", i == 0 ? "\nAvailable folders: " : ", ", folderInfo.name, i == folders.size() - 1 ? "\n" : ""); - } - } -} - -void printSelectedMailboxInfo(IMAPSession &imap) -{ - /* Declare the selected folder info class to get the info of selected mailbox folder */ - SelectedFolderInfo sFolder = imap.selectedFolder(); - - /* Show the mailbox info */ - Serial.printf("\nInfo of the selected folder\nTotal Messages: %d\n", sFolder.msgCount()); - Serial.printf("Predicted next UID: %d\n", sFolder.nextUID()); - for (size_t i = 0; i < sFolder.flagCount(); i++) - Serial.printf("%s%s%s", i == 0 ? "Flags: " : ", ", sFolder.flag(i).c_str(), i == sFolder.flagCount() - 1 ? "\n" : ""); -} - -void printRFC822Messages(IMAP_MSG_Item &msg) -{ - Serial.printf("RFC822 Messages: %d message(s)\n****************************\n", msg.rfc822.size()); - for (size_t j = 0; j < msg.rfc822.size(); j++) - { - IMAP_MSG_Item rfc822 = msg.rfc822[j]; - Serial.printf("%d. \n", j + 1); - Serial.printf("Messsage ID: %s\n", rfc822.messageID); - Serial.printf("From: %s\n", rfc822.from); - Serial.printf("Sender: %s\n", rfc822.sender); - Serial.printf("To: %s\n", rfc822.to); - Serial.printf("CC: %s\n", rfc822.cc); - Serial.printf("Subject: %s\n", rfc822.subject); - Serial.printf("Date: %s\n", rfc822.date); - Serial.printf("Reply-To: %s\n", rfc822.reply_to); - Serial.printf("Return-Path: %s\n", rfc822.return_path); - Serial.printf("Comment: %s\n", rfc822.comment); - Serial.printf("Keyword: %s\n", rfc822.keyword); - Serial.printf("Text Message: %s\n", rfc822.text.content); - Serial.printf("Text Message Charset: %s\n", rfc822.text.charSet); - Serial.printf("Text Message Transfer Encoding: %s\n", rfc822.text.transfer_encoding); - Serial.printf("HTML Message: %s\n", rfc822.html.content); - Serial.printf("HTML Message Charset: %s\n", rfc822.html.charSet); - Serial.printf("HTML Message Transfer Encoding: %s\n\n", rfc822.html.transfer_encoding); - - if (rfc822.attachments.size() > 0) - printAttacements(rfc822); - } -} - -void printAttacements(IMAP_MSG_Item &msg) -{ - Serial.printf("Attachment: %d file(s)\n****************************\n", msg.attachments.size()); - for (size_t j = 0; j < msg.attachments.size(); j++) - { - IMAP_Attach_Item att = msg.attachments[j]; - /** att.type can be - * esp_mail_att_type_none or 0 - * esp_mail_att_type_attachment or 1 - * esp_mail_att_type_inline or 2 - */ - Serial.printf("%d. Filename: %s, Name: %s, Size: %d, MIME: %s, Type: %s, Creation Date: %s\n", j + 1, att.filename, att.name, att.size, att.mime, att.type == esp_mail_att_type_attachment ? "attachment" : "inline", att.creationDate); - } - Serial.println(); -} - -void printMessages(IMAPSession &imap) -{ - /* Get the message list from the message list data */ - IMAP_MSG_List msgList = imap.data(); - - for (size_t i = 0; i < msgList.msgItems.size(); i++) - { - /* Iterate to get each message data through the message item data */ - IMAP_MSG_Item msg = msgList.msgItems[i]; - - Serial.println("################################"); - Serial.printf("Messsage Number: %s\n", msg.msgNo); - Serial.printf("Messsage UID: %s\n", msg.UID); - Serial.printf("Messsage ID: %s\n", msg.ID); - Serial.printf("Accept Language: %s\n", msg.acceptLang); - Serial.printf("Content Language: %s\n", msg.contentLang); - Serial.printf("From: %s\n", msg.from); - Serial.printf("From Charset: %s\n", msg.fromCharset); - Serial.printf("To: %s\n", msg.to); - Serial.printf("To Charset: %s\n", msg.toCharset); - Serial.printf("CC: %s\n", msg.cc); - Serial.printf("CC Charset: %s\n", msg.ccCharset); - Serial.printf("Date: %s\n", msg.date); - Serial.printf("Subject: %s\n", msg.subject); - Serial.printf("Subject Charset: %s\n", msg.subjectCharset); - - /* If the result contains the message info (Fetch mode) */ - if (!imap.headerOnly()) - { - Serial.printf("Text Message: %s\n", msg.text.content); - Serial.printf("Text Message Charset: %s\n", msg.text.charSet); - Serial.printf("Text Message Transfer Encoding: %s\n", msg.text.transfer_encoding); - Serial.printf("HTML Message: %s\n", msg.html.content); - Serial.printf("HTML Message Charset: %s\n", msg.html.charSet); - Serial.printf("HTML Message Transfer Encoding: %s\n\n", msg.html.transfer_encoding); - - if (msg.attachments.size() > 0) - printAttacements(msg); - - if (msg.rfc822.size() > 0) - printRFC822Messages(msg); - } - - Serial.println(); - } -} diff --git a/lib/libesp32/lib_mail/examples/Send_Access_Token/Send_Access_Token.ino b/lib/libesp32/lib_mail/examples/Send_Access_Token/Send_Access_Token.ino deleted file mode 100644 index bdebd82a5..000000000 --- a/lib/libesp32/lib_mail/examples/Send_Access_Token/Send_Access_Token.ino +++ /dev/null @@ -1,203 +0,0 @@ - - -/** - *This example will log in with the SASL XOAUTH2 mechanisme using OAuth2.0 access token. - * - * Created by K. Suwatchai (Mobizt) - * - * Email: suwatchai@outlook.com - * - * Github: https://github.com/mobizt/ESP-Mail-Client - * - * Copyright (c) 2021 mobizt - * -*/ - -//To use send Email for Gmail to port 465 (SSL), less secure app option should be enabled. https://myaccount.google.com/lesssecureapps?pli=1 - -#include -#if defined(ESP32) -#include -#elif defined(ESP8266) -#include -#endif -#include - -#define WIFI_SSID "################" -#define WIFI_PASSWORD "################" - - -#define SMTP_HOST "################" - -/** The smtp port e.g. - * 25 or esp_mail_smtp_port_25 - * 465 or esp_mail_smtp_port_465 - * 587 or esp_mail_smtp_port_587 -*/ -#define SMTP_PORT 25 - -/* The user Email for OAuth2.0 access token */ -#define AUTHOR_EMAIL "################" - -/** The OAuth2.0 access token - * The generation, exchange and refresh of the access token are not available - * in this library. - * - * To test this using GMail, get the OAuth2.0 access token from this web site - * https://developers.google.com/oauthplayground/ - * - * You can use the ESP Signer library to generate OAuth2.0 access token - * The library is available here https://github.com/mobizt/ESP-Signer - * - * 1. Select the following scope (in Step 1) from Gmail API V1 - * https://mail.google.com/ - * https://mail.google.com/ - * - * 2. Click Authorize APIs button. - * 3. Cick Exchangeauthorization code for tokens. - * 4. From the response, look at access_token from the JSON payload node. - * 5. Copy that access token and paste to the AUTHOR_ACCESS_TOKEN value. - * - * The token will be expired in 3600 seconds (1 Hr). - * The AUTHOR_EMAIL above is the Email address that you granted to access the Gmail services. -*/ -#define AUTHOR_ACCESS_TOKEN "################" - -/* The SMTP Session object used for Email sending */ -SMTPSession smtp; - -/* Callback function to get the Email sending status */ -void smtpCallback(SMTP_Status status); - -void setup() -{ - - Serial.begin(115200); - Serial.println(); - - Serial.print("Connecting to AP"); - - WiFi.begin(WIFI_SSID, WIFI_PASSWORD); - while (WiFi.status() != WL_CONNECTED) - { - Serial.print("."); - delay(200); - } - - Serial.println(""); - Serial.println("WiFi connected."); - Serial.println("IP address: "); - Serial.println(WiFi.localIP()); - Serial.println(); - - /** Enable the debug via Serial port - * none debug or 0 - * basic debug or 1 - */ - smtp.debug(1); - - /* Set the callback function to get the sending results */ - smtp.callback(smtpCallback); - - /* Declare the session config data */ - ESP_Mail_Session session; - - /* Set the session config */ - session.server.host_name = SMTP_HOST; - session.server.port = SMTP_PORT; - session.login.email = AUTHOR_EMAIL; - session.login.accessToken = AUTHOR_ACCESS_TOKEN; - session.login.user_domain = "mydomain.net"; - - /* Declare the message class */ - SMTP_Message message; - - /* Set the message headers */ - message.sender.name = "ESP Mail"; - message.sender.email = AUTHOR_EMAIL; - message.subject = "Test sending Email using Access token"; - message.addRecipient("Admin", "####@#####_dot_com"); - - message.text.content = "This is simple plain text message"; - - /** The Plain text message character set e.g. - * us-ascii - * utf-8 - * utf-7 - * The default value is utf-8 - */ - message.text.charSet = "us-ascii"; - - /** The content transfer encoding e.g. - * enc_7bit or "7bit" (not encoded) - * enc_qp or "quoted-printable" (encoded) - * enc_base64 or "base64" (encoded) - * enc_binary or "binary" (not encoded) - * enc_8bit or "8bit" (not encoded) - * The default value is "7bit" - */ - message.text.transfer_encoding = Content_Transfer_Encoding::enc_7bit; - - /** The message priority - * esp_mail_smtp_priority_high or 1 - * esp_mail_smtp_priority_normal or 3 - * esp_mail_smtp_priority_low or 5 - * The default value is esp_mail_smtp_priority_low - */ - message.priority = esp_mail_smtp_priority::esp_mail_smtp_priority_low; - - /** The Delivery Status Notifications e.g. - * esp_mail_smtp_notify_never - * esp_mail_smtp_notify_success - * esp_mail_smtp_notify_failure - * esp_mail_smtp_notify_delay - * The default value is esp_mail_smtp_notify_never - */ - message.response.notify = esp_mail_smtp_notify_success | esp_mail_smtp_notify_failure | esp_mail_smtp_notify_delay; - - /* Connect to server with the session config */ - if (!smtp.connect(&session)) - return; - - /* Set the custom message header */ - message.addHeader("Message-ID: "); - - /* Start sending Email and close the session */ - if (!MailClient.sendMail(&smtp, &message)) - Serial.println("Error sending Email, " + smtp.errorReason()); -} - -void loop() -{ -} - -/* Callback function to get the Email sending status */ -void smtpCallback(SMTP_Status status) -{ - /* Print the current status */ - Serial.println(status.info()); - - /* Print the sending result */ - if (status.success()) - { - Serial.println("----------------"); - Serial.printf("Message sent success: %d\n", status.completedCount()); - Serial.printf("Message sent failled: %d\n", status.failedCount()); - Serial.println("----------------\n"); - struct tm dt; - - for (size_t i = 0; i < smtp.sendingResult.size(); i++) - { - /* Get the result item */ - SMTP_Result result = smtp.sendingResult.getItem(i); - localtime_r(&result.timesstamp, &dt); - - Serial.printf("Message No: %d\n", i + 1); - Serial.printf("Status: %s\n", result.completed ? "success" : "failed"); - Serial.printf("Date/Time: %d/%d/%d %d:%d:%d\n", dt.tm_year + 1900, dt.tm_mon + 1, dt.tm_mday, dt.tm_hour, dt.tm_min, dt.tm_sec); - Serial.printf("Recipient: %s\n", result.recipients); - Serial.printf("Subject: %s\n", result.subject); - } - Serial.println("----------------\n"); - } -} diff --git a/lib/libesp32/lib_mail/examples/Send_Attachment_Blob/Send_Attachment_Blob.ino b/lib/libesp32/lib_mail/examples/Send_Attachment_Blob/Send_Attachment_Blob.ino deleted file mode 100644 index 7ff054a80..000000000 --- a/lib/libesp32/lib_mail/examples/Send_Attachment_Blob/Send_Attachment_Blob.ino +++ /dev/null @@ -1,268 +0,0 @@ - - -/** - * This example will send the Email with attachments and - * inline images stored in heap and flash memories. - * - * The html and text version messages will be sent. - * - * Created by K. Suwatchai (Mobizt) - * - * Email: suwatchai@outlook.com - * - * Github: https://github.com/mobizt/ESP-Mail-Client - * - * Copyright (c) 2021 mobizt - * -*/ - -//To use send Email for Gmail to port 465 (SSL), less secure app option should be enabled. https://myaccount.google.com/lesssecureapps?pli=1 - -#include -#if defined(ESP32) -#include -#elif defined(ESP8266) -#include -#endif -#include - -/* This is for attachment data */ -#include "image.h" - -#define WIFI_SSID "################" -#define WIFI_PASSWORD "################" - -/** The smtp host name e.g. smtp.gmail.com for GMail or smtp.office365.com for Outlook or smtp.mail.yahoo.com - * For yahoo mail, log in to your yahoo mail in web browser and generate app password by go to - * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc - * and use the app password as password with your yahoo mail account to login. - * The google app password signin is also available https://support.google.com/mail/answer/185833?hl=en -*/ -#define SMTP_HOST "################" - -/** The smtp port e.g. - * 25 or esp_mail_smtp_port_25 - * 465 or esp_mail_smtp_port_465 - * 587 or esp_mail_smtp_port_587 -*/ -#define SMTP_PORT esp_mail_smtp_port_587 - -/* The log in credentials */ -#define AUTHOR_EMAIL "################" -#define AUTHOR_PASSWORD "################" - -/* The SMTP Session object used for Email sending */ -SMTPSession smtp; - -/* Callback function to get the Email sending status */ -void smtpCallback(SMTP_Status status); - -void setup() -{ - - Serial.begin(115200); - Serial.println(); - - Serial.print("Connecting to AP"); - - WiFi.begin(WIFI_SSID, WIFI_PASSWORD); - while (WiFi.status() != WL_CONNECTED) - { - Serial.print("."); - delay(200); - } - - Serial.println(""); - Serial.println("WiFi connected."); - Serial.println("IP address: "); - Serial.println(WiFi.localIP()); - Serial.println(); - - /** Enable the debug via Serial port - * none debug or 0 - * basic debug or 1 - */ - smtp.debug(1); - - /* Set the callback function to get the sending results */ - smtp.callback(smtpCallback); - - /* Declare the session config data */ - ESP_Mail_Session session; - - /* Set the session config */ - session.server.host_name = SMTP_HOST; - session.server.port = SMTP_PORT; - session.login.email = AUTHOR_EMAIL; - session.login.password = AUTHOR_PASSWORD; - session.login.user_domain = "mydomain.net"; - - /* Declare the message class */ - SMTP_Message message; - - /* Enable the chunked data transfer with pipelining for large message if server supported */ - message.enable.chunking = true; - - /* Set the message headers */ - message.sender.name = "ESP Mail"; - message.sender.email = AUTHOR_EMAIL; - - message.subject = "Test sending Email with attachments and inline images"; - message.addRecipient("user1", "####@#####_dot_com"); - - message.html.content = "This message contains 3 inline images and 1 attachment file.

"; - - /** The HTML text message character set e.g. - * us-ascii - * utf-8 - * utf-7 - * The default value is utf-8 - */ - message.html.charSet = "utf-8"; - - /** The content transfer encoding e.g. - * enc_7bit or "7bit" (not encoded) - * enc_qp or "quoted-printable" (encoded) - * enc_base64 or "base64" (encoded) - * enc_binary or "binary" (not encoded) - * enc_8bit or "8bit" (not encoded) - * The default value is "7bit" - */ - message.html.transfer_encoding = Content_Transfer_Encoding::enc_qp; - - message.text.content = "This message contains 3 inline images and 1 attachment file.\r\nThe inline images were not shown in the plain text message."; - message.text.charSet = "utf-8"; - message.text.transfer_encoding = Content_Transfer_Encoding::enc_base64; - - /** The message priority - * esp_mail_smtp_priority_high or 1 - * esp_mail_smtp_priority_normal or 3 - * esp_mail_smtp_priority_low or 5 - * The default value is esp_mail_smtp_priority_low - */ - message.priority = esp_mail_smtp_priority::esp_mail_smtp_priority_normal; - - /** The Delivery Status Notifications e.g. - * esp_mail_smtp_notify_never - * esp_mail_smtp_notify_success - * esp_mail_smtp_notify_failure - * esp_mail_smtp_notify_delay - * The default value is esp_mail_smtp_notify_never - */ - message.response.notify = esp_mail_smtp_notify_success | esp_mail_smtp_notify_failure | esp_mail_smtp_notify_delay; - - /* Set the custom message header */ - message.addHeader("Message-ID: "); - - /* The attachment data item */ - SMTP_Attachment att; - - /** Set the inline image info e.g. - * file name, MIME type, BLOB data, BLOB data size, - * transfer encoding (should be base64 for inline image) - */ - att.descr.filename = "firebase_logo.png"; - att.descr.mime = "image/png"; - att.blob.data = firebase_png; - att.blob.size = sizeof(firebase_png); - att.descr.transfer_encoding = Content_Transfer_Encoding::enc_base64; - - /* Add inline image to the message */ - message.addInlineImage(att); - - /** Set the inline image info e.g. - * file name, MIME type, BLOB data, BLOB data size. - * The default transfer encoding is base64. - */ - message.resetAttachItem(att); //Clear the attach item data to reuse - att.descr.filename = "tree.gif"; - att.descr.mime = "image/gif"; - att.blob.data = tree_gif; - att.blob.size = sizeof(tree_gif); - att.descr.transfer_encoding = Content_Transfer_Encoding::enc_base64; - - /* Add inline image to the message */ - message.addInlineImage(att); - - /** Set the inline image info e.g. - * file name, MIME type, BLOB data, BLOB data size. - * The default transfer encoding is base64. - */ - message.resetAttachItem(att); //Clear the attach item data to reuse - att.descr.filename = "bird.gif"; - att.descr.mime = "image/gif"; - att.blob.data = bird_gif; - att.blob.size = sizeof(bird_gif); - att.descr.transfer_encoding = Content_Transfer_Encoding::enc_base64; - - /* Add inline image to the message */ - message.addInlineImage(att); - - /* Prepare the attachment data (from ram) */ - uint8_t *a = new uint8_t[512]; - int j = 0; - - for (int i = 0; i < 512; i++) - { - a[i] = j; - j++; - if (j > 255) - j = 0; - } - - /** Set the attachment info e.g. - * file name, MIME type, BLOB data, BLOB data size. - * The default transfer encoding is base64. - */ - message.resetAttachItem(att); //Clear the attach item data to reuse - att.descr.filename = "test.dat"; - att.descr.mime = "application/octet-stream"; - att.blob.data = a; - att.blob.size = 512; - att.descr.transfer_encoding = Content_Transfer_Encoding::enc_base64; - /* Add attachment to the message */ - message.addAttachment(att); - - /* Connect to server with the session config */ - if (!smtp.connect(&session)) - return; - - /* Start sending the Email and close the session */ - if (!MailClient.sendMail(&smtp, &message, true)) - Serial.println("Error sending Email, " + smtp.errorReason()); -} - -void loop() -{ -} - -/* Callback function to get the Email sending status */ -void smtpCallback(SMTP_Status status) -{ - /* Print the current status */ - Serial.println(status.info()); - - /* Print the sending result */ - if (status.success()) - { - Serial.println("----------------"); - Serial.printf("Message sent success: %d\n", status.completedCount()); - Serial.printf("Message sent failled: %d\n", status.failedCount()); - Serial.println("----------------\n"); - struct tm dt; - - for (size_t i = 0; i < smtp.sendingResult.size(); i++) - { - /* Get the result item */ - SMTP_Result result = smtp.sendingResult.getItem(i); - localtime_r(&result.timesstamp, &dt); - - Serial.printf("Message No: %d\n", i + 1); - Serial.printf("Status: %s\n", result.completed ? "success" : "failed"); - Serial.printf("Date/Time: %d/%d/%d %d:%d:%d\n", dt.tm_year + 1900, dt.tm_mon + 1, dt.tm_mday, dt.tm_hour, dt.tm_min, dt.tm_sec); - Serial.printf("Recipient: %s\n", result.recipients); - Serial.printf("Subject: %s\n", result.subject); - } - Serial.println("----------------\n"); - } -} diff --git a/lib/libesp32/lib_mail/examples/Send_Attachment_File/Send_Attachment_File.ino b/lib/libesp32/lib_mail/examples/Send_Attachment_File/Send_Attachment_File.ino deleted file mode 100644 index 3dcd0fc9e..000000000 --- a/lib/libesp32/lib_mail/examples/Send_Attachment_File/Send_Attachment_File.ino +++ /dev/null @@ -1,427 +0,0 @@ - - -/** - * This example will send the Email with attachments and - * inline images stored in flash and SD card. - * - * The html and text version messages will be sent. - * - * Created by K. Suwatchai (Mobizt) - * - * Email: suwatchai@outlook.com - * - * Github: https://github.com/mobizt/ESP-Mail-Client - * - * Copyright (c) 2021 mobizt - * -*/ - -//To use send Email for Gmail to port 465 (SSL), less secure app option should be enabled. https://myaccount.google.com/lesssecureapps?pli=1 - -//The file systems for flash and sd memory can be changed in ESP_Mail_FS.h. - -#include -#if defined(ESP32) -#include -#elif defined(ESP8266) -#include -#endif -#include - -#define WIFI_SSID "################" -#define WIFI_PASSWORD "################" - -/** The smtp host name e.g. smtp.gmail.com for GMail or smtp.office365.com for Outlook or smtp.mail.yahoo.com - * For yahoo mail, log in to your yahoo mail in web browser and generate app password by go to - * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc - * and use the app password as password with your yahoo mail account to login. - * The google app password signin is also available https://support.google.com/mail/answer/185833?hl=en -*/ -#define SMTP_HOST "################" - -/** The smtp port e.g. - * 25 or esp_mail_smtp_port_25 - * 465 or esp_mail_smtp_port_465 - * 587 or esp_mail_smtp_port_587 -*/ -#define SMTP_PORT esp_mail_smtp_port_587 - -/* The log in credentials */ -#define AUTHOR_EMAIL "################" -#define AUTHOR_PASSWORD "################" - -/* The SMTP Session object used for Email sending */ -SMTPSession smtp; - -/* Callback function to get the Email sending status */ -void smtpCallback(SMTP_Status status); - -void setup() -{ - - Serial.begin(115200); - Serial.println(); - - Serial.print("Connecting to AP"); - - WiFi.begin(WIFI_SSID, WIFI_PASSWORD); - while (WiFi.status() != WL_CONNECTED) - { - Serial.print("."); - delay(200); - } - - Serial.println(""); - Serial.println("WiFi connected."); - Serial.println("IP address: "); - Serial.println(WiFi.localIP()); - Serial.println(); - - static uint8_t buf[512]; - - /** In case the SD card/adapter was used for the file storagge, the SPI pins can be configure from - * MailClient.sdBegin function which may be different for ESP32 and ESP8266 - * For ESP32, assign all of SPI pins - * MailClient.sdBegin(14,2,15,13) - * Which SCK = 14, MISO = 2, MOSI = 15 and SS = 13 - * And for ESP8266, assign the CS pins of SPI port - * MailClient.sdBegin(15) - * Which pin 15 is the CS pin of SD card adapter - */ - - Serial.println("Mounting SD Card..."); - -#if defined(ESP32) - if (SD.begin()) // MailClient.sdBegin(14,2,15,13) for TTGO T8 v1.7 or 1.8 -#elif defined(ESP8266) - if (SD.begin(15)) -#endif - { - - if (SD.exists("/orange.png")) - SD.remove("/orange.png"); - if (SD.exists("/bin1.dat")) - SD.remove("/bin1.dat"); - - Serial.println("Preparing SD file attachments..."); - - const char *orangeImg = "iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAAoUlEQVR42u3RMQ0AMAgAsCFgftHLiQpsENJaaFT+fqwRQoQgRAhChCBECEKECBGCECEIEYIQIQgRghCECEGIEIQIQYgQhCBECEKEIEQIQoQgBCFCECIEIUIQIgQhCBGCECEIEYIQIQhBiBCECEGIEIQIQQhChCBECEKEIEQIQhAiBCFCECIEIUIQghAhCBGCECEIEYIQIUKEIEQIQoQg5LoBGi/oCaOpTXoAAAAASUVORK5CYII="; - - File file = SD.open("/orange.png", FILE_WRITE); - file.print(orangeImg); - file.close(); - - file = SD.open("/bin1.dat", FILE_WRITE); - - buf[0] = 'H'; - buf[1] = 'E'; - buf[2] = 'A'; - buf[3] = 'D'; - file.write(buf, 4); - - size_t i; - - for (i = 0; i < 4; i++) - { - memset(buf, i + 1, 512); - file.write(buf, 512); - } - - buf[0] = 'T'; - buf[1] = 'A'; - buf[2] = 'I'; - buf[3] = 'L'; - file.write(buf, 4); - file.close(); - } - else - { - Serial.println("SD Card Monting Failed"); - } - - Serial.println("Mounting SPIFFS..."); - -#if defined(ESP32) - if (SPIFFS.begin(true)) -#elif defined(ESP8266) - if (SPIFFS.begin()) -#endif - { - //SPIFFS.format(); - - if (SPIFFS.exists("/green.png")) - SPIFFS.remove("/green.png"); - if (SPIFFS.exists("/bin2.dat")) - SPIFFS.remove("/bin2.dat"); - - Serial.println("Preparing SPIFFS attachments..."); - - const char *greenImg = "iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAAoUlEQVR42u3RAQ0AMAgAoJviyWxtAtNYwzmoQGT/eqwRQoQgRAhChCBECEKECBGCECEIEYIQIQgRghCECEGIEIQIQYgQhCBECEKEIEQIQoQgBCFCECIEIUIQIgQhCBGCECEIEYIQIQhBiBCECEGIEIQIQQhChCBECEKEIEQIQhAiBCFCECIEIUIQghAhCBGCECEIEYIQIUKEIEQIQoQg5LoBBaDPbQYiMoMAAAAASUVORK5CYII="; - -#if defined(ESP32) - File file = SPIFFS.open("/green.png", FILE_WRITE); -#elif defined(ESP8266) - File file = SPIFFS.open("/green.png", "w"); -#endif - - file.print(greenImg); - file.close(); - -#if defined(ESP32) - file = SPIFFS.open("/bin2.dat", FILE_WRITE); -#elif defined(ESP8266) - file = SPIFFS.open("/bin2.dat", "w"); -#endif - - buf[0] = 'H'; - buf[1] = 'E'; - buf[2] = 'L'; - buf[3] = 'L'; - buf[4] = 'O'; - file.write(buf, 5); - - size_t i; - for (i = 0; i < 4; i++) - { - memset(buf, i + 1, 512); - file.write(buf, 512); - } - - buf[0] = 'G'; - buf[1] = 'O'; - buf[2] = 'O'; - buf[3] = 'D'; - buf[4] = 'B'; - buf[5] = 'Y'; - buf[6] = 'E'; - file.write(buf, 7); - file.close(); - } - else - { - Serial.println("SPIFFS Monting Failed"); - } - - /** Enable the debug via Serial port - * none debug or 0 - * basic debug or 1 - */ - smtp.debug(1); - - /* Set the callback function to get the sending results */ - smtp.callback(smtpCallback); - - /* Declare the session config data */ - ESP_Mail_Session session; - - /** ######################################################## - * Some properties of SMTPSession data and parameters pass to - * SMTP_Message class accept the pointer to constant char - * i.e. const char*. - * - * You may assign a string literal to that properties or function - * like below example. - * - * session.login.user_domain = "mydomain.net"; - * session.login.user_domain = String("mydomain.net").c_str(); - * - * or - * - * String doman = "mydomain.net"; - * session.login.user_domain = domain.c_str(); - * - * And - * - * String name = "Jack " + String("dawson"); - * String email = "jack_dawson" + String(123) + "@mail.com"; - * - * message.addRecipient(name.c_str(), email.c_str()); - * - * message.addHeader(String("Message-ID: ").c_str()); - * - * or - * - * String header = "Message-ID: "; - * message.addHeader(header.c_str()); - * - * ########################################################### - */ - - /* Set the session config */ - session.server.host_name = SMTP_HOST; - session.server.port = SMTP_PORT; - session.login.email = AUTHOR_EMAIL; - session.login.password = AUTHOR_PASSWORD; - session.login.user_domain = "mydomain.net"; - - /* Declare the message class */ - SMTP_Message message; - - /* Enable the chunked data transfer with pipelining for large message if server supported */ - message.enable.chunking = true; - - /* Set the message headers */ - message.sender.name = "ESP Mail"; - message.sender.email = AUTHOR_EMAIL; - - message.subject = "Test sending Email with attachments and inline images from SD card and Flash"; - message.addRecipient("user1", "####@#####_dot_com"); - - /** Two alternative content versions are sending in this example e.g. plain text and html */ - String htmlMsg = "This message contains 2 inline images and 2 attachment files.

"; - message.html.content = htmlMsg.c_str(); - - /** The HTML text message character set e.g. - * us-ascii - * utf-8 - * utf-7 - * The default value is utf-8 - */ - message.html.charSet = "utf-8"; - - /** The content transfer encoding e.g. - * enc_7bit or "7bit" (not encoded) - * enc_qp or "quoted-printable" (encoded) - * enc_base64 or "base64" (encoded) - * enc_binary or "binary" (not encoded) - * enc_8bit or "8bit" (not encoded) - * The default value is "7bit" - */ - message.html.transfer_encoding = Content_Transfer_Encoding::enc_qp; - - message.text.content = "This message contains 2 inline images and 2 attachment files.\r\nThe inline images were not shown in the plain text message."; - message.text.charSet = "utf-8"; - message.text.transfer_encoding = Content_Transfer_Encoding::enc_base64; - - /** The message priority - * esp_mail_smtp_priority_high or 1 - * esp_mail_smtp_priority_normal or 3 - * esp_mail_smtp_priority_low or 5 - * The default value is esp_mail_smtp_priority_low - */ - message.priority = esp_mail_smtp_priority::esp_mail_smtp_priority_normal; - - /** The Delivery Status Notifications e.g. - * esp_mail_smtp_notify_never - * esp_mail_smtp_notify_success - * esp_mail_smtp_notify_failure - * esp_mail_smtp_notify_delay - * The default value is esp_mail_smtp_notify_never - */ - message.response.notify = esp_mail_smtp_notify_success | esp_mail_smtp_notify_failure | esp_mail_smtp_notify_delay; - - /* Set the custom message header */ - message.addHeader("Message-ID: "); - - /* The attachment data item */ - SMTP_Attachment att; - - /** Set the inline image info e.g. - * file name, MIME type, file path, file storage type, - * transfer encoding and content encoding - */ - att.descr.filename = "orange.png"; - att.descr.mime = "image/png"; - att.file.path = "/orange.png"; - - /** The file storage type e.g. - * esp_mail_file_storage_type_none, - * esp_mail_file_storage_type_flash, and - * esp_mail_file_storage_type_sd - */ - att.file.storage_type = esp_mail_file_storage_type_sd; - - /* Need to be base64 transfer encoding for inline image */ - att.descr.transfer_encoding = Content_Transfer_Encoding::enc_base64; - - /** The orange.png file is already base64 encoded file. - * Then set the content encoding to match the transfer encoding - * which no encoding was taken place prior to sending. - */ - att.descr.content_encoding = Content_Transfer_Encoding::enc_base64; - - /* Add inline image to the message */ - message.addInlineImage(att); - - /** Set the attachment info e.g. - * file name, MIME type, file path, file storage type, - * transfer encoding and content encoding - */ - message.resetAttachItem(att); //Clear the attach item data to reuse - att.descr.filename = "bin1.dat"; - att.descr.mime = "application/octet-stream"; //binary data - att.file.path = "/bin1.dat"; - att.file.storage_type = esp_mail_file_storage_type_sd; - att.descr.transfer_encoding = Content_Transfer_Encoding::enc_base64; - - /* Add attachment to the message */ - message.addAttachment(att); - - /** Set the inline image info e.g. - * file name, MIME type, file path, file storage type, - * transfer encoding and content encoding - */ - message.resetAttachItem(att); //Clear the attach item data to reuse - att.descr.filename = "green.png"; - att.descr.mime = "image/png"; - att.file.path = "/green.png"; - att.file.storage_type = esp_mail_file_storage_type_flash; - att.descr.transfer_encoding = Content_Transfer_Encoding::enc_base64; - att.descr.content_encoding = Content_Transfer_Encoding::enc_base64; - message.addInlineImage(att); - - /** Set the attachment info e.g. - * file name, MIME type, file path, file storage type, - * transfer encoding and content encoding - */ - message.resetAttachItem(att); //Clear the attach item data to reuse - att.descr.filename = "bin2.dat"; - att.descr.mime = "application/octet-stream"; - att.file.path = "/bin2.dat"; - att.file.storage_type = esp_mail_file_storage_type_flash; - att.descr.transfer_encoding = Content_Transfer_Encoding::enc_base64; - message.addAttachment(att); - - /* Connect to server with the session config */ - if (!smtp.connect(&session)) - return; - - /* Start sending the Email and close the session */ - if (!MailClient.sendMail(&smtp, &message, true)) - Serial.println("Error sending Email, " + smtp.errorReason()); -} - -void loop() -{ -} - -/* Callback function to get the Email sending status */ -void smtpCallback(SMTP_Status status) -{ - /* Print the current status */ - Serial.println(status.info()); - - /* Print the sending result */ - if (status.success()) - { - Serial.println("----------------"); - Serial.printf("Message sent success: %d\n", status.completedCount()); - Serial.printf("Message sent failled: %d\n", status.failedCount()); - Serial.println("----------------\n"); - struct tm dt; - - for (size_t i = 0; i < smtp.sendingResult.size(); i++) - { - /* Get the result item */ - SMTP_Result result = smtp.sendingResult.getItem(i); - localtime_r(&result.timesstamp, &dt); - - Serial.printf("Message No: %d\n", i + 1); - Serial.printf("Status: %s\n", result.completed ? "success" : "failed"); - Serial.printf("Date/Time: %d/%d/%d %d:%d:%d\n", dt.tm_year + 1900, dt.tm_mon + 1, dt.tm_mday, dt.tm_hour, dt.tm_min, dt.tm_sec); - Serial.printf("Recipient: %s\n", result.recipients); - Serial.printf("Subject: %s\n", result.subject); - } - Serial.println("----------------\n"); - } -} diff --git a/lib/libesp32/lib_mail/examples/Send_Embedded_Message/Send_Embedded_Message.ino b/lib/libesp32/lib_mail/examples/Send_Embedded_Message/Send_Embedded_Message.ino deleted file mode 100644 index 8cc3b5e36..000000000 --- a/lib/libesp32/lib_mail/examples/Send_Embedded_Message/Send_Embedded_Message.ino +++ /dev/null @@ -1,203 +0,0 @@ - - -/** - * This example will send the Email which the - * message html and text body will be embedded as - * attachment or inline content. - * - * Created by K. Suwatchai (Mobizt) - * - * Email: suwatchai@outlook.com - * - * Github: https://github.com/mobizt/ESP-Mail-Client - * - * Copyright (c) 2021 mobizt - * -*/ - -//To use send Email for Gmail to port 465 (SSL), less secure app option should be enabled. https://myaccount.google.com/lesssecureapps?pli=1 - -#include -#if defined(ESP32) -#include -#elif defined(ESP8266) -#include -#endif -#include - - -#define WIFI_SSID "################" -#define WIFI_PASSWORD "################" - -/** The smtp host name e.g. smtp.gmail.com for GMail or smtp.office365.com for Outlook or smtp.mail.yahoo.com - * For yahoo mail, log in to your yahoo mail in web browser and generate app password by go to - * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc - * and use the app password as password with your yahoo mail account to login. - * The google app password signin is also available https://support.google.com/mail/answer/185833?hl=en -*/ -#define SMTP_HOST "################" - -/** The smtp port e.g. - * 25 or esp_mail_smtp_port_25 - * 465 or esp_mail_smtp_port_465 - * 587 or esp_mail_smtp_port_587 -*/ -#define SMTP_PORT 25 - -/* The log in credentials */ -#define AUTHOR_EMAIL "################" -#define AUTHOR_PASSWORD "################" - -/* The SMTP Session object used for Email sending */ -SMTPSession smtp; - -/* Callback function to get the Email sending status */ -void smtpCallback(SMTP_Status status); - -void setup() -{ - - Serial.begin(115200); - Serial.println(); - - Serial.print("Connecting to AP"); - - WiFi.begin(WIFI_SSID, WIFI_PASSWORD); - while (WiFi.status() != WL_CONNECTED) - { - Serial.print("."); - delay(200); - } - - Serial.println(""); - Serial.println("WiFi connected."); - Serial.println("IP address: "); - Serial.println(WiFi.localIP()); - Serial.println(); - - /** Enable the debug via Serial port - * none debug or 0 - * basic debug or 1 - */ - smtp.debug(1); - - /* Set the callback function to get the sending results */ - smtp.callback(smtpCallback); - - /* Declare the session config data */ - ESP_Mail_Session session; - - /* Set the session config */ - session.server.host_name = SMTP_HOST; - session.server.port = SMTP_PORT; - session.login.email = AUTHOR_EMAIL; - session.login.password = AUTHOR_PASSWORD; - session.login.user_domain = "mydomain.net"; - - /* Declare the message class */ - SMTP_Message message; - - /* Set the message headers */ - message.sender.name = "ESP Mail"; - message.sender.email = AUTHOR_EMAIL; - message.subject = "Test sending message as embedded files"; - message.addRecipient("Admin", "####@#####_dot_com"); - - message.html.content = "This is html message"; - - /** The Plain text message character set e.g. - * us-ascii - * utf-8 - * utf-7 - * The default value is utf-8 - */ - message.html.charSet = "utf-8"; - - /** The content transfer encoding e.g. - * enc_7bit or "7bit" (not encoded) - * enc_qp or "quoted-printable" (encoded) - * enc_base64 or "base64" (encoded) - * enc_binary or "binary" (not encoded) - * enc_8bit or "8bit" (not encoded) - * The default value is "7bit" - */ - message.html.transfer_encoding = Content_Transfer_Encoding::enc_qp; - - /* Enable to send this message body as file */ - message.html.embed.enable = true; - - /* The name of embedded file */ - message.html.embed.filename = "test.html"; - - /** The embedded type - * esp_mail_smtp_embed_message_type_attachment or 0 - * esp_mail_smtp_embed_message_type_inline or 1 - */ - message.html.embed.type = esp_mail_smtp_embed_message_type_attachment; - - - - message.text.content = "This is simple plain text message"; - message.text.charSet = "utf-8"; - message.text.transfer_encoding = Content_Transfer_Encoding::enc_base64; - message.text.embed.enable = true; - message.text.embed.filename = "test.txt"; - message.text.embed.type = esp_mail_smtp_embed_message_type_inline; - - - /** The message priority - * esp_mail_smtp_priority_high or 1 - * esp_mail_smtp_priority_normal or 3 - * esp_mail_smtp_priority_low or 5 - * The default value is esp_mail_smtp_priority_low - */ - message.priority = esp_mail_smtp_priority::esp_mail_smtp_priority_low; - - - /* Set the custom message header */ - message.addHeader("Message-ID: "); - - - /* Connect to server with the session config */ - if (!smtp.connect(&session)) - return; - - /* Start sending Email and close the session */ - if (!MailClient.sendMail(&smtp, &message)) - Serial.println("Error sending Email, " + smtp.errorReason()); -} - -void loop() -{ -} - -/* Callback function to get the Email sending status */ -void smtpCallback(SMTP_Status status) -{ - /* Print the current status */ - Serial.println(status.info()); - - /* Print the sending result */ - if (status.success()) - { - Serial.println("----------------"); - Serial.printf("Message sent success: %d\n", status.completedCount()); - Serial.printf("Message sent failled: %d\n", status.failedCount()); - Serial.println("----------------\n"); - struct tm dt; - - for (size_t i = 0; i < smtp.sendingResult.size(); i++) - { - /* Get the result item */ - SMTP_Result result = smtp.sendingResult.getItem(i); - localtime_r(&result.timesstamp, &dt); - - Serial.printf("Message No: %d\n", i + 1); - Serial.printf("Status: %s\n", result.completed ? "success" : "failed"); - Serial.printf("Date/Time: %d/%d/%d %d:%d:%d\n", dt.tm_year + 1900, dt.tm_mon + 1, dt.tm_mday, dt.tm_hour, dt.tm_min, dt.tm_sec); - Serial.printf("Recipient: %s\n", result.recipients); - Serial.printf("Subject: %s\n", result.subject); - } - Serial.println("----------------\n"); - } -} diff --git a/lib/libesp32/lib_mail/examples/Send_Enriched_Text/Send_Enriched_Text.ino b/lib/libesp32/lib_mail/examples/Send_Enriched_Text/Send_Enriched_Text.ino deleted file mode 100644 index be8f2578d..000000000 --- a/lib/libesp32/lib_mail/examples/Send_Enriched_Text/Send_Enriched_Text.ino +++ /dev/null @@ -1,187 +0,0 @@ - - -/** - * This example will send the Email in enriched text version. - * - * Created by K. Suwatchai (Mobizt) - * - * Email: suwatchai@outlook.com - * - * Github: https://github.com/mobizt/ESP-Mail-Client - * - * Copyright (c) 2021 mobizt - * -*/ - -//To use send Email for Gmail to port 465 (SSL), less secure app option should be enabled. https://myaccount.google.com/lesssecureapps?pli=1 - -#include -#if defined(ESP32) -#include -#elif defined(ESP8266) -#include -#endif -#include - -#define WIFI_SSID "################" -#define WIFI_PASSWORD "################" - -/** The smtp host name e.g. smtp.gmail.com for GMail or smtp.office365.com for Outlook or smtp.mail.yahoo.com - * For yahoo mail, log in to your yahoo mail in web browser and generate app password by go to - * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc - * and use the app password as password with your yahoo mail account to login. - * The google app password signin is also available https://support.google.com/mail/answer/185833?hl=en -*/ -#define SMTP_HOST "################" - -/** The smtp port e.g. - * 25 or esp_mail_smtp_port_25 - * 465 or esp_mail_smtp_port_465 - * 587 or esp_mail_smtp_port_587 -*/ -#define SMTP_PORT 25 - -/* The log in credentials */ -#define AUTHOR_EMAIL "################" -#define AUTHOR_PASSWORD "################" - -/* The SMTP Session object used for Email sending */ -SMTPSession smtp; - -/* Callback function to get the Email sending status */ -void smtpCallback(SMTP_Status status); - -void setup() -{ - - Serial.begin(115200); - Serial.println(); - - Serial.print("Connecting to AP"); - - WiFi.begin(WIFI_SSID, WIFI_PASSWORD); - while (WiFi.status() != WL_CONNECTED) - { - Serial.print("."); - delay(200); - } - - Serial.println(""); - Serial.println("WiFi connected."); - Serial.println("IP address: "); - Serial.println(WiFi.localIP()); - Serial.println(); - - /** Enable the debug via Serial port - * none debug or 0 - * basic debug or 1 - */ - smtp.debug(1); - - /* Set the callback function to get the sending results */ - smtp.callback(smtpCallback); - - /* Declare the session config data */ - ESP_Mail_Session session; - - /* Set the session config */ - session.server.host_name = SMTP_HOST; - session.server.port = SMTP_PORT; - session.login.email = AUTHOR_EMAIL; - session.login.password = AUTHOR_PASSWORD; - session.login.user_domain = "mydomain.net"; - - /* Declare the message class */ - SMTP_Message message; - - /* Set the message headers */ - message.sender.name = "ESP Mail"; - message.sender.email = AUTHOR_EMAIL; - message.subject = "Test sending enriched text Email"; - message.addRecipient("Someone", "####@#####_dot_com"); - - message.text.content = "This is enriched as defined in RFC 1896\r\n\r\nIsn't it cool?"; - - message.text.content_type = "text/enriched"; - - /** The Plain text message character set e.g. - * us-ascii - * utf-8 - * utf-7 - * The default value is utf-8 - */ - message.text.charSet = "us-ascii"; - - /** The content transfer encoding e.g. - * enc_7bit or "7bit" (not encoded) - * enc_qp or "quoted-printable" (encoded) - * enc_base64 or "base64" (encoded) - * enc_binary or "binary" (not encoded) - * enc_8bit or "8bit" (not encoded) - * The default value is "7bit" - */ - message.text.transfer_encoding = Content_Transfer_Encoding::enc_7bit; - - /** The message priority - * esp_mail_smtp_priority_high or 1 - * esp_mail_smtp_priority_normal or 3 - * esp_mail_smtp_priority_low or 5 - * The default value is esp_mail_smtp_priority_low - */ - message.priority = esp_mail_smtp_priority::esp_mail_smtp_priority_low; - - /** The Delivery Status Notifications e.g. - * esp_mail_smtp_notify_never - * esp_mail_smtp_notify_success - * esp_mail_smtp_notify_failure - * esp_mail_smtp_notify_delay - * The default value is esp_mail_smtp_notify_never - */ - message.response.notify = esp_mail_smtp_notify_success | esp_mail_smtp_notify_failure | esp_mail_smtp_notify_delay; - - /* Set the custom message header */ - message.addHeader("Message-ID: "); - - /* Connect to server with the session config */ - if (!smtp.connect(&session)) - return; - - /* Start sending Email and close the session */ - if (!MailClient.sendMail(&smtp, &message)) - Serial.println("Error sending Email, " + smtp.errorReason()); -} - -void loop() -{ -} - -/* Callback function to get the Email sending status */ -void smtpCallback(SMTP_Status status) -{ - /* Print the current status */ - Serial.println(status.info()); - - /* Print the sending result */ - if (status.success()) - { - Serial.println("----------------"); - Serial.printf("Message sent success: %d\n", status.completedCount()); - Serial.printf("Message sent failled: %d\n", status.failedCount()); - Serial.println("----------------\n"); - struct tm dt; - - for (size_t i = 0; i < smtp.sendingResult.size(); i++) - { - /* Get the result item */ - SMTP_Result result = smtp.sendingResult.getItem(i); - localtime_r(&result.timesstamp, &dt); - - Serial.printf("Message No: %d\n", i + 1); - Serial.printf("Status: %s\n", result.completed ? "success" : "failed"); - Serial.printf("Date/Time: %d/%d/%d %d:%d:%d\n", dt.tm_year + 1900, dt.tm_mon + 1, dt.tm_mday, dt.tm_hour, dt.tm_min, dt.tm_sec); - Serial.printf("Recipient: %s\n", result.recipients); - Serial.printf("Subject: %s\n", result.subject); - } - Serial.println("----------------\n"); - } -} diff --git a/lib/libesp32/lib_mail/examples/Send_Flash_Message_with_Inline_Image/Send_Flash_Message_with_Inline_Image.ino b/lib/libesp32/lib_mail/examples/Send_Flash_Message_with_Inline_Image/Send_Flash_Message_with_Inline_Image.ino deleted file mode 100644 index 1ba0a3ec5..000000000 --- a/lib/libesp32/lib_mail/examples/Send_Flash_Message_with_Inline_Image/Send_Flash_Message_with_Inline_Image.ino +++ /dev/null @@ -1,287 +0,0 @@ - - -/** - * This example will send the Email with inline images stored in flash memory. - * The message content stores as HTML data in flash memory - * - * The html and text version messages will be sent. - * - * Created by K. Suwatchai (Mobizt) - * - * Email: suwatchai@outlook.com - * - * Github: https://github.com/mobizt/ESP-Mail-Client - * - * Copyright (c) 2021 mobizt - * -*/ - -//To use send Email for Gmail to port 465 (SSL), less secure app option should be enabled. https://myaccount.google.com/lesssecureapps?pli=1 - -//The file systems for flash and sd memory can be changed in ESP_Mail_FS.h. - -#include -#if defined(ESP32) -#include -#elif defined(ESP8266) -#include -#endif -#include - -#define WIFI_SSID "################" -#define WIFI_PASSWORD "################" - -/** The smtp host name e.g. smtp.gmail.com for GMail or smtp.office365.com for Outlook or smtp.mail.yahoo.com - * For yahoo mail, log in to your yahoo mail in web browser and generate app password by go to - * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc - * and use the app password as password with your yahoo mail account to login. - * The google app password signin is also available https://support.google.com/mail/answer/185833?hl=en -*/ -#define SMTP_HOST "################" - -/** The smtp port e.g. - * 25 or esp_mail_smtp_port_25 - * 465 or esp_mail_smtp_port_465 - * 587 or esp_mail_smtp_port_587 -*/ -#define SMTP_PORT esp_mail_smtp_port_587 - -/* The log in credentials */ -#define AUTHOR_EMAIL "################" -#define AUTHOR_PASSWORD "################" - -/* The SMTP Session object used for Email sending */ -SMTPSession smtp; - -/* Callback function to get the Email sending status */ -void smtpCallback(SMTP_Status status); - -void setup() -{ - - Serial.begin(115200); - Serial.println(); - - Serial.print("Connecting to AP"); - - WiFi.begin(WIFI_SSID, WIFI_PASSWORD); - while (WiFi.status() != WL_CONNECTED) - { - Serial.print("."); - delay(200); - } - - Serial.println(""); - Serial.println("WiFi connected."); - Serial.println("IP address: "); - Serial.println(WiFi.localIP()); - Serial.println(); - - Serial.println("Mounting SPIFFS..."); - - const char *html = "This message contains 2 inline images.

\"orange \"green"; - const char *orangeImg = "iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAAoUlEQVR42u3RMQ0AMAgAsCFgftHLiQpsENJaaFT+fqwRQoQgRAhChCBECEKECBGCECEIEYIQIQgRghCECEGIEIQIQYgQhCBECEKEIEQIQoQgBCFCECIEIUIQIgQhCBGCECEIEYIQIQhBiBCECEGIEIQIQQhChCBECEKEIEQIQhAiBCFCECIEIUIQghAhCBGCECEIEYIQIUKEIEQIQoQg5LoBGi/oCaOpTXoAAAAASUVORK5CYII="; - const char *greenImg = "iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAAoUlEQVR42u3RAQ0AMAgAoJviyWxtAtNYwzmoQGT/eqwRQoQgRAhChCBECEKECBGCECEIEYIQIQgRghCECEGIEIQIQYgQhCBECEKEIEQIQoQgBCFCECIEIUIQIgQhCBGCECEIEYIQIQhBiBCECEGIEIQIQQhChCBECEKEIEQIQhAiBCFCECIEIUIQghAhCBGCECEIEYIQIUKEIEQIQoQg5LoBBaDPbQYiMoMAAAAASUVORK5CYII="; - -#if defined(ESP32) - if (SPIFFS.begin(true)) -#elif defined(ESP8266) - if (SPIFFS.begin()) -#endif - { - - //SPIFFS.format(); - - if (SPIFFS.exists("/orange.png")) - SPIFFS.remove("/orange.png"); - if (SPIFFS.exists("/green.png")) - SPIFFS.remove("/green.png"); - if (SPIFFS.exists("/msg.html")) - SPIFFS.remove("/msg.html"); - - Serial.println("Preparing SPIFFS attachments..."); - -#if defined(ESP32) - File file = SPIFFS.open("/orange.png", FILE_WRITE); -#elif defined(ESP8266) - File file = SPIFFS.open("/orange.png", "w"); -#endif - file.print(orangeImg); - file.close(); - -#if defined(ESP32) - file = SPIFFS.open("/green.png", FILE_WRITE); -#elif defined(ESP8266) - file = SPIFFS.open("/green.png", "w"); -#endif - file.print(greenImg); - file.close(); - -#if defined(ESP32) - file = SPIFFS.open("/msg.html", FILE_WRITE); -#elif defined(ESP8266) - file = SPIFFS.open("/msg.html", "w"); -#endif - file.print(html); - file.close(); - } - else - { - Serial.println("SPIFFS Monting Failed"); - } - - /** Enable the debug via Serial port - * none debug or 0 - * basic debug or 1 - */ - smtp.debug(1); - - /* Set the callback function to get the sending results */ - smtp.callback(smtpCallback); - - /* Declare the session config data */ - ESP_Mail_Session session; - - /* Set the session config */ - session.server.host_name = SMTP_HOST; - session.server.port = SMTP_PORT; - session.login.email = AUTHOR_EMAIL; - session.login.password = AUTHOR_PASSWORD; - session.login.user_domain = "mydomain.net"; - - /* Declare the message class */ - SMTP_Message message; - - /* Enable the chunked data transfer with pipelining for large message if server supported */ - message.enable.chunking = true; - - /* Set the message headers */ - message.sender.name = "ESP Mail"; - message.sender.email = AUTHOR_EMAIL; - - message.subject = "Test sending Email with message content and inline images stored in flash memory"; - message.addRecipient("user1", "####@#####_dot_com"); - - /* Two alternative content versions are sending in this example e.g. plain text and html */ - - /* Assign blob data (in flash or ram) as HTML message */ - message.html.blob.data = (const uint8_t *)html; - message.html.blob.size = strlen(html); - - //Or get the content from file - //message.html.file.name = "/msg.html"; - //message.html.file.type = esp_mail_file_storage_type_flash; - - /** The content transfer encoding e.g. - * enc_7bit or "7bit" (not encoded) - * enc_qp or "quoted-printable" (encoded) <- not supported for message from blob and file - * enc_base64 or "base64" (encoded) - * enc_binary or "binary" (not encoded) - * enc_8bit or "8bit" (not encoded) - * The default value is "7bit" - */ - message.html.transfer_encoding = Content_Transfer_Encoding::enc_7bit; - - /** The HTML text message character set e.g. - * us-ascii - * utf-8 - * utf-7 - * The default value is utf-8 - */ - message.html.charSet = "utf-8"; - - message.text.content = "This message contains 2 inline images.\r\nThe inline images were not shown in the plain text message."; - message.text.charSet = "utf-8"; - message.text.transfer_encoding = Content_Transfer_Encoding::enc_base64; - - /* Set the custom message header */ - message.addHeader("Message-ID: "); - - /* The attachment data item */ - SMTP_Attachment att; - - /** Set the inline image info e.g. - * file name, MIME type, file path, file storage type, - * transfer encoding and content encoding - */ - att.descr.filename = "orange.png"; - att.descr.mime = "image/png"; - att.file.path = "/orange.png"; - att.descr.content_id = "image-001"; //The content id (cid) of orange image in the src tag - - /** The file storage type e.g. - * esp_mail_file_storage_type_none, - * esp_mail_file_storage_type_flash, and - * esp_mail_file_storage_type_sd - */ - att.file.storage_type = esp_mail_file_storage_type_flash; - - /* Need to be base64 transfer encoding for inline image */ - att.descr.transfer_encoding = Content_Transfer_Encoding::enc_base64; - - /** The orange.png file is already base64 encoded file. - * Then set the content encoding to match the transfer encoding - * which no encoding was taken place prior to sending. - */ - att.descr.content_encoding = Content_Transfer_Encoding::enc_base64; - - /* Add inline image to the message */ - message.addInlineImage(att); - - /** Set the inline image info e.g. - * file name, MIME type, file path, file storage type, - * transfer encoding and content encoding - */ - message.resetAttachItem(att); //Clear the attach item data to reuse - att.descr.filename = "green.png"; - att.descr.mime = "image/png"; - att.file.path = "/green.png"; - att.descr.content_id = "image-002"; //The content id (cid) of green image in the src tag - att.file.storage_type = esp_mail_file_storage_type_flash; - att.descr.transfer_encoding = Content_Transfer_Encoding::enc_base64; - att.descr.content_encoding = Content_Transfer_Encoding::enc_base64; - message.addInlineImage(att); - - /* Connect to server with the session config */ - if (!smtp.connect(&session)) - return; - - /* Start sending the Email and close the session */ - if (!MailClient.sendMail(&smtp, &message, true)) - Serial.println("Error sending Email, " + smtp.errorReason()); -} - -void loop() -{ -} - -/* Callback function to get the Email sending status */ -void smtpCallback(SMTP_Status status) -{ - /* Print the current status */ - Serial.println(status.info()); - - /* Print the sending result */ - if (status.success()) - { - Serial.println("----------------"); - Serial.printf("Message sent success: %d\n", status.completedCount()); - Serial.printf("Message sent failled: %d\n", status.failedCount()); - Serial.println("----------------\n"); - struct tm dt; - - for (size_t i = 0; i < smtp.sendingResult.size(); i++) - { - /* Get the result item */ - SMTP_Result result = smtp.sendingResult.getItem(i); - localtime_r(&result.timesstamp, &dt); - - Serial.printf("Message No: %d\n", i + 1); - Serial.printf("Status: %s\n", result.completed ? "success" : "failed"); - Serial.printf("Date/Time: %d/%d/%d %d:%d:%d\n", dt.tm_year + 1900, dt.tm_mon + 1, dt.tm_mday, dt.tm_hour, dt.tm_min, dt.tm_sec); - Serial.printf("Recipient: %s\n", result.recipients); - Serial.printf("Subject: %s\n", result.subject); - } - Serial.println("----------------\n"); - } -} diff --git a/lib/libesp32/lib_mail/examples/Send_HTML/Send_HTML.ino b/lib/libesp32/lib_mail/examples/Send_HTML/Send_HTML.ino deleted file mode 100644 index 81b0a5998..000000000 --- a/lib/libesp32/lib_mail/examples/Send_HTML/Send_HTML.ino +++ /dev/null @@ -1,221 +0,0 @@ - - -/** - * This example will send the Email in - * the html version. - * - * - * Created by K. Suwatchai (Mobizt) - * - * Email: suwatchai@outlook.com - * - * Github: https://github.com/mobizt/ESP-Mail-Client - * - * Copyright (c) 2021 mobizt - * -*/ - -//To use send Email for Gmail to port 465 (SSL), less secure app option should be enabled. https://myaccount.google.com/lesssecureapps?pli=1 - -#include -#if defined(ESP32) -#include -#elif defined(ESP8266) -#include -#endif -#include - -#define WIFI_SSID "################" -#define WIFI_PASSWORD "################" - -/** The smtp host name e.g. smtp.gmail.com for GMail or smtp.office365.com for Outlook or smtp.mail.yahoo.com - * For yahoo mail, log in to your yahoo mail in web browser and generate app password by go to - * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc - * and use the app password as password with your yahoo mail account to login. - * The google app password signin is also available https://support.google.com/mail/answer/185833?hl=en -*/ -#define SMTP_HOST "################" - -/** The smtp port e.g. - * 25 or esp_mail_smtp_port_25 - * 465 or esp_mail_smtp_port_465 - * 587 or esp_mail_smtp_port_587 -*/ -#define SMTP_PORT 25 - -/* The log in credentials */ -#define AUTHOR_EMAIL "################" -#define AUTHOR_PASSWORD "################" - -/* The SMTP Session object used for Email sending */ -SMTPSession smtp; - -/* Callback function to get the Email sending status */ -void smtpCallback(SMTP_Status status); - -void setup() -{ - - Serial.begin(115200); - Serial.println(); - - Serial.print("Connecting to AP"); - - WiFi.begin(WIFI_SSID, WIFI_PASSWORD); - while (WiFi.status() != WL_CONNECTED) - { - Serial.print("."); - delay(200); - } - - Serial.println(""); - Serial.println("WiFi connected."); - Serial.println("IP address: "); - Serial.println(WiFi.localIP()); - Serial.println(); - - /** Enable the debug via Serial port - * none debug or 0 - * basic debug or 1 - */ - smtp.debug(1); - - /* Set the callback function to get the sending results */ - smtp.callback(smtpCallback); - - /* Declare the session config data */ - ESP_Mail_Session session; - - /** ######################################################## - * Some properties of SMTPSession data and parameters pass to - * SMTP_Message class accept the pointer to constant char - * i.e. const char*. - * - * You may assign a string literal to that properties or function - * like below example. - * - * session.login.user_domain = "mydomain.net"; - * session.login.user_domain = String("mydomain.net").c_str(); - * - * or - * - * String doman = "mydomain.net"; - * session.login.user_domain = domain.c_str(); - * - * And - * - * String name = "Jack " + String("dawson"); - * String email = "jack_dawson" + String(123) + "@mail.com"; - * - * message.addRecipient(name.c_str(), email.c_str()); - * - * message.addHeader(String("Message-ID: ").c_str()); - * - * or - * - * String header = "Message-ID: "; - * message.addHeader(header.c_str()); - * - * ########################################################### - */ - - /* Set the session config */ - session.server.host_name = SMTP_HOST; - session.server.port = SMTP_PORT; - session.login.email = AUTHOR_EMAIL; - session.login.password = AUTHOR_PASSWORD; - session.login.user_domain = "mydomain.net"; - - /* Declare the message class */ - SMTP_Message message; - - /* Set the message headers */ - message.sender.name = "ESP Mail"; - message.sender.email = AUTHOR_EMAIL; - message.subject = "Test sending html Email"; - message.addRecipient("Admin", "####@#####_dot_com"); - - String htmlMsg = "

This is the html text message.

The message was sent via ESP device.

"; - message.html.content = htmlMsg.c_str(); - - /** The html text message character set e.g. - * us-ascii - * utf-8 - * utf-7 - * The default value is utf-8 - */ - message.html.charSet = "us-ascii"; - - /** The content transfer encoding e.g. - * enc_7bit or "7bit" (not encoded) - * enc_qp or "quoted-printable" (encoded) - * enc_base64 or "base64" (encoded) - * enc_binary or "binary" (not encoded) - * enc_8bit or "8bit" (not encoded) - * The default value is "7bit" - */ - message.html.transfer_encoding = Content_Transfer_Encoding::enc_7bit; - - /** The message priority - * esp_mail_smtp_priority_high or 1 - * esp_mail_smtp_priority_normal or 3 - * esp_mail_smtp_priority_low or 5 - * The default value is esp_mail_smtp_priority_low - */ - message.priority = esp_mail_smtp_priority::esp_mail_smtp_priority_low; - - /** The Delivery Status Notifications e.g. - * esp_mail_smtp_notify_never - * esp_mail_smtp_notify_success - * esp_mail_smtp_notify_failure - * esp_mail_smtp_notify_delay - * The default value is esp_mail_smtp_notify_never - */ - message.response.notify = esp_mail_smtp_notify_success | esp_mail_smtp_notify_failure | esp_mail_smtp_notify_delay; - - /* Set the custom message header */ - message.addHeader("Message-ID: "); - - /* Connect to server with the session config */ - if (!smtp.connect(&session)) - return; - - /* Start sending Email and close the session */ - if (!MailClient.sendMail(&smtp, &message)) - Serial.println("Error sending Email, " + smtp.errorReason()); -} - -void loop() -{ -} - -/* Callback function to get the Email sending status */ -void smtpCallback(SMTP_Status status) -{ - /* Print the current status */ - Serial.println(status.info()); - - /* Print the sending result */ - if (status.success()) - { - Serial.println("----------------"); - Serial.printf("Message sent success: %d\n", status.completedCount()); - Serial.printf("Message sent failled: %d\n", status.failedCount()); - Serial.println("----------------\n"); - struct tm dt; - - for (size_t i = 0; i < smtp.sendingResult.size(); i++) - { - /* Get the result item */ - SMTP_Result result = smtp.sendingResult.getItem(i); - localtime_r(&result.timesstamp, &dt); - - Serial.printf("Message No: %d\n", i + 1); - Serial.printf("Status: %s\n", result.completed ? "success" : "failed"); - Serial.printf("Date/Time: %d/%d/%d %d:%d:%d\n", dt.tm_year + 1900, dt.tm_mon + 1, dt.tm_mday, dt.tm_hour, dt.tm_min, dt.tm_sec); - Serial.printf("Recipient: %s\n", result.recipients); - Serial.printf("Subject: %s\n", result.subject); - } - Serial.println("----------------\n"); - } -} diff --git a/lib/libesp32/lib_mail/examples/Send_Parallel_Attachment/Send_Parallel_Attachment.ino b/lib/libesp32/lib_mail/examples/Send_Parallel_Attachment/Send_Parallel_Attachment.ino deleted file mode 100644 index 65f6d3536..000000000 --- a/lib/libesp32/lib_mail/examples/Send_Parallel_Attachment/Send_Parallel_Attachment.ino +++ /dev/null @@ -1,229 +0,0 @@ - - -/** - * This example will send the Email with media as parallen attachments - * e.g. audio and images and play or display them simultaneously on the Email client. - * - * This depends on the Mail client supports. - * - * The html and text version messages will be sent. - * - * Created by K. Suwatchai (Mobizt) - * - * Email: suwatchai@outlook.com - * - * Github: https://github.com/mobizt/ESP-Mail-Client - * - * Copyright (c) 2021 mobizt - * -*/ - -//To use send Email for Gmail to port 465 (SSL), less secure app option should be enabled. https://myaccount.google.com/lesssecureapps?pli=1 - -//The file systems for flash and sd memory can be changed in ESP_Mail_FS.h. - -#include -#if defined(ESP32) -#include -#elif defined(ESP8266) -#include -#endif -#include - -/* This is for attachment data */ -#include "data.h" - -#define WIFI_SSID "################" -#define WIFI_PASSWORD "################" - -/** The smtp host name e.g. smtp.gmail.com for GMail or smtp.office365.com for Outlook or smtp.mail.yahoo.com - * For yahoo mail, log in to your yahoo mail in web browser and generate app password by go to - * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc - * and use the app password as password with your yahoo mail account to login -*/ -#define SMTP_HOST "################" - -/** The smtp port e.g. - * 25 or esp_mail_smtp_port_25 - * 465 or esp_mail_smtp_port_465 - * 587 or esp_mail_smtp_port_587 -*/ -#define SMTP_PORT esp_mail_smtp_port_587 - -/* The log in credentials */ -#define AUTHOR_EMAIL "################" -#define AUTHOR_PASSWORD "################" - -/* The SMTP Session object used for Email sending */ -SMTPSession smtp; - -/* Callback function to get the Email sending status */ -void smtpCallback(SMTP_Status status); - -void setup() -{ - - Serial.begin(115200); - Serial.println(); - - Serial.print("Connecting to AP"); - - WiFi.begin(WIFI_SSID, WIFI_PASSWORD); - while (WiFi.status() != WL_CONNECTED) - { - Serial.print("."); - delay(200); - } - - Serial.println(""); - Serial.println("WiFi connected."); - Serial.println("IP address: "); - Serial.println(WiFi.localIP()); - Serial.println(); - - /** Enable the debug via Serial port - * none debug or 0 - * basic debug or 1 - */ - smtp.debug(1); - - /* Set the callback function to get the sending results */ - smtp.callback(smtpCallback); - - /* Declare the session config data */ - ESP_Mail_Session session; - - /* Set the session config */ - session.server.host_name = SMTP_HOST; - session.server.port = SMTP_PORT; - session.login.email = AUTHOR_EMAIL; - session.login.password = AUTHOR_PASSWORD; - session.login.user_domain = "mydomain.net"; - - /* Declare the message class */ - SMTP_Message message; - - /* Enable the chunked data transfer with pipelining for large message if server supported */ - message.enable.chunking = true; - - /* Set the message headers */ - message.sender.name = "ESP Mail"; - message.sender.email = AUTHOR_EMAIL; - - message.subject = "Test sending Email with parallel attachments"; - message.addRecipient("user1", "####@#####_dot_com"); - - message.html.content = "This message contains image and audio file which will play on the Mail client in parallel or simultaneously (depends on the client supports)."; - - /** The HTML text message character set e.g. - * us-ascii - * utf-8 - * utf-7 - * The default value is utf-8 - */ - message.html.charSet = "utf-8"; - - /** The content transfer encoding e.g. - * enc_7bit or "7bit" (not encoded) - * enc_qp or "quoted-printable" (encoded) - * enc_base64 or "base64" (encoded) - * enc_binary or "binary" (not encoded) - * enc_8bit or "8bit" (not encoded) - * The default value is "7bit" - */ - message.html.transfer_encoding = Content_Transfer_Encoding::enc_qp; - - message.text.content = "This message contains image and audio file which will play on the Mail client in parallel or simultaneously (depends on the client supports)."; - message.text.charSet = "us-ascii"; - message.text.transfer_encoding = Content_Transfer_Encoding::enc_base64; - - /** The message priority - * esp_mail_smtp_priority_high or 1 - * esp_mail_smtp_priority_normal or 3 - * esp_mail_smtp_priority_low or 5 - * The default value is esp_mail_smtp_priority_low - */ - message.priority = esp_mail_smtp_priority::esp_mail_smtp_priority_normal; - - /** The Delivery Status Notifications e.g. - * esp_mail_smtp_notify_never - * esp_mail_smtp_notify_success - * esp_mail_smtp_notify_failure - * esp_mail_smtp_notify_delay - * The default value is esp_mail_smtp_notify_never - */ - message.response.notify = esp_mail_smtp_notify_success | esp_mail_smtp_notify_failure | esp_mail_smtp_notify_delay; - - /* Set the custom message header */ - message.addHeader("Message-ID: "); - - /* The attachment data item */ - SMTP_Attachment att; - - /** Set the attachment info e.g. - * file name, MIME type, file path, file storage type, - * transfer encoding and content encoding - */ - att.descr.filename = "haun.png"; - att.descr.mime = "image/png"; - att.blob.data = shaun_png; - att.blob.size = sizeof(shaun_png); - att.descr.transfer_encoding = Content_Transfer_Encoding::enc_base64; - message.addParallelAttachment(att); - - /** Set the attachment info e.g. - * file name, MIME type, file path, file storage type, - * transfer encoding and content encoding - */ - message.resetAttachItem(att); //Clear the attach item data to reuse - att.descr.filename = "mu_law.wav"; - att.descr.mime = "audio/basic"; - att.blob.data = mu_law_wave; - att.blob.size = sizeof(mu_law_wave); - att.descr.transfer_encoding = Content_Transfer_Encoding::enc_base64; - - message.addParallelAttachment(att); - - /* Connect to server with the session config */ - if (!smtp.connect(&session)) - return; - - /* Start sending the Email and close the session */ - if (!MailClient.sendMail(&smtp, &message, true)) - Serial.println("Error sending Email, " + smtp.errorReason()); -} - -void loop() -{ -} - -/* Callback function to get the Email sending status */ -void smtpCallback(SMTP_Status status) -{ - /* Print the current status */ - Serial.println(status.info()); - - /* Print the sending result */ - if (status.success()) - { - Serial.println("----------------"); - Serial.printf("Message sent success: %d\n", status.completedCount()); - Serial.printf("Message sent failled: %d\n", status.failedCount()); - Serial.println("----------------\n"); - struct tm dt; - - for (size_t i = 0; i < smtp.sendingResult.size(); i++) - { - /* Get the result item */ - SMTP_Result result = smtp.sendingResult.getItem(i); - localtime_r(&result.timesstamp, &dt); - - Serial.printf("Message No: %d\n", i + 1); - Serial.printf("Status: %s\n", result.completed ? "success" : "failed"); - Serial.printf("Date/Time: %d/%d/%d %d:%d:%d\n", dt.tm_year + 1900, dt.tm_mon + 1, dt.tm_mday, dt.tm_hour, dt.tm_min, dt.tm_sec); - Serial.printf("Recipient: %s\n", result.recipients); - Serial.printf("Subject: %s\n", result.subject); - } - Serial.println("----------------\n"); - } -} diff --git a/lib/libesp32/lib_mail/examples/Send_RFC822_Attachment/Send_RFC822_Attachment.ino b/lib/libesp32/lib_mail/examples/Send_RFC822_Attachment/Send_RFC822_Attachment.ino deleted file mode 100644 index 371515fe1..000000000 --- a/lib/libesp32/lib_mail/examples/Send_RFC822_Attachment/Send_RFC822_Attachment.ino +++ /dev/null @@ -1,252 +0,0 @@ - - -/** - * This example will send the Email in plain text version - * with rfc822 message attachment which the rfc822 message - * also contains its attachement. - * - * Created by K. Suwatchai (Mobizt) - * - * Email: suwatchai@outlook.com - * - * Github: https://github.com/mobizt/ESP-Mail-Client - * - * Copyright (c) 2021 mobizt - * -*/ - -//To use send Email for Gmail to port 465 (SSL), less secure app option should be enabled. https://myaccount.google.com/lesssecureapps?pli=1 - -#include -#if defined(ESP32) -#include -#elif defined(ESP8266) -#include -#endif -#include - -/* This is for attachment data */ -#include "image.h" - -#define WIFI_SSID "################" -#define WIFI_PASSWORD "################" - -/** The smtp host name e.g. smtp.gmail.com for GMail or smtp.office365.com for Outlook or smtp.mail.yahoo.com - * For yahoo mail, log in to your yahoo mail in web browser and generate app password by go to - * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc - * and use the app password as password with your yahoo mail account to login. - * The google app password signin is also available https://support.google.com/mail/answer/185833?hl=en -*/ -#define SMTP_HOST "################" - -/** The smtp port e.g. - * 25 or esp_mail_smtp_port_25 - * 465 or esp_mail_smtp_port_465 - * 587 or esp_mail_smtp_port_587 -*/ -#define SMTP_PORT 25 - -/* The log in credentials */ -#define AUTHOR_EMAIL "################" -#define AUTHOR_PASSWORD "################" - -/* The SMTP Session object used for Email sending */ -SMTPSession smtp; - -/* Callback function to get the Email sending status */ -void smtpCallback(SMTP_Status status); - -void setup() -{ - - Serial.begin(115200); - Serial.println(); - - Serial.print("Connecting to AP"); - - WiFi.begin(WIFI_SSID, WIFI_PASSWORD); - while (WiFi.status() != WL_CONNECTED) - { - Serial.print("."); - delay(200); - } - - Serial.println(""); - Serial.println("WiFi connected."); - Serial.println("IP address: "); - Serial.println(WiFi.localIP()); - Serial.println(); - - Serial.println("Connect to NTP server and set the device time\r\nPlease wait...\r\n"); - float timeZone = 3;//GMT+3 - float daylightOffset = 0; - - /* Set the device time */ - MailClient.Time.setClock(timeZone, daylightOffset); - - /** Enable the debug via Serial port - * none debug or 0 - * basic debug or 1 - */ - smtp.debug(1); - - /* Set the callback function to get the sending results */ - smtp.callback(smtpCallback); - - /* Declare the session config data */ - ESP_Mail_Session session; - - /* Set the session config */ - session.server.host_name = SMTP_HOST; - session.server.port = SMTP_PORT; - session.login.email = AUTHOR_EMAIL; - session.login.password = AUTHOR_PASSWORD; - session.login.user_domain = "mydomain.net"; - - /* Declare the message class */ - SMTP_Message message; - - /* Set the message headers */ - message.sender.name = "ESP Mail"; - message.sender.email = AUTHOR_EMAIL; - message.subject = "Test sending Email with rfc822 attachment"; - message.addRecipient("Someone", "####@#####_dot_com"); - - message.text.content = "This is simple plain text message with rfc822 attachment"; - - /** The Plain text message character set e.g. - * us-ascii - * utf-8 - * utf-7 - * The default value is utf-8 - */ - message.text.charSet = "us-ascii"; - - /** The content transfer encoding e.g. - * enc_7bit or "7bit" (not encoded) - * enc_qp or "quoted-printable" (encoded) - * enc_base64 or "base64" (encoded) - * enc_binary or "binary" (not encoded) - * enc_8bit or "8bit" (not encoded) - * The default value is "7bit" - */ - message.text.transfer_encoding = Content_Transfer_Encoding::enc_7bit; - - /** The message priority - * esp_mail_smtp_priority_high or 1 - * esp_mail_smtp_priority_normal or 3 - * esp_mail_smtp_priority_low or 5 - * The default value is esp_mail_smtp_priority_low - */ - message.priority = esp_mail_smtp_priority::esp_mail_smtp_priority_low; - - /* Set the custom message header */ - message.addHeader("Message-ID: "); - - SMTP_Message rfc822; - rfc822.messageID = "1234@local.machine.example"; - rfc822.from.name = "rob"; - rfc822.from.email = "rob@example.com"; - rfc822.sender.name = "steve"; - rfc822.sender.email = "steve@example.com"; - String dt = MailClient.Time.getDateTimeString(); - rfc822.date = dt.c_str(); - rfc822.subject = "Test rfc822 message"; - rfc822.comment = "This is comment"; - rfc822.addRecipient("joe", "joe@example.com"); - rfc822.response.reply_to = "rob@example.com"; - rfc822.text.charSet = "utf-8"; - rfc822.text.content = "This is rfc822 text message"; - rfc822.text.transfer_encoding = Content_Transfer_Encoding::enc_qp; - - rfc822.html.charSet = "utf-8"; - rfc822.html.content = "This is rfc822 html message"; - rfc822.html.transfer_encoding = Content_Transfer_Encoding::enc_base64; - - /* The attachment data item */ - SMTP_Attachment att; - - /** Set the attachment info e.g. - * file name, MIME type, BLOB data, BLOB data size, - * and transfer encoding - */ - att.descr.filename = "firebase_logo.png"; - att.descr.mime = "image/png"; - att.blob.data = firebase_png; - att.blob.size = sizeof(firebase_png); - att.descr.transfer_encoding = Content_Transfer_Encoding::enc_base64; - - /* Add the attachment to the rfc822 message */ - rfc822.addAttachment(att); - - /* Prepare other attachment data */ - uint8_t *a = new uint8_t[512]; - int j = 0; - - for (int i = 0; i < 512; i++) - { - a[i] = j; - j++; - if (j > 255) - j = 0; - } - - /** Set the attachment info e.g. - * file name, MIME type, BLOB data, BLOB data size. - * The default transfer encoding is base64. - */ - message.resetAttachItem(att); //Clear the attach item data to reuse - att.descr.filename = "test.dat"; - att.descr.mime = "application/octet-stream"; - att.blob.data = a; - att.blob.size = 512; - - /* Add this attachment to the message */ - message.addAttachment(att); - - /* Add rfc822 message in the message */ - message.addMessage(rfc822); - - /* Connect to server with the session config */ - if (!smtp.connect(&session)) - return; - - /* Start sending Email and close the session */ - if (!MailClient.sendMail(&smtp, &message)) - Serial.println("Error sending Email, " + smtp.errorReason()); -} - -void loop() -{ -} - -/* Callback function to get the Email sending status */ -void smtpCallback(SMTP_Status status) -{ - /* Print the current status */ - Serial.println(status.info()); - - /* Print the sending result */ - if (status.success()) - { - Serial.println("----------------"); - Serial.printf("Message sent success: %d\n", status.completedCount()); - Serial.printf("Message sent failled: %d\n", status.failedCount()); - Serial.println("----------------\n"); - struct tm dt; - - for (size_t i = 0; i < smtp.sendingResult.size(); i++) - { - /* Get the result item */ - SMTP_Result result = smtp.sendingResult.getItem(i); - localtime_r(&result.timesstamp, &dt); - - Serial.printf("Message No: %d\n", i + 1); - Serial.printf("Status: %s\n", result.completed ? "success" : "failed"); - Serial.printf("Date/Time: %d/%d/%d %d:%d:%d\n", dt.tm_year + 1900, dt.tm_mon + 1, dt.tm_mday, dt.tm_hour, dt.tm_min, dt.tm_sec); - Serial.printf("Recipient: %s\n", result.recipients); - Serial.printf("Subject: %s\n", result.subject); - } - Serial.println("----------------\n"); - } -} diff --git a/lib/libesp32/lib_mail/examples/Send_Reuse_Session/Send_Reuse_Session.ino b/lib/libesp32/lib_mail/examples/Send_Reuse_Session/Send_Reuse_Session.ino deleted file mode 100644 index 45bd373f0..000000000 --- a/lib/libesp32/lib_mail/examples/Send_Reuse_Session/Send_Reuse_Session.ino +++ /dev/null @@ -1,245 +0,0 @@ - - -/** - * This example will send multiple messages which - * the session was keep open during sending. - * - * Created by K. Suwatchai (Mobizt) - * - * Email: suwatchai@outlook.com - * - * Github: https://github.com/mobizt/ESP-Mail-Client - * - * Copyright (c) 2021 mobizt - * -*/ - -//To use send Email for Gmail to port 465 (SSL), less secure app option should be enabled. https://myaccount.google.com/lesssecureapps?pli=1 - -#include -#if defined(ESP32) -#include -#elif defined(ESP8266) -#include -#endif -#include - - -#define WIFI_SSID "################" -#define WIFI_PASSWORD "################" - -/** The smtp host name e.g. smtp.gmail.com for GMail or smtp.office365.com for Outlook or smtp.mail.yahoo.com - * For yahoo mail, log in to your yahoo mail in web browser and generate app password by go to - * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc - * and use the app password as password with your yahoo mail account to login. - * The google app password signin is also available https://support.google.com/mail/answer/185833?hl=en -*/ -#define SMTP_HOST "################" - -/** The smtp port e.g. - * 25 or esp_mail_smtp_port_25 - * 465 or esp_mail_smtp_port_465 - * 587 or esp_mail_smtp_port_587 -*/ -#define SMTP_PORT esp_mail_smtp_port_587 - -/* The log in credentials */ -#define AUTHOR_EMAIL "################" -#define AUTHOR_PASSWORD "################" - -/* The SMTP Session object used for Email sending */ -SMTPSession smtp; - -/* Callback function to get the Email sending status */ -void smtpCallback(SMTP_Status status); - -void setup() -{ - - Serial.begin(115200); - Serial.println(); - - Serial.print("Connecting to AP"); - - WiFi.begin(WIFI_SSID, WIFI_PASSWORD); - while (WiFi.status() != WL_CONNECTED) - { - Serial.print("."); - delay(200); - } - - Serial.println(""); - Serial.println("WiFi connected."); - Serial.println("IP address: "); - Serial.println(WiFi.localIP()); - Serial.println(); - - /** Enable the debug via Serial port - * none debug or 0 - * basic debug or 1 - */ - smtp.debug(1); - - /* Set the callback function to get the sending results */ - smtp.callback(smtpCallback); - - /* Declare the session config data */ - ESP_Mail_Session session; - - /* Set the session config */ - session.server.host_name = SMTP_HOST; - session.server.port = SMTP_PORT; - session.login.email = AUTHOR_EMAIL; - session.login.password = AUTHOR_PASSWORD; - session.login.user_domain = "mydomain.net"; - - /* Declare the message class */ - SMTP_Message message; - - /* Set the message headers */ - message.sender.name = "ESP Mail"; - message.sender.email = AUTHOR_EMAIL; - message.subject = "First Email with session reusage"; - message.addRecipient("Admin1", "####@#####_dot_com"); - message.addRecipient("Admin2", "####@#####_dot_com"); - message.addCc("####@#####_dot_com"); - message.addBcc("####@#####_dot_com"); - - message.html.content = "

This is the first message.

"; - - /** The HTML text message character set e.g. - * us-ascii - * utf-8 - * utf-7 - * The default value is utf-8 - */ - message.html.charSet = "utf-8"; - - /** The content transfer encoding e.g. - * enc_7bit or "7bit" (not encoded) - * enc_qp or "quoted-printable" (encoded) - * enc_base64 or "base64" (encoded) - * enc_binary or "binary" (not encoded) - * enc_8bit or "8bit" (not encoded) - * The default value is "7bit" - */ - message.html.transfer_encoding = Content_Transfer_Encoding::enc_qp; - - /** The option to add soft line break to to the message for - * the long text message > 78 characters (rfc 3676) - * Some Servers may not compliant with the standard. - */ - message.text.flowed = true; - - message.text.content = "This is the first message"; - message.text.charSet = "us-ascii"; - - message.html.transfer_encoding = Content_Transfer_Encoding::enc_base64; - - /** The message priority - * esp_mail_smtp_priority_high or 1 - * esp_mail_smtp_priority_normal or 3 - * esp_mail_smtp_priority_low or 5 - * The default value is esp_mail_smtp_priority_low - */ - message.priority = esp_mail_smtp_priority::esp_mail_smtp_priority_normal; - - /** The Delivery Status Notifications e.g. - * esp_mail_smtp_notify_never - * esp_mail_smtp_notify_success - * esp_mail_smtp_notify_failure - * esp_mail_smtp_notify_delay - * The default value is esp_mail_smtp_notify_never - */ - message.response.notify = esp_mail_smtp_notify_success | esp_mail_smtp_notify_failure | esp_mail_smtp_notify_delay; - - /* Set the custom message header */ - message.addHeader("Message-ID: "); - - Serial.println(); - Serial.println("Sending first Email..."); - - /* Connect to server with the session config */ - if (!smtp.connect(&session)) - return; - - /** Start sending the first Email and keep open the session - * The third parameter is for close the session. - */ - if (!MailClient.sendMail(&smtp, &message, false)) - Serial.println("Error sending Email, " + smtp.errorReason()); - - - /* To clear all message data */ - //message.clear(); - - /** Clear primary recipients, Cc recipients, Bcc recipients, custom headers - * attachments and inline images - */ - message.clearRecipients(); - message.clearCc(); - message.clearBcc(); - //message.clearAttachments(); - //message.clearInlineimages(); - - message.subject = "Second Email with session reusage"; - - message.addRecipient("Admin3", "####@#####_dot_com"); - message.addRecipient("Admin4", "####@#####_dot_com"); - message.addCc("####@#####_dot_com"); - message.addBcc("####@#####_dot_com"); - - message.html.content = "

This is the second message.

"; - message.html.charSet = "us-ascii"; - - message.html.transfer_encoding = Content_Transfer_Encoding::enc_7bit; - - message.text.content = "This is the second message"; - message.text.charSet = "UTF-8"; - message.text.transfer_encoding = Content_Transfer_Encoding::enc_qp; - - /* Set the custom message header */ - message.addHeader("Message-ID: "); - - Serial.println(); - Serial.println("Sending second Email..."); - - /* Start sending the second mail and close the session */ - if (!MailClient.sendMail(&smtp, &message)) - Serial.println("Error sending Email, " + smtp.errorReason()); -} - -void loop() -{ -} - -/* Callback function to get the Email sending status */ -void smtpCallback(SMTP_Status status) -{ - /* Print the current status */ - Serial.println(status.info()); - - /* Print the sending result */ - if (status.success()) - { - Serial.println("----------------"); - Serial.printf("Message sent success: %d\n", status.completedCount()); - Serial.printf("Message sent failled: %d\n", status.failedCount()); - Serial.println("----------------\n"); - struct tm dt; - - for (size_t i = 0; i < smtp.sendingResult.size(); i++) - { - /* Get the result item */ - SMTP_Result result = smtp.sendingResult.getItem(i); - localtime_r(&result.timesstamp, &dt); - - Serial.printf("Message No: %d\n", i + 1); - Serial.printf("Status: %s\n", result.completed ? "success" : "failed"); - Serial.printf("Date/Time: %d/%d/%d %d:%d:%d\n", dt.tm_year + 1900, dt.tm_mon + 1, dt.tm_mday, dt.tm_hour, dt.tm_min, dt.tm_sec); - Serial.printf("Recipient: %s\n", result.recipients); - Serial.printf("Subject: %s\n", result.subject); - } - Serial.println("----------------\n"); - } -} diff --git a/lib/libesp32/lib_mail/examples/Send_Text/Send_Text.ino b/lib/libesp32/lib_mail/examples/Send_Text/Send_Text.ino deleted file mode 100644 index 8c7cfc418..000000000 --- a/lib/libesp32/lib_mail/examples/Send_Text/Send_Text.ino +++ /dev/null @@ -1,219 +0,0 @@ - - -/** - * This example will send the Email in plain text version. - * - * Created by K. Suwatchai (Mobizt) - * - * Email: suwatchai@outlook.com - * - * Github: https://github.com/mobizt/ESP-Mail-Client - * - * Copyright (c) 2021 mobizt - * -*/ - -//To use send Email for Gmail to port 465 (SSL), less secure app option should be enabled. https://myaccount.google.com/lesssecureapps?pli=1 - -#include -#if defined(ESP32) -#include -#elif defined(ESP8266) -#include -#endif -#include - -#define WIFI_SSID "################" -#define WIFI_PASSWORD "################" - -/** The smtp host name e.g. smtp.gmail.com for GMail or smtp.office365.com for Outlook or smtp.mail.yahoo.com - * For yahoo mail, log in to your yahoo mail in web browser and generate app password by go to - * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc - * and use the app password as password with your yahoo mail account to login. - * The google app password signin is also available https://support.google.com/mail/answer/185833?hl=en -*/ -#define SMTP_HOST "################" - -/** The smtp port e.g. - * 25 or esp_mail_smtp_port_25 - * 465 or esp_mail_smtp_port_465 - * 587 or esp_mail_smtp_port_587 -*/ -#define SMTP_PORT 25 - -/* The sign in credentials */ -#define AUTHOR_EMAIL "################" -#define AUTHOR_PASSWORD "################" - -/* The SMTP Session object used for Email sending */ -SMTPSession smtp; - -/* Callback function to get the Email sending status */ -void smtpCallback(SMTP_Status status); - -void setup() -{ - - Serial.begin(115200); - Serial.println(); - - Serial.print("Connecting to AP"); - - WiFi.begin(WIFI_SSID, WIFI_PASSWORD); - while (WiFi.status() != WL_CONNECTED) - { - Serial.print("."); - delay(200); - } - - Serial.println(""); - Serial.println("WiFi connected."); - Serial.println("IP address: "); - Serial.println(WiFi.localIP()); - Serial.println(); - - /** Enable the debug via Serial port - * none debug or 0 - * basic debug or 1 - */ - smtp.debug(1); - - /* Set the callback function to get the sending results */ - smtp.callback(smtpCallback); - - /* Declare the session config data */ - ESP_Mail_Session session; - - /** ######################################################## - * Some properties of SMTPSession data and parameters pass to - * SMTP_Message class accept the pointer to constant char - * i.e. const char*. - * - * You may assign a string literal to that properties or function - * like below example. - * - * session.login.user_domain = "mydomain.net"; - * session.login.user_domain = String("mydomain.net").c_str(); - * - * or - * - * String doman = "mydomain.net"; - * session.login.user_domain = domain.c_str(); - * - * And - * - * String name = "Jack " + String("dawson"); - * String email = "jack_dawson" + String(123) + "@mail.com"; - * - * message.addRecipient(name.c_str(), email.c_str()); - * - * message.addHeader(String("Message-ID: ").c_str()); - * - * or - * - * String header = "Message-ID: "; - * message.addHeader(header.c_str()); - * - * ########################################################### - */ - - /* Set the session config */ - session.server.host_name = SMTP_HOST; - session.server.port = SMTP_PORT; - session.login.email = AUTHOR_EMAIL; - session.login.password = AUTHOR_PASSWORD; - session.login.user_domain = "mydomain.net"; - - /* Declare the message class */ - SMTP_Message message; - - /* Set the message headers */ - message.sender.name = "ESP Mail"; - message.sender.email = AUTHOR_EMAIL; - message.subject = "Test sending plain text Email"; - message.addRecipient("Someone", "####@#####_dot_com"); - - String textMsg = "This is simple plain text message"; - message.text.content = textMsg.c_str(); - - /** The Plain text message character set e.g. - * us-ascii - * utf-8 - * utf-7 - * The default value is utf-8 - */ - message.text.charSet = "us-ascii"; - - /** The content transfer encoding e.g. - * enc_7bit or "7bit" (not encoded) - * enc_qp or "quoted-printable" (encoded) - * enc_base64 or "base64" (encoded) - * enc_binary or "binary" (not encoded) - * enc_8bit or "8bit" (not encoded) - * The default value is "7bit" - */ - message.text.transfer_encoding = Content_Transfer_Encoding::enc_7bit; - - /** The message priority - * esp_mail_smtp_priority_high or 1 - * esp_mail_smtp_priority_normal or 3 - * esp_mail_smtp_priority_low or 5 - * The default value is esp_mail_smtp_priority_low - */ - message.priority = esp_mail_smtp_priority::esp_mail_smtp_priority_low; - - /** The Delivery Status Notifications e.g. - * esp_mail_smtp_notify_never - * esp_mail_smtp_notify_success - * esp_mail_smtp_notify_failure - * esp_mail_smtp_notify_delay - * The default value is esp_mail_smtp_notify_never - */ - message.response.notify = esp_mail_smtp_notify_success | esp_mail_smtp_notify_failure | esp_mail_smtp_notify_delay; - - /* Set the custom message header */ - message.addHeader("Message-ID: "); - - /* Connect to server with the session config */ - if (!smtp.connect(&session)) - return; - - /* Start sending Email and close the session */ - if (!MailClient.sendMail(&smtp, &message)) - Serial.println("Error sending Email, " + smtp.errorReason()); -} - -void loop() -{ -} - -/* Callback function to get the Email sending status */ -void smtpCallback(SMTP_Status status) -{ - /* Print the current status */ - Serial.println(status.info()); - - /* Print the sending result */ - if (status.success()) - { - Serial.println("----------------"); - Serial.printf("Message sent success: %d\n", status.completedCount()); - Serial.printf("Message sent failled: %d\n", status.failedCount()); - Serial.println("----------------\n"); - struct tm dt; - - for (size_t i = 0; i < smtp.sendingResult.size(); i++) - { - /* Get the result item */ - SMTP_Result result = smtp.sendingResult.getItem(i); - localtime_r(&result.timesstamp, &dt); - - Serial.printf("Message No: %d\n", i + 1); - Serial.printf("Status: %s\n", result.completed ? "success" : "failed"); - Serial.printf("Date/Time: %d/%d/%d %d:%d:%d\n", dt.tm_year + 1900, dt.tm_mon + 1, dt.tm_mday, dt.tm_hour, dt.tm_min, dt.tm_sec); - Serial.printf("Recipient: %s\n", result.recipients); - Serial.printf("Subject: %s\n", result.subject); - } - Serial.println("----------------\n"); - } -} diff --git a/lib/libesp32/lib_mail/examples/Send_Text_Flowed/Send_Text_Flowed.ino b/lib/libesp32/lib_mail/examples/Send_Text_Flowed/Send_Text_Flowed.ino deleted file mode 100644 index a1ea2f4fe..000000000 --- a/lib/libesp32/lib_mail/examples/Send_Text_Flowed/Send_Text_Flowed.ino +++ /dev/null @@ -1,229 +0,0 @@ - - -/** - * This example will send the Email in plain text version - * with the quoted text and long line text. - * - * - * Created by K. Suwatchai (Mobizt) - * - * Email: suwatchai@outlook.com - * - * Github: https://github.com/mobizt/ESP-Mail-Client - * - * Copyright (c) 2021 mobizt - * -*/ - -//To use send Email for Gmail to port 465 (SSL), less secure app option should be enabled. https://myaccount.google.com/lesssecureapps?pli=1 - -#include -#if defined(ESP32) -#include -#elif defined(ESP8266) -#include -#endif -#include - -#define WIFI_SSID "################" -#define WIFI_PASSWORD "################" - -/** The smtp host name e.g. smtp.gmail.com for GMail or smtp.office365.com for Outlook or smtp.mail.yahoo.com - * For yahoo mail, log in to your yahoo mail in web browser and generate app password by go to - * https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc - * and use the app password as password with your yahoo mail account to login. - * The google app password signin is also available https://support.google.com/mail/answer/185833?hl=en -*/ -#define SMTP_HOST "################" - -/** The smtp port e.g. - * 25 or esp_mail_smtp_port_25 - * 465 or esp_mail_smtp_port_465 - * 587 or esp_mail_smtp_port_587 -*/ -#define SMTP_PORT 25 - -/* The log in credentials */ -#define AUTHOR_EMAIL "################" -#define AUTHOR_PASSWORD "################" - -/* The SMTP Session object used for Email sending */ -SMTPSession smtp; - -/* Callback function to get the Email sending status */ -void smtpCallback(SMTP_Status status); - -void setup() -{ - - Serial.begin(115200); - Serial.println(); - - Serial.print("Connecting to AP"); - - WiFi.begin(WIFI_SSID, WIFI_PASSWORD); - while (WiFi.status() != WL_CONNECTED) - { - Serial.print("."); - delay(200); - } - - Serial.println(""); - Serial.println("WiFi connected."); - Serial.println("IP address: "); - Serial.println(WiFi.localIP()); - Serial.println(); - - /** Enable the debug via Serial port - * none debug or 0 - * basic debug or 1 - */ - smtp.debug(1); - - /* Set the callback function to get the sending results */ - smtp.callback(smtpCallback); - - /* Declare the session config data */ - ESP_Mail_Session session; - - /** ######################################################## - * Some properties of SMTPSession data and parameters pass to - * SMTP_Message class accept the pointer to constant char - * i.e. const char*. - * - * You may assign a string literal to that properties or function - * like below example. - * - * session.login.user_domain = "mydomain.net"; - * session.login.user_domain = String("mydomain.net").c_str(); - * - * or - * - * String doman = "mydomain.net"; - * session.login.user_domain = domain.c_str(); - * - * And - * - * String name = "Jack " + String("dawson"); - * String email = "jack_dawson" + String(123) + "@mail.com"; - * - * message.addRecipient(name.c_str(), email.c_str()); - * - * message.addHeader(String("Message-ID: ").c_str()); - * - * or - * - * String header = "Message-ID: "; - * message.addHeader(header.c_str()); - * - * ########################################################### - */ - - /* Set the session config */ - session.server.host_name = SMTP_HOST; - session.server.port = SMTP_PORT; - session.login.email = AUTHOR_EMAIL; - session.login.password = AUTHOR_PASSWORD; - session.login.user_domain = "mydomain.net"; - - /* Declare the message class */ - SMTP_Message message; - - /* Set the message headers */ - message.sender.name = "ESP Mail"; - message.sender.email = AUTHOR_EMAIL; - message.subject = "Test sending flowed plain text Email"; - message.addRecipient("Someone", "####@#####_dot_com"); - - /** The option to add soft line break to to the message for - * the long text message > 78 characters (rfc 3676) - * Some Servers may not compliant with the standard. - */ - message.text.flowed = true; - - /** if the option message.text.flowed is true, - * the following plain text message will be wrapped. - */ - message.text.content = "The text below is the long quoted text which breaks into several lines.\r\n\r\n>> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.\r\n\r\nThis is the normal short text.\r\n\r\nAnother long text, abcdefg hijklmnop qrstuv wxyz abcdefg hijklmnop qrstuv wxyz abcdefg hijklmnop qrstuv wxyz."; - - /** The Plain text message character set e.g. - * us-ascii - * utf-8 - * utf-7 - * The default value is utf-8 - */ - message.text.charSet = "us-ascii"; - - /** The content transfer encoding e.g. - * enc_7bit or "7bit" (not encoded) - * enc_qp or "quoted-printable" (encoded) - * enc_base64 or "base64" (encoded) - * enc_binary or "binary" (not encoded) - * enc_8bit or "8bit" (not encoded) - * The default value is "7bit" - */ - message.text.transfer_encoding = Content_Transfer_Encoding::enc_7bit; - - /** The message priority - * esp_mail_smtp_priority_high or 1 - * esp_mail_smtp_priority_normal or 3 - * esp_mail_smtp_priority_low or 5 - * The default value is esp_mail_smtp_priority_low - */ - message.priority = esp_mail_smtp_priority::esp_mail_smtp_priority_low; - - /** The Delivery Status Notifications e.g. - * esp_mail_smtp_notify_never - * esp_mail_smtp_notify_success - * esp_mail_smtp_notify_failure - * esp_mail_smtp_notify_delay - * The default value is esp_mail_smtp_notify_never - */ - message.response.notify = esp_mail_smtp_notify_success | esp_mail_smtp_notify_failure | esp_mail_smtp_notify_delay; - - /* Set the custom message header */ - message.addHeader("Message-ID: "); - - /* Connect to server with the session config */ - if (!smtp.connect(&session)) - return; - - /* Start sending Email and close the session */ - if (!MailClient.sendMail(&smtp, &message)) - Serial.println("Error sending Email, " + smtp.errorReason()); -} - -void loop() -{ -} - -/* Callback function to get the Email sending status */ -void smtpCallback(SMTP_Status status) -{ - /* Print the current status */ - Serial.println(status.info()); - - /* Print the sending result */ - if (status.success()) - { - Serial.println("----------------"); - Serial.printf("Message sent success: %d\n", status.completedCount()); - Serial.printf("Message sent failled: %d\n", status.failedCount()); - Serial.println("----------------\n"); - struct tm dt; - - for (size_t i = 0; i < smtp.sendingResult.size(); i++) - { - /* Get the result item */ - SMTP_Result result = smtp.sendingResult.getItem(i); - localtime_r(&result.timesstamp, &dt); - - Serial.printf("Message No: %d\n", i + 1); - Serial.printf("Status: %s\n", result.completed ? "success" : "failed"); - Serial.printf("Date/Time: %d/%d/%d %d:%d:%d\n", dt.tm_year + 1900, dt.tm_mon + 1, dt.tm_mday, dt.tm_hour, dt.tm_min, dt.tm_sec); - Serial.printf("Recipient: %s\n", result.recipients); - Serial.printf("Subject: %s\n", result.subject); - } - Serial.println("----------------\n"); - } -} diff --git a/lib/libesp32/lib_mail/examples/Set_Flags/Set_Flags.ino b/lib/libesp32/lib_mail/examples/Set_Flags/Set_Flags.ino deleted file mode 100644 index 238a17ddf..000000000 --- a/lib/libesp32/lib_mail/examples/Set_Flags/Set_Flags.ino +++ /dev/null @@ -1,363 +0,0 @@ -/** - * This example will set the argument to the flags and read the message. - * - * Email: suwatchai@outlook.com - * - * Github: https://github.com/mobizt/ESP-Mail-Client - * - * Copyright (c) 2021 mobizt - * -*/ - -/** To receive Email using Gmail, IMAP option should be enabled. https://support.google.com/mail/answer/7126229?hl=en - * and also https://accounts.google.com/b/0/DisplayUnlockCaptcha - * -*/ - -/** For ESP8266, with BearSSL WiFi Client - * The memory reserved for completed valid SSL response from IMAP is 16 kbytes which - * may cause your device out of memory reset in case the memory - * allocation error. -*/ - -#include -#if defined(ESP32) -#include -#elif defined(ESP8266) -#include -#endif -#include - -#define WIFI_SSID "################" -#define WIFI_PASSWORD "################" - -/* The imap host name e.g. imap.gmail.com for GMail or outlook.office365.com for Outlook */ -#define IMAP_HOST "################" - -/** The imap port e.g. - * 143 or esp_mail_imap_port_143 - * 993 or esp_mail_imap_port_993 -*/ -#define IMAP_PORT 993 - -/* The log in credentials */ -#define AUTHOR_EMAIL "################" -#define AUTHOR_PASSWORD "################" - -/* Callback function to get the Email reading status */ -void imapCallback(IMAP_Status status); - -/* Print the list of mailbox folders */ -void printAllMailboxesInfo(IMAPSession &imap); - -/* Print the selected folder info */ -void printSelectedMailboxInfo(IMAPSession &imap); - -/* Print all messages from the message list */ -void printMessages(IMAPSession &imap); - -/* Print all rfc822 messages included in the message */ -void printRFC822Messages(IMAP_MSG_Item &msg); - -/* Print all attachments info from the message */ -void printAttacements(IMAP_MSG_Item &msg); - -/* The IMAP Session object used for Email reading */ -IMAPSession imap; - - -void setup() -{ - - Serial.begin(115200); - Serial.println(); - - Serial.print("Connecting to AP"); - - WiFi.begin(WIFI_SSID, WIFI_PASSWORD); - while (WiFi.status() != WL_CONNECTED) - { - Serial.print("."); - delay(200); - } - - Serial.println(""); - Serial.println("WiFi connected."); - Serial.println("IP address: "); - Serial.println(WiFi.localIP()); - Serial.println(); - - /** Enable the debug via Serial port - * none debug or 0 - * basic debug or 1 - */ - imap.debug(1); - - /* Set the callback function to get the reading results */ - imap.callback(imapCallback); - - /** In case the SD card/adapter was used for the file storagge, the SPI pins can be configure from - * MailClient.sdBegin function which may be different for ESP32 and ESP8266 - * For ESP32, assign all of SPI pins - * MailClient.sdBegin(14,2,15,13) - * Which SCK = 14, MISO = 2, MOSI = 15 and SS = 13 - * And for ESP8266, assign the CS pins of SPI port - * MailClient.sdBegin(15) - * Which pin 15 is the CS pin of SD card adapter - */ - - /* Declare the session config data */ - ESP_Mail_Session session; - - /* Set the session config */ - session.server.host_name = IMAP_HOST; - session.server.port = IMAP_PORT; - session.login.email = AUTHOR_EMAIL; - session.login.password = AUTHOR_PASSWORD; - - - /* Setup the configuration for searching or fetching operation and its result */ - IMAP_Config config; - - /* Message UID to fetch or read e.g. 100 */ - config.fetch.uid = "100"; - - /* Set seen flag */ - //config.fetch.set_seen = true; - - /* Search criteria */ - config.search.criteria = ""; - - /* Also search the unseen message */ - config.search.unseen_msg = true; - - /* Set the storage to save the downloaded files and attachments */ - config.storage.saved_path = "/email_data"; - - /** The file storage type e.g. - * esp_mail_file_storage_type_none, - * esp_mail_file_storage_type_flash, and - * esp_mail_file_storage_type_sd - */ - config.storage.type = esp_mail_file_storage_type_flash; - - /** Set to download heades, text and html messaeges, - * attachments and inline images respectively. - */ - config.download.header = true; - config.download.text = true; - config.download.html = true; - config.download.attachment = true; - config.download.inlineImg = true; - - /** Set to enable the results i.e. html and text messaeges - * which the content stored in the IMAPSession object is limited - * by the option config.limit.msg_size. - * The whole message can be download through config.download.text - * or config.download.html which not depends on these enable options. - */ - config.enable.html = true; - config.enable.text = true; - - /* Set to enable the sort the result by message UID in the ascending order */ - config.enable.recent_sort = true; - - /* Set to report the download progress via the default serial port */ - config.enable.download_status = true; - - /* Set the limit of number of messages in the search results */ - config.limit.search = 5; - - /** Set the maximum size of message stored in - * IMAPSession object in byte - */ - config.limit.msg_size = 512; - - /** Set the maximum attachments and inline images files size - * that can be downloaded in byte. - * The file which its size is largger than this limit may be saved - * as truncated file. - */ - config.limit.attachment_size = 1024 * 1024 * 5; - - - - /* Connect to server with the session and config */ - if (!imap.connect(&session, &config)) - return; - - /* {Optional] */ - printAllMailboxesInfo(imap); - - /* Open or select the mailbox folder to read or search the message */ - if (!imap.selectFolder("INBOX")) - return; - - /* {Optional] */ - printSelectedMailboxInfo(imap); - - /** Set \Seen and \Answered to flags for message with UID 100 - * The seesion will keep open. - */ - if (MailClient.setFlag(&imap, 100, "\\Seen \\Answered", false)) - Serial.println("Setting FLAG success"); - else - Serial.println("Error, setting FLAG"); - - /* Add \Seen and \Answered to flags for message with UID 100 */ - //MailClient.addFlag(imap, 100, "\\Seen \\Answered", false); - - /* Remove \Seen and \Answered from flags for message with UID 100 */ - //MailClient.removeFlag(imap, 100, "\\Seen \\Answered", false); - - /* Read or search the Email and close the session */ - MailClient.readMail(&imap); - - /* Clear all stored data in IMAPSession object */ - imap.empty(); -} - -void loop() -{ - -} - -/* Callback function to get the Email reading status */ -void imapCallback(IMAP_Status status) -{ - /* Print the current status */ - Serial.println(status.info()); - - /* Show the result when reading finished */ - if (status.success()) - { - /* Print the result */ - printMessages(imap); - - /* Clear all stored data in IMAPSession object */ - imap.empty(); - Serial.printf("Free Heap: %d", ESP.getFreeHeap()); - } -} - -void printAllMailboxesInfo(IMAPSession &imap) -{ - /* Declare the folder collection class to get the list of mailbox folders */ - FoldersCollection folders; - - /* Get the mailbox folders */ - if (imap.getFolders(folders)) - { - for (size_t i = 0; i < folders.size(); i++) - { - /* Iterate each folder info using the folder info item data */ - FolderInfo folderInfo = folders.info(i); - Serial.printf("%s%s%s", i == 0 ? "\nAvailable folders: " : ", ", folderInfo.name, i == folders.size() - 1 ? "\n" : ""); - } - } -} - -void printSelectedMailboxInfo(IMAPSession &imap) -{ - /* Declare the selected folder info class to get the info of selected mailbox folder */ - SelectedFolderInfo sFolder = imap.selectedFolder(); - - /* Show the mailbox info */ - Serial.printf("\nInfo of the selected folder\nTotal Messages: %d\n", sFolder.msgCount()); - Serial.printf("Predicted next UID: %d\n", sFolder.nextUID()); - for (size_t i = 0; i < sFolder.flagCount(); i++) - Serial.printf("%s%s%s", i == 0 ? "Flags: " : ", ", sFolder.flag(i).c_str(), i == sFolder.flagCount() - 1 ? "\n" : ""); -} - -void printRFC822Messages(IMAP_MSG_Item &msg) -{ - Serial.printf("RFC822 Messages: %d message(s)\n****************************\n", msg.rfc822.size()); - for (size_t j = 0; j < msg.rfc822.size(); j++) - { - IMAP_MSG_Item rfc822 = msg.rfc822[j]; - Serial.printf("%d. \n", j + 1); - Serial.printf("Messsage ID: %s\n", rfc822.messageID); - Serial.printf("From: %s\n", rfc822.from); - Serial.printf("Sender: %s\n", rfc822.sender); - Serial.printf("To: %s\n", rfc822.to); - Serial.printf("CC: %s\n", rfc822.cc); - Serial.printf("Subject: %s\n", rfc822.subject); - Serial.printf("Date: %s\n", rfc822.date); - Serial.printf("Reply-To: %s\n", rfc822.reply_to); - Serial.printf("Return-Path: %s\n", rfc822.return_path); - Serial.printf("Comment: %s\n", rfc822.comment); - Serial.printf("Keyword: %s\n", rfc822.keyword); - Serial.printf("Text Message: %s\n", rfc822.text.content); - Serial.printf("Text Message Charset: %s\n", rfc822.text.charSet); - Serial.printf("Text Message Transfer Encoding: %s\n", rfc822.text.transfer_encoding); - Serial.printf("HTML Message: %s\n", rfc822.html.content); - Serial.printf("HTML Message Charset: %s\n", rfc822.html.charSet); - Serial.printf("HTML Message Transfer Encoding: %s\n\n", rfc822.html.transfer_encoding); - - if (rfc822.attachments.size() > 0) - printAttacements(rfc822); - } -} - -void printAttacements(IMAP_MSG_Item &msg) -{ - Serial.printf("Attachment: %d file(s)\n****************************\n", msg.attachments.size()); - for (size_t j = 0; j < msg.attachments.size(); j++) - { - IMAP_Attach_Item att = msg.attachments[j]; - /** att.type can be - * esp_mail_att_type_none or 0 - * esp_mail_att_type_attachment or 1 - * esp_mail_att_type_inline or 2 - */ - Serial.printf("%d. Filename: %s, Name: %s, Size: %d, MIME: %s, Type: %s, Creation Date: %s\n", j + 1, att.filename, att.name, att.size, att.mime, att.type == esp_mail_att_type_attachment ? "attachment" : "inline", att.creationDate); - } - Serial.println(); -} - -void printMessages(IMAPSession &imap) -{ - /* Get the message list from the message list data */ - IMAP_MSG_List msgList = imap.data(); - - for (size_t i = 0; i < msgList.msgItems.size(); i++) - { - /* Iterate to get each message data through the message item data */ - IMAP_MSG_Item msg = msgList.msgItems[i]; - - Serial.println("################################"); - Serial.printf("Messsage Number: %s\n", msg.msgNo); - Serial.printf("Messsage UID: %s\n", msg.UID); - Serial.printf("Messsage ID: %s\n", msg.ID); - Serial.printf("Accept Language: %s\n", msg.acceptLang); - Serial.printf("Content Language: %s\n", msg.contentLang); - Serial.printf("From: %s\n", msg.from); - Serial.printf("From Charset: %s\n", msg.fromCharset); - Serial.printf("To: %s\n", msg.to); - Serial.printf("To Charset: %s\n", msg.toCharset); - Serial.printf("CC: %s\n", msg.cc); - Serial.printf("CC Charset: %s\n", msg.ccCharset); - Serial.printf("Date: %s\n", msg.date); - Serial.printf("Subject: %s\n", msg.subject); - Serial.printf("Subject Charset: %s\n", msg.subjectCharset); - - /* If the result contains the message info (Fetch mode) */ - if (!imap.headerOnly()) - { - Serial.printf("Text Message: %s\n", msg.text.content); - Serial.printf("Text Message Charset: %s\n", msg.text.charSet); - Serial.printf("Text Message Transfer Encoding: %s\n", msg.text.transfer_encoding); - Serial.printf("HTML Message: %s\n", msg.html.content); - Serial.printf("HTML Message Charset: %s\n", msg.html.charSet); - Serial.printf("HTML Message Transfer Encoding: %s\n\n", msg.html.transfer_encoding); - - if (msg.attachments.size() > 0) - printAttacements(msg); - - if (msg.rfc822.size() > 0) - printRFC822Messages(msg); - } - - Serial.println(); - } -} diff --git a/lib/libesp32/lib_mail/library.json b/lib/libesp32/lib_mail/library.json deleted file mode 100644 index 30dac17bb..000000000 --- a/lib/libesp32/lib_mail/library.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "name": "ESP Mail Client", - "version": "1.2.0", - "keywords": "communication, email, imap, smtp, esp32, esp8266, arduino", - "description": "Mail Client Arduino Library for Espressif ESP32 and ESP8266 devices. This library allows the ESP32 and ESP8266 devices to send and read Email with the many options and features e.g. the attachments, inline images, embeded rfc822 messages are supported for upload when sending and download when reading the Emails.", - "repository": { - "type": "git", - "url": "https://github.com/mobizt/ESP-Mail-Client.git" - }, - "authors": [{ - "name": "Mobizt", - "email": "suwatchai@outlook.com" - }], - "frameworks": "arduino", - "platforms": "espressif32, espressif8266" -} diff --git a/lib/libesp32/lib_mail/library.properties b/lib/libesp32/lib_mail/library.properties deleted file mode 100644 index a574456bd..000000000 --- a/lib/libesp32/lib_mail/library.properties +++ /dev/null @@ -1,17 +0,0 @@ -name=ESP Mail Client - -version=1.2.0 - -author=Mobizt - -maintainer=Mobizt - -sentence=Mail Client Arduino Library for Espressif ESP32 and ESP8266 devices. - -paragraph=This library allows the ESP32 and ESP8266 devices to send and read Email with the many options and features e.g. the attachments, inline images, embeded rfc822 messages are supported for upload when sending and download when reading the Emails. - -category=Communication - -url=https://github.com/mobizt/ESP-Mail-Client - -architectures=esp32,esp8266 diff --git a/lib/libesp32/lib_mail/src/ESP_Mail_Client.cpp b/lib/libesp32/lib_mail/src/ESP_Mail_Client.cpp deleted file mode 100644 index 897d832b8..000000000 --- a/lib/libesp32/lib_mail/src/ESP_Mail_Client.cpp +++ /dev/null @@ -1,8548 +0,0 @@ -/** - * Mail Client Arduino Library for Espressif's ESP32 and ESP8266 - * - * Version: 1.2.0 - * Released: May 17, 2021 - * - * Updates: - * - Add support ESP8266 Core SDK v3.x.x. - * - * - * This library allows Espressif's ESP32 and ESP8266 devices to send and read Email - * through the SMTP and IMAP servers. - * - * The MIT License (MIT) - * Copyright (c) 2021 K. Suwatchai (Mobizt) - * - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -#ifndef ESP_Mail_Client_CPP -#define ESP_Mail_Client_CPP - -#include "ESP_Mail_Client.h" - -#if defined(ESP32) -extern "C" -{ -#include -#include -} -#endif - -bool ESP_Mail_Client::sendIMAPCommand(IMAPSession *imap, int msgIndex, int cmdCase) -{ - - std::string cmd; - if (imap->_uidSearch || strlen(imap->_config->fetch.uid) > 0) - appendP(cmd, esp_mail_str_142, true); - else - appendP(cmd, esp_mail_str_143, true); - - char *tmp = intStr(imap->_msgNum[msgIndex]); - cmd += tmp; - delS(tmp); - appendP(cmd, esp_mail_str_147, false); - if (!imap->_config->fetch.set_seen) - { - appendP(cmd, esp_mail_str_152, false); - appendP(cmd, esp_mail_str_214, false); - } - appendP(cmd, esp_mail_str_218, false); - - switch (cmdCase) - { - case 1: - - appendP(cmd, esp_mail_str_269, false); - break; - - case 2: - - if (cPart(imap)->partNumFetchStr.length() > 0) - cmd += cPart(imap)->partNumFetchStr; - else - appendP(cmd, esp_mail_str_215, false); - appendP(cmd, esp_mail_str_156, false); - break; - - case 3: - - cmd += cPart(imap)->partNumFetchStr; - appendP(cmd, esp_mail_str_156, false); - break; - - default: - break; - } - - if (imapSend(imap, cmd.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return false; - return true; -} - -bool ESP_Mail_Client::readMail(IMAPSession *imap, bool closeSession) -{ - - imap->checkUID(); - imap->checkPath(); - - if (!imap->_tcpConnected) - imap->_mailboxOpened = false; - - std::string buf; - std::string command; - std::string _uid; - appendP(command, esp_mail_str_27, true); - char *tmp = nullptr; - size_t readCount = 0; - imap->_multipart_levels.clear(); - - if (!reconnect(imap)) - return false; - - int cmem = ESP.getFreeHeap(); - - if (cmem < ESP_MAIL_MIN_MEM) - { - if (imap->_debug) - { - esp_mail_debug(""); - errorStatusCB(imap, MAIL_CLIENT_ERROR_OUT_OF_MEMORY); - } - goto out; - } - - //new session - if (!imap->_tcpConnected) - { - //authenticate new - if (!imapAuth(imap)) - { - closeTCP(imap); - return false; - } - } - else - { - //reuse session - for (size_t i = 0; i < imap->_headers.size(); i++) - imap->_headers[i].part_headers.clear(); - imap->_headers.clear(); - - if (strlen(imap->_config->fetch.uid) > 0) - imap->_headerOnly = false; - else - imap->_headerOnly = true; - } - imap->_rfc822_part_count = 0; - imap->_mbif._availableItems = 0; - imap->_msgNum.clear(); - imap->_uidSearch = false; - imap->_mbif._searchCount = 0; - - if (imap->_currentFolder.length() == 0) - return handleIMAPError(imap, IMAP_STATUS_NO_MAILBOX_FOLDER_OPENED, false); - - if (!imap->_mailboxOpened || (imap->_config->fetch.set_seen && !imap->_headerOnly && imap->_readOnlyMode)) - { - if (!imap->openFolder(imap->_currentFolder.c_str(), imap->_readOnlyMode && !imap->_config->fetch.set_seen)) - return handleIMAPError(imap, IMAP_STATUS_OPEN_MAILBOX_FAILED, false); - } - - if (imap->_headerOnly) - { - if (strlen(imap->_config->search.criteria) > 0) - { - - if (imap->_readCallback) - { - imapCB(imap, "", false); - imapCBP(imap, esp_mail_str_66, false); - } - - if (imap->_debug) - debugInfoP(esp_mail_str_232); - - if (strposP(imap->_config->search.criteria, esp_mail_str_137, 0) != -1) - { - imap->_uidSearch = true; - appendP(command, esp_mail_str_138, false); - } - - appendP(command, esp_mail_str_139, false); - - for (size_t i = 0; i < strlen(imap->_config->search.criteria); i++) - { - if (imap->_config->search.criteria[i] != ' ' && imap->_config->search.criteria[i] != '\r' && imap->_config->search.criteria[i] != '\n' && imap->_config->search.criteria[i] != '$') - buf.append(1, imap->_config->search.criteria[i]); - - if (imap->_config->search.criteria[i] == ' ') - { - tmp = strP(esp_mail_str_140); - char *tmp2 = strP(esp_mail_str_224); - - if ((imap->_uidSearch && strcmp(buf.c_str(), tmp) == 0) || (imap->_unseen && buf.find(tmp2) != std::string::npos)) - buf.clear(); - delS(tmp); - delS(tmp2); - - tmp = strP(esp_mail_str_141); - if (strcmp(buf.c_str(), tmp) != 0 && buf.length() > 0) - { - appendP(command, esp_mail_str_131, false); - command += buf; - } - delS(tmp); - buf.clear(); - } - } - - tmp = strP(esp_mail_str_223); - if (imap->_unseen && strpos(imap->_config->search.criteria, tmp, 0) == -1) - appendP(command, esp_mail_str_223, false); - delS(tmp); - - if (buf.length() > 0) - { - appendP(command, esp_mail_str_131, false); - command += buf; - } - - if (imapSend(imap, command.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return false; - - std::string().swap(command); - - imap->_imap_cmd = esp_mail_imap_command::esp_mail_imap_cmd_search; - - if (!handleIMAPResponse(imap, IMAP_STATUS_BAD_COMMAND, closeSession)) - return false; - - if (imap->_readCallback) - { - std::string s; - appendP(s, esp_mail_str_34, true); - appendP(s, esp_mail_str_68, false); - char *tmp = intStr(imap->_config->limit.search); - s += tmp; - delS(tmp); - imapCB(imap, s.c_str(), false); - - if (imap->_msgNum.size() > 0) - { - - appendP(s, esp_mail_str_69, true); - tmp = intStr(imap->_mbif._searchCount); - s += tmp; - delS(tmp); - appendP(s, esp_mail_str_70, false); - imapCB(imap, s.c_str(), false); - - appendP(s, esp_mail_str_71, true); - tmp = intStr(imap->_msgNum.size()); - s += tmp; - delS(tmp); - appendP(s, esp_mail_str_70, false); - imapCB(imap, s.c_str(), false); - } - else - imapCBP(imap, esp_mail_str_72, false); - } - } - else - { - imap->_mbif._availableItems++; - imap->_msgNum.push_back(imap->_mbif._nextUID - 1); - imap->_headerOnly = false; - char *tmp = intStr(imap->_mbif._nextUID - 1); - _uid = tmp; - delS(tmp); - imap->_config->fetch.uid = _uid.c_str(); - - if (imap->_readCallback) - imapCBP(imap, esp_mail_str_73, false); - } - } - else - { - imap->_mbif._availableItems++; - imap->_msgNum.push_back(atoi(imap->_config->fetch.uid)); - } - - for (size_t i = 0; i < imap->_msgNum.size(); i++) - { - - imap->_cMsgIdx = i; - imap->_totalRead++; - - if (ESP.getFreeHeap() - (imap->_config->limit.msg_size * (i + 1)) < ESP_MAIL_MIN_MEM) - { - if (imap->_debug) - errorStatusCB(imap, MAIL_CLIENT_ERROR_OUT_OF_MEMORY); - goto out; - } - - if (imap->_readCallback) - { - readCount++; - - std::string s; - appendP(s, esp_mail_str_74, true); - char *tmp = intStr(imap->_totalRead); - s += tmp; - delS(tmp); - - if (imap->_uidSearch || strlen(imap->_config->fetch.uid) > 0) - appendP(s, esp_mail_str_75, false); - else - appendP(s, esp_mail_str_76, false); - - tmp = intStr(imap->_msgNum[i]); - s += tmp; - delS(tmp); - imapCB(imap, "", false); - imapCB(imap, s.c_str(), false); - } - - if (imap->_debug) - debugInfoP(esp_mail_str_233); - - std::string cmd; - if (imap->_uidSearch || strlen(imap->_config->fetch.uid) > 0) - appendP(cmd, esp_mail_str_142, true); - else - appendP(cmd, esp_mail_str_143, true); - - if (imap->_debug) - debugInfoP(esp_mail_str_77); - - char *tmp = intStr(imap->_msgNum[i]); - cmd += tmp; - delS(tmp); - - appendP(cmd, esp_mail_str_147, false); - if (!imap->_config->fetch.set_seen) - { - appendP(cmd, esp_mail_str_152, false); - appendP(cmd, esp_mail_str_214, false); - } - appendP(cmd, esp_mail_str_218, false); - - appendP(cmd, esp_mail_str_144, false); - appendP(cmd, esp_mail_str_156, false); - if (imapSend(imap, cmd.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return false; - - imap->_imap_cmd = esp_mail_imap_command::esp_mail_imap_cmd_fetch_body_header; - - int err = IMAP_STATUS_BAD_COMMAND; - if (imap->_headerOnly) - err = IMAP_STATUS_IMAP_RESPONSE_FAILED; - - if (!handleIMAPResponse(imap, err, closeSession)) - return false; - - if (!imap->_headerOnly) - { - imap->_cPartIdx = 0; - - //multipart - if (cHeader(imap)->multipart) - { - struct esp_mail_imap_multipart_level_t mlevel; - mlevel.level = 1; - mlevel.fetch_rfc822_header = false; - mlevel.append_body_text = false; - imap->_multipart_levels.push_back(mlevel); - - if (!fetchMultipartBodyHeader(imap, i)) - return false; - } - else - { - //singlepart - if (imap->_debug) - { - std::string s; - appendP(s, esp_mail_str_81, true); - s += '1'; - esp_mail_debug(s.c_str()); - } - - cHeader(imap)->partNumStr.clear(); - if (!sendIMAPCommand(imap, i, 1)) - return false; - - imap->_imap_cmd = esp_mail_imap_command::esp_mail_imap_cmd_fetch_body_mime; - if (!handleIMAPResponse(imap, IMAP_STATUS_BAD_COMMAND, closeSession)) - return false; - } - - if (imap->_config->download.text || imap->_config->download.html || imap->_config->download.attachment || imap->_config->download.inlineImg) - { - if (!_sdOk && imap->_storageType == esp_mail_file_storage_type_sd) - { - _sdOk = sdTest(); - if (_sdOk) - if (!ESP_MAIL_SD_FS.exists(imap->_config->storage.saved_path)) - createDirs(imap->_config->storage.saved_path); - } - else if (!_flashOk && imap->_storageType == esp_mail_file_storage_type_flash) -#if defined(ESP32) - _flashOk = ESP_MAIL_FLASH_FS.begin(FORMAT_FLASH); -#elif defined(ESP8266) - _flashOk = ESP_MAIL_FLASH_FS.begin(); -#endif - } - - if (cHeader(imap)->part_headers.size() > 0) - { - if (cHeader(imap)->attachment_count > 0 && imap->_readCallback) - { - std::string s; - appendP(s, esp_mail_str_34, true); - appendP(s, esp_mail_str_78, false); - char *tmp = intStr(cHeader(imap)->attachment_count); - s += tmp; - delS(tmp); - appendP(s, esp_mail_str_79, false); - imapCB(imap, s.c_str(), false); - - for (size_t j = 0; j < cHeader(imap)->part_headers.size(); j++) - { - imap->_cPartIdx = j; - if (!cPart(imap)->rfc822_part && cPart(imap)->attach_type != esp_mail_att_type_none) - imapCB(imap, cPart(imap)->filename.c_str(), false); - } - } - - std::string s1, s2; - int _idx1 = 0; - for (size_t j = 0; j < cHeader(imap)->part_headers.size(); j++) - { - imap->_cPartIdx = j; - if (cPart(imap)->rfc822_part) - { - s1 = cPart(imap)->partNumStr; - _idx1 = cPart(imap)->rfc822_msg_Idx; - } - else if (s1.length() > 0) - { - if (multipartMember(s1, cPart(imap)->partNumStr)) - { - cPart(imap)->message_sub_type = esp_mail_imap_message_sub_type_rfc822; - cPart(imap)->rfc822_msg_Idx = _idx1; - } - } - - if (cPart(imap)->multipart_sub_type == esp_mail_imap_multipart_sub_type_parallel) - s2 = cPart(imap)->partNumStr; - else if (s2.length() > 0) - { - if (multipartMember(s2, cPart(imap)->partNumStr)) - { - cPart(imap)->attach_type = esp_mail_att_type_attachment; - if (cPart(imap)->filename.length() == 0) - { - if (cPart(imap)->name.length() > 0) - cPart(imap)->filename = cPart(imap)->name; - else - { - char *tmp = getUID(); - cPart(imap)->filename = tmp; - appendP(cPart(imap)->filename, esp_mail_str_40, false); - delS(tmp); - } - } - } - } - } - - int acnt = 0; - int ccnt = 0; - - for (size_t j = 0; j < cHeader(imap)->part_headers.size(); j++) - { - imap->_cPartIdx = j; - - if (cPart(imap)->rfc822_part || cPart(imap)->multipart_sub_type != esp_mail_imap_multipart_sub_type_none) - continue; - - bool rfc822_body_subtype = cPart(imap)->message_sub_type == esp_mail_imap_message_sub_type_rfc822; - - if (cPart(imap)->attach_type == esp_mail_att_type_none || cPart(imap)->msg_type == esp_mail_msg_type_html || cPart(imap)->msg_type == esp_mail_msg_type_plain || cPart(imap)->msg_type == esp_mail_msg_type_enriched) - { - - bool ret = ((imap->_config->enable.rfc822 || imap->_config->download.rfc822) && rfc822_body_subtype) || (!rfc822_body_subtype && ((imap->_config->enable.text && (cPart(imap)->msg_type == esp_mail_msg_type_plain || cPart(imap)->msg_type == esp_mail_msg_type_enriched)) || (imap->_config->enable.html && cPart(imap)->msg_type == esp_mail_msg_type_html) || (cPart(imap)->msg_type == esp_mail_msg_type_html && imap->_config->download.html) || ((cPart(imap)->msg_type == esp_mail_msg_type_plain || cPart(imap)->msg_type == esp_mail_msg_type_enriched) && imap->_config->download.text))); - if (!ret) - continue; - - if ((imap->_config->download.rfc822 && rfc822_body_subtype) || (!rfc822_body_subtype && ((cPart(imap)->msg_type == esp_mail_msg_type_html && imap->_config->download.html) || ((cPart(imap)->msg_type == esp_mail_msg_type_plain || cPart(imap)->msg_type == esp_mail_msg_type_enriched) && imap->_config->download.text)))) - { - - if (ccnt == 0) - { - imapCB(imap, "", false); - imapCBP(imap, esp_mail_str_57, false); - } - - if (imap->_debug) - { - if (cPart(imap)->msg_type == esp_mail_msg_type_plain || cPart(imap)->msg_type == esp_mail_msg_type_enriched) - debugInfoP(esp_mail_str_59); - else if (cPart(imap)->msg_type == esp_mail_msg_type_html) - debugInfoP(esp_mail_str_60); - } - } - else - { - if (ccnt == 0) - { - imapCB(imap, "", false); - imapCBP(imap, esp_mail_str_307, false); - } - - if (imap->_debug) - { - if (cPart(imap)->msg_type == esp_mail_msg_type_plain || cPart(imap)->msg_type == esp_mail_msg_type_enriched) - debugInfoP(esp_mail_str_308); - else if (cPart(imap)->msg_type == esp_mail_msg_type_html) - debugInfoP(esp_mail_str_309); - } - } - - ccnt++; - - if (!sendIMAPCommand(imap, i, 2)) - return false; - - imap->_imap_cmd = esp_mail_imap_command::esp_mail_imap_cmd_fetch_body_text; - if (!handleIMAPResponse(imap, IMAP_STATUS_IMAP_RESPONSE_FAILED, closeSession)) - return false; - } - else if (cPart(imap)->attach_type != esp_mail_att_type_none && (_sdOk || _flashOk)) - { - - if (imap->_config->download.attachment || imap->_config->download.inlineImg) - { - if (acnt == 0) - { - imapCB(imap, "", false); - imapCBP(imap, esp_mail_str_80, false); - } - - if (imap->_debug) - debugInfoP(esp_mail_str_55); - - acnt++; - if (cPart(imap)->octetLen <= (int)imap->_config->limit.attachment_size) - { - - if (_sdOk || _flashOk) - { - - if ((int)j < (int)cHeader(imap)->part_headers.size() - 1) - if (cHeader(imap)->part_headers[j + 1].octetLen > (int)imap->_config->limit.attachment_size) - cHeader(imap)->downloaded_bytes += cHeader(imap)->part_headers[j + 1].octetLen; - - if (!sendIMAPCommand(imap, i, 3)) - return false; - - imap->_imap_cmd = esp_mail_imap_command::esp_mail_imap_cmd_fetch_body_attachment; - if (!handleIMAPResponse(imap, IMAP_STATUS_IMAP_RESPONSE_FAILED, closeSession)) - return false; - delay(0); - } - } - else - { - if ((int)j == (int)cHeader(imap)->part_headers.size() - 1) - cHeader(imap)->downloaded_bytes += cPart(imap)->octetLen; - } - } - } - } - } - - if (imap->_config->download.header && !imap->_headerSaved) - { - if (imap->_readCallback) - { - imapCB(imap, "", false); - imapCBP(imap, esp_mail_str_124, false); - } - saveHeader(imap); - } - - if (closeSession) - { - if (imap->_storageType == esp_mail_file_storage_type_sd) - { - if (_sdOk) - ESP_MAIL_SD_FS.end(); - _sdOk = false; - } - else if (imap->_storageType == esp_mail_file_storage_type_flash) - { - if (_flashOk) - ESP_MAIL_FLASH_FS.end(); - - _flashOk = false; - } - } - - imap->_cMsgIdx++; - } - - if (imap->_debug) - { - std::string s; - appendP(s, esp_mail_str_261, true); - appendP(s, esp_mail_str_84, false); - char *tmp = intStr(ESP.getFreeHeap()); - s += tmp; - delS(tmp); - esp_mail_debug(s.c_str()); - } - } - -out: - - if (readCount < imap->_msgNum.size()) - { - imap->_mbif._availableItems = readCount; - imap->_msgNum.erase(imap->_msgNum.begin() + readCount, imap->_msgNum.end()); - } - - if (closeSession) - { - if (!imap->closeSession()) - return false; - } - else - { - if (imap->_readCallback) - { - imapCB(imap, "", false); - imapCBP(imap, esp_mail_str_87, false); - } - - if (imap->_debug) - debugInfoP(esp_mail_str_88); - } - - if (imap->_readCallback) - imapCB(imap, "", true); - - return true; -} -bool ESP_Mail_Client::getMultipartFechCmd(IMAPSession *imap, int msgIdx, std::string &partText) -{ - if (imap->_multipart_levels.size() == 0) - return false; - - int cLevel = imap->_multipart_levels.size() - 1; - - cHeader(imap)->partNumStr.clear(); - - if (imap->_uidSearch || strlen(imap->_config->fetch.uid) > 0) - appendP(partText, esp_mail_str_142, true); - else - appendP(partText, esp_mail_str_143, true); - - char *tmp = intStr(imap->_msgNum[msgIdx]); - partText += tmp; - delS(tmp); - - appendP(partText, esp_mail_str_147, false); - if (!imap->_config->fetch.set_seen) - { - appendP(partText, esp_mail_str_152, false); - appendP(partText, esp_mail_str_214, false); - } - appendP(partText, esp_mail_str_218, false); - - for (size_t i = 0; i < imap->_multipart_levels.size(); i++) - { - if (i > 0) - { - appendP(partText, esp_mail_str_152, false); - appendP(cHeader(imap)->partNumStr, esp_mail_str_152, false); - } - - tmp = intStr(imap->_multipart_levels[i].level); - partText += tmp; - cHeader(imap)->partNumStr += tmp; - delS(tmp); - } - - if (imap->_multipart_levels[cLevel].fetch_rfc822_header) - { - appendP(partText, esp_mail_str_51, false); - imap->_multipart_levels[cLevel].append_body_text = true; - } - else - appendP(partText, esp_mail_str_148, false); - - imap->_multipart_levels[cLevel].fetch_rfc822_header = false; - - return true; -} - -bool ESP_Mail_Client::multipartMember(const std::string &part, const std::string &check) -{ - if (part.length() > check.length()) - return false; - - for (size_t i = 0; i < part.length(); i++) - if (part[i] != check[i]) - return false; - - return true; -} - -bool ESP_Mail_Client::fetchMultipartBodyHeader(IMAPSession *imap, int msgIdx) -{ - bool ret = true; - - if (!connected(imap)) - { - closeTCP(imap); - return false; - } - int cLevel = 0; - - do - { - - struct esp_mail_message_part_info_t *_cpart = &cHeader(imap)->part_headers[cHeader(imap)->message_data_count - 1]; - bool rfc822_body_subtype = _cpart->message_sub_type == esp_mail_imap_message_sub_type_rfc822; - - std::string cmd; - - if (!getMultipartFechCmd(imap, msgIdx, cmd)) - return true; - - if (imap->_debug) - { - std::string s; - if (imap->_multipart_levels.size() > 1) - appendP(s, esp_mail_str_86, true); - else - appendP(s, esp_mail_str_81, true); - s += cHeader(imap)->partNumStr; - esp_mail_debug(s.c_str()); - } - - if (imapSend(imap, cmd.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return false; - - imap->_imap_cmd = esp_mail_imap_cmd_fetch_body_mime; - - ret = handleIMAPResponse(imap, IMAP_STATUS_IMAP_RESPONSE_FAILED, false); - - _cpart = &cHeader(imap)->part_headers[cHeader(imap)->message_data_count - 1]; - rfc822_body_subtype = _cpart->message_sub_type == esp_mail_imap_message_sub_type_rfc822; - cLevel = imap->_multipart_levels.size() - 1; - - if (ret) - { - - if (_cpart->multipart) - { - if (_cpart->multipart_sub_type == esp_mail_imap_multipart_sub_type_parallel || _cpart->multipart_sub_type == esp_mail_imap_multipart_sub_type_alternative || _cpart->multipart_sub_type == esp_mail_imap_multipart_sub_type_related || _cpart->multipart_sub_type == esp_mail_imap_multipart_sub_type_mixed) - { - struct esp_mail_imap_multipart_level_t mlevel; - mlevel.level = 1; - mlevel.fetch_rfc822_header = false; - mlevel.append_body_text = false; - imap->_multipart_levels.push_back(mlevel); - fetchMultipartBodyHeader(imap, msgIdx); - } - else - imap->_multipart_levels[cLevel].level++; - } - else - { - if (rfc822_body_subtype) - { - //to get additional rfc822 message header - imap->_multipart_levels[cLevel].fetch_rfc822_header = true; - fetchMultipartBodyHeader(imap, msgIdx); - } - else - { - if (imap->_multipart_levels[cLevel].append_body_text) - { - //single part rfc822 message body, append TEXT to the body fetch command - appendP(_cpart->partNumFetchStr, esp_mail_str_152, false); - appendP(_cpart->partNumFetchStr, esp_mail_str_215, false); - imap->_multipart_levels[cLevel].append_body_text = false; - } - imap->_multipart_levels[cLevel].level++; - } - } - } - - } while (ret); - - imap->_multipart_levels.pop_back(); - - if (imap->_multipart_levels.size() > 0) - { - cLevel = imap->_multipart_levels.size() - 1; - imap->_multipart_levels[cLevel].level++; - } - - return true; -} - -bool ESP_Mail_Client::connected(IMAPSession *imap) -{ - if (!imap->_secure) - { - if (!imap->httpClient._stream()) - return false; - return imap->httpClient._stream()->_ns_connected(); - } - else - { - if (!imap->httpClient.stream()) - return false; - return imap->httpClient.stream()->connected(); - } -} - -bool ESP_Mail_Client::imapAuth(IMAPSession *imap) -{ - - bool ssl = false; - std::string buf; -#if defined(ESP32) - imap->httpClient.setDebugCallback(NULL); -#elif defined(ESP8266) - -#endif - - if (imap->_config != nullptr) - { - if (strlen(imap->_config->fetch.uid) > 0) - imap->_headerOnly = false; - else - imap->_headerOnly = true; - } - - imap->_totalRead = 0; - imap->_secure = true; - bool secureMode = true; - -#if defined(ESP32) - if (imap->_debug) - imap->httpClient.setDebugCallback(esp_mail_debug); -#elif defined(ESP8266) - imap->httpClient.txBufDivider = 16; //minimum, tx buffer size for ssl data and request command data - imap->httpClient.rxBufDivider = 1; - if (imap->_config != nullptr) - { - if (!imap->_headerOnly && !imap->_config->enable.html && !imap->_config->enable.text && !imap->_config->download.attachment && !imap->_config->download.inlineImg && !imap->_config->download.html && !imap->_config->download.text) - imap->httpClient.rxBufDivider = 16; // minimum rx buffer size for only message header - } -#endif - - if (imap->_sesson_cfg->server.port == esp_mail_imap_port_143) - { - imap->_secure = false; - secureMode = false; - } - else - secureMode = !imap->_sesson_cfg->secure.startTLS; - - setSecure(imap->httpClient, imap->_sesson_cfg, imap->_caCert); - - if (imap->_readCallback) - imapCBP(imap, esp_mail_str_50, false); - - if (imap->_debug) - { - std::string s; - appendP(s, esp_mail_str_314, true); - s += ESP_MAIL_VERSION; - esp_mail_debug(s.c_str()); - - debugInfoP(esp_mail_str_225); - appendP(s, esp_mail_str_261, true); - appendP(s, esp_mail_str_211, false); - s += imap->_sesson_cfg->server.host_name; - esp_mail_debug(s.c_str()); - char *tmp = intStr(imap->_sesson_cfg->server.port); - appendP(s, esp_mail_str_261, true); - appendP(s, esp_mail_str_201, false); - s += tmp; - delS(tmp); - esp_mail_debug(s.c_str()); - } - - imap->httpClient.begin(imap->_sesson_cfg->server.host_name, imap->_sesson_cfg->server.port); - - if (!imap->httpClient.connect(secureMode)) - return handleIMAPError(imap, IMAP_STATUS_SERVER_CONNECT_FAILED, false); - - imap->_tcpConnected = true; - WiFiClient *stream = imap->httpClient.stream(); -#if defined(ESP32) - stream->setTimeout(ESP_MAIL_DEFAULT_TCP_TIMEOUT_SEC); -#elif defined(ESP8266) - stream->setTimeout(ESP_MAIL_DEFAULT_TCP_TIMEOUT_SEC * 1000); -#endif - imap->httpClient.tcpTimeout = ESP_MAIL_DEFAULT_TCP_TIMEOUT_SEC * 1000; - - if (imap->_readCallback) - imapCBP(imap, esp_mail_str_54, false); - - if (imap->_debug) - debugInfoP(esp_mail_str_228); - -init: - - if (!imap->checkCapability()) - return false; - - //start TLS when needed or the server issue - if ((imap->_auth_capability.start_tls || imap->_sesson_cfg->secure.startTLS) && !ssl) - { - std::string s; - if (imap->_readCallback) - { - appendP(s, esp_mail_str_34, true); - appendP(s, esp_mail_str_209, false); - esp_mail_debug(s.c_str()); - } - - if (imap->_debug) - { - appendP(s, esp_mail_str_196, true); - esp_mail_debug(s.c_str()); - } - - imapSendP(imap, esp_mail_str_311, false); - imap->_imap_cmd = esp_mail_imap_command::esp_mail_imap_cmd_starttls; - if (!handleIMAPResponse(imap, IMAP_STATUS_BAD_COMMAND, false)) - return false; - - if (imap->_debug) - { - debugInfoP(esp_mail_str_310); - } - - //connect in secure mode - //do ssl handshaking - if (!imap->httpClient._stream()->_ns_connect_ssl()) - return handleIMAPError(imap, MAIL_CLIENT_ERROR_SSL_TLS_STRUCTURE_SETUP, false); - - //set the secure mode - imap->_sesson_cfg->secure.startTLS = false; - ssl = true; - imap->_secure = true; - - //check the capabilitiy again - goto init; - } - - imap->clearMessageData(); - imap->_mailboxOpened = false; - - bool creds = strlen(imap->_sesson_cfg->login.email) > 0 && strlen(imap->_sesson_cfg->login.password) > 0; - bool xoauth_auth = strlen(imap->_sesson_cfg->login.accessToken) > 0 && imap->_auth_capability.xoauth2; - bool login_auth = creds; - bool plain_auth = imap->_auth_capability.plain && creds; - - bool supported_auth = xoauth_auth || login_auth || plain_auth; - - if (!supported_auth) - return handleIMAPError(imap, IMAP_STATUS_NO_SUPPORTED_AUTH, false); - - //rfc4959 - if (supported_auth) - { - if (imap->_readCallback) - { - imapCB(imap, "", false); - imapCBP(imap, esp_mail_str_56, false); - } - } - - if (xoauth_auth) - { - if (!imap->_auth_capability.xoauth2) - return handleIMAPError(imap, IMAP_STATUS_SERVER_OAUTH2_LOGIN_DISABLED, false); - - if (imap->_debug) - debugInfoP(esp_mail_str_291); - - std::string cmd; - appendP(cmd, esp_mail_str_292, true); - cmd += getEncodedToken(imap); - if (imapSend(imap, cmd.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return false; - - imap->_imap_cmd = esp_mail_imap_command::esp_mail_imap_cmd_auth; - if (!handleIMAPResponse(imap, IMAP_STATUS_LOGIN_FAILED, false)) - return false; - } - else if (login_auth) - { - - if (imap->_debug) - debugInfoP(esp_mail_str_229); - - std::string cmd; - - appendP(cmd, esp_mail_str_130, true); - cmd += imap->_sesson_cfg->login.email; - appendP(cmd, esp_mail_str_131, false); - cmd += imap->_sesson_cfg->login.password; - - if (imapSend(imap, cmd.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return false; - - imap->_imap_cmd = esp_mail_imap_command::esp_mail_imap_cmd_login; - if (!handleIMAPResponse(imap, IMAP_STATUS_LOGIN_FAILED, true)) - return false; - } - else if (plain_auth) - { - if (imap->_debug) - debugInfoP(esp_mail_str_290); - - const char *usr = imap->_sesson_cfg->login.email; - const char *psw = imap->_sesson_cfg->login.password; - int len = strlen(usr) + strlen(psw) + 2; - uint8_t *tmp = new uint8_t[len]; - memset(tmp, 0, len); - int p = 1; - memcpy(tmp + p, usr, strlen(usr)); - p += strlen(usr) + 1; - memcpy(tmp + p, psw, strlen(psw)); - p += strlen(psw); - - std::string s; - appendP(s, esp_mail_str_41, true); - s += encodeBase64Str(tmp, p); - delete[] tmp; - - if (imapSend(imap, s.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return false; - - imap->_imap_cmd = esp_mail_imap_command::esp_mail_imap_cmd_login; - if (!handleIMAPResponse(imap, IMAP_STATUS_LOGIN_FAILED, true)) - return false; - } - - return true; -} - -std::string ESP_Mail_Client::getEncodedToken(IMAPSession *imap) -{ - std::string raw; - appendP(raw, esp_mail_str_285, true); - raw += imap->_sesson_cfg->login.email; - appendP(raw, esp_mail_str_286, false); - raw += imap->_sesson_cfg->login.accessToken; - appendP(raw, esp_mail_str_287, false); - std::string s = encodeBase64Str((const unsigned char *)raw.c_str(), raw.length()); - return s; -} - -bool ESP_Mail_Client::imapLogout(IMAPSession *imap) -{ - if (imap->_readCallback) - { - imapCB(imap, "", false); - imapCBP(imap, esp_mail_str_85, false); - } - - if (imap->_debug) - debugInfoP(esp_mail_str_234); - - if (imapSendP(imap, esp_mail_str_146, true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return false; - - imap->_imap_cmd = esp_mail_imap_cmd_logout; - if (!handleIMAPResponse(imap, IMAP_STATUS_BAD_COMMAND, false)) - return false; - - if (imap->_readCallback) - { - imapCB(imap, "", false); - imapCBP(imap, esp_mail_str_187, false); - } - - if (imap->_debug) - debugInfoP(esp_mail_str_235); - - return true; -} - -void ESP_Mail_Client::errorStatusCB(IMAPSession *imap, int error) -{ - imap->_imapStatus.statusCode = error; - std::string s; - if (imap->_readCallback) - { - appendP(s, esp_mail_str_53, true); - s += imap->errorReason().c_str(); - imapCB(imap, s.c_str(), false); - } - - if (imap->_debug) - { - appendP(s, esp_mail_str_185, true); - s += imap->errorReason().c_str(); - esp_mail_debug(s.c_str()); - } -} - -size_t ESP_Mail_Client::imapSendP(IMAPSession *imap, PGM_P v, bool newline) -{ - if (!reconnect(imap)) - { - closeTCP(imap); - return 0; - } - - if (!connected(imap)) - { - errorStatusCB(imap, MAIL_CLIENT_ERROR_CONNECTION_LOST); - return 0; - } - - if (!imap->_tcpConnected) - { - errorStatusCB(imap, MAIL_CLIENT_ERROR_SERVER_CONNECTION_FAILED); - return 0; - } - - char *tmp = strP(v); - size_t len = 0; - - if (newline) - { - if (imap->_debugLevel > esp_mail_debug_level_2) - esp_mail_debug(tmp); - if (!imap->_secure) - len = imap->httpClient._ns_println(tmp); - else - len = imap->httpClient.stream()->println(tmp); - } - else - { - if (imap->_debugLevel > esp_mail_debug_level_2) - esp_mail_debug_line(tmp, false); - if (!imap->_secure) - len = imap->httpClient._ns_print(tmp); - else - len = imap->httpClient.stream()->print(tmp); - } - - if (len != strlen(tmp) && len != strlen(tmp) + 2) - { - errorStatusCB(imap, MAIL_CLIENT_ERROR_SERVER_CONNECTION_FAILED); - len = 0; - } - - delS(tmp); - - return len; -} - -size_t ESP_Mail_Client::imapSend(IMAPSession *imap, const char *data, bool newline) -{ - if (!reconnect(imap)) - { - closeTCP(imap); - return 0; - } - - if (!connected(imap)) - { - errorStatusCB(imap, MAIL_CLIENT_ERROR_CONNECTION_LOST); - return 0; - } - - if (!imap->_tcpConnected) - { - errorStatusCB(imap, MAIL_CLIENT_ERROR_SERVER_CONNECTION_FAILED); - return 0; - } - - size_t len = 0; - - if (newline) - { - if (imap->_debugLevel > esp_mail_debug_level_2) - esp_mail_debug(data); - if (!imap->_secure) - len = imap->httpClient._ns_println(data); - else - len = imap->httpClient.stream()->println(data); - } - else - { - if (imap->_debugLevel > esp_mail_debug_level_2) - esp_mail_debug_line(data, false); - if (!imap->_secure) - len = imap->httpClient._ns_print(data); - else - len = imap->httpClient.stream()->print(data); - } - - if (len != strlen(data) && len != strlen(data) + 2) - { - errorStatusCB(imap, MAIL_CLIENT_ERROR_SERVER_CONNECTION_FAILED); - len = 0; - } - return len; -} - -size_t ESP_Mail_Client::imapSend(IMAPSession *imap, int data, bool newline) -{ - if (!reconnect(imap)) - { - closeTCP(imap); - return 0; - } - - if (!connected(imap)) - { - errorStatusCB(imap, MAIL_CLIENT_ERROR_CONNECTION_LOST); - return 0; - } - - if (!imap->_tcpConnected) - { - errorStatusCB(imap, MAIL_CLIENT_ERROR_SERVER_CONNECTION_FAILED); - return 0; - } - - char *tmp = intStr(data); - size_t len = 0; - - if (newline) - { - if (imap->_debugLevel > esp_mail_debug_level_2) - esp_mail_debug(tmp); - if (!imap->_secure) - len = imap->httpClient._ns_println(tmp); - else - len = imap->httpClient.stream()->println(tmp); - } - else - { - if (imap->_debugLevel > esp_mail_debug_level_2) - esp_mail_debug_line(tmp, false); - if (!imap->_secure) - len = imap->httpClient._ns_print(tmp); - else - len = imap->httpClient.stream()->print(tmp); - } - - if (len != strlen(tmp) && len != strlen(tmp) + 2) - { - errorStatusCB(imap, MAIL_CLIENT_ERROR_SERVER_CONNECTION_FAILED); - len = 0; - } - - delS(tmp); - - return len; -} - -bool ESP_Mail_Client::setFlag(IMAPSession *imap, int msgUID, const char *flag, bool closeSession) -{ - return _setFlag(imap, msgUID, flag, 0, closeSession); -} - -bool ESP_Mail_Client::addFlag(IMAPSession *imap, int msgUID, const char *flag, bool closeSession) -{ - return _setFlag(imap, msgUID, flag, 1, closeSession); -} - -bool ESP_Mail_Client::removeFlag(IMAPSession *imap, int msgUID, const char *flag, bool closeSession) -{ - return _setFlag(imap, msgUID, flag, 2, closeSession); -} - -bool ESP_Mail_Client::_setFlag(IMAPSession *imap, int msgUID, const char *flag, uint8_t action, bool closeSession) -{ - if (!reconnect(imap)) - return false; - - if (!imap->_tcpConnected) - { - imap->_mailboxOpened = false; - return false; - } - - if (imap->_currentFolder.length() == 0) - { - if (imap->_readCallback) - debugInfoP(esp_mail_str_153); - - if (imap->_debug) - { - std::string e; - appendP(e, esp_mail_str_185, true); - appendP(e, esp_mail_str_151, false); - esp_mail_debug(e.c_str()); - } - } - else - { - if (imap->_readOnlyMode || !imap->_mailboxOpened) - { - if (!imap->selectFolder(imap->_currentFolder.c_str(), false)) - return false; - } - } - - if (imap->_readCallback) - { - imapCB(imap, "", false); - if (action == 0) - debugInfoP(esp_mail_str_157); - else if (action == 1) - debugInfoP(esp_mail_str_155); - else - debugInfoP(esp_mail_str_154); - } - - if (imap->_debug) - { - if (action == 0) - debugInfoP(esp_mail_str_253); - else if (action == 1) - debugInfoP(esp_mail_str_254); - else - debugInfoP(esp_mail_str_255); - } - - std::string cmd; - appendP(cmd, esp_mail_str_249, true); - char *tmp = intStr(msgUID); - cmd += tmp; - delS(tmp); - if (action == 0) - appendP(cmd, esp_mail_str_250, false); - else if (action == 1) - appendP(cmd, esp_mail_str_251, false); - else - appendP(cmd, esp_mail_str_252, false); - cmd += flag; - appendP(cmd, esp_mail_str_192, false); - - if (imapSend(imap, cmd.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return false; - - imap->_imap_cmd = esp_mail_imap_cmd_store; - - if (!handleIMAPResponse(imap, IMAP_STATUS_PARSE_FLAG_FAILED, false)) - return false; - - if (closeSession) - imap->closeSession(); - - return true; -} - -void ESP_Mail_Client::createDirs(std::string dirs) -{ - std::string dir = ""; - int count = 0; - for (size_t i = 0; i < dirs.length(); i++) - { - dir.append(1, dirs[i]); - count++; - if (dirs[i] == '/') - { - if (dir.length() > 0) - ESP_MAIL_SD_FS.mkdir(dir.substr(0, dir.length() - 1).c_str()); - count = 0; - } - } - if (count > 0) - ESP_MAIL_SD_FS.mkdir(dir.c_str()); - std::string().swap(dir); -} - -bool ESP_Mail_Client::sdTest() -{ -#if defined(CARD_TYPE_SD) - if (_sdConfigSet) - sdBegin(_sck, _miso, _mosi, _ss); - else - sdBegin(); -#endif - -#if defined(ESP32) -#if defined(CARD_TYPE_SD_MMC) - if (_sdConfigSet) - sdMMCBegin(sd_mmc_mountpoint, sd_mmc_mode1bit, sd_mmc_format_if_mount_failed); -#endif -#endif - - file = ESP_MAIL_SD_FS.open(esp_mail_str_204, FILE_WRITE); - if (!file) - return false; - - if (!file.write(32)) - return false; - file.close(); - - file = ESP_MAIL_SD_FS.open(esp_mail_str_204); - if (!file) - return false; - - while (file.available()) - { - if (file.read() != 32) - return false; - } - file.close(); - - ESP_MAIL_SD_FS.remove(esp_mail_str_204); - - return true; -} - -std::string ESP_Mail_Client::getEncodedToken(SMTPSession *smtp) -{ - std::string raw; - appendP(raw, esp_mail_str_285, true); - raw += smtp->_sesson_cfg->login.email; - appendP(raw, esp_mail_str_286, false); - raw += smtp->_sesson_cfg->login.accessToken; - appendP(raw, esp_mail_str_287, false); - return encodeBase64Str((const unsigned char *)raw.c_str(), raw.length()); -} - -bool ESP_Mail_Client::smtpAuth(SMTPSession *smtp) -{ - - if (!reconnect(smtp)) - return false; - - bool ssl = false; - smtp->_secure = true; - bool secureMode = true; - - std::string s; - -#if defined(ESP32) - smtp->httpClient.setDebugCallback(NULL); -#elif defined(ESP8266) - smtp->httpClient.rxBufDivider = 16; // minimum rx buffer for smtp status response - smtp->httpClient.txBufDivider = 8; // medium tx buffer for faster attachment/inline data transfer -#endif - - if (smtp->_sesson_cfg->server.port == esp_mail_smtp_port_25) - { - smtp->_secure = false; - secureMode = false; - } - else - { - if (smtp->_sesson_cfg->server.port == esp_mail_smtp_port_587) - smtp->_sesson_cfg->secure.startTLS = true; - - secureMode = !smtp->_sesson_cfg->secure.startTLS; - - //to prevent to send the connection upgrade command when some server promotes - //the starttls capability even the current connection was already secured. - if (smtp->_sesson_cfg->server.port == esp_mail_smtp_port_465) - ssl = true; - } - - setSecure(smtp->httpClient, smtp->_sesson_cfg, smtp->_caCert); - - //Server connection attempt: no status code - if (smtp->_sendCallback) - smtpCBP(smtp, esp_mail_str_120); - - if (smtp->_debug) - { - appendP(s, esp_mail_str_314, true); - s += ESP_MAIL_VERSION; - esp_mail_debug(s.c_str()); - - debugInfoP(esp_mail_str_236); - appendP(s, esp_mail_str_261, true); - appendP(s, esp_mail_str_211, false); - s += smtp->_sesson_cfg->server.host_name; - esp_mail_debug(s.c_str()); - char *tmp = intStr(smtp->_sesson_cfg->server.port); - appendP(s, esp_mail_str_261, true); - appendP(s, esp_mail_str_201, false); - s += tmp; - delS(tmp); - esp_mail_debug(s.c_str()); - } -#if defined(ESP32) - if (smtp->_debug) - smtp->httpClient.setDebugCallback(esp_mail_debug); -#endif - - smtp->httpClient.begin(smtp->_sesson_cfg->server.host_name, smtp->_sesson_cfg->server.port); - - if (!smtp->httpClient.connect(secureMode)) - return handleSMTPError(smtp, SMTP_STATUS_SERVER_CONNECT_FAILED); - - //server connected - smtp->_tcpConnected = true; - - if (smtp->_debug) - debugInfoP(esp_mail_str_238); - - if (smtp->_sendCallback) - { - smtpCB(smtp, ""); - smtpCBP(smtp, esp_mail_str_121); - } - -#if defined(ESP32) - smtp->httpClient.stream()->setTimeout(ESP_MAIL_DEFAULT_TCP_TIMEOUT_SEC); -#elif defined(ESP8266) - smtp->httpClient.stream()->setTimeout(ESP_MAIL_DEFAULT_TCP_TIMEOUT_SEC * 1000); -#endif - smtp->httpClient.tcpTimeout = ESP_MAIL_DEFAULT_TCP_TIMEOUT_SEC * 1000; - - smtp->_smtp_cmd = esp_mail_smtp_command::esp_mail_smtp_cmd_initial_state; - - //expected status code 220 for ready to service - if (!handleSMTPResponse(smtp, esp_mail_smtp_status_code_220, SMTP_STATUS_SMTP_GREETING_GET_RESPONSE_FAILED)) - return false; - -init: - - //Sending greeting hello response - if (smtp->_sendCallback) - { - smtpCB(smtp, ""); - smtpCBP(smtp, esp_mail_str_122); - } - - if (smtp->_debug) - debugInfoP(esp_mail_str_239); - - appendP(s, esp_mail_str_6, true); - if (strlen(smtp->_sesson_cfg->login.user_domain) > 0) - s += smtp->_sesson_cfg->login.user_domain; - else - appendP(s, esp_mail_str_44, false); - - if (smtpSendP(smtp, s.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return false; - - smtp->_smtp_cmd = esp_mail_smtp_command::esp_mail_smtp_cmd_greeting; - - if (!handleSMTPResponse(smtp, esp_mail_smtp_status_code_250, 0)) - { - appendP(s, esp_mail_str_5, true); - if (strlen(smtp->_sesson_cfg->login.user_domain) > 0) - s += smtp->_sesson_cfg->login.user_domain; - else - appendP(s, esp_mail_str_44, false); - - if (smtpSend(smtp, s.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return false; - if (!handleSMTPResponse(smtp, esp_mail_smtp_status_code_250, SMTP_STATUS_SMTP_GREETING_SEND_ACK_FAILED)) - return false; - smtp->_send_capability.esmtp = false; - smtp->_auth_capability.login = true; - } - else - smtp->_send_capability.esmtp = true; - - //start TLS when needed - if ((smtp->_auth_capability.start_tls || smtp->_sesson_cfg->secure.startTLS) && !ssl) - { - //send starttls command - if (smtp->_sendCallback) - { - smtpCB(smtp, ""); - smtpCBP(smtp, esp_mail_str_209); - } - - if (smtp->_debug) - { - appendP(s, esp_mail_str_196, true); - esp_mail_debug(s.c_str()); - } - - //expected status code 250 for complete the request - //some server returns 220 to restart to initial state - smtp->_smtp_cmd = esp_mail_smtp_command::esp_mail_smtp_cmd_start_tls; - smtpSendP(smtp, esp_mail_str_311, false); - if (!handleSMTPResponse(smtp, esp_mail_smtp_status_code_250, SMTP_STATUS_SMTP_GREETING_SEND_ACK_FAILED)) - return false; - - if (smtp->_debug) - { - debugInfoP(esp_mail_str_310); - } - - //connect using secure mode - //do ssl handshaking - if (!smtp->httpClient._stream()->_ns_connect_ssl()) - return handleSMTPError(smtp, MAIL_CLIENT_ERROR_SSL_TLS_STRUCTURE_SETUP); - - //set the secure mode - smtp->_sesson_cfg->secure.startTLS = false; - ssl = true; - smtp->_secure = true; - - //return to initial state if the response status is 220. - if (smtp->_smtpStatus.respCode == esp_mail_smtp_status_code_220) - goto init; - } - - bool creds = strlen(smtp->_sesson_cfg->login.email) > 0 && strlen(smtp->_sesson_cfg->login.password) > 0; - bool xoauth_auth = strlen(smtp->_sesson_cfg->login.accessToken) > 0 && smtp->_auth_capability.xoauth2; - bool login_auth = smtp->_auth_capability.login && creds; - bool plain_auth = smtp->_auth_capability.plain && creds; - - if (xoauth_auth || login_auth || plain_auth) - { - if (smtp->_sendCallback) - { - smtpCB(smtp, "", false); - smtpCBP(smtp, esp_mail_str_56, false); - } - - //log in - if (xoauth_auth) - { - if (smtp->_debug) - debugInfoP(esp_mail_str_288); - - if (!smtp->_auth_capability.xoauth2) - return handleSMTPError(smtp, SMTP_STATUS_SERVER_OAUTH2_LOGIN_DISABLED, false); - - if (smtpSendP(smtp, esp_mail_str_289, false) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return false; - - if (smtpSend(smtp, getEncodedToken(smtp).c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return false; - - smtp->_smtp_cmd = esp_mail_smtp_command::esp_mail_smtp_cmd_auth; - if (!handleSMTPResponse(smtp, esp_mail_smtp_status_code_235, SMTP_STATUS_AUTHEN_FAILED)) - return false; - - return true; - } - else if (plain_auth) - { - - if (smtp->_debug) - debugInfoP(esp_mail_str_241); - - if (smtp->_debug) - { - appendP(s, esp_mail_str_261, true); - s += smtp->_sesson_cfg->login.email; - esp_mail_debug(s.c_str()); - - appendP(s, esp_mail_str_131, false); - for (size_t i = 0; i < strlen(smtp->_sesson_cfg->login.password); i++) - appendP(s, esp_mail_str_183, false); - esp_mail_debug(s.c_str()); - } - - //rfc4616 - const char *usr = smtp->_sesson_cfg->login.email; - const char *psw = smtp->_sesson_cfg->login.password; - int len = strlen(usr) + strlen(psw) + 2; - uint8_t *tmp = new uint8_t[len]; - memset(tmp, 0, len); - int p = 1; - memcpy(tmp + p, usr, strlen(usr)); - p += strlen(usr) + 1; - memcpy(tmp + p, psw, strlen(psw)); - p += strlen(psw); - - std::string s; - appendP(s, esp_mail_str_45, true); - appendP(s, esp_mail_str_131, false); - s += encodeBase64Str(tmp, p); - delete[] tmp; - - if (smtpSend(smtp, s.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return false; - - smtp->_smtp_cmd = esp_mail_smtp_command::esp_mail_smtp_cmd_auth_plain; - if (!handleSMTPResponse(smtp, esp_mail_smtp_status_code_235, SMTP_STATUS_USER_LOGIN_FAILED)) - return false; - - return true; - } - else if (login_auth) - { - if (smtp->_debug) - debugInfoP(esp_mail_str_240); - - if (smtpSendP(smtp, esp_mail_str_4, true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return false; - - if (!handleSMTPResponse(smtp, esp_mail_smtp_status_code_334, SMTP_STATUS_AUTHEN_FAILED)) - return false; - - if (smtp->_debug) - { - appendP(s, esp_mail_str_261, true); - s += smtp->_sesson_cfg->login.email; - esp_mail_debug(s.c_str()); - } - - if (smtpSend(smtp, encodeBase64Str((const unsigned char *)smtp->_sesson_cfg->login.email, strlen(smtp->_sesson_cfg->login.email)).c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return false; - - smtp->_smtp_cmd = esp_mail_smtp_command::esp_mail_smtp_cmd_login_user; - if (!handleSMTPResponse(smtp, esp_mail_smtp_status_code_334, SMTP_STATUS_USER_LOGIN_FAILED)) - return false; - - if (smtp->_debug) - { - appendP(s, esp_mail_str_261, true); - for (size_t i = 0; i < strlen(smtp->_sesson_cfg->login.password); i++) - appendP(s, esp_mail_str_183, false); - esp_mail_debug(s.c_str()); - } - - if (smtpSend(smtp, encodeBase64Str((const unsigned char *)smtp->_sesson_cfg->login.password, strlen(smtp->_sesson_cfg->login.password)).c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return false; - - smtp->_smtp_cmd = esp_mail_smtp_command::esp_mail_smtp_cmd_login_psw; - if (!handleSMTPResponse(smtp, esp_mail_smtp_status_code_235, SMTP_STATUS_PASSWORD_LOGIN_FAILED)) - return false; - - return true; - } - } - - return true; -} - -void ESP_Mail_Client::mimeFromFile(const char *name, std::string &mime) -{ - std::string ext = name; - size_t p = ext.find_last_of("."); - if (p != std::string::npos) - { - ext = ext.substr(p, ext.length() - p); - if (ext.length() > 0) - getMIME(ext.c_str(), mime); - } -} - -bool ESP_Mail_Client::connected(SMTPSession *smtp) -{ - if (smtp->_sesson_cfg->secure.startTLS || !smtp->_secure) - { - if (!smtp->httpClient._stream()) - return false; - return smtp->httpClient._stream()->_ns_connected(); - } - else - { - if (!smtp->httpClient.stream()) - return false; - return smtp->httpClient.stream()->connected(); - } -} - -bool ESP_Mail_Client::setSendingResult(SMTPSession *smtp, SMTP_Message *msg, bool result) -{ - if (result) - smtp->_sentSuccessCount++; - else - smtp->_sentFailedCount++; - - if (smtp->_sendCallback) - { - struct esp_mail_smtp_send_status_t status; - status.completed = result; - status.timesstamp = time(nullptr); - status.subject = msg->subject; - status.recipients = msg->_rcp[0].email; - - smtp->sendingResult.add(status); - - smtp->_cbData._sentSuccess = smtp->_sentSuccessCount; - smtp->_cbData._sentFailed = smtp->_sentFailedCount; - } - - return result; -} - -bool ESP_Mail_Client::sendMail(SMTPSession *smtp, SMTP_Message *msg, bool closeSession) -{ - - if (strlen(msg->html.content) > 0 || msg->html.blob.size > 0 || strlen(msg->html.file.name) > 0) - msg->type |= esp_mail_msg_type_html; - - if (strlen(msg->text.content) > 0 || msg->text.blob.size > 0 || strlen(msg->text.file.name) > 0) - msg->type |= esp_mail_msg_type_plain; - - for (size_t i = 0; i < msg->_rfc822.size(); i++) - { - if (strlen(msg->_rfc822[i].html.content) > 0) - msg->_rfc822[i].type |= esp_mail_msg_type_html; - - if (strlen(msg->_rfc822[i].text.content) > 0) - msg->_rfc822[i].type |= esp_mail_msg_type_plain; - } - - return _sendMail(smtp, msg, closeSession); -} - -void ESP_Mail_Client::getMIME(const char *ext, std::string &mime) -{ - mime = ""; - for (int i = 0; i < esp_mail_file_extension_maxType; i++) - { - if (strcmp_P(ext, mimeinfo[i].endsWith) == 0) - { - char *tmp = strP(mimeinfo[i].mimeType); - mime = tmp; - delS(tmp); - break; - } - } -} - -size_t ESP_Mail_Client::numAtt(SMTPSession *smtp, esp_mail_attach_type type, SMTP_Message *msg) -{ - size_t count = 0; - for (size_t i = 0; i < msg->_att.size(); i++) - { - if (msg->_att[i]._int.att_type == type) - count++; - } - return count; -} - -bool ESP_Mail_Client::validEmail(const char *s) -{ - std::string str(s); - auto at = std::find(str.begin(), str.end(), '@'); - auto dot = std::find(at, str.end(), '.'); - return (at != str.end()) && (dot != str.end()); -} -bool ESP_Mail_Client::checkEmail(SMTPSession *smtp, SMTP_Message *msg) -{ - bool validRecipient = false; - - if (!validEmail(msg->sender.email)) - { - errorStatusCB(smtp, SMTP_STATUS_NO_VALID_SENDER_EXISTED); - return setSendingResult(smtp, msg, false); - } - - for (uint8_t i = 0; i < msg->_rcp.size(); i++) - { - if (validEmail(msg->_rcp[i].email)) - validRecipient = true; - } - - if (!validRecipient) - { - errorStatusCB(smtp, SMTP_STATUS_NO_VALID_RECIPIENTS_EXISTED); - return setSendingResult(smtp, msg, false); - } - - return true; -} - -bool ESP_Mail_Client::_sendMail(SMTPSession *smtp, SMTP_Message *msg, bool closeSession) -{ - - smtp->_smtpStatus.statusCode = 0; - smtp->_smtpStatus.respCode = 0; - smtp->_smtpStatus.text.clear(); - bool rfc822MSG = false; - - if (!checkEmail(smtp, msg)) - return false; - - smtp->_chunkedEnable = false; - smtp->_chunkCount = 0; - - //new session - if (!smtp->_tcpConnected) - { - if (!smtpAuth(smtp)) - { - closeTCP(smtp); - return setSendingResult(smtp, msg, false); - } - smtp->_sentSuccessCount = 0; - smtp->_sentFailedCount = 0; - smtp->sendingResult.clear(); - } - else - { - //reuse session - if (smtp->_sendCallback) - { - smtpCB(smtp, ""); - if (smtp->_sentSuccessCount || smtp->_sentFailedCount) - smtpCBP(smtp, esp_mail_str_267); - else - smtpCBP(smtp, esp_mail_str_208); - } - - if (smtp->_debug) - { - if (smtp->_sentSuccessCount || smtp->_sentFailedCount) - debugInfoP(esp_mail_str_268); - else - debugInfoP(esp_mail_str_207); - } - } - - if (smtp->_sendCallback) - { - smtpCB(smtp, ""); - smtpCBP(smtp, esp_mail_str_125); - } - - if (smtp->_debug) - debugInfoP(esp_mail_str_242); - - std::string buf; - std::string buf2; - checkBinaryData(smtp, msg); - - if (msg->priority >= esp_mail_smtp_priority_high && msg->priority <= esp_mail_smtp_priority_low) - { - char *tmp = intStr(msg->priority); - appendP(buf2, esp_mail_str_17, true); - buf2 += tmp; - delS(tmp); - appendP(buf2, esp_mail_str_34, false); - - if (msg->priority == esp_mail_smtp_priority_high) - { - appendP(buf2, esp_mail_str_18, false); - appendP(buf2, esp_mail_str_21, false); - } - else if (msg->priority == esp_mail_smtp_priority_normal) - { - appendP(buf2, esp_mail_str_19, false); - appendP(buf2, esp_mail_str_22, false); - } - else if (msg->priority == esp_mail_smtp_priority_low) - { - appendP(buf2, esp_mail_str_20, false); - appendP(buf2, esp_mail_str_23, false); - } - } - - appendP(buf2, esp_mail_str_10, false); - - if (strlen(msg->sender.name) > 0) - buf2 += msg->sender.name; - - appendP(buf2, esp_mail_str_14, false); - buf2 += msg->sender.email; - appendP(buf2, esp_mail_str_15, false); - appendP(buf2, esp_mail_str_34, false); - - appendP(buf, esp_mail_str_8, true); - appendP(buf, esp_mail_str_14, false); - buf += msg->sender.email; - appendP(buf, esp_mail_str_15, false); - - if (smtp->_send_capability.binaryMIME && smtp->_send_capability.chunking && msg->enable.chunking && (msg->text._int.binary || msg->html._int.binary)) - appendP(buf, esp_mail_str_104, false); - - if (smtpSend(smtp, buf.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return setSendingResult(smtp, msg, false); - - smtp->_smtp_cmd = esp_mail_smtp_command::esp_mail_smtp_cmd_send_header_sender; - if (!handleSMTPResponse(smtp, esp_mail_smtp_status_code_250, SMTP_STATUS_SEND_HEADER_SENDER_FAILED)) - return setSendingResult(smtp, msg, false); - - for (uint8_t i = 0; i < msg->_rcp.size(); i++) - { - if (i == 0) - { - appendP(buf2, esp_mail_str_11, false); - if (strlen(msg->_rcp[i].name) > 0) - buf2 += msg->_rcp[i].name; - - appendP(buf2, esp_mail_str_14, false); - buf2 += msg->_rcp[i].email; - appendP(buf2, esp_mail_str_15, false); - } - else - { - if (strlen(msg->_rcp[i].name) > 0) - { - appendP(buf2, esp_mail_str_263, false); - buf2 += msg->_rcp[i].name; - appendP(buf2, esp_mail_str_14, false); - } - else - appendP(buf2, esp_mail_str_13, false); - buf2 += msg->_rcp[i].email; - appendP(buf2, esp_mail_str_15, false); - } - - if (i == msg->_rcp.size() - 1) - appendP(buf2, esp_mail_str_34, false); - - buf.clear(); - //only address - appendP(buf, esp_mail_str_9, false); - appendP(buf, esp_mail_str_14, false); - buf += msg->_rcp[i].email; - appendP(buf, esp_mail_str_15, false); - - //rfc3461, rfc3464 - if (smtp->_send_capability.dsn) - { - if (msg->response.notify != esp_mail_smtp_notify::esp_mail_smtp_notify_never) - { - appendP(buf, esp_mail_str_262, false); - int opcnt = 0; - if (msg->response.notify && esp_mail_smtp_notify::esp_mail_smtp_notify_success) - { - if (opcnt > 0) - appendP(buf, esp_mail_str_263, false); - appendP(buf, esp_mail_str_264, false); - opcnt++; - } - if (msg->response.notify && esp_mail_smtp_notify::esp_mail_smtp_notify_failure) - { - if (opcnt > 0) - appendP(buf, esp_mail_str_263, false); - appendP(buf, esp_mail_str_265, false); - opcnt++; - } - if (msg->response.notify && esp_mail_smtp_notify::esp_mail_smtp_notify_delay) - { - if (opcnt > 0) - appendP(buf, esp_mail_str_263, false); - appendP(buf, esp_mail_str_266, false); - opcnt++; - } - } - } - - if (smtpSend(smtp, buf.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return setSendingResult(smtp, msg, false); - - smtp->_smtp_cmd = esp_mail_smtp_command::esp_mail_smtp_cmd_send_header_recipient; - if (!handleSMTPResponse(smtp, esp_mail_smtp_status_code_250, SMTP_STATUS_SEND_HEADER_RECIPIENT_FAILED)) - return setSendingResult(smtp, msg, false); - } - - for (uint8_t i = 0; i < msg->_cc.size(); i++) - { - if (i == 0) - { - appendP(buf2, esp_mail_str_12, false); - appendP(buf2, esp_mail_str_14, false); - buf2 += msg->_cc[i].email; - appendP(buf2, esp_mail_str_15, false); - } - else - { - appendP(buf2, esp_mail_str_13, false); - buf2 += msg->_cc[i].email; - appendP(buf2, esp_mail_str_15, false); - } - - if (i == msg->_cc.size() - 1) - appendP(buf2, esp_mail_str_34, false); - - buf.clear(); - - appendP(buf, esp_mail_str_9, false); - appendP(buf, esp_mail_str_14, false); - buf += msg->_cc[i].email; - appendP(buf, esp_mail_str_15, false); - - if (smtpSend(smtp, buf.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return setSendingResult(smtp, msg, false); - - smtp->_smtp_cmd = esp_mail_smtp_command::esp_mail_smtp_cmd_send_header_recipient; - if (!handleSMTPResponse(smtp, esp_mail_smtp_status_code_250, SMTP_STATUS_SEND_HEADER_RECIPIENT_FAILED)) - return setSendingResult(smtp, msg, false); - } - - for (uint8_t i = 0; i < msg->_bcc.size(); i++) - { - appendP(buf, esp_mail_str_9, true); - appendP(buf, esp_mail_str_14, false); - buf += msg->_bcc[i].email; - appendP(buf, esp_mail_str_15, false); - if (smtpSend(smtp, buf.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return setSendingResult(smtp, msg, false); - smtp->_smtp_cmd = esp_mail_smtp_command::esp_mail_smtp_cmd_send_header_recipient; - if (!handleSMTPResponse(smtp, esp_mail_smtp_status_code_250, SMTP_STATUS_SEND_HEADER_RECIPIENT_FAILED)) - return setSendingResult(smtp, msg, false); - } - - if (smtp->_sendCallback) - { - smtpCB(smtp, ""); - smtpCBP(smtp, esp_mail_str_126); - } - - if (smtp->_debug) - debugInfoP(esp_mail_str_243); - - if (smtp->_send_capability.chunking && msg->enable.chunking) - { - smtp->_chunkedEnable = true; - if (!bdat(smtp, msg, buf2.length(), false)) - return false; - } - else - { - if (smtpSendP(smtp, esp_mail_str_16, true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return setSendingResult(smtp, msg, false); - - smtp->_smtp_cmd = esp_mail_smtp_command::esp_mail_smtp_cmd_send_body; - if (!handleSMTPResponse(smtp, esp_mail_smtp_status_code_354, SMTP_STATUS_SEND_BODY_FAILED)) - return setSendingResult(smtp, msg, false); - } - - if (smtpSend(smtp, buf2.c_str(), false) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return setSendingResult(smtp, msg, false); - - std::string s; - appendP(s, esp_mail_str_24, true); - s += msg->subject; - appendP(s, esp_mail_str_34, false); - - if (msg->_hdr.size() > 0) - { - for (uint8_t k = 0; k < msg->_hdr.size(); k++) - { - s += msg->_hdr[k]; - appendP(s, esp_mail_str_34, false); - } - } - - if (strlen(msg->response.reply_to) > 0) - { - appendP(s, esp_mail_str_184, false); - appendP(s, esp_mail_str_14, false); - s += msg->response.reply_to; - appendP(s, esp_mail_str_15, false); - appendP(s, esp_mail_str_34, false); - } - - if (strlen(msg->response.return_path) > 0) - { - appendP(s, esp_mail_str_46, false); - appendP(s, esp_mail_str_14, false); - s += msg->response.return_path; - appendP(s, esp_mail_str_15, false); - appendP(s, esp_mail_str_34, false); - } - - appendP(s, esp_mail_str_3, false); - - if (!bdat(smtp, msg, s.length(), false)) - return false; - - if (smtpSend(smtp, s.c_str(), false) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return setSendingResult(smtp, msg, false); - - return sendMSGData(smtp, msg, closeSession, rfc822MSG); -} - -bool ESP_Mail_Client::sendMSGData(SMTPSession *smtp, SMTP_Message *msg, bool closeSession, bool rfc822MSG) -{ - std::string s; - std::string mixed = getBoundary(15); - std::string alt = getBoundary(15); - - if (numAtt(smtp, esp_mail_att_type_attachment, msg) == 0 && msg->_parallel.size() == 0 && msg->_rfc822.size() == 0) - { - if (msg->type == (esp_mail_msg_type_plain | esp_mail_msg_type_html | esp_mail_msg_type_enriched) || numAtt(smtp, esp_mail_att_type_inline, msg) > 0) - { - if (!sendMSG(smtp, msg, alt)) - return setSendingResult(smtp, msg, false); - } - else if (msg->type != esp_mail_msg_type_none) - { - if (!sendPartText(smtp, msg, msg->type, "")) - return setSendingResult(smtp, msg, false); - } - } - else - { - appendP(s, esp_mail_str_1, true); - s += mixed; - appendP(s, esp_mail_str_35, false); - - appendP(s, esp_mail_str_33, false); - s += mixed; - appendP(s, esp_mail_str_34, false); - - if (!bdat(smtp, msg, s.length(), false)) - return false; - - if (smtpSend(smtp, s.c_str(), false) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return setSendingResult(smtp, msg, false); - - if (!sendMSG(smtp, msg, alt)) - return setSendingResult(smtp, msg, false); - - if (!bdat(smtp, msg, 2, false)) - return false; - - if (smtpSendP(smtp, esp_mail_str_34, false) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return setSendingResult(smtp, msg, false); - - if (smtp->_sendCallback) - { - smtpCB(smtp, ""); - smtpCBP(smtp, esp_mail_str_127); - } - - if (smtp->_debug) - debugInfoP(esp_mail_str_244); - - if (smtp->_sendCallback && numAtt(smtp, esp_mail_att_type_attachment, msg) > 0) - esp_mail_debug(""); - - if (!sendAttachments(smtp, msg, mixed)) - return setSendingResult(smtp, msg, false); - - if (!sendParallelAttachments(smtp, msg, mixed)) - return setSendingResult(smtp, msg, false); - - if (!sendRFC822Msg(smtp, msg, mixed, closeSession, msg->_rfc822.size() > 0)) - return setSendingResult(smtp, msg, false); - - appendP(s, esp_mail_str_33, true); - s += mixed; - appendP(s, esp_mail_str_33, false); - - if (!bdat(smtp, msg, s.length(), false)) - return false; - - if (smtpSend(smtp, s.c_str(), false) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return setSendingResult(smtp, msg, false); - } - - if (!rfc822MSG) - { - if (smtp->_sendCallback) - { - smtpCB(smtp, ""); - smtpCBP(smtp, esp_mail_str_303); - } - - if (smtp->_debug) - debugInfoP(esp_mail_str_304); - - if (smtp->_chunkedEnable) - { - - if (!bdat(smtp, msg, 0, true)) - return false; - - smtp->_smtp_cmd = esp_mail_smtp_cmd_chunk_termination; - if (!handleSMTPResponse(smtp, esp_mail_smtp_status_code_250, SMTP_STATUS_SEND_BODY_FAILED)) - return false; - } - else - { - if (smtpSendP(smtp, esp_mail_str_37, false) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return setSendingResult(smtp, msg, false); - - smtp->_smtp_cmd = esp_mail_smtp_command::esp_mail_smtp_cmd_send_body; - if (!handleSMTPResponse(smtp, esp_mail_smtp_status_code_250, SMTP_STATUS_SEND_BODY_FAILED)) - return setSendingResult(smtp, msg, false); - } - - setSendingResult(smtp, msg, true); - - if (closeSession) - if (!smtp->closeSession()) - return false; - } - - return true; -} - -bool ESP_Mail_Client::sendRFC822Msg(SMTPSession *smtp, SMTP_Message *msg, const std::string &boundary, bool closeSession, bool rfc822MSG) -{ - if (msg->_rfc822.size() == 0) - return true; - std::string buf; - for (uint8_t i = 0; i < msg->_rfc822.size(); i++) - { - buf.clear(); - getRFC822PartHeader(smtp, buf, boundary); - - getRFC822MsgEnvelope(smtp, &msg->_rfc822[i], buf); - - if (!bdat(smtp, msg, buf.length(), false)) - return false; - - if (smtpSend(smtp, buf.c_str(), false) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return false; - - if (!sendMSGData(smtp, &msg->_rfc822[i], closeSession, rfc822MSG)) - return false; - } - - return true; -} - -void ESP_Mail_Client::getRFC822MsgEnvelope(SMTPSession *smtp, SMTP_Message *msg, std::string &buf) -{ - if (strlen(msg->date) > 0) - { - appendP(buf, esp_mail_str_99, false); - buf += msg->date; - appendP(buf, esp_mail_str_34, false); - } - - if (strlen(msg->from.email) > 0) - { - appendP(buf, esp_mail_str_10, false); - - if (strlen(msg->from.name) > 0) - buf += msg->from.name; - - appendP(buf, esp_mail_str_14, false); - buf += msg->from.email; - appendP(buf, esp_mail_str_15, false); - appendP(buf, esp_mail_str_34, false); - } - - if (strlen(msg->sender.email) > 0) - { - appendP(buf, esp_mail_str_150, false); - - if (strlen(msg->sender.name) > 0) - buf += msg->sender.name; - - appendP(buf, esp_mail_str_14, false); - buf += msg->sender.email; - appendP(buf, esp_mail_str_15, false); - appendP(buf, esp_mail_str_34, false); - } - - if (strlen(msg->response.reply_to) > 0) - { - appendP(buf, esp_mail_str_184, false); - appendP(buf, esp_mail_str_14, false); - buf += msg->response.reply_to; - appendP(buf, esp_mail_str_15, false); - appendP(buf, esp_mail_str_34, false); - } - - if (strlen(msg->response.return_path) > 0) - { - appendP(buf, esp_mail_str_46, false); - appendP(buf, esp_mail_str_14, false); - buf += msg->response.return_path; - appendP(buf, esp_mail_str_15, false); - appendP(buf, esp_mail_str_34, false); - } - - for (uint8_t i = 0; i < msg->_rcp.size(); i++) - { - if (i == 0) - { - appendP(buf, esp_mail_str_11, false); - if (strlen(msg->_rcp[i].name) > 0) - buf += msg->_rcp[i].name; - - appendP(buf, esp_mail_str_14, false); - buf += msg->_rcp[i].email; - appendP(buf, esp_mail_str_15, false); - } - else - { - if (strlen(msg->_rcp[i].name) > 0) - { - appendP(buf, esp_mail_str_263, false); - buf += msg->_rcp[i].name; - appendP(buf, esp_mail_str_14, false); - } - else - appendP(buf, esp_mail_str_13, false); - buf += msg->_rcp[i].email; - appendP(buf, esp_mail_str_15, false); - } - - if (i == msg->_rcp.size() - 1) - appendP(buf, esp_mail_str_34, false); - } - - for (uint8_t i = 0; i < msg->_cc.size(); i++) - { - if (i == 0) - { - appendP(buf, esp_mail_str_12, false); - appendP(buf, esp_mail_str_14, false); - buf += msg->_cc[i].email; - appendP(buf, esp_mail_str_15, false); - } - else - { - appendP(buf, esp_mail_str_13, false); - buf += msg->_cc[i].email; - appendP(buf, esp_mail_str_15, false); - } - - if (i == msg->_cc.size() - 1) - appendP(buf, esp_mail_str_34, false); - } - - for (uint8_t i = 0; i < msg->_bcc.size(); i++) - { - if (i == 0) - { - appendP(buf, esp_mail_str_149, false); - appendP(buf, esp_mail_str_14, false); - buf += msg->_bcc[i].email; - appendP(buf, esp_mail_str_15, false); - } - else - { - appendP(buf, esp_mail_str_13, false); - buf += msg->_bcc[i].email; - appendP(buf, esp_mail_str_15, false); - } - - if (i == msg->_bcc.size() - 1) - appendP(buf, esp_mail_str_34, false); - } - - if (strlen(msg->subject) > 0) - { - appendP(buf, esp_mail_str_279, false); - buf += msg->subject; - appendP(buf, esp_mail_str_34, false); - } - - if (strlen(msg->keyword) > 0) - { - appendP(buf, esp_mail_str_145, false); - buf += msg->keyword; - appendP(buf, esp_mail_str_34, false); - } - - if (strlen(msg->comment) > 0) - { - appendP(buf, esp_mail_str_134, false); - buf += msg->comment; - appendP(buf, esp_mail_str_34, false); - } - - if (strlen(msg->messageID) > 0) - { - appendP(buf, esp_mail_str_274, false); - appendP(buf, esp_mail_str_14, false); - buf += msg->messageID; - appendP(buf, esp_mail_str_15, false); - appendP(buf, esp_mail_str_34, false); - } -} - -bool ESP_Mail_Client::bdat(SMTPSession *smtp, SMTP_Message *msg, int len, bool last) -{ - if (!smtp->_chunkedEnable || !msg->enable.chunking) - return true; - - smtp->_chunkCount++; - - std::string bdat; - appendP(bdat, esp_mail_str_106, true); - char *tmp = intStr(len); - bdat += tmp; - if (last) - appendP(bdat, esp_mail_str_173, false); - delS(tmp); - if (smtpSend(smtp, bdat.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return setSendingResult(smtp, msg, false); - - if (!smtp->_send_capability.pipelining) - { - smtp->_smtp_cmd = esp_mail_smtp_command::esp_mail_smtp_cmd_send_body; - if (!handleSMTPResponse(smtp, esp_mail_smtp_status_code_250, SMTP_STATUS_SEND_BODY_FAILED)) - return setSendingResult(smtp, msg, false); - smtp->_chunkCount = 0; - } - return true; -} - -void ESP_Mail_Client::checkBinaryData(SMTPSession *smtp, SMTP_Message *msg) -{ - if (msg->type & esp_mail_msg_type_plain || msg->type == esp_mail_msg_type_enriched || msg->type & esp_mail_msg_type_html) - { - if ((msg->type & esp_mail_msg_type_plain || msg->type == esp_mail_msg_type_enriched) > 0) - { - if (strlen(msg->text.transfer_encoding) > 0) - { - if (strcmp(msg->text.transfer_encoding, Content_Transfer_Encoding::enc_binary) == 0) - { - msg->text._int.binary = true; - } - } - } - - if ((msg->type & esp_mail_msg_type_html) > 0) - { - if (strlen(msg->html.transfer_encoding) > 0) - { - if (strcmp(msg->html.transfer_encoding, Content_Transfer_Encoding::enc_binary) == 0) - { - msg->html._int.binary = true; - } - } - } - } - - for (size_t i = 0; i < msg->_att.size(); i++) - { - if (strcmpP(msg->_att[i].descr.transfer_encoding, 0, esp_mail_str_166)) - { - msg->_att[i]._int.binary = true; - } - } -} - -bool ESP_Mail_Client::sendBlob(SMTPSession *smtp, SMTP_Message *msg, SMTP_Attachment *att) -{ - if (strcmp(att->descr.transfer_encoding, Content_Transfer_Encoding::enc_base64) == 0 && strcmp(att->descr.transfer_encoding, att->descr.content_encoding) != 0) - { - if (!sendBase64(smtp, msg, (const unsigned char *)att->blob.data, att->blob.size, att->_int.flash_blob, att->descr.filename, smtp->_sendCallback != NULL)) - return false; - return true; - } - else - { - if (att->blob.size > 0) - { - size_t chunkSize = ESP_MAIL_CLIENT_STREAM_CHUNK_SIZE; - size_t writeLen = 0; - uint8_t *buf = new uint8_t[chunkSize]; - int pg = 0, _pg = 0; - while (writeLen < att->blob.size) - { - if (writeLen > att->blob.size - chunkSize) - chunkSize = att->blob.size - writeLen; - - if (!bdat(smtp, msg, chunkSize, false)) - break; - memcpy_P(buf, att->blob.data, chunkSize); - if (smtpSend(smtp, buf, chunkSize) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - break; - - if (smtp->_sendCallback) - { - pg = (float)(100.0f * writeLen / att->blob.size); - if (pg != _pg) - uploadReport(att->descr.filename, pg); - _pg = pg; - } - writeLen += chunkSize; - } - delete[] buf; - if (smtp->_sendCallback && _pg < 100) - uploadReport(att->descr.filename, 100); - - return writeLen >= att->blob.size; - } - } - return false; -} - -bool ESP_Mail_Client::sendFile(SMTPSession *smtp, SMTP_Message *msg, SMTP_Attachment *att, File &file) -{ - if (strcmp(att->descr.transfer_encoding, Content_Transfer_Encoding::enc_base64) == 0 && strcmp(att->descr.transfer_encoding, att->descr.content_encoding) != 0) - { - if (!sendBase64Stream(smtp, msg, file, att->descr.filename, smtp->_sendCallback != NULL)) - return false; - return true; - } - else - { - if (file.size() > 0) - { - size_t chunkSize = ESP_MAIL_CLIENT_STREAM_CHUNK_SIZE; - size_t writeLen = 0; - if (file.size() < chunkSize) - chunkSize = file.size(); - uint8_t *buf = new uint8_t[chunkSize]; - int pg = 0, _pg = 0; - while (writeLen < file.size() && file.available()) - { - if (writeLen > file.size() - chunkSize) - chunkSize = file.size() - writeLen; - size_t readLen = file.read(buf, chunkSize); - if (readLen != chunkSize) - { - errorStatusCB(smtp, MAIL_CLIENT_ERROR_FILE_IO_ERROR); - break; - } - - if (!bdat(smtp, msg, chunkSize, false)) - break; - - if (smtpSend(smtp, buf, chunkSize) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - break; - - if (smtp->_sendCallback) - { - pg = (float)(100.0f * writeLen / file.size()); - if (pg != _pg) - uploadReport(att->descr.filename, pg); - _pg = pg; - } - writeLen += chunkSize; - } - delete[] buf; - if (smtp->_sendCallback && _pg < 100) - uploadReport(att->descr.filename, 100); - return writeLen == file.size(); - } - return false; - } - return false; -} - -bool ESP_Mail_Client::sendParallelAttachments(SMTPSession *smtp, SMTP_Message *msg, const std::string &boundary) -{ - if (msg->_parallel.size() == 0) - return true; - - std::string buf; - std::string parallel = getBoundary(15); - appendP(buf, esp_mail_str_33, true); - buf += boundary; - appendP(buf, esp_mail_str_34, false); - - appendP(buf, esp_mail_str_28, false); - buf += parallel; - appendP(buf, esp_mail_str_35, false); - - if (!bdat(smtp, msg, buf.length(), false)) - return false; - - if (smtpSend(smtp, buf.c_str(), false) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return setSendingResult(smtp, msg, false); - - if (!sendAttachments(smtp, msg, parallel, true)) - return setSendingResult(smtp, msg, false); - - appendP(buf, esp_mail_str_33, true); - buf += parallel; - appendP(buf, esp_mail_str_33, false); - - if (!bdat(smtp, msg, buf.length(), false)) - return false; - - if (smtpSend(smtp, buf.c_str(), false) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return setSendingResult(smtp, msg, false); - - return true; -} - -bool ESP_Mail_Client::sendAttachments(SMTPSession *smtp, SMTP_Message *msg, const std::string &boundary, bool parallel) -{ - std::string s; - std::string buf; - int cnt = 0; - - SMTP_Attachment *att = nullptr; - - size_t sz = msg->_att.size(); - if (parallel) - sz = msg->_parallel.size(); - - for (size_t i = 0; i < sz; i++) - { - if (parallel) - att = &msg->_parallel[i]; - else - att = &msg->_att[i]; - - if (att->_int.att_type == esp_mail_att_type_attachment) - { - appendP(s, esp_mail_str_261, true); - s += att->descr.filename; - - if (smtp->_sendCallback) - { - if (cnt > 0) - smtpCB(smtp, ""); - smtpCB(smtp, att->descr.filename); - } - - if (smtp->_debug) - esp_mail_debug(s.c_str()); - - cnt++; - - if (att->file.storage_type == esp_mail_file_storage_type_none) - { - if (!att->blob.data) - continue; - - if (smtp->_sendCallback) - smtpCB(smtp, att->descr.filename); - - if (smtp->_debug) - esp_mail_debug(s.c_str()); - - buf.clear(); - getAttachHeader(buf, boundary, att, att->blob.size); - - if (!bdat(smtp, msg, buf.length(), false)) - return false; - - if (smtpSend(smtp, buf.c_str(), false) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return false; - - if (!sendBlob(smtp, msg, att)) - return false; - - if (!bdat(smtp, msg, 2, false)) - return false; - - if (smtpSendP(smtp, esp_mail_str_34, false) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return false; - } - else - { - - if (!_sdOk && att->file.storage_type == esp_mail_file_storage_type_sd) - _sdOk = sdTest(); - - if (!_flashOk && att->file.storage_type == esp_mail_file_storage_type_flash) -#if defined(ESP32) - _flashOk = ESP_MAIL_FLASH_FS.begin(FORMAT_FLASH); -#elif defined(ESP8266) - _flashOk = ESP_MAIL_FLASH_FS.begin(); -#endif - - if ((!_sdOk && att->file.storage_type == esp_mail_file_storage_type_sd) || (!_flashOk && att->file.storage_type == esp_mail_file_storage_type_flash)) - { - - if (smtp->_sendCallback) - debugInfoP(esp_mail_str_158); - - if (smtp->_debug) - { - std::string e; - appendP(e, esp_mail_str_185, true); - appendP(e, esp_mail_str_158, false); - esp_mail_debug(e.c_str()); - } - - continue; - } - - if (openFileRead(smtp, msg, att, file, s, buf, boundary, false)) - { - if (file) - { - - if (!sendFile(smtp, msg, att, file)) - return false; - - if (!bdat(smtp, msg, 2, false)) - return false; - - if (smtpSendP(smtp, esp_mail_str_34, false) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return false; - } - } - } - } - } - return true; -} - -bool ESP_Mail_Client::openFileRead(SMTPSession *smtp, SMTP_Message *msg, SMTP_Attachment *att, File &file, std::string &s, std::string &buf, const std::string &boundary, bool inlined) -{ - bool file_existed = false; - std::string filepath; - - if (strlen(att->file.path) > 0) - { - if (att->file.path[0] != '/') - appendP(filepath, esp_mail_str_202, true); - filepath += att->file.path; - } - - if (att->file.storage_type == esp_mail_file_storage_type_sd) { - file_existed = ESP_MAIL_SD_FS.exists(filepath.c_str()); - } else if (att->file.storage_type == esp_mail_file_storage_type_flash) { - file_existed = ESP_MAIL_FLASH_FS.exists(filepath.c_str()); - } else if (att->file.storage_type == esp_mail_file_storage_type_univ) { - file_existed = ufsp->exists(filepath.c_str()); - } - - if (!file_existed) - { - - if (strlen(att->descr.filename) > 0) - { - filepath.clear(); - if (att->descr.filename[0] != '/') - appendP(filepath, esp_mail_str_202, true); - filepath += att->descr.filename; - } - - if (att->file.storage_type == esp_mail_file_storage_type_sd) { - file_existed = ESP_MAIL_SD_FS.exists(filepath.c_str()); - } else if (att->file.storage_type == esp_mail_file_storage_type_flash) { - file_existed = ESP_MAIL_FLASH_FS.exists(filepath.c_str()); - } else if (att->file.storage_type == esp_mail_file_storage_type_univ) { - file_existed = ufsp->exists(filepath.c_str()); - } - } - - if (!file_existed) - { - if (smtp->_sendCallback) - debugInfoP(esp_mail_str_158); - - if (smtp->_debug) - { - std::string e; - appendP(e, esp_mail_str_185, true); - appendP(e, esp_mail_str_158, false); - esp_mail_debug(e.c_str()); - } - } - - if (file_existed) - { - - buf.clear(); - - if (att->file.storage_type == esp_mail_file_storage_type_sd) { - file = ESP_MAIL_SD_FS.open(filepath.c_str(), FILE_READ); - } else if (att->file.storage_type == esp_mail_file_storage_type_flash) { -#if defined(ESP32) - file = ESP_MAIL_FLASH_FS.open(filepath.c_str(), FILE_READ); -#elif defined(ESP8266) - file = ESP_MAIL_FLASH_FS.open(filepath.c_str(), "r"); -#endif - } else if (att->file.storage_type == esp_mail_file_storage_type_univ) { - file = ufsp->open(filepath.c_str(), "r"); - } - - if (!file) - return false; - - if (inlined) - getInlineHeader(buf, boundary, att, file.size()); - else - getAttachHeader(buf, boundary, att, file.size()); - - if (!bdat(smtp, msg, buf.length(), false)) - return false; - - if (smtpSend(smtp, buf.c_str(), false) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return false; - - return true; - } - - return false; -} - -bool ESP_Mail_Client::openFileRead2(SMTPSession *smtp, SMTP_Message *msg, File &file, const char *path, esp_mail_file_storage_type storageType) -{ - bool file_existed = false; - std::string filepath; - - if (strlen(path) > 0) - { - if (path[0] != '/') - appendP(filepath, esp_mail_str_202, true); - filepath += path; - } - - if (storageType == esp_mail_file_storage_type_sd) { - file_existed = ESP_MAIL_SD_FS.exists(filepath.c_str()); - } else if (storageType == esp_mail_file_storage_type_flash) { - file_existed = ESP_MAIL_FLASH_FS.exists(filepath.c_str()); - } else if (storageType == esp_mail_file_storage_type_univ) { - file_existed = ufsp->exists(filepath.c_str()); - } - - if (!file_existed) - { - if (smtp->_sendCallback) - debugInfoP(esp_mail_str_158); - - if (smtp->_debug) - { - std::string e; - appendP(e, esp_mail_str_185, true); - appendP(e, esp_mail_str_158, false); - esp_mail_debug(e.c_str()); - } - } - - if (file_existed) - { - if (storageType == esp_mail_file_storage_type_sd) - file = ESP_MAIL_SD_FS.open(filepath.c_str(), FILE_READ); - else if (storageType == esp_mail_file_storage_type_flash) -#if defined(ESP32) - file = ESP_MAIL_FLASH_FS.open(filepath.c_str(), FILE_READ); -#elif defined(ESP8266) - file = ESP_MAIL_FLASH_FS.open(filepath.c_str(), "r"); -#endif - return true; - } - - return false; -} - -bool ESP_Mail_Client::sendInline(SMTPSession *smtp, SMTP_Message *msg, const std::string &boundary, byte type) -{ - size_t num = numAtt(smtp, esp_mail_att_type_inline, msg) > 0; - - if (num > 0) - { - if (smtp->_sendCallback) - { - smtpCB(smtp, ""); - smtpCBP(smtp, esp_mail_str_167); - } - - if (smtp->_debug) - debugInfoP(esp_mail_str_271); - } - - std::string s; - std::string buf; - std::string related = getBoundary(15); - int cnt = 0; - SMTP_Attachment *att = nullptr; - - appendP(s, esp_mail_str_33, true); - s += boundary; - appendP(s, esp_mail_str_34, false); - - appendP(s, esp_mail_str_298, false); - s += related; - appendP(s, esp_mail_str_35, false); - - if (!bdat(smtp, msg, s.length(), false)) - return false; - - if (smtpSend(smtp, s.c_str()) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return false; - - if (!sendPartText(smtp, msg, type, related.c_str())) - return false; - - if (smtp->_sendCallback && numAtt(smtp, esp_mail_att_type_inline, msg) > 0) - esp_mail_debug(""); - - if (num > 0) - { - for (uint8_t i = 0; i < msg->_att.size(); i++) - { - att = &msg->_att[i]; - if (att->_int.att_type == esp_mail_att_type_inline) - { - appendP(s, esp_mail_str_261, true); - s += att->descr.filename; - - if (smtp->_sendCallback) - { - if (cnt > 0) - smtpCB(smtp, ""); - smtpCB(smtp, att->descr.filename); - } - - if (smtp->_debug) - esp_mail_debug(s.c_str()); - - cnt++; - - if (att->file.storage_type == esp_mail_file_storage_type_none) - { - if (!att->blob.data) - continue; - - if (smtp->_sendCallback) - smtpCB(smtp, att->descr.filename); - - if (smtp->_debug) - esp_mail_debug(s.c_str()); - - buf.clear(); - getInlineHeader(buf, related, att, att->blob.size); - - if (!bdat(smtp, msg, buf.length(), false)) - return false; - - if (smtpSend(smtp, buf.c_str(), false) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return false; - - if (!sendBlob(smtp, msg, att)) - return false; - - if (!bdat(smtp, msg, 2, false)) - return false; - - if (smtpSendP(smtp, esp_mail_str_34, false) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return false; - } - else - { - if (!_sdOk && att->file.storage_type == esp_mail_file_storage_type_sd) - _sdOk = sdTest(); - - if (!_flashOk && att->file.storage_type == esp_mail_file_storage_type_flash) -#if defined(ESP32) - _flashOk = ESP_MAIL_FLASH_FS.begin(FORMAT_FLASH); -#elif defined(ESP8266) - _flashOk = ESP_MAIL_FLASH_FS.begin(); -#endif - - if ((!_sdOk && att->file.storage_type == esp_mail_file_storage_type_sd) || (!_flashOk && att->file.storage_type == esp_mail_file_storage_type_flash)) - { - - if (smtp->_sendCallback) - debugInfoP(esp_mail_str_158); - - if (smtp->_debug) - { - std::string e; - appendP(e, esp_mail_str_185, true); - appendP(e, esp_mail_str_158, false); - esp_mail_debug(e.c_str()); - } - - continue; - } - - if (openFileRead(smtp, msg, att, file, s, buf, related, true)) - { - if (!file) - { - errorStatusCB(smtp, MAIL_CLIENT_ERROR_FILE_IO_ERROR); - return false; - } - - if (!sendFile(smtp, msg, att, file)) - return false; - - if (!bdat(smtp, msg, 2, false)) - return false; - - if (smtpSendP(smtp, esp_mail_str_34, false) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return false; - } - } - } - } - } - - appendP(s, esp_mail_str_34, true); - appendP(s, esp_mail_str_33, false); - s += related; - appendP(s, esp_mail_str_33, false); - appendP(s, esp_mail_str_34, false); - - if (!bdat(smtp, msg, s.length(), false)) - return false; - - if (smtpSend(smtp, s.c_str(), false) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return false; - - return true; -} - -void ESP_Mail_Client::errorStatusCB(SMTPSession *smtp, int error) -{ - smtp->_smtpStatus.statusCode = error; - std::string s; - - if (smtp->_sendCallback) - { - appendP(s, esp_mail_str_53, true); - s += smtp->errorReason().c_str(); - smtpCB(smtp, s.c_str(), false); - } - - if (smtp->_debug) - { - appendP(s, esp_mail_str_185, true); - s += smtp->errorReason().c_str(); - esp_mail_debug(s.c_str()); - } -} - -size_t ESP_Mail_Client::smtpSendP(SMTPSession *smtp, PGM_P v, bool newline) -{ - if (!reconnect(smtp)) - { - closeTCP(smtp); - return 0; - } - - if (!connected(smtp)) - { - errorStatusCB(smtp, MAIL_CLIENT_ERROR_CONNECTION_LOST); - return 0; - } - - if (!smtp->_tcpConnected) - { - errorStatusCB(smtp, MAIL_CLIENT_ERROR_SERVER_CONNECTION_FAILED); - return 0; - } - - char *tmp = strP(v); - size_t len = 0; - - if (newline) - { - if (smtp->_debugLevel > esp_mail_debug_level_2) - esp_mail_debug(tmp); - if (smtp->_sesson_cfg->secure.startTLS || !smtp->_secure) - len = smtp->httpClient._ns_println(tmp); - else - len = smtp->httpClient.stream()->println(tmp); - } - else - { - if (smtp->_debugLevel > esp_mail_debug_level_2) - esp_mail_debug_line(tmp, false); - - if (smtp->_sesson_cfg->secure.startTLS || !smtp->_secure) - len = smtp->httpClient._ns_print(tmp); - else - len = smtp->httpClient.stream()->print(tmp); - } - - if (len != strlen(tmp) && len != strlen(tmp) + 2) - { - errorStatusCB(smtp, MAIL_CLIENT_ERROR_SERVER_CONNECTION_FAILED); - len = 0; - } - - delS(tmp); - - return len; -} - -size_t ESP_Mail_Client::smtpSend(SMTPSession *smtp, const char *data, bool newline) -{ - if (!reconnect(smtp)) - { - closeTCP(smtp); - return 0; - } - - if (!connected(smtp)) - { - errorStatusCB(smtp, MAIL_CLIENT_ERROR_CONNECTION_LOST); - return 0; - } - - if (!smtp->_tcpConnected) - { - errorStatusCB(smtp, MAIL_CLIENT_ERROR_SERVER_CONNECTION_FAILED); - return 0; - } - - size_t len = 0; - - if (newline) - { - if (smtp->_debugLevel > esp_mail_debug_level_2) - esp_mail_debug(data); - - if (smtp->_sesson_cfg->secure.startTLS || !smtp->_secure) - len = smtp->httpClient._ns_println(data); - else - len = smtp->httpClient.stream()->println(data); - } - else - { - if (smtp->_debugLevel > esp_mail_debug_level_2) - esp_mail_debug_line(data, false); - - if (smtp->_sesson_cfg->secure.startTLS || !smtp->_secure) - len = smtp->httpClient._ns_print(data); - else - len = smtp->httpClient.stream()->print(data); - } - - if (len != strlen(data) && len != strlen(data) + 2) - { - errorStatusCB(smtp, MAIL_CLIENT_ERROR_SERVER_CONNECTION_FAILED); - len = 0; - } - - return len; -} - -size_t ESP_Mail_Client::smtpSend(SMTPSession *smtp, int data, bool newline) -{ - if (!reconnect(smtp)) - { - closeTCP(smtp); - return 0; - } - - if (!connected(smtp)) - { - errorStatusCB(smtp, MAIL_CLIENT_ERROR_CONNECTION_LOST); - return 0; - } - - if (!smtp->_tcpConnected) - { - errorStatusCB(smtp, MAIL_CLIENT_ERROR_SERVER_CONNECTION_FAILED); - return 0; - } - - char *tmp = intStr(data); - size_t len = 0; - - if (newline) - { - if (smtp->_debugLevel > esp_mail_debug_level_2) - esp_mail_debug(tmp); - - if (smtp->_sesson_cfg->secure.startTLS || !smtp->_secure) - len = smtp->httpClient._ns_println(tmp); - else - len = smtp->httpClient.stream()->println(tmp); - } - else - { - if (smtp->_debugLevel > esp_mail_debug_level_2) - esp_mail_debug_line(tmp, false); - - if (smtp->_sesson_cfg->secure.startTLS || !smtp->_secure) - len = smtp->httpClient._ns_print(tmp); - else - len = smtp->httpClient.stream()->print(tmp); - } - - if (len != strlen(tmp) && len != strlen(tmp) + 2) - { - errorStatusCB(smtp, MAIL_CLIENT_ERROR_SERVER_CONNECTION_FAILED); - len = 0; - } - - delS(tmp); - - return len; -} - -size_t ESP_Mail_Client::smtpSend(SMTPSession *smtp, uint8_t *data, size_t size) -{ - if (!reconnect(smtp)) - { - closeTCP(smtp); - return 0; - } - - if (!connected(smtp)) - { - errorStatusCB(smtp, MAIL_CLIENT_ERROR_CONNECTION_LOST); - return 0; - } - - if (!smtp->_tcpConnected) - { - errorStatusCB(smtp, MAIL_CLIENT_ERROR_SERVER_CONNECTION_FAILED); - return 0; - } - - size_t len = 0; - - if (smtp->_sesson_cfg->secure.startTLS || !smtp->_secure) - len = smtp->httpClient._stream()->write(data, size); - else - len = smtp->httpClient.stream()->write(data, size); - - if (len != size) - { - errorStatusCB(smtp, MAIL_CLIENT_ERROR_SERVER_CONNECTION_FAILED); - len = 0; - } - - return len; -} - -bool ESP_Mail_Client::handleSMTPError(SMTPSession *smtp, int err, bool ret) -{ - if (err < 0) - errorStatusCB(smtp, err); - - if (smtp->_tcpConnected) - closeTCP(smtp); - - return ret; -} - -void ESP_Mail_Client::debugInfoP(PGM_P info) -{ - char *tmp = strP(info); - esp_mail_debug(tmp); - delS(tmp); -} - -bool ESP_Mail_Client::sdBegin(uint8_t sck, uint8_t miso, uint8_t mosi, uint8_t ss) -{ - _sck = sck; - _miso = miso; - _mosi = mosi; - _ss = ss; - _sdConfigSet = true; -#if defined(ESP32) -#if defined(CARD_TYPE_SD) - SPI.begin(_sck, _miso, _mosi, _ss); - return ESP_MAIL_SD_FS.begin(_ss, SPI); -#endif -#elif defined(ESP8266) - return ESP_MAIL_SD_FS.begin(_ss); -#endif - return false; -} - -bool ESP_Mail_Client::sdBegin(void) -{ - _sdConfigSet = false; -#if defined(ESP32) - return ESP_MAIL_SD_FS.begin(); -#elif defined(ESP8266) - return ESP_MAIL_SD_FS.begin(SD_CS_PIN); -#endif - return false; -} - -bool ESP_Mail_Client::sdMMCBegin(const char *mountpoint, bool mode1bit, bool format_if_mount_failed) -{ -#if defined(ESP32) -#if defined(CARD_TYPE_SD_MMC) - _sdConfigSet = true; - sd_mmc_mountpoint = mountpoint; - sd_mmc_mode1bit = mode1bit; - sd_mmc_format_if_mount_failed = format_if_mount_failed; - return ESP_MAIL_SD_FS.begin(mountpoint, mode1bit, format_if_mount_failed); -#endif -#endif - return false; -} - -bool ESP_Mail_Client::sendPartText(SMTPSession *smtp, SMTP_Message *msg, uint8_t type, const char *boundary) -{ - std::string header; - - if (strlen(boundary) > 0) - { - appendP(header, esp_mail_str_33, false); - header += boundary; - appendP(header, esp_mail_str_34, false); - } - - if (type == esp_mail_msg_type_plain || type == esp_mail_msg_type_enriched) - { - if (strlen(msg->text.content_type) > 0) - { - appendP(header, esp_mail_str_25, false); - header += msg->text.content_type; - - if (strlen(msg->text.charSet) > 0) - { - appendP(header, esp_mail_str_97, false); - appendP(header, esp_mail_str_131, false); - appendP(header, esp_mail_str_168, false); - header += msg->text.charSet; - appendP(header, esp_mail_str_136, false); - } - - if (msg->text.flowed) - { - appendP(header, esp_mail_str_97, false); - appendP(header, esp_mail_str_131, false); - appendP(header, esp_mail_str_270, false); - - appendP(header, esp_mail_str_97, false); - appendP(header, esp_mail_str_131, false); - appendP(header, esp_mail_str_110, false); - } - - if (msg->text.embed.enable) - { - appendP(header, esp_mail_str_26, false); - appendP(header, esp_mail_str_164, false); - appendP(header, esp_mail_str_136, false); - char *tmp = getUID(); - msg->text._int.cid = tmp; - delS(tmp); - } - - appendP(header, esp_mail_str_34, false); - } - - if (strlen(msg->text.transfer_encoding) > 0) - { - appendP(header, esp_mail_str_272, false); - header += msg->text.transfer_encoding; - appendP(header, esp_mail_str_34, false); - } - } - else if (type == esp_mail_msg_type_html) - { - if (strlen(msg->text.content_type) > 0) - { - appendP(header, esp_mail_str_25, false); - header += msg->html.content_type; - - if (strlen(msg->html.charSet) > 0) - { - appendP(header, esp_mail_str_97, false); - appendP(header, esp_mail_str_131, false); - appendP(header, esp_mail_str_168, false); - header += msg->html.charSet; - appendP(header, esp_mail_str_136, false); - } - if (msg->html.embed.enable) - { - appendP(header, esp_mail_str_26, false); - appendP(header, esp_mail_str_159, false); - appendP(header, esp_mail_str_136, false); - char *tmp = getUID(); - msg->html._int.cid = tmp; - delS(tmp); - } - appendP(header, esp_mail_str_34, false); - } - - if (strlen(msg->html.transfer_encoding) > 0) - { - appendP(header, esp_mail_str_272, false); - header += msg->html.transfer_encoding; - appendP(header, esp_mail_str_34, false); - } - } - - if ((type == esp_mail_msg_type_html && msg->html.embed.enable) || ((type == esp_mail_msg_type_plain || type == esp_mail_msg_type_enriched) && msg->text.embed.enable)) - { - - if ((type == esp_mail_msg_type_plain || type == esp_mail_msg_type_enriched) && msg->text.embed.enable) - { - if (msg->text.embed.type == esp_mail_smtp_embed_message_type_attachment) - appendP(header, esp_mail_str_30, false); - else if (msg->text.embed.type == esp_mail_smtp_embed_message_type_inline) - appendP(header, esp_mail_str_299, false); - - if (strlen(msg->text.embed.filename) > 0) - header += msg->text.embed.filename; - else - appendP(header, esp_mail_str_164, false); - appendP(header, esp_mail_str_36, false); - - if (msg->text.embed.type == esp_mail_smtp_embed_message_type_inline) - { - appendP(header, esp_mail_str_300, false); - if (strlen(msg->text.embed.filename) > 0) - header += msg->text.embed.filename; - else - appendP(header, esp_mail_str_159, false); - appendP(header, esp_mail_str_34, false); - - appendP(header, esp_mail_str_301, false); - header += msg->text._int.cid; - appendP(header, esp_mail_str_15, false); - appendP(header, esp_mail_str_34, false); - } - } - else if (type == esp_mail_msg_type_html && msg->html.embed.enable) - { - if (msg->html.embed.type == esp_mail_smtp_embed_message_type_attachment) - appendP(header, esp_mail_str_30, false); - else if (msg->html.embed.type == esp_mail_smtp_embed_message_type_inline) - appendP(header, esp_mail_str_299, false); - - if (strlen(msg->html.embed.filename) > 0) - header += msg->html.embed.filename; - else - appendP(header, esp_mail_str_159, false); - appendP(header, esp_mail_str_36, false); - - if (msg->html.embed.type == esp_mail_smtp_embed_message_type_inline) - { - appendP(header, esp_mail_str_300, false); - if (strlen(msg->html.embed.filename) > 0) - header += msg->html.embed.filename; - else - appendP(header, esp_mail_str_159, false); - appendP(header, esp_mail_str_34, false); - - appendP(header, esp_mail_str_301, false); - header += msg->html._int.cid; - appendP(header, esp_mail_str_15, false); - appendP(header, esp_mail_str_34, false); - } - } - } - - appendP(header, esp_mail_str_34, false); - - if ((msg->text.blob.size > 0 && (type == esp_mail_msg_type_plain || type == esp_mail_msg_type_enriched)) || (msg->html.blob.size > 0 && type == esp_mail_msg_type_html)) - { - if (!bdat(smtp, msg, header.length(), false)) - return false; - - if (smtpSend(smtp, header.c_str()) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return false; - - header.clear(); - - if (!sendBlobBody(smtp, msg, type)) - return false; - } - else if ((strlen(msg->text.file.name) > 0 && (type == esp_mail_msg_type_plain || type == esp_mail_msg_type_enriched)) || (strlen(msg->html.file.name) > 0 && type == esp_mail_msg_type_html)) - { - if (!bdat(smtp, msg, header.length(), false)) - return false; - - if (smtpSend(smtp, header.c_str()) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return false; - - header.clear(); - - if (!sendFileBody(smtp, msg, type)) - return false; - } - else - encodingText(smtp, msg, type, header); - - appendP(header, esp_mail_str_34, false); - - if (strlen(boundary) > 0) - appendP(header, esp_mail_str_34, false); - - if (!bdat(smtp, msg, header.length(), false)) - return false; - - if (smtpSend(smtp, header.c_str()) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return false; - - return true; -} - -char *ESP_Mail_Client::getUID() -{ - char *tmp = new char[36]; - memset(tmp, 0, 36); - itoa(random(10000000, 20000000), tmp, 10); - return tmp; -} - -bool ESP_Mail_Client::sendBlobBody(SMTPSession *smtp, SMTP_Message *msg, uint8_t type) -{ - - if (msg->text.blob.size == 0 && msg->html.blob.size == 0) - return true; - - bool ret = true; - int bufLen = 512; - size_t pos = 0; - int pg = 0, _pg = 0; - - if (type == esp_mail_msg_type_plain || type == esp_mail_msg_type_enriched) - { - char *tmp = strP(esp_mail_str_325); - - if (strlen(msg->text.transfer_encoding) > 0) - { - if (strcmp(msg->text.transfer_encoding, Content_Transfer_Encoding::enc_base64) == 0) - { - ret = sendBase64(smtp, msg, (const unsigned char *)msg->text.blob.data, msg->text.blob.size, true, tmp, smtp->_sendCallback != NULL); - delS(tmp); - return ret; - } - } - - int len = msg->text.blob.size; - int available = len; - uint8_t *buf = new uint8_t[bufLen + 1]; - while (available) - { - if (available > bufLen) - available = bufLen; - - memcpy_P(buf, msg->text.blob.data + pos, available); - - if (!bdat(smtp, msg, available, false)) - break; - if (smtpSend(smtp, buf, available) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - break; - pos += available; - len -= available; - available = len; - if (smtp->_sendCallback) - { - pg = (float)(100.0f * pos / msg->text.blob.size); - if (pg != _pg) - uploadReport(tmp, pg); - _pg = pg; - } - } - delete[] buf; - delS(tmp); - } - else if (type == esp_mail_message_type::esp_mail_msg_type_html) - { - char *tmp = strP(esp_mail_str_325); - - if (strlen(msg->html.transfer_encoding) > 0) - { - if (strcmp(msg->html.transfer_encoding, Content_Transfer_Encoding::enc_base64) == 0) - { - ret = sendBase64(smtp, msg, (const unsigned char *)msg->html.blob.data, msg->html.blob.size, true, tmp, smtp->_sendCallback != NULL); - delS(tmp); - return ret; - } - } - int len = msg->html.blob.size; - int available = len; - uint8_t *buf = new uint8_t[bufLen + 1]; - while (available) - { - - if (available > bufLen) - available = bufLen; - - memcpy_P(buf, msg->html.blob.data + pos, available); - - if (!bdat(smtp, msg, available, false)) - { - ret = false; - break; - } - - if (smtpSend(smtp, buf, available) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - { - ret = false; - break; - } - pos += available; - len -= available; - available = len; - if (smtp->_sendCallback) - { - pg = (float)(100.0f * pos / msg->html.blob.size); - if (pg != _pg) - uploadReport(tmp, pg); - _pg = pg; - } - } - delete[] buf; - delS(tmp); - } - return ret; -} - -bool ESP_Mail_Client::sendFileBody(SMTPSession *smtp, SMTP_Message *msg, uint8_t type) -{ - - if (strlen(msg->text.file.name) == 0 && strlen(msg->html.file.name) == 0) - return true; - - bool ret = true; - size_t chunkSize = ESP_MAIL_CLIENT_STREAM_CHUNK_SIZE; - size_t writeLen = 0; - int pg = 0, _pg = 0; - - if (type == esp_mail_msg_type_plain || type == esp_mail_msg_type_enriched) - { - - if (!openFileRead2(smtp, msg, file, msg->text.file.name, msg->text.file.type)) - return false; - - char *tmp = strP(esp_mail_str_326); - - if (strlen(msg->text.transfer_encoding) > 0) - { - if (strcmp(msg->text.transfer_encoding, Content_Transfer_Encoding::enc_base64) == 0) - { - ret = sendBase64Stream(smtp, msg, file, tmp, smtp->_sendCallback != NULL); - delS(tmp); - return ret; - } - } - - if (file.size() > 0) - { - - if (file.size() < chunkSize) - chunkSize = file.size(); - uint8_t *buf = new uint8_t[chunkSize]; - while (writeLen < file.size() && file.available()) - { - if (writeLen > file.size() - chunkSize) - chunkSize = file.size() - writeLen; - size_t readLen = file.read(buf, chunkSize); - - if (readLen != chunkSize) - { - errorStatusCB(smtp, MAIL_CLIENT_ERROR_FILE_IO_ERROR); - break; - } - - if (!bdat(smtp, msg, chunkSize, false)) - { - ret = false; - break; - } - - if (smtpSend(smtp, buf, chunkSize) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - { - ret = false; - break; - } - - if (smtp->_sendCallback) - { - pg = (float)(100.0f * writeLen / file.size()); - if (pg != _pg) - uploadReport(tmp, pg); - _pg = pg; - } - writeLen += chunkSize; - } - delete[] buf; - if (smtp->_sendCallback && _pg < 100) - uploadReport(tmp, 100); - - delS(tmp); - return ret && writeLen == file.size(); - } - } - else if (type == esp_mail_message_type::esp_mail_msg_type_html) - { - - if (!openFileRead2(smtp, msg, file, msg->html.file.name, msg->html.file.type)) - return false; - - char *tmp = strP(esp_mail_str_326); - - if (strlen(msg->html.transfer_encoding) > 0) - { - if (strcmp(msg->html.transfer_encoding, Content_Transfer_Encoding::enc_base64) == 0) - { - ret = sendBase64Stream(smtp, msg, file, tmp, smtp->_sendCallback != NULL); - delS(tmp); - return ret; - } - } - - if (file.size() > 0) - { - - if (file.size() < chunkSize) - chunkSize = file.size(); - uint8_t *buf = new uint8_t[chunkSize]; - while (writeLen < file.size() && file.available()) - { - if (writeLen > file.size() - chunkSize) - chunkSize = file.size() - writeLen; - size_t readLen = file.read(buf, chunkSize); - - if (readLen != chunkSize) - { - errorStatusCB(smtp, MAIL_CLIENT_ERROR_FILE_IO_ERROR); - break; - } - - if (!bdat(smtp, msg, chunkSize, false)) - { - ret = false; - break; - } - - if (smtpSend(smtp, buf, chunkSize) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - { - ret = false; - break; - } - - if (smtp->_sendCallback) - { - pg = (float)(100.0f * writeLen / file.size()); - if (pg != _pg) - uploadReport(tmp, pg); - _pg = pg; - } - writeLen += chunkSize; - } - delete[] buf; - if (smtp->_sendCallback && _pg < 100) - uploadReport(tmp, 100); - - delS(tmp); - return ret && writeLen == file.size(); - } - } - - return false; -} - -void ESP_Mail_Client::encodingText(SMTPSession *smtp, SMTP_Message *msg, uint8_t type, std::string &content) -{ - if (type == esp_mail_msg_type_plain || type == esp_mail_msg_type_enriched) - { - std::string s = msg->text.content; - - if (msg->text.flowed) - formatFlowedText(s); - - if (strlen(msg->text.transfer_encoding) > 0) - { - if (strcmp(msg->text.transfer_encoding, Content_Transfer_Encoding::enc_base64) == 0) - content += encodeBase64Str((const unsigned char *)s.c_str(), s.length()); - else if (strcmp(msg->text.transfer_encoding, Content_Transfer_Encoding::enc_qp) == 0) - { - char *out = newS(s.length() * 3 + 1); - encodeQP(s.c_str(), out); - content += out; - delS(out); - } - else - content += s; - } - else - content += s; - } - else if (type == esp_mail_message_type::esp_mail_msg_type_html) - { - char *tmp = nullptr; - std::string s = msg->html.content; - std::string fnd, rep; - SMTP_Attachment *att = nullptr; - for (uint8_t i = 0; i < msg->_att.size(); i++) - { - att = &msg->_att[i]; - if (att->_int.att_type == esp_mail_att_type_inline) - { - std::string filename(att->descr.filename); - - size_t found = filename.find_last_of("/\\"); - if (found != std::string::npos) - filename = filename.substr(found + 1); - - appendP(fnd, esp_mail_str_136, true); - fnd += filename; - appendP(fnd, esp_mail_str_136, false); - - appendP(rep, esp_mail_str_136, true); - appendP(rep, esp_mail_str_302, false); - if (strlen(att->descr.content_id) > 0) - rep += att->descr.content_id; - else - rep += att->_int.cid; - appendP(rep, esp_mail_str_136, false); - - tmp = strReplace((char *)s.c_str(), (char *)fnd.c_str(), (char *)rep.c_str()); - s = tmp; - delS(tmp); - } - } - - if (strlen(msg->html.transfer_encoding) > 0) - { - if (strcmp(msg->html.transfer_encoding, Content_Transfer_Encoding::enc_base64) == 0) - content += encodeBase64Str((const unsigned char *)s.c_str(), s.length()); - else if (strcmp(msg->html.transfer_encoding, Content_Transfer_Encoding::enc_qp) == 0) - { - char *out = newS(strlen(msg->html.content) * 3 + 1); - encodeQP(msg->html.content, out); - content += out; - delS(out); - } - else - content += s; - } - else - content += s; - std::string().swap(s); - } -} - -/* Safe string splitter to avoid strsep bugs*/ -void ESP_Mail_Client::splitTk(std::string &str, std::vector &tk, const char *delim) -{ - std::size_t current, previous = 0; - current = str.find(delim, previous); - std::string s; - while (current != std::string::npos) - { - s = str.substr(previous, current - previous); - tk.push_back(s); - previous = current + strlen(delim); - current = str.find(delim, previous); - } - s = str.substr(previous, current - previous); - tk.push_back(s); - std::string().swap(s); -} - -/** Add the soft line break to the long text line (rfc 3676) - * and add Format=flowed parameter in the plain text content-type header. - * We use the existing white space as a part of this soft line break - * and set delSp="no" parameter to the header. - * - * Some servers are not rfc 3676 compliant. - * This causes the text lines are wrapped instead of joined. - * - * Some mail clients trim the space before the line break - * which makes the soft line break cannot be seen. -*/ -void ESP_Mail_Client::formatFlowedText(std::string &content) -{ - int count = 0; - std::string qms; - int j = 0; - std::vector tokens = std::vector(); - char *stk = strP(esp_mail_str_34); - char *qm = strP(esp_mail_str_15); - splitTk(content, tokens, stk); - content.clear(); - for (size_t i = 0; i < tokens.size(); i++) - { - if (tokens[i].length() > 0) - { - j = 0; - qms.clear(); - while (tokens[i][j] == qm[0]) - { - qms += qm; - j++; - } - softBreak(tokens[i], qms.c_str()); - if (count > 0) - content += stk; - content += tokens[i]; - } - else if (count > 0) - content += stk; - count++; - } - - delS(stk); - delS(qm); - tokens.clear(); -} - -void ESP_Mail_Client::softBreak(std::string &content, const char *quoteMarks) -{ - size_t len = 0; - char *stk = strP(esp_mail_str_131); - std::vector tokens = std::vector(); - splitTk(content, tokens, stk); - content.clear(); - for (size_t i = 0; i < tokens.size(); i++) - { - if (tokens[i].length() > 0) - { - if (len + tokens[i].length() + 3 > FLOWED_TEXT_LEN) - { - /* insert soft crlf */ - content += stk; - appendP(content, esp_mail_str_34, false); - - /* insert quote marks */ - if (strlen(quoteMarks) > 0) - content += quoteMarks; - content += tokens[i]; - len = tokens[i].length(); - } - else - { - if (len > 0) - { - content += stk; - len += strlen(stk); - } - content += tokens[i]; - len += tokens[i].length(); - } - } - } - delS(stk); - tokens.clear(); -} - -bool ESP_Mail_Client::sendMSG(SMTPSession *smtp, SMTP_Message *msg, const std::string &boundary) -{ - std::string alt = getBoundary(15); - std::string s; - - if (numAtt(smtp, esp_mail_att_type_inline, msg) > 0) - { - appendP(s, esp_mail_str_297, true); - s += alt; - appendP(s, esp_mail_str_35, false); - - if (!bdat(smtp, msg, s.length(), false)) - return false; - - if (smtpSend(smtp, s.c_str(), false) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return false; - - if (msg->type == esp_mail_msg_type_plain || msg->type == esp_mail_msg_type_enriched || msg->type == esp_mail_msg_type_html) - { - if (!sendInline(smtp, msg, alt, msg->type)) - return false; - } - else if (msg->type == (esp_mail_msg_type_html | esp_mail_msg_type_enriched | esp_mail_msg_type_plain)) - { - if (!sendPartText(smtp, msg, esp_mail_msg_type_plain, alt.c_str())) - return false; - if (!sendInline(smtp, msg, alt, esp_mail_msg_type_html)) - return false; - } - - appendP(s, esp_mail_str_33, true); - s += alt; - appendP(s, esp_mail_str_33, false); - appendP(s, esp_mail_str_34, false); - - if (!bdat(smtp, msg, s.length(), false)) - return false; - - if (smtpSend(smtp, s.c_str(), false) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return false; - } - else - { - if (msg->type == esp_mail_msg_type_plain || msg->type == esp_mail_msg_type_enriched || msg->type == esp_mail_msg_type_html) - { - if (!sendPartText(smtp, msg, msg->type, "")) - return false; - } - else if (msg->type == (esp_mail_msg_type_html | esp_mail_msg_type_enriched | esp_mail_msg_type_plain)) - { - appendP(s, esp_mail_str_33, true); - s += boundary; - appendP(s, esp_mail_str_34, false); - appendP(s, esp_mail_str_297, false); - s += alt; - appendP(s, esp_mail_str_35, false); - - if (!bdat(smtp, msg, s.length(), false)) - return false; - - if (smtpSend(smtp, s.c_str(), false) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return false; - - if (!sendPartText(smtp, msg, esp_mail_msg_type_plain, alt.c_str())) - return false; - - if (!sendPartText(smtp, msg, esp_mail_msg_type_html, alt.c_str())) - return false; - } - } - return true; -} - -void ESP_Mail_Client::getInlineHeader(std::string &header, const std::string &boundary, SMTP_Attachment *inlineAttach, size_t size) -{ - appendP(header, esp_mail_str_33, false); - header += boundary; - appendP(header, esp_mail_str_34, false); - - appendP(header, esp_mail_str_25, false); - - if (strlen(inlineAttach->descr.mime) == 0) - { - std::string mime; - mimeFromFile(inlineAttach->descr.filename, mime); - if (mime.length() > 0) - header += mime; - else - appendP(header, esp_mail_str_32, false); - } - else - header += inlineAttach->descr.mime; - - appendP(header, esp_mail_str_26, false); - - std::string filename = inlineAttach->descr.filename; - - size_t found = filename.find_last_of("/\\"); - - if (found != std::string::npos) - filename = filename.substr(found + 1); - - header += filename; - appendP(header, esp_mail_str_36, false); - - appendP(header, esp_mail_str_299, false); - header += filename; - appendP(header, esp_mail_str_327, false); - char *tmp = intStr(size); - header += tmp; - delS(tmp); - appendP(header, esp_mail_str_34, false); - - appendP(header, esp_mail_str_300, false); - header += filename; - appendP(header, esp_mail_str_34, false); - - appendP(header, esp_mail_str_301, false); - if (strlen(inlineAttach->descr.content_id) > 0) - header += inlineAttach->descr.content_id; - else - header += inlineAttach->_int.cid; - - appendP(header, esp_mail_str_15, false); - - appendP(header, esp_mail_str_34, false); - - if (strlen(inlineAttach->descr.transfer_encoding) > 0) - { - appendP(header, esp_mail_str_272, false); - header += inlineAttach->descr.transfer_encoding; - appendP(header, esp_mail_str_34, false); - } - appendP(header, esp_mail_str_34, false); - - std::string().swap(filename); -} - -void ESP_Mail_Client::getAttachHeader(std::string &header, const std::string &boundary, SMTP_Attachment *attach, size_t size) -{ - appendP(header, esp_mail_str_33, false); - header += boundary; - appendP(header, esp_mail_str_34, false); - - appendP(header, esp_mail_str_25, false); - - if (strlen(attach->descr.mime) == 0) - { - std::string mime; - mimeFromFile(attach->descr.filename, mime); - if (mime.length() > 0) - header += mime; - else - appendP(header, esp_mail_str_32, false); - } - else - header += attach->descr.mime; - - appendP(header, esp_mail_str_26, false); - - std::string filename = attach->descr.filename; - - size_t found = filename.find_last_of("/\\"); - if (found != std::string::npos) - filename = filename.substr(found + 1); - - header += filename; - appendP(header, esp_mail_str_36, false); - - if (!attach->_int.parallel) - { - appendP(header, esp_mail_str_30, false); - header += filename; - appendP(header, esp_mail_str_327, false); - char *tmp = intStr(size); - header += tmp; - delS(tmp); - appendP(header, esp_mail_str_34, false); - } - - if (strlen(attach->descr.transfer_encoding) > 0) - { - appendP(header, esp_mail_str_272, false); - header += attach->descr.transfer_encoding; - appendP(header, esp_mail_str_34, false); - } - - appendP(header, esp_mail_str_34, false); - - std::string().swap(filename); -} - -void ESP_Mail_Client::getRFC822PartHeader(SMTPSession *smtp, std::string &header, const std::string &boundary) -{ - appendP(header, esp_mail_str_33, false); - header += boundary; - appendP(header, esp_mail_str_34, false); - - appendP(header, esp_mail_str_25, false); - - appendP(header, esp_mail_str_123, false); - appendP(header, esp_mail_str_34, false); - - appendP(header, esp_mail_str_98, false); - - appendP(header, esp_mail_str_34, false); -} - -void ESP_Mail_Client::smtpCBP(SMTPSession *smtp, PGM_P info, bool success) -{ - std::string s; - appendP(s, info, true); - smtp->_cbData._info = s; - smtp->_cbData._success = success; - smtp->_sendCallback(smtp->_cbData); - std::string().swap(s); -} - -void ESP_Mail_Client::smtpCB(SMTPSession *smtp, const char *info, bool success) -{ - smtp->_cbData._info = info; - smtp->_cbData._success = success; - smtp->_sendCallback(smtp->_cbData); -} - -void ESP_Mail_Client::imapCBP(IMAPSession *imap, PGM_P info, bool success) -{ - char *tmp = strP(info); - imap->_cbData._info = tmp; - imap->_cbData._success = success; - imap->_readCallback(imap->_cbData); - delS(tmp); -} - -void ESP_Mail_Client::imapCB(IMAPSession *imap, const char *info, bool success) -{ - imap->_cbData._info = info; - imap->_cbData._success = success; - imap->_readCallback(imap->_cbData); -} - -void ESP_Mail_Client::strcat_c(char *str, char c) -{ - for (; *str; str++) - ; - *str++ = c; - *str++ = 0; -} -int ESP_Mail_Client::strpos(const char *haystack, const char *needle, int offset) -{ - size_t len = strlen(haystack); - size_t len2 = strlen(needle); - if (len == 0 || len < len2 || len2 == 0 || offset >= (int)len || offset < 0) - return -1; - char *_haystack = newS(len - offset + 1); - _haystack[len - offset] = 0; - strncpy(_haystack, haystack + offset, len - offset); - char *p = stristr(_haystack, needle); - int r = -1; - if (p) - r = p - _haystack + offset; - delS(_haystack); - return r; -} - -char *ESP_Mail_Client::stristr(const char *str1, const char *str2) -{ - const char *p1 = str1; - const char *p2 = str2; - const char *r = *p2 == 0 ? str1 : 0; - - while (*p1 != 0 && *p2 != 0) - { - if (tolower((unsigned char)*p1) == tolower((unsigned char)*p2)) - { - if (r == 0) - r = p1; - p2++; - } - else - { - p2 = str2; - if (r != 0) - p1 = r + 1; - - if (tolower((unsigned char)*p1) == tolower((unsigned char)*p2)) - { - r = p1; - p2++; - } - else - r = 0; - } - - p1++; - } - - return *p2 == 0 ? (char *)r : 0; -} - -char *ESP_Mail_Client::rstrstr(const char *haystack, const char *needle) -{ - size_t needle_length = strlen(needle); - const char *haystack_end = haystack + strlen(haystack) - needle_length; - const char *p; - size_t i; - for (p = haystack_end; p >= haystack; --p) - { - for (i = 0; i < needle_length; ++i) - { - if (p[i] != needle[i]) - goto next; - } - return (char *)p; - next:; - } - return 0; -} - -int ESP_Mail_Client::rstrpos(const char *haystack, const char *needle, int offset) -{ - size_t len = strlen(haystack); - size_t len2 = strlen(needle); - if (len == 0 || len < len2 || len2 == 0 || offset >= (int)len) - return -1; - char *_haystack = newS(len - offset + 1); - _haystack[len - offset] = 0; - strncpy(_haystack, haystack + offset, len - offset); - char *p = rstrstr(_haystack, needle); - int r = -1; - if (p) - r = p - _haystack + offset; - delS(_haystack); - return r; -} - -int ESP_Mail_Client::readLine(WiFiClient *stream, char *buf, int bufLen, bool crlf, int &count) -{ - int ret = -1; - char c = 0; - char _c = 0; - int idx = 0; - if (!stream) - return idx; - while (stream->available() && idx < bufLen) - { - ret = stream->read(); - if (ret > -1) - { - if (idx >= bufLen - 1) - return idx; - - c = (char)ret; - strcat_c(buf, c); - idx++; - count++; - if (_c == '\r' && c == '\n') - { - if (!crlf) - { - buf[idx - 2] = 0; - idx -= 2; - } - return idx; - } - _c = c; - } - if (!stream) - return idx; - } - return idx; -} - -#if defined(ESP32) -int ESP_Mail_Client::_readLine(ESP_Mail_WCS32 *stream, char *buf, int bufLen, bool crlf, int &count) -#elif defined(ESP8266) -int ESP_Mail_Client::_readLine(ESP_Mail::ESP_Mail_WCS *stream, char *buf, int bufLen, bool crlf, int &count) -#endif -{ - int ret = -1; - char c = 0; - char _c = 0; - int idx = 0; - if (!stream) - return idx; - while (stream->_ns_available() && idx < bufLen) - { - ret = stream->_ns_read(); - if (ret > -1) - { - if (idx >= bufLen - 1) - return idx; - - c = (char)ret; - strcat_c(buf, c); - idx++; - count++; - if (_c == '\r' && c == '\n') - { - if (!crlf) - { - buf[idx - 2] = 0; - idx -= 2; - } - return idx; - } - _c = c; - } - if (!stream) - return idx; - } - return idx; -} - -int ESP_Mail_Client::getMSGNUM(IMAPSession *imap, char *buf, int bufLen, int &chunkIdx, bool &endSearch, int &nump, const char *key, const char *pc) -{ - int ret = -1; - char c = 0; - int idx = 0; - int num = 0; - while (available(imap) > 0 && idx < bufLen) - { - delay(0); - if (!imap->_secure) - ret = imap->httpClient._stream()->read(); - else - ret = imap->httpClient.stream()->read(); - - if (ret > -1) - { - - if (idx >= bufLen - 1) - return idx; - - c = (char)ret; - - if (c == '\n') - c = ' '; - - strcat_c(buf, c); - idx++; - - if (chunkIdx == 0) - { - if (strcmp(buf, key) == 0) - { - chunkIdx++; - return 0; - } - - if (strposP(buf, esp_mail_imap_response_1, 0) > -1) - goto end_search; - } - else - { - if (c == ' ') - { - imap->_mbif._searchCount++; - if (imap->_config->enable.recent_sort) - { - imap->_msgNum.push_back(atoi(buf)); - if (imap->_msgNum.size() > imap->_config->limit.search) - imap->_msgNum.erase(imap->_msgNum.begin()); - } - else - { - if (imap->_msgNum.size() < imap->_config->limit.search) - imap->_msgNum.push_back(atoi(buf)); - } - - if (imap->_debug) - { - num = (float)(100.0f * imap->_mbif._searchCount / imap->_mbif._msgCount); - if (nump != num) - { - nump = num; - searchReport(num, pc); - } - } - - chunkIdx++; - return idx; - } - else if (c == '$') - { - if (imap->_config->enable.recent_sort) - std::sort(imap->_msgNum.begin(), imap->_msgNum.end(), compFunc); - - goto end_search; - } - } - } - } - - return idx; - -end_search: - - endSearch = true; - int read = available(imap); - - if (!imap->_secure) - idx = imap->httpClient._stream()->readBytes(buf + idx, read); - else - idx = imap->httpClient.stream()->readBytes(buf + idx, read); - - return idx; -} - -struct esp_mail_message_part_info_t *ESP_Mail_Client::cPart(IMAPSession *imap) -{ - return &cHeader(imap)->part_headers[imap->_cPartIdx]; -} - -struct esp_mail_message_header_t *ESP_Mail_Client::cHeader(IMAPSession *imap) -{ - return &imap->_headers[cIdx(imap)]; -} - -void ESP_Mail_Client::handleHeader(IMAPSession *imap, char *buf, int bufLen, int &chunkIdx, struct esp_mail_message_header_t &header, int &headerState, int &octetCount) -{ - - char *tmp = nullptr; - if (chunkIdx == 0) - { - if (strposP(buf, esp_mail_str_324, 0) != -1 && buf[0] == '*') - chunkIdx++; - - tmp = subStr(buf, esp_mail_str_193, esp_mail_str_194, 0); - if (tmp) - { - octetCount = 2; - header.header_data_len = atoi(tmp); - delS(tmp); - } - } - else - { - if (octetCount > header.header_data_len + 2) - return; - - if (strcmpP(buf, 0, esp_mail_str_10)) - { - headerState = esp_mail_imap_header_state::esp_mail_imap_state_from; - tmp = subStr(buf, esp_mail_str_10, NULL, 0, -1); - setHeader(imap, tmp, header, headerState); - delS(tmp); - } - else if (strcmpP(buf, 0, esp_mail_str_11)) - { - headerState = esp_mail_imap_header_state::esp_mail_imap_state_to; - tmp = subStr(buf, esp_mail_str_11, NULL, 0, -1); - setHeader(imap, tmp, header, headerState); - delS(tmp); - } - else if (strcmpP(buf, 0, esp_mail_str_276)) - { - headerState = esp_mail_imap_header_state::esp_mail_imap_state_cc; - tmp = subStr(buf, esp_mail_str_276, NULL, 0, -1); - setHeader(imap, tmp, header, headerState); - delS(tmp); - } - else if (strcmpP(buf, 0, esp_mail_str_279)) - { - headerState = esp_mail_imap_header_state::esp_mail_imap_state_subject; - tmp = subStr(buf, esp_mail_str_279, NULL, 0, -1); - setHeader(imap, tmp, header, headerState); - delS(tmp); - } - else if (strcmpP(buf, 0, esp_mail_str_25)) - { - headerState = esp_mail_imap_header_state::esp_mail_imap_state_content_type; - tmp = subStr(buf, esp_mail_str_25, esp_mail_str_97, 0); - if (tmp) - { - setHeader(imap, buf, header, headerState); - delS(tmp); - } - } - else if (strcmpP(buf, 0, esp_mail_str_172)) - { - headerState = esp_mail_imap_header_state::esp_mail_imap_state_content_transfer_encoding; - tmp = subStr(buf, esp_mail_str_172, NULL, 0, -1); - if (tmp) - { - setHeader(imap, tmp, header, headerState); - delS(tmp); - } - } - else if (strcmpP(buf, 0, esp_mail_str_190)) - { - headerState = esp_mail_imap_header_state::esp_mail_imap_state_accept_language; - tmp = subStr(buf, esp_mail_str_190, NULL, 0, -1); - if (tmp) - { - setHeader(imap, tmp, header, headerState); - delS(tmp); - } - } - else if (strcmpP(buf, 0, esp_mail_str_191)) - { - headerState = esp_mail_imap_header_state::esp_mail_imap_state_content_language; - tmp = subStr(buf, esp_mail_str_191, NULL, 0, -1); - if (tmp) - { - setHeader(imap, tmp, header, headerState); - delS(tmp); - } - } - else if (strcmpP(buf, 0, esp_mail_str_273)) - { - headerState = esp_mail_imap_header_state::esp_mail_imap_state_date; - tmp = subStr(buf, esp_mail_str_273, NULL, 0, -1); - if (tmp) - { - setHeader(imap, tmp, header, headerState); - delS(tmp); - } - } - else if (strcmpP(buf, 0, esp_mail_str_274)) - { - headerState = esp_mail_imap_header_state::esp_mail_imap_state_msg_id; - tmp = subStr(buf, esp_mail_str_274, NULL, 0, -1); - if (tmp) - { - setHeader(imap, tmp, header, headerState); - delS(tmp); - } - } - chunkIdx++; - } -} - -void ESP_Mail_Client::setHeader(IMAPSession *imap, char *buf, struct esp_mail_message_header_t &header, int state) -{ - switch (state) - { - case esp_mail_imap_header_state::esp_mail_imap_state_from: - header.from += buf; - break; - case esp_mail_imap_header_state::esp_mail_imap_state_to: - header.to += buf; - break; - case esp_mail_imap_header_state::esp_mail_imap_state_cc: - header.cc += buf; - break; - case esp_mail_imap_header_state::esp_mail_imap_state_subject: - header.subject += buf; - break; - case esp_mail_imap_header_state::esp_mail_imap_state_content_type: - header.content_type += buf; - break; - case esp_mail_imap_header_state::esp_mail_imap_state_content_transfer_encoding: - header.content_transfer_encoding += buf; - break; - case esp_mail_imap_header_state::esp_mail_imap_state_accept_language: - header.accept_language += buf; - break; - case esp_mail_imap_header_state::esp_mail_imap_state_content_language: - header.content_language += buf; - break; - case esp_mail_imap_header_state::esp_mail_imap_state_date: - header.date += buf; - break; - case esp_mail_imap_header_state::esp_mail_imap_state_msg_id: - header.message_id += buf; - break; - case esp_mail_imap_header_state::esp_mail_imap_state_char_set: - header.char_set += buf; - break; - case esp_mail_imap_header_state::esp_mail_imap_state_boundary: - header.boundary += buf; - break; - default: - break; - } -} - -void ESP_Mail_Client::handlePartHeader(IMAPSession *imap, char *buf, int &chunkIdx, struct esp_mail_message_part_info_t &part) -{ - char *tmp = nullptr; - if (chunkIdx == 0) - { - tmp = subStr(buf, esp_mail_imap_response_7, NULL, 0, -1); - if (tmp) - { - delS(tmp); - tmp = subStr(buf, esp_mail_str_193, esp_mail_str_194, 0); - if (tmp) - { - chunkIdx++; - part.octetLen = atoi(tmp); - delS(tmp); - } - } - } - else - { - if (strcmpP(buf, 0, esp_mail_str_25)) - { - tmp = subStr(buf, esp_mail_str_25, esp_mail_str_97, 0); - bool con_type = false; - if (tmp) - { - con_type = true; - part.content_type = tmp; - delS(tmp); - int p1 = strposP(part.content_type.c_str(), esp_mail_imap_composite_media_type_t::multipart, 0); - if (p1 != -1) - { - p1 += strlen(esp_mail_imap_composite_media_type_t::multipart) + 1; - part.multipart = true; - //inline or embedded images - if (strpos(part.content_type.c_str(), esp_mail_imap_multipart_sub_type_t::related, p1) != -1) - part.multipart_sub_type = esp_mail_imap_multipart_sub_type_related; - //multiple text formats e.g. plain, html, enriched - else if (strpos(part.content_type.c_str(), esp_mail_imap_multipart_sub_type_t::alternative, p1) != -1) - part.multipart_sub_type = esp_mail_imap_multipart_sub_type_alternative; - //medias - else if (strpos(part.content_type.c_str(), esp_mail_imap_multipart_sub_type_t::parallel, p1) != -1) - part.multipart_sub_type = esp_mail_imap_multipart_sub_type_parallel; - //rfc822 encapsulated - else if (strpos(part.content_type.c_str(), esp_mail_imap_multipart_sub_type_t::digest, p1) != -1) - part.multipart_sub_type = esp_mail_imap_multipart_sub_type_digest; - else if (strpos(part.content_type.c_str(), esp_mail_imap_multipart_sub_type_t::report, p1) != -1) - part.multipart_sub_type = esp_mail_imap_multipart_sub_type_report; - //others can be attachments - else if (strpos(part.content_type.c_str(), esp_mail_imap_multipart_sub_type_t::mixed, p1) != -1) - part.multipart_sub_type = esp_mail_imap_multipart_sub_type_mixed; - } - - p1 = strposP(part.content_type.c_str(), esp_mail_imap_composite_media_type_t::message, 0); - if (p1 != -1) - { - p1 += strlen(esp_mail_imap_composite_media_type_t::message) + 1; - if (strpos(part.content_type.c_str(), esp_mail_imap_message_sub_type_t::rfc822, p1) != -1) - part.message_sub_type = esp_mail_imap_message_sub_type_rfc822; - else if (strpos(part.content_type.c_str(), esp_mail_imap_message_sub_type_t::Partial, p1) != -1) - part.message_sub_type = esp_mail_imap_message_sub_type_partial; - else if (strpos(part.content_type.c_str(), esp_mail_imap_message_sub_type_t::External_Body, p1) != -1) - part.message_sub_type = esp_mail_imap_message_sub_type_external_body; - else if (strpos(part.content_type.c_str(), esp_mail_imap_message_sub_type_t::delivery_status, p1) != -1) - part.message_sub_type = esp_mail_imap_message_sub_type_delivery_status; - } - - p1 = strpos(part.content_type.c_str(), esp_mail_imap_descrete_media_type_t::text, 0); - if (p1 != -1) - { - p1 += strlen(esp_mail_imap_descrete_media_type_t::text) + 1; - if (strpos(part.content_type.c_str(), esp_mail_imap_media_text_sub_type_t::plain, p1) != -1) - part.msg_type = esp_mail_msg_type_plain; - else if (strpos(part.content_type.c_str(), esp_mail_imap_media_text_sub_type_t::enriched, p1) != -1) - part.msg_type = esp_mail_msg_type_enriched; - else if (strpos(part.content_type.c_str(), esp_mail_imap_media_text_sub_type_t::html, p1) != -1) - part.msg_type = esp_mail_msg_type_html; - else - part.msg_type = esp_mail_msg_type_plain; - } - } - - if (con_type) - { - if (part.msg_type == esp_mail_msg_type_plain || part.msg_type == esp_mail_msg_type_enriched) - { - tmp = subStr(buf, esp_mail_str_168, esp_mail_str_136, 0); - if (tmp) - { - part.charset = tmp; - delS(tmp); - } - else - { - tmp = subStr(buf, esp_mail_str_169, NULL, 0, -1); - if (tmp) - { - part.charset = tmp; - delS(tmp); - } - } - - if (strposP(buf, esp_mail_str_275, 0) > -1 || strposP(buf, esp_mail_str_270, 0) > -1) - part.plain_flowed = true; - if (strposP(buf, esp_mail_str_259, 0) > -1 || strposP(buf, esp_mail_str_257, 0) > -1) - part.plain_delsp = true; - } - - if (part.charset.length() == 0) - { - tmp = subStr(buf, esp_mail_str_168, esp_mail_str_136, 0); - if (tmp) - { - part.charset = tmp; - delS(tmp); - } - else - { - tmp = subStr(buf, esp_mail_str_169, NULL, 0, -1); - if (tmp) - { - part.charset = tmp; - delS(tmp); - } - } - } - - tmp = subStr(buf, esp_mail_str_170, esp_mail_str_136, 0); - if (tmp) - { - part.name = tmp; - delS(tmp); - } - else - { - tmp = subStr(buf, esp_mail_str_171, NULL, 0, -1); - if (tmp) - { - part.name = tmp; - delS(tmp); - } - } - } - } - else if (strcmpP(buf, 0, esp_mail_str_172)) - { - tmp = subStr(buf, esp_mail_str_172, NULL, 0, -1); - if (tmp) - { - part.content_transfer_encoding = tmp; - delS(tmp); - } - } - else if (strcmpP(buf, 0, esp_mail_str_174)) - { - tmp = subStr(buf, esp_mail_str_174, NULL, 0, -1); - if (tmp) - { - part.descr = tmp; - delS(tmp); - } - } - else if (strcmpP(buf, 0, esp_mail_str_175)) - { - tmp = subStr(buf, esp_mail_str_175, esp_mail_str_97, 0); - if (tmp) - { - //don't count altenative part text and html as embedded contents - if (cHeader(imap)->multipart_sub_type != esp_mail_imap_multipart_sub_type_alternative) - { - part.content_disposition = tmp; - if (strcmp(tmp, esp_mail_imap_content_disposition_type_t::attachment) == 0) - part.attach_type = esp_mail_att_type_attachment; - else if (strcmp(tmp, esp_mail_imap_content_disposition_type_t::inline_) == 0) - part.attach_type = esp_mail_att_type_inline; - } - delS(tmp); - } - } - else if (strcmpP(buf, 0, esp_mail_str_150)) - { - tmp = subStr(buf, esp_mail_str_150, NULL, 0, -1); - if (tmp) - { - part.rfc822_header.sender = tmp; - delS(tmp); - } - } - else if (strcmpP(buf, 0, esp_mail_str_10)) - { - tmp = subStr(buf, esp_mail_str_10, NULL, 0, -1); - if (tmp) - { - part.rfc822_header.from = tmp; - delS(tmp); - } - } - else if (strcmpP(buf, 0, esp_mail_str_11)) - { - tmp = subStr(buf, esp_mail_str_11, NULL, 0, -1); - if (tmp) - { - part.rfc822_header.to = tmp; - delS(tmp); - } - } - else if (strcmpP(buf, 0, esp_mail_str_12)) - { - tmp = subStr(buf, esp_mail_str_12, NULL, 0, -1); - if (tmp) - { - part.rfc822_header.cc = tmp; - delS(tmp); - } - } - else if (strcmpP(buf, 0, esp_mail_str_184)) - { - tmp = subStr(buf, esp_mail_str_184, NULL, 0, -1); - if (tmp) - { - part.rfc822_header.reply_to = tmp; - delS(tmp); - } - } - else if (strcmpP(buf, 0, esp_mail_str_134)) - { - tmp = subStr(buf, esp_mail_str_134, NULL, 0, -1); - if (tmp) - { - part.rfc822_header.comment = tmp; - delS(tmp); - } - } - else if (strcmpP(buf, 0, esp_mail_str_24)) - { - tmp = subStr(buf, esp_mail_str_24, NULL, 0, -1); - if (tmp) - { - part.rfc822_header.subject = tmp; - delS(tmp); - } - } - else if (strcmpP(buf, 0, esp_mail_str_189)) - { - tmp = subStr(buf, esp_mail_str_189, NULL, 0, -1); - if (tmp) - { - part.rfc822_header.messageID = tmp; - delS(tmp); - } - } - else if (strcmpP(buf, 0, esp_mail_str_46)) - { - tmp = subStr(buf, esp_mail_str_46, NULL, 0, -1); - if (tmp) - { - part.rfc822_header.return_path = tmp; - delS(tmp); - } - } - else if (strcmpP(buf, 0, esp_mail_str_99)) - { - tmp = subStr(buf, esp_mail_str_99, NULL, 0, -1); - if (tmp) - { - part.rfc822_header.date = tmp; - delS(tmp); - } - } - else if (strcmpP(buf, 0, esp_mail_str_145)) - { - tmp = subStr(buf, esp_mail_str_145, NULL, 0, -1); - if (tmp) - { - part.rfc822_header.keyword = tmp; - delS(tmp); - } - } - - if (part.content_disposition.length() > 0) - { - tmp = subStr(buf, esp_mail_str_176, esp_mail_str_136, 0); - if (tmp) - { - part.filename = tmp; - delS(tmp); - } - else - { - tmp = subStr(buf, esp_mail_str_177, NULL, 0, -1); - if (tmp) - { - part.filename = tmp; - delS(tmp); - } - } - - tmp = subStr(buf, esp_mail_str_178, esp_mail_str_97, 0); - if (tmp) - { - part.attach_data_size = atoi(tmp); - delS(tmp); - cHeader(imap)->total_attach_data_size += part.attach_data_size; - part.sizeProp = true; - } - else - { - tmp = subStr(buf, esp_mail_str_178, NULL, 0, -1); - if (tmp) - { - part.attach_data_size = atoi(tmp); - delS(tmp); - cHeader(imap)->total_attach_data_size += part.attach_data_size; - part.sizeProp = true; - } - } - - tmp = subStr(buf, esp_mail_str_179, esp_mail_str_136, 0); - if (tmp) - { - part.creation_date = tmp; - delS(tmp); - } - else - { - tmp = subStr(buf, esp_mail_str_180, NULL, 0, -1); - if (tmp) - { - part.creation_date = tmp; - delS(tmp); - } - } - - tmp = subStr(buf, esp_mail_str_181, esp_mail_str_136, 0); - if (tmp) - { - part.modification_date = tmp; - delS(tmp); - } - else - { - tmp = subStr(buf, esp_mail_str_182, NULL, 0, -1); - if (tmp) - { - part.modification_date = tmp; - delS(tmp); - } - } - } - - chunkIdx++; - } -} - -char *ESP_Mail_Client::subStr(const char *buf, PGM_P beginH, PGM_P endH, int beginPos, int endPos) -{ - - char *tmp = nullptr; - int p1 = strposP(buf, beginH, beginPos); - if (p1 != -1) - { - int p2 = -1; - if (endPos == 0) - p2 = strposP(buf, endH, p1 + strlen_P(beginH)); - - if (p2 == -1) - p2 = strlen(buf); - - int len = p2 - p1 - strlen_P(beginH); - tmp = newS(len + 1); - memcpy(tmp, &buf[p1 + strlen_P(beginH)], len); - return tmp; - } - - return nullptr; -} - -void ESP_Mail_Client::handleAuth(SMTPSession *smtp, char *buf) -{ - if (strposP(buf, esp_mail_smtp_response_1, 0) > -1) - { - if (strposP(buf, esp_mail_smtp_response_2, 0) > -1) - smtp->_auth_capability.login = true; - if (strposP(buf, esp_mail_smtp_response_3, 0) > -1) - smtp->_auth_capability.plain = true; - if (strposP(buf, esp_mail_smtp_response_4, 0) > -1) - smtp->_auth_capability.xoauth2 = true; - if (strposP(buf, esp_mail_smtp_response_11, 0) > -1) - smtp->_auth_capability.cram_md5 = true; - if (strposP(buf, esp_mail_smtp_response_12, 0) > -1) - smtp->_auth_capability.digest_md5 = true; - } - else if (strposP(buf, esp_mail_smtp_response_5, 0) > -1) - smtp->_auth_capability.start_tls = true; - else if (strposP(buf, esp_mail_smtp_response_6, 0) > -1) - smtp->_send_capability._8bitMIME = true; - else if (strposP(buf, esp_mail_smtp_response_7, 0) > -1) - smtp->_send_capability.binaryMIME = true; - else if (strposP(buf, esp_mail_smtp_response_8, 0) > -1) - smtp->_send_capability.chunking = true; - else if (strposP(buf, esp_mail_smtp_response_9, 0) > -1) - smtp->_send_capability.utf8 = true; - else if (strposP(buf, esp_mail_smtp_response_10, 0) > -1) - smtp->_send_capability.pipelining = true; - else if (strposP(buf, esp_mail_smtp_response_13, 0) > -1) - smtp->_send_capability.dsn = true; -} - -int ESP_Mail_Client::available(SMTPSession *smtp) -{ - int sz = 0; - if (smtp->_sesson_cfg->secure.startTLS || !smtp->_secure) - { - if (smtp->httpClient._stream()) - sz = smtp->httpClient._stream()->_ns_available(); - } - else - { - if (smtp->httpClient.stream()) - sz = smtp->httpClient.stream()->available(); - } - - return sz; -} - -bool ESP_Mail_Client::handleSMTPResponse(SMTPSession *smtp, esp_mail_smtp_status_code respCode, int errCode) -{ - if (!reconnect(smtp)) - return false; - - bool ret = false; - char *response = nullptr; - int readLen = 0; - long dataTime = millis(); - int chunkBufSize = 0; - std::string s, r; - int chunkIndex = 0; - int count = 0; - bool completedResponse = false; - smtp->_smtpStatus.statusCode = 0; - smtp->_smtpStatus.respCode = 0; - smtp->_smtpStatus.text.clear(); - uint8_t minResLen = 5; - struct esp_mail_smtp_response_status_t status; - - chunkBufSize = available(smtp); - - while (smtp->_tcpConnected && chunkBufSize <= 0) - { - if (!reconnect(smtp, dataTime)) - return false; - if (!connected(smtp)) - { - errorStatusCB(smtp, MAIL_CLIENT_ERROR_CONNECTION_LOST); - return false; - } - chunkBufSize = available(smtp); - delay(0); - } - - dataTime = millis(); - - if (chunkBufSize > 1) - { - while (!completedResponse) - { - delay(0); - - if (!reconnect(smtp, dataTime)) - return false; - - if (!connected(smtp)) - { - errorStatusCB(smtp, MAIL_CLIENT_ERROR_CONNECTION_LOST); - return false; - } - - chunkBufSize = available(smtp); - - if (chunkBufSize <= 0) - break; - - if (chunkBufSize > 0) - { - chunkBufSize = 512; - response = newS(chunkBufSize + 1); - - if (smtp->_sesson_cfg->secure.startTLS || !smtp->_secure) - readLen = _readLine(smtp->httpClient._stream(), response, chunkBufSize, false, count); - else - readLen = readLine(smtp->httpClient.stream(), response, chunkBufSize, false, count); - - if (readLen) - { - if (smtp->_smtp_cmd != esp_mail_smtp_command::esp_mail_smtp_cmd_initial_state) - { - //sometimes server sent multiple lines response - //sometimes rx buffer may not ready for a while - if (strlen(response) < minResLen) - { - r += response; - chunkBufSize = 0; - while (chunkBufSize == 0) - { - delay(0); - if (!reconnect(smtp, dataTime)) - return false; - chunkBufSize = available(smtp); - } - } - else - { - if (r.length() > 0) - { - r += response; - memset(response, 0, chunkBufSize); - strcpy(response, r.c_str()); - } - - if (smtp->_debugLevel > esp_mail_debug_level_1) - esp_mail_debug((const char *)response); - } - - if (smtp->_smtp_cmd == esp_mail_smtp_command::esp_mail_smtp_cmd_greeting) - handleAuth(smtp, response); - } - - getResponseStatus(response, respCode, 0, status); - - //get the status code again for unexpected return code - if (smtp->_smtp_cmd == esp_mail_smtp_command::esp_mail_smtp_cmd_start_tls || status.respCode == 0) - getResponseStatus(response, esp_mail_smtp_status_code_0, 0, status); - - ret = respCode == status.respCode; - smtp->_smtpStatus = status; - - if (status.respCode > 0 && (status.respCode < 400 || status.respCode == respCode)) - ret = true; - - if (smtp->_debug && strlen(response) >= minResLen) - { - appendP(s, esp_mail_str_260, true); - if (smtp->_smtpStatus.respCode != esp_mail_smtp_status_code_334) - s += response; - else - { - //base64 response - size_t olen; - char *decoded = (char *)decodeBase64((const unsigned char *)status.text.c_str(), status.text.length(), &olen); - if (decoded && olen > 0) - { - olen += s.length(); - s += decoded; - s[olen] = 0; - delete[] decoded; - } - } - esp_mail_debug(s.c_str()); - r.clear(); - } - - completedResponse = smtp->_smtpStatus.respCode > 0 && status.text.length() > minResLen; - - if (smtp->_smtp_cmd == esp_mail_smtp_command::esp_mail_smtp_cmd_auth && smtp->_smtpStatus.respCode == esp_mail_smtp_status_code_334) - { - if (authFailed(response, readLen, chunkIndex, 4)) - { - smtp->_smtpStatus.statusCode = -1; - ret = false; - } - } - - chunkIndex++; - - if (smtp->_chunkedEnable && smtp->_smtp_cmd == esp_mail_smtp_command::esp_mail_smtp_cmd_chunk_termination) - completedResponse = smtp->_chunkCount == chunkIndex; - } - delS(response); - } - } - - if (!ret) - handleSMTPError(smtp, errCode, false); - } - - return ret; -} - -void ESP_Mail_Client::getResponseStatus(const char *buf, esp_mail_smtp_status_code respCode, int beginPos, struct esp_mail_smtp_response_status_t &status) -{ - std::string s; - char *tmp = nullptr; - int p1 = 0; - if (respCode > esp_mail_smtp_status_code_0) - { - tmp = intStr((int)respCode); - s = tmp; - appendP(s, esp_mail_str_131, false); - delS(tmp); - p1 = strpos(buf, (const char *)s.c_str(), beginPos); - } - - if (p1 != -1) - { - int ofs = s.length() - 2; - if (ofs < 0) - ofs = 1; - - int p2 = strposP(buf, esp_mail_str_131, p1 + ofs); - - if (p2 < 4 && p2 > -1) - { - tmp = newS(p2 + 1); - memcpy(tmp, &buf[p1], p2); - status.respCode = atoi(tmp); - delS(tmp); - - p1 = p2 + 1; - p2 = strlen(buf); - if (p2 > p1) - { - tmp = newS(p2 + 1); - memcpy(tmp, &buf[p1], p2 - p1); - status.text = tmp; - delS(tmp); - } - } - } -} - -void ESP_Mail_Client::closeTCP(SMTPSession *smtp) -{ - - if (smtp->_tcpConnected) - { - if (smtp->httpClient.stream()) - { - if (connected(smtp)) - { - if (smtp->_sesson_cfg->secure.startTLS || !smtp->_secure) - smtp->httpClient._stream()->stop(); - else - smtp->httpClient.stream()->stop(); - } - } - _lastReconnectMillis = millis(); - } - smtp->_tcpConnected = false; -} - -void ESP_Mail_Client::closeTCP(IMAPSession *imap) -{ - - if (imap->_tcpConnected) - { - if (imap->httpClient.stream()) - { - if (connected(imap)) - { - if (!imap->_secure) - imap->httpClient._stream()->stop(); - else - imap->httpClient.stream()->stop(); - } - } - _lastReconnectMillis = millis(); - } - imap->_tcpConnected = false; -} - -#if defined(ESP32) -void ESP_Mail_Client::setSecure(ESP_Mail_HTTPClient32 &httpClient, ESP_Mail_Session *session, std::shared_ptr caCert) -#elif defined(ESP8266) -void ESP_Mail_Client::setSecure(ESP_Mail_HTTPClient &httpClient, ESP_Mail_Session *session, std::shared_ptr caCert) -#endif -{ - -#if defined(ESP32) - if (httpClient._certType == -1) - { - if (strlen(session->certificate.cert_file) == 0) - { - if (caCert != nullptr) - httpClient.setCACert(caCert.get()); - else - httpClient.setCACert(nullptr); - } - else - { - httpClient.setCertFile(session->certificate.cert_file, session->certificate.cert_file_storage_type); - } - } -#elif defined(ESP8266) - - if (httpClient._certType == -1) - { - -#ifndef USING_AXTLS - if (!MailClient._clockReady && (strlen(session->certificate.cert_file) > 0 || caCert != nullptr)) - { - MailClient.setClock(MailClient._gmtOffset); - httpClient._clockReady = MailClient._clockReady; - } -#endif - if (strlen(session->certificate.cert_file) == 0) - { - if (caCert != nullptr) - httpClient.setCACert(caCert.get()); - else - httpClient.setCACert(nullptr); - } - else - { - httpClient.setCertFile(session->certificate.cert_file, session->certificate.cert_file_storage_type, MailClient._sdPin); - } - } -#endif -} - -bool ESP_Mail_Client::ethLinkUp() -{ - bool ret = false; -#if defined(ESP32) - char *ip = strP(esp_mail_str_328); - if (strcmp(ETH.localIP().toString().c_str(), ip) != 0) -// ret = ETH.linkUp(); - ret = true; - delS(ip); -#endif - return ret; -} - -bool ESP_Mail_Client::reconnect(SMTPSession *smtp, unsigned long dataTime) -{ - - bool status = WiFi.status() == WL_CONNECTED || ethLinkUp(); - - if (dataTime > 0) - { - if (millis() - dataTime > smtp->httpClient.tcpTimeout) - { - closeTCP(smtp); - errorStatusCB(smtp, MAIL_CLIENT_ERROR_READ_TIMEOUT); - return false; - } - } - - if (!status) - { - if (smtp->_tcpConnected) - closeTCP(smtp); - - errorStatusCB(smtp, MAIL_CLIENT_ERROR_CONNECTION_LOST); - - if (millis() - _lastReconnectMillis > _reconnectTimeout && !smtp->_tcpConnected) - { -#if defined(ESP32) - esp_wifi_connect(); -#elif defined(ESP8266) - WiFi.reconnect(); -#endif - _lastReconnectMillis = millis(); - } - - status = WiFi.status() == WL_CONNECTED || ethLinkUp(); - } - - return status; -} - -bool ESP_Mail_Client::reconnect(IMAPSession *imap, unsigned long dataTime, bool downloadRequest) -{ - - bool status = WiFi.status() == WL_CONNECTED || ethLinkUp(); - - if (dataTime > 0) - { - if (millis() - dataTime > imap->httpClient.tcpTimeout) - { - - closeTCP(imap); - - if (imap->_headers.size() > 0) - { - if (downloadRequest) - { - errorStatusCB(imap, IMAP_STATUS_ERROR_DOWNLAD_TIMEOUT); - if (cHeader(imap)->part_headers.size() > 0) - cPart(imap)->download_error = imap->errorReason().c_str(); - } - else - { - errorStatusCB(imap, MAIL_CLIENT_ERROR_READ_TIMEOUT); - cHeader(imap)->error_msg = imap->errorReason().c_str(); - } - } - return false; - } - } - - if (!status) - { - - if (imap->_tcpConnected) - closeTCP(imap); - - errorStatusCB(imap, MAIL_CLIENT_ERROR_CONNECTION_LOST); - - if (imap->_headers.size() > 0) - { - if (downloadRequest) - cPart(imap)->download_error = imap->errorReason().c_str(); - else - cHeader(imap)->error_msg = imap->errorReason().c_str(); - } - - if (millis() - _lastReconnectMillis > _reconnectTimeout && !imap->_tcpConnected) - { -#if defined(ESP32) - esp_wifi_connect(); -#elif defined(ESP8266) - WiFi.reconnect(); -#endif - _lastReconnectMillis = millis(); - } - - status = WiFi.status() == WL_CONNECTED || ethLinkUp(); - } - - return status; -} - -void ESP_Mail_Client::delS(char *p) -{ - if (p != nullptr) - delete[] p; -} - -char *ESP_Mail_Client::newS(size_t len) -{ - char *p = new char[len]; - memset(p, 0, len); - return p; -} - -char *ESP_Mail_Client::newS(char *p, size_t len) -{ - delS(p); - p = newS(len); - return p; -} - -char *ESP_Mail_Client::newS(char *p, size_t len, char *d) -{ - delS(p); - p = newS(len); - strcpy(p, d); - return p; -} - -bool ESP_Mail_Client::strcmpP(const char *buf, int ofs, PGM_P beginH) -{ - char *tmp = nullptr; - if (ofs < 0) - { - int p = strposP(buf, beginH, 0); - if (p == -1) - return false; - ofs = p; - } - tmp = strP(beginH); - char *tmp2 = newS(strlen_P(beginH) + 1); - memcpy(tmp2, &buf[ofs], strlen_P(beginH)); - tmp2[strlen_P(beginH)] = 0; - bool ret = (strcasecmp(tmp, tmp2) == 0); - delS(tmp); - delS(tmp2); - return ret; -} - -int ESP_Mail_Client::strposP(const char *buf, PGM_P beginH, int ofs) -{ - char *tmp = strP(beginH); - int p = strpos(buf, tmp, ofs); - delS(tmp); - return p; -} - -char *ESP_Mail_Client::strP(PGM_P pgm) -{ - size_t len = strlen_P(pgm) + 1; - char *buf = newS(len); - strcpy_P(buf, pgm); - buf[len - 1] = 0; - return buf; -} - -void ESP_Mail_Client::appendP(std::string &buf, PGM_P p, bool empty) -{ - if (empty) - buf.clear(); - char *b = strP(p); - buf += b; - delS(b); -} - -char *ESP_Mail_Client::intStr(int value) -{ - char *buf = newS(36); - memset(buf, 0, 36); - itoa(value, buf, 10); - return buf; -} - -int ESP_Mail_Client::available(IMAPSession *imap) -{ - int sz = 0; - if (!imap->_secure) - { - if (imap->httpClient._stream()) - sz = imap->httpClient._stream()->_ns_available(); - } - else - { - if (imap->httpClient.stream()) - sz = imap->httpClient.stream()->available(); - } - return sz; -} - -bool ESP_Mail_Client::handleIMAPResponse(IMAPSession *imap, int errCode, bool closeSession) -{ - - if (!reconnect(imap)) - return false; - - esp_mail_imap_response_status imapResp = esp_mail_imap_response_status::esp_mail_imap_resp_unknown; - char *response = nullptr; - int readLen = 0; - long dataTime = millis(); - int chunkBufSize = available(imap); - int chunkIdx = 0; - std::string s; - bool completedResponse = false; - bool endSearch = false; - struct esp_mail_message_header_t header; - struct esp_mail_message_part_info_t part; - - std::string filePath = ""; - bool downloadRequest = false; - int reportState = 0; - int octetCount = 0; - int octetLength = 0; - int oCount = 0; - bool tmo = false; - int headerState = 0; - int scnt = 0; - int dcnt = -1; - char *skey = nullptr; - char *spc = nullptr; - char *lastBuf = nullptr; - char *tmp = nullptr; - bool crLF = imap->_imap_cmd == esp_mail_imap_cmd_fetch_body_text && strcmpP(cPart(imap)->content_transfer_encoding.c_str(), 0, esp_mail_str_31); - - while (imap->_tcpConnected && chunkBufSize <= 0) - { - if (!reconnect(imap, dataTime)) - return false; - if (!connected(imap)) - { - errorStatusCB(imap, MAIL_CLIENT_ERROR_CONNECTION_LOST); - return false; - } - chunkBufSize = available(imap); - delay(0); - } - - dataTime = millis(); - - if (chunkBufSize > 1) - { - if (imap->_imap_cmd == esp_mail_imap_cmd_examine) - { - imap->_mbif.clear(); - imap->_mbif._msgCount = 0; - imap->_nextUID = ""; - } - - if (imap->_imap_cmd == esp_mail_imap_cmd_search) - { - imap->_mbif._searchCount = 0; - imap->_msgNum.clear(); - } - - chunkBufSize = 512; - response = newS(chunkBufSize + 1); - - if (imap->_imap_cmd == esp_mail_imap_command::esp_mail_imap_cmd_search) - { - skey = strP(esp_mail_imap_response_6); - spc = strP(esp_mail_str_92); - } - - if (imap->_imap_cmd == esp_mail_imap_cmd_fetch_body_attachment || imap->_imap_cmd == esp_mail_imap_cmd_fetch_body_inline) - lastBuf = newS(BASE64_CHUNKED_LEN + 1); - - while (!completedResponse) - { - delay(0); - if (!reconnect(imap, dataTime) || !connected(imap)) - { - if (imap->_imap_cmd == esp_mail_imap_command::esp_mail_imap_cmd_search) - { - delS(skey); - delS(spc); - } - - if (!connected(imap)) - { - errorStatusCB(imap, MAIL_CLIENT_ERROR_CONNECTION_LOST); - return false; - } - return false; - } - chunkBufSize = available(imap); - - if (chunkBufSize > 0) - { - chunkBufSize = 512; - - if (imap->_imap_cmd == esp_mail_imap_command::esp_mail_imap_cmd_search) - { - readLen = getMSGNUM(imap, response, chunkBufSize, chunkIdx, endSearch, scnt, skey, spc); - imap->_mbif._availableItems = imap->_msgNum.size(); - } - else - { - if (!imap->_secure) - readLen = _readLine(imap->httpClient._stream(), response, chunkBufSize, crLF, octetCount); - else - readLen = readLine(imap->httpClient.stream(), response, chunkBufSize, crLF, octetCount); - } - - if (readLen) - { - - if (imap->_debugLevel > esp_mail_debug_level_1) - { - if (imap->_imap_cmd != esp_mail_imap_cmd_search && imap->_imap_cmd != esp_mail_imap_cmd_fetch_body_text && imap->_imap_cmd != esp_mail_imap_cmd_fetch_body_attachment && imap->_imap_cmd != esp_mail_imap_cmd_fetch_body_inline) - esp_mail_debug((const char *)response); - } - - if (imap->_imap_cmd != esp_mail_imap_cmd_search || (imap->_imap_cmd == esp_mail_imap_cmd_search && endSearch)) - imapResp = imapResponseStatus(imap, response); - - if (imapResp != esp_mail_imap_response_status::esp_mail_imap_resp_unknown) - { - if (imap->_debugLevel > esp_mail_debug_level_1) - { - if (imap->_imap_cmd == esp_mail_imap_cmd_fetch_body_text || imap->_imap_cmd == esp_mail_imap_cmd_fetch_body_attachment || imap->_imap_cmd == esp_mail_imap_cmd_fetch_body_inline) - esp_mail_debug((const char *)response); - } - - if (imap->_imap_cmd == esp_mail_imap_cmd_close) - completedResponse = true; - else - { - //some IMAP servers advertise CAPABILITY in their responses - //try to read the next available response - memset(response, 0, chunkBufSize); - if (!imap->_secure) - readLen = _readLine(imap->httpClient._stream(), response, chunkBufSize, true, octetCount); - else - readLen = readLine(imap->httpClient.stream(), response, chunkBufSize, true, octetCount); - if (readLen) - { - completedResponse = false; - imapResp = imapResponseStatus(imap, response); - if (imapResp > esp_mail_imap_response_status::esp_mail_imap_resp_unknown) - completedResponse = true; - } - else - completedResponse = true; - } - } - else - { - if (imap->_imap_cmd == esp_mail_imap_cmd_auth) - { - if (authFailed(response, readLen, chunkIdx, 2)) - completedResponse = true; - } - else if (imap->_imap_cmd == esp_mail_imap_cmd_capability) - handleCapability(imap, response, chunkIdx); - else if (imap->_imap_cmd == esp_mail_imap_cmd_list) - handleFolders(imap, response); - else if (imap->_imap_cmd == esp_mail_imap_cmd_select || imap->_imap_cmd == esp_mail_imap_cmd_examine) - handleExamine(imap, response); - else if (imap->_imap_cmd == esp_mail_imap_cmd_fetch_body_header) - { - char *tmp = intStr(cMSG(imap)); - header.message_uid = tmp; - delS(tmp); - - tmp = intStr(imap->_totalRead); - header.message_no = tmp; - delS(tmp); - - int _st = headerState; - handleHeader(imap, response, readLen, chunkIdx, header, headerState, octetCount); - if (_st == headerState && headerState > 0 && octetCount <= header.header_data_len) - setHeader(imap, response, header, headerState); - } - else if (imap->_imap_cmd == esp_mail_imap_cmd_fetch_body_mime) - handlePartHeader(imap, response, chunkIdx, part); - else if (imap->_imap_cmd == esp_mail_imap_cmd_fetch_body_text) - decodeText(imap, response, readLen, chunkIdx, file, filePath, downloadRequest, octetLength, octetCount, dcnt); - else if (imap->_imap_cmd == esp_mail_imap_cmd_fetch_body_attachment || imap->_imap_cmd == esp_mail_imap_cmd_fetch_body_inline) - { - - if (strcmpP(cPart(imap)->content_transfer_encoding.c_str(), 0, esp_mail_str_31)) - { - //multi-line chunked base64 string attachment handle - if (octetCount < octetLength && readLen < BASE64_CHUNKED_LEN) - { - if (strlen(lastBuf) > 0) - { - tmp = newS(readLen + strlen(lastBuf) + 2); - strcpy(tmp, lastBuf); - strcat(tmp, response); - readLen = strlen(tmp); - tmo = handleAttachment(imap, tmp, readLen, chunkIdx, file, filePath, downloadRequest, octetCount, octetLength, oCount, reportState, dcnt); - delS(tmp); - memset(lastBuf, 0, BASE64_CHUNKED_LEN + 1); - if (!tmo) - break; - } - else if (readLen < BASE64_CHUNKED_LEN + 1) - strcpy(lastBuf, response); - } - else - { - tmo = handleAttachment(imap, response, readLen, chunkIdx, file, filePath, downloadRequest, octetCount, octetLength, oCount, reportState, dcnt); - if (!tmo) - break; - } - } - else - tmo = handleAttachment(imap, response, readLen, chunkIdx, file, filePath, downloadRequest, octetCount, octetLength, oCount, reportState, dcnt); - } - dataTime = millis(); - } - } - memset(response, 0, chunkBufSize); - } - } - delS(response); - if (imap->_imap_cmd == esp_mail_imap_command::esp_mail_imap_cmd_search) - { - if (imap->_debug && scnt > 0 && scnt < 100) - searchReport(100, spc); - delS(skey); - delS(spc); - } - if (imap->_imap_cmd == esp_mail_imap_cmd_fetch_body_attachment) - delS(lastBuf); - } - - if ((imap->_imap_cmd == esp_mail_imap_cmd_fetch_body_header && header.header_data_len == 0) || imapResp == esp_mail_imap_response_status::esp_mail_imap_resp_no) - { - if (imapResp == esp_mail_imap_response_status::esp_mail_imap_resp_no) - imap->_imapStatus.statusCode = IMAP_STATUS_IMAP_RESPONSE_FAILED; - else - imap->_imapStatus.statusCode = IMAP_STATUS_NO_MESSAGE; - - if (imap->_readCallback) - { - std::string s; - appendP(s, esp_mail_str_53, true); - s += imap->errorReason().c_str(); - imapCB(imap, s.c_str(), false); - } - - if (imap->_debug) - { - std::string s; - appendP(s, esp_mail_str_185, true); - s += imap->errorReason().c_str(); - esp_mail_debug_line(s.c_str(), true); - } - - return false; - } - - if (imapResp == esp_mail_imap_response_status::esp_mail_imap_resp_ok) - { - if (imap->_imap_cmd == esp_mail_imap_cmd_fetch_body_header) - { - char *buf = newS(header.content_type.length() + 1); - strcpy(buf, header.content_type.c_str()); - header.content_type.clear(); - - tmp = subStr(buf, esp_mail_str_25, esp_mail_str_97, 0); - if (tmp) - { - headerState = esp_mail_imap_header_state::esp_mail_imap_state_content_type; - setHeader(imap, tmp, header, headerState); - delS(tmp); - - int p1 = strposP(header.content_type.c_str(), esp_mail_imap_composite_media_type_t::multipart, 0); - if (p1 != -1) - { - p1 += strlen(esp_mail_imap_composite_media_type_t::multipart) + 1; - header.multipart = true; - //inline or embedded images - if (strpos(part.content_type.c_str(), esp_mail_imap_multipart_sub_type_t::related, p1) != -1) - header.multipart_sub_type = esp_mail_imap_multipart_sub_type_related; - //multiple text formats e.g. plain, html, enriched - else if (strpos(part.content_type.c_str(), esp_mail_imap_multipart_sub_type_t::alternative, p1) != -1) - header.multipart_sub_type = esp_mail_imap_multipart_sub_type_alternative; - //medias - else if (strpos(part.content_type.c_str(), esp_mail_imap_multipart_sub_type_t::parallel, p1) != -1) - header.multipart_sub_type = esp_mail_imap_multipart_sub_type_parallel; - //rfc822 encapsulated - else if (strpos(part.content_type.c_str(), esp_mail_imap_multipart_sub_type_t::digest, p1) != -1) - header.multipart_sub_type = esp_mail_imap_multipart_sub_type_digest; - else if (strpos(part.content_type.c_str(), esp_mail_imap_multipart_sub_type_t::report, p1) != -1) - header.multipart_sub_type = esp_mail_imap_multipart_sub_type_report; - //others can be attachments - else if (strpos(part.content_type.c_str(), esp_mail_imap_multipart_sub_type_t::mixed, p1) != -1) - header.multipart_sub_type = esp_mail_imap_multipart_sub_type_mixed; - } - - p1 = strposP(header.content_type.c_str(), esp_mail_imap_composite_media_type_t::message, 0); - if (p1 != -1) - { - p1 += strlen(esp_mail_imap_composite_media_type_t::message) + 1; - if (strpos(part.content_type.c_str(), esp_mail_imap_message_sub_type_t::rfc822, p1) != -1) - { - header.rfc822_part = true; - header.message_sub_type = esp_mail_imap_message_sub_type_rfc822; - } - else if (strpos(part.content_type.c_str(), esp_mail_imap_message_sub_type_t::Partial, p1) != -1) - header.message_sub_type = esp_mail_imap_message_sub_type_partial; - else if (strpos(part.content_type.c_str(), esp_mail_imap_message_sub_type_t::External_Body, p1) != -1) - header.message_sub_type = esp_mail_imap_message_sub_type_external_body; - else if (strpos(part.content_type.c_str(), esp_mail_imap_message_sub_type_t::delivery_status, p1) != -1) - header.message_sub_type = esp_mail_imap_message_sub_type_delivery_status; - } - - tmp = subStr(buf, esp_mail_str_169, NULL, 0, -1); - if (tmp) - { - headerState = esp_mail_imap_header_state::esp_mail_imap_state_char_set; - setHeader(imap, tmp, header, headerState); - delS(tmp); - } - - if (header.multipart) - { - if (strcmpP(buf, 0, esp_mail_str_277)) - { - tmp = subStr(buf, esp_mail_str_277, esp_mail_str_136, 0); - if (tmp) - { - headerState = esp_mail_imap_header_state::esp_mail_imap_state_boundary; - setHeader(imap, tmp, header, headerState); - delS(tmp); - } - } - } - } - - delS(buf); - - decodeHeader(header.from, header.from_charset); - decodeHeader(header.to, header.to_charset); - decodeHeader(header.cc, header.cc_charset); - decodeHeader(header.subject, header.subject_charset); - - imap->_headers.push_back(header); - } - - if (imap->_imap_cmd == esp_mail_imap_cmd_fetch_body_mime) - { - //expect the octet length in the response for the existent part - if (part.octetLen > 0) - { - - part.partNumStr = cHeader(imap)->partNumStr; - part.partNumFetchStr = cHeader(imap)->partNumStr; - if (cHeader(imap)->part_headers.size() > 0) - { - - struct esp_mail_message_part_info_t *_part = &cHeader(imap)->part_headers[cHeader(imap)->part_headers.size() - 1]; - bool rfc822_body_subtype = _part->message_sub_type == esp_mail_imap_message_sub_type_rfc822; - - if (rfc822_body_subtype) - { - if (!_part->rfc822_part) - { - //additional rfc822 message header, store it to the rfc822 part header - _part->rfc822_part = true; - _part->rfc822_header = part.rfc822_header; - imap->_rfc822_part_count++; - _part->rfc822_msg_Idx = imap->_rfc822_part_count; - } - } - } - - cHeader(imap)->part_headers.push_back(part); - cHeader(imap)->message_data_count = cHeader(imap)->part_headers.size(); - - if (part.msg_type == esp_mail_msg_type_plain || part.msg_type == esp_mail_msg_type_enriched || part.msg_type == esp_mail_msg_type_html || part.attach_type == esp_mail_att_type_none || (part.attach_type == esp_mail_att_type_attachment && imap->_config->download.attachment) || (part.attach_type == esp_mail_att_type_inline && imap->_config->download.inlineImg)) - { - if (part.message_sub_type != esp_mail_imap_message_sub_type_rfc822) - { - if (part.attach_type != esp_mail_att_type_none && cHeader(imap)->multipart_sub_type != esp_mail_imap_multipart_sub_type_alternative) - cHeader(imap)->attachment_count++; - } - } - } - else - { - //nonexistent part - //return false to exit the loop without closing the connection - if (closeSession) - imap->closeSession(); - return false; - } - } - - if (imap->_imap_cmd == esp_mail_imap_cmd_fetch_body_attachment || imap->_imap_cmd == esp_mail_imap_cmd_fetch_body_text || imap->_imap_cmd == esp_mail_imap_cmd_fetch_body_inline) - { - if (cPart(imap)->file_open_write) - file.close(); - } - - if (imap->_imap_cmd == esp_mail_imap_cmd_fetch_body_text) - cPart(imap)->text[cPart(imap)->textLen] = 0; - } - else - { - //some server responses NO and should exit (false) from MIME feching loop without - //closing the session - if (imap->_imap_cmd != esp_mail_imap_cmd_fetch_body_mime) - return handleIMAPError(imap, errCode, false); - - if (closeSession) - imap->closeSession(); - return false; - } - - return true; -} - -void ESP_Mail_Client::saveHeader(IMAPSession *imap) -{ - - std::string headerFilePath; - prepareFilePath(imap, headerFilePath, true); - if (imap->_storageType == esp_mail_file_storage_type_sd && !_sdOk) - _sdOk = sdTest(); - else if (imap->_storageType == esp_mail_file_storage_type_flash && !_flashOk) -#if defined(ESP32) - _flashOk = ESP_MAIL_FLASH_FS.begin(FORMAT_FLASH); -#elif defined(ESP8266) - _flashOk = ESP_MAIL_FLASH_FS.begin(); -#endif - - if (_sdOk || _flashOk) - { - if (file) - file.close(); - - if (imap->_storageType == esp_mail_file_storage_type_sd) { - file = ESP_MAIL_SD_FS.open(headerFilePath.c_str(), FILE_WRITE); - } else if (imap->_storageType == esp_mail_file_storage_type_flash) { -#if defined(ESP32) - file = ESP_MAIL_FLASH_FS.open(headerFilePath.c_str(), FILE_WRITE); -#elif defined(ESP8266) - file = ESP_MAIL_FLASH_FS.open(headerFilePath.c_str(), "w"); -#endif - } else if (imap->_storageType == esp_mail_file_storage_type_univ) { - file = ufsp->open(headerFilePath.c_str(), "w"); - } - - if (file) - { - std::string s; - appendP(s, esp_mail_str_99, true); - file.print(s.c_str()); - file.println(cHeader(imap)->date.c_str()); - - appendP(s, esp_mail_str_100, true); - file.print(s.c_str()); - if (imap->_uidSearch) - file.println(cMSG(imap)); - else - file.println(); - - appendP(s, esp_mail_str_101, true); - file.print(s.c_str()); - file.println(cMSG(imap)); - - appendP(s, esp_mail_str_102, true); - file.print(s.c_str()); - file.println(cHeader(imap)->accept_language.c_str()); - - appendP(s, esp_mail_str_103, true); - file.print(s.c_str()); - file.println(cHeader(imap)->content_language.c_str()); - - appendP(s, esp_mail_str_10, true); - file.print(s.c_str()); - file.println(cHeader(imap)->from.c_str()); - - appendP(s, esp_mail_str_105, true); - file.print(s.c_str()); - file.println(cHeader(imap)->from_charset.c_str()); - - appendP(s, esp_mail_str_11, true); - file.print(s.c_str()); - file.println(cHeader(imap)->to.c_str()); - - appendP(s, esp_mail_str_107, true); - file.print(s.c_str()); - file.println(cHeader(imap)->to_charset.c_str()); - - appendP(s, esp_mail_str_108, true); - file.print(s.c_str()); - file.println(cHeader(imap)->cc.c_str()); - - appendP(s, esp_mail_str_109, true); - file.print(s.c_str()); - file.println(cHeader(imap)->cc_charset.c_str()); - - appendP(s, esp_mail_str_24, true); - file.print(s.c_str()); - file.println(cHeader(imap)->subject.c_str()); - - appendP(s, esp_mail_str_111, true); - file.print(s.c_str()); - file.println(cHeader(imap)->subject_charset.c_str()); - - appendP(s, esp_mail_str_112, true); - file.print(s.c_str()); - file.println(cPart(imap)->charset.c_str()); - - if (cHeader(imap)->attachment_count > 0) - { - - appendP(s, esp_mail_str_113, true); - file.print(s.c_str()); - file.println(cHeader(imap)->attachment_count); - - for (int j = 0; j < cHeader(imap)->attachment_count; j++) - { - if (imap->_headers[cIdx(imap)].part_headers[j].attach_type == esp_mail_att_type_none || imap->_headers[cIdx(imap)].part_headers[j].rfc822_part) - continue; - struct esp_mail_attacment_info_t att; - att.filename = imap->_headers[cIdx(imap)].part_headers[j].filename.c_str(); - att.mime = imap->_headers[cIdx(imap)].part_headers[j].content_type.c_str(); - att.name = imap->_headers[cIdx(imap)].part_headers[j].name.c_str(); - att.size = imap->_headers[cIdx(imap)].part_headers[j].attach_data_size; - att.creationDate = imap->_headers[cIdx(imap)].part_headers[j].creation_date.c_str(); - att.type = imap->_headers[cIdx(imap)].part_headers[j].attach_type; - - appendP(s, esp_mail_str_114, true); - file.print(s.c_str()); - file.println(j + 1); - - appendP(s, esp_mail_str_115, true); - file.print(s.c_str()); - file.println(att.filename); - - appendP(s, esp_mail_str_116, true); - file.print(s.c_str()); - file.println(att.name); - - appendP(s, esp_mail_str_117, true); - file.print(s.c_str()); - file.println(att.size); - - appendP(s, esp_mail_str_118, true); - file.print(s.c_str()); - file.println(att.mime); - - appendP(s, esp_mail_str_119, true); - file.print(s.c_str()); - file.println(att.creationDate); - } - } - - file.close(); - } - imap->_headerSaved = true; - } -} - -esp_mail_imap_response_status ESP_Mail_Client::imapResponseStatus(IMAPSession *imap, char *response) -{ - imap->_imapStatus.text.clear(); - if (strposP(response, esp_mail_imap_response_1, 0) > -1) - return esp_mail_imap_response_status::esp_mail_imap_resp_ok; - else if (strposP(response, esp_mail_imap_response_2, 0) > -1) - { - imap->_imapStatus.text = response; - imap->_imapStatus.text = imap->_imapStatus.text.substr(strlen_P(esp_mail_imap_response_2)); - return esp_mail_imap_response_status::esp_mail_imap_resp_no; - } - else if (strposP(response, esp_mail_imap_response_3, 0) > -1) - { - imap->_imapStatus.text = response; - imap->_imapStatus.text = imap->_imapStatus.text.substr(strlen_P(esp_mail_imap_response_3)); - return esp_mail_imap_response_status::esp_mail_imap_resp_bad; - } - return esp_mail_imap_response_status::esp_mail_imap_resp_unknown; -} - -void ESP_Mail_Client::decodeHeader(std::string &headerField, std::string &headerEnc) -{ - - size_t p1 = 0, p2 = 0; - - while (headerField[p1] == ' ' && p1 < headerField.length() - 1) - p1++; - - if (headerField[p1] == '=' && headerField[p1 + 1] == '?') - { - p2 = headerField.find("?", p1 + 2); - if (p2 != std::string::npos) - headerEnc = headerField.substr(p1 + 2, p2 - p1 - 2); - } - - int bufSize = 512; - char *buf = newS(bufSize); - - RFC2047Decoder.rfc2047Decode(buf, headerField.c_str(), bufSize); - - if (getEncodingFromCharset(headerEnc.c_str()) == esp_mail_char_decoding_scheme_iso8859_1) - { - int len = strlen(buf); - int olen = (len + 1) * 2; - unsigned char *out = (unsigned char *)newS(olen); - decodeLatin1_UTF8(out, &olen, (unsigned char *)buf, &len); - delS(buf); - buf = (char *)out; - } - else if (getEncodingFromCharset(headerEnc.c_str()) == esp_mail_char_decoding_scheme_tis620) - { - size_t len2 = strlen(buf); - char *tmp = newS((len2 + 1) * 3); - decodeTIS620_UTF8(tmp, buf, len2); - delS(buf); - buf = tmp; - } - - headerField = buf; - delS(buf); -} - -esp_mail_char_decoding_scheme ESP_Mail_Client::getEncodingFromCharset(const char *enc) -{ - esp_mail_char_decoding_scheme scheme = esp_mail_char_decoding_scheme_default; - - if (strposP(enc, esp_mail_str_237, 0) > -1 || strposP(enc, esp_mail_str_231, 0) > -1 || strposP(enc, esp_mail_str_226, 0) > -1) - scheme = esp_mail_char_decoding_scheme_tis620; - else if (strposP(enc, esp_mail_str_227, 0) > -1) - scheme = esp_mail_char_decoding_scheme_iso8859_1; - - return scheme; -} - -bool ESP_Mail_Client::handleAttachment(IMAPSession *imap, char *buf, int bufLen, int &chunkIdx, File &file, std::string &filePath, bool &downloadRequest, int &octetCount, int &octetLength, int &oCount, int &reportState, int &downloadCount) -{ - if (chunkIdx == 0) - { - char *tmp = subStr(buf, esp_mail_str_193, esp_mail_str_194, 0); - if (tmp) - { - octetCount = 2; //CRLF counted from first line - octetLength = atoi(tmp); - delS(tmp); - chunkIdx++; - cHeader(imap)->total_download_size += octetLength; - } - return true; - } - - if (octetLength == 0) - return true; - - chunkIdx++; - - delay(0); - - if (!cPart(imap)->file_open_write) - { - - cPart(imap)->file_open_write = true; - - if (imap->_storageType == esp_mail_file_storage_type_sd && !_sdOk) - _sdOk = sdTest(); - else if (imap->_storageType == esp_mail_file_storage_type_flash && !_flashOk) -#if defined(ESP32) - _flashOk = ESP_MAIL_FLASH_FS.begin(FORMAT_FLASH); -#elif defined(ESP8266) - _flashOk = ESP_MAIL_FLASH_FS.begin(); -#endif - - if (_sdOk || _flashOk) - { - - downloadRequest = true; - - filePath.clear(); - filePath += imap->_config->storage.saved_path; - appendP(filePath, esp_mail_str_202, false); - - char *tmp = intStr(cMSG(imap)); - filePath += tmp; - delS(tmp); - - if (imap->_storageType == esp_mail_file_storage_type_sd) - if (!ESP_MAIL_SD_FS.exists(filePath.c_str())) - createDirs(filePath); - - appendP(filePath, esp_mail_str_202, false); - - filePath += cPart(imap)->filename; - - if (imap->_storageType == esp_mail_file_storage_type_sd) - file = ESP_MAIL_SD_FS.open(filePath.c_str(), FILE_WRITE); - else if (imap->_storageType == esp_mail_file_storage_type_flash) -#if defined(ESP32) - file = ESP_MAIL_FLASH_FS.open(filePath.c_str(), FILE_WRITE); -#elif defined(ESP8266) - file = ESP_MAIL_FLASH_FS.open(filePath.c_str(), "w"); -#endif - } - } - - if (_sdOk || _flashOk) - { - int nOctet = oCount + bufLen + 2; - if (nOctet > octetLength) - { - if (imap->_readCallback) - downloadReport(imap, 100); - - if (oCount < octetLength) - { - int dLen = nOctet - 2 - octetLength; - bufLen -= dLen; - buf[bufLen] = 0; - } - else - return true; - } - - oCount += bufLen + 2; - - if (strcmpP(cPart(imap)->content_transfer_encoding.c_str(), 0, esp_mail_str_31)) - { - - size_t olen = 0; - unsigned char *decoded = decodeBase64((const unsigned char *)buf, bufLen, &olen); - - if (decoded) - { - - if (!cPart(imap)->sizeProp) - { - cPart(imap)->attach_data_size += olen; - cHeader(imap)->total_attach_data_size += cPart(imap)->attach_data_size; - } - - file.write((const uint8_t *)decoded, olen); - delay(0); - delete[] decoded; - - if (imap->_config->enable.download_status) - { - int p = 0; - if (cHeader(imap)->total_download_size > 0) - p = 100 * octetCount / cHeader(imap)->total_download_size; - - if ((p != downloadCount) && (p <= 100)) - { - downloadCount = p; - if (imap->_readCallback && reportState != -1) - downloadReport(imap, p); - reportState = -1; - } - else - reportState = 0; - } - } - - if (!reconnect(imap)) - return false; - } - else - { - //binary content - if (!cPart(imap)->sizeProp) - { - cPart(imap)->attach_data_size += bufLen; - cHeader(imap)->total_attach_data_size += cPart(imap)->attach_data_size; - } - - file.write((const uint8_t *)buf, bufLen); - delay(0); - - if (imap->_config->enable.download_status) - { - int p = 0; - if (cHeader(imap)->total_download_size > 0) - p = 100 * octetCount / cHeader(imap)->total_download_size; - - if ((p != downloadCount) && (p <= 100)) - { - downloadCount = p; - if (imap->_readCallback && reportState != -1) - downloadReport(imap, p); - reportState = -1; - } - else - reportState = 0; - } - - if (!reconnect(imap)) - return false; - } - } - return true; -} - -void ESP_Mail_Client::downloadReport(IMAPSession *imap, int progress) -{ - if (imap->_readCallback && progress % ESP_MAIL_PROGRESS_REPORT_STEP == 0) - { - std::string s; - char *tmp = intStr(progress); - appendP(s, esp_mail_str_90, true); - appendP(s, esp_mail_str_131, false); - s += cPart(imap)->filename; - appendP(s, esp_mail_str_91, false); - s += tmp; - delS(tmp); - appendP(s, esp_mail_str_92, false); - appendP(s, esp_mail_str_34, false); - esp_mail_debug_line(s.c_str(), false); - std::string().swap(s); - } -} - -void ESP_Mail_Client::fetchReport(IMAPSession *imap, int progress, bool download) -{ - if (imap->_readCallback && progress % ESP_MAIL_PROGRESS_REPORT_STEP == 0) - { - std::string s; - char *tmp = intStr(progress); - if (download) - appendP(s, esp_mail_str_90, true); - else - appendP(s, esp_mail_str_83, true); - appendP(s, esp_mail_str_131, false); - if (cPart(imap)->filename.length() > 0) - { - s += cPart(imap)->filename; - appendP(s, esp_mail_str_91, false); - } - s += tmp; - delS(tmp); - appendP(s, esp_mail_str_92, false); - appendP(s, esp_mail_str_34, false); - esp_mail_debug_line(s.c_str(), false); - std::string().swap(s); - } -} - -void ESP_Mail_Client::searchReport(int progress, const char *percent) -{ - if (progress % ESP_MAIL_PROGRESS_REPORT_STEP == 0) - { - char *tmp = intStr(progress); - std::string s; - appendP(s, esp_mail_str_261, true); - s += tmp; - s += percent; - appendP(s, esp_mail_str_34, false); - esp_mail_debug_line(s.c_str(), false); - delS(tmp); - } -} - -void ESP_Mail_Client::uploadReport(const char *filename, int progress) -{ - if (progress % ESP_MAIL_PROGRESS_REPORT_STEP == 0) - { - std::string s; - char *tmp = intStr(progress); - appendP(s, esp_mail_str_160, true); - s += filename; - appendP(s, esp_mail_str_91, false); - s += tmp; - delS(tmp); - appendP(s, esp_mail_str_92, false); - appendP(s, esp_mail_str_34, false); - esp_mail_debug_line(s.c_str(), false); - std::string().swap(s); - } -} - -int ESP_Mail_Client::cMSG(IMAPSession *imap) -{ - return imap->_msgNum[cIdx(imap)]; -} - -int ESP_Mail_Client::cIdx(IMAPSession *imap) -{ - return imap->_cMsgIdx; -} - -void ESP_Mail_Client::decodeTIS620_UTF8(char *out, const char *in, size_t len) -{ - //output is the 3-byte value UTF-8 - int j = 0; - for (size_t i = 0; i < len; i++) - { - if (in[i] < 0x80) - out[j++] = in[i]; - else if ((in[i] >= 0xa0 && in[i] < 0xdb) || (in[i] > 0xde && in[i] < 0xfc)) - { - int unicode = 0x0e00 + in[i] - 0xa0; - out[j++] = 0xe0 | ((unicode >> 12) & 0xf); - out[j++] = 0x80 | ((unicode >> 6) & 0x3f); - out[j++] = 0x80 | (unicode & 0x3f); - } - } -} - -int ESP_Mail_Client::decodeLatin1_UTF8(unsigned char *out, int *outlen, const unsigned char *in, int *inlen) -{ - unsigned char *outstart = out; - const unsigned char *base = in; - const unsigned char *processed = in; - unsigned char *outend = out + *outlen; - const unsigned char *inend; - unsigned int c; - int bits; - - inend = in + (*inlen); - while ((in < inend) && (out - outstart + 5 < *outlen)) - { - c = *in++; - - /* assertion: c is a single UTF-4 value */ - if (out >= outend) - break; - if (c < 0x80) - { - *out++ = c; - bits = -6; - } - else - { - *out++ = ((c >> 6) & 0x1F) | 0xC0; - bits = 0; - } - - for (; bits >= 0; bits -= 6) - { - if (out >= outend) - break; - *out++ = ((c >> bits) & 0x3F) | 0x80; - } - processed = (const unsigned char *)in; - } - *outlen = out - outstart; - *inlen = processed - base; - return (0); -} - -void ESP_Mail_Client::decodeText(IMAPSession *imap, char *buf, int bufLen, int &chunkIdx, File &file, std::string &filePath, bool &downloadRequest, int &octetLength, int &octetCount, int &readCount) -{ - bool rfc822_body_subtype = cPart(imap)->message_sub_type == esp_mail_imap_message_sub_type_rfc822; - if (chunkIdx == 0) - { - char *tmp = subStr(buf, esp_mail_str_193, esp_mail_str_194, 0); - if (tmp) - { - octetCount = 2; - octetLength = atoi(tmp); - delS(tmp); - chunkIdx++; - cPart(imap)->octetLen = octetLength; - - if ((rfc822_body_subtype && imap->_config->download.rfc822) || (!rfc822_body_subtype && ((cPart(imap)->msg_type == esp_mail_msg_type_html && imap->_config->download.html) || ((cPart(imap)->msg_type == esp_mail_msg_type_plain || cPart(imap)->msg_type == esp_mail_msg_type_enriched) && imap->_config->download.text)))) - prepareFilePath(imap, filePath, false); - - if (filePath.length() == 0) - { - if (!rfc822_body_subtype) - appendP(filePath, esp_mail_str_67, false); - else - { - appendP(filePath, esp_mail_str_82, false); - appendP(filePath, esp_mail_str_131, false); - appendP(filePath, esp_mail_str_67, false); - } - } - cPart(imap)->filename = filePath; - - return; - } - else - { - if (imap->_debug) - { - char *tmp = strP(esp_mail_str_280); - esp_mail_debug_line(tmp, false); - delS(tmp); - } - } - } - - delay(0); - - if (octetLength == 0) - return; - - if (imap->_config->download.rfc822 || imap->_config->download.html || imap->_config->download.text || (rfc822_body_subtype && imap->_config->enable.rfc822) || (!rfc822_body_subtype && ((cPart(imap)->msg_type == esp_mail_msg_type_html && imap->_config->enable.html) || ((cPart(imap)->msg_type == esp_mail_msg_type_plain || cPart(imap)->msg_type == esp_mail_msg_type_enriched) && imap->_config->enable.text)))) - { - if (imap->_readCallback && octetCount > octetLength + 2 && readCount < 100) - fetchReport(imap, 100, (imap->_config->download.rfc822 && rfc822_body_subtype) || (!rfc822_body_subtype && ((cPart(imap)->msg_type == esp_mail_msg_type_html && imap->_config->download.html) || ((cPart(imap)->msg_type == esp_mail_msg_type_plain || cPart(imap)->msg_type == esp_mail_msg_type_enriched) && imap->_config->download.text)))); - - if (octetCount <= octetLength + 2) - { - size_t olen = 0; - char *decoded = nullptr; - bool newC = true; - if (strcmpP(cPart(imap)->content_transfer_encoding.c_str(), 0, esp_mail_str_31)) - { - decoded = (char *)decodeBase64((const unsigned char *)buf, bufLen, &olen); - } - else if (strcmpP(cPart(imap)->content_transfer_encoding.c_str(), 0, esp_mail_str_278)) - { - decoded = newS(bufLen + 10); - decodeQP(buf, decoded); - olen = strlen(decoded); - } - else if (strcmpP(cPart(imap)->content_transfer_encoding.c_str(), 0, esp_mail_str_29)) - { - decoded = decode7Bit(buf); - olen = strlen(decoded); - } - else - { - //8bit and binary - newC = false; - decoded = buf; - olen = bufLen; - } - - if (decoded) - { - - if ((rfc822_body_subtype && imap->_config->enable.rfc822) || (!rfc822_body_subtype && ((cPart(imap)->msg_type == esp_mail_msg_type_html && imap->_config->enable.html) || ((cPart(imap)->msg_type == esp_mail_msg_type_plain || cPart(imap)->msg_type == esp_mail_msg_type_enriched) && imap->_config->enable.text)))) - { - - if (getEncodingFromCharset(cPart(imap)->charset.c_str()) == esp_mail_char_decoding_scheme_iso8859_1) - { - int ilen = olen; - int olen2 = (ilen + 1) * 2; - unsigned char *tmp = (unsigned char *)newS(olen2); - decodeLatin1_UTF8(tmp, &olen2, (unsigned char *)decoded, &ilen); - delS(decoded); - olen = olen2; - decoded = (char *)tmp; - } - else if (getEncodingFromCharset(cPart(imap)->charset.c_str()) == esp_mail_char_decoding_scheme_tis620) - { - char *out = newS((olen + 1) * 3); - delS(decoded); - decodeTIS620_UTF8(out, decoded, olen); - olen = strlen(out); - decoded = out; - } - - int p = 0; - - if (octetLength > 0) - p = 100 * octetCount / octetLength; - - if ((p != readCount) && (p <= 100)) - { - readCount = p; - if (imap->_readCallback) - fetchReport(imap, p, (imap->_config->download.rfc822 && rfc822_body_subtype) || (!rfc822_body_subtype && ((cPart(imap)->msg_type == esp_mail_msg_type_html && imap->_config->download.html) || ((cPart(imap)->msg_type == esp_mail_msg_type_plain || cPart(imap)->msg_type == esp_mail_msg_type_enriched) && imap->_config->download.text)))); - } - - if (cPart(imap)->text.length() < imap->_config->limit.msg_size) - { - - if (cPart(imap)->text.length() + olen < imap->_config->limit.msg_size) - { - cPart(imap)->textLen += olen; - cPart(imap)->text.append(decoded, olen); - } - else - { - int d = imap->_config->limit.msg_size - cPart(imap)->text.length(); - cPart(imap)->textLen += d; - if (d > 0) - cPart(imap)->text.append(decoded, d); - } - } - } - - if (filePath.length() > 0) - { - if (!cPart(imap)->file_open_write) - { - cPart(imap)->file_open_write = true; - - if (_sdOk || _flashOk) - { - downloadRequest = true; - - if (imap->_storageType == esp_mail_file_storage_type_sd) - file = ESP_MAIL_SD_FS.open(filePath.c_str(), FILE_WRITE); - else if (imap->_storageType == esp_mail_file_storage_type_flash) -#if defined(ESP32) - file = ESP_MAIL_FLASH_FS.open(filePath.c_str(), FILE_WRITE); -#elif defined(ESP8266) - file = ESP_MAIL_FLASH_FS.open(filePath.c_str(), "w"); -#endif - } - } - - if (_sdOk || _flashOk) - file.write((const uint8_t *)decoded, olen); - } - - if (newC) - delS(decoded); - } - } - } -} -void ESP_Mail_Client::prepareFilePath(IMAPSession *imap, std::string &filePath, bool header) -{ - bool rfc822_body_subtype = cPart(imap)->message_sub_type == esp_mail_imap_message_sub_type_rfc822; - std::string fpath = imap->_config->storage.saved_path; - appendP(fpath, esp_mail_str_202, false); - char *tmp = intStr(cMSG(imap)); - fpath += tmp; - delS(tmp); - - if (imap->_storageType == esp_mail_file_storage_type_sd) - if (!ESP_MAIL_SD_FS.exists(fpath.c_str())) - createDirs(fpath); - - if (header) - { - appendP(fpath, esp_mail_str_203, false); - } - else - { - if (!rfc822_body_subtype) - { - appendP(fpath, esp_mail_str_161, false); - if (cPart(imap)->msg_type == esp_mail_msg_type_plain || cPart(imap)->msg_type == esp_mail_msg_type_enriched) - appendP(fpath, esp_mail_str_95, false); - else if (cPart(imap)->msg_type == esp_mail_msg_type_html) - appendP(fpath, esp_mail_str_94, false); - } - else - { - appendP(fpath, esp_mail_str_163, false); - - if (cPart(imap)->rfc822_msg_Idx > 0) - { - char *tmp = intStr(cPart(imap)->rfc822_msg_Idx); - fpath += tmp; - delS(tmp); - } - - if (cPart(imap)->msg_type == esp_mail_msg_type_plain || cPart(imap)->msg_type == esp_mail_msg_type_enriched) - appendP(fpath, esp_mail_str_95, false); - else if (cPart(imap)->msg_type == esp_mail_msg_type_html) - appendP(fpath, esp_mail_str_94, false); - else - //possible rfc822 encapsulated message which cannot fetch its header - appendP(fpath, esp_mail_str_40, false); - } - } - - filePath = fpath; -} - -char *ESP_Mail_Client::strReplace(char *orig, char *rep, char *with) -{ - char *result = nullptr; - char *ins = nullptr; - char *tmp = nullptr; - int len_rep; - int len_with; - int len_front; - int count; - - len_with = strlen(with); - len_rep = strlen(rep); - - ins = orig; - for (count = 0; (tmp = strstr(ins, rep)); ++count) - ins = tmp + len_rep; - - tmp = result = newS(strlen(orig) + (len_with - len_rep) * count + 1); - while (count--) - { - ins = strstr(orig, rep); - len_front = ins - orig; - tmp = strncpy(tmp, orig, len_front) + len_front; - tmp = strcpy(tmp, with) + len_with; - orig += len_front + len_rep; - } - strcpy(tmp, orig); - return result; -} - -int ESP_Mail_Client::decodeChar(const char *s) -{ - assert(s); - assert(*s == '='); - return 16 * hexval(*(s + 1)) + hexval(*(s + 2)); -} - -void ESP_Mail_Client::decodeQP(const char *buf, char *out) -{ - char *tmp = strP(esp_mail_str_295); - while (*buf) - { - if (*buf != '=') - strcat_c(out, *buf++); - else if (*(buf + 1) == '\r' && *(buf + 2) == '\n') - buf += 3; - else if (*(buf + 1) == '\n') - buf += 2; - else if (!strchr(tmp, *(buf + 1))) - strcat_c(out, *buf++); - else if (!strchr(tmp, *(buf + 2))) - strcat_c(out, *buf++); - else - { - strcat_c(out, decodeChar(buf)); - buf += 3; - } - } - delS(tmp); -} - -std::string ESP_Mail_Client::getBoundary(size_t len) -{ - char *tmp = strP(boundary_table); - char *buf = newS(len); - if (len) - { - --len; - buf[0] = tmp[0]; - buf[1] = tmp[1]; - for (size_t n = 2; n < len; n++) - { - int key = rand() % (int)(strlen(tmp) - 1); - buf[n] = tmp[key]; - } - buf[len] = '\0'; - } - std::string s = buf; - delS(buf); - delS(tmp); - return s; -} - -char *ESP_Mail_Client::decode7Bit(char *buf) -{ - char *out = strReplaceP(buf, imap_7bit_key1, imap_7bit_val1); - char *tmp = newS(strlen(out) + 10); - strcpy(tmp, out); - delS(out); - out = strReplaceP(tmp, imap_7bit_key2, imap_7bit_val2); - - delS(tmp); - tmp = newS(strlen(out) + 10); - strcpy(tmp, out); - delS(out); - out = strReplaceP(tmp, imap_7bit_key3, imap_7bit_val3); - - delS(tmp); - tmp = newS(strlen(out) + 10); - strcpy(tmp, out); - delS(out); - out = strReplaceP(tmp, imap_7bit_key4, imap_7bit_val4); - - delS(tmp); - tmp = newS(strlen(out) + 10); - strcpy(tmp, out); - delS(out); - out = strReplaceP(tmp, imap_7bit_key5, imap_7bit_val5); - - delS(tmp); - tmp = newS(strlen(out) + 10); - strcpy(tmp, out); - delS(out); - out = strReplaceP(tmp, imap_7bit_key6, imap_7bit_val6); - - delS(tmp); - tmp = newS(strlen(out) + 10); - strcpy(tmp, out); - delS(out); - out = strReplaceP(tmp, imap_7bit_key7, imap_7bit_val7); - - delS(tmp); - tmp = newS(strlen(out) + 10); - strcpy(tmp, out); - delS(out); - out = strReplaceP(tmp, imap_7bit_key8, imap_7bit_val8); - - delS(tmp); - tmp = newS(strlen(out) + 10); - strcpy(tmp, out); - delS(out); - out = strReplaceP(tmp, imap_7bit_key9, imap_7bit_val9); - - delS(tmp); - tmp = newS(strlen(out) + 10); - strcpy(tmp, out); - delS(out); - out = strReplaceP(tmp, imap_7bit_key10, imap_7bit_val10); - - delS(tmp); - tmp = newS(strlen(out) + 10); - strcpy(tmp, out); - delS(out); - out = strReplaceP(tmp, imap_7bit_key11, imap_7bit_val11); - - delS(tmp); - tmp = newS(strlen(out) + 10); - strcpy(tmp, out); - delS(out); - out = strReplaceP(tmp, imap_7bit_key12, imap_7bit_val12); - - delS(tmp); - tmp = newS(strlen(out) + 10); - strcpy(tmp, out); - delS(out); - out = strReplaceP(tmp, imap_7bit_key13, imap_7bit_val13); - delS(tmp); - return out; -} - -char *ESP_Mail_Client::strReplaceP(char *buf, PGM_P name, PGM_P value) -{ - char *n = strP(name); - char *v = strP(value); - char *out = strReplace(buf, n, v); - delS(n); - delS(v); - return out; -} - -void ESP_Mail_Client::handleCapability(IMAPSession *imap, char *buf, int &chunkIdx) -{ - if (chunkIdx == 0) - { - if (strposP(buf, esp_mail_imap_response_10, 0) > -1) - { - if (strposP(buf, esp_mail_imap_response_11, 0) > -1) - imap->_auth_capability.login = true; - if (strposP(buf, esp_mail_imap_response_12, 0) > -1) - imap->_auth_capability.plain = true; - if (strposP(buf, esp_mail_imap_response_13, 0) > -1) - imap->_auth_capability.xoauth2 = true; - if (strposP(buf, esp_mail_imap_response_14, 0) > -1) - imap->_auth_capability.start_tls = true; - if (strposP(buf, esp_mail_imap_response_15, 0) > -1) - imap->_auth_capability.cram_md5 = true; - if (strposP(buf, esp_mail_imap_response_16, 0) > -1) - imap->_auth_capability.digest_md5 = true; - } - } -} - -bool ESP_Mail_Client::authFailed(char *buf, int bufLen, int &chunkIdx, int ofs) -{ - bool ret = false; - if (chunkIdx == 0) - { - size_t olen; - unsigned char *decoded = decodeBase64((const unsigned char *)(buf + ofs), bufLen - ofs, &olen); - if (decoded) - { - ret = strposP((char *)decoded, esp_mail_str_294, 0) > -1; - delete[] decoded; - } - chunkIdx++; - } - return ret; -} - -void ESP_Mail_Client::handleFolders(IMAPSession *imap, char *buf) -{ - struct esp_mail_folder_info_t fd; - char *tmp = nullptr; - int p1 = strposP(buf, esp_mail_imap_response_4, 0); - int p2 = 0; - if (p1 != -1) - { - p1 = strposP(buf, esp_mail_str_198, 0); - if (p1 != -1) - { - p2 = strposP(buf, esp_mail_str_192, p1 + 1); - if (p2 != -1) - { - tmp = newS(p2 - p1); - strncpy(tmp, buf + p1 + 1, p2 - p1 - 1); - if (tmp[p2 - p1 - 2] == '\r') - tmp[p2 - p1 - 2] = 0; - fd.attributes = tmp; - delS(tmp); - } - } - - p1 = strposP(buf, esp_mail_str_136, 0); - if (p1 != -1) - { - p2 = strposP(buf, esp_mail_str_136, p1 + 1); - if (p2 != -1) - { - tmp = newS(p2 - p1); - strncpy(tmp, buf + p1 + 1, p2 - p1 - 1); - if (tmp[p2 - p1 - 2] == '\r') - tmp[p2 - p1 - 2] = 0; - fd.delimiter = tmp; - delS(tmp); - } - } - - p1 = strposP(buf, esp_mail_str_131, p2); - if (p1 != -1) - { - p2 = strlen(buf); - tmp = newS(p2 - p1); - if (buf[p1 + 1] == '"') - p1++; - strncpy(tmp, buf + p1 + 1, p2 - p1 - 1); - if (tmp[p2 - p1 - 2] == '\r') - tmp[p2 - p1 - 2] = 0; - if (tmp[strlen(tmp) - 1] == '"') - tmp[strlen(tmp) - 1] = 0; - fd.name = tmp; - delS(tmp); - } - imap->_folders.add(fd); - } -} - -void ESP_Mail_Client::handleExamine(IMAPSession *imap, char *buf) -{ - char *tmp = nullptr; - int p1, p2; - - if (imap->_mbif._msgCount == 0) - { - p1 = strposP(buf, esp_mail_str_199, 0); - if (p1 != -1) - { - tmp = newS(p1); - strncpy(tmp, buf + 2, p1 - 1); - imap->_mbif._msgCount = atoi(tmp); - delS(tmp); - return; - } - } - - if (imap->_mbif._flags.size() == 0) - { - p1 = strposP(buf, esp_mail_imap_response_5, 0); - if (p1 != -1) - { - p1 = strposP(buf, esp_mail_str_198, 0); - if (p1 != -1) - { - p2 = strposP(buf, esp_mail_str_192, p1 + 1); - if (p2 != -1) - { - tmp = newS(p2 - p1); - strncpy(tmp, buf + p1 + 1, p2 - p1 - 1); - char *stk = strP(esp_mail_str_131); - char *end_token; - char *token = strtok_r(tmp, stk, &end_token); - while (token != NULL) - { - imap->_mbif.addFlag(token); - token = strtok_r(NULL, stk, &end_token); - } - if (token) - delS(token); - delS(tmp); - delS(stk); - } - } - return; - } - } - - if (imap->_nextUID.length() == 0) - { - p1 = strposP(buf, esp_mail_str_200, 0); - if (p1 != -1) - { - p2 = strposP(buf, esp_mail_str_156, p1 + strlen_P(esp_mail_str_200)); - if (p2 != -1) - { - tmp = newS(p2 - p1 - strlen_P(esp_mail_str_200) + 1); - strncpy(tmp, buf + p1 + strlen_P(esp_mail_str_200), p2 - p1 - strlen_P(esp_mail_str_200)); - imap->_nextUID = tmp; - imap->_mbif._nextUID = atoi(tmp); - delS(tmp); - } - return; - } - } -} - -bool ESP_Mail_Client::handleIMAPError(IMAPSession *imap, int err, bool ret) -{ - if (err < 0) - { - errorStatusCB(imap, err); - - if (imap->_headers.size() > 0) - { - if ((imap->_imap_cmd == esp_mail_imap_cmd_fetch_body_attachment || imap->_imap_cmd == esp_mail_imap_cmd_fetch_body_inline) && (imap->_config->download.attachment || imap->_config->download.inlineImg)) - { - if (cHeader(imap)->part_headers.size() > 0) - cPart(imap)->download_error = imap->errorReason().c_str(); - } - else - cHeader(imap)->error_msg = imap->errorReason().c_str(); - - cHeader(imap)->error = true; - } - } - - if (imap->_tcpConnected) - closeTCP(imap); - - imap->_cbData.empty(); - - return ret; -} - -unsigned char *ESP_Mail_Client::decodeBase64(const unsigned char *src, size_t len, size_t *out_len) -{ - - unsigned char *out, *pos, block[4], tmp; - size_t i, count, olen; - int pad = 0; - size_t extra_pad; - - unsigned char *dtable = new unsigned char[256]; - - memset(dtable, 0x80, 256); - - for (i = 0; i < sizeof(b64_index_table) - 1; i++) - dtable[b64_index_table[i]] = (unsigned char)i; - dtable['='] = 0; - - count = 0; - for (i = 0; i < len; i++) - { - if (dtable[src[i]] != 0x80) - count++; - } - - if (count == 0) - goto exit; - extra_pad = (4 - count % 4) % 4; - - olen = (count + extra_pad) / 4 * 3; - pos = out = (unsigned char *)malloc(olen); - if (out == NULL) - goto exit; - - count = 0; - for (i = 0; i < len + extra_pad; i++) - { - unsigned char val; - - if (i >= len) - val = '='; - else - val = src[i]; - tmp = dtable[val]; - if (tmp == 0x80) - continue; - - if (val == '=') - pad++; - block[count] = tmp; - count++; - if (count == 4) - { - *pos++ = (block[0] << 2) | (block[1] >> 4); - *pos++ = (block[1] << 4) | (block[2] >> 2); - *pos++ = (block[2] << 6) | block[3]; - count = 0; - if (pad) - { - if (pad == 1) - pos--; - else if (pad == 2) - pos -= 2; - else - { - free(out); - goto exit; - } - break; - } - } - } - - *out_len = pos - out; - delete[] dtable; - return out; -exit: - delete[] dtable; - return nullptr; -} - -std::string ESP_Mail_Client::encodeBase64Str(const unsigned char *src, size_t len) -{ - return encodeBase64Str((uint8_t *)src, len); -} - -std::string ESP_Mail_Client::encodeBase64Str(uint8_t *src, size_t len) -{ - std::string outStr; - unsigned char *out, *pos; - const unsigned char *end, *in; - size_t olen = 4 * ((len + 2) / 3); - if (olen < len) - return outStr; - - outStr.resize(olen); - out = (unsigned char *)&outStr[0]; - - end = src + len; - in = src; - pos = out; - - while (end - in >= 3) - { - *pos++ = b64_index_table[in[0] >> 2]; - *pos++ = b64_index_table[((in[0] & 0x03) << 4) | (in[1] >> 4)]; - *pos++ = b64_index_table[((in[1] & 0x0f) << 2) | (in[2] >> 6)]; - *pos++ = b64_index_table[in[2] & 0x3f]; - in += 3; - } - - if (end - in) - { - *pos++ = b64_index_table[in[0] >> 2]; - if (end - in == 1) - { - *pos++ = b64_index_table[(in[0] & 0x03) << 4]; - *pos++ = '='; - } - else - { - *pos++ = b64_index_table[((in[0] & 0x03) << 4) | (in[1] >> 4)]; - *pos++ = b64_index_table[(in[1] & 0x0f) << 2]; - } - *pos++ = '='; - } - - return outStr; -} - -void ESP_Mail_Client::encodeQP(const char *buf, char *out) -{ - int n = 0, p = 0, pos = 0; - assert(buf); - for (n = 0; *buf; buf++) - { - if (n >= 73 && *buf != 10 && *buf != 13) - { - p = sprintf(out + pos, "=\r\n"); - pos += p; - n = 0; - } - - if (*buf == 10 || *buf == 13) - { - strcat_c(out, *buf); - pos++; - n = 0; - } - else if (*buf < 32 || *buf == 61 || *buf > 126) - { - p = sprintf(out + pos, "=%02X", (unsigned char)*buf); - n += p; - pos += p; - } - else if (*buf != 32 || (*(buf + 1) != 10 && *(buf + 1) != 13)) - { - strcat_c(out, *buf); - n++; - pos++; - } - else - { - p = sprintf(out + pos, "=20"); - n += p; - pos += p; - } - } -} - -bool ESP_Mail_Client::sendBase64(SMTPSession *smtp, SMTP_Message *msg, const unsigned char *data, size_t len, bool flashMem, const char *filename, bool report) -{ - bool ret = false; - const unsigned char *end, *in; - - size_t olen = 4 * ((len + 2) / 3); - - if (olen < len) - return false; - - end = data + len; - in = data; - - size_t chunkSize = 936; - size_t byteAdded = 0; - size_t byteSent = 0; - - int dByte = 0; - unsigned char *buf = new unsigned char[chunkSize]; - memset(buf, 0, chunkSize); - - unsigned char *tmp = new unsigned char[3]; - int bcnt = 0; - int pg = 0, _pg = 0; - - if (report) - uploadReport(filename, bcnt); - - while (end - in >= 3) - { - - memset(tmp, 0, 3); - if (flashMem) - memcpy_P(tmp, in, 3); - else - memcpy(tmp, in, 3); - bcnt += 3; - - buf[byteAdded++] = b64_index_table[tmp[0] >> 2]; - buf[byteAdded++] = b64_index_table[((tmp[0] & 0x03) << 4) | (tmp[1] >> 4)]; - buf[byteAdded++] = b64_index_table[((tmp[1] & 0x0f) << 2) | (tmp[2] >> 6)]; - buf[byteAdded++] = b64_index_table[tmp[2] & 0x3f]; - dByte += 4; - if (dByte == BASE64_CHUNKED_LEN) - { - if (byteAdded + 1 < chunkSize) - { - buf[byteAdded++] = 0x0d; - buf[byteAdded++] = 0x0a; - } - dByte = 0; - } - if (byteAdded >= chunkSize - 4) - { - byteSent += byteAdded; - - if (!bdat(smtp, msg, byteAdded, false)) - goto ex; - - if (smtpSend(smtp, buf, byteAdded) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - goto ex; - memset(buf, 0, chunkSize); - byteAdded = 0; - } - in += 3; - - if (report) - { - pg = (float)(100.0f * bcnt / len); - if (pg != _pg) - uploadReport(filename, pg); - _pg = pg; - } - } - - if (byteAdded > 0) - { - if (!bdat(smtp, msg, byteAdded, false)) - goto ex; - - if (smtpSend(smtp, buf, byteAdded) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - goto ex; - } - - if (end - in) - { - memset(buf, 0, chunkSize); - byteAdded = 0; - memset(tmp, 0, 3); - if (flashMem) - { - if (end - in == 1) - memcpy_P(tmp, in, 1); - else - memcpy_P(tmp, in, 2); - } - else - { - if (end - in == 1) - memcpy(tmp, in, 1); - else - memcpy(tmp, in, 2); - } - - buf[byteAdded++] = b64_index_table[tmp[0] >> 2]; - if (end - in == 1) - { - buf[byteAdded++] = b64_index_table[(tmp[0] & 0x03) << 4]; - buf[byteAdded++] = '='; - } - else - { - buf[byteAdded++] = b64_index_table[((tmp[0] & 0x03) << 4) | (tmp[1] >> 4)]; - buf[byteAdded++] = b64_index_table[(tmp[1] & 0x0f) << 2]; - } - buf[byteAdded++] = '='; - - if (!bdat(smtp, msg, byteAdded, false)) - goto ex; - - if (smtpSend(smtp, buf, byteAdded) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - goto ex; - memset(buf, 0, chunkSize); - } - - if (report && _pg < 100) - uploadReport(filename, 100); - - ret = true; -ex: - if (report) - esp_mail_debug(""); - delete[] tmp; - delete[] buf; - return ret; -} - -bool ESP_Mail_Client::sendBase64Stream(SMTPSession *smtp, SMTP_Message *msg, File file, const char *filename, bool report) -{ - bool ret = false; - - if (!file) - { - errorStatusCB(smtp, MAIL_CLIENT_ERROR_FILE_IO_ERROR); - return false; - } - - size_t chunkSize = 936; - size_t byteAdded = 0; - size_t byteSent = 0; - - unsigned char *buf = new unsigned char[chunkSize]; - memset(buf, 0, chunkSize); - - size_t len = file.size(); - size_t fbufIndex = 0; - unsigned char *fbuf = new unsigned char[3]; - - int dByte = 0; - - int bcnt = 0; - int pg = 0, _pg = 0; - - if (report) - uploadReport(filename, bcnt); - - while (file.available()) - { - memset(fbuf, 0, 3); - if (len - fbufIndex >= 3) - { - bcnt += 3; - size_t readLen = file.read(fbuf, 3); - if (readLen != 3) - { - errorStatusCB(smtp, MAIL_CLIENT_ERROR_FILE_IO_ERROR); - break; - } - - buf[byteAdded++] = b64_index_table[fbuf[0] >> 2]; - buf[byteAdded++] = b64_index_table[((fbuf[0] & 0x03) << 4) | (fbuf[1] >> 4)]; - buf[byteAdded++] = b64_index_table[((fbuf[1] & 0x0f) << 2) | (fbuf[2] >> 6)]; - buf[byteAdded++] = b64_index_table[fbuf[2] & 0x3f]; - dByte += 4; - if (dByte == BASE64_CHUNKED_LEN) - { - if (byteAdded + 1 < chunkSize) - { - buf[byteAdded++] = 0x0d; - buf[byteAdded++] = 0x0a; - } - dByte = 0; - } - if (byteAdded >= chunkSize - 4) - { - byteSent += byteAdded; - - if (!bdat(smtp, msg, byteAdded, false)) - goto ex; - - if (smtpSend(smtp, buf, byteAdded) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - goto ex; - - memset(buf, 0, chunkSize); - byteAdded = 0; - } - fbufIndex += 3; - - if (report) - { - pg = (float)(100.0f * bcnt / len); - if (pg != _pg) - uploadReport(filename, pg); - _pg = pg; - } - } - else - { - size_t readLen = file.read(fbuf, len - fbufIndex); - if (readLen != len - fbufIndex) - { - errorStatusCB(smtp, MAIL_CLIENT_ERROR_FILE_IO_ERROR); - break; - } - } - } - - file.close(); - if (byteAdded > 0) - { - if (!bdat(smtp, msg, byteAdded, false)) - goto ex; - - if (smtpSend(smtp, buf, byteAdded) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - goto ex; - } - - if (len - fbufIndex > 0) - { - memset(buf, 0, chunkSize); - byteAdded = 0; - buf[byteAdded++] = b64_index_table[fbuf[0] >> 2]; - if (len - fbufIndex == 1) - { - buf[byteAdded++] = b64_index_table[(fbuf[0] & 0x03) << 4]; - buf[byteAdded++] = '='; - } - else - { - buf[byteAdded++] = b64_index_table[((fbuf[0] & 0x03) << 4) | (fbuf[1] >> 4)]; - buf[byteAdded++] = b64_index_table[(fbuf[1] & 0x0f) << 2]; - } - buf[byteAdded++] = '='; - - if (!bdat(smtp, msg, byteAdded, false)) - goto ex; - - if (smtpSend(smtp, buf, byteAdded) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - goto ex; - } - ret = true; - - if (report && _pg < 100) - uploadReport(filename, 100); - -ex: - delete[] buf; - delete[] fbuf; - file.close(); - return ret; -} - -IMAPSession::IMAPSession() {} -IMAPSession::~IMAPSession() -{ - empty(); - _caCert.reset(); - _caCert = nullptr; -} - -bool IMAPSession::closeSession() -{ - if (!_tcpConnected) - return false; -#if defined(ESP32) - /** - * The strange behavior in ESP8266 SSL client, BearSSLWiFiClientSecure - * The client disposed without memory released after the server close - * the connection due to LOGOUT command, which caused the memory leaks. - */ - if (!MailClient.imapLogout(this)) - return false; -#endif - return MailClient.handleIMAPError(this, 0, true); -} - -bool IMAPSession::connect(ESP_Mail_Session *sesssion, IMAP_Config *config) -{ - if (_tcpConnected) - MailClient.closeTCP(this); - - _sesson_cfg = sesssion; - _config = config; - _caCert = nullptr; - - if (strlen(_sesson_cfg->certificate.cert_data) > 0) - _caCert = std::shared_ptr(_sesson_cfg->certificate.cert_data); - - if (strlen(_sesson_cfg->certificate.cert_file) > 0) - { - if (_sesson_cfg->certificate.cert_file_storage_type == esp_mail_file_storage_type::esp_mail_file_storage_type_sd && !MailClient._sdOk) - MailClient._sdOk = MailClient.sdTest(); - if (_sesson_cfg->certificate.cert_file_storage_type == esp_mail_file_storage_type::esp_mail_file_storage_type_flash && !MailClient._flashOk) -#if defined(ESP32) - MailClient._flashOk = ESP_MAIL_FLASH_FS.begin(FORMAT_FLASH); -#elif defined(ESP8266) - MailClient._flashOk = ESP_MAIL_FLASH_FS.begin(); -#endif - } - - return MailClient.imapAuth(this); -} - -void IMAPSession::debug(int level) -{ - if (level > esp_mail_debug_level_0) - { - if (level > esp_mail_debug_level_3) - level = esp_mail_debug_level_1; - _debugLevel = level; - _debug = true; - } - else - { - _debugLevel = esp_mail_debug_level_0; - _debug = false; - } -} - -String IMAPSession::errorReason() -{ - std::string ret; - - if (_imapStatus.text.length() > 0) - return _imapStatus.text.c_str(); - - switch (_imapStatus.statusCode) - { - case IMAP_STATUS_SERVER_CONNECT_FAILED: - MailClient.appendP(ret, esp_mail_str_38, true); - break; - case MAIL_CLIENT_ERROR_CONNECTION_LOST: - MailClient.appendP(ret, esp_mail_str_221, true); - break; - case MAIL_CLIENT_ERROR_READ_TIMEOUT: - MailClient.appendP(ret, esp_mail_str_258, true); - break; - case MAIL_CLIENT_ERROR_SERVER_CONNECTION_FAILED: - MailClient.appendP(ret, esp_mail_str_305, true); - break; - case IMAP_STATUS_NO_MESSAGE: - MailClient.appendP(ret, esp_mail_str_306, true); - break; - case IMAP_STATUS_ERROR_DOWNLAD_TIMEOUT: - MailClient.appendP(ret, esp_mail_str_93, true); - break; - case MAIL_CLIENT_ERROR_SSL_TLS_STRUCTURE_SETUP: - MailClient.appendP(ret, esp_mail_str_132, true); - break; - case IMAP_STATUS_CLOSE_MAILBOX_FAILED: - MailClient.appendP(ret, esp_mail_str_188, true); - break; - case IMAP_STATUS_OPEN_MAILBOX_FAILED: - MailClient.appendP(ret, esp_mail_str_281, true); - break; - case IMAP_STATUS_LIST_MAILBOXS_FAILED: - MailClient.appendP(ret, esp_mail_str_62, true); - break; - case IMAP_STATUS_NO_SUPPORTED_AUTH: - MailClient.appendP(ret, esp_mail_str_42, true); - break; - case IMAP_STATUS_CHECK_CAPABILITIES_FAILED: - MailClient.appendP(ret, esp_mail_str_63, true); - break; - case MAIL_CLIENT_ERROR_OUT_OF_MEMORY: - MailClient.appendP(ret, esp_mail_str_186, true); - break; - case IMAP_STATUS_NO_MAILBOX_FOLDER_OPENED: - MailClient.appendP(ret, esp_mail_str_153, true); - break; - - default: - break; - } - return ret.c_str(); -} - -bool IMAPSession::selectFolder(const char *folderName, bool readOnly) -{ - if (_tcpConnected) - { - if (!openFolder(folderName, readOnly)) - return false; - } - else - { - _currentFolder = folderName; - } - return true; -} - -bool IMAPSession::openFolder(const char *folderName, bool readOnly) -{ - if (!_tcpConnected) - return false; - if (readOnly) - return openMailbox(folderName, esp_mail_imap_auth_mode::esp_mail_imap_mode_examine, true); - else - return openMailbox(folderName, esp_mail_imap_auth_mode::esp_mail_imap_mode_select, true); -} - -bool IMAPSession::getFolders(FoldersCollection &folders) -{ - if (!_tcpConnected) - return false; - return getMailboxes(folders); -} - -bool IMAPSession::closeFolder(const char *folderName) -{ - if (!_tcpConnected) - return false; - return closeMailbox(); -} - -void IMAPSession::checkUID() -{ - if (MailClient.strcmpP(_config->fetch.uid, 0, esp_mail_str_140) || MailClient.strcmpP(_config->fetch.uid, 0, esp_mail_str_212) || - MailClient.strcmpP(_config->fetch.uid, 0, esp_mail_str_213) || MailClient.strcmpP(_config->fetch.uid, 0, esp_mail_str_214) || MailClient.strcmpP(_config->fetch.uid, 0, esp_mail_str_215) || - MailClient.strcmpP(_config->fetch.uid, 0, esp_mail_str_216) || MailClient.strcmpP(_config->fetch.uid, 0, esp_mail_str_217) || MailClient.strcmpP(_config->fetch.uid, 0, esp_mail_str_218) || - MailClient.strcmpP(_config->fetch.uid, 0, esp_mail_str_219) || MailClient.strcmpP(_config->fetch.uid, 0, esp_mail_str_220)) - _config->fetch.uid = "*"; -} - -void IMAPSession::checkPath() -{ - std::string path = _config->storage.saved_path; - if (path[0] != '/') - { - path = "/"; - path += _config->storage.saved_path; - path = path.c_str(); - } -} - -bool IMAPSession::headerOnly() -{ - return _headerOnly; -} - -struct esp_mail_imap_msg_list_t IMAPSession::data() -{ - struct esp_mail_imap_msg_list_t ret; - - for (size_t i = 0; i < _headers.size(); i++) - { - if (ESP.getFreeHeap() < ESP_MAIL_MIN_MEM) - continue; - - struct esp_mail_imap_msg_item_t itm; - - itm.UID = _headers[i].message_uid.c_str(); - itm.ID = _headers[i].message_id.c_str(); - itm.msgNo = _headers[i].message_no.c_str(); - itm.from = _headers[i].from.c_str(); - itm.fromCharset = _headers[i].from_charset.c_str(); - itm.to = _headers[i].to.c_str(); - itm.toCharset = _headers[i].to_charset.c_str(); - itm.cc = _headers[i].cc.c_str(); - itm.ccCharset = _headers[i].cc_charset.c_str(); - itm.subject = _headers[i].subject.c_str(); - itm.subjectCharset = _headers[i].subject_charset.c_str(); - itm.date = _headers[i].date.c_str(); - itm.fetchError = _headers[i].error_msg.c_str(); - - getMessages(i, itm); - - getRFC822Messages(i, itm); - - ret.msgItems.push_back(itm); - } - - return ret; -} - -SelectedFolderInfo IMAPSession::selectedFolder() -{ - return _mbif; -} - -void IMAPSession::callback(imapStatusCallback imapCallback) -{ - _readCallback = std::move(imapCallback); -} - -void IMAPSession::getMessages(uint16_t messageIndex, struct esp_mail_imap_msg_item_t &msg) -{ - msg.text.content = ""; - msg.text.charSet = ""; - msg.text.content_type = ""; - msg.text.transfer_encoding = ""; - msg.html.content = ""; - msg.html.charSet = ""; - msg.html.content_type = ""; - msg.html.transfer_encoding = ""; - - if (messageIndex < _headers.size()) - { - int sz = _headers[messageIndex].part_headers.size(); - if (sz > 0) - { - for (int i = 0; i < sz; i++) - { - if (!_headers[messageIndex].part_headers[i].rfc822_part && _headers[messageIndex].part_headers[i].message_sub_type != esp_mail_imap_message_sub_type_rfc822) - { - if (_headers[messageIndex].part_headers[i].attach_type == esp_mail_att_type_none) - { - if (_headers[messageIndex].part_headers[i].msg_type == esp_mail_msg_type_plain || _headers[messageIndex].part_headers[i].msg_type == esp_mail_msg_type_enriched) - { - msg.text.content = _headers[messageIndex].part_headers[i].text.c_str(); - msg.text.charSet = _headers[messageIndex].part_headers[i].charset.c_str(); - msg.text.content_type = _headers[messageIndex].part_headers[i].content_type.c_str(); - msg.text.transfer_encoding = _headers[messageIndex].part_headers[i].content_transfer_encoding.c_str(); - } - - if (_headers[messageIndex].part_headers[i].msg_type == esp_mail_msg_type_html) - { - msg.html.content = _headers[messageIndex].part_headers[i].text.c_str(); - msg.html.charSet = _headers[messageIndex].part_headers[i].charset.c_str(); - msg.html.content_type = _headers[messageIndex].part_headers[i].content_type.c_str(); - msg.html.transfer_encoding = _headers[messageIndex].part_headers[i].content_transfer_encoding.c_str(); - } - } - else - { - struct esp_mail_attacment_info_t att; - att.filename = _headers[messageIndex].part_headers[i].filename.c_str(); - att.mime = _headers[messageIndex].part_headers[i].content_type.c_str(); - att.name = _headers[messageIndex].part_headers[i].name.c_str(); - att.size = _headers[messageIndex].part_headers[i].attach_data_size; - att.creationDate = _headers[messageIndex].part_headers[i].creation_date.c_str(); - att.type = _headers[messageIndex].part_headers[i].attach_type; - msg.attachments.push_back(att); - } - } - } - } - } -} - -void IMAPSession::getRFC822Messages(uint16_t messageIndex, struct esp_mail_imap_msg_item_t &msg) -{ - if (messageIndex < _headers.size()) - { - int sz = _headers[messageIndex].part_headers.size(); - int partIdx = 0; - int cIdx = 0; - IMAP_MSG_Item *_rfc822 = nullptr; - if (sz > 0) - { - for (int i = 0; i < sz; i++) - { - if (_headers[messageIndex].part_headers[i].message_sub_type == esp_mail_imap_message_sub_type_rfc822) - { - if (_headers[messageIndex].part_headers[i].rfc822_part) - { - if (partIdx > 0) - msg.rfc822.push_back(*_rfc822); - cIdx = i; - partIdx++; - _rfc822 = new IMAP_MSG_Item(); - - _rfc822->from = _headers[messageIndex].part_headers[i].rfc822_header.from.c_str(); - _rfc822->sender = _headers[messageIndex].part_headers[i].rfc822_header.sender.c_str(); - _rfc822->to = _headers[messageIndex].part_headers[i].rfc822_header.to.c_str(); - _rfc822->cc = _headers[messageIndex].part_headers[i].rfc822_header.cc.c_str(); - _rfc822->bcc = _headers[messageIndex].part_headers[i].rfc822_header.bcc.c_str(); - _rfc822->return_path = _headers[messageIndex].part_headers[i].rfc822_header.return_path.c_str(); - _rfc822->reply_to = _headers[messageIndex].part_headers[i].rfc822_header.reply_to.c_str(); - _rfc822->subject = _headers[messageIndex].part_headers[i].rfc822_header.subject.c_str(); - _rfc822->comment = _headers[messageIndex].part_headers[i].rfc822_header.comment.c_str(); - _rfc822->keyword = _headers[messageIndex].part_headers[i].rfc822_header.keyword.c_str(); - _rfc822->date = _headers[messageIndex].part_headers[i].rfc822_header.date.c_str(); - _rfc822->messageID = _headers[messageIndex].part_headers[i].rfc822_header.messageID.c_str(); - _rfc822->text.charSet = ""; - _rfc822->text.content_type = ""; - _rfc822->text.transfer_encoding = ""; - _rfc822->html.charSet = ""; - _rfc822->html.content_type = ""; - _rfc822->html.transfer_encoding = ""; - } - else - { - if (MailClient.multipartMember(_headers[messageIndex].part_headers[cIdx].partNumStr, _headers[messageIndex].part_headers[i].partNumStr)) - { - if (_headers[messageIndex].part_headers[i].attach_type == esp_mail_att_type_none) - { - if (_headers[messageIndex].part_headers[i].msg_type == esp_mail_msg_type_plain || _headers[messageIndex].part_headers[i].msg_type == esp_mail_msg_type_enriched) - { - _rfc822->text.charSet = _headers[messageIndex].part_headers[i].charset.c_str(); - _rfc822->text.content_type = _headers[messageIndex].part_headers[i].content_type.c_str(); - _rfc822->text.content = _headers[messageIndex].part_headers[i].text.c_str(); - _rfc822->text.transfer_encoding = _headers[messageIndex].part_headers[i].content_transfer_encoding.c_str(); - } - if (_headers[messageIndex].part_headers[i].msg_type == esp_mail_msg_type_html) - { - _rfc822->html.charSet = _headers[messageIndex].part_headers[i].charset.c_str(); - _rfc822->html.content_type = _headers[messageIndex].part_headers[i].content_type.c_str(); - _rfc822->html.content = _headers[messageIndex].part_headers[i].text.c_str(); - _rfc822->html.transfer_encoding = _headers[messageIndex].part_headers[i].content_transfer_encoding.c_str(); - } - } - else - { - struct esp_mail_attacment_info_t att; - att.filename = _headers[messageIndex].part_headers[i].filename.c_str(); - att.mime = _headers[messageIndex].part_headers[i].content_type.c_str(); - att.name = _headers[messageIndex].part_headers[i].name.c_str(); - att.size = _headers[messageIndex].part_headers[i].attach_data_size; - att.creationDate = _headers[messageIndex].part_headers[i].creation_date.c_str(); - att.type = _headers[messageIndex].part_headers[i].attach_type; - _rfc822->attachments.push_back(att); - } - } - } - } - } - - if ((int)msg.rfc822.size() < partIdx && _rfc822 != nullptr) - msg.rfc822.push_back(*_rfc822); - } - } -} - -bool IMAPSession::closeMailbox() -{ - - if (!MailClient.reconnect(this)) - return false; - - std::string s; - - if (_readCallback) - { - MailClient.appendP(s, esp_mail_str_210, true); - s += _currentFolder; - MailClient.appendP(s, esp_mail_str_96, false); - MailClient.imapCB(this, "", false); - MailClient.imapCB(this, s.c_str(), false); - } - - if (_debug) - MailClient.debugInfoP(esp_mail_str_197); - - if (MailClient.imapSendP(this, esp_mail_str_195, true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return false; - _imap_cmd = esp_mail_imap_cmd_close; - if (!MailClient.handleIMAPResponse(this, IMAP_STATUS_CLOSE_MAILBOX_FAILED, false)) - return false; - - _currentFolder.clear(); - _mailboxOpened = false; - - return true; -} - -bool IMAPSession::openMailbox(const char *folder, esp_mail_imap_auth_mode mode, bool waitResponse) -{ - - if (!MailClient.reconnect(this)) - return false; - - if (_currentFolder.length() > 0) - { - if (strcmp(_currentFolder.c_str(), folder) != 0) - { - if (!closeMailbox()) - return false; - } - } - - _currentFolder = folder; - std::string s; - if (_readCallback) - { - MailClient.appendP(s, esp_mail_str_61, true); - s += _currentFolder; - MailClient.appendP(s, esp_mail_str_96, false); - MailClient.imapCB(this, "", false); - MailClient.imapCB(this, s.c_str(), false); - } - - if (_debug) - MailClient.debugInfoP(esp_mail_str_248); - - if (mode == esp_mail_imap_mode_examine) - { - MailClient.appendP(s, esp_mail_str_135, true); - _imap_cmd = esp_mail_imap_cmd_examine; - } - else if (mode == esp_mail_imap_mode_select) - { - MailClient.appendP(s, esp_mail_str_247, true); - _imap_cmd = esp_mail_imap_cmd_select; - } - s += _currentFolder; - MailClient.appendP(s, esp_mail_str_136, false); - if (MailClient.imapSend(this, s.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return false; - if (waitResponse) - { - - if (!MailClient.handleIMAPResponse(this, IMAP_STATUS_OPEN_MAILBOX_FAILED, false)) - return false; - } - - if (mode == esp_mail_imap_mode_examine) - _readOnlyMode = true; - else if (mode == esp_mail_imap_mode_select) - _readOnlyMode = false; - - _mailboxOpened = true; - - return true; -} - -bool IMAPSession::getMailboxes(FoldersCollection &folders) -{ - _folders.clear(); - - if (_readCallback) - { - MailClient.imapCB(this, "", false); - MailClient.imapCBP(this, esp_mail_str_58, false); - } - - if (_debug) - MailClient.debugInfoP(esp_mail_str_230); - - if (MailClient.imapSendP(this, esp_mail_str_133, true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return false; - _imap_cmd = esp_mail_imap_command::esp_mail_imap_cmd_list; - if (!MailClient.handleIMAPResponse(this, IMAP_STATUS_LIST_MAILBOXS_FAILED, false)) - return false; - - folders = _folders; - return true; -} - -bool IMAPSession::checkCapability() -{ - if (_readCallback) - { - MailClient.imapCB(this, "", false); - MailClient.imapCBP(this, esp_mail_str_64, false); - } - - if (_debug) - MailClient.debugInfoP(esp_mail_str_65); - - if (MailClient.imapSendP(this, esp_mail_str_2, true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return false; - - _imap_cmd = esp_mail_imap_command::esp_mail_imap_cmd_capability; - if (!MailClient.handleIMAPResponse(this, IMAP_STATUS_CHECK_CAPABILITIES_FAILED, false)) - return false; - - return true; -} - -bool IMAPSession::createFolder(const char *folderName) -{ - if (_debug) - { - MailClient.imapCB(this, "", false); - MailClient.debugInfoP(esp_mail_str_320); - } - - std::string cmd; - MailClient.appendP(cmd, esp_mail_str_322, true); - cmd += folderName; - - if (MailClient.imapSend(this, cmd.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return false; - - _imap_cmd = esp_mail_imap_command::esp_mail_imap_cmd_create; - if (!MailClient.handleIMAPResponse(this, IMAP_STATUS_BAD_COMMAND, false)) - return false; - - return true; -} - -bool IMAPSession::deleteFolder(const char *folderName) -{ - if (_debug) - { - MailClient.imapCB(this, "", false); - MailClient.debugInfoP(esp_mail_str_321); - } - - std::string cmd; - MailClient.appendP(cmd, esp_mail_str_323, true); - cmd += folderName; - - if (MailClient.imapSend(this, cmd.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return false; - - _imap_cmd = esp_mail_imap_command::esp_mail_imap_cmd_delete; - if (!MailClient.handleIMAPResponse(this, IMAP_STATUS_BAD_COMMAND, false)) - return false; - - return true; -} - -bool IMAPSession::deleteMessages(MessageList *toDelete, bool expunge) -{ - if (toDelete->_list.size() > 0) - { - - if (!selectFolder(_currentFolder.c_str(), false)) - return false; - - if (_debug) - { - MailClient.imapCB(this, "", false); - MailClient.debugInfoP(esp_mail_str_316); - } - - std::string cmd; - char *tmp = nullptr; - MailClient.appendP(cmd, esp_mail_str_249, true); - for (size_t i = 0; i < toDelete->_list.size(); i++) - { - if (i > 0) - MailClient.appendP(cmd, esp_mail_str_263, false); - tmp = MailClient.intStr(toDelete->_list[i]); - cmd += tmp; - MailClient.delS(tmp); - } - MailClient.appendP(cmd, esp_mail_str_315, false); - - if (MailClient.imapSend(this, cmd.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return false; - - _imap_cmd = esp_mail_imap_command::esp_mail_imap_cmd_store; - if (!MailClient.handleIMAPResponse(this, IMAP_STATUS_BAD_COMMAND, false)) - return false; - - if (expunge) - { - if (MailClient.imapSendP(this, esp_mail_str_317, true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return false; - - _imap_cmd = esp_mail_imap_command::esp_mail_imap_cmd_expunge; - if (!MailClient.handleIMAPResponse(this, IMAP_STATUS_BAD_COMMAND, false)) - return false; - } - } - - return true; -} - -bool IMAPSession::copyMessages(MessageList *toCopy, const char *dest) -{ - if (toCopy->_list.size() > 0) - { - - if (!selectFolder(_currentFolder.c_str(), false)) - return false; - - if (_debug) - { - MailClient.imapCB(this, "", false); - std::string s; - MailClient.appendP(s, esp_mail_str_318, true); - s += dest; - esp_mail_debug(s.c_str()); - } - - std::string cmd; - char *tmp = nullptr; - MailClient.appendP(cmd, esp_mail_str_319, true); - for (size_t i = 0; i < toCopy->_list.size(); i++) - { - if (i > 0) - MailClient.appendP(cmd, esp_mail_str_263, false); - tmp = MailClient.intStr(toCopy->_list[i]); - cmd += tmp; - MailClient.delS(tmp); - } - MailClient.appendP(cmd, esp_mail_str_131, false); - cmd += dest; - - if (MailClient.imapSend(this, cmd.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) - return false; - - _imap_cmd = esp_mail_imap_command::esp_mail_imap_cmd_store; - if (!MailClient.handleIMAPResponse(this, IMAP_STATUS_BAD_COMMAND, false)) - return false; - } - - return true; -} - -#if defined(ESP8266) -void ESP_Mail_Client::setClock(float offset) -{ - if (WiFi.status() != WL_CONNECTED) - WiFi.reconnect(); - - time_t now = time(nullptr); - - _clockReady = now > ESP_MAIL_CLIENT_VALID_TS; - - if (!_clockReady) - { - char *server1 = strP(esp_mail_str_283); - char *server2 = strP(esp_mail_str_296); - - configTime(offset * 3600, 0, server1, server2); - - now = time(nullptr); - uint8_t attempts = 0; - while (now < ESP_MAIL_CLIENT_VALID_TS) - { - now = time(nullptr); - attempts++; - if (attempts > 200 || now > ESP_MAIL_CLIENT_VALID_TS) - break; - delay(100); - } - - delS(server1); - delS(server2); - } - - _clockReady = now > ESP_MAIL_CLIENT_VALID_TS; -} -#endif - -void IMAPSession::empty() -{ - std::string().swap(_nextUID); - clearMessageData(); -} - -void IMAPSession::clearMessageData() -{ - for (size_t i = 0; i < _headers.size(); i++) - { - _headers[i].part_headers.clear(); - std::vector().swap(_headers[i].part_headers); - } - std::vector().swap(_headers); - std::vector().swap(_msgNum); - _folders.clear(); - _mbif._flags.clear(); - _mbif._searchCount = 0; -} - -SMTPSession::SMTPSession() -{ -} - -SMTPSession::~SMTPSession() -{ - closeSession(); - _caCert.reset(); - _caCert = nullptr; -} - -bool SMTPSession::connect(ESP_Mail_Session *config) -{ - if (_tcpConnected) - MailClient.closeTCP(this); - - _sesson_cfg = config; - _caCert = nullptr; - - if (strlen(_sesson_cfg->certificate.cert_data) > 0) - _caCert = std::shared_ptr(_sesson_cfg->certificate.cert_data); - - if (strlen(_sesson_cfg->certificate.cert_file) > 0) - { - if (_sesson_cfg->certificate.cert_file_storage_type == esp_mail_file_storage_type::esp_mail_file_storage_type_sd && !MailClient._sdOk) - MailClient._sdOk = MailClient.sdTest(); - if (_sesson_cfg->certificate.cert_file_storage_type == esp_mail_file_storage_type::esp_mail_file_storage_type_flash && !MailClient._flashOk) -#if defined(ESP32) - MailClient._flashOk = ESP_MAIL_FLASH_FS.begin(FORMAT_FLASH); -#elif defined(ESP8266) - MailClient._flashOk = ESP_MAIL_FLASH_FS.begin(); -#endif - } - return MailClient.smtpAuth(this); -} - -void SMTPSession::debug(int level) -{ - if (level > esp_mail_debug_level_0) - { - if (level > esp_mail_debug_level_3) - level = esp_mail_debug_level_1; - _debugLevel = level; - _debug = true; - } - else - { - _debugLevel = esp_mail_debug_level_0; - _debug = false; - } -} - -String SMTPSession::errorReason() -{ - std::string ret; - - switch (_smtpStatus.statusCode) - { - case SMTP_STATUS_SERVER_CONNECT_FAILED: - MailClient.appendP(ret, esp_mail_str_38, true); - break; - case SMTP_STATUS_SMTP_GREETING_GET_RESPONSE_FAILED: - MailClient.appendP(ret, esp_mail_str_39, true); - break; - case SMTP_STATUS_SMTP_GREETING_SEND_ACK_FAILED: - MailClient.appendP(ret, esp_mail_str_39, true); - break; - case SMTP_STATUS_AUTHEN_NOT_SUPPORT: - MailClient.appendP(ret, esp_mail_str_42, true); - break; - case SMTP_STATUS_AUTHEN_FAILED: - MailClient.appendP(ret, esp_mail_str_43, true); - break; - case SMTP_STATUS_USER_LOGIN_FAILED: - MailClient.appendP(ret, esp_mail_str_43, true); - break; - case SMTP_STATUS_PASSWORD_LOGIN_FAILED: - MailClient.appendP(ret, esp_mail_str_47, true); - break; - case SMTP_STATUS_SEND_HEADER_SENDER_FAILED: - MailClient.appendP(ret, esp_mail_str_48, true); - break; - case SMTP_STATUS_SEND_HEADER_RECIPIENT_FAILED: - MailClient.appendP(ret, esp_mail_str_222, true); - break; - case SMTP_STATUS_SEND_BODY_FAILED: - MailClient.appendP(ret, esp_mail_str_49, true); - break; - case MAIL_CLIENT_ERROR_CONNECTION_LOST: - MailClient.appendP(ret, esp_mail_str_221, true); - break; - case MAIL_CLIENT_ERROR_READ_TIMEOUT: - MailClient.appendP(ret, esp_mail_str_258, true); - break; - case MAIL_CLIENT_ERROR_FILE_IO_ERROR: - MailClient.appendP(ret, esp_mail_str_282, true); - break; - case SMTP_STATUS_SERVER_OAUTH2_LOGIN_DISABLED: - MailClient.appendP(ret, esp_mail_str_293, true); - break; - case MAIL_CLIENT_ERROR_SERVER_CONNECTION_FAILED: - MailClient.appendP(ret, esp_mail_str_305, true); - break; - case MAIL_CLIENT_ERROR_SSL_TLS_STRUCTURE_SETUP: - MailClient.appendP(ret, esp_mail_str_132, true); - break; - case SMTP_STATUS_NO_VALID_RECIPIENTS_EXISTED: - MailClient.appendP(ret, esp_mail_str_206, true); - break; - case SMTP_STATUS_NO_VALID_SENDER_EXISTED: - MailClient.appendP(ret, esp_mail_str_205, true); - break; - case MAIL_CLIENT_ERROR_OUT_OF_MEMORY: - MailClient.appendP(ret, esp_mail_str_186, true); - break; - case SMTP_STATUS_NO_SUPPORTED_AUTH: - MailClient.appendP(ret, esp_mail_str_42, true); - break; - - default: - break; - } - - if (_smtpStatus.text.length() > 0 && ret.length() == 0) - { - MailClient.appendP(ret, esp_mail_str_312, true); - char *code = MailClient.intStr(_smtpStatus.respCode); - ret += code; - MailClient.delS(code); - MailClient.appendP(ret, esp_mail_str_313, false); - ret += _smtpStatus.text; - return ret.c_str(); - } - return ret.c_str(); -} - -bool SMTPSession::closeSession() -{ - if (!_tcpConnected) - return false; - - if (_sendCallback) - { - _cbData._sentSuccess = _sentSuccessCount; - _cbData._sentFailed = _sentFailedCount; - MailClient.smtpCB(this, ""); - MailClient.smtpCBP(this, esp_mail_str_128); - } - - if (_debug) - MailClient.debugInfoP(esp_mail_str_245); - - bool ret = true; - -/* Sign out */ -#if defined(ESP32) - /** - * The strange behavior in ESP8266 SSL client, BearSSLWiFiClientSecure - * The client disposed without memory released after the server close - * the connection due to QUIT command, which caused the memory leaks. - */ - MailClient.smtpSendP(this, esp_mail_str_7, true); - _smtp_cmd = esp_mail_smtp_cmd_logout; - ret = MailClient.handleSMTPResponse(this, esp_mail_smtp_status_code_221, SMTP_STATUS_SEND_BODY_FAILED); -#endif - - if (ret) - { - - if (_sendCallback) - { - MailClient.smtpCB(this, ""); - MailClient.smtpCBP(this, esp_mail_str_129, false); - } - - if (_debug) - MailClient.debugInfoP(esp_mail_str_246); - - if (_sendCallback) - MailClient.smtpCB(this, "", true); - } - - return MailClient.handleSMTPError(this, 0, ret); -} - -void SMTPSession::callback(smtpStatusCallback smtpCallback) -{ - _sendCallback = std::move(smtpCallback); -} - -IMAP_Status::IMAP_Status() -{ -} -IMAP_Status::~IMAP_Status() -{ - empty(); -} - -const char *IMAP_Status::info() -{ - return _info.c_str(); -} - -bool IMAP_Status::success() -{ - return _success; -} - -void IMAP_Status::empty() -{ - std::string().swap(_info); -} - -SMTP_Status::SMTP_Status() -{ -} - -SMTP_Status::~SMTP_Status() -{ - empty(); -} - -const char *SMTP_Status::info() -{ - return _info.c_str(); -} - -bool SMTP_Status::success() -{ - return _success; -} - -size_t SMTP_Status::completedCount() -{ - return _sentSuccess; -} - -size_t SMTP_Status::failedCount() -{ - return _sentFailed; -} - -void SMTP_Status::empty() -{ - std::string().swap(_info); -} - -ESP_Mail_Client MailClient = ESP_Mail_Client(); - -#endif /* ESP_Mail_Client_CPP */ diff --git a/lib/libesp32/lib_mail/src/ESP_Mail_Client.h b/lib/libesp32/lib_mail/src/ESP_Mail_Client.h deleted file mode 100644 index 88785170a..000000000 --- a/lib/libesp32/lib_mail/src/ESP_Mail_Client.h +++ /dev/null @@ -1,2820 +0,0 @@ -#ifndef ESP_Mail_Client_H -#define ESP_Mail_Client_H - -#define ESP_MAIL_VERSION "1.2.0" - -/** - * Mail Client Arduino Library for Espressif's ESP32 and ESP8266 - * - * Version: 1.2.0 - * Released: May 17, 2021 - * - * Updates: - * - Add support ESP8266 Core SDK v3.x.x. - * - * - * This library allows Espressif's ESP32 and ESP8266 devices to send and read - * Email - * through the SMTP and IMAP servers. - * - * The MIT License (MIT) - * Copyright (c) 2021 K. Suwatchai (Mobizt) - * - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies - * of - * the Software, and to permit persons to whom the Software is furnished to do - * so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS - * OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -#include -#include "extras/RFC2047.h" -#include "extras/ESPTimeHelper.h" - -#if defined(ESP32) -#define FORMAT_FLASH FORMAT_FLASH_IF_MOUNT_FAILED -#include -#include -//#include -#include -#include "wcs/esp32/ESP_Mail_HTTPClient32.h" -#elif defined(ESP8266) -#include -#define FS_NO_GLOBALS -#include -#include "wcs/esp8266/ESP_Mail_HTTPClient.h" -#endif - -#include "extras/MIMEInfo.h" - -#include -#include -#include - -#if defined(ESP8266) -#define SD_CS_PIN 15 -#endif - -#define SMTP_STATUS_SERVER_CONNECT_FAILED -100 -#define SMTP_STATUS_SMTP_GREETING_GET_RESPONSE_FAILED -101 -#define SMTP_STATUS_SMTP_GREETING_SEND_ACK_FAILED -102 -#define SMTP_STATUS_AUTHEN_NOT_SUPPORT -103 -#define SMTP_STATUS_AUTHEN_FAILED -104 -#define SMTP_STATUS_USER_LOGIN_FAILED -105 -#define SMTP_STATUS_PASSWORD_LOGIN_FAILED -106 -#define SMTP_STATUS_SEND_HEADER_SENDER_FAILED -107 -#define SMTP_STATUS_SEND_HEADER_RECIPIENT_FAILED -108 -#define SMTP_STATUS_SEND_BODY_FAILED -109 -#define SMTP_STATUS_SERVER_OAUTH2_LOGIN_DISABLED -110 -#define SMTP_STATUS_NO_VALID_RECIPIENTS_EXISTED -111 -#define SMTP_STATUS_NO_VALID_SENDER_EXISTED -112 -#define SMTP_STATUS_NO_SUPPORTED_AUTH -113 - -#define IMAP_STATUS_SERVER_CONNECT_FAILED -200 -#define IMAP_STATUS_IMAP_RESPONSE_FAILED -201 -#define IMAP_STATUS_LOGIN_FAILED -202 -#define IMAP_STATUS_BAD_COMMAND -203 -#define IMAP_STATUS_PARSE_FLAG_FAILED -204 -#define IMAP_STATUS_SERVER_OAUTH2_LOGIN_DISABLED -205 -#define IMAP_STATUS_NO_MESSAGE -206 -#define IMAP_STATUS_ERROR_DOWNLAD_TIMEOUT -207 -#define IMAP_STATUS_CLOSE_MAILBOX_FAILED -208 -#define IMAP_STATUS_OPEN_MAILBOX_FAILED -209 -#define IMAP_STATUS_LIST_MAILBOXS_FAILED -210 -#define IMAP_STATUS_CHECK_CAPABILITIES_FAILED -211 -#define IMAP_STATUS_NO_SUPPORTED_AUTH -212 -#define IMAP_STATUS_NO_MAILBOX_FOLDER_OPENED -213 - -#define MAIL_CLIENT_ERROR_CONNECTION_LOST -28 -#define MAIL_CLIENT_ERROR_READ_TIMEOUT -29 -#define MAIL_CLIENT_ERROR_FILE_IO_ERROR -30 -#define MAIL_CLIENT_ERROR_SERVER_CONNECTION_FAILED -31 -#define MAIL_CLIENT_ERROR_SSL_TLS_STRUCTURE_SETUP -32 -#define MAIL_CLIENT_ERROR_OUT_OF_MEMORY -33 - -#define MAX_EMAIL_SEARCH_LIMIT 1000 -#define BASE64_CHUNKED_LEN 76 -#define FLOWED_TEXT_LEN 78 -#define ESP_MAIL_WIFI_RECONNECT_TIMEOUT 10000 -#define ESP_MAIL_PROGRESS_REPORT_STEP 20 -#define ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED 0 -#define ESP_MAIL_CLIENT_STREAM_CHUNK_SIZE 256 -#define ESP_MAIL_CLIENT_VALID_TS 1577836800 - -#if defined(ESP32) -#define ESP_MAIL_MIN_MEM 70000 -#elif defined(ESP8266) -#define ESP_MAIL_MIN_MEM 4000 -#endif - -class IMAPSession; -class SMTPSession; -class SMTP_Status; -class DownloadProgress; -class MessageData; - -enum esp_mail_smtp_status_code -{ - esp_mail_smtp_status_code_0, // default - - /* Positive Completion */ - esp_mail_smtp_status_code_211 = 221, // System status, or system help reply - esp_mail_smtp_status_code_214 = - 214, // Help message(A response to the HELP command) - esp_mail_smtp_status_code_220 = 220, // Service ready - esp_mail_smtp_status_code_221 = - 221, // Service closing transmission channel [RFC 2034] - esp_mail_smtp_status_code_235 = - 235, // 2.7.0 Authentication succeeded[RFC 4954] - esp_mail_smtp_status_code_250 = 250, // Requested mail action okay, completed - esp_mail_smtp_status_code_251 = 251, // User not local; will forward - esp_mail_smtp_status_code_252 = 252, // Cannot verify the user, but it will - // try to deliver the message anyway - - /* Positive Intermediate */ - esp_mail_smtp_status_code_334 = 334, //(Server challenge - the text part - //contains the Base64 - encoded - //challenge)[RFC 4954] - esp_mail_smtp_status_code_354 = 354, // Start mail input - - /* Transient Negative Completion */ - /* "Transient Negative" means the error condition is temporary, and the action - may be requested again.*/ - esp_mail_smtp_status_code_421 = - 421, // Service is unavailable because the server is shutting down. - esp_mail_smtp_status_code_432 = - 432, // 4.7.12 A password transition is needed [RFC 4954] - esp_mail_smtp_status_code_450 = - 450, // Requested mail action not taken: mailbox unavailable (e.g., - // mailbox busy or temporarily blocked for policy reasons) - esp_mail_smtp_status_code_451 = - 451, // Requested action aborted : local error in processing - // e.g.IMAP server unavailable[RFC 4468] - esp_mail_smtp_status_code_452 = - 452, // Requested action not taken : insufficient system storage - esp_mail_smtp_status_code_454 = - 454, // 4.7.0 Temporary authentication failure[RFC 4954] - esp_mail_smtp_status_code_455 = - 455, // Server unable to accommodate parameters - - /* Permanent Negative Completion */ - esp_mail_smtp_status_code_500 = 500, // Syntax error, command unrecognized - // (This may include errors such as - // command line too long) - // e.g. Authentication Exchange line is too long [RFC 4954] - esp_mail_smtp_status_code_501 = - 501, // Syntax error in parameters or arguments - // e.g. 5.5.2 Cannot Base64-decode Client responses [RFC 4954] - // 5.7.0 Client initiated Authentication Exchange (only when the SASL - // mechanism specified that client does not begin the authentication exchange) - // [RFC 4954] - esp_mail_smtp_status_code_502 = 502, // Command not implemented - esp_mail_smtp_status_code_503 = 503, // Bad sequence of commands - esp_mail_smtp_status_code_504 = 504, // Command parameter is not implemented - // e.g. 5.5.4 Unrecognized authentication type [RFC 4954] - esp_mail_smtp_status_code_521 = 521, // Server does not accept mail [RFC 7504] - esp_mail_smtp_status_code_523 = 523, // Encryption Needed [RFC 5248] - esp_mail_smtp_status_code_530 = - 530, // 5.7.0 Authentication required [RFC 4954] - esp_mail_smtp_status_code_534 = - 534, // 5.7.9 Authentication mechanism is too weak [RFC 4954] - esp_mail_smtp_status_code_535 = - 535, // 5.7.8 Authentication credentials invalid [RFC 4954] - esp_mail_smtp_status_code_538 = 538, // 5.7.11 Encryption required for - // requested authentication mechanism[RFC - // 4954] - esp_mail_smtp_status_code_550 = - 550, // Requested action not taken: mailbox unavailable (e.g., mailbox not - // found, no access, or command rejected for policy reasons) - esp_mail_smtp_status_code_551 = - 551, // User not local; please try - esp_mail_smtp_status_code_552 = - 552, // Requested mail action aborted: exceeded storage allocation - esp_mail_smtp_status_code_553 = - 553, // Requested action not taken: mailbox name not allowed - esp_mail_smtp_status_code_554 = 554, // Transaction has failed (Or, in the - // case of a connection-opening response, - // "No SMTP service here") - // e.g. 5.3.4 Message too big for system [RFC 4468] - esp_mail_smtp_status_code_556 = 556, // Domain does not accept mail[RFC 7504] -}; - -enum esp_mail_smtp_port -{ - esp_mail_smtp_port_25 = 25, // PLAIN/TLS with STARTTLS - esp_mail_smtp_port_465 = 465, // SSL - esp_mail_smtp_port_587 = 587 // TLS with STARTTLS -}; - -enum esp_mail_imap_port -{ - esp_mail_imap_port_143 = 143, // PLAIN/TLS with STARTTLS - esp_mail_imap_port_993 = 993, // SSL -}; - -enum esp_mail_smtp_notify -{ - esp_mail_smtp_notify_never = 0, - esp_mail_smtp_notify_success = 1, - esp_mail_smtp_notify_failure = 2, - esp_mail_smtp_notify_delay = 4 -}; - -enum esp_mail_attach_type -{ - esp_mail_att_type_none, - esp_mail_att_type_attachment, - esp_mail_att_type_inline -}; - -enum esp_mail_message_type -{ - esp_mail_msg_type_none = 0, - esp_mail_msg_type_plain = 1, - esp_mail_msg_type_html = 2, - esp_mail_msg_type_enriched = 1 -}; - -enum esp_mail_auth_type -{ - esp_mail_auth_type_psw, - esp_mail_auth_type_oath2, - esp_mail_auth_type_token -}; - -enum esp_mail_imap_auth_mode -{ - esp_mail_imap_mode_examine, - esp_mail_imap_mode_select -}; - -enum esp_mail_imap_response_status -{ - esp_mail_imap_resp_unknown, - esp_mail_imap_resp_ok, - esp_mail_imap_resp_no, - esp_mail_imap_resp_bad -}; - -enum esp_mail_imap_header_state -{ - esp_mail_imap_state_from = 1, - esp_mail_imap_state_to, - esp_mail_imap_state_cc, - esp_mail_imap_state_subject, - esp_mail_imap_state_content_type, - esp_mail_imap_state_content_transfer_encoding, - esp_mail_imap_state_accept_language, - esp_mail_imap_state_content_language, - esp_mail_imap_state_date, - esp_mail_imap_state_msg_id, - esp_mail_imap_state_char_set, - esp_mail_imap_state_boundary -}; - -enum esp_mail_imap_command -{ - esp_mail_imap_cmd_capability, - esp_mail_imap_cmd_starttls, - esp_mail_imap_cmd_login, - esp_mail_imap_cmd_plain, - esp_mail_imap_cmd_auth, - esp_mail_imap_cmd_list, - esp_mail_imap_cmd_select, - esp_mail_imap_cmd_examine, - esp_mail_imap_cmd_close, - esp_mail_imap_cmd_status, - esp_mail_imap_cmd_search, - esp_mail_imap_cmd_fetch_body_header, - esp_mail_imap_cmd_fetch_body_mime, - esp_mail_imap_cmd_fetch_body_text, - esp_mail_imap_cmd_fetch_body_attachment, - esp_mail_imap_cmd_fetch_body_inline, - esp_mail_imap_cmd_logout, - esp_mail_imap_cmd_store, - esp_mail_imap_cmd_expunge, - esp_mail_imap_cmd_create, - esp_mail_imap_cmd_delete -}; - -enum esp_mail_imap_mime_fetch_type -{ - esp_mail_imap_mime_fetch_type_part, - esp_mail_imap_mime_fetch_type_sub_part1, - esp_mail_imap_mime_fetch_type_sub_part2 -}; - -enum esp_mail_smtp_command -{ - esp_mail_smtp_cmd_initial_state, - esp_mail_smtp_cmd_greeting, - esp_mail_smtp_cmd_start_tls, - esp_mail_smtp_cmd_login_user, - esp_mail_smtp_cmd_auth_plain, - esp_mail_smtp_cmd_auth, - esp_mail_smtp_cmd_login_psw, - esp_mail_smtp_cmd_send_header_sender, - esp_mail_smtp_cmd_send_header_recipient, - esp_mail_smtp_cmd_send_body, - esp_mail_smtp_cmd_chunk_termination, - esp_mail_smtp_cmd_logout -}; - -enum esp_mail_imap_header_type -{ - esp_mail_imap_header_from, - esp_mail_imap_header_to, - esp_mail_imap_header_cc, - esp_mail_imap_header_subject, - esp_mail_imap_header_date, - esp_mail_imap_header_msg_id, - esp_mail_imap_header_cont_lang, - esp_mail_imap_header_accept_lang -}; - -enum esp_mail_char_decoding_scheme -{ - esp_mail_char_decoding_scheme_default, - esp_mail_char_decoding_scheme_iso8859_1, - esp_mail_char_decoding_scheme_tis620 -}; - -enum esp_mail_smtp_priority -{ - esp_mail_smtp_priority_high = 1, - esp_mail_smtp_priority_normal = 3, - esp_mail_smtp_priority_low = 5, -}; - -enum esp_mail_smtp_embed_message_type -{ - esp_mail_smtp_embed_message_type_attachment = 0, - esp_mail_smtp_embed_message_type_inline -}; - -enum esp_mail_debug_level -{ - esp_mail_debug_level_0 = 0, - esp_mail_debug_level_1, - esp_mail_debug_level_2 = 222, - esp_mail_debug_level_3 = 333 -}; - -enum esp_mail_imap_multipart_sub_type -{ - esp_mail_imap_multipart_sub_type_none = 0, - esp_mail_imap_multipart_sub_type_mixed, - esp_mail_imap_multipart_sub_type_alternative, - esp_mail_imap_multipart_sub_type_parallel, - esp_mail_imap_multipart_sub_type_digest, - esp_mail_imap_multipart_sub_type_related, - esp_mail_imap_multipart_sub_type_report, -}; - -enum esp_mail_imap_message_sub_type -{ - esp_mail_imap_message_sub_type_none = 0, - esp_mail_imap_message_sub_type_rfc822, - esp_mail_imap_message_sub_type_delivery_status, - esp_mail_imap_message_sub_type_partial, - esp_mail_imap_message_sub_type_external_body, -}; - -/* descrete media types (rfc 2046) */ -struct esp_mail_imap_descrete_media_type_t -{ - /** textual information with subtypes - * "plain" - * "enriched" (rfc 1896 revised from richtext in rfc 1341) - * - * unrecognized subtypes and charset should be interpreted as - * application/octet-stream - * - * parameters: - * "charset" (rfc 2045) default is us-ascii - * for character set includes 8-bit characters - * and such characters are used in the body, Content-Transfer-Encoding - * header field and a corresponding encoding on the data are required - * - * ISO-8859-X where "X" is to be replaced, as - * necessary, for the parts of ISO-8859 [ISO-8859]. - */ - static constexpr const char *text = "text"; - - /** image data with subtypes (rfc 2048) - * "jpeg" - * "gif" - * - * unrecognized subtypes should be interpreted as application/octet-stream - */ - static constexpr const char *image = "image"; - - /** audio data with initial subtype - * "baic" -- for single channel audio encoded using 8bit ISDN mu-law [PCM] - * at a sample rate of 8000 Hz. - * - * Unrecognized subtypes of "audio" should at a miniumum be treated as - * "application/octet-stream" - */ - static constexpr const char *audio = "audio"; - - /** video data with initial subtype - * "mpeg" - * - * Unrecognized subtypes of "video" should at a minumum be treated as - * "application/octet-stream" - */ - static constexpr const char *video = "video"; - - /** some other kind of data, typically either - * uninterpreted binary data or information to be - * processed by an application with subtypes - * - * "octet-stream" -- uninterpreted binary data - * "PostScript" -- for the transport of PostScript material - * - * Other expected uses include spreadsheets, data for mail-based - * scheduling systems, and languages for "active" (computational) - * messaging, and word processing formats that are not directly readable. - * - * The octet-stream subtype parameters: - * TYPE, PADDING, NAME - */ - static constexpr const char *application = "application"; -}; - -/** composite media types (rfc 2046) - * - * As stated in the definition of the Content-Transfer-Encoding field - * [RFC 2045], no encoding other than "7bit", "8bit", or "binary" is - * permitted for entities of type "multipart". The "multipart" boundary - * delimiters and header fields are always represented as 7bit US-ASCII - * in any case (though the header fields may encode non-US-ASCII header - * text as per RFC 2047) and data within the body parts can be encoded - * on a part-by-part basis, with Content-Transfer-Encoding fields for - * each appropriate body part. -*/ -struct esp_mail_imap_composite_media_type_t -{ - /** data consisting of multiple entities of independent data types - * The Content-Type field for multipart entities requires one parameter, - * "boundary". - * The boundary delimiter line is then defined as a line - * consisting entirely of two hyphen characters ("-", decimal value 45) - * followed by the boundary parameter value from the Content-Type header - * field, optional linear whitespace, and a terminating CRLF. - * - * NOTE: The CRLF preceding the boundary delimiter line is conceptually - * attached to the boundary so that it is possible to have a part that - * does not end with a CRLF (line break). Body parts that must be - * considered to end with line breaks, therefore, must have two CRLFs - * preceding the boundary delimiter line, the first of which is part of - * the preceding body part, and the second of which is part of the - * encapsulation boundary. - * - * Boundary delimiters must not appear within the encapsulated material, - * and must be no longer than 70 characters, not counting the two - * leading hyphens. - * - * The boundary delimiter line following the last body part is a - * distinguished delimiter that indicates that no further body parts - * will follow. Such a delimiter line is identical to the previous - * delimiter lines, with the addition of two more hyphens after the - * boundary parameter value. - * - * See rfc2049 Appendix A for a Complex Multipart Example - */ - static constexpr const char *multipart = "multipart"; - - /* an encapsulated message */ - static constexpr const char *message = "message"; -}; - -struct esp_mail_imap_media_text_sub_type_t -{ - static constexpr const char *plain = "plain"; - static constexpr const char *enriched = "enriched"; - static constexpr const char *html = "html"; -}; - -/* multipart sub types */ -struct esp_mail_imap_multipart_sub_type_t -{ - /* a generic mixed set of parts */ - static constexpr const char *mixed = "mixed"; - - /* the same data in multiple formats */ - static constexpr const char *alternative = "alternative"; - - /* parts intended to be viewed simultaneously */ - static constexpr const char *parallel = "parallel"; - - /* multipart entities in which each part has a default type of - * "message/rfc822" */ - static constexpr const char *digest = "digest"; - - /* for compound objects consisting of several inter-related body parts (rfc - * 2387) */ - static constexpr const char *related = "related"; - - /* rfc 3462 */ - static constexpr const char *report = "report"; -}; - -/* message body sub types */ -struct esp_mail_imap_message_sub_type_t -{ - /* body contains an encapsulated message, with the syntax of an RFC 822 - * message. */ - static constexpr const char *rfc822 = "rfc822"; - - /* to allow large objects to be delivered as several separate pieces of mail - */ - static constexpr const char *Partial = "Partial"; - - /* the actual body data are not included, but merely referenced */ - static constexpr const char *External_Body = "External-Body"; - - static constexpr const char *delivery_status = "delivery-status"; -}; - -/** content disposition rfc 2183 - * - * Parameters: - * "filename", "creation-date","modification-date", - * "read-date", * "size" -*/ -struct esp_mail_imap_content_disposition_type_t -{ - /** if it is intended to be displayed automatically - * upon display of the message. - */ - static constexpr const char *inline_ = "inline"; - - /** to indicate that they are separate from the main body - * of the mail message, and that their display should not - * be automatic, but contingent upon some further action of the user. - */ - static constexpr const char *attachment = "attachment"; -}; - -struct esp_mail_internal_use_t -{ - bool binary = false; - std::string cid = ""; -}; - -struct esp_mail_content_transfer_encoding_t -{ - /* The default 7-bit transfer encoding for US-ACII characters*/ - static constexpr const char *enc_7bit = "7bit"; - - /* The quoted printable transfer encoding for non-US-ASCII characters*/ - static constexpr const char *enc_qp = "quoted-printable"; - - /* The base64 encoded transfer encoding */ - static constexpr const char *enc_base64 = "base64"; - - /* The 8-bit transfer encoding for extended-US-ASCII characters*/ - static constexpr const char *enc_8bit = "8bit"; - - /* The binary transfer encoding for extended-US-ASCII characters with no line - * length limit*/ - static constexpr const char *enc_binary = "binary"; -}; - -struct esp_mail_smtp_response_status_t -{ - int respCode = 0; - int statusCode = 0; - std::string text = ""; -}; - -struct esp_mail_imap_response_status_t -{ - int statusCode = 0; - std::string text = ""; -}; - -/* The option to embed this message content as a file */ -struct esp_mail_smtp_embed_message_body_t -{ - /* Enable to send this message body as file */ - bool enable = false; - - /* The name of embedded file */ - const char *filename = ""; - - /** The embedded type - * esp_mail_smtp_embed_message_type_attachment or 0 - * esp_mail_smtp_embed_message_type_inline or 1 - */ - esp_mail_smtp_embed_message_type type = - esp_mail_smtp_embed_message_type_attachment; -}; - -struct esp_mail_file_message_content_t -{ - /* The file path include its name */ - const char *name = ""; - - /** The type of file storages e.g. - * esp_mail_file_storage_type_none, - * esp_mail_file_storage_type_flash, and - * esp_mail_file_storage_type_sd - */ - esp_mail_file_storage_type type = esp_mail_file_storage_type_flash; -}; - -struct esp_mail_blob_message_content_t -{ - /* The array of content in flash memory */ - const uint8_t *data = nullptr; - - /* The array size in bytes */ - size_t size = 0; -}; - -/* The PLAIN text body details of the message */ -struct esp_mail_plain_body_t -{ - /* The option to embed this message content as a file */ - struct esp_mail_smtp_embed_message_body_t embed; - - /* The PLAIN text content of the message */ - const char *content = ""; - - /* The blob that contins PLAIN text content of the message */ - struct esp_mail_blob_message_content_t blob; - - /* The file that contins PLAIN text content of the message */ - struct esp_mail_file_message_content_t file; - - /* The charset of the PLAIN text content of the message */ - const char *charSet = "UTF-8"; - - /* The content type of message */ - const char *content_type = "text/plain"; - - /* The option to encode the content for data transfer */ - const char *transfer_encoding = "7bit"; - - /* The option to send the PLAIN text with wrapping */ - bool flowed = false; - - /* The internal usage data */ - struct esp_mail_internal_use_t _int; -}; - -struct esp_mail_html_body_t -{ - /* The option to embedded the content as a file */ - struct esp_mail_smtp_embed_message_body_t embed; - - /* The HTML content of the message */ - const char *content = ""; - - /* The blob that contins HTML content of the message */ - struct esp_mail_blob_message_content_t blob; - - /* The file that contins HTML content of the message */ - struct esp_mail_file_message_content_t file; - - /* The charset of the HTML content of the message */ - const char *charSet = "UTF-8"; - - /* The content type of message */ - const char *content_type = "text/html"; - - /* The option to encode the content for data transfer */ - const char *transfer_encoding = "7bit"; - - /* The internal usage data */ - struct esp_mail_internal_use_t _int; -}; - -struct esp_mail_link_internal_t -{ - std::string cid = ""; -}; - -struct esp_mail_email_info_t -{ - /* The name of Email author*/ - const char *name = ""; - - /* The Email address */ - const char *email = ""; -}; -struct esp_mail_smtp_msg_response_t -{ - /* The author Email address to reply */ - const char *reply_to = ""; - - /* The sender Email address to return the message */ - const char *return_path = ""; - - /** The Delivery Status Notifications e.g. esp_mail_smtp_notify_never, - * esp_mail_smtp_notify_success, - * esp_mail_smtp_notify_failure, and - * esp_mail_smtp_notify_delay - */ - int notify = esp_mail_smtp_notify::esp_mail_smtp_notify_never; -}; - -struct esp_mail_smtp_enable_option_t -{ - /* Enable chunk data sending for large message */ - bool chunking = false; -}; - -struct esp_mail_attach_blob_t -{ - /* BLOB data (flash or ram) */ - const uint8_t *data = nullptr; - - /* BLOB data size in byte */ - size_t size = 0; -}; - -struct esp_mail_attach_file_t -{ - const char *path = ""; - /** The file storage type e.g. esp_mail_file_storage_type_none, - * esp_mail_file_storage_type_flash, and - * esp_mail_file_storage_type_sd - */ - esp_mail_file_storage_type storage_type = esp_mail_file_storage_type_none; -}; - -struct esp_mail_attach_descr_t -{ - /* The name of attachment */ - const char *name = ""; - - /* The attachment file name */ - const char *filename = ""; - - /* The MIME type of attachment */ - const char *mime = ""; - - /* The transfer encoding of attachment e.g. base64 */ - const char *transfer_encoding = "base64"; - - /* The content encoding of attachment e.g. base64 */ - const char *content_encoding = ""; - - /* The content id of attachment file */ - const char *content_id = ""; -}; - -struct esp_mail_attach_internal_t -{ - esp_mail_attach_type att_type = esp_mail_att_type_attachment; - int index = 0; - int msg_uid = 0; - bool flash_blob = false; - bool binary = false; - bool parallel = false; - std::string cid = ""; -}; - -struct esp_mail_attachment_t -{ - /* The attachment description */ - struct esp_mail_attach_descr_t descr; - - /* The BLOB data config */ - struct esp_mail_attach_blob_t blob; - - /* The file data config */ - struct esp_mail_attach_file_t file; - - /* reserved for internal usage */ - struct esp_mail_attach_internal_t _int; -}; - -struct esp_mail_smtp_recipient_t -{ - /* The recipient's name */ - const char *name = ""; - - /* The recipient's Email address */ - const char *email = ""; -}; - -struct esp_mail_smtp_recipient_address_t -{ - /* The recipient's Email address */ - const char *email = ""; -}; - -struct esp_mail_smtp_send_status_t -{ - /* The status of the message */ - bool completed = false; - - /* The primary recipient mailbox of the message */ - const char *recipients = ""; - - /* The topic of the message */ - const char *subject = ""; - - /* The timestamp of the message */ - time_t timesstamp = 0; -}; - -struct esp_mail_attacment_info_t -{ - const char *filename = ""; - const char *name = ""; - const char *creationDate = ""; - const char *mime = ""; - esp_mail_attach_type type = esp_mail_att_type_none; - size_t size; -}; - -struct esp_mail_auth_capability_t -{ - bool plain = false; - bool xoauth2 = false; - bool cram_md5 = false; - bool digest_md5 = false; - bool login = false; - bool start_tls = false; -}; - -struct esp_mail_smtp_capability_t -{ - bool esmtp = false; - bool binaryMIME = false; - bool _8bitMIME = false; - bool chunking = false; - bool utf8 = false; - bool pipelining = false; - bool dsn = false; -}; - -struct esp_mail_imap_rfc822_msg_header_item_t -{ - std::string sender = ""; - std::string from; - std::string subject = ""; - std::string messageID = ""; - std::string keyword = ""; - std::string comment = ""; - std::string date = ""; - std::string return_path = ""; - std::string reply_to; - std::string to = ""; - std::string cc = ""; - std::string bcc = ""; -}; - -struct esp_mail_message_part_info_t -{ - int octetLen = 0; - int attach_data_size = 0; - int textLen = 0; - bool sizeProp = false; - int nestedLevel = 0; - std::string partNumStr = ""; - std::string partNumFetchStr = ""; - std::string text = ""; - std::string filename = ""; - std::string type = ""; - std::string save_path = ""; - std::string name = ""; - std::string content_disposition = ""; - std::string content_type = ""; - std::string descr = ""; - std::string content_transfer_encoding = ""; - std::string creation_date = ""; - std::string modification_date = ""; - std::string charset = ""; - std::string download_error = ""; - esp_mail_attach_type attach_type = esp_mail_att_type_none; - esp_mail_message_type msg_type = esp_mail_msg_type_none; - bool file_open_write = false; - bool multipart = false; - esp_mail_imap_multipart_sub_type multipart_sub_type = - esp_mail_imap_multipart_sub_type_none; - esp_mail_imap_message_sub_type message_sub_type = - esp_mail_imap_message_sub_type_none; - bool rfc822_part = false; - int rfc822_msg_Idx = 0; - struct esp_mail_imap_rfc822_msg_header_item_t rfc822_header; - bool error = false; - bool plain_flowed = false; - bool plain_delsp = false; -}; - -struct esp_mail_message_header_t -{ - int header_data_len = 0; - std::string from = ""; - std::string to = ""; - std::string cc = ""; - std::string subject = ""; - std::string content_type = ""; - std::string content_transfer_encoding = ""; - std::string date = ""; - std::string message_id = ""; - std::string message_uid = ""; - std::string message_no = ""; - std::string boundary = ""; - std::string accept_language = ""; - std::string content_language = ""; - std::string char_set = ""; - bool multipart = false; - bool rfc822_part = false; - int rfc822Idx = 0; - std::string partNumStr = ""; - - esp_mail_imap_multipart_sub_type multipart_sub_type = - esp_mail_imap_multipart_sub_type_none; - esp_mail_imap_message_sub_type message_sub_type = - esp_mail_imap_message_sub_type_none; - std::string from_charset = ""; - std::string to_charset = ""; - std::string cc_charset = ""; - std::string subject_charset = ""; - std::string msgID = ""; - std::string error_msg = ""; - bool error = false; - std::vector part_headers = - std::vector(); - int attachment_count = 0; - int total_download_size = 0; - int downloaded_size = 0; - int total_attach_data_size = 0; - int downloaded_bytes = 0; - int message_data_count = 0; -}; - -/* Internal use */ -struct esp_mail_folder_info_t -{ - std::string name = ""; - std::string attributes = ""; - std::string delimiter = ""; -}; - -struct esp_mail_folder_info_item_t -{ - /* The name of folder */ - const char *name = ""; - - /* The attributes of folder */ - const char *attributes = ""; - - /* The delimeter of folder */ - const char *delimiter = ""; -}; - -struct esp_mail_sesson_cert_config_t -{ - /* The certificate data (base64 data) */ - const char *cert_data = ""; - - /* The certificate file (DER format) */ - const char *cert_file = ""; - - /* The storage type */ - esp_mail_file_storage_type cert_file_storage_type; -}; - -struct esp_mail_sesson_sever_config_t -{ - /* The hostName of the server */ - const char *host_name = ""; - /* The port on the server to connect to */ - uint16_t port = 0; -}; - -/* The log in credentials */ -struct esp_mail_sesson_login_config_t -{ - /* The user Email address to log in */ - const char *email = ""; - - /* The user password to log in */ - const char *password = ""; - - /* The OAuth2.0 access token to log in */ - const char *accessToken = ""; - - /* The user domain or ip of client */ - const char *user_domain = ""; -}; - -struct esp_mail_sesson_secure_config_t -{ - /* The option to send the command to start the TLS connection */ - bool startTLS = false; -}; - -struct esp_mail_session_config_t -{ - /* The server config */ - struct esp_mail_sesson_sever_config_t server; - - /* The log in config */ - struct esp_mail_sesson_login_config_t login; - - /* The secure config */ - struct esp_mail_sesson_secure_config_t secure; - - /* The certificate config */ - struct esp_mail_sesson_cert_config_t certificate; -}; - -struct esp_mail_imap_download_config_t -{ - /* To download the PLAIN text content of the message */ - bool text = false; - - /* To download the HTML content of the message */ - bool html = false; - - /* To download the attachments of the message */ - bool attachment = false; - - /* To download the inline image of the message */ - bool inlineImg = false; - - /* To download the rfc822 mesages in the message */ - bool rfc822 = false; - - /* To download the message header */ - bool header = false; -}; - -struct esp_mail_imap_enable_config_t -{ - /* To store the PLAIN text of the message in the IMAPSession */ - bool text = false; - - /* To store the HTML of the message in the IMAPSession */ - bool html = false; - - /* To store the rfc822 messages in the IMAPSession */ - bool rfc822 = false; - - /* To enable the download status via the serial port */ - bool download_status = false; - - /* To sort the message UID of the search result in descending order */ - bool recent_sort = false; -}; - -struct esp_mail_imap_limit_config_t -{ - /* The maximum messages from the search result */ - size_t search = 10; - - /** The maximum size of the memory buffer to store the message content. - * This is only limit for data to be stored in the IMAPSession. - */ - size_t msg_size = 1024; - - /* The maximum size of each attachment to download */ - size_t attachment_size = 1024 * 1024 * 5; -}; - -struct esp_mail_imap_storage_config_t -{ - /* The path to save the downloaded file */ - const char *saved_path = "/"; - - /** The type of file storages e.g. - * esp_mail_file_storage_type_none, - * esp_mail_file_storage_type_flash, and - * esp_mail_file_storage_type_sd - */ - esp_mail_file_storage_type type = esp_mail_file_storage_type_flash; -}; - -struct esp_mail_imap_search_config_t -{ - /* The search criteria */ - const char *criteria = ""; - - /* The option to search the unseen message */ - bool unseen_msg = false; -}; - -struct esp_mail_imap_fetch_config_t -{ - /* The UID of message to fetch */ - const char *uid = ""; - - /* Set the message flag as seen */ - bool set_seen = false; -}; - -struct esp_mail_imap_read_config_t -{ - /* The config for fetching */ - struct esp_mail_imap_fetch_config_t fetch; - - /* The config for search */ - struct esp_mail_imap_search_config_t search; - - /* The config about the limits */ - struct esp_mail_imap_limit_config_t limit; - - /* The config to enable the features */ - struct esp_mail_imap_enable_config_t enable; - - /* The config about downloads */ - struct esp_mail_imap_download_config_t download; - - /* The config about the storage and path to save the downloaded file */ - struct esp_mail_imap_storage_config_t storage; -}; - -/* Mail and MIME Header Fields */ -struct esp_mail_imap_msg_item_t -{ - /* The message number */ - const char *msgNo = ""; - - /* The message UID */ - const char *UID = ""; - - /* The message identifier (RFC 4021) */ - const char *ID = ""; - - /* The language(s) for auto-responses (RFC 4021) */ - const char *acceptLang = ""; - - /* The language of message content (RFC 4021) */ - const char *contentLang = ""; - - /* The mailbox of message author (RFC 4021) */ - const char *from = ""; - - /* The charset of the mailbox of message author */ - const char *fromCharset = ""; - - /* The primary recipient mailbox (RFC 4021) */ - const char *to = ""; - - /* The charset of the primary recipient mailbox */ - const char *toCharset = ""; - - /* The Carbon-copy recipient mailboxes (RFC 4021) */ - const char *cc = ""; - - /* The charset of the Carbon-copy recipient mailbox header */ - const char *ccCharset = ""; - - /* The message date and time (RFC 4021) */ - const char *date = ""; - - /* The topic of message (RFC 4021) */ - const char *subject = ""; - - /* The topic of message charset */ - const char *subjectCharset = ""; - - /* The PLAIN text content of the message */ - struct esp_mail_plain_body_t text; - - /* The HTML content of the message */ - struct esp_mail_html_body_t html; - - /* rfc822 related */ - - /* The sender Email */ - const char *sender; - - /* The message identifier */ - const char *messageID = ""; - - /* The keywords or phrases, separated by commas */ - const char *keyword = ""; - - /* The comment about message */ - const char *comment = ""; - - /* The return recipient of the message */ - const char *return_path = ""; - - /* The Email address to reply */ - const char *reply_to; - - /* The Blind carbon-copy recipients */ - const char *bcc = ""; - - /* The error description from fetching the message */ - const char *fetchError = ""; - - /* The info about the attachments in the message */ - std::vector attachments = - std::vector(); - - /* The info about the rfc822 messages included in the message */ - std::vector rfc822 = - std::vector(); -}; - -struct esp_mail_imap_msg_list_t -{ - /* The info of a message */ - std::vector msgItems = - std::vector(); -}; - -struct esp_mail_smtp_msg_type_t -{ - bool rfc822 = false; - int rfc822Idx = 0; -}; -struct esp_mail_imap_multipart_level_t -{ - uint8_t level = 0; - bool fetch_rfc822_header = false; - bool append_body_text = false; -}; - -/** The content transfer encoding - * enc_7bit or "7bit" - * enc_qp or "quoted-printable" - * enc_base64 or "base64" - * enc_binary or "binary" - * enc_8bit or "8bit" -*/ -typedef struct esp_mail_content_transfer_encoding_t Content_Transfer_Encoding; - -/* The result from sending the Email */ -typedef struct esp_mail_smtp_send_status_t SMTP_Result; - -/* The attachment item details for a message which returned from fetching the - * Email */ -typedef struct esp_mail_attacment_info_t IMAP_Attach_Item; - -/* The attachment details for sending the Email */ -typedef struct esp_mail_attachment_t SMTP_Attachment; - -/* The info of the selected or open mailbox folder e.g. name, attributes and - * delimiter */ -typedef struct esp_mail_folder_info_item_t FolderInfo; - -/* The session configuations */ -typedef struct esp_mail_session_config_t ESP_Mail_Session; - -/** The IMAP operation configuations */ -typedef struct esp_mail_imap_read_config_t IMAP_Config; - -/* The message item data of the IMAP_MSG_List which contains header, body and - * attachments info for eacch message*/ -typedef struct esp_mail_imap_msg_item_t IMAP_MSG_Item; - -/* The list that contains the message items from searching or fetching the Email - */ -typedef struct esp_mail_imap_msg_list_t IMAP_MSG_List; - -static const char esp_mail_str_1[] PROGMEM = - "Content-Type: multipart/mixed; boundary=\""; -static const char esp_mail_str_2[] PROGMEM = "$ CAPABILITY"; -static const char esp_mail_str_3[] PROGMEM = "Mime-Version: 1.0\r\n"; -static const char esp_mail_str_4[] PROGMEM = "AUTH LOGIN"; -static const char esp_mail_str_5[] PROGMEM = "HELO "; -static const char esp_mail_str_6[] PROGMEM = "EHLO "; -static const char esp_mail_str_7[] PROGMEM = "QUIT"; -static const char esp_mail_str_8[] PROGMEM = "MAIL FROM:"; -static const char esp_mail_str_9[] PROGMEM = "RCPT TO:"; -static const char esp_mail_str_10[] PROGMEM = "From: "; -static const char esp_mail_str_11[] PROGMEM = "To: "; -static const char esp_mail_str_12[] PROGMEM = "Cc: "; -static const char esp_mail_str_13[] PROGMEM = ",<"; -static const char esp_mail_str_14[] PROGMEM = "<"; -static const char esp_mail_str_15[] PROGMEM = ">"; -static const char esp_mail_str_16[] PROGMEM = "DATA"; -static const char esp_mail_str_17[] PROGMEM = "X-Priority: "; -static const char esp_mail_str_18[] PROGMEM = "X-MSMail-Priority: High\r\n"; -static const char esp_mail_str_19[] PROGMEM = "X-MSMail-Priority: Normal\r\n"; -static const char esp_mail_str_20[] PROGMEM = "X-MSMail-Priority: Low\r\n"; -static const char esp_mail_str_21[] PROGMEM = "Importance: High\r\n"; -static const char esp_mail_str_22[] PROGMEM = "Importance: Normal\r\n"; -static const char esp_mail_str_23[] PROGMEM = "Importance: Low\r\n"; -static const char esp_mail_str_24[] PROGMEM = "Subject: "; -static const char esp_mail_str_25[] PROGMEM = "Content-Type: "; -static const char esp_mail_str_26[] PROGMEM = "; Name=\""; -static const char esp_mail_str_27[] PROGMEM = "$"; -static const char esp_mail_str_28[] PROGMEM = - "Content-Type: multipart/parallel; boundary=\""; -static const char esp_mail_str_29[] PROGMEM = "7bit"; -static const char esp_mail_str_30[] PROGMEM = - "Content-Disposition: attachment; filename=\""; -static const char esp_mail_str_31[] PROGMEM = "base64"; -static const char esp_mail_str_32[] PROGMEM = "application/octet-stream"; -static const char esp_mail_str_33[] PROGMEM = "--"; -static const char esp_mail_str_34[] PROGMEM = "\r\n"; -static const char esp_mail_str_35[] PROGMEM = "\"\r\n\r\n"; -static const char esp_mail_str_36[] PROGMEM = "\"\r\n"; -static const char esp_mail_str_37[] PROGMEM = "\r\n.\r\n"; -static const char esp_mail_str_38[] PROGMEM = "unable to connect to server"; -static const char esp_mail_str_39[] PROGMEM = "SMTP server greeting failed"; -static const char esp_mail_str_40[] PROGMEM = ".dat"; -static const char esp_mail_str_41[] PROGMEM = "$ AUTHENTICATE PLAIN "; -static const char esp_mail_str_42[] PROGMEM = - "the provided SASL authentication mechanism is not support"; -static const char esp_mail_str_43[] PROGMEM = "authentication failed"; -static const char esp_mail_str_44[] PROGMEM = "mydomain.com"; -static const char esp_mail_str_45[] PROGMEM = "AUTH PLAIN"; -static const char esp_mail_str_46[] PROGMEM = "Return-Path: "; -static const char esp_mail_str_47[] PROGMEM = "login password is not valid"; -static const char esp_mail_str_48[] PROGMEM = "send header failed"; -static const char esp_mail_str_49[] PROGMEM = "send body failed"; -static const char esp_mail_str_50[] PROGMEM = "Connecting to IMAP server..."; -static const char esp_mail_str_51[] PROGMEM = - ".HEADER.FIELDS (SUBJECT FROM SENDER RETURN-PATH TO REPLY-TO DATE CC " - "Message-ID COMMENT KEYWORD content-type Content-transfer-encoding)]"; -static const char esp_mail_str_52[] PROGMEM = "failed"; -static const char esp_mail_str_53[] PROGMEM = "Error, "; -static const char esp_mail_str_54[] PROGMEM = "IMAP server connected"; -static const char esp_mail_str_55[] PROGMEM = "> C: download attachment"; -static const char esp_mail_str_56[] PROGMEM = "Logging in..."; -static const char esp_mail_str_57[] PROGMEM = "Downloading messages..."; -static const char esp_mail_str_58[] PROGMEM = - "Reading the list of mailboxes..."; -static const char esp_mail_str_59[] PROGMEM = - "> C: download plain TEXT message"; -static const char esp_mail_str_60[] PROGMEM = "> C: download HTML message"; -static const char esp_mail_str_61[] PROGMEM = "Selecting the "; -static const char esp_mail_str_62[] PROGMEM = "fail to list the mailboxes"; -static const char esp_mail_str_63[] PROGMEM = "fail to check the capabilities"; -static const char esp_mail_str_64[] PROGMEM = "Check the capability..."; -static const char esp_mail_str_65[] PROGMEM = "> C: check the capability"; -static const char esp_mail_str_66[] PROGMEM = "Searching messages..."; -static const char esp_mail_str_67[] PROGMEM = "message"; -static const char esp_mail_str_68[] PROGMEM = "Search limit:"; -static const char esp_mail_str_69[] PROGMEM = "Found "; -static const char esp_mail_str_70[] PROGMEM = " messages"; -static const char esp_mail_str_71[] PROGMEM = "Show "; -static const char esp_mail_str_72[] PROGMEM = - "No message found for search criteria"; -static const char esp_mail_str_73[] PROGMEM = - "Search criteria does not set, fetch the recent message"; -static const char esp_mail_str_74[] PROGMEM = "Fetching message "; -static const char esp_mail_str_75[] PROGMEM = ", UID: "; -static const char esp_mail_str_76[] PROGMEM = ", Number: "; -static const char esp_mail_str_77[] PROGMEM = "> C: fetch message header"; -static const char esp_mail_str_78[] PROGMEM = "Attachments ("; -static const char esp_mail_str_79[] PROGMEM = ")"; -static const char esp_mail_str_80[] PROGMEM = "Downloading attachments..."; -static const char esp_mail_str_81[] PROGMEM = "> C: fetch body part header, "; -static const char esp_mail_str_82[] PROGMEM = "rfc822"; -static const char esp_mail_str_83[] PROGMEM = "reading"; -static const char esp_mail_str_84[] PROGMEM = "Free Heap: "; -static const char esp_mail_str_85[] PROGMEM = "Logging out..."; -static const char esp_mail_str_86[] PROGMEM = - "> C: fetch body sub part header, "; -static const char esp_mail_str_87[] PROGMEM = "Finished reading Email"; -static const char esp_mail_str_88[] PROGMEM = "> C: finished reading Email"; -static const char esp_mail_str_89[] PROGMEM = "SD card mount failed"; -static const char esp_mail_str_90[] PROGMEM = "download"; -static const char esp_mail_str_91[] PROGMEM = ", "; -static const char esp_mail_str_92[] PROGMEM = "%"; -static const char esp_mail_str_93[] PROGMEM = "connection timeout"; -static const char esp_mail_str_94[] PROGMEM = ".html"; -static const char esp_mail_str_95[] PROGMEM = ".txt"; -static const char esp_mail_str_96[] PROGMEM = " folder..."; -static const char esp_mail_str_97[] PROGMEM = ";"; -static const char esp_mail_str_98[] PROGMEM = - "Content-Disposition: attachment\r\n"; -static const char esp_mail_str_99[] PROGMEM = "Date: "; -static const char esp_mail_str_100[] PROGMEM = "Messsage UID: "; -static const char esp_mail_str_101[] PROGMEM = "Messsage ID: "; -static const char esp_mail_str_102[] PROGMEM = "Accept Language: "; -static const char esp_mail_str_103[] PROGMEM = "Content Language: "; -static const char esp_mail_str_104[] PROGMEM = " BODY=BINARYMIME"; -static const char esp_mail_str_105[] PROGMEM = "From Charset: "; -static const char esp_mail_str_106[] PROGMEM = "BDAT "; -static const char esp_mail_str_107[] PROGMEM = "To Charset: "; -static const char esp_mail_str_108[] PROGMEM = "CC: "; -static const char esp_mail_str_109[] PROGMEM = "CC Charset: "; -static const char esp_mail_str_110[] PROGMEM = "delsp=\"no\""; -static const char esp_mail_str_111[] PROGMEM = "Subject Charset: "; -static const char esp_mail_str_112[] PROGMEM = "Message Charset: "; -static const char esp_mail_str_113[] PROGMEM = "Attachment: "; -static const char esp_mail_str_114[] PROGMEM = "File Index: "; -static const char esp_mail_str_115[] PROGMEM = "Filename: "; -static const char esp_mail_str_116[] PROGMEM = "Name: "; -static const char esp_mail_str_117[] PROGMEM = "Size: "; -static const char esp_mail_str_118[] PROGMEM = "Type: "; -static const char esp_mail_str_119[] PROGMEM = "Creation Date: "; -static const char esp_mail_str_120[] PROGMEM = "Connecting to SMTP server..."; -static const char esp_mail_str_121[] PROGMEM = - "SMTP server connected, wait for greeting..."; -static const char esp_mail_str_122[] PROGMEM = "Sending greeting response..."; -static const char esp_mail_str_123[] PROGMEM = "message/rfc822"; -static const char esp_mail_str_124[] PROGMEM = - "Saving message header to file..."; -static const char esp_mail_str_125[] PROGMEM = "Sending message header..."; -static const char esp_mail_str_126[] PROGMEM = "Sending message body..."; -static const char esp_mail_str_127[] PROGMEM = "Sending attachments..."; -static const char esp_mail_str_128[] PROGMEM = "Closing the session..."; -static const char esp_mail_str_129[] PROGMEM = "Message sent successfully"; -static const char esp_mail_str_130[] PROGMEM = "$ LOGIN "; -static const char esp_mail_str_131[] PROGMEM = " "; -static const char esp_mail_str_132[] PROGMEM = - "fail to set up the SSL/TLS structure"; -static const char esp_mail_str_133[] PROGMEM = "$ LIST \"\" *"; -static const char esp_mail_str_134[] PROGMEM = "Comment: "; -static const char esp_mail_str_135[] PROGMEM = "$ EXAMINE \""; -static const char esp_mail_str_136[] PROGMEM = "\""; -static const char esp_mail_str_137[] PROGMEM = "UID "; -static const char esp_mail_str_138[] PROGMEM = " UID"; -static const char esp_mail_str_139[] PROGMEM = " SEARCH"; -static const char esp_mail_str_140[] PROGMEM = "UID"; -static const char esp_mail_str_141[] PROGMEM = "SEARCH"; -static const char esp_mail_str_142[] PROGMEM = "$ UID FETCH "; -static const char esp_mail_str_143[] PROGMEM = "$ FETCH "; -static const char esp_mail_str_144[] PROGMEM = - "HEADER.FIELDS (SUBJECT FROM TO DATE CC Message-ID Accept-Language " - "content-type Content-transfer-encoding Content-Language)"; -static const char esp_mail_str_145[] PROGMEM = "Keyword: "; -static const char esp_mail_str_146[] PROGMEM = "$ LOGOUT"; -static const char esp_mail_str_147[] PROGMEM = " BODY"; -static const char esp_mail_str_148[] PROGMEM = ".MIME]"; -static const char esp_mail_str_149[] PROGMEM = "Bcc: "; -static const char esp_mail_str_150[] PROGMEM = "Sender: "; -static const char esp_mail_str_151[] PROGMEM = "no mailbox opened"; -static const char esp_mail_str_152[] PROGMEM = "."; -static const char esp_mail_str_153[] PROGMEM = "No mailbox opened"; -static const char esp_mail_str_154[] PROGMEM = "Remove FLAG"; -static const char esp_mail_str_155[] PROGMEM = "Add FLAG"; -static const char esp_mail_str_156[] PROGMEM = "]"; -static const char esp_mail_str_157[] PROGMEM = "Set FLAG"; -static const char esp_mail_str_158[] PROGMEM = - "file does not exist or can't access"; -static const char esp_mail_str_159[] PROGMEM = "msg.html"; -static const char esp_mail_str_160[] PROGMEM = "upload "; -static const char esp_mail_str_161[] PROGMEM = "/msg"; -static const char esp_mail_str_163[] PROGMEM = "/rfc822_msg"; -static const char esp_mail_str_164[] PROGMEM = "msg.txt"; -static const char esp_mail_str_165[] PROGMEM = "Content-Length: "; -static const char esp_mail_str_166[] PROGMEM = "binary"; -static const char esp_mail_str_167[] PROGMEM = "Sending inline data..."; -static const char esp_mail_str_168[] PROGMEM = "charset=\""; -static const char esp_mail_str_169[] PROGMEM = "charset="; -static const char esp_mail_str_170[] PROGMEM = "name=\""; -static const char esp_mail_str_171[] PROGMEM = "name="; -static const char esp_mail_str_172[] PROGMEM = "content-transfer-encoding: "; -static const char esp_mail_str_173[] PROGMEM = " LAST"; -static const char esp_mail_str_174[] PROGMEM = "content-description: "; -static const char esp_mail_str_175[] PROGMEM = "content-disposition: "; -static const char esp_mail_str_176[] PROGMEM = "filename=\""; -static const char esp_mail_str_177[] PROGMEM = "filename="; -static const char esp_mail_str_178[] PROGMEM = "size="; -static const char esp_mail_str_179[] PROGMEM = "creation-date=\""; -static const char esp_mail_str_180[] PROGMEM = "creation-date="; -static const char esp_mail_str_181[] PROGMEM = "modification-date=\""; -static const char esp_mail_str_182[] PROGMEM = "modification-date="; -static const char esp_mail_str_183[] PROGMEM = "*"; -static const char esp_mail_str_184[] PROGMEM = "Reply-To: "; -static const char esp_mail_str_185[] PROGMEM = "> E: "; -static const char esp_mail_str_186[] PROGMEM = "out of memory"; -static const char esp_mail_str_187[] PROGMEM = "Message fetch cmpleted"; -static const char esp_mail_str_188[] PROGMEM = "fail to close the mailbox"; -static const char esp_mail_str_189[] PROGMEM = "message-id: "; -static const char esp_mail_str_190[] PROGMEM = "accept-language: "; -static const char esp_mail_str_191[] PROGMEM = "content-language: "; -static const char esp_mail_str_192[] PROGMEM = ")"; -static const char esp_mail_str_193[] PROGMEM = "{"; -static const char esp_mail_str_194[] PROGMEM = "}"; -static const char esp_mail_str_195[] PROGMEM = "$ CLOSE\r\n"; -static const char esp_mail_str_196[] PROGMEM = "> C: send STARTTLS command"; -static const char esp_mail_str_197[] PROGMEM = "> C: close the mailbox folder"; -static const char esp_mail_str_198[] PROGMEM = "("; -static const char esp_mail_str_199[] PROGMEM = " EXISTS"; -static const char esp_mail_str_200[] PROGMEM = " [UIDNEXT "; -static const char esp_mail_str_201[] PROGMEM = "port > "; -static const char esp_mail_str_202[] PROGMEM = "/"; -static const char esp_mail_str_203[] PROGMEM = "/header.txt"; -static const char esp_mail_str_204[] PROGMEM = "/esp.32"; -static const char esp_mail_str_205[] PROGMEM = - "sender Email address is not valid"; -static const char esp_mail_str_206[] PROGMEM = - "some of the recipient Email address is not valid"; -static const char esp_mail_str_207[] PROGMEM = "> C: send Email"; -static const char esp_mail_str_208[] PROGMEM = "Sending Email..."; -static const char esp_mail_str_209[] PROGMEM = "Send command, STARTTLS"; -static const char esp_mail_str_210[] PROGMEM = "Closing the "; -static const char esp_mail_str_211[] PROGMEM = "host > "; -static const char esp_mail_str_212[] PROGMEM = "FLAGS"; -static const char esp_mail_str_213[] PROGMEM = "BODY"; -static const char esp_mail_str_214[] PROGMEM = "PEEK"; -static const char esp_mail_str_215[] PROGMEM = "TEXT"; -static const char esp_mail_str_216[] PROGMEM = "HEADER"; -static const char esp_mail_str_217[] PROGMEM = "FIELDS"; -static const char esp_mail_str_218[] PROGMEM = "["; -static const char esp_mail_str_219[] PROGMEM = "]"; -static const char esp_mail_str_220[] PROGMEM = "MIME"; -static const char esp_mail_str_221[] PROGMEM = "connection lost"; -static const char esp_mail_str_222[] PROGMEM = "set recipient failed"; -static const char esp_mail_str_223[] PROGMEM = " NEW"; -static const char esp_mail_str_224[] PROGMEM = "ALL"; -static const char esp_mail_str_225[] PROGMEM = "> C: connect to IMAP server"; -static const char esp_mail_str_226[] PROGMEM = "windows-874"; -static const char esp_mail_str_227[] PROGMEM = "iso-8859-1"; -static const char esp_mail_str_228[] PROGMEM = "> C: server connected"; -static const char esp_mail_str_229[] PROGMEM = "> C: send imap command, LOGIN"; -static const char esp_mail_str_230[] PROGMEM = "> C: send imap command, LIST"; -static const char esp_mail_str_231[] PROGMEM = "iso-8859-11"; -static const char esp_mail_str_232[] PROGMEM = "> C: search messages"; -static const char esp_mail_str_233[] PROGMEM = "> C: send imap command, FETCH"; -static const char esp_mail_str_234[] PROGMEM = "> C: send imap command, LOGOUT"; -static const char esp_mail_str_235[] PROGMEM = "> C: message fetch completed"; -static const char esp_mail_str_236[] PROGMEM = "> C: connect to SMTP server"; -static const char esp_mail_str_237[] PROGMEM = "tis-620"; -static const char esp_mail_str_238[] PROGMEM = "> C: smtp server connected"; -static const char esp_mail_str_239[] PROGMEM = "> C: send smtp command, HELO"; -static const char esp_mail_str_240[] PROGMEM = - "> C: send smtp command, AUTH LOGIN"; -static const char esp_mail_str_241[] PROGMEM = - "> C: send smtp command, AUTH PLAIN"; -static const char esp_mail_str_242[] PROGMEM = "> C: send message header"; -static const char esp_mail_str_243[] PROGMEM = "> C: send message body"; -static const char esp_mail_str_244[] PROGMEM = "> C: send attachments"; -static const char esp_mail_str_245[] PROGMEM = - "> C: terminate the SMTP session"; -static const char esp_mail_str_246[] PROGMEM = "> C: Message sent successfully"; -static const char esp_mail_str_247[] PROGMEM = "$ SELECT \""; -static const char esp_mail_str_248[] PROGMEM = "> C: open the mailbox folder"; -static const char esp_mail_str_249[] PROGMEM = "$ UID STORE "; -static const char esp_mail_str_250[] PROGMEM = " FLAGS ("; -static const char esp_mail_str_251[] PROGMEM = " +FLAGS ("; -static const char esp_mail_str_252[] PROGMEM = " -FLAGS ("; -static const char esp_mail_str_253[] PROGMEM = "> C: set FLAG"; -static const char esp_mail_str_254[] PROGMEM = "> C: add FLAG"; -static const char esp_mail_str_255[] PROGMEM = "> C: remove FLAG"; -static const char esp_mail_str_256[] PROGMEM = "could not parse flag"; -static const char esp_mail_str_257[] PROGMEM = "delsp=\"yes\""; -static const char esp_mail_str_258[] PROGMEM = "session timed out"; -static const char esp_mail_str_259[] PROGMEM = "delsp=yes"; -static const char esp_mail_str_260[] PROGMEM = "< S: "; -static const char esp_mail_str_261[] PROGMEM = "> C: "; -static const char esp_mail_str_262[] PROGMEM = " NOTIFY="; -static const char esp_mail_str_263[] PROGMEM = ","; -static const char esp_mail_str_264[] PROGMEM = "SUCCESS"; -static const char esp_mail_str_265[] PROGMEM = "FAILURE"; -static const char esp_mail_str_266[] PROGMEM = "DELAY"; -static const char esp_mail_str_267[] PROGMEM = "Sending next Email..."; -static const char esp_mail_str_268[] PROGMEM = "> C: send next Email"; -static const char esp_mail_str_269[] PROGMEM = - "header.fields (content-type Content-transfer-encoding)]"; -static const char esp_mail_str_270[] PROGMEM = "format=\"flowed\""; -static const char esp_mail_str_271[] PROGMEM = "> C: send inline data"; -static const char esp_mail_str_272[] PROGMEM = "Content-transfer-encoding: "; -static const char esp_mail_str_273[] PROGMEM = "Date: "; -static const char esp_mail_str_274[] PROGMEM = "Message-ID:"; -static const char esp_mail_str_275[] PROGMEM = "format=flowed"; -static const char esp_mail_str_276[] PROGMEM = "CC: "; -static const char esp_mail_str_277[] PROGMEM = "boundary=\""; -static const char esp_mail_str_278[] PROGMEM = "quoted-printable"; -static const char esp_mail_str_279[] PROGMEM = "Subject:"; -static const char esp_mail_str_280[] PROGMEM = "> C: no content"; -static const char esp_mail_str_281[] PROGMEM = "fail to open the mailbox"; -static const char esp_mail_str_282[] PROGMEM = "file I/O error"; -static const char esp_mail_str_283[] PROGMEM = "time.nist.gov"; -static const char esp_mail_str_284[] PROGMEM = - "log in was disabled for this server"; -static const char esp_mail_str_285[] PROGMEM = "user="; -static const char esp_mail_str_286[] PROGMEM = "\1auth=Bearer "; -static const char esp_mail_str_287[] PROGMEM = "\1\1"; -static const char esp_mail_str_288[] PROGMEM = - "> C: send smtp command, AUTH XOAUTH2"; -static const char esp_mail_str_289[] PROGMEM = "AUTH XOAUTH2 "; -static const char esp_mail_str_290[] PROGMEM = - "> C: send imap command, AUTHENTICATE PLAIN"; -static const char esp_mail_str_291[] PROGMEM = - "> C: send imap command, AUTH XOAUTH2"; -static const char esp_mail_str_292[] PROGMEM = "$ AUTHENTICATE XOAUTH2 "; -static const char esp_mail_str_293[] PROGMEM = - "OAuth2.0 log in was disabled for this server"; -static const char esp_mail_str_294[] PROGMEM = "{\"status\":"; -static const char esp_mail_str_295[] PROGMEM = "0123456789ABCDEF"; -static const char esp_mail_str_296[] PROGMEM = "pool.ntp.org"; -static const char esp_mail_str_297[] PROGMEM = - "Content-Type: multipart/alternative; boundary=\""; -static const char esp_mail_str_298[] PROGMEM = - "Content-Type: multipart/related; boundary=\""; -static const char esp_mail_str_299[] PROGMEM = - "Content-Disposition: inline; filename=\""; -static const char esp_mail_str_300[] PROGMEM = "Content-Location: "; -static const char esp_mail_str_301[] PROGMEM = "Content-ID: <"; -static const char esp_mail_str_302[] PROGMEM = "cid:"; -static const char esp_mail_str_303[] PROGMEM = - "Finishing the message sending..."; -static const char esp_mail_str_304[] PROGMEM = - "> C: Finish the message sending"; -static const char esp_mail_str_305[] PROGMEM = "connection failed"; -static const char esp_mail_str_306[] PROGMEM = - "some of the requested messages no longer exist"; -static const char esp_mail_str_307[] PROGMEM = "Reading messages..."; -static const char esp_mail_str_308[] PROGMEM = - "> C: reading plain TEXT message"; -static const char esp_mail_str_309[] PROGMEM = "> C: reading HTML message"; -static const char esp_mail_str_310[] PROGMEM = - "> C: performing the SSL/TLS handshake"; -static const char esp_mail_str_311[] PROGMEM = "STARTTLS\r\n"; -static const char esp_mail_str_312[] PROGMEM = "code: "; -static const char esp_mail_str_313[] PROGMEM = ", text: "; -static const char esp_mail_str_314[] PROGMEM = "> C: ESP Mail Client v"; -static const char esp_mail_str_315[] PROGMEM = " +FLAGS.SILENT (\\Deleted)"; -static const char esp_mail_str_316[] PROGMEM = "> C: delete message(s)"; -static const char esp_mail_str_317[] PROGMEM = "$ EXPUNGE"; -static const char esp_mail_str_318[] PROGMEM = "> C: copy message(s) to "; -static const char esp_mail_str_319[] PROGMEM = "$ UID COPY "; -static const char esp_mail_str_320[] PROGMEM = "> C: create folder"; -static const char esp_mail_str_321[] PROGMEM = "> C: delete folder"; -static const char esp_mail_str_322[] PROGMEM = "$ CREATE "; -static const char esp_mail_str_323[] PROGMEM = "$ DELETE "; -static const char esp_mail_str_324[] PROGMEM = "HEADER.FIELDS"; -static const char esp_mail_str_325[] PROGMEM = "flash content message"; -static const char esp_mail_str_326[] PROGMEM = "file content message"; -static const char esp_mail_str_327[] PROGMEM = "\"; size="; -static const char esp_mail_str_328[] PROGMEM = "0.0.0.0"; - -static const char esp_mail_smtp_response_1[] PROGMEM = "AUTH "; -static const char esp_mail_smtp_response_2[] PROGMEM = " LOGIN"; -static const char esp_mail_smtp_response_3[] PROGMEM = " PLAIN"; -static const char esp_mail_smtp_response_4[] PROGMEM = " XOAUTH2"; -static const char esp_mail_smtp_response_5[] PROGMEM = "STARTTLS"; -static const char esp_mail_smtp_response_6[] PROGMEM = "8BITMIME"; -static const char esp_mail_smtp_response_7[] PROGMEM = "BINARYMIME"; -static const char esp_mail_smtp_response_8[] PROGMEM = "CHUNKING"; -static const char esp_mail_smtp_response_9[] PROGMEM = "SMTPUTF8"; -static const char esp_mail_smtp_response_10[] PROGMEM = "PIPELINING"; -static const char esp_mail_smtp_response_11[] PROGMEM = " CRAM-MD5"; -static const char esp_mail_smtp_response_12[] PROGMEM = " DIGEST-MD5"; -static const char esp_mail_smtp_response_13[] PROGMEM = "DSN"; -// Tagged -static const char esp_mail_imap_response_1[] PROGMEM = "$ OK "; -static const char esp_mail_imap_response_2[] PROGMEM = "$ NO "; -static const char esp_mail_imap_response_3[] PROGMEM = "$ BAD "; -// Untagged -static const char esp_mail_imap_response_4[] PROGMEM = "* LIST "; -static const char esp_mail_imap_response_5[] PROGMEM = "* FLAGS "; -static const char esp_mail_imap_response_6[] PROGMEM = "* SEARCH "; -static const char esp_mail_imap_response_7[] PROGMEM = " FETCH "; -static const char esp_mail_imap_response_8[] PROGMEM = " NIL "; -static const char esp_mail_imap_response_9[] PROGMEM = " UID "; -static const char esp_mail_imap_response_10[] PROGMEM = "* CAPABILITY "; -static const char esp_mail_imap_response_11[] PROGMEM = "LOGINDISABLED"; -static const char esp_mail_imap_response_12[] PROGMEM = "AUTH=PLAIN"; -static const char esp_mail_imap_response_13[] PROGMEM = "AUTH=XOAUTH2"; -static const char esp_mail_imap_response_14[] PROGMEM = "STARTTLS"; -static const char esp_mail_imap_response_15[] PROGMEM = "CRAM-MD5"; -static const char esp_mail_imap_response_16[] PROGMEM = "DIGEST-MD5"; - -static const char imap_7bit_key1[] PROGMEM = "=20"; -static const char imap_7bit_val1[] PROGMEM = " "; -static const char imap_7bit_key2[] PROGMEM = "=2C"; -static const char imap_7bit_val2[] PROGMEM = ","; -static const char imap_7bit_key3[] PROGMEM = "=E2=80=99"; -static const char imap_7bit_val3[] PROGMEM = "'"; -static const char imap_7bit_key4[] PROGMEM = "=0A"; -static const char imap_7bit_val4[] PROGMEM = "\r\n"; -static const char imap_7bit_key5[] PROGMEM = "=0D"; -static const char imap_7bit_val5[] PROGMEM = "\r\n"; -static const char imap_7bit_key6[] PROGMEM = "=A0"; -static const char imap_7bit_val6[] PROGMEM = " "; -static const char imap_7bit_key7[] PROGMEM = "=B9"; -static const char imap_7bit_val7[] PROGMEM = "$sup1"; -static const char imap_7bit_key8[] PROGMEM = "=C2=A0"; -static const char imap_7bit_val8[] PROGMEM = " "; -static const char imap_7bit_key9[] PROGMEM = "=\r\n"; -static const char imap_7bit_val9[] PROGMEM = ""; -static const char imap_7bit_key10[] PROGMEM = "=E2=80=A6"; -static const char imap_7bit_val10[] PROGMEM = "…"; -static const char imap_7bit_key11[] PROGMEM = "=E2=80=A2"; -static const char imap_7bit_val11[] PROGMEM = "•"; -static const char imap_7bit_key12[] PROGMEM = "=E2=80=93"; -static const char imap_7bit_val12[] PROGMEM = "–"; -static const char imap_7bit_key13[] PROGMEM = "=E2=80=94"; -static const char imap_7bit_val13[] PROGMEM = "—"; - -static const unsigned char b64_index_table[65] = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; -static const char boundary_table[] PROGMEM = - "=_abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - -__attribute__((used)) static bool compFunc(uint32_t i, uint32_t j) -{ - return (i > j); -} - -class MessageList -{ -public: - friend class IMAPSession; - MessageList(){}; - ~MessageList() { clear(); }; - void add(int uid) - { - if (uid > 0) - _list.push_back(uid); - } - - void clear() { _list.clear(); } - -private: - std::vector _list = std::vector(); -}; - -/* The class that provides the info of selected or opened mailbox folder */ -class SelectedFolderInfo -{ -public: - friend class ESP_Mail_Client; - friend class IMAPSession; - SelectedFolderInfo(){}; - ~SelectedFolderInfo() { clear(); }; - - /* Get the flags count for this mailbox */ - size_t flagCount() { return _flags.size(); }; - - /* Get the numbers of messages in this mailbox */ - size_t msgCount() { return _msgCount; }; - - /* Get the predict next message UID */ - size_t nextUID() { return _nextUID; }; - - /* Get the numbers of messages from search result based on the search criteria - */ - size_t searchCount() { return _searchCount; }; - - /* Get the numbers of messages to be stored in the ressult */ - size_t availableMessages() { return _availableItems; }; - - /* Get the flag argument at the specified index */ - String flag(size_t index) - { - if (index < _flags.size()) - return _flags[index].c_str(); - return ""; - } - -private: - void addFlag(const char *flag) { _flags.push_back(flag); }; - void clear() - { - for (size_t i = 0; i < _flags.size(); i++) - std::string().swap(_flags[i]); - _flags.clear(); - } - size_t _msgCount = 0; - size_t _nextUID = 0; - size_t _searchCount = 0; - size_t _availableItems = 0; - std::vector _flags = std::vector(); -}; - -/* The class that provides the list of FolderInfo e.g. name, attributes and - * delimiter */ -class FoldersCollection -{ -public: - friend class ESP_Mail_Client; - friend class IMAPSession; - FoldersCollection(){}; - ~FoldersCollection() { clear(); }; - size_t size() { return _folders.size(); }; - - struct esp_mail_folder_info_item_t info(size_t index) - { - struct esp_mail_folder_info_item_t fd; - if (index < _folders.size()) - { - fd.name = _folders[index].name.c_str(); - fd.attributes = _folders[index].attributes.c_str(); - fd.delimiter = _folders[index].delimiter.c_str(); - } - return fd; - } - -private: - void add(struct esp_mail_folder_info_t &fd) { _folders.push_back(fd); }; - void clear() - { - for (size_t i = 0; i < _folders.size(); i++) - { - if (_folders[i].name.length() > 0) - std::string().swap(_folders[i].name); - if (_folders[i].attributes.length() > 0) - std::string().swap(_folders[i].attributes); - if (_folders[i].delimiter.length() > 0) - std::string().swap(_folders[i].delimiter); - } - _folders.clear(); - } - std::vector _folders = - std::vector(); -}; - -/* The class that provides the status of message feching and searching */ -class IMAP_Status -{ -public: - IMAP_Status(); - ~IMAP_Status(); - const char *info(); - bool success(); - void empty(); - friend class IMAPSession; - - std::string _info = ""; - bool _success = false; -}; - -/* The SMTP message class */ -class SMTP_Message -{ -public: - SMTP_Message(){}; - ~SMTP_Message() { clear(); }; - - void resetAttachItem(SMTP_Attachment &att) - { - att.blob.size = 0; - att.blob.data = nullptr; - att.file.path = ""; - att.file.storage_type = esp_mail_file_storage_type_none; - att.descr.name = ""; - att.descr.filename = ""; - att.descr.transfer_encoding = ""; - att.descr.content_encoding = ""; - att.descr.mime = ""; - att.descr.content_id = ""; - att._int.att_type = esp_mail_att_type_none; - att._int.index = 0; - att._int.msg_uid = 0; - att._int.flash_blob = false; - att._int.binary = false; - att._int.parallel = false; - att._int.cid = ""; - } - - void clear() - { - sender.name = ""; - sender.email = ""; - subject = ""; - text.charSet = ""; - text.content = ""; - text.content_type = ""; - text.embed.enable = false; - html.charSet = ""; - html.content = ""; - html.content_type = ""; - html.embed.enable = false; - response.reply_to = ""; - response.notify = esp_mail_smtp_notify::esp_mail_smtp_notify_never; - priority = esp_mail_smtp_priority::esp_mail_smtp_priority_normal; - - for (size_t i = 0; i < _rcp.size(); i++) - { - _rcp[i].name = ""; - _rcp[i].email = ""; - } - - for (size_t i = 0; i < _cc.size(); i++) - _cc[i].email = ""; - - for (size_t i = 0; i < _bcc.size(); i++) - _bcc[i].email = ""; - - for (size_t i = 0; i < _hdr.size(); i++) - _hdr[i] = ""; - - for (size_t i = 0; i < _att.size(); i++) - { - _att[i].descr.filename = ""; - _att[i].blob.data = nullptr; - _att[i].descr.mime = ""; - _att[i].descr.name = ""; - _att[i].blob.size = 0; - _att[i].descr.transfer_encoding = ""; - _att[i].file.path = ""; - _att[i].file.storage_type = esp_mail_file_storage_type_none; - } - - for (size_t i = 0; i < _parallel.size(); i++) - { - _parallel[i].descr.filename = ""; - _parallel[i].blob.data = nullptr; - _parallel[i].descr.mime = ""; - _parallel[i].descr.name = ""; - _parallel[i].blob.size = 0; - _parallel[i].descr.transfer_encoding = ""; - _parallel[i].file.path = ""; - _parallel[i].file.storage_type = esp_mail_file_storage_type_none; - } - _rcp.clear(); - _cc.clear(); - _bcc.clear(); - _hdr.clear(); - _att.clear(); - _parallel.clear(); - } - - /** Clear all the inline images - */ - void clearInlineimages() - { - for (int i = (int)_att.size() - 1; i >= 0; i--) - { - if (_att[i]._int.att_type == esp_mail_att_type_inline) - _att.erase(_att.begin() + i); - } - }; - - /* Clear all the attachments */ - void clearAttachments() - { - for (int i = (int)_att.size() - 1; i >= 0; i--) - { - if (_att[i]._int.att_type == esp_mail_att_type_attachment) - _att.erase(_att.begin() + i); - } - - for (int i = (int)_parallel.size() - 1; i >= 0; i--) - _parallel.erase(_parallel.begin() + i); - }; - - /** Clear all rfc822 message attachment - */ - void clearRFC822Messages() - { - for (int i = (int)_rfc822.size() - 1; i >= 0; i--) - { - _rfc822[i].clear(); - _rfc822.erase(_rfc822.begin() + i); - } - }; - - /** Clear the primary recipient mailboxes - */ - void clearRecipients() { _rcp.clear(); }; - - /** Clear the Carbon-copy recipient mailboxes - */ - void clearCc() { _cc.clear(); }; - - /** Clear the Blind-carbon-copy recipient mailboxes - */ - void clearBcc() { _bcc.clear(); }; - - /** Clear the custom message headers - */ - void clearHeader() { _hdr.clear(); }; - - /** Add attachment to the message - * - * @param att The SMTP_Attachment data item - */ - void addAttachment(SMTP_Attachment &att) - { - att._int.att_type = esp_mail_att_type_attachment; - att._int.parallel = false; - att._int.flash_blob = true; - _att.push_back(att); - }; - - /** Add parallel attachment to the message - * - * @param att The SMTP_Attachment data item - */ - void addParallelAttachment(SMTP_Attachment &att) - { - att._int.att_type = esp_mail_att_type_attachment; - att._int.parallel = true; - att._int.flash_blob = true; - _parallel.push_back(att); - }; - - /** Add inline image to the message - * - * @param att The SMTP_Attachment data item - */ - void addInlineImage(SMTP_Attachment &att) - { - att._int.flash_blob = true; - att._int.parallel = false; - att._int.att_type = esp_mail_att_type_inline; - char *tmp = new char[36]; - memset(tmp, 0, 36); - itoa(random(10000000, 20000000), tmp, 10); - att._int.cid = tmp; - delete[] tmp; - _att.push_back(att); - }; - - /** Add rfc822 message to the message - * - * @param msg The RFC822_Message class object - */ - void addMessage(SMTP_Message &msg) { _rfc822.push_back(msg); } - - /** Add the primary recipient mailbox to the message - * - * @param name The name of primary recipient - * @param email The Email address of primary recipient - */ - void addRecipient(const char *name, const char *email) - { - struct esp_mail_smtp_recipient_t rcp; - rcp.name = name; - rcp.email = email; - _rcp.push_back(rcp); - }; - - /** Add Carbon-copy recipient mailbox - * - * @param email The Email address of the secondary recipient - */ - void addCc(const char *email) - { - struct esp_mail_smtp_recipient_address_t cc; - cc.email = email; - _cc.push_back(cc); - }; - - /** Add Blind-carbon-copy recipient mailbox - * - * @param email The Email address of the tertiary recipient - */ - void addBcc(const char *email) - { - struct esp_mail_smtp_recipient_address_t bcc; - bcc.email = email; - _bcc.push_back(bcc); - }; - - /** Add the custom header to the message - * - * @param hdr The header name and value - */ - void addHeader(const char *hdr) { _hdr.push_back(hdr); }; - - /* The message author config */ - struct esp_mail_email_info_t sender; - - /* The topic of message */ - const char *subject = ""; - - /* The message type */ - byte type = esp_mail_msg_type_none; - - /* The PLAIN text message */ - struct esp_mail_plain_body_t text; - - /* The HTML text message */ - struct esp_mail_html_body_t html; - - /* The response config */ - struct esp_mail_smtp_msg_response_t response; - - /* The priority of the message */ - esp_mail_smtp_priority priority = - esp_mail_smtp_priority::esp_mail_smtp_priority_normal; - - /* The enable options */ - struct esp_mail_smtp_enable_option_t enable; - - /* The message from config */ - struct esp_mail_email_info_t from; - - /* The message identifier */ - const char *messageID = ""; - - /* The keywords or phrases, separated by commas */ - const char *keyword = ""; - - /* The comment about message */ - const char *comment = ""; - - /* The date of message */ - const char *date = ""; - - /* The return recipient of the message */ - const char *return_path = ""; - -private: - friend class ESP_Mail_Client; - std::vector _rcp = - std::vector(); - std::vector _cc = - std::vector(); - std::vector _bcc = - std::vector(); - std::vector _hdr = std::vector(); - std::vector _att = std::vector(); - std::vector _parallel = std::vector(); - std::vector _rfc822 = std::vector(); -}; - -class SMTP_Status -{ -public: - friend class SMTPSession; - friend class ESP_Mail_Client; - - SMTP_Status(); - ~SMTP_Status(); - const char *info(); - bool success(); - void empty(); - size_t completedCount(); - size_t failedCount(); - -private: - std::string _info = ""; - bool _success = false; - size_t _sentSuccess = 0; - size_t _sentFailed = 0; -}; - -typedef void (*imapStatusCallback)(IMAP_Status); -typedef void (*smtpStatusCallback)(SMTP_Status); - -class ESP_Mail_Client -{ - -public: - /** Sending Email through the SMTP server - * - * @param smtp The pointer to SMTP session object which holds the data and the - * TCP client. - * @param msg The pointer to SMTP_Message class which contains the header, - * body, and attachments. - * @param closeSession The option to Close the SMTP session after sent. - * @return The boolean value indicates the success of operation. - */ - bool sendMail(SMTPSession *smtp, SMTP_Message *msg, bool closeSession = true); - - /** Reading Email through IMAP server. - * - * @param imap The pointer to IMAP sesssion object which holds the data and - the TCP client. - - * @param closeSession The option to close the IMAP session after fetching or - searching the Email. - * @return The boolean value indicates the success of operation. - */ - bool readMail(IMAPSession *imap, bool closeSession = true); - - /** Set the argument to the Flags for the specified message. - * - * @param imap The pointer to IMAP session object which holds the data and the - * TCP client. - * @param msgUID The UID of the message. - * @param flags The flag list to set. - * @param closeSession The option to close the IMAP session after set flag. - * @return The boolean value indicates the success of operation. - */ - bool setFlag(IMAPSession *imap, int msgUID, const char *flags, - bool closeSession); - - /** Add the argument to the Flags for the specified message. - * - * @param imap The pointer to IMAP session object which holds the data and the - * TCP client. - * @param msgUID The UID of the message. - * @param flags The flag list to set. - * @param closeSession The option to close the IMAP session after add flag. - * @return The boolean value indicates the success of operation. - */ - bool addFlag(IMAPSession *imap, int msgUID, const char *flags, - bool closeSession); - - /** Remove the argument from the Flags for the specified message. - * - * @param imap The pointer to IMAP session object which holds the data and the - * TCP client. - * @param msgUID The UID of the message that flags to be removed. - * @param flags The flag list to remove. - * @param closeSession The option to close the IMAP session after remove flag. - * @return The boolean value indicates the success of operation. - */ - bool removeFlag(IMAPSession *imap, int msgUID, const char *flags, - bool closeSession); - - /** Initialize the SD card with the SPI port. - * - * @param sck The SPI Clock pin (ESP32 only). - * @param miso The SPI MISO pin (ESSP32 only). - * @param mosi The SPI MOSI pin (ESP32 only). - * @param ss The SPI Chip/Slave Select pin (ESP32 and ESP8266). - * @return The boolean value indicates the success of operation. - */ - bool sdBegin(uint8_t sck, uint8_t miso, uint8_t mosi, uint8_t ss); - - /** Initialize the SD card with the default SPI port. - * - * @return The boolean value which indicates the success of operation. - */ - bool sdBegin(); - - /** Initialize the SD_MMC card (ESSP32 only). - * - * @param mountpoint The mounting point. - * @param mode1bit Allow 1 bit data line. - * @param format_if_mount_failed Format SD_MMC card if mount failed. - * @return The boolean value indicates the success of operation. - */ - bool sdMMCBegin(const char *mountpoint = "/sdcard", bool mode1bit = false, bool format_if_mount_failed = false); - - - ESPTimeHelper Time; - -private: - friend class SMTPSession; - friend class IMAPSession; -#if defined(ESP8266) - void setClock(float offset); -#endif - - RFC2047_Decoder RFC2047Decoder; - File file; - - bool _sdOk = false; - bool _flashOk = false; - bool _sdConfigSet = false; - uint8_t _sck, _miso, _mosi, _ss; - const char *sd_mmc_mountpoint = ""; - bool sd_mmc_mode1bit = false; - bool sd_mmc_format_if_mount_failed = false; - -#if defined(ESP8266) - bool _clockReady = false; - uint8_t _sdPin = SD_CS_PIN; - float _gmtOffset = 0.0; -#endif - - unsigned long _lastReconnectMillis = 0; - uint16_t _reconnectTimeout = ESP_MAIL_WIFI_RECONNECT_TIMEOUT; - - bool _sendMail(SMTPSession *smtp, SMTP_Message *msg, - bool closeSession = true); - bool ethLinkUp(); - bool reconnect(SMTPSession *smtp, unsigned long dataTime = 0); - bool reconnect(IMAPSession *imap, unsigned long dataTime = 0, - bool downloadRequestuest = false); - void closeTCP(SMTPSession *smtp); - void closeTCP(IMAPSession *imap); - void getMIME(const char *ext, std::string &mime); - void mimeFromFile(const char *name, std::string &mime); -#if defined(ESP32) - void setSecure(ESP_Mail_HTTPClient32 &httpClient, ESP_Mail_Session *session, - std::shared_ptr caCert); -#elif defined(ESP8266) - void setSecure(ESP_Mail_HTTPClient &httpClient, ESP_Mail_Session *session, - std::shared_ptr caCert); -#endif - void delS(char *p); - char *newS(size_t len); - char *newS(char *p, size_t len); - char *newS(char *p, size_t len, char *d); - bool strcmpP(const char *buf, int ofs, PGM_P beginH); - int strposP(const char *buf, PGM_P beginH, int ofs); - char *strP(PGM_P pgm); - void appendP(std::string &buf, PGM_P p, bool empty); - char *intStr(int value); - void errorStatusCB(SMTPSession *smtp, int error); - size_t smtpSendP(SMTPSession *smtp, PGM_P v, bool newline = false); - size_t smtpSend(SMTPSession *smtp, const char *data, bool newline = false); - size_t smtpSend(SMTPSession *smtp, int data, bool newline = false); - size_t smtpSend(SMTPSession *smtp, uint8_t *data, size_t size); - bool getMultipartFechCmd(IMAPSession *imap, int msgIdx, - std::string &partText); - bool multipartMember(const std::string &part, const std::string &check); - bool fetchMultipartBodyHeader(IMAPSession *imap, int msgIdx); - bool connected(IMAPSession *imap); - bool imapAuth(IMAPSession *imap); - bool sendIMAPCommand(IMAPSession *imap, int msgIndex, int cmdCase); - bool handleSMTPError(SMTPSession *smtp, int err, bool ret = false); - void errorStatusCB(IMAPSession *imap, int error); - size_t imapSendP(IMAPSession *imap, PGM_P v, bool newline = false); - size_t imapSend(IMAPSession *imap, const char *data, bool nwline = false); - size_t imapSend(IMAPSession *imap, int data, bool newline = false); - std::string getBoundary(size_t len); - std::string getEncodedToken(IMAPSession *imap); - bool imapLogout(IMAPSession *imap); - bool sendParallelAttachments(SMTPSession *smtp, SMTP_Message *msg, - const std::string &boundary); - bool sendAttachments(SMTPSession *smtp, SMTP_Message *msg, - const std::string &boundary, bool parallel = false); - - bool sendMSGData(SMTPSession *smtp, SMTP_Message *msg, bool closeSession, - bool rfc822MSG); - bool sendRFC822Msg(SMTPSession *smtp, SMTP_Message *msg, - const std::string &boundary, bool closeSession, - bool rfc822MSG); - void getRFC822MsgEnvelope(SMTPSession *smtp, SMTP_Message *msg, - std::string &buf); - bool bdat(SMTPSession *smtp, SMTP_Message *msg, int len, bool last); - void checkBinaryData(SMTPSession *smtp, SMTP_Message *msg); - bool sendBlob(SMTPSession *smtp, SMTP_Message *msg, SMTP_Attachment *att); - bool sendFile(SMTPSession *smtp, SMTP_Message *msg, SMTP_Attachment *att, - File &file); - bool openFileRead(SMTPSession *smtp, SMTP_Message *msg, SMTP_Attachment *att, - File &file, std::string &s, std::string &buf, - const std::string &boundary, bool inlined); - bool openFileRead2(SMTPSession *smtp, SMTP_Message *msg, File &file, - const char *path, esp_mail_file_storage_type storageType); - bool sendInline(SMTPSession *smtp, SMTP_Message *msg, - const std::string &boundary, byte type); - void debugInfoP(PGM_P info); - size_t numAtt(SMTPSession *smtp, esp_mail_attach_type type, - SMTP_Message *msg); - bool validEmail(const char *s); - bool checkEmail(SMTPSession *smtp, SMTP_Message *msg); - bool sendPartText(SMTPSession *smtp, SMTP_Message *msg, byte type, - const char *boundary); - char *getUID(); - bool sendBlobBody(SMTPSession *smtp, SMTP_Message *msg, uint8_t type); - bool sendFileBody(SMTPSession *smtp, SMTP_Message *msg, uint8_t type); - void encodingText(SMTPSession *smtp, SMTP_Message *msg, uint8_t type, - std::string &content); - void splitTk(std::string &str, std::vector &tk, - const char *delim); - void formatFlowedText(std::string &content); - void softBreak(std::string &content, const char *quoteMarks); - bool sendMSG(SMTPSession *smtp, SMTP_Message *msg, - const std::string &boundary); - void getAttachHeader(std::string &header, const std::string &boundary, - SMTP_Attachment *attach, size_t size); - void getRFC822PartHeader(SMTPSession *smtp, std::string &header, - const std::string &boundary); - void getInlineHeader(std::string &header, const std::string &boundary, - SMTP_Attachment *inlineAttach, size_t size); - unsigned char *decodeBase64(const unsigned char *src, size_t len, - size_t *out_len); - std::string encodeBase64Str(const unsigned char *src, size_t len); - std::string encodeBase64Str(uint8_t *src, size_t len); - void encodeQP(const char *buf, char *out); - bool sendBase64(SMTPSession *smtp, SMTP_Message *msg, - const unsigned char *data, size_t len, bool flashMem, - const char *filename, bool report); - bool sendBase64Stream(SMTPSession *smtp, SMTP_Message *msg, File file, - const char *filename, bool report); - void smtpCBP(SMTPSession *smtp, PGM_P info, bool success = false); - void smtpCB(SMTPSession *smtp, const char *info, bool success = false); - void imapCBP(IMAPSession *imap, PGM_P info, bool success); - void imapCB(IMAPSession *imap, const char *info, bool success); - int readLine(WiFiClient *stream, char *buf, int bufLen, bool crlf, - int &count); -#if defined(ESP32) - int _readLine(ESP_Mail_WCS32 *stream, char *buf, int bufLen, bool crlf, - int &count); -#elif defined(ESP8266) - int _readLine(ESP_Mail::ESP_Mail_WCS *stream, char *buf, int bufLen, - bool crlf, int &count); -#endif - int getMSGNUM(IMAPSession *imap, char *buf, int bufLen, int &chunkIdx, - bool &endSearch, int &nump, const char *key, const char *pc); - void handleHeader(IMAPSession *imap, char *buf, int bufLen, int &chunkIdx, - struct esp_mail_message_header_t &header, int &headerState, - int &octetCount); - void setHeader(IMAPSession *imap, char *buf, - struct esp_mail_message_header_t &header, int state); - void handlePartHeader(IMAPSession *imap, char *buf, int &chunkIdx, - struct esp_mail_message_part_info_t &part); - char *subStr(const char *buf, PGM_P beginH, PGM_P endH, int beginPos, - int endPos = 0); - struct esp_mail_message_part_info_t *cPart(IMAPSession *imap); - struct esp_mail_message_header_t *cHeader(IMAPSession *imap); - void strcat_c(char *str, char c); - int strpos(const char *haystack, const char *needle, int offset); - char *stristr(const char *str1, const char *str2); - char *rstrstr(const char *haystack, const char *needle); - int rstrpos(const char *haystack, const char *needle, int offset); - void getResponseStatus(const char *buf, esp_mail_smtp_status_code respCode, - int beginPos, - struct esp_mail_smtp_response_status_t &status); - void handleAuth(SMTPSession *smtp, char *buf); - std::string getEncodedToken(SMTPSession *smtp); - bool connected(SMTPSession *smtp); - bool setSendingResult(SMTPSession *smtp, SMTP_Message *msg, bool result); - bool smtpAuth(SMTPSession *smtp); - int available(SMTPSession *smtp); - bool handleSMTPResponse(SMTPSession *smtp, esp_mail_smtp_status_code respCode, - int errCode); - int available(IMAPSession *imap); - bool handleIMAPResponse(IMAPSession *imap, int errCode, bool closeSession); - void downloadReport(IMAPSession *imap, int progress); - void fetchReport(IMAPSession *imap, int progress, bool html); - void searchReport(int progress, const char *percent); - void uploadReport(const char *filename, int progress); - int cMSG(IMAPSession *imap); - int cIdx(IMAPSession *imap); - esp_mail_imap_response_status imapResponseStatus(IMAPSession *imap, - char *response); - void saveHeader(IMAPSession *imap); - esp_mail_char_decoding_scheme getEncodingFromCharset(const char *enc); - void decodeHeader(std::string &headerField, std::string &headerEnc); - bool handleAttachment(IMAPSession *imap, char *buf, int bufLen, int &chunkIdx, - File &file, std::string &filePath, - bool &downloadRequest, int &octetCount, - int &octetLength, int &oCount, int &reportState, - int &downloadCount); - int decodeLatin1_UTF8(unsigned char *out, int *outlen, - const unsigned char *in, int *inlen); - void decodeTIS620_UTF8(char *out, const char *in, size_t len); - void decodeText(IMAPSession *imap, char *buf, int bufLen, int &chunkIdx, - File &file, std::string &filePath, bool &downloadRequest, - int &octetLength, int &readDataLen, int &readCount); - void prepareFilePath(IMAPSession *imap, std::string &filePath, bool header); - int decodeChar(const char *s); - void decodeQP(const char *buf, char *out); - char *decode7Bit(char *buf); - char *strReplace(char *orig, char *rep, char *with); - char *strReplaceP(char *buf, PGM_P key, PGM_P value); - bool authFailed(char *buf, int bufLen, int &chunkIdx, int ofs); - void handleFolders(IMAPSession *imap, char *buf); - void handleCapability(IMAPSession *imap, char *buf, int &chunkIdx); - void handleExamine(IMAPSession *imap, char *buf); - bool handleIMAPError(IMAPSession *imap, int err, bool ret); - bool _setFlag(IMAPSession *imap, int msgUID, const char *flags, - uint8_t action, bool closeSession); - void createDirs(std::string dirs); - bool sdTest(); -}; - -class IMAPSession -{ -public: - IMAPSession(); - ~IMAPSession(); - - /** Begin the IMAP server connection. - * - * @param session The pointer to ESP_Mail_Session structured data that keeps - * the server and log in details. - * @param config The pointer to IMAP_Config structured data that keeps the - * operation options. - * @return The boolean value which indicates the success of operation. - */ - bool connect(ESP_Mail_Session *session, IMAP_Config *config); - - /** Close the IMAP session. - * - * @return The boolean value which indicates the success of operation. - */ - bool closeSession(); - - /** Set to enable the debug. - * - * @param level The level to enable the debug message - * level = 0, no debug - * level = 1, basic debug - * level = 2, full debug 1 - * level = 333, full debug 2 - */ - void debug(int level); - - /** Get the list of all the mailbox folders since the TCP session was opened - * and user was authenticated. - * - * @param folders The FoldersCollection class that contains the collection of - * the - * FolderInfo structured data. - * @return The boolean value which indicates the success of operation. - */ - bool getFolders(FoldersCollection &folders); - - /** Select or open the mailbox folder to search or fetch the message inside. - * - * @param folderName The known mailbox folder name. The default name is INBOX. - * @param readOnly The option to open the mailbox for read only. Set this - * option to false when you wish - * to modify the Flags using the setFlag, addFlag and removeFlag functions. - * @return The boolean value which indicates the success of operation. - */ - bool selectFolder(const char *folderName, bool readOnly = true); - - /** Open the mailbox folder to read or search the mesages. - * - * @param folderName The name of known mailbox folder to be opened. - * @param readOnly The option to open the mailbox for reading only. Set this - * option to false when you wish - * to modify the flags using the setFlag, addFlag and removeFlag functions. - * @return The boolean value which indicates the success of operation. - */ - bool openFolder(const char *folderName, bool readOnly = true); - - /** Close the mailbox folder that was opened. - * - * @param folderName The known mailbox folder name. - * @return The boolean value which indicates the success of operation. - */ - bool closeFolder(const char *folderName); - - /** Create folder. - * - * @param folderName The name of folder to create. - * @return The boolean value which indicates the success of operation. - */ - bool createFolder(const char *folderName); - - /** Delete folder. - * - * @param folderName The name of folder to delete. - * @return The boolean value which indicates the success of operation. - */ - bool deleteFolder(const char *folderName); - - /** Copy the messages to the defined mailbox folder. - * - * @param toCopy The pointer to the MessageListList class that contains the - * list of messages to copy. - * @param dest The destination folder that the messages to copy to. - * @return The boolean value which indicates the success of operation. - */ - bool copyMessages(MessageList *toCopy, const char *dest); - - /** Delete the messages in the opened mailbox folder. - * - * @param toDelete The pointer to the MessageListList class that contains the - * list of messages to delete. - * @param expunge The boolean option to expunge all messages. - * @return The boolean value which indicates the success of operation. - */ - bool deleteMessages(MessageList *toDelete, bool expunge = false); - - /** Assign the callback function that returns the operating status when - * fetching or reading the Email. - * - * @param imapCallback The function that accepts the imapStatusCallback as - * parameter. - */ - void callback(imapStatusCallback imapCallback); - - /** Determine if no message body contained in the search result and only the - * message header is available. - */ - bool headerOnly(); - - /** Get the message list from search or fetch the Emails - * - * @return The IMAP_MSG_List structured data which contains text and html - * contents, - * attachments, inline images, embedded rfc822 messages details for each - * message. - */ - IMAP_MSG_List data(); - - /** Get the details of the selected or opned mailbox folder - * - * @return The SelectedFolderInfo class which contains the info about flags, - * total messages, next UID, - * search count and the available messages count. - */ - SelectedFolderInfo selectedFolder(); - - /** Get the error details when readingg the Emails - * - * @return The string of error details. - */ - String errorReason(); - - /** Clear all the cache data stored in the IMAP session object. - */ - void empty(); - - friend class ESP_Mail_Client; - friend class foldderList; - -private: - void clearMessageData(); - void checkUID(); - void checkPath(); - void getMessages(uint16_t messageIndex, struct esp_mail_imap_msg_item_t &msg); - void getRFC822Messages(uint16_t messageIndex, - struct esp_mail_imap_msg_item_t &msg); - bool closeMailbox(); - bool openMailbox(const char *folder, esp_mail_imap_auth_mode mode, - bool waitResponse); - bool getMailboxes(FoldersCollection &flders); - bool checkCapability(); - - bool _tcpConnected = false; - struct esp_mail_imap_response_status_t _imapStatus; - int _cMsgIdx = 0; - int _cPartIdx = 0; - int _totalRead = 0; - std::vector _headers = - std::vector(); - - esp_mail_imap_command _imap_cmd = - esp_mail_imap_command::esp_mail_imap_cmd_login; - // std::string _partNumStr = ""; - std::vector _multipart_levels = - std::vector(); - int _rfc822_part_count = 0; - esp_mail_file_storage_type _storageType = - esp_mail_file_storage_type::esp_mail_file_storage_type_flash; - bool _unseen = false; - bool _readOnlyMode = true; - struct esp_mail_auth_capability_t _auth_capability; - ESP_Mail_Session *_sesson_cfg; - std::string _currentFolder = ""; - bool _mailboxOpened = false; - std::string _nextUID = ""; - - struct esp_mail_imap_read_config_t *_config = nullptr; - - bool _headerOnly = true; - bool _uidSearch = false; - bool _headerSaved = false; - bool _debug = false; - int _debugLevel = 0; - bool _secure = false; - imapStatusCallback _readCallback = NULL; - - std::vector _msgNum = std::vector(); - FoldersCollection _folders; - SelectedFolderInfo _mbif; - - int _certType = -1; - std::shared_ptr _caCert = nullptr; - -#if defined(ESP32) - ESP_Mail_HTTPClient32 httpClient; -#elif defined(ESP8266) - ESP_Mail_HTTPClient httpClient; -#endif - - IMAP_Status _cbData; -}; - -class SendingResult -{ -private: - std::vector _result = - std::vector(); - void add(struct esp_mail_smtp_send_status_t r) - { - struct esp_mail_smtp_send_status_t _r = r; - _result.push_back(_r); - } - void clear() - { - for (size_t i = 0; i < _result.size(); i++) - { - _result[i].recipients = ""; - _result[i].subject = ""; - _result[i].timesstamp = 0; - _result[i].completed = false; - } - _result.clear(); - } - -public: - friend class SMTPSession; - friend class ESP_Mail_Client; - SendingResult(){}; - ~SendingResult() { clear(); }; - SMTP_Result getItem(size_t index) - { - struct esp_mail_smtp_send_status_t r; - if (index < _result.size()) - return _result[index]; - return r; - } - size_t size() { return _result.size(); }; -}; - -class SMTPSession -{ -public: - SMTPSession(); - ~SMTPSession(); - - /** Begin the SMTP server connection. - * - * @param session The pointer to ESP_Mail_Session structured data that keeps - * the server and log in details. - * @return The boolean value indicates the success of operation. - */ - bool connect(ESP_Mail_Session *session); - - /** Close the SMTP session. - * - */ - bool closeSession(); - - /** Set to enable the debug. - * - * @param level The level to enable the debug message - * level = 0, no debug - * level = 1, basic debug - * level = 2, full debug 1 - * level = 333, full debug 2 - */ - void debug(int level); - - /** Get the error details when sending the Email - * - * @return The string of error details. - */ - String errorReason(); - - /** Set the Email sending status callback function. - * - * @param smtpCallback The callback function that accept the - * smtpStatusCallback param. - */ - void callback(smtpStatusCallback smtpCallback); - - SendingResult sendingResult; - - friend class ESP_Mail_Client; - -private: - bool _tcpConnected = false; - struct esp_mail_smtp_response_status_t _smtpStatus; - int _sentSuccessCount = 0; - int _sentFailedCount = 0; - bool _chunkedEnable = false; - int _chunkCount = 0; - - esp_mail_smtp_command _smtp_cmd = - esp_mail_smtp_command::esp_mail_smtp_cmd_greeting; - struct esp_mail_auth_capability_t _auth_capability; - struct esp_mail_smtp_capability_t _send_capability; - ESP_Mail_Session *_sesson_cfg = NULL; - - bool _debug = false; - int _debugLevel = 0; - bool _secure = false; - smtpStatusCallback _sendCallback = NULL; - - SMTP_Status _cbData; - struct esp_mail_smtp_msg_type_t _msgType; - - int _certType = -1; - std::shared_ptr _caCert = nullptr; - -#if defined(ESP32) - ESP_Mail_HTTPClient32 httpClient; -#elif defined(ESP8266) - ESP_Mail_HTTPClient httpClient; -#endif -}; - - -//#define EMAIL_DEBUG_PRINTLN Serial.println -//#define EMAIL_DEBUG_PRINT Serial.print -#define EMAIL_DEBUG_PRINTLN Tasmota_print -#define EMAIL_DEBUG_PRINT Tasmota_print - -extern void Tasmota_print(const char *); - -static void __attribute__((used)) esp_mail_debug(const char *msg) -{ - delay(0); - EMAIL_DEBUG_PRINTLN(msg); -} - -static void __attribute__((used)) -esp_mail_debug_line(const char *msg, bool newline) -{ - delay(0); - if (newline) - EMAIL_DEBUG_PRINTLN(msg); - else - EMAIL_DEBUG_PRINT(msg); -} - -extern ESP_Mail_Client MailClient; - -extern FS *ufsp; - -#endif // ESP_Mail_Client_H diff --git a/lib/libesp32/lib_mail/src/ESP_Mail_FS.h b/lib/libesp32/lib_mail/src/ESP_Mail_FS.h deleted file mode 100644 index 0e9007fcb..000000000 --- a/lib/libesp32/lib_mail/src/ESP_Mail_FS.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef ESP_Mail_CONFIG_H -#define ESP_Mail_CONFIG_H -#include - -/** - * To use other flash file systems - * - * LittleFS File system - * - * #include - * #define ESP_Mail_DEFAULT_FLASH_FS LittleFS //For ESP8266 LitteFS - * - * - * FFat File system - * - * #include - * #define ESP_Mail_DEFAULT_FLASH_FS FFat //For ESP32 FFat - * -*/ -// #define ESP_Mail_DEFAULT_FLASH_FS SPIFFS - -#include -#define ESP_Mail_DEFAULT_FLASH_FS LittleFS - -/** - * To use SD card file systems with different hardware interface - * e.g. SDMMC hardware bus on the ESP32 - * https://github.com/espressif/arduino-esp32/tree/master/libraries/SD#faq - * - #include - #define ESP_Mail_DEFAULT_SD_FS SD_MMC //For ESP32 SDMMC - #define CARD_TYPE_SD_MMC 1 - * -*/ -#define ESP_Mail_DEFAULT_SD_FS SD -#define CARD_TYPE_SD 1 - -//For ESP32, format SPIFFS or FFat if mounting failed -#define FORMAT_FLASH_IF_MOUNT_FAILED 1 - - -#endif \ No newline at end of file diff --git a/lib/libesp32/lib_mail/src/README.md b/lib/libesp32/lib_mail/src/README.md deleted file mode 100644 index 0e9c5094e..000000000 --- a/lib/libesp32/lib_mail/src/README.md +++ /dev/null @@ -1,2031 +0,0 @@ -# ESP Mail Client Arduino Library for ESP32 and ESP8266 - - -The detail and usage of the available functions in the latest version (1.2.0) are showed below. - - -## Global functions - - -#### Sending Email through the SMTP server. - -param **`smtp`** The pointer to SMTP session object which holds the data and the TCP client. - -param **`msg`** The pointer to SMTP_Message class which contains the header, body, and attachments. - -param **`closeSession`** The option to Close the SMTP session after sent. - -return **`boolean`** The boolean value indicates the success of operation. - -```C++ -bool sendMail(SMTPSession *smtp, SMTP_Message *msg, bool closeSession = true); -``` - - - - - -#### Reading Email through IMAP server. - -param **`imap`** The pointer to IMAP sesssion object which holds the data and the TCP client. - -param **`closeSession`** The option to close the IMAP session after fetching or searching the Email. - -return **`boolean`** The boolean value indicates the success of operation. - -```C++ -bool readMail(IMAPSession *imap, bool closeSession = true); -``` - - - - - -#### Set the argument to the Flags for the specified message. - -param **`imap`** The pointer to IMAP session object which holds the data and the TCP client. - -param **`msgUID`** The UID of the message. - -param **`flags`** The flag list to set. - -param **`closeSession`** The option to close the IMAP session after set flag. - -return **`boolean`** The boolean value indicates the success of operation. - -```C++ -bool setFlag(IMAPSession *imap, int msgUID, const char *flags, bool closeSession); -``` - - - - - -#### Add the argument to the Flags for the specified message. - -param **`imap`** The pointer to IMAP session object which holds the data and the TCP client. - -param **`msgUID`** The UID of the message. - -param **`flags`** The flag list to set. - -param **`closeSession`** The option to close the IMAP session after add flag. - -return **`boolean`** The boolean value indicates the success of operation. - -```C++ -bool addFlag(IMAPSession *imap, int msgUID, const char *flags, bool closeSession); -``` - - - - - - -#### Remove the argument from the Flags for the specified message. - -param **`imap`** The pointer to IMAP session object which holds the data and the TCP client. - -param **`msgUID`** The UID of the message that flags to be removed. - -param **`flags`** The flag list to remove. - -param **`closeSession`** The option to close the IMAP session after remove flag. - -return **`boolean`** The boolean value indicates the success of operation. - -```C++ -bool removeFlag(IMAPSession *imap, int msgUID, const char *flags, bool closeSession); -``` - - - - - - -#### Initialize the SD card with the SPI port. - -param **`sck`** The SPI Clock pin (ESP32 only). - -param **`miso`** The SPI MISO pin (ESSP32 only). - -param **`mosi`** The SPI MOSI pin (ESP32 only). - -param **`ss`** The SPI Chip/Slave Select pin (ESP32 and ESP8266). - -return **`boolean`** The boolean value indicates the success of operation. - -```C++ -bool sdBegin(uint8_t sck, uint8_t miso, uint8_t mosi, uint8_t ss); -``` - - - - - - -#### Initialize the SD_MMC card (ESP32 only). - -param **`mountpoint`** The mounting point. - -param **`mode1bit`** Allow 1 bit data line (SPI mode). - -param **`format_if_mount_failed`** Format SD_MMC card if mount failed. - -return **`Boolean`** type status indicates the success of the operation. - -```C++ -bool sdMMCBegin(const char *mountpoint = "/sdcard", bool mode1bit = false, bool format_if_mount_failed = false); -``` - - - - - - -#### Initialize the SD card with the default SPI port. - -return **`boolean`** The boolean value which indicates the success of operation. - -```C++ -bool sdBegin(void); -``` - - - - - - -## IMAPSession class functions - - -The following functions are available from the IMAP Session class. - -This class used for controlling IMAP transports and retrieving the data from the IMAP server. - - - - - -#### Begin the IMAP server connection. - -param **`session`** The pointer to ESP_Mail_Session structured data that keeps the server and log in details. - -param **`config`** The pointer to IMAP_Config structured data that keeps the operation options. - -return **`boolean`** The boolean value which indicates the success of operation. - -```C++ -bool connect(ESP_Mail_Session *session, IMAP_Config *config); -``` - - -#### Close the IMAP session. - -return **`boolean`** The boolean value which indicates the success of operation. - -```C++ -bool closeSession(); -``` - - - - - - -#### Set to enable the debug. - -param **`level`** The level to enable the debug message - -level = 0, no debug - -level = 1, basic debug - -level = 2, full debug 1 - -level = 333, full debug 2 - -```C++ -void debug(int level); -``` - - - - - -#### Get the list of all the mailbox folders since the TCP session was opened and user was authenticated. - -param **`folders`** The FoldersCollection class that contains the collection of the -FolderInfo structured data. - -return **`boolean`** The boolean value which indicates the success of operation. - -```C++ -bool getFolders(FoldersCollection &folders); -``` - - - - - -#### Select or open the mailbox folder to search or fetch the message inside. - -param **`folderName`** The known mailbox folder name. The default name is INBOX. - -param **`readOnly`** The option to open the mailbox for read only. Set this option to false when you wish -to modify the Flags using the setFlag, addFlag and removeFlag functions. - -return **`boolean`** The boolean value which indicates the success of operation. - -```C++ -bool selectFolder(const char *folderName, bool readOnly = true); -``` - - - - - -#### Open the mailbox folder to read or search the mesages. - -param **`folderName`** The name of known mailbox folder to be opened. - -param **`readOnly`** The option to open the mailbox for reading only. Set this option to false when you wish -to modify the flags using the setFlag, addFlag and removeFlag functions. - -return **`boolean`** The boolean value which indicates the success of operation. - -```C++ -bool openFolder(const char *folderName, bool readOnly = true); -``` - - - - - -#### Close the mailbox folder that was opened. - -param **`folderName`** The mailbox folder name. - -return **`boolean`** The boolean value which indicates the success of operation. - -```C++ -bool closeFolder(const char *folderName); -``` - - - - - - -#### Create folder. - -param **`folderName`** The name of folder to create. - -return **`boolean`** The boolean value which indicates the success of operation. - -```C++ -bool createFolder(const char *folderName); -``` - - - - - - -#### Delete folder. - -param **`folderName`** The name of folder to delete.. - -return **`boolean`** The boolean value which indicates the success of operation. - -```C++ -bool deleteFolder(const char *folderName); -``` - - - - - - -#### Copy the messages to the defined mailbox folder. - -param **`toCopy`** The pointer to the MessageList class that contains the list of messages to copy. - -param **`dest`** The destination folder that the messages to copy to. - -return **`boolean`** The boolean value which indicates the success of operation. - -```C++ -bool copyMessages(MessageList *toCopy, const char *dest); -``` - - - - - -#### Delete the messages in the opened mailbox folder. - -param **`toDelete`** The pointer to the MessageList class that contains the list of messages to delete. - -param **`expunge`** The boolean option to expunge all messages. - -return **`boolean`** The boolean value which indicates the success of operation. - -```C++ -bool deleteMessages(MessageList *toDelete, bool expunge = false); -``` - - - - - - - -#### Assign the callback function that returns the operating status when fetching or reading the Email. - -param **`imapCallback`** The function that accepts the imapStatusCallback as parameter. - -```C++ -void callback(imapStatusCallback imapCallback); -``` - - - - - -#### Determine if no message body contained in the search result and only the message header is available. - -```C++ -bool headerOnly(); -``` - - - - - -#### Get the message list from search or fetch the Emails - -return **`The IMAP_MSG_List structured`** data which contains the text and html contents, -attachments, inline images, embedded rfc822 messages details for each message. - -```C++ -IMAP_MSG_List data(); -``` - - - - - -#### Get the details of the selected or opned mailbox folder - -return **`The SelectedFolderInfo class`** instance which contains the info about flags, total messages, next UID, -earch count and the available messages count. - -```C++ -SelectedFolderInfo selectedFolder(); -``` - - - - - -#### Get the error details when readingg the Emails - -return **`String`** The string of error details. - -```C++ -String errorReason(); -``` - - - - - -#### Clear all the cache data stored in the IMAP session object. - -```C++ -void empty(); -``` - - - - - -## IMAPSession class functions - - -The following functions are available from the SMTP Session class. - -This class is similar to the IMAP session class, used for controlling SMTP transports -and retrieving the data from the SMTP server. - - - - - - -#### Begin the SMTP server connection. - -param **`session`** The pointer to ESP_Mail_Session structured data that keeps the server and log in details. - -return **`boolean`** The boolean value indicates the success of operation. - -```C++ -bool connect(ESP_Mail_Session *session); -``` - - - - - -### Close the SMTP session. - -```C++ -bool closeSession(); -``` - - - - - -#### Set to enable the debug. - -param **`level`** The level to enable the debug message - -level = 0, no debug - -level = 1, basic debug - -level = 2, full debug 1 - -level = 333, full debug 2 - -```C++ -void debug(int level); -``` - - - - - -#### Get the error details when sending the Email - -return **`String`** The string of error details. - -```C++ -String errorReason(); -``` - - - - - -#### Set the Email sending status callback function. - -param **`smtpCallback`** The callback function that accept the smtpStatusCallback param. - -```C++ -void callback(smtpStatusCallback smtpCallback); -``` - - - - - -## SMTP_Message class functions - - -The following functions are available from the SMTP Message class. - -This class is used for storing the message data including headers, body and attachments -which will be processed with the SMTP session class. - - - - -#### To reset the SMTP_Attachment item data - -param **`att`** The SMTP_Attachment class that stores the info about attachment - -This function was used for clear the internal data of attachment item to be ready for reuse. - -```C++ -void resetAttachItem(SMTP_Attachment &att); -``` - - - -#### To clear all data in SMTP_Message class included headers, bodies and attachments - -```C++ -void clear(); -``` - - - - -#### To clear all the inline images in SMTP_Message class. - -```C++ -void clearInlineimages(); -``` - - - - - -#### To clear all the attachments. - -```C++ -void clearAttachments(); -``` - - - - - -#### To clear all rfc822 message attachment. - -```C++ -void clearRFC822Messages(); -``` - - - - - -#### To clear the primary recipient mailboxes. - -```C++ -void clearRecipients(); -``` - - - - - -#### To clear the Carbon-copy recipient mailboxes. - -```C++ -void clearCc(); -``` - - - - - -#### To clear the Blind-carbon-copy recipient mailboxes. - -```C++ -void clearBcc(); -``` - - -#### To clear the custom message headers. - -```C++ -void clearHeader(); -``` - - - - -#### To add attachment to the message. - -param **`att`** The SMTP_Attachment data item - -```C++ -void addAttachment(SMTP_Attachment &att); -``` - - - - - -#### To add parallel attachment to the message. - -param **`att`** The SMTP_Attachment data item - -```C++ -void addParallelAttachment(SMTP_Attachment &att); -``` - - - - - -#### To add inline image to the message. - -param **`att`** The SMTP_Attachment data item - -```C++ -void addInlineImage(SMTP_Attachment &att); -``` - - - - - -#### To add rfc822 message to the message. - -param **`msg`** The RFC822_Message class object - -```C++ -void addMessage(SMTP_Message &msg); -``` - - - - - -#### To add the primary recipient mailbox to the message. - -param **`name`** The name of primary recipient - -param **`email`** The Email address of primary recipient - -```C++ -void addRecipient(const char *name, const char *email); -``` - - - - - -#### To add Carbon-copy recipient mailbox. - -param **`email`** The Email address of secondary recipient - -```C++ -void addCc(const char *email); -``` - - - - - -#### To add Blind-carbon-copy recipient mailbox. - -param **`email`** The Email address of the tertiary recipient - -```C++ -void addBcc(const char *email); -``` - - - - - -#### To add the custom header to the message. - -param **`hdr`** The header name and value - -```C++ -void addHeader(const char *hdr); -``` - - - - -##### [properties] The message author config - -This property has the sub properties - -###### [const char*] name - The sender name. - -###### [const char*] email - The sender Email address. - -```C++ -esp_mail_email_info_t sender; -``` - - -##### [properties] The topic of message - -```C++ -const char *subject; -``` - - -##### [properties] The message type - -```C++ -byte type; -``` - - -##### [properties] The PLAIN text message - -This property has the sub properties - -###### [esp_mail_smtp_embed_message_body_t] embed - The option to embed this message content as a file. - -###### [const char*] content - The PLAIN text content of the message. - -###### [esp_mail_blob_message_content_t] blob - The blob that contins PLAIN text content of the message. - -###### [esp_mail_file_message_content_t] file - The file that contins PLAIN text content of the message. - -###### [const char*] charSet - The character transcoding of the PLAIN text content of the message. - -###### [const char*] content_type - The content type of message. - -###### [const char*] transfer_encoding - The option to encode the content for data transfer. - -###### [boolean] flowed - The option to send the PLAIN text with wrapping. - -```C++ -esp_mail_plain_body_t text; -``` - - -##### [properties] The HTML text message - -This propery has the sub properties - -###### [const char*] content - The HTML content of the message. - -###### [esp_mail_blob_message_content_t] blob - The blob that contins HTML content of the message. - -###### [esp_mail_file_message_content_t] file - The file that contins HTML content of the message. - -###### [const char*] charSet - The character transcoding of the HTML content of the message. - -###### [const char*] content_type - The content type of message. - -###### [const char*] transfer_encoding - The option to encode the content for data transfer. - -```C++ -esp_mail_html_body_t html; -``` - - -##### [properties] The response config - -This propery has the sub properties - -###### [const char*] reply_to - The author Email address to reply. - -###### [const char*] return_path - The sender Email address to return the message. - -###### [int] notify - The Delivery Status Notifications enumeration e.g. - -esp_mail_smtp_notify_never = 0, - -esp_mail_smtp_notify_success = 1, - -esp_mail_smtp_notify_failure = 2, and - -esp_mail_smtp_notify_delay = 4 - -```C++ -esp_mail_smtp_msg_response_t response; -``` - - -##### [properties] The priority of the message - -This property has the enumeration values - -esp_mail_smtp_priority_high = 1, - -esp_mail_smtp_priority_normal = 3, - -esp_mail_smtp_priority_low = 5 - -```C++ -esp_mail_smtp_priority priority; -``` - - -##### [properties] The enable options - -This propery has the sub property - -###### [boolean] chunking - enable chunk data sending for large message. - -```C++ -esp_mail_smtp_enable_option_t enable; -``` - - -##### [properties] The message from config - -This property has the sub properties - -###### [const char*] name - The messsage author name. - -###### [const char*] email - The message author Email address. - -```C++ -esp_mail_email_info_t from; -``` - - -##### [properties] The message identifier - -```C++ -const char *messageID; -``` - -##### [properties] The keywords or phrases, separated by commas - -```C++ -const char *keyword; -``` - - -##### [properties] The comment about message - -```C++ -const char *comment; -``` - - -##### [properties] The date of message - -```C++ -const char *date; -``` - - -##### [properties] The return recipient of the message - -```C++ -const char *return_path; -``` - - - - - - -## IMAP_Status class functions - - -The following functions are available from the IMAP Status class. - -This class is used as the callback parameter for retrieving the status while reading the Email. - - - - -#### Provide the information of each process in the reading operation. - -return **`string`** The info for each process - -```C++ -const char *info(); -``` - - - - -#### Provide the status of completion. - -return **`boolean`** The bool value indicates that all reading processes are finished - -```C++ -bool success(); -``` - - - - - -#### To clear all data store in this class. - -```C++ -void empty(); -``` - - - - - - -## SMTP_Status class functions - - -The following functions are available from the SMTP Status class. - -This class is used as the callback parameter for retrieving the status while sending the Email. - - - - -#### Provide the information of each process in the sending operation. - -return **`string`** The info for each process - -```C++ -const char *info(); -``` - - - - -#### Provide the status of completion. - -return **`boolean`** The bool value indicates that all sending processes are finished - -```C++ -bool success(); -``` - - - - - -#### To clear all data store in this class. - -```C++ -void empty(); -``` - - - - -#### Provide the number of complete sending message. - -return **`number`** The number of message that was sent - -```C++ -size_t completedCount(); -``` - - - - - -#### Provide the number of failed sending message. - -return **`number`** The number of message that was not sent - -```C++ -size_t failedCount(); -``` - - - - -## SendingResult class functions - - -The following functions are available from the SendingResult class. - -This class is used for retrieving the info about the result of sending the messages. - - - - -#### Provide the information of a message sending status. - -param **`index`** The index number of a message sending status - -return **`SMTP_Result`** The SMTP_Result type data that provides these properties - -##### [bool] completed - The status of the message - -#### [const char *] recipients - The primary recipient mailbox of the message - -#### [const char *] subject - The topic of the message - -#### [time_t] timesstamp - The timestamp of the message - -```C++ -SMTP_Result getItem(size_t index); -``` - - - - - -#### Provide the amount of the result data. - -return **`number`** The number of result item - -```C++ -size_t size(); -``` - - - - -## FoldersCollection class functions - - -The following functions are available from the FoldersCollection class. - -This class is used for retrieving the info about the mailbox folders which available to read or serach -in the user Email mailbox. - - - - -#### Provide the information of a folder in a folder collection. - -param **`index`** The index number of folders - -return **`esp_mail_folder_info_item_t`** The esp_mail_folder_info_item_t structured data that provides these properties - -#### [const char *] name - The name of folder - -#### [const char *] attributes - The attributes of folder - -#### [const char *] delimiter - The delimeter of folder - -```C++ -esp_mail_folder_info_item_t info(size_t index); -``` - - - - - -#### Provide the number of folders in the collection. - -return **`number`** The number of folder in the collection - -```C++ -size_t size(); -``` - - - - - - -## SelectedFolderInfo class functions - - -The following functions are available from the SelectedFolderInfo class. - -This class is used for retrieving the info about the sselected or opened mailbox folder. - - - - -#### Provide the numbers of flags in the user Email mailbox. - -return **`number`** The numbers of flags - -```C++ -size_t flagCount(); -``` - - - - - -#### Provide the numbers of messages in this mailbox. - -return **`number`** The numbers of messages in the selected mailbox folder - -```C++ -size_t msgCount(); -``` - - - - - -#### Provide the predicted next message UID in the sselected folder. - -return **`number`** The number represents the next message UID number - -```C++ -size_t nextUID(); -``` - - - - - -#### Provide the numbers of messages from search result based on the search criteria. - -return **`number`** The total number of messsages from search - -```C++ -size_t searchCount(); -``` - - - - - -#### Provide the numbers of messages to be stored in the ressult. - -return **`number`** The number of messsage stored from search - -```C++ -size_t availableMessages(); -``` - - - - - -#### Provide the flag argument at the specified index. - -return **`index`** The index of flag in the flags list - -return **`String`** The argument of selected flag - -```C++ -String flag(size_t index); -``` - - - - -## ESP_Mail_Session type data - - -The following properties are available from the ESP_Mail_Session data type. - -This data type is used for storing the session info about the server and login credentials. - - -#### [Properties] The server config - -This property has the sub properties - -##### [const char *] host_name - The hostName of the server. - -##### [uint16_t] port - The port on the server to connect to. - -```C++ -esp_mail_sesson_sever_config_t server; -``` - - -#### [Properties] The log in config - -This property has the sub properties - -##### [const char *] email - The user Email address to log in. - -##### [consst char *] password - The user password to log in. - -##### [consst char *] accessToken - The OAuth2.0 access token to log in. - -##### [consst char *] user_domain - The user domain or ip of client. - -```C++ -esp_mail_sesson_login_config_t login; -``` - - -#### [Properties] The secure config - -This property has the sub properties - -##### [bool] startTLS - The option to send the command to start the TLS connection. - -```C++ -esp_mail_sesson_secure_config_t secure; -``` - - - -#### [Properties] The certificate config - -##### [const char *] cert_data - The certificate data (base64 data). - -##### [consst char *] cert_file - The certificate file (DER format). - -##### [esp_mail_file_storage_type] cert_file_storage_type - The storage type. - -```C++ -esp_mail_sesson_cert_config_t certificate; -``` - - - - -## IMAP_Config type data - - -The following properties are available from the IMAP_Config data type. - -This data type is used for storing the IMAP transport and operating options to -control and store the operation result e.g. the messahe contents from search and fetch. - - - - -#### [Properties] The config for fetching - -This property has the sub property - -##### [const char *] uid - The UID of message to fetch. - -```C++ -esp_mail_imap_fetch_config_t fetch; -``` - - -#### [Properties] The config for search - -This property has the sub properties - -##### [const char *] criteria - The search criteria. - -##### [boolean] unseen_msg - The option to search the unseen message. - -```C++ -esp_mail_imap_search_config_t search; -``` - - -#### [Properties] The config about the limits - -This property has the sub properties - -##### [size_t] search - The maximum messages from the search result. - -##### [size_t] msg_size - The maximum size of the memory buffer to store the message content. - -This is only limit for data to be stored in the IMAPSession. - -##### [size_t] attachment_size - The maximum size of each attachment to download. - -```C++ -esp_mail_imap_limit_config_t limit; -``` - - - -#### [Properties] The config to enable the features - -This property has the sub properties - -##### [boolean] text - To store the PLAIN text of the message in the IMAPSession. - -##### [boolean] html - To store the HTML of the message in the IMAPSession. - -##### [boolean] rfc822 - To store the rfc822 messages in the IMAPSession. - -##### [boolean] download_status - To enable the download status via the serial port. - -##### [boolean] recent_sort - To sort the message UID of the search result in descending order. - -```C++ -esp_mail_imap_enable_config_t enable; -``` - - - -#### [Properties] The config about downloads - -This property has the sub properties - -##### [boolean] text - To download the PLAIN text content of the message. - -##### [boolean] html - To download the HTML content of the message. - -##### [boolean] attachment - To download the attachments of the message. - -##### [boolean] inlineImg - To download the inline image of the message. - -##### [boolean] rfc822 - To download the rfc822 mesages in the message. - -##### [boolean] header - To download the message header. - -```C++ -esp_mail_imap_download_config_t download; -``` - - - -#### [Properties] The config about the storage and path to save the downloaded file. - -This property has the sub properties - -##### [const char*] saved_path - The path to save the downloaded file. - -##### [esp_mail_file_storage_type] type - The type of file storages enumeration e.g. - -esp_mail_file_storage_type_none = 0, - -esp_mail_file_storage_type_flash = 1, and - -esp_mail_file_storage_type_sd = 2 - -```C++ -esp_mail_imap_storage_config_t storage; -``` - - - - - -## esp_mail_smtp_embed_message_body_t structured data - - -The following properties are available from the IMAP_Config data type. - -This data type is used for storing the IMAP transport and operating options to -control and store the operation result e.g. the messahe contents from search and fetch. - - - - -##### [Properties] Enable to send this message body as file - -```C++ -bool enable; -``` - - -##### [Properties] The name of embedded file - -```C++ -const char* enable; -``` - - -##### [Properties] The embedded type enumeration - -esp_mail_smtp_embed_message_type_attachment = 0 - -sp_mail_smtp_embed_message_type_inline = 1 - -```C++ -esp_mail_smtp_embed_message_type type; -``` - - - - - - -## esp_mail_blob_message_content_t structured data - - -The following properties are available from the esp_mail_blob_message_content_t data type. - -This data type is used for storing the blob info of message body. - - - - -##### [Properties] The array of content in flash memory. - -```C++ -const uint8_t * data; -``` - - -##### [Properties] The array size in bytes. - -```C++ -size_t size; -``` - - - - - -## esp_mail_file_message_content_t structured data - - -The following properties are available from the esp_mail_file_message_content_t data type. - -This data type is used for storing the file info of message body. - - - - -##### [Properties] The file path include its name. - -```C++ -const char *name; -``` - - -##### [Properties] The type of file storages. - -```C++ -esp_mail_file_storage_type type; -``` - - - - - - -## IMAP_MSG_Item type data - - -The following properties are available from the IMAP_MSG_Item data type. - -This data type is used for message item info and its contents from search and fetch. - - - - -#### [Properties] The message number - -```C++ -const char *msgNo; -``` - - -#### [Properties] The message UID - -```C++ -const char *UID; -``` - - -#### [Properties] The message identifier - -```C++ -const char *ID; -``` - - - -#### [Properties] The language(s) for auto-responses - -```C++ -const char *acceptLang; -``` - - - -#### [Properties] The language of message content - -```C++ -const char *contentLang; -``` - - - -#### [Properties] The mailbox of message author - -```C++ -const char *from; -``` - - -#### [Properties] The charset of the mailbox of message author - -```C++ -const char *fromCharset; -``` - - -#### [Properties] The primary recipient mailbox - -```C++ -const char *to; -``` - - -#### [Properties] The charset of the primary recipient mailbox - -```C++ -const char *toCharset; -``` - - -#### [Properties] The Carbon-copy recipient mailboxes - -```C++ -const char *cc; -``` - - -#### [Properties] The charset of the Carbon-copy recipient mailbox header - -```C++ -const char *ccCharset; -``` - -#### [Properties] The message date and time - -```C++ -const char *date; -``` - -#### [Properties] The topic of message - -```C++ -const char *subject; -``` - -#### [Properties] The topic of message charset - -```C++ -const char *subjectCharset; -``` - -#### [Properties] The PLAIN text content of the message - -```C++ -esp_mail_plain_body_t text; -``` - -#### [Properties] The HTML content of the message - -```C++ -esp_mail_html_body_t html; -``` - -#### [Properties] The sender Email - -```C++ -const char *sender; -``` - -#### [Properties] The message identifier - -```C++ -const char *messageID; -``` - -#### [Properties] The keywords or phrases, separated by commas - -```C++ -const char *keyword; -``` - -#### [Properties] The comment about message - -```C++ -const char *comment; -``` - - -#### [Properties] The return recipient of the message - -```C++ -const char *return_path; -``` - - -#### [Properties] The Email address to reply - -```C++ -const char *reply_to; -``` - - -#### [Properties] The Blind carbon-copy recipients - -```C++ -const char *bcc; -``` - - -#### [Properties] The error description from fetching the message - -```C++ -const char *fetchError; -``` - - -#### [Properties] The info about the attachments in the message - -```C++ -std::vector attachments; -``` - -#### [Properties] The info about the rfc822 messages included in the message - -```C++ -std::vector rfc822; -``` - - - - - - -## Search Criteria - -Search crieria is used for searching the mailbox for messages that match -the given searching criteria. - -Searching criteria consist of one or more search keys. When multiple keys are -specified, the result is the intersection (AND function) of all the messages -that match those keys. - -Example: - - **`DELETED FROM "SMITH" SINCE 1-Feb-1994`** refers -to all deleted messages from Smith that were placed in the mailbox since -February 1, 1994. - -A search key can also be a parenthesized list of one or more search keys -(e.g., for use with the OR and NOT keys). - -**`SINCE 10-Feb-2019`** will search all messages that received since 10 Feb 2019 - -**`UID SEARCH ALL`** will seach all message which will return the message UID -that can be use later for fetch one or more messages. - - -The following keywords can be used for the search criteria. - - -**ALL** - All messages in the mailbox; the default initial key for ANDing. - -**ANSWERED** - Messages with the \Answered flag set. - -**BCC** - Messages that contain the specified string in the envelope structure's BCC field. - -**BEFORE** - Messages whose internal date (disregarding time and timezone) is earlier than the specified date. - -**BODY** - Messages that contain the specified string in the body of the message. - -**CC** - Messages that contain the specified string in the envelope structure's CC field. - -**DELETED** - Messages with the \Deleted flag set. - -**DRAFT** - Messages with the \Draft flag set. - -**FLAGGED** - Messages with the \Flagged flag set. - -**FROM** - Messages that contain the specified string in the envelope structure's FROM field. - -**HEADER** - Messages that have a header with the specified field-name (as defined in [RFC-2822]) - -and that contains the specified string in the text of the header (what comes after the colon). - -If the string to search is zero-length, this matches all messages that have a header line with - -the specified field-name regardless of the contents. - -**KEYWORD** - Messages with the specified keyword flag set. - -**LARGER** - Messages with an (RFC-2822) size larger than the specified number of octets. - -**NEW** - Messages that have the \Recent flag set but not the \Seen flag. - -This is functionally equivalent to **"(RECENT UNSEEN)"**. - -**NOT** - Messages that do not match the specified search key. - -**OLD** - Messages that do not have the \Recent flag set. This is functionally equivalent to - -**"NOT RECENT"** (as opposed to **"NOT NEW"**). - -**ON** - Messages whose internal date (disregarding time and timezone) is within the specified date. - -**OR** - Messages that match either search key. - -**RECENT** - Messages that have the \Recent flag set. - -**SEEN** - Messages that have the \Seen flag set. - -**SENTBEFORE** - Messages whose (RFC-2822) Date: header (disregarding time and timezone) is earlier than the specified date. - -**SENTON** - Messages whose (RFC-2822) Date: header (disregarding time and timezone) is within the specified date. - -**SENTSINCE** - Messages whose (RFC-2822) Date: header (disregarding time and timezone) is within or later than the specified date. - -**SINCE** - Messages whose internal date (disregarding time and timezone) is within or later than the specified date. - -**SMALLER** - Messages with an (RFC-2822) size smaller than the specified number of octets. - -**SUBJECT** - Messages that contain the specified string in the envelope structure's SUBJECT field. - -**TEXT** - Messages that contain the specified string in the header or body of the message. - -**TO** - Messages that contain the specified string in the envelope structure's TO field. - -**UID** - Messages with unique identifiers corresponding to the specified unique identifier set. - -Sequence set ranges are permitted. - -**UNANSWERED** - Messages that do not have the \Answered flag set. - -**UNDELETED** - Messages that do not have the \Deleted flag set. - -**UNDRAFT** - Messages that do not have the \Draft flag set. - -**UNFLAGGED** - Messages that do not have the \Flagged flag set. - -**UNKEYWORD** - Messages that do not have the specified keyword flag set. - -**UNSEEN** - Messages that do not have the \Seen flag set. - - - - - - - - - -## MailClient.Time functions - - -The helper function to set and get the system time. - - - - - -#### Set the system time from the NTP server - -param **`gmtOffset`** The GMT time offset in hour. - -param **`daylightOffset`** The Daylight time offset in hour. - -return **`boolean`** The status indicates the success of operation. - -This requires internet connection - -```C++ -bool setClock(float gmtOffset, float daylightOffset); -``` - - - - - - -#### Provide the Unix time - -return **`uint32_t`** The value of current Unix time. - -```C++ -uint32_t getUnixTime(); -``` - - - - - - -#### Provide the timestamp from the year, month, date, hour, minute, and second provided - -param **`year`** The year. - -param **`mon`** The months from 1 to 12. - -param **`date`** The dates. - -param **`hour`** The hours. - -param **`mins`** The minutes. - -param **`sec`** The seconds. - -return **`time_t`** The value of timestamp. - -```C++ -time_t getTimestamp(int year, int mon, int date, int hour, int mins, int sec); -``` - - - - - - -#### Provide the current year. - -return **`int`** The value of current year. - -```C++ -int getYear(); -``` - - - - - - -#### Provide the current month. - -return **`int`** The value of current month. - -```C++ -int getMonth(); -``` - - - - - -#### Provide the current date. - -return **`int`** The value of current date. - -```C++ -int getDay(); -``` - - - - - - -#### Provide the current day of week. - -return **`int`** The value of day of week. - -1 for sunday and 7 for saturday - -```C++ -int getDayOfWeek(); -``` - - - - - -#### Provide the current day of week in String. - -return **`String`** The value of day of week. - -Returns sunday, monday, tuesday, wednesday, thurseday, friday and saturday. - -```C++ -String getDayOfWeekString(); -``` - - - - - - -#### Provide the current hour. - -return **`int`** The value of current hour (0 to 23). - -```C++ -int getHour(); -``` - - - - - - -#### Provide the current minute. - -return **`int`** The value of current minute (0 to 59). - -```C++ -int getMin(); -``` - - - - - - -#### Provide the current second. - -return **`int`** The value of current second (0 to 59). - -```C++ -int getSecond(); -``` - - - - - - - -#### Provide the total days of current year. - -return **`int`** The value of total days of current year. - -```C++ -int getNumberOfDayThisYear(); -``` - - - - - - -#### Provide the total days of from January 1, 1970 to specific date. - -param **`year`** The years from 1970. - -param **`mon`** The months from 1 to 12. - -param **`date`** The dates. - -return **`int`** The value of total days. - -```C++ -int getTotalDays(int year, int month, int day); -``` - - - - - -#### Provide the day of week from specific date. - -param **`year`** The years. - -param **`month`** The months from 1 to 12. - -param **`day`** The dates. - -return **`int`** The value of day of week. - -1 for sunday and 7 for saturday - -```C++ -int dayofWeek(int year, int month, int day); -``` - - - - - - -#### Provide the second of current hour. - -return **`int`** The value of current second. - -```C++ -int getCurrentSecond(); -``` - - - - - -#### Provide the current timestamp. - -return **`uint64_t`** The value of current timestamp. - -```C++ -uint64_t getCurrentTimestamp(); -``` - - - - - - -#### Provide the date and time from second counted from January 1, 1970. - -param **`sec`** The seconds from January 1, 1970 00.00. - -return **`tm`** The tm structured data. - -The returned structured data tm has the members e.g. - -tm_year (from 1900), tm_mon (from 0 to 11), tm_mday, tm_hour, tm_min and tm_sec. - -```C++ -struct tm getTimeFromSec(int secCount); -``` - - - - - - -#### Provide the current date time string that valid for Email - -return **`String`** The current date time string. - -```C++ -String getDateTimeString(); -``` - - - - - - - -## License - -The MIT License (MIT) - -Copyright (c) 2021 K. Suwatchai (Mobizt) - - -Permission is hereby granted, free of charge, to any person returning a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software is furnished to do so, -subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - diff --git a/lib/libesp32/lib_mail/src/SDK_Version_Common.h b/lib/libesp32/lib_mail/src/SDK_Version_Common.h deleted file mode 100644 index c0db7a62c..000000000 --- a/lib/libesp32/lib_mail/src/SDK_Version_Common.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef _SDK_VERSION_COMMON_H -#define _SDK_VERSION_COMMON_H - -#if defined(ESP8266) - -#include - -//__GNUC__ -//__GNUC_MINOR__ -//__GNUC_PATCHLEVEL__ - -#ifdef __GNUC__ -#if __GNUC__ > 4 || __GNUC__ == 10 -#define ESP8266_CORE_SDK_V3_X_X -#endif -#endif - -#endif - -#endif \ No newline at end of file diff --git a/lib/libesp32/lib_mail/src/extras/ESPTimeHelper.cpp b/lib/libesp32/lib_mail/src/extras/ESPTimeHelper.cpp deleted file mode 100644 index b88b1c753..000000000 --- a/lib/libesp32/lib_mail/src/extras/ESPTimeHelper.cpp +++ /dev/null @@ -1,286 +0,0 @@ -/* - * ESP8266/ESP32 Internet Time Helper Arduino Library v 1.0.2 - * - * The MIT License (MIT) - * Copyright (c) 2021 K. Suwatchai (Mobizt) - * - * - * Permission is hereby granted, free of charge, to any person returning a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -#ifndef ESPTimeHelper_CPP -#define ESPTimeHelper_CPP - -#include "ESPTimeHelper.h" - -ESPTimeHelper::ESPTimeHelper() -{ -} - -uint32_t ESPTimeHelper::getUnixTime() -{ - uint32_t utime = (msec_time_diff + millis()) / 1000; - return utime; -} - -int ESPTimeHelper::setTimestamp(time_t ts) -{ - struct timeval tm = {ts, 0};//sec, us - return settimeofday((const timeval *)&tm, 0); -} - -time_t ESPTimeHelper::getTimestamp(int year, int mon, int date, int hour, int mins, int sec) -{ - struct tm timeinfo; - timeinfo.tm_year = year - 1900; - timeinfo.tm_mon = mon - 1; - timeinfo.tm_mday = date; - timeinfo.tm_hour = hour; - timeinfo.tm_min = mins; - timeinfo.tm_sec = sec; - time_t ts = mktime(&timeinfo); - return ts; -} - -bool ESPTimeHelper::setClock(float gmtOffset, float daylightOffset) -{ - TZ = gmtOffset; - DST_MN = daylightOffset; - configTime((TZ)*3600, (DST_MN)*60, "pool.ntp.org", "time.nist.gov"); - - now = time(nullptr); - uint8_t attempts = 0; - while (now < 1577836800) - { - now = time(nullptr); - attempts++; - if (attempts > 200 || now > 1577836800) - break; - delay(100); - } - - uint64_t tmp = now; - tmp = tmp * 1000; - msec_time_diff = tmp - millis(); - -#if defined(ESP32) - getLocalTime(&timeinfo); -#elif defined(ESP8266) - gmtime_r(&now, &timeinfo); -#endif - - clockReady = now > 8 * 3600 * 2; - return clockReady; -} - -int ESPTimeHelper::getYear() -{ - setSysTime(); - return timeinfo.tm_year + 1900; -} -int ESPTimeHelper::getMonth() -{ - setSysTime(); - return timeinfo.tm_mon + 1; -} -int ESPTimeHelper::getDay() -{ - setSysTime(); - return timeinfo.tm_mday; -} - -int ESPTimeHelper::getDayOfWeek() -{ - setSysTime(); - return timeinfo.tm_wday; -} -String ESPTimeHelper::getDayOfWeekString() -{ - setSysTime(); - return dow[timeinfo.tm_wday]; -} - -int ESPTimeHelper::getHour() -{ - setSysTime(); - return timeinfo.tm_hour; -} - -int ESPTimeHelper::getMin() -{ - setSysTime(); - return timeinfo.tm_min; -} -int ESPTimeHelper::getSec() -{ - setSysTime(); - return timeinfo.tm_sec; -} -int ESPTimeHelper::getNumberOfDayThisYear() -{ - setSysTime(); - return timeinfo.tm_yday + 1; -} - -int ESPTimeHelper::totalDays(int y, int m, int d) -{ - static char daytab[2][13] = - { - {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, - {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}}; - int daystotal = d; - for (int year = 1; year <= y; year++) - { - int max_month = (year < y ? 12 : m - 1); - int leap = (year % 4 == 0); - if (year % 100 == 0 && year % 400 != 0) - leap = 0; - for (int month = 1; month <= max_month; month++) - { - daystotal += daytab[leap][month]; - } - } - return daystotal; -} -int ESPTimeHelper::getTotalDays(int year, int month, int day) -{ - return totalDays(year, month, day) - totalDays(1970, 1, 1); -} - -int ESPTimeHelper::dayofWeek(int year, int month, int day) /* 1 <= m <= 12, y > 1752 (in the U.K.) */ -{ - static int t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4}; - year -= month < 3; - return (year + year / 4 - year / 100 + year / 400 + t[month - 1] + day) % 7; -} - -int ESPTimeHelper::getCurrentSecond() -{ - return (timeinfo.tm_hour * 3600) + (timeinfo.tm_min * 60) + timeinfo.tm_sec; -} -uint64_t ESPTimeHelper::getCurrentTimestamp() -{ - return now; -} -struct tm ESPTimeHelper::getTimeFromSec(int seconds) -{ - struct tm timeinfo; - int _yrs = seconds / (365 * 24 * 3600); - seconds = seconds - _yrs * (365 * 24 * 3600); - timeinfo.tm_year = _yrs - 1900; - int _months = seconds / (30 * 24 * 3600); - seconds = seconds - _months * (30 * 24 * 3600); - timeinfo.tm_mon = _months - 1; - int _days = seconds / (24 * 3600); - seconds = seconds - _days * (24 * 3600); - timeinfo.tm_mday = _days; - int _hr = seconds / 3600; - seconds = seconds - _hr * 3600; - timeinfo.tm_hour = _hr; - int _min = seconds / 60; - seconds = seconds - _min * 60; - timeinfo.tm_min = _min; - timeinfo.tm_sec = seconds; - return timeinfo; -} - -char *ESPTimeHelper::intStr(int value) -{ - char *buf = new char[36]; - memset(buf, 0, 36); - itoa(value, buf, 10); - return buf; -} - -String ESPTimeHelper::getDateTimeString() -{ - setSysTime(); - std::string s; - - s = sdow[timeinfo.tm_wday]; - - s += ", "; - char *tmp = intStr(timeinfo.tm_mday); - s += tmp; - delete[] tmp; - - s += " "; - s += months[timeinfo.tm_mon]; - - s += " "; - tmp = intStr(timeinfo.tm_year + 1900); - s += tmp; - delete[] tmp; - - s += " "; - if (timeinfo.tm_hour < 10) - s += "0"; - tmp = intStr(timeinfo.tm_hour); - s += tmp; - delete[] tmp; - - s += ":"; - if (timeinfo.tm_min < 10) - s += "0"; - tmp = intStr(timeinfo.tm_min); - s += tmp; - delete[] tmp; - - s += ":"; - if (timeinfo.tm_sec < 10) - s += "0"; - tmp = intStr(timeinfo.tm_sec); - s += tmp; - delete[] tmp; - - int p = 1; - if (TZ < 0) - p = -1; - int tz = TZ; - float dif = (p * (TZ - tz)) * 60.0; - if (TZ < 0) - s += " -"; - else - s += " +"; - - if (tz < 10) - s += "0"; - tmp = intStr(tz); - s += tmp; - delete[] tmp; - - if (dif < 10) - s += "0"; - tmp = intStr((int)dif); - s += tmp; - delete[] tmp; - - return s.c_str(); -} - -void ESPTimeHelper::setSysTime() -{ -#if defined(ESP32) - getLocalTime(&timeinfo); -#elif defined(ESP8266) - now = time(nullptr); - localtime_r(&now, &timeinfo); -#endif -} - -#endif //ESPTimeHelper_CPP \ No newline at end of file diff --git a/lib/libesp32/lib_mail/src/extras/ESPTimeHelper.h b/lib/libesp32/lib_mail/src/extras/ESPTimeHelper.h deleted file mode 100644 index 2cc5fcddf..000000000 --- a/lib/libesp32/lib_mail/src/extras/ESPTimeHelper.h +++ /dev/null @@ -1,199 +0,0 @@ -/* - * ESP8266/ESP32 Internet Time Helper Arduino Library v 1.0.2 - * - * The MIT License (MIT) - * Copyright (c) 2021 K. Suwatchai (Mobizt) - * - * - * Permission is hereby granted, free of charge, to any person returning a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -#ifndef ESPTimeHelper_H -#define ESPTimeHelper_H - -#include -#include -#if defined(ESP32) -#include -#elif defined(ESP8266) -#include -#include "SDK_Version_Common.h" -#endif - -class ESPTimeHelper -{ -public: - ESPTimeHelper(); - - /** Set the system time from the NTP server - * - * @param gmtOffset The GMT time offset in hour. - * @param daylightOffset The Daylight time offset in hour. - * @return boolean The status indicates the success of operation. - * - * @note This requires internet connection - */ - bool setClock(float gmtOffset, float daylightOffset); - - /** Set system time with provided timestamp - * - * @param ts timestamp in seconds from midnight Jan 1, 1970. - * @return error number, 0 for success. - */ - int setTimestamp(time_t ts); - - /** Provide the Unix time - * - * @return uint32_t The value of current Unix time. - */ - uint32_t getUnixTime(); - - /** Provide the timestamp from the year, month, date, hour, minute, - * and second provided. - * - * @param year The year. - * @param mon The month from 1 to 12. - * @param date The dates. - * @param hour The hours. - * @param mins The minutes. - * @param sec The seconds. - * @return time_t The value of timestamp. - */ - time_t getTimestamp(int year, int mon, int date, int hour, int mins, int sec); - - /** Provide the current year. - * - * @return int The value of current year. - */ - int getYear(); - - /** Provide the current month. - * - * @return int The value of current month. - */ - int getMonth(); - - /** Provide the current date. - * - * @return int The value of current date. - */ - int getDay(); - - /** Provide the current day of week. - * - * @return int The value of current day of week. - * - * @note 1 for sunday and 7 for saturday. - */ - int getDayOfWeek(); - - /** Provide the current day of week in String. - * - * @return String The value of day of week. - */ - String getDayOfWeekString(); - - /** Provide the current hour. - * - * @return int The value of current hour (0 to 23). - */ - int getHour(); - - /** Provide the current minute. - * - * @return int The value of current minute. - */ - int getMin(); - - /** Provide the current second. - * - * @return int The value of current second. - */ - int getSec(); - - /** Provide the total days of current year. - * - * @return int The value of total days of current year. - */ - int getNumberOfDayThisYear(); - - /** Provide the total days of from January 1, 1970 to specific date. - * - * @param year The year from 1970. - * @param mon The month from 1 to 12. - * @param day The dates. - * @return int The value of total days. - */ - int getTotalDays(int year, int month, int day); - - /** Provide the day of week from specific date. - * - * @param year The year from 1970. - * @param mon The month from 1 to 12. - * @param day The dates. - * @return int the value of day of week. - * @note 1 for sunday and 7 for saturday - */ - int dayofWeek(int year, int month, int day); - - /** Provide the second of current hour. - * - * @return int The value of current second. - */ - int getCurrentSecond(); - - /** Provide the current timestamp. - * - * @return uint64_t The value of current timestamp. - */ - uint64_t getCurrentTimestamp(); - - /** Provide the date and time from second counted from January 1, 1970. - * - * @param sec The seconds from January 1, 1970 00.00. - * @return tm The tm structured data. - * - * @note The returned structured data tm has the members e.g. - * tm_year (from 1900), tm_mon (from 0 to 11), tm_mday, tm_hour, - * tm_min and tm_sec. - */ - struct tm getTimeFromSec(int seconds); - - /** Provide the current date time string that valid for Email. - * - * @return String The current date time string. - */ - String getDateTimeString(); - - time_t now; - uint64_t msec_time_diff = 0; - struct tm timeinfo; - float TZ = 0.0; - uint8_t DST_MN = 0; - bool clockReady = false; - -private: - int totalDays(int y, int m, int d); - char *intStr(int value); - void setSysTime(); - const char *dow[7] = {"sunday", "monday", "tuesday", "wednesday", "thurseday", "friday", "saturday"}; - const char *months[12] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; - const char *sdow[7] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; -}; - -#endif //ESPTimeHelper_H diff --git a/lib/libesp32/lib_mail/src/extras/MIMEInfo.h b/lib/libesp32/lib_mail/src/extras/MIMEInfo.h deleted file mode 100644 index 38269eb6b..000000000 --- a/lib/libesp32/lib_mail/src/extras/MIMEInfo.h +++ /dev/null @@ -1,65 +0,0 @@ -#ifndef MIMEInfo_H -#define MIMEInfo_H -#include - -enum esp_mail_file_extension -{ - esp_mail_file_extension_html, - esp_mail_file_extension_htm, - esp_mail_file_extension_css, - esp_mail_file_extension_txt, - esp_mail_file_extension_js, - esp_mail_file_extension_json, - esp_mail_file_extension_png, - esp_mail_file_extension_gif, - esp_mail_file_extension_jpg, - esp_mail_file_extension_ico, - esp_mail_file_extension_svg, - esp_mail_file_extension_ttf, - esp_mail_file_extension_otf, - esp_mail_file_extension_woff, - esp_mail_file_extension_woff2, - esp_mail_file_extension_eot, - esp_mail_file_extension_sfnt, - esp_mail_file_extension_xml, - esp_mail_file_extension_pdf, - esp_mail_file_extension_zip, - esp_mail_file_extension_gz, - esp_mail_file_extension_appcache, - esp_mail_file_extension_none, - esp_mail_file_extension_maxType -}; - -struct esp_mail_mime_prop_t -{ - char endsWith[10]; - char mimeType[50]; -}; - -const struct esp_mail_mime_prop_t mimeinfo[esp_mail_file_extension_maxType] PROGMEM = - { - {".html", "text/html"}, - {".htm", "text/html"}, - {".css", "text/css"}, - {".txt", "text/plain"}, - {".js", "application/javascript"}, - {".json", "application/json"}, - {".png", "image/png"}, - {".gif", "image/gif"}, - {".jpg", "image/jpeg"}, - {".ico", "image/x-icon"}, - {".svg", "image/svg+xml"}, - {".ttf", "application/x-font-ttf"}, - {".otf", "application/x-font-opentype"}, - {".woff", "application/font-woff"}, - {".woff2", "application/font-woff2"}, - {".eot", "application/vnd.ms-fontobject"}, - {".sfnt", "application/font-sfnt"}, - {".xml", "text/xml"}, - {".pdf", "application/pdf"}, - {".zip", "application/zip"}, - {".gz", "application/x-gzip"}, - {".appcache", "text/cache-manifest"}, - {"", "application/octet-stream"}}; - -#endif diff --git a/lib/libesp32/lib_mail/src/extras/RFC2047.cpp b/lib/libesp32/lib_mail/src/extras/RFC2047.cpp deleted file mode 100644 index 8f5dc31e3..000000000 --- a/lib/libesp32/lib_mail/src/extras/RFC2047.cpp +++ /dev/null @@ -1,237 +0,0 @@ -#ifndef RFC2047_CPP -#define RFC2047_CPP - -#include "RFC2047.h" - -RFC2047_Decoder::RFC2047_Decoder() {} -RFC2047_Decoder::~RFC2047_Decoder() {} - -void RFC2047_Decoder::rfc2047Decode(char *d, const char *s, size_t dlen) -{ - - const char *p, *q; - size_t n; - int found_encoded = 0; - - dlen--; /* save room for the terminal nul */ - - while (*s && dlen > 0) - { - if ((p = strstr (s, "=?")) == NULL || - (q = strchr (p + 2, '?')) == NULL || - (q = strchr (q + 1, '?')) == NULL || - (q = strstr (q + 1, "?=")) == NULL) - { - /* no encoded words */ - if (d != s) - strfcpy (d, s, dlen + 1); - return; - } - - if (p != s) - { - n = (size_t) (p - s); - /* ignore spaces between encoded words */ - if (!found_encoded || strspn (s, " \t\r\n") != n) - { - if (n > dlen) - n = dlen; - if (d != s) - memcpy (d, s, n); - d += n; - dlen -= n; - } - } - - rfc2047DecodeWord (d, p, dlen); - found_encoded = 1; - s = q + 2; - n = strlen (d); - dlen -= n; - d += n; - } - *d = 0; -} - -void RFC2047_Decoder::rfc2047DecodeWord(char *d, const char *s, size_t dlen) -{ - - char *p = safe_strdup (s); - char *pp = p; - char *pd = d; - size_t len = dlen; - int enc = 0, filter = 0, count = 0, c1, c2, c3, c4; - - while ((pp = strtok (pp, "?")) != NULL) - { - count++; - switch (count) - { - case 2: - if (strcasecmp (pp, Charset) != 0) - { - filter = 1; - } - break; - case 3: - if (toupper (*pp) == 'Q') - enc = ENCQUOTEDPRINTABLE; - else if (toupper (*pp) == 'B') - enc = ENCBASE64; - else - return; - break; - case 4: - if (enc == ENCQUOTEDPRINTABLE) - { - while (*pp && len > 0) - { - if (*pp == '_') - { - *pd++ = ' '; - len--; - } - else if (*pp == '=') - { - *pd++ = (hexval(pp[1]) << 4) | hexval(pp[2]); - len--; - pp += 2; - } - else - { - *pd++ = *pp; - len--; - } - pp++; - } - *pd = 0; - } - else if (enc == ENCBASE64) - { - while (*pp && len > 0) - { - c1 = base64val(pp[0]); - c2 = base64val(pp[1]); - *pd++ = (c1 << 2) | ((c2 >> 4) & 0x3); - if (--len == 0) break; - - if (pp[2] == '=') break; - - c3 = base64val(pp[2]); - *pd++ = ((c2 & 0xf) << 4) | ((c3 >> 2) & 0xf); - if (--len == 0) - break; - - if (pp[3] == '=') - break; - - c4 = base64val(pp[3]); - *pd++ = ((c3 & 0x3) << 6) | c4; - if (--len == 0) - break; - - pp += 4; - } - *pd = 0; - } - break; - } - pp = 0; - } - safe_free (&p); - if (filter) - { - - pd = d; - while (*pd) - { - if (!IsPrint (*pd)) - *pd = '?'; - pd++; - } - } - return; -} - -void *RFC2047_Decoder::safe_calloc(size_t nmemb, size_t size) -{ - void *p; - - if (!nmemb || !size) - return NULL; - if (!(p = calloc (nmemb, size))) - { - //out of memory - return NULL; - } - return p; -} - -void *RFC2047_Decoder::safe_malloc(unsigned int siz) -{ - void *p; - - if (siz == 0) - return 0; - if ((p = (void *) malloc (siz)) == 0) - { - //out of memory - return NULL; - } - return (p); -} - -void RFC2047_Decoder::safe_realloc(void **p, size_t siz) -{ - void *r; - - if (siz == 0) - { - if (*p) - { - free (*p); - *p = NULL; - } - return; - } - - if (*p) - r = (void *) realloc (*p, siz); - else - { - r = (void *) malloc (siz); - } - - if (!r) - { - //out of memory - return; - } - - *p = r; -} - -void RFC2047_Decoder::safe_free(void *ptr) -{ - void **p = (void **)ptr; - if (*p) - { - free (*p); - *p = 0; - } -} - -char *RFC2047_Decoder::safe_strdup(const char *s) -{ - char *p; - size_t l; - - if (!s || !*s) return 0; - l = strlen (s) + 1; - p = (char *)safe_malloc (l); - memcpy (p, s, l); - return (p); -} - - -#endif //RFC2047_CPP \ No newline at end of file diff --git a/lib/libesp32/lib_mail/src/wcs/esp32/ESP_Mail_HTTPClient32.cpp b/lib/libesp32/lib_mail/src/wcs/esp32/ESP_Mail_HTTPClient32.cpp deleted file mode 100644 index a1d386ea6..000000000 --- a/lib/libesp32/lib_mail/src/wcs/esp32/ESP_Mail_HTTPClient32.cpp +++ /dev/null @@ -1,233 +0,0 @@ -/* - * Customized version of ESP32 HTTPClient Library. - * - * v 1.1.5 - * - * The MIT License (MIT) - * Copyright (c) 2021 K. Suwatchai (Mobizt) - * - * HTTPClient Arduino library for ESP32 - * - * Copyright (c) 2015 Markus Sattler. All rights reserved. - * This file is part of the HTTPClient for Arduino. - * Port to ESP32 by Evandro Luis Copercini (2017), - * changed fingerprints to CA verification. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * -*/ - -#ifndef ESP_Mail_HTTPClient32_CPP -#define ESP_Mail_HTTPClient32_CPP - -#ifdef ESP32 - -#include "ESP_Mail_HTTPClient32.h" - -ESP_Mail_HTTPClient32::ESP_Mail_HTTPClient32() -{ -} - -ESP_Mail_HTTPClient32::~ESP_Mail_HTTPClient32() -{ - if (_wcs) - { - _wcs->stop(); - _wcs.reset(nullptr); - _wcs.release(); - } - std::string().swap(_host); - std::string().swap(_caCertFile); -} - -bool ESP_Mail_HTTPClient32::begin(const char *host, uint16_t port) -{ - _host = host; - _port = port; - return true; -} - -bool ESP_Mail_HTTPClient32::connected() -{ - if (_wcs) - { - if (_secured) - return _wcs->connected(); - else - return _wcs->_ns_connected(); - } - return false; -} - -bool ESP_Mail_HTTPClient32::send(const char *header) -{ - if (!connected()) - return false; - if (_secured) - return (_wcs->write(header, strlen(header)) == strlen(header)); - else - return (_wcs->_ns_write(header, strlen(header)) == strlen(header)); -} - -int ESP_Mail_HTTPClient32::send(const char *header, const char *payload) -{ - size_t size = strlen(payload); - if (strlen(header) > 0) - { - if (!connect(_secured)) - { - return ESP_MAIL_ERROR_HTTPC_ERROR_CONNECTION_REFUSED; - } - - if (!send(header)) - { - return ESP_MAIL_ERROR_HTTPC_ERROR_SEND_HEADER_FAILED; - } - } - - if (size > 0) - { - if (_secured) - { - if (_wcs->write(&payload[0], size) != size) - return ESP_MAIL_ERROR_HTTPC_ERROR_SEND_PAYLOAD_FAILED; - } - else - { - if (_wcs->_ns_write(&payload[0], size) != size) - return ESP_MAIL_ERROR_HTTPC_ERROR_SEND_PAYLOAD_FAILED; - } - } - - return 0; -} - -WiFiClient *ESP_Mail_HTTPClient32::stream(void) -{ - if (connected()) - return _wcs.get(); - return nullptr; -} -ESP_Mail_WCS32 *ESP_Mail_HTTPClient32::_stream(void) -{ - if (connected()) - return _wcs.get(); - return nullptr; -} - -size_t ESP_Mail_HTTPClient32::_ns_print(const char *buf) -{ - size_t size = strlen(buf); - return _wcs->_ns_write(&buf[0], size); -} - -size_t ESP_Mail_HTTPClient32::_ns_println(const char *buf) -{ - size_t size = strlen(buf); - size_t wr = _wcs->_ns_write((const char *)&buf[0], size); - std::string s = "\r\n"; - wr += _wcs->_ns_write(s.c_str(), s.length()); - return wr; -} - -bool ESP_Mail_HTTPClient32::connect(void) -{ - return connect(false); -} - -bool ESP_Mail_HTTPClient32::connect(bool secured) -{ - _secured = secured; - - if (connected()) - { - if (_secured) - { - while (_wcs->available() > 0) - _wcs->read(); - } - else - { - while (_wcs->_ns_available() > 0) - _wcs->_ns_read(); - } - return true; - } - - if (_debugCallback) - _wcs->setDebugCB(&_debugCallback); - _wcs->setSTARTTLS(!secured); - - if (!_wcs->connect(_host.c_str(), _port)) - return false; - return connected(); -} - -void ESP_Mail_HTTPClient32::setDebugCallback(DebugMsgCallback cb) -{ - _debugCallback = std::move(cb); -} - -void ESP_Mail_HTTPClient32::setCACert(const char *caCert) -{ - _wcs->setCACert(caCert); - if (caCert) - _certType = 1; - else - { - setInsecure(); - _certType = 0; - } - //_wcs->setNoDelay(true); -} - -void ESP_Mail_HTTPClient32::setCertFile(const char *caCertFile, esp_mail_file_storage_type storageType) -{ - - if (strlen(caCertFile) > 0) - { - File f; - if (storageType == esp_mail_file_storage_type_flash) - { - ESP_MAIL_FLASH_FS.begin(); - if (ESP_MAIL_FLASH_FS.exists(caCertFile)) - f = ESP_MAIL_FLASH_FS.open(caCertFile, FILE_READ); - } - else if (storageType == esp_mail_file_storage_type_sd) - { - ESP_MAIL_SD_FS.begin(); - if (ESP_MAIL_SD_FS.exists(caCertFile)) - f = ESP_MAIL_SD_FS.open(caCertFile, FILE_READ); - } - - if (f) - { - size_t len = f.size(); - _wcs->loadCACert(f, len); - f.close(); - } - _certType = 2; - } - //_wcs->setNoDelay(true); -} - -void ESP_Mail_HTTPClient32::setInsecure() -{ - _wcs->setInsecure(); -} - -#endif //ESP32 - -#endif //ESP_Mail_HTTPClient32_CPP diff --git a/lib/libesp32/lib_mail/src/wcs/esp32/ESP_Mail_HTTPClient32.h b/lib/libesp32/lib_mail/src/wcs/esp32/ESP_Mail_HTTPClient32.h deleted file mode 100644 index 189e25ad1..000000000 --- a/lib/libesp32/lib_mail/src/wcs/esp32/ESP_Mail_HTTPClient32.h +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Customized version of ESP32 HTTPClient Library. - * - * v 1.1.5 - * - * The MIT License (MIT) - * Copyright (c) 2021 K. Suwatchai (Mobizt) - * - * HTTPClient Arduino library for ESP32 - * - * Copyright (c) 2015 Markus Sattler. All rights reserved. - * This file is part of the HTTPClient for Arduino. - * Port to ESP32 by Evandro Luis Copercini (2017), - * changed fingerprints to CA verification. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * -*/ - -#ifndef ESP_Mail_HTTPClient32_H -#define ESP_Mail_HTTPClient32_H - -#ifdef ESP32 - -#include -#include -#include -//#include -#include -#include "ESP_Mail_FS.h" -#include "ESP_Mail_WCS32.h" - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" -#define ESP_MAIL_FLASH_FS ESP_Mail_DEFAULT_FLASH_FS -#define ESP_MAIL_SD_FS ESP_Mail_DEFAULT_SD_FS - -#if __has_include() || __has_include() -#error WiFi UART bridge was not supported. -#endif - -#define ESP_MAIL_ERROR_HTTPC_ERROR_CONNECTION_REFUSED (-1) -#define ESP_MAIL_ERROR_HTTPC_ERROR_SEND_HEADER_FAILED (-2) -#define ESP_MAIL_ERROR_HTTPC_ERROR_SEND_PAYLOAD_FAILED (-3) -#define ESP_MAIL_DEFAULT_TCP_TIMEOUT_SEC 30 - -enum esp_mail_file_storage_type -{ - esp_mail_file_storage_type_none, - esp_mail_file_storage_type_flash, - esp_mail_file_storage_type_sd, - esp_mail_file_storage_type_univ -}; - -class ESP_Mail_HTTPClient32 -{ -public: - ESP_Mail_HTTPClient32(); - ~ESP_Mail_HTTPClient32(); - - /** - * Initialization of new http connection. - * \param host - Host name without protocols. - * \param port - Server's port. - * \return True as default. - * If no certificate string provided, use (const char*)NULL to CAcert param - */ - bool begin(const char *host, uint16_t port); - - /** - * Check the http connection status. - * \return True if connected. - */ - bool connected(); - - /** - * Establish http connection if header provided and send it, send payload if provided. - * \param header - The header string (constant chars array). - * \param payload - The payload string (constant chars array), optional. - * \return http status code, Return zero if new http connection and header and/or payload sent - * with no error or no header and payload provided. If obly payload provided, no new http connection was established. - */ - int send(const char *header, const char *payload); - - /** - * Send extra header without making new http connection (if send has been called) - * \param header - The header string (constant chars array). - * \return True if header sending success. - * Need to call send with header first. - */ - bool send(const char *header); - - /** - * Get the WiFi client pointer. - * \return WiFi client pointer. - */ - WiFiClient *stream(void); - - /** - * Set insecure mode - */ - void setInsecure(); - - ESP_Mail_WCS32 *_stream(void); - size_t _ns_print(const char *buf); - size_t _ns_println(const char *buf); - - int tcpTimeout = 40000; - bool connect(void); - bool connect(bool secured); - void setCACert(const char *caCert); - void setCertFile(const char *caCertFile, esp_mail_file_storage_type storageType); - void setDebugCallback(DebugMsgCallback cb); - bool _secured = true; - - int _certType = -1; - std::string _caCertFile = ""; - esp_mail_file_storage_type _caCertFileStoreageType = esp_mail_file_storage_type::esp_mail_file_storage_type_none; - -protected: - DebugMsgCallback _debugCallback = NULL; - std::unique_ptr _wcs = std::unique_ptr(new ESP_Mail_WCS32()); - - std::string _host = ""; - uint16_t _port = 0; -}; - -#endif //ESP32 - -#endif //ESP_Mail_HTTPClient32_H diff --git a/lib/libesp32/lib_mail/src/wcs/esp32/ESP_Mail_WCS32.cpp b/lib/libesp32/lib_mail/src/wcs/esp32/ESP_Mail_WCS32.cpp deleted file mode 100644 index 72946d9e2..000000000 --- a/lib/libesp32/lib_mail/src/wcs/esp32/ESP_Mail_WCS32.cpp +++ /dev/null @@ -1,564 +0,0 @@ -/* - *Customized WiFiClientSecure.cpp version 1.0.8 - * - * The MIT License (MIT) - * Copyright (c) 2021 K. Suwatchai (Mobizt) - * - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -/* - WiFiClientSecure.cpp - Client Secure class for ESP32 - Copyright (c) 2016 Hristo Gochkov All right reserved. - Additions Copyright (C) 2017 Evandro Luis Copercini. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef ESP_Mail_WCS32_CPP -#define ESP_Mail_WCS32_CPP - -#ifdef ESP32 - -#include "ESP_Mail_WCS32.h" -#include -#include -#include - -#undef connect -#undef write -#undef read - -ESP_Mail_WCS32::ESP_Mail_WCS32() -{ - _connected = false; - - sslclient = new esp_mail_ssl_client32::esp_mail_ssl_ctx32; - _ssl_client32.ssl_init(sslclient); - sslclient->socket = -1; - sslclient->handshake_timeout = 120000; - _use_insecure = false; - _CA_cert = NULL; - _cert = NULL; - _private_key = NULL; - _pskIdent = NULL; - _psKey = NULL; - next = NULL; -} - -ESP_Mail_WCS32::ESP_Mail_WCS32(int sock) -{ - _connected = false; - _timeout = 0; - - sslclient = new esp_mail_ssl_client32::esp_mail_ssl_ctx32; - _ssl_client32.ssl_init(sslclient); - sslclient->socket = sock; - sslclient->handshake_timeout = 120000; - - if (sock >= 0) - { - _connected = true; - } - - _CA_cert = NULL; - _cert = NULL; - _private_key = NULL; - _pskIdent = NULL; - _psKey = NULL; - next = NULL; -} - -ESP_Mail_WCS32::ESP_Mail_WCS32(bool secured) -{ - _connected = false; - - sslclient = new esp_mail_ssl_client32::esp_mail_ssl_ctx32; - _ssl_client32.ssl_init(sslclient); - sslclient->socket = -1; - sslclient->handshake_timeout = 120000; - _use_insecure = !secured; - _secured = secured; - _CA_cert = NULL; - _cert = NULL; - _private_key = NULL; - _pskIdent = NULL; - _psKey = NULL; - next = NULL; -} - -ESP_Mail_WCS32::~ESP_Mail_WCS32() -{ - stop(); - delete sslclient; -} - -ESP_Mail_WCS32 &ESP_Mail_WCS32::operator=(const ESP_Mail_WCS32 &other) -{ - stop(); - sslclient->socket = other.sslclient->socket; - _connected = other._connected; - return *this; -} - -void ESP_Mail_WCS32::stop() -{ - if (sslclient->socket >= 0) - { - close(sslclient->socket); - sslclient->socket = -1; - _connected = false; - _peek = -1; - } - _ssl_client32.stop_ssl_socket(sslclient, _CA_cert, _cert, _private_key); -} - -int ESP_Mail_WCS32::connect(IPAddress ip, uint16_t port) -{ - if (_pskIdent && _psKey) - return connect(ip, port, _pskIdent, _psKey); - return connect(ip, port, _CA_cert, _cert, _private_key); -} - -int ESP_Mail_WCS32::connect(IPAddress ip, uint16_t port, int32_t timeout) -{ - _timeout = timeout; - return connect(ip, port); -} - -int ESP_Mail_WCS32::connect(const char *host, uint16_t port) -{ - if (_pskIdent && _psKey) - return connect(host, port, _pskIdent, _psKey); - return connect(host, port, _CA_cert, _cert, _private_key); -} - -int ESP_Mail_WCS32::connect(const char *host, uint16_t port, int32_t timeout) -{ - _timeout = timeout; - return connect(host, port); -} - -int ESP_Mail_WCS32::connect(IPAddress ip, uint16_t port, const char *CA_cert, const char *cert, const char *private_key) -{ - return connect(ip.toString().c_str(), port, CA_cert, cert, private_key); -} - -int ESP_Mail_WCS32::connect(const char *host, uint16_t port, const char *CA_cert, const char *cert, const char *private_key) -{ - _host = host; - _port = port; - _withCert = true; - - if (_timeout > 0) - { - sslclient->handshake_timeout = _timeout; - } - - int ret = _ssl_client32.start_socket(sslclient, host, port, _timeout, CA_cert, cert, private_key, NULL, NULL, _use_insecure); - - _lastError = ret; - if (ret < 0) - { - log_e("start_ssl_client: %d", ret); - stop(); - return 0; - } - - if (_secured) - { - ret = _ssl_client32.start_ssl_client(sslclient, host, port, _timeout, CA_cert, cert, private_key, NULL, NULL, _use_insecure); - _lastError = ret; - if (ret < 0) - { - log_e("start_ssl_client: %d", ret); - stop(); - return 0; - } - } - - _connected = true; - return 1; -} - -int ESP_Mail_WCS32::connect(IPAddress ip, uint16_t port, const char *pskIdent, const char *psKey) -{ - return connect(ip.toString().c_str(), port, pskIdent, psKey); -} - -int ESP_Mail_WCS32::connect(const char *host, uint16_t port, const char *pskIdent, const char *psKey) -{ - _host = host; - _port = port; - _withCert = true; - - log_v("start_ssl_client with PSK"); - if (_timeout > 0) - { - sslclient->handshake_timeout = _timeout; - } - - int ret = _ssl_client32.start_socket(sslclient, host, port, _timeout, NULL, NULL, NULL, pskIdent, psKey, _use_insecure); - _lastError = ret; - if (ret < 0) - { - log_e("start_ssl_client: %d", ret); - stop(); - return 0; - } - - if (_secured) - { - ret = _ssl_client32.start_ssl_client(sslclient, host, port, _timeout, NULL, NULL, NULL, pskIdent, psKey, _use_insecure); - _lastError = ret; - if (ret < 0) - { - log_e("start_ssl_client: %d", ret); - stop(); - return 0; - } - } - _connected = true; - return 1; -} - -int ESP_Mail_WCS32::peek() -{ - if (_peek >= 0) - { - return _peek; - } - _peek = timedRead(); - return _peek; -} - -size_t ESP_Mail_WCS32::write(uint8_t data) -{ - return write(&data, 1); -} - -int ESP_Mail_WCS32::read() -{ - uint8_t data = -1; - int res = read(&data, 1); - if (res < 0) - { - return res; - } - return data; -} - -size_t ESP_Mail_WCS32::write(const uint8_t *buf, size_t size) -{ - if (!_connected) - { - return 0; - } - int res = _ssl_client32.send_ssl_data(sslclient, buf, size); - if (res < 0) - { - stop(); - res = 0; - } - return res; -} - -int ESP_Mail_WCS32::read(uint8_t *buf, size_t size) -{ - int peeked = 0; - int avail = available(); - if ((!buf && size) || avail <= 0) - { - return -1; - } - if (!size) - { - return 0; - } - if (_peek >= 0) - { - buf[0] = _peek; - _peek = -1; - size--; - avail--; - if (!size || !avail) - { - return 1; - } - buf++; - peeked = 1; - } - - int res = _ssl_client32.get_ssl_receive(sslclient, buf, size); - if (res < 0) - { - stop(); - return peeked ? peeked : res; - } - return res + peeked; -} - -int ESP_Mail_WCS32::available() -{ - int peeked = (_peek >= 0); - if (!_connected) - { - return peeked; - } - int res = _ssl_client32.data_to_read(sslclient); - if (res < 0) - { - stop(); - return peeked ? peeked : res; - } - return res + peeked; -} - -uint8_t ESP_Mail_WCS32::connected() -{ - uint8_t dummy = 0; - read(&dummy, 0); - - return _connected; -} - -void ESP_Mail_WCS32::setInsecure() -{ - _CA_cert = NULL; - _cert = NULL; - _private_key = NULL; - _pskIdent = NULL; - _psKey = NULL; - _use_insecure = true; -} - -void ESP_Mail_WCS32::setCACert(const char *rootCA) -{ - _CA_cert = rootCA; -} - -void ESP_Mail_WCS32::setCertificate(const char *client_ca) -{ - _cert = client_ca; -} - -void ESP_Mail_WCS32::setPrivateKey(const char *private_key) -{ - _private_key = private_key; -} - -void ESP_Mail_WCS32::setPreSharedKey(const char *pskIdent, const char *psKey) -{ - _pskIdent = pskIdent; - _psKey = psKey; -} - -bool ESP_Mail_WCS32::verify(const char *fp, const char *domain_name) -{ - if (!sslclient) - return false; - - return _ssl_client32.verify_ssl_fingerprint(sslclient, fp, domain_name); -} - -char *ESP_Mail_WCS32::_streamLoad(Stream &stream, size_t size) -{ - char *dest = (char *)malloc(size + 1); - if (!dest) - { - return nullptr; - } - if (size != stream.readBytes(dest, size)) - { - free(dest); - dest = nullptr; - return nullptr; - } - dest[size] = '\0'; - return dest; -} - -bool ESP_Mail_WCS32::loadCACert(Stream &stream, size_t size) -{ - char *dest = _streamLoad(stream, size); - bool ret = false; - if (dest) - { - setCACert(dest); - ret = true; - } - return ret; -} - -bool ESP_Mail_WCS32::loadCertificate(Stream &stream, size_t size) -{ - char *dest = _streamLoad(stream, size); - bool ret = false; - if (dest) - { - setCertificate(dest); - ret = true; - } - return ret; -} - -bool ESP_Mail_WCS32::loadPrivateKey(Stream &stream, size_t size) -{ - char *dest = _streamLoad(stream, size); - bool ret = false; - if (dest) - { - setPrivateKey(dest); - ret = true; - } - return ret; -} - -int ESP_Mail_WCS32::lastError(char *buf, const size_t size) -{ - if (!_lastError) - { - return 0; - } - mbedtls_strerror(_lastError, buf, size); - return _lastError; -} - -void ESP_Mail_WCS32::setHandshakeTimeout(unsigned long handshake_timeout) -{ - sslclient->handshake_timeout = handshake_timeout * 1000; -} - -void ESP_Mail_WCS32::setSTARTTLS(bool enable) -{ - _secured = !enable; -} - -void ESP_Mail_WCS32::setDebugCB(DebugMsgCallback *cb) -{ - sslclient->_debugCallback = cb; -} - -int ESP_Mail_WCS32::_ns_available() -{ - if (sslclient->socket < 0) - return false; - - if (_rxBuf.length() == 0) - { - int bufLen = 1024; - char *tmp = new char[bufLen]; - memset(tmp, 0, bufLen); - int ret = _ssl_client32._ns_lwip_read(sslclient, tmp, bufLen); - if (ret > 0) - _rxBuf += tmp; - delete[] tmp; - } - - int result = _rxBuf.length(); - - if (!result) - { - optimistic_yield(100); - } - return result; -} - -size_t ESP_Mail_WCS32::_ns_write(const char *buf, size_t size) -{ - if (sslclient->socket < 0 || !size) - return 0; - return _ssl_client32._ns_lwip_write(sslclient, buf, size); -} - -size_t ESP_Mail_WCS32::_ns_read(char *buf, size_t size) -{ - if (_rxBuf.length() == 0) - return _ssl_client32._ns_lwip_read(sslclient, buf, size); - else - { - size_t sz = size; - if (sz > _rxBuf.length()) - sz = _rxBuf.length(); - strncpy(buf, _rxBuf.c_str(), sz); - _rxBuf.erase(0, sz); - return sz; - } -} - -int ESP_Mail_WCS32::_ns_read() -{ - int c = -1; - if (_rxBuf.length() == 0) - { - char *buf = new char[2]; - memset(buf, 0, 2); - int ret = _ssl_client32._ns_lwip_read(sslclient, buf, 1); - if (ret > 0) - c = buf[0]; - delete[] buf; - } - else - { - c = _rxBuf.c_str()[0]; - _rxBuf.erase(0, 1); - } - - return c; -} - -uint8_t ESP_Mail_WCS32::_ns_connected() -{ - return sslclient->socket >= 0; -} - -bool ESP_Mail_WCS32::_ns_connect_ssl() -{ - int ret = 0; - if (_withKey) - ret = _ssl_client32.start_ssl_client(sslclient, _host.c_str(), _port, _timeout, _CA_cert, _cert, _private_key, NULL, NULL, _use_insecure); - else if (_withCert) - ret = _ssl_client32.start_ssl_client(sslclient, _host.c_str(), _port, _timeout, NULL, NULL, NULL, _pskIdent, _psKey, _use_insecure); - - _lastError = ret; - if (ret < 0) - { - log_e("start_ssl_client: %d", ret); - stop(); - return 0; - } - - return 1; -} - -#endif //ESP32 - -#endif //ESP_Mail_WCS32_CPP \ No newline at end of file diff --git a/lib/libesp32/lib_mail/src/wcs/esp32/ESP_Mail_WCS32.h b/lib/libesp32/lib_mail/src/wcs/esp32/ESP_Mail_WCS32.h deleted file mode 100644 index 35be7527d..000000000 --- a/lib/libesp32/lib_mail/src/wcs/esp32/ESP_Mail_WCS32.h +++ /dev/null @@ -1,160 +0,0 @@ - -/* - *Customized WiFiClientSecure.h version 1.0.8 - * - * The MIT License (MIT) - * Copyright (c) 2021 K. Suwatchai (Mobizt) - * - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -/* - WiFiClientSecure.h - Base class that provides Client SSL to ESP32 - Copyright (c) 2011 Adrian McEwen. All right reserved. - Additions Copyright (C) 2017 Evandro Luis Copercini. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef ESP_Mail_WCS32_H -#define ESP_Mail_WCS32_H - -#ifdef ESP32 - -#include "Arduino.h" -#include "IPAddress.h" -#include -#include "esp_mail_ssl_client32.h" - -typedef void (*DebugMsgCallback)(const char *msg); - -class ESP_Mail_WCS32 : public WiFiClient -{ - friend class ESP_Mail_HTTPClient32; - -protected: - esp_mail_ssl_client32::esp_mail_ssl_ctx32 *sslclient; - - int _lastError = 0; - int _peek = -1; - int _timeout = 0; - bool _use_insecure; - const char *_CA_cert; - const char *_cert; - const char *_private_key; - const char *_pskIdent; // identity for PSK cipher suites - const char *_psKey; // key in hex for PSK cipher suites - -public: - ESP_Mail_WCS32 *next; - ESP_Mail_WCS32(); - ESP_Mail_WCS32(int socket); - ESP_Mail_WCS32(bool secured); - ~ESP_Mail_WCS32(); - int connect(IPAddress ip, uint16_t port); - int connect(IPAddress ip, uint16_t port, int32_t timeout); - int connect(const char *host, uint16_t port); - int connect(const char *host, uint16_t port, int32_t timeout); - int connect(IPAddress ip, uint16_t port, const char *rootCABuff, const char *cli_cert, const char *cli_key); - int connect(const char *host, uint16_t port, const char *rootCABuff, const char *cli_cert, const char *cli_key); - int connect(IPAddress ip, uint16_t port, const char *pskIdent, const char *psKey); - int connect(const char *host, uint16_t port, const char *pskIdent, const char *psKey); - int peek(); - size_t write(uint8_t data); - size_t write(const uint8_t *buf, size_t size); - int available(); - int read(); - int read(uint8_t *buf, size_t size); - void flush() {} - void stop(); - uint8_t connected(); - int lastError(char *buf, const size_t size); - void setInsecure(); // Don't validate the chain, just accept whatever is given. VERY INSECURE! - void setPreSharedKey(const char *pskIdent, const char *psKey); // psKey in Hex - void setCACert(const char *rootCA); - void setCertificate(const char *client_ca); - void setPrivateKey(const char *private_key); - bool loadCACert(Stream &stream, size_t size); - bool loadCertificate(Stream &stream, size_t size); - bool loadPrivateKey(Stream &stream, size_t size); - bool verify(const char *fingerprint, const char *domain_name); - void setHandshakeTimeout(unsigned long handshake_timeout); - int setTimeout(uint32_t seconds) { return 0; } - void setSTARTTLS(bool enable); - void setDebugCB(DebugMsgCallback *cb); - int _ns_available(); - size_t _ns_write(const char *buf, size_t size); - size_t _ns_read(char *buf, size_t size); - int _ns_read(); - uint8_t _ns_connected(); - bool _ns_connect_ssl(); - - operator bool() - { - return connected(); - } - ESP_Mail_WCS32 &operator=(const ESP_Mail_WCS32 &other); - bool operator==(const bool value) - { - return bool() == value; - } - bool operator!=(const bool value) - { - return bool() != value; - } - bool operator==(const ESP_Mail_WCS32 &); - bool operator!=(const ESP_Mail_WCS32 &rhs) - { - return !this->operator==(rhs); - }; - - int socket() - { - return sslclient->socket = -1; - } - -private: - esp_mail_ssl_client32 _ssl_client32; - char *_streamLoad(Stream &stream, size_t size); - bool _secured = true; - bool _withCert = false; - bool _withKey = false; - std::string _host = ""; - std::string _rxBuf = ""; - int _port; - - //friend class WiFiServer; - using Print::write; -}; - -#endif //ESP32 - -#endif //ESP_Mail_WCS32_H diff --git a/lib/libesp32/lib_mail/src/wcs/esp32/esp_mail_ssl_client32.cpp b/lib/libesp32/lib_mail/src/wcs/esp32/esp_mail_ssl_client32.cpp deleted file mode 100644 index a96e2d6c8..000000000 --- a/lib/libesp32/lib_mail/src/wcs/esp32/esp_mail_ssl_client32.cpp +++ /dev/null @@ -1,702 +0,0 @@ -/* - *Customized ssl_client.cpp to support STARTTLS protocol, version 1.0.8 - * - * The MIT License (MIT) - * Copyright (c) 2021 K. Suwatchai (Mobizt) - * - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -/* Provide SSL/TLS functions to ESP32 with Arduino IDE -* -* Adapted from the ssl_client1 example of mbedtls. -* -* Original Copyright (C) 2006-2015, ARM Limited, All Rights Reserved, Apache 2.0 License. -* Additions Copyright (C) 2017 Evandro Luis Copercini, Apache 2.0 License. -*/ - -#ifndef ESP_MAIL_SSL_CLIENT32_CPP -#define ESP_MAIL_SSL_CLIENT32_CPP - -#ifdef ESP32 - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "esp_mail_ssl_client32.h" -#include - -#if !defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED) && !defined(MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED) -#error "Please configure IDF framework to include mbedTLS -> Enable pre-shared-key ciphersuites and activate at least one cipher" -#endif - -const char *_esp_mail_pers32 = "esp_mail_esp32-tls"; - -static int _handle_error(int err, const char *file, int line) -{ - if (err == -30848) - { - return err; - } -#ifdef MBEDTLS_ERROR_C - char error_buf[100]; - mbedtls_strerror(err, error_buf, 100); - log_e("[%s():%d]: (%d) %s", file, line, err, error_buf); -#else - log_e("[%s():%d]: code %d", file, line, err); -#endif - return err; -} - -#define handle_error(e) _handle_error(e, __FUNCTION__, __LINE__) - -void esp_mail_ssl_client32::ssl_init(esp_mail_ssl_ctx32 *ssl_client) -{ - mbedtls_ssl_init(&ssl_client->ssl_ctx); - mbedtls_ssl_config_init(&ssl_client->ssl_conf); - mbedtls_ctr_drbg_init(&ssl_client->drbg_ctx); -} - -int esp_mail_ssl_client32::start_socket(esp_mail_ssl_ctx32 *ssl_client, const char *host, uint32_t port, int timeout, const char *rootCABuff, const char *cli_cert, const char *cli_key, const char *pskIdent, const char *psKey, bool insecure) -{ - - if (rootCABuff == NULL && pskIdent == NULL && psKey == NULL && !insecure) - { - if (ssl_client->_debugCallback) - ssl_client_debug_pgm_send_cb(ssl_client, esp_ssl_client_str_27); - return -1; - } - - int enable = 1; - - if (ssl_client->_debugCallback) - ssl_client_debug_pgm_send_cb(ssl_client, esp_ssl_client_str_2); - - log_v("Free internal heap before TLS %u", ESP.getFreeHeap()); - - log_v("Starting socket"); - ssl_client->socket = -1; - - ssl_client->socket = lwip_socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); - if (ssl_client->socket < 0) - { - if (ssl_client->_debugCallback) - ssl_client_debug_pgm_send_cb(ssl_client, esp_ssl_client_str_3); - log_e("ERROR opening socket"); - return ssl_client->socket; - } - - IPAddress srv((uint32_t)0); - if (!WiFiGenericClass::hostByName(host, srv)) - { - if (ssl_client->_debugCallback) - ssl_client_debug_pgm_send_cb(ssl_client, esp_ssl_client_str_4); - return -1; - } - - struct sockaddr_in serv_addr; - memset(&serv_addr, 0, sizeof(serv_addr)); - serv_addr.sin_family = AF_INET; - serv_addr.sin_addr.s_addr = srv; - serv_addr.sin_port = htons(port); - - if (ssl_client->_debugCallback) - ssl_client_debug_pgm_send_cb(ssl_client, esp_ssl_client_str_5); - - if (lwip_connect(ssl_client->socket, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) == 0) - { - if (timeout <= 0) - { - timeout = 30000; // Milli seconds. - } - timeval so_timeout = {.tv_sec = timeout / 1000, .tv_usec = (timeout % 1000) * 1000}; - -#define ROE(x, msg) \ - { \ - if (((x) < 0)) \ - { \ - log_e("LWIP Socket config of " msg " failed."); \ - return -1; \ - } \ - } - ROE(lwip_setsockopt(ssl_client->socket, SOL_SOCKET, SO_RCVTIMEO, &so_timeout, sizeof(so_timeout)), "SO_RCVTIMEO"); - ROE(lwip_setsockopt(ssl_client->socket, SOL_SOCKET, SO_SNDTIMEO, &so_timeout, sizeof(so_timeout)), "SO_SNDTIMEO"); - - ROE(lwip_setsockopt(ssl_client->socket, IPPROTO_TCP, TCP_NODELAY, &enable, sizeof(enable)), "TCP_NODELAY"); - ROE(lwip_setsockopt(ssl_client->socket, SOL_SOCKET, SO_KEEPALIVE, &enable, sizeof(enable)), "SO_KEEPALIVE"); - } - else - { - if (ssl_client->_debugCallback) - ssl_client_debug_pgm_send_cb(ssl_client, esp_ssl_client_str_7); - log_e("Connect to Server failed!"); - return -1; - } - - fcntl(ssl_client->socket, F_SETFL, fcntl(ssl_client->socket, F_GETFL, 0) | O_NONBLOCK); - - return ssl_client->socket; -} - -int esp_mail_ssl_client32::start_ssl_client(esp_mail_ssl_ctx32 *ssl_client, const char *host, uint32_t port, int timeout, const char *rootCABuff, const char *cli_cert, const char *cli_key, const char *pskIdent, const char *psKey, bool insecure) -{ - - char buf[512]; - int ret, flags; - - if (ssl_client->_debugCallback) - ssl_client_debug_pgm_send_cb(ssl_client, esp_ssl_client_str_9); - - log_v("Seeding the random number generator"); - mbedtls_entropy_init(&ssl_client->entropy_ctx); - - ret = mbedtls_ctr_drbg_seed(&ssl_client->drbg_ctx, mbedtls_entropy_func, &ssl_client->entropy_ctx, (const unsigned char *)_esp_mail_pers32, strlen(_esp_mail_pers32)); - if (ret < 0) - { - if (ssl_client->_debugCallback) - ssl_client_send_mbedtls_error_cb(ssl_client, ret); - return handle_error(ret); - } - - if (ssl_client->_debugCallback) - ssl_client_debug_pgm_send_cb(ssl_client, esp_ssl_client_str_10); - - log_v("Setting up the SSL/TLS structure..."); - - if ((ret = mbedtls_ssl_config_defaults(&ssl_client->ssl_conf, - MBEDTLS_SSL_IS_CLIENT, - MBEDTLS_SSL_TRANSPORT_STREAM, - MBEDTLS_SSL_PRESET_DEFAULT)) != 0) - { - if (ssl_client->_debugCallback) - ssl_client_send_mbedtls_error_cb(ssl_client, ret); - return handle_error(ret); - } - - // MBEDTLS_SSL_VERIFY_REQUIRED if a CA certificate is defined on Arduino IDE and - // MBEDTLS_SSL_VERIFY_NONE if not. - - if (insecure) - { - if (ssl_client->_debugCallback) - ssl_client_debug_pgm_send_cb(ssl_client, esp_ssl_client_str_28); - - mbedtls_ssl_conf_authmode(&ssl_client->ssl_conf, MBEDTLS_SSL_VERIFY_NONE); - log_i("WARNING: Skipping SSL Verification. INSECURE!"); - } - else if (rootCABuff != NULL) - { - if (ssl_client->_debugCallback) - ssl_client_debug_pgm_send_cb(ssl_client, esp_ssl_client_str_11); - log_v("Loading CA cert"); - mbedtls_x509_crt_init(&ssl_client->ca_cert); - mbedtls_ssl_conf_authmode(&ssl_client->ssl_conf, MBEDTLS_SSL_VERIFY_REQUIRED); - ret = mbedtls_x509_crt_parse(&ssl_client->ca_cert, (const unsigned char *)rootCABuff, strlen(rootCABuff) + 1); - mbedtls_ssl_conf_ca_chain(&ssl_client->ssl_conf, &ssl_client->ca_cert, NULL); - //mbedtls_ssl_conf_verify(&ssl_client->ssl_ctx, my_verify, NULL ); - if (ret < 0) - { - if (ssl_client->_debugCallback) - ssl_client_send_mbedtls_error_cb(ssl_client, ret); - // free the ca_cert in the case parse failed, otherwise, the old ca_cert still in the heap memory, that lead to "out of memory" crash. - mbedtls_x509_crt_free(&ssl_client->ca_cert); - return handle_error(ret); - } - } - else if (pskIdent != NULL && psKey != NULL) - { - if (ssl_client->_debugCallback) - ssl_client_debug_pgm_send_cb(ssl_client, esp_ssl_client_str_12); - log_v("Setting up PSK"); - // convert PSK from hex to binary - if ((strlen(psKey) & 1) != 0 || strlen(psKey) > 2 * MBEDTLS_PSK_MAX_LEN) - { - if (ssl_client->_debugCallback) - ssl_client_debug_pgm_send_cb(ssl_client, esp_ssl_client_str_13); - log_e("pre-shared key not valid hex or too long"); - return -1; - } - - unsigned char psk[MBEDTLS_PSK_MAX_LEN]; - size_t psk_len = strlen(psKey) / 2; - for (int j = 0; j < strlen(psKey); j += 2) - { - char c = psKey[j]; - if (c >= '0' && c <= '9') - c -= '0'; - else if (c >= 'A' && c <= 'F') - c -= 'A' - 10; - else if (c >= 'a' && c <= 'f') - c -= 'a' - 10; - else - return -1; - psk[j / 2] = c << 4; - c = psKey[j + 1]; - if (c >= '0' && c <= '9') - c -= '0'; - else if (c >= 'A' && c <= 'F') - c -= 'A' - 10; - else if (c >= 'a' && c <= 'f') - c -= 'a' - 10; - else - return -1; - psk[j / 2] |= c; - } - // set mbedtls config - if (ssl_client->_debugCallback) - ssl_client_debug_pgm_send_cb(ssl_client, esp_ssl_client_str_14); - - ret = mbedtls_ssl_conf_psk(&ssl_client->ssl_conf, psk, psk_len, - (const unsigned char *)pskIdent, strlen(pskIdent)); - if (ret != 0) - { - if (ssl_client->_debugCallback) - ssl_client_send_mbedtls_error_cb(ssl_client, ret); - - log_e("mbedtls_ssl_conf_psk returned %d", ret); - return handle_error(ret); - } - } - else - { - return -1; - } - - if (!insecure && cli_cert != NULL && cli_key != NULL) - { - - mbedtls_x509_crt_init(&ssl_client->client_cert); - mbedtls_pk_init(&ssl_client->client_key); - - if (ssl_client->_debugCallback) - ssl_client_debug_pgm_send_cb(ssl_client, esp_ssl_client_str_15); - - log_v("Loading CRT cert"); - - ret = mbedtls_x509_crt_parse(&ssl_client->client_cert, (const unsigned char *)cli_cert, strlen(cli_cert) + 1); - if (ret < 0) - { - if (ssl_client->_debugCallback) - ssl_client_send_mbedtls_error_cb(ssl_client, ret); - // free the client_cert in the case parse failed, otherwise, the old client_cert still in the heap memory, that lead to "out of memory" crash. - mbedtls_x509_crt_free(&ssl_client->client_cert); - return handle_error(ret); - } - - if (ssl_client->_debugCallback) - ssl_client_debug_pgm_send_cb(ssl_client, esp_ssl_client_str_16); - - log_v("Loading private key"); - ret = mbedtls_pk_parse_key(&ssl_client->client_key, (const unsigned char *)cli_key, strlen(cli_key) + 1, NULL, 0); - - if (ret != 0) - { - if (ssl_client->_debugCallback) - ssl_client_send_mbedtls_error_cb(ssl_client, ret); - return handle_error(ret); - } - - mbedtls_ssl_conf_own_cert(&ssl_client->ssl_conf, &ssl_client->client_cert, &ssl_client->client_key); - } - - if (ssl_client->_debugCallback) - ssl_client_debug_pgm_send_cb(ssl_client, esp_ssl_client_str_17); - - log_v("Setting hostname for TLS session..."); - - // Hostname set here should match CN in server certificate - if ((ret = mbedtls_ssl_set_hostname(&ssl_client->ssl_ctx, host)) != 0) - { - if (ssl_client->_debugCallback) - ssl_client_send_mbedtls_error_cb(ssl_client, ret); - return handle_error(ret); - } - - mbedtls_ssl_conf_rng(&ssl_client->ssl_conf, mbedtls_ctr_drbg_random, &ssl_client->drbg_ctx); - - if ((ret = mbedtls_ssl_setup(&ssl_client->ssl_ctx, &ssl_client->ssl_conf)) != 0) - { - if (ssl_client->_debugCallback) - ssl_client_send_mbedtls_error_cb(ssl_client, ret); - return handle_error(ret); - } - - mbedtls_ssl_set_bio(&ssl_client->ssl_ctx, &ssl_client->socket, mbedtls_net_send, mbedtls_net_recv, NULL); - - if (ssl_client->_debugCallback) - ssl_client_debug_pgm_send_cb(ssl_client, esp_ssl_client_str_18); - - log_v("Performing the SSL/TLS handshake..."); - unsigned long handshake_start_time = millis(); - while ((ret = mbedtls_ssl_handshake(&ssl_client->ssl_ctx)) != 0) - { - if (ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE) - { - if (ssl_client->_debugCallback) - ssl_client_send_mbedtls_error_cb(ssl_client, ret); - return handle_error(ret); - } - if ((millis() - handshake_start_time) > ssl_client->handshake_timeout) - return -1; - vTaskDelay(2); //2 ticks - } - - if (cli_cert != NULL && cli_key != NULL) - { - log_d("Protocol is %s Ciphersuite is %s", mbedtls_ssl_get_version(&ssl_client->ssl_ctx), mbedtls_ssl_get_ciphersuite(&ssl_client->ssl_ctx)); - if ((ret = mbedtls_ssl_get_record_expansion(&ssl_client->ssl_ctx)) >= 0) - { - log_d("Record expansion is %d", ret); - } - else - { - log_w("Record expansion is unknown (compression)"); - } - } - - if (ssl_client->_debugCallback) - ssl_client_debug_pgm_send_cb(ssl_client, esp_ssl_client_str_19); - - log_v("Verifying peer X.509 certificate..."); - - if ((flags = mbedtls_ssl_get_verify_result(&ssl_client->ssl_ctx)) != 0) - { - memset(buf, 0, sizeof(buf)); - mbedtls_x509_crt_verify_info(buf, sizeof(buf), " ! ", flags); - log_e("Failed to verify peer certificate! verification info: %s", buf); - stop_ssl_socket(ssl_client, rootCABuff, cli_cert, cli_key); //It's not safe continue. - return handle_error(ret); - } - else - { - log_v("Certificate verified."); - } - - if (rootCABuff != NULL) - { - mbedtls_x509_crt_free(&ssl_client->ca_cert); - } - - if (cli_cert != NULL) - { - mbedtls_x509_crt_free(&ssl_client->client_cert); - } - - if (cli_key != NULL) - { - mbedtls_pk_free(&ssl_client->client_key); - } - - log_v("Free internal heap after TLS %u", ESP.getFreeHeap()); - - return ssl_client->socket; -} - -void esp_mail_ssl_client32::stop_ssl_socket(esp_mail_ssl_ctx32 *ssl_client, const char *rootCABuff, const char *cli_cert, const char *cli_key) -{ - if (ssl_client->_debugCallback) - ssl_client_debug_pgm_send_cb(ssl_client, esp_ssl_client_str_22); - - log_v("Cleaning SSL connection."); - - if (ssl_client->socket >= 0) - { - close(ssl_client->socket); - ssl_client->socket = -1; - } - - mbedtls_ssl_free(&ssl_client->ssl_ctx); - mbedtls_ssl_config_free(&ssl_client->ssl_conf); - mbedtls_ctr_drbg_free(&ssl_client->drbg_ctx); - mbedtls_entropy_free(&ssl_client->entropy_ctx); -} - -int esp_mail_ssl_client32::data_to_read(esp_mail_ssl_ctx32 *ssl_client) -{ - int ret, res; - ret = mbedtls_ssl_read(&ssl_client->ssl_ctx, NULL, 0); - //log_e("RET: %i",ret); //for low level debug - res = mbedtls_ssl_get_bytes_avail(&ssl_client->ssl_ctx); - //log_e("RES: %i",res); //for low level debug - if (ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE && ret < 0) - { - if (ssl_client->_debugCallback) - ssl_client_send_mbedtls_error_cb(ssl_client, ret); - return handle_error(ret); - } - - return res; -} - -int esp_mail_ssl_client32::send_ssl_data(esp_mail_ssl_ctx32 *ssl_client, const uint8_t *data, size_t len) -{ - log_v("Writing HTTP request with %d bytes...", len); //for low level debug - int ret = -1; - - while ((ret = mbedtls_ssl_write(&ssl_client->ssl_ctx, data, len)) <= 0) - { - if (ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE && ret < 0) - { - log_v("Handling error %d", ret); //for low level debug - return handle_error(ret); - } - //wait for space to become available - vTaskDelay(2); - } - - return ret; -} - -int esp_mail_ssl_client32::get_ssl_receive(esp_mail_ssl_ctx32 *ssl_client, uint8_t *data, int length) -{ - - //log_d( "Reading HTTP response..."); //for low level debug - int ret = -1; - - ret = mbedtls_ssl_read(&ssl_client->ssl_ctx, data, length); - - //log_v( "%d bytes read", ret); //for low level debug - return ret; -} - -bool esp_mail_ssl_client32::parseHexNibble(char pb, uint8_t *res) -{ - if (pb >= '0' && pb <= '9') - { - *res = (uint8_t)(pb - '0'); - return true; - } - else if (pb >= 'a' && pb <= 'f') - { - *res = (uint8_t)(pb - 'a' + 10); - return true; - } - else if (pb >= 'A' && pb <= 'F') - { - *res = (uint8_t)(pb - 'A' + 10); - return true; - } - return false; -} - -// Compare a name from certificate and domain name, return true if they match -bool esp_mail_ssl_client32::matchName(const std::string &name, const std::string &domainName) -{ - size_t wildcardPos = name.find('*'); - if (wildcardPos == std::string::npos) - { - // Not a wildcard, expect an exact match - return name == domainName; - } - - size_t firstDotPos = name.find('.'); - if (wildcardPos > firstDotPos) - { - // Wildcard is not part of leftmost component of domain name - // Do not attempt to match (rfc6125 6.4.3.1) - return false; - } - if (wildcardPos != 0 || firstDotPos != 1) - { - // Matching of wildcards such as baz*.example.com and b*z.example.com - // is optional. Maybe implement this in the future? - return false; - } - size_t domainNameFirstDotPos = domainName.find('.'); - if (domainNameFirstDotPos == std::string::npos) - { - return false; - } - return domainName.substr(domainNameFirstDotPos) == name.substr(firstDotPos); -} - -// Verifies certificate provided by the peer to match specified SHA256 fingerprint -bool esp_mail_ssl_client32::verify_ssl_fingerprint(esp_mail_ssl_ctx32 *ssl_client, const char *fp, const char *domain_name) -{ - // Convert hex string to byte array - uint8_t fingerprint_local[32]; - int len = strlen(fp); - int pos = 0; - for (size_t i = 0; i < sizeof(fingerprint_local); ++i) - { - while (pos < len && ((fp[pos] == ' ') || (fp[pos] == ':'))) - { - ++pos; - } - if (pos > len - 2) - { - log_d("pos:%d len:%d fingerprint too short", pos, len); - return false; - } - uint8_t high, low; - if (!parseHexNibble(fp[pos], &high) || !parseHexNibble(fp[pos + 1], &low)) - { - log_d("pos:%d len:%d invalid hex sequence: %c%c", pos, len, fp[pos], fp[pos + 1]); - return false; - } - pos += 2; - fingerprint_local[i] = low | (high << 4); - } - - // Get certificate provided by the peer - const mbedtls_x509_crt *crt = mbedtls_ssl_get_peer_cert(&ssl_client->ssl_ctx); - - if (!crt) - { - log_d("could not fetch peer certificate"); - return false; - } - - // Calculate certificate's SHA256 fingerprint - uint8_t fingerprint_remote[32]; - mbedtls_sha256_context sha256_ctx; - mbedtls_sha256_init(&sha256_ctx); - mbedtls_sha256_starts(&sha256_ctx, false); - mbedtls_sha256_update(&sha256_ctx, crt->raw.p, crt->raw.len); - mbedtls_sha256_finish(&sha256_ctx, fingerprint_remote); - - // Check if fingerprints match - if (memcmp(fingerprint_local, fingerprint_remote, 32)) - { - log_d("fingerprint doesn't match"); - return false; - } - - // Additionally check if certificate has domain name if provided - if (domain_name) - return verify_ssl_dn(ssl_client, domain_name); - else - return true; -} - -// Checks if peer certificate has specified domain in CN or SANs -bool esp_mail_ssl_client32::verify_ssl_dn(esp_mail_ssl_ctx32 *ssl_client, const char *domain_name) -{ - log_d("domain name: '%s'", (domain_name) ? domain_name : "(null)"); - std::string domain_name_str(domain_name); - std::transform(domain_name_str.begin(), domain_name_str.end(), domain_name_str.begin(), ::tolower); - - // Get certificate provided by the peer - const mbedtls_x509_crt *crt = mbedtls_ssl_get_peer_cert(&ssl_client->ssl_ctx); - - // Check for domain name in SANs - const mbedtls_x509_sequence *san = &crt->subject_alt_names; - while (san != nullptr) - { - std::string san_str((const char *)san->buf.p, san->buf.len); - std::transform(san_str.begin(), san_str.end(), san_str.begin(), ::tolower); - - if (matchName(san_str, domain_name_str)) - return true; - - log_d("SAN '%s': no match", san_str.c_str()); - - // Fetch next SAN - san = san->next; - } - - // Check for domain name in CN - const mbedtls_asn1_named_data *common_name = &crt->subject; - while (common_name != nullptr) - { - // While iterating through DN objects, check for CN object - if (!MBEDTLS_OID_CMP(MBEDTLS_OID_AT_CN, &common_name->oid)) - { - std::string common_name_str((const char *)common_name->val.p, common_name->val.len); - - if (matchName(common_name_str, domain_name_str)) - return true; - - log_d("CN '%s': not match", common_name_str.c_str()); - } - - // Fetch next DN object - common_name = common_name->next; - } - - return false; -} - -int esp_mail_ssl_client32::_ns_lwip_write(esp_mail_ssl_ctx32 *ssl_client, const char *buf, int bufLen) -{ - return lwip_write(ssl_client->socket, buf, bufLen); -} - -int esp_mail_ssl_client32::_ns_lwip_read(esp_mail_ssl_ctx32 *ssl_client, char *buf, int bufLen) -{ - fd_set readset; - fd_set writeset; - fd_set errset; - - struct timeval tv; - - FD_ZERO(&readset); - FD_SET(ssl_client->socket, &readset); - FD_ZERO(&writeset); - FD_SET(ssl_client->socket, &writeset); - - FD_ZERO(&errset); - FD_SET(ssl_client->socket, &errset); - - tv.tv_sec = 1; - tv.tv_usec = 0; - int ret = lwip_select(ssl_client->socket, &readset, &writeset, &errset, &tv); - - if (ret < 0) - return ret; - - return read(ssl_client->socket, buf, bufLen); -} - -void esp_mail_ssl_client32::ssl_client_send_mbedtls_error_cb(esp_mail_ssl_ctx32 *ssl_client, int errNo) -{ - char *buf = new char[512]; - char *error_buf = new char[100]; - memset(buf, 0, 512); - strcpy_P(buf, esp_ssl_client_str_1); - mbedtls_strerror(errNo, error_buf, 100); - strcat(buf, error_buf); - DebugMsgCallback cb = *ssl_client->_debugCallback; - cb(buf); - delete[] error_buf; - delete[] buf; -} - -void esp_mail_ssl_client32::ssl_client_debug_pgm_send_cb(esp_mail_ssl_ctx32 *ssl_client, PGM_P info) -{ - size_t dbgInfoLen = strlen_P(info) + 10; - char *dbgInfo = new char[dbgInfoLen]; - memset(dbgInfo, 0, dbgInfoLen); - strcpy_P(dbgInfo, info); - DebugMsgCallback cb = *ssl_client->_debugCallback; - cb(dbgInfo); - delete[] dbgInfo; -} - -#endif //ESP32 - -#endif //ESP_MAIL_SSL_CLIENT32_CPP diff --git a/lib/libesp32/lib_mail/src/wcs/esp32/esp_mail_ssl_client32.h b/lib/libesp32/lib_mail/src/wcs/esp32/esp_mail_ssl_client32.h deleted file mode 100644 index b0704d13f..000000000 --- a/lib/libesp32/lib_mail/src/wcs/esp32/esp_mail_ssl_client32.h +++ /dev/null @@ -1,118 +0,0 @@ -/* - *Customized ssl_client.h to support STARTTLS protocol, version 1.0.8 - * - * The MIT License (MIT) - * Copyright (c) 2021 K. Suwatchai (Mobizt) - * - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -/* Provide SSL/TLS functions to ESP32 with Arduino IDE - * by Evandro Copercini - 2017 - Apache 2.0 License - */ - -#ifndef ESP_MAIL_SSL_CLIENT32_H -#define ESP_MAIL_SSL_CLIENT32_H - -#ifdef ESP32 -#include -#include "mbedtls/platform.h" -#include "mbedtls/net.h" -#include "mbedtls/debug.h" -#include "mbedtls/ssl.h" -#include "mbedtls/entropy.h" -#include "mbedtls/ctr_drbg.h" -#include "mbedtls/error.h" - -static const char esp_ssl_client_str_1[] PROGMEM = "! E: "; -static const char esp_ssl_client_str_2[] PROGMEM = "> C: starting socket"; -static const char esp_ssl_client_str_3[] PROGMEM = "! E: opening socket"; -static const char esp_ssl_client_str_4[] PROGMEM = "! E: could not get ip from host"; -static const char esp_ssl_client_str_5[] PROGMEM = "> C: connecting to Server"; -static const char esp_ssl_client_str_6[] PROGMEM = "> C: server connected"; -static const char esp_ssl_client_str_7[] PROGMEM = "! E: connect to Server failed!"; -static const char esp_ssl_client_str_8[] PROGMEM = "< S: "; -static const char esp_ssl_client_str_9[] PROGMEM = "> C: seeding the random number generator"; -static const char esp_ssl_client_str_10[] PROGMEM = "> C: setting up the SSL/TLS structure"; -static const char esp_ssl_client_str_11[] PROGMEM = "> C: loading CA cert"; -static const char esp_ssl_client_str_12[] PROGMEM = "> C: setting up PSK"; -static const char esp_ssl_client_str_13[] PROGMEM = "! E: pre-shared key not valid hex or too long"; -static const char esp_ssl_client_str_14[] PROGMEM = "> C: set mbedtls config"; -static const char esp_ssl_client_str_15[] PROGMEM = "> C: loading CRT cert"; -static const char esp_ssl_client_str_16[] PROGMEM = "> C: loading private key"; -static const char esp_ssl_client_str_17[] PROGMEM = "> C: setting hostname for TLS session"; -static const char esp_ssl_client_str_18[] PROGMEM = "> C: performing the SSL/TLS handshake"; -static const char esp_ssl_client_str_19[] PROGMEM = "> C: verifying peer X.509 certificate"; -static const char esp_ssl_client_str_20[] PROGMEM = "! E: failed to verify peer certificate!"; -static const char esp_ssl_client_str_21[] PROGMEM = "> C: certificate verified"; -static const char esp_ssl_client_str_22[] PROGMEM = "> C: cleaning SSL connection"; -static const char esp_ssl_client_str_23[] PROGMEM = "! E: fingerprint too short"; -static const char esp_ssl_client_str_24[] PROGMEM = "! E: invalid hex sequence"; -static const char esp_ssl_client_str_25[] PROGMEM = "! E: could not fetch peer certificate"; -static const char esp_ssl_client_str_26[] PROGMEM = "! E: fingerprint doesn't match"; -static const char esp_ssl_client_str_27[] PROGMEM = "! E: root certificate, PSK identity or keys are required for secured connection"; -static const char esp_ssl_client_str_28[] PROGMEM = "! W: Skipping SSL Verification. INSECURE!"; - -class esp_mail_ssl_client32 -{ -public: - esp_mail_ssl_client32(){}; - - typedef void (*DebugMsgCallback)(const char *msg); - - typedef struct esp_mail_ssl_ctx32 - { - int socket; - mbedtls_ssl_context ssl_ctx; - mbedtls_ssl_config ssl_conf; - - mbedtls_ctr_drbg_context drbg_ctx; - mbedtls_entropy_context entropy_ctx; - - mbedtls_x509_crt ca_cert; - mbedtls_x509_crt client_cert; - mbedtls_pk_context client_key; - DebugMsgCallback *_debugCallback = NULL; - - unsigned long handshake_timeout; - } esp_mail_ssl_ctx32; - - void ssl_init(esp_mail_ssl_ctx32 *ssl_client); - - int start_socket(esp_mail_ssl_ctx32 *ssl_client, const char *host, uint32_t port, int timeout, const char *rootCABuff, const char *cli_cert, const char *cli_key, const char *pskIdent, const char *psKey, bool insecure); - int start_ssl_client(esp_mail_ssl_ctx32 *ssl_client, const char *host, uint32_t port, int timeout, const char *rootCABuff, const char *cli_cert, const char *cli_key, const char *pskIdent, const char *psKey, bool insecure); - void stop_ssl_socket(esp_mail_ssl_ctx32 *ssl_client, const char *rootCABuff, const char *cli_cert, const char *cli_key); - - int data_to_read(esp_mail_ssl_ctx32 *ssl_client); - int send_ssl_data(esp_mail_ssl_ctx32 *ssl_client, const uint8_t *data, size_t len); - int get_ssl_receive(esp_mail_ssl_ctx32 *ssl_client, uint8_t *data, int length); - bool verify_ssl_fingerprint(esp_mail_ssl_ctx32 *ssl_client, const char *fp, const char *domain_name); - bool verify_ssl_dn(esp_mail_ssl_ctx32 *ssl_client, const char *domain_name); - - int _ns_lwip_write(esp_mail_ssl_ctx32 *ssl_client, const char *buf, int bufLen); - int _ns_lwip_read(esp_mail_ssl_ctx32 *ssl_client, char *buf, int bufLen); - void ssl_client_send_mbedtls_error_cb(esp_mail_ssl_ctx32 *ssl_client, int errNo); - void ssl_client_debug_pgm_send_cb(esp_mail_ssl_ctx32 *ssl_client, PGM_P info); - bool parseHexNibble(char pb, uint8_t *res); - bool matchName(const std::string &name, const std::string &domainName); -}; - -#endif //ESP32 - -#endif //ESP_MAIL_SSL_CLIENT32_H diff --git a/lib/libesp32/lib_mail/src/wcs/esp8266/ESP_Mail_BearSSLHelpers.h b/lib/libesp32/lib_mail/src/wcs/esp8266/ESP_Mail_BearSSLHelpers.h deleted file mode 100644 index 4ee319736..000000000 --- a/lib/libesp32/lib_mail/src/wcs/esp8266/ESP_Mail_BearSSLHelpers.h +++ /dev/null @@ -1,200 +0,0 @@ -/* - Copy of BearSSLHelpers.h - - WiFiClientBearSSL- SSL client/server for esp8266 using BearSSL libraries - - Mostly compatible with Arduino WiFi shield library and standard - WiFiClient/ServerSecure (except for certificate handling). - - Copyright (c) 2018 Earle F. Philhower, III - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef ESP_Mail_BearSSLHelpers_H -#define ESP_Mail_BearSSLHelpers_H - -#ifdef ESP8266 - -#include -#include - -// Internal opaque structures, not needed by user applications -namespace ESP_Mail_brssl -{ - class public_key; - class private_key; -}; // namespace ESP_Mail_brssl - -namespace ESP_Mail -{ - - // Holds either a single public RSA or EC key for use when BearSSL wants a pubkey. - // Copies all associated data so no need to keep input PEM/DER keys. - // All inputs can be either in RAM or PROGMEM. - class PublicKey - { - public: - PublicKey(); - PublicKey(const char *pemKey); - PublicKey(const uint8_t *derKey, size_t derLen); - ~PublicKey(); - - bool parse(const char *pemKey); - bool parse(const uint8_t *derKey, size_t derLen); - - // Accessors for internal use, not needed by apps - bool isRSA() const; - bool isEC() const; - const br_rsa_public_key *getRSA() const; - const br_ec_public_key *getEC() const; - - // Disable the copy constructor, we're pointer based - PublicKey(const PublicKey &that) = delete; - - private: - ESP_Mail_brssl::public_key *_key; - }; - - // Holds either a single private RSA or EC key for use when BearSSL wants a secretkey. - // Copies all associated data so no need to keep input PEM/DER keys. - // All inputs can be either in RAM or PROGMEM. - class PrivateKey - { - public: - PrivateKey(); - PrivateKey(const char *pemKey); - PrivateKey(const uint8_t *derKey, size_t derLen); - ~PrivateKey(); - - bool parse(const char *pemKey); - bool parse(const uint8_t *derKey, size_t derLen); - - // Accessors for internal use, not needed by apps - bool isRSA() const; - bool isEC() const; - const br_rsa_private_key *getRSA() const; - const br_ec_private_key *getEC() const; - - // Disable the copy constructor, we're pointer based - PrivateKey(const PrivateKey &that) = delete; - - private: - ESP_Mail_brssl::private_key *_key; - }; - - // Holds one or more X.509 certificates and associated trust anchors for - // use whenever BearSSL needs a cert or TA. May want to have multiple - // certs for things like a series of trusted CAs (but check the CertStore class - // for a more memory efficient way). - // Copies all associated data so no need to keep input PEM/DER certs. - // All inputs can be either in RAM or PROGMEM. - class ESP_Mail_X509List - { - public: - ESP_Mail_X509List(); - ESP_Mail_X509List(const char *pemCert); - ESP_Mail_X509List(const uint8_t *derCert, size_t derLen); - ~ESP_Mail_X509List(); - - bool append(const char *pemCert); - bool append(const uint8_t *derCert, size_t derLen); - - // Accessors - size_t getCount() const - { - return _count; - } - const br_x509_certificate *getX509Certs() const - { - return _cert; - } - const br_x509_trust_anchor *getTrustAnchors() const - { - return _ta; - } - - // Disable the copy constructor, we're pointer based - ESP_Mail_X509List(const ESP_Mail_X509List &that) = delete; - - private: - size_t _count; - br_x509_certificate *_cert; - br_x509_trust_anchor *_ta; - }; - - // Opaque object which wraps the BearSSL SSL session to make repeated connections - // significantly faster. Completely optional. - class ESP_Mail_WCS; - - class Session - { - friend class ESP_Mail_WCS; - - public: - Session() { memset(&_session, 0, sizeof(_session)); } - - private: - br_ssl_session_parameters *getSession() { return &_session; } - // The actual BearSSL ession information - br_ssl_session_parameters _session; - }; - - // Updater SHA256 hash and signature verification - class HashSHA256 : public UpdaterHashClass - { - public: - virtual void begin() override; - virtual void add(const void *data, uint32_t len) override; - virtual void end() override; - virtual int len() override; - virtual const void *hash() override; - virtual const unsigned char *oid() override; - - private: - br_sha256_context _cc; - unsigned char _sha256[32]; - }; - - class SigningVerifier : public UpdaterVerifyClass - { - public: - virtual uint32_t length() override; - virtual bool verify(UpdaterHashClass *hash, const void *signature, uint32_t signatureLen) override; - - public: - SigningVerifier(PublicKey *pubKey) { _pubKey = pubKey; } - - private: - PublicKey *_pubKey; - }; - /* -// Stack thunked versions of calls -extern "C" { -extern unsigned char *thunk_br_ssl_engine_recvapp_buf( const br_ssl_engine_context *cc, size_t *len); -extern void thunk_br_ssl_engine_recvapp_ack(br_ssl_engine_context *cc, size_t len); -extern unsigned char *thunk_br_ssl_engine_recvrec_buf( const br_ssl_engine_context *cc, size_t *len); -extern void thunk_br_ssl_engine_recvrec_ack(br_ssl_engine_context *cc, size_t len); -extern unsigned char *thunk_br_ssl_engine_sendapp_buf( const br_ssl_engine_context *cc, size_t *len); -extern void thunk_br_ssl_engine_sendapp_ack(br_ssl_engine_context *cc, size_t len); -extern unsigned char *thunk_br_ssl_engine_sendrec_buf( const br_ssl_engine_context *cc, size_t *len); -extern void thunk_br_ssl_engine_sendrec_ack(br_ssl_engine_context *cc, size_t len); -}; -*/ - -}; // namespace ESP_Mail - -#endif /* ESP8266 */ - -#endif /* ESP_Mail_BearSSLHelpers_H */ diff --git a/lib/libesp32/lib_mail/src/wcs/esp8266/ESP_Mail_CertStoreBearSSL.cpp b/lib/libesp32/lib_mail/src/wcs/esp8266/ESP_Mail_CertStoreBearSSL.cpp deleted file mode 100644 index f8efb1155..000000000 --- a/lib/libesp32/lib_mail/src/wcs/esp8266/ESP_Mail_CertStoreBearSSL.cpp +++ /dev/null @@ -1,238 +0,0 @@ -/* - Copy of CertStoreBearSSL.cpp - Library for Arduino ESP8266 - Copyright (c) 2018 Earle F. Philhower, III - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ -#ifndef ESP_Mail_CertStoreBearSSL_CPP -#define ESP_Mail_CertStoreBearSSL_CPP - -#ifdef ESP8266 - -#include "ESP_Mail_CertStoreBearSSL.h" -#include - - -#ifdef DEBUG_ESP_SSL -#define DEBUG_BSSL(fmt, ...) DEBUG_ESP_PORT.printf_P((PGM_P)PSTR( "BSSL:" fmt), ## __VA_ARGS__) -#else -#define DEBUG_BSSL(...) -#endif - -namespace ESP_Mail { - -extern "C" { - // Callback for the x509 decoder - static void dn_append(void *ctx, const void *buf, size_t len) { - br_sha256_context *sha1 = (br_sha256_context*)ctx; - br_sha256_update(sha1, buf, len); - } -} - - -ESP_Mail_CertStore::~ESP_Mail_CertStore() { - free(_indexName); - free(_dataName); -} - -ESP_Mail_CertStore::ESP_Mail_CertInfo ESP_Mail_CertStore::_preprocessCert(uint32_t length, uint32_t offset, const void *raw) { - ESP_Mail_CertStore::ESP_Mail_CertInfo ci; - - // Clear the CertInfo - memset(&ci, 0, sizeof(ci)); - - // Process it using SHA256, same as the hashed_dn - br_x509_decoder_context *ctx = new br_x509_decoder_context; - br_sha256_context *sha256 = new br_sha256_context; - if (!ctx || !sha256) { - DEBUG_BSSL("CertStore::_preprocessCert: OOM\n"); - return ci; - } - - br_sha256_init(sha256); - br_x509_decoder_init(ctx, dn_append, sha256, nullptr, nullptr); - br_x509_decoder_push(ctx, (const void*)raw, length); - - // Copy result to structure - br_sha256_out(sha256, &ci.sha256); - ci.length = length; - ci.offset = offset; - - // Clean up allocated memory - delete sha256; - delete ctx; - - // Return result - return ci; -} - -// The certs.ar file is a UNIX ar format file, concatenating all the -// individual certificates into a single blob in a space-efficient way. -int ESP_Mail_CertStore::initCertStore(FS &fs, const char *indexFileName, const char *dataFileName) { - int count = 0; - uint32_t offset = 0; - - _fs = &fs; - - // In case initCertStore called multiple times, don't leak old filenames - free(_indexName); - free(_dataName); - - // No strdup_P, so manually do it - _indexName = (char *)malloc(strlen_P(indexFileName) + 1); - _dataName = (char *)malloc(strlen_P(dataFileName) + 1); - if (!_indexName || !_dataName) { - free(_indexName); - free(_dataName); - return 0; - } - memcpy_P(_indexName, indexFileName, strlen_P(indexFileName) + 1); - memcpy_P(_dataName, dataFileName, strlen_P(dataFileName) + 1); - - File index = _fs->open(_indexName, "w"); - if (!index) { - return 0; - } - - File data = _fs->open(_dataName, "r"); - if (!data) { - index.close(); - return 0; - } - - uint8_t magic[8]; - if (data.read(magic, sizeof(magic)) != sizeof(magic) || - memcmp(magic, "!\n", sizeof(magic)) ) { - data.close(); - index.close(); - return 0; - } - offset += sizeof(magic); - - while (true) { - uint8_t fileHeader[60]; - // 0..15 = filename in ASCII - // 48...57 = length in decimal ASCII - uint32_t length; - if (data.read(fileHeader, sizeof(fileHeader)) != sizeof(fileHeader)) { - break; - } - offset += sizeof(fileHeader); - fileHeader[58] = 0; - if (1 != sscanf((char *)(fileHeader + 48), "%d", &length) || !length) { - break; - } - - void *raw = malloc(length); - if (!raw) { - break; - } - if (data.read((uint8_t *)raw, length) != length) { - free(raw); - break; - } - - // If the filename starts with "//" then this is a rename file, skip it - if (fileHeader[0] != '/' || fileHeader[1] != '/') { - ESP_Mail_CertStore::ESP_Mail_CertInfo ci = _preprocessCert(length, offset, raw); - if (index.write((uint8_t *)&ci, sizeof(ci)) != (ssize_t)sizeof(ci)) { - free(raw); - break; - } - count++; - } - - offset += length; - free(raw); - if (offset & 1) { - uint8_t x; - data.read(&x, 1); - offset++; - } - } - data.close(); - index.close(); - return count; -} - -void ESP_Mail_CertStore::installCertStore(br_x509_minimal_context *ctx) { - br_x509_minimal_set_dynamic(ctx, (void*)this, findHashedTA, freeHashedTA); -} - -const br_x509_trust_anchor *ESP_Mail_CertStore::findHashedTA(void *ctx, void *hashed_dn, size_t len) { - ESP_Mail_CertStore *cs = static_cast(ctx); - ESP_Mail_CertStore::ESP_Mail_CertInfo ci; - - if (!cs || len != sizeof(ci.sha256) || !cs->_indexName || !cs->_dataName || !cs->_fs) { - return nullptr; - } - - File index = cs->_fs->open(cs->_indexName, "r"); - if (!index) { - return nullptr; - } - - while (index.read((uint8_t *)&ci, sizeof(ci)) == sizeof(ci)) { - if (!memcmp(ci.sha256, hashed_dn, sizeof(ci.sha256))) { - index.close(); - uint8_t *der = (uint8_t*)malloc(ci.length); - if (!der) { - return nullptr; - } - File data = cs->_fs->open(cs->_dataName, "r"); - if (!data) { - free(der); - return nullptr; - } - if (!data.seek(ci.offset, SeekSet)) { - data.close(); - free(der); - return nullptr; - } - if (data.read((uint8_t *)der, ci.length) != ci.length) { - free(der); - return nullptr; - } - data.close(); - cs->_x509 = new ESP_Mail_X509List(der, ci.length); - free(der); - if (!cs->_x509) { - DEBUG_BSSL("CertStore::findHashedTA: OOM\n"); - return nullptr; - } - - br_x509_trust_anchor *ta = (br_x509_trust_anchor*)cs->_x509->getTrustAnchors(); - memcpy(ta->dn.data, ci.sha256, sizeof(ci.sha256)); - ta->dn.len = sizeof(ci.sha256); - - return ta; - } - } - index.close(); - return nullptr; -} - -void ESP_Mail_CertStore::freeHashedTA(void *ctx, const br_x509_trust_anchor *ta) { - ESP_Mail_CertStore *cs = static_cast(ctx); - (void) ta; // Unused - delete cs->_x509; - cs->_x509 = nullptr; -} - -} - -#endif /* ESP8266 */ - -#endif /* ESP_Mail_CertStoreBearSSL_CPP */ \ No newline at end of file diff --git a/lib/libesp32/lib_mail/src/wcs/esp8266/ESP_Mail_HTTPClient.cpp b/lib/libesp32/lib_mail/src/wcs/esp8266/ESP_Mail_HTTPClient.cpp deleted file mode 100644 index b1fdbff5f..000000000 --- a/lib/libesp32/lib_mail/src/wcs/esp8266/ESP_Mail_HTTPClient.cpp +++ /dev/null @@ -1,261 +0,0 @@ -/* - * HTTP Client for ESP8266 wrapper v1.0.3 - * - * The MIT License (MIT) - * Copyright (c) 2021 K. Suwatchai (Mobizt) - * - * - * Permission is hereby granted, free of charge, to any person returning a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -#ifndef ESP_Mail_HTTPClient_CPP -#define ESP_Mail_HTTPClient_CPP - -#ifdef ESP8266 - -#include "ESP_Mail_HTTPClient.h" - -ESP_Mail_HTTPClient::ESP_Mail_HTTPClient() -{ -} - -ESP_Mail_HTTPClient::~ESP_Mail_HTTPClient() -{ - if (_wcs) - { - _wcs->stop(); - _wcs.reset(nullptr); - _wcs.release(); - } - - std::string().swap(_host); - std::string().swap(_caCertFile); - _cacert.reset(new char); - _cacert = nullptr; -} - -bool ESP_Mail_HTTPClient::begin(const char *host, uint16_t port) -{ - if (strcmp(_host.c_str(), host) != 0) - mflnChecked = false; - - _host = host; - _port = port; - - //probe for fragmentation support at the specified size - if (!mflnChecked) - { - fragmentable = _wcs->probeMaxFragmentLength(_host.c_str(), _port, chunkSize); - if (fragmentable) - { - _bsslRxSize = chunkSize; - _bsslTxSize = chunkSize; - _wcs->setBufferSizes(_bsslRxSize, _bsslTxSize); - } - mflnChecked = true; - } - - if (!fragmentable) - _wcs->setBufferSizes(maxRXBufSize / rxBufDivider, maxTXBufSize / txBufDivider); - - return true; -} - -bool ESP_Mail_HTTPClient::connected() -{ - if (_wcs) - { - if (_secured) - return _wcs->connected(); - else - return _wcs->_ns_connected(); - } - - return false; -} - -bool ESP_Mail_HTTPClient::send(const char *header) -{ - if (!connected()) - return false; - if (_secured) - return (_wcs->write((uint8_t *)header, strlen(header)) == strlen(header)); - else - return (_wcs->_ns_write((uint8_t *)header, strlen(header)) == strlen(header)); -} - -int ESP_Mail_HTTPClient::send(const char *header, const char *payload) -{ - size_t size = strlen(payload); - if (strlen(header) > 0) - { - if (!connect(_secured)) - { - return ESP_MAIL_ERROR_HTTPC_ERROR_CONNECTION_REFUSED; - } - - if (!send(header)) - { - return ESP_MAIL_ERROR_HTTPC_ERROR_SEND_HEADER_FAILED; - } - } - - if (size > 0) - { - if (_secured) - { - if (_wcs->write((uint8_t *)&payload[0], size) != size) - return ESP_MAIL_ERROR_HTTPC_ERROR_SEND_PAYLOAD_FAILED; - } - else - { - if (_wcs->_ns_write((uint8_t *)&payload[0], size) != size) - return ESP_MAIL_ERROR_HTTPC_ERROR_SEND_PAYLOAD_FAILED; - } - } - - return 0; -} - -WiFiClient *ESP_Mail_HTTPClient::stream(void) -{ - if (connected()) - return _wcs.get(); - return nullptr; -} - -ESP_Mail::ESP_Mail_WCS *ESP_Mail_HTTPClient::_stream(void) -{ - if (connected()) - return _wcs.get(); - return nullptr; -} - -size_t ESP_Mail_HTTPClient::_ns_print(const char *buf) -{ - size_t size = strlen(buf); - return _wcs->_ns_write((uint8_t *)&buf[0], size); -} - -size_t ESP_Mail_HTTPClient::_ns_println(const char *buf) -{ - size_t size = strlen(buf); - size_t wr = _wcs->_ns_write((uint8_t *)&buf[0], size); - std::string s = "\r\n"; - wr += _wcs->_ns_write((uint8_t *)s.c_str(), s.length()); - return wr; -} - -bool ESP_Mail_HTTPClient::connect(bool secured) -{ - _secured = secured; - - if (connected()) - { - if (_secured) - { - while (_wcs->available() > 0) - _wcs->read(); - } - else - { - while (_wcs->_ns_available() > 0) - _wcs->_ns_read(); - } - return true; - } - - _wcs->setStartTLS(!_secured); - if (!_wcs->connect(_host.c_str(), _port)) - return false; - - return connected(); -} - - -void ESP_Mail_HTTPClient::setCACert(const char *caCert) -{ - -#ifndef USING_AXTLS - _wcs->setBufferSizes(_bsslRxSize, _bsslTxSize); -#endif - - if (caCert) - { -#ifndef USING_AXTLS - _wcs->setTrustAnchors(new ESP_Mail::ESP_Mail_X509List(caCert)); -#else - _wcs->setCACert_P(caCert, strlen_P(caCert)); -#endif - _certType = 1; - } - else - { -#ifndef USING_AXTLS - _wcs->setInsecure(); -#endif - _certType = 0; - } - - _wcs->setNoDelay(true); -} - -void ESP_Mail_HTTPClient::setCertFile(const char *caCertFile, esp_mail_file_storage_type storageType, uint8_t sdPin) -{ - -#ifndef USING_AXTLS - _sdPin = sdPin; - _wcs->setBufferSizes(_bsslRxSize, _bsslTxSize); - - if (_clockReady && strlen(caCertFile) > 0) - { - - fs::File f; - if (storageType == esp_mail_file_storage_type_flash) - { - ESP_MAIL_FLASH_FS.begin(); - if (ESP_MAIL_FLASH_FS.exists(caCertFile)) - f = ESP_MAIL_FLASH_FS.open(caCertFile, "r"); - } - else if (storageType == esp_mail_file_storage_type_sd) - { - ESP_MAIL_SD_FS.begin(_sdPin); - if (ESP_MAIL_SD_FS.exists(caCertFile)) - f = ESP_MAIL_SD_FS.open(caCertFile, FILE_READ); - } - - if (f) - { - size_t len = f.size(); - uint8_t *der = new uint8_t[len]; - if (f.available()) - f.read(der, len); - f.close(); - _wcs->setTrustAnchors(new ESP_Mail::ESP_Mail_X509List(der, len)); - delete[] der; - } - _certType = 2; - } -#endif - - _wcs->setNoDelay(true); -} - -#endif /* ESP8266 */ - -#endif /* ESP_Mail_HTTPClient_CPP */ \ No newline at end of file diff --git a/lib/libesp32/lib_mail/src/wcs/esp8266/ESP_Mail_HTTPClient.h b/lib/libesp32/lib_mail/src/wcs/esp8266/ESP_Mail_HTTPClient.h deleted file mode 100644 index 883158a8d..000000000 --- a/lib/libesp32/lib_mail/src/wcs/esp8266/ESP_Mail_HTTPClient.h +++ /dev/null @@ -1,149 +0,0 @@ -/* - * HTTP Client for ESP8266 wrapper v1.0.3 - * - * The MIT License (MIT) - * Copyright (c) 2021 K. Suwatchai (Mobizt) - * - * - * Permission is hereby granted, free of charge, to any person returning a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -#ifndef ESP_Mail_HTTPClient_H -#define ESP_Mail_HTTPClient_H - -#ifdef ESP8266 - -//ARDUINO_ESP8266_GIT_VER -//2.6.2 0xbc204a9b -//2.6.1 0x482516e3 -//2.6.0 0x643ec203 -//2.5.2 0x8b899c12 -//2.5.1 0xac02aff5 -//2.5.0 0x951aeffa -//2.5.0-beta3 0x21db8fc9 -//2.5.0-beta2 0x0fd86a07 -//2.5.0-beta1 0x9c1e03a1 -//2.4.2 0xbb28d4a3 -//2.4.1 0x614f7c32 -//2.4.0 0x4ceabea9 -//2.4.0-rc2 0x0c897c37 -//2.4.0-rc1 0xf6d232f1 - -#include -#include -#include -#include - -#include "SDK_Version_Common.h" - -#ifndef ARDUINO_ESP8266_GIT_VER -#error Your ESP8266 Arduino Core SDK is outdated, please update. From Arduino IDE go to Boards Manager and search 'esp8266' then select the latest version. -#endif - -#include - -#if ARDUINO_ESP8266_GIT_VER != 0xf6d232f1 && ARDUINO_ESP8266_GIT_VER != 0x0c897c37 && ARDUINO_ESP8266_GIT_VER != 0x4ceabea9 && ARDUINO_ESP8266_GIT_VER != 0x614f7c32 && ARDUINO_ESP8266_GIT_VER != 0xbb28d4a3 -#include "ESP_Mail_WCS.h" -#include "ESP_Mail_BearSSLHelpers.h" -#define ESP_MAIL_SSL_CLIENT ESP_Mail::ESP_Mail_WCS -#else -#error Please update the ESP8266 Arduino Core SDK to latest version. -#endif - -#define FS_NO_GLOBALS -#include -#include -#include "ESP_Mail_FS.h" -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" -#define ESP_MAIL_FLASH_FS ESP_Mail_DEFAULT_FLASH_FS -#define ESP_MAIL_SD_FS ESP_Mail_DEFAULT_SD_FS - -#if __has_include() || __has_include() -#error WiFi UART bridge was not supported. -#endif - -#define ESP_MAIL_ERROR_HTTPC_ERROR_CONNECTION_REFUSED (-1) -#define ESP_MAIL_ERROR_HTTPC_ERROR_SEND_HEADER_FAILED (-2) -#define ESP_MAIL_ERROR_HTTPC_ERROR_SEND_PAYLOAD_FAILED (-3) -#define ESP_MAIL_DEFAULT_TCP_TIMEOUT_SEC 30 - -enum esp_mail_file_storage_type -{ - esp_mail_file_storage_type_none, - esp_mail_file_storage_type_flash, - esp_mail_file_storage_type_sd, - esp_mail_file_storage_type_univ -}; - -class ESP_Mail_HTTPClient -{ - -public: - ESP_Mail_HTTPClient(); - ~ESP_Mail_HTTPClient(); - - bool begin(const char *host, uint16_t port); - - bool connected(void); - - int send(const char *header, const char *payload); - - bool send(const char *header); - - WiFiClient *stream(void); - - ESP_Mail::ESP_Mail_WCS *_stream(void); - - size_t _ns_print(const char *buf); - - size_t _ns_println(const char *buf); - - void setCACert(const char *caCert); - void setCertFile(const char *caCertFile, esp_mail_file_storage_type storageType, uint8_t sdPin); - bool connect(bool secured); - - int _certType = -1; - std::string _caCertFile = ""; - esp_mail_file_storage_type _caCertFileStoreageType = esp_mail_file_storage_type::esp_mail_file_storage_type_none; - uint16_t tcpTimeout = 40000; - - uint8_t _sdPin = 15; - bool _clockReady = false; - uint16_t _bsslRxSize = 1024; - uint16_t _bsslTxSize = 1024; - bool fragmentable = false; - int chunkSize = 1024; - int maxRXBufSize = 16384; //SSL full supported 16 kB - int maxTXBufSize = 16384; - bool mflnChecked = false; - int rxBufDivider = maxRXBufSize / chunkSize; - int txBufDivider = maxRXBufSize / chunkSize; - ; - -private: - std::unique_ptr _wcs = std::unique_ptr(new ESP_MAIL_SSL_CLIENT()); - std::unique_ptr _cacert; - std::string _host = ""; - uint16_t _port = 0; - bool _secured = true; -}; - -#endif /* ESP8266 */ - -#endif /* ESP_Mail_HTTPClient_H */ \ No newline at end of file diff --git a/lib/libesp32/lib_mail/src/wcs/esp8266/ESP_Mail_WCS.cpp b/lib/libesp32/lib_mail/src/wcs/esp8266/ESP_Mail_WCS.cpp deleted file mode 100644 index d419a9249..000000000 --- a/lib/libesp32/lib_mail/src/wcs/esp8266/ESP_Mail_WCS.cpp +++ /dev/null @@ -1,2139 +0,0 @@ -/* - Customized version of WiFiClientSecure.cpp v1.0.1 - - WiFiClientBearSSL- SSL client/server for esp8266 using BearSSL libraries - - Mostly compatible with Arduino WiFi shield library and standard - WiFiClient/ServerSecure (except for certificate handling). - - Copyright (c) 2018 Earle F. Philhower, III - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef ESP_Mail_WCS_CPP -#define ESP_Mail_WCS_CPP - -#ifdef ESP8266 - -#define LWIP_INTERNAL - -#include -#include -#include - -extern "C" -{ -#include -#include -} -#include -#include -#include -#include -#include "ESP_Mail_WCS.h" -#include -#include -#include -#include -#include -#include -#include -#ifdef ESP8266 - #include -#endif -#include - -#if !CORE_MOCK - -// The BearSSL thunks in use for now -#define br_ssl_engine_recvapp_ack thunk_br_ssl_engine_recvapp_ack -#define br_ssl_engine_recvapp_buf thunk_br_ssl_engine_recvapp_buf -#define br_ssl_engine_recvrec_ack thunk_br_ssl_engine_recvrec_ack -#define br_ssl_engine_recvrec_buf thunk_br_ssl_engine_recvrec_buf -#define br_ssl_engine_sendapp_ack thunk_br_ssl_engine_sendapp_ack -#define br_ssl_engine_sendapp_buf thunk_br_ssl_engine_sendapp_buf -#define br_ssl_engine_sendrec_ack thunk_br_ssl_engine_sendrec_ack -#define br_ssl_engine_sendrec_buf thunk_br_ssl_engine_sendrec_buf - -#endif - -#ifdef DEBUG_ESP_SSL -#define DEBUG_BSSL(fmt, ...) DEBUG_ESP_PORT.printf_P((PGM_P)PSTR("BSSL:" fmt), ##__VA_ARGS__) -#else -#define DEBUG_BSSL(...) -#endif - -namespace ESP_Mail -{ - - void ESP_Mail_WCS::_clear() - { - // TLS handshake may take more than the 5 second default timeout - _timeout = 15000; - - _sc = nullptr; - _sc_svr = nullptr; - _eng = nullptr; - _x509_minimal = nullptr; - _x509_insecure = nullptr; - _x509_knownkey = nullptr; - _iobuf_in = nullptr; - _iobuf_out = nullptr; - _now = 0; // You can override or ensure time() is correct w/configTime - _ta = nullptr; - setBufferSizes(16384, 512); // Minimum safe - _handshake_done = false; - _recvapp_buf = nullptr; - _recvapp_len = 0; - _oom_err = false; - _session = nullptr; - _cipher_list = nullptr; - _cipher_cnt = 0; - } - - void ESP_Mail_WCS::_clearAuthenticationSettings() - { - _use_insecure = false; - _use_fingerprint = false; - _use_self_signed = false; - _knownkey = nullptr; - _sk = nullptr; - _ta = nullptr; - _axtls_ta = nullptr; - _axtls_chain = nullptr; - _axtls_sk = nullptr; - } - - ESP_Mail_WCS::ESP_Mail_WCS() : WiFiClient() - { - _clear(); - _clearAuthenticationSettings(); - _certStore = nullptr; // Don't want to remove cert store on a clear, should be long lived - stack_thunk_add_ref(); - } - - ESP_Mail_WCS::ESP_Mail_WCS(const ESP_Mail_WCS &rhs) : WiFiClient(rhs) - { - *this = rhs; - stack_thunk_add_ref(); - } - - ESP_Mail_WCS::~ESP_Mail_WCS() - { - if (_client) - { - _client->unref(); - _client = nullptr; - } - _cipher_list = nullptr; // std::shared will free if last reference - _freeSSL(); - stack_thunk_del_ref(); - // Clean up any dangling axtls compat structures, if needed - _axtls_ta = nullptr; - _axtls_chain = nullptr; - _axtls_sk = nullptr; - } - - ESP_Mail_WCS::ESP_Mail_WCS(ClientContext *client, - const ESP_Mail_X509List *chain, const PrivateKey *sk, - int iobuf_in_size, int iobuf_out_size, const ESP_Mail_X509List *client_CA_ta) - { - _clear(); - _clearAuthenticationSettings(); - stack_thunk_add_ref(); - _iobuf_in_size = iobuf_in_size; - _iobuf_out_size = iobuf_out_size; - _client = client; - _client->ref(); - if (!_connectSSLServerRSA(chain, sk, client_CA_ta)) - { - _client->unref(); - _client = nullptr; - _clear(); - } - } - - ESP_Mail_WCS::ESP_Mail_WCS(ClientContext *client, - const ESP_Mail_X509List *chain, - unsigned cert_issuer_key_type, const PrivateKey *sk, - int iobuf_in_size, int iobuf_out_size, const ESP_Mail_X509List *client_CA_ta) - { - _clear(); - _clearAuthenticationSettings(); - stack_thunk_add_ref(); - _iobuf_in_size = iobuf_in_size; - _iobuf_out_size = iobuf_out_size; - _client = client; - _client->ref(); - if (!_connectSSLServerEC(chain, cert_issuer_key_type, sk, client_CA_ta)) - { - _client->unref(); - _client = nullptr; - _clear(); - } - } - - void ESP_Mail_WCS::setClientRSACert(const ESP_Mail_X509List *chain, const PrivateKey *sk) - { - _chain = chain; - _sk = sk; - } - - void ESP_Mail_WCS::setClientECCert(const ESP_Mail_X509List *chain, - const PrivateKey *sk, unsigned allowed_usages, unsigned cert_issuer_key_type) - { - _chain = chain; - _sk = sk; - _allowed_usages = allowed_usages; - _cert_issuer_key_type = cert_issuer_key_type; - } - - void ESP_Mail_WCS::setBufferSizes(int recv, int xmit) - { - // Following constants taken from bearssl/src/ssl/ssl_engine.c (not exported unfortunately) - const int MAX_OUT_OVERHEAD = 85; - const int MAX_IN_OVERHEAD = 325; - - // The data buffers must be between 512B and 16KB - recv = std::max(512, std::min(16384, recv)); - xmit = std::max(512, std::min(16384, xmit)); - - // Add in overhead for SSL protocol - recv += MAX_IN_OVERHEAD; - xmit += MAX_OUT_OVERHEAD; - _iobuf_in_size = recv; - _iobuf_out_size = xmit; - } - - bool ESP_Mail_WCS::stop(unsigned int maxWaitMs) - { - bool ret = WiFiClient::stop(maxWaitMs); // calls our virtual flush() - // Only if we've already connected, store session params and clear the connection options - if (_handshake_done) - { - if (_session) - { - br_ssl_engine_get_session_parameters(_eng, _session->getSession()); - } - } - _freeSSL(); - return ret; - } - - bool ESP_Mail_WCS::flush(unsigned int maxWaitMs) - { - (void)_run_until(BR_SSL_SENDAPP); - return WiFiClient::flush(maxWaitMs); - } - - int ESP_Mail_WCS::connect(IPAddress ip, uint16_t port) - { - if (!WiFiClient::connect(ip, port)) - { - return 0; - } - return _connectSSL(nullptr); - } - - int ESP_Mail_WCS::connect(const char *name, uint16_t port) - { - IPAddress remote_addr; - if (!WiFi.hostByName(name, remote_addr)) - { - DEBUG_BSSL("connect: Name loopup failure\n"); - return 0; - } - if (!WiFiClient::connect(remote_addr, port)) - { - DEBUG_BSSL("connect: Unable to connect TCP socket\n"); - return 0; - } - _host_name = name; - if (!_secured) - return true; - return _connectSSL(name); - } - - int ESP_Mail_WCS::connect(const String &host, uint16_t port) - { - return connect(host.c_str(), port); - } - - void ESP_Mail_WCS::_freeSSL() - { - // These are smart pointers and will free if refcnt==0 - _sc = nullptr; - _sc_svr = nullptr; - _x509_minimal = nullptr; - _x509_insecure = nullptr; - _x509_knownkey = nullptr; - _iobuf_in = nullptr; - _iobuf_out = nullptr; - // Reset non-allocated ptrs (pointing to bits potentially free'd above) - _recvapp_buf = nullptr; - _recvapp_len = 0; - // This connection is toast - _handshake_done = false; - _timeout = 15000; - } - - bool ESP_Mail_WCS::_clientConnected() - { - return (_client && _client->state() == ESTABLISHED); - } - - uint8_t ESP_Mail_WCS::connected() - { - if (available() || (_clientConnected() && _handshake_done && (br_ssl_engine_current_state(_eng) != BR_SSL_CLOSED))) - { - return true; - } - return false; - } - - size_t ESP_Mail_WCS::_write(const uint8_t *buf, size_t size, bool pmem) - { - size_t sent_bytes = 0; - - if (!connected() || !size || !_handshake_done) - { - return 0; - } - - do - { - // Ensure we yield if we need multiple fragments to avoid WDT - if (sent_bytes) - { - optimistic_yield(1000); - } - - // Get BearSSL to a state where we can send - if (_run_until(BR_SSL_SENDAPP) < 0) - { - break; - } - - if (br_ssl_engine_current_state(_eng) & BR_SSL_SENDAPP) - { - size_t sendapp_len; - unsigned char *sendapp_buf = br_ssl_engine_sendapp_buf(_eng, &sendapp_len); - int to_send = size > sendapp_len ? sendapp_len : size; - if (pmem) - { - memcpy_P(sendapp_buf, buf, to_send); - } - else - { - memcpy(sendapp_buf, buf, to_send); - } - br_ssl_engine_sendapp_ack(_eng, to_send); - br_ssl_engine_flush(_eng, 0); - flush(); - buf += to_send; - sent_bytes += to_send; - size -= to_send; - } - else - { - break; - } - } while (size); - - return sent_bytes; - } - - size_t ESP_Mail_WCS::write(const uint8_t *buf, size_t size) - { - return _write(buf, size, false); - } - - size_t ESP_Mail_WCS::write_P(PGM_P buf, size_t size) - { - return _write((const uint8_t *)buf, size, true); - } - - // We have to manually read and send individual chunks. - size_t ESP_Mail_WCS::write(Stream &stream) - { - size_t totalSent = 0; - size_t countRead; - size_t countSent; - - if (!connected() || !_handshake_done) - { - DEBUG_BSSL("write: Connect/handshake not completed yet\n"); - return 0; - } - - do - { - uint8_t temp[256]; // Temporary chunk size same as ClientContext - countSent = 0; - countRead = stream.readBytes(temp, sizeof(temp)); - if (countRead) - { - countSent = _write((const uint8_t *)temp, countRead, true); - totalSent += countSent; - } - yield(); // Feed the WDT - } while ((countSent == countRead) && (countSent > 0)); - return totalSent; - } - - int ESP_Mail_WCS::read(uint8_t *buf, size_t size) - { - if (!ctx_present() || !_handshake_done) - { - return -1; - } - - int avail = available(); - bool conn = connected(); - if (!avail && conn) - { - return 0; // We're still connected, but nothing to read - } - if (!avail && !conn) - { - DEBUG_BSSL("read: Not connected, none left available\n"); - return -1; - } - - if (avail) - { - // Take data from the recvapp buffer - int to_copy = _recvapp_len < size ? _recvapp_len : size; - memcpy(buf, _recvapp_buf, to_copy); - br_ssl_engine_recvapp_ack(_eng, to_copy); - _recvapp_buf = nullptr; - _recvapp_len = 0; - return to_copy; - } - - if (!conn) - { - DEBUG_BSSL("read: Not connected\n"); - return -1; - } - return 0; // If we're connected, no error but no read. - } - - int ESP_Mail_WCS::read() - { - uint8_t c; - if (1 == read(&c, 1)) - { - return c; - } - DEBUG_BSSL("read: failed\n"); - return -1; - } - - int ESP_Mail_WCS::available() - { - if (_recvapp_buf) - { - return _recvapp_len; // Anything from last call? - } - _recvapp_buf = nullptr; - _recvapp_len = 0; - if (!ctx_present() || _run_until(BR_SSL_RECVAPP, false) < 0) - { - return 0; - } - int st = br_ssl_engine_current_state(_eng); - if (st == BR_SSL_CLOSED) - { - return 0; // Nothing leftover, SSL is closed - } - if (st & BR_SSL_RECVAPP) - { - _recvapp_buf = br_ssl_engine_recvapp_buf(_eng, &_recvapp_len); - return _recvapp_len; - } - - return 0; - } - - int ESP_Mail_WCS::peek() - { - if (!ctx_present() || !available()) - { - DEBUG_BSSL("peek: Not connected, none left available\n"); - return -1; - } - if (_recvapp_buf && _recvapp_len) - { - return _recvapp_buf[0]; - } - DEBUG_BSSL("peek: No data left\n"); - return -1; - } - - size_t ESP_Mail_WCS::peekBytes(uint8_t *buffer, size_t length) - { - size_t to_copy = 0; - if (!ctx_present()) - { - DEBUG_BSSL("peekBytes: Not connected\n"); - return 0; - } - - _startMillis = millis(); - while ((available() < (int)length) && ((millis() - _startMillis) < 5000)) - { - yield(); - } - - to_copy = _recvapp_len < length ? _recvapp_len : length; - memcpy(buffer, _recvapp_buf, to_copy); - return to_copy; - } - - /* --- Copied almost verbatim from BEARSSL SSL_IO.C --- - Run the engine, until the specified target state is achieved, or - an error occurs. The target state is SENDAPP, RECVAPP, or the - combination of both (the combination matches either). When a match is - achieved, this function returns 0. On error, it returns -1. -*/ - int ESP_Mail_WCS::_run_until(unsigned target, bool blocking) - { - if (!ctx_present()) - { - DEBUG_BSSL("_run_until: Not connected\n"); - return -1; - } - - esp8266::polledTimeout::oneShotMs loopTimeout(_timeout); - - for (int no_work = 0; blocking || no_work < 2;) - { - optimistic_yield(100); - - if (loopTimeout) - { - DEBUG_BSSL("_run_until: Timeout\n"); - return -1; - } - - int state; - state = br_ssl_engine_current_state(_eng); - if (state & BR_SSL_CLOSED) - { - return -1; - } - - if (!(_client->state() == ESTABLISHED) && !WiFiClient::available()) - { - return (state & target) ? 0 : -1; - } - - /* - If there is some record data to send, do it. This takes - precedence over everything else. - */ - if (state & BR_SSL_SENDREC) - { - unsigned char *buf; - size_t len; - int wlen; - size_t availForWrite; - - buf = br_ssl_engine_sendrec_buf(_eng, &len); - availForWrite = WiFiClient::availableForWrite(); - - if (!blocking && len > availForWrite) - { - /* - writes on WiFiClient will block if len > availableForWrite() - this is needed to prevent available() calls from blocking - on dropped connections - */ - len = availForWrite; - } - wlen = WiFiClient::write(buf, len); - if (wlen <= 0) - { - /* - If we received a close_notify and we - still send something, then we have our - own response close_notify to send, and - the peer is allowed by RFC 5246 not to - wait for it. - */ - return -1; - } - if (wlen > 0) - { - br_ssl_engine_sendrec_ack(_eng, wlen); - } - no_work = 0; - continue; - } - - /* - If we reached our target, then we are finished. - */ - if (state & target) - { - return 0; - } - - /* - If some application data must be read, and we did not - exit, then this means that we are trying to write data, - and that's not possible until the application data is - read. This may happen if using a shared in/out buffer, - and the underlying protocol is not strictly half-duplex. - This is unrecoverable here, so we report an error. - */ - if (state & BR_SSL_RECVAPP) - { - DEBUG_BSSL("_run_until: Fatal protocol state\n"); - return -1; - } - - /* - If we reached that point, then either we are trying - to read data and there is some, or the engine is stuck - until a new record is obtained. - */ - if (state & BR_SSL_RECVREC) - { - if (WiFiClient::available()) - { - unsigned char *buf; - size_t len; - int rlen; - - buf = br_ssl_engine_recvrec_buf(_eng, &len); - rlen = WiFiClient::read(buf, len); - if (rlen < 0) - { - return -1; - } - if (rlen > 0) - { - br_ssl_engine_recvrec_ack(_eng, rlen); - } - no_work = 0; - continue; - } - } - - /* - We can reach that point if the target RECVAPP, and - the state contains SENDAPP only. This may happen with - a shared in/out buffer. In that case, we must flush - the buffered data to "make room" for a new incoming - record. - */ - br_ssl_engine_flush(_eng, 0); - - no_work++; // We didn't actually advance here - } - // We only get here if we ran through the loop without getting anything done - return -1; - } - - bool ESP_Mail_WCS::_wait_for_handshake() - { - _handshake_done = false; - while (!_handshake_done && _clientConnected()) - { - int ret = _run_until(BR_SSL_SENDAPP); - if (ret < 0) - { - DEBUG_BSSL("_wait_for_handshake: failed\n"); - break; - } - if (br_ssl_engine_current_state(_eng) & BR_SSL_SENDAPP) - { - _handshake_done = true; - } - optimistic_yield(1000); - } - return _handshake_done; - } - - static uint8_t htoi(unsigned char c) - { - if (c >= '0' && c <= '9') - return c - '0'; - else if (c >= 'A' && c <= 'F') - return 10 + c - 'A'; - else if (c >= 'a' && c <= 'f') - return 10 + c - 'a'; - else - return 255; - } - - // Set a fingerprint by parsing an ASCII string - bool ESP_Mail_WCS::setFingerprint(const char *fpStr) - { - int idx = 0; - uint8_t c, d; - uint8_t fp[20]; - - while (idx < 20) - { - c = pgm_read_byte(fpStr++); - if (!c) - break; // String ended, done processing - d = pgm_read_byte(fpStr++); - if (!d) - { - DEBUG_BSSL("setFingerprint: FP too short\n"); - return false; // Only half of the last hex digit, error - } - c = htoi(c); - d = htoi(d); - if ((c > 15) || (d > 15)) - { - DEBUG_BSSL("setFingerprint: Invalid char\n"); - return false; // Error in one of the hex characters - } - fp[idx++] = (c << 4) | d; - - // Skip 0 or more spaces or colons - while (pgm_read_byte(fpStr) && (pgm_read_byte(fpStr) == ' ' || pgm_read_byte(fpStr) == ':')) - { - fpStr++; - } - } - if ((idx != 20) || pgm_read_byte(fpStr)) - { - DEBUG_BSSL("setFingerprint: Garbage at end of fp\n"); - return false; // Garbage at EOL or we didn't have enough hex digits - } - return setFingerprint(fp); - } - - extern "C" - { - - // BearSSL doesn't define a true insecure decoder, so we make one ourselves - // from the simple parser. It generates the issuer and subject hashes and - // the SHA1 fingerprint, only one (or none!) of which will be used to - // "verify" the certificate. - - // Private x509 decoder state - struct br_x509_insecure_context - { - const br_x509_class *vtable; - bool done_cert; - const uint8_t *match_fingerprint; - br_sha1_context sha1_cert; - bool allow_self_signed; - br_sha256_context sha256_subject; - br_sha256_context sha256_issuer; - br_x509_decoder_context ctx; - }; - - // Callback for the x509_minimal subject DN - static void insecure_subject_dn_append(void *ctx, const void *buf, size_t len) - { - br_x509_insecure_context *xc = (br_x509_insecure_context *)ctx; - br_sha256_update(&xc->sha256_subject, buf, len); - } - - // Callback for the x509_minimal issuer DN - static void insecure_issuer_dn_append(void *ctx, const void *buf, size_t len) - { - br_x509_insecure_context *xc = (br_x509_insecure_context *)ctx; - br_sha256_update(&xc->sha256_issuer, buf, len); - } - - // Callback on the first byte of any certificate - static void insecure_start_chain(const br_x509_class **ctx, const char *server_name) - { - br_x509_insecure_context *xc = (br_x509_insecure_context *)ctx; - br_x509_decoder_init(&xc->ctx, insecure_subject_dn_append, xc, insecure_issuer_dn_append, xc); - xc->done_cert = false; - br_sha1_init(&xc->sha1_cert); - br_sha256_init(&xc->sha256_subject); - br_sha256_init(&xc->sha256_issuer); - (void)server_name; - } - - // Callback for each certificate present in the chain (but only operates - // on the first one by design). - static void insecure_start_cert(const br_x509_class **ctx, uint32_t length) - { - (void)ctx; - (void)length; - } - - // Callback for each byte stream in the chain. Only process first cert. - static void insecure_append(const br_x509_class **ctx, const unsigned char *buf, size_t len) - { - br_x509_insecure_context *xc = (br_x509_insecure_context *)ctx; - // Don't process anything but the first certificate in the chain - if (!xc->done_cert) - { - br_sha1_update(&xc->sha1_cert, buf, len); - br_x509_decoder_push(&xc->ctx, (const void *)buf, len); -#ifdef DEBUG_ESP_SSL - DEBUG_BSSL("CERT: "); - for (size_t i = 0; i < len; i++) - { - DEBUG_ESP_PORT.printf_P(PSTR("%02x "), buf[i] & 0xff); - } - DEBUG_ESP_PORT.printf_P(PSTR("\n")); -#endif - } - } - - // Callback on individual cert end. - static void insecure_end_cert(const br_x509_class **ctx) - { - br_x509_insecure_context *xc = (br_x509_insecure_context *)ctx; - xc->done_cert = true; - } - - // Callback when complete chain has been parsed. - // Return 0 on validation success, !0 on validation error - static unsigned insecure_end_chain(const br_x509_class **ctx) - { - const br_x509_insecure_context *xc = (const br_x509_insecure_context *)ctx; - if (!xc->done_cert) - { - DEBUG_BSSL("insecure_end_chain: No cert seen\n"); - return 1; // error - } - - // Handle SHA1 fingerprint matching - char res[20]; - br_sha1_out(&xc->sha1_cert, res); - if (xc->match_fingerprint && memcmp(res, xc->match_fingerprint, sizeof(res))) - { -#ifdef DEBUG_ESP_SSL - DEBUG_BSSL("insecure_end_chain: Received cert FP doesn't match\n"); - char buff[3 * sizeof(res) + 1]; // 3 chars per byte XX_, and null - buff[0] = 0; - for (size_t i = 0; i < sizeof(res); i++) - { - char hex[4]; // XX_\0 - snprintf(hex, sizeof(hex), "%02x ", xc->match_fingerprint[i] & 0xff); - strlcat(buff, hex, sizeof(buff)); - } - DEBUG_BSSL("insecure_end_chain: expected %s\n", buff); - buff[0] = 0; - for (size_t i = 0; i < sizeof(res); i++) - { - char hex[4]; // XX_\0 - snprintf(hex, sizeof(hex), "%02x ", res[i] & 0xff); - strlcat(buff, hex, sizeof(buff)); - } - DEBUG_BSSL("insecure_end_chain: received %s\n", buff); -#endif - return BR_ERR_X509_NOT_TRUSTED; - } - - // Handle self-signer certificate acceptance - char res_issuer[32]; - char res_subject[32]; - br_sha256_out(&xc->sha256_issuer, res_issuer); - br_sha256_out(&xc->sha256_subject, res_subject); - if (xc->allow_self_signed && memcmp(res_subject, res_issuer, sizeof(res_issuer))) - { - DEBUG_BSSL("insecure_end_chain: Didn't get self-signed cert\n"); - return BR_ERR_X509_NOT_TRUSTED; - } - - // Default (no validation at all) or no errors in prior checks = success. - return 0; - } - - // Return the public key from the validator (set by x509_minimal) - static const br_x509_pkey *insecure_get_pkey(const br_x509_class *const *ctx, unsigned *usages) - { - const br_x509_insecure_context *xc = (const br_x509_insecure_context *)ctx; - if (usages != NULL) - { - *usages = BR_KEYTYPE_KEYX | BR_KEYTYPE_SIGN; // I said we were insecure! - } - return &xc->ctx.pkey; - } - - // Set up the x509 insecure data structures for BearSSL core to use. - void esp_mail_br_x509_insecure_init(br_x509_insecure_context *ctx, int _use_fingerprint, const uint8_t _fingerprint[20], int _allow_self_signed) - { - static const br_x509_class br_x509_insecure_vtable PROGMEM = { - sizeof(br_x509_insecure_context), - insecure_start_chain, - insecure_start_cert, - insecure_append, - insecure_end_cert, - insecure_end_chain, - insecure_get_pkey}; - - memset(ctx, 0, sizeof *ctx); - ctx->vtable = &br_x509_insecure_vtable; - ctx->done_cert = false; - ctx->match_fingerprint = _use_fingerprint ? _fingerprint : nullptr; - ctx->allow_self_signed = _allow_self_signed ? 1 : 0; - } - - // Some constants uses to init the server/client contexts - // Note that suites_P needs to be copied to RAM before use w/BearSSL! - // List copied verbatim from BearSSL/ssl_client_full.c - /* - * The "full" profile supports all implemented cipher suites. - * - * Rationale for suite order, from most important to least - * important rule: - * - * -- Don't use 3DES if AES or ChaCha20 is available. - * -- Try to have Forward Secrecy (ECDHE suite) if possible. - * -- When not using Forward Secrecy, ECDH key exchange is - * better than RSA key exchange (slightly more expensive on the - * client, but much cheaper on the server, and it implies smaller - * messages). - * -- ChaCha20+Poly1305 is better than AES/GCM (faster, smaller code). - * -- GCM is better than CCM and CBC. CCM is better than CBC. - * -- CCM is preferable over CCM_8 (with CCM_8, forgeries may succeed - * with probability 2^(-64)). - * -- AES-128 is preferred over AES-256 (AES-128 is already - * strong enough, and AES-256 is 40% more expensive). - */ - static const uint16_t suites_P[] PROGMEM = { -#ifndef BEARSSL_SSL_BASIC - BR_TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256, - BR_TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256, - BR_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, - BR_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, - BR_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, - BR_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, - BR_TLS_ECDHE_ECDSA_WITH_AES_128_CCM, - BR_TLS_ECDHE_ECDSA_WITH_AES_256_CCM, - BR_TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8, - BR_TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8, - BR_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, - BR_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, - BR_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384, - BR_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384, - BR_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, - BR_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, - BR_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, - BR_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, - BR_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256, - BR_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256, - BR_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384, - BR_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384, - BR_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256, - BR_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256, - BR_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384, - BR_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384, - BR_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA, - BR_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA, - BR_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA, - BR_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA, - BR_TLS_RSA_WITH_AES_128_GCM_SHA256, - BR_TLS_RSA_WITH_AES_256_GCM_SHA384, - BR_TLS_RSA_WITH_AES_128_CCM, - BR_TLS_RSA_WITH_AES_256_CCM, - BR_TLS_RSA_WITH_AES_128_CCM_8, - BR_TLS_RSA_WITH_AES_256_CCM_8, -#endif - BR_TLS_RSA_WITH_AES_128_CBC_SHA256, - BR_TLS_RSA_WITH_AES_256_CBC_SHA256, - BR_TLS_RSA_WITH_AES_128_CBC_SHA, - BR_TLS_RSA_WITH_AES_256_CBC_SHA, -#ifndef BEARSSL_SSL_BASIC - BR_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA, - BR_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, - BR_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA, - BR_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA, - BR_TLS_RSA_WITH_3DES_EDE_CBC_SHA -#endif - }; -#ifndef BEARSSL_SSL_BASIC - // Server w/EC has one set, not possible with basic SSL config - static const uint16_t suites_server_ec_P[] PROGMEM = { - BR_TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256, - BR_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, - BR_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, - BR_TLS_ECDHE_ECDSA_WITH_AES_128_CCM, - BR_TLS_ECDHE_ECDSA_WITH_AES_256_CCM, - BR_TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8, - BR_TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8, - BR_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, - BR_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384, - BR_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, - BR_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, - BR_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256, - BR_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256, - BR_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384, - BR_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384, - BR_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256, - BR_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256, - BR_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384, - BR_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384, - BR_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA, - BR_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA, - BR_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA, - BR_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA, - BR_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA, - BR_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA, - BR_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA}; -#endif - - static const uint16_t suites_server_rsa_P[] PROGMEM = { -#ifndef BEARSSL_SSL_BASIC - BR_TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256, - BR_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, - BR_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, - BR_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, - BR_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384, - BR_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, - BR_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, - BR_TLS_RSA_WITH_AES_128_GCM_SHA256, - BR_TLS_RSA_WITH_AES_256_GCM_SHA384, - BR_TLS_RSA_WITH_AES_128_CCM, - BR_TLS_RSA_WITH_AES_256_CCM, - BR_TLS_RSA_WITH_AES_128_CCM_8, - BR_TLS_RSA_WITH_AES_256_CCM_8, -#endif - BR_TLS_RSA_WITH_AES_128_CBC_SHA256, - BR_TLS_RSA_WITH_AES_256_CBC_SHA256, - BR_TLS_RSA_WITH_AES_128_CBC_SHA, - BR_TLS_RSA_WITH_AES_256_CBC_SHA, -#ifndef BEARSSL_SSL_BASIC - BR_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, - BR_TLS_RSA_WITH_3DES_EDE_CBC_SHA -#endif - }; - - // For apps which want to use less secure but faster ciphers, only - static const uint16_t faster_suites_P[] PROGMEM = { - BR_TLS_RSA_WITH_AES_256_CBC_SHA256, - BR_TLS_RSA_WITH_AES_128_CBC_SHA256, - BR_TLS_RSA_WITH_AES_256_CBC_SHA, - BR_TLS_RSA_WITH_AES_128_CBC_SHA}; - - // Install hashes into the SSL engine - static void br_ssl_client_install_hashes(br_ssl_engine_context *eng) - { - br_ssl_engine_set_hash(eng, br_md5_ID, &br_md5_vtable); - br_ssl_engine_set_hash(eng, br_sha1_ID, &br_sha1_vtable); - br_ssl_engine_set_hash(eng, br_sha224_ID, &br_sha224_vtable); - br_ssl_engine_set_hash(eng, br_sha256_ID, &br_sha256_vtable); - br_ssl_engine_set_hash(eng, br_sha384_ID, &br_sha384_vtable); - br_ssl_engine_set_hash(eng, br_sha512_ID, &br_sha512_vtable); - } - - static void br_x509_minimal_install_hashes(br_x509_minimal_context *x509) - { - br_x509_minimal_set_hash(x509, br_md5_ID, &br_md5_vtable); - br_x509_minimal_set_hash(x509, br_sha1_ID, &br_sha1_vtable); - br_x509_minimal_set_hash(x509, br_sha224_ID, &br_sha224_vtable); - br_x509_minimal_set_hash(x509, br_sha256_ID, &br_sha256_vtable); - br_x509_minimal_set_hash(x509, br_sha384_ID, &br_sha384_vtable); - br_x509_minimal_set_hash(x509, br_sha512_ID, &br_sha512_vtable); - } - - // Default initializion for our SSL clients - static void br_ssl_client_base_init(br_ssl_client_context *cc, const uint16_t *cipher_list, int cipher_cnt) - { - uint16_t suites[cipher_cnt]; - memcpy_P(suites, cipher_list, cipher_cnt * sizeof(cipher_list[0])); - br_ssl_client_zero(cc); - br_ssl_engine_add_flags(&cc->eng, BR_OPT_NO_RENEGOTIATION); // forbid SSL renegociation, as we free the Private Key after handshake - br_ssl_engine_set_versions(&cc->eng, BR_TLS10, BR_TLS12); - br_ssl_engine_set_suites(&cc->eng, suites, (sizeof suites) / (sizeof suites[0])); - br_ssl_client_set_default_rsapub(cc); - br_ssl_engine_set_default_rsavrfy(&cc->eng); -#ifndef BEARSSL_SSL_BASIC - br_ssl_engine_set_default_ecdsa(&cc->eng); -#endif - br_ssl_client_install_hashes(&cc->eng); - br_ssl_engine_set_prf10(&cc->eng, &br_tls10_prf); - br_ssl_engine_set_prf_sha256(&cc->eng, &br_tls12_sha256_prf); - br_ssl_engine_set_prf_sha384(&cc->eng, &br_tls12_sha384_prf); - br_ssl_engine_set_default_aes_cbc(&cc->eng); -#ifndef BEARSSL_SSL_BASIC - br_ssl_engine_set_default_aes_gcm(&cc->eng); - br_ssl_engine_set_default_aes_ccm(&cc->eng); - br_ssl_engine_set_default_des_cbc(&cc->eng); - br_ssl_engine_set_default_chapol(&cc->eng); -#endif - } - - // Default initializion for our SSL clients - static void br_ssl_server_base_init(br_ssl_server_context *cc, const uint16_t *cipher_list, int cipher_cnt) - { - uint16_t suites[cipher_cnt]; - memcpy_P(suites, cipher_list, cipher_cnt * sizeof(cipher_list[0])); - br_ssl_server_zero(cc); - br_ssl_engine_add_flags(&cc->eng, BR_OPT_NO_RENEGOTIATION); // forbid SSL renegociation, as we free the Private Key after handshake - br_ssl_engine_set_versions(&cc->eng, BR_TLS10, BR_TLS12); - br_ssl_engine_set_suites(&cc->eng, suites, (sizeof suites) / (sizeof suites[0])); -#ifndef BEARSSL_SSL_BASIC - br_ssl_engine_set_default_ec(&cc->eng); -#endif - - br_ssl_client_install_hashes(&cc->eng); - br_ssl_engine_set_prf10(&cc->eng, &br_tls10_prf); - br_ssl_engine_set_prf_sha256(&cc->eng, &br_tls12_sha256_prf); - br_ssl_engine_set_prf_sha384(&cc->eng, &br_tls12_sha384_prf); - br_ssl_engine_set_default_aes_cbc(&cc->eng); -#ifndef BEARSSL_SSL_BASIC - br_ssl_engine_set_default_aes_ccm(&cc->eng); - br_ssl_engine_set_default_aes_gcm(&cc->eng); - br_ssl_engine_set_default_des_cbc(&cc->eng); - br_ssl_engine_set_default_chapol(&cc->eng); -#endif - } - } - - // Set custom list of ciphers - bool ESP_Mail_WCS::setCiphers(const uint16_t *cipherAry, int cipherCount) - { - _cipher_list = nullptr; - _cipher_list = std::shared_ptr(new uint16_t[cipherCount], std::default_delete()); - if (!_cipher_list.get()) - { - DEBUG_BSSL("setCiphers: list empty\n"); - return false; - } - memcpy_P(_cipher_list.get(), cipherAry, cipherCount * sizeof(uint16_t)); - _cipher_cnt = cipherCount; - return true; - } - - bool ESP_Mail_WCS::setCiphersLessSecure() - { - return setCiphers(faster_suites_P, sizeof(faster_suites_P) / sizeof(faster_suites_P[0])); - } - - bool ESP_Mail_WCS::setCiphers(std::vector list) - { - return setCiphers(&list[0], list.size()); - } - - // Installs the appropriate X509 cert validation method for a client connection - bool ESP_Mail_WCS::_installClientX509Validator() - { - if (_use_insecure || _use_fingerprint || _use_self_signed) - { - // Use common insecure x509 authenticator - _x509_insecure = std::make_shared(); - if (!_x509_insecure) - { - DEBUG_BSSL("_installClientX509Validator: OOM for _x509_insecure\n"); - return false; - } - esp_mail_br_x509_insecure_init(_x509_insecure.get(), _use_fingerprint, _fingerprint, _use_self_signed); - br_ssl_engine_set_x509(_eng, &_x509_insecure->vtable); - } - else if (_knownkey) - { - // Simple, pre-known public key authenticator, ignores cert completely. - _x509_knownkey = std::make_shared(); - if (!_x509_knownkey) - { - DEBUG_BSSL("_installClientX509Validator: OOM for _x509_knownkey\n"); - return false; - } - if (_knownkey->isRSA()) - { - br_x509_knownkey_init_rsa(_x509_knownkey.get(), _knownkey->getRSA(), _knownkey_usages); - } - else if (_knownkey->isEC()) - { -#ifndef BEARSSL_SSL_BASIC - br_x509_knownkey_init_ec(_x509_knownkey.get(), _knownkey->getEC(), _knownkey_usages); -#else - (void)_knownkey; - (void)_knownkey_usages; - DEBUG_BSSL("_installClientX509Validator: Attempting to use EC keys in minimal cipher mode (no EC)\n"); - return false; -#endif - } - br_ssl_engine_set_x509(_eng, &_x509_knownkey->vtable); - } - else - { - // X509 minimal validator. Checks dates, cert chain for trusted CA, etc. - _x509_minimal = std::make_shared(); - if (!_x509_minimal) - { - DEBUG_BSSL("_installClientX509Validator: OOM for _x509_minimal\n"); - return false; - } - br_x509_minimal_init(_x509_minimal.get(), &br_sha256_vtable, _ta ? _ta->getTrustAnchors() : nullptr, _ta ? _ta->getCount() : 0); - br_x509_minimal_set_rsa(_x509_minimal.get(), br_ssl_engine_get_rsavrfy(_eng)); -#ifndef BEARSSL_SSL_BASIC - br_x509_minimal_set_ecdsa(_x509_minimal.get(), br_ssl_engine_get_ec(_eng), br_ssl_engine_get_ecdsa(_eng)); -#endif - br_x509_minimal_install_hashes(_x509_minimal.get()); - if (_now) - { - // Magic constants convert to x509 times - br_x509_minimal_set_time(_x509_minimal.get(), ((uint32_t)_now) / 86400 + 719528, ((uint32_t)_now) % 86400); - } - if (_certStore) - { - _certStore->installCertStore(_x509_minimal.get()); - } - br_ssl_engine_set_x509(_eng, &_x509_minimal->vtable); - } - return true; - } - - // Called by connect() to do the actual SSL setup and handshake. - // Returns if the SSL handshake succeeded. - bool ESP_Mail_WCS::_connectSSL(const char *hostName) - { - DEBUG_BSSL("_connectSSL: start connection\n"); - _freeSSL(); - _oom_err = false; - -#ifdef DEBUG_ESP_SSL - // BearSSL will reject all connections unless an authentication option is set, warn in DEBUG builds - if (!_use_insecure && !_use_fingerprint && !_use_self_signed && !_knownkey && !_certStore && !_ta) - { - DEBUG_BSSL("Connection *will* fail, no authentication method is setup\n"); - } -#endif - - _sc = std::make_shared(); - _eng = &_sc->eng; // Allocation/deallocation taken care of by the _sc shared_ptr - _iobuf_in = std::shared_ptr(new unsigned char[_iobuf_in_size], std::default_delete()); - _iobuf_out = std::shared_ptr(new unsigned char[_iobuf_out_size], std::default_delete()); - - if (!_sc || !_iobuf_in || !_iobuf_out) - { - _freeSSL(); // Frees _sc, _iobuf* - _oom_err = true; - DEBUG_BSSL("_connectSSL: OOM error\n"); - return false; - } - - // If no cipher list yet set, use defaults - if (_cipher_list.get() == nullptr) - { - br_ssl_client_base_init(_sc.get(), suites_P, sizeof(suites_P) / sizeof(suites_P[0])); - } - else - { - br_ssl_client_base_init(_sc.get(), _cipher_list.get(), _cipher_cnt); - } - // Only failure possible in the installation is OOM - if (!_installClientX509Validator()) - { - _freeSSL(); - _oom_err = true; - DEBUG_BSSL("_connectSSL: Can't install x509 validator\n"); - return false; - } - br_ssl_engine_set_buffers_bidi(_eng, _iobuf_in.get(), _iobuf_in_size, _iobuf_out.get(), _iobuf_out_size); - - // Apply any client certificates, if supplied. - if (_sk && _sk->isRSA()) - { - br_ssl_client_set_single_rsa(_sc.get(), _chain ? _chain->getX509Certs() : nullptr, _chain ? _chain->getCount() : 0, - _sk->getRSA(), br_rsa_pkcs1_sign_get_default()); - } - else if (_sk && _sk->isEC()) - { -#ifndef BEARSSL_SSL_BASIC - br_ssl_client_set_single_ec(_sc.get(), _chain ? _chain->getX509Certs() : nullptr, _chain ? _chain->getCount() : 0, - _sk->getEC(), _allowed_usages, - _cert_issuer_key_type, br_ec_get_default(), br_ecdsa_sign_asn1_get_default()); -#else - _freeSSL(); - DEBUG_BSSL("_connectSSL: Attempting to use EC cert in minimal cipher mode (no EC)\n"); - return false; -#endif - } - - // Restore session from the storage spot, if present - if (_session) - { - br_ssl_engine_set_session_parameters(_eng, _session->getSession()); - } - - if (!br_ssl_client_reset(_sc.get(), hostName, _session ? 1 : 0)) - { - _freeSSL(); - DEBUG_BSSL("_connectSSL: Can't reset client\n"); - return false; - } - - auto ret = _wait_for_handshake(); -#ifdef DEBUG_ESP_SSL - if (!ret) - { - char err[256]; - getLastSSLError(err, sizeof(err)); - DEBUG_BSSL("Couldn't connect. Error = '%s'\n", err); - } - else - { - DEBUG_BSSL("Connected!\n"); - } -#endif - - // Session is already validated here, there is no need to keep following - _x509_minimal = nullptr; - _x509_insecure = nullptr; - _x509_knownkey = nullptr; - - // reduce timeout after successful handshake to fail fast if server stop accepting our data for whathever reason - if (ret) - _timeout = 5000; - - return ret; - } - - // Slightly different X509 setup for servers who want to validate client - // certificates, so factor it out as it's used in RSA and EC servers. - bool ESP_Mail_WCS::_installServerX509Validator(const ESP_Mail_X509List *client_CA_ta) - { - if (client_CA_ta) - { - _ta = client_CA_ta; - // X509 minimal validator. Checks dates, cert chain for trusted CA, etc. - _x509_minimal = std::make_shared(); - if (!_x509_minimal) - { - _freeSSL(); - _oom_err = true; - DEBUG_BSSL("_installServerX509Validator: OOM for _x509_minimal\n"); - return false; - } - br_x509_minimal_init(_x509_minimal.get(), &br_sha256_vtable, _ta->getTrustAnchors(), _ta->getCount()); - br_ssl_engine_set_default_rsavrfy(_eng); -#ifndef BEARSSL_SSL_BASIC - br_ssl_engine_set_default_ecdsa(_eng); -#endif - br_x509_minimal_set_rsa(_x509_minimal.get(), br_ssl_engine_get_rsavrfy(_eng)); -#ifndef BEARSSL_SSL_BASIC - br_x509_minimal_set_ecdsa(_x509_minimal.get(), br_ssl_engine_get_ec(_eng), br_ssl_engine_get_ecdsa(_eng)); -#endif - br_x509_minimal_install_hashes(_x509_minimal.get()); - if (_now) - { - // Magic constants convert to x509 times - br_x509_minimal_set_time(_x509_minimal.get(), ((uint32_t)_now) / 86400 + 719528, ((uint32_t)_now) % 86400); - } - br_ssl_engine_set_x509(_eng, &_x509_minimal->vtable); - br_ssl_server_set_trust_anchor_names_alt(_sc_svr.get(), _ta->getTrustAnchors(), _ta->getCount()); - } - return true; - } - - // Called by WiFiServerBearSSL when an RSA cert/key is specified. - bool ESP_Mail_WCS::_connectSSLServerRSA(const ESP_Mail_X509List *chain, - const PrivateKey *sk, - const ESP_Mail_X509List *client_CA_ta) - { - _freeSSL(); - _oom_err = false; - _sc_svr = std::make_shared(); - _eng = &_sc_svr->eng; // Allocation/deallocation taken care of by the _sc shared_ptr - _iobuf_in = std::shared_ptr(new unsigned char[_iobuf_in_size], std::default_delete()); - _iobuf_out = std::shared_ptr(new unsigned char[_iobuf_out_size], std::default_delete()); - - if (!_sc_svr || !_iobuf_in || !_iobuf_out) - { - _freeSSL(); - _oom_err = true; - DEBUG_BSSL("_connectSSLServerRSA: OOM error\n"); - return false; - } - - br_ssl_server_base_init(_sc_svr.get(), suites_server_rsa_P, sizeof(suites_server_rsa_P) / sizeof(suites_server_rsa_P[0])); - br_ssl_server_set_single_rsa(_sc_svr.get(), chain ? chain->getX509Certs() : nullptr, chain ? chain->getCount() : 0, - sk ? sk->getRSA() : nullptr, BR_KEYTYPE_KEYX | BR_KEYTYPE_SIGN, - br_rsa_private_get_default(), br_rsa_pkcs1_sign_get_default()); - br_ssl_engine_set_buffers_bidi(_eng, _iobuf_in.get(), _iobuf_in_size, _iobuf_out.get(), _iobuf_out_size); - if (client_CA_ta && !_installServerX509Validator(client_CA_ta)) - { - DEBUG_BSSL("_connectSSLServerRSA: Can't install serverX509check\n"); - return false; - } - if (!br_ssl_server_reset(_sc_svr.get())) - { - _freeSSL(); - DEBUG_BSSL("_connectSSLServerRSA: Can't reset server ctx\n"); - return false; - } - - return _wait_for_handshake(); - } - - // Called by WiFiServerBearSSL when an elliptic curve cert/key is specified. - bool ESP_Mail_WCS::_connectSSLServerEC(const ESP_Mail_X509List *chain, - unsigned cert_issuer_key_type, const PrivateKey *sk, - const ESP_Mail_X509List *client_CA_ta) - { -#ifndef BEARSSL_SSL_BASIC - _freeSSL(); - _oom_err = false; - _sc_svr = std::make_shared(); - _eng = &_sc_svr->eng; // Allocation/deallocation taken care of by the _sc shared_ptr - _iobuf_in = std::shared_ptr(new unsigned char[_iobuf_in_size], std::default_delete()); - _iobuf_out = std::shared_ptr(new unsigned char[_iobuf_out_size], std::default_delete()); - - if (!_sc_svr || !_iobuf_in || !_iobuf_out) - { - _freeSSL(); - _oom_err = true; - DEBUG_BSSL("_connectSSLServerEC: OOM error\n"); - return false; - } - - br_ssl_server_base_init(_sc_svr.get(), suites_server_ec_P, sizeof(suites_server_ec_P) / sizeof(suites_server_ec_P[0])); - br_ssl_server_set_single_ec(_sc_svr.get(), chain ? chain->getX509Certs() : nullptr, chain ? chain->getCount() : 0, - sk ? sk->getEC() : nullptr, BR_KEYTYPE_KEYX | BR_KEYTYPE_SIGN, - cert_issuer_key_type, br_ssl_engine_get_ec(_eng), br_ecdsa_i15_sign_asn1); - br_ssl_engine_set_buffers_bidi(_eng, _iobuf_in.get(), _iobuf_in_size, _iobuf_out.get(), _iobuf_out_size); - if (client_CA_ta && !_installServerX509Validator(client_CA_ta)) - { - DEBUG_BSSL("_connectSSLServerEC: Can't install serverX509check\n"); - return false; - } - if (!br_ssl_server_reset(_sc_svr.get())) - { - _freeSSL(); - DEBUG_BSSL("_connectSSLServerEC: Can't reset server ctx\n"); - return false; - } - - return _wait_for_handshake(); -#else - (void)chain; - (void)cert_issuer_key_type; - (void)sk; - (void)client_CA_ta; - DEBUG_BSSL("_connectSSLServerEC: Attempting to use EC cert in minimal cipher mode (no EC)\n"); - return false; -#endif - } - - // Returns an error ID and possibly a string (if dest != null) of the last - // BearSSL reported error. - int ESP_Mail_WCS::getLastSSLError(char *dest, size_t len) - { - int err = 0; - const char *t = PSTR("OK"); - if (_sc || _sc_svr) - { - err = br_ssl_engine_last_error(_eng); - } - if (_oom_err) - { - err = -1000; - } - switch (err) - { - case -1000: - t = PSTR("Unable to allocate memory for SSL structures and buffers."); - break; - case BR_ERR_BAD_PARAM: - t = PSTR("Caller-provided parameter is incorrect."); - break; - case BR_ERR_BAD_STATE: - t = PSTR("Operation requested by the caller cannot be applied with the current context state (e.g. reading data while outgoing data is waiting to be sent)."); - break; - case BR_ERR_UNSUPPORTED_VERSION: - t = PSTR("Incoming protocol or record version is unsupported."); - break; - case BR_ERR_BAD_VERSION: - t = PSTR("Incoming record version does not match the expected version."); - break; - case BR_ERR_BAD_LENGTH: - t = PSTR("Incoming record length is invalid."); - break; - case BR_ERR_TOO_LARGE: - t = PSTR("Incoming record is too large to be processed, or buffer is too small for the handshake message to send."); - break; - case BR_ERR_BAD_MAC: - t = PSTR("Decryption found an invalid padding, or the record MAC is not correct."); - break; - case BR_ERR_NO_RANDOM: - t = PSTR("No initial entropy was provided, and none can be obtained from the OS."); - break; - case BR_ERR_UNKNOWN_TYPE: - t = PSTR("Incoming record type is unknown."); - break; - case BR_ERR_UNEXPECTED: - t = PSTR("Incoming record or message has wrong type with regards to the current engine state."); - break; - case BR_ERR_BAD_CCS: - t = PSTR("ChangeCipherSpec message from the peer has invalid contents."); - break; - case BR_ERR_BAD_ALERT: - t = PSTR("Alert message from the peer has invalid contents (odd length)."); - break; - case BR_ERR_BAD_HANDSHAKE: - t = PSTR("Incoming handshake message decoding failed."); - break; - case BR_ERR_OVERSIZED_ID: - t = PSTR("ServerHello contains a session ID which is larger than 32 bytes."); - break; - case BR_ERR_BAD_CIPHER_SUITE: - t = PSTR("Server wants to use a cipher suite that we did not claim to support. This is also reported if we tried to advertise a cipher suite that we do not support."); - break; - case BR_ERR_BAD_COMPRESSION: - t = PSTR("Server wants to use a compression that we did not claim to support."); - break; - case BR_ERR_BAD_FRAGLEN: - t = PSTR("Server's max fragment length does not match client's."); - break; - case BR_ERR_BAD_SECRENEG: - t = PSTR("Secure renegotiation failed."); - break; - case BR_ERR_EXTRA_EXTENSION: - t = PSTR("Server sent an extension type that we did not announce, or used the same extension type several times in a single ServerHello."); - break; - case BR_ERR_BAD_SNI: - t = PSTR("Invalid Server Name Indication contents (when used by the server, this extension shall be empty)."); - break; - case BR_ERR_BAD_HELLO_DONE: - t = PSTR("Invalid ServerHelloDone from the server (length is not 0)."); - break; - case BR_ERR_LIMIT_EXCEEDED: - t = PSTR("Internal limit exceeded (e.g. server's public key is too large)."); - break; - case BR_ERR_BAD_FINISHED: - t = PSTR("Finished message from peer does not match the expected value."); - break; - case BR_ERR_RESUME_MISMATCH: - t = PSTR("Session resumption attempt with distinct version or cipher suite."); - break; - case BR_ERR_INVALID_ALGORITHM: - t = PSTR("Unsupported or invalid algorithm (ECDHE curve, signature algorithm, hash function)."); - break; - case BR_ERR_BAD_SIGNATURE: - t = PSTR("Invalid signature in ServerKeyExchange or CertificateVerify message."); - break; - case BR_ERR_WRONG_KEY_USAGE: - t = PSTR("Peer's public key does not have the proper type or is not allowed for the requested operation."); - break; - case BR_ERR_NO_CLIENT_AUTH: - t = PSTR("Client did not send a certificate upon request, or the client certificate could not be validated."); - break; - case BR_ERR_IO: - t = PSTR("I/O error or premature close on transport stream."); - break; - case BR_ERR_X509_INVALID_VALUE: - t = PSTR("Invalid value in an ASN.1 structure."); - break; - case BR_ERR_X509_TRUNCATED: - t = PSTR("Truncated certificate or other ASN.1 object."); - break; - case BR_ERR_X509_EMPTY_CHAIN: - t = PSTR("Empty certificate chain (no certificate at all)."); - break; - case BR_ERR_X509_INNER_TRUNC: - t = PSTR("Decoding error: inner element extends beyond outer element size."); - break; - case BR_ERR_X509_BAD_TAG_CLASS: - t = PSTR("Decoding error: unsupported tag class (application or private)."); - break; - case BR_ERR_X509_BAD_TAG_VALUE: - t = PSTR("Decoding error: unsupported tag value."); - break; - case BR_ERR_X509_INDEFINITE_LENGTH: - t = PSTR("Decoding error: indefinite length."); - break; - case BR_ERR_X509_EXTRA_ELEMENT: - t = PSTR("Decoding error: extraneous element."); - break; - case BR_ERR_X509_UNEXPECTED: - t = PSTR("Decoding error: unexpected element."); - break; - case BR_ERR_X509_NOT_CONSTRUCTED: - t = PSTR("Decoding error: expected constructed element, but is primitive."); - break; - case BR_ERR_X509_NOT_PRIMITIVE: - t = PSTR("Decoding error: expected primitive element, but is constructed."); - break; - case BR_ERR_X509_PARTIAL_BYTE: - t = PSTR("Decoding error: BIT STRING length is not multiple of 8."); - break; - case BR_ERR_X509_BAD_BOOLEAN: - t = PSTR("Decoding error: BOOLEAN value has invalid length."); - break; - case BR_ERR_X509_OVERFLOW: - t = PSTR("Decoding error: value is off-limits."); - break; - case BR_ERR_X509_BAD_DN: - t = PSTR("Invalid distinguished name."); - break; - case BR_ERR_X509_BAD_TIME: - t = PSTR("Invalid date/time representation."); - break; - case BR_ERR_X509_UNSUPPORTED: - t = PSTR("Certificate contains unsupported features that cannot be ignored."); - break; - case BR_ERR_X509_LIMIT_EXCEEDED: - t = PSTR("Key or signature size exceeds internal limits."); - break; - case BR_ERR_X509_WRONG_KEY_TYPE: - t = PSTR("Key type does not match that which was expected."); - break; - case BR_ERR_X509_BAD_SIGNATURE: - t = PSTR("Signature is invalid."); - break; - case BR_ERR_X509_TIME_UNKNOWN: - t = PSTR("Validation time is unknown."); - break; - case BR_ERR_X509_EXPIRED: - t = PSTR("Certificate is expired or not yet valid."); - break; - case BR_ERR_X509_DN_MISMATCH: - t = PSTR("Issuer/Subject DN mismatch in the chain."); - break; - case BR_ERR_X509_BAD_SERVER_NAME: - t = PSTR("Expected server name was not found in the chain."); - break; - case BR_ERR_X509_CRITICAL_EXTENSION: - t = PSTR("Unknown critical extension in certificate."); - break; - case BR_ERR_X509_NOT_CA: - t = PSTR("Not a CA, or path length constraint violation."); - break; - case BR_ERR_X509_FORBIDDEN_KEY_USAGE: - t = PSTR("Key Usage extension prohibits intended usage."); - break; - case BR_ERR_X509_WEAK_PUBLIC_KEY: - t = PSTR("Public key found in certificate is too small."); - break; - case BR_ERR_X509_NOT_TRUSTED: - t = PSTR("Chain could not be linked to a trust anchor."); - break; - default: - t = PSTR("Unknown error code."); - break; - } - if (dest) - { - strncpy_P(dest, t, len); - dest[len - 1] = 0; - } - return err; - } - - bool ESP_Mail_WCS::probeMaxFragmentLength(const char *name, uint16_t port, uint16_t len) - { - IPAddress remote_addr; - if (!WiFi.hostByName(name, remote_addr)) - { - DEBUG_BSSL("probeMaxFragmentLength: Can't resolve host\n"); - return false; - } - return ESP_Mail_WCS::probeMaxFragmentLength(remote_addr, port, len); - } - - bool ESP_Mail_WCS::probeMaxFragmentLength(const String &host, uint16_t port, uint16_t len) - { - return ESP_Mail_WCS::probeMaxFragmentLength(host.c_str(), port, len); - } - - // Helper function which aborts a TLS handshake by sending TLS - // ClientAbort and ClientClose messages. - static bool _SendAbort(WiFiClient &probe, bool supportsLen) - { - // If we're still connected, send the appropriate notice that - // we're aborting the handshake per RFCs. - static const uint8_t clientAbort_P[] PROGMEM = { - 0x15 /*alert*/, 0x03, 0x03 /*TLS 1.2*/, 0x00, 0x02, - 1, 90 /* warning: user_cancelled */ - }; - static const uint8_t clientClose_P[] PROGMEM = { - 0x15 /*alert*/, 0x03, 0x03 /*TLS 1.2*/, 0x00, 0x02, - 1, 0 /* warning: close_notify */ - }; - if (probe.connected()) - { - uint8_t msg[sizeof(clientAbort_P)]; - memcpy_P(msg, clientAbort_P, sizeof(clientAbort_P)); - probe.write(msg, sizeof(clientAbort_P)); - memcpy_P(msg, clientClose_P, sizeof(clientClose_P)); - probe.write(msg, sizeof(clientClose_P)); - } - return supportsLen; - } - - // Checks for support of Maximum Frame Length Negotiation at the given - // blocksize. Note that, per spec, only 512, 1024, 2048, and 4096 are - // supported. Many servers today do not support this negotiation. - - // TODO - Allow for fragmentation...but not very critical as the ServerHello - // we use comes to < 80 bytes which has no reason to ever be fragmented. - // TODO - Check the type of returned extensions and that the MFL is the exact - // same one we sent. Not critical as only horribly broken servers would - // return changed or add their own extensions. - bool ESP_Mail_WCS::probeMaxFragmentLength(IPAddress ip, uint16_t port, uint16_t len) - { - // Hardcoded TLS 1.2 packets used throughout - static const uint8_t clientHelloHead_P[] PROGMEM = { - 0x16, 0x03, 0x03, 0x00, 0, // TLS header, change last 2 bytes to len - 0x01, 0x00, 0x00, 0, // Last 3 bytes == length - 0x03, 0x03, // Proto version TLS 1.2 - 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, // Random (gmtime + rand[28]) - 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, - 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, - 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, - 0x00, // Session ID - }; - // Followed by our cipher-suite, generated on-the-fly - // 0x00, 0x02, // cipher suite len - // 0xc0, 0x13, // BR_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA - static const uint8_t clientHelloTail_P[] PROGMEM = { - 0x01, 0x00, // No compression - 0x00, 26 + 14 + 6 + 5, // Extension length - 0x00, 0x0d, 0x00, 0x16, 0x00, 0x14, 0x04, 0x03, 0x03, 0x03, 0x05, 0x03, - 0x06, 0x03, 0x02, 0x03, 0x04, 0x01, 0x03, 0x01, 0x05, 0x01, 0x06, - 0x01, 0x02, 0x01, // Supported signature algorithms - 0x00, 0x0a, 0x00, 0x0a, 0x00, 0x08, 0x00, 0x17, 0x00, 0x18, 0x00, 0x19, - 0x00, 0x1d, // Supported groups - 0x00, 0x0b, 0x00, 0x02, 0x01, 0x00, // Supported EC formats - 0x00, 0x01, // Max Frag Len - 0x00, 0x01, // len of MaxFragLen - }; - // Followed by a 1-byte MFLN size requesst - // 0x04 // 2^12 = 4K - uint8_t mfl; - - switch (len) - { - case 512: - mfl = 1; - break; - case 1024: - mfl = 2; - break; - case 2048: - mfl = 3; - break; - case 4096: - mfl = 4; - break; - default: - return false; // Invalid size - } - int ttlLen = sizeof(clientHelloHead_P) + (2 + sizeof(suites_P)) + (sizeof(clientHelloTail_P) + 1); - uint8_t *clientHello = new uint8_t[ttlLen]; - if (!clientHello) - { - DEBUG_BSSL("probeMaxFragmentLength: OOM\n"); - return false; - } - memcpy_P(clientHello, clientHelloHead_P, sizeof(clientHelloHead_P)); - clientHello[sizeof(clientHelloHead_P) + 0] = sizeof(suites_P) >> 8; // MSB byte len - clientHello[sizeof(clientHelloHead_P) + 1] = sizeof(suites_P) & 0xff; // LSB byte len - for (size_t i = 0; i < sizeof(suites_P) / sizeof(suites_P[0]); i++) - { - uint16_t flip = pgm_read_word(&suites_P[i]); - // Swap to network byte order - flip = ((flip >> 8) & 0xff) | ((flip & 0xff) << 8); - memcpy(clientHello + sizeof(clientHelloHead_P) + 2 + 2 * i, &flip, 2); - } - memcpy_P(clientHello + sizeof(clientHelloHead_P) + 2 + sizeof(suites_P), clientHelloTail_P, sizeof(clientHelloTail_P)); - clientHello[sizeof(clientHelloHead_P) + 2 + sizeof(suites_P) + sizeof(clientHelloTail_P)] = mfl; - - // Fix up TLS fragment length - clientHello[3] = (ttlLen - 5) >> 8; - clientHello[4] = (ttlLen - 5) & 0xff; - // Fix up ClientHello message length - clientHello[7] = (ttlLen - 5 - 4) >> 8; - clientHello[8] = (ttlLen - 5 - 4) & 0xff; - - WiFiClient probe; - probe.connect(ip, port); - if (!probe.connected()) - { - delete[] clientHello; - DEBUG_BSSL("probeMaxFragmentLength: Can't connect\n"); - return false; - } - - int ret = probe.write(clientHello, ttlLen); - delete[] clientHello; // We're done w/the hello message - if (!probe.connected() || (ret != ttlLen)) - { - DEBUG_BSSL("probeMaxFragmentLength: Protocol error\n"); - return false; - } - - bool supportsLen = false; - uint8_t fragResp[5]; - int fragLen; - uint8_t hand[4]; - int handLen; - uint8_t protoVer[2]; - uint8_t rand[32]; - uint8_t sessionLen; - uint8_t cipher[2]; - uint8_t comp; - uint8_t extBytes[2]; - uint16_t extLen; - - ret = probe.readBytes(fragResp, 5); - if (!probe.connected() || (ret != 5) || (fragResp[0] != 0x16) || (fragResp[1] != 0x03) || (fragResp[2] != 0x03)) - { - // Short read, not a HANDSHAKE or not TLS 1.2, so it's not supported - return _SendAbort(probe, supportsLen); - } - fragLen = (fragResp[3] << 8) | fragResp[4]; - if (fragLen < 4 + 2 + 32 + 1 + 2 + 1) - { - // Too short to have an extension - return _SendAbort(probe, supportsLen); - } - - ret = probe.readBytes(hand, 4); - fragLen -= ret; - if ((ret != 4) || (hand[0] != 2)) - { - // Short read or not server_hello - return _SendAbort(probe, supportsLen); - } - handLen = (hand[1] << 16) | (hand[2] << 8) | hand[3]; - if (handLen != fragLen) - { - // Got some weird mismatch, this is invalid - return _SendAbort(probe, supportsLen); - } - - ret = probe.readBytes(protoVer, 2); - handLen -= ret; - if ((ret != 2) || (protoVer[0] != 0x03) || (protoVer[1] != 0x03)) - { - // Short read or not tls 1.2, so can't do MFLN - return _SendAbort(probe, supportsLen); - } - - ret = probe.readBytes(rand, 32); - handLen -= ret; - if (ret != 32) - { - // short read of random data - return _SendAbort(probe, supportsLen); - } - - ret = probe.readBytes(&sessionLen, 1); - handLen -= ret; - if ((ret != 1) || (sessionLen > 32)) - { - // short read of session len or invalid size - return _SendAbort(probe, supportsLen); - } - if (sessionLen) - { - ret = probe.readBytes(rand, sessionLen); - handLen -= ret; - if (ret != sessionLen) - { - // short session id read - return _SendAbort(probe, supportsLen); - } - } - - ret = probe.readBytes(cipher, 2); - handLen -= ret; - if (ret != 2) - { - // Short read...we don't check the cipher here - return _SendAbort(probe, supportsLen); - } - - ret = probe.readBytes(&comp, 1); - handLen -= ret; - if ((ret != 1) || comp != 0) - { - // short read or invalid compression - return _SendAbort(probe, supportsLen); - } - - ret = probe.readBytes(extBytes, 2); - handLen -= ret; - extLen = extBytes[1] | (extBytes[0] << 8); - if ((extLen == 0) || (ret != 2)) - { - return _SendAbort(probe, supportsLen); - } - - while (handLen > 0) - { - // Parse each extension and look for MFLN - uint8_t typeBytes[2]; - ret = probe.readBytes(typeBytes, 2); - handLen -= 2; - if ((ret != 2) || (handLen <= 0)) - { - return _SendAbort(probe, supportsLen); - } - uint8_t lenBytes[2]; - ret = probe.readBytes(lenBytes, 2); - handLen -= 2; - uint16_t extLen = lenBytes[1] | (lenBytes[0] << 8); - if ((ret != 2) || (handLen <= 0) || (extLen > 32) || (extLen > handLen)) - { - return _SendAbort(probe, supportsLen); - } - if ((typeBytes[0] == 0x00) && (typeBytes[1] == 0x01)) - { // MFLN extension! - // If present and 1-byte in length, it's supported - return _SendAbort(probe, extLen == 1 ? true : false); - } - // Skip the extension, move to next one - uint8_t junk[32]; - ret = probe.readBytes(junk, extLen); - handLen -= extLen; - if (ret != extLen) - { - return _SendAbort(probe, supportsLen); - } - } - return _SendAbort(probe, supportsLen); - } - - // AXTLS compatibility interfaces - bool ESP_Mail_WCS::setCACert(const uint8_t *pk, size_t size) - { - _axtls_ta = nullptr; - _axtls_ta = std::shared_ptr(new ESP_Mail_X509List(pk, size)); - _ta = _axtls_ta.get(); - return _ta ? true : false; - } - - bool ESP_Mail_WCS::setCertificate(const uint8_t *pk, size_t size) - { - _axtls_chain = nullptr; - _axtls_chain = std::shared_ptr(new ESP_Mail_X509List(pk, size)); - _chain = _axtls_chain.get(); - return _chain ? true : false; - } - - bool ESP_Mail_WCS::setPrivateKey(const uint8_t *pk, size_t size) - { - _axtls_sk = nullptr; - _axtls_sk = std::shared_ptr(new PrivateKey(pk, size)); - _sk = _axtls_sk.get(); - return _sk ? true : false; - } - - uint8_t *ESP_Mail_WCS::_streamLoad(Stream &stream, size_t size) - { - uint8_t *dest = (uint8_t *)malloc(size); - if (!dest) - { - return nullptr; - } - if (size != stream.readBytes(dest, size)) - { - free(dest); - return nullptr; - } - return dest; - } - - bool ESP_Mail_WCS::loadCACert(Stream &stream, size_t size) - { - uint8_t *dest = _streamLoad(stream, size); - bool ret = false; - if (dest) - { -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" - ret = setCACert(dest, size); -#pragma GCC diagnostic pop - } - free(dest); - return ret; - } - - bool ESP_Mail_WCS::loadCertificate(Stream &stream, size_t size) - { - uint8_t *dest = _streamLoad(stream, size); - bool ret = false; - if (dest) - { -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" - ret = setCertificate(dest, size); -#pragma GCC diagnostic pop - } - free(dest); - return ret; - } - - bool ESP_Mail_WCS::loadPrivateKey(Stream &stream, size_t size) - { - uint8_t *dest = _streamLoad(stream, size); - bool ret = false; - if (dest) - { -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" - ret = setPrivateKey(dest, size); -#pragma GCC diagnostic pop - } - free(dest); - return ret; - } - - void ESP_Mail_WCS::setStartTLS(bool enable) - { - _secured = !enable; - } - - size_t ESP_Mail_WCS::_ns_write(uint8_t b) - { - return write(&b, 1); - } - - size_t ESP_Mail_WCS::_ns_write(const uint8_t *buf, size_t size) - { - if (!_client || !size) - { - return 0; - } - _client->setTimeout(_timeout); -#if defined(ESP8266_CORE_SDK_V3_X_X) - return _client->write((const char *)buf, size); -#else - return _client->write(buf, size); -#endif - } - - size_t ESP_Mail_WCS::_ns_write(Stream &stream, size_t unused) - { - (void)unused; - return WiFiClient::write(stream); - } - - size_t ESP_Mail_WCS::_ns_write(Stream &stream) - { - if (!_client || !stream.available()) - { - return 0; - } - _client->setTimeout(_timeout); -#if defined(ESP8266_CORE_SDK_V3_X_X) - size_t dl = stream.available(); - uint8_t buf[dl]; - stream.readBytes(buf, dl); - return _client->write((const char *)buf, dl); -#else - return _client->write(stream); -#endif - } - - size_t ESP_Mail_WCS::_ns_write_P(PGM_P buf, size_t size) - { - - if (!_client || !size) - { - return 0; - } - _client->setTimeout(_timeout); - -#if defined(ESP8266_CORE_SDK_V3_X_X) - char dest[size]; - memcpy_P((void *)dest, (PGM_VOID_P)buf, size); - return _client->write((const char *)dest, size); -#else - return _client->write_P(buf, size); -#endif - } - - int ESP_Mail_WCS::_ns_available() - { - if (!_client) - return false; - - int result = _client->getSize(); - - if (!result) - { - optimistic_yield(100); - } - return result; - } - - int ESP_Mail_WCS::_ns_read() - { - if (!_ns_available()) - return -1; - - return _client->read(); - } - - int ESP_Mail_WCS::_ns_read(uint8_t *buf, size_t size) - { - return (int)_client->read(reinterpret_cast(buf), size); - } - - int ESP_Mail_WCS::_ns_peek() - { - if (!_ns_available()) - return -1; - - return _client->peek(); - } - - size_t ESP_Mail_WCS::_ns_peekBytes(uint8_t *buffer, size_t length) - { - size_t count = 0; - - if (!_client) - { - return 0; - } - - _startMillis = millis(); - while ((_ns_available() < (int)length) && ((millis() - _startMillis) < _timeout)) - { - yield(); - } - - if (_ns_available() < (int)length) - { - count = _ns_available(); - } - else - { - count = length; - } - - return _client->peekBytes((char *)buffer, count); - } - - uint8_t ESP_Mail_WCS::_ns_connected() - { - if (!_client || _client->state() == CLOSED) - return 0; - - return _client->state() == ESTABLISHED || _ns_available(); - } - - bool ESP_Mail_WCS::_ns_connect_ssl() - { - return _connectSSL(_host_name.c_str()); - } -}; // namespace ESP_Mail - -#endif /* ESP8266 */ - -#endif /* ESP_Mail_WCS_CPP */ \ No newline at end of file diff --git a/lib/libesp32/lib_mail/src/wcs/esp8266/ESP_Mail_WCS.h b/lib/libesp32/lib_mail/src/wcs/esp8266/ESP_Mail_WCS.h deleted file mode 100644 index aef48cc5e..000000000 --- a/lib/libesp32/lib_mail/src/wcs/esp8266/ESP_Mail_WCS.h +++ /dev/null @@ -1,306 +0,0 @@ -/* - Customized version of WiFiClientSecure.h v1.0.1 - - WiFiClientBearSSL- SSL client/server for esp8266 using BearSSL libraries - - Mostly compatible with Arduino WiFi shield library and standard - WiFiClient/ServerSecure (except for certificate handling). - - Copyright (c) 2018 Earle F. Philhower, III - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef ESP_Mail_WCS_H -#define ESP_Mail_WCS_H - -#ifdef ESP8266 - -#include -#include -#include -#include "ESP_Mail_BearSSLHelpers.h" -#include "ESP_Mail_CertStoreBearSSL.h" -#include "SDK_Version_Common.h" - -namespace ESP_Mail { - -//#define DEBUG_ESP_SSL -//#define DEBUG_ESP_PORT Serial - - struct br_x509_insecure_context; - - class ESP_Mail_WCS : public WiFiClient - { - public: - ESP_Mail_WCS(); - ESP_Mail_WCS(const ESP_Mail_WCS &rhs); - ~ESP_Mail_WCS() override; - - ESP_Mail_WCS& operator=(const ESP_Mail_WCS&) = default; // The shared-ptrs handle themselves automatically - - int connect(IPAddress ip, uint16_t port) override; - int connect(const String& host, uint16_t port) override; - int connect(const char* name, uint16_t port) override; - - uint8_t connected() override; - size_t write(const uint8_t *buf, size_t size) override; - size_t write_P(PGM_P buf, size_t size) override; - size_t write(const char *buf) { - return write((const uint8_t*)buf, strlen(buf)); - } - size_t write_P(const char *buf) { - return write_P((PGM_P)buf, strlen_P(buf)); - } - size_t write(Stream& stream); // Note this is not virtual - int read(uint8_t *buf, size_t size) override; - int available() override; - int read() override; - int peek() override; - size_t peekBytes(uint8_t *buffer, size_t length) override; - bool flush(unsigned int maxWaitMs); - bool stop(unsigned int maxWaitMs); - void flush() override { (void)flush(0); } - void stop() override { (void)stop(0); } - - // Allow sessions to be saved/restored automatically to a memory area - void setSession(Session *session) { _session = session; } - - // Don't validate the chain, just accept whatever is given. VERY INSECURE! - void setInsecure() { - _clearAuthenticationSettings(); - _use_insecure = true; - } - // Assume a given public key, don't validate or use cert info at all - void setKnownKey(const PublicKey *pk, unsigned usages = BR_KEYTYPE_KEYX | BR_KEYTYPE_SIGN) { - _clearAuthenticationSettings(); - _knownkey = pk; - _knownkey_usages = usages; - } - // Only check SHA1 fingerprint of certificate - bool setFingerprint(const uint8_t fingerprint[20]) { - _clearAuthenticationSettings(); - _use_fingerprint = true; - memcpy_P(_fingerprint, fingerprint, 20); - return true; - } - bool setFingerprint(const char *fpStr); - // Accept any certificate that's self-signed - void allowSelfSignedCerts() { - _clearAuthenticationSettings(); - _use_self_signed = true; - } - // Install certificates of trusted CAs or specific site - void setTrustAnchors(const ESP_Mail_X509List *ta) { - _clearAuthenticationSettings(); - _ta = ta; - } - // In cases when NTP is not used, app must set a time manually to check cert validity - void setX509Time(time_t now) { - _now = now; - } - // Install a client certificate for this connection, in case the server requires it (i.e. MQTT) - void setClientRSACert(const ESP_Mail_X509List *cert, const PrivateKey *sk); - void setClientECCert(const ESP_Mail_X509List *cert, const PrivateKey *sk, - unsigned allowed_usages, unsigned cert_issuer_key_type); - - // Sets the requested buffer size for transmit and receive - void setBufferSizes(int recv, int xmit); - - // Returns whether MFLN negotiation for the above buffer sizes succeeded (after connection) - int getMFLNStatus() { - return connected() && br_ssl_engine_get_mfln_negotiated(_eng); - } - - // Return an error code and possibly a text string in a passed-in buffer with last SSL failure - int getLastSSLError(char *dest = NULL, size_t len = 0); - - // Attach a preconfigured certificate store - void setCertStore(ESP_Mail_CertStore *certStore) { - _certStore = certStore; - } - - // Select specific ciphers (i.e. optimize for speed over security) - // These may be in PROGMEM or RAM, either will run properly - bool setCiphers(const uint16_t *cipherAry, int cipherCount); - bool setCiphers(std::vector list); - bool setCiphersLessSecure(); // Only use the limited set of RSA ciphers without EC - - // Check for Maximum Fragment Length support for given len before connection (possibly insecure) - static bool probeMaxFragmentLength(IPAddress ip, uint16_t port, uint16_t len); - static bool probeMaxFragmentLength(const char *hostname, uint16_t port, uint16_t len); - static bool probeMaxFragmentLength(const String& host, uint16_t port, uint16_t len); - - void setStartTLS(bool enable); - size_t _ns_write(uint8_t b); - size_t _ns_write(const uint8_t *buf, size_t size); - size_t _ns_write(Stream &stream, size_t unused); - size_t _ns_write(Stream &stream); - size_t _ns_write_P(PGM_P buf, size_t size); - int _ns_available(); - int _ns_read(); - int _ns_read(uint8_t *buf, size_t size); - int _ns_peek(); - size_t _ns_peekBytes(uint8_t *buffer, size_t length); - uint8_t _ns_connected(); - bool _ns_connect_ssl(); - - //////////////////////////////////////////////////// - // AxTLS API deprecated warnings to help upgrading - - bool setCACert(const uint8_t* pk, size_t size) ; - bool setCertificate(const uint8_t* pk, size_t size) ; - bool setPrivateKey(const uint8_t* pk, size_t size) ; - - bool loadCACert(Stream& stream, size_t size) ; - bool loadCertificate(Stream& stream, size_t size) ; - bool loadPrivateKey(Stream& stream, size_t size) ; - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" - - bool setCACert_P(PGM_VOID_P pk, size_t size) { - return setCACert((const uint8_t *)pk, size); - } - - bool setCertificate_P(PGM_VOID_P pk, size_t size) { - return setCertificate((const uint8_t *)pk, size); - } - - bool setPrivateKey_P(PGM_VOID_P pk, size_t size) { - return setPrivateKey((const uint8_t *)pk, size); - } - -#pragma GCC diagnostic pop - - template - bool loadCertificate(TFile& file) { - return loadCertificate(file, file.size()); - } - - template - bool loadPrivateKey(TFile& file) { - return loadPrivateKey(file, file.size()); - } - - template - bool loadCACert(TFile& file) { - return loadCACert(file, file.size()); - } - - bool verify(const char* fingerprint, const char* domain_name) { - (void)fingerprint; - (void)domain_name; - return connected(); - } - - bool verifyCertChain(const char* domain_name) { - (void)domain_name; - return connected(); - } - - // AxTLS API deprecated section end - ///////////////////////////////////// - - protected: - bool _connectSSL(const char *hostName); // Do initial SSL handshake - - private: - void _clear(); - void _clearAuthenticationSettings(); - // Only one of the following two should ever be != nullptr! - std::shared_ptr _sc; - std::shared_ptr _sc_svr; - inline bool ctx_present() { - return (_sc != nullptr) || (_sc_svr != nullptr); - } - br_ssl_engine_context *_eng; // &_sc->eng, to allow for client or server contexts - std::shared_ptr _x509_minimal; - std::shared_ptr _x509_insecure; - std::shared_ptr _x509_knownkey; - std::shared_ptr _iobuf_in; - std::shared_ptr _iobuf_out; - time_t _now; - const ESP_Mail_X509List *_ta; - ESP_Mail_CertStore *_certStore; - int _iobuf_in_size; - int _iobuf_out_size; - bool _handshake_done; - bool _oom_err; - - bool _secured; - std::string _host_name; - - // AXTLS compatibility shim elements: - // AXTLS managed memory for certs and keys, while BearSSL assumes - // the app manages these. Use this local storage for holding the - // BearSSL created objects in a shared form. - std::shared_ptr _axtls_ta; - std::shared_ptr _axtls_chain; - std::shared_ptr _axtls_sk; - - // Optional storage space pointer for session parameters - // Will be used on connect and updated on close - Session *_session; - - bool _use_insecure; - bool _use_fingerprint; - uint8_t _fingerprint[20]; - bool _use_self_signed; - const PublicKey *_knownkey; - unsigned _knownkey_usages; - - // Custom cipher list pointer or NULL if default - std::shared_ptr _cipher_list; - uint8_t _cipher_cnt; - - unsigned char *_recvapp_buf; - size_t _recvapp_len; - - bool _clientConnected(); // Is the underlying socket alive? - void _freeSSL(); - int _run_until(unsigned target, bool blocking = true); - size_t _write(const uint8_t *buf, size_t size, bool pmem); - bool _wait_for_handshake(); // Sets and return the _handshake_done after connecting - - // Optional client certificate - const ESP_Mail_X509List *_chain; - const PrivateKey *_sk; - unsigned _allowed_usages; - unsigned _cert_issuer_key_type; - - // Methods for handling server.available() call which returns a client connection. - friend class WiFiServerSecure; // Server needs to access these constructors - ESP_Mail_WCS(ClientContext *client, const ESP_Mail_X509List *chain, unsigned cert_issuer_key_type, - const PrivateKey *sk, int iobuf_in_size, int iobuf_out_size, const ESP_Mail_X509List *client_CA_ta); - ESP_Mail_WCS(ClientContext* client, const ESP_Mail_X509List *chain, const PrivateKey *sk, - int iobuf_in_size, int iobuf_out_size, const ESP_Mail_X509List *client_CA_ta); - - // RSA keyed server - bool _connectSSLServerRSA(const ESP_Mail_X509List *chain, const PrivateKey *sk, const ESP_Mail_X509List *client_CA_ta); - // EC keyed server - bool _connectSSLServerEC(const ESP_Mail_X509List *chain, unsigned cert_issuer_key_type, const PrivateKey *sk, - const ESP_Mail_X509List *client_CA_ta); - - // X.509 validators differ from server to client - bool _installClientX509Validator(); // Set up X509 validator for a client conn. - bool _installServerX509Validator(const ESP_Mail_X509List *client_CA_ta); // Setup X509 client cert validation, if supplied - - uint8_t *_streamLoad(Stream& stream, size_t size); - }; -}; - -#endif /* ESP8266 */ - -#endif /* ESP_Mail_WCS_H */ diff --git a/tasmota/tasmota_xdrv_driver/xdrv_01_2_webserver_esp32_mail.ino b/tasmota/tasmota_xdrv_driver/xdrv_01_2_webserver_esp32_mail.ino index 8a99bc5f0..066cfce64 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_01_2_webserver_esp32_mail.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_01_2_webserver_esp32_mail.ino @@ -25,6 +25,66 @@ * and a section >m is found, the lines in this section (until #) are sent as email body \*********************************************************************************************/ +// +// Black magic necessary for BearSSL and BearSSL in libmail to live in parallel +// +extern "C" { +typedef struct { + + /* Structure for returning the public key. */ + br_x509_pkey pkey; + + /* CPU for the T0 virtual machine. */ + struct { + uint32_t *dp; + uint32_t *rp; + const unsigned char *ip; + } cpu; + uint32_t dp_stack[32]; + uint32_t rp_stack[32]; + int err; + + /* The pad serves as destination for various operations. */ + unsigned char pad[256]; + + /* Flag set when decoding succeeds. */ + unsigned char decoded; + + /* Validity dates. */ + uint32_t notbefore_days, notbefore_seconds; + uint32_t notafter_days, notafter_seconds; + + /* The "CA" flag. This is set to true if the certificate contains + a Basic Constraints extension that asserts CA status. */ + unsigned char isCA; + + /* DN processing: the subject DN is extracted and pushed to the + provided callback. */ + unsigned char copy_dn; + void *append_dn_ctx; + void (*append_dn)(void *ctx, const void *buf, size_t len); + + /* Certificate data chunk. */ + const unsigned char *hbuf; + size_t hlen; + + /* Buffer for decoded public key. */ + unsigned char pkey_data[BR_X509_BUFSIZE_KEY]; + + /* Type of key and hash function used in the certificate signature. */ + unsigned char signer_key_type; + unsigned char signer_hash_id; + +} br_x509_decoder_context_libmail; + + + void br_x509_decoder_push_libmail(br_x509_decoder_context_libmail *ctx, const void *data, size_t len); + void br_x509_decoder_init(br_x509_decoder_context_libmail *ctx, + void (*append_dn)(void *ctx, const void *buf, size_t len), + void *append_dn_ctx); +} + +#include "SSLClient/ESP_SSLClient.h" #include // #define DEBUG_EMAIL_PORT // Enable debugging @@ -339,7 +399,7 @@ void smtpCallback(SMTP_Status status) { for (size_t i = 0; i < smtp->sendingResult.size(); i++) { /* Get the result item */ SMTP_Result result = smtp->sendingResult.getItem(i); - localtime_r(&result.timesstamp, &dt); + localtime_r((time_t*)&result.timestamp, &dt); Serial.printf("Message No: %d\n", i + 1); Serial.printf("Status: %s\n", result.completed ? "success" : "failed");