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

Compilation error: dereferencing pointer to incomplete type ‘RSA {aka struct rsa_st}’ #129

Open
matthiasbock opened this issue Apr 24, 2017 · 10 comments

Comments

@matthiasbock
Copy link

Sorry, the previously reported issue vysheng/tg#1338 is actually located in this repository.

The problem was:
I was trying to compile vysheng/tg@6547c0b,
but got the following error:

$ ./configure && make
...
gcc -I. -I. -I./tgl -g -O2  -I/usr/local/include -I/usr/include -I/usr/include -I/usr/include/lua5.2  -DHAVE_CONFIG_H -Wall -Werror -Wextra -Wno-missing-field-initializers -Wno-deprecated-declarations -fno-strict-aliasing -fno-omit-frame-pointer -ggdb -Wno-unused-parameter -fPIC -iquote ./tgl -c -MP -MD -MF dep/crypto/sha_openssl.d -MQ objs/crypto/sha_openssl.o -o objs/crypto/sha_openssl.o tgl/crypto/sha_openssl.c
gcc -I. -I. -I./tgl -g -O2  -I/usr/local/include -I/usr/include -I/usr/include -I/usr/include/lua5.2  -DHAVE_CONFIG_H -Wall -Werror -Wextra -Wno-missing-field-initializers -Wno-deprecated-declarations -fno-strict-aliasing -fno-omit-frame-pointer -ggdb -Wno-unused-parameter -fPIC -iquote ./tgl -c -MP -MD -MF dep/crypto/sha_altern.d -MQ objs/crypto/sha_altern.o -o objs/crypto/sha_altern.o tgl/crypto/sha_altern.c
gcc -I. -I. -I./tgl -g -O2  -I/usr/local/include -I/usr/include -I/usr/include -I/usr/include/lua5.2  -DHAVE_CONFIG_H -Wall -Werror -Wextra -Wno-missing-field-initializers -Wno-deprecated-declarations -fno-strict-aliasing -fno-omit-frame-pointer -ggdb -Wno-unused-parameter -fPIC -iquote ./tgl -c -MP -MD -MF dep/crypto/aes_openssl.d -MQ objs/crypto/aes_openssl.o -o objs/crypto/aes_openssl.o tgl/crypto/aes_openssl.c
tgl/crypto/rsa_pem_openssl.c: In function ‘TGLC_rsa_new’:
tgl/crypto/rsa_pem_openssl.c:41:6: error: dereferencing pointer to incomplete type ‘RSA {aka struct rsa_st}’
   ret->e = unwrap_bn (TGLC_bn_new ());
      ^~
tgl/crypto/rsa_pem_openssl.c: In function ‘TGLC_rsa_n’:
tgl/crypto/rsa_pem_openssl.c:52:1: error: control reaches end of non-void function [-Werror=return-type]
 RSA_GETTER(n);
 ^~~~~~~~~~
tgl/crypto/rsa_pem_openssl.c: In function ‘TGLC_rsa_e’:
tgl/crypto/rsa_pem_openssl.c:53:1: error: control reaches end of non-void function [-Werror=return-type]
 RSA_GETTER(e);
 ^~~~~~~~~~
cc1: all warnings being treated as errors
Makefile.tgl:20: recipe for target 'objs/crypto/rsa_pem_openssl.o' failed
make: *** [objs/crypto/rsa_pem_openssl.o] Error 1

Cheers, Matthias

@matthiasbock
Copy link
Author

The problem appears to be fixed by this patch:

diff --git a/crypto/rsa_pem_openssl.c b/crypto/rsa_pem_openssl.c
index db653f2..49a9e3f 100644
--- a/crypto/rsa_pem_openssl.c
+++ b/crypto/rsa_pem_openssl.c
@@ -36,18 +36,28 @@ TGLC_WRAPPER_ASSOC(rsa,RSA)
 // TODO: Refactor crucial struct-identity into its own header.
 TGLC_WRAPPER_ASSOC(bn,BIGNUM)
 
