Skip to content

Commit

Permalink
fix regression itroduced in prior commit
Browse files Browse the repository at this point in the history
  • Loading branch information
sjlombardo committed Sep 3, 2013
1 parent f25510f commit f291262
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ static void cipher_hex2bin(const char *hex, int sz, unsigned char *out){
static void cipher_bin2hex(const unsigned char* in, int sz, char *out) {
int i;
for(i=0; i < sz; i++) {
sqlite3_snprintf(2, out + (i*2), "%02x ", in[i]);
sqlite3_snprintf(3, out + (i*2), "%02x ", in[i]);
}
}

Expand Down
17 changes: 7 additions & 10 deletions src/crypto_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -389,10 +389,9 @@ static int sqlcipher_cipher_ctx_set_keyspec(cipher_ctx *ctx, const unsigned char

ctx->keyspec[0] = 'x';
ctx->keyspec[1] = '\'';
ctx->keyspec[ctx->keyspec_sz - 1] = '\'';
cipher_bin2hex(key, key_sz, ctx->keyspec + 2);
cipher_bin2hex(salt, salt_sz, ctx->keyspec + (key_sz * 2) + 2);

ctx->keyspec[ctx->keyspec_sz - 1] = '\'';
return SQLITE_OK;
}

Expand Down Expand Up @@ -980,15 +979,9 @@ int sqlcipher_codec_ctx_migrate(codec_ctx *ctx) {
memcpy(key, ctx->read_ctx->pass, ctx->read_ctx->pass_sz);

if(db_filename){

const char* commands[4];
char *attach_command = sqlite3_mprintf("ATTACH DATABASE '%s-migrated' as migrate KEY '%s';",
db_filename, key);
const char* commands[] = {
upgrade_4k_format == 1 ? pragma_4k_kdf_iter : "",
upgrade_1x_format == 1 ? pragma_hmac_off : "",
attach_command,
"SELECT sqlcipher_export('migrate');",
};

int rc = sqlcipher_check_connection(db_filename, key, key_sz, "");
if(rc == SQLITE_OK){
Expand Down Expand Up @@ -1019,7 +1012,11 @@ int sqlcipher_codec_ctx_migrate(codec_ctx *ctx) {
goto handle_error;
}


commands[0] = upgrade_4k_format == 1 ? pragma_4k_kdf_iter : "";
commands[1] = upgrade_1x_format == 1 ? pragma_hmac_off : "";
commands[2] = attach_command;
commands[3] = "SELECT sqlcipher_export('migrate');";

for(command_idx = 0; command_idx < (sizeof(commands)/sizeof(commands[0])); command_idx++){
const char *command = commands[command_idx];
if(strcmp(command, "") == 0){
Expand Down

0 comments on commit f291262

Please sign in to comment.