1

I'm trying to compile a C++ project on Fedora 31 and I receive this error:

[ 66%] Building CXX object proxy_ws/CMakeFiles/proxy_lws.dir/proxy_lws.cpp.o
In file included from /vagrant/include/libwebsockets.h:600,
                 from /vagrant/proxy_ws/proxy_lws_utils.hpp:12,
                 from /vagrant/proxy_ws/proxy_lws.cpp:18:
/vagrant/include/libwebsockets/lws-genhash.h:80:18: error: field ‘ctx’ has incomplete type ‘HMAC_CTX’ {aka ‘hmac_ctx_st’}
   80 |         HMAC_CTX ctx;
      |                  ^~~
In file included from /usr/include/openssl/crypto.h:25,
                 from /usr/include/openssl/comp.h:16,
                 from /usr/include/openssl/ssl.h:17,
                 from /vagrant/include/libwebsockets.h:250,
                 from /vagrant/proxy_ws/proxy_lws_utils.hpp:12,
                 from /vagrant/proxy_ws/proxy_lws.cpp:18:
/usr/include/openssl/ossl_typ.h:104:16: note: forward declaration of ‘HMAC_CTX’ {aka ‘struct hmac_ctx_st’}
  104 | typedef struct hmac_ctx_st HMAC_CTX;
      |                ^~~~~~~~~~~

Any ideas on how to fix it?

doctopus
  • 5,349
  • 8
  • 53
  • 105
  • Only one thing you can do: Find the definition of `hmac_ctx_st` and make sure included or whatever you have to do so it can be found by the compiler before it reaches `HMAC_CTX ctx;` I don't have enough information to actually be helpful, unfortunately. – user4581301 Jun 09 '20 at 02:38

1 Answers1

2

I assume you are using the latest version of the openSSL library.

Take a look at this: https://wiki.openssl.org/index.php/OpenSSL_1.1.0_Changes

The first line notes that the goal of the update API for openSSL is to make the structs more "opaque". So you may not use hmac_ctx_st directly.

Scroll a bit further down in the link provided above and you will see the following:

Application code now has to use pointers, and cannot allocate objects directly on the stack. For instance if the old code did:

BN_CTX ctx; 

You now have to do:

BN_CTX *ctx;

ctx = BN_CTX_new();
[...]
BN_CTX_free(ctx);

So this is the starting point of your problem. You most likely need to declare ctx as a pointer and allocate memory on the heap.

However be aware that you may run into more issues. Given that the whole premise of the updated library is to improve security, you must now manipulate data in that struct via "getters" and "setters".

Nimo
  • 324
  • 2
  • 15