summaryrefslogtreecommitdiff
path: root/tools/communityauth/generate_cryptkey.py
blob: 4c6376c0e40df3c0e0c5fadef7f99631661e531e (plain)
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
#!/usr/bin/env python3

#
# This script generates a crypto key that can be used for
# community authentication integration.
#

from Cryptodome import Random
import base64
import sys


def usage():
    print("Usage: generate_cryptkey.py <version>")
    print("")
    print("Version must be 3 or 4, representing the version of community authentication encryption to use")
    sys.exit(0)


if __name__ == "__main__":
    if len(sys.argv) != 2:
        usage()
    if sys.argv[1] not in ("3", "4"):
        usage()

    version = int(sys.argv[1])
    keylen = 64 if version == 3 else 32

    print("The next row contains a {}-byte ({}-bit) symmetric crypto key.".format(keylen, keylen * 8))
    print("This key should be used to integrate a community auth site.")
    print("Note that each site should have it's own key!!")
    print("")

    r = Random.new()
    key = r.read(keylen)
    print(base64.b64encode(key).decode('ascii'))