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

can't build with mbedtls 3.x #125

Open
evilsocket opened this issue Nov 12, 2022 · 8 comments
Open

can't build with mbedtls 3.x #125

evilsocket opened this issue Nov 12, 2022 · 8 comments

Comments

@evilsocket
Copy link

Hi, apologies if this is documented somewhere, I tried to look for macOS installation instructions with no luck.

I downloaded the v2.3.0 version of the code and tried to use the macos/build.sh, however I got this message:

cc -Os -Wall -Wwrite-strings -pedantic -std=gnu99 -I/usr/local/include  -DLPD -DBOB -DDNS -DTLS -c -o build/main.o src/main.c
cc -Os -Wall -Wwrite-strings -pedantic -std=gnu99 -I/usr/local/include  -DLPD -DBOB -DDNS -DTLS -c -o build/searches.o src/searches.c
cc -Os -Wall -Wwrite-strings -pedantic -std=gnu99 -I/usr/local/include  -DLPD -DBOB -DDNS -DTLS -c -o build/kad.o src/kad.c
cc -Os -Wall -Wwrite-strings -pedantic -std=gnu99 -I/usr/local/include  -DLPD -DBOB -DDNS -DTLS -c -o build/log.o src/log.c
cc -Os -Wall -Wwrite-strings -pedantic -std=gnu99 -I/usr/local/include  -DLPD -DBOB -DDNS -DTLS -c -o build/conf.o src/conf.c
cc -Os -Wall -Wwrite-strings -pedantic -std=gnu99 -I/usr/local/include  -DLPD -DBOB -DDNS -DTLS -c -o build/net.o src/net.c
cc -Os -Wall -Wwrite-strings -pedantic -std=gnu99 -I/usr/local/include  -DLPD -DBOB -DDNS -DTLS -c -o build/utils.o src/utils.c
cc -Os -Wall -Wwrite-strings -pedantic -std=gnu99 -I/usr/local/include  -DLPD -DBOB -DDNS -DTLS -c -o build/announces.o src/announces.c
cc -Os -Wall -Wwrite-strings -pedantic -std=gnu99 -I/usr/local/include  -DLPD -DBOB -DDNS -DTLS -c -o build/peerfile.o src/peerfile.c
cc -Os -Wall -Wwrite-strings -pedantic -std=gnu99 -I/usr/local/include  -DLPD -DBOB -DDNS -DTLS -c -o build/unix.o src/unix.c
cc -Os -Wall -Wwrite-strings -pedantic -std=gnu99 -I/usr/local/include  -DLPD -DBOB -DDNS -DTLS -c -o build/ext-lpd.o src/ext-lpd.c
cc -Os -Wall -Wwrite-strings -pedantic -std=gnu99 -I/usr/local/include  -DLPD -DBOB -DDNS -DTLS -c -o build/ext-bob.o src/ext-bob.c
src/ext-bob.c:9:10: fatal error: 'mbedtls/platform.h' file not found
#include "mbedtls/platform.h"

However I did install mbedtls with brew, in fact all I needed to do in order to fix this specific error was:

sudo ln -s /opt/homebrew/include /usr/local/include

Suggesting that the script doesn't take into account brew installed dependencies (or that my brew env is somehow very broken, but i don't think, it's relatively clean and new).

Now I'm getting another compilation error related to mbedtls:

cc -Os -Wall -Wwrite-strings -pedantic -std=gnu99 -I/usr/local/include  -DLPD -DBOB -DDNS -DTLS -c -o build/main.o src/main.c
cc -Os -Wall -Wwrite-strings -pedantic -std=gnu99 -I/usr/local/include  -DLPD -DBOB -DDNS -DTLS -c -o build/searches.o src/searches.c
cc -Os -Wall -Wwrite-strings -pedantic -std=gnu99 -I/usr/local/include  -DLPD -DBOB -DDNS -DTLS -c -o build/kad.o src/kad.c
cc -Os -Wall -Wwrite-strings -pedantic -std=gnu99 -I/usr/local/include  -DLPD -DBOB -DDNS -DTLS -c -o build/log.o src/log.c
cc -Os -Wall -Wwrite-strings -pedantic -std=gnu99 -I/usr/local/include  -DLPD -DBOB -DDNS -DTLS -c -o build/conf.o src/conf.c
cc -Os -Wall -Wwrite-strings -pedantic -std=gnu99 -I/usr/local/include  -DLPD -DBOB -DDNS -DTLS -c -o build/net.o src/net.c
cc -Os -Wall -Wwrite-strings -pedantic -std=gnu99 -I/usr/local/include  -DLPD -DBOB -DDNS -DTLS -c -o build/utils.o src/utils.c
cc -Os -Wall -Wwrite-strings -pedantic -std=gnu99 -I/usr/local/include  -DLPD -DBOB -DDNS -DTLS -c -o build/announces.o src/announces.c
cc -Os -Wall -Wwrite-strings -pedantic -std=gnu99 -I/usr/local/include  -DLPD -DBOB -DDNS -DTLS -c -o build/peerfile.o src/peerfile.c
cc -Os -Wall -Wwrite-strings -pedantic -std=gnu99 -I/usr/local/include  -DLPD -DBOB -DDNS -DTLS -c -o build/unix.o src/unix.c
cc -Os -Wall -Wwrite-strings -pedantic -std=gnu99 -I/usr/local/include  -DLPD -DBOB -DDNS -DTLS -c -o build/ext-lpd.o src/ext-lpd.c
cc -Os -Wall -Wwrite-strings -pedantic -std=gnu99 -I/usr/local/include  -DLPD -DBOB -DDNS -DTLS -c -o build/ext-bob.o src/ext-bob.c
src/ext-bob.c:116:13: error: no member named 'p' in 'struct mbedtls_mpi'
        if (grp->A.p == NULL) {
            ~~~~~~ ^
src/ext-bob.c:210:65: error: no member named 'Q' in 'struct mbedtls_ecp_keypair'
        mbedtls_mpi_write_binary(&mbedtls_pk_ec(resource->ctx_verify)->Q.X, buf + 3, ECPARAMS_SIZE);
                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  ^
src/ext-bob.c:259:10: error: no member named 'grp' in 'struct mbedtls_ecp_keypair'
                                &kp->grp, compressed, sizeof(compressed),
                                 ~~  ^
src/ext-bob.c:268:10: error: no member named 'grp' in 'struct mbedtls_ecp_keypair'
                                &kp->grp, &kp->Q,
                                 ~~  ^
src/ext-bob.c:268:20: error: no member named 'Q' in 'struct mbedtls_ecp_keypair'
                                &kp->grp, &kp->Q,
                                           ~~  ^
src/ext-bob.c:325:49: error: no member named 'Q' in 'struct mbedtls_ecp_keypair'
        mbedtls_mpi_write_binary(&mbedtls_pk_ec(*ctx)->Q.X, buf, sizeof(buf));
                                  ~~~~~~~~~~~~~~~~~~~  ^
src/ext-bob.c:366:52: error: no member named 'Q' in 'struct mbedtls_ecp_keypair'
        } while (mbedtls_mpi_get_bit(&mbedtls_pk_ec(ctx)->Q.Y, 0) != 0);
                                      ~~~~~~~~~~~~~~~~~~  ^
