Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: 'MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE' undeclared, while building with cmake. #6879

Closed
iammihirsig opened this issue Jan 5, 2023 · 19 comments · Fixed by #6893
Closed
Assignees
Labels

Comments

@iammihirsig
Copy link
Contributor

iammihirsig commented Jan 5, 2023

Summary

After cloning the project , when I try to build it using cmake It throws an error.

error.c:108:25: error: ‘MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE’ undeclared

System information

Mbed TLS version (number or commit id):

  • Version : Mbed TLS 3.3.0
  • Last commit 8c89224991adff88d53cd380f42a2baa36f91454

Operating system and version:

  • Operating System : Linux Mint 21 Cinnamon
  • Cinnamon version : 5.4.12
  • Kernel : 5.15.0-56-generic
  • Configuration (if not default, please attach mbedtls_config.h): Configuration is default.

Compiler and options (if you used a pre-built binary, please indicate how you obtained it):

  • None

Additional environment information:

  • None

Expected behavior

  • Build process must run successfully and produced the desired files.

Actual behavior

  • Throws an error :
/home/scorpion/Desktop/Untitled Folder/build/library/error.c:108:25: error: ‘MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE’ undeclared (first use in this function); did you mean ‘MBEDTLS_SSL_ALL_ALERT_MESSAGES’?
  108 |         if(use_ret == -(MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE))
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                         MBEDTLS_SSL_ALL_ALERT_MESSAGES
/home/scorpion/Desktop/Untitled Folder/build/library/error.c:108:25: note: each undeclared identifier is reported only once for each function it appears in
gmake[2]: *** [library/CMakeFiles/mbedcrypto.dir/build.make:551: library/CMakeFiles/mbedcrypto.dir/error.c.o] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:813: library/CMakeFiles/mbedcrypto.dir/all] Error 2
gmake: *** [Makefile:146: all] Error 2
![cmake](https://user-images.githubusercontent.com/92584041/210714678-45127b40-67d6-449a-9886-f5a7d75404fd.png)

Steps to reproduce

  • clone the repo on your local system
  • mkdir build
  • cd build
  • cmake /path/to/mbedtls/folder/
  • cmake --build .

Additional information

cmake /path/to/mbedtls/folder/ output :

Image 1

cmake --build . output :

Image 2

@tom-daubney-arm
Copy link
Contributor

tom-daubney-arm commented Jan 5, 2023

Hi @Mihir-Raj-Singh, thanks for raising an issue. I have been playing around with this today and I am really struggling to reproduce this bug. I am using Ubuntu 18.04, so I don't have access to Linux Mint however I have tested your reproduction steps with the following gcc versions: 7.5, 8.4, 9.4, 10.3 and 11.1. None of these compiler versions gave me the error you describe and the compilation completed successfully in all cases. I know you are using 11.3, so perhaps there is a specific issue with that version.

Could I ask you please switch to a different version of gcc, maybe 10.X, and then try to compile in the way you have detailed in your post?

Thanks in advance.

@iammihirsig
Copy link
Contributor Author

iammihirsig commented Jan 6, 2023

  • Thanks @tom-daubney-arm for pointing out.

  • I installed another version of gcc/g++ .

  • But can you please specify how I run cmake with another version of gcc ? (It's take 11.03 by default) I have installed gcc-10 but gcc always refers to 11.03 by default in system and also in cmake.

  • My whole system is dependent upon version 11.03. So I can't remove it.

My suggestion is that we need one more person to test it if it works or not. Maybe the problem is within my system.

@tom-daubney-arm
Copy link
Contributor

So I am not exactly sure of the proceedure in Linux Mint, however this webpage explains how it works on my machine running Ubuntu 18.04. I guess since Mint is derived from Ubuntu there is a chance that this could work on Mint as well.

Scroll down to the bottom of the webpage to the heading "Installing Multiple GCC Versions". From here you can see how the command sudo update-alternatives --config gcc works for switching out the default version of gcc on an Ubuntu system. It requires some set up commands to be run first, but this is all detailed in the linked webpage. Maybe this works on Mint, or if not you will need to find an equivalent system/command on Mint.

Please report back with your findings. Thank you.

@iammihirsig
Copy link
Contributor Author

iammihirsig commented Jan 6, 2023

Indeed , the gcc switching method works on mint .
I did try it with other older gcc versions as suggested. But still I encounter the same error.
It's not a gcc problem, I guess.

Maybe I should close this Issue ?

gcc 9
build error

@tom-daubney-arm
Copy link
Contributor

Hi @Mihir-Raj-Singh , It's possible that we will end up closing the issue but I am happy to do some more investigating first if that is possible. Could you please paste your entire cmake output, both the configuration and the actual build output as text, rather than a partial screenshot? I might be able to get a bit more information that way.

Also, have you tried cloning the project again? By that I mean does this error occur every time you try to clone the project from scratch?

@tom-daubney-arm tom-daubney-arm changed the title MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE While building with cmake. Error: 'MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE' undeclared, while building with cmake. Jan 6, 2023
@tom-daubney-arm
Copy link
Contributor

Note: Edited title to better reflect the nature of the error.

@iammihirsig
Copy link
Contributor Author

Hey @tom-daubney-arm , It's alright let's do some more investigation on this issue. Will be a great opportunity for me to learn as a beginner in programming and in open source.

I did try cloning the project from scratch , it occurs every time.

  • Here are the cmake outputs -
cmake ~/Desktop/Untitled\ Folder/mbedtls/              

-- The C compiler identification is GNU 9.5.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Found Python3: /usr/bin/python3.10 (found version "3.10.6") found components: Interpreter 
-- Performing Test C_COMPILER_SUPPORTS_WFORMAT_SIGNEDNESS
-- Performing Test C_COMPILER_SUPPORTS_WFORMAT_SIGNEDNESS - Success
-- Found Perl: /usr/bin/perl (found version "5.34.0") 
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE  
-- Configuring done
-- Generating done
-- Build files have been written to: /home/scorpion/Desktop/Untitled Folder/build

cmake --build .                              
[  0%] Building C object CMakeFiles/mbedtls_test.dir/tests/src/asn1_helpers.c.o
[  0%] Building C object CMakeFiles/mbedtls_test.dir/tests/src/bignum_helpers.c.o
[  0%] Building C object CMakeFiles/mbedtls_test.dir/tests/src/certs.c.o
[  0%] Building C object CMakeFiles/mbedtls_test.dir/tests/src/drivers/hash.c.o
[  0%] Building C object CMakeFiles/mbedtls_test.dir/tests/src/drivers/platform_builtin_keys.c.o
[  1%] Building C object CMakeFiles/mbedtls_test.dir/tests/src/drivers/test_driver_aead.c.o
[  1%] Building C object CMakeFiles/mbedtls_test.dir/tests/src/drivers/test_driver_asymmetric_encryption.c.o
[  1%] Building C object CMakeFiles/mbedtls_test.dir/tests/src/drivers/test_driver_cipher.c.o
[  1%] Building C object CMakeFiles/mbedtls_test.dir/tests/src/drivers/test_driver_key_agreement.c.o
[  1%] Building C object CMakeFiles/mbedtls_test.dir/tests/src/drivers/test_driver_key_management.c.o
[  1%] Building C object CMakeFiles/mbedtls_test.dir/tests/src/drivers/test_driver_mac.c.o
[  2%] Building C object CMakeFiles/mbedtls_test.dir/tests/src/drivers/test_driver_signature.c.o
[  2%] Building C object CMakeFiles/mbedtls_test.dir/tests/src/fake_external_rng_for_test.c.o
[  2%] Building C object CMakeFiles/mbedtls_test.dir/tests/src/helpers.c.o
[  2%] Building C object CMakeFiles/mbedtls_test.dir/tests/src/psa_crypto_helpers.c.o
[  2%] Building C object CMakeFiles/mbedtls_test.dir/tests/src/psa_exercise_key.c.o
[  2%] Building C object CMakeFiles/mbedtls_test.dir/tests/src/random.c.o
[  2%] Building C object CMakeFiles/mbedtls_test.dir/tests/src/threading_helpers.c.o
[  2%] Built target mbedtls_test
[  2%] Generating version_features.c
[  2%] Generating error.c
readline() on closed filehandle FILE at /home/scorpion/Desktop/Untitled Folder/mbedtls/library/../scripts/generate_errors.pl line 68.
Use of uninitialized value $content in pattern match (m//) at /home/scorpion/Desktop/Untitled Folder/mbedtls/library/../scripts/generate_errors.pl line 71.
[  2%] Generating psa_crypto_driver_wrappers.c
[  2%] Building C object library/CMakeFiles/mbedcrypto.dir/aes.c.o
[  3%] Building C object library/CMakeFiles/mbedcrypto.dir/aesni.c.o
[  3%] Building C object library/CMakeFiles/mbedcrypto.dir/aria.c.o
[  3%] Building C object library/CMakeFiles/mbedcrypto.dir/asn1parse.c.o
[  3%] Building C object library/CMakeFiles/mbedcrypto.dir/asn1write.c.o
[  3%] Building C object library/CMakeFiles/mbedcrypto.dir/base64.c.o
[  3%] Building C object library/CMakeFiles/mbedcrypto.dir/bignum.c.o
[  4%] Building C object library/CMakeFiles/mbedcrypto.dir/bignum_core.c.o
[  4%] Building C object library/CMakeFiles/mbedcrypto.dir/bignum_mod.c.o
[  4%] Building C object library/CMakeFiles/mbedcrypto.dir/bignum_mod_raw.c.o
[  4%] Building C object library/CMakeFiles/mbedcrypto.dir/camellia.c.o
[  4%] Building C object library/CMakeFiles/mbedcrypto.dir/ccm.c.o
[  4%] Building C object library/CMakeFiles/mbedcrypto.dir/chacha20.c.o
[  4%] Building C object library/CMakeFiles/mbedcrypto.dir/chachapoly.c.o
[  5%] Building C object library/CMakeFiles/mbedcrypto.dir/cipher.c.o
[  5%] Building C object library/CMakeFiles/mbedcrypto.dir/cipher_wrap.c.o
[  5%] Building C object library/CMakeFiles/mbedcrypto.dir/constant_time.c.o
[  5%] Building C object library/CMakeFiles/mbedcrypto.dir/cmac.c.o
[  5%] Building C object library/CMakeFiles/mbedcrypto.dir/ctr_drbg.c.o
[  5%] Building C object library/CMakeFiles/mbedcrypto.dir/des.c.o
[  6%] Building C object library/CMakeFiles/mbedcrypto.dir/dhm.c.o
[  6%] Building C object library/CMakeFiles/mbedcrypto.dir/ecdh.c.o
[  6%] Building C object library/CMakeFiles/mbedcrypto.dir/ecdsa.c.o
[  6%] Building C object library/CMakeFiles/mbedcrypto.dir/ecjpake.c.o
[  6%] Building C object library/CMakeFiles/mbedcrypto.dir/ecp.c.o
[  6%] Building C object library/CMakeFiles/mbedcrypto.dir/ecp_curves.c.o
[  7%] Building C object library/CMakeFiles/mbedcrypto.dir/entropy.c.o
[  7%] Building C object library/CMakeFiles/mbedcrypto.dir/entropy_poll.c.o
[  7%] Building C object library/CMakeFiles/mbedcrypto.dir/error.c.o
/home/scorpion/Desktop/Untitled Folder/build/library/error.c: In function ‘mbedtls_strerror’:
/home/scorpion/Desktop/Untitled Folder/build/library/error.c:108:25: error: ‘MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE’ undeclared (first use in this function); did you mean ‘MBEDTLS_SSL_ALL_ALERT_MESSAGES’?
  108 |         if(use_ret == -(MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE))
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                         MBEDTLS_SSL_ALL_ALERT_MESSAGES
/home/scorpion/Desktop/Untitled Folder/build/library/error.c:108:25: note: each undeclared identifier is reported only once for each function it appears in
gmake[2]: *** [library/CMakeFiles/mbedcrypto.dir/build.make:551: library/CMakeFiles/mbedcrypto.dir/error.c.o] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:813: library/CMakeFiles/mbedcrypto.dir/all] Error 2
gmake: *** [Makefile:146: all] Error 2

both the configuration and the actual build output as text,

Can you please be more specific which configuration file you are talking about ? (If you need anything else let me know.)

@tom-daubney-arm
Copy link
Contributor

Thanks. The configuration output I was referring to is what you have copied over in the first block of output. Thanks for sending that.

I will also need your cmake version please

@iammihirsig
Copy link
Contributor Author

Thank you , Here you go :

cmake version 3.22.1
CMake suite maintained and supported by Kitware (kitware.com/cmake).

@gilles-peskine-arm
Copy link
Contributor

[  2%] Generating error.c
readline() on closed filehandle FILE at /home/scorpion/Desktop/Untitled Folder/mbedtls/library/../scripts/generate_errors.pl line 68.
Use of uninitialized value $content in pattern match (m//) at /home/scorpion/Desktop/Untitled Folder/mbedtls/library/../scripts/generate_errors.pl line 71.

Well, something went wrong here. Two bugs:

  1. generate_errors.pl is complaining about something. It doesn't normally do that. We need to figure out why.
  2. The error didn't stop the build. It should have.

@tom-cosgrove-arm
Copy link
Contributor

tom-cosgrove-arm commented Jan 6, 2023

readline() on closed filehandle FILE

This is because there is no check for success/failure after open(FILE, '<:crlf', "$file") at line 67 in scripts/generate_errors.pl.

Of course, the next obvious question is why did that open() fail? I'm wondering about the space in the pathname

@gilles-peskine-arm
Copy link
Contributor

why did that open() fail?

My guess is that cmake is invoking the script in the wrong directory when doing an out-of-tree build (perhaps with additional preconditions for it going wrong).

@gilles-peskine-arm
Copy link
Contributor

Note to whoever fixes that bug: if you're not familiar with perl and you prefer to rewrite the script in python, feel free.

@tom-cosgrove-arm
Copy link
Contributor

Okay, I can reproduce this with a space in the path leading to the checked-out code

@tom-cosgrove-arm
Copy link
Contributor

and the fix is

diff --git a/scripts/generate_errors.pl b/scripts/generate_errors.pl
index 5395abf41..878cfba33 100755
--- a/scripts/generate_errors.pl
+++ b/scripts/generate_errors.pl
@@ -60,11 +60,11 @@ open(FORMAT_FILE, '<:crlf', "$error_format_file") or die "Opening error format f
 my $error_format = <FORMAT_FILE>;
 close(FORMAT_FILE);
 
-my @files = <$include_dir/*.h>;
+my @files = glob qq("$include_dir/*.h");
 my @necessary_include_files;
 my @matches;
 foreach my $file (@files) {
-    open(FILE, '<:crlf', "$file");
+    open(FILE, '<:crlf', $file) or die("$0: $file: $!");
     my $content = <FILE>;
     close FILE;
     my $found = 0;

(see https://stackoverflow.com/a/32262481/7761803 for the nightmare that is globbing in Perl with spaces in paths)

@tom-cosgrove-arm
Copy link
Contributor

So to the OP: until this fix gets into the library, the workaround is not to have a directory name with a space in it in the path leading to the code (even using cmake .. rather than cmake /path/to/directory with/spaces won't work, I'm afraid, as cmake seems to expand relative paths)

@tom-daubney-arm
Copy link
Contributor

Thanks @tom-cosgrove-arm and @gilles-peskine-arm. I will raise a PR that patches the Perl script.

@iammihirsig
Copy link
Contributor Author

Thanks @tom-daubney-arm @gilles-peskine-arm @tom-cosgrove-arm For the collaboration and figuring out the problematic files.👍

tom-daubney-arm added a commit to tom-daubney-arm/mbedtls that referenced this issue Jan 9, 2023
Modify generate_errors.pl such that it can now handle
opening files where the file path includes a directory
names containing spaces.

Raised in issue Mbed-TLS#6879. Fix provided by
@tom-cosgrove-arm in aforementioned issue.

Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
tom-daubney-arm added a commit to tom-daubney-arm/mbedtls that referenced this issue Jan 9, 2023
Modify generate_errors.pl such that it can now handle
opening files where the file path includes a directory
name containing spaces.

Raised in issue Mbed-TLS#6879. Fix provided by
@tom-cosgrove-arm in aforementioned issue.

Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
tom-daubney-arm added a commit to tom-daubney-arm/mbedtls that referenced this issue Jan 9, 2023
Modify generate_errors.pl such that it can now handle
opening files where the file path includes a directory
name containing spaces.

Raised in issue Mbed-TLS#6879. Fix provided by
@tom-cosgrove-arm in aforementioned issue.

Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
AndrzejKurek pushed a commit to AndrzejKurek/mbedtls that referenced this issue Jan 17, 2023
Modify generate_errors.pl such that it can now handle
opening files where the file path includes a directory
name containing spaces.

Raised in issue Mbed-TLS#6879. Fix provided by
@tom-cosgrove-arm in aforementioned issue.

Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
@yigit-mechatnom
Copy link

and the fix is

diff --git a/scripts/generate_errors.pl b/scripts/generate_errors.pl
index 5395abf41..878cfba33 100755
--- a/scripts/generate_errors.pl
+++ b/scripts/generate_errors.pl
@@ -60,11 +60,11 @@ open(FORMAT_FILE, '<:crlf', "$error_format_file") or die "Opening error format f
 my $error_format = <FORMAT_FILE>;
 close(FORMAT_FILE);
 
-my @files = <$include_dir/*.h>;
+my @files = glob qq("$include_dir/*.h");
 my @necessary_include_files;
 my @matches;
 foreach my $file (@files) {
-    open(FILE, '<:crlf', "$file");
+    open(FILE, '<:crlf', $file) or die("$0: $file: $!");
     my $content = <FILE>;
     close FILE;
     my $found = 0;

(see https://stackoverflow.com/a/32262481/7761803 for the nightmare that is globbing in Perl with spaces in paths)

I made these changes but still the same problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
5 participants