42
MySQL 과 MariaDB 과 과과 과과과 과과과 과과 , Engine Level Encryption 과과과 과과 / D’Amo 과과 2 과 Penta Security Systems Inc.

DEVIEW 2013 Presentation

Embed Size (px)

DESCRIPTION

Presentation for DEVIEW 2013, developer conference by NHN. This session have introduced encryption technology, engine-level encryption for MySQL & MariaDB. This is main technology of MyDiamo. Although this is Korean one, you can understand what we said. See more at http://www.mydiamo.com Thanks.

Citation preview

Page 1: DEVIEW 2013 Presentation

MySQL 과 MariaDB 를 위한 새로운 암호화 방법 ,

Engine Level Encryption

박광근 팀장 / D’Amo 개발 2 팀Penta Security Systems Inc.

Page 2: DEVIEW 2013 Presentation

CONTENTS1. 개발 배경

2. 개발 방향 & OSS 와의 관계

3. Encryption Engine 구조 및 소스

4. What’s Next?

Page 3: DEVIEW 2013 Presentation

0. 시작하기에 앞서…

Page 4: DEVIEW 2013 Presentation

1. 개발 배경

Page 5: DEVIEW 2013 Presentation

1. 개발 배경

암호화를 위한 고려사항

보안 , 성능 , 기능 을 고려하여 암호화를 해야 한다 .

보안(Security)

성능(Perfor-

mance)

기능(Functionality)

DBMS 암호화

Page 6: DEVIEW 2013 Presentation

1. 개발 배경

IT 시스템 구조

CLIENT DATABASEAS(Application Server)

SERVER

Page 7: DEVIEW 2013 Presentation

사용자 인증 암호화

전송 구간 암호화

주요 파일 암호화

암호화 키 안전한 관리( 저장 및 접근제어 )

1. 개발 배경

암호화 종류

사용자 인증 암호화

전송 구간 암호화

주요 파일 암호화

암호화 키 안전한 관리( 저장 및 접근제어 )

사용자 인증 암호화

개인정보 암호화암호화된 데이터 접근제어

암호화 키 안전한 관리( 저장 및 접근제어 )

사용자 인증 암호화

구간 암호화

DBMS 암호화

키 관리

파일 암호화

암호화 종류

CLIENT DATABASEAS(Application Server)

SERVER

Page 8: DEVIEW 2013 Presentation

DATABASEAS(Application Server)

SERVER

1. 개발 배경

DBMS 암호화 방식

DBMS 암호화 종류

Application API암호화

Plug-in 암호화

Engine Level암호화

Database API암호화

Page 9: DEVIEW 2013 Presentation

1. 개발 배경

DBMS 암호화 방식

DBMS 암호화 종류 – 암호화 단위

Column-Level 암호화File-Level 암호화

Page 10: DEVIEW 2013 Presentation

1. 개발 배경

DBMS 암호화 방식

DBMS 암호화 종류 – 암호화 장소

1. Application API 암호화

Application Server 소스를

수정하여 암호화

2. Database API 암호화

Database 소스를 수정하여 암호화

3. Plug-in 암호화

Database 서버 내부에 암호화

모듈을 삽입하여 암호화

4. Engine Level 암호화

Database 내부에 암호화 Engine

을 삽입하여 암호화

DATABASEAS(Application Server)

SERVER

API Application암호화

Plug-in 암호화Engine Level

암호화

Database API암호화

Page 11: DEVIEW 2013 Presentation

1. 개발 배경

Engine Level 암호화

기존 Database Level Encryption 이 존재

ex) TDE (Transparent Database Encryption)

DATABASEEncryptedDATABASE

TDE

Page 12: DEVIEW 2013 Presentation

1. 개발 배경

Engine Level 암호화

기존 Database Level Encryption 의 한계

What can I encrypt and decrypt?

Who can encrypt and decrypt?

When can I encrypt and decrypt?

Who manage the encryption key?

Encryption is not Security

Page 13: DEVIEW 2013 Presentation

1. 개발 배경

암호화는 보안이 아닌가 ?

접근제어 , 감사 , 안전한 키 관리가 가능할 때 , 암호화는 보안이 될 수 있다 .

KeyData

Encryption

AccessControl

Audit

Page 14: DEVIEW 2013 Presentation

1. 개발 배경

Open Source Database, MySQL & MariaDB (1/3)

내부 소스가 공개된 Open Source DB 인 MySQL 와 MariaDB 는 좀 더 효율적인

암호화 소프트웨어 개발 가능

MySQL & MariaDB 에 가장 최적화된 암호화 방식은 Engine Level Encryption

Page 15: DEVIEW 2013 Presentation

1. 개발 배경

Open Source Database, MySQL & MariaDB (2/3)

Applica-tion

Applica-tion

Applica-tion

MySQL Server

Storage En-gine

Data

Page 16: DEVIEW 2013 Presentation

1. 개발 배경

Open Source Database, MySQL & MariaDB (3/3)

암호화 엔진 (Encryption Engine) 을 내부에 삽입하는 방식

MySQL Server

Storage En-gine

Data

Applica-tion

Applica-tion

Applica-tion

Encryption Engine

Page 17: DEVIEW 2013 Presentation

1. 개발 배경

Engine Level Encryption for MySQL & MariaDB

자체 개발 Encryption Engine 을 통한 안전한 암호화 제공 가능

Encryption

Access Con-trol

Audit

Key Manage-ment

Page 18: DEVIEW 2013 Presentation

2. 개발 방향 & OSS 와의 관계

Page 19: DEVIEW 2013 Presentation

2. 개발 방향 & OSS 와의 관계

MySQL 과 MariaDB 의 라이선스 정책

MySQL GPL 라이선스

GPL LGPL BSD MPL QPL/상용QT

코드의 무료 이용 O O O O O/X

코드의 자유 배포 O O O O O/X

소스 코드의 공개 O O O O O/X

소스 코드의 수정 O O O O O/O

수정 코드의 소스 공개 O O X O O/X

상용 소프트웨어와의 링크 X O O O X/O

Page 20: DEVIEW 2013 Presentation

2. 개발 방향 & OSS 와의 관계

MySQL 과 MariaDB 의 라이선스 정책 활용

암호화 엔진 오픈 소스

암호화 엔진 + 암호 모듈 프리웨어

Page 21: DEVIEW 2013 Presentation

3. Encryption Engine 구조 및 소스

Page 22: DEVIEW 2013 Presentation

3. Encryption Engine 구조 및 소스

Application API 암호화 방식

ENC = Enc_Str(‘700101-1234567’)INSERT INTO TABLE(SSN) VALUE (ENC)

SELECT SSN as ENC_SSN FROM TABLE SSN = Dec_Str(ENC_SSN)

8078DE5E30D1C706BCE816D6759CBDFE

‘700101-1234567’ 입력

‘700101-1234567’ 조회

CLIENTDATABASEAS

(Application Server)

SERVER

Page 23: DEVIEW 2013 Presentation

3. Encryption Engine 구조 및 소스

Database API 암호화 방식

INSERT INTO TABLE(SSN) VALUE (ENC_UDF(‘700101-1234567’))

SELECT DEC_UDF(SSN) FROM TA-BLE

8078DE5E30D1C706BCE816D6759CBDFE

‘700101-1234567’ 입력

‘700101-1234567’ 조회

CLIENTDATABASEAS

(Application Server)

SERVER

Page 24: DEVIEW 2013 Presentation

3. Encryption Engine 구조 및 소스

INSERT INTO TABLE(SSN) VALUE (AES_Encrypt(‘700101-1234567’, ‘KEY’))

SELECT AES_Decrypt(SSN, ‘KEY’) FROM TABLE

8078DE5E30D1C706BCE816D6759CBDFE

‘700101-1234567’ 입력

‘700101-1234567’ 조회

CLIENTDATABASEAS

(Application Server)

SERVER

Database API 암호화 방식 : MySQL 과 MariaDB 기본 암호화 함수

Page 25: DEVIEW 2013 Presentation

3. Encryption Engine 구조 및 소스

Plug-in 암호화 방식

INSERT INTO TABLE(SSN) VALUE (‘700101-1234567’)

SELECT SSN FROM TABLE

8078DE5E30D1C706BCE816D6759CBDFE

‘700101-1234567’ 입력

‘700101-1234567’ 출력

INSERT INTO TABLE(SSN) VALUE(ENC_UDF(‘700101-1234567’)

SELECT DEC_UDF(SSN) FROM TABLE

CLIENTDATABASEAS

(Application Server)

SERVER

Page 26: DEVIEW 2013 Presentation

3. Encryption Engine 구조 및 소스

Engine Level 암호화 방식 : Encryption Engine

INSERT INTO TABLE(SSN) VALUE (‘700101-1234567’)

SELECT SSN FROM TABLE

8078DE5E30D1C706BCE816D6759CBDFE

‘700101-1234567’ 입력

‘700101-1234567’ 출력

CLIENTDATABASEAS

(Application Server)

SERVER

Page 27: DEVIEW 2013 Presentation

Storage EngineStorage Engine

3. Encryption Engine 구조 및 소스

Encryption Engine 구조

MyISAM InnoDB …

MySQL Server

Data

Encryption Engine

MyISAM InnoDB …

MySQL Server

Encrypted Data & Data

Page 28: DEVIEW 2013 Presentation

3. Encryption Engine 구조 및 소스

Encryption Engine : 데이터 처리 방법

• Record 단위로 처리• 컬럼 타입

• VARCHAR : 컬럼길이 + 데이터• 컬럼 사이즈가 256 이상일 경우 : 컬럼길이 (2byte)+ 데이터• 컬럼 사이즈가 256 미만일 경우 : 컬럼길이 (1byte)+ 데이터

• CHAR• 컬럼 사이즈

• 예 ) CREATE TABLE MEMBER ( C1 VARCHAR(20), C2 CHAR(10) );• INSERT INTO MEMBER VALUES ( ‘1234’, ‘12345’);• 0x 04 31323334 31323334352020202020• 컬럼길이 ‘ 1234’ ‘12345 ’

Page 29: DEVIEW 2013 Presentation

3. Encryption Engine 구조 및 소스

Encryption Engine : 암호화 함수 1

bool ha_example::encData(TABLE *table, uchar *buf){ unsigned int fieldCount = table->s->fields; for (unsigned int i = 0; i < fieldCount; i++) { Field *field = table->field[i];

if (!checkAccessPrivilege(field->field_index)) return false; if (!isEncryptedColumn(field->field_index)) continue; if (!checkEncPrivilege(field->field_index)) return false;

암호화 함수 2 } return true;}

Page 30: DEVIEW 2013 Presentation

3. Encryption Engine 구조 및 소스

Encryption Engine : 암호화 함수 2

Field *field = table->field[i]; uchar* record = table->record[0]; uint offset = field->offset(record); enum_field_types type = (enum_field_types) field->type();

switch (type) { case MYSQL_TYPE_VARCHAR: { data_length = *(buf + offset); dataPos = buf + offset + 1;

outLen = encDataVar(field->field_index, dataPos, data_length, out);

*(buf + offset) = (uchar) (outLen & 0xFF); memcpy(dataPos, (uchar*) out, (size_t) outLen); break; } }

Page 31: DEVIEW 2013 Presentation

3. Encryption Engine 구조 및 소스

Encryption Engine : 데이터 입력 ( INSERT )

Int ha_example::write_row(uchar *buf){ int error = HA_ERR_INTERNAL_ERROR;

if ( encData(table, buf) ) error = storage_handler->write_row(buf);

return error;}

Page 32: DEVIEW 2013 Presentation

3. Encryption Engine 구조 및 소스

Encryption Engine : 데이터 조회 ( SELECT )

Int ha_example::rnd_next(uchar *buf){ int error = 0;

error = storage_handler->rnd_next(buf) if ( error ) return error;

if ( !decData(table, buf) ) { return HA_ERR_INTERNAL_ERROR; }

return error;}

Page 33: DEVIEW 2013 Presentation

3. Encryption Engine 구조 및 소스

Encryption Engine : 데이터 수정 ( UPDATE )

int ha_example::update_row(const uchar *old_data, uchar *new_data){ int error = HA_ERR_INTERNAL_ERROR; uchar* tmpBuf = (uchar*) malloc(table->s->reclength); memcpy(tmpBuf, old_data, table->s->reclength);

if (encData(table, new_data)) { if (encData(table, tmpBuf)) { error = storage_handler->update_row(tmpBuf, new_data); } }

free(tmpBuf); return error;}

Page 34: DEVIEW 2013 Presentation

3. Encryption Engine 구조 및 소스

Encryption Engine : 데이터 검색 조회 ( WHERE ) – INDEX 없을 경우

Int ha_example::rnd_next(uchar *buf){ int error = 0;

error = storage_handler->rnd_next(buf) if ( error ) return error;

if ( !decData(table, buf) ) { return HA_ERR_INTERNAL_ERROR; }

return error;}

Page 35: DEVIEW 2013 Presentation

3. Encryption Engine 구조 및 소스

Encryption Engine : 데이터 검색 조회 ( WHERE ) – INDEX 있을 경우

int ha_damo::index_read_map(uchar *buf, const uchar *key, key_part_map keypart_map, enum ha_rkey_function find_flag){ int error = 0; int keyLen = calculate_key_len(table, active_index, key, keypart_map); uchar* keyTmp = (uchar*) malloc(keyLen); memcpy(keyTmp, key, keyLen); if ( !keyEncrypt(active_index, keyTemp, keyLen) ) return HA_ERR_INTERNAL_ERROR;

error = storage_handler->index_read_map(buf, keyTemp, keypart_map, find_flag)

if (error) return error;

if ( !decData(table, buf) ) return HA_ERR_INTERNAL_ERROR;

return 0;}

Page 36: DEVIEW 2013 Presentation

3. Encryption Engine 구조 및 소스

Encryption Engine : 데이터 삭제 ( DELETE )

int ha_example::delete_row(const uchar *buf){ int error = HA_ERR_INTERNAL_ERROR;

uchar* tmpBuf = (uchar*) malloc(table->s->reclength); memcpy(tmpBuf, buf, table->s->reclength);

if (encData(table, tmpBuf)) { error = storage_handler->delete_row(tmpBuf); }

free(tmpBuf); return error;}

Page 37: DEVIEW 2013 Presentation

3. Encryption Engine 구조 및 소스

Custom Storage Engine 관련 자료

• MySQL Source • storage/example/ha_example.h• storage/example/ha_example.cc

• MySQL Dev Page• Storage Engine

• http://dev.mysql.com/doc/refman/5.1/en/storage-engines.html• Custom Storage Engine

• http://dev.mysql.com/doc/internals/en/custom-engine.html • Data Type Storage Requirements

• http://dev.mysql.com/doc/refman/5.1/en/storage-requirements.html

Page 38: DEVIEW 2013 Presentation

4. What’s Next?

Page 39: DEVIEW 2013 Presentation

4. What’s Next?

현재 상황

비상업적 개인을 대상으로 프리웨어로 배포 중

Page 40: DEVIEW 2013 Presentation

4. What’s Next?

미래 계획

다른 OSS DB 에 대한 개발도 검토중

Page 41: DEVIEW 2013 Presentation

Q&A

Page 42: DEVIEW 2013 Presentation

THANK YOU