diff --git a/other/fun/make-funny-savefile.py b/other/fun/make-funny-savefile.py new file mode 100755 index 00000000..43f14a6e --- /dev/null +++ b/other/fun/make-funny-savefile.py @@ -0,0 +1,122 @@ +#!/usr/bin/python + +""" +Generate a new (and empty) save file with predefined keys. Used to play +with externally generated keys. + +(c) 2015 Alexandre Erwin Ittner + +Distributed under the GNU GPL v3 or later, WITHOUT ANY WARRANTY. See the +file "COPYING" for license information. + + +Usage: + + ./make-funny-savefile.py + + The new user profile will be saved to . + + The keys must be an hex-encoded valid key pair generated by any means + (eg. strkey.c); username may be anything. A random nospam value will be + generated. + + Once the savefile is done, load it in your favorite client to get some + DHT nodes, set status and status messages, add friends, etc. + + +Example (of course, do not try using this key for anything real): + + ./make-funny-savefile.py 123411DC8B1A4760B648E0C7243B65F01069E4858F45C612CE1A6F673B603830 CC39440CFC063E4A95B7F2FB2580210558BE5C073AFC1C9604D431CCA3132238 "Test user" test.tox + + +""" + + +PUBLIC_KEY_LENGTH = 32 +PRIVATE_KEY_LENGTH = 32 + +# Constants taken from messenger.c +MESSENGER_STATE_COOKIE_GLOBAL = 0x15ed1b1f +MESSENGER_STATE_COOKIE_TYPE = 0x01ce +MESSENGER_STATE_TYPE_NOSPAMKEYS = 1 +MESSENGER_STATE_TYPE_DHT = 2 +MESSENGER_STATE_TYPE_FRIENDS = 3 +MESSENGER_STATE_TYPE_NAME = 4 +MESSENGER_STATE_TYPE_STATUSMESSAGE = 5 +MESSENGER_STATE_TYPE_STATUS = 6 +MESSENGER_STATE_TYPE_TCP_RELAY = 10 +MESSENGER_STATE_TYPE_PATH_NODE = 11 + +STATUS_MESSAGE = "New user".encode("utf-8") + + + +import sys +import struct +import os + +def abort(msg): + print(msg) + exit(1) + + + +if len(sys.argv) != 5: + abort("Usage: %s " % (sys.argv[0])) + +try: + public_key = sys.argv[1].decode("hex") +except: + abort("Bad public key") + +try: + private_key = sys.argv[2].decode("hex") +except: + abort("Bad private key") + +if len(public_key) != PUBLIC_KEY_LENGTH: + abort("Public key with wrong length") + +if len(private_key) != PRIVATE_KEY_LENGTH: + abort("Private key with wrong length") + +user_name = sys.argv[3].encode("utf-8") + +if len(user_name) > 32: + abort("User name too long (for this script, at least)") + +out_file_name = sys.argv[4] +nospam = os.urandom(4) + + +def make_subheader(h_type, h_length): + return ( + struct.pack("