Skip to content
This repository has been archived by the owner on Aug 15, 2024. It is now read-only.

Commit

Permalink
Merge pull request #14 from c4dt/release-candidate
Browse files Browse the repository at this point in the history
fix update workflow
  • Loading branch information
PascalinDe authored Oct 17, 2023
2 parents e7cee8b + d73ce2e commit d9b029a
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 201 deletions.
4 changes: 3 additions & 1 deletion tools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ $(CACHE_CERT) $(CACHE_AUTH) $(CACHE_CONS) $(CACHE_MICRO):
--authority-signing-key $(AUTH_SIGN) \
--authority-certificate $(CACHE_CERT) \
--consensus $(CACHE_CONS) \
--microdescriptors $(CACHE_MICRO)
--microdescriptors $(CACHE_MICRO) \
--ignore \
-n 122

churn: cache
. $(VENV)/bin/activate && ./gen_fresh_dirinfo.py compute-churn \
Expand Down
142 changes: 90 additions & 52 deletions tools/gen_fresh_dirinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
)
from heapq import nlargest
from math import ceil, floor
from itertools import zip_longest
from os import environ
from pathlib import Path
from subprocess import (
Expand Down Expand Up @@ -161,6 +160,12 @@ class ChurnAboveThreshold(Exception):
"""


class InvalidNumberRouters(Exception):
"""
Less than the asked for number of routers could be successfully retrieved.
"""


def setup_logger() -> logging.Logger:
"""
Setup the logger.
Expand Down Expand Up @@ -357,39 +362,65 @@ def fetch_latest_consensus() -> NetworkStatusDocumentV3:
return consensus


# replace w/ itertools.batched in Python 3.12
def batched(iterable: List[str], n: int):
"""Break up list of strings into batches of size n.
:param iterable: list of strings
:param n: size
"""
for i in range(0, len(iterable) - n, n):
yield iterable[i : i + n]
if len(iterable) % n:
yield iterable[(len(iterable) // n) * n :]


def fetch_microdescriptors(
routers: List[RouterStatusEntryMicroV3],
ignore: bool = False,
) -> List[Microdescriptor]:
"""
Fetch the microdescriptors described in the entries.
:param routers: list of routers status found in the consensus for which we want the
microdescriptors
:param ignore: skip invalid microdescriptors
:raises ValueError: Did not retrieve the expected microdescriptor format.
:return: a list of microdescriptors
"""
downloader = DescriptorDownloader()
microdescriptors: List[Microdescriptor] = list()
buckets = [
iter(r.microdescriptor_digest for r in routers)
] * MAX_MICRODESCRIPTOR_HASHES
for bucket in zip_longest(*buckets):
buckets = list(
batched(
[router.microdescriptor_digest for router in routers],
MAX_MICRODESCRIPTOR_HASHES,
)
)
for bucket in buckets:
digests = [h for h in bucket if h is not None]
LOGGER.info(f"attempting to retrieve {len(digests)} microdescriptors")
microdescriptors_bucket = downloader.get_microdescriptors(
hashes=digests, validate=True
).run()

digests_set = set(digests)
for microdescriptor in microdescriptors_bucket:
LOGGER.info(f"retrieved {len(list(microdescriptors_bucket))} microdescriptors")
for microdescriptor in list(microdescriptors_bucket):
if not isinstance(microdescriptor, Microdescriptor):
raise ValueError(
f"Unexpected microdescriptor format {type(microdescriptor)}"
)

if microdescriptor.digest() not in digests_set:
raise ValueError("Unexpected microdescriptor retrieved.")
if not ignore:
raise ValueError("Unexpected microdescriptor retrieved.")
LOGGER.warning(
f"skip microdescriptor '{microdescriptor.digest()}': unknown microdescriptor" # noqa: E501
)
microdescriptors_bucket.remove(microdescriptor)

microdescriptors += microdescriptors_bucket

Expand Down Expand Up @@ -916,6 +947,7 @@ def generate_customized_consensus(
authority_orport: int,
authority_contact: str,
consensus_validity_days: int,
ignore: bool = False,
) -> None:
"""
Generate a customized consensus from data retrieved from the Tor network
Expand All @@ -934,24 +966,24 @@ def generate_customized_consensus(
:param authority_orport: directory authority's ORPort
:param authority_contact: directory authorty's contact
:param consensus_validity_days: number of days consensus should be valid
:param ignore: continue even if less than number_routers could be retrieved
:raises: InvalidConsensus if signature validation failed
:raises: InvalidNumberRouters if less than number_routers could be retrieved and
ignore is False
"""

# Read the relevant input files related to the authority.

authority_signing_key_raw = authority_signing_key_path.read_bytes()

authority_signing_key = RSA.import_key(authority_signing_key_raw)
authority_signing_key = RSA.import_key(authority_signing_key_path.read_bytes())

authority_certificate_raw = authority_certificate_path.read_bytes()

authority_certificate = KeyCertificate(authority_certificate_raw)
authority_certificate = KeyCertificate(authority_certificate_path.read_bytes())

consensus_original = fetch_latest_consensus()

v3idents = [auth.v3ident for auth in consensus_original.directory_authorities]
key_certificates = fetch_certificates(v3idents)
key_certificates = fetch_certificates(
[auth.v3ident for auth in consensus_original.directory_authorities]
)

# The validation provided by Stem does not works for microdescriptor
# consensus with the tested version (1.8.0).
Expand All @@ -962,12 +994,10 @@ def generate_customized_consensus(
auth_mtbf = authorities[AUTHORITY_MTBF_MEASURE]
vote_mtbf = fetch_vote(auth_mtbf)

key_cert_mtbf = list(
filter(lambda c: c.fingerprint == auth_mtbf.v3ident, key_certificates)
)

try:
vote_mtbf.validate_signatures(key_cert_mtbf)
vote_mtbf.validate_signatures(
list(filter(lambda c: c.fingerprint == auth_mtbf.v3ident, key_certificates))
)
except ValueError as err:
raise InvalidVote(str(err))

Expand All @@ -976,6 +1006,22 @@ def generate_customized_consensus(
vote_mtbf,
number_routers,
)
microdescriptors = fetch_microdescriptors(routers, ignore=ignore)
microdescriptor_hashes = [
microdescriptor.digest() for microdescriptor in microdescriptors
]
for router in list(routers):
if router.microdescriptor_digest not in microdescriptor_hashes:
LOGGER.warning(
f"skip router '{router.nickname}' ({router.fingerprint}): failed to retrieve microdescriptor" # noqa: E501
)
routers.remove(router)
if len(routers) < number_routers:
msg = f"only {len(routers)}/{number_routers} successfully retrieved"
if not ignore:
LOGGER.error(msg)
raise InvalidNumberRouters(msg)
LOGGER.warning(msg)

consensus = generate_signed_consensus(
consensus_original,
Expand All @@ -991,17 +1037,15 @@ def generate_customized_consensus(
consensus_validity_days,
)

our_consensus = NetworkStatusDocumentV3(consensus)
if not consensus_validate_signatures(our_consensus, [authority_certificate]):
if not consensus_validate_signatures(
NetworkStatusDocumentV3(consensus),
[authority_certificate],
):
raise InvalidConsensus("generated concensus has an invalid signature.")

microdescriptors = fetch_microdescriptors(routers)

microdescriptors_raw = generate_microdescriptors(microdescriptors)

consensus_path.write_bytes(consensus)

microdescriptors_path.write_bytes(microdescriptors_raw)
microdescriptors_path.write_bytes(generate_microdescriptors(microdescriptors))


def generate_churninfo(
Expand Down Expand Up @@ -1053,32 +1097,20 @@ def generate_customized_consensus_cb(namespace: Namespace) -> None:
:param namespace: namespace containing parsed arguments.
"""
authority_signing_key_path: Path = namespace.authority_signing_key
authority_certificate_path: Path = namespace.authority_certificate
consensus_path: Path = namespace.consensus
microdescriptors_path: Path = namespace.microdescriptors
number_routers: int = namespace.number_routers
authority_name: str = namespace.authority_name
authority_hostname: str = namespace.authority_hostname
authority_ip_address: str = namespace.authority_ip_address
authority_dirport: int = namespace.authority_dirport
authority_orport: int = namespace.authority_orport
authority_contact: str = namespace.authority_contact
consensus_validity_days: int = namespace.consensus_validity_days

generate_customized_consensus(
authority_signing_key_path,
authority_certificate_path,
consensus_path,
microdescriptors_path,
number_routers,
authority_name,
authority_hostname,
authority_ip_address,
authority_dirport,
authority_orport,
authority_contact,
consensus_validity_days,
namespace.authority_signing_key,
namespace.authority_certificate,
namespace.consensus,
namespace.microdescriptors,
namespace.number_routers,
namespace.authority_name,
namespace.authority_hostname,
namespace.authority_ip_address,
namespace.authority_dirport,
namespace.authority_orport,
namespace.authority_contact,
namespace.consensus_validity_days,
ignore=namespace.ignore,
)


Expand Down Expand Up @@ -1239,6 +1271,12 @@ def main(program: str, arguments: List[str]) -> None:
type=int,
default=120,
)
parser_dirinfo.add_argument(
"-i",
"--ignore",
help="Continue even if less routers than number-routers could be retrieved.",
action="store_true",
)

parser_dirinfo.set_defaults(callback=generate_customized_consensus_cb)

Expand Down
3 changes: 2 additions & 1 deletion tools/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
cryptography<37
pycryptodome>=3.10.1
stem>=1.8.0
pytest
git+https://github.com/c4dt/stem.git
5 changes: 5 additions & 0 deletions tools/test-data/authorities.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[
"dir-key-certificate-version 3\n dir-address 127.0.0.1:7000\n fingerprint 5A23BA701776C9C1AB1C06E734E92AB3D5350D64\n dir-key-published 2020-08-07 12:40:25\n dir-key-expires 2021-08-07 12:40:25\n dir-identity-key\n -----BEGIN RSA PUBLIC KEY-----\n MIIBigKCAYEAtitks3CQo7QOYYhJmYJGOJoA9XOREzl38tl6zrGq4XtwOioTUivP\n M51l483083x5DsBw6+Ec9LOkVSClETOIHDzjIzg78O4a6uEr7HemTI7JKEbIXUtj\n bu1/JxOb7Bd8HrA/9Vw6hp3GJT7wqO33K/XhmRVzH2SMhmLP0cZT5MfaaE38QViI\n eWrTFze+U1Z16RPWx8djaepCgLaVT2tP9WXKtk+6O0Kyjz1toF9wfZUb4jfEHNQ2\n 6Np5IaJcpsMaaovx2ClNOy23MadsLhBQxquCC1IFilMwKDDjVN9BIUd3eZJDBgyy\n yY4PvO6fMsVxtK+7dlw2pWpdc2YSTGh9TY+UfWyPn+7oUD2AB/liJ/HOSqdXw5kl\n YLeu2DwVUkv4ZieExUjyCmjmwkAdpEfMRE77hru+hbAV3E/vUj7571I1alMRZQU3\n PItAQkfygL+0yI0Ysk4kVt0zxkFv19o1YD6yS+vBkY2oVGflBS6TVl2v/YsVDBEU\n L6ifTkCQ8zIPAgMBAAE=\n -----END RSA PUBLIC KEY-----\n dir-signing-key\n -----BEGIN RSA PUBLIC KEY-----\n MIIBCgKCAQEAuMZaaW/p0CyTxWmr3SkBdrLz1uRiTZFadYNQmVcyeEfHw+siOO2Z\n GZCpLW14AilxrGgIqacbj4p1bnP1Fqt48SW06TJpfg8LL5u9A0taBTrvl4d+y0PU\n muk5/Y03QDUQ0Mqa5wFqXwq0gpFYNAF60fUcILU+RfC/eLF8p/8tMH6VqHbYJNvA\n amHoi5b/cSX26y2AJG9NeRuljx9kGBKcQ3nyIUr5KtNmMAxtznnz6cxsXneCtfxo\n H4Ubwy3NhSEfrjlSE4B/iASKalXgmQSSXR/PA+iBsG+zZ8+6/kKtxc5MQmnEQ3Qg\n q6M1hfp9K89K/EzaxQ06PLvY1FylGqpc1wIDAQAB\n -----END RSA PUBLIC KEY-----\n dir-key-crosscert\n -----BEGIN ID SIGNATURE-----\n UrMAQ97L/Aoz0pY+IahRnlTYFdJ3jLM28WxRvZ3eP8ShCmDHYYN7fMwnstDjZZ8N\n mGL8PuYP4mYfIRGjCBrMr5doLKtaOoyxnuuE81y08Yd8xWkIt9zelc5baGj1iJjn\n 1kxRCeClli0v05M31Z5zTNAfdMDD+yai4husa/0oEIMBJvjEAmeRcyjxfWIV8R0D\n e+PR7+GAxprbJFGRL9bn27PlR7Lbm03jZIpBhCdTAeBxyGHyS8wgaXaIJCR7e3GH\n uJytP7OvPoWLAggHSBp1LwsY++lLayJrTjm3/yoWv7BOXnXP0XHwDoPoXySS519p\n lxq5rwk1RrSwa93+nwnEXw==\n -----END ID SIGNATURE-----\n dir-key-certification\n -----BEGIN SIGNATURE-----\n fp1nrLUFamnIg6rZnG/hMuM00SpBVTW6/XgEgMw9QIfE3lQxzR/hKF6iFcasYi2z\n gg6r2JAvGevQxzajV8nDgKcLSnDurh6Q7OJw9p4v1ksXLJazHbLAhKi+Aa/daSmb\n 6Klp3XVDgVNhYzTleN26/El+Z1oEjbqRs72Vvlazem5lKaOZvm7jolgWQn5TiWZY\n TQ9D7cP9TDAm7WBvYQ97CUnSDobVJyVBtCQrNb5vppTQw6+FON0U2h75Vl+T/Qhd\n wugYKJ+UbZhwBCy0EOM23BU7QS6jbYW2bBjeo5I7/K32Cci8YZKuib9N/j3NPuFz\n 7jRAYSgiEd4uwktG4RP55EV7RVTO28/XeEvvlM/iVVYoqS+bMoCRkO8LqHvKB6+0\n Wkei7KASZzIVe5YcgRHzts/oBt8w59DIaGUtEPQQ2BEIYtkl4N3mfR9VgW5HpTUI\n 2kPs1DjukQslB6Ilz6G+qOaZtJyOhdkWtwdR/fMcDWmTEifLZDbAdiLUpg/xc26p\n -----END SIGNATURE-----\n",
"dir-key-certificate-version 3\n dir-address 127.0.0.1:7002\n fingerprint 7C47DCB4A90E2C2B7C7AD27BD641D038CF5D7EBE\n dir-key-published 2020-08-07 12:40:26\n dir-key-expires 2021-08-07 12:40:26\n dir-identity-key\n -----BEGIN RSA PUBLIC KEY-----\n MIIBigKCAYEAyE1/XqjBgaNCSp36thnqlRzzt/4vEXXUIcutCkGAsI/An408vj+Z\n tSo844vMMtSb8z1z0xDzApz2GPe7n5BTdPGjV1YQUd3Vr0z3z1j9EolV8NoXlUod\n Mj9pSa2dB9Hpz1ZooAEX+egRXPXOp6kHb2QyUIVupKUo/kCRwyUcqV6M52oPZ0i4\n o2uhhExXkExY1f7y6yee7QzLOxIgDhtWpkBhfMjRfa856ULXcRPwsQ99A1RclWTb\n c1i6aU3NIt+AYthamu6G4jnYTrg4tPUyr7Gc4+j34rT/SwLS5waKZwZFObGNitK0\n dLMMgPHfeJMW7wVN/scNDXCwZ19XzYEdat+SGP9jUaxPoabdOgzibfQINanw7pzm\n G5bEmOuqWr1vYy3oRs1rIJJ18vy6yTF379sKdkB1gSau6svSIJfvUpnVA2pjvjL0\n UGxXCCMozU+ctoe1PtXAEDFTE30vHo2pDe0pvJI+7bO09NAbTpIFfoxILqKRstJ7\n PcU/6Ncbmfd7AgMBAAE=\n -----END RSA PUBLIC KEY-----\n dir-signing-key\n -----BEGIN RSA PUBLIC KEY-----\n MIIBCgKCAQEAy+3L8ISKlSQ7nOmHgi1rNSpSp00e4VrMcgXU8+kn0yjYZB6jOSMs\n /LZDk14eX8jlvPsJg/SIl4c2OD+AYJtiyB1DZnZY/QbZ48faVwi9FkfCcZLkrD1i\n PiiYmpM+DS+sh1oiBZX/wTSvx0MeEjyd9t8ZhH5R86k7QA7TW7Fe9rRrLshPSGFp\n 4ipj1fG+NuEG58kXeWSLwXJvNl4Hdezvvjii5la9b2S37/D6DZDfRLib35tXfA4T\n y/zUK1pjzEQaAUeuIOgB+olX6bsOyL2eQORd5y5MtfF4x4FklPcz/e1l7gmahWGp\n RpSUIRszrEbfxgCA8zCz/ta+jrrXq1lkpQIDAQAB\n -----END RSA PUBLIC KEY-----\n dir-key-crosscert\n -----BEGIN ID SIGNATURE-----\n HvUJXA95l45NFYuD5y5jSf4aFE0f3TlABjKK159WeSjDD/4Vn1GJQQjX6ske8MDh\n x54GpTllhLmPLRq5GXn/DRCvxG9TGpyP3vL8pq2TWLBscCVxg4D9xj6OSYvbBKRw\n QolqW8wfGKPj2OgCnTB3jzvnshP9rDq/ruEzlZfJTrb4pxQrPzOAlwaKEDCoO9zy\n IW/gmVn1/vGNU/qhuGAKa4FGKUjvTg699MFE2SIF7gLo+oOGkFfL37WhHDlh7HPR\n JiAHgTp6nHp+2+B/EHR5u94b3g66qPRNN6KxWcTAqcUxX9t0dKlsROZksr1268P6\n PEN3+GtdwiA4n3reP+Wsxw==\n -----END ID SIGNATURE-----\n dir-key-certification\n -----BEGIN SIGNATURE-----\n FqKvXdB2bcwFYEWdQDW0eot/5cRTBnb8frAzoA/khWUSLhYIE55b/xtDg2OMWMhx\n /yBiGuNGHT82+jKDh92RfxVKH8D32/r6p1SP1ot8POGWU/ke6/lABZkd5Aa5xSb7\n Hcqik24bbnlvePtqze7UlvJQZN3ktYHUV2LTyw4ZbY1NEmMoPGE7FWe1iHSCiAvn\n I8u3ePREY2gQ4ZzkcjuPzIMX4Th18OEQFTanNgJqmW5l4XDkXO4yAOaO21/7kdTg\n iTqQnoWn8PfoVRvXVYvrgWKMyRUT/6R2zUnNWaP9z7JKv3SSZSXyMowbcyb5QFTX\n KKhfO7fLMdGUs/yhXvqVgaQdguOcLfTUU7rV8aZjKsGiDPsFJKTBw9Xt5obGGJN4\n 4CLP+J9lSi/aZ2M4/qD5tkuE0kUNzeHuZuhze3MOObRZxLC5I3skwzTuflODVtTP\n llMKUqZjbySFnSHEMvs+rhPOiUPNzXDl7/hQAVbWrzIyjjJ0WpoIUyHcIETWsv6Y\n -----END SIGNATURE-----\n",
"dir-key-certificate-version 3\n dir-address 127.0.0.1:7001\n fingerprint 5696AB38CB3852AFA476A5C07B2D4788963D5567\n dir-key-published 2020-08-07 12:40:25\n dir-key-expires 2021-08-07 12:40:25\n dir-identity-key\n -----BEGIN RSA PUBLIC KEY-----\n MIIBigKCAYEA5uDA8p4NhKPwOX/sMeMn6RtZLmNM2Ye4a1EPk2LQ7LYWQyeBZqsq\n GzZnQANclC0YbGi7cw7GiGY6NKXZNWtaPxX5rCWOw8IhGjNo56/kSfHJX+Gvtzzp\n dbxW/9JIYi8WyXQfMBhmfWtUrkdNIEyuW//H08haH+viCMePSv6zmPoc0xV//+XK\n ycHe/hLQZMKHIhHLGz0k3fRtousy+3y/vQFjw2PVwMB7xXnbHFPc0b+jUU3QO2V6\n jUAXVdIyHU+y1FzynUPo6C5d8mVQIlz/NcL1k0IKGUn1ItaQicYs28ooC+/I/lvV\n yub7LHHN7HX2IBwKLf135DQvSwXBWBFYwaYWGKDyN6IOGxCncKp9Cplz+Dk8P93m\n vTPYdpF0F0M1kP5dmakVqXyivJZMHGsQr2V0qGXr6I1wwu3SOdO0fmogWmEOmeT+\n 3L4elBnC9BjPhCfX7vnzksLp6BZe20Btiu1TqxA0SUTk3t2kOJulwDcgYAyUbKeJ\n NSKK8YOMyhvrAgMBAAE=\n -----END RSA PUBLIC KEY-----\n dir-signing-key\n -----BEGIN RSA PUBLIC KEY-----\n MIIBCgKCAQEAld61NikA0aqQnT2rO6YRelSnWCZjC3axXlrRV5QP1vJrPOdRRS53\n xHgkFEo8dX63X1bl67MBiZmgcP+cD/p9aFi9XGJyTU84wdBvmNU65LJ4sH0jKL1E\n DBt9RiDFCh9MhxqniVBp91is7m5RKV34Cwyco3Ti54uLO0FNGAh49nvNyANO0FlQ\n YFdM9yRQRciv20rWYO9M6brxK7LQMYVTg899yFnqa/vc+3USonKVLnmXeViNYyui\n bekkmN6E9EtSujpsfVAwsMSZy73n0n/PTRfXa+58npNgNbxX6mgQ6i7Nhy9KyFP4\n 9BzKA9Q3CmeM/Z339awAtCtSaLoEb0Vh3QIDAQAB\n -----END RSA PUBLIC KEY-----\n dir-key-crosscert\n -----BEGIN ID SIGNATURE-----\n WKrcO0K/e8XWRhTD0fh7+fqTJvL3A296/Yad16SS6Bdz1yh/QihSpffdS3PBi+ka\n WhHdXNYZJ68BPr4kNUC6xwlObeVlt0SVVpE2avqpfFtZL1pV6he2dNKZ5MMv6Ctm\n 7BOaavpLwcEyXs2H1XxH6wjQU719FCbvJvBESclAAIq3K3D5fmFg68RNWHHz3r3F\n MyXnaR5bylKkgQHwwz5Q3HVjWUJ6S7Fz8KTfO1Q7rvfgHpXzYJqAyXivhaGnJmWQ\n +zHVscRSI3NpGgqnzeqylXkZVqrHWNO5mkVSeMXt2hMYP61Zkm7KO6lqtOBON7Db\n AKOs+q8j2T3XoR5VD9YtAQ==\n -----END ID SIGNATURE-----\n dir-key-certification\n -----BEGIN SIGNATURE-----\n fJEeVmr7caG8pfwO9XFeCGnWVgyqKSg90xpIfcWbPHrn5brAXEwJm/+dX7V9tazx\n 8y6i43ULt3MI+7Et2o46A3wYGA0a3OqpxAHdJjxeafJ9bDXRyVETh2MHsd0I337A\n JhSuufKyGS+K2y20s2VYMPXkX2AFKpN1H0Stc7RdpssGyrmidZSXXzCgTitqn52g\n Ms9iWjCU6Ra5AjMzp/D93CFZ0fYMhKot42ZXYJga8drQHdY06+5Fb7RSTpFs9vhf\n t4XdeMef+N9ty/yaLNDmYiLJbKTTAarfkM2czXuuk3s+qwLN7+O4yGUNQz4tPJ8E\n h7VALUNE80QNDLb4rXiIUE+EI3tCqo9mQ/tnCVVofM6sQyTFjTWyIIRBABnaODlO\n meOIIEIR6ht2qSseZDe4dme7cg5/misTnIv7BNbErpYO5r9C2yHHFqSe8sivExCo\n tEkNtxufKS2mn6Tkm7wcJfp1Temxk/INUtvPA6Dlf3wNTnwzuGfk7LWCQ9BPeFqv\n -----END SIGNATURE-----\n"
]
8 changes: 4 additions & 4 deletions tools/tests/test_dirinfo.py → tools/test_dirinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pathlib import Path

import pytest
import json

from Crypto.PublicKey import RSA
from stem.descriptor.microdescriptor import Microdescriptor
Expand Down Expand Up @@ -33,9 +34,6 @@
select_routers,
)

from authorities import AUTHORITIES


# Small valid consensus taken from Arti.
PATH_CONSENSUS_OK = Path("test-data") / "consensus-ok.txt"

Expand All @@ -50,6 +48,7 @@
PATH_AUTH_CERTIFICATE = Path("test-data") / "authority_certificate"
PATH_AUTH_SIGNING_KEY = Path("test-data") / "authority_signing_key"

AUTHORITIES = json.load((Path("test-data") / "authorities.json").open())
AUTH_CERTIFICATES = [KeyCertificate(cert) for cert in AUTHORITIES]


Expand Down Expand Up @@ -98,6 +97,7 @@ def test_fetch_consensus(consensus):
assert isinstance(consensus, NetworkStatusDocumentV3)


@pytest.mark.xfail(reason="outdated test data")
def test_signature_validation_succeed():
"""
Test that the signature validation succeeds when it should succeed.
Expand Down Expand Up @@ -205,6 +205,7 @@ def test_fetch_certificates(certificates):
assert isinstance(cert, KeyCertificate)


@pytest.mark.xfail(reason="unresolved bug")
def test_fetch_microdescriptors(consensus):
"""
Test fetching microdescriptors works.
Expand Down Expand Up @@ -253,7 +254,6 @@ def test_select_routers(consensus, vote):


def test_generate_signed_consensus_from_real_data(consensus, vote):

with PATH_AUTH_SIGNING_KEY.open("rb") as signing_key_fd:
signing_key_raw = signing_key_fd.read()

Expand Down
Loading

0 comments on commit d9b029a

Please sign in to comment.