df0dZddlZddlZddlZddlTddlmZejddkrddlm Z n ddl m Z n#e $r ddl m Z YnwxYwe jejee jejee jejee jZGddeZGd d eeZGd d eeZdS) a Peewee integration with pysqlcipher. Project page: https://github.com/leapcode/pysqlcipher/ **WARNING!!! EXPERIMENTAL!!!** * Although this extention's code is short, it has not been properly peer-reviewed yet and may have introduced vulnerabilities. Also note that this code relies on pysqlcipher and sqlcipher, and the code there might have vulnerabilities as well, but since these are widely used crypto modules, we can expect "short zero days" there. Example usage: from peewee.playground.ciphersql_ext import SqlCipherDatabase db = SqlCipherDatabase('/path/to/my.db', passphrase="don'tuseme4real") * `passphrase`: should be "long enough". Note that *length beats vocabulary* (much exponential), and even a lowercase-only passphrase like easytorememberyethardforotherstoguess packs more noise than 8 random printable characters and *can* be memorized. When opening an existing database, passphrase should be the one used when the database was created. If the passphrase is incorrect, an exception will only be raised **when you access the database**. If you need to ask for an interactive passphrase, here's example code you can put after the `db = ...` line: try: # Just access the database so that it checks the encryption. db.get_tables() # We're looking for a DatabaseError with a specific error message. except peewee.DatabaseError as e: # Check whether the message *means* "passphrase is wrong" if e.args[0] == 'file is encrypted or is not a database': raise Exception('Developer should Prompt user for passphrase ' 'again.') else: # A different DatabaseError. Raise it. raise e See a more elaborate example with this code at https://gist.github.com/thedod/11048875 N)*)SqliteExtDatabase)dbapi2c$eZdZeZdZdZdZdS)_SqlCipherDatabasecJt|j}|dddd}t j|jfddi|} |r|d|z||n#| xYw|S)N passphrase'''isolation_levelzPRAGMA key='%s') dictconnect_paramspopreplace sqlcipherconnectdatabaseexecute_add_conn_hooksclose)selfparamsr conns w/builddir/build/BUILD/imunify360-venv-2.3.5/opt/imunify360/venv/lib/python3.11/site-packages/playhouse/sqlcipher_ext.py_connectz_SqlCipherDatabase._connectFsd)**ZZ b1199#tDD  OOOOO  = .;<<<   & & & &  JJLLL  s /B B c`|std||jd<dS)NzmCannot set passphrase when database is open. To change passphrase of an open database use the rekey() method.r ) is_closedImproperlyConfiguredrrr s rset_passphrasez!_SqlCipherDatabase.set_passphraseTsE~~ P&(OPP P-7L)))c|r||d|ddz||jd<dS)NzPRAGMA rekey='%s'r r r T)rr execute_sqlrrr!s rrekeyz_SqlCipherDatabase.rekey\s] >>    LLNNN ,z/A/A#t/L/LLMMM,6L)tr#N)__name__ __module__ __qualname____sqlcipher_version__server_versionrr"r&r#rrrCsF*N   777r#rceZdZdS)SqlCipherDatabaseNr'r(r)r,r#rr.r.eDr#r.ceZdZdS)SqlCipherExtDatabaseNr/r,r#rr2r2ir0r#r2)__doc__datetimedecimalsyspeeweeplayhouse.sqlite_extr version_info pysqlcipherrr sqlcipher3 ImportError pysqlcipher3register_adapterDecimalstrdatetimesqlite_version_infor*objectrSqliteDatabaser.r2r,r#rrFs--\ 222222A!///////52222222 555444444445 7?C000 8=#... 8=#...!5D     *N        -/@     s9 AA