Initial reporting of the cipher provider version

Execute PRAGMA cipher_provider_version;

Supports OpenSSL, libtomcrypt, and
common crypto when running on OS X
This commit is contained in:
Nick Parker 2016-02-22 15:53:08 -06:00
parent cbcb03710a
commit f9044bf604
7 changed files with 36 additions and 1 deletions

View File

@ -132,6 +132,11 @@ int sqlcipher_codec_pragma(sqlite3* db, int iDb, Parse *pParse, const char *zLef
sqlcipher_codec_get_cipher_provider(ctx));
}
} else
if( sqlite3StrICmp(zLeft, "cipher_provider_version")==0 && !zRight){
if(ctx) { codec_vdbe_return_static_string(pParse, "cipher_provider_version",
sqlcipher_codec_get_provider_version(ctx));
}
} else
if( sqlite3StrICmp(zLeft, "cipher_version")==0 && !zRight ){
codec_vdbe_return_static_string(pParse, "cipher_version", codec_get_cipher_version());
}else

View File

@ -240,7 +240,7 @@ static int sqlcipher_codec_get_store_pass(codec_ctx *ctx);
static void sqlcipher_codec_get_pass(codec_ctx *ctx, void **zKey, int *nKey);
static void sqlcipher_codec_set_store_pass(codec_ctx *ctx, int value);
int sqlcipher_codec_fips_status(codec_ctx *ctx);
const char* sqlcipher_codec_get_provider_version(codec_ctx *ctx);
#endif
#endif
/* END SQLCIPHER */

View File

@ -35,6 +35,7 @@
#include "sqlcipher.h"
#include <CommonCrypto/CommonCrypto.h>
#include <Security/SecRandom.h>
#include <CoreFoundation/CoreFoundation.h>
static int sqlcipher_cc_add_random(void *ctx, void *buffer, int length) {
return SQLITE_OK;
@ -49,6 +50,19 @@ static const char* sqlcipher_cc_get_provider_name(void *ctx) {
return "commoncrypto";
}
static const char* sqlcipher_cc_get_provider_version(void *ctx) {
#if TARGET_OS_MAC
CFBundleRef bundle = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.security"));
if(bundle == NULL) {
return "unknown";
}
CFTypeRef version = CFBundleGetValueForInfoDictionaryKey(bundle, CFSTR("CFBundleShortVersionString"));
return CFStringGetCStringPtr(version, kCFStringEncodingUTF8);
#else
return "unknown";
#endif
}
static int sqlcipher_cc_hmac(void *ctx, unsigned char *hmac_key, int key_sz, unsigned char *in, int in_sz, unsigned char *in2, int in2_sz, unsigned char *out) {
CCHmacContext hmac_context;
CCHmacInit(&hmac_context, kCCHmacAlgSHA1, hmac_key, key_sz);
@ -142,6 +156,7 @@ int sqlcipher_cc_setup(sqlcipher_provider *p) {
p->ctx_free = sqlcipher_cc_ctx_free;
p->add_random = sqlcipher_cc_add_random;
p->fips_status = sqlcipher_cc_fips_status;
p->get_provider_version = sqlcipher_cc_get_provider_version;
return SQLITE_OK;
}

View File

@ -1229,5 +1229,9 @@ int sqlcipher_codec_fips_status(codec_ctx *ctx) {
return ctx->read_ctx->provider->fips_status(ctx->read_ctx);
}
const char* sqlcipher_codec_get_provider_version(codec_ctx *ctx) {
return ctx->read_ctx->provider->get_provider_version(ctx->read_ctx);
}
#endif
/* END SQLCIPHER */

View File

@ -124,6 +124,10 @@ static const char* sqlcipher_ltc_get_provider_name(void *ctx) {
return "libtomcrypt";
}
static const char* sqlcipher_ltc_get_provider_version(void *ctx) {
return SCRYPT;
}
static int sqlcipher_ltc_random(void *ctx, void *buffer, int length) {
#ifndef SQLCIPHER_LTC_NO_MUTEX_RAND
sqlite3_mutex_enter(ltc_rand_mutex);
@ -251,6 +255,7 @@ int sqlcipher_ltc_setup(sqlcipher_provider *p) {
p->ctx_free = sqlcipher_ltc_ctx_free;
p->add_random = sqlcipher_ltc_add_random;
p->fips_status = sqlcipher_ltc_fips_status;
p->get_provider_version = sqlcipher_ltc_get_provider_version;
return SQLITE_OK;
}

View File

@ -131,6 +131,10 @@ static const char* sqlcipher_openssl_get_provider_name(void *ctx) {
return "openssl";
}
static const char* sqlcipher_openssl_get_provider_version(void *ctx) {
return OPENSSL_VERSION_TEXT;
}
/* generate a defined number of random bytes */
static int sqlcipher_openssl_random (void *ctx, void *buffer, int length) {
int rc = 0;
@ -263,6 +267,7 @@ int sqlcipher_openssl_setup(sqlcipher_provider *p) {
p->ctx_free = sqlcipher_openssl_ctx_free;
p->add_random = sqlcipher_openssl_add_random;
p->fips_status = sqlcipher_openssl_fips_status;
p->get_provider_version = sqlcipher_openssl_get_provider_version;
return SQLITE_OK;
}

View File

@ -56,6 +56,7 @@ typedef struct {
int (*ctx_init)(void **ctx);
int (*ctx_free)(void **ctx);
int (*fips_status)(void *ctx);
const char* (*get_provider_version)(void *ctx);
} sqlcipher_provider;
/* utility functions */