Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions data.py-dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ from __future__ import annotations

import os

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

from typing import TYPE_CHECKING, Any

Expand All @@ -17,11 +17,6 @@ if TYPE_CHECKING:
HOST_DEFAULT_USER = "root"
HOST_DEFAULT_PASSWORD = ""

def hash_password(password):
"""Hash password for /etc/password."""
salt = crypt.mksalt(crypt.METHOD_SHA512) # type: ignore
return crypt.crypt(password, salt)

HOST_DEFAULT_PASSWORD_HASH = hash_password(HOST_DEFAULT_PASSWORD)

# Public keys for a private keys available to the test runner
Expand Down
6 changes: 6 additions & 0 deletions lib/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from uuid import UUID

import requests
from passlib.hash import sha512_crypt
from pydantic import TypeAdapter

from typing import (
Expand Down Expand Up @@ -398,3 +399,8 @@ def _param_clear(host: Host, xe_prefix: str, uuid: str, param_name: str) -> None
""" Common implementation for param_clear. """
args: dict[str, str | bool | dict[str, str]] = {'uuid': uuid, 'param-name': param_name}
host.xe(f'{xe_prefix}-param-clear', args)

def hash_password(password: str) -> str:
"""Hash password for /etc/shadow."""
# XCP-ng uses sha512 with 5000 rounds by default
return sha512_crypt.using(rounds=5000).hash(password)
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ requires-python = ">=3.11"
dependencies = [
"cryptography>=3.3.1",
"gitpython",
# TODO: keep legacycrypt to let the user transition to lib.common.hash_password in their data.py
"legacycrypt",
Comment thread
olivierh-pro marked this conversation as resolved.
"packaging>=20.7",
"passlib",
"pluggy>=1.1.0",
"pydantic",
"pytest>=8.0.0",
Expand All @@ -34,6 +36,7 @@ dev = [
"zizmor",
"prek>=0.4.1",
"autopep8",
"types-passlib",
]

[tool.pyright]
Expand Down
1 change: 1 addition & 0 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ cryptography>=3.3.1
gitpython
legacycrypt
packaging>=20.7
passlib
pluggy>=1.1.0
pydantic
pytest>=8.0.0
Expand Down
1 change: 1 addition & 0 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ types-pexpect
zizmor
prek>=0.4.1
autopep8
types-passlib
-r base.txt
22 changes: 22 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading