コード例 #1
0
def test_guess():
    assert kdf.key_from_password == kdf.guess(username='******',
                                              password='******',
                                              key_file=None,
                                              cert_file=None,
                                              appname='zerodb.com',
                                              key=None)

    assert kdf.key_from_cert == kdf.guess(
        username=None,
        password=None,
        key_file=ZEO.tests.testssl.client_key,
        cert_file=ZEO.tests.testssl.client_cert,
        appname='zerodb.com',
        key=None)

    assert kdf.hash_password == kdf.guess(username='******',
                                          password='******',
                                          key_file=None,
                                          cert_file=None,
                                          appname='zerodb.com',
                                          key=test_key)

    assert kdf.hash_password == kdf.guess(
        username=None,
        password=None,
        key_file=ZEO.tests.testssl.client_key,
        cert_file=ZEO.tests.testssl.client_cert,
        appname='zerodb.com',
        key=test_key)
コード例 #2
0
ファイル: test_kdf.py プロジェクト: zerodb/zerodb
def test_guess():
    assert kdf.key_from_password == kdf.guess(
            username='******', password='******',
            key_file=None, cert_file=None,
            appname='zerodb.com', key=None)

    assert kdf.key_from_cert == kdf.guess(
            username=None, password=None,
            key_file=ZEO.tests.testssl.client_key,
            cert_file=ZEO.tests.testssl.client_cert,
            appname='zerodb.com', key=None)

    assert kdf.hash_password == kdf.guess(
            username='******', password='******',
            key_file=None, cert_file=None,
            appname='zerodb.com', key=test_key)

    assert kdf.hash_password == kdf.guess(
            username=None, password=None,
            key_file=ZEO.tests.testssl.client_key,
            cert_file=ZEO.tests.testssl.client_cert,
            appname='zerodb.com', key=test_key)
コード例 #3
0
ファイル: db.py プロジェクト: zerodb/zerodb
    def __init__(
        self,
        sock,
        key=None,
        username=None,
        password=None,
        cert_file=None,
        key_file=None,
        server_cert=None,
        security=None,
        debug=False,
        pool_timeout=3600,
        pool_size=7,
        autoreindex=True,
        wait_timeout=30,
        **kw
    ):
        """
        :param str sock: UNIX (str) or TCP ((str, int)) socket
        :type sock: str or tuple
        :param str username: Username
        :param str password: Password
        :param bytes key: Encryption key

        :param cert_file: Client certificate for authentication (pem)
        :param key_file: Private key for that certificate (pem)
        :param server_cert: Server certitificate if not registered with CA

        :param function security: Key derivation function from
                                  zerodb.crypto.kdf

        :param bool debug: Whether to log debug messages
        """

        if (cert_file or key_file) and not (cert_file and key_file):
            raise TypeError("If you specify a cert file or a key file," " you must specify both.")

        ssl_context = make_ssl(cert_file, key_file, server_cert)

        if security is None:
            security = kdf.guess(username, password, key_file, cert_file, self.appname, key)

        password, key = security(username, password, key_file, cert_file, self.appname, key)

        if password:
            credentials = dict(name=username, password=password)
        else:
            credentials = None

        if isinstance(sock, six.string_types):
            sock = str(sock)
        elif type(sock) in (list, tuple):
            assert len(sock) == 2
            sock = str(sock[0]), int(sock[1])

        self._autoreindex = autoreindex
        self._reindex_queue_processor = AutoReindexQueueProcessor(self, enabled=autoreindex)
        component.provideUtility(self._reindex_queue_processor, IIndexQueueProcessor, "zerodb-indexer")

        self._init_default_crypto(key=key)

        # Store all the arguments necessary for login in this instance
        self.__storage_kwargs = {
            "sock": sock,
            "ssl": ssl_context,
            "cache_size": 2 ** 30,
            "debug": debug,
            "wait_timeout": wait_timeout,
            "credentials": credentials,
        }

        self.__db_kwargs = {
            "pool_size": pool_size,
            "pool_timeout": pool_timeout,
            "cache_size": 1000000,
            "cache_size_bytes": 100 * 2 ** 20,
        }
        self.__db_kwargs.update(kw)

        # For multi-threading
        self.__pid = os.getpid()

        self._init_db()
        self._models = {}
コード例 #4
0
ファイル: db.py プロジェクト: superwow/zerodb
    def __init__(self,
                 sock,
                 key=None,
                 username=None,
                 password=None,
                 cert_file=None,
                 key_file=None,
                 server_cert=None,
                 security=None,
                 debug=False,
                 pool_timeout=3600,
                 pool_size=7,
                 autoreindex=True,
                 wait_timeout=30,
                 **kw):
        """
        :param str sock: UNIX (str) or TCP ((str, int)) socket
        :type sock: str or tuple
        :param str username: Username
        :param str password: Password
        :param bytes key: Encryption key

        :param cert_file: Client certificate for authentication (pem)
        :param key_file: Private key for that certificate (pem)
        :param server_cert: Server certitificate if not registered with CA

        :param function security: Key derivation function from
                                  zerodb.crypto.kdf

        :param bool debug: Whether to log debug messages
        """

        if (cert_file or key_file) and not (cert_file and key_file):
            raise TypeError("If you specify a cert file or a key file,"
                            " you must specify both.")

        ssl_context = make_ssl(cert_file, key_file, server_cert)

        if security is None:
            security = kdf.guess(username, password, key_file, cert_file,
                                 self.appname, key)

        password, key = security(username, password, key_file, cert_file,
                                 self.appname, key)

        if password:
            credentials = dict(name=username, password=password)
        else:
            credentials = None

        if isinstance(sock, six.string_types):
            sock = str(sock)
        elif type(sock) in (list, tuple):
            assert len(sock) == 2
            sock = str(sock[0]), int(sock[1])

        self._autoreindex = autoreindex
        self._reindex_queue_processor = AutoReindexQueueProcessor(
            self, enabled=autoreindex)
        component.provideUtility(self._reindex_queue_processor,
                                 IIndexQueueProcessor, 'zerodb-indexer')

        self._init_default_crypto(key=key)

        # Store all the arguments necessary for login in this instance
        self.__storage_kwargs = {
            "sock": sock,
            "ssl": ssl_context,
            "cache_size": 2**30,
            "debug": debug,
            "wait_timeout": wait_timeout,
            "credentials": credentials,
        }

        self.__db_kwargs = {
            "pool_size": pool_size,
            "pool_timeout": pool_timeout,
            "cache_size": 1000000,
            "cache_size_bytes": 100 * 2**20
        }
        self.__db_kwargs.update(kw)

        # For multi-threading
        self.__pid = os.getpid()

        self._init_db()
        self._models = {}