Skip to content

Commit

Permalink
Cycle passwords across sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
Vishal Gowda committed Mar 9, 2017
1 parent d4caf99 commit b127b57
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 11 deletions.
1 change: 1 addition & 0 deletions hedroid/master/droid_keeper.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ struct DroidRequest {
struct ConnParams {
1: string host,
2: string port,
3: optional string password,
}

exception ApplicationException {
Expand Down
15 changes: 14 additions & 1 deletion hedroid/master/tgen/droid_keeper/ttypes.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions hedroid/master/thrift_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def get_endpoint_for_user(self, user):
cpars = ConnParams()
cpars.host = endpoint_cpars.host
cpars.port = endpoint_cpars.port
cpars.password = endpoint_cpars.password
return cpars

def interact_with_endpoint(self, dr):
Expand Down
1 change: 1 addition & 0 deletions hedroid/worker/droid_service.thrift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
struct ConnParams {
1: string host,
2: string port,
3: optional string password,
}

exception ApplicationException {
Expand Down
12 changes: 10 additions & 2 deletions hedroid/worker/helpers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import os

from hedroid.common_settings import DEBUG
from hedroid.worker.zk_droid import DroidZkClient
from hedroid.worker.utils import restart_adb_server
from hedroid.worker.utils import restart_adb_server, generate_password
from hedroid.logger import logger
from hedroid.worker.xvfb import Xvfb
from hedroid.worker.emulator import Emulator
Expand Down Expand Up @@ -50,7 +51,10 @@ def stop(self):

def cleanup(self):
logger.debug('Cleaning up droid')
# Cleanup emulator
self.emulator.cleanup()
# Cycle password for vnc server
self.x11vnc.cycle_password()


class DroidBuilder(object):
Expand Down Expand Up @@ -105,6 +109,7 @@ def build(self):
x11vnc = X11VNC(
display=self.display,
clip=self.clip,
password=generate_password(),
)
websockify = Websockify(
source_port=self.ws_port,
Expand Down Expand Up @@ -146,7 +151,10 @@ def setup(self):
except IndexError:
break
except Exception as err:
import ipdb; ipdb.set_trace()
print err
if DEBUG:
import ipdb
ipdb.set_trace()

def count(self):
return len(self.initialised)
Expand Down
15 changes: 14 additions & 1 deletion hedroid/worker/tgen/droid_service/ttypes.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions hedroid/worker/thrift_server.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os
import atexit

import requests
import shutil

from hedroid.logger import logger
Expand All @@ -10,7 +9,8 @@
from hedroid.worker.utils import get_package_name_from_url
from hedroid.common_settings import VAR_DIR

from hedroid.worker.tgen.droid_service.ttypes import ConnParams, ApplicationException
from hedroid.worker.tgen.droid_service.ttypes import ConnParams
from hedroid.worker.tgen.droid_service.ttypes import ApplicationException
from hedroid.worker.tgen.droid_service import DroidService

from thrift.transport import TSocket
Expand Down Expand Up @@ -66,6 +66,7 @@ def get_endpoint(self, endpoint_id):
cp = ConnParams()
cp.host = get_public_hostname()
cp.port = endpoint.websockify.source_port
cp.password = endpoint.x11vnc.password
return cp

def run_operation(self, endpoint_id, operation, apk_url):
Expand Down Expand Up @@ -111,5 +112,6 @@ def start_server():
handler.pre_server_start_log()
server.serve()


if __name__ == '__main__':
start_server()
9 changes: 8 additions & 1 deletion hedroid/worker/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
import json
import os
import socket
import uuid
from copy import deepcopy
from tempfile import NamedTemporaryFile

import requests
from requests.exceptions import ConnectTimeout
import subprocess32 as subprocess

from hedroid.common_settings import CONFIG_PATH, HOSTNAME
from hedroid.common_settings import CONFIG_PATH, HOSTNAME, DEBUG
from hedroid.logger import logger


Expand Down Expand Up @@ -123,5 +124,11 @@ def get_config():
return deepcopy(CachedGlobals.CONFIG)


def generate_password():
if DEBUG:
return "youknowthis"
return uuid.uuid4().hex


if __name__ == '__main__':
print is_open_port(5672)
26 changes: 22 additions & 4 deletions hedroid/worker/vnc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
from hedroid.logger import logger
from hedroid.common_settings import VAR_DIR
from hedroid.worker.executor import Executor
from hedroid.worker.utils import generate_password


class X11VNCExecutor(Executor):
def __init__(self, display, rfb_port, clip):
def __init__(self, display, rfb_port, clip, password):
super(X11VNCExecutor, self).__init__(display)
self.display = display
self.rfb_port = rfb_port
self.clip = clip
self.password = password

self._portfile_p = os.path.join(VAR_DIR, "vnc-port-{}".format(display))

Expand All @@ -33,8 +35,10 @@ def portfile_wait(self):
def _start(self):
cmd = ["x11vnc", "-forever", "-rfbport", str(self.rfb_port),
"-display", ":{}".format(self.display),
"-noxdamage", "-xkb", "-noscr",
"-noxfixes", "-nowf", "-ncache", "10",
"-clip", self.clip, "-flag", self._portfile_p]
"-clip", self.clip, "-flag", self._portfile_p,
"-passwd", self.password]
# Remove portfile if it previously exists
try:
os.remove(self._portfile_p)
Expand All @@ -60,9 +64,10 @@ def stop(self):


class X11VNC(object):
def __init__(self, display=None, clip=None):
def __init__(self, display=None, clip=None, password="youknowthis"):
self.display = display or os.environ.get('DISPLAY_PORT', '1')
self.clip = clip or '530x965+15+30'
self.password = password

self.executor = None

Expand All @@ -72,10 +77,23 @@ def get_rfbport(self):
def start(self):
logger.debug('Starting X11VNC')

self.executor = X11VNCExecutor(self.display, self.get_rfbport(), self.clip)
self.executor = X11VNCExecutor(
self.display, self.get_rfbport(), self.clip, self.password)
self.executor.start()
logger.debug('X11VNC Ready!')

def cycle_password(self):
logger.debug('Cycling passwords for x11vnc')
# Set new password
self.password = generate_password()
# Stop the server
self.executor.stop()
self.executor = X11VNCExecutor(
self.display, self.get_rfbport(), self.clip, self.password)
# Start the server again
self.executor.start()
logger.debug('Password cycle complete!')

def stop(self):
logger.debug('Stopping X11VNC')
self.executor.stop()
Expand Down

0 comments on commit b127b57

Please sign in to comment.