aboutsummaryrefslogtreecommitdiff
path: root/index.ts
diff options
context:
space:
mode:
authorgrant-kun <[email protected]>2022-10-04 09:00:27 -0500
committergrant-kun <[email protected]>2022-10-04 09:00:27 -0500
commit5b6bdefbec79245a93d38ea423738322580e73b7 (patch)
treecd28049ef4670b8fdd4bbaed36db2e9b5a972f04 /index.ts
parentcb88571c538e54a363ee2489df2eff23283174d0 (diff)
kanna
Diffstat (limited to 'index.ts')
-rw-r--r--index.ts31
1 files changed, 20 insertions, 11 deletions
diff --git a/index.ts b/index.ts
index 2412b22..fff4e97 100644
--- a/index.ts
+++ b/index.ts
@@ -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