Ejemplo n.º 1
0
    def handle_socks_args(self, args):
        """
        Receive arguments `args' passed over a SOCKS connection.

        The SOCKS authentication mechanism is (ab)used to pass arguments to
        pluggable transports.  This method receives these arguments and parses
        them.  As argument, we only expect a UniformDH shared secret.
        """

        log.debug("Received the following arguments over SOCKS: %s." % args)

        if len(args) != 1:
            raise base.SOCKSArgsError("Too many SOCKS arguments "
                                      "(expected 1 but got %d)." % len(args))

        # The ScrambleSuit specification defines that the shared secret is
        # called "password".
        if not args[0].startswith("password="******"The SOCKS argument must start with "
                                      "`password='******'=')[1].strip()))
        except TypeError as error:
            log.error(error.message)
            raise base.PluggableTransportError("Given password '%s' is not " \
                    "valid Base32!  Run 'generate_password.py' to generate " \
                    "a good password." % args[0].split('=')[1].strip())

        rawLength = len(self.uniformDHSecret)
        if rawLength != const.SHARED_SECRET_LENGTH:
            raise base.PluggableTransportError(
                "The UniformDH password "
                "must be %d bytes in length but %d bytes are given." %
                (const.SHARED_SECRET_LENGTH, rawLength))

        self.uniformdh = uniformdh.new(self.uniformDHSecret, self.weAreServer)
Ejemplo n.º 2
0
    def handle_socks_args(self, args):
        log.debug("obfs2: Got '%s' as SOCKS arguments." % args)

        # A shared secret might already be set if obfsproxy is in
        # external-mode and both a cli shared-secret was specified
        # _and_ a SOCKS per-connection shared secret.
        if self.shared_secret:
            log.notice("obfs2: Hm. Weird configuration. A shared secret "
                       "was specified twice. I will keep the one "
                       "supplied by the SOCKS arguments.")

        if len(args) != 1:
            err_msg = "obfs2: Too many SOCKS arguments (%d) (%s)" % (len(args), str(args))
            log.warning(err_msg)
            raise base.SOCKSArgsError(err_msg)

        if not args[0].startswith("shared-secret="):
            err_msg = "obfs2: SOCKS arg is not correctly formatted  (%s)" % args[0]
            log.warning(err_msg)
            raise base.SOCKSArgsError(err_msg)

        self.shared_secret = args[0][14:]