Skip to content

Commit 5238dce

Browse files
committed
fix: Use expected TLS config and update to the latest cloudflare API version
1 parent 540ac17 commit 5238dce

File tree

4 files changed

+55
-26
lines changed

4 files changed

+55
-26
lines changed

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from setuptools import setup
22

33
setup(name='WARP+ to WireGuard',
4-
version='0.6',
4+
version='0.7',
55
description='A simple cli to get WARP+ as WireGuard configuration',
66
url='https://github.com/warp-plus/warpy-python',
77
download_url='https://github.com/warp-plus/warpy-python/archive/v_05.tar.gz',
@@ -12,7 +12,7 @@
1212
packages=['warpy'],
1313
install_requires=['pynacl', "requests"],
1414
entry_points={'console_scripts': [
15-
'warpy = warpy.__main__',
15+
'warpy = warpy.__main__:main',
1616
]},
1717
classifiers=[
1818
'Development Status :: 3 - Alpha', # Chose either "3 - Alpha", "4 - Beta" or "5 - Production/Stable" as the current state of your package

warpy/__main__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ def show_user_info(config):
5757
info = warp_plus.get_info(config["id"], config["token"])
5858
text = '\nID: {}\n'.format(config['id'])
5959
text += "Public Key: {}\n".format(config['key']['public_key'])
60-
text += "Account Type: {}\n".format(info['result']['account']['account_type'])
61-
text += "Quota: {}GB".format(round(int(info['result']['account']['quota']) / (10 ** 9), 2))
60+
text += "Account Type: {}\n".format(info['account']['account_type'])
61+
text += "Quota: {}GB".format(round(int(info['account']['quota']) / (10 ** 9), 2))
6262
print(text)
6363

6464

@@ -168,7 +168,8 @@ def register():
168168
print(warp_plus.export_to_wireguard(reg))
169169
warp_plus.increase_quota(reg)
170170

171-
def init():
171+
172+
def main():
172173
invalid = False
173174
_input = None
174175
show_menu()
@@ -205,4 +206,5 @@ def init():
205206
show_menu()
206207

207208

208-
init()
209+
if __name__ == '__main__':
210+
main()

warpy/cli.py renamed to warpy/main.py

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55
import requests
66
from nacl.bindings import crypto_scalarmult_base
77

8-
from warpy.utils import generate_string, conf
8+
from warpy.utils import generate_string, conf, TlsAdapter
9+
10+
api_version = "v0a884"
11+
12+
session = requests.session()
13+
session.mount("https://", TlsAdapter())
914

1015

1116
class WarpPlus:
@@ -18,49 +23,49 @@ def generate_key():
1823

1924
def enable_warp(self, config):
2025
data = {"warp_enabled": True}
21-
url = 'https://api.cloudflareclient.com/v0a745/reg/' + config['id']
26+
url = 'https://api.cloudflareclient.com/' + api_version + '/reg/' + config['id']
2227
headers = {"Accept-Encoding": "gzip",
2328
"User-Agent": "okhttp/3.12.1",
2429
"Authorization": "Bearer {}".format(config['token']),
2530
"Content-Type": "application/json; charset=UTF-8"}
26-
req = requests.patch(url, json=data, headers=headers)
31+
req = session.request("PATCH", url, json=data, headers=headers)
2732
req.raise_for_status()
2833
req = req.json()
2934
assert req["warp_enabled"] is True
3035

3136
def register(self, key=None, referrer=None):
3237

33-
url = 'https://api.cloudflareclient.com/v0a745/reg'
38+
url = 'https://api.cloudflareclient.com/' + api_version + '/reg'
3439

35-
headers = {'Content-Type': 'application/json; charset=UTF-8',
36-
'Host': 'api.cloudflareclient.com',
37-
'Connection': 'Keep-Alive',
38-
'Accept-Encoding': 'gzip',
39-
'User-Agent': 'okhttp/3.12.1'}
40+
headers = {"Accept-Encoding": "gzip",
41+
"User-Agent": "okhttp/3.12.1",
42+
"Content-Type": "application/json; charset=UTF-8"}
4043

4144
install_id = generate_string(11)
4245
key = key if key else self.generate_key()
4346
data = {"key": key[1],
44-
"install_id": install_id,
45-
"fcm_token": "{}:APA91b{}".format(install_id, generate_string(134)),
47+
"install_id": "",
48+
"fcm_token": "",
4649
"referrer": referrer or "",
4750
"warp_enabled": True,
48-
"tos": datetime.datetime.now().isoformat()[:-3] + "+07:00",
51+
"tos": datetime.datetime.now().isoformat()[:-7] + "Z",
52+
"model": "",
4953
"type": "Android",
50-
"locale": "en-GB"}
51-
52-
req = requests.post(url, headers=headers, json=data)
53-
req.raise_for_status()
54+
"locale": "en_US"}
55+
req = session.request('POST', url, headers=headers, json=data)
56+
if req.status_code != 200:
57+
return {}
5458
req_json = dict(req.json())
5559
req_json['key'] = {"public_key": req_json['config']['peers'][0]['public_key'], "private_key": key[0]}
5660
return req_json
5761

5862
@staticmethod
5963
def get_info(ID, token):
60-
url = 'https://api.cloudflareclient.com/v0i1909221500/reg/' + ID.strip()
64+
url = 'https://api.cloudflareclient.com/' + api_version + '/reg/' + ID.strip()
6165
headers = {"Authorization": "Bearer " + token.strip()}
62-
req = requests.get(url, headers=headers)
63-
req.raise_for_status()
66+
req = session.request("GET", url, headers=headers)
67+
if req.status_code != 200:
68+
raise Exception(req.text)
6469
return req.json()
6570

6671
@staticmethod

warpy/utils.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
import random
22
import string
3+
from requests.adapters import HTTPAdapter
4+
from urllib3.poolmanager import PoolManager
5+
from urllib3.util import ssl_
6+
7+
CIPHERS = (
8+
'ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:'
9+
'ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-SHA256:AES256-SHA'
10+
)
311

412
conf = '''
513
[Interface]
@@ -11,6 +19,20 @@
1119
Endpoint = {endpoint}
1220
AllowedIPs = 0.0.0.0/0'''
1321

22+
23+
class TlsAdapter(HTTPAdapter):
24+
25+
def __init__(self, ssl_options=0, **kwargs):
26+
self.ssl_options = ssl_options
27+
super(TlsAdapter, self).__init__(**kwargs)
28+
29+
def init_poolmanager(self, *pool_args, **pool_kwargs):
30+
ctx = ssl_.create_urllib3_context(ciphers=CIPHERS, cert_reqs=ssl.CERT_REQUIRED, options=self.ssl_options)
31+
self.poolmanager = PoolManager(*pool_args,
32+
ssl_context=ctx,
33+
**pool_kwargs)
34+
35+
1436
class Colored:
1537
HEADER = '\033[43;40m'
1638
PINK = '\033[95m'
@@ -26,4 +48,4 @@ class Colored:
2648

2749
def generate_string(length):
2850
letters = string.ascii_letters + string.digits
29-
return ''.join(random.choice(letters) for _ in range(length))
51+
return ''.join(random.choice(letters) for _ in range(length))

0 commit comments

Comments
 (0)