Skip to content
Snippets Groups Projects
Commit 3a6f2641 authored by Alexander Tim Hobelsberger's avatar Alexander Tim Hobelsberger
Browse files

TLS

parent a23bab7b
No related branches found
No related tags found
No related merge requests found
...@@ -2,20 +2,28 @@ ...@@ -2,20 +2,28 @@
const express = require('express'); const express = require('express');
const app = express(); const app = express();
const http = require('http'); const http = require('http');
const https = require('https');
const fs = require('fs');
const { mongo, default: mongoose } = require('mongoose'); const { mongo, default: mongoose } = require('mongoose');
const server = http.createServer(app); //http Server
//const server = http.createServer(app);
//https Server
const server = https.createServer({
key: fs.readFileSync(__dirname + '/tls/key.pem'),
cert: fs.readFileSync(__dirname + '/tls/cert.pem'),
}, app);
const { Server } = require("socket.io"); const { Server } = require("socket.io");
const io = new Server(server); const io = new Server(server);
const bodyParser = require('body-parser'); const bodyParser = require('body-parser');
const registerRoute = require('./routes/register'); const registerRoute = require('./routes/register');
const loginRoute = require('./routes/login'); const loginRoute = require('./routes/login');
const fs = require('fs');
const activeUsers = new Map(); const activeUsers = new Map();
const authenticationRoute = require('./routes/auth'); const authenticationRoute = require('./routes/auth');
const { response } = require('express'); const { response } = require('express');
const { resolve } = require('path'); const { resolve } = require('path');
//DB Connection //DB Connection
mongoose.connect("mongodb://127.0.0.1:27017/cloudComputing"); mongoose.connect("mongodb://127.0.0.1:27017/cloudComputing");
...@@ -322,9 +330,12 @@ io.on("connection", (socket) => { ...@@ -322,9 +330,12 @@ io.on("connection", (socket) => {
}); });
}); });
server.listen(3000, () => {
//http Server
/* server.listen(3000, () => {
console.log('listening on Port :3000'); console.log('listening on Port :3000');
}); }); */
server.listen(3000, () => console.log('Server on Port 3000'));
module.exports = {activeUsers}; module.exports = {activeUsers};
\ No newline at end of file
/**
* Summary:
* Schema for MongoDB wich defines the shape of the documents within the collection
*
*/
const mongoose = require('mongoose'); const mongoose = require('mongoose');
const schema = mongoose.Schema; const schema = mongoose.Schema;
......
...@@ -683,6 +683,19 @@ ...@@ -683,6 +683,19 @@
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
"integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==" "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw=="
}, },
"node_modules/fsevents": {
"version": "2.3.2",
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz",
"integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==",
"hasInstallScript": true,
"optional": true,
"os": [
"darwin"
],
"engines": {
"node": "^8.16.0 || ^10.6.0 || >=11.0.0"
}
},
"node_modules/function-bind": { "node_modules/function-bind": {
"version": "1.1.1", "version": "1.1.1",
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz",
...@@ -805,6 +818,11 @@ ...@@ -805,6 +818,11 @@
"node": ">= 0.8" "node": ">= 0.8"
} }
}, },
"node_modules/https": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/https/-/https-1.0.0.tgz",
"integrity": "sha512-4EC57ddXrkaF0x83Oj8sM6SLQHAWXw90Skqu2M4AEWENZ3F02dFJE/GARA8igO79tcgYqGrD7ae4f5L3um2lgg=="
},
"node_modules/https-proxy-agent": { "node_modules/https-proxy-agent": {
"version": "5.0.1", "version": "5.0.1",
"resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz", "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz",
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
"express": "^4.18.2", "express": "^4.18.2",
"fs": "*", "fs": "*",
"http": "*", "http": "*",
"https": "^1.0.0",
"jsonwebtoken": "^8.5.1", "jsonwebtoken": "^8.5.1",
"mongoose": "^6.6.7", "mongoose": "^6.6.7",
"nodemon": "^2.0.20", "nodemon": "^2.0.20",
...@@ -834,6 +835,11 @@ ...@@ -834,6 +835,11 @@
"node": ">= 0.8" "node": ">= 0.8"
} }
}, },
"node_modules/https": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/https/-/https-1.0.0.tgz",
"integrity": "sha512-4EC57ddXrkaF0x83Oj8sM6SLQHAWXw90Skqu2M4AEWENZ3F02dFJE/GARA8igO79tcgYqGrD7ae4f5L3um2lgg=="
},
"node_modules/https-proxy-agent": { "node_modules/https-proxy-agent": {
"version": "5.0.1", "version": "5.0.1",
"resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz", "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz",
...@@ -2645,6 +2651,11 @@ ...@@ -2645,6 +2651,11 @@
"toidentifier": "1.0.1" "toidentifier": "1.0.1"
} }
}, },
"https": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/https/-/https-1.0.0.tgz",
"integrity": "sha512-4EC57ddXrkaF0x83Oj8sM6SLQHAWXw90Skqu2M4AEWENZ3F02dFJE/GARA8igO79tcgYqGrD7ae4f5L3um2lgg=="
},
"https-proxy-agent": { "https-proxy-agent": {
"version": "5.0.1", "version": "5.0.1",
"resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz", "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz",
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
"express": "^4.18.2", "express": "^4.18.2",
"fs": "*", "fs": "*",
"http": "*", "http": "*",
"https": "^1.0.0",
"jsonwebtoken": "^8.5.1", "jsonwebtoken": "^8.5.1",
"mongoose": "^6.6.7", "mongoose": "^6.6.7",
"nodemon": "^2.0.20", "nodemon": "^2.0.20",
......
...@@ -20,12 +20,13 @@ require('dotenv').config(); ...@@ -20,12 +20,13 @@ require('dotenv').config();
* *
* @listens fetch to"/login" from client * @listens fetch to"/login" from client
* *
* @param {Json} req Json Body from Client. * @param {object} req Json Body from Client.
* @return {Json} res Response from server. * @return {json} res Response from server.
*/ */
router.post('/', async(req, res) => { router.post('/', async(req, res) => {
var name = req.body.name; var name = req.body.name;
var password = req.body.password; var password = req.body.password;
console.log(req.body);
User.findOne({name: name}) User.findOne({name: name})
.then(user => { .then(user => {
if(user){ if(user){
......
-----BEGIN CERTIFICATE-----
MIID4DCCAsgCCQC4PBSgAI/pZDANBgkqhkiG9w0BAQUFADCBsDELMAkGA1UEBhMC
REUxHTAbBgNVBAgMFEJhZGVuLVfDg8K8cnR0ZW1iZXJnMREwDwYDVQQHDAhTdXR0
Z2FydDEeMBwGA1UECgwVSG9jaHNjaHVsZSBSZXV0bGluZ2VuMQswCQYDVQQLDAJJ
VDEXMBUGA1UEAwwOQ2xvdWRDb21wdXRpbmcxKTAnBgkqhkiG9w0BCQEWGmhvYmVs
c2JlcmdlcmFsZXhAZ21haWwuY29tMCAXDTIyMTEwODE0NDYxN1oYDzIwNTAwMzI1
MTQ0NjE3WjCBsDELMAkGA1UEBhMCREUxHTAbBgNVBAgMFEJhZGVuLVfDg8K8cnR0
ZW1iZXJnMREwDwYDVQQHDAhTdXR0Z2FydDEeMBwGA1UECgwVSG9jaHNjaHVsZSBS
ZXV0bGluZ2VuMQswCQYDVQQLDAJJVDEXMBUGA1UEAwwOQ2xvdWRDb21wdXRpbmcx
KTAnBgkqhkiG9w0BCQEWGmhvYmVsc2JlcmdlcmFsZXhAZ21haWwuY29tMIIBIjAN
BgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAt5Mmx2emnxM7rJhjirXWAPEFkOef
V2mxgBbQTzQPYhauPmtIIwBFfL7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r+U0H8g4jaKZbokNB13iMnPZFpvKdKs9uF
CxtCOeEbOmc3+PGGuOVo80fWV0sq68YQgLBfUsDPjYI+jA5DeHIr0022/MAHC0Oa
N1cTqlIJeHhVXUUgyYTWCJOBhBMoNzhB9Sh5gyzBCRfCk8F6Uoy7
-----END RSA PRIVATE KEY-----
...@@ -60,7 +60,7 @@ ...@@ -60,7 +60,7 @@
redirect: 'follow' redirect: 'follow'
}; };
fetch("http://localhost:3000/login", requestOptions) fetch("https://localhost:3000/login", requestOptions)
.then(response => response.json()) .then(response => response.json())
.then((result) => { .then((result) => {
...@@ -121,7 +121,7 @@ ...@@ -121,7 +121,7 @@
redirect: 'follow' redirect: 'follow'
}; };
fetch("http://localhost:3000/authenticate", requestOptions) fetch("https://localhost:3000/authenticate", requestOptions)
.then((response) => { .then((response) => {
if (response.status === 200) { if (response.status === 200) {
......
...@@ -61,7 +61,7 @@ ...@@ -61,7 +61,7 @@
redirect: 'follow' redirect: 'follow'
}; };
fetch("http://localhost:3000/register", requestOptions) fetch("https://localhost:3000/register", requestOptions)
.then((response) => { .then((response) => {
if(response.ok){ if(response.ok){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment