Uw-imap package SSL support broken?

I'm running version 21.02.0 and wanted to try out the asterisk-app-voicemail-imap package, but found that if I enabled connecting to the IMAP server via SSL by setting imapflags=ssl in Asterisk's voicemail.conf, Asterisk would report app_voicemail_imap.c: IMAP Error: Can't open mailbox {}INBOX: invalid remote specification, and tcpdump showed that it didn't even attempt to connect. If I changed it to not use SSL (changing the port number and imapflags in voicemail.conf), it connected (but doesn't work because the IMAP server requires STARTTLS if not connecting via imaps).

Looking at the source for asterisk and the uw-imap library that asterisk uses, it seems like the problem comes from this patch for uw-imap, in particular where it moves ssl$(SSLTYPE) to the beginning in once: onceenv ckp$(PASSWDTYPE) ssl$(SSLTYPE) osdep.c. The Makefile creates a linkage.c file containing various initialization calls needed depending on the compile options selected. The ssl$(SSLTYPE) target appends some stuff to linkage.c, but the onceenv target calls the drivers script, which deletes linkage.c as the very first thing it does.

So originally, the onceenv target would create an initial linkage.c file, then subsequent targets, such as ssl$(SSLTYPE) would append things to it as needed. But the patch moves ssl$(SSLTYPE) to the front, so it creates/appends its SSL initialization calls to linkage.c, but then onceenv clobbers it and the SSL initialization is lost.

What's the purpose of changing the order of those targets? Removing that section of the patch allows asterisk-app-voicemail-imap to connect to the IMAP server over SSL, and it seems to actually work.

Please consider to upgrade to 21.02.1, as the SSL libraries (openssl and wolfssl) have been upgraded in that version, to deal with the fallout of the letsencrypt CA cross-signing certs. Although I don't really expect an improvement in your case, it's still a worthwhile check.

You might find some answers in https://github.com/openwrt/packages/pull/5065 that originally added the uw-imap package.

seems to be mainly discussion between @lucize @pprindeville

See also the later stuff:

It looks like that change came from from Alpine Linux: https://git.alpinelinux.org/aports/commit/main/imap/fix-linking.patch?id=6c73adbe1eadb7caf44971bb4b12ec0e61e596f7 with the commit comment "we need to add the libs at the end otherwise will --as-needed remove the ssl libs and we end up with an underlinked c-client library."

However, I don't get how reordering the once target would affect that, and that change clearly breaks the generation of a proper linkage.c. The changes to the onceenv target seem fine though. How can I tell if the libc-client.so I built is "underlinked"? As I mentioned, I copied my newly-built libc-client.so.2007f and app_voicemail_imap.so over, and they work fine.

In any case, I think I'll submit a bug report :slight_smile: