add jingle_xtls.py, get_context helper function
This commit is contained in:
parent
216c370c1f
commit
e9af72e944
2 changed files with 44 additions and 0 deletions
|
@ -93,6 +93,7 @@ class JingleFileTransfer(JingleContent):
|
|||
file_props['session-type'] = 'jingle'
|
||||
|
||||
self.use_security = bool(content.getTag('security'))
|
||||
# TODO: extract fingerprint element, encryption method element for later use
|
||||
|
||||
file_tag = content.getTag('description').getTag('offer').getTag('file')
|
||||
for attribute in file_tag.getAttrs():
|
||||
|
|
43
src/common/jingle_xtls.py
Normal file
43
src/common/jingle_xtls.py
Normal file
|
@ -0,0 +1,43 @@
|
|||
# -*- coding:utf-8 -*-
|
||||
## src/common/jingle_xtls.py
|
||||
##
|
||||
## This file is part of Gajim.
|
||||
##
|
||||
## Gajim is free software; you can redistribute it and/or modify
|
||||
## it under the terms of the GNU General Public License as published
|
||||
## by the Free Software Foundation; version 3 only.
|
||||
##
|
||||
## Gajim is distributed in the hope that it will be useful,
|
||||
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
## GNU General Public License for more details.
|
||||
##
|
||||
## You should have received a copy of the GNU General Public License
|
||||
## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
||||
##
|
||||
|
||||
import logging
|
||||
log = logging.getLogger('gajim.c.jingle_xtls')
|
||||
|
||||
PYOPENSSL_PRESENT = False
|
||||
|
||||
try:
|
||||
import OpenSSL
|
||||
PYOPENSSL_PRESENT = True
|
||||
from OpenSSL import SSL, Context
|
||||
except ImportError:
|
||||
log.info("PyOpenSSL not available")
|
||||
|
||||
def default_callback(connection, certificate, error_num, depth, return_code):
|
||||
log.info("certificate: %s" % certificate)
|
||||
return return_code
|
||||
|
||||
def get_context(fingerprint, verify_cb=None):
|
||||
"""
|
||||
constructs and returns the context objects
|
||||
"""
|
||||
ctx = SSL.Context(TLSv1_METHOD)
|
||||
ctx.set_verify(SSL.VERIFY_PEER|SSL.VERIFY_FAIL_IF_NO_PEER_CERT, verify_cb or default_callback)
|
||||
# TODO: set private key, set certificate, set verification path
|
||||
return ctx
|
||||
|
Loading…
Add table
Reference in a new issue