Skip to content

Commit

Permalink
Add config for verification of ssl certificates
Browse files Browse the repository at this point in the history
  • Loading branch information
awesome-michael committed Mar 19, 2022
1 parent 7f427e8 commit 5bda63f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
2 changes: 2 additions & 0 deletions conf/example_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ homeserver: https://example.org
domain: example.org
# Application Service Token from the matrix Homeserver
as_token: very-secret
# Verify https certificate (True) or ignore 'unsafe' SSL certificates (False)
verify-ssl: True
# Don't download files from Slack and upload them to Matrix
skip-files: False
# Path to the Slack Backup relative to the current directory or absolute
Expand Down
2 changes: 1 addition & 1 deletion slack-matrix-migration/slack-matrix-migration/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def uploadContentFromURI(content, uri, config, user):

url = "%s/_matrix/media/r0/upload?user_id=%s&filename=%s" % (config["homeserver"],user,content["title"],)
try:
r = requests.post(url, headers={'Authorization': 'Bearer ' + config["as_token"], 'Content-Type': content["mimetype"]}, data=file_content, verify=False)
r = requests.post(url, headers={'Authorization': 'Bearer ' + config["as_token"], 'Content-Type': content["mimetype"]}, data=file_content, verify=config["verify-ssl"])
except requests.exceptions.RequestException as e:
# catastrophic error. bail.
log.error(
Expand Down
12 changes: 6 additions & 6 deletions slack-matrix-migration/slack-matrix-migration/migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def login(server_location):
}

# Get the access token
r = requests.post(url, json=data, verify=False)
r = requests.post(url, json=data, verify=config["verify-ssl"])

if r.status_code != 200:
log.info("ERROR! Received %d %s" % (r.status_code, r.reason))
Expand All @@ -216,7 +216,7 @@ def login(server_location):
def getMaxUploadSize(config, access_token):
# get maxUploadSize from Homeserver
url = "%s/_matrix/media/r0/config?access_token=%s" % (config_yaml["homeserver"],access_token,)
r = requests.get(url, verify=False)
r = requests.get(url, verify=config["verify-ssl"])

if r.status_code != 200:
log.info("ERROR! Received %d %s" % (r.status_code, r.reason))
Expand Down Expand Up @@ -249,7 +249,7 @@ def register_user(
"admin": admin,
}
try:
r = requests.put(url, json=data, headers=headers, verify=False)
r = requests.put(url, json=data, headers=headers, verify=config["verify-ssl"])
except requests.exceptions.RequestException as e:
# catastrophic error. bail.
log.error(
Expand Down Expand Up @@ -305,7 +305,7 @@ def register_room(

#_log.info("Sending registration request...")
try:
r = requests.post(url, headers={'Authorization': 'Bearer ' + as_token}, json=body, verify=False, timeout=300 )
r = requests.post(url, headers={'Authorization': 'Bearer ' + as_token}, json=body, verify=config["verify-ssl"], timeout=300 )
# except requests.exceptions.Timeout:
# # Maybe set up for a retry, or continue in a retry loop
# except requests.exceptions.TooManyRedirects:
Expand Down Expand Up @@ -350,7 +350,7 @@ def autojoin_users(

#_log.info("Sending registration request...")
try:
r = requests.post(url, headers={'Authorization': 'Bearer ' + config["as_token"]}, verify=False)
r = requests.post(url, headers={'Authorization': 'Bearer ' + config["as_token"]}, verify=config["verify-ssl"])
except requests.exceptions.RequestException as e:
log.error(
"Logging an uncaught exception {}".format(e),
Expand Down Expand Up @@ -840,7 +840,7 @@ def kick_imported_users(server_location, admin_user, access_token, tick):
data = {"user_id": name}

try:
r = requests.post(url, json=data, headers=headers, verify=False)
r = requests.post(url, json=data, headers=headers, verify=config["verify-ssl"])
except requests.exceptions.RequestException as e:
# catastrophic error. bail.
log.error(
Expand Down
6 changes: 3 additions & 3 deletions slack-matrix-migration/slack-matrix-migration/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def send_event(
#_log.info("Sending registration request...")

try:
r = requests.put(url, headers={'Authorization': 'Bearer ' + config["as_token"]}, json=matrix_message, verify=False)
r = requests.put(url, headers={'Authorization': 'Bearer ' + config["as_token"]}, json=matrix_message, verify=config["verify-ssl"])
except requests.exceptions.RequestException as e:
# catastrophic error. bail.
log.error(
Expand All @@ -70,7 +70,7 @@ def send_event(
conf
)
try:
r = requests.put(url, headers={'Authorization': 'Bearer ' + config["as_token"]}, json=matrix_message, verify=False)
r = requests.put(url, headers={'Authorization': 'Bearer ' + config["as_token"]}, json=matrix_message, verify=config["verify-ssl"])
except requests.exceptions.RequestException as e:
# catastrophic error. bail.
log.error(
Expand Down Expand Up @@ -109,7 +109,7 @@ def invite_user(

#_log.info("Sending registration request...")
try:
r = requests.post(url, headers={'Authorization': 'Bearer ' + config["as_token"]}, json=body, verify=False)
r = requests.post(url, headers={'Authorization': 'Bearer ' + config["as_token"]}, json=body, verify=config["verify-ssl"])
except requests.exceptions.RequestException as e:
# catastrophic error. bail.
log.error(
Expand Down

0 comments on commit 5bda63f

Please sign in to comment.