summaryrefslogtreecommitdiff
path: root/other
diff options
context:
space:
mode:
Diffstat (limited to 'other')
-rwxr-xr-xother/fun/make-funny-savefile.py122
1 files changed, 122 insertions, 0 deletions
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 @@
1#!/usr/bin/python
2
3"""
4Generate a new (and empty) save file with predefined keys. Used to play
5with externally generated keys.
6
7(c) 2015 Alexandre Erwin Ittner
8
9Distributed under the GNU GPL v3 or later, WITHOUT ANY WARRANTY. See the
10file "COPYING" for license information.
11
12
13Usage:
14
15 ./make-funny-savefile.py <public key> <private key> <user name> <out file>
16
17 The new user profile will be saved to <out file>.
18
19 The keys must be an hex-encoded valid key pair generated by any means
20 (eg. strkey.c); username may be anything. A random nospam value will be
21 generated.
22
23 Once the savefile is done, load it in your favorite client to get some
24 DHT nodes, set status and status messages, add friends, etc.
25
26
27Example (of course, do not try using this key for anything real):
28
29 ./make-funny-savefile.py 123411DC8B1A4760B648E0C7243B65F01069E4858F45C612CE1A6F673B603830 CC39440CFC063E4A95B7F2FB2580210558BE5C073AFC1C9604D431CCA3132238 "Test user" test.tox
30
31
32"""
33
34
35PUBLIC_KEY_LENGTH = 32
36PRIVATE_KEY_LENGTH = 32
37
38# Constants taken from messenger.c
39MESSENGER_STATE_COOKIE_GLOBAL = 0x15ed1b1f
40MESSENGER_STATE_COOKIE_TYPE = 0x01ce
41MESSENGER_STATE_TYPE_NOSPAMKEYS = 1
42MESSENGER_STATE_TYPE_DHT = 2
43MESSENGER_STATE_TYPE_FRIENDS = 3
44MESSENGER_STATE_TYPE_NAME = 4
45MESSENGER_STATE_TYPE_STATUSMESSAGE = 5
46MESSENGER_STATE_TYPE_STATUS = 6
47MESSENGER_STATE_TYPE_TCP_RELAY = 10
48MESSENGER_STATE_TYPE_PATH_NODE = 11
49
50STATUS_MESSAGE = "New user".encode("utf-8")
51
52
53
54import sys
55import struct
56import os
57
58def abort(msg):
59 print(msg)
60 exit(1)
61
62
63
64if len(sys.argv) != 5:
65 abort("Usage: %s <public key> <private key> <user name> <out file>" % (sys.argv[0]))
66
67try:
68 public_key = sys.argv[1].decode("hex")
69except:
70 abort("Bad public key")
71
72try:
73 private_key = sys.argv[2].decode("hex")
74except:
75 abort("Bad private key")
76
77if len(public_key) != PUBLIC_KEY_LENGTH:
78 abort("Public key with wrong length")
79
80if len(private_key) != PRIVATE_KEY_LENGTH:
81 abort("Private key with wrong length")
82
83user_name = sys.argv[3].encode("utf-8")
84
85if len(user_name) > 32:
86 abort("User name too long (for this script, at least)")
87
88out_file_name = sys.argv[4]
89nospam = os.urandom(4)
90
91
92def make_subheader(h_type, h_length):
93 return (
94 struct.pack("<I", h_length) +
95 struct.pack("<H", h_type) +
96 struct.pack("<H", MESSENGER_STATE_COOKIE_TYPE))
97
98data = (
99 # Main header
100 struct.pack("<I", 0) +
101 struct.pack("<I", MESSENGER_STATE_COOKIE_GLOBAL) +
102
103 # Keys
104 make_subheader(MESSENGER_STATE_TYPE_NOSPAMKEYS,
105 len(nospam) + PUBLIC_KEY_LENGTH + PRIVATE_KEY_LENGTH) +
106 nospam + public_key + private_key +
107
108 # Name (not really needed, but helps)
109 make_subheader(MESSENGER_STATE_TYPE_NAME, len(user_name)) +
110 user_name +
111
112 # Status message (not really needed, but helps)
113 make_subheader(MESSENGER_STATE_TYPE_STATUSMESSAGE, len(STATUS_MESSAGE)) +
114 STATUS_MESSAGE
115)
116
117
118try:
119 with open(out_file_name, "wb") as fp:
120 fp.write(data)
121except Exception as e:
122 abort(str(e))