8
8
#include " esphome/core/application.h"
9
9
#include " esphome/core/hal.h"
10
10
#include " esphome/core/util.h"
11
+ #include " esphome/components/md5/md5.h"
11
12
#include " esphome/components/network/util.h"
12
13
13
14
#include < cerrno>
14
15
#include < cstdio>
15
16
16
- #ifdef USE_OTA_PASSWORD
17
- #include < MD5Builder.h>
18
- #endif
19
-
20
17
namespace esphome {
21
18
namespace ota {
22
19
@@ -173,12 +170,12 @@ void OTAComponent::handle_() {
173
170
if (!this ->password_ .empty ()) {
174
171
buf[0 ] = OTA_RESPONSE_REQUEST_AUTH;
175
172
this ->writeall_ (buf, 1 );
176
- MD5Builder md5_builder {};
177
- md5_builder. begin ();
173
+ md5::MD5Digest md5 {};
174
+ md5. init ();
178
175
sprintf (sbuf, " %08X" , random_uint32 ());
179
- md5_builder .add (sbuf);
180
- md5_builder .calculate ();
181
- md5_builder. getChars (sbuf);
176
+ md5 .add (sbuf, 8 );
177
+ md5 .calculate ();
178
+ md5. get_hex (sbuf);
182
179
ESP_LOGV (TAG, " Auth: Nonce is %s" , sbuf);
183
180
184
181
// Send nonce, 32 bytes hex MD5
@@ -188,10 +185,10 @@ void OTAComponent::handle_() {
188
185
}
189
186
190
187
// prepare challenge
191
- md5_builder. begin ();
192
- md5_builder .add (this ->password_ .c_str ());
188
+ md5. init ();
189
+ md5 .add (this ->password_ .c_str (), this -> password_ . length ());
193
190
// add nonce
194
- md5_builder .add (sbuf);
191
+ md5 .add (sbuf, 32 );
195
192
196
193
// Receive cnonce, 32 bytes hex MD5
197
194
if (!this ->readall_ (buf, 32 )) {
@@ -201,11 +198,11 @@ void OTAComponent::handle_() {
201
198
sbuf[32 ] = ' \0 ' ;
202
199
ESP_LOGV (TAG, " Auth: CNonce is %s" , sbuf);
203
200
// add cnonce
204
- md5_builder .add (sbuf);
201
+ md5 .add (sbuf, 32 );
205
202
206
203
// calculate result
207
- md5_builder .calculate ();
208
- md5_builder. getChars (sbuf);
204
+ md5 .calculate ();
205
+ md5. get_hex (sbuf);
209
206
ESP_LOGV (TAG, " Auth: Result is %s" , sbuf);
210
207
211
208
// Receive result, 32 bytes hex MD5
0 commit comments