コード例 #1
0
ファイル: controller.py プロジェクト: eoinof/stem
 def test_getconf(self):
   """
   Exercises GETCONF with valid and invalid queries.
   """
   
   if test.runner.require_control(self): return
   
   runner = test.runner.get_runner()
   
   with runner.get_tor_controller() as controller:
     socket = controller.get_socket()
     if isinstance(socket, stem.socket.ControlPort):
       connection_value = str(socket.get_port())
       config_key = "ControlPort"
     elif isinstance(socket, stem.socket.ControlSocketFile):
       connection_value = str(socket.get_socket_path())
       config_key = "ControlSocket"
     
     # successful single query
     self.assertEqual(connection_value, controller.get_conf(config_key))
     self.assertEqual(connection_value, controller.get_conf(config_key, "la-di-dah"))
     
     # succeessful batch query
     expected = {config_key: [connection_value]}
     self.assertEqual(expected, controller.get_conf_map([config_key]))
     self.assertEqual(expected, controller.get_conf_map([config_key], "la-di-dah"))
     
     request_params = ["ControlPORT", "dirport", "datadirectory"]
     reply_params = controller.get_conf_map(request_params, multiple=False).keys()
     self.assertEqual(set(request_params), set(reply_params))
     
     # non-existant option(s)
     self.assertRaises(stem.socket.InvalidArguments, controller.get_conf, "blarg")
     self.assertEqual("la-di-dah", controller.get_conf("blarg", "la-di-dah"))
     self.assertRaises(stem.socket.InvalidArguments, controller.get_conf_map, "blarg")
     self.assertEqual("la-di-dah", controller.get_conf_map("blarg", "la-di-dah"))
     
     self.assertRaises(stem.socket.InvalidRequest, controller.get_conf_map, ["blarg", "huadf"], multiple = True)
     self.assertEqual("la-di-dah", controller.get_conf_map(["erfusdj", "afiafj"], "la-di-dah", multiple = True))
     
     # multivalue configuration keys
     nodefamilies = [("abc", "xyz", "pqrs"), ("mno", "tuv", "wxyz")]
     controller.msg("SETCONF %s" % " ".join(["nodefamily=\"" + ",".join(x) + "\"" for x in nodefamilies]))
     self.assertEqual([",".join(n) for n in nodefamilies], controller.get_conf("nodefamily", multiple = True))
     controller.msg("RESETCONF NodeFamily")
     
     # empty input
     self.assertEqual(None, controller.get_conf(""))
     self.assertEqual({}, controller.get_conf_map([]))
     self.assertEqual({}, controller.get_conf_map([""]))
     self.assertEqual(None, controller.get_conf("          "))
     self.assertEqual({}, controller.get_conf_map(["    ", "        "]))
     
     self.assertEqual("la-di-dah", controller.get_conf("", "la-di-dah"))
     self.assertEqual({}, controller.get_conf_map("", "la-di-dah"))
     self.assertEqual({}, controller.get_conf_map([], "la-di-dah"))
コード例 #2
0
from subprocess import Popen
from common import *
import socket, ssl, tempfile, os, os.path

if __name__ == "__main__":
    ghostunnel = None
    try:
        # create certs
        root = RootCert('root')
        root.create_signed_cert('server')
        root.create_signed_cert('client')

        # start ghostunnel
        socket = UnixClient()
        ghostunnel = run_ghostunnel([
            'client', '--listen=unix:{0}'.format(socket.get_socket_path()),
            '--target={0}:13002'.format(LOCALHOST), '--keystore=client.p12',
            '--cacert=root.crt',
            '--status={0}:{1}'.format(LOCALHOST, STATUS_PORT)
        ])

        # connect with client, confirm that the tunnel is up
        pair = SocketPair(socket, TlsServer('server', 'root', 13002))
        pair.validate_can_send_from_server("hello world",
                                           "1: server -> client")
        pair.validate_can_send_from_client("hello world",
                                           "1: client -> server")
        pair.validate_closing_server_closes_client(
            "1: server closed -> client closed")

        print_ok("OK")
コード例 #3
0
from common import *
import socket, ssl, tempfile, os

if __name__ == "__main__":
    ghostunnel = None
    try:
        # create certs
        root = RootCert('root')
        root.create_signed_cert('server')
        root.create_signed_cert('client')

        # start ghostunnel
        socket = UnixServer()
        ghostunnel = run_ghostunnel([
            'server', '--listen={0}:13001'.format(LOCALHOST),
            '--target=unix:{0}'.format(socket.get_socket_path()),
            '--keystore=server.p12', '--cacert=root.crt', '--allow-ou=client',
            '--status={0}:{1}'.format(LOCALHOST, STATUS_PORT)
        ])

        # connect with client, confirm that the tunnel is up
        pair = SocketPair(TlsClient('client', 'root', 13001), socket)
        pair.validate_can_send_from_server("hello world",
                                           "1: server -> client")
        pair.validate_can_send_from_client("hello world",
                                           "1: client -> server")
        pair.validate_closing_server_closes_client(
            "1: server closed -> client closed")

        print_ok("OK")
    finally:
