razor.patch 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. From 1a8dc0ea64c6bbe187babdb1079bc0cf05926e59 Mon Sep 17 00:00:00 2001
  2. From: Robert Scheck <robert@fedoraproject.org>
  3. Date: Fri, 10 Dec 2021 00:21:56 +0100
  4. Subject: [PATCH] Use Digest::SHA instead of Digest::SHA1
  5. Switch from Digest::SHA1 to Digest::SHA, because: Digest::SHA is a bit
  6. faster than Digest::SHA1, Digest::SHA1 has been removed from some Linux
  7. distributions, Digest::SHA is a core library (as of Perl >= 5.10.0) and
  8. Digest::SHA1 is not (and never will be). See also:
  9. - https://src.fedoraproject.org/rpms/perl-Razor-Agent/c/75fa8a6c1f1fdf779312dac68f331a288bd2920f?branch=rawhide
  10. - https://stackoverflow.com/questions/3420720/what-are-the-advantages-of-digestsha-over-digestsha1
  11. Original author: Warren Togami <wtogami@redhat.com>
  12. ---
  13. INSTALL | 2 +-
  14. META.json | 2 +-
  15. META.yml | 2 +-
  16. Makefile.PL | 2 +-
  17. lib/Razor2/Client/Engine.pm | 1 -
  18. lib/Razor2/Signature/Ephemeral.pm | 14 +++++++-------
  19. lib/Razor2/Signature/Whiplash.pm | 14 ++++++--------
  20. lib/Razor2/String.pm | 17 +++++++----------
  21. 8 files changed, 24 insertions(+), 30 deletions(-)
  22. diff --git a/INSTALL b/INSTALL
  23. index 2de1b42..1852ba0 100644
  24. --- a/INSTALL
  25. +++ b/INSTALL
  26. @@ -25,7 +25,7 @@ option, like so:
  27. following Perl modules from CPAN:
  28. Time::HiRes
  29. - Digest::SHA1
  30. + Digest::SHA
  31. MIME::Base64
  32. Test::Simple
  33. Test::Harness
  34. diff --git a/META.json b/META.json
  35. index f893748..e616292 100644
  36. --- a/META.json
  37. +++ b/META.json
  38. @@ -33,7 +33,7 @@
  39. },
  40. "runtime" : {
  41. "requires" : {
  42. - "Digest::SHA1" : "0",
  43. + "Digest::SHA" : "0",
  44. "File::Copy" : "0",
  45. "File::Spec" : "0",
  46. "Getopt::Long" : "0",
  47. diff --git a/META.yml b/META.yml
  48. index 4a0831c..314b0fc 100644
  49. --- a/META.yml
  50. +++ b/META.yml
  51. @@ -19,7 +19,7 @@ no_index:
  52. - t
  53. - inc
  54. requires:
  55. - Digest::SHA1: '0'
  56. + Digest::SHA: '0'
  57. File::Copy: '0'
  58. File::Spec: '0'
  59. Getopt::Long: '0'
  60. diff --git a/Makefile.PL b/Makefile.PL
  61. index 833d1dc..095f7e3 100644
  62. --- a/Makefile.PL
  63. +++ b/Makefile.PL
  64. @@ -22,7 +22,7 @@ WriteMakefile(
  65. ( $ExtUtils::MakeMaker::VERSION >= 6.3002 ? ( 'LICENSE' => 'perl', ) : () ),
  66. EXE_FILES => [qw( bin/razor-client bin/razor-admin bin/razor-check bin/razor-report bin/razor-revoke )],
  67. PREREQ_PM => {
  68. - 'Digest::SHA1' => 0,
  69. + 'Digest::SHA' => 0,
  70. 'File::Copy' => 0,
  71. 'File::Spec' => 0,
  72. 'Getopt::Long' => 0,
  73. diff --git a/lib/Razor2/Client/Engine.pm b/lib/Razor2/Client/Engine.pm
  74. index 98f2f44..f3610b4 100644
  75. --- a/lib/Razor2/Client/Engine.pm
  76. +++ b/lib/Razor2/Client/Engine.pm
  77. @@ -1,7 +1,6 @@
  78. package Razor2::Client::Engine;
  79. use strict;
  80. -use Digest::SHA1 qw(sha1_hex);
  81. use Data::Dumper;
  82. use Razor2::Signature::Ephemeral;
  83. use Razor2::Engine::VR8;
  84. diff --git a/lib/Razor2/Signature/Ephemeral.pm b/lib/Razor2/Signature/Ephemeral.pm
  85. index 4310b6c..6764e8e 100644
  86. --- a/lib/Razor2/Signature/Ephemeral.pm
  87. +++ b/lib/Razor2/Signature/Ephemeral.pm
  88. @@ -2,9 +2,13 @@
  89. package Razor2::Signature::Ephemeral;
  90. use strict;
  91. -use Digest::SHA1;
  92. use Data::Dumper;
  93. +BEGIN {
  94. + eval { require Digest::SHA; import Digest::SHA qw(sha1_hex); 1 }
  95. + or do { require Digest::SHA1; import Digest::SHA1 qw(sha1_hex) }
  96. +}
  97. +
  98. sub new {
  99. my ( $class, %args ) = @_;
  100. @@ -88,17 +92,13 @@ sub hexdigest {
  101. }
  102. my $digest;
  103. - my $ctx = Digest::SHA1->new;
  104. if ( $seclength > 128 ) {
  105. - $ctx->add($section1);
  106. - $ctx->add($section2);
  107. - $digest = $ctx->hexdigest;
  108. + $digest = sha1_hex($section1, $section2);
  109. }
  110. else {
  111. debug("Sections too small... reverting back to orginal content.");
  112. - $ctx->add($content);
  113. - $digest = $ctx->hexdigest;
  114. + $digest = sha1_hex($content);
  115. }
  116. debug("Computed e-hash is $digest");
  117. diff --git a/lib/Razor2/Signature/Whiplash.pm b/lib/Razor2/Signature/Whiplash.pm
  118. index 2977371..40ace61 100644
  119. --- a/lib/Razor2/Signature/Whiplash.pm
  120. +++ b/lib/Razor2/Signature/Whiplash.pm
  121. @@ -7,7 +7,10 @@
  122. package Razor2::Signature::Whiplash;
  123. -use Digest::SHA1;
  124. +BEGIN {
  125. + eval { require Digest::SHA; import Digest::SHA qw(sha1_hex); 1 }
  126. + or do { require Digest::SHA1; import Digest::SHA1 qw(sha1_hex) }
  127. +}
  128. sub new {
  129. @@ -682,13 +685,8 @@ sub whiplash {
  130. # the value of length to the nearest multiple of ``length_error''.
  131. # Take the first 20 hex chars from SHA1 and call it the signature.
  132. - my $sha1 = Digest::SHA1->new();
  133. -
  134. - $sha1->add($host);
  135. - $sig = substr $sha1->hexdigest, 0, 12;
  136. -
  137. - $sha1->add($corrected_length);
  138. - $sig .= substr $sha1->hexdigest, 0, 4;
  139. + $sig = substr sha1_hex($host), 0, 12;
  140. + $sig .= substr sha1_hex($corrected_length), 0, 4;
  141. push @sigs, $sig;
  142. $sig_meta{$sig} = [ $host, $corrected_length ];
  143. diff --git a/lib/Razor2/String.pm b/lib/Razor2/String.pm
  144. index dbcb903..b623917 100644
  145. --- a/lib/Razor2/String.pm
  146. +++ b/lib/Razor2/String.pm
  147. @@ -1,11 +1,15 @@
  148. # $Id: String.pm,v 1.48 2005/06/13 21:09:59 vipul Exp $
  149. package Razor2::String;
  150. -use Digest::SHA1 qw(sha1_hex);
  151. use URI::Escape;
  152. use Razor2::Preproc::enBase64;
  153. use Data::Dumper;
  154. +BEGIN {
  155. + eval { require Digest::SHA; import Digest::SHA qw(sha1_hex); 1 }
  156. + or do { require Digest::SHA1; import Digest::SHA1 qw(sha1_hex) }
  157. +}
  158. +
  159. #use MIME::Parser;
  160. require Exporter;
  161. @@ -65,15 +69,8 @@ sub hmac2_sha1 {
  162. return unless $text && $iv1 && $iv2;
  163. die "no ref's allowed" if ref($text);
  164. - my $ctx = Digest::SHA1->new;
  165. - $ctx->add($iv2);
  166. - $ctx->add($text);
  167. - my $digest = $ctx->hexdigest;
  168. -
  169. - $ctx = Digest::SHA1->new;
  170. - $ctx->add($iv1);
  171. - $ctx->add($digest);
  172. - $digest = $ctx->hexdigest;
  173. + my $digest = sha1_hex($iv2, $text);
  174. + $digest = sha1_hex($iv1, $digest);
  175. return ( hextobase64($digest), $digest );
  176. }