Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
7f653ae
MariaDB 10.1 page encryption v0.1 Alpha
Sep 23, 2014
b6bb3f1
Cmake Problem fix
Sep 24, 2014
a939f5a
gitignore
Sep 24, 2014
08bb1a4
fixed unit tests
Sep 24, 2014
71eac24
Bugfix unittests
Sep 24, 2014
997cfc4
page compression activated and page compression combined with page en…
Sep 26, 2014
8cc3e36
merged with 10_1 branch
Sep 26, 2014
8831a6d
fixed merged error
Sep 26, 2014
2e26a4e
Key file parser can handle encrypted keyfiles
Sep 24, 2014
f4f3cd7
Merge encrypted keyfile parser into 10.1
Sep 26, 2014
ae6ea13
florin key auslesen
fugaciu Sep 26, 2014
579146b
minor
Sep 26, 2014
5913b4f
Merge remote-tracking branch 'origin/florin' into fix_unittest
Sep 29, 2014
c4e195e
zwischenst
Sep 30, 2014
dbe784f
zwischens
Sep 30, 2014
c45e43c
working with PAGE_COMPRESSED PAGE_ENCRYPTION and no use of flush_lsn …
Sep 30, 2014
1e0811f
merge encryption + compression
Oct 1, 2014
57d338e
Auslesen keyfile
Oct 2, 2014
ece8828
typedef ulint entfernt
Oct 2, 2014
c31d6e6
fix unit test build file
Oct 2, 2014
3ab88c5
key aus keyfile
Oct 2, 2014
d887798
Merge branch 'florin' of ssh://192.168.103.248/srv/git/mariadb_10 int…
Oct 2, 2014
a74dddb
respect key length and reactivate unit test
Oct 2, 2014
22d832e
Removed blocksize output
Oct 2, 2014
b8a81ec
change header comments and removed a unit test
Oct 6, 2014
8c6f6d7
Merge branch 'florin' of ssh://192.168.103.248/srv/git/mariadb_10 int…
Oct 6, 2014
b6bad41
Removed keyfile tests
Oct 6, 2014
4f5d280
Merge remote-tracking branch 'mariadb/10.1' into 10.1
Oct 6, 2014
050ca92
Using my_fopen instead of fopne
Oct 6, 2014
bf6610d
Using fprintf instead of printf for error messages
Oct 6, 2014
598038d
removed name
Oct 6, 2014
5043762
revert enabling page compression method
Oct 7, 2014
a68f779
Secret can now be delivered via a File by prepending FILE: magic.
Oct 8, 2014
8ae485b
Merge branch 'SecretFile' into 10.1
Oct 8, 2014
efa2372
Removed storage/enc/keyfile.c
Oct 8, 2014
ee219c5
Code cleanup removed compiler warnings
Oct 8, 2014
036d52e
Unittest cleanup
Oct 8, 2014
30f0308
Windows build essentials
Oct 8, 2014
0ad2284
merged
Oct 8, 2014
a9b0c48
EperiKeySingleton removed fix path
Oct 8, 2014
90022b4
windows, impl: PAGE_ENCRYPTION
Oct 9, 2014
7cd4990
added sthg to ignore list
Oct 9, 2014
adc89fd
Merge remote-tracking branch 'Windows changes' into cleanup
Oct 9, 2014
5bb4614
fix Linux - Windows patch
Oct 9, 2014
acfa72d
revert some changes
Oct 9, 2014
10d2a2f
Merge branch 'Windows patch' into 10.1
Oct 9, 2014
41ed273
Added interface for keyserver
Oct 10, 2014
6ca7fc3
Check for NULLpointer in keystore.
Oct 10, 2014
9fd4585
printKeyEntry will no longer reveal key when not compiled in debug mode.
Oct 10, 2014
8380b82
improved key file handling
Oct 10, 2014
c79d54e
merged page encryption and minor improvements for error handling
Oct 10, 2014
e673d00
Singleton can now tell you if a key is present or not.
Oct 14, 2014
5c946ff
Simplified call to extract key
Oct 14, 2014
340dfd9
some error handling if key file n.a.
Oct 14, 2014
282199d
made alter table working...
Oct 14, 2014
ac561db
Code cleanup - simplification
Oct 14, 2014
b0a0830
Secret file using absolut path instead of relative path.
Oct 14, 2014
03ffc88
Merge remote-tracking branch 'svn/10.1' into mergeme
Oct 14, 2014
8fc45be
fixed decryption original page type and improved unit test!
Oct 15, 2014
046fba7
changed checksum calculation, so that headers are included, added a u…
Oct 15, 2014
923ca50
Salt now reading the correct number of bytes
Oct 16, 2014
f10525a
Merge branch '10.1' of svn
Oct 16, 2014
c4afc1d
backup meines zwischenstandes...
Oct 16, 2014
16624c8
encryptin sec file possible (with std. passphrase)
Oct 16, 2014
6dbd4d6
String terminators removed.
Oct 16, 2014
6333c1f
fix windows issues, support unc path
Oct 16, 2014
e9cf418
Merge remote-tracking branch 'Windows network path'
Oct 16, 2014
1e72272
cleanup of code
Oct 22, 2014
23df03b
removed superfluous stuff
Oct 23, 2014
47a3bab
removed superfluous defines
Oct 23, 2014
a2cf68d
use openssl compiler flag
Oct 23, 2014
f4a35a7
added a comment
Oct 23, 2014
9607b8f
introduced yassl for encryption, improved compilier flags for windows…
Oct 24, 2014
7d58711
fix ut_align call, removed keys from output (debug)
Oct 24, 2014
de74ef1
improved cbc enc/dec with no padding support
Oct 27, 2014
4bf6a7c
added unit tests for page_encryption, added support for row_format=co…
Oct 28, 2014
5bc08f8
page type 8 and 9 are not encrypted anymore to support recovery for r…
Oct 29, 2014
0c96878
Merge remote-tracking branch 'mariadb/10.1' into pageenc
Oct 29, 2014
df2ec54
Removed printf from productive build.
Oct 30, 2014
f8b6f19
free allocated buffers
Oct 30, 2014
d357cda
changed comments, removed dead code
Oct 31, 2014
cda7631
fixed unit test
Oct 31, 2014
049a6a8
fix win 64 build (only page_encryption files)
Nov 3, 2014
e209ec8
fix memory leak
Nov 18, 2014
d75dac2
fix error with page_compressed tables
Nov 19, 2014
0a76259
use slot structure for temporary memory.
Nov 24, 2014
1bd9500
reduced usage of buffer variables
Nov 25, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
.cproject
.project
Debug/*
pcre/*
pcre3/*
_32/*
_64/*
bld/*
*-t
*.a
*.ctest
Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ SET(CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE ON)
ADD_DEFINITIONS(-DHAVE_CONFIG_H)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/include)


# Add bundled or system zlib.
MYSQL_CHECK_ZLIB_WITH_COMPRESS()
# Add bundled yassl/taocrypt or system openssl.
Expand Down Expand Up @@ -380,6 +381,7 @@ IF(WITH_UNIT_TESTS)
ADD_SUBDIRECTORY(unittest/examples)
ADD_SUBDIRECTORY(unittest/mysys)
ADD_SUBDIRECTORY(unittest/my_decimal)
ADD_SUBDIRECTORY(unittest/eperi)
IF(NOT WITHOUT_SERVER)
ADD_SUBDIRECTORY(unittest/sql)
ENDIF()
Expand Down
46 changes: 46 additions & 0 deletions dbug/dbug.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
#undef SAFE_MUTEX
#include <m_string.h>
#include <errno.h>
#include <stdio.h>

#ifndef DBUG_OFF

Expand Down Expand Up @@ -2184,6 +2185,51 @@ const char* _db_get_func_(void)
return cs->func;
}


void dump_buffer(unsigned n, const unsigned char* buf) {
int on_this_line = 0;
int counter = 0;
int cc =0;
char ch =0;

FILE* stream = stderr;
fflush(stream);
fprintf(stream, "%06X: ", counter);
while (n-- > 0) {
fprintf(stream, "%02X ", *buf++);
on_this_line += 1;
if (on_this_line == 16 || n == 0) {
int i;
fprintf(stream, " ");
cc = on_this_line;
if (cc != 16) {


for (i = on_this_line; i < 16; i++) {
fprintf(stream," " );
}
}
for (i = on_this_line; i > 0; i--) {
ch =isprint(buf[-i]) ? buf[-i] : '.';
fprintf(stream,"%c",ch);
}

fprintf(stream,"\n" );

on_this_line = 0;
if (n!=0) fprintf(stream, "%06X: ", ++counter);


} else {
counter++;
}
}
fprintf( stream, "\n");
fflush(stream);
}



#else

/*
Expand Down
38 changes: 38 additions & 0 deletions include/keyfile.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* Copyright (C) 2014 eperi GmbH. All Rights Reserved.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */

/******************************************************************/
#ifndef KEYFILE_H
#define KEYFILE_H
#include<stdio.h>

struct keyentry {
int id;
char *iv;
char *key;
};

int
parseFile(FILE * fp, struct keyentry **allKeys, const int k_len, const char *secret);

int
parseLine(const char *line, struct keyentry *entry, const int k_len);

int
isComment(char *line);

char*
trim(char *in);
#endif
83 changes: 83 additions & 0 deletions include/my_aes.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
#ifndef MY_AES_INCLUDED
#define MY_AES_INCLUDED

#define AES_OK 0
#define AES_BAD_DATA -1
#define AES_BAD_KEYSIZE -5
#define AES_KEY_CREATION_FAILED -10

#define MY_AES_BLOCK_SIZE 16 /* Block size in bytes */

/* Copyright (c) 2002, 2006 MySQL AB, 2009 Sun Microsystems, Inc.
Use is subject to license terms.

Expand All @@ -27,6 +34,57 @@ C_MODE_START

#define AES_KEY_LENGTH 128 /* Must be 128 192 or 256 */


/**
Crypt buffer with AES encryption algorithm.

SYNOPSIS
my_aes_encrypt()
@param source [in] Pointer to data for encryption
@param source_length [in] Size of encryption data
@param dest [out] Buffer to place encrypted data (must be large enough)
@param dest_length [out] Pointer to size of encrypted data
@param key [in] Key to be used for encryption
@param key_length [in] Length of the key. 16, 24 or 32
@param iv [in] Iv to be used for encryption
@param iv_length [in] Length of the iv. should be 16.
@param noPadding [in] if set to true, no padding is used, input data size must be a mulitple of the AES block size

@return
!= 0 error
0 no error
*/
int my_aes_encrypt_cbc(const char* source, uint32 source_length,
char* dest, uint32 *dest_length,
const unsigned char* key, uint8 key_length,
const unsigned char* iv, uint8 iv_length,
int noPadding);


/**
* Calculate key and iv from a given salt and secret as it is handled in openssl encrypted files via console
*
* SYNOPSIS
* my_Bytes_To_Key()
* @param salt [in] the given salt as extracted from the encrypted file
* @param secret [in] the given secret as String, provided by the user
* @param key [out] 32 Bytes of key are written to this pointer
* @param iv [out] 16 Bytes of iv are written to this pointer
*/
void my_bytes_to_key(const unsigned char *salt,
const char *secret, unsigned char *key,
unsigned char *iv);
/**
Decode Hexencoded String to uint8[].
my_aes_hexToUint()
@param iv [in] Pointer to hexadecimal encoded IV String
@param dest [out] Pointer to output uint8 array. Memory needs to be allocated by caller
@param iv_length [in] Size of destination array.
*/
void my_aes_hexToUint(const char* in,
unsigned char *out,
int dest_length);

/*
my_aes_encrypt - Crypt buffer with AES encryption algorithm.
source - Pointer to data for encryption
Expand All @@ -41,6 +99,31 @@ C_MODE_START
int my_aes_encrypt(const char *source, int source_length, char *dest,
const char *key, int key_length);

/**
AES decryption - CBC mode

SYNOPSIS
my_aes_encrypt()
@param source [in] Pointer to data to decrypt
@param source_length [in] Size of data
@param dest [out] Buffer to place decrypted data (must be large enough)
@param dest_length [out] Pointer to size of decrypted data
@param key [in] Key to be used for decryption
@param key_length [in] Length of the key. 16, 24 or 32
@param iv [in] Iv to be used for encryption
@param iv_length [in] Length of the iv. should be 16.
@param noPadding [in] if set to true, no padding is used, input data size must be a mulitple of the AES block size

@return
!= 0 error
0 no error
*/
int my_aes_decrypt_cbc(const char* source, uint32 source_length,
char* dest, uint32 *dest_length,
const unsigned char* key, uint8 key_length,
const unsigned char* iv, uint8 iv_length,
int noPadding);

/*
my_aes_decrypt - DeCrypt buffer with AES encryption algorithm.
source - Pointer to data for decryption
Expand Down
3 changes: 3 additions & 0 deletions include/my_dbug.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ extern void _db_return_(uint _line_, struct _db_stack_frame_ *_stack_frame_);
extern void _db_pargs_(uint _line_,const char *keyword);
extern void _db_doprnt_(const char *format,...)
ATTRIBUTE_FORMAT(printf, 1, 2);

extern void dump_buffer(unsigned n, const unsigned char* buf);

extern void _db_dump_(uint _line_,const char *keyword,
const unsigned char *memory, size_t length);
extern void _db_end_(void);
Expand Down
3 changes: 3 additions & 0 deletions include/mysql/plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ enum enum_mysql_show_type
SHOW_always_last
};




/* backward compatibility mapping. */
#define SHOW_INT SHOW_UINT
#define SHOW_LONG SHOW_ULONG
Expand Down
20 changes: 20 additions & 0 deletions mysql-test/r/enc.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
DROP TABLE IF EXISTS t1;
DROP DATABASE IF EXISTS test;
CREATE DATABASE test;
USE test;
set @save_storage_engine= @@storage_engine;
set storage_engine=InnoDB;
CREATE TABLE t1 (id int)
PAGE_ENCRYPTION='abc';
ERROR HY000: Incorrect value 'abc' for option 'PAGE_ENCRYPTION'
CREATE TABLE t1 (id int)
PAGE_ENCRYPTION=1
PAGE_ENCRYPTION_KEY='0xFFC';
ERROR HY000: Incorrect value '0xFFC' for option 'PAGE_ENCRYPTION_KEY'
CREATE TABLE t1 (id int(11))
PAGE_ENCRYPTION=1
PAGE_ENCRYPTION_KEY=42;
INSERT INTO t1(id) values(1);
SELECT * FROM t1;
id
1
28 changes: 28 additions & 0 deletions mysql-test/t/enc.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-- source include/have_xtradb.inc

--disable_warnings
DROP TABLE IF EXISTS t1;
DROP DATABASE IF EXISTS test;
--enable_warnings

CREATE DATABASE test;
USE test;
set @save_storage_engine= @@storage_engine;
set storage_engine=InnoDB;

--error ER_BAD_OPTION_VALUE
CREATE TABLE t1 (id int)
PAGE_ENCRYPTION='abc';

--error ER_BAD_OPTION_VALUE
CREATE TABLE t1 (id int)
PAGE_ENCRYPTION=1
PAGE_ENCRYPTION_KEY='0xFFC';

CREATE TABLE t1 (id int(11))
PAGE_ENCRYPTION=1
PAGE_ENCRYPTION_KEY=42;

INSERT INTO t1(id) values(1);
SELECT * FROM t1;

4 changes: 2 additions & 2 deletions mysys/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ SET(MYSYS_SOURCES array.c charset-def.c charset.c checksum.c my_default.c
my_atomic.c my_getncpus.c my_safehash.c my_chmod.c my_rnd.c
my_uuid.c wqueue.c waiting_threads.c ma_dyncol.c
my_rdtsc.c my_context.c psi_noop.c
file_logger.c)
file_logger.c )

IF (WIN32)
SET (MYSYS_SOURCES ${MYSYS_SOURCES} my_winthread.c my_wincond.c my_winerr.c my_winfile.c my_windac.c my_conio.c)
Expand Down Expand Up @@ -70,7 +70,7 @@ IF(HAVE_MLOCK)
ENDIF()

ADD_CONVENIENCE_LIBRARY(mysys ${MYSYS_SOURCES})
TARGET_LINK_LIBRARIES(mysys dbug strings ${ZLIB_LIBRARY}
TARGET_LINK_LIBRARIES(mysys dbug strings mysys_ssl ${ZLIB_LIBRARY}
${LIBNSL} ${LIBM} ${LIBRT} ${LIBSOCKET} ${LIBEXECINFO})
DTRACE_INSTRUMENT(mysys)

Expand Down
Loading