コード例 #4
0
from subprocess import Popen
from common import *
import socket, ssl, tempfile, os, os.path

if __name__ == "__main__":
  ghostunnel = None
  try:
    # create certs
    root = RootCert('root')
    root.create_signed_cert('server')
    root.create_signed_cert('client')

    # start ghostunnel
    socket = UnixClient()
    ghostunnel = run_ghostunnel(['client', '--listen=unix:{0}'.format(socket.get_socket_path()),
      '--target={0}:13002'.format(LOCALHOST), '--keystore=client.p12',
      '--cacert=root.crt', '--status={0}:{1}'.format(LOCALHOST, STATUS_PORT)])

    # connect with client, confirm that the tunnel is up
    pair = SocketPair(socket, TlsServer('server', 'root', 13002))
    pair.validate_can_send_from_server("hello world", "1: server -> client")
    pair.validate_can_send_from_client("hello world", "1: client -> server")
    pair.validate_closing_server_closes_client("1: server closed -> client closed")

    print_ok("OK")
  finally:
    terminate(ghostunnel)
    if os.path.exists(socket.get_socket_path()):
      raise Exception('failed to clean up unix socket')
コード例 #5
0
import socket
import os
import os.path

if __name__ == "__main__":
    ghostunnel = None
    try:
        # create certs
        root = RootCert('root')
        root.create_signed_cert('server')
        root.create_signed_cert('client')

        # start ghostunnel
        socket = UnixClient()
        ghostunnel = run_ghostunnel(['client',
                                     '--listen=unix:{0}'.format(socket.get_socket_path()),
                                     '--target={0}:13002'.format(LOCALHOST),
                                     '--keystore=client.p12',
                                     '--cacert=root.crt',
                                     '--status={0}:{1}'.format(LOCALHOST,
                                                               STATUS_PORT)])

        # connect with client, confirm that the tunnel is up
        pair = SocketPair(socket, TlsServer('server', 'root', 13002))
        pair.validate_can_send_from_server(
            "hello world", "1: server -> client")
        pair.validate_can_send_from_client(
            "hello world", "1: client -> server")
        pair.validate_closing_server_closes_client(
            "1: server closed -> client closed")
コード例 #6
0
# Creates a ghostunnel. Ensures ghostunnel can connect to a unix socket.

from subprocess import Popen
from test_common import RootCert, LOCALHOST, STATUS_PORT, SocketPair, print_ok, TlsClient, UnixServer
import socket, ssl, tempfile, os

if __name__ == "__main__":
  ghostunnel = None
  try:
    # create certs
    root = RootCert('root')
    root.create_signed_cert('server')
    root.create_signed_cert('client')

    # start ghostunnel
    socket = UnixServer()
    ghostunnel = Popen(['../ghostunnel', 'server', '--listen={0}:13001'.format(LOCALHOST),
      '--target=unix:{0}'.format(socket.get_socket_path()), '--keystore=server.p12',
      '--cacert=root.crt', '--allow-ou=client', '--status={0}:{1}'.format(LOCALHOST, STATUS_PORT)])

    # connect with client, confirm that the tunnel is up
    pair = SocketPair(TlsClient('client', 'root', 13001), socket)
    pair.validate_can_send_from_server("hello world", "1: server -> client")
    pair.validate_can_send_from_client("hello world", "1: client -> server")
    pair.validate_closing_server_closes_client("1: server closed -> client closed")

    print_ok("OK")
  finally:
    if ghostunnel:
      ghostunnel.kill()
コード例 #7
0
from subprocess import Popen
from test_common import RootCert, LOCALHOST, STATUS_PORT, SocketPair, print_ok, TlsServer, UnixClient
import socket, ssl, tempfile, os

if __name__ == "__main__":
  ghostunnel = None
  try:
    # create certs
    root = RootCert('root')
    root.create_signed_cert('server')
    root.create_signed_cert('client')

    # start ghostunnel
    socket = UnixClient()
    ghostunnel = Popen(['../ghostunnel', 'client', '--listen=unix:{0}'.format(socket.get_socket_path()),
      '--target={0}:13005'.format(LOCALHOST), '--keystore=client.p12',
      '--cacert=root.crt', '--status={0}:{1}'.format(LOCALHOST, STATUS_PORT)])

    # connect with client, confirm that the tunnel is up
    pair = SocketPair(socket, TlsServer('server', 'root', 13005))

    pair.validate_can_send_from_server("hello world", "1: server -> client")
    pair.validate_can_send_from_client("hello world", "1: client -> server")
    pair.validate_closing_server_closes_client("1: server closed -> client closed")

    print_ok("OK")
  finally:
    if ghostunnel:
      ghostunnel.kill()