Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 88193f2

Browse files
authored
Remove direct refeferences to PyNaCl (use signedjson instead). (#12902)
1 parent 79dadf7 commit 88193f2

File tree

6 files changed

+12
-20
lines changed

6 files changed

+12
-20
lines changed

changelog.d/12902.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove PyNaCl occurrences directly used in Synapse code.

contrib/cmdclient/console.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
""" Starts a synapse client console. """
1818
import argparse
19+
import binascii
1920
import cmd
2021
import getpass
2122
import json
@@ -26,9 +27,8 @@
2627
from http import TwistedHttpClient
2728
from typing import Optional
2829

29-
import nacl.encoding
30-
import nacl.signing
3130
import urlparse
31+
from signedjson.key import NACL_ED25519, decode_verify_key_bytes
3232
from signedjson.sign import SignatureVerifyException, verify_signed_json
3333

3434
from twisted.internet import defer, reactor, threads
@@ -41,7 +41,6 @@
4141

4242

4343
class SynapseCmd(cmd.Cmd):
44-
4544
"""Basic synapse command-line processor.
4645
4746
This processes commands from the user and calls the relevant HTTP methods.
@@ -420,8 +419,8 @@ def _do_invite(self, roomid, userstring):
420419
pubKey = None
421420
pubKeyObj = yield self.http_client.do_request("GET", url)
422421
if "public_key" in pubKeyObj:
423-
pubKey = nacl.signing.VerifyKey(
424-
pubKeyObj["public_key"], encoder=nacl.encoding.HexEncoder
422+
pubKey = decode_verify_key_bytes(
423+
NACL_ED25519, binascii.unhexlify(pubKeyObj["public_key"])
425424
)
426425
else:
427426
print("No public key found in pubkey response!")

poetry.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ unpaddedbase64 = ">=2.1.0"
113113
canonicaljson = ">=1.4.0"
114114
# we use the type definitions added in signedjson 1.1.
115115
signedjson = ">=1.1.0"
116-
PyNaCl = ">=1.2.1"
117116
# validating SSL certs for IP addresses requires service_identity 18.1.
118117
service-identity = ">=18.1.0"
119118
# Twisted 18.9 introduces some logger improvements that the structured

tests/crypto/test_event_signing.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
16-
import nacl.signing
17-
import signedjson.types
18-
from unpaddedbase64 import decode_base64
15+
from signedjson.key import decode_signing_key_base64
16+
from signedjson.types import SigningKey
1917

2018
from synapse.api.room_versions import RoomVersions
2119
from synapse.crypto.event_signing import add_hashes_and_signatures
@@ -25,7 +23,7 @@
2523

2624
# Perform these tests using given secret key so we get entirely deterministic
2725
# signatures output that we can test against.
28-
SIGNING_KEY_SEED = decode_base64("YJDBA9Xnr2sVqXD9Vj7XVUnmFZcZrlw8Md7kMW+3XA1")
26+
SIGNING_KEY_SEED = "YJDBA9Xnr2sVqXD9Vj7XVUnmFZcZrlw8Md7kMW+3XA1"
2927

3028
KEY_ALG = "ed25519"
3129
KEY_VER = "1"
@@ -36,14 +34,9 @@
3634

3735
class EventSigningTestCase(unittest.TestCase):
3836
def setUp(self):
39-
# NB: `signedjson` expects `nacl.signing.SigningKey` instances which have been
40-
# monkeypatched to include new `alg` and `version` attributes. This is captured
41-
# by the `signedjson.types.SigningKey` protocol.
42-
self.signing_key: signedjson.types.SigningKey = nacl.signing.SigningKey( # type: ignore[assignment]
43-
SIGNING_KEY_SEED
37+
self.signing_key: SigningKey = decode_signing_key_base64(
38+
KEY_ALG, KEY_VER, SIGNING_KEY_SEED
4439
)
45-
self.signing_key.alg = KEY_ALG
46-
self.signing_key.version = KEY_VER
4740

4841
def test_sign_minimal(self):
4942
event_dict = {

tests/crypto/test_keyring.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
import canonicaljson
2020
import signedjson.key
2121
import signedjson.sign
22-
from nacl.signing import SigningKey
2322
from signedjson.key import encode_verify_key_base64, get_verify_key
23+
from signedjson.types import SigningKey
2424

2525
from twisted.internet import defer
2626
from twisted.internet.defer import Deferred, ensureDeferred

0 commit comments

Comments
 (0)