-
Notifications
You must be signed in to change notification settings - Fork 963
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use a hash based file paths on *new* uploads
Instead of using a file path like {pyver}/{name[0]}/{name}/{filename}, we will instead use one that looks like {hash[:2]}/{hash[2:4]}/{hash[4:]}{filename}, where `hash` is the blake2b(digest_size=32) hex digest (lowercased) of the actual file contents. This will ensure that the contents referred to by a specific file URL cannot change without also changing the URL. This also adds File.blake2_256_digest to hold this new hash.
- Loading branch information
Showing
8 changed files
with
146 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
warehouse/migrations/versions/0977b97fce94_add_file_blake2_256_digest.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
""" | ||
Add File.blake2_256_digest | ||
Revision ID: 0977b97fce94 | ||
Revises: f46672a776f1 | ||
Create Date: 2016-04-18 20:40:22.101245 | ||
""" | ||
|
||
import citext | ||
import sqlalchemy as sa | ||
|
||
from alembic import op | ||
|
||
|
||
revision = "0977b97fce94" | ||
down_revision = "f46672a776f1" | ||
|
||
|
||
def upgrade(): | ||
op.add_column( | ||
"release_files", | ||
sa.Column("blake2_256_digest", citext.CIText(), nullable=True), | ||
) | ||
op.create_unique_constraint(None, "release_files", ["blake2_256_digest"]) | ||
op.create_check_constraint( | ||
None, | ||
"release_files", | ||
"sha256_digest ~* '^[A-F0-9]{64}$'", | ||
) | ||
|
||
|
||
def downgrade(): | ||
raise RuntimeError("Cannot Go Backwards In Time.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43e9a7b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity, why Blake2b instead of something, well, more standard?
43e9a7b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blake2 is faster than MD5, Sha1, Sha2, and Sha3 while being at least as secure (in terms of bits of protection against preimage and collision resistance)... but really mostly because I like it and there wasn't any reason not to :)