summaryrefslogtreecommitdiff
path: root/storage/xtradb/fil/fil0crypt.cc
diff options
context:
space:
mode:
Diffstat (limited to 'storage/xtradb/fil/fil0crypt.cc')
-rw-r--r--storage/xtradb/fil/fil0crypt.cc39
1 files changed, 18 insertions, 21 deletions
diff --git a/storage/xtradb/fil/fil0crypt.cc b/storage/xtradb/fil/fil0crypt.cc
index 4719a37fab2..d7b26eed49f 100644
--- a/storage/xtradb/fil/fil0crypt.cc
+++ b/storage/xtradb/fil/fil0crypt.cc
@@ -303,9 +303,8 @@ fil_crypt_get_latest_key(byte *dst, uint* key_length,
}
return fil_crypt_get_key(dst, key_length, crypt_data, *version, false);
- } else {
- return fil_crypt_get_key(dst, key_length, NULL, *version, true);
}
+ return fil_crypt_get_key(dst, key_length, NULL, *version, true);
}
/******************************************************************
@@ -622,13 +621,25 @@ fil_space_encrypt(ulint space, ulint offset, lsn_t lsn,
byte key[MY_AES_MAX_KEY_LENGTH];
uint key_length;
+ ulint orig_page_type = mach_read_from_2(src_frame+FIL_PAGE_TYPE);
+ if (orig_page_type==FIL_PAGE_TYPE_FSP_HDR
+ || orig_page_type==FIL_PAGE_TYPE_XDES
+ || orig_page_type== FIL_PAGE_PAGE_ENCRYPTED
+ || orig_page_type== FIL_PAGE_PAGE_COMPRESSED_ENCRYPTED) {
+ //TODO: is this really needed ?
+ memcpy(dst_frame, src_frame, page_size);
+ return;
+ }
+
if (srv_encrypt_tables) {
crypt_data = fil_space_get_crypt_data(space);
+
if (crypt_data == NULL) {
//TODO: Is this really needed ?
memcpy(dst_frame, src_frame, page_size);
return;
}
+
fil_crypt_get_latest_key(key, &key_length, crypt_data, &key_version);
} else {
key_version = encryption_key;
@@ -647,9 +658,7 @@ fil_space_encrypt(ulint space, ulint offset, lsn_t lsn,
src_frame + FIL_PAGE_OFFSET);
mach_write_to_4(iv + 4, space_offset);
mach_write_to_8(iv + 8, lsn);
- }
- else
- {
+ } else {
// take the iv from the key provider
int load_iv_rc = get_encryption_iv(key_version, (uchar *) iv, sizeof(iv));
@@ -667,19 +676,9 @@ fil_space_encrypt(ulint space, ulint offset, lsn_t lsn,
}
}
-
ibool page_compressed = (mach_read_from_2(src_frame+FIL_PAGE_TYPE) == FIL_PAGE_PAGE_COMPRESSED);
ibool page_encrypted = fil_space_is_page_encrypted(space);
ulint compression_alg = mach_read_from_8(src_frame+FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION);
- ulint orig_page_type = mach_read_from_2(src_frame+FIL_PAGE_TYPE);
-
- if (orig_page_type==FIL_PAGE_TYPE_FSP_HDR
- || orig_page_type==FIL_PAGE_TYPE_XDES
- || orig_page_type== FIL_PAGE_PAGE_ENCRYPTED
- || orig_page_type== FIL_PAGE_PAGE_COMPRESSED_ENCRYPTED) {
- memcpy(dst_frame, src_frame, page_size);
- return;
- }
// copy page header
memcpy(dst_frame, src_frame, FIL_PAGE_DATA);
@@ -708,7 +707,7 @@ fil_space_encrypt(ulint space, ulint offset, lsn_t lsn,
uint32 dstlen;
if (page_compressed) {
- srclen = page_size - FIL_PAGE_DATA;
+ srclen = page_size - FIL_PAGE_DATA;;
}
int rc = (* my_aes_encrypt_dynamic)(src, srclen,
@@ -789,6 +788,7 @@ fil_space_check_encryption_read(
ulint space) /*!< in: tablespace id */
{
fil_space_crypt_t* crypt_data = fil_space_get_crypt_data(space);
+
if (crypt_data == NULL)
return false;
@@ -815,6 +815,7 @@ fil_space_decrypt(fil_space_crypt_t* crypt_data,
|| page_type == FIL_PAGE_PAGE_COMPRESSED);
ulint orig_page_type=0;
+
if (page_type == FIL_PAGE_PAGE_ENCRYPTED) {
key_version = mach_read_from_2(
src_frame + FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION);
@@ -846,7 +847,6 @@ fil_space_decrypt(fil_space_crypt_t* crypt_data,
mach_write_to_2(dst_frame+FIL_PAGE_TYPE, orig_page_type);
}
-
// get key
byte key[MY_AES_MAX_KEY_LENGTH];
uint key_length;
@@ -862,9 +862,7 @@ fil_space_decrypt(fil_space_crypt_t* crypt_data,
mach_write_to_4(iv + 0, space);
mach_write_to_4(iv + 4, offset);
mach_write_to_8(iv + 8, lsn);
- }
- else
- {
+ } else {
// take the iv from the key provider
int load_iv_rc = get_encryption_iv(key_version, (uchar *) iv, sizeof(iv));
@@ -886,7 +884,6 @@ fil_space_decrypt(fil_space_crypt_t* crypt_data,
byte* dst = dst_frame + FIL_PAGE_DATA;
uint32 dstlen;
ulint srclen = page_size - (FIL_PAGE_DATA + FIL_PAGE_DATA_END);
-
ulint compressed_len;
ulint compression_method;