mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-02-08 04:10:25 +00:00
Add a tool for matching the node key in the announcement
And use it in the recently added test
This commit is contained in:
parent
212f96dfe7
commit
25287870ee
@ -2,7 +2,10 @@
|
|||||||
Testtools-style matchers useful to the Tahoe-LAFS test suite.
|
Testtools-style matchers useful to the Tahoe-LAFS test suite.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import attr
|
||||||
|
|
||||||
from testtools.matchers import (
|
from testtools.matchers import (
|
||||||
|
Mismatch,
|
||||||
AfterPreprocessing,
|
AfterPreprocessing,
|
||||||
MatchesStructure,
|
MatchesStructure,
|
||||||
MatchesDict,
|
MatchesDict,
|
||||||
@ -17,9 +20,37 @@ from foolscap.furl import (
|
|||||||
from allmydata.util import (
|
from allmydata.util import (
|
||||||
base32,
|
base32,
|
||||||
)
|
)
|
||||||
|
from allmydata.node import (
|
||||||
|
read_config,
|
||||||
|
)
|
||||||
|
from allmydata.crypto import (
|
||||||
|
ed25519,
|
||||||
|
error,
|
||||||
|
)
|
||||||
|
|
||||||
|
@attr.s
|
||||||
|
class MatchesNodePublicKey(object):
|
||||||
|
"""
|
||||||
|
Match an object representing the node's private key.
|
||||||
|
|
||||||
|
To verify, the private key is loaded from the node's private config
|
||||||
|
directory at the time the match is checked.
|
||||||
|
"""
|
||||||
|
basedir = attr.ib()
|
||||||
|
|
||||||
|
def match(self, other):
|
||||||
|
config = read_config(self.basedir, u"tub.port")
|
||||||
|
privkey_bytes = config.get_private_config("node.privkey")
|
||||||
|
private_key = ed25519.signing_keypair_from_string(privkey_bytes)[0]
|
||||||
|
signature = ed25519.sign_data(private_key, b"")
|
||||||
|
other_public_key = ed25519.verifying_key_from_signing_key(other)
|
||||||
|
try:
|
||||||
|
ed25519.verify_signature(other_public_key, signature, b"")
|
||||||
|
except error.BadSignature:
|
||||||
|
return Mismatch("The signature did not verify.")
|
||||||
|
|
||||||
|
|
||||||
def matches_anonymous_storage_announcement():
|
def matches_anonymous_storage_announcement(basedir):
|
||||||
"""
|
"""
|
||||||
Match an anonymous storage announcement.
|
Match an anonymous storage announcement.
|
||||||
"""
|
"""
|
||||||
@ -30,8 +61,7 @@ def matches_anonymous_storage_announcement():
|
|||||||
"anonymous-storage-FURL": matches_furl(),
|
"anonymous-storage-FURL": matches_furl(),
|
||||||
"permutation-seed-base32": matches_base32(),
|
"permutation-seed-base32": matches_base32(),
|
||||||
}),
|
}),
|
||||||
# Not sure what kind of assertion to make against the key
|
signing_key=MatchesNodePublicKey(basedir),
|
||||||
signing_key=Always(),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1122,7 +1122,7 @@ introducer.furl = pb://abcde@nowhere/fake
|
|||||||
# Match the following list (of one element) ...
|
# Match the following list (of one element) ...
|
||||||
MatchesListwise([
|
MatchesListwise([
|
||||||
# The only element in the list ...
|
# The only element in the list ...
|
||||||
matches_anonymous_storage_announcement(),
|
matches_anonymous_storage_announcement(self.basedir),
|
||||||
]),
|
]),
|
||||||
)),
|
)),
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user