diff --git a/client/ip.php b/client/ip.php deleted file mode 100644 index adaf8a1..0000000 --- a/client/ip.php +++ /dev/null @@ -1,2 +0,0 @@ - { + this.initStatus.keyInit = true; + this.initCheck(); + }); FileCache.initCache( // SUCCESS @@ -50,6 +54,6 @@ class Entrypoint { } private static ready(): void { - + alert("ready"); } } \ No newline at end of file diff --git a/client/src/FileCache.ts b/client/src/FileCache.ts index 0382740..044d9b8 100644 --- a/client/src/FileCache.ts +++ b/client/src/FileCache.ts @@ -1,7 +1,9 @@ class FileCache { private static dbHandle: IDBDatabase = null; - public static initCache(success: ()=>void, error: (error: string)=>void): void { + public static initCache(success: ()=>void, + error: (error: string)=>void): void + { var request = window.indexedDB.open("fileCache", 3); request.onupgradeneeded = (event: any) => { @@ -16,12 +18,15 @@ class FileCache { if(db.objectStoreNames.contains("hashes")) db.deleteObjectStore("hashes"); - db.createObjectStore("files", {keyPath: "name", autoIncrement: false}); - db.createObjectStore("metadata", {keyPath: "name", autoIncrement: false}); + db.createObjectStore("files", + {keyPath: "name", autoIncrement: false}); + db.createObjectStore("metadata", + {keyPath: "name", autoIncrement: false}); }; request.onerror = (event: any) => { - error("Could not upgrade the client database to the most recent version."); + error("Could not upgrade the client database " + +"to the most recent version."); }; request.onsuccess = (event: any) => { @@ -30,7 +35,9 @@ class FileCache { }; } - public static getMeta(fileName: string, success: (meta: FileMeta)=>void, error: (error: string)=>void): void { + public static getMeta(fileName: string, success: (meta: FileMeta)=>void, + error: (error: string)=>void): void + { var query = this.dbHandle.transaction("metadata"); var store = query.objectStore("metadata"); var request = store.get(fileName); @@ -50,7 +57,10 @@ class FileCache { store.put(meta); } - public static getFile(fileName: string, success: (name: string, data: Uint8Array)=>void, error: (error: string)=>void): void { + public static getFile(fileName: string, + success: (name: string, data: Uint8Array)=>void, + error: (error: string)=>void): void + { var query = this.dbHandle.transaction("files"); var store = query.objectStore("files"); var request = store.get(fileName); diff --git a/client/src/sock/Connection.ts b/client/src/sock/Connection.ts index 6903f01..2840333 100644 --- a/client/src/sock/Connection.ts +++ b/client/src/sock/Connection.ts @@ -39,7 +39,6 @@ class Connection { if(this._isOpen) return; - // FLAG replace hard coded url with one loaded from a config file this.sock = new WebSocket(this.address); this.sock.binaryType = "arraybuffer"; @@ -63,7 +62,7 @@ class Connection { private onMessage(event: any): void { var raw = new Uint8Array(event.data); var msg: Packet; - try { + try { msg = (!this.useCipher || !Cipher.ready) ? Packet.fromBytes(raw) : Packet.fromBytes(Cipher.parse(raw)); diff --git a/client/src/sock/Crypto.ts b/client/src/sock/Crypto.ts index 30973f9..6bfd22f 100644 --- a/client/src/sock/Crypto.ts +++ b/client/src/sock/Crypto.ts @@ -9,8 +9,11 @@ class Key { return !Key._privateKey.eq(new bigInt(0)); } - public static init(): void { - Key.secret = Random.generatePrime(512); + public static init(onsuccess: ()=>void): void { + setTimeout(() => { + Key.secret = Random.generatePrime(512); + onsuccess(); + }, 0); } public static generateResponsePacket(request: Packet): Packet { diff --git a/client/src/sock/Packet.ts b/client/src/sock/Packet.ts index 4b9bdc3..fca9537 100644 --- a/client/src/sock/Packet.ts +++ b/client/src/sock/Packet.ts @@ -10,7 +10,7 @@ const enum kSlaveId { } class Packet { - private static magicNumber: Uint8Array = new Uint8Array([0xF0, 0x9F, 0xA6, 0x91]); + private static magicNumber: Uint8Array = new Uint8Array([0xB0, 0x0B]); private _id: number; public get id(): number { diff --git a/client/style.css b/client/style.css index 9d45273..5b5a5b0 100644 --- a/client/style.css +++ b/client/style.css @@ -49,7 +49,8 @@ body { top:0; bottom:0; margin: auto; - background: url('img/sock.png') center no-repeat; + /* NOTE uncomment this when not at work */ + /* background: url('img/sock.png') center no-repeat; */ background-size: contain; /* FLEX BOX - USED TO CENTER CHILD ELEMENTS DYNAMICALLY*/ diff --git a/server/src/.main.cpp.kate-swp b/server/src/.main.cpp.kate-swp new file mode 100644 index 0000000..59be521 Binary files /dev/null and b/server/src/.main.cpp.kate-swp differ diff --git a/server/src/crypto/keyex.cpp b/server/src/crypto/keyex.cpp index 64bf911..533d8b8 100644 --- a/server/src/crypto/keyex.cpp +++ b/server/src/crypto/keyex.cpp @@ -1,18 +1,19 @@ #include "keyex.hpp" +sosc::BigUInt sosc::cgc::KeyExchange::secret; + sosc::cgc::KeyExchange::KeyExchange() { if(KeyExchange::secret.IsZero()) - KeyExchange::secret = - BigUInt::GenerateRandomPrime(this->key_size_bytes); + KeyExchange::secret = FastRandomPrime(); - this->modulus = BigUInt::GenerateRandomPrime(this->key_size_bytes); + this->modulus = FastRandomPrime(); } sosc::Packet sosc::cgc::KeyExchange::GenerateRequest() const { return Packet(1, { this->generator.ToString(), this->modulus.ToString(), - BigUInt::ModPow(this->generator, this->secret, this->modulus); + BigUInt::ModPow(this->generator, this->secret, this->modulus) }); } @@ -50,3 +51,12 @@ bool sosc::cgc::KeyExchange::ParseResponse(const Packet& response) { return true; } + +sosc::BigUInt sosc::cgc::KeyExchange::FastRandomPrime() { + BigUInt prime; + for(int i = 0; i < this->key_size_bytes; i += 16) + prime += BigUInt::GenerateRandomPrime(16) << (i * 8); + + return prime; +} + diff --git a/server/src/crypto/keyex.hpp b/server/src/crypto/keyex.hpp index bbed485..20d8214 100644 --- a/server/src/crypto/keyex.hpp +++ b/server/src/crypto/keyex.hpp @@ -25,6 +25,8 @@ public: const int key_size = 512; const int key_size_bytes = key_size / 8; private: + BigUInt FastRandomPrime(); + const BigUInt generator = BigUInt(2u); static BigUInt secret; BigUInt modulus; diff --git a/server/src/main.cpp b/server/src/main.cpp index b0b9be4..b801bc4 100644 --- a/server/src/main.cpp +++ b/server/src/main.cpp @@ -81,9 +81,11 @@ int main(int argc, char **argv) { //<< c.ToString() << std::endl << std::endl //<< sosc::BigUInt::ModPow(a, b, c).ToString() << std::endl; - << sosc::BigUInt::GenerateRandomPrime(32).ToString() << std::endl - << sosc::BigUInt::GenerateRandomPrime(32).ToString() << std::endl - << sosc::BigUInt::GenerateRandomPrime(32).ToString() << std::endl; + << sosc::BigUInt::GenerateRandomPrime(16).ToString() << std::endl + << sosc::BigUInt::GenerateRandomPrime(16).ToString() << std::endl + << sosc::BigUInt::GenerateRandomPrime(16).ToString() << std::endl + << sosc::BigUInt::GenerateRandomPrime(16).ToString() << std::endl; + std::cout << (time(NULL) - start) << std::endl;