src/ext-bob.c:387:54: error: too few arguments to function call, expected 5, have 3
        if ((ret = mbedtls_pk_parse_keyfile(&ctx, path, NULL)) != 0) {
                   ~~~~~~~~~~~~~~~~~~~~~~~~                 ^
/usr/local/include/mbedtls/pk.h:847:5: note: 'mbedtls_pk_parse_keyfile' declared here
int mbedtls_pk_parse_keyfile( mbedtls_pk_context *ctx,
    ^
src/ext-bob.c:394:26: error: no member named 'grp' in 'struct mbedtls_ecp_keypair'
        if (mbedtls_pk_ec(ctx)->grp.id != ECPARAMS) {
            ~~~~~~~~~~~~~~~~~~  ^
src/ext-bob.c:396:59: error: no member named 'grp' in 'struct mbedtls_ecp_keypair'
                        mbedtls_ecp_curve_info_from_grp_id(mbedtls_pk_ec(ctx)->grp.id)->name,
                                                           ~~~~~~~~~~~~~~~~~~  ^
src/log.h:16:22: note: expanded from macro 'log_error'
  log_print(LOG_ERR, __VA_ARGS__);
                     ^~~~~~~~~~~
src/ext-bob.c:477:59: error: no member named 'Q' in 'struct mbedtls_ecp_keypair'
                mbedtls_mpi_write_binary(&mbedtls_pk_ec(key->ctx_sign)->Q.X, epkey, ECPARAMS_SIZE);
                                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~  ^
src/ext-bob.c:507:56: error: too few arguments to function call, expected 9, have 8
                        sig + 3, &slen, mbedtls_ctr_drbg_random, &g_ctr_drbg);
                                                                            ^
/usr/local/include/mbedtls/ecdsa.h:307:5: note: 'mbedtls_ecdsa_write_signature' declared here
int mbedtls_ecdsa_write_signature( mbedtls_ecdsa_context *ctx,
    ^
src/ext-bob.c:584:64: error: no member named 'grp' in 'struct mbedtls_ecp_keypair'
                mbedtls_ecp_group_load(&mbedtls_pk_ec(resource->ctx_verify)->grp, ECPARAMS);
                                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  ^

It seems that the source is based on another version of the library, which is not indicated anywhere in the docs unless I've missed something.

macOS v12.6 (Monterey) running on M1
XCode tools installed
brew installed
mbedtls v3.2.1 installed via brew

How do I build this thing on macOS? :)

Thanks

@mwarning
Copy link
Owner

I successfully tried mbedtls-2.16.12 and will try with 3.2.1 later today.

@mwarning
Copy link
Owner

mwarning commented Nov 13, 2022

mbedtls 3.0.0 made some fields private. We need to find a workaround.

@evilsocket
Copy link
Author

I've managed to build it by downgrading to 2.28.1 ( brew install mbedtls@2 ) and creating the following symlinks:

sudo ln -s /opt/homebrew/opt/mbedtls@2/include/mbedtls /usr/local/include/
sudo ln -s /opt/homebrew/opt/mbedtls@2/lib/*.* /usr/local/lib/

@mwarning
Copy link
Owner

homebrew is kind of special. I think brew link mbedtls would do the linking for you.

@evilsocket evilsocket changed the title can't build on macos with macos/build.sh can't build with mbedtls 3.x Nov 13, 2022
@mwarning
Copy link
Owner

FYI, this will help: Mbed-TLS/mbedtls#6282

@neheb
Copy link

neheb commented May 14, 2024

src/ext-bob.c: In function 'mbedtls_ecp_decompress':
src/ext-bob.c:116:19: error: 'mbedtls_mpi' has no member named 'p'
  116 |         if (grp->A.p == NULL) {
      |                   ^
src/ext-bob.c: In function 'bob_send_challenge':
src/ext-bob.c:210:70: error: 'mbedtls_ecp_keypair' has no member named 'Q'
  210 |         mbedtls_mpi_write_binary(&mbedtls_pk_ec(resource->ctx_verify)->Q.X, buf + 3, ECPARAMS_SIZE);
      |                                                                      ^~
src/ext-bob.c: In function 'bob_trigger_auth':
src/ext-bob.c:259:36: error: 'mbedtls_ecp_keypair' has no member named 'grp'
  259 |                                 &kp->grp, compressed, sizeof(compressed),
      |                                    ^~
src/ext-bob.c:268:36: error: 'mbedtls_ecp_keypair' has no member named 'grp'
  268 |                                 &kp->grp, &kp->Q,
      |                                    ^~
src/ext-bob.c:268:46: error: 'mbedtls_ecp_keypair' has no member named 'Q'
  268 |                                 &kp->grp, &kp->Q,
      |                                              ^~
src/ext-bob.c: In function 'get_pkey_base32hex':
src/ext-bob.c:325:54: error: 'mbedtls_ecp_keypair' has no member named 'Q'
  325 |         mbedtls_mpi_write_binary(&mbedtls_pk_ec(*ctx)->Q.X, buf, sizeof(buf));
      |                                                      ^~
src/ext-bob.c: In function 'bob_create_key':
src/ext-bob.c:366:57: error: 'mbedtls_ecp_keypair' has no member named 'Q'
  366 |         } while (mbedtls_mpi_get_bit(&mbedtls_pk_ec(ctx)->Q.Y, 0) != 0);
      |                                                         ^~
src/ext-bob.c: In function 'bob_load_key':
src/ext-bob.c:387:20: error: too few arguments to function 'mbedtls_pk_parse_keyfile'
  387 |         if ((ret = mbedtls_pk_parse_keyfile(&ctx, path, NULL)) != 0) {
      |                    ^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /home/mangix/devstuff/openwrt/staging_dir/target-i386_pentium-mmx_musl/usr/include/mbedtls/x509.h:17,
                 from src/ext-bob.c:15:
/home/mangix/devstuff/openwrt/staging_dir/target-i386_pentium-mmx_musl/usr/include/mbedtls/pk.h:1166:5: note: declared here
 1166 | int mbedtls_pk_parse_keyfile(mbedtls_pk_context *ctx,
      |     ^~~~~~~~~~~~~~~~~~~~~~~~
src/ext-bob.c:394:31: error: 'mbedtls_ecp_keypair' has no member named 'grp'
  394 |         if (mbedtls_pk_ec(ctx)->grp.id != ECPARAMS) {
      |                               ^~
In file included from src/ext-bob.c:19:
src/ext-bob.c:396:78: error: 'mbedtls_ecp_keypair' has no member named 'grp'
  396 |                         mbedtls_ecp_curve_info_from_grp_id(mbedtls_pk_ec(ctx)->grp.id)->name,
      |                                                                              ^~
src/log.h:16:22: note: in definition of macro 'log_error'
   16 |   log_print(LOG_ERR, __VA_ARGS__);
      |                      ^~~~~~~~~~~
src/ext-bob.c: In function 'bob_find_key':
src/ext-bob.c:477:71: error: 'mbedtls_ecp_keypair' has no member named 'Q'
  477 |                 mbedtls_mpi_write_binary(&mbedtls_pk_ec(key->ctx_sign)->Q.X, epkey, ECPARAMS_SIZE);
      |                                                                       ^~
src/ext-bob.c: In function 'bob_encrypt_challenge':
src/ext-bob.c:507:34: error: passing argument 6 of 'mbedtls_ecdsa_write_signature' makes integer from pointer without a cast [-Wint-conversion]
  507 |                         sig + 3, &slen, mbedtls_ctr_drbg_random, &g_ctr_drbg);
      |                                  ^~~~~
      |                                  |
      |                                  size_t * {aka unsigned int *}
In file included from src/ext-bob.c:12:
/home/mangix/devstuff/openwrt/staging_dir/target-i386_pentium-mmx_musl/usr/include/mbedtls/ecdsa.h:475:62: note: expected 'size_t' {aka 'unsigned int'} but argument is of type 'size_t *' {aka 'unsigned int *'}
  475 |                                   unsigned char *sig, size_t sig_size, size_t *slen,
      |                                                       ~~~~~~~^~~~~~~~
src/ext-bob.c:507:41: error: passing argument 7 of 'mbedtls_ecdsa_write_signature' from incompatible pointer type [-Wincompatible-pointer-types]
  507 |                         sig + 3, &slen, mbedtls_ctr_drbg_random, &g_ctr_drbg);
      |                                         ^~~~~~~~~~~~~~~~~~~~~~~
      |                                         |
      |                                         int (*)(void *, unsigned char *, size_t) {aka int (*)(void *, unsigned char *, unsigned int)}
/home/mangix/devstuff/openwrt/staging_dir/target-i386_pentium-mmx_musl/usr/include/mbedtls/ecdsa.h:475:80: note: expected 'size_t *' {aka 'unsigned int *'} but argument is of type 'int (*)(void *, unsigned char *, size_t)' {aka 'int (*)(void *, unsigned char *, unsigned int)'}
  475 |                                   unsigned char *sig, size_t sig_size, size_t *slen,
      |                                                                        ~~~~~~~~^~~~
src/ext-bob.c:507:66: error: passing argument 8 of 'mbedtls_ecdsa_write_signature' from incompatible pointer type [-Wincompatible-pointer-types]
  507 |                         sig + 3, &slen, mbedtls_ctr_drbg_random, &g_ctr_drbg);
      |                                                                  ^~~~~~~~~~~
      |                                                                  |
      |                                                                  mbedtls_ctr_drbg_context *
/home/mangix/devstuff/openwrt/staging_dir/target-i386_pentium-mmx_musl/usr/include/mbedtls/ecdsa.h:476:41: note: expected 'int (*)(void *, unsigned char *, size_t)' {aka 'int (*)(void *, unsigned char *, unsigned int)'} but argument is of type 'mbedtls_ctr_drbg_context *'
  476 |                                   int (*f_rng)(void *, unsigned char *, size_t),
      |                                   ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/ext-bob.c:504:23: error: too few arguments to function 'mbedtls_ecdsa_write_signature'
  504 |                 ret = mbedtls_ecdsa_write_signature(
      |                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/mangix/devstuff/openwrt/staging_dir/target-i386_pentium-mmx_musl/usr/include/mbedtls/ecdsa.h:472:5: note: declared here
  472 | int mbedtls_ecdsa_write_signature(mbedtls_ecdsa_context *ctx,
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/ext-bob.c: In function 'bob_setup':
src/ext-bob.c:584:76: error: 'mbedtls_ecp_keypair' has no member named 'grp'
  584 |                 mbedtls_ecp_group_load(&mbedtls_pk_ec(resource->ctx_verify)->grp, ECPARAMS);
      |                                                                            ^~
make[3]: *** [Makefile:81: build/ext-bob.o] Error 1
make[3]: Leaving directory '/home/mangix/devstuff/openwrt/build_dir/target-i386_pentium-mmx_musl/KadNode-2.3.0'

@mwarning
Copy link
Owner

mwarning commented May 15, 2024

Hi @neheb. KadNode does not support mbedtls 3.x yet. If OpenWrt wants to update, then I suggest to remove the KadeNode package for now.

@neheb
Copy link

neheb commented May 15, 2024

mbedtls 3.6 is in master.

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

No branches or pull requests

3 participants