Created
June 21, 2021 14:54
-
-
Save qinghon/2e1ac878d9f468fcdb216181d6ba9eb7 to your computer and use it in GitHub Desktop.
libtorrent python binding test signature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import sys | |
import time | |
import nacl | |
from nacl.signing import SigningKey, VerifyKey | |
import libtorrent as lt | |
if __name__ == '__main__': | |
port = 6880 | |
seed_hex = '' | |
pub_key: [bytes] = None | |
sec_key: [bytes] = None | |
if len(sys.argv) > 1: | |
if sys.argv[1] in ["-p"]: | |
port = int(sys.argv[2]) | |
seed_hex = '829ee32a86b93d3766df28d8d77069fdc04e05b17fb095043c72a56d846d0372' | |
if seed_hex: | |
signing = SigningKey(bytes.fromhex(seed_hex)) | |
pub_key = signing.verify_key.encode() | |
sec_key = signing._signing_key | |
print("pub_key: ", pub_key.hex()) | |
print("sec_key: ",sec_key.hex()) | |
singed = signing.sign("4:abcd".encode()) | |
print(singed.hex()) | |
try: | |
if signing.verify_key.verify("4:abcd".encode(), singed.signature): | |
print("verifyed!") | |
except nacl.exceptions.BadSignatureError: | |
print("invalid signature") | |
ses = lt.session({'listen_interfaces': "%s:%d" % ("127.0.0.1", port), | |
'dht_bootstrap_nodes': ''}) | |
ses.add_extension(lt.create_ut_pex_plugin) | |
ses.add_extension(lt.create_ut_metadata_plugin) | |
ses.add_extension(lt.create_smart_ban_plugin) | |
ses.add_dht_node(("127.0.0.1", port ^ 1)) | |
ses.set_alert_mask(lt.alert_category.dht_log) | |
while (True): | |
alerts = ses.pop_alerts() | |
for a in alerts: | |
print(a) | |
if pub_key and sec_key: | |
ses.dht_put_mutable_item(sec_key, pub_key, "abcd", "") | |
# ses.dht_put_mutable_item(pub_key, sec_key, "abcd", "") | |
time.sleep(2) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment