Unifomize license headers

This commit is contained in:
Alexandre Iooss 2022-03-11 17:16:11 +01:00
parent 9dc40279fa
commit 8d44182af8
51 changed files with 249 additions and 135 deletions

View file

@ -1,3 +1,7 @@
# This file is part of photo21
# Copyright (C) 2022 Amicale des élèves de l'ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
import hashlib
import base64
from collections import OrderedDict
@ -15,11 +19,12 @@ class SHA512PasswordHasher(BasePasswordHasher):
It is used to migrate passwords from old Symfony2 photos server.
https://github.com/symfony/symfony/blob/2.8/src/Symfony/Component/Security/Core/Encoder/MessageDigestPasswordEncoder.php
"""
algorithm = "sha512"
def encode(self, password, iteration, salt):
assert password is not None
assert salt and '$' not in salt
assert salt and "$" not in salt
salted = force_bytes(password + "{" + salt + "}")
digest = hashlib.sha512(salted).digest()
# "stretch" hash
@ -30,19 +35,21 @@ class SHA512PasswordHasher(BasePasswordHasher):
return encoded[:128]
def verify(self, password, encoded):
algorithm, iteration, salt, hash = encoded.split('$', 3)
algorithm, iteration, salt, hash = encoded.split("$", 3)
assert algorithm == self.algorithm
encoded_2 = self.encode(password, iteration, salt)
return constant_time_compare(encoded, encoded_2)
def safe_summary(self, encoded):
algorithm, iteration, salt, hash = encoded.split('$', 3)
algorithm, iteration, salt, hash = encoded.split("$", 3)
assert algorithm == self.algorithm
return OrderedDict([
(_('algorithm'), algorithm),
(_('salt'), mask_hash(salt, show=2)),
(_('hash'), mask_hash(hash)),
])
return OrderedDict(
[
(_("algorithm"), algorithm),
(_("salt"), mask_hash(salt, show=2)),
(_("hash"), mask_hash(hash)),
]
)
def harden_runtime(self, password, encoded):
pass