diff --git a/libsql-ffi/build.rs b/libsql-ffi/build.rs index c3c5beb0c4..45f33c47a5 100644 --- a/libsql-ffi/build.rs +++ b/libsql-ffi/build.rs @@ -494,7 +494,7 @@ fn build_multiple_ciphers(out_path: &Path) -> PathBuf { if cfg!(feature = "wasmtime-bindings") { config.define("LIBSQL_ENABLE_WASM_RUNTIME", "1"); } - config.define("LIBSQL_ENCRYPTION", "1"); + config.define("LIBSQL_EXTRA_URI_PARAMS", "1"); if cfg!(feature = "session") { config diff --git a/libsql-ffi/bundled/SQLite3MultipleCiphers/CMakeLists.txt b/libsql-ffi/bundled/SQLite3MultipleCiphers/CMakeLists.txt index e178589249..07eeed2276 100644 --- a/libsql-ffi/bundled/SQLite3MultipleCiphers/CMakeLists.txt +++ b/libsql-ffi/bundled/SQLite3MultipleCiphers/CMakeLists.txt @@ -124,7 +124,7 @@ set(SQLITE3MC_BASE_DEFINITIONS $<$:LIBSQL_ENABLE_WASM_RUNTIME=1> LIBSQL_EXTRA_PRAGMAS=1 LIBSQL_CUSTOM_PAGER_CODEC=1 - LIBSQL_ENCRYPTION=1 + LIBSQL_EXTRA_URI_PARAMS=1 SQLITE_ENABLE_DBSTAT_VTAB=1 SQLITE_ENABLE_DBPAGE_VTAB=1 diff --git a/libsql-ffi/bundled/SQLite3MultipleCiphers/src/cipher_config.c b/libsql-ffi/bundled/SQLite3MultipleCiphers/src/cipher_config.c index 6937968d7b..0dfd6cd329 100644 --- a/libsql-ffi/bundled/SQLite3MultipleCiphers/src/cipher_config.c +++ b/libsql-ffi/bundled/SQLite3MultipleCiphers/src/cipher_config.c @@ -1167,3 +1167,11 @@ sqlite3mcHandleMainKey(sqlite3* db, const char* zPath) } return rc; } + +int libsql_handle_extra_attach_params(sqlite3* db, const char* zName, const char* zPath, sqlite3_value* pKey, char** zErrDyn) { + return sqlite3mcHandleAttachKey(db, zName, zPath, pKey, zErrDyn); +} + +int libsql_handle_extra_uri_params(sqlite3 *db, const char *zOpen) { + return sqlite3mcHandleMainKey(db, zOpen); +} diff --git a/libsql-ffi/bundled/src/sqlite3.c b/libsql-ffi/bundled/src/sqlite3.c index a446238be3..8de0b90e32 100644 --- a/libsql-ffi/bundled/src/sqlite3.c +++ b/libsql-ffi/bundled/src/sqlite3.c @@ -121872,10 +121872,6 @@ SQLITE_PRIVATE int sqlite3DbIsNamed(sqlite3 *db, int iDb, const char *zName){ int libsql_handle_extra_attach_params(sqlite3* db, const char* zName, const char* zPath, sqlite3_value* pKey, char** zErrDyn); #endif -#ifdef LIBSQL_ENCRYPTION -SQLITE_PRIVATE int sqlite3mcHandleAttachKey(sqlite3*, const char*, const char*, sqlite3_value*, char**); -#endif - /* ** An SQL user-function registered to do the work of an ATTACH statement. The ** three arguments to the function come directly from an attach statement: @@ -122032,19 +122028,11 @@ static void attachFunc( } #ifdef LIBSQL_EXTRA_URI_PARAMS if (rc == SQLITE_OK) { - rc = libsql_handle_extra_attach_params(db, zName, zPath, argv, &zErrDyn); - } -#endif - -#ifdef LIBSQL_ENCRYPTION - /* If the ATTACH statement came with key parameter, then lets handle it here. */ - if( rc==SQLITE_OK ){ - if( argv != NULL && argv[0] != NULL && argv[1] != NULL && argv[2] != NULL ){ - rc = sqlite3mcHandleAttachKey(db, zName, zPath, argv[2], &zErrDyn); + if (argv != NULL && argv[0] != NULL && argv[1] != NULL && argv[2] != NULL) { + rc = libsql_handle_extra_attach_params(db, zName, zPath, argv[2], &zErrDyn); } } #endif - sqlite3_free_filename( zPath ); /* If the file was opened successfully, read the schema for the new database. diff --git a/libsql-sqlite3/src/attach.c b/libsql-sqlite3/src/attach.c index 989cc49ac3..5ded93a7ce 100644 --- a/libsql-sqlite3/src/attach.c +++ b/libsql-sqlite3/src/attach.c @@ -61,10 +61,6 @@ int sqlite3DbIsNamed(sqlite3 *db, int iDb, const char *zName){ int libsql_handle_extra_attach_params(sqlite3* db, const char* zName, const char* zPath, sqlite3_value* pKey, char** zErrDyn); #endif -#ifdef LIBSQL_ENCRYPTION -SQLITE_PRIVATE int sqlite3mcHandleAttachKey(sqlite3*, const char*, const char*, sqlite3_value*, char**); -#endif - /* ** An SQL user-function registered to do the work of an ATTACH statement. The ** three arguments to the function come directly from an attach statement: @@ -221,19 +217,11 @@ static void attachFunc( } #ifdef LIBSQL_EXTRA_URI_PARAMS if (rc == SQLITE_OK) { - rc = libsql_handle_extra_attach_params(db, zName, zPath, argv, &zErrDyn); - } -#endif - -#ifdef LIBSQL_ENCRYPTION - /* If the ATTACH statement came with key parameter, then lets handle it here. */ - if( rc==SQLITE_OK ){ - if( argv != NULL && argv[0] != NULL && argv[1] != NULL && argv[2] != NULL ){ - rc = sqlite3mcHandleAttachKey(db, zName, zPath, argv[2], &zErrDyn); + if (argv != NULL && argv[0] != NULL && argv[1] != NULL && argv[2] != NULL) { + rc = libsql_handle_extra_attach_params(db, zName, zPath, argv[2], &zErrDyn); } } #endif - sqlite3_free_filename( zPath ); /* If the file was opened successfully, read the schema for the new database. diff --git a/libsql/tests/encryption.rs b/libsql/tests/encryption.rs index b6cc926740..9c87440d0a 100644 --- a/libsql/tests/encryption.rs +++ b/libsql/tests/encryption.rs @@ -45,6 +45,17 @@ async fn test_encryption() { assert_eq!(text, "the only winning move is not to play"); } + // let's test encryption with connection string + { + let conn_str = format!("file:{}?key=s3cR3t", tempdir.join("encrypted.db").display()); + let db = Builder::new_local(&conn_str).build().await.unwrap(); + let conn = db.connect().unwrap(); + let mut results = conn.query("SELECT * FROM messages", ()).await.unwrap(); + let row = results.next().await.unwrap().unwrap(); + let text: String = row.get(0).unwrap(); + assert_eq!(text, "the only winning move is not to play"); + } + { let _ = std::fs::remove_file(&encrypted_path); let _ = std::fs::remove_file(&base_path);