1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-22 21:23:07 +03:00

393 Commits

Author SHA1 Message Date
david gauchard
85e68093e9
Automatic stack location selection (SYS or HEAP), enable per library AR-chive in arduino build system (#5018)
Automatic stack location selection (SYS or HEAP), enable per library AR-chive in arduino build system 

* enable dot_a_linkage on internal libraries
* add device tests
* boards generator: deprecate --noextra4k/--allowWPS and fix documentation
2018-08-20 14:35:52 +02:00
Earle F. Philhower, III
56b98fd4df Move all PROGMEM to their own section (#5048)
According to the GCC man page, __section__ attributes should only be used
for global variables.  However, the PROGMEM and ICACHE_RODATA macros use
this variable decorator even for local variables.  Most of the time it works,
but when a static or inlined function tries to use a PROGMEM/PSTR/etc.
variable the compiler can throw an error like:
  error: XXX causes a section type conflict with YYY

Change the PROGMEM macro to emit a section name that is unique (a combo
of the file, line, and counter variables to ensure uniqueness).  The
standard linker script will place them properly in .IROM without
any changes.

Fixes #5036 and others.
2018-08-15 11:46:13 -03:00
Earle F. Philhower, III
53091882b8
Fix minor BearSSL API issues (#4901)
Fixes #4882 and updates GitHub certificate fingerprint to the current one
in BearSSL_Validation example.

When setting a authentication mode or stopping, clear all others out in case
the object is being re-used.

Add in a yield during the SSL handshake to allow a graceful timeout and not
a WDT error when the remote server hiccups.  Thanks to @Jeroen88 for
finding and testing this.
2018-07-16 09:35:00 -07:00
Earle F. Philhower, III
89d2f42153
Note that CERTS.IDX file is generated on-chip (#4902)
Several users have been worried that they need to generate the IDX file,
but don't know how.  The CertStore code actually writes this file on object
creation, and the user never needs to explicitly generate or upload it.

Add a comment to the example explicitly noting this.
2018-07-08 21:54:40 -07:00
Earle F. Philhower, III
945535ae78
Make ar compatible with GNU and BSD in example (#4907)
Change the "ar" options in the example CertStore.AR archive generator to
make them compatible with both Linux and MacOS.
2018-07-08 21:12:32 -07:00
david gauchard
e486887f18
optionally allow WPS (#4889) 2018-07-06 16:45:25 +02:00
Earle F. Philhower, III
794630e068
Remove dependency on SD/SPIFFS from CertStore (#4760)
Due to popular demand, remove the hardcoded dependency on SPIFFS
or SD from the CertStore by factoring out the file interface into
a new class (CertStoreFile) that the user will need to implement
as a thin wrapper around either a SPIFFS.file or a SD.file

Combine the downloaded certificates into a UNIX "ar" archive
and parse that on-the-fly to allow easy inspection and creation
of the Cert Store database.

Examples updated with a new certificate downloader that creates
the certs.ar archive and with a single sample that can be built
for either SPIFFS or SD with a #define.  Users can copy the
implementation of the CertStoreFile they need to their own code
as it is self-contained.

Also move the CertStore to the BearSSL namespace and remove the
suffix and separate SPIFFS/SD sources.

Remove the "deep+" change from the CI build as well (no special
options needed on any PIO or makefile build).

We'll revisit the filesystem wrapper for 2.5.0, hopefully having a
unified template for both filesystem usage at a global level.  For
current users, be aware the interface may change (simplify!) in
release 2.5.0.

Fixes #4740
2018-06-12 19:06:26 -07:00
Earle F. Philhower, III
c0cfe875c2
Make BearSSL::write() blocking, match axTLS (#4804)
When a message is sent by the app that is larger than the SSL buffer,
it will take multiple TLS fragments to transfer.  Writes will loop
through and not return until either all data is transferred or there
is an error.
2018-06-12 13:18:00 -07:00
Earle F. Philhower, III
529baabef8
Return data in internal SSL buffers after close (#4756)
When the TCP socket is closed there may be some data left in the
BearSSL internal buffers which can be read by the application.

The BearSSL pump, however, would always return no data available
in the case the socket was disconnected before checking if the
SSL was in a state where the app could possibly read.

Fix by returning if the state is available, even if the connection
is gone.  Eventually no more data will become available to read
and the original -1 will be returned.

This should match the existing axTLS ::connected() behavior.
2018-05-23 08:24:34 -07:00
Earle F. Philhower, III
9b5f3c2882
Report connected when any bytes are available (#4754)
The SSL pipeline is multi-stage, and the TCP connection can go down
even though there is still data waiting to be decrypted or in the
decryption buffer.

Explicitly check that there if there can be any data made available
to the app, and if so report that we are still connected().  When
there is no data and there is no TCP connection, report disconnected.
2018-05-22 11:04:32 -07:00
Earle F. Philhower, III
e3c970210f
Add BearSSL client and server, support true bidir, lower memory, modern SSL (#4273)
BearSSL (https://www.bearssl.org) is a TLS(SSL) library written by
Thomas Pornin that is optimized for lower-memory embedded systems
like the ESP8266. It supports a wide variety of modern ciphers and
is unique in that it doesn't perform any memory allocations during
operation (which is the unfortunate bane of the current axTLS).

BearSSL is also absolutely focused on security and by default performs
all its security checks on x.509 certificates during the connection
phase (but if you want to be insecure and dangerous, that's possible
too).

While it does support unidirectional SSL buffers, like axTLS,
as implemented the ESP8266 wrappers only support bidirectional
buffers. These bidirectional buffers avoid deadlocks in protocols
which don't have well separated receive and transmit periods.

This patch adds several classes which allow connecting to TLS servers
using this library in almost the same way as axTLS:
BearSSL::WiFiClientSecure - WiFiClient that supports TLS
BearSSL::WiFiServerSecure - WiFiServer supporting TLS and client certs

It also introduces objects for PEM/DER encoded keys and certificates:
BearSSLX509List - x.509 Certificate (list) for general use
BearSSLPrivateKey - RSA or EC private key
BearSSLPublicKey - RSA or EC public key (i.e. from a public website)

Finally, it adds a Certificate Authority store object which lets
BearSSL access a set of trusted CA certificates on SPIFFS to allow it
to verify the identity of any remote site on the Internet, without
requiring RAM except for the single matching certificate.
CertStoreSPIFFSBearSSL - Certificate store utility

Client certificates are supported for the BearSSL::WiFiClientSecure, and
what's more the BearSSL::WiFiServerSecure can also *require* remote clients
to have a trusted certificate signed by a specific CA (or yourself with
self-signing CAs).

Maximum Fragment Length Negotiation probing and usage are supported, but
be aware that most sites on the Internet don't support it yet.  When
available, you can reduce the memory footprint of the SSL client or server
dramatically (i.e. down to 2-8KB vs. the ~22KB required for a full 16K
receive fragment and 512b send fragment).  You can also manually set a
smaller fragment size and guarantee at your protocol level all data will
fit within it.

Examples are included to show the usage of these new features.

axTLS has been moved to its own namespace, "axtls".  A default "using"
clause allows existing apps to run using axTLS without any changes.

The BearSSL::WiFi{client,server}Secure implements the axTLS
client/server API which lets many end user applications take advantage
of BearSSL with few or no changes.

The BearSSL static library used presently is stored at
https://github.com/earlephilhower/bearssl-esp8266 and can be built
using the standard ESP8266 toolchain.
2018-05-14 20:46:47 -07:00
Dan Worth
7820fb73a5 Added channel, ssid scan (#4636)
* Added channel, ssid scan

Overloaded scanNetworks so scan can occur on a single channel and/or for a particular ssid.

* Added parameters to scanNetworks

channel number and ssid have been added as optional parameters to the orginal scanNetworks()
2018-04-13 15:55:45 -03:00
david gauchard
b08d282673 fix connection reset by peer case (#4626)
* fix connection reset by peer case where pcb is set to null in ClientContext::_error but not reported to WiFiClient

* ClientContext: rename functions *_sent to *_acked (:sent to :ack in debug)

* use nullptr instead of 0
2018-04-11 22:25:04 -03:00
Iman Ahmadvand
241531aa4c Adding softAP SSID & PSK query API (#4138)
* softAP SSID & PSK query API added.
Signatures:
String ESP8266WiFiAP::softAPSSID() const;
String ESP8266WiFiAP::softAPPSK() const;

* Fix for proper C-style string copy

* add API to validate input ip as string
Signatures:
static bool IPAddress::isValid(const String& arg);
static bool IPAddress::isValid(const char* arg, size_t len);

* fix indentation

* fix ip string validation to use built-in implementation.
signatures:
static bool isValid(const String& arg);
static bool isValid(const char* arg);
2018-03-28 09:27:20 -03:00
Ivan Grokhotkov
95b1348a71 WiFiClient: clean up ClientContext before connecting (#4516)
Fixes https://github.com/esp8266/Arduino/issues/4497
2018-03-23 12:19:45 -03:00
Earle F. Philhower, III
42f824b2e4 Fix WebServerSecure streamFile() (#4545)
* Fix WebServerSecure streamFile()

ESP8266WebServerSecure's streamFile was using the base class' method
which did not use SSL encrypt before transmitting, leading to failure.

Add a new template method and required support for
WiFiClientSecure::write(Stream&) (using a local temp buffer since the
SSL libs do not grok Arduino Streams at all).

Fixes #4544

* Match ClientContext buffer and yield() behavior

ClientContext sends out 256 bytes at a time and gives a yield after
each chunk to ensure the WDT doesn't fire.  Mimic that behavior in
WiFiClientSecure::write(Stream&).
2018-03-22 00:53:37 -03:00
Harald
3267443348 Fix random crashing of ClientContext::write(Stream) and write_P(PGM_P buf, size_t size) (#2504) (#4530)
* Fix random crashing of ClientContext::write(Stream) and write_P(PGM_P buf, size_t size) (#2504)

* - Allow partial buffer release

* - Refined comments
2018-03-22 00:01:22 -03:00
Jonatan Olofsson
461c922586 Compressed dns (#3769)
* Add UdpContext seek and tell

* Add support for DNS compressed messages

* mDNS compressed pointer: Validate offset before jumping
2018-03-16 09:46:35 -03:00
Shawn A
836c7da8cc adds getautoreconnect() (#4359) 2018-03-16 01:15:30 -03:00
Shawn A
0643d6e7ab Bugfix/persistentchecks (#3798)
* persistent check fixes

fixes assumtions that persistent matches current configs, and prevents changes when such conditions exist

* oops

* fix code compliance block scoping
2018-03-08 23:55:09 -03:00
Ivan Grokhotkov
61cd8d8385 examples: format all .ino files
This formats all the example source files using Arduino style rules.
2018-03-08 14:32:06 +08:00
per1234
7999f5c29c Use correct separator in keywords.txt
The Arduino IDE currently requires the use of a tab separator between the name and identifier. Without this tab the keyword is not highlighted.

Reference:
https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5:-Library-specification#keywords
2018-03-05 15:51:14 +08:00
david gauchard
a2e7c7d016 (bool)WiFiClient needs to return ::connected() since ClientContext is not destroyed on ::stop() (#4422) 2018-03-02 20:27:08 -03:00
Ivan Grokhotkov
1349bafd83 [WIP] ESP8266WiFi: initialize new fields, remove old workaround (#4413)
* ESP8266WiFi: initialise new STA configuration fields

* ESP8266WiFi: remove workaround for wifi_station_ap_number
2018-02-28 17:21:32 -03:00
Ivan Grokhotkov
ee5a1e2804 WiFiClient: don’t destroy ClientContext on ::stop
Reported in https://github.com/esp8266/Arduino/issues/4078.

WiFiClient::stopAll, called from a WiFi disconnected event handler,
could be called while WiFiClient::connect was in progress. This issue
was initially fixed in #4194, by testing `this` pointer for being
non-null in ClientContext::connect.

This change delegates deletion of ClientContext to WiFiClient
destructor. WiFiClient::stop only calls ClientContext::stop, which
closes/aborts the connection.
2018-02-20 03:33:55 +03:00
Ivan Grokhotkov
28d8a41219 ESP8266WiFi: zero-initialise scan_config structure
Fixes #4394
2018-02-20 03:33:03 +03:00
Earle F. Philhower, III
f9ac524b13
Add -Werror to acceptance builds for C and CPP (#4369)
Use platform.local.txt to add -Werror to GCC for the build of all
code.  Any warnings on a submitted patch will cause an error.

Several examples and libraries had warnings/errors (missing returns
on functions, types, etc.).  Clean those up with this commit as well.
2018-02-17 18:47:10 -08:00
Earle F. Philhower, III
bf5a0f24dc Fix mem leak in SSL server, allow for concurrent client and server connections w/o interference (#4305)
* Fix leak on multiple SSL server connections

Fixes #4302

The refcnt setup for the WiFiClientSecure's SSLContext and ClientContext
had issues in certain conditions, causing a massive memory leak on each
SSL server connection.  Depending on the state of the machine, after two or
three connections it would OOM and crash.

This patch replaces most of the refcnt operations with C++11 shared_ptr
operations, cleaning up the code substantially and removing the leakage.

Also fixes a race condition where ClientContext was free'd before the SSLContext
was stopped/shutdown.  When the SSLContext tried to do ssl_free, axtls would
attempt to send out the real SSL disconnect bits over the wire, however by
this time the ClientContext is invalid and it would fault.

* Separate client and server SSL_CTX, support both

Refactor to use a separate client SSL_CTX and server SSL_CTX.  This
allows for separate certificates to be installed on each, and means
that you can now have both a *single* client and a *single* server
running in parallel at the same time, as they'll have separate memory
areas.

Tested using mqtt_esp8266 SSL client with a client certificate and a
WebServerSecure with its own custom certificate and key in parallel.

* Add brackets around a couple if-else clauses
2018-02-08 15:25:24 -03:00
david gauchard
64885fd5cf
minor cosmetics (dead code, -Wallextra) (#4274) 2018-02-07 01:34:46 +01:00
Earle F. Philhower, III
4c23e66bba
SSL server DEBUG, code cleanup fixes (#4280)
The server needs to load an X509 and RSA key, but instead of using
the existing loadObject() calls implemented its own.  Remove them and
use the standard ones instead.

The DEBUG_OUTPUT macro was undefined in the SSL Web server.  Add it
in do that when you compile with DEBUG=HTTP_SERVER it actually compiles.
2018-02-06 07:33:26 -08:00
Earle F. Philhower, III
c8dbfb160b Refrech api.github.com x509 certificate (#4306)
The certificate fingerprint included with the HTTPSRequest example seems
to be for an expired api.github.com certificate.  Replace with the current
one to avoid reporting "certificate mismatch" errors when running.
2018-02-06 11:06:05 -03:00
Earle F. Philhower, III
e38f19e008
Remove warnings when NDEBUG build option used (#4196)
When building using the new NDEBUG option recently added, the assert()
macro is defined to nothing. This leaves a few variables unused in the
WiFi stack causing compiler warnings. Add in empty casts to remove
these warnings. Does not affect actual assert use when NDEBUG is not
defined.
2018-02-04 20:59:31 -08:00
david gauchard
199fe0f16d
ClientContext:_write_some: release buffer once data really accepted for sending (#4265)
may fix #1872
2018-02-01 11:49:04 +01:00
NameOfTheRose
84228b1c73 Nameoftherose patch for Issue #2435 (#4256)
* WiFiTelnetToSerial Example - Minor Issues #2435

* WiFiTelnetToSerial Example - Minor Issues #2435

Patch to rectify issue #2435
2018-01-29 13:28:28 -03:00
Develo
38fe6fc488
Add timeout to WiFi connection loop in WiFiMulti (#4146) 2018-01-20 14:45:54 -03:00
david gauchard
dd00db1b8c check ClientContext's this and _pcb once out of the ::connect() delay (#4194)
fix #4078
2018-01-18 21:20:33 -03:00
Develo
b08ff10269
Rework of arduino compatibility in WiFiSTAClass::config (#4145) 2018-01-17 15:30:24 -03:00
Zandt Tittle
ca25068733 initialize io_ctx to nullptr 2018-01-12 18:39:10 +08:00
Develo
02259a412c
fixed support for psk in WiFiSTA, added support for psk to WiFiMulti, minor code cleanups (#4076) 2018-01-10 23:15:24 -03:00
Earle F. Philhower, III
bd1c7ce1dc Add SSL enabled WiFiServer, Updater, WebServer
Adds SSL server mode for WiFiServerSecure, for plain SSL connections,
ESP8266WebServerSecure, for HTTPS web serving, and SecureHTTPSUpdater for
encrypted OTA updates.

Example code is provided for all new options, as well as a BASH script for
generating their own, self-signed certificates.

Both ESP8266WebServerSecure and SecureHTTPSUpdater are important for secure
password-based authentication.  HTTP Basic Authentication, the only supported
model presently, sends the username and password in *cleartext* and therefore
should *never* be used in any un-SSL encrypted channel unless you don't mind
sharing your login and password with anyone else on the internet.  Even if the
ESP8266 is not safety critical, this cleartext broadcast could expose you should
you reuse this password elsewhere on your network or the internet.
2018-01-10 11:56:32 +08:00
Luis Carlos Becerra Rueda
8765da258b Added WifiServer::begin(uint16_t port) method, listening port can be changed at runtime (#4123) 2018-01-09 22:10:43 -03:00
david gauchard
9cfbbc7ad3 keepalive api (default 2h,75s,9 not enabled) (#3937) 2018-01-05 00:17:37 -03:00
letsbuildit
b0bb1e144f Fix issue with UdpContext.h comment (#4068) 2018-01-02 10:16:06 -03:00
Patrick José Pereira
4ab89d07fc ESP8266WiFiMulti: Add count function (#3073)
Return total number of AP added

Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
2017-12-30 13:16:47 -03:00
Rick van Schijndel
28803540a2 Added String hostname support to WiFiClient and WiFiClientSecure (#3349)
* Added String hostname support to WiFiClient and WiFiClientSecure

* Typo in WiFi
2017-12-29 01:58:36 -03:00
Hans Winzell
7dd50360b9 Fix bug in WiFiClientBasic.ino (#3902) 2017-12-28 09:47:10 -03:00
Ivan Grokhotkov
3838e58f62 WiFiClientSecure: don't use the broken max_fragment_length extension (#4033)
axTLS does not correctly implement max_fragment_length extension. This
causes servers which understand this extension (currently GnuTLS- and
WolfSSL-based) to reject the client hello.

Until this is fixed in axTLS, remove the call to enable this extension
from WiFiClientSecure.

Fixes https://github.com/esp8266/Arduino/issues/3932.
2017-12-28 01:45:49 -03:00
Ivan Grokhotkov
7fc23c6f7a WiFiUDP: fix crash when calling destinationIP with no packet available (#4036)
Fixes https://github.com/esp8266/Arduino/issues/3989.
2017-12-27 23:15:11 -03:00
Ivan Grokhotkov
fac64900dd Configurable WiFiClientSecure connect timeout, better default value (#4027)
* WiFiClientSecure: use _timeout setting when connecting

This timeout value can be customized via a call to setTimeout function.

Closes https://github.com/esp8266/Arduino/issues/3944.

* WiFiClientSecure: increase default connection timeout to 15 sec
2017-12-26 14:01:28 -03:00
Ivan Grokhotkov
ddda374985 WiFiClientSecure: don't trash unread decrypted data when writing (#4024)
* WiFiClientSecure: don't decrypt when testing for 'connected'

* WiFiClientSecure: don't trash unread decrypted data when writing

When application requests to write data, check if there is any unread
decrypted data left. If there is, don't write immediately, but save the
data to be written. When all decrypted data has been consumed by the
application, send out the saved outgoing data.

Fixes https://github.com/esp8266/Arduino/issues/2256.
2017-12-26 11:28:18 -03:00