handle cert path more commonly
This commit is contained in:
parent
fb41b65368
commit
b6d746115d
|
@ -268,8 +268,8 @@ def check_and_possibly_create_paths():
|
|||
MY_DATA = configpaths.gajimpaths['MY_DATA']
|
||||
MY_CONFIG = configpaths.gajimpaths['MY_CONFIG']
|
||||
MY_CACHE = configpaths.gajimpaths['MY_CACHE']
|
||||
XTLS_CERTS = os.path.expanduser(jingle_xtls.CERTIFICATE_DIR)
|
||||
LOCAL_XTLS_CERTS = os.path.expanduser(jingle_xtls.LOCAL_CERT_DIR)
|
||||
XTLS_CERTS = configpaths.gajimpaths['MY_PEER_CERTS']
|
||||
LOCAL_XTLS_CERTS = configpaths.gajimpaths['MY_CERT']
|
||||
|
||||
if not os.path.exists(MY_DATA):
|
||||
create_path(MY_DATA)
|
||||
|
@ -338,9 +338,13 @@ def check_and_possibly_create_paths():
|
|||
|
||||
if not os.path.exists(XTLS_CERTS):
|
||||
create_path(XTLS_CERTS)
|
||||
if not (os.path.exists(os.path.join(LOCAL_XTLS_CERTS, jingle_xtls.SELF_SIGNED_CERTIFICATE + '.cert')) and
|
||||
os.path.exists(os.path.join(LOCAL_XTLS_CERTS, jingle_xtls.SELF_SIGNED_CERTIFICATE + '.pkey'))):
|
||||
jingle_xtls.make_certs(os.path.join(LOCAL_XTLS_CERTS, jingle_xtls.SELF_SIGNED_CERTIFICATE), 'gajim')
|
||||
if not os.path.exists(LOCAL_XTLS_CERTS):
|
||||
create_path(LOCAL_XTLS_CERTS)
|
||||
cert_name = os.path.join(LOCAL_XTLS_CERTS,
|
||||
jingle_xtls.SELF_SIGNED_CERTIFICATE)
|
||||
if not (os.path.exists(cert_name + '.cert') and os.path.exists(
|
||||
cert_name + '.pkey')):
|
||||
jingle_xtls.make_certs(cert_name, 'gajim')
|
||||
|
||||
|
||||
def create_path(directory):
|
||||
|
|
|
@ -84,10 +84,12 @@ MY_ICONSETS_PATH = gajimpaths['MY_ICONSETS']
|
|||
MY_MOOD_ICONSETS_PATH = gajimpaths['MY_MOOD_ICONSETS']
|
||||
MY_ACTIVITY_ICONSETS_PATH = gajimpaths['MY_ACTIVITY_ICONSETS']
|
||||
MY_CACERTS = gajimpaths['MY_CACERTS']
|
||||
MY_PEER_CERTS_PATH = gajimpaths['MY_PEER_CERTS']
|
||||
TMP = gajimpaths['TMP']
|
||||
DATA_DIR = gajimpaths['DATA']
|
||||
ICONS_DIR = gajimpaths['ICONS']
|
||||
HOME_DIR = gajimpaths['HOME']
|
||||
MY_CERT_DIR = gajimpaths['MY_CERT']
|
||||
|
||||
try:
|
||||
LANG = locale.getdefaultlocale()[0] # en_US, fr_FR, el_GR etc..
|
||||
|
|
|
@ -20,12 +20,9 @@ import os
|
|||
|
||||
import logging
|
||||
import common
|
||||
import gajim
|
||||
from common import gajim
|
||||
log = logging.getLogger('gajim.c.jingle_xtls')
|
||||
|
||||
from common import configpaths
|
||||
gajimpath = configpaths.gajimpaths
|
||||
|
||||
PYOPENSSL_PRESENT = False
|
||||
|
||||
pending_sessions = {} # key-exchange id -> session, accept that session once key-exchange completes
|
||||
|
@ -49,10 +46,6 @@ if PYOPENSSL_PRESENT:
|
|||
from OpenSSL.SSL import Context
|
||||
from OpenSSL import crypto
|
||||
|
||||
CERTIFICATE_DIR = gajimpath['MY_PEER_CERTS']
|
||||
LOCAL_CERT_DIR = gajimpath['MY_CERT']
|
||||
print 'CERTIFICATE_DIR: ', CERTIFICATE_DIR
|
||||
print 'MY_CERT_DIR: ', LOCAL_CERT_DIR
|
||||
SELF_SIGNED_CERTIFICATE = 'localcert'
|
||||
|
||||
def default_callback(connection, certificate, error_num, depth, return_code):
|
||||
|
@ -103,16 +96,17 @@ def get_context(fingerprint, verify_cb=None):
|
|||
elif fingerprint == 'client':
|
||||
ctx.set_verify(SSL.VERIFY_PEER, verify_cb or default_callback)
|
||||
|
||||
ctx.use_privatekey_file (os.path.expanduser(os.path.join(LOCAL_CERT_DIR, SELF_SIGNED_CERTIFICATE) + '.pkey'))
|
||||
ctx.use_certificate_file(os.path.expanduser(os.path.join(LOCAL_CERT_DIR, SELF_SIGNED_CERTIFICATE) + '.cert'))
|
||||
cert_name = os.path.join(gajim.MY_CERT_DIR, SELF_SIGNED_CERTIFICATE)
|
||||
ctx.use_privatekey_file (cert_name + '.pkey')
|
||||
ctx.use_certificate_file(cert_name + '.cert')
|
||||
store = ctx.get_cert_store()
|
||||
for f in os.listdir(os.path.expanduser(CERTIFICATE_DIR)):
|
||||
load_cert_file(os.path.join(os.path.expanduser(CERTIFICATE_DIR), f), store)
|
||||
for f in os.listdir(os.path.expanduser(gajim.MY_PEER_CERTS_PATH)):
|
||||
load_cert_file(os.path.join(os.path.expanduser(gajim.MY_PEER_CERTS_PATH), f), store)
|
||||
print 'certificate file' + f + ' loaded', 'fingerprint', fingerprint
|
||||
return ctx
|
||||
|
||||
def send_cert(con, jid_from, sid):
|
||||
certpath = os.path.expanduser(os.path.join(LOCAL_CERT_DIR, SELF_SIGNED_CERTIFICATE) + '.cert')
|
||||
certpath = os.path.join(gajim.MY_CERT_DIR, SELF_SIGNED_CERTIFICATE) + '.cert'
|
||||
certfile = open(certpath, 'r')
|
||||
certificate = ''
|
||||
for line in certfile.readlines():
|
||||
|
@ -134,7 +128,7 @@ def send_cert(con, jid_from, sid):
|
|||
|
||||
def handle_new_cert(con, obj, jid_from):
|
||||
jid = gajim.get_jid_without_resource(jid_from)
|
||||
certpath = os.path.join(os.path.expanduser(CERTIFICATE_DIR), jid)
|
||||
certpath = os.path.join(os.path.expanduser(gajim.MY_PEER_CERTS_PATH), jid)
|
||||
certpath += '.cert'
|
||||
|
||||
id = obj.getAttr('id')
|
||||
|
|
Loading…
Reference in New Issue