Skip to content

Commit 0683002

Browse files
authored
Merge pull request #240 from timlegge/rsa
Migrate from Crypt::OpenSSL::RSA to Crypt::PK::RSA
2 parents adeaaf8 + 1debfe3 commit 0683002

File tree

6 files changed

+29
-35
lines changed

6 files changed

+29
-35
lines changed

LICENSE

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ This is free software, licensed under:
2222
Version 1, February 1989
2323

2424
Copyright (C) 1989 Free Software Foundation, Inc.
25-
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25+
<https://fsf.org/>
2626

2727
Everyone is permitted to copy and distribute verbatim copies
2828
of this license document, but changing it is not allowed.
@@ -236,8 +236,7 @@ the exclusion of warranty; and each file should have at least the
236236
GNU General Public License for more details.
237237

238238
You should have received a copy of the GNU General Public License
239-
along with this program; if not, write to the Free Software
240-
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA
239+
along with this program; if not, see <https://www.gnu.org/licenses/>.
241240

242241

243242
Also add information on how to contact you by electronic and paper mail.
@@ -264,8 +263,8 @@ necessary. Here a sample; alter the names:
264263
program `Gnomovision' (a program to direct compilers to make passes
265264
at assemblers) written by James Hacker.
266265

267-
<signature of Ty Coon>, 1 April 1989
268-
Ty Coon, President of Vice
266+
<signature of Moe Ghoul>, 1 April 1989
267+
Moe Ghoul, President of Vice
269268

270269
That's all there is to it!
271270

Makefile.PL

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@ my %WriteMakefileArgs = (
1717
"NAME" => "Net::SAML2",
1818
"PREREQ_PM" => {
1919
"Carp" => 0,
20-
"Crypt::OpenSSL::Bignum" => 0,
21-
"Crypt::OpenSSL::RSA" => 0,
2220
"Crypt::OpenSSL::Random" => 0,
2321
"Crypt::OpenSSL::Verify" => 0,
2422
"Crypt::OpenSSL::X509" => 0,
23+
"Crypt::PK::RSA" => 0,
2524
"DateTime" => 0,
2625
"DateTime::Format::XSD" => 0,
2726
"DateTime::HiRes" => 0,
@@ -53,7 +52,7 @@ my %WriteMakefileArgs = (
5352
"XML::Generator" => "1.13",
5453
"XML::LibXML" => 0,
5554
"XML::LibXML::XPathContext" => 0,
56-
"XML::Sig" => "0.66",
55+
"XML::Sig" => "0.67",
5756
"namespace::autoclean" => 0
5857
},
5958
"TEST_REQUIRES" => {
@@ -71,7 +70,7 @@ my %WriteMakefileArgs = (
7170
"Test::Pod" => "1.14",
7271
"Test::Pod::Coverage" => "1.04"
7372
},
74-
"VERSION" => "0.82",
73+
"VERSION" => "0.83",
7574
"test" => {
7675
"TESTS" => "t/*.t t/author/*.t"
7776
}
@@ -80,11 +79,10 @@ my %WriteMakefileArgs = (
8079

8180
my %FallbackPrereqs = (
8281
"Carp" => 0,
83-
"Crypt::OpenSSL::Bignum" => 0,
84-
"Crypt::OpenSSL::RSA" => 0,
8582
"Crypt::OpenSSL::Random" => 0,
8683
"Crypt::OpenSSL::Verify" => 0,
8784
"Crypt::OpenSSL::X509" => 0,
85+
"Crypt::PK::RSA" => 0,
8886
"DateTime" => 0,
8987
"DateTime::Format::XSD" => 0,
9088
"DateTime::HiRes" => 0,
@@ -129,7 +127,7 @@ my %FallbackPrereqs = (
129127
"XML::Generator" => "1.13",
130128
"XML::LibXML" => 0,
131129
"XML::LibXML::XPathContext" => 0,
132-
"XML::Sig" => "0.66",
130+
"XML::Sig" => "0.67",
133131
"namespace::autoclean" => 0
134132
);
135133

README

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ NAME
22
Net::SAML2 - SAML2 bindings and protocol implementation
33

44
VERSION
5-
version 0.82
5+
version 0.83
66

77
SYNOPSIS
88
See TUTORIAL.md for implementation documentation and
@@ -72,12 +72,12 @@ SYNOPSIS
7272
DESCRIPTION
7373
Support for the Web Browser SSO profile of SAML2.
7474

75-
Net::SAML2 correctly perform the SSO process against numerous SAML
76-
Identity Providers (IdPs). It has been tested against:
77-
7875
Version 0.54 and newer support EncryptedAssertions. No changes required
7976
to existing SP applications if EncryptedAssertions are not in use.
8077

78+
Net::SAML2 correctly perform the SSO process against numerous SAML
79+
Identity Providers (IdPs). It has been tested against:
80+
8181
Auth0 (requires Net::SAML2 >=0.39)
8282
Azure (Microsoft Office 365)
8383
GSuite (Google)

cpanfile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
# Do not edit this file directly. To change prereqs, edit the `dist.ini` file.
22

33
requires "Carp" => "0";
4-
requires "Crypt::OpenSSL::Bignum" => "0";
5-
requires "Crypt::OpenSSL::RSA" => "0";
64
requires "Crypt::OpenSSL::Random" => "0";
75
requires "Crypt::OpenSSL::Verify" => "0";
86
requires "Crypt::OpenSSL::X509" => "0";
7+
requires "Crypt::PK::RSA" => "0";
98
requires "DateTime" => "0";
109
requires "DateTime::Format::XSD" => "0";
1110
requires "DateTime::HiRes" => "0";
@@ -37,7 +36,7 @@ requires "XML::Enc" => "0.13";
3736
requires "XML::Generator" => "1.13";
3837
requires "XML::LibXML" => "0";
3938
requires "XML::LibXML::XPathContext" => "0";
40-
requires "XML::Sig" => "0.66";
39+
requires "XML::Sig" => "0.67";
4140
requires "namespace::autoclean" => "0";
4241
requires "perl" => "5.014";
4342

dist.ini

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ skip = feature
5757
[Prereqs / RuntimeRequires]
5858
perl = 5.014
5959
XML::Enc = 0.13
60-
XML::Sig = 0.66
61-
; Here because it isn't provided by Crypt::OpenSSL::RSA
62-
Crypt::OpenSSL::Bignum = 0
60+
XML::Sig = 0.67
6361
URN::OASIS::SAML2 = 0.007
6462
XML::Generator = 1.13
6563

lib/Net/SAML2/Binding/Redirect.pm

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use Moose;
44
# VERSION
55

66
use Carp qw(croak);
7-
use Crypt::OpenSSL::RSA;
7+
use Crypt::PK::RSA;
88
use Crypt::OpenSSL::X509;
99
use File::Slurper qw/ read_text /;
1010
use IO::Compress::RawDeflate qw/ rawdeflate /;
@@ -197,18 +197,16 @@ sub _sign_redirect_uri {
197197
my $uri = shift;
198198

199199
my $key_string = read_text($self->key);
200-
my $rsa_priv = Crypt::OpenSSL::RSA->new_private_key($key_string);
201-
202-
my $method = "use_" . $self->sig_hash . "_hash";
203-
$rsa_priv->$method;
200+
my $pk = Crypt::PK::RSA->new();
201+
my $rsa_priv = $pk->import_key(\$key_string);
204202

205203
$uri->query_param('SigAlg',
206204
$self->sig_hash eq 'sha1'
207205
? 'http://www.w3.org/2000/09/xmldsig#rsa-sha1'
208206
: 'http://www.w3.org/2001/04/xmldsig-more#rsa-' . $self->sig_hash);
209207

210208
my $to_sign = $uri->query;
211-
my $sig = encode_base64($rsa_priv->sign($to_sign), '');
209+
my $sig = encode_base64($rsa_priv->sign_message($to_sign, uc($self->sig_hash), 'v1.5'), '');
212210
$uri->query_param('Signature', $sig);
213211
return $uri->as_string;
214212
}
@@ -289,24 +287,26 @@ sub _verify {
289287

290288
foreach my $crt (@{$self->cert}) {
291289
my $cert = Crypt::OpenSSL::X509->new_from_string($crt);
292-
my $rsa_pub = Crypt::OpenSSL::RSA->new_public_key($cert->pubkey);
290+
my $pk = Crypt::PK::RSA->new();
291+
my $rsa_pub = $pk->import_key(\$cert->pubkey);
293292

293+
my $hash_name;
294294
if ($sigalg eq 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha256') {
295-
$rsa_pub->use_sha256_hash;
295+
$hash_name = 'SHA256';
296296
} elsif ($sigalg eq 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha224') {
297-
$rsa_pub->use_sha224_hash;
297+
$hash_name = 'SHA224';
298298
} elsif ($sigalg eq 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha384') {
299-
$rsa_pub->use_sha384_hash;
299+
$hash_name = 'SHA384';
300300
} elsif ($sigalg eq 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha512') {
301-
$rsa_pub->use_sha512_hash;
301+
$hash_name = 'SHA512';
302302
} elsif ($sigalg eq 'http://www.w3.org/2000/09/xmldsig#rsa-sha1') {
303-
$rsa_pub->use_sha1_hash;
303+
$hash_name = 'SHA1';
304304
}
305305
else {
306306
warn "Unsupported Signature Algorithim: $sigalg, defaulting to sha256" if $self->debug;
307307
}
308308

309-
return 1 if $rsa_pub->verify($signed, $sig);
309+
return 1 if $rsa_pub->verify_message($sig, $signed, $hash_name, 'v1.5');
310310

311311
warn "Unable to verify with " . $cert->subject if $self->debug;
312312
}

0 commit comments

Comments
 (0)