diff options
Diffstat (limited to 'index.ts')
-rw-r--r-- | index.ts | 31 |
1 files changed, 20 insertions, 11 deletions
@@ -9,14 +9,23 @@ app.use(bodyParser.urlencoded({ extended: false })); app.use(bodyParser.json()); const NodeRSA = require('node-rsa'); var ip = require("ip") -//let priv = ''; - +function log(m:string){ + var date = new Date; + console.log('['+date.getHours()+':'+date.getMinutes()+':'+date.getSeconds()+'] ' + m) +} interface keyring{ - [sid: string]: string, + [sid: string]: { + mypub:string, + theirpub:string, + mypriv:string, + }, } 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`) +}) app.get('/', (req:any, res:any) => { res.sendFile(__dirname+"/html/index.html") }) @@ -32,12 +41,15 @@ app.get('/src/lights-out.gif', (req:any, res:any) => { app.get('/src/kanna.gif', (req:any, res:any) => { res.sendFile(__dirname+'/src/kanna.gif') }) -app.post('/pub.key', async (req:{body:{json:boolean,sid:keyof keyring}}, res:any) => { +app.post('/pub.key', async (req:{body:{json:boolean,sid:keyof keyring,pub:string}}, res:any) => { if(req.body.json){ const key = new NodeRSA({b: 1024}); - keyring[req.body.sid]=key.exportKey('pkcs1-private') + 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')) } }) @@ -45,13 +57,13 @@ app.post('/pub.key', async (req:{body:{json:boolean,sid:keyof keyring}}, res:any app.post('/login/submit', async (req:{body:{json:boolean,enc:boolean,data:string,sid:keyof keyring}}, res:any) => { const key = new NodeRSA({b: 1024}) - key.importKey(keyring[req.body.sid],'pkcs1-private') + key.importKey(keyring[req.body.sid].mypriv,'pkcs1-private') let dec:{user:string,pass:string} = JSON.parse((atob(key.decrypt(req.body.data,'base64','base64')))) let users = JSON.parse(readFileSync('json/user.json').toString()) for(let user of users){ let use=user as typeof users - console.log(use) + log(use) if(user.name==dec.user&&user.pass==dec.pass){ res.send('logged in, hello!') } @@ -59,6 +71,3 @@ app.post('/login/submit', async (req:{body:{json:boolean,enc:boolean,data:string }) -app.listen(port,'0.0.0.0', () => { - console.log(`kanna is on http://${ip.address()}:${port} click on me click on me! :3`) -})
\ No newline at end of file |