roc-streaming / roc-toolkit

Real-time audio streaming over the network.
https://roc-streaming.org
Mozilla Public License 2.0
1.06k stars 213 forks source link

Compiling issue following tutorial: modules/raop/raop_client.c: In function 'rsa_encrypt': #440

Closed r31griffo closed 3 years ago

r31griffo commented 3 years ago

G'day everyone, I'm hoping someone might be able to assist, I'm not well versed with compiling applications and don't really know where to start with this. If this is more of an issue for the Pulseaudio gurus, please let me know as I'm desperate to get this going, the other network streaming options I've tried have either been unsuccessful or the latency was too high.

Following this tutorial: https://gavv.github.io/articles/roc-tutorial/

I get stuck on this command: scons -Q --enable-pulseaudio-modules --build-3rdparty=openfec,pulseaudio

After the first failure, I noticed it was trying to compile pulseaudio version 5, I've updated this to match my version of Pulseaudio with this command: scons -Q --enable-pulseaudio-modules --build-3rdparty=openfec,pulseaudio:8.0

Unfortunately the error remains unchanged (build.log also attached): modules/raop/raop_client.c: In function 'rsa_encrypt': modules/raop/raop_client.c:167:8: error: dereferencing pointer to incomplete type 'RSA {aka struct rsa_st}' rsa->n = BN_bin2bn(modules, size, NULL); ^ Makefile:8607: recipe for target 'modules/raop/libraop_la-raop_client.lo' failed make[3]: [modules/raop/libraop_la-raop_client.lo] Error 1 make[3]: Waiting for unfinished jobs.... make[3]: Leaving directory '/root/roc/roc/roc-toolkit/3rdparty/arm-pc-linux-gnueabihf/gcc-5.4.0-release/build/pulseaudio-8.0/src/pulseaudio-8.0/src' Makefile:4849: recipe for target 'all' failed make[2]: [all] Error 2 make[2]: Leaving directory '/root/roc/roc/roc-toolkit/3rdparty/arm-pc-linux-gnueabihf/gcc-5.4.0-release/build/pulseaudio-8.0/src/pulseaudio-8.0/src' Makefile:803: recipe for target 'all-recursive' failed make[1]: [all-recursive] Error 1 make[1]: Leaving directory '/root/roc/roc/roc-toolkit/3rdparty/arm-pc-linux-gnueabihf/gcc-5.4.0-release/build/pulseaudio-8.0/src/pulseaudio-8.0' Makefile:618: recipe for target 'all' failed make: *** [all] Error 2

build.log

r31griffo commented 3 years ago

Google to the rescue... admittedly I've got no idea of the impact this might cause but it compiles now.

"rijulg" had exactly the same error with a different version of Pulseaudio 9.0, I've followed the steps he outlines from bullet point 3 in this link: https://gist.github.com/therealkenc/5dae7eefbacb0083e485348bd25ee33c

To summarise, after running scons and failing I found the file with the following function: static int rsa_encrypt, I did this by running: grep -Ril "rsa_encrypt" ./

Then replaced the entire function with the following:

