Index: SSLeay.xs
===================================================================
--- SSLeay.xs (revision 466)
+++ SSLeay.xs (working copy)
@@ -4640,12 +4640,55 @@
EC_KEY * key
long
-SSL_CTX_set_tmp_ecdh(ctx,ecdh);
+SSL_CTX_set_tmp_ecdh(ctx,ecdh)
SSL_CTX * ctx
EC_KEY * ecdh
+int
+EVP_PKEY_assign_EC_KEY(pkey,key)
+ EVP_PKEY * pkey
+ EC_KEY * key
+
+
+EC_KEY *
+EC_KEY_generate_key(curve)
+ SV *curve;
+ CODE:
+ EC_GROUP *group = NULL;
+ EC_KEY *eckey = NULL;
+ int nid;
+
+ RETVAL = 0;
+ if (SvIOK(curve)) {
+ nid = SvIV(curve);
+ } else {
+ nid = OBJ_sn2nid(SvPV_nolen(curve));
+#if OPENSSL_VERSION_NUMBER > 0x10002000L
+ if (!nid) nid = EC_curve_nist2nid(SvPV_nolen(curve));
#endif
+ if (!nid) croak("unkown curve %s",SvPV_nolen(curve));
+ }
+ group = EC_GROUP_new_by_curve_name(nid);
+ if (!group) croak("unkown curve nid=%d",nid);
+ EC_GROUP_set_asn1_flag(group,OPENSSL_EC_NAMED_CURVE);
+
+ eckey = EC_KEY_new();
+ if ( eckey
+ && EC_KEY_set_group(eckey, group)
+ && EC_KEY_generate_key(eckey)) {
+ RETVAL = eckey;
+ } else {
+ if (eckey) EC_KEY_free(eckey);
+ }
+ if (group) EC_GROUP_free(group);
+
+ OUTPUT:
+ RETVAL
+
+
+#endif
+
void *
SSL_get_app_data(s)
SSL * s
Index: inc/Module/Install/PRIVATE/Net/SSLeay.pm
===================================================================
--- inc/Module/Install/PRIVATE/Net/SSLeay.pm (revision 466)
+++ inc/Module/Install/PRIVATE/Net/SSLeay.pm (working copy)
@@ -1,5 +1,6 @@
#line 1
#line 1
+#line 1
package Module::Install::PRIVATE::Net::SSLeay;
use strict;
@@ -68,7 +69,7 @@
for ("$prefix/include", "$prefix/inc32", '/usr/kerberos/include') {
push @{$opts->{inc_paths}}, $_ if -f "$_/openssl/ssl.h";
}
- for ($prefix, "$prefix/lib64", "$prefix/lib", "$prefix/out32dll") {
+ for ($prefix, "$prefix/lib", "$prefix/out32dll") {
push @{$opts->{lib_paths}}, $_ if -d $_;
}
@@ -96,10 +97,11 @@
@pairs = (['libeay32','ssleay32'],['libeay32MD','ssleay32MD'],['libeay32MT','ssleay32MT']) if $Config{cc} =~ /cl/;
for my $dir (@{$opts->{lib_paths}}) {
for my $p (@pairs) {
- $found = 1 if ($Config{cc} =~ /gcc/ && -f "$dir/lib$p->[0].a" && -f "$dir/lib$p->[1].a");
- $found = 1 if ($Config{cc} =~ /cl/ && -f "$dir/$p->[0].lib" && -f "$dir/p->[1].lib");
+ my ($s_lib_found, $s_lib_found);
+ $found = 1 if $Config{cc} =~ /gcc/ && -f "$dir/lib$p->[0].a" && -f "$dir/lib$p->[1].a";
+ $found = 1 if $Config{cc} =~ /cl/ && -f "$dir/$p->[0].lib" && -f "$dir/$p->[1].lib";
if ($found) {
- $opts->{lib_links} = [$p->[0], $p->[1], 'crypt32']; # Some systems need this system lib crypt32 too
+ $opts->{lib_links} = [$p->[0], $p->[1]];
$opts->{lib_paths} = [$dir];
last;
}
@@ -107,7 +109,7 @@
}
if (!$found) {
#fallback to the old behaviour
- push @{ $opts->{lib_links} }, qw( libeay32MD ssleay32MD libeay32 ssleay32 libssl32 crypt32);
+ push @{ $opts->{lib_links} }, qw( libeay32MD ssleay32MD libeay32 ssleay32 libssl32);
}
}
elsif ($^O eq 'VMS') {
@@ -138,12 +140,7 @@
$opts->{cccdlflags} .= '-fPIC';
}
}
- # From HMBRAND to handle multple version of OPENSSL installed
- if (my $lp = join " " => map { "-L$_" } @{$opts->{lib_paths} || []})
- {
- my $mma = $self->makemaker_args;
- ($mma->{uc $_} = $Config{$_}) =~ s/-L/$lp -L/ for qw( lddlflags ldflags );
- }
+
return $opts;
}
@@ -179,23 +176,19 @@
}
my @guesses = (
- '/usr/local/opt/openssl/bin/openssl' => '/usr/local/opt/openssl', # OSX homebrew openssl
- '/usr/local/bin/openssl' => '/usr/local', # OSX homebrew openssl
- '/opt/local/bin/openssl' => '/opt/local', # Macports openssl
- '/usr/bin/openssl' => '/usr',
- '/usr/sbin/openssl' => '/usr',
- '/opt/ssl/bin/openssl' => '/opt/ssl',
- '/opt/ssl/sbin/openssl' => '/opt/ssl',
- '/usr/local/ssl/bin/openssl' => '/usr/local/ssl',
- '/usr/local/openssl/bin/openssl' => '/usr/local/openssl',
- '/apps/openssl/std/bin/openssl' => '/apps/openssl/std',
- '/usr/sfw/bin/openssl' => '/usr/sfw', # Open Solaris
- 'C:\OpenSSL\bin\openssl.exe' => 'C:\OpenSSL',
- 'C:\OpenSSL-Win32\bin\openssl.exe' => 'C:\OpenSSL-Win32',
- $Config{prefix} . '\bin\openssl.exe' => $Config{prefix}, # strawberry perl
- $Config{prefix} . '\..\c\bin\openssl.exe' => $Config{prefix} . '\..\c', # strawberry perl
- '/sslexe/openssl.exe' => '/sslroot', # VMS, openssl.org
- '/ssl$exe/openssl.exe' => '/ssl$root', # VMS, HP install
+ '/usr/bin/openssl' => '/usr',
+ '/usr/sbin/openssl' => '/usr',
+ '/opt/ssl/bin/openssl' => '/opt/ssl',
+ '/opt/ssl/sbin/openssl' => '/opt/ssl',
+ '/usr/local/ssl/bin/openssl' => '/usr/local/ssl',
+ '/usr/local/openssl/bin/openssl' => '/usr/local/openssl',
+ '/apps/openssl/std/bin/openssl' => '/apps/openssl/std',
+ '/usr/sfw/bin/openssl' => '/usr/sfw', # Open Solaris
+ 'C:\OpenSSL\bin\openssl.exe' => 'C:\OpenSSL',
+ $Config{prefix} . '\bin\openssl.exe' => $Config{prefix}, # strawberry perl
+ $Config{prefix} . '\..\c\bin\openssl.exe' => $Config{prefix} . '\..\c', # strawberry perl
+ '/sslexe/openssl.exe' => '/sslroot', # VMS, openssl.org
+ '/ssl$exe/openssl.exe' => '/ssl$root', # VMS, HP install
);
while (my $k = shift @guesses
Index: lib/Net/SSLeay.pod
===================================================================
--- lib/Net/SSLeay.pod (revision 466)
+++ lib/Net/SSLeay.pod (working copy)
@@ -1395,8 +1395,8 @@
Set the key referenced by $pkey to $key
-B<NOTE:> In accordance with the OpenSSL naming convention the $key assigned
-to the $pkey using the "1" functions must be freed as well as $pkey.
+B<NOTE:> No reference counter will be increased, i.e. $key will be freed if
+$pkey is freed.
my $rv = Net::SSLeay::EVP_PKEY_assign_RSA($pkey, $key);
# $pkey - value corresponding to openssl's EVP_PKEY structure
@@ -1404,8 +1404,26 @@
#
# returns: 1 on success, 0 on failure
-Check openssl doc L<
http://www.openssl.org/docs/crypto/EVP_PKEY_set1_RSA.html|
http://www.openssl.org/docs/crypto/EVP_PKEY_set1_RSA.html>
+Check openssl doc L<
http://www.openssl.org/docs/crypto/EVP_PKEY_assign_RSA.html|
http://www.openssl.org/docs/crypto/EVP_PKEY_assign_RSA.html>
+=item * EVP_PKEY_assign_EC_KEY
+
+B<COMPATIBILITY:> not available in Net-SSLeay-1.74 and before
+
+Set the key referenced by $pkey to $key
+
+B<NOTE:> No reference counter will be increased, i.e. $key will be freed if
+$pkey is freed.
+
+ my $rv = Net::SSLeay::EVP_PKEY_assign_EC_KEY($pkey, $key);
+ # $pkey - value corresponding to openssl's EVP_PKEY structure
+ # $key - value corresponding to openssl's EC_KEY structure
+ #
+ # returns: 1 on success, 0 on failure
+
+Check openssl doc L<
http://www.openssl.org/docs/crypto/EVP_PKEY_assign_EC_KEY.html|
http://www.openssl.org/docs/crypto/EVP_PKEY_assign_EC_KEY.html>
+
+
=item * EVP_PKEY_bits
B<COMPATIBILITY:> not available in Net-SSLeay-1.45 and before
@@ -7995,6 +8013,23 @@
TBA
+=item * EC_KEY_generate_key
+
+Generates a EC key and returns it in a newly allocated EC_KEY structure.
+The EC key then can be used to create a PKEY which can be used in calls
+like X509_set_pubkey.
+
+ my $key = Net::SSLeay::EVP_PKEY_new();
+ my $ec = Net::SSLeay::EC_KEY_generate_key($curve);
+ Net::SSLeay::EVP_PKEY_assign_EC_KEY($key,$ec);
+
+ # $curve - curve name like 'secp521r1' or the matching Id (integer) of the curve
+ #
+ # returns: value corresponding to openssl's EC_KEY structure (0 on failure)
+
+This function has no equivalent in OpenSSL but combines multiple OpenSSL
+functions for an easier interface.
+
=back
Index: t/local/63_ec_key_generate_key.t
===================================================================
--- t/local/63_ec_key_generate_key.t (nonexistent)
+++ t/local/63_ec_key_generate_key.t (working copy)
@@ -0,0 +1,36 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use Test::More;
+use Net::SSLeay;
+
+if (!defined &Net::SSLeay::EC_KEY_generate_key) {
+ plan skip_all => "no suport for ECC in your OpenSSL";
+ exit(0);
+}
+
+plan tests => 4;
+
+Net::SSLeay::randomize();
+Net::SSLeay::load_error_strings();
+Net::SSLeay::ERR_load_crypto_strings();
+Net::SSLeay::SSLeay_add_ssl_algorithms();
+
+my $ec = Net::SSLeay::EC_KEY_generate_key('prime256v1');
+ok($ec,'EC key created');
+
+if ($ec) {
+ my $key = Net::SSLeay::EVP_PKEY_new();
+ my $rv = Net::SSLeay::EVP_PKEY_assign_EC_KEY($key,$ec);
+ ok($rv,'EC key assigned to PKEY');
+
+ my $pem = Net::SSLeay::PEM_get_string_PrivateKey($key);
+ ok( $pem =~m{^---.* PRIVATE KEY}m, "output key as PEM");
+
+ my $bio = Net::SSLeay::BIO_new( Net::SSLeay::BIO_s_mem());
+ Net::SSLeay::BIO_write($bio,$pem);
+ my $newkey = Net::SSLeay::PEM_read_bio_PrivateKey($bio);
+ ok($newkey,"read key again from PEM");
+}
+