aboutsummaryrefslogtreecommitdiff
path: root/index.ts
diff options
context:
space:
mode:
Diffstat (limited to 'index.ts')
-rw-r--r--index.ts32
1 files changed, 22 insertions, 10 deletions
diff --git a/index.ts b/index.ts
index fff4e97..81301ee 100644
--- a/index.ts
+++ b/index.ts
@@ -1,17 +1,20 @@
import { readFileSync } from "fs"
-
+var privateKey = readFileSync('certs/selfsigned.key', 'utf8');
+var certificate = readFileSync('certs/selfsigned.crt', 'utf8');
+var http = require('http');
+var https = require('https');
const express = require('express')
const app = express()
-const port = 8008
+//const port = 8008
const fs = require('fs')
const bodyParser = require("body-parser");
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
const NodeRSA = require('node-rsa');
var ip = require("ip")
-function log(m:string){
+function log(m:any){
var date = new Date;
- console.log('['+date.getHours()+':'+date.getMinutes()+':'+date.getSeconds()+'] ' + m)
+ console.log('['+date.getHours()+':'+date.getMinutes()+':'+date.getSeconds()+'] ' + m.toString())
}
interface keyring{
[sid: string]: {
@@ -22,10 +25,19 @@ interface keyring{
}
let keyring = {} as keyring
let key:any;
-app.listen(port,'0.0.0.0', () => {
-
- log(`kanna is on http://${ip.address()}:${port} click on me click on me! :3`)
+
+
+//http
+var httpServer = http.createServer(app);
+var credentials = {key: privateKey, cert: certificate};
+var httpsServer = https.createServer(credentials, app);
+httpServer.listen(80,'0.0.0.0', () => {
+ log(`kanna is on http://${ip.address()} click on me click on me! :3`)
+})
+httpsServer.listen(443,'0.0.0.0', () => {
+ log(`kanna is secure now too!! https://${ip.address()}`)
})
+//end
app.get('/', (req:any, res:any) => {
res.sendFile(__dirname+"/html/index.html")
})
@@ -49,7 +61,6 @@ app.post('/pub.key', async (req:{body:{json:boolean,sid:keyof keyring,pub:string
keyring[req.body.sid]={mypriv:key.exportKey('pkcs1-private'),
mypub:key.exportKey('pkcs8-public'),
theirpub:req.body.pub}
- console.log(keyring)
res.send(key.exportKey('pkcs8-public'))
}
})
@@ -63,9 +74,10 @@ app.post('/login/submit', async (req:{body:{json:boolean,enc:boolean,data:string
let users = JSON.parse(readFileSync('json/user.json').toString())
for(let user of users){
let use=user as typeof users
- log(use)
if(user.name==dec.user&&user.pass==dec.pass){
- res.send('logged in, hello!')
+ const skey = new NodeRSA()
+ skey.importKey(keyring[req.body.sid].theirpub,'pkcs8-public')
+ res.send(JSON.stringify({data:skey.encrypt('<h1>hello!</h1>','base64'),enc:true,html:true}))
}
}
})