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
90fd537c
Commit
90fd537c
authored
Jan 25, 2018
by
yiwenshao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add escape related
parent
b130e3aa
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
273 additions
and
3 deletions
+273
-3
fast_insert.cc
debug/fast_insert.cc
+1
-1
parser_stringify_test.cc
debug/parser_stringify_test.cc
+94
-0
parser_test_mysql_type_metadata.cc
debug/parser_test_mysql_type_metadata.cc
+97
-0
try_insert.cc
debug/try_insert.cc
+1
-1
Makefrag
test_wrapper/Makefrag
+7
-0
main.cc
test_wrapper/main.cc
+3
-0
reuse.cc
wrapper/reuse.cc
+54
-1
reuse.hh
wrapper/reuse.hh
+16
-0
No files found.
debug/fast_insert.cc
View file @
90fd537c
...
...
@@ -225,7 +225,7 @@ main(int argc,char**argv) {
SharedProxyState
*
shared_ps
=
new
SharedProxyState
(
ci
,
embeddedDir
,
master_key
,
determineSecurityRating
());
assert
(
shared_ps
!=
NULL
);
std
::
string
query1
=
"insert into
child
values(1,
\"
ZHAOYUN
\"
),(2,'XC'),(3,'KK')"
;
std
::
string
query1
=
"insert into
student
values(1,
\"
ZHAOYUN
\"
),(2,'XC'),(3,'KK')"
;
std
::
vector
<
std
::
string
>
querys
{
query1
};
for
(
auto
item
:
querys
){
std
::
cout
<<
item
<<
std
::
endl
;
...
...
debug/parser_stringify_test.cc
0 → 100644
View file @
90fd537c
#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 <main/rewrite_main.hh>
#include "wrapper/reuse.hh"
static
std
::
string
embeddedDir
=
"/t/cryt/shadow"
;
/*convert lex of insert into string*/
static
std
::
ostream
&
simple_insert
(
std
::
ostream
&
out
,
LEX
&
lex
){
String
s
;
THD
*
t
=
current_thd
;
const
char
*
cmd
=
"INSERT"
;
out
<<
cmd
<<
" "
;
lex
.
select_lex
.
table_list
.
first
->
print
(
t
,
&
s
,
QT_ORDINARY
);
out
<<
"INTO "
<<
s
;
out
<<
" values "
<<
noparen
(
lex
.
many_values
);
return
out
;
}
static
std
::
string
convert_insert
(
const
LEX
&
lex
)
{
std
::
ostringstream
o
;
simple_insert
(
o
,
const_cast
<
LEX
&>
(
lex
));
return
o
.
str
();
}
static
void
testInsertHandler
(
std
::
string
query
,
std
::
string
db
){
std
::
unique_ptr
<
Connect
>
e_conn
(
Connect
::
getEmbedded
(
embeddedDir
));
std
::
unique_ptr
<
SchemaInfo
>
schema
(
new
SchemaInfo
());
std
::
function
<
DBMeta
*
(
DBMeta
*
const
)
>
loadChildren
=
[
&
loadChildren
,
&
e_conn
](
DBMeta
*
const
parent
)
{
auto
kids
=
parent
->
fetchChildren
(
e_conn
);
for
(
auto
it
:
kids
)
{
loadChildren
(
it
);
}
return
parent
;
};
//load all metadata and then store it in schema
loadChildren
(
schema
.
get
());
const
std
::
unique_ptr
<
AES_KEY
>
&
TK
=
std
::
unique_ptr
<
AES_KEY
>
(
getKey
(
std
::
string
(
"113341234"
)));
//just like what we do in Rewrite::rewrite,dispatchOnLex
Analysis
analysis
(
std
::
string
(
db
),
*
schema
,
TK
,
SECURITY_RATING
::
SENSITIVE
);
std
::
unique_ptr
<
query_parse
>
p
;
p
=
std
::
unique_ptr
<
query_parse
>
(
new
query_parse
(
db
,
query
));
LEX
*
const
lex
=
p
->
lex
();
std
::
cout
<<
convert_insert
(
*
lex
)
<<
std
::
endl
;
}
int
main
(
int
argc
,
char
**
argv
)
{
char
*
buffer
;
if
((
buffer
=
getcwd
(
NULL
,
0
))
==
NULL
){
perror
(
"getcwd error"
);
}
embeddedDir
=
std
::
string
(
buffer
)
+
"/shadow"
;
if
(
argc
!=
2
){
assert
(
0
);
}
std
::
string
db
(
argv
[
1
]);
// initFileOnions("conf/already.cnf");
const
std
::
string
master_key
=
"113341234"
;
ConnectionInfo
ci
(
"localhost"
,
"root"
,
"letmein"
,
3306
);
SharedProxyState
*
shared_ps
=
new
SharedProxyState
(
ci
,
embeddedDir
,
master_key
,
determineSecurityRating
());
assert
(
shared_ps
!=
NULL
);
std
::
string
query1
(
"insert into student values(1,'a
\n
b
\n
d
\0\0
'); "
,
50
);
std
::
vector
<
std
::
string
>
querys
{
query1
};
for
(
auto
item
:
querys
){
std
::
cout
<<
item
<<
std
::
endl
;
testInsertHandler
(
item
,
db
);
std
::
cout
<<
std
::
endl
;
}
return
0
;
}
debug/parser_test_mysql_type_metadata.cc
0 → 100644
View file @
90fd537c
/*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 <stdlib.h>
#include <stdio.h>
#include <string>
#include <map>
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include "wrapper/reuse.hh"
#include "wrapper/common.hh"
#include "wrapper/insert_lib.hh"
#include "util/constants.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"
;
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
;
//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"
;
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
void
show
(
std
::
string
s
){
create_embedded_thd
(
0
);
Item
*
res
=
MySQLFieldTypeToItem
(
static_cast
<
enum_field_types
>
(
253
),
s
);
(
void
)
res
;
(
void
)(
res
->
name
);
//able to get the escapsed string
String
s2
;
const_cast
<
Item
&>
(
*
res
).
print
(
&
s2
,
QT_ORDINARY
);
(
void
)(
s2
.
ptr
());
std
::
string
ress
(
s2
.
ptr
(),
s2
.
length
());
std
::
cout
<<
ress
<<
std
::
endl
;
return
;
}
int
main
(
int
argc
,
char
*
argv
[]){
init
();
create_embedded_thd
(
0
);
std
::
string
db
=
"tdb"
,
table
=
"student"
;
std
::
string
ip
=
"localhost"
;
if
(
argc
==
4
){
ip
=
std
::
string
(
argv
[
1
]);
db
=
std
::
string
(
argv
[
2
]);
table
=
std
::
string
(
argv
[
3
]);
}
std
::
unique_ptr
<
SchemaInfo
>
schema
=
myLoadSchemaInfo
(
embeddedDir
);
schema
.
get
();
const
std
::
unique_ptr
<
AES_KEY
>
&
TK
=
std
::
unique_ptr
<
AES_KEY
>
(
getKey
(
std
::
string
(
"113341234"
)));
Analysis
analysis
(
db
,
*
schema
,
TK
,
SECURITY_RATING
::
SENSITIVE
);
(
void
)
analysis
;
std
::
string
s
(
"a
\n
b
\n
d
\0\0
"
,
7
);
std
::
string
s2
(
"a
\\
nb
\\
nd
\\
0
\\
0"
,
11
);
show
(
s
);
show
(
s2
);
return
0
;
}
debug/try_insert.cc
View file @
90fd537c
...
...
@@ -122,7 +122,7 @@ main() {
ConnectionInfo
ci
(
"localhost"
,
"root"
,
"letmein"
,
3306
);
SharedProxyState
*
shared_ps
=
new
SharedProxyState
(
ci
,
embeddedDir
,
master_key
,
determineSecurityRating
());
assert
(
shared_ps
!=
NULL
);
std
::
string
query1
=
"insert into
child
values(1,
\"
zhangfei
\"
)"
;
std
::
string
query1
=
"insert into
student
values(1,
\"
zhangfei
\"
)"
;
std
::
vector
<
std
::
string
>
querys
{
query1
};
for
(
auto
item
:
querys
){
std
::
cout
<<
item
<<
std
::
endl
;
...
...
test_wrapper/Makefrag
0 → 100644
View file @
90fd537c
OBJDIRS += test_wrapper
##note that xx=*.cc will not expand. wildcard *.cc will include files from other directories.
##%.o will include testall
TESTALL_OBJS := $(patsubst %.cc,$(OBJDIR)/%.o,$(wildcard test_wrapper/*.cc))
TESTALL_EXES := $(patsubst test_wrapper/%.cc,test_wrapper_exe/%,$(wildcard test_wrapper/*.cc))
all: $(TESTALL_OBJS) $(TESTALL_EXES)
test_wrapper/main.cc
0 → 100644
View file @
90fd537c
int
main
()
{
return
0
;
}
wrapper/reuse.cc
View file @
90fd537c
#include "wrapper/reuse.hh"
#include "util/util.hh"
#include <map>
using
std
::
cout
;
using
std
::
cin
;
...
...
@@ -432,6 +433,45 @@ write_row_data(rawMySQLReturnValue& resraw,std::string db,std::string table,std:
}
}
/* Write a column of data of the type string in mysql. one line per record.
string should be escaped before being written into the file */
void
writeRowdataEscapeString
(
const
std
::
vector
<
std
::
string
>
&
column
,
std
::
string
db
,
std
::
string
table
,
std
::
string
columnFilename
,
unsigned
int
maxLength
)
{
FILE
*
dataFileHandler
=
fopen
(
columnFilename
.
c_str
(),
"w"
);
char
*
buf
=
new
char
[
2
*
maxLength
+
1u
];
const
std
::
string
token
=
"
\n
"
;
for
(
auto
&
item
:
column
){
size_t
len
=
escape_string_for_mysql_modify
(
buf
,
item
.
c_str
(),
item
.
size
());
fwrite
(
buf
,
1
,
len
,
dataFileHandler
);
fwrite
(
token
.
c_str
(),
1
,
token
.
size
(),
dataFileHandler
);
}
fclose
(
dataFileHandler
);
delete
[]
buf
;
}
/* write a column of data in type integer.
one record per line
*/
void
writeRowdataNum
(
const
std
::
vector
<
std
::
string
>
&
column
,
std
::
string
db
,
std
::
string
table
,
std
::
string
columnFilename
)
{
FILE
*
dataFileHandler
=
fopen
(
columnFilename
.
c_str
(),
"w"
);
const
std
::
string
token
=
"
\n
"
;
for
(
auto
&
item
:
column
)
{
fwrite
(
item
.
c_str
(),
1
,
item
.
size
(),
dataFileHandler
);
fwrite
(
token
.
c_str
(),
1
,
token
.
size
(),
dataFileHandler
);
}
fclose
(
dataFileHandler
);
}
STORE_STRATEGY
currentStrategy
=
STORE_STRATEGY
::
ALL
;
...
...
@@ -489,6 +529,17 @@ void load_num_file(std::string filename,std::vector<std::string> &res){
infile
.
close
();
}
void
load_file_escape
(
std
::
string
filename
,
std
::
vector
<
std
::
string
>
&
res
)
{
std
::
ifstream
infile
(
filename
);
std
::
string
line
;
while
(
std
::
getline
(
infile
,
line
)){
res
.
push_back
(
std
::
move
(
line
));
}
infile
.
close
();
}
void
load_num_file_count
(
std
::
string
filename
,
std
::
vector
<
std
::
string
>
&
res
,
...
...
@@ -505,7 +556,9 @@ load_num_file_count(std::string filename,
infile
.
close
();
}
void
load_string_file
(
std
::
string
filename
,
std
::
vector
<
std
::
string
>
&
res
,
unsigned
long
length
){
void
load_string_file
(
std
::
string
filename
,
std
::
vector
<
std
::
string
>
&
res
,
unsigned
long
length
)
{
char
*
buf
=
new
char
[
length
];
int
fd
=
open
(
filename
.
c_str
(),
O_RDONLY
);
if
(
fd
==-
1
)
assert
(
0
);
//reading from -1 may cause errors
...
...
wrapper/reuse.hh
View file @
90fd537c
...
...
@@ -207,4 +207,20 @@ load_string_file_count(std::string filename,
void
load_file_escape
(
std
::
string
filename
,
std
::
vector
<
std
::
string
>
&
res
);
void
writeRowdataEscapeString
(
const
std
::
vector
<
std
::
string
>
&
column
,
std
::
string
db
,
std
::
string
table
,
std
::
string
columnFilename
,
unsigned
int
maxLength
);
void
writeRowdataNum
(
const
std
::
vector
<
std
::
string
>
&
column
,
std
::
string
db
,
std
::
string
table
,
std
::
string
columnFilename
);
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