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
a9b370a2
Commit
a9b370a2
authored
May 25, 2017
by
Casualet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
able to quota string
parent
ed43ac52
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
250 additions
and
9 deletions
+250
-9
Makefrag
main/Makefrag
+1
-1
mbk.cc
main/mbk.cc
+82
-8
test_layer.cc
main/test_layer.cc
+8
-0
test_schema.cc
main/test_schema.cc
+159
-0
.main.cc.swp
packages/tls/mysqlWrapper/.main.cc.swp
+0
-0
No files found.
main/Makefrag
View file @
a9b370a2
...
...
@@ -7,7 +7,7 @@ CRYPTDB_SRCS := schema.cc Translator.cc Connect.cc \
rewrite_func.cc rewrite_sum.cc metadata_tables.cc \
error.cc stored_procedures.cc rewrite_ds.cc rewrite_main.cc
CRYPTDB_PROGS:= cdb_test mbk test_layer
CRYPTDB_PROGS:= cdb_test mbk test_layer
test_schema
CRYPTDBPROGOBJS := $(patsubst %,$(OBJDIR)/main/%,$(CRYPTDB_PROGS))
...
...
main/mbk.cc
View file @
a9b370a2
...
...
@@ -501,6 +501,58 @@ std::string getBackupQuery(SchemaInfo &schema, std::vector<transField> &tfds,
return
res
;
}
static
std
::
string
getBackupQueryWithoutSalt
(
SchemaInfo
&
schema
,
std
::
vector
<
transField
>
&
tfds
,
std
::
string
db
=
"tdb"
,
std
::
string
table
=
"student1"
)
{
std
::
string
res
=
"SELECT "
;
const
std
::
unique_ptr
<
IdentityMetaKey
>
dbmeta_key
(
new
IdentityMetaKey
(
db
));
//get databaseMeta, search in the map
DatabaseMeta
*
dbm
=
schema
.
getChild
(
*
dbmeta_key
);
const
TableMeta
&
tbm
=
*
((
*
dbm
).
getChild
(
IdentityMetaKey
(
table
)));
std
::
string
annotablename
=
tbm
.
getAnonTableName
();
int
numOfChoosenField
=
0
;
//then a list of onion names
for
(
auto
item
:
tfds
){
for
(
auto
index
:
item
.
choosenOnions
){
res
+=
item
.
fields
[
index
];
res
+=
" , "
;
numOfChoosenField
++
;
}
}
res
=
res
.
substr
(
0
,
res
.
size
()
-
2
);
res
=
res
+
"FROM `"
+
db
+
std
::
string
(
"`.`"
)
+
annotablename
+
"` limit 1;"
;
rawReturnValue
resraw
=
executeAndGetResultRemote
(
globalConn
,
res
);
assert
(
numOfChoosenField
==
(
int
)
resraw
.
fieldTypes
.
size
());
vector
<
bool
>
whetherToQuote
;
for
(
auto
i
=
0u
;
i
<
resraw
.
fieldTypes
.
size
();
i
++
){
if
(
IS_NUM
(
resraw
.
fieldTypes
[
i
]))
whetherToQuote
.
push_back
(
false
);
else
whetherToQuote
.
push_back
(
true
);
}
int
fieldIndex
=
0
;
res
=
"SELECT "
;
for
(
auto
item
:
tfds
){
for
(
auto
index
:
item
.
choosenOnions
){
if
(
whetherToQuote
[
fieldIndex
]){
res
+=
string
(
"QUOTE("
)
+
item
.
fields
[
index
]
+
")"
;
res
+=
" , "
;
}
else
{
res
+=
item
.
fields
[
index
];
res
+=
" , "
;
}
fieldIndex
++
;
}
}
res
+=
"FROM `"
+
db
+
std
::
string
(
"`.`"
)
+
annotablename
+
"`"
;
return
res
;
}
static
std
::
string
getInsertQuery
(
SchemaInfo
&
schema
,
std
::
vector
<
transField
>
&
tfds
,
std
::
string
db
,
std
::
string
table
,
rawReturnValue
&
rows
){
...
...
@@ -577,10 +629,15 @@ std::string getTestQuery(SchemaInfo &schema, std::vector<transField> &tfds,
int
main
(
int
argc
,
char
*
argv
[])
{
if
(
argc
!=
3
){
if
(
argc
!=
4
){
for
(
int
i
=
0
;
i
<
argc
;
i
++
){
printf
(
"%s
\n
"
,
argv
[
i
]);
}
cout
<<
"./mbk dbname tablename option"
"0. back up and decrypt"
"1. back up all"
"2. back up the first onion with out dealing with quote "
"3. back up the first onion while dealing with quote "
<<
endl
;
return
0
;
}
gmp
[
SECLEVEL
::
INVALID
]
=
"INVALID"
;
...
...
@@ -621,11 +678,8 @@ main(int argc, char* argv[]) {
//Connect end!!
globalConn
=
new
Connect
(
ci
.
server
,
ci
.
user
,
ci
.
passwd
,
ci
.
port
);
//-------------------------finish connection---------------------------------------
std
::
string
curQuery
=
"backpart"
;
//unsigned long long _thread_id = globalConn->get_thread_id();
if
(
curQuery
!=
"quit"
){
if
(
curQuery
==
"test"
){
if
(
string
(
argv
[
3
])
==
"0"
){
std
::
string
db
,
table
;
std
::
cout
<<
"please input dbname "
<<
std
::
endl
;
cin
>>
db
;
...
...
@@ -644,7 +698,7 @@ main(int argc, char* argv[]) {
ResType
rawtorestype
=
MygetResTypeFromLuaTable
(
false
,
&
resraw
);
auto
finalresults
=
decryptResults
(
rawtorestype
,
*
rm
);
parseResType
(
finalresults
);
}
else
if
(
curQuery
==
"backall
"
){
}
else
if
(
string
(
argv
[
3
])
==
"1
"
){
std
::
string
db
,
table
;
std
::
cout
<<
"please input dbname "
<<
std
::
endl
;
cin
>>
db
;
...
...
@@ -668,7 +722,7 @@ main(int argc, char* argv[]) {
cout
<<
backq
<<
endl
;
rawReturnValue
resraw
=
executeAndGetResultRemote
(
globalConn
,
backq
);
getInsertQuery
(
*
schema
,
res
,
db
,
table
,
resraw
);
}
else
if
(
curQuery
==
"backpart
"
){
}
else
if
(
string
(
argv
[
3
])
==
"2
"
){
std
::
string
db
(
argv
[
1
]),
table
(
argv
[
2
]);
std
::
cout
<<
db
<<
":"
<<
table
<<
std
::
endl
;
std
::
unique_ptr
<
SchemaInfo
>
schema
=
myLoadSchemaInfo
();
...
...
@@ -687,7 +741,27 @@ main(int argc, char* argv[]) {
cout
<<
backq
<<
endl
;
rawReturnValue
resraw
=
executeAndGetResultRemote
(
globalConn
,
backq
);
getInsertQuery
(
*
schema
,
res
,
db
,
table
,
resraw
);
}
else
if
(
string
(
argv
[
3
])
==
"3"
){
std
::
string
db
(
argv
[
1
]),
table
(
argv
[
2
]);
std
::
cout
<<
db
<<
":"
<<
table
<<
std
::
endl
;
std
::
unique_ptr
<
SchemaInfo
>
schema
=
myLoadSchemaInfo
();
//get all the fields in the tables.
std
::
vector
<
FieldMeta
*>
fms
=
getFieldMeta
(
*
schema
,
db
,
table
);
auto
res
=
getTransField
(
fms
);
//for each filed, we choose all the onions and salts.
for
(
auto
&
item
:
res
){
assert
(
item
.
choosenOnions
.
size
()
==
0u
);
assert
(
item
.
onions
.
size
()
==
item
.
originalOm
.
size
());
assert
(
item
.
fields
.
size
()
==
item
.
originalOm
.
size
()
||
item
.
fields
.
size
()
==
item
.
originalOm
.
size
()
+
1
);
item
.
choosenOnions
.
push_back
(
0
);
}
std
::
string
backq
=
getBackupQueryWithoutSalt
(
*
schema
,
res
,
db
,
table
);
cout
<<
backq
<<
endl
;
//rawReturnValue resraw = executeAndGetResultRemote(globalConn,backq);
//getInsertQuery(*schema,res,db,table,resraw);
}
}
return
0
;
}
main/test_layer.cc
View file @
a9b370a2
...
...
@@ -360,6 +360,13 @@ void testEncrypt2(SchemaInfo &schema){
cout
<<
string
(
s
.
ptr
(),
s
.
length
())
<<
endl
;
}
static
void
myAdjustOnion
(){
}
int
main
(
int
argc
,
char
*
argv
[])
{
...
...
@@ -430,5 +437,6 @@ main(int argc, char* argv[]) {
assert
(
thd
);
testEncrypt
(
*
schema
);
testEncrypt2
(
*
schema
);
myAdjustOnion
();
return
0
;
}
main/test_schema.cc
0 → 100644
View file @
a9b370a2
#include <cstdlib>
#include <cstdio>
#include <string>
#include <map>
#include <iostream>
#include <fstream>
#include <sstream>
#include <stdexcept>
#include <vector>
#include <set>
#include <list>
#include <algorithm>
#include <functional>
#include <cctype>
#include <locale>
#include <unistd.h>
#include <sys/types.h>
#include <dirent.h>
#include <main/Connect.hh>
#include <main/rewrite_main.hh>
#include <main/rewrite_util.hh>
#include <main/sql_handler.hh>
#include <main/dml_handler.hh>
#include <main/ddl_handler.hh>
#include <main/metadata_tables.hh>
#include <main/macro_util.hh>
#include <main/CryptoHandlers.hh>
#include <parser/embedmysql.hh>
#include <parser/stringify.hh>
#include <parser/lex_util.hh>
#include <readline/readline.h>
#include <readline/history.h>
#include <crypto/ecjoin.hh>
#include <util/errstream.hh>
#include <util/cryptdb_log.hh>
#include <util/enum_text.hh>
#include <util/yield.hpp>
#include "util/onions.hh"
#include <sstream>
#include <map>
std
::
map
<
SECLEVEL
,
std
::
string
>
gmp
;
static
std
::
string
embeddedDir
=
"/t/cryt/shadow"
;
static
void
processLayers
(
const
EncLayer
&
enc
){
//std::cout<<enc.serialize(enc)<<std::endl;
std
::
cout
<<
enc
.
name
()
<<
std
::
endl
;
}
static
void
processOnionMeta
(
const
OnionMeta
&
onion
){
std
::
cout
<<
GREEN_BEGIN
<<
"PRINT OnionMeta"
<<
COLOR_END
<<
std
::
endl
;
std
::
cout
<<
"onionmeta->getAnonOnionName(): "
<<
onion
.
getAnonOnionName
()
<<
std
::
endl
;
auto
&
layers
=
onion
.
getLayers
();
for
(
auto
&
slayer
:
layers
){
processLayers
(
*
(
slayer
.
get
()));
}
}
static
void
processFieldMeta
(
const
FieldMeta
&
field
){
std
::
cout
<<
GREEN_BEGIN
<<
"PRINT FieldMeta"
<<
COLOR_END
<<
std
::
endl
;
for
(
const
auto
&
onion
:
field
.
getChildren
()){
std
::
cout
<<
onion
.
second
->
getDatabaseID
()
<<
":"
<<
onion
.
first
.
getValue
()
<<
std
::
endl
;
processOnionMeta
(
*
(
onion
.
second
));
}
}
static
void
processTableMeta
(
const
TableMeta
&
table
){
std
::
cout
<<
GREEN_BEGIN
<<
"PRINT TableMeta"
<<
COLOR_END
<<
std
::
endl
;
for
(
const
auto
&
field
:
table
.
getChildren
()){
std
::
cout
<<
"fieldmeta->stringify: "
<<
field
.
second
->
stringify
()
<<
std
::
endl
;
std
::
cout
<<
"fieldmeta->stringify: "
<<
field
.
second
->
getFieldName
()
<<
std
::
endl
;
std
::
cout
<<
field
.
second
->
getDatabaseID
()
<<
":"
<<
field
.
first
.
getValue
()
<<
std
::
endl
;
processFieldMeta
(
*
(
field
.
second
));
}
}
static
void
processDatabaseMeta
(
const
DatabaseMeta
&
db
)
{
std
::
cout
<<
GREEN_BEGIN
<<
"PRINT DatabaseMeta"
<<
COLOR_END
<<
std
::
endl
;
for
(
const
auto
&
table
:
db
.
getChildren
()){
std
::
cout
<<
table
.
second
->
getDatabaseID
()
<<
":"
<<
table
.
first
.
getValue
()
<<
":"
<<
table
.
first
.
getSerial
()
<<
std
::
endl
;
std
::
cout
<<
"tableMeta->getAnonTableName: "
<<
table
.
second
->
getAnonTableName
()
<<
std
::
endl
;
processTableMeta
(
*
(
table
.
second
));
}
}
static
void
processSchemaInfo
(
SchemaInfo
&
schema
){
//we have a map here
std
::
cout
<<
GREEN_BEGIN
<<
"PRINT SchemaInfo"
<<
COLOR_END
<<
std
::
endl
;
//only const auto & is allowed, now copying. or we meet use of deleted function.
for
(
const
auto
&
child
:
schema
.
getChildren
())
{
std
::
cout
<<
child
.
second
->
getDatabaseID
()
<<
":"
<<
child
.
first
.
getValue
()
<<
":"
<<
child
.
first
.
getSerial
()
<<
std
::
endl
;
processDatabaseMeta
(
*
(
child
.
second
));
}
}
static
std
::
unique_ptr
<
SchemaInfo
>
myLoadSchemaInfo
()
{
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
());
//Analysis analysis(std::string("student"),*schema,std::unique_ptr<AES_KEY>(getKey(std::string("113341234"))),
// SECURITY_RATING::SENSITIVE);
//test_Analysis(analysis);
return
schema
;
}
int
main
()
{
gmp
[
SECLEVEL
::
INVALID
]
=
"INVALID"
;
gmp
[
SECLEVEL
::
PLAINVAL
]
=
"PLAINVAL"
;
gmp
[
SECLEVEL
::
OPE
]
=
"OPE"
;
gmp
[
SECLEVEL
::
DETJOIN
]
=
"DETJOIN"
;
gmp
[
SECLEVEL
::
OPEFOREIGN
]
=
"OPEFOREIGN"
;
gmp
[
SECLEVEL
::
DET
]
=
"DET"
;
gmp
[
SECLEVEL
::
SEARCH
]
=
"SEARCH"
;
gmp
[
SECLEVEL
::
HOM
]
=
"HOM"
;
gmp
[
SECLEVEL
::
RND
]
=
"RND"
;
char
*
buffer
;
if
((
buffer
=
getcwd
(
NULL
,
0
))
==
NULL
){
perror
(
"getcwd error"
);
}
embeddedDir
=
std
::
string
(
buffer
)
+
"/shadow"
;
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
::
unique_ptr
<
SchemaInfo
>
schema
=
myLoadSchemaInfo
();
processSchemaInfo
(
*
schema
);
return
0
;
}
packages/tls/mysqlWrapper/.main.cc.swp
0 → 100644
View file @
a9b370a2
File added
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