Example #1
0
def eigenDecompose(X):
    """
    X is 2D Hermitian or symmetric matrix
    returns  eigenvalues and eigenvectors of X 
    """
    logging.info("computing eigendecomposition...")
    s, U = eigh(X)  #Returns the eigenvalues and eigenvectors
    if (npnim(s) < -1e-4):
        common.terminate("Negative eigenvalues were found.")
    s[s < 0] = 0
    ind = argsort(s)
    ind = ind[s > 1e-12]
    U = U[:, ind]
    s = s[ind]
    return s, U
Example #2
0
                                           "1: client -> server")
        pair.validate_can_send_from_server("hello world",
                                           "1: server -> client")
        pair.validate_closing_client_closes_server(
            "1: client closed -> server closed")

        # connect to other_server, confirm that the tunnel isn't up
        try:
            pair = SocketPair(
                TcpClient(13001),
                TlsServer('other_server',
                          'other_root',
                          13002,
                          cert_reqs=ssl.CERT_NONE))
            raise Exception('failed to reject other_server')
        except ssl.SSLError:
            print_ok("other_server with unknown CA correctly rejected")

        # connect to server2, confirm that the tunnel isn't up
        try:
            pair = SocketPair(
                TcpClient(13001),
                TlsServer('server2', 'root', 13002, cert_reqs=ssl.CERT_NONE))
            raise Exception('failed to reject serve2')
        except ssl.SSLError:
            print_ok("server2 with incorrect CN correctly rejected")

        print_ok("OK")
    finally:
        terminate(ghostunnel)
        # wait for startup
        TlsClient(None, 'root', STATUS_PORT).connect(20, 'server')

        # create connections with client
        pair1 = SocketPair(
            TlsClient('client', 'root', 13001), TcpServer(13002))
        pair1.validate_can_send_from_client("toto", "pair1 works")

        # shut down ghostunnel with connection open, make sure it doesn't hang
        print_ok('attempting to terminate ghostunnel via SIGTERM signals')
        for n in range(0, 90):
            try:
                try:
                    ghostunnel.terminate()
                    ghostunnel.wait(timeout=1)
                except BaseException:
                    pass
                os.kill(ghostunnel.pid, 0)
                print_ok("ghostunnel is still alive")
            except BaseException:
                stopped = True
                break
            time.sleep(1)

        if not stopped:
            raise Exception('ghostunnel did not terminate within 90 seconds')

        print_ok("OK (terminated)")
    finally:
        terminate(ghostunnel)
            '--disable-authentication', '--allow-cn=test.example.com',
            '--cacert=root.crt'
        ])
        assert_not_zero(ghostunnel1)

        ghostunnel2 = run_ghostunnel([
            'server', '--listen={0}:13001'.format(LOCALHOST),
            '--target={0}:13002'.format(LOCALHOST), '--keystore=server.p12',
            '--cert=server.crt', '--key=server.key', '--cacert=root.crt'
        ])
        assert_not_zero(ghostunnel2)

        ghostunnel3 = run_ghostunnel([
            'server', '--listen={0}:13001'.format(LOCALHOST),
            '--target={0}:13002'.format(LOCALHOST), '--cert=server.crt',
            '--cacert=root.crt'
        ])
        assert_not_zero(ghostunnel3)

        ghostunnel4 = run_ghostunnel([
            'server', '--listen={0}:13001'.format(LOCALHOST),
            '--target={0}:13002'.format(LOCALHOST), '--key=server.crt',
            '--cacert=root.crt'
        ])
        assert_not_zero(ghostunnel4)
    finally:
        terminate(ghostunnel1)
        terminate(ghostunnel2)
        terminate(ghostunnel3)
        terminate(ghostunnel4)