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

Fix deprecated TLSv1 and encodestring usage. #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
14 changes: 6 additions & 8 deletions ovirtclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
import urllib.request
import threading
from time import sleep, time
from base64 import encodestring
from base64 import encodebytes
from xml.etree import cElementTree as ET
from random import randint
from subprocess import Popen
from os import remove, access, X_OK
from os.path import isfile
from ssl import SSLContext, PROTOCOL_TLSv1
from ssl import SSLContext, PROTOCOL_TLS
from globalconf import *
from credentials import Credentials
from about import About
Expand Down Expand Up @@ -326,12 +326,11 @@ def get_viewer_ticket(self, vmid):
global conf

req = urllib.request.Request('%s/%s/%s/%s' % (conf.CONFIG['ovirturl'], 'vms', vmid, 'graphicsconsoles'))
# Python 2 -> 3 conversion: encodestring expects a byte-like string, not str
base64str = encodestring(('%s:%s' % (conf.USERNAME + '@' + conf.CONFIG['ovirtdomain'], conf.PASSWORD)).encode()).decode().replace('\n', '')
base64str = encodebytes(('%s:%s' % (conf.USERNAME + '@' + conf.CONFIG['ovirtdomain'], conf.PASSWORD)).encode('UTF-8')).decode('UTF-8').replace('\n', '')
req.add_header('Authorization', 'Basic ' + base64str)
req.add_header('filter', 'true')

unverified_ctxt = SSLContext(PROTOCOL_TLSv1)
unverified_ctxt = SSLContext(PROTOCOL_TLS)
tickethash = urllib.request.urlopen(req, context=unverified_ctxt).read()
xmlcontent = ET.fromstring(tickethash)

Expand Down Expand Up @@ -361,14 +360,13 @@ def store_vv_file(self, vmid, ticket):
return False

req = urllib.request.Request('%s/%s/%s/%s/%s' % (conf.CONFIG['ovirturl'], 'vms', vmid, 'graphicsconsoles', ticket))
# Python 2 -> 3 conversion: encodestring expects a byte-like string, not str
base64str = encodestring(('%s:%s' % (conf.USERNAME + '@' + conf.CONFIG['ovirtdomain'], conf.PASSWORD)).encode()).decode().replace('\n', '')
base64str = encodebytes(('%s:%s' % (conf.USERNAME + '@' + conf.CONFIG['ovirtdomain'], conf.PASSWORD)).encode('UTF-8')).decode('UTF-8').replace('\n', '')
req.add_header('Authorization', 'Basic ' + base64str)
req.add_header('Content-Type', 'application/xml')
req.add_header('Accept', 'application/x-virt-viewer')
req.add_header('filter', 'true')

unverified_ctxt = SSLContext(PROTOCOL_TLSv1)
unverified_ctxt = SSLContext(PROTOCOL_TLS)
try:
contents = urllib.request.urlopen(req, context=unverified_ctxt).read()
if conf.CONFIG['fullscreen'] == '1':
Expand Down