I'm compiling OpenSSL myself and am attempting to use that in my
application.

I've created a LWP test script:

use LWP::UserAgent 6;
use Net::HTTPS;
use File::Spec;
use Archive::Zip;

my $ua = LWP::UserAgent->new();

# If we're in the PAR'd case, we need to do a few extra things to setup the
# cacert.pem file access.  Otherwise, we rely on cacert.pem being in the
# existing PERL5LIB (wherever that may be).

if ( exists $ENV{PAR_TEMP} ) {
    print "PAR bootstrap root folder: $ENV{PAR_TEMP}\n\n";

    # We expect the cacert.pem to be in $ENV{PAR_TEMP}/inc/cacert.pem
    my $ca_file = File::Spec->catfile( $ENV{PAR_TEMP}, 'inc', 'cacert.pem'
);

    # If PAR_GLOBAL_CLEAN is true, we'll need to extract the file
    # If PAR_GLOBAL_CLEAN is false (or if it's executed as parl PROG.par),
    # the cacert file should already exist in PAR_TEMP, so don't extract it
again:
    if ( ! -f $ca_file ) {
        print "Extracting $ca_file\n";
        my $zip = $PAR::LibCache{$ENV{PAR_PROGNAME}};
        $zip->extractMember( 'cacert.pem', $ca_file );
    }

    if ( -f $ca_file ) {
        print "CA Cert file location: $ca_file\n\n";
    }
    $ua->ssl_opts( SSL_ca_file => $ca_file );
}

my $result = $ua->get("https://google.com";);
if ( $result->is_success ) {
    print $result->content;
}
else {
    print "ERROR: " . $result->status_line . "\n";
}

Everything works well on most platforms, but I've got a problem
specifically with FreeBSD where the packed shared libs are not found,
presumably because the par-temp is never accessed.

FreeBSD:

$ lwp_test
Can't load '/var/tmp/par-726f6f74/temp-86696/Rtl6JMPnvc.so' for module
Net::SSLeay: Shared object "libssl.so.1.0.0" not found, required by
"Rtl6JMPnvc.so" at
/path/to/perl_base/lib/5.14.2/i386-freebsd-thread-multi/DynaLoader.pm line
190.
 at /path/to/local/perl5lib/lib/perl5/PAR/Heavy.pm line 75
Compilation failed in require at IO/Socket/SSL.pm line 18.
BEGIN failed--compilation aborted at IO/Socket/SSL.pm line 18.
Compilation failed in require at Net/HTTPS.pm line 26.
Can't locate Net/SSL.pm in @INC (@INC contains: CODE(0x8ac5b60)
CODE(0x8855fb0) CODE(0x88652d0)) at Net/HTTPS.pm line 30.
Compilation failed in require at script/lwp_test.pl line 6.
BEGIN failed--compilation aborted at script/lwp_test.pl line 6.

>From a truss output, I never see anything other than system library paths
being accessed:
access("/usr/lib/libssl.so.1.0.0",0)             ERR#2 'No such file or
directory'
access("/usr/lib32/libssl.so.1.0.0",0)           ERR#2 'No such file or
directory'
access("/usr/local/lib32/compat/libssl.so.1.0.0",0) ERR#2 'No such file or
directory'
access("/lib32/libssl.so.1.0.0",0)               ERR#2 'No such file or
directory'
access("/usr/lib32/libssl.so.1.0.0",0)           ERR#2 'No such file or
directory'

Compare this to RHEL, which succeeds:

open("/usr/lib/tls/x86_64/libssl.so.1.0.0", O_RDONLY) = -1 ENOENT (No such
file or directory)
stat("/usr/lib/tls/x86_64", 0x7fff68b231d0) = -1 ENOENT (No such file or
directory)
open("/usr/lib/tls/libssl.so.1.0.0", O_RDONLY) = -1 ENOENT (No such file or
directory)
stat("/usr/lib/tls", 0x7fff68b231d0)    = -1 ENOENT (No such file or
directory)
open("/usr/lib/x86_64/libssl.so.1.0.0", O_RDONLY) = -1 ENOENT (No such file
or directory)
stat("/usr/lib/x86_64", 0x7fff68b231d0) = -1 ENOENT (No such file or
directory)
open("/usr/lib/libssl.so.1.0.0", O_RDONLY) = -1 ENOENT (No such file or
directory)
stat("/usr/lib", {st_mode=S_IFDIR|0755, st_size=126976, ...}) = 0
open("/tmp/par-74686f6b65/temp-25615/libssl.so.1.0.0", O_RDONLY) = 7
read(7, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0@j\1\0\0\0\0\0"...,
832) = 832
fstat(7, {st_mode=S_IFREG|0555, st_size=455094, ...}) = 0
mmap(NULL, 2501864, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 7, 0) =
0x2b6a62837000

I'm packaging in this form:
pp -C -c -x -l ${libcrypto_lib} -l ${libssl_lib} -a
${cacert_file};cacert.pem -o lwp_test lwp_test.pl

Where:
libcrypto_lib=/path/to/libcrypto
libssl_lib=/path/to/libssl
cacert_file=/path/to/local/perl5lib/lib/perl5/Mozilla/CA/cacert.pem

What's going on with FreeBSD compared to others?  Is there some magic I can
invoke to control the shared library path loading order and locations?

A couple more tidbits of information:
Perl 5.14.2
PAR 1.005
PAR::Packer 1.013

libcrypto/libssl are packed with pp:
$ unzip -l lwp_test |egrep "ssl|crypto"
  1582965  07-03-12 08:51
shlib/i386-freebsd-thread-multi/libcrypto.so.1.0.0
   368693  07-03-12 08:51   shlib/i386-freebsd-thread-multi/libssl.so.1.0.0

libcrypto/libssl are extracted from the package (from PAR_GLOBAL_DEBUG=1 on
a different execution from above):
Extracting "shlib/i386-freebsd-thread-multi/libcrypto.so.1.0.0" to
"/var/tmp/par-726f6f74/temp-86899/libcrypto.so.1.0.0"
Extracting "shlib/i386-freebsd-thread-multi/libssl.so.1.0.0" to
"/var/tmp/par-726f6f74/temp-86899/libssl.so.1.0.0"

Thanks
-Tim

Reply via email to