Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
Admin
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
osuny
Admin
Commits
0cf4ce11
Unverified
Commit
0cf4ce11
authored
2 years ago
by
Sébastien Gaya
Browse files
Options
Downloads
Patches
Plain Diff
rescue the other one
parent
0de17159
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
db/migrate/20230106132654_migrate_to_rails7_sha256_signature.rb
+15
-10
15 additions, 10 deletions
...rate/20230106132654_migrate_to_rails7_sha256_signature.rb
db/schema.rb
+1
-1
1 addition, 1 deletion
db/schema.rb
docs/_rd/digest_upgrade.md
+22
-15
22 additions, 15 deletions
docs/_rd/digest_upgrade.md
with
38 additions
and
26 deletions
db/migrate/20230106132654_migrate_to_rails7_sha256_signature.rb
+
15
−
10
View file @
0cf4ce11
...
...
@@ -32,17 +32,22 @@ class MigrateToRails7Sha256Signature < ActiveRecord::Migration[7.0]
blob
=
ActiveStorage
::
Blob
.
find_signed!
(
legacy_signed_id
)
legacy_signed_id
rescue
ActiveSupport
::
MessageVerifier
::
InvalidSignature
#
key_generator
=
ActiveSupport
::
KeyGenerator
.
new
(
Rails
.
application
.
secrets
.
secret_key_base
,
iterations:
1000
,
hash_digest_class:
OpenSSL
::
Digest
::
SHA1
)
key_generator
=
ActiveSupport
::
CachingKeyGenerator
.
new
(
key_generator
)
secret
=
key_generator
.
generate_key
(
"ActiveStorage"
)
verifier
=
ActiveSupport
::
MessageVerifier
.
new
(
secret
)
begin
# Try to find blob with ID from SHA1-signed_id
key_generator
=
ActiveSupport
::
KeyGenerator
.
new
(
Rails
.
application
.
secrets
.
secret_key_base
,
iterations:
1000
,
hash_digest_class:
OpenSSL
::
Digest
::
SHA1
)
key_generator
=
ActiveSupport
::
CachingKeyGenerator
.
new
(
key_generator
)
secret
=
key_generator
.
generate_key
(
"ActiveStorage"
)
verifier
=
ActiveSupport
::
MessageVerifier
.
new
(
secret
)
ActiveStorage
::
Blob
.
find_by_id
(
verifier
.
verify
(
legacy_signed_id
,
purpose: :blob_id
)).
try
(
:signed_id
)
ActiveStorage
::
Blob
.
find_by_id
(
verifier
.
verify
(
legacy_signed_id
,
purpose: :blob_id
)).
try
(
:signed_id
)
rescue
ActiveSupport
::
MessageVerifier
::
InvalidSignature
# Blob not found (SHA1 and SHA256), corrupted blob ID, ignore
legacy_signed_id
end
end
end
end
This diff is collapsed.
Click to expand it.
db/schema.rb
+
1
−
1
View file @
0cf4ce11
...
...
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
[
7.0
].
define
(
version:
2023_01_06_
094946
)
do
ActiveRecord
::
Schema
[
7.0
].
define
(
version:
2023_01_06_
132654
)
do
# These are extensions that must be enabled in order to support this database
enable_extension
"pgcrypto"
enable_extension
"plpgsql"
...
...
This diff is collapsed.
Click to expand it.
docs/_rd/digest_upgrade.md
+
22
−
15
View file @
0cf4ce11
...
...
@@ -19,21 +19,28 @@ Pour les fichiers médias, une mise à jour des sites web va actualiser sans pro
```
ruby
class
ActiveStorageKeyConverter
def
self
.
convert
(
legacy_signed_id
)
# Try to find blob with the un-modified legacy_signed_id
blob
=
ActiveStorage
::
Blob
.
find_signed!
(
legacy_signed_id
)
legacy_signed_id
rescue
ActiveSupport
::
MessageVerifier
::
InvalidSignature
#
key_generator
=
ActiveSupport
::
KeyGenerator
.
new
(
Rails
.
application
.
secrets
.
secret_key_base
,
iterations:
1000
,
hash_digest_class:
OpenSSL
::
Digest
::
SHA1
)
key_generator
=
ActiveSupport
::
CachingKeyGenerator
.
new
(
key_generator
)
secret
=
key_generator
.
generate_key
(
"ActiveStorage"
)
verifier
=
ActiveSupport
::
MessageVerifier
.
new
(
secret
)
ActiveStorage
::
Blob
.
find_by_id
(
verifier
.
verify
(
legacy_signed_id
,
purpose: :blob_id
)).
try
(
:signed_id
)
begin
# Try to find blob with the un-modified legacy_signed_id
blob
=
ActiveStorage
::
Blob
.
find_signed!
(
legacy_signed_id
)
legacy_signed_id
rescue
ActiveSupport
::
MessageVerifier
::
InvalidSignature
begin
# Try to find blob with ID from SHA1-signed_id
key_generator
=
ActiveSupport
::
KeyGenerator
.
new
(
Rails
.
application
.
secrets
.
secret_key_base
,
iterations:
1000
,
hash_digest_class:
OpenSSL
::
Digest
::
SHA1
)
key_generator
=
ActiveSupport
::
CachingKeyGenerator
.
new
(
key_generator
)
secret
=
key_generator
.
generate_key
(
"ActiveStorage"
)
verifier
=
ActiveSupport
::
MessageVerifier
.
new
(
secret
)
ActiveStorage
::
Blob
.
find_by_id
(
verifier
.
verify
(
legacy_signed_id
,
purpose: :blob_id
)).
try
(
:signed_id
)
rescue
ActiveSupport
::
MessageVerifier
::
InvalidSignature
# Blob not found (SHA1 and SHA256), corrupted blob ID, ignore
legacy_signed_id
end
end
end
end
```
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment