client happenings
This commit is contained in:
parent
13aa6b184f
commit
8c3469c4c1
12 changed files with 68 additions and 30 deletions
|
@ -1,2 +0,0 @@
|
||||||
<?php
|
|
||||||
echo $_SERVER["REMOTE_ADDR"];
|
|
|
@ -34,7 +34,10 @@ var Entrypoint = (function () {
|
||||||
};
|
};
|
||||||
Entrypoint.start = function () {
|
Entrypoint.start = function () {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
Key.init();
|
Key.init(function () {
|
||||||
|
_this.initStatus.keyInit = true;
|
||||||
|
_this.initCheck();
|
||||||
|
});
|
||||||
FileCache.initCache(
|
FileCache.initCache(
|
||||||
// SUCCESS
|
// SUCCESS
|
||||||
function () {
|
function () {
|
||||||
|
@ -47,10 +50,12 @@ var Entrypoint = (function () {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
Entrypoint.ready = function () {
|
Entrypoint.ready = function () {
|
||||||
|
alert("ready");
|
||||||
};
|
};
|
||||||
return Entrypoint;
|
return Entrypoint;
|
||||||
}());
|
}());
|
||||||
Entrypoint.initStatus = {
|
Entrypoint.initStatus = {
|
||||||
|
keyInit: false,
|
||||||
fileCache: false
|
fileCache: false
|
||||||
};
|
};
|
||||||
var FileCache = (function () {
|
var FileCache = (function () {
|
||||||
|
@ -71,7 +76,8 @@ var FileCache = (function () {
|
||||||
db.createObjectStore("metadata", { keyPath: "name", autoIncrement: false });
|
db.createObjectStore("metadata", { keyPath: "name", autoIncrement: false });
|
||||||
};
|
};
|
||||||
request.onerror = function (event) {
|
request.onerror = function (event) {
|
||||||
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 = function (event) {
|
request.onsuccess = function (event) {
|
||||||
_this.dbHandle = request.result;
|
_this.dbHandle = request.result;
|
||||||
|
@ -204,7 +210,6 @@ var Connection = (function () {
|
||||||
Connection.prototype.open = function () {
|
Connection.prototype.open = function () {
|
||||||
if (this._isOpen)
|
if (this._isOpen)
|
||||||
return;
|
return;
|
||||||
// FLAG replace hard coded url with one loaded from a config file
|
|
||||||
this.sock = new WebSocket(this.address);
|
this.sock = new WebSocket(this.address);
|
||||||
this.sock.binaryType = "arraybuffer";
|
this.sock.binaryType = "arraybuffer";
|
||||||
this.sock.onopen = this.onOpen;
|
this.sock.onopen = this.onOpen;
|
||||||
|
@ -224,7 +229,8 @@ var Connection = (function () {
|
||||||
var raw = new Uint8Array(event.data);
|
var raw = new Uint8Array(event.data);
|
||||||
var msg;
|
var msg;
|
||||||
try {
|
try {
|
||||||
msg = !this.useCipher || !Cipher.ready ? Packet.fromBytes(raw)
|
msg = (!this.useCipher || !Cipher.ready)
|
||||||
|
? Packet.fromBytes(raw)
|
||||||
: Packet.fromBytes(Cipher.parse(raw));
|
: Packet.fromBytes(Cipher.parse(raw));
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
|
@ -281,8 +287,11 @@ var Key = (function () {
|
||||||
enumerable: true,
|
enumerable: true,
|
||||||
configurable: true
|
configurable: true
|
||||||
});
|
});
|
||||||
Key.init = function () {
|
Key.init = function (onsuccess) {
|
||||||
|
setTimeout(function () {
|
||||||
Key.secret = Random.generatePrime(512);
|
Key.secret = Random.generatePrime(512);
|
||||||
|
onsuccess();
|
||||||
|
}, 0);
|
||||||
};
|
};
|
||||||
Key.generateResponsePacket = function (request) {
|
Key.generateResponsePacket = function (request) {
|
||||||
var generator = new bigInt(request[0].toString(), 16);
|
var generator = new bigInt(request[0].toString(), 16);
|
||||||
|
@ -458,7 +467,7 @@ var Packet = (function () {
|
||||||
};
|
};
|
||||||
return Packet;
|
return Packet;
|
||||||
}());
|
}());
|
||||||
Packet.magicNumber = new Uint8Array([0xF0, 0x9F, 0xA6, 0x91]);
|
Packet.magicNumber = new Uint8Array([0xB0, 0x0B]);
|
||||||
// ** STRING EXTENSIONS ** \\
|
// ** STRING EXTENSIONS ** \\
|
||||||
String.prototype.replaceAll = function (needle, replace, ignoreCase) {
|
String.prototype.replaceAll = function (needle, replace, ignoreCase) {
|
||||||
if (ignoreCase === void 0) { ignoreCase = false; }
|
if (ignoreCase === void 0) { ignoreCase = false; }
|
||||||
|
|
|
@ -20,6 +20,7 @@ class SockContext {
|
||||||
|
|
||||||
class Entrypoint {
|
class Entrypoint {
|
||||||
private static initStatus = {
|
private static initStatus = {
|
||||||
|
keyInit: false,
|
||||||
fileCache: false
|
fileCache: false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +34,10 @@ class Entrypoint {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static start(): void {
|
public static start(): void {
|
||||||
Key.init();
|
Key.init(() => {
|
||||||
|
this.initStatus.keyInit = true;
|
||||||
|
this.initCheck();
|
||||||
|
});
|
||||||
|
|
||||||
FileCache.initCache(
|
FileCache.initCache(
|
||||||
// SUCCESS
|
// SUCCESS
|
||||||
|
@ -50,6 +54,6 @@ class Entrypoint {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ready(): void {
|
private static ready(): void {
|
||||||
|
alert("ready");
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,7 +1,9 @@
|
||||||
class FileCache {
|
class FileCache {
|
||||||
private static dbHandle: IDBDatabase = null;
|
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);
|
var request = window.indexedDB.open("fileCache", 3);
|
||||||
|
|
||||||
request.onupgradeneeded = (event: any) => {
|
request.onupgradeneeded = (event: any) => {
|
||||||
|
@ -16,12 +18,15 @@ class FileCache {
|
||||||
if(db.objectStoreNames.contains("hashes"))
|
if(db.objectStoreNames.contains("hashes"))
|
||||||
db.deleteObjectStore("hashes");
|
db.deleteObjectStore("hashes");
|
||||||
|
|
||||||
db.createObjectStore("files", {keyPath: "name", autoIncrement: false});
|
db.createObjectStore("files",
|
||||||
db.createObjectStore("metadata", {keyPath: "name", autoIncrement: false});
|
{keyPath: "name", autoIncrement: false});
|
||||||
|
db.createObjectStore("metadata",
|
||||||
|
{keyPath: "name", autoIncrement: false});
|
||||||
};
|
};
|
||||||
|
|
||||||
request.onerror = (event: any) => {
|
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) => {
|
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 query = this.dbHandle.transaction("metadata");
|
||||||
var store = query.objectStore("metadata");
|
var store = query.objectStore("metadata");
|
||||||
var request = store.get(fileName);
|
var request = store.get(fileName);
|
||||||
|
@ -50,7 +57,10 @@ class FileCache {
|
||||||
store.put(meta);
|
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 query = this.dbHandle.transaction("files");
|
||||||
var store = query.objectStore("files");
|
var store = query.objectStore("files");
|
||||||
var request = store.get(fileName);
|
var request = store.get(fileName);
|
||||||
|
|
|
@ -39,7 +39,6 @@ class Connection {
|
||||||
if(this._isOpen)
|
if(this._isOpen)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// FLAG replace hard coded url with one loaded from a config file
|
|
||||||
this.sock = new WebSocket(this.address);
|
this.sock = new WebSocket(this.address);
|
||||||
this.sock.binaryType = "arraybuffer";
|
this.sock.binaryType = "arraybuffer";
|
||||||
|
|
||||||
|
|
|
@ -9,8 +9,11 @@ class Key {
|
||||||
return !Key._privateKey.eq(new bigInt(0));
|
return !Key._privateKey.eq(new bigInt(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static init(): void {
|
public static init(onsuccess: ()=>void): void {
|
||||||
|
setTimeout(() => {
|
||||||
Key.secret = Random.generatePrime(512);
|
Key.secret = Random.generatePrime(512);
|
||||||
|
onsuccess();
|
||||||
|
}, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static generateResponsePacket(request: Packet): Packet {
|
public static generateResponsePacket(request: Packet): Packet {
|
||||||
|
|
|
@ -10,7 +10,7 @@ const enum kSlaveId {
|
||||||
}
|
}
|
||||||
|
|
||||||
class Packet {
|
class Packet {
|
||||||
private static magicNumber: Uint8Array = new Uint8Array([0xF0, 0x9F, 0xA6, 0x91]);
|
private static magicNumber: Uint8Array = new Uint8Array([0xB0, 0x0B]);
|
||||||
|
|
||||||
private _id: number;
|
private _id: number;
|
||||||
public get id(): number {
|
public get id(): number {
|
||||||
|
|
|
@ -49,7 +49,8 @@ body {
|
||||||
top:0;
|
top:0;
|
||||||
bottom:0;
|
bottom:0;
|
||||||
margin: auto;
|
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;
|
background-size: contain;
|
||||||
|
|
||||||
/* FLEX BOX - USED TO CENTER CHILD ELEMENTS DYNAMICALLY*/
|
/* FLEX BOX - USED TO CENTER CHILD ELEMENTS DYNAMICALLY*/
|
||||||
|
|
BIN
server/src/.main.cpp.kate-swp
Normal file
BIN
server/src/.main.cpp.kate-swp
Normal file
Binary file not shown.
|
@ -1,18 +1,19 @@
|
||||||
#include "keyex.hpp"
|
#include "keyex.hpp"
|
||||||
|
|
||||||
|
sosc::BigUInt sosc::cgc::KeyExchange::secret;
|
||||||
|
|
||||||
sosc::cgc::KeyExchange::KeyExchange() {
|
sosc::cgc::KeyExchange::KeyExchange() {
|
||||||
if(KeyExchange::secret.IsZero())
|
if(KeyExchange::secret.IsZero())
|
||||||
KeyExchange::secret =
|
KeyExchange::secret = FastRandomPrime();
|
||||||
BigUInt::GenerateRandomPrime(this->key_size_bytes);
|
|
||||||
|
|
||||||
this->modulus = BigUInt::GenerateRandomPrime(this->key_size_bytes);
|
this->modulus = FastRandomPrime();
|
||||||
}
|
}
|
||||||
|
|
||||||
sosc::Packet sosc::cgc::KeyExchange::GenerateRequest() const {
|
sosc::Packet sosc::cgc::KeyExchange::GenerateRequest() const {
|
||||||
return Packet(1, {
|
return Packet(1, {
|
||||||
this->generator.ToString(),
|
this->generator.ToString(),
|
||||||
this->modulus.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;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,8 @@ public:
|
||||||
const int key_size = 512;
|
const int key_size = 512;
|
||||||
const int key_size_bytes = key_size / 8;
|
const int key_size_bytes = key_size / 8;
|
||||||
private:
|
private:
|
||||||
|
BigUInt FastRandomPrime();
|
||||||
|
|
||||||
const BigUInt generator = BigUInt(2u);
|
const BigUInt generator = BigUInt(2u);
|
||||||
static BigUInt secret;
|
static BigUInt secret;
|
||||||
BigUInt modulus;
|
BigUInt modulus;
|
||||||
|
|
|
@ -81,9 +81,11 @@ int main(int argc, char **argv) {
|
||||||
//<< c.ToString() << std::endl << std::endl
|
//<< c.ToString() << std::endl << std::endl
|
||||||
//<< sosc::BigUInt::ModPow(a, b, c).ToString() << std::endl;
|
//<< sosc::BigUInt::ModPow(a, b, c).ToString() << std::endl;
|
||||||
|
|
||||||
<< sosc::BigUInt::GenerateRandomPrime(32).ToString() << std::endl
|
<< sosc::BigUInt::GenerateRandomPrime(16).ToString() << std::endl
|
||||||
<< sosc::BigUInt::GenerateRandomPrime(32).ToString() << std::endl
|
<< sosc::BigUInt::GenerateRandomPrime(16).ToString() << std::endl
|
||||||
<< sosc::BigUInt::GenerateRandomPrime(32).ToString() << std::endl;
|
<< sosc::BigUInt::GenerateRandomPrime(16).ToString() << std::endl
|
||||||
|
<< sosc::BigUInt::GenerateRandomPrime(16).ToString() << std::endl;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
std::cout << (time(NULL) - start) << std::endl;
|
std::cout << (time(NULL) - start) << std::endl;
|
||||||
|
|
Loading…
Reference in a new issue