mirror of
https://github.com/ChristianLight/tutor.git
synced 2025-04-02 09:41:50 +00:00
Switch from crypt to bcrypt for htpasswd generation
This is more portable, as described here: https://github.com/overhangio/tutor/issues/381
This commit is contained in:
parent
02cc106af3
commit
6848253b8e
@ -4,6 +4,7 @@ Note: Breaking changes between versions are indicated by "💥".
|
|||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
- [Improvement] Switch to `bcrypt` for htpasswd password generation, for better portability on Windows.
|
||||||
- [Improvement] In the openedx production docker image, add some jitter to the gunicorn worker restart process to prevent all workers from restarting at the same time.
|
- [Improvement] In the openedx production docker image, add some jitter to the gunicorn worker restart process to prevent all workers from restarting at the same time.
|
||||||
|
|
||||||
## v10.4.0 (2020-10-30)
|
## v10.4.0 (2020-10-30)
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
import base64
|
import base64
|
||||||
from crypt import crypt
|
|
||||||
from hmac import compare_digest
|
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
@ -12,6 +10,7 @@ import sys
|
|||||||
|
|
||||||
import click
|
import click
|
||||||
from Crypto.PublicKey import RSA
|
from Crypto.PublicKey import RSA
|
||||||
|
from Crypto.Protocol.KDF import bcrypt, bcrypt_check
|
||||||
|
|
||||||
from . import exceptions
|
from . import exceptions
|
||||||
from . import fmt
|
from . import fmt
|
||||||
@ -19,20 +18,23 @@ from . import fmt
|
|||||||
|
|
||||||
def encrypt(text):
|
def encrypt(text):
|
||||||
"""
|
"""
|
||||||
Encrypt some textual content. The method employed is the same as suggested in the
|
Encrypt some textual content with bcrypt.
|
||||||
`python docs <https://docs.python.org/3/library/crypt.html#examples>`__. The
|
https://pycryptodome.readthedocs.io/en/latest/src/protocol/kdf.html#bcrypt
|
||||||
encryption process is compatible with the password verification performed by
|
The encryption process is compatible with the password verification performed by
|
||||||
`htpasswd <https://httpd.apache.org/docs/2.4/programs/htpasswd.html>`__.
|
`htpasswd <https://httpd.apache.org/docs/2.4/programs/htpasswd.html>`__.
|
||||||
"""
|
"""
|
||||||
hashed = crypt(text)
|
return bcrypt(text.encode(), 12).decode()
|
||||||
return crypt(text, hashed)
|
|
||||||
|
|
||||||
|
|
||||||
def verify_encrypted(encrypted, text):
|
def verify_encrypted(encrypted, text):
|
||||||
"""
|
"""
|
||||||
Return True/False if the encrypted content corresponds to the unencrypted text.
|
Return True/False if the encrypted content corresponds to the unencrypted text.
|
||||||
"""
|
"""
|
||||||
return compare_digest(crypt(text, encrypted), encrypted)
|
try:
|
||||||
|
bcrypt_check(text.encode(), encrypted.encode())
|
||||||
|
return True
|
||||||
|
except ValueError:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def ensure_file_directory_exists(path):
|
def ensure_file_directory_exists(path):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user