diff --git a/pyseeder/crypto.py b/pyseeder/crypto.py index 3a9e8eb..0bf2f60 100644 --- a/pyseeder/crypto.py +++ b/pyseeder/crypto.py @@ -33,8 +33,8 @@ def keygen(pub_key, priv_key, priv_key_password, user_id): subject = issuer = x509.Name([ x509.NameAttribute(NameOID.COUNTRY_NAME, "XX"), x509.NameAttribute(NameOID.STATE_OR_PROVINCE_NAME, "XX"), - x509.NameAttribute(NameOID.LOCALITY_NAME, "XX"), - x509.NameAttribute(NameOID.ORGANIZATION_NAME, "I2P Anonymous Network"), + x509.NameAttribute(NameOID.LOCALITY_NAME, "I2P Anonymous Network"), + x509.NameAttribute(NameOID.ORGANIZATION_NAME, "XX"), x509.NameAttribute(NameOID.ORGANIZATIONAL_UNIT_NAME, "I2P"), x509.NameAttribute(NameOID.COMMON_NAME, user_id), ]) diff --git a/pyseeder/transport.py b/pyseeder/transport.py index 3735734..15f4d0c 100644 --- a/pyseeder/transport.py +++ b/pyseeder/transport.py @@ -55,4 +55,3 @@ def upload(filename, config): except ImportError: raise PyseederException( "{} transport can't be loaded".format(t)) - diff --git a/pyseeder/transports/git_publish.py b/pyseeder/transports/git_publish.py new file mode 100644 index 0000000..8184631 --- /dev/null +++ b/pyseeder/transports/git_publish.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python3 +# unpythonic script to (re)upload asset to github release +# used for stealthy I2P reseeding +# GENERATE TOKEN for this script here --> https://github.com/settings/tokens +# Check scope: public_repo (shall be enough) + +from urllib.parse import urljoin +from mimetypes import guess_type +from pyseeder.utils import TransportException +import requests +import os + +TRANSPORT_NAME = "git" + +def run(filename, config): + if "GH_USERNAME" not in config: + raise TransportException("git: No username specified in config") + else: + REPO_USERNAME = config["GH_USERNAME"] + if "GH_TOKEN" not in config: + raise TransportException("git: No token specified in config") + else: + REPO_TOKEN = config["GH_TOKEN"] + if "GH_REPO" not in config: + raise TransportException("git: No repository specified in config") + else: + REPO_PATH = config["GH_REPO"] + if "GH_TAG" not in config: + raise TransportException("git: No tag specified in config") + else: + REPO_TAG = config["GH_TAG"] + + API_URL = "https://api.github.com/" + asset_name = os.path.split(filename)[1] + content_type = guess_type(asset_name)[0] or "application/zip" + creds = (REPO_USERNAME, REPO_TOKEN) + release_info_url = urljoin(API_URL, "/repos/{}/releases/tags/{}".format( + REPO_PATH, REPO_TAG)) + + # get release info + resp = requests.get(release_info_url, auth=creds) + assert resp.status_code is 200, "Successfull auth must return 200" + + # delete old asset + for x in resp.json()["assets"]: + if x["name"] == asset_name: + r = requests.delete(x["url"], auth=creds) + assert r.status_code is 204, "Deletion must return 204" + + # upload new asset + # im super lazy + upload_url = resp.json()["upload_url"].split("{")[0] + headers = {'Content-Type': content_type} + params = {'name': asset_name} + + data = open(filename, 'rb').read() + r = requests.post(upload_url, headers=headers, params=params, auth=creds, + data=data) + assert r.status_code is 201, "Upload must return 201" diff --git a/requirements.txt b/requirements.txt index b98e00d..9bbd7c4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ -cryptography>=1.4 +cryptography==1.4 +requests \ No newline at end of file diff --git a/transports.ini.example b/transports.ini.example index 285eaef..ae8542a 100644 --- a/transports.ini.example +++ b/transports.ini.example @@ -1,10 +1,18 @@ [transports] ; enabled transports separated by space -enabled=git +enabled=git_publish [git] ; Folder with git repository to use folder=/home/user/reseed-data-repo +[git_publish] +; GENERATE TOKEN for this script here --> https://github.com/settings/tokens +; Check scope: public_repo (shall be enough) +GH_USERNAME=user +GH_TOKEN=your token here +GH_REPO=user/i2pd-reseed +GH_TAG=1.0 + [dropbox] ; todo