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
86165e20
Commit
86165e20
authored
Jan 19, 2018
by
yiwenshao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
first version of reencryption in debug/loadtemp.cc
parent
4ebad9fe
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
143 additions
and
27 deletions
+143
-27
.loadstep.cc.swp
debug/.loadstep.cc.swp
+0
-0
loadstep.cc
debug/loadstep.cc
+37
-19
Makefrag
wrapper/Makefrag
+1
-1
insert_lib.cc
wrapper/insert_lib.cc
+69
-0
insert_lib.hh
wrapper/insert_lib.hh
+30
-0
reuse.cc
wrapper/reuse.cc
+4
-6
reuse.hh
wrapper/reuse.hh
+2
-1
No files found.
debug/.loadstep.cc.swp
deleted
100644 → 0
View file @
4ebad9fe
File deleted
debug/loadstep.cc
View file @
86165e20
...
...
@@ -13,6 +13,7 @@
#include <algorithm>
#include "wrapper/reuse.hh"
#include "wrapper/common.hh"
#include "wrapper/insert_lib.hh"
using
std
::
cout
;
using
std
::
cin
;
using
std
::
endl
;
...
...
@@ -175,12 +176,7 @@ static ResType load_files(std::string db="tdb", std::string table="student"){
auto
finalresults
=
decryptResults
(
rawtorestype
,
*
rm
);
return
finalresults
;
}
static
void
local_wrapper
(
const
Item
&
i
,
const
FieldMeta
&
fm
,
Analysis
&
a
,
List
<
Item
>
*
const
append_list
){
//为什么这里不是push item??
append_list
->
push_back
(
&
(
const_cast
<
Item
&>
(
i
)));
}
static
std
::
ostream
&
insert_list_show
(
std
::
ostream
&
out
,
List
<
List_item
>
&
newList
){
...
...
@@ -188,31 +184,53 @@ insert_list_show(std::ostream &out,List<List_item> &newList){
return
out
;
}
static
void
local_wrapper
(
const
Item
&
i
,
const
FieldMeta
&
fm
,
Analysis
&
a
,
List
<
Item
>
*
const
append_list
){
//为什么这里不是push item??
// append_list->push_back(&(const_cast<Item&>(i)));
//do not use the plain strategy
std
::
vector
<
Item
*>
l
;
my_typical_rewrite_insert_type
(
i
,
fm
,
a
,
&
l
);
for
(
auto
it
:
l
)
{
append_list
->
push_back
(
it
);
}
}
int
main
(
int
argc
,
char
*
argv
[]){
init
();
create_embedded_thd
(
0
);
std
::
string
db
=
"tdb"
,
table
=
"student"
;
/*load and decrypt*/
ResType
res
=
load_files
(
db
,
table
);
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
);
Analysis
analysis
(
db
,
*
schema
,
TK
,
SECURITY_RATING
::
SENSITIVE
);
/*choose decryption onion, load and decrypt to plain text*/
ResType
res
=
load_files
(
db
,
table
);
std
::
string
annoTableName
=
analysis
.
getTableMeta
(
db
,
table
).
getAnonTableName
();
const
std
::
string
head
=
std
::
string
(
"INSERT INTO `"
)
+
db
+
"`.`"
+
annoTableName
+
"` "
;
/*reencryption to get the encrypted insert!!!*/
for
(
auto
&
row
:
res
.
rows
){
List
<
List_item
>
newList
;
for
(
auto
field_name
:
res
.
names
){
std
::
cout
<<
field_name
<<
std
::
endl
;
FieldMeta
&
fm
=
analysis
.
getFieldMeta
(
db
,
table
,
field_name
);
List
<
Item
>
*
const
newList0
=
new
List
<
Item
>
();
local_wrapper
(
*
res
.
rows
[
0
][
0
],
fm
,
analysis
,
newList0
);
newList
.
push_back
(
newList0
);
for
(
auto
i
=
0u
;
i
<
res
.
names
.
size
();
i
++
){
std
::
string
field_name
=
res
.
names
[
i
];
FieldMeta
&
fm
=
analysis
.
getFieldMeta
(
db
,
table
,
field_name
);
local_wrapper
(
*
row
[
i
],
fm
,
analysis
,
newList0
);
}
newList
.
push_back
(
newList0
);
std
::
ostringstream
o
;
insert_list_show
(
o
,
newList
);
std
::
cout
<<
o
.
str
()
<<
std
::
endl
;
std
::
cout
<<
(
head
+
o
.
str
())
<<
std
::
endl
;
}
return
0
;
}
wrapper/Makefrag
View file @
86165e20
OBJDIRS += wrapper
WRAPPER_SRCS := common.cc reuse.cc
WRAPPER_SRCS := common.cc reuse.cc
insert_lib.cc
all: $(OBJDIR)/libwrapper.so
...
...
wrapper/insert_lib.cc
0 → 100644
View file @
86165e20
#include "wrapper/insert_lib.hh"
Item
*
my_encrypt_item_layers
(
const
Item
&
i
,
onion
o
,
const
OnionMeta
&
om
,
const
Analysis
&
a
,
uint64_t
IV
)
{
assert
(
!
RiboldMYSQL
::
is_null
(
i
));
const
auto
&
enc_layers
=
a
.
getEncLayers
(
om
);
assert_s
(
enc_layers
.
size
()
>
0
,
"onion must have at least one layer"
);
const
Item
*
enc
=
&
i
;
Item
*
new_enc
=
NULL
;
for
(
const
auto
&
it
:
enc_layers
)
{
new_enc
=
it
->
encrypt
(
*
enc
,
IV
);
assert
(
new_enc
);
enc
=
new_enc
;
}
assert
(
new_enc
&&
new_enc
!=
&
i
);
return
new_enc
;
}
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
;
}
std
::
string
convert_insert
(
const
LEX
&
lex
)
{
std
::
ostringstream
o
;
simple_insert
(
o
,
const_cast
<
LEX
&>
(
lex
));
return
o
.
str
();
}
void
my_typical_rewrite_insert_type
(
const
Item
&
i
,
const
FieldMeta
&
fm
,
Analysis
&
a
,
std
::
vector
<
Item
*>
*
l
)
{
const
uint64_t
salt
=
fm
.
getHasSalt
()
?
randomValue
()
:
0
;
uint64_t
IV
=
salt
;
for
(
auto
it
:
fm
.
orderedOnionMetas
())
{
const
onion
o
=
it
.
first
->
getValue
();
OnionMeta
*
const
om
=
it
.
second
;
l
->
push_back
(
my_encrypt_item_layers
(
i
,
o
,
*
om
,
a
,
IV
));
}
if
(
fm
.
getHasSalt
())
{
l
->
push_back
(
new
Item_int
(
static_cast
<
ulonglong
>
(
salt
)));
}
}
void
myRewriteInsertHelper
(
const
Item
&
i
,
const
FieldMeta
&
fm
,
Analysis
&
a
,
List
<
Item
>
*
const
append_list
){
std
::
vector
<
Item
*>
l
;
my_typical_rewrite_insert_type
(
i
,
fm
,
a
,
&
l
);
for
(
auto
it
:
l
)
{
append_list
->
push_back
(
it
);
}
}
wrapper/insert_lib.hh
0 → 100644
View file @
86165e20
#pragma once
#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>
Item
*
my_encrypt_item_layers
(
const
Item
&
i
,
onion
o
,
const
OnionMeta
&
om
,
const
Analysis
&
a
,
uint64_t
IV
);
std
::
ostream
&
simple_insert
(
std
::
ostream
&
out
,
LEX
&
lex
);
std
::
string
convert_insert
(
const
LEX
&
lex
);
void
my_typical_rewrite_insert_type
(
const
Item
&
i
,
const
FieldMeta
&
fm
,
Analysis
&
a
,
std
::
vector
<
Item
*>
*
l
);
void
myRewriteInsertHelper
(
const
Item
&
i
,
const
FieldMeta
&
fm
,
Analysis
&
a
,
List
<
Item
>
*
const
append_list
);
wrapper/reuse.cc
View file @
86165e20
...
...
@@ -383,7 +383,7 @@ write_row_data(rawMySQLReturnValue& resraw,std::string db,std::string table,std:
}
STORE_STRATEGY
currentStrategy
=
STORE_STRATEGY
::
FIRST
;
STORE_STRATEGY
currentStrategy
=
STORE_STRATEGY
::
ALL
;
/*storage used when we store*/
void
storeStrategies
(
std
::
vector
<
FieldMetaTrans
>&
res
){
...
...
@@ -394,8 +394,9 @@ void storeStrategies(std::vector<FieldMetaTrans>& res){
item
.
choose
(
in
);
}
}
else
if
(
currentStrategy
==
STORE_STRATEGY
::
ALL
){
for
(
auto
&
item
:
res
){
item
.
chooseAll
();
}
}
else
{
exit
(
0
);
}
...
...
@@ -427,6 +428,3 @@ int getDecryptionOnionIndex(FieldMetaTrans& fdtrans) {
return
res
;
}
wrapper/reuse.hh
View file @
86165e20
...
...
@@ -82,7 +82,7 @@ public:
void
trans
(
FieldMeta
*
fm
);
void
choose
(
std
::
vector
<
onion
>
onionSet
);
void
choose
(
std
::
vector
<
int
>
onionIndexSet
);
void
chooseAll
(){
choosenOnionO
=
onionsO
;
choosenOnionName
=
onionsName
;}
const
std
::
vector
<
std
::
string
>
getChoosenOnionName
(){
return
choosenOnionName
;}
void
setChoosenOnionName
(
const
std
::
vector
<
std
::
string
>
input
){
choosenOnionName
=
input
;}
...
...
@@ -154,3 +154,4 @@ enum class STORE_STRATEGY{
};
int
getDecryptionOnionIndex
(
FieldMetaTrans
&
fdtrans
);
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