Better random string generation (#1803)

This commit is contained in:
Xavier 2019-06-27 21:59:18 +02:00
parent b1f12b72e5
commit 2fcaf52bcf
15 changed files with 35 additions and 28 deletions

View File

@ -4,13 +4,13 @@
"Xavier Guimard <x.guimard@free.fr>, Clément Oudot <clement@oodo.net>" "Xavier Guimard <x.guimard@free.fr>, Clément Oudot <clement@oodo.net>"
], ],
"dynamic_config" : 1, "dynamic_config" : 1,
"generated_by" : "ExtUtils::MakeMaker version 7.24, CPAN::Meta::Converter version 2.150010", "generated_by" : "ExtUtils::MakeMaker version 7.34, CPAN::Meta::Converter version 2.150010",
"license" : [ "license" : [
"open_source" "open_source"
], ],
"meta-spec" : { "meta-spec" : {
"url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
"version" : "2" "version" : 2
}, },
"name" : "Lemonldap-NG-Common", "name" : "Lemonldap-NG-Common",
"no_index" : { "no_index" : {
@ -41,7 +41,8 @@
"DBI" : "0", "DBI" : "0",
"LWP::Protocol::https" : "0", "LWP::Protocol::https" : "0",
"Net::LDAP" : "0", "Net::LDAP" : "0",
"SOAP::Lite" : "0" "SOAP::Lite" : "0",
"String::Random" : "0"
}, },
"requires" : { "requires" : {
"Apache::Session" : "0", "Apache::Session" : "0",
@ -72,5 +73,5 @@
"x_MailingList" : "mailto:lemonldap-ng-dev@ow2.org" "x_MailingList" : "mailto:lemonldap-ng-dev@ow2.org"
}, },
"version" : "v2.0.4", "version" : "v2.0.4",
"x_serialization_backend" : "JSON::PP version 2.27400_02" "x_serialization_backend" : "JSON::PP version 2.97001"
} }

View File

@ -9,7 +9,7 @@ build_requires:
configure_requires: configure_requires:
ExtUtils::MakeMaker: '0' ExtUtils::MakeMaker: '0'
dynamic_config: 1 dynamic_config: 1
generated_by: 'ExtUtils::MakeMaker version 7.24, CPAN::Meta::Converter version 2.150010' generated_by: 'ExtUtils::MakeMaker version 7.34, CPAN::Meta::Converter version 2.150010'
license: open_source license: open_source
meta-spec: meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html url: http://module-build.sourceforge.net/META-spec-v1.4.html
@ -28,6 +28,7 @@ recommends:
LWP::Protocol::https: '0' LWP::Protocol::https: '0'
Net::LDAP: '0' Net::LDAP: '0'
SOAP::Lite: '0' SOAP::Lite: '0'
String::Random: '0'
requires: requires:
Apache::Session: '0' Apache::Session: '0'
Cache::Cache: '0' Cache::Cache: '0'

View File

@ -34,6 +34,7 @@ WriteMakefile(
'Convert::Base32' => 0, 'Convert::Base32' => 0,
'Cookie::Baker::XS' => 0, 'Cookie::Baker::XS' => 0,
'Crypt::URandom' => 0, 'Crypt::URandom' => 0,
'String::Random' => 0,
'DBI' => 0, 'DBI' => 0,
'Net::LDAP' => 0, 'Net::LDAP' => 0,
'SOAP::Lite' => 0, 'SOAP::Lite' => 0,

View File

@ -12,18 +12,25 @@ use strict;
use Crypt::Rijndael; use Crypt::Rijndael;
use MIME::Base64; use MIME::Base64;
use Digest::MD5 qw(md5); use Digest::MD5 qw(md5);
use String::Random;
use bytes; use bytes;
our $VERSION = '2.0.0'; our $VERSION = '2.0.0';
my $newIv; my ( $newIv, $randG );
BEGIN { BEGIN {
eval { require Crypt::URandom; Crypt::URandom::urandom(16) }; eval { require Crypt::URandom; Crypt::URandom::urandom(16) };
if ($@) { if ($@) {
$newIv = sub { return md5( rand() . time . {} ) }; $newIv = sub { return md5( rand() . time . {} ) };
$randG = sub {
my $a = 256;
$a = unpack( "C", Crypt::URandom::urandom(1) ) while ( $a > $_[0] );
return $a;
};
} }
else { else {
$newIv = sub { return Crypt::URandom::urandom(16) }; $newIv = sub { return Crypt::URandom::urandom(16) };
$randG = sub { return int( rand( $_[0] ) ) };
} }
} }
@ -190,4 +197,8 @@ sub _cryptHex {
return $data; return $data;
} }
sub srandom {
return String::Random->new( rand_gen => $randG );
}
1; 1;

View File

@ -4,13 +4,13 @@
"Xavier Guimard <x.guimard@free.fr>, Clément Oudot <clement@oodo.net>" "Xavier Guimard <x.guimard@free.fr>, Clément Oudot <clement@oodo.net>"
], ],
"dynamic_config" : 1, "dynamic_config" : 1,
"generated_by" : "ExtUtils::MakeMaker version 7.24, CPAN::Meta::Converter version 2.150010", "generated_by" : "ExtUtils::MakeMaker version 7.34, CPAN::Meta::Converter version 2.150010",
"license" : [ "license" : [
"open_source" "open_source"
], ],
"meta-spec" : { "meta-spec" : {
"url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
"version" : "2" "version" : 2
}, },
"name" : "Lemonldap-NG-Handler", "name" : "Lemonldap-NG-Handler",
"no_index" : { "no_index" : {
@ -59,5 +59,5 @@
"x_MailingList" : "mailto:lemonldap-ng-dev@ow2.org" "x_MailingList" : "mailto:lemonldap-ng-dev@ow2.org"
}, },
"version" : "v2.0.4", "version" : "v2.0.4",
"x_serialization_backend" : "JSON::PP version 2.27400_02" "x_serialization_backend" : "JSON::PP version 2.97001"
} }

View File

@ -11,7 +11,7 @@ build_requires:
configure_requires: configure_requires:
ExtUtils::MakeMaker: '0' ExtUtils::MakeMaker: '0'
dynamic_config: 1 dynamic_config: 1
generated_by: 'ExtUtils::MakeMaker version 7.24, CPAN::Meta::Converter version 2.150010' generated_by: 'ExtUtils::MakeMaker version 7.34, CPAN::Meta::Converter version 2.150010'
license: open_source license: open_source
meta-spec: meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html url: http://module-build.sourceforge.net/META-spec-v1.4.html

View File

@ -4,13 +4,13 @@
"Xavier Guimard <x.guimard@free.fr>, Clément Oudot <clement@oodo.net>" "Xavier Guimard <x.guimard@free.fr>, Clément Oudot <clement@oodo.net>"
], ],
"dynamic_config" : 1, "dynamic_config" : 1,
"generated_by" : "ExtUtils::MakeMaker version 7.24, CPAN::Meta::Converter version 2.150010", "generated_by" : "ExtUtils::MakeMaker version 7.34, CPAN::Meta::Converter version 2.150010",
"license" : [ "license" : [
"open_source" "open_source"
], ],
"meta-spec" : { "meta-spec" : {
"url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
"version" : "2" "version" : 2
}, },
"name" : "Lemonldap-NG-Manager", "name" : "Lemonldap-NG-Manager",
"no_index" : { "no_index" : {
@ -55,5 +55,5 @@
"x_MailingList" : "mailto:lemonldap-ng-dev@ow2.org" "x_MailingList" : "mailto:lemonldap-ng-dev@ow2.org"
}, },
"version" : "v2.0.4", "version" : "v2.0.4",
"x_serialization_backend" : "JSON::PP version 2.27400_02" "x_serialization_backend" : "JSON::PP version 2.97001"
} }

View File

@ -9,7 +9,7 @@ build_requires:
configure_requires: configure_requires:
ExtUtils::MakeMaker: '0' ExtUtils::MakeMaker: '0'
dynamic_config: 1 dynamic_config: 1
generated_by: 'ExtUtils::MakeMaker version 7.24, CPAN::Meta::Converter version 2.150010' generated_by: 'ExtUtils::MakeMaker version 7.34, CPAN::Meta::Converter version 2.150010'
license: open_source license: open_source
meta-spec: meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html url: http://module-build.sourceforge.net/META-spec-v1.4.html

View File

@ -4,13 +4,13 @@
"Xavier Guimard <x.guimard@free.fr>, Clément Oudot <clement@oodo.net>" "Xavier Guimard <x.guimard@free.fr>, Clément Oudot <clement@oodo.net>"
], ],
"dynamic_config" : 1, "dynamic_config" : 1,
"generated_by" : "ExtUtils::MakeMaker version 7.24, CPAN::Meta::Converter version 2.150010", "generated_by" : "ExtUtils::MakeMaker version 7.34, CPAN::Meta::Converter version 2.150010",
"license" : [ "license" : [
"open_source" "open_source"
], ],
"meta-spec" : { "meta-spec" : {
"url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
"version" : "2" "version" : 2
}, },
"name" : "Lemonldap-NG-Portal", "name" : "Lemonldap-NG-Portal",
"no_index" : { "no_index" : {
@ -57,7 +57,6 @@
"Net::OpenID::Consumer" : "0", "Net::OpenID::Consumer" : "0",
"Net::OpenID::Server" : "0", "Net::OpenID::Server" : "0",
"SOAP::Lite" : "0", "SOAP::Lite" : "0",
"String::Random" : "0",
"Unicode::String" : "0", "Unicode::String" : "0",
"Web::ID" : "0" "Web::ID" : "0"
}, },
@ -78,5 +77,5 @@
"x_MailingList" : "mailto:lemonldap-ng-dev@ow2.org" "x_MailingList" : "mailto:lemonldap-ng-dev@ow2.org"
}, },
"version" : "v2.0.4", "version" : "v2.0.4",
"x_serialization_backend" : "JSON::PP version 2.27400_02" "x_serialization_backend" : "JSON::PP version 2.97001"
} }

View File

@ -14,7 +14,7 @@ build_requires:
configure_requires: configure_requires:
ExtUtils::MakeMaker: '0' ExtUtils::MakeMaker: '0'
dynamic_config: 1 dynamic_config: 1
generated_by: 'ExtUtils::MakeMaker version 7.24, CPAN::Meta::Converter version 2.150010' generated_by: 'ExtUtils::MakeMaker version 7.34, CPAN::Meta::Converter version 2.150010'
license: open_source license: open_source
meta-spec: meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html url: http://module-build.sourceforge.net/META-spec-v1.4.html
@ -43,7 +43,6 @@ recommends:
Net::OpenID::Consumer: '0' Net::OpenID::Consumer: '0'
Net::OpenID::Server: '0' Net::OpenID::Server: '0'
SOAP::Lite: '0' SOAP::Lite: '0'
String::Random: '0'
Unicode::String: '0' Unicode::String: '0'
Web::ID: '0' Web::ID: '0'
requires: requires:

View File

@ -27,7 +27,6 @@ WriteMakefile(
'Net::OpenID::Consumer' => 0, 'Net::OpenID::Consumer' => 0,
'Net::OpenID::Server' => 0, 'Net::OpenID::Server' => 0,
'SOAP::Lite' => 0, 'SOAP::Lite' => 0,
'String::Random' => 0,
'Unicode::String' => 0, 'Unicode::String' => 0,
'Web::ID' => 0, 'Web::ID' => 0,
}, },

View File

@ -2,7 +2,6 @@ package Lemonldap::NG::Portal::2F::Ext2F;
use strict; use strict;
use Mouse; use Mouse;
use String::Random;
use Lemonldap::NG::Portal::Main::Constants qw( use Lemonldap::NG::Portal::Main::Constants qw(
PE_BADCREDENTIALS PE_BADCREDENTIALS
PE_ERROR PE_ERROR
@ -38,7 +37,7 @@ sub init {
$self->error("Missing 'ext2FSendCommand' parameter, aborting"); $self->error("Missing 'ext2FSendCommand' parameter, aborting");
return 0; return 0;
} }
$self->random( String::Random->new ); $self->random( Lemonldap::NG::Common::Crypto::srandom() );
$self->logo( $self->conf->{ext2fLogo} ) $self->logo( $self->conf->{ext2fLogo} )
if ( $self->conf->{ext2fLogo} ); if ( $self->conf->{ext2fLogo} );
return $self->SUPER::init(); return $self->SUPER::init();

View File

@ -2,7 +2,6 @@ package Lemonldap::NG::Portal::2F::Mail2F;
use strict; use strict;
use Mouse; use Mouse;
use String::Random;
use Lemonldap::NG::Portal::Main::Constants qw( use Lemonldap::NG::Portal::Main::Constants qw(
PE_BADCREDENTIALS PE_BADCREDENTIALS
PE_ERROR PE_ERROR
@ -23,7 +22,7 @@ has prefix => ( is => 'ro', default => 'mail' );
has random => ( has random => (
is => 'rw', is => 'rw',
default => sub { default => sub {
return String::Random->new; return Lemonldap::NG::Common::Crypto::srandom();
} }
); );

View File

@ -8,7 +8,6 @@ use Lemonldap::NG::Common::UserAgent;
use Lemonldap::NG::Common::FormEncode; use Lemonldap::NG::Common::FormEncode;
use XML::Simple; use XML::Simple;
use MIME::Base64; use MIME::Base64;
use String::Random;
use HTTP::Request; # SOAP call use HTTP::Request; # SOAP call
use POSIX qw(strftime); # Convert SAML2 date into timestamp use POSIX qw(strftime); # Convert SAML2 date into timestamp
use Time::Local; # Convert SAML2 date into timestamp use Time::Local; # Convert SAML2 date into timestamp

View File

@ -8,7 +8,6 @@ package Lemonldap::NG::Portal::Lib::SMTP;
use strict; use strict;
use Mouse; use Mouse;
use JSON qw(from_json); use JSON qw(from_json);
use String::Random;
use MIME::Entity; use MIME::Entity;
use Email::Sender::Simple qw(sendmail); use Email::Sender::Simple qw(sendmail);
use Email::Sender::Transport::SMTP qw(); use Email::Sender::Transport::SMTP qw();
@ -24,7 +23,7 @@ our $transport;
has random => ( has random => (
is => 'rw', is => 'rw',
default => sub { default => sub {
return String::Random->new; return Lemonldap::NG::Common::Crypto::srandom();
} }
); );
has charset => ( has charset => (