[asterisk-dev] [Code Review] Wrap OpenSSL library initialization to make it safe for loaded modules to also use OpenSSL.

Kevin Fleming reviewboard at asterisk.org
Wed Jan 25 16:26:09 CST 2012


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviewboard.asterisk.org/r/1006/
-----------------------------------------------------------

(Updated Jan. 25, 2012, 4:26 p.m.)


Review request for Asterisk Developers.


Changes
-------

Updated to incorporate feedback from various people:

* Building 'libasteriskssl' is now optional (enabled by default). It can be disabled using the "--disable-libasteriskssl" argument to the configure script.

* On traditional Unix-type platforms, libasteriskssl.so is now versioned, for ABI safety.

* Support for building libasterisskl.dylib on Mac OS/X (Darwin) is now included (contributed by Tilghman Lesher).

* After researching how the static and dynamic linkers work together (specifically library load order and symbol resolution order), libasteriskssl.c was greatly simplified. It has returned to only wrapping the OpenSSL initialization/shutdown functions from libssl and libcrypto (there is no need to wrap other functions used by code in the main Asterisk binary, as that binary is once again also linked to libssl and libcrypto directly).

* Installation (and uninstallation) of the main Asterisk binary and libasteriskssl has been relocated from the top-level Makefile to the Makefile in 'main' (where they are built).


Summary
-------

During the devcon after AstriCon 2010, we got a report that using PostgreSQL from within Asterisk, when the PostgreSQL connections are configured to use SSL/TLS to connect to the database server, can cause random crashes and other bizarre behavior. The reporter said this was known to be an issue with some other packages as well (notably Kamailio), and had to do with both Asterisk and the PostgreSQL libraries assuming they "owned" the OpenSSL libraries in the process' memory space, and thus calling initialization code twice (or worse).

This patch addresses this problem by using dynamic linker functionality to *wrap* the real OpenSSL initialization functions (and some other dangerous ones) with versions that don't actually do anything, and then calling the real ones only *one* time during Asterisk startup. To make this work, the SSL functionality that is normally built into the main Asterisk binary now must be built into a dynamic library (libasteriskssl.so), which is installed into the standard dynamic library location on the system (this is *not* an Asterisk loadable module, just a regular dynamic library).

As part of this patch, the usage of ASTLIBDIR throughout the build system to refer to the directory where Asterisk loadable modules are installed was changed to ASTMODDIR (which matches how it is referred to in the source code and in asterisk.conf), and a new definition of ASTLIBDIR was created to point to the system's dynamic library directory.


Diffs (updated)
-----

  /trunk/build_tools/make_defaults_h 352631 
  /trunk/build_tools/mkpkgconfig 352631 
  /trunk/configure UNKNOWN 
  /trunk/configure.ac 352631 
  /trunk/Makefile.moddir_rules 352631 
  /trunk/Makefile 352631 
  /trunk/include/asterisk.h 352631 
  /trunk/include/asterisk/optional_api.h 352631 
  /trunk/main/Makefile 352631 
  /trunk/main/ssl.c 352631 
  /trunk/makeopts.in 352631 

Diff: https://reviewboard.asterisk.org/r/1006/diff


Testing
-------

Compiles and runs on Linux x86-64 with no apparent change in behavior. The Makefile bits to install libasteriskssl.so in the right place will probably have to be checked by Solaris, Darwin and *BSD users to get them right.


Thanks,

Kevin

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-dev/attachments/20120125/605e4c65/attachment.htm>


More information about the asterisk-dev mailing list