Skip to content

Commit 6ecf106

Browse files
authored
Merge pull request rails#41722 from dbussink/openssl-constants
Always use OpenSSL constants for Digest operations
2 parents e8daf30 + 0523532 commit 6ecf106

File tree

37 files changed

+110
-73
lines changed

37 files changed

+110
-73
lines changed

actioncable/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* OpenSSL constants are now used for Digest computations.
2+
3+
*Dirkjan Bussink*
4+
15
* The Action Cable client now includes safeguards to prevent a "thundering
26
herd" of client reconnects after server connectivity loss:
37

actioncable/lib/action_cable/subscription_adapter/postgresql.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
gem "pg", "~> 1.1"
44
require "pg"
55
require "thread"
6-
require "digest/sha1"
6+
require "openssl"
77

88
module ActionCable
99
module SubscriptionAdapter
@@ -58,7 +58,7 @@ def with_broadcast_connection(&block) # :nodoc:
5858

5959
private
6060
def channel_identifier(channel)
61-
channel.size > 63 ? Digest::SHA1.hexdigest(channel) : channel
61+
channel.size > 63 ? OpenSSL::Digest::SHA1.hexdigest(channel) : channel
6262
end
6363

6464
def listener

actionmailbox/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@
22

33
*Santiago Bartesaghi*
44

5+
* OpenSSL constants are now used for Digest computations.
6+
7+
*Dirkjan Bussink*
58

69
Please check [6-1-stable](https://github.com/rails/rails/blob/6-1-stable/actionmailbox/CHANGELOG.md) for previous changes.

actionmailbox/app/models/action_mailbox/inbound_email/message_id.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module ActionMailbox::InboundEmail::MessageId
1414
# attachment called +raw_email+. Before the upload, extract the Message-ID from the +source+ and set
1515
# it as an attribute on the new +InboundEmail+.
1616
def create_and_extract_message_id!(source, **options)
17-
message_checksum = Digest::SHA1.hexdigest(source)
17+
message_checksum = OpenSSL::Digest::SHA1.hexdigest(source)
1818
message_id = extract_message_id(source) || generate_missing_message_id(message_checksum)
1919

2020
create! raw_email: create_and_upload_raw_email!(source),

actionpack/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* OpenSSL constants are now used for Digest computations.
2+
3+
*Dirkjan Bussink*
4+
15
* Remove IE6-7-8 file download related hack/fix from ActionController::DataStreaming module
26

37
Due to the age of those versions of IE this fix is no longer relevant, more importantly it creates an edge-case for unexpected Cache-Control headers.

actionpack/lib/action_controller/metal/http_authentication.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,11 @@ def authentication_request(controller, realm, message)
138138
#
139139
# === Simple \Digest example
140140
#
141-
# require "digest/md5"
141+
# require "openssl"
142142
# class PostsController < ApplicationController
143143
# REALM = "SuperSecret"
144144
# USERS = {"dhh" => "secret", #plain text password
145-
# "dap" => Digest::MD5.hexdigest(["dap",REALM,"secret"].join(":"))} #ha1 digest password
145+
# "dap" => OpenSSL::Digest::MD5.hexdigest(["dap",REALM,"secret"].join(":"))} #ha1 digest password
146146
#
147147
# before_action :authenticate, except: [:index]
148148
#
@@ -230,12 +230,12 @@ def validate_digest_response(request, realm, &password_procedure)
230230
# of a plain-text password.
231231
def expected_response(http_method, uri, credentials, password, password_is_ha1 = true)
232232
ha1 = password_is_ha1 ? password : ha1(credentials, password)
233-
ha2 = ::Digest::MD5.hexdigest([http_method.to_s.upcase, uri].join(":"))
234-
::Digest::MD5.hexdigest([ha1, credentials[:nonce], credentials[:nc], credentials[:cnonce], credentials[:qop], ha2].join(":"))
233+
ha2 = OpenSSL::Digest::MD5.hexdigest([http_method.to_s.upcase, uri].join(":"))
234+
OpenSSL::Digest::MD5.hexdigest([ha1, credentials[:nonce], credentials[:nc], credentials[:cnonce], credentials[:qop], ha2].join(":"))
235235
end
236236

237237
def ha1(credentials, password)
238-
::Digest::MD5.hexdigest([credentials[:username], credentials[:realm], password].join(":"))
238+
OpenSSL::Digest::MD5.hexdigest([credentials[:username], credentials[:realm], password].join(":"))
239239
end
240240

241241
def encode_credentials(http_method, credentials, password, password_is_ha1)
@@ -309,7 +309,7 @@ def secret_token(request)
309309
def nonce(secret_key, time = Time.now)
310310
t = time.to_i
311311
hashed = [t, secret_key]
312-
digest = ::Digest::MD5.hexdigest(hashed.join(":"))
312+
digest = OpenSSL::Digest::MD5.hexdigest(hashed.join(":"))
313313
::Base64.strict_encode64("#{t}:#{digest}")
314314
end
315315

@@ -326,7 +326,7 @@ def validate_nonce(secret_key, request, value, seconds_to_timeout = 5 * 60)
326326

327327
# Opaque based on digest of secret key
328328
def opaque(secret_key)
329-
::Digest::MD5.hexdigest(secret_key)
329+
OpenSSL::Digest::MD5.hexdigest(secret_key)
330330
end
331331
end
332332

actionpack/test/controller/http_digest_authentication_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class DummyDigestController < ActionController::Base
99
before_action :authenticate_with_request, only: :display
1010

1111
USERS = { "lifo" => "world", "pretty" => "please",
12-
"dhh" => ::Digest::MD5.hexdigest(["dhh", "SuperSecret", "secret"].join(":")) }
12+
"dhh" => OpenSSL::Digest::MD5.hexdigest(["dhh", "SuperSecret", "secret"].join(":")) }
1313

1414
def index
1515
render plain: "Hello Secret"
@@ -185,7 +185,7 @@ def authenticate_with_request
185185
test "authentication request with password stored as ha1 digest hash" do
186186
@request.env["HTTP_AUTHORIZATION"] = encode_credentials(
187187
username: "dhh",
188-
password: ::Digest::MD5.hexdigest(["dhh", "SuperSecret", "secret"].join(":")),
188+
password: OpenSSL::Digest::MD5.hexdigest(["dhh", "SuperSecret", "secret"].join(":")),
189189
password_is_ha1: true)
190190
get :display
191191

actiontext/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* OpenSSL constants are now used for Digest computations.
2+
3+
*Dirkjan Bussink*
4+
15
* Add support for passing `form:` option to `rich_text_area_tag` and
26
`rich_text_area` helpers to specify the `<input type="hidden" form="...">`
37
value.

actiontext/lib/action_text/attachments/caching.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def cache_key(*args)
99

1010
private
1111
def cache_digest
12-
Digest::SHA256.hexdigest(node.to_s)
12+
OpenSSL::Digest::SHA256.hexdigest(node.to_s)
1313
end
1414
end
1515
end

actionview/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* OpenSSL constants are now used for Digest computations.
2+
3+
*Dirkjan Bussink*
4+
15
* The `translate` helper now passes `default` values that aren't
26
translation keys through `I18n.translate` for interpolation.
37

0 commit comments

Comments
 (0)