Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
arduino-esp32
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
arduino-esp32
Commits
3d92edec
Unverified
Commit
3d92edec
authored
May 15, 2024
by
Juraj Andrássy
Committed by
GitHub
May 15, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: NetworkClientSecure - copyability improvements (#9632)
and _timeout shadowing fixed
parent
c7b98a51
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
19 deletions
+22
-19
libraries/NetworkClientSecure/src/NetworkClientSecure.cpp
libraries/NetworkClientSecure/src/NetworkClientSecure.cpp
+14
-16
libraries/NetworkClientSecure/src/NetworkClientSecure.h
libraries/NetworkClientSecure/src/NetworkClientSecure.h
+0
-3
libraries/NetworkClientSecure/src/ssl_client.cpp
libraries/NetworkClientSecure/src/ssl_client.cpp
+4
-0
libraries/NetworkClientSecure/src/ssl_client.h
libraries/NetworkClientSecure/src/ssl_client.h
+4
-0
No files found.
libraries/NetworkClientSecure/src/NetworkClientSecure.cpp
View file @
3d92edec
...
...
@@ -83,7 +83,7 @@ void NetworkClientSecure::stop() {
stop_ssl_socket
(
sslclient
.
get
());
_connected
=
false
;
_peek
=
-
1
;
sslclient
->
peek_buf
=
-
1
;
_lastReadTimeout
=
0
;
_lastWriteTimeout
=
0
;
}
...
...
@@ -134,7 +134,7 @@ int NetworkClientSecure::connect(IPAddress ip, uint16_t port, const char *host,
log_i
(
"Actual TLS start postponed."
);
}
_lastE
rror
=
ret
;
sslclient
->
last_e
rror
=
ret
;
if
(
ret
<
0
)
{
log_e
(
"start_ssl_client: connect failed: %d"
,
ret
);
...
...
@@ -175,7 +175,7 @@ int NetworkClientSecure::connect(const char *host, uint16_t port, const char *ps
}
int
ret
=
start_ssl_client
(
sslclient
.
get
(),
address
,
port
,
host
,
_timeout
,
NULL
,
false
,
NULL
,
NULL
,
pskIdent
,
psKey
,
_use_insecure
,
_alpn_protos
);
_lastE
rror
=
ret
;
sslclient
->
last_e
rror
=
ret
;
if
(
ret
<
0
)
{
log_e
(
"start_ssl_client: connect failed %d"
,
ret
);
stop
();
...
...
@@ -186,11 +186,11 @@ int NetworkClientSecure::connect(const char *host, uint16_t port, const char *ps
}
int
NetworkClientSecure
::
peek
()
{
if
(
_peek
>=
0
)
{
return
_peek
;
if
(
sslclient
->
peek_buf
>=
0
)
{
return
sslclient
->
peek_buf
;
}
_peek
=
timedRead
();
return
_peek
;
sslclient
->
peek_buf
=
timedRead
();
return
sslclient
->
peek_buf
;
}
size_t
NetworkClientSecure
::
write
(
uint8_t
data
)
{
...
...
@@ -253,9 +253,9 @@ int NetworkClientSecure::read(uint8_t *buf, size_t size) {
if
(
!
size
)
{
return
0
;
}
if
(
_peek
>=
0
)
{
buf
[
0
]
=
_peek
;
_peek
=
-
1
;
if
(
sslclient
->
peek_buf
>=
0
)
{
buf
[
0
]
=
sslclient
->
peek_buf
;
sslclient
->
peek_buf
=
-
1
;
size
--
;
avail
--
;
if
(
!
size
||
!
avail
)
{
...
...
@@ -279,7 +279,7 @@ int NetworkClientSecure::available() {
return
peek_net_receive
(
sslclient
.
get
(),
0
);
}
int
peeked
=
(
_peek
>=
0
),
res
=
-
1
;
int
peeked
=
(
sslclient
->
peek_buf
>=
0
),
res
=
-
1
;
if
(
!
_connected
)
{
return
peeked
;
}
...
...
@@ -399,11 +399,9 @@ bool NetworkClientSecure::loadPrivateKey(Stream &stream, size_t size) {
}
int
NetworkClientSecure
::
lastError
(
char
*
buf
,
const
size_t
size
)
{
if
(
!
_lastError
)
{
return
0
;
}
mbedtls_strerror
(
_lastError
,
buf
,
size
);
return
_lastError
;
int
lastError
=
sslclient
->
last_error
;
mbedtls_strerror
(
lastError
,
buf
,
size
);
return
lastError
;
}
void
NetworkClientSecure
::
setHandshakeTimeout
(
unsigned
long
handshake_timeout
)
{
...
...
libraries/NetworkClientSecure/src/NetworkClientSecure.h
View file @
3d92edec
...
...
@@ -30,9 +30,6 @@ class NetworkClientSecure : public NetworkClient {
protected:
std
::
shared_ptr
<
sslclient_context
>
sslclient
;
int
_lastError
=
0
;
int
_peek
=
-
1
;
int
_timeout
;
bool
_use_insecure
;
bool
_stillinPlainStart
=
false
;
const
char
*
_CA_cert
;
...
...
libraries/NetworkClientSecure/src/ssl_client.cpp
View file @
3d92edec
...
...
@@ -48,6 +48,7 @@ void ssl_init(sslclient_context *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
);
ssl_client
->
peek_buf
=
-
1
;
}
int
start_ssl_client
(
...
...
@@ -368,12 +369,15 @@ void stop_ssl_socket(sslclient_context *ssl_client) {
// save only interesting fields
int
handshake_timeout
=
ssl_client
->
handshake_timeout
;
int
socket_timeout
=
ssl_client
->
socket_timeout
;
int
last_err
=
ssl_client
->
last_error
;
// reset embedded pointers to zero
memset
(
ssl_client
,
0
,
sizeof
(
sslclient_context
));
ssl_client
->
handshake_timeout
=
handshake_timeout
;
ssl_client
->
socket_timeout
=
socket_timeout
;
ssl_client
->
last_error
=
last_err
;
ssl_client
->
peek_buf
=
-
1
;
}
int
data_to_read
(
sslclient_context
*
ssl_client
)
{
...
...
libraries/NetworkClientSecure/src/ssl_client.h
View file @
3d92edec
...
...
@@ -26,6 +26,10 @@ typedef struct sslclient_context {
unsigned
long
socket_timeout
;
unsigned
long
handshake_timeout
;
int
last_error
;
int
peek_buf
;
}
sslclient_context
;
void
ssl_init
(
sslclient_context
*
ssl_client
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment