Commit ad9370af authored by Emmanuel Gil Peyrot's avatar Emmanuel Gil Peyrot

Fix a bunch of issues in common.jingle*.

parent 57fb80f1
...@@ -142,6 +142,10 @@ SHOW_LIST = ['offline', 'connecting', 'online', 'chat', 'away', 'xa', 'dnd', ...@@ -142,6 +142,10 @@ SHOW_LIST = ['offline', 'connecting', 'online', 'chat', 'away', 'xa', 'dnd',
# zeroconf account name # zeroconf account name
ZEROCONF_ACC_NAME = 'Local' ZEROCONF_ACC_NAME = 'Local'
# These will be set in gajim.gui_interface.
idlequeue = None
socks5queue = None
HAVE_ZEROCONF = True HAVE_ZEROCONF = True
try: try:
__import__('avahi') __import__('avahi')
......
...@@ -28,19 +28,21 @@ Handles the jingle signalling protocol ...@@ -28,19 +28,21 @@ Handles the jingle signalling protocol
# * config: # * config:
# - codecs # - codecs
import logging
import nbxmpp import nbxmpp
from common import helpers from common import helpers
from common import gajim from common import gajim
from common.jingle_session import JingleSession, JingleStates from common.jingle_session import JingleSession, JingleStates
if gajim.HAVE_FARSTREAM:
from common.jingle_rtp import JingleAudio, JingleVideo
from common.jingle_ft import JingleFileTransfer from common.jingle_ft import JingleFileTransfer
from common.jingle_transport import JingleTransportSocks5, JingleTransportIBB from common.jingle_transport import JingleTransportSocks5, JingleTransportIBB
if gajim.HAVE_FARSTREAM:
from common.jingle_rtp import JingleAudio, JingleVideo
import logging
logger = logging.getLogger('gajim.c.jingle') logger = logging.getLogger('gajim.c.jingle')
class ConnectionJingle(object): class ConnectionJingle(object):
""" """
This object depends on that it is a part of Connection class. This object depends on that it is a part of Connection class.
...@@ -80,7 +82,7 @@ class ConnectionJingle(object): ...@@ -80,7 +82,7 @@ class ConnectionJingle(object):
try: try:
jid = helpers.get_full_jid_from_iq(stanza) jid = helpers.get_full_jid_from_iq(stanza)
except helpers.InvalidFormat: except helpers.InvalidFormat:
logger.warn('Invalid JID: %s, ignoring it' % stanza.getFrom()) logger.warning('Invalid JID: %s, ignoring it', stanza.getFrom())
return return
id_ = stanza.getID() id_ = stanza.getID()
if (jid, id_) in self.__iq_responses.keys(): if (jid, id_) in self.__iq_responses.keys():
...@@ -102,14 +104,14 @@ class ConnectionJingle(object): ...@@ -102,14 +104,14 @@ class ConnectionJingle(object):
if sid not in self._sessions: if sid not in self._sessions:
#TODO: tie-breaking and other things... #TODO: tie-breaking and other things...
newjingle = JingleSession(con=self, weinitiate=False, jid=jid, newjingle = JingleSession(con=self, weinitiate=False, jid=jid,
iq_id=id_, sid=sid) iq_id=id_, sid=sid)
self._sessions[sid] = newjingle self._sessions[sid] = newjingle
# we already have such session in dispatcher... # we already have such session in dispatcher...
self._sessions[sid].collect_iq_id(id_) self._sessions[sid].collect_iq_id(id_)
self._sessions[sid].on_stanza(stanza) self._sessions[sid].on_stanza(stanza)
# Delete invalid/unneeded sessions # Delete invalid/unneeded sessions
if sid in self._sessions and \ if sid in self._sessions and \
self._sessions[sid].state == JingleStates.ended: self._sessions[sid].state == JingleStates.ENDED:
self.delete_jingle_session(sid) self.delete_jingle_session(sid)
raise nbxmpp.NodeProcessed raise nbxmpp.NodeProcessed
...@@ -132,20 +134,20 @@ class ConnectionJingle(object): ...@@ -132,20 +134,20 @@ class ConnectionJingle(object):
jingle = self.get_jingle_session(jid, media='audio') jingle = self.get_jingle_session(jid, media='audio')
if jingle: if jingle:
jingle.add_content('video', JingleVideo(jingle, in_xid=in_xid, jingle.add_content('video', JingleVideo(jingle, in_xid=in_xid,
out_xid=out_xid)) out_xid=out_xid))
else: else:
jingle = JingleSession(self, weinitiate=True, jid=jid) jingle = JingleSession(self, weinitiate=True, jid=jid)
self._sessions[jingle.sid] = jingle self._sessions[jingle.sid] = jingle
jingle.add_content('video', JingleVideo(jingle, in_xid=in_xid, jingle.add_content('video', JingleVideo(jingle, in_xid=in_xid,
out_xid=out_xid)) out_xid=out_xid))
jingle.start_session() jingle.start_session()
return jingle.sid return jingle.sid
def start_file_transfer(self, jid, file_props, request=False): def start_file_transfer(self, jid, file_props, request=False):
logger.info("start file transfer with file: %s" % file_props) logger.info("start file transfer with file: %s", file_props)
contact = gajim.contacts.get_contact_with_highest_priority(self.name, contact = gajim.contacts.get_contact_with_highest_priority(self.name,
gajim.get_jid_without_resource(jid)) gajim.get_jid_without_resource(jid))
if gajim.contacts.is_gc_contact(self.name,jid): if gajim.contacts.is_gc_contact(self.name, jid):
gcc = jid.split('/') gcc = jid.split('/')
if len(gcc) == 2: if len(gcc) == 2:
contact = gajim.contacts.get_gc_contact(self.name, gcc[0], gcc[1]) contact = gajim.contacts.get_gc_contact(self.name, gcc[0], gcc[1])
...@@ -162,7 +164,8 @@ class ConnectionJingle(object): ...@@ -162,7 +164,8 @@ class ConnectionJingle(object):
elif contact.supports(nbxmpp.NS_JINGLE_IBB): elif contact.supports(nbxmpp.NS_JINGLE_IBB):
transport = JingleTransportIBB() transport = JingleTransportIBB()
c = JingleFileTransfer(jingle, transport=transport, c = JingleFileTransfer(jingle, transport=transport,
file_props=file_props, use_security=use_security) file_props=file_props,
use_security=use_security)
file_props.algo = self.__hash_support(contact) file_props.algo = self.__hash_support(contact)
jingle.add_content('file' + helpers.get_random_string_16(), c) jingle.add_content('file' + helpers.get_random_string_16(), c)
jingle.start_session() jingle.start_session()
......
...@@ -37,7 +37,7 @@ class JingleContentSetupException(Exception): ...@@ -37,7 +37,7 @@ class JingleContentSetupException(Exception):
""" """
class JingleContent(object): class JingleContent:
""" """
An abstraction of content in Jingle sessions An abstraction of content in Jingle sessions
""" """
...@@ -48,8 +48,8 @@ class JingleContent(object): ...@@ -48,8 +48,8 @@ class JingleContent(object):
# will be filled by JingleSession.add_content() # will be filled by JingleSession.add_content()
# don't uncomment these lines, we will catch more buggy code then # don't uncomment these lines, we will catch more buggy code then
# (a JingleContent not added to session shouldn't send anything) # (a JingleContent not added to session shouldn't send anything)
#self.creator = None self.creator = None
#self.name = None self.name = None
self.accepted = False self.accepted = False
self.sent = False self.sent = False
self.negotiated = False self.negotiated = False
...@@ -59,35 +59,39 @@ class JingleContent(object): ...@@ -59,35 +59,39 @@ class JingleContent(object):
self.senders = 'both' #FIXME self.senders = 'both' #FIXME
self.allow_sending = True # Used for stream direction, attribute 'senders' self.allow_sending = True # Used for stream direction, attribute 'senders'
# These were found by the Politie
self.file_props = None
self.use_security = None
self.callbacks = { self.callbacks = {
# these are called when *we* get stanzas # these are called when *we* get stanzas
'content-accept': [self.__on_transport_info, 'content-accept': [self.__on_transport_info,
self.__on_content_accept], self.__on_content_accept],
'content-add': [self.__on_transport_info], 'content-add': [self.__on_transport_info],
'content-modify': [], 'content-modify': [],
'content-reject': [], 'content-reject': [],
'content-remove': [], 'content-remove': [],
'description-info': [], 'description-info': [],
'security-info': [], 'security-info': [],
'session-accept': [self.__on_transport_info, 'session-accept': [self.__on_transport_info,
self.__on_content_accept], self.__on_content_accept],
'session-info': [], 'session-info': [],
'session-initiate': [self.__on_transport_info], 'session-initiate': [self.__on_transport_info],
'session-terminate': [], 'session-terminate': [],
'transport-info': [self.__on_transport_info], 'transport-info': [self.__on_transport_info],
'transport-replace': [self.__on_transport_replace], 'transport-replace': [self.__on_transport_replace],
'transport-accept': [], 'transport-accept': [],
'transport-reject': [], 'transport-reject': [],
'iq-result': [], 'iq-result': [],
'iq-error': [], 'iq-error': [],
# these are called when *we* sent these stanzas # these are called when *we* sent these stanzas
'content-accept-sent': [self.__fill_jingle_stanza, 'content-accept-sent': [self.__fill_jingle_stanza,
self.__on_content_accept], self.__on_content_accept],
'content-add-sent': [self.__fill_jingle_stanza], 'content-add-sent': [self.__fill_jingle_stanza],
'session-initiate-sent': [self.__fill_jingle_stanza], 'session-initiate-sent': [self.__fill_jingle_stanza],
'session-accept-sent': [self.__fill_jingle_stanza, 'session-accept-sent': [self.__fill_jingle_stanza,
self.__on_content_accept], self.__on_content_accept],
'session-terminate-sent': [], 'session-terminate-sent': [],
} }
def is_ready(self): def is_ready(self):
...@@ -134,8 +138,8 @@ class JingleContent(object): ...@@ -134,8 +138,8 @@ class JingleContent(object):
if payload is None: if payload is None:
payload = [] payload = []
return nbxmpp.Node('content', return nbxmpp.Node('content',
attrs={'name': self.name, 'creator': self.creator}, attrs={'name': self.name, 'creator': self.creator},
payload=payload) payload=payload)
def send_candidate(self, candidate): def send_candidate(self, candidate):
""" """
...@@ -191,17 +195,16 @@ class JingleContent(object): ...@@ -191,17 +195,16 @@ class JingleContent(object):
file_tag.addChild(node=node) file_tag.addChild(node=node)
if self.file_props.type_ == 'r': if self.file_props.type_ == 'r':
if self.file_props.hash_: if self.file_props.hash_:
h = file_tag.addChild('hash', attrs={ file_tag.addChild('hash', attrs={'algo': self.file_props.algo},
'algo': self.file_props.algo}, namespace=nbxmpp.NS_HASHES, namespace=nbxmpp.NS_HASHES,
payload=self.file_props.hash_) payload=self.file_props.hash_)
else: else:
# if the file is less than 10 mb, then it is small # if the file is less than 10 mb, then it is small
# lets calculate it right away # lets calculate it right away
if self.file_props.size < 10000000 and not \ if self.file_props.size < 10000000 and not self.file_props.hash_:
self.file_props.hash_: hash_data = content._compute_hash()
h = self._calcHash() if hash_data:
if h: file_tag.addChild(node=hash_data)
file_tag.addChild(node=h)
pjid = gajim.get_jid_without_resource(self.session.peerjid) pjid = gajim.get_jid_without_resource(self.session.peerjid)
file_info = {'name' : self.file_props.name, file_info = {'name' : self.file_props.name,
'file-name' : self.file_props.file_name, 'file-name' : self.file_props.file_name,
...@@ -223,9 +226,9 @@ class JingleContent(object): ...@@ -223,9 +226,9 @@ class JingleContent(object):
cert = load_cert_file(certpath) cert = load_cert_file(certpath)
if cert: if cert:
try: try:
digest_algo = cert.get_signature_algorithm().decode('utf-8' digest_algo = (cert.get_signature_algorithm()
).split('With')[0] .decode('utf-8').split('With')[0])
except AttributeError as e: except AttributeError:
# Old py-OpenSSL is missing get_signature_algorithm # Old py-OpenSSL is missing get_signature_algorithm
digest_algo = "sha256" digest_algo = "sha256"
security.addChild('fingerprint').addData(cert.digest( security.addChild('fingerprint').addData(cert.digest(
...@@ -240,5 +243,3 @@ class JingleContent(object): ...@@ -240,5 +243,3 @@ class JingleContent(object):
def destroy(self): def destroy(self):
self.callbacks = None self.callbacks = None
del self.session.contents[(self.creator, self.name)] del self.session.contents[(self.creator, self.name)]
This diff is collapsed.
...@@ -13,11 +13,14 @@ ...@@ -13,11 +13,14 @@
## You should have received a copy of the GNU General Public License ## You should have received a copy of the GNU General Public License
## along with Gajim. If not, see <http://www.gnu.org/licenses/>. ## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
from common import gajim
import nbxmpp import nbxmpp
from common.jingle_transport import * from common import gajim
from common.jingle_transport import TransportType
from common.socks5 import Socks5ReceiverClient, Socks5SenderClient from common.socks5 import Socks5ReceiverClient, Socks5SenderClient
import logging
log = logging.getLogger('gajim.c.jingle_ftstates')
class JingleFileTransferStates: class JingleFileTransferStates:
''' '''
...@@ -31,7 +34,7 @@ class JingleFileTransferStates: ...@@ -31,7 +34,7 @@ class JingleFileTransferStates:
''' '''
This method MUST be overriden by a subclass This method MUST be overriden by a subclass
''' '''
raise Exception('This is an abstract method!!') raise NotImplementedError('This is an abstract method!')
class StateInitialized(JingleFileTransferStates): class StateInitialized(JingleFileTransferStates):
...@@ -50,8 +53,10 @@ class StateInitialized(JingleFileTransferStates): ...@@ -50,8 +53,10 @@ class StateInitialized(JingleFileTransferStates):
fingerprint = 'client' fingerprint = 'client'
# Connect to the candidate host, on success call on_connect method # Connect to the candidate host, on success call on_connect method
gajim.socks5queue.connect_to_hosts(self.jft.session.connection.name, gajim.socks5queue.connect_to_hosts(self.jft.session.connection.name,
self.jft.file_props.sid, self.jft.on_connect, self.jft.file_props.sid,
self.jft._on_connect_error, fingerprint=fingerprint) self.jft.on_connect,
self.jft._on_connect_error,
fingerprint=fingerprint)
class StateCandSent(JingleFileTransferStates): class StateCandSent(JingleFileTransferStates):
...@@ -59,7 +64,7 @@ class StateCandSent(JingleFileTransferStates): ...@@ -59,7 +64,7 @@ class StateCandSent(JingleFileTransferStates):
This state sends our nominated candidate This state sends our nominated candidate
''' '''
def _sendCand(self, args): def _send_candidate(self, args):
if 'candError' in args: if 'candError' in args:
self.jft.nominated_cand['our-cand'] = False self.jft.nominated_cand['our-cand'] = False
self.jft.send_error_candidate() self.jft.send_error_candidate()
...@@ -80,16 +85,16 @@ class StateCandSent(JingleFileTransferStates): ...@@ -80,16 +85,16 @@ class StateCandSent(JingleFileTransferStates):
self.jft.session.send_transport_info(content) self.jft.session.send_transport_info(content)
def action(self, args=None): def action(self, args=None):
self._sendCand(args) self._send_candidate(args)
class StateCandReceived(JingleFileTransferStates): class StateCandReceived(JingleFileTransferStates):
''' '''
This state happens when we receive a candidate. This state happens when we receive a candidate.
It takes the arguments: canError if we receive a candidate-error It takes the arguments: canError if we receive a candidate-error
''' '''
def _recvCand(self, args): def _recv_candidate(self, args):
if 'candError' in args: if 'candError' in args:
return return
content = args['content'] content = args['content']
...@@ -100,17 +105,17 @@ class StateCandReceived(JingleFileTransferStates): ...@@ -100,17 +105,17 @@ class StateCandReceived(JingleFileTransferStates):
if cand['candidate_id'] == streamhost_cid: if cand['candidate_id'] == streamhost_cid:
streamhost_used = cand streamhost_used = cand
break break
if streamhost_used == None: if streamhost_used is None:
log.info("unknow streamhost") log.info("unknow streamhost")
return return
# We save the candidate nominated by peer # We save the candidate nominated by peer
self.jft.nominated_cand['peer-cand'] = streamhost_used self.jft.nominated_cand['peer-cand'] = streamhost_used
def action(self, args=None): def action(self, args=None):
self._recvCand(args) self._recv_candidate(args)
class StateCandSentAndRecv( StateCandSent, StateCandReceived): class StateCandSentAndRecv(StateCandSent, StateCandReceived):
''' '''
This state happens when we have received and sent the candidates. This state happens when we have received and sent the candidates.
It takes the boolean argument: sendCand in order to decide whether It takes the boolean argument: sendCand in order to decide whether
...@@ -119,9 +124,9 @@ class StateCandSentAndRecv( StateCandSent, StateCandReceived): ...@@ -119,9 +124,9 @@ class StateCandSentAndRecv( StateCandSent, StateCandReceived):
def action(self, args=None): def action(self, args=None):
if args['sendCand']: if args['sendCand']:
self._sendCand(args) self._send_candidate(args)
else: else:
self._recvCand(args) self._recv_candidate(args)
class StateTransportReplace(JingleFileTransferStates): class StateTransportReplace(JingleFileTransferStates):
...@@ -139,16 +144,16 @@ class StateTransfering(JingleFileTransferStates): ...@@ -139,16 +144,16 @@ class StateTransfering(JingleFileTransferStates):
we have. we have.
''' '''
def __start_IBB_transfer(self, con): def _start_ibb_transfer(self, con):
self.jft.file_props.transport_sid = self.jft.transport.sid self.jft.file_props.transport_sid = self.jft.transport.sid
fp = open(self.jft.file_props.file_name, 'r') fp = open(self.jft.file_props.file_name, 'r')
con.OpenStream( self.jft.file_props.sid, self.jft.session.peerjid, fp, con.OpenStream(self.jft.file_props.sid, self.jft.session.peerjid, fp,
blocksize=4096) blocksize=4096)
def __start_SOCK5_transfer(self): def _start_sock5_transfer(self):
# It tells wether we start the transfer as client or server # It tells wether we start the transfer as client or server
mode = None mode = None
if self.jft.isOurCandUsed(): if self.jft.is_our_candidate_used():
mode = 'client' mode = 'client'
streamhost_used = self.jft.nominated_cand['our-cand'] streamhost_used = self.jft.nominated_cand['our-cand']
gajim.socks5queue.remove_server(self.jft.file_props.sid) gajim.socks5queue.remove_server(self.jft.file_props.sid)
...@@ -191,34 +196,34 @@ class StateTransfering(JingleFileTransferStates): ...@@ -191,34 +196,34 @@ class StateTransfering(JingleFileTransferStates):
gajim.socks5queue.idx += 1 gajim.socks5queue.idx += 1
idx = gajim.socks5queue.idx idx = gajim.socks5queue.idx
sockobj = Socks5SenderClient(gajim.idlequeue, idx, sockobj = Socks5SenderClient(gajim.idlequeue, idx,
gajim.socks5queue, _sock=None, gajim.socks5queue, _sock=None,
host=str(streamhost_used['host']), host=str(streamhost_used['host']),
port=int(streamhost_used['port']), fingerprint=None, port=int(streamhost_used['port']),
connected=False, file_props=self.jft.file_props) fingerprint=None, connected=False,
file_props=self.jft.file_props)
else: else:
sockobj = Socks5ReceiverClient(gajim.idlequeue, streamhost_used, sockobj = Socks5ReceiverClient(gajim.idlequeue, streamhost_used,
sid=self.jft.file_props.sid, sid=self.jft.file_props.sid,
file_props=self.jft.file_props, fingerprint=None) file_props=self.jft.file_props,
fingerprint=None)
sockobj.proxy = True sockobj.proxy = True
sockobj.streamhost = streamhost_used sockobj.streamhost = streamhost_used
gajim.socks5queue.add_sockobj(self.jft.session.connection.name, gajim.socks5queue.add_sockobj(self.jft.session.connection.name,
sockobj) sockobj)
streamhost_used['idx'] = sockobj.queue_idx streamhost_used['idx'] = sockobj.queue_idx
# If we offered the nominated candidate used, we activate # If we offered the nominated candidate used, we activate
# the proxy # the proxy
if not self.jft.isOurCandUsed(): if not self.jft.is_our_candidate_used():
gajim.socks5queue.on_success[self.jft.file_props.sid] = \ gajim.socks5queue.on_success[self.jft.file_props.sid] = \
self.jft.transport._on_proxy_auth_ok self.jft.transport._on_proxy_auth_ok
# TODO: add on failure # TODO: add on failure
else: else:
jid = gajim.get_jid_without_resource(self.jft.session.ourjid) jid = gajim.get_jid_without_resource(self.jft.session.ourjid)
gajim.socks5queue.send_file(self.jft.file_props, gajim.socks5queue.send_file(self.jft.file_props,
self.jft.session.connection.name, mode) self.jft.session.connection.name, mode)
def action(self, args=None): def action(self, args=None):
if self.jft.transport.type_ == TransportType.IBB: if self.jft.transport.type_ == TransportType.IBB:
self.__start_IBB_transfer(self.jft.session.connection) self._start_ibb_transfer(self.jft.session.connection)
elif self.jft.transport.type_ == TransportType.SOCKS5: elif self.jft.transport.type_ == TransportType.SOCKS5:
self.__start_SOCK5_transfer() self._start_sock5_transfer()
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -16,13 +16,15 @@ ...@@ -16,13 +16,15 @@
## along with Gajim. If not, see <http://www.gnu.org/licenses/>. ## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
## ##
import logging
import os import os
import nbxmpp
import logging import nbxmpp
from common import gajim from common import gajim
log = logging.getLogger('gajim.c.jingle_xtls') log = logging.getLogger('gajim.c.jingle_xtls')
PYOPENSSL_PRESENT = False PYOPENSSL_PRESENT = False
# key-exchange id -> [callback, args], accept that session once key-exchange completes # key-exchange id -> [callback, args], accept that session once key-exchange completes
...@@ -53,7 +55,7 @@ DH_PARAMS = 'dh_params.pem' ...@@ -53,7 +55,7 @@ DH_PARAMS = 'dh_params.pem'
DEFAULT_DH_PARAMS = 'dh4096.pem' DEFAULT_DH_PARAMS = 'dh4096.pem'
def default_callback(connection, certificate, error_num, depth, return_code): def default_callback(connection, certificate, error_num, depth, return_code):
log.info("certificate: %s" % certificate) log.info("certificate: %s", certificate)
return return_code return return_code
def load_cert_file(cert_path, cert_store=None): def load_cert_file(cert_path, cert_store=None):
...@@ -65,8 +67,8 @@ def load_cert_file(cert_path, cert_store=None): ...@@ -65,8 +67,8 @@ def load_cert_file(cert_path, cert_store=None):
try: try:
f = open(cert_path) f = open(cert_path)
except IOError as e: except IOError as e:
log.warning('Unable to open certificate file %s: %s' % (cert_path, log.warning('Unable to open certificate file %s: %s', cert_path,
str(e))) str(e))
return None return None
lines = f.readlines() lines = f.readlines()
i = 0 i = 0
...@@ -84,11 +86,11 @@ def load_cert_file(cert_path, cert_store=None): ...@@ -84,11 +86,11 @@ def load_cert_file(cert_path, cert_store=None):
f.close() f.close()
return x509cert return x509cert
except OpenSSL.crypto.Error as exception_obj: except OpenSSL.crypto.Error as exception_obj:
log.warning('Unable to load a certificate from file %s: %s' %\ log.warning('Unable to load a certificate from file %s: %s',
(cert_path, exception_obj.args[0][0][2])) cert_path, exception_obj.args[0][0][2])
except: except:
log.warning('Unknown error while loading certificate from file ' log.warning('Unknown error while loading certificate from file '
'%s' % cert_path) '%s', cert_path)
begin = -1 begin = -1
i += 1 i += 1
f.close() f.close()
...@@ -105,7 +107,7 @@ def get_context(fingerprint, verify_cb=None, remote_jid=None): ...@@ -105,7 +107,7 @@ def get_context(fingerprint, verify_cb=None, remote_jid=None):
if fingerprint == 'server': # for testing purposes only if fingerprint == 'server': # for testing purposes only
ctx.set_verify(SSL.VERIFY_NONE|SSL.VERIFY_FAIL_IF_NO_PEER_CERT, ctx.set_verify(SSL.VERIFY_NONE|SSL.VERIFY_FAIL_IF_NO_PEER_CERT,
verify_cb or default_callback) verify_cb or default_callback)
elif fingerprint == 'client': elif fingerprint == 'client':
ctx.set_verify(SSL.VERIFY_PEER, verify_cb or default_callback) ctx.set_verify(SSL.VERIFY_PEER, verify_cb or default_callback)
...@@ -121,23 +123,23 @@ def get_context(fingerprint, verify_cb=None, remote_jid=None): ...@@ -121,23 +123,23 @@ def get_context(fingerprint, verify_cb=None, remote_jid=None):
ctx.load_tmp_dh(dh_params_name.encode('utf-8')) ctx.load_tmp_dh(dh_params_name.encode('utf-8'))
except FileNotFoundError as err: except FileNotFoundError as err:
default_dh_params_name = os.path.join(gajim.DATA_DIR, default_dh_params_name = os.path.join(gajim.DATA_DIR,
'other', DEFAULT_DH_PARAMS) 'other', DEFAULT_DH_PARAMS)
try: try:
with open(default_dh_params_name, "r") as default_dh_params_file: with open(default_dh_params_name, "r") as default_dh_params_file:
ctx.load_tmp_dh(default_dh_params_name.encode('utf-8')) ctx.load_tmp_dh(default_dh_params_name.encode('utf-8'))
except FileNotFoundError as err: except FileNotFoundError as err:
log.error('Unable to load default DH parameter file: %s , %s' log.error('Unable to load default DH parameter file: %s, %s',
% (default_dh_params_name, err)) default_dh_params_name, err)
raise raise
if remote_jid: if remote_jid:
store = ctx.get_cert_store() store = ctx.get_cert_store()
path = os.path.join(os.path.expanduser(gajim.MY_PEER_CERTS_PATH), path = os.path.join(os.path.expanduser(gajim.MY_PEER_CERTS_PATH),
remote_jid) + '.cert' remote_jid) + '.cert'
if os.path.exists(path): if os.path.exists(path):
load_cert_file(path, cert_store=store) load_cert_file(path, cert_store=store)
log.debug('certificate file ' + path + ' loaded fingerprint ' + \ log.debug('certificate file %s loaded fingerprint %s',
fingerprint) path, fingerprint)
return ctx return ctx
def read_cert(certpath): def read_cert(certpath):
...@@ -212,16 +214,16 @@ def send_cert_request(con, to_jid): ...@@ -212,16 +214,16 @@ def send_cert_request(con, to_jid):
# the following code is partly due to pyopenssl examples # the following code is partly due to pyopenssl examples
def createKeyPair(type, bits): def createKeyPair(type_, bits):
""" """
Create a public/private key pair. Create a public/private key pair.
Arguments: type - Key type, must be one of TYPE_RSA and TYPE_DSA Arguments: type_ - Key type, must be one of TYPE_RSA and TYPE_DSA
bits - Number of bits to use in the key bits - Number of bits to use in the key
Returns: The public/private key pair in a PKey object Returns: The public/private key pair in a PKey object
""" """
pkey = crypto.PKey() pkey = crypto.PKey()
pkey.generate_key(type, bits) pkey.generate_key(type_, bits)
return pkey return pkey
def createCertRequest(pkey, digest="sha256", **name): def createCertRequest(pkey, digest="sha256", **name):
...@@ -244,7 +246,7 @@ def createCertRequest(pkey, digest="sha256", **name): ...@@ -244,7 +246,7 @@ def createCertRequest(pkey, digest="sha256", **name):
req = crypto.X509Req() req = crypto.X509Req()
subj = req.get_subject() subj = req.get_subject()
for (key,value) in name.items(): for (key, value) in name.items():