Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libsql-ffi/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion libsql-ffi/bundled/SQLite3MultipleCiphers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ set(SQLITE3MC_BASE_DEFINITIONS
$<$<BOOL:${LIBSQL_ENABLE_WASM_RUNTIME}>: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
Expand Down
8 changes: 8 additions & 0 deletions libsql-ffi/bundled/SQLite3MultipleCiphers/src/cipher_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
16 changes: 2 additions & 14 deletions libsql-ffi/bundled/src/sqlite3.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand Down
16 changes: 2 additions & 14 deletions libsql-sqlite3/src/attach.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand Down
11 changes: 11 additions & 0 deletions libsql/tests/encryption.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading