Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
Practical-Cryptdb
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Zhaozhen
Practical-Cryptdb
Commits
7201cb3c
Commit
7201cb3c
authored
Mar 23, 2018
by
yiwenshao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add more tests
parent
4fb44f22
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
178 additions
and
27 deletions
+178
-27
memory_RND_int.cc
debug/memory_RND_int.cc
+102
-0
embedmysql.cc
parser/embedmysql.cc
+1
-1
embedmysql.hh
parser/embedmysql.hh
+2
-2
memory_check.cc
test_parser/memory_check.cc
+27
-0
parser.cc
test_parser/parser.cc
+33
-0
try_insert.cc
tools/try_insert.cc
+13
-24
No files found.
debug/memory_RND_int.cc
0 → 100644
View file @
7201cb3c
#include "parser/sql_utils.hh"
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include <map>
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include "main/CryptoHandlers.hh"
#include "wrapper/reuse.hh"
#include "wrapper/common.hh"
#include "wrapper/insert_lib.hh"
#include "util/constants.hh"
#include "util/timer.hh"
#include "util/log.hh"
#include "util/onions.hh"
using
std
::
cout
;
using
std
::
cin
;
using
std
::
endl
;
using
std
::
vector
;
using
std
::
string
;
using
std
::
to_string
;
static
std
::
string
embeddedDir
=
"/t/cryt/shadow"
;
static
std
::
map
<
std
::
string
,
WrapperState
*>
clients
;
//This connection mimics the behaviour of MySQL-Proxy
Connect
*
globalConn
;
/*for each field, convert the format to FieldMeta_Wrapper*/
static
void
init
(){
std
::
string
client
=
"192.168.1.1:1234"
;
//one Wrapper per user.
clients
[
client
]
=
new
WrapperState
();
//Connect phase
ConnectionInfo
ci
(
"localhost"
,
"root"
,
"letmein"
,
3306
);
const
std
::
string
master_key
=
"113341234"
;
char
*
buffer
;
if
((
buffer
=
getcwd
(
NULL
,
0
))
==
NULL
){
perror
(
"getcwd error"
);
}
embeddedDir
=
std
::
string
(
buffer
)
+
"/shadow"
;
free
(
buffer
);
SharedProxyState
*
shared_ps
=
new
SharedProxyState
(
ci
,
embeddedDir
,
master_key
,
determineSecurityRating
());
assert
(
0
==
mysql_thread_init
());
//we init embedded database here.
clients
[
client
]
->
ps
=
std
::
unique_ptr
<
ProxyState
>
(
new
ProxyState
(
*
shared_ps
));
clients
[
client
]
->
ps
->
safeCreateEmbeddedTHD
();
//Connect end!!
globalConn
=
new
Connect
(
ci
.
server
,
ci
.
user
,
ci
.
passwd
,
ci
.
port
);
}
static
Item
*
getItemInt
(
std
::
string
input
)
{
return
new
(
current_thd
->
mem_root
)
Item_int
(
static_cast
<
ulonglong
>
(
valFromStr
(
input
)));
}
static
Item
*
getItemIntNew
(
std
::
string
input
){
return
::
new
Item_int
(
static_cast
<
ulonglong
>
(
valFromStr
(
input
)));
}
static
Create_field
*
getUnsignedIntField
(){
Create_field
*
f
=
new
Create_field
;
f
->
sql_type
=
MYSQL_TYPE_LONG
;
f
->
flags
|=
UNSIGNED_FLAG
;
return
f
;
}
int
main
(
int
argc
,
char
**
argv
)
{
UNUSED
(
getItemInt
);
UNUSED
(
getItemIntNew
);
UNUSED
(
getUnsignedIntField
);
//still has 80B memory leak
init
();
create_embedded_thd
(
0
);
std
::
string
key
=
"key"
;
Create_field
*
cf
=
getUnsignedIntField
();
RND_int
*
ri
=
new
RND_int
(
*
cf
,
key
);
Item
*
plain
=
::
new
Item_int
(
static_cast
<
ulonglong
>
(
valFromStr
(
"123456789"
)));
// Item * plain = getItemIntNew("123456789");
// plain = getItemIntNew("1233344");
// Item * enc = NULL;
// Item * dec = NULL;
// enc = ri->encrypt(*plain,0u);
// dec = ri->decrypt(*enc,0u);
// delete ri;
// delete cf;
UNUSED
(
plain
);
UNUSED
(
cf
);
UNUSED
(
ri
);
return
0
;
}
//main/schema.cc:83 is use to create layers of encryption
parser/embedmysql.cc
View file @
7201cb3c
...
@@ -79,7 +79,7 @@ getInnoDBPlugin()
...
@@ -79,7 +79,7 @@ getInnoDBPlugin()
query_parse
::
query_parse
(
const
std
::
string
&
db
,
const
std
::
string
&
q
)
query_parse
::
query_parse
(
const
std
::
string
&
db
,
const
std
::
string
&
q
)
{
{
assert
(
create_embedded_thd
(
0
));
assert
(
create_embedded_thd
(
0
));
//
类内自带的THD* t结构
.
//
THD* t
.
t
=
current_thd
;
t
=
current_thd
;
assert
(
t
!=
NULL
);
assert
(
t
!=
NULL
);
...
...
parser/embedmysql.hh
View file @
7201cb3c
...
@@ -15,7 +15,7 @@ class query_parse {
...
@@ -15,7 +15,7 @@ class query_parse {
LEX
*
lex
();
LEX
*
lex
();
private
:
private
:
void
cleanup
();
void
cleanup
();
THD
*
t
;
THD
*
t
;
/*used to hold current_thd*/
Parser_state
ps
;
/*
这里包含了词法分析和语法分析时候, 使用的内部状态
*/
Parser_state
ps
;
/*
the internal state used by parser
*/
};
};
test_parser/memory_check.cc
0 → 100644
View file @
7201cb3c
#include <string>
#include <iostream>
#include <unistd.h>
#include <sys/types.h>
#include <dirent.h>
#include "parser/sql_utils.hh"
#include "parser/lex_util.hh"
#include "parser/embedmysql.hh"
#include "util/util.hh"
#include "util/constants.hh"
static
std
::
string
embeddedDir
=
"/t/cryt/shadow"
;
int
main
()
{
char
*
buffer
;
if
((
buffer
=
getcwd
(
NULL
,
0
))
==
NULL
){
perror
(
"getcwd error"
);
}
embeddedDir
=
std
::
string
(
buffer
)
+
"/shadow"
;
free
(
buffer
);
init_mysql
(
embeddedDir
);
//0;0;15,246,176
std
::
string
line
=
"show databases;"
;
std
::
unique_ptr
<
query_parse
>
p
;
p
=
std
::
unique_ptr
<
query_parse
>
(
new
query_parse
(
"tdb"
,
line
));
//0;0;15,246,552
UNUSED
(
p
);
return
0
;
}
test_parser/parser.cc
0 → 100644
View file @
7201cb3c
#include <string>
#include <iostream>
#include <vector>
#include <functional>
#include <unistd.h>
#include <sys/types.h>
#include <dirent.h>
#include <main/Connect.hh>
#include <main/rewrite_util.hh>
#include <main/sql_handler.hh>
#include <main/dml_handler.hh>
#include <main/ddl_handler.hh>
#include <main/CryptoHandlers.hh>
#include "util/util.hh"
#include "util/constants.hh"
static
std
::
string
embeddedDir
=
"/t/cryt/shadow"
;
int
main
()
{
char
*
buffer
;
if
((
buffer
=
getcwd
(
NULL
,
0
))
==
NULL
){
perror
(
"getcwd error"
);
}
embeddedDir
=
std
::
string
(
buffer
)
+
"/shadow"
;
free
(
buffer
);
// init_mysql(embeddedDir);
std
::
string
filename
=
std
::
string
(
cryptdb_dir
)
+
"/test_parser/"
+
"template"
;
std
::
string
line
=
"show databases;"
;
std
::
unique_ptr
<
query_parse
>
p
;
p
=
std
::
unique_ptr
<
query_parse
>
(
new
query_parse
(
"tdb"
,
line
));
LEX
*
const
lex
=
p
->
lex
();
UNUSED
(
lex
);
return
0
;
}
tools/try_insert.cc
View file @
7201cb3c
...
@@ -34,21 +34,13 @@ static std::string getInsertResults(Analysis a,LEX* lex){
...
@@ -34,21 +34,13 @@ static std::string getInsertResults(Analysis a,LEX* lex){
lex
->
select_lex
.
table_list
.
first
->
db
;
lex
->
select_lex
.
table_list
.
first
->
db
;
//from databasemeta to tablemeta.
//from databasemeta to tablemeta.
const
TableMeta
&
tm
=
a
.
getTableMeta
(
db_name
,
table
);
const
TableMeta
&
tm
=
a
.
getTableMeta
(
db_name
,
table
);
//rewrite table name
//rewrite table name
new_lex
->
select_lex
.
table_list
.
first
=
new_lex
->
select_lex
.
table_list
.
first
=
rewrite_table_list
(
lex
->
select_lex
.
table_list
.
first
,
a
);
rewrite_table_list
(
lex
->
select_lex
.
table_list
.
first
,
a
);
std
::
vector
<
FieldMeta
*>
fmVec
;
std
::
vector
<
FieldMeta
*>
fmVec
;
std
::
vector
<
Item
*>
implicit_defaults
;
// No field list, use the table order.
assert
(
fmVec
.
empty
());
std
::
vector
<
FieldMeta
*>
fmetas
=
tm
.
orderedFieldMetas
();
std
::
vector
<
FieldMeta
*>
fmetas
=
tm
.
orderedFieldMetas
();
fmVec
.
assign
(
fmetas
.
begin
(),
fmetas
.
end
());
fmVec
.
assign
(
fmetas
.
begin
(),
fmetas
.
end
());
if
(
lex
->
many_values
.
head
())
{
if
(
lex
->
many_values
.
head
())
{
//start processing many values
auto
it
=
List_iterator
<
List_item
>
(
lex
->
many_values
);
auto
it
=
List_iterator
<
List_item
>
(
lex
->
many_values
);
List
<
List_item
>
newList
;
List
<
List_item
>
newList
;
for
(;;)
{
for
(;;)
{
...
@@ -58,34 +50,27 @@ static std::string getInsertResults(Analysis a,LEX* lex){
...
@@ -58,34 +50,27 @@ static std::string getInsertResults(Analysis a,LEX* lex){
}
}
List
<
Item
>
*
const
newList0
=
new
List
<
Item
>
();
List
<
Item
>
*
const
newList0
=
new
List
<
Item
>
();
if
(
li
->
elements
!=
fmVec
.
size
())
{
if
(
li
->
elements
!=
fmVec
.
size
())
{
TEST_TextMessageError
(
0
==
li
->
elements
exit
(
0
);
&&
NULL
==
lex
->
field_list
.
head
(),
"size mismatch between fields"
" and values!"
);
}
else
{
}
else
{
auto
it0
=
List_iterator
<
Item
>
(
*
li
);
auto
it0
=
List_iterator
<
Item
>
(
*
li
);
auto
fmVecIt
=
fmVec
.
begin
();
auto
fmVecIt
=
fmVec
.
begin
();
for
(;;)
{
for
(;;)
{
const
Item
*
const
i
=
it0
++
;
const
Item
*
const
i
=
it0
++
;
assert
(
!!
i
==
(
fmVec
.
end
()
!=
fmVecIt
));
assert
(
!!
i
==
(
fmVec
.
end
()
!=
fmVecIt
));
if
(
!
i
)
{
if
(
!
i
)
{
break
;
break
;
}
}
//fetch values, and use fieldMeta to facilitate rewrite
//every filed should be encrypted with onions of encryption
myRewriteInsertHelper
(
*
i
,
**
fmVecIt
,
a
,
newList0
);
myRewriteInsertHelper
(
*
i
,
**
fmVecIt
,
a
,
newList0
);
++
fmVecIt
;
++
fmVecIt
;
}
}
for
(
auto
def_it
:
implicit_defaults
)
{
newList0
->
push_back
(
def_it
);
}
}
}
newList
.
push_back
(
newList0
);
newList
.
push_back
(
newList0
);
}
}
new_lex
->
many_values
=
newList
;
new_lex
->
many_values
=
newList
;
}
}
return
lexToQuery
(
*
new_lex
);
return
lexToQuery
(
*
new_lex
);
return
"aa"
;
}
}
...
@@ -106,11 +91,14 @@ static void testInsertHandler(std::string query){
...
@@ -106,11 +91,14 @@ static void testInsertHandler(std::string query){
//just like what we do in Rewrite::rewrite,dispatchOnLex
//just like what we do in Rewrite::rewrite,dispatchOnLex
Analysis
analysis
(
std
::
string
(
"tdb"
),
*
schema
,
TK
,
Analysis
analysis
(
std
::
string
(
"tdb"
),
*
schema
,
TK
,
SECURITY_RATING
::
SENSITIVE
);
SECURITY_RATING
::
SENSITIVE
);
(
void
)
analysis
;
std
::
unique_ptr
<
query_parse
>
p
;
std
::
unique_ptr
<
query_parse
>
p
;
p
=
std
::
unique_ptr
<
query_parse
>
(
p
=
std
::
unique_ptr
<
query_parse
>
(
new
query_parse
(
"tdb"
,
query
));
new
query_parse
(
"tdb"
,
query
));
LEX
*
const
lex
=
p
->
lex
();
LEX
*
const
lex
=
p
->
lex
();
std
::
cout
<<
getInsertResults
(
analysis
,
lex
)
<<
std
::
endl
;
std
::
cout
<<
getInsertResults
(
analysis
,
lex
)
<<
std
::
endl
;
(
void
)
lex
;
}
}
int
int
...
@@ -132,13 +120,14 @@ main() {
...
@@ -132,13 +120,14 @@ main() {
assert
(
shared_ps
!=
NULL
);
assert
(
shared_ps
!=
NULL
);
UNUSED
(
testInsertHandler
);
UNUSED
(
testInsertHandler
);
UNUSED
(
getInsertResults
);
UNUSED
(
getInsertResults
);
// std::string query1 = "insert into student values(1,\"zhangfei\")";
std
::
string
query1
=
"insert into student values(1,
\"
zhangfei
\"
)"
;
/* std::vector<std::string> querys{query1};
std
::
vector
<
std
::
string
>
queries
{
query1
};
for(auto item:querys){
for
(
unsigned
int
i
=
0u
;
i
<
100u
;
i
++
){
std::cout<<item<<std::endl;
//queries.push_back(query1);
}
for
(
auto
item
:
queries
){
testInsertHandler
(
item
);
testInsertHandler
(
item
);
std::cout<<std::endl;
}
}
*/
return
0
;
return
0
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment