From 5d65d89e01105bc1b37995175cd9336ea2c737e0 Mon Sep 17 00:00:00 2001 From: "Kali Kaneko (leap communications)" Date: Fri, 28 Jun 2019 17:01:41 +0200 Subject: [feat] add vendorize script to generate config --- branding/check-ca-crt.py | 46 ++++++++++++++++++++ branding/config.go.tmpl | 32 ++++++++++++++ branding/config/riseup-ca.crt | 32 ++++++++++++++ branding/config/vendor.conf | 24 +++++++++++ branding/vendorize.py | 99 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 233 insertions(+) create mode 100755 branding/check-ca-crt.py create mode 100644 branding/config.go.tmpl create mode 100644 branding/config/riseup-ca.crt create mode 100644 branding/config/vendor.conf create mode 100755 branding/vendorize.py (limited to 'branding') diff --git a/branding/check-ca-crt.py b/branding/check-ca-crt.py new file mode 100755 index 0000000..6462467 --- /dev/null +++ b/branding/check-ca-crt.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python3 +import re +import sys +import urllib.request + +SCRIPT_NAME = 'check-ca-crt.py' + +USAGE = '''Check that the stored provider CA matches the one announced online. +Usage: {name} + +Example: {name} riseup black.riseup.net'''.format(name=SCRIPT_NAME) + + +def getLocalCert(provider): + sanitized = re.sub(r'[^\w\s-]', '', provider).strip().lower() + with open('config/{provider}-ca.crt'.format(provider=sanitized)) as crt: + return crt.read().strip() + + +def getRemoteCert(uri): + fp = urllib.request.urlopen('https://' + uri + '/ca.crt') + remote_cert = fp.read().decode('utf-8').strip() + fp.close() + return remote_cert + + +if __name__ == '__main__': + + if len(sys.argv) != 3: + print('[!] Not enough arguments') + print(USAGE) + sys.exit(1) + + provider = sys.argv[1] + uri = sys.argv[2] + + local = getLocalCert(provider) + remote = getRemoteCert(uri) + + try: + assert local == remote + except AssertionError: + print('[!] ERROR: remote and local CA certs do not match') + sys.exit(1) + else: + print('OK') diff --git a/branding/config.go.tmpl b/branding/config.go.tmpl new file mode 100644 index 0000000..c3a9a33 --- /dev/null +++ b/branding/config.go.tmpl @@ -0,0 +1,32 @@ +/* + DO NOT EDIT -------------------------------------------------- + + This file has been automatically generated by `go generate`. + Any changes will be overriden. + + DO NOT EDIT -------------------------------------------------- +*/ + +package config + +/* All these constants are defined in the vendor.conf file +*/ +const ( + Provider = "$providerURL" + ApplicationName = "$applicationName" + BinaryName = "$binaryName" + DonateURL = "$donateURL" + HelpURL = "$helpURL" + TosURL = "$tosURL" + APIURL = "$apiURL" + GeolocationAPI = "$geolocationAPI" +) + +/* + +CaCert : a string containing a representation of the provider CA, used to + sign the webapp and openvpn certificates. should be placed in + config/[provider]-ca.crt + +*/ +var CaCert = []byte(`$caCertString`) diff --git a/branding/config/riseup-ca.crt b/branding/config/riseup-ca.crt new file mode 100644 index 0000000..cbec39c --- /dev/null +++ b/branding/config/riseup-ca.crt @@ -0,0 +1,32 @@ +-----BEGIN CERTIFICATE----- +MIIFjTCCA3WgAwIBAgIBATANBgkqhkiG9w0BAQ0FADBZMRgwFgYDVQQKDA9SaXNl +dXAgTmV0d29ya3MxGzAZBgNVBAsMEmh0dHBzOi8vcmlzZXVwLm5ldDEgMB4GA1UE +AwwXUmlzZXVwIE5ldHdvcmtzIFJvb3QgQ0EwHhcNMTQwNDI4MDAwMDAwWhcNMjQw +NDI4MDAwMDAwWjBZMRgwFgYDVQQKDA9SaXNldXAgTmV0d29ya3MxGzAZBgNVBAsM +Emh0dHBzOi8vcmlzZXVwLm5ldDEgMB4GA1UEAwwXUmlzZXVwIE5ldHdvcmtzIFJv +b3QgQ0EwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQC76J4ciMJ8Sg0m +TP7DF2DT9zNe0Csk4myoMFC57rfJeqsAlJCv1XMzBmXrw8wq/9z7XHv6n/0sWU7a +7cF2hLR33ktjwODlx7vorU39/lXLndo492ZBhXQtG1INMShyv+nlmzO6GT7ESfNE +LliFitEzwIegpMqxCIHXFuobGSCWF4N0qLHkq/SYUMoOJ96O3hmPSl1kFDRMtWXY +iw1SEKjUvpyDJpVs3NGxeLCaA7bAWhDY5s5Yb2f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T4qMFbixQmc8bGyuakr23wjMvfO7eZUxBuWYR2SkcP26sozF9PF +tGhbZHQVGZUTVPyvwahMUEhbPGVerOW0IYpxkm0x/eaWdTc4vPpf/rIlgbAjarnJ +UN9SaWRlWKSdP4haujnzCoJbM7dU9bjvlGZNyXEekgeT0W2qFeGGp+yyUWw8tNsp +0BuC1b7uW/bBn/xKm319wXVDvBgZgcktMolak39V7DVO +-----END CERTIFICATE----- diff --git a/branding/config/vendor.conf b/branding/config/vendor.conf new file mode 100644 index 0000000..ee5aa36 --- /dev/null +++ b/branding/config/vendor.conf @@ -0,0 +1,24 @@ +[default] + +provider = riseup + + +[riseup] + +name = Riseup +applicationName = RiseupVPN +binaryName = riseup-vpn +providerURL = riseup.net +tosURL = https://riseup.net/tos +helpURL = https://riseup.net/support +donateURL = https://riseup.net/donate +apiURL = https://api.black.riseup.net/ +geolocationAPI = https://api.black.riseup.net:9001/json + + +[calyx] + +name = Calyx +applicationName = CalyxVPN +binaryName = calyx-vpn +apiURL = https://calyx.org diff --git a/branding/vendorize.py b/branding/vendorize.py new file mode 100755 index 0000000..46cc1e6 --- /dev/null +++ b/branding/vendorize.py @@ -0,0 +1,99 @@ +#!/usr/bin/env python3 + +import os +import sys + +from string import Template +import configparser + +OUTFILE = 'config.go' +INFILE = 'config.go.tmpl' +CONFIGFILE = 'config/vendor.conf' +SCRIPT_NAME = 'vendorize' + + +def getProviderData(config): + default = config['default']['provider'] + print("[+] Configured provider:", default) + + c = config[default] + d = dict() + + keys = ('name', 'applicationName', 'binaryName', + 'providerURL', 'tosURL', 'helpURL', + 'donateURL', 'apiURL', 'geolocationAPI', 'caCertString') + + for value in keys: + d[value] = c.get(value) + + return d + + +def addCaData(data, configfile): + provider = data.get('name').lower() + folder, f = os.path.split(configfile) + caFile = os.path.join(folder, provider + '-ca.crt') + if not os.path.isfile(caFile): + bail('[!] Cannot find CA file in {path}'.format(path=caFile)) + with open(caFile) as ca: + data['caCertString'] = ca.read().strip() + + +def writeOutput(data, infile, outfile): + + with open(infile) as infile: + s = Template(infile.read()) + + with open(outfile, 'w') as outf: + outf.write(s.substitute(data)) + + +def bail(msg=None): + if not msg: + print('Usage: {scriptname}.py