Ejemplo n.º 1
0
    def __init__(self, filename, realm=None):
        """
        :param str filename: Config file with users and their password hashes
        :param str realm: ZODB's default permissions realm
        """
        self.storage_filename = path.splitext(filename)[0] + ".db"
        self.storage = FileStorage.FileStorage(self.storage_filename)
        self.db = ZODB.DB(self.storage)
        self.db_conn = self.db.open()
        self.db_root = self.db_conn.root()
        root = self.db_root
        with transaction.manager:
            if not "users" in root:
                root["users"] = IdStore()  # uid -> user
            if not "usernames" in root:
                root["usernames"] = self.family.OI.BTree()  # username -> uid

        self.filename = filename
        self.load()

        # Frankly speaking, this realm-based security is questionable
        # Keep it here for now
        if realm:
            if self.realm and self.realm != realm:
                raise ValueError("Specified realm %r differs from database "
                                 "realm %r" % (realm or '', self.realm))
            else:
                self.realm = realm

        self.noncekey = rand(32)
Ejemplo n.º 2
0
    def __init__(self, filename, realm=None):
        """
        :param str filename: Config file with users and their password hashes
        :param str realm: ZODB's default permissions realm
        """
        self.storage_filename = path.splitext(filename)[0] + ".db"
        self.storage = FileStorage.FileStorage(self.storage_filename)
        self.db = ZODB.DB(self.storage)
        self.db_conn = self.db.open()
        self.db_root = self.db_conn.root()
        root = self.db_root
        with transaction.manager:
            if not "users" in root:
                root["users"] = IdStore()  # uid -> user
            if not "usernames" in root:
                root["usernames"] = self.family.OI.BTree()  # username -> uid

        self.filename = filename
        self.load()

        # Frankly speaking, this realm-based security is questionable
        # Keep it here for now
        if realm:
            if self.realm and self.realm != realm:
                raise ValueError("Specified realm %r differs from database "
                                 "realm %r" % (realm or '', self.realm))
            else:
                self.realm = realm

        self.noncekey = rand(32)
Ejemplo n.º 3
0
def test_aes_rand():
    key = rand(32)

    cipher1 = AES(key=key)
    ciphertext = cipher1.encrypt(TEST_TEXT)

    cipher2 = AES(key=key)
    assert cipher2.decrypt(ciphertext) == TEST_TEXT
Ejemplo n.º 4
0
 def _encrypt(self, data):
     """
     :param str data: Data to encrypt
     :return: Encrypted data with hash inside and IV outside
     :rtype: str
     """
     iv = rand(self.iv_size)
     cipher = AES.new(self.key, self.mode, iv)
     h = sha256(data).digest()
     return cipher.encrypt(data + h) + iv
Ejemplo n.º 5
0
 def auth_get_challenge(self):
     """Return realm, challenge, and nonce."""
     self._challenge = rand(32)
     self._key_nonce = self._get_nonce()
     return self.auth_realm, self._challenge, self._key_nonce
Ejemplo n.º 6
0
 def auth_get_challenge(self):
     """Return realm, challenge, and nonce."""
     self._challenge = rand(32)
     self._key_nonce = self._get_nonce()
     return self.auth_realm, self._challenge, self._key_nonce