~vomun-developers/anonplus/vomun-trunk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#! /usr/bin/env python
print('''
=== Anon+ Setup ===
== Project Vomun ==
''')
import os
import json
import hashlib
import libs.errors


try:
    import Crypto
    import Crypto.PublicKey.RSA
except ImportError:
    raise libs.errors.DependancyError('''PyCrypto is required to use Anon+
        Get it for Linux at https://www.dlitz.net/software/pycrypto/
        Get it for Windows at http://www.voidspace.org.uk/python/modules.shtml#pycrypto
    ''')
    
# Check PyCrpyto version basics - require v2.1.x or higher
if Crypto.version_info[0] < 2 or Crypto.version_info[1] < 1:
    raise libs.errors.DependancyError(
            'Please update PyCrypto: https://www.dlitz.net/software/pycrypto/')

## Prepare for setup
# Find local variables
print('[*] Preparing for setup...')
HOME = os.path.expanduser('~')
VOMUN_PATH = os.path.join(HOME, '.vomun')
KEYS_PATH = os.path.join(VOMUN_PATH, 'keys.json')
CONFIG_PATH = os.path.join(VOMUN_PATH, 'config.json')

USER_NAME = raw_input('Pick a user name: ')

# Setup file structure for Anon+
try:
    print(' [*] Making ~/.vomun/')
    os.mkdir(VOMUN_PATH, 0711)
except OSError as error:
    if error.errno == 17:
        print('  [*] %s already exists. Do not need to create.' % VOMUN_PATH)
    else:
        print('  [*] Error creating %s' % VOMUN_PATH)
        raise libs.errors.InstallError(
                     'Please check your file permissions for %s' % HOME)

## Key setup
# Generate 2048 bit node key
keys = {}
print('[*] Setting up encryption keys')
print(' [*] Generating a 2048 bit node key')
print('     this could take a while...')

# ####################################
# TODO: do non-symbolic key generation
# ####################################
keys['nodekey'] = Crypto.PublicKey.RSA.generate(2048)
keys['nodekey'].hash = hashlib.sha256(
        keys['nodekey'].publickey().exportKey()).hexdigest()

print('  [*] Done. Key fingerprint:')
print('      %s' % keys['nodekey'].hash)


# Generate 2048 bit identity key
print(' [*] Generating a 2048 bit identity key')
print('     this could take a while...')

# ####################################
# TODO: do non-symbolic key generation
# ####################################
keys['userkey'] = Crypto.PublicKey.RSA.generate(2048)
keys['userkey'].hash = hashlib.sha256(
        keys['userkey'].publickey().exportKey()).hexdigest()

print('  [*] Done. Key fingerprint:')
print('      %s' % keys['userkey'].hash)

# Write keys
print('[*] Writing keys to keys.json')
keys_by_hash = {
    keys['nodekey'].hash: keys['nodekey'].exportKey(),
    keys['userkey'].hash: keys['userkey'].exportKey()
}
try:
    key_file = open(KEYS_PATH, 'w')
    key_file.write(json.dumps(keys_by_hash, indent = 4))
    key_file.close()
except IOError:
    print('  [*] Error writing %s. Check file permissions.' % KEY_PATH)
    raise libs.errors.InstallError('Could not write to %s.' % KEY_PATH)


## Configuration
# Generate the contents
print('[*] Generating the config file...')
config = json.dumps({
    'keyfile': KEYS_PATH.replace('\\', '\\\\'),
    'vomundir': VOMUN_PATH.replace('\\', '\\\\'),
    'nodekey': keys['nodekey'].hash,
    'userkey': keys['userkey'].hash,
    'username': USER_NAME
}, indent = 4)

try:
    print(' [*] Writing the config file.')
    config_file = open(CONFIG_PATH, 'w')
    config_file.write(config)
    config_file.close()
except IOError as error:
    print('  [*] Error writing %s. Check file permissions.' % CONFIG_PATH)
    raise libs.errors.InstallError('Could not write to %s.' % CONFIG_PATH)

friendlistpath = os.path.expanduser('~/.vomun/friends.json')
try:
        friendlistr = open(friendlistpath, "r")
        friendlistr.close()
except IOError:
        friendlistr = open(friendlistpath, "w")
        friendlistr.write('[]')
        friendlistr.close()
        
## Setup complete
print(' == Setup Complete ==')
print('''
 == Anon+ Setup is Complete ==
Please run vomun.py and then go to
http://localhost:7777/ to use it.
''')
os.system("vomun.py")
os.system("python vomun.py")