Skip to content

Commit

Permalink
Fix issue #20
Browse files Browse the repository at this point in the history
The legacy cipher configuration parameter was not properly set on configuring a cipher scheme via PRAGMA commands or via URI parameters
  • Loading branch information
utelle committed Dec 9, 2020
1 parent c87a453 commit e27c041
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 46 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ dnl Copyright (C) 2019-2020 Ulrich Telle <ulrich@telle-online.de>
dnl
dnl This file is covered by the same licence as the entire SQLite3 Multiple Ciphers package.

AC_INIT([sqlite3mc], [1.1.1], [ulrich@telle-online.de])
AC_INIT([sqlite3mc], [1.1.2], [ulrich@telle-online.de])

dnl This is the version tested with, might work with earlier ones.
AC_PREREQ([2.69])
Expand Down
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ The code was mainly developed under Windows, but was tested under Linux as well.

## Version history

* 1.1.2 - *December 2020*
- Fixed a bug on cipher configuration via PRAGMA commands or URI parameters
* 1.1.1 - *December 2020*
- Fixed a bug on removing encryption from an encrypted database
* 1.1.0 - *December 2020*
Expand Down
67 changes: 24 additions & 43 deletions src/cipher_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,11 @@ sqlite3mcConfigureFromUri(sqlite3* db, const char *zDbName, int configDefault)
cipherParams = (strlen(globalCodecParameterTable[j].m_name) > 0) ? globalCodecParameterTable[j].m_params : NULL;
if (cipherParams != NULL)
{
/*
** Flag whether to skip the legacy parameter
** Currently enabled only in case of the SQLCipher scheme
*/
int skipLegacy = 0;
/* Set global parameters (cipher and hmac_check) */
int hmacCheck = sqlite3_uri_boolean(dbFileName, "hmac_check", 1);
if (configDefault)
Expand All @@ -666,13 +671,17 @@ sqlite3mcConfigureFromUri(sqlite3* db, const char *zDbName, int configDefault)
int legacy = (int) sqlite3_uri_int64(dbFileName, "legacy", 0);
if (legacy > 0 && legacy <= SQLCIPHER_VERSION_MAX)
{
sqlite3mcConfigureSQLCipherVersion(db, configDefault, legacy);
char* param = (configDefault) ? "default:legacy" : "legacy";
sqlite3mc_config_cipher(db, cipherName, param, legacy);
skipLegacy = 1;
}
}

/* Check all cipher specific parameters */
for (j = 0; strlen(cipherParams[j].m_name) > 0; ++j)
{
if (skipLegacy && sqlite3_stricmp(cipherParams[j].m_name, "legacy") == 0) continue;

int value = (int) sqlite3_uri_int64(dbFileName, cipherParams[j].m_name, -1);
if (value >= 0)
{
Expand Down Expand Up @@ -816,56 +825,28 @@ sqlite3mcFileControlPragma(sqlite3* db, const char* zDbName, int op, void* pArg)
if (cipherParams != NULL)
{
const char* cipherName = globalCodecParameterTable[j].m_name;
if ((cipher == CODEC_TYPE_SQLCIPHER) && (sqlite3StrICmp(pragmaName, "legacy") == 0))
int j;
for (j = 0; strlen(cipherParams[j].m_name) > 0; ++j)
{
/* Special handling for SQLCipher */
int legacy = (isIntValue) ? intValue : -1;
if (legacy > 0 && legacy <= SQLCIPHER_VERSION_MAX)
{
sqlite3mcConfigureSQLCipherVersion(db, configDefault, legacy);
((char**)pArg)[0] = sqlite3_mprintf("%d", legacy);
rc = SQLITE_OK;
}
else
if (sqlite3_stricmp(pragmaName, cipherParams[j].m_name) == 0) break;
}
if (strlen(cipherParams[j].m_name) > 0)
{
char* param = (configDefault) ? sqlite3_mprintf("default:%s", pragmaName) : pragmaName;
if (isIntValue)
{
int value;
if (configDefault)
{
value = sqlite3mc_config_cipher(db, "sqlcipher", "default:legacy", legacy);
}
else
{
value = sqlite3mc_config_cipher(db, "sqlcipher", "legacy", legacy);
}
int value = sqlite3mc_config_cipher(db, cipherName, param, intValue);
((char**)pArg)[0] = sqlite3_mprintf("%d", value);
rc = SQLITE_OK;
}
}
else
{
int j;
for (j = 0; strlen(cipherParams[j].m_name) > 0; ++j)
else
{
if (sqlite3_stricmp(pragmaName, cipherParams[j].m_name) == 0) break;
((char**) pArg)[0] = sqlite3_mprintf("Malformed integer value '%s'.", pragmaValue);
rc = SQLITE_ERROR;
}
if (strlen(cipherParams[j].m_name) > 0)
if (configDefault)
{
char* param = (configDefault) ? sqlite3_mprintf("default:%s", pragmaName) : pragmaName;
if (isIntValue)
{
int value = sqlite3mc_config_cipher(db, cipherName, param, intValue);
((char**)pArg)[0] = sqlite3_mprintf("%d", value);
rc = SQLITE_OK;
}
else
{
((char**) pArg)[0] = sqlite3_mprintf("Malformed integer value '%s'.", pragmaValue);
rc = SQLITE_ERROR;
}
if (configDefault)
{
sqlite3_free(param);
}
sqlite3_free(param);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/sqlite3mc_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

#define SQLITE3MC_VERSION_MAJOR 1
#define SQLITE3MC_VERSION_MINOR 1
#define SQLITE3MC_VERSION_RELEASE 1
#define SQLITE3MC_VERSION_RELEASE 2
#define SQLITE3MC_VERSION_SUBRELEASE 0
#define SQLITE3MC_VERSION_STRING "SQLite3 Multiple Ciphers 1.1.1"
#define SQLITE3MC_VERSION_STRING "SQLite3 Multiple Ciphers 1.1.2"

#endif /* SQLITE3MC_VERSION_H_ */

0 comments on commit e27c041

Please sign in to comment.