Skip to content

Commit 789db8a

Browse files
committed
Use passlib in place of legacycrypt
legacycrypt requires to install libcrypt.so.1 manually Keep legacycrypt as a dependency for now, to ease the transition to those who already have a custom data.py. Move hash_password() to lib.common, to make easier to change the implementation in the future. Signed-off-by: Gaëtan Lehmann <gaetan.lehmann@vates.tech>
1 parent f35020f commit 789db8a

7 files changed

Lines changed: 33 additions & 8 deletions

File tree

conftest.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818
callable_marker,
1919
is_uuid,
2020
prefix_object_name,
21-
setup_formatted_and_mounted_disk,
2221
shortened_nodeid,
23-
teardown_formatted_and_mounted_disk,
2422
vm_image,
2523
wait_for,
2624
)

data.py-dist

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ from __future__ import annotations
44

55
import os
66

7-
import legacycrypt as crypt # type: ignore[import-untyped]
7+
from lib.common import hash_password
88

99
from typing import TYPE_CHECKING, Any
1010

@@ -17,11 +17,6 @@ if TYPE_CHECKING:
1717
HOST_DEFAULT_USER = "root"
1818
HOST_DEFAULT_PASSWORD = ""
1919

20-
def hash_password(password):
21-
"""Hash password for /etc/password."""
22-
salt = crypt.mksalt(crypt.METHOD_SHA512) # type: ignore
23-
return crypt.crypt(password, salt)
24-
2520
HOST_DEFAULT_PASSWORD_HASH = hash_password(HOST_DEFAULT_PASSWORD)
2621

2722
# Public keys for a private keys available to the test runner

lib/common.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from uuid import UUID
1919

2020
import requests
21+
from passlib.hash import sha512_crypt
2122
from pydantic import TypeAdapter
2223

2324
from typing import (
@@ -366,3 +367,7 @@ def _param_clear(host: Host, xe_prefix: str, uuid: str, param_name: str) -> None
366367
""" Common implementation for param_clear. """
367368
args: dict[str, str | bool | dict[str, str]] = {'uuid': uuid, 'param-name': param_name}
368369
host.xe(f'{xe_prefix}-param-clear', args)
370+
371+
def hash_password(password: str) -> str:
372+
"""Hash password for /etc/password."""
373+
return sha512_crypt.using(rounds=5000).hash(password)

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ requires-python = ">=3.11"
77
dependencies = [
88
"cryptography>=3.3.1",
99
"gitpython",
10+
# TODO: keep legacycrypt to let the user transition to lib.common.hash_password in their data.py
1011
"legacycrypt",
1112
"packaging>=20.7",
13+
"passlib",
1214
"pluggy>=1.1.0",
1315
"pydantic",
1416
"pytest>=8.0.0",
@@ -32,6 +34,7 @@ dev = [
3234
"types-colorama",
3335
"types-pexpect",
3436
"zizmor",
37+
"types-passlib",
3538
]
3639

3740
[tool.pyright]

requirements/base.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ cryptography>=3.3.1
33
gitpython
44
legacycrypt
55
packaging>=20.7
6+
passlib
67
pluggy>=1.1.0
78
pydantic
89
pytest>=8.0.0

requirements/dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ types-pygments
1313
types-colorama
1414
types-pexpect
1515
zizmor
16+
types-passlib
1617
-r base.txt

uv.lock

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)