Beispiel #1
0
    def get_bitmask_helper_path():
        if STANDALONE:
            return os.path.join(here(), "..", "apps", "helpers",
                                "bitmask-root")

        return pkg_resources.resource_filename(
            'leap.bitmask.vpn.helpers.linux', 'bitmask-root')
Beispiel #2
0
    def get_bitmask_polkit_policy_path():
        if STANDALONE:
            return os.path.join(here(), "..", "apps", "helpers",
                                "se.leap.bitmask.bundle.policy")

        return pkg_resources.resource_filename(
            'leap.bitmask.vpn.helpers.linux', 'se.leap.bitmask.bundle.policy')
    def _get_gpg_bin_path(self):
        """
        Return the path to gpg binary.

        :returns: the gpg binary path
        :rtype: str
        """
        gpgbin = None
        if flags.STANDALONE:
            gpgbin = os.path.join(
                get_path_prefix(), "..", "apps", "mail", "gpg")
            if IS_WIN:
                gpgbin += ".exe"
        else:
            try:
                gpgbin_options = which("gpg")
                # gnupg checks that the path to the binary is not a
                # symlink, so we need to filter those and come up with
                # just one option.
                for opt in gpgbin_options:
                    if not os.path.islink(opt):
                        gpgbin = opt
                        break
            except IndexError as e:
                logger.debug("Couldn't find the gpg binary!")
                logger.exception(e)
        if IS_MAC:
            gpgbin = os.path.abspath(
                os.path.join(here(), "apps", "mail", "gpg"))
        leap_check(gpgbin is not None, "Could not find gpg binary")
        return gpgbin
Beispiel #4
0
def fix_qtplugins_path():
    # This is a small workaround for a bug in macholib, there is a slight typo
    # in the path for the qt plugins that is added to the dynamic loader path
    # in the libs.
    if sys.platform in ('win32', 'darwin'):
        from PySide import QtCore
        plugins_path = os.path.join(os.path.dirname(here(QtCore)), 'plugins')
        QtCore.QCoreApplication.setLibraryPaths([plugins_path])
Beispiel #5
0
def fix_qtplugins_path():
    # This is a small workaround for a bug in macholib, there is a slight typo
    # in the path for the qt plugins that is added to the dynamic loader path
    # in the libs.
    if sys.platform in ('win32', 'darwin'):
        from PySide import QtCore
        plugins_path = os.path.join(os.path.dirname(here(QtCore)), 'plugins')
        QtCore.QCoreApplication.setLibraryPaths([plugins_path])
Beispiel #6
0
def uninstall_helpers():
    cmd = 'bitmask_helpers uninstall'
    if STANDALONE:
        binary_path = os.path.join(here(), "bitmask")
        cmd = "%s %s" % (binary_path, cmd)

    # TODO  check if the command has succeeded, and display error
    # if failed
    commands.getoutput('pkexec ' + cmd)
Beispiel #7
0
def get_pinned_path(domain=None, extension='.json'):
    if domain is None:
        filename = ''
    else:
        filename = domain.encode(sys.getfilesystemencoding()) + extension

    if STANDALONE:
        return os.path.join(here(), "..", "apps", "providers", filename)

    return pkg_resources.resource_filename('leap.bitmask.bonafide.providers',
                                           filename)
Beispiel #8
0
def run_bitmaskd():
    # TODO --- configure where to put the logs... (get --logfile, --logdir
    # from the bitmask_cli
    for (index, arg) in enumerate(argv):
        if arg == '--backend':
            flags.BACKEND = argv[index + 1]
    argv[1:] = [
        '-y',
        join(here(core), "bitmaskd.tac"),
        '--pidfile',
        '/tmp/bitmaskd.pid',
        '--logfile',
        '/tmp/bitmaskd.log',
        '--umask=0022',
    ]
    print '[+] launching bitmaskd...'
    run()
    def _get_gpg_bin_path(self):
        """
        Return the path to gpg binary.

        :returns: the gpg binary path
        :rtype: str
        """
        gpgbin = None
        if flags.STANDALONE:
            gpgbin = os.path.join(
                get_path_prefix(), "..", "apps", "mail", "gpg")
            if IS_WIN:
                gpgbin += ".exe"
        else:
            try:
                gpgbin_options = which("gpg")
                # gnupg checks that the path to the binary is not a
                # symlink, so we need to filter those and come up with
                # just one option.
                for opt in gpgbin_options:
                    if not os.path.islink(opt):
                        gpgbin = opt
                        break
            except IndexError as e:
                logger.debug("Couldn't find the gpg binary!")
                logger.exception(e)
        if IS_MAC:
            gpgbin = os.path.abspath(
                os.path.join(here(), "apps", "mail", "gpg"))

        # During the transition towards gpg2, we can look for /usr/bin/gpg1
        # binary, in case it was renamed using dpkg-divert or manually.
        # We could just pick gpg2, but we need to solve #7564 first.
        if gpgbin is None:
            try:
                gpgbin_options = which("gpg1")
                for opt in gpgbin_options:
                    if not os.path.islink(opt):
                        gpgbin = opt
                        break
            except IndexError as e:
                logger.debug("Couldn't find the gpg1 binary!")
                logger.exception(e)
        leap_check(gpgbin is not None, "Could not find gpg1 binary")
        return gpgbin
    def _get_gpg_bin_path(self):
        """
        Return the path to gpg binary.

        :returns: the gpg binary path
        :rtype: str
        """
        gpgbin = None
        if flags.STANDALONE:
            gpgbin = os.path.join(get_path_prefix(), "..", "apps", "mail",
                                  "gpg")
            if IS_WIN:
                gpgbin += ".exe"
        else:
            try:
                gpgbin_options = which("gpg")
                # gnupg checks that the path to the binary is not a
                # symlink, so we need to filter those and come up with
                # just one option.
                for opt in gpgbin_options:
                    if not os.path.islink(opt):
                        gpgbin = opt
                        break
            except IndexError as e:
                logger.debug("Couldn't find the gpg binary!")
                logger.exception(e)
        if IS_MAC:
            gpgbin = os.path.abspath(
                os.path.join(here(), "apps", "mail", "gpg"))

        # During the transition towards gpg2, we can look for /usr/bin/gpg1
        # binary, in case it was renamed using dpkg-divert or manually.
        # We could just pick gpg2, but we need to solve #7564 first.
        if gpgbin is None:
            try:
                gpgbin_options = which("gpg1")
                for opt in gpgbin_options:
                    if not os.path.islink(opt):
                        gpgbin = opt
                        break
            except IndexError as e:
                logger.debug("Couldn't find the gpg1 binary!")
                logger.exception(e)
        leap_check(gpgbin is not None, "Could not find gpg1 binary")
        return gpgbin
Beispiel #11
0
def _helper_installer(action):
    if action not in ('install', 'uninstall'):
        raise Exception('Wrong action: %s' % action)

    if IS_LINUX:
        cmd = 'bitmask_helpers ' + action
        if STANDALONE:
            binary_path = os.path.join(here(), "bitmask")
            cmd = "%s %s" % (binary_path, cmd)
        if os.getuid() != 0:
            cmd = 'pkexec ' + cmd
        retcode, output = commands.getstatusoutput(cmd)
        if retcode != 0:
            log.error('Error installing/uninstalling helpers: %s' % output)
            log.error('Command was: %s' % cmd)
            raise Exception('Could not install/uninstall helpers')
    else:
        raise Exception('No install mechanism for this platform')
Beispiel #12
0
def launch_gui():
    from leap.bitmask.util import STANDALONE
    systray = 'bitmask-systray'

    snap = os.environ.get('SNAP')

    if snap:
        STANDALONE = True
        _here = snap
        systray = '/snap/bin/riseup-vpn.bitmask-systray'
    else:
        _here = here()

    if STANDALONE:
        gui = os.path.join(_here, systray)
    else:
        gui = systray
    print("trying to launch: %s" % gui)
    subprocess.call([gui])
Beispiel #13
0
    def startService(self):
        if HAS_WEB_UI:
            webdir = os.path.abspath(
                pkg_resources.resource_filename('leap.bitmask_js', 'public'))
            log.debug('webdir: %s' % webdir)
        else:
            log.warn('bitmask_js not found, serving bitmask.core ui')
            webdir = os.path.abspath(
                pkg_resources.resource_filename(
                    'leap.bitmask.core.web', 'static'))
            jspath = os.path.join(
                here(), '..', '..', '..',
                'ui', 'app', 'lib', 'bitmask.js')
            jsapi = File(os.path.abspath(jspath))

        api = Api(CommandDispatcher(self._core), self._core.global_tokens)

        root = File(webdir)
        root.putChild(u'API', api)

        # XXX remove it we don't bring session tokens again
        # protected_api = protectedResourceFactory(
        # api, self._core.global_tokens, self.API_WHITELIST)
        # root.putChild(u'API', protected_api)

        if not HAS_WEB_UI:
            root.putChild('bitmask.js', jsapi)

        factory = Site(root)
        self.site = factory

        if self.onion and _has_txtorcon():
            self._start_onion_service(factory)
        else:
            interface = '127.0.0.1'
            endpoint = endpoints.TCP4ServerEndpoint(
                reactor, self.port, interface=interface)
            self.uri = 'https://%s:%s' % (interface, self.port)
            endpoint.listen(factory)

        # TODO this should be set in a callback to the listen call
        self.running = True
Beispiel #14
0
 def get_bitmask_openvpn_path():
     if STANDALONE:
         return os.path.join(here(), "..", "apps", "vpn", "openvpn.leap")