Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored SSL Handling #73

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/blockbookClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# file LICENSE.txt or http://www.opensource.org/licenses/mit-license.php.

import requests
import certifi

from misc import getCallerName, getFunctionName, printException

Expand Down Expand Up @@ -45,7 +46,7 @@ def checkResponse(self, method, param=""):
url = f"{self.url}/api/{method}"
if param != "":
url += "/{param}"
resp = requests.get(url, data={}, verify=True)
resp = requests.get(url, data={}, verify=certifi.where())
if resp.status_code == 200:
data = resp.json()
return data
Expand Down
3 changes: 2 additions & 1 deletion src/cryptoIDClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from random import choice
import requests
import certifi

from misc import getCallerName, getFunctionName, printException

Expand Down Expand Up @@ -51,7 +52,7 @@ def __init__(self, isTestnet=False):
def checkResponse(self, parameters):
key = choice(api_keys)
parameters['key'] = key
resp = requests.get(self.url, params=parameters)
resp = requests.get(self.url, params=parameters, verify=certifi.where())
if resp.status_code == 200:
data = resp.json()
return data
Expand Down
5 changes: 4 additions & 1 deletion src/mainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,10 @@ def updateRPCstatus(self, ctrl, fDebug=False):
return

rpcResponseTime = None
if r_time1 is not None and r_time2 != 0:
if r_time1 is None:
r_time1 = 0.0
if r_time2 is None:
r_time2 = 0.0
rpcResponseTime = round((r_time1 + r_time2) / 2, 3)

# Do not update status if the user has selected a different server since the start of updateRPCStatus()
Expand Down
3 changes: 2 additions & 1 deletion src/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,9 @@ def getFunctionName(inDecorator=False):

def getRemoteSPMTversion():
import requests
import certifi
try:
resp = requests.get("https://raw.githubusercontent.com/PIVX-Project/PIVX-SPMT/master/src/version.txt")
resp = requests.get("https://raw.githubusercontent.com/PIVX-Project/PIVX-SPMT/master/src/version.txt", verify=certifi.where())
if resp.status_code == 200:
data = resp.json()
return data['number']
Expand Down
26 changes: 11 additions & 15 deletions src/rpcClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
# file LICENSE.txt or http://www.opensource.org/licenses/mit-license.php.

from bitcoinrpc.authproxy import AuthServiceProxy

import http.client as httplib
import ssl
import threading

from constants import DEFAULT_PROTOCOL_VERSION, MINIMUM_FEE
Expand All @@ -18,7 +15,9 @@
def process_RPC_exceptions(func):
def wrapper(*args, **kwargs):
try:
args[0].httpConnection.connect()
# If httpConnection exists, connect manually
if hasattr(args[0], 'httpConnection') and args[0].httpConnection:
args[0].httpConnection.connect()
return func(*args, **kwargs)
except Exception as e:
message = "Exception in RPC client"
Expand All @@ -32,11 +31,13 @@ def wrapper(*args, **kwargs):
else:
return None
finally:
try:
args[0].httpConnection.close()
except Exception as e:
printDbg(e)
pass
# If httpConnection exists, close it
if hasattr(args[0], 'httpConnection') and args[0].httpConnection:
try:
args[0].httpConnection.close()
except Exception as e:
printDbg(e)
pass
return wrapper


Expand All @@ -48,13 +49,8 @@ def __init__(self, rpc_protocol, rpc_host, rpc_user, rpc_password):

self.rpc_url = f"{rpc_protocol}://{rpc_user}:{rpc_password}@{rpc_host}"

host, port = rpc_host.split(":")
if rpc_protocol == "https":
self.httpConnection = httplib.HTTPSConnection(host, port, timeout=20, context=ssl.create_default_context())
else:
self.httpConnection = httplib.HTTPConnection(host, port, timeout=20)

self.conn = AuthServiceProxy(self.rpc_url, timeout=1000, connection=self.httpConnection)
self.conn = AuthServiceProxy(self.rpc_url, timeout=1000)

@process_RPC_exceptions
def getBlockCount(self):
Expand Down