<commit_before>from __future__ import absolute_import,unicode_literals

import os
import ssl
import socket
import logging

logger = logging.getLogger(__name__)

import synapse.compat as s_compat
import synapse.lib.socket as s_socket

from synapse.links.common import *

class SslRelay(LinkRelay):

    proto = 'ssl'

    def _reqValidLink(self):
        host = self.link[1].get('host')
        port = self.link[1].get('port')

        if host == None:
            raise PropNotFound('host')

        if port == None:
            raise PropNotFound('port')

        cafile = self.link[1].get('cafile')
        if cafile != None and not os.path.isfile(cafile):
            raise NoSuchFile(cafile)

        keyfile = self.link[1].get('keyfile')
        if keyfile != None and not os.path.isfile(keyfile):
            raise NoSuchFile(keyfile)

        certfile = self.link[1].get('certfile')
        if certfile != None and not os.path.isfile(certfile):
            raise NoSuchFile(certfile)

    def _listen(self):

        host = self.link[1].get('host')
        port = self.link[1].get('port')

        sock = socket.socket()
        sock.bind( (host,port) )

        sock.listen(100)

        self.link[1]['port'] = sock.getsockname()[1]

        cafile = self.link[1].get('cafile')
        keyfile = self.link[1].get('keyfile')
        certfile = self.link[1].get('certfile')

        sslopts = dict(server_side=True,
                       ca_certs=cafile,
                       keyfile=keyfile,
                       certfile=certfile,
                       cert_reqs=ssl.CERT_NONE,
                       do_handshake_on_connect=False,
                       ssl_version=ssl.PROTOCOL_TLSv1,
                  )

        # if they give a cafile to the server, require client certs
        if cafile != None:
            sslopts['cert_reqs'] = ssl.CERT_REQUIRED

        wrap = ssl.wrap_socket(sock, **sslopts)<commit_msg>allow relative and userdir based paths in ssl link proto<commit_after>from __future__ import absolute_import,unicode_literals

import os
import ssl
import socket
import logging

logger = logging.getLogger(__name__)

import synapse.compat as s_compat
import synapse.lib.socket as s_socket

from synapse.links.common import *

class SslRelay(LinkRelay):

    proto = 'ssl'

    def _reqValidLink(self):
        host = self.link[1].get('host')
        port = self.link[1].get('port')

        if host == None:
            raise PropNotFound('host')

        if port == None:
            raise PropNotFound('port')

        cafile = self.link[1].get('cafile')
        if cafile != None:
            self.link[1]['cafile'] = reqpath(cafile)

        keyfile = self.link[1].get('keyfile')
        if keyfile != None:
            self.link[1]['keyfile'] = reqpath(keyfile)

        certfile = self.link[1].get('certfile')
        if certfile != None:
            self.link[1]['certfile'] = reqpath(certfile)

    def _listen(self):

        host = self.link[1].get('host')
        port = self.link[1].get('port')

        sock = socket.socket()
        sock.bind( (host,port) )

        sock.listen(100)

        self.link[1]['port'] = sock.getsockname()[1]

        cafile = self.link[1].get('cafile')
        keyfile = self.link[1].get('keyfile')
        certfile = self.link[1].get('certfile')

        sslopts = dict(server_side=True,
                       ca_certs=cafile,
                       keyfile=keyfile,
                       certfile=certfile,
                       cert_reqs=ssl.CERT_NONE,
                       do_handshake_on_connect=False,
                       ssl_version=ssl.PROTOCOL_TLSv1,
                  )

        # if they give a cafile to the server, require client certs
        if cafile != None:
            sslopts['cert_reqs'] = ssl.CERT_REQUIRED

        wrap = ssl.wrap_socket(sock, **sslopts)
{'fraction_non_alphanumeric': 0.11715914981855884, 'fraction_numerical': 0.009072058061171591, 'mean_word_length': 2.0457774269928968, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '471738', 'n_tokens_mistral': 1217, 'n_tokens_neox': 1175, 'n_words': 241}