22
22
You should have received a copy of the GNU Lesser General Public License along with this library;
23
23
if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
24
25
- Version: 1.4.1
25
+ Version: 1.5.0
26
26
27
27
Version Modified By Date Comments
28
28
------- ----------- ---------- -----------
32
32
1.3.0 K Hoang 23/10/2021 Making compatible with breaking core v2.0.0+
33
33
1.4.0 K Hoang 27/11/2021 Auto detect ESP32 core version
34
34
1.4.1 K Hoang 29/11/2021 Fix bug in examples to reduce connection time
35
+ 1.5.0 K Hoang 01/10/2022 Fix AsyncWebSocket bug
35
36
*****************************************************************************************************************************/
36
37
37
38
#include " Arduino.h"
38
39
#include " AsyncWebSocket.h"
39
40
40
41
#include < libb64/cencode.h>
41
42
42
- extern " C"
43
- {
44
- typedef struct
45
- {
46
- uint32_t state[5 ];
47
- uint32_t count[2 ];
48
- unsigned char buffer[64 ];
49
- } SHA1_CTX;
50
-
51
- void SHA1Transform (uint32_t state[5 ], const unsigned char buffer[64 ]);
52
- void SHA1Init (SHA1_CTX* context);
53
- void SHA1Update (SHA1_CTX* context, const unsigned char * data, uint32_t len);
54
- void SHA1Final (unsigned char digest[20 ], SHA1_CTX* context);
55
- }
43
+ #include " Crypto/sha1.h"
44
+ #include " Crypto/Hash.h"
56
45
57
46
#define MAX_PRINTF_LEN 64
58
47
@@ -1653,13 +1642,13 @@ AsyncWebSocket::AsyncWebSocketClientLinkedList AsyncWebSocket::getClients() cons
1653
1642
Authentication code from https://github.com/Links2004/arduinoWebSockets/blob/master/src/WebSockets.cpp#L480
1654
1643
*/
1655
1644
1656
- AsyncWebSocketResponse::AsyncWebSocketResponse (const String& key, AsyncWebSocket *server)
1645
+ AsyncWebSocketResponse::AsyncWebSocketResponse (const String & key, AsyncWebSocket * server)
1657
1646
{
1658
1647
_server = server;
1659
1648
_code = 101 ;
1660
1649
_sendContentLength = false ;
1661
1650
1662
- uint8_t * hash = (uint8_t *)malloc (20 );
1651
+ uint8_t * hash = (uint8_t *) malloc (HASH_BUFFER_SIZE );
1663
1652
1664
1653
if (hash == NULL )
1665
1654
{
@@ -1676,23 +1665,29 @@ AsyncWebSocketResponse::AsyncWebSocketResponse(const String& key, AsyncWebSocket
1676
1665
return ;
1677
1666
}
1678
1667
1679
- (String&)key += WS_STR_UUID;
1680
- SHA1_CTX ctx;
1681
- SHA1Init (&ctx);
1682
- SHA1Update (&ctx, (const unsigned char *)key.c_str (), key.length ());
1683
- SHA1Final (hash, &ctx);
1668
+ sha1_context _ctx;
1669
+
1670
+ (String&) key += WS_STR_UUID;
1671
+
1672
+ sha1_starts (&_ctx);
1673
+ sha1_update (&_ctx, (const unsigned char *) key.c_str (), key.length ());
1674
+ sha1_finish (&_ctx, hash);
1675
+ // ////
1684
1676
1685
1677
base64_encodestate _state;
1686
1678
base64_init_encodestate (&_state);
1687
- int len = base64_encode_block ((const char *) hash, 20 , buffer, &_state);
1679
+ int len = base64_encode_block ((const char *) hash, HASH_BUFFER_SIZE , buffer, &_state);
1688
1680
len = base64_encode_blockend ((buffer + len), &_state);
1681
+
1689
1682
addHeader (WS_STR_CONNECTION, WS_STR_UPGRADE);
1690
1683
addHeader (WS_STR_UPGRADE, " websocket" );
1691
1684
addHeader (WS_STR_ACCEPT, buffer);
1685
+
1692
1686
free (buffer);
1693
1687
free (hash);
1694
1688
}
1695
1689
1690
+
1696
1691
void AsyncWebSocketResponse::_respond (AsyncWebServerRequest *request)
1697
1692
{
1698
1693
if (_state == RESPONSE_FAILED)
0 commit comments