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
00035 #ifdef FADE_EVAL
00036 #include <sys/timeb.h>
00037 #endif
00038
00039 using namespace std;
00040
00041 static const int SECRET_LENGTH = 64;
00042 static const int COMMAND_BUFFER_LENGTH = 256;
00043
00047 class Client
00048 {
00049 int sockfd;
00050 string path;
00051 string ephemerizerAddress;
00052 vector<Storage *> storages;
00053 string secretFile;
00054 unsigned char secret[SECRET_LENGTH];
00055 Client() {}
00056 ~Client()
00057 {
00058 for (vector<Storage *>::const_iterator it = storages.begin(); it != storages.end(); ++it)
00059 {
00060 delete *it;
00061 }
00062 }
00063 void closeSocket() const;
00064 void encrypt(const string &filename, const unsigned char *key) const;
00065 void decrypt(const string &filename, const unsigned char *key) const;
00066 bool checkHMAC(const string &filename) const;
00067 void getFile(const string &filename, const string& ext) const;
00068 void putFile(const string &filename, const string& ext) const;
00069 public:
00074 static Client *instance();
00075
00080 string getPath() const
00081 {
00082 return path;
00083 }
00084
00089 void setPath(const string &path)
00090 {
00091 this->path = path;
00092 }
00093
00098 void setEphemerizerAddress(const string &address)
00099 {
00100 ephemerizerAddress = address;
00101 }
00102
00107 void addLocalStorage(const char *dir)
00108 {
00109 storages.push_back(new LocalStorage(dir));
00110 }
00111
00116 void addS3Storage(const char *bucket)
00117 {
00118 storages.push_back(new S3Storage(bucket));
00119 }
00120
00125 void setSecretFile(const string &secretFile)
00126 {
00127 this->secretFile = secretFile;
00128 }
00129
00136 bool upload(const string &filename, char *policyName);
00137
00143 bool download(const string &filename);
00144
00151 bool renew(const string &filename, const char *newPolicyName);
00152
00157 bool generateSecret();
00158
00163 void readConfig(const char *filename)
00164 {
00165 ClientConfig::parse(filename);
00166 }
00167
00171 void readSecret();
00172
00181 unsigned int interact(const unsigned char *request, unsigned int requestLength, unsigned char *response, unsigned int responseLength);
00182 #ifdef FADE_EVAL
00183 timeb encStartTime, encEndTime;
00184 timeb hmacStartTime, hmacEndTime;
00185 timeb allStartTime, allEndTime;
00186 timeb fileStartTime, fileEndTime;
00187 timeb metaStartTime, metaEndTime;
00188 timeb metaStartTime2, metaEndTime2;
00189 #endif
00190 };
00191
00192 #endif