Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 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
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.cproject
.project
Debug/*
*-t
*.a
*.ctest
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,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, " ");
int 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
63 changes: 63 additions & 0 deletions include/my_aes.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#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

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

Expand All @@ -27,6 +32,47 @@ C_MODE_START

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


/*
my_aes_encrypt_cbc- Crypt buffer with AES encryption algorithm using cbc mode.
source - Pointer to data for encryption
source_length - size of encryption data
dest - buffer to place encrypted data (must be large enough)
key - Key to be used for encryption
kel_length - Length of the key. Will handle keys of any length

returns - size of encrypted data, or negative in case of error.
*/
int my_aes_encrypt_cbc(const char* source, unsigned long int source_length,
char* dest, unsigned long int *dest_length,
const unsigned char* key, uint8 key_length,
const unsigned char* iv, uint8 iv_length);


/**
* 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 +87,23 @@ C_MODE_START
int my_aes_encrypt(const char *source, int source_length, char *dest,
const char *key, int key_length);

/*
my_aes_decrypt_cbc - DeCrypt buffer with AES encryption algorithm using
cbc Mode.
source - Pointer to data for decryption
source_length - size of encrypted data
dest - buffer to place decrypted data (must be large enough)
key - Key to be used for decryption
kel_length - Length of the key. Will handle keys of any length

returns - size of original data, or negative in case of error.
*/

int my_aes_decrypt_cbc(const char* source, unsigned long int source_length,
char* dest, unsigned long int *dest_length,
const unsigned char* key, uint8 key_length,
const unsigned char* iv, uint8 iv_length);

/*
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
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 @@ -39,7 +39,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 @@ -68,7 +68,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