aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authormarvin-borner@live.com2018-04-11 18:36:44 +0200
committermarvin-borner@live.com2018-04-11 18:36:44 +0200
commit2a221f180ebf6f86e3709401804108fcda65184f (patch)
treef947f37deb7d0192a3c6aed15ffd30d9c7aeea6b
parenta935f6bc393490d02119e9c6cbc62787b3656fac (diff)
Started implementing chat encryption
-rw-r--r--TestEncryption.php18
-rw-r--r--assets/js/chat.js34
-rw-r--r--assets/js/main.js8
-rw-r--r--assets/php/Chatserver/bin/WebChatServer.php (renamed from assets/php/bin/WebChatServer.php)4
-rw-r--r--assets/php/Chatserver/bin/server.csr (renamed from assets/php/bin/server.csr)0
-rw-r--r--assets/php/Chatserver/src/ChatProcessor.php (renamed from assets/php/src/ChatProcessor.php)0
-rw-r--r--assets/php/SavePublicKey.php17
-rw-r--r--assets/php/composer.json2
-rw-r--r--assets/php/vendor/composer/autoload_psr4.php2
-rw-r--r--assets/php/vendor/composer/autoload_static.php2
-rw-r--r--index.php1
11 files changed, 71 insertions, 17 deletions
diff --git a/TestEncryption.php b/TestEncryption.php
index e4a9085..097b727 100644
--- a/TestEncryption.php
+++ b/TestEncryption.php
@@ -14,18 +14,26 @@
<script src="assets/js/encryption.js"></script>
<script>
// The passphrase used to repeatably generate this RSA key.
- var PassPhrase = "The Moon is a Harsh Mistress.";
-
+ var PassPhrase = randomString(16);
// The length of the RSA key, in bits.
var Bits = 1024;
-
var MattsRSAkey = cryptico.generateRSAKey(PassPhrase, Bits);
var MattsPublicKeyString = cryptico.publicKeyString(MattsRSAkey);
- var PlainText = "Matt, I need you to help me with my Starcraft strategy.";
+ var PlainText = "Hello Bro";
var EncryptionResult = cryptico.encrypt(PlainText, MattsPublicKeyString);
-
console.log(EncryptionResult.cipher);
+
+ function randomString(len, charSet) {
+ charSet = charSet || 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
+ var randomString = '';
+ for (var i = 0; i < len; i++) {
+ var randomPoz = Math.floor(Math.random() * charSet.length);
+ randomString += charSet.substring(randomPoz,randomPoz+1);
+ }
+ return randomString;
+ }
+
</script>
</body>
</html> \ No newline at end of file
diff --git a/assets/js/chat.js b/assets/js/chat.js
index 9543f87..9acff1d 100644
--- a/assets/js/chat.js
+++ b/assets/js/chat.js
@@ -1,10 +1,42 @@
+/************
+ GENERATE KEYS
+ ************/
+if (localStorage.getItem('KeysGenerated') === null || localStorage.getItem('KeysGenerated') !== "true") {
+ // GENERATE
+ var EncryptionPhrase = "PASSWORD 123"; // THE USERS PASSWORD
+ var RSABitLength = 1024;
+ var PrivateKeyString = cryptico.generateRSAKey(EncryptionPhrase, RSABitLength);
+ var PublicKeyString = cryptico.publicKeyString(PrivateKeyString);
+ // SAVE TO DATABASE
+ $.ajax({
+ type: "POST",
+ url: "assets/php/SavePublicKey.php",
+ data: {
+ UserID: "1", // TEMPORARY
+ PublicKeyString: PublicKeyString
+ },
+ async: true,
+ error: function () {
+ console.error("Error while saving public key to database!");
+ },
+ success: function () {
+ localStorage.setItem('KeysGenerated', "true");
+ }
+ });
+}
+
+
+/******
+ GENERAL
+ ******/
+
var ChatTextInput = $("#ChatTextInput");
var SubscribeTextInput = $("#SubscribeTextInput");
var ChatResponses = $("#ChatResponses");
var WebSocket = new WebSocket('wss://marvinborner.ddnss.de:1337');
WebSocket.onopen = function () {
- //console.log("Chat connection established!");
+ console.log("Chat connection established!");
};
WebSocket.onmessage = function (e) {
var MessageObject = JSON.parse(e.data);
diff --git a/assets/js/main.js b/assets/js/main.js
index b9cfe34..aa0f76b 100644
--- a/assets/js/main.js
+++ b/assets/js/main.js
@@ -1,10 +1,6 @@
-/******
- GENERAL
- ******/
-
/*****
- NAVBAR
- *****/
+NAVBAR
+*****/
var $el, leftPos, newWidth,
$mainNav = $(".Navbar");
$mainNav.append("<span class='NavbarLine'></span>");
diff --git a/assets/php/bin/WebChatServer.php b/assets/php/Chatserver/bin/WebChatServer.php
index bebd7b9..15f573b 100644
--- a/assets/php/bin/WebChatServer.php
+++ b/assets/php/Chatserver/bin/WebChatServer.php
@@ -1,5 +1,5 @@
<?php
-require '../vendor/autoload.php';
+require '../../vendor/autoload.php';
use Ratchet\Server\IoServer;
use Ratchet\Http\HttpServer;
@@ -15,4 +15,4 @@ $server = IoServer::factory(
1338
);
-$server->run();
+$server->run(); \ No newline at end of file
diff --git a/assets/php/bin/server.csr b/assets/php/Chatserver/bin/server.csr
index 8523b82..8523b82 100644
--- a/assets/php/bin/server.csr
+++ b/assets/php/Chatserver/bin/server.csr
diff --git a/assets/php/src/ChatProcessor.php b/assets/php/Chatserver/src/ChatProcessor.php
index da78c9b..da78c9b 100644
--- a/assets/php/src/ChatProcessor.php
+++ b/assets/php/Chatserver/src/ChatProcessor.php
diff --git a/assets/php/SavePublicKey.php b/assets/php/SavePublicKey.php
new file mode 100644
index 0000000..725a005
--- /dev/null
+++ b/assets/php/SavePublicKey.php
@@ -0,0 +1,17 @@
+<?php
+if (isset($_POST["UserID"]) && isset($_POST["PublicKeyString"])) {
+ require "DataBaseConf.php";
+ $CheckIfAlreadySetStmt = $conn->prepare("SELECT count(*) FROM `PublicKeys` WHERE UserID = :UserID");
+ $CheckIfAlreadySetStmt->bindValue(':UserID', $_POST['UserID']);
+ $CheckIfAlreadySetStmt->execute();
+ $CheckIfAlreadySetRes = $CheckIfAlreadySetStmt->fetchColumn();
+ if ($CheckIfAlreadySetRes == 1) {
+ $UpdatePublicKeyStmt = $conn->prepare("UPDATE `PublicKeys` SET PublicKeyString = :PublicKeyString WHERE UserID = :UserID");
+ $UpdatePublicKeyStmt->execute(array('PublicKeyString' => $_POST["PublicKeyString"], 'UserID' => $_POST["UserID"]));
+ } else if ($CheckIfAlreadySetRes == 0) {
+ $InsertPublicKeyStmt = $conn->prepare("INSERT INTO `PublicKeys` (UserID, PublicKeyString) VALUES (:UserID, :PublicKeyString)");
+ $InsertPublicKeyStmt->execute(array('PublicKeyString' => $_POST["PublicKeyString"], 'UserID' => $_POST["UserID"]));
+ }
+} else {
+ http_response_code(400);
+} \ No newline at end of file
diff --git a/assets/php/composer.json b/assets/php/composer.json
index 7c3318b..8406940 100644
--- a/assets/php/composer.json
+++ b/assets/php/composer.json
@@ -1,7 +1,7 @@
{
"autoload": {
"psr-4": {
- "Websocket\\": "src"
+ "Websocket\\": "Chatserver/src"
}
},
"require": {
diff --git a/assets/php/vendor/composer/autoload_psr4.php b/assets/php/vendor/composer/autoload_psr4.php
index 7240c63..5c1a135 100644
--- a/assets/php/vendor/composer/autoload_psr4.php
+++ b/assets/php/vendor/composer/autoload_psr4.php
@@ -6,7 +6,7 @@ $vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
- 'Websocket\\' => array($baseDir . '/src'),
+ 'Websocket\\' => array($baseDir . '/Chatserver/src'),
'Symfony\\Polyfill\\Php70\\' => array($vendorDir . '/symfony/polyfill-php70'),
'Symfony\\Polyfill\\Mbstring\\' => array($vendorDir . '/symfony/polyfill-mbstring'),
'Symfony\\Component\\Routing\\' => array($vendorDir . '/symfony/routing'),
diff --git a/assets/php/vendor/composer/autoload_static.php b/assets/php/vendor/composer/autoload_static.php
index e598fbf..e3cbb9e 100644
--- a/assets/php/vendor/composer/autoload_static.php
+++ b/assets/php/vendor/composer/autoload_static.php
@@ -56,7 +56,7 @@ class ComposerStaticInit3c5661e077098f105cbab5a541fd4883
public static $prefixDirsPsr4 = array (
'Websocket\\' =>
array (
- 0 => __DIR__ . '/../..' . '/src',
+ 0 => __DIR__ . '/../..' . '/Chatserver/src',
),
'Symfony\\Polyfill\\Php70\\' =>
array (
diff --git a/index.php b/index.php
index 568cd1b..bdadeba 100644
--- a/index.php
+++ b/index.php
@@ -105,6 +105,7 @@
<script src="https://code.jquery.com/jquery-latest.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.min.js"></script>
+<script src="assets/js/encryption.js"></script>
<script src="assets/js/chat.js"></script>
<script src="assets/js/main.js"></script>