8000 Initial reporting of the cipher provider version · codeguru85/sqlcipher@f9044bf · GitHub
[go: up one dir, main page]

Skip to content

Commit f9044bf

Browse files
Initial reporting of the cipher provider version
Execute PRAGMA cipher_provider_version; Supports OpenSSL, libtomcrypt, and common crypto when running on OS X
1 parent cbcb037 commit f9044bf

File tree

7 files changed

+36
-1
lines changed

7 files changed

+36
-1
lines changed

src/crypto.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ int sqlcipher_codec_pragma(sqlite3* db, int iDb, Parse *pParse, const char *zLef
132132
sqlcipher_codec_get_cipher_provider(ctx));
133133
}
134134
} else
135+
if( sqlite3StrICmp(zLeft, "cipher_provider_version")==0 && !zRight){
136+
if(ctx) { codec_vdbe_return_static_string(pParse, "cipher_provider_version",
137+
sqlcipher_codec_get_provider_version(ctx));
138+
}
139+
} else
135140
if( sqlite3StrICmp(zLeft, "cipher_version")==0 && !zRight ){
136141
codec_vdbe_return_static_string(pParse, "cipher_version", codec_get_cipher_version());
137142
}else

src/crypto.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ static int sqlcipher_codec_get_store_pass(codec_ctx *ctx);
240240
static void sqlcipher_codec_get_pass(codec_ctx *ctx, void **zKey, int *nKey);
241241
static void sqlcipher_codec_set_store_pass(codec_ctx *ctx, int value);
242242
int sqlcipher_codec_fips_status(codec_ctx *ctx);
243-
243+
const char* sqlcipher_codec_get_provider_version(codec_ctx *ctx);
244244
#endif
245245
#endif
246246
/* END SQLCIPHER */

src/crypto_cc.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "sqlcipher.h"
3636
#include <CommonCrypto/CommonCrypto.h>
3737
#include <Security/SecRandom.h>
38+
#include <CoreFoundation/CoreFoundation.h>
3839

3940
static int sqlcipher_cc_add_random(void *ctx, void *buffer, int length) {
4041
return SQLITE_OK;
@@ -49,6 +50,19 @@ static const char* sqlcipher_cc_get_provider_name(void *ctx) {
4950
return "commoncrypto";
5051
}
5152

53+
static const char* sqlcipher_cc_get_provider_version(void *ctx) {
54+
#if TARGET_OS_MAC
55+
CFBundleRef bundle = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.security"));
56+
if(bundle == NULL) {
57+
return "unknown";
58+
}
59+
CFTypeRef version = CFBundleGetValueForInfoDictionaryKey(bundle, CFSTR("CFBundleShortVersionString"));
60+
return CFStringGetCStringPtr(version, kCFStringEncodingUTF8);
61+
#else
62+
return "unknown";
63+
#endif
64+
}
65+
5266
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) {
5367
CCHmacContext hmac_context;
5468
CCHmacInit(&hmac_context, kCCHmacAlgSHA1, hmac_key, key_sz);
@@ -142,6 +156,7 @@ int sqlcipher_cc_setup(sqlcipher_provider *p) {
142156
p->ctx_free = sqlcipher_cc_ctx_free;
143157
p->add_random = sqlcipher_cc_add_random;
144158
p->fips_status = sqlcipher_cc_fips_status;
159+
p->get_provider_version = sqlcipher_cc_get_provider_version;
145160
return SQLITE_OK;
146161
}
147162

src/crypto_impl.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,5 +1229,9 @@ int sqlcipher_codec_fips_status(codec_ctx *ctx) {
12291229
return ctx->read_ctx->provider->fips_status(ctx->read_ctx);
12301230
}
12311231

1232+
const char* sqlcipher_codec_get_provider_version(codec_ctx *ctx) {
1233+
return ctx->read_ctx->provider->get_provider_version(ctx->read_ctx);
1234+
}
1235+
12321236
#endif
12331237
/* END SQLCIPHER */

src/crypto_libtomcrypt.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ static const char* sqlcipher_ltc_get_provider_name(void *ctx) {
124124
return "libtomcrypt";
125125
}
126126

127+
static const char* sqlcipher_ltc_get_provider_version(void *ctx) {
128+
return SCRYPT;
129+
}
130+
127131
static int sqlcipher_ltc_random(void *ctx, void *buffer, int length) {
128132
#ifndef SQLCIPHER_LTC_NO_MUTEX_RAND
129133
sqlite3_mutex_enter(ltc_rand_mutex);
@@ -251,6 +255,7 @@ int sqlcipher_ltc_setup(sqlcipher_provider *p) {
251255
p->ctx_free = sqlcipher_ltc_ctx_free;
252256
p->add_random = sqlcipher_ltc_add_random;
253257
p->fips_status = sqlcipher_ltc_fips_status;
258+
p->get_provider_version = sqlcipher_ltc_get_provider_version;
254259
return SQLITE_OK;
255260
}
256261

src/crypto_openssl.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ static const char* sqlcipher_openssl_get_provider_name(void *ctx) {
131131
return "openssl";
132132
}
133133

134+
static const char* sqlcipher_openssl_get_provider_version(void *ctx) {
135+
return OPENSSL_VERSION_TEXT;
136+
}
137+
134138
/* generate a defined number of random bytes */
135139
static int sqlcipher_openssl_random (void *ctx, void *buffer, int length) {
136140
int rc = 0;
@@ -263,6 +267,7 @@ int sqlcipher_openssl_setup(sqlcipher_provider *p) {
263267
p->ctx_free = sqlcipher_openssl_ctx_free;
264268
p->add_random = sqlcipher_openssl_add_random;
265269
p->fips_status = sqlcipher_openssl_fips_status;
270+
p->get_provider_version = sqlcipher_openssl_get_provider_version;
266271
return SQLITE_OK;
267272
}
268273

src/sqlcipher.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ typedef struct {
5656
int (*ctx_init)(void **ctx);
5757
int (*ctx_free)(void **ctx);
5858
int (*fips_status)(void *ctx);
59+
const char* (*get_provider_version)(void *ctx);
5960
} sqlcipher_provider;
6061

6162
/* utility functions */

0 commit comments

Comments
 (0)
0