From 525243c689b1bc0d04a3a6904c243bdae63f9d8d Mon Sep 17 00:00:00 2001 From: Nick Parker Date: Thu, 17 May 2012 07:59:43 -0500 Subject: [PATCH] Adding PRAGMA cipher_version to identify the current SQLCipher version, also including test. --- src/crypto.c | 10 ++++++++++ src/crypto.h | 4 ++++ src/pragma.c | 4 ++++ test/crypto.test | 12 ++++++++++++ 4 files changed, 30 insertions(+) diff --git a/src/crypto.c b/src/crypto.c index 3b1bfbf7..8928fb9d 100644 --- a/src/crypto.c +++ b/src/crypto.c @@ -38,6 +38,16 @@ #include "btreeInt.h" #include "crypto.h" +/* Generate code to return a string value */ +void codec_vdbe_return_static_string(Parse *pParse, const char *zLabel, const char *value){ + Vdbe *v = sqlite3GetVdbe(pParse); + int mem = ++pParse->nMem; + sqlite3VdbeAddOp4(v, OP_String, 0, mem, 0, (char*)value, P4_STATIC); + sqlite3VdbeSetNumCols(v, 1); + sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLabel, SQLITE_STATIC); + sqlite3VdbeAddOp2(v, OP_ResultRow, mem, 1); +} + int codec_set_kdf_iter(sqlite3* db, int nDb, int kdf_iter, int for_ctx) { struct Db *pDb = &db->aDb[nDb]; CODEC_TRACE(("codec_set_kdf_iter: entered db=%p nDb=%d kdf_iter=%d for_ctx=%d\n", db, nDb, kdf_iter, for_ctx)); diff --git a/src/crypto.h b/src/crypto.h index 6074907f..6485c968 100644 --- a/src/crypto.h +++ b/src/crypto.h @@ -37,6 +37,10 @@ #define FILE_HEADER_SZ 16 +#ifndef CIPHER_VERSION +#define CIPHER_VERSION "2.0.5" +#endif + #ifndef CIPHER #define CIPHER "aes-256-cbc" #endif diff --git a/src/pragma.c b/src/pragma.c index 1b23bc61..09282a73 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -1535,6 +1535,10 @@ void sqlite3Pragma( } }else /** BEGIN CRYPTO **/ + if( sqlite3StrICmp(zLeft, "cipher_version")==0 && !zRight ){ + extern void codec_vdbe_return_static_string(Parse *pParse, const char *zLabel, const char *value); + codec_vdbe_return_static_string(pParse, "cipher_version", CIPHER_VERSION); + }else if( sqlite3StrICmp(zLeft, "cipher")==0 && zRight ){ extern int codec_set_cipher_name(sqlite3*, int, const char *, int); codec_set_cipher_name(db, iDb, zRight, 2); // change cipher for both diff --git a/test/crypto.test b/test/crypto.test index 78240561..cefe533a 100644 --- a/test/crypto.test +++ b/test/crypto.test @@ -1205,4 +1205,16 @@ do_test change-default-use-hmac-attach { db close file delete -force test.db +# verify the pragma cipher_version +# returns the currently configured +# sqlcipher version +do_test verify-pragma-cipher-version { + sqlite_orig db test.db + execsql { + PRAGMA cipher_version; + } +} {2.0.5} +db close +file delete -force test.db + finish_test