+/*
+ * Note: Since OpenSSL version 1.1.0-pre5 the RSA struct (rsa_st) is opaque,
+ * see https://wiki.openssl.org/index.php/OpenSSL_1.1.0_Changes
+ */
 TGLC_rsa *TGLC_rsa_new (unsigned long e, int n_bytes, const unsigned char *n) {
   RSA *ret = RSA_new ();
-  ret->e = unwrap_bn (TGLC_bn_new ());
-  TGLC_bn_set_word (wrap_bn (ret->e), e);
-  ret->n = unwrap_bn (TGLC_bn_bin2bn (n, n_bytes, NULL));
+  BIGNUM *ret_e = unwrap_bn (TGLC_bn_new ());
+  BIGNUM *ret_n = unwrap_bn (TGLC_bn_bin2bn (n, n_bytes, NULL));
+  RSA_set0_key (ret, ret_n, ret_e, NULL);
+  TGLC_bn_set_word (wrap_bn (ret_e), e);
   return wrap_rsa (ret);
 }
 
-#define RSA_GETTER(M)                                                          \
-  TGLC_bn *TGLC_rsa_ ## M (TGLC_rsa *key) {                                    \
-    return wrap_bn (unwrap_rsa (key)->M);                                      \
-  }                                                                            \
+#define RSA_GETTER(M)                       \
+TGLC_bn *TGLC_rsa_ ## M (TGLC_rsa *key) {   \
+    BIGNUM *rsa_n, *rsa_e, *rsa_d;          \
+    RSA_get0_key(unwrap_rsa (key),          \
+        (const BIGNUM **) &rsa_n,           \
+        (const BIGNUM **) &rsa_e,           \
+        (const BIGNUM **) &rsa_d);          \
+    return wrap_bn (rsa_ ## M);             \
+}
 
 RSA_GETTER(n);
 RSA_GETTER(e);

matthiasbock added a commit to matthiasbock/tgl that referenced this issue Apr 24, 2017
Implemented support for opaque structs (since OpenSSL version 1.1.0).
Compilation tested successfully with libssl-dev versions 1.0.2k and 1.1.0e.
@BenWiederhake
Copy link
Contributor

See also #126 and majn#16

@AndreasGocht
Copy link

Thx. patch fixed the make error for me.

cTapuk added a commit to cTapuk/tgl that referenced this issue Oct 12, 2017
alexkoster added a commit to alexkoster/tgl that referenced this issue Nov 15, 2017
@nikodm
Copy link

nikodm commented Nov 26, 2017

Hey Guys,
After spending two days on trying to get telegram up and running on my pi, I give up.
I know this will sound rather stupid to you guys, but I'm just starting the scripting and al this stuff so don't go to hard on me please ;-)
I managed to get the telegram-cli up and running in minutes on my ubuntu machines, but I keep on having this openssl compilation error when I try it on my pi.

After searching the web and a lot of trial and error, I found this fix.
But, I have no idea what I have to do to get this fix on my raspberry, any help is welcome.

Big thanks in advance and hats off to you programmer guys!

@cskowronnek
Copy link

cskowronnek commented Feb 26, 2018

The compilation with the patch fails during make with the following error:

tgl/crypto/rsa_pem_openssl.c:105:20: error: stray ‘##’ in program
TGLC_bn *TGLC_rsa_ ## M (TGLC_rsa *key) {
^~
tgl/crypto/rsa_pem_openssl.c:105:23: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute’ before ‘M’
TGLC_bn *TGLC_rsa_ ## M (TGLC_rsa *key) {
^
tgl/crypto/rsa_pem_openssl.c:117:26: error: stray ‘##’ in program
return wrap_bn (rsa_ ## M);
^~

@matthiasbock
Copy link
Author

@cskowronnek: I can't reproduce your problem. Since the above patch is confirmed working by various people, I suspect, you didn't apply it properly.

If you wish assistance, please provide:

  • git commit hashes of your tg repo (git rev-parse --short HEAD)
  • and of your tgl subrepo (git ls-tree HEAD tgl/)
  • compiler version (gcc -v)
  • your tgl/crypto/rsa_pem_openssl.c
  • the command you use for compilation

@zuzzy87
Copy link

zuzzy87 commented Apr 2, 2018

sorry for the question but I'm new on unix, how can I apply the patch and on what? thanks

@zuzzy87
Copy link

zuzzy87 commented Apr 3, 2018

thank you very much for the answer, I change the file rsa_perm_openssl.c but the make doesn't work,
I try the telepot library and it's working

uqs pushed a commit to freebsd/freebsd-ports that referenced this issue Oct 21, 2018
Add extra-patch to fix build on 12.0-CURRENT after updating OpenSSL to version 1.1.1

See vysheng/tgl#129


git-svn-id: svn+ssh://svn.freebsd.org/ports/head@482679 35697150-7ecd-e111-bb59-0022644237b5
uqs pushed a commit to freebsd/freebsd-ports that referenced this issue Oct 21, 2018
Add extra-patch to fix build on 12.0-CURRENT after updating OpenSSL to version 1.1.1

See vysheng/tgl#129
Jehops pushed a commit to Jehops/freebsd-ports-legacy that referenced this issue Oct 21, 2018
Add extra-patch to fix build on 12.0-CURRENT after updating OpenSSL to version 1.1.1

See vysheng/tgl#129


git-svn-id: svn+ssh://svn.freebsd.org/ports/head@482679 35697150-7ecd-e111-bb59-0022644237b5
swills pushed a commit to swills/freebsd-ports that referenced this issue Oct 22, 2018
Add extra-patch to fix build on 12.0-CURRENT after updating OpenSSL to version 1.1.1

See vysheng/tgl#129


git-svn-id: svn+ssh://svn.freebsd.org/ports/head@482679 35697150-7ecd-e111-bb59-0022644237b5
uqs pushed a commit to freebsd/freebsd-ports that referenced this issue Nov 2, 2018
net-im/telegram: Unbreak build on 12.0-CURRENT

Add extra-patch to fix build on 12.0-CURRENT after updating OpenSSL to version 1.1.1

See vysheng/tgl#129
sitano added a commit to sitano/tgl that referenced this issue Nov 9, 2018
@CurbYourStrangeness
Copy link

CurbYourStrangeness commented Jun 15, 2019

I'm having a similar if slightly different problem when I try to configure and make telegram on my pi.

tgl/crypto/rsa_pem_openssl.c: In function ‘TGLC_rsa_new’:
tgl/crypto/rsa_pem_openssl.c:41:6: error: dereferencing pointer to incomplete type ‘RSA {aka struct rsa_st}’
ret->e = unwrap_bn (TGLC_bn_new ());
^~
(the '^' is pointing at the '->' in 'ret->e'; it's been awhile since I've done C, please forgive/please correct terminology.)


tgl/crypto/rsa_pem_openssl.c: In function ‘TGLC_rsa_n’:
tgl/crypto/rsa_pem_openssl.c:52:1: error: control reaches end of non-void function [-Werror=return-type]
RSA_GETTER(n);
^~~~~~~~~~


tgl/crypto/rsa_pem_openssl.c: In function ‘TGLC_rsa_e’:
tgl/crypto/rsa_pem_openssl.c:53:1: error: control reaches end of non-void function [-Werror=return-type]
RSA_GETTER(e);
^~~~~~~~~~


cc1: all warnings being treated as errors
Makefile.tgl:20: recipe for target 'objs/crypto/rsa_pem_openssl.o' failed
make: *** [objs/crypto/rsa_pem_openssl.o] Error 1

^are the errors I'm getting. And about applying patches, what might that look like in this context?

@BenWiederhake
Copy link
Contributor

This is a dead repo. Try one of the forks.

uqs pushed a commit to freebsd/freebsd-ports that referenced this issue Apr 1, 2021
net-im/telegram: Unbreak build on 12.0-CURRENT

Add extra-patch to fix build on 12.0-CURRENT after updating OpenSSL to version 1.1.1

See vysheng/tgl#129
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

7 participants