Alien-LibreSSL

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

0.05      2020-02-11 05:55:06 -0700
  - More accurate probing of system libs on even older versions of Strawberry.

0.04      2020-02-10 20:18:35 -0700
  - Use Home Brew OpenSSL as system SSL if available.
  - Honor the OPENSSL_PREFIX environment variable, if set.
  - More accurate probing of system libs on older versions of Strawberry.

0.03      2019-06-04 08:42:45 -0700
  - Don't trust the system OpenSSL on recent OS X
    if /usr/include/openssl does not exist.
  - Use Decode::Mojo instead of Decode::HTML.

0.02      2017-10-03 11:24:46 -0400
  - Patch for Microsoft Visual C++
  - Fallback on http if https is not available

0.01      2017-10-03 09:20:50 -0400
  - initial version

LICENSE  view on Meta::CPAN


Source code for a work means the preferred form of the work for making
modifications to it.  For an executable file, complete source code means
all the source code for all modules it contains; but, as a special
exception, it need not include source code for modules which are standard
libraries that accompany the operating system on which the executable
file runs, or for standard header files or definitions files that
accompany that operating system.

  4. You may not copy, modify, sublicense, distribute or transfer the
Program except as expressly provided under this General Public License.
Any attempt otherwise to copy, modify, sublicense, distribute or transfer
the Program is void, and will automatically terminate your rights to use
the Program under this License.  However, parties who have received
copies, or rights to use copies, from you under this General Public
License will not have their licenses terminated so long as such parties
remain in full compliance.

  5. By copying, distributing or modifying the Program (or any work based
on the Program) you indicate your acceptance of this license to do so,
and all its terms and conditions.

MANIFEST  view on Meta::CPAN

META.yml
Makefile.PL
README
alienfile
author.yml
dist.ini
lib/Alien/LibreSSL.pm
maint/cip-test
patch/Net-SSLeay.diff
patch/gen.pl
patch/libressl-2.6.2.diff
patch/libressl-2.6.2.pl
patch/libressl-portable.openbsd.diff
patch/libressl-portable.portable.diff
perlcriticrc
t/00_diag.t
t/alien_libressl.t
xt/author/critic.t
xt/author/eol.t
xt/author/no_tabs.t
xt/author/pod.t
xt/author/pod_coverage.t
xt/author/pod_spelling_common.t
xt/author/pod_spelling_system.t
xt/author/strict.t
xt/author/version.t
xt/release/changes.t

README  view on Meta::CPAN

     );
     
     $build->create_build_script;

    Perl script:

     use Alien::LibreSSL;
     use Env qw( @PATH );
     
     unshift @PATH, 'Alien::LibreSSL->bin_dir;
     system 'openssl ...';

DESCRIPTION

    This module provides an implementation of SSL. It will use the system
    SSL, if it can be found. If the system does not provide SSL, this alien
    will download and build LibreSSL, a drop in replacement for OpenSSL

 Motivation

    SSL has lots of pitfalls. SSL on Perl has all of those pitfalls plus

alienfile  view on Meta::CPAN

use Path::Tiny ();

configure {
  requires 'Path::Tiny'
};

if(defined $ENV{OPENSSL_PREFIX} && -d "$ENV{OPENSSL_PREFIX}/lib/pkgconfig") {
  unshift @PKG_CONFIG_PATH, "$ENV{OPENSSL_PREFIX}/lib/pkgconfig";
}

