snapshot of https://github.com/zulip/zulip.git @ 48c69911c7dd4e03b20552eb3bd77ad8151c1357 (2026-09-15)
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
import configparser
|
||||
import json
|
||||
from argparse import ArgumentParser
|
||||
from typing import Any
|
||||
|
||||
from django.conf import settings
|
||||
from nacl.encoding import Base64Encoder
|
||||
from nacl.public import PrivateKey
|
||||
from typing_extensions import override
|
||||
|
||||
from zerver.lib.management import ZulipBaseCommand
|
||||
|
||||
|
||||
class Command(ZulipBaseCommand):
|
||||
help = """
|
||||
Add or remove a key pair from the `push_registration_encryption_keys` map.
|
||||
|
||||
Usage:
|
||||
./manage.py manage_push_registration_encryption_keys --add
|
||||
./manage.py manage_push_registration_encryption_keys --remove-key <public-key>
|
||||
"""
|
||||
|
||||
@override
|
||||
def add_arguments(self, parser: ArgumentParser) -> None:
|
||||
parser.add_argument(
|
||||
"--add",
|
||||
action="store_true",
|
||||
help="Add a new key pair to the `push_registration_encryption_keys` map.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--remove-key",
|
||||
metavar="PUBLIC_KEY",
|
||||
help="Remove the key pair associated with the given public key from the `push_registration_encryption_keys` map.",
|
||||
)
|
||||
|
||||
@override
|
||||
def handle(self, *args: Any, **options: Any) -> None:
|
||||
if not options["add"] and options["remove_key"] is None:
|
||||
print("Error: Please provide either --add or --remove-key <public-key>.")
|
||||
return
|
||||
|
||||
if settings.DEVELOPMENT:
|
||||
SECRETS_FILENAME = "zproject/dev-secrets.conf"
|
||||
else:
|
||||
SECRETS_FILENAME = "/etc/zulip/zulip-secrets.conf"
|
||||
|
||||
config = configparser.ConfigParser()
|
||||
config.read(SECRETS_FILENAME)
|
||||
push_registration_encryption_keys: dict[str, str] = json.loads(
|
||||
config.get("secrets", "push_registration_encryption_keys", fallback="{}")
|
||||
)
|
||||
|
||||
added_key_pair: tuple[str, str] | None = None
|
||||
if options["add"]:
|
||||
# Generate a new key-pair and store.
|
||||
private_key = PrivateKey.generate()
|
||||
private_key_str = Base64Encoder.encode(bytes(private_key)).decode("utf-8")
|
||||
public_key_str = Base64Encoder.encode(bytes(private_key.public_key)).decode("utf-8")
|
||||
push_registration_encryption_keys[public_key_str] = private_key_str
|
||||
added_key_pair = (public_key_str, private_key_str)
|
||||
|
||||
if options["remove_key"] is not None:
|
||||
# Remove the key-pair for the given public key.
|
||||
remove_key = options["remove_key"]
|
||||
if remove_key not in push_registration_encryption_keys:
|
||||
print("Error: No key pair found for the given public key.")
|
||||
return
|
||||
|
||||
del push_registration_encryption_keys[remove_key]
|
||||
|
||||
config.set(
|
||||
"secrets",
|
||||
"push_registration_encryption_keys",
|
||||
json.dumps(push_registration_encryption_keys),
|
||||
)
|
||||
with open(SECRETS_FILENAME, "w") as secrets_file:
|
||||
config.write(secrets_file)
|
||||
|
||||
if added_key_pair is not None:
|
||||
public_key_str, private_key_str = added_key_pair
|
||||
print("Added a new key pair:")
|
||||
print(f"- Public key: {public_key_str}")
|
||||
print(f"- Private key: {private_key_str}")
|
||||
|
||||
if options["remove_key"] is not None:
|
||||
print(f"Removed the key pair for public key: {options['remove_key']}")
|
||||
Reference in New Issue
Block a user