Ejemplo n.º 1
0
    def test_long_key(self):
        private_key_file = os.path.join(os.path.dirname(__file__), 'testfiles',
                                        'tmp', 'id_rsa_tmp')
        public_key_file = os.path.join(os.path.dirname(__file__), 'testfiles',
                                       'tmp', 'id_rsa_tmp.pub')

        logger.debug('getting key pair')
        private_key, public_key = create_new_key_pair(4096)
        with open(private_key_file, 'w') as f:
            f.write(private_key)
        with open(public_key_file, 'w') as f:
            f.write(public_key)

        port_out = self.osinteraction.get_open_port()
        out_session = Session()
        out_session.local_port = port_out
        out_session.server_session_token = None
        out_session.public_key_file = public_key_file
        out_session.private_key_file = private_key_file

        out_app = None
        try:
            out_app = start_openport_session(self, out_session)
            remote_host, remote_port, link = out_session.server, out_session.server_port, out_session.open_port_for_ip_link
            click_open_for_ip_link(link)
            print(remote_port)
            sleep(10)
            #sleep(1000)
            check_tcp_port_forward(self,
                                   remote_host=remote_host,
                                   local_port=port_out,
                                   remote_port=remote_port)
        finally:
            if out_app:
                out_app.stop()
Ejemplo n.º 2
0
    def test_forward_tunnel(self):
        port_out = self.osinteraction.get_open_port()

        out_session = Session()
        out_session.local_port = port_out
        out_session.server_session_token = None

        out_app, in_app = None, None
        try:
            out_app = start_openport_session(self, out_session)

            remote_host, remote_port, link = out_session.server, out_session.server_port, out_session.open_port_for_ip_link
            click_open_for_ip_link(link)
            check_tcp_port_forward(self, remote_host=remote_host, local_port=port_out, remote_port=remote_port)

            port_in = self.osinteraction.get_open_port()
            logger.info('port_in: %s' % port_in)

            in_session = Session()
            in_session.forward_tunnel = True
            in_session.server_port = out_session.server_port
            in_session.local_port = port_in

            in_app = start_openport_session(self, in_session)
            sleep(10)

            check_tcp_port_forward(self, remote_host='127.0.0.1', local_port=port_out, remote_port=port_in)

            port_bad_in = self.osinteraction.get_open_port()
            bad_session = Session()
            bad_session.forward_tunnel = True
            bad_session.server_port = out_session.server_port
            bad_session.local_port = port_bad_in

            keys = create_new_key_pair()
            private_key_file = 'testfiles/tmp/tmp_key'
            with open(private_key_file, 'w') as f:
                f.write(keys[0])

            public_key_file = 'testfiles/tmp/tmp_key.pub'
            with open(public_key_file, 'w') as f:
                f.write(keys[1])

            bad_session.public_key_file = public_key_file
            bad_session.private_key_file = private_key_file

            fail = False
            try:
                in_app = start_openport_session(self, bad_session)
                fail = True
            except AssertionError:
                pass
            self.assertFalse(fail)

            self.assertFalse(check_tcp_port_forward(self, remote_host='127.0.0.1', local_port=port_out, remote_port=port_bad_in, fail_on_error=False))
        finally:
            if out_app:
                out_app.stop()
            if in_app:
                in_app.stop()
Ejemplo n.º 3
0
    def test_same_port_new_key(self):

        logger.debug('getting key pair')
        private_key, public_key = create_new_key_pair()

        logger.debug('requesting port')
        dictionary = request_port(url='%s/api/v1/request-port' %
                                  self.test_server,
                                  public_key=public_key)

        response = PortForwardResponse(dictionary)

        self.assertNotEqual(None, response.open_port_for_ip_link)
        logger.debug('requesting port')
        dictionary2 = request_port(
            url='%s/api/v1/request-port' % self.test_server,
            public_key=public_key,
            restart_session_token=response.session_token,
            request_server_port=response.remote_port)

        response2 = PortForwardResponse(dictionary2)

        self.assertEqual(response2.remote_port, response.remote_port)

        logger.debug('requesting port')
        dictionary3 = request_port(url='%s/api/v1/request-port' %
                                   self.test_server,
                                   public_key=public_key,
                                   restart_session_token='not the same token',
                                   request_server_port=response.remote_port)
        response3 = PortForwardResponse(dictionary3)
        self.assertNotEqual(response3.remote_port, response.remote_port)
        logger.debug('test done')
Ejemplo n.º 4
0
    def test_new_key__not_clicking_open_for_ip_link(self):
        private_key_file = os.path.join(os.path.dirname(__file__), 'testfiles', 'tmp', 'id_rsa_tmp')
        public_key_file = os.path.join(os.path.dirname(__file__), 'testfiles', 'tmp', 'id_rsa_tmp.pub')

        logger.debug('getting key pair')
        private_key, public_key = create_new_key_pair()
        with open(private_key_file, 'w') as f:
            f.write(private_key)
        with open(public_key_file, 'w') as f:
            f.write(public_key)

        path = os.path.join(os.path.dirname(__file__), '../resources/logo-base.ico')
        self.assertTrue(os.path.exists(path), 'file does not exist %s' % path)
        share = self.get_share(path)
        share.private_key_file = private_key_file
        share.public_key_file = public_key_file
        self.app = start_openportit_session(self, share)
        self.assertTrue(share.open_port_for_ip_link)
        temp_file = os.path.join(os.path.dirname(__file__), 'testfiles', 'tmp',
                                 os.path.basename(share.filePath) + get_token(3))

        try:
            urllib.urlretrieve(share.get_link(), temp_file)
            self.fail('the download should have failed.')
        except self.failureException as e:
            raise e
        except Exception as e:
            print(e)

        click_open_for_ip_link(share.open_port_for_ip_link)

        sleep(5)
        print ('temp file: ' + temp_file)
        self.downloadAndCheckFile(share, temp_file)