00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00026 #ifndef FADE_CLIENT_H
00027 #define FADE_CLIENT_H
00028
00029 #include <string>
00030 #include <vector>
00031 #include "LocalStorage.h"
00032 #include "S3Storage.h"
00033 #include "ClientConfig.h"
00034 #include "../common/Common.h"
00035
00036 #ifdef FADE_EVAL
00037 #include <sys/timeb.h>
00038 #endif
00039
00040 using namespace std;
00041
00042 static const int SECRET_LENGTH = 64;
00043
00047 class Client
00048 {
00049 int sockfd;
00050 string path;
00051 vector<pair<string, int> > ephemerizerAddress;
00052 vector<Storage *> storages;
00053 string secretFile;
00054 unsigned char secret[SECRET_LENGTH];
00055 int ssss_threshold;
00056 int ssss_number;
00057 string cpabe_pubkey_file;
00058 string cpabe_privkey_file;
00059 Client()
00060 : ssss_threshold(1), ssss_number(1)
00061 {
00062 }
00063 ~Client()
00064 {
00065 for (vector<Storage *>::const_iterator it = storages.begin(); it != storages.end(); ++it)
00066 {
00067 delete *it;
00068 }
00069 }
00070 void closeSocket() const;
00071 void encrypt(const string &filename, const unsigned char *key) const;
00072 void decrypt(const string &filename, const unsigned char *key) const;
00073 bool checkHMAC(const string &filename) const;
00074 void getFile(const string &filename, const string& ext) const;
00075 void putFile(const string &filename, const string& ext) const;
00076 public:
00081 static Client *instance();
00082
00087 string getPath() const
00088 {
00089 return path;
00090 }
00091
00096 void setPath(const string &path)
00097 {
00098 this->path = path;
00099 }
00100
00105 void addEphemerizerAddress(const string &address)
00106 {
00107 size_t colon = address.find(':');
00108 ephemerizerAddress.push_back(make_pair(address.substr(0, colon), atoi(address.substr(colon + 1).c_str())));
00109 }
00110
00115 void addLocalStorage(const char *dir)
00116 {
00117 storages.push_back(new LocalStorage(dir));
00118 }
00119
00124 void addS3Storage(const char *bucket)
00125 {
00126 storages.push_back(new S3Storage(bucket));
00127 }
00128
00133 void setSecretFile(const string &secretFile)
00134 {
00135 this->secretFile = secretFile;
00136 }
00137
00142 void setThreshold(int threshold)
00143 {
00144 ssss_threshold = threshold;
00145 }
00146
00151 void setNumber(int number)
00152 {
00153 ssss_number = number;
00154 }
00155
00160 string getCpabePublicKeyFile() const
00161 {
00162 return cpabe_pubkey_file;
00163 }
00164
00169 void setCpabePublicKeyFile(const string &filename)
00170 {
00171 cpabe_pubkey_file = filename;
00172 }
00173
00178 string getCpabePrivateKeyFile() const
00179 {
00180 return cpabe_privkey_file;
00181 }
00182
00187 void setCpabePrivateKeyFile(const string &filename)
00188 {
00189 cpabe_privkey_file = filename;
00190 }
00191
00198 bool upload(const string &filename, char *policyName);
00199
00205 bool download(const string &filename);
00206
00213 bool renew(const string &filename, const char *newPolicyName);
00214
00220 bool revoke(const char *policyName);
00221
00226 bool generateSecret();
00227
00232 void readConfig(const char *filename)
00233 {
00234 ClientConfig::parse(filename);
00235 }
00236
00240 void readSecret();
00241
00251 unsigned int interact(const unsigned char *request, unsigned int requestLength, unsigned char *response, unsigned int responseLength, int keyManagerID = 0);
00252 #ifdef FADE_EVAL
00253 timeb allStartTime, allEndTime;
00254 timeb fileStartTime, fileEndTime;
00255 timeb metaStartTime, metaEndTime;
00256 timeb metaStartTime2, metaEndTime2;
00257 #endif
00258 };
00259
00260 #endif