Skip to content

Commit e27c041

Browse files
committed
Fix issue #20
The legacy cipher configuration parameter was not properly set on configuring a cipher scheme via PRAGMA commands or via URI parameters
1 parent c87a453 commit e27c041

File tree

4 files changed

+29
-46
lines changed

4 files changed

+29
-46
lines changed

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ dnl Copyright (C) 2019-2020 Ulrich Telle <[email protected]>
44
dnl
55
dnl This file is covered by the same licence as the entire SQLite3 Multiple Ciphers package.
66

7-
AC_INIT([sqlite3mc], [1.1.1], [[email protected]])
7+
AC_INIT([sqlite3mc], [1.1.2], [[email protected]])
88

99
dnl This is the version tested with, might work with earlier ones.
1010
AC_PREREQ([2.69])

readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ The code was mainly developed under Windows, but was tested under Linux as well.
1212

1313
## Version history
1414

15+
* 1.1.2 - *December 2020*
16+
- Fixed a bug on cipher configuration via PRAGMA commands or URI parameters
1517
* 1.1.1 - *December 2020*
1618
- Fixed a bug on removing encryption from an encrypted database
1719
* 1.1.0 - *December 2020*

src/cipher_config.c

Lines changed: 24 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,11 @@ sqlite3mcConfigureFromUri(sqlite3* db, const char *zDbName, int configDefault)
645645
cipherParams = (strlen(globalCodecParameterTable[j].m_name) > 0) ? globalCodecParameterTable[j].m_params : NULL;
646646
if (cipherParams != NULL)
647647
{
648+
/*
649+
** Flag whether to skip the legacy parameter
650+
** Currently enabled only in case of the SQLCipher scheme
651+
*/
652+
int skipLegacy = 0;
648653
/* Set global parameters (cipher and hmac_check) */
649654
int hmacCheck = sqlite3_uri_boolean(dbFileName, "hmac_check", 1);
650655
if (configDefault)
@@ -666,13 +671,17 @@ sqlite3mcConfigureFromUri(sqlite3* db, const char *zDbName, int configDefault)
666671
int legacy = (int) sqlite3_uri_int64(dbFileName, "legacy", 0);
667672
if (legacy > 0 && legacy <= SQLCIPHER_VERSION_MAX)
668673
{
669-
sqlite3mcConfigureSQLCipherVersion(db, configDefault, legacy);
674+
char* param = (configDefault) ? "default:legacy" : "legacy";
675+
sqlite3mc_config_cipher(db, cipherName, param, legacy);
676+
skipLegacy = 1;
670677
}
671678
}
672679

673680
/* Check all cipher specific parameters */
674681
for (j = 0; strlen(cipherParams[j].m_name) > 0; ++j)
675682
{
683+
if (skipLegacy && sqlite3_stricmp(cipherParams[j].m_name, "legacy") == 0) continue;
684+
676685
int value = (int) sqlite3_uri_int64(dbFileName, cipherParams[j].m_name, -1);
677686
if (value >= 0)
678687
{
@@ -816,56 +825,28 @@ sqlite3mcFileControlPragma(sqlite3* db, const char* zDbName, int op, void* pArg)
816825
if (cipherParams != NULL)
817826
{
818827
const char* cipherName = globalCodecParameterTable[j].m_name;
819-
if ((cipher == CODEC_TYPE_SQLCIPHER) && (sqlite3StrICmp(pragmaName, "legacy") == 0))
828+
int j;
829+
for (j = 0; strlen(cipherParams[j].m_name) > 0; ++j)
820830
{
821-
/* Special handling for SQLCipher */
822-
int legacy = (isIntValue) ? intValue : -1;
823-
if (legacy > 0 && legacy <= SQLCIPHER_VERSION_MAX)
824-
{
825-
sqlite3mcConfigureSQLCipherVersion(db, configDefault, legacy);
826-
((char**)pArg)[0] = sqlite3_mprintf("%d", legacy);
827-
rc = SQLITE_OK;
828-
}
829-
else
831+
if (sqlite3_stricmp(pragmaName, cipherParams[j].m_name) == 0) break;
832+
}
833+
if (strlen(cipherParams[j].m_name) > 0)
834+
{
835+
char* param = (configDefault) ? sqlite3_mprintf("default:%s", pragmaName) : pragmaName;
836+
if (isIntValue)
830837
{
831-
int value;
832-
if (configDefault)
833-
{
834-
value = sqlite3mc_config_cipher(db, "sqlcipher", "default:legacy", legacy);
835-
}
836-
else
837-
{
838-
value = sqlite3mc_config_cipher(db, "sqlcipher", "legacy", legacy);
839-
}
838+
int value = sqlite3mc_config_cipher(db, cipherName, param, intValue);
840839
((char**)pArg)[0] = sqlite3_mprintf("%d", value);
841840
rc = SQLITE_OK;
842841
}
843-
}
844-
else
845-
{
846-
int j;
847-
for (j = 0; strlen(cipherParams[j].m_name) > 0; ++j)
842+
else
848843
{
849-
if (sqlite3_stricmp(pragmaName, cipherParams[j].m_name) == 0) break;
844+
((char**) pArg)[0] = sqlite3_mprintf("Malformed integer value '%s'.", pragmaValue);
845+
rc = SQLITE_ERROR;
850846
}
851-
if (strlen(cipherParams[j].m_name) > 0)
847+
if (configDefault)
852848
{
853-
char* param = (configDefault) ? sqlite3_mprintf("default:%s", pragmaName) : pragmaName;
854-
if (isIntValue)
855-
{
856-
int value = sqlite3mc_config_cipher(db, cipherName, param, intValue);
857-
((char**)pArg)[0] = sqlite3_mprintf("%d", value);
858-
rc = SQLITE_OK;
859-
}
860-
else
861-
{
862-
((char**) pArg)[0] = sqlite3_mprintf("Malformed integer value '%s'.", pragmaValue);
863-
rc = SQLITE_ERROR;
864-
}
865-
if (configDefault)
866-
{
867-
sqlite3_free(param);
868-
}
849+
sqlite3_free(param);
869850
}
870851
}
871852
}

src/sqlite3mc_version.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
#define SQLITE3MC_VERSION_MAJOR 1
1616
#define SQLITE3MC_VERSION_MINOR 1
17-
#define SQLITE3MC_VERSION_RELEASE 1
17+
#define SQLITE3MC_VERSION_RELEASE 2
1818
#define SQLITE3MC_VERSION_SUBRELEASE 0
19-
#define SQLITE3MC_VERSION_STRING "SQLite3 Multiple Ciphers 1.1.1"
19+
#define SQLITE3MC_VERSION_STRING "SQLite3 Multiple Ciphers 1.1.2"
2020

2121
#endif /* SQLITE3MC_VERSION_H_ */

0 commit comments

Comments
 (0)