Commit 1dd67ae5 authored by Aral Balkan's avatar Aral Balkan
Browse files

Store private routes in database and prune unused one regularly

parent 180ac3bb
const { SodiumPlus, X25519PublicKey } = require('sodium-plus')
const { decodeBase64 } = require('tweetnacl-util')
// Check every minute and prune sign-in paths that haven’t been used in the last ten seconds.
setInterval(() => {
const now = Date.now()
if (db.privateRoutes) {
db.privateRoutes.forEach((privateRoute, index) => {
if (privateRoute.createdAt === privateRoute.accessedAt && (now - privateRoute.createdAt > 10000)) {
console.log('Pruning unused private path', privateRoute)
db.privateRoutes.splice(index, 1)
}
})
}
console.log('After prune', db.privateRoutes)
}, 1 /* minute */ * 60 * 1000)
let sodium
......@@ -18,6 +33,15 @@ module.exports = async (request, response) => {
console.log('Unencrypted secret path', unecryptedPrivateSocketPathFragment)
// Add the unencrypted secret path, along with the current time, to the routes
// so we can listen for requests on it.
if (!db.privateRoutes) {
db.privateRoutes = []
}
db.privateRoutes.push({ createdAt: Date.now(), accessedAt: Date.now(), route: unecryptedPrivateSocketPathFragment })
console.log('Private routes', db.privateRoutes)
// Next, we encrypt it using the person’s public encryption key.
// Since this is over a TLS connection, we don’t need to prove our
// identity so a sealed box will suffice.
......
node_modules
*.crt
*.key
.db
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment