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
e4f54f44
Commit
e4f54f44
authored
Jan 07, 2018
by
yiwenshao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify debug/test_load_schema
parent
257981b5
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
87 additions
and
41 deletions
+87
-41
test_load_schema.cc
debug/test_load_schema.cc
+12
-14
in.sql
in.sql
+10
-0
Connect.hh
main/Connect.hh
+2
-0
load_and_store.cc
main/load_and_store.cc
+59
-26
schema.hh
main/schema.hh
+3
-1
MyConnect.h
packages/tls/mysql_wrapper/mysqllib/MyConnect.h
+1
-0
No files found.
debug/test_load_schema.cc
View file @
e4f54f44
...
...
@@ -94,25 +94,23 @@ static std::unique_ptr<SchemaInfo> myLoadSchemaInfo(){
return
schema
;
}
static
void
init_embedded_db
(){
std
::
string
client
=
"192.168.1.1:1234"
;
ConnectionInfo
ci
(
"localhost"
,
"root"
,
"letmein"
,
3306
);
const
std
::
string
master_key
=
"113341234"
;
SharedProxyState
*
shared_ps
=
new
SharedProxyState
(
ci
,
embeddedDir
,
master_key
,
determineSecurityRating
());
(
void
)
shared_ps
;
}
int
main
()
{
char
*
buffer
;
if
((
buffer
=
getcwd
(
NULL
,
0
))
==
NULL
){
perror
(
"getcwd error"
);
}
embeddedDir
=
std
::
string
(
buffer
)
+
"/shadow"
;
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"
;
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!!
embeddedDir
=
std
::
string
(
buffer
)
+
"/shadow"
;
//init embedded db
init_embedded_db
();
std
::
unique_ptr
<
SchemaInfo
>
sm
=
myLoadSchemaInfo
();
processSchemaInfo
(
*
sm
);
return
0
;
...
...
in.sql
0 → 100644
View file @
e4f54f44
INSERT
INTO
`student`
VALUES
(
1
,
"shao"
),(
2
,
"shao"
),(
3
,
"shao"
),(
4
,
"shao"
);
INSERT
INTO
`student`
VALUES
(
1
,
"shao"
),(
2
,
"shao"
),(
3
,
"shao"
),(
4
,
"shao"
);
INSERT
INTO
`student`
VALUES
(
1
,
"shao"
),(
2
,
"shao"
),(
3
,
"shao"
),(
4
,
"shao"
);
INSERT
INTO
`student`
VALUES
(
1
,
"shao"
),(
2
,
"shao"
),(
3
,
"shao"
),(
4
,
"shao"
);
INSERT
INTO
`student`
VALUES
(
1
,
"shao"
),(
2
,
"shao"
),(
3
,
"shao"
),(
4
,
"shao"
);
INSERT
INTO
`student`
VALUES
(
1
,
"shao"
),(
2
,
"shao"
),(
3
,
"shao"
),(
4
,
"shao"
);
INSERT
INTO
`student`
VALUES
(
1
,
"shao"
),(
2
,
"shao"
),(
3
,
"shao"
),(
4
,
"shao"
);
INSERT
INTO
`student`
VALUES
(
1
,
"shao"
),(
2
,
"shao"
),(
3
,
"shao"
),(
4
,
"shao"
);
INSERT
INTO
`student`
VALUES
(
1
,
"shao"
),(
2
,
"shao"
),(
3
,
"shao"
),(
4
,
"shao"
);
INSERT
INTO
`student`
VALUES
(
1
,
"shao"
),(
2
,
"shao"
),(
3
,
"shao"
),(
4
,
"shao"
);
main/Connect.hh
View file @
e4f54f44
...
...
@@ -68,6 +68,8 @@ class Connect {
uint64_t
get_affected_rows
();
MYSQL
*
get_conn
(){
return
conn
;}
~
Connect
();
private
:
...
...
main/load_and_store.cc
View file @
e4f54f44
/*1. store data as column files, and restore data as plaintext insert query
* 2. plaintext insert query should be able to recover directly
* 3. should be able to used exsisting data to reduce the computation overhead(to be implemented)
*/
#include <cstdlib>
#include <cstdio>
#include <string>
...
...
@@ -65,6 +69,9 @@ using std::to_string;
static
std
::
string
embeddedDir
=
"/t/cryt/shadow"
;
char
*
globalEsp
=
NULL
;
int
num_of_pipe
=
4
;
//global map, for each client, we have one WrapperState which contains ProxyState.
static
std
::
map
<
std
::
string
,
WrapperState
*>
clients
;
...
...
@@ -117,7 +124,7 @@ void rawMySQLReturnValue::show(){
//must be static, or we get "no previous declaration"
//execute the query and getthe rawReturnVale, this struct can be copied.
//execute the query and get
the rawReturnVale, this struct can be copied.
static
rawMySQLReturnValue
executeAndGetResultRemote
(
Connect
*
curConn
,
std
::
string
query
){
std
::
unique_ptr
<
DBResult
>
dbres
;
...
...
@@ -162,6 +169,7 @@ rawMySQLReturnValue executeAndGetResultRemote(Connect * curConn,std::string quer
return
myRaw
;
}
//helper function for transforming the rawMySQLReturnValue
static
Item_null
*
...
...
@@ -205,8 +213,8 @@ ResType MygetResTypeFromLuaTable(bool isNULL,rawMySQLReturnValue *inRow = NULL,i
}
rows
.
push_back
(
curTempRow
);
}
uint64_t
afrow
=
globalConn
->
get_affected_rows
();
std
::
cout
<<
GREEN_BEGIN
<<
"Affected rows: "
<<
afrow
<<
COLOR_END
<<
std
::
endl
;
//
uint64_t afrow = globalConn->get_affected_rows();
//
std::cout<<GREEN_BEGIN<<"Affected rows: "<<afrow<<COLOR_END<<std::endl;
return
ResType
(
true
,
0
,
in_last_insert_id
,
std
::
move
(
names
),
std
::
move
(
types
),
std
::
move
(
rows
));
...
...
@@ -214,22 +222,22 @@ ResType MygetResTypeFromLuaTable(bool isNULL,rawMySQLReturnValue *inRow = NULL,i
}
//printResType for testing purposes
static
void
parseResType
(
const
ResType
&
rd
)
{
std
::
cout
<<
RED_BEGIN
<<
"rd.affected_rows: "
<<
rd
.
affected_rows
<<
COLOR_END
<<
std
::
endl
;
std
::
cout
<<
RED_BEGIN
<<
"rd.insert_id: "
<<
rd
.
insert_id
<<
COLOR_END
<<
std
::
endl
;
for
(
auto
name
:
rd
.
names
){
std
::
cout
<<
name
<<
"
\t
"
;
}
std
::
cout
<<
std
::
endl
;
for
(
auto
row
:
rd
.
rows
){
for
(
auto
item
:
row
){
std
::
cout
<<
ItemToString
(
*
item
)
<<
"
\t
"
;
}
std
::
cout
<<
std
::
endl
;
}
}
//
static
//
void parseResType(const ResType &rd) {
////
std::cout<<RED_BEGIN<<"rd.affected_rows: "<<rd.affected_rows<<COLOR_END<<std::endl;
////
std::cout<<RED_BEGIN<<"rd.insert_id: "<<rd.insert_id<<COLOR_END<<std::endl;
//
//
for(auto name:rd.names){
//
std::cout<<name<<"\t";
//
}
//
std::cout<<std::endl;
//
for(auto row:rd.rows){
//
for(auto item:row){
//
std::cout<<ItemToString(*item)<<"\t";
//
}
//
std::cout<<std::endl;
//
}
//
}
//first step of back
static
std
::
vector
<
FieldMeta
*>
getFieldMeta
(
SchemaInfo
&
schema
,
std
::
string
db
=
"tdb"
,
...
...
@@ -440,10 +448,17 @@ ResType decryptResults(const ResType &dbres, const ReturnMeta &rmeta) {
}
col_index
++
;
}
std
::
vector
<
enum_field_types
>
types
;
for
(
auto
item
:
dec_rows
[
0
]){
types
.
push_back
(
item
->
field_type
());
}
//resType is used befor and after descrypting.
return
ResType
(
dbres
.
ok
,
dbres
.
affected_rows
,
dbres
.
insert_id
,
std
::
move
(
dec_names
),
std
::
vector
<
enum_field_types
>
(
dbres
.
types
),
std
::
vector
<
enum_field_types
>
(
types
),
//different from previous version
std
::
move
(
dec_rows
));
}
...
...
@@ -738,6 +753,14 @@ static ResType load_files(std::string db="tdb", std::string table="student"){
std
::
vector
<
FieldMeta
*>
fms
=
getFieldMeta
(
*
schema
,
db
,
table
);
auto
res
=
getTransField
(
fms
);
std
::
vector
<
enum_field_types
>
types
;
//Added
for
(
auto
item
:
fms
){
types
.
push_back
(
item
->
getSqlType
());
}
//Add new field form FieldMeta
if
(
types
.
size
()
==
1
){
//to be
}
meta_file
res_meta
=
load_meta
(
db
,
table
);
for
(
unsigned
int
i
=
0
;
i
<
res_meta
.
choosen_onions
.
size
();
i
++
){
...
...
@@ -758,7 +781,7 @@ static ResType load_files(std::string db="tdb", std::string table="student"){
}
ResType
rawtorestype
=
MygetResTypeFromLuaTable
(
false
,
&
resraw2
);
auto
finalresults
=
decryptResults
(
rawtorestype
,
*
rm
);
parseResType
(
finalresults
);
//
parseResType(finalresults);
return
finalresults
;
}
...
...
@@ -825,7 +848,7 @@ static void add(rawMySQLReturnValue & str,ResType & item ){
static
void
construct_insert
(
rawMySQLReturnValue
&
str
,
std
::
string
table
,
std
::
vector
<
string
>
&
res
){
std
::
string
head
=
string
(
"INSERT INTO `"
)
+
table
+
"` VALUES "
;
int
num_of_pipe
=
3
;
int
cnt
=
0
;
string
cur
=
head
;
for
(
unsigned
int
i
=
0u
;
i
<
str
.
rowValues
.
size
();
i
++
){
...
...
@@ -833,12 +856,15 @@ static void construct_insert(rawMySQLReturnValue & str,std::string table,std::ve
cur
+=
"("
;
for
(
unsigned
int
j
=
0u
;
j
<
str
.
rowValues
[
i
].
size
();
j
++
){
if
(
IS_NUM
(
str
.
fieldTypes
[
j
]))
{
cout
<<
str
.
fieldTypes
[
j
]
<<
endl
;
//
cout<<str.fieldTypes[j]<<endl;
cur
+=
str
.
rowValues
[
i
][
j
]
+=
","
;
cout
<<
"isnum"
<<
endl
;
//
cout<<"isnum"<<endl;
}
else
{
cur
+=
string
(
"
\"
"
)
+=
str
.
rowValues
[
i
][
j
]
+=
"
\"
,"
;
cout
<<
"notnum"
<<
endl
;
//cur+=string("\"")+=str.rowValues[i][j]+="\",";
int
len
=
str
.
rowValues
[
i
][
j
].
size
();
mysql_real_escape_string
(
globalConn
->
get_conn
(),
globalEsp
,
str
.
rowValues
[
i
][
j
].
c_str
(),
len
);
cur
+=
string
(
"
\"
"
)
+=
string
(
globalEsp
)
+=
"
\"
,"
;
}
}
cur
.
back
()
=
')'
;
...
...
@@ -866,6 +892,12 @@ main(int argc, char* argv[]) {
std
::
string
option
(
argv
[
1
]);
std
::
string
db
=
"tdb"
,
table
=
"student"
;
globalEsp
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
5000
);
if
(
globalEsp
==
NULL
){
printf
(
"unable to allocate esp
\n
"
);
return
0
;
}
if
(
option
==
"store"
){
store
(
db
,
table
);
}
else
if
(
option
==
"load"
){
...
...
@@ -879,5 +911,6 @@ main(int argc, char* argv[]) {
cout
<<
item
<<
endl
;
}
}
free
(
globalEsp
);
return
0
;
}
main/schema.hh
View file @
e4f54f44
...
...
@@ -134,6 +134,8 @@ public:
bool
getHasSalt
()
const
{
return
has_salt
;}
const
std
::
string
getFieldName
()
const
{
return
fname
;}
enum_field_types
getSqlType
(){
return
sql_type
;}
//ADDED BY SHAOYIWEN
private
:
const
std
::
string
fname
;
const
std
::
string
salt_name
;
...
...
@@ -149,7 +151,7 @@ private:
enum
enum_field_types
sql_type
;
SECLEVEL
getOnionLevel
(
onion
o
)
const
;
enum_field_types
getSqlType
(){
return
sql_type
;}
static
onionlayout
determineOnionLayout
(
const
AES_KEY
*
const
m_key
,
const
Create_field
&
f
,
...
...
packages/tls/mysql_wrapper/mysqllib/MyConnect.h
View file @
e4f54f44
...
...
@@ -87,6 +87,7 @@ class Connect {
uint64_t
get_affected_rows
();
void
get_version
();
void
finish_with_error
(
MYSQL
*
con
,
bool
close
=
true
);
MYSQL
*
get_conn
(){
return
conn
;}
~
Connect
();
private
:
MYSQL
*
conn
;
...
...
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