static int rsa_encrypt(uint8_t text, int len, uint8_t res) {
const char n[] = "59dE8qLieItsH1WgjrcFRKj6eUWqi+bGLOX1HL3U3GhC/j0Qg90u3sG/1CUtwC" "5vOYvfDmFI6oSFXi5ELabWJmT2dKHzBJKa3k9ok+8t9ucRqMd6DZHJ2YCCLlDR" "KSKv6kDqnw4UwPdpOMXziC/AMj3Z/lUVX1G7WSHCAWKf1zNS1eLvqr+boEjXuB" "OitnZ/bDzPHrTOZz0Dew0uowxf/+sG+NCK3eQJVxqcaJ/vEHKIVd2M+5qL71yJ" "Q+87X6oV3eaYvt3zWZYD6z5vYTcrtij2VZ9Zmni/UAaHqn9JdsBWLUEpVviYnh" "imNVvYFZeCXg/IdTQ+x4IRdiXNv5hEew=="; const char e[] = "AQAB"; const char e2[] = "JAHH"; uint8_t modules[256]; uint8_t exponent[8]; uint8_t privateExponent[8]; int size,sizen,sizee,sizef; RSA *rsa; rsa = RSA_new(); sizen = pa_base64_decode(n, modules); sizee = pa_base64_decode(e, exponent); sizef = pa_base64_decode(e2, privateExponent);

if OPENSSL_VERSION_NUMBER < 0x10100000L

    /* OpenSSL 1.0.2 and below (old code) */
    rsa->n = BN_bin2bn(modules, sizen, NULL);
    rsa->e = BN_bin2bn(exponent, sizee, NULL);
#else
    /* OpenSSL 1.1.0 and above (new code) */
    RSA_set0_crt_params(
        rsa,
        BN_bin2bn(modules, sizen, NULL),
        BN_bin2bn(exponent, sizee, NULL),
        BN_bin2bn(privateExponent, sizef, NULL)
    );
#endif
size = RSA_public_encrypt(len, text, res, rsa, RSA_PKCS1_OAEP_PADDING);
RSA_free(rsa);
return size;

}

And added "#include <openssl/opensslv.h>" with all the other includes Re-ran: scons -Q --enable-pulseaudio-modules --build-3rdparty=openfec,pulseaudio:8.0

Finally I manually copied files to their locations: cp ./bin/arm-pc-linux-gnueabihf/roc-{recv,send,conv} /usr/bin cp ./bin/arm-pc-linux-gnueabihf/libroc.so.. /usr/lib cp ./bin/arm-pc-linux-gnueabihf/module-roc-sink* /usr/lib/pulse-8.0/modules

Jesus82 commented 3 years ago

I had the same issue with Raspberry OS (based in debian). Tried your fix, but no luck (I'm running Pulseaudio 5)

modules/raop/raop_client.c:168:9: error: storage size of ‘rsa’ isn’t known
     RSA rsa;
         ^~~
modules/raop/raop_client.c:178:5: error: expected expression before ‘/’ token
     / OpenSSL 1.1.0 and above (new code) */
     ^
modules/raop/raop_client.c:178:15: error: too many decimal points in number
     / OpenSSL 1.1.0 and above (new code) */
gavv commented 3 years ago

Hi thanks for report.

@r31griffo @Jesus82 Could you tell what OS versions did you use, so that I could try to reproduce it?

Jesus82 commented 3 years ago

Hi @gavv it is Raspberry Pi OS 32 bits, latest release (11-01-2021), it is a debian based linux. https://www.raspberrypi.org/software/

r31griffo commented 3 years ago

@Jesus82 @gavv Sorry for the delay replying; my workload has been crazy lately. From memory the board I'm using is a NanoPi NEO-LTS running

lsb_release -d

Description: Ubuntu 16.04.2 LTS

uname -a

Linux vring 4.14.52 #114 SMP Tue Mar 5 16:05:06 CST 2019 armv7l armv7l armv7l GNU/Linux

Another funny issue (probably related to me not having an onboard RTC or maybe my implementation is weird) is over time my secondary network speaker's delay/latency increases and often the remote speaker will remove itself. Not reporting as an issue yet because I haven't looked into it, just weird.

gavv commented 3 years ago

I was able to reproduce it. Older pulseaudio is just not compatible with newer openssl.

The "fix" is simple: just disable openssl when building pulseaudio. It's completely OK to do it since we're building pulseaudio only to link our modules with its internal libraries (like libpulsecore), and after linking we don't in any way use pulseaudio binaries which we've built. So it's OK if some features are disables in them.

I've pushed the fix to master: 70bdbf04e11653d73874d6e608f6037cada688dd

gavv commented 3 years ago

Another funny issue (probably related to me not having an onboard RTC or maybe my implementation is weird) is over time my secondary network speaker's delay/latency increases and often the remote speaker will remove itself. Not reporting as an issue yet because I haven't looked into it, just weird.

Interesting, feel free to open an issue of that.

gavv commented 3 years ago

Closing this, feel free to reopen if you'll have any troubles with the fix.