forked from stefan-contiu/trusted-sharing
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathadmin_app.cpp
174 lines (134 loc) · 3.96 KB
/
admin_app.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*
* Admin Application. Untrusted Part.
* TODO :
* * move RedisCloud to own H file
* * construct a System Set-up method
* *
* * write methods to serialize
* * fill in the methods af admin api
*/
#include <cpp_redis/cpp_redis>
#include <iostream>
#include <string.h>
#include "pbc_ibbe/spibbe.h"
#include "pbc_ibbe/ibbe.h"
using namespace std;
class RedisCloud
{
private:
RedisCloud() {}
static cpp_redis::redis_client client;
public:
static void Init()
{
client.connect("127.0.0.1", 6379, [](cpp_redis::redis_client&) {
std::cout << "client disconnected (disconnection handler)" << std::endl;
});
}
static void Bye()
{
client.disconnect();
}
static void PutText(std::string key, std::string value)
{
client.set(key, value);
client.commit();
}
static std::string GetText(std::string key)
{
client.get(key, [](cpp_redis::reply& reply) {
return reply.as_string();
});
}
static void PutBinary(std::string key, unsigned char* data)
{
std::string s( reinterpret_cast< char const* >(data) ) ;
client.set(key, s);
client.commit();
}
static unsigned char* GetBinary(std::string key)
{
client.get(key, [](cpp_redis::reply& reply) {
unsigned char *val = new unsigned char[reply.as_string().length() + 1];
strcpy((char *)val, reply.as_string().c_str());
return val;
});
}
static void Commit()
{
client.sync_commit();
}
};
cpp_redis::redis_client RedisCloud::client;
class AdminApp
{
private:
int i;
public:
AdminApp()
{
// load the system public_key
// load the encrypted master key
}
void create_group(vector<string> user_names, string group_name);
void add_user_to_group(string user_name, string group_name);
void remove_user_from_group(string user_name, string group_name);
};
void AdminApp::create_group(vector<string> user_names, string group_name)
{
// TODO : ...
}
int test_redis()
{
std::cout << "REDIS CLOUD DEMO: " << std::endl;
RedisCloud::Init();
unsigned char a[] = {1, 2, 255, 4};
RedisCloud::PutBinary("stefan", a);
RedisCloud::Commit();
RedisCloud::GetBinary("stefan");
RedisCloud::Bye();
return 0;
}
unsigned char* serialize_public_key(PublicKey pk)
{
unsigned char* s = (unsigned char*) malloc(64);
return s;
}
unsigned char* serialize_short_public_key(ShortPublicKey spk)
{
unsigned char* s = (unsigned char*) malloc(64);
return s;
}
unsigned char* serialize_master_secret_key(MasterSecretKey msk)
{
unsigned char* s = (unsigned char*) malloc(64);
return s;
}
int system_setup_beginning_of_time(int max_users_per_partition, vector<string> admin_enclaves_pub_keys)
{
PublicKey pk;
ShortPublicKey spk;
MasterSecretKey msk;
int c = 1;
char* f = "a.param";
setup_sgx_safe(&pk, &spk, &msk, max_users_per_partition, c, &f);
// future improvement: the list of encalves_public_keys will be passed to the
// method above and therefore msk will come back encrypted
// serialize the keys
unsigned char* s_pk = serialize_public_key(pk);
unsigned char* s_spk = serialize_short_public_key(spk);
unsigned char* s_msk = serialize_master_secret_key(msk);
// store them on the cloud
RedisCloud::Init();
RedisCloud::PutBinary("pub_key", s_pk);
RedisCloud::PutBinary("short_pub_key", s_spk);
RedisCloud::PutBinary("master_secret_key", s_msk);
RedisCloud::Commit();
RedisCloud::Bye();
}
int main(void) {
//test_redis();
vector<string> enclave_pub_keys;
system_setup_beginning_of_time(100, enclave_pub_keys);
return 0;
}