wiki-security-sessionless 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Zach
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # Federated Wiki - Security Plug-in: Sessionless
2
+
3
+ -------------
4
+
5
+ This module lets wiki owners supply public keys for use with the [Sessionless][sessionless] protocol.
6
+ The tl;dr of that here is that you can utilize a private key stored locally on your machine, to create a signature, which logs you into your wiki instance.
7
+ The public key for this signature is stored on the server, and can be shared or reused however you'd like, and thus no third party identity provider or shared personal information needs to be used.
8
+
9
+ -------------
10
+
11
+ ## Configuration
12
+
13
+ -------------
14
+
15
+ This plugin expects an owner file that looks like this:
16
+
17
+ ```json
18
+ {
19
+ "name": "owner's name",
20
+ "keys": {
21
+ "pubKey": "028a2a944b5bcd93fb130d94abd22bd51569a3fcf17117521f37a7c5466c1baf96"
22
+ }
23
+ }
24
+ ```
25
+
26
+ Multiple key support will be added in a future update.
27
+
28
+ There are many ways to get sessionless keys.
29
+ This repo contains a simple `generate-keys.js` script that can be run to get a key pair, but anything that can generate keys on the secp256k1 curve can be used including openssl, and various other cryptographic libraries.
30
+
31
+ --------------
32
+
33
+ ## Usage
34
+
35
+ --------------
36
+
37
+ ### Server
38
+
39
+ Launch the wiki server with at least the following args:
40
+
41
+ `wiki --security_type=sessionless --id /path/to/.wiki/status/owner.json --security=./security --cookieSecret=biglongstring --session_duration=10`
42
+
43
+ * `cookieSecret` needs to be consistent across server starts to maintain existing sessions. Alternatively, if you'd like to burn all sessions just change the secret.
44
+
45
+ * `session_duration` is the number in days that you'd like your sessions to be valid for. Fractional days should work, but are untested by the author of this plugin.
46
+
47
+ ### Client
48
+
49
+ There is no need for a UI to login, instead a timestamp and signature is passed as query parameters to the login route of your wiki.
50
+ To get the signature this repo provides a `generate-signature.js` helper script, which can be run as follows:
51
+
52
+ `PRIVATE_KEY=<put your key here> OWNER_NAME=planetnineisaspaceship node generate-signature.js`
53
+
54
+ You can of course use any other method of getting a signature.
55
+ The server will check a message that is the timestamp that is passed in the query params, and the owner's name on the server.
56
+ In the future the timestamp will only be valid for a small amount of time, but that is left for a future version.
57
+
58
+ Once you have your signature you'll want to construct this kind of url:
59
+
60
+ `http://<domain.wiki>/login?timestamp=1739658960170&signature=c9220aaec64bbb61bf66928e4fca546e0cfe64ce3637b69d16025e6968cfc99e3ccf32a73a9536da7cb2b74ba7670a24bf8c5c4d0b3210a7fc6c142d5de7b215`
61
+
62
+ Pasting that into your browser will log you in, and you'll be all set.
63
+
64
+
65
+ [sessionless]: https://github.com/planet-nine-app/sessionless
@@ -0,0 +1,3 @@
1
+ const sessionless = require('sessionless-node');
2
+
3
+ sessionless.generateKeys(() => {}, () => {}).then(console.log).catch(console.error);
@@ -0,0 +1,21 @@
1
+ const sessionless = require('sessionless-node');
2
+
3
+ if(!process.env.PRIVATE_KEY || !process.env.OWNER_NAME) {
4
+ console.error('please provide a PRIVATE_KEY and OWNER_NAME');
5
+ process.exit();
6
+ }
7
+
8
+ sessionless.getKeys = () => {
9
+ return {
10
+ privateKey: process.env.PRIVATE_KEY,
11
+ pubKey: ''
12
+ };
13
+ };
14
+
15
+ const timestamp = new Date().getTime() + '';
16
+ const message = timestamp + process.env.OWNER_NAME;
17
+
18
+ sessionless.sign(message)
19
+ .then(signature => console.log(`?timestamp=${timestamp}&signature=${signature}`))
20
+ .catch(console.error);
21
+
package/index.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./server/sessionless');
package/package.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "wiki-security-sessionless",
3
+ "version": "0.0.1",
4
+ "description": "A sessionless security module for the federated wiki",
5
+ "keywords": [
6
+ "federated",
7
+ "wiki"
8
+ ],
9
+ "license": "MIT",
10
+ "author": "planetnineisaspaceship",
11
+ "type": "commonjs",
12
+ "main": "index.js",
13
+ "scripts": {
14
+ "test": "echo \"Error: no test specified\" && exit 1"
15
+ },
16
+ "dependencies": {
17
+ "sessionless-node": "^0.11.0"
18
+ }
19
+ }
@@ -0,0 +1,90 @@
1
+ const fs = require('fs');
2
+ const sessionless = require('sessionless-node');
3
+
4
+ console.log('sessionless server starting');
5
+
6
+ let keys;
7
+ const saveKeys = (_keys) => keys = _keys;
8
+ const getKeys = () => keys;
9
+
10
+ module.exports = (log, loga, argv) => {
11
+ const security = {};
12
+
13
+ const idFile = argv.id;
14
+
15
+ let owner = '';
16
+ let ownerName = '';
17
+
18
+ security.retrieveOwner = (callback) => {
19
+ fs.readFile(idFile, (err, data) => {
20
+ if(err) {
21
+ return callback(err);
22
+ }
23
+ owner = JSON.parse(data);
24
+ callback();
25
+ });
26
+ };
27
+
28
+ security.getOwner = () => {
29
+ if(!owner || !owner.name) {
30
+ ownerName = '';
31
+ } else {
32
+ ownerName = owner.name;
33
+ }
34
+ return ownerName;
35
+ };
36
+
37
+ security.setOwner = (id, callback) => {
38
+ // I don't think there is a reason to set owner during runtime so this is left as a noop for now
39
+ };
40
+
41
+ security.getUser = (req) => {
42
+ // TODO: This may be relevant if we add joan for PAP
43
+ };
44
+
45
+ security.isAuthorized = async (req) => {
46
+ if(req.session.key) {
47
+ const keys = await sessionless.getKeys();
48
+ const signature = await sessionless.sign(req.path);
49
+ try {
50
+ const isVerified = sessionless.verifySignature(signature, req.path, keys.pubKey);
51
+ return isVerified;
52
+ } catch(err) {
53
+ return false;
54
+ }
55
+ }
56
+ return false;
57
+ }
58
+
59
+ security.login = async (req, res) => {
60
+ const timestamp = req.query.timestamp;
61
+ const signature = req.query.signature;
62
+ const name = owner.name;
63
+ const message = timestamp + name;
64
+
65
+ try {
66
+ if(sessionless.verifySignature(signature, message, owner.keys.pubKey)) {
67
+ const keys = await sessionless.generateKeys(saveKeys, getKeys);
68
+
69
+ req.session.key = keys.privateKey;
70
+ return res.redirect('/view/welcome-visitors');
71
+ }
72
+ } catch(err) {}
73
+
74
+
75
+ res.status(403);
76
+ return res.send('unauthorized');
77
+ };
78
+
79
+ security.logout = async (req, res) => {
80
+ req.session.reset();
81
+ res.send("OK");
82
+ };
83
+
84
+ security.defineRoutes = (app, cors, updateOwner) => {
85
+ app.get('/login', cors, security.login);
86
+ app.get('/logout', cors, security.logout);
87
+ };
88
+
89
+ return security;
90
+ };