hannestschofenig / mbedtls

An open source, portable, easy to use, readable and flexible SSL library
https://tls.mbed.org
Apache License 2.0
15 stars 8 forks source link

Fix compiler error when ALPN is enabled in server. #390

Closed lhuang04 closed 2 years ago

lhuang04 commented 2 years ago

Summary: Fix the following error when I enable ALPN.

diff --git a/include/mbedtls/mbedtls_config.h b/include/mbedtls/mbedtls_config.h
index 9d0f5f070..31bc3270c 100644
--- a/include/mbedtls/mbedtls_config.h
+++ b/include/mbedtls/mbedtls_config.h
@@ -1585,7 +1585,7 @@
  *
  * Comment this macro to disable support for ALPN.
  */
-//#define MBEDTLS_SSL_ALPN
+#define MBEDTLS_SSL_ALPN

 /**
  * \def MBEDTLS_SSL_DTLS_ANTI_REPLAY
[ 33%] Linking C executable crl_app
/home/lhuang04/upstream/library/ssl_tls13_server.c: In function ‘ssl_parse_alpn_ext’:
/home/lhuang04/upstream/library/ssl_tls13_server.c:1313:29: error: expected ‘;’ before ‘const’
     const unsigned char *end const = buf + len;
                             ^~~~~~
                             ;
/home/lhuang04/upstream/library/ssl_tls13_server.c:1313:36: error: expected identifier or ‘(’ before ‘=’ token
     const unsigned char *end const = buf + len;
                                    ^
/home/lhuang04/upstream/library/ssl_tls13_server.c:1342:36: error: ‘end’ undeclared (first use in this function)
     for( cur_cli = buf; cur_cli != end; cur_cli += cur_cli_len )
                                    ^~~
/home/lhuang04/upstream/library/ssl_tls13_server.c:1342:36: note: each undeclared identifier is reported only once for each function it appears in
/home/lhuang04/upstream/library/ssl_tls13_server.c:1360:45: error: ‘cur_len’ undeclared (first use in this function); did you mean ‘cur_cli’?
                 memcmp( cur_cli, *cur_ours, cur_len ) == 0 )
                                             ^~~~~~~
                                             cur_cli
[ 33%] Linking C executable req_app
/home/lhuang04/upstream/library/ssl_tls13_server.c: In function ‘ssl_client_hello_parse’:
/home/lhuang04/upstream/library/ssl_tls13_server.c:2604:55: error: ‘ALPN_EXTENSION’ undeclared (first use in this function)
                 ssl->handshake->extensions_present |= ALPN_EXTENSION;
                                                       ^~~~~~~~~~~~~~
/home/lhuang04/upstream/library/ssl_tls13_server.c: In function ‘ssl_write_alpn_ext’:
/home/lhuang04/upstream/library/ssl_tls13_server.c:2907:48: error: ‘ALPN_EXTENSION’ undeclared (first use in this function)
     if( ( ssl->handshake->extensions_present & ALPN_EXTENSION ) == 0 ||
                                                ^~~~~~~~~~~~~~
[ 34%] Linking C executable cert_req
make[2]: *** [library/CMakeFiles/mbedtls.dir/build.make:258: library/CMakeFiles/mbedtls.dir/ssl_tls13_server.c.o] Error 1
make[2]: *** Waiting for unfinished jobs....

Test Plan:

tests/ssl-opt.sh -p -s -f "TLS 1.3, ALPN" 

Reviewers:

Subscribers:

Tasks:

Tags:

Notes:

Status

READY/IN DEVELOPMENT/HOLD

Requires Backporting

When there is a bug fix, it should be backported to all maintained and supported branches. Changes do not have to be backported if:

Yes | NO
Which branch?

Migrations

If there is any API change, what's the incentive and logic for it.

YES | NO

Additional comments

Any additional information that could be of interest

Todos

Steps to test or reproduce

Outline the steps to test or reproduce the PR here.

hannestschofenig commented 2 years ago

This PR looks good to me.

hannestschofenig commented 2 years ago

How is this PR related to https://github.com/ARMmbed/mbedtls/pull/5448?

lhuang04 commented 2 years ago

How is this PR related to ARMmbed#5448?

This one is to fix a ALPN compile error for mbedtls server. ARMmbed#5448 is for client. ARMmbed#5448 is a PR to port something that is working in tls13-prototype to development.