if($^O eq 'darwin' && ! -d '/usr/include/openssl')
{
  # The OpenSSL that ships with recent OS X is completely broken
  # from a developer perspective.  They provide an openssl binary,
  # libraries and a .pc file, but no headers.  I guess the reason
  # is OpenSSL is considered deprecated on the platform, but then
  # why ship the .pc file?  We set PKG_CONFIG_LIBDIR to just the
  # to skip /usr/lib/pkgconfig, unless the user has specified it.
  # (presumably if they have set it, they have done so for a reason).
  unless(defined $ENV{PKG_CONFIG_LIBDIR}) {
    @PKG_CONFIG_LIBDIR = qw(
      /usr/local/lib/pkgconfig
      /usr/local/share/pkgconfig
    )
  }

  if( -d '/usr/local/Cellar/libressl' )
  {
    require File::Glob;
    my($dir) = File::Glob::bsd_glob('/usr/local/Cellar/libressl/*/lib/pkgconfig');
    push @PKG_CONFIG_LIBDIR, $dir;
  }

  if( -d '/usr/local/Cellar/openssl' )
  {
    require File::Glob;
    my($dir) = File::Glob::bsd_glob('/usr/local/Cellar/openssl/*/lib/pkgconfig');
    push @PKG_CONFIG_LIBDIR, $dir;
  }

  if( -l '/opt/local/bin/openssl' ) {
    my $dir = Path::Tiny->new(readlink '/opt/local/bin/openssl');
    $dir = $dir->relative('/opt/local/bin') if $dir->is_relative;
    $dir = $dir
      ->parent
      ->parent
      ->child('lib')
      ->child('pkgconfig');
    push @PKG_CONFIG_LIBDIR, "$dir";
  }

  log "overidding PKG_CONFIG_LIBDIR on macOS: $ENV{PKG_CONFIG_LIBDIR}";

alienfile  view on Meta::CPAN


if($^O eq 'MSWin32' && $Config{myuname} =~ /strawberry-?perl 5\.([0-9]+)\./ && $1 < 20)
{
  my $libdir = Path::Tiny->new($^X)->parent->parent->parent->child('c/lib');
  # older versions of Straberry didn't have a working pkg-config
  plugin 'Probe::CBuilder' => (
    libs    => $_,
    version => qr/version = \|(.*?)\|/,
    program => <<'EOF',
#include <stdio.h>
#include <openssl/crypto.h>
int main()
{
  const char *version;
#ifdef OPENSSL_VERSION
  version = OpenSSL_version(OPENSSL_VERSION);
#else
  version = SSLeay_version(SSLEAY_VERSION);
#endif
  printf("version = |%s|\n", version);
  return 0;
}
EOF
  ) for (
    '-leay32 -lssl32',
    '-lssl -lcrypto',
    '-lcrypto -lssl',
    "-L$libdir -leay32 -lssl32",
    "-L$libdir -lssl -lcrypto",
    "-L$libdir -lcrypto -lssl",
  );

  meta->after_hook(gather_system => sub {
    my $build = shift;
    if($build->runtime_prop->{version} =~ /^(open|libre)ssl (\S+)/i)
    {
      $build->runtime_prop->{version} = $2;
    }
  });
}
else
{
  plugin 'PkgConfig' => 'openssl';
}

share {

  start_url 'https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/';
  plugin Download => (
    version       => qr/^libressl-([0-9\.]+)\.tar\.gz$/,
    bootstrap_ssl => 1,
  );

  unless(meta->has_hook('fetch'))
  {
    my $ftp_ok = $ENV{ALIEN_OPENSSL_FTP};
    $ftp_ok = 1 unless defined $ftp_ok;
    if($ftp_ok)
    {
      log(" ************************************************* ");
      log(" *  WARNING downloading LibreSSL via HTTP        * ");

lib/Alien/LibreSSL.pm  view on Meta::CPAN

 );
 
 $build->create_build_script;

Perl script:

 use Alien::LibreSSL;
 use Env qw( @PATH );
 
 unshift @PATH, 'Alien::LibreSSL->bin_dir;
 system 'openssl ...';

=head1 DESCRIPTION

This module provides an implementation of SSL.  It will use the system
SSL, if it can be found.  If the system does not provide SSL, this alien
will download and build LibreSSL, a drop in replacement for OpenSSL

=head2 Motivation

SSL has lots of pitfalls.  SSL on Perl has all of those pitfalls plus some

patch/Net-SSLeay.diff  view on Meta::CPAN

diff --git a/SSLeay.xs b/SSLeay.xs
index 67acfe0..10dbb4a 100644
--- a/SSLeay.xs
+++ b/SSLeay.xs
@@ -849,13 +849,15 @@ int ssleay_session_secret_cb_invoke(SSL* s, void* secret, int *secret_len,
 
     res = POPi;
     if (res) {
+#if OPENSSL_VERSION_NUMBER >= 0x10100000L
+	STRLEN newsecretlen;
+#endif
         /* See if there is a preferred cipher selected, if so it is an index into the stack */
         if (SvIOK(pref_cipher))
             *cipher = sk_SSL_CIPHER_value(peer_ciphers, SvIV(pref_cipher));
 
 #if OPENSSL_VERSION_NUMBER >= 0x10100000L
 	/* Use any new master secret set by the callback function in secret */
-	STRLEN newsecretlen;
 	char* newsecretdata = SvPV(secretsv, newsecretlen);
 	memcpy(secret, newsecretdata, newsecretlen);
 #endif
diff --git a/inc/Module/Install/PRIVATE/Net/SSLeay.pm b/inc/Module/Install/PRIVATE/Net/SSLeay.pm
index ad0203a..e89637a 100644
--- a/inc/Module/Install/PRIVATE/Net/SSLeay.pm
+++ b/inc/Module/Install/PRIVATE/Net/SSLeay.pm
@@ -26,25 +26,53 @@ sub ssleay {
     my $prefix = $self->find_openssl_prefix;
     my $exec   = $self->find_openssl_exec($prefix);
 
-    unless (-x $exec) {
-        print <<EOM;
-*** Could not find OpenSSL
-    If it's already installed, please set the OPENSSL_PREFIX environment
-    variable accordingly. If it isn't installed yet, get the latest version
-    from http://www.openssl.org/.
-EOM
-        exit 0; # according http://wiki.cpantesters.org/wiki/CPANAuthorNotes this is best-practice when "missing library"
-    }
+    if (-x $exec) {
+        $self->check_openssl_version($prefix, $exec);
+        my $opts = $self->ssleay_get_build_opts($prefix, $exec);
+
+        if (eval { require ExtUtils::CBuilder }) {
+          my $source = 'test.c';
+          open(my $fh, '>', $source);
+          print $fh "#include <openssl/err.h>\n";
+          close $fh;
+          my $b = ExtUtils::CBuilder->new;
+          my $object = eval {
+            $b->compile(
+              source       => $source, 
+              include_dirs => [$opts->{inc_paths}],
+            );
+          };
+
+          if ($object) {

patch/Net-SSLeay.diff  view on Meta::CPAN

+              $self->makemaker_args(
+                  CCCDLFLAGS => $opts->{cccdlflags},
+                  OPTIMIZE => $opts->{optimize},
+                  INC => join(' ', map qq{"-I$_"}, @{$opts->{inc_paths}}),
+                  LIBS => join(' ', (map qq{"-L$_"}, @{$opts->{lib_paths}}), (map {"-l$_"} @{$opts->{lib_links}})),
+              );
+
+          } else {
+              undef $exec;
 
-    $self->check_openssl_version($prefix, $exec);
-    my $opts = $self->ssleay_get_build_opts($prefix, $exec);
+          }
+          
+          unlink $source;
+        }
+    }
 
-    $self->makemaker_args(
-        CCCDLFLAGS => $opts->{cccdlflags},
-        OPTIMIZE => $opts->{optimize},
-        INC => join(' ', map qq{"-I$_"}, @{$opts->{inc_paths}}),

patch/libressl-2.6.2.diff  view on Meta::CPAN

diff --git a/apps/openssl/compat/poll_win.c b/apps/openssl/compat/poll_win.c
index c9422b9..cc9fdac 100644
--- a/apps/openssl/compat/poll_win.c
+++ b/apps/openssl/compat/poll_win.c
@@ -44,9 +44,9 @@ conn_has_oob_data(int fd)
 static int
 is_socket(int fd)
 {
+	WSANETWORKEVENTS events;
 	if (fd < 3)
 		return 0;
-	WSANETWORKEVENTS events;
 	return (WSAEnumNetworkEvents((SOCKET)fd, NULL, &events) == 0);
 }

patch/libressl-2.6.2.pl  view on Meta::CPAN

+	size_t i;
 
 	if (ret == NULL)
 		return NULL;
 
-	size_t i;
 	for (i = 0; i < ret->num; i++) {
 		if (ret->data[i] == NULL)
 			continue;
',
          'apps/openssl/compat/poll_win.c' => '@@ -44,9 +44,9 @@ conn_has_oob_data(int fd)
 static int
 is_socket(int fd)
 {
+	WSANETWORKEVENTS events;
 	if (fd < 3)
 		return 0;
-	WSANETWORKEVENTS events;
 	return (WSAEnumNetworkEvents((SOCKET)fd, NULL, &events) == 0);
 }
 

patch/libressl-portable.portable.diff  view on Meta::CPAN

diff --git a/apps/openssl/compat/poll_win.c b/apps/openssl/compat/poll_win.c
index c9422b9..cc9fdac 100644
--- a/apps/openssl/compat/poll_win.c
+++ b/apps/openssl/compat/poll_win.c
@@ -44,9 +44,9 @@ conn_has_oob_data(int fd)
 static int
 is_socket(int fd)
 {
+	WSANETWORKEVENTS events;
 	if (fd < 3)
 		return 0;
-	WSANETWORKEVENTS events;
 	return (WSAEnumNetworkEvents((SOCKET)fd, NULL, &events) == 0);
 }

t/alien_libressl.t  view on Meta::CPAN

  ok $version;
  note "version = $version";
};

done_testing

__DATA__
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include <openssl/crypto.h>

MODULE = TA_MODULE PACKAGE = TA_MODULE

const char *
version(klass)
    const char *klass;
  CODE:
#ifdef OPENSSL_VERSION
    RETVAL = OpenSSL_version(OPENSSL_VERSION);
#else



( run in 0.918 second using v1.01-cache-2.11-cpan-acf6aa7dc9e )