pisha-server 0.0.0-stage → 0.0.11
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 +21 -0
- package/README.md +40 -2
- package/accounts/accounts.js +754 -0
- package/accounts/index.js +1 -0
- package/accounts/passwords.js +41 -0
- package/accounts/totp.js +54 -0
- package/boards/boards.js +1079 -0
- package/boards/github.js +212 -0
- package/boards/index.js +1 -0
- package/boards/sync.js +980 -0
- package/companies.js +294 -0
- package/company-export.js +101 -0
- package/company.js +79 -0
- package/dashboard/dashboard.js +407 -0
- package/dashboard/index.js +1 -0
- package/data-upgrade.js +69 -0
- package/install/linux.sh +181 -0
- package/install/macos.sh +121 -0
- package/install/windows.bat +54 -0
- package/machines/index.js +3 -0
- package/machines/machines.js +910 -0
- package/messaging/inbox.js +252 -0
- package/messaging/index.js +3 -0
- package/messaging/messaging.js +551 -0
- package/messaging/plans.js +67 -0
- package/observation/index.js +1 -0
- package/observation/observation.js +224 -0
- package/organization/index.js +1 -0
- package/organization/organization.js +218 -0
- package/package.json +54 -4
- package/permissions/index.js +1 -0
- package/permissions/permissions.js +211 -0
- package/pisha-host.mjs +3297 -0
- package/pisha-host.mjs.sig +1 -0
- package/platform/acme.js +207 -0
- package/platform/basics.js +14 -0
- package/platform/config.js +154 -0
- package/platform/control.js +93 -0
- package/platform/credentials.js +151 -0
- package/platform/database.js +251 -0
- package/platform/errors.js +13 -0
- package/platform/files.js +50 -0
- package/platform/http.js +207 -0
- package/platform/index.js +58 -0
- package/platform/limits.js +122 -0
- package/platform/listen.js +183 -0
- package/platform/roles.js +6 -0
- package/platform/stream.js +19 -0
- package/platform/text.js +83 -0
- package/platform/ws.js +186 -0
- package/routes.js +405 -0
- package/server.js +65 -0
- package/sessions/index.js +1 -0
- package/sessions/sessions.js +533 -0
- package/ui/LICENSE-affectui.txt +26 -0
- package/ui/addmachine.js +151 -0
- package/ui/api.js +20 -0
- package/ui/app.js +143 -0
- package/ui/attention.js +78 -0
- package/ui/back.js +166 -0
- package/ui/boards.js +958 -0
- package/ui/chat.js +388 -0
- package/ui/content.js +157 -0
- package/ui/dialogs.js +135 -0
- package/ui/doing.js +112 -0
- package/ui/dom.js +6 -0
- package/ui/ds-base.css +146 -0
- package/ui/ds-components.css +229 -0
- package/ui/fonts/LICENSE-space-grotesk.txt +93 -0
- package/ui/fonts/space-grotesk-latin-700-normal.woff2 +0 -0
- package/ui/fonts/space-grotesk-latin-ext-700-normal.woff2 +0 -0
- package/ui/format.js +25 -0
- package/ui/i18n.js +2093 -0
- package/ui/icons/apple-touch-icon.png +0 -0
- package/ui/icons/icon-192.png +0 -0
- package/ui/icons/icon-512.png +0 -0
- package/ui/icons/maskable-512.png +0 -0
- package/ui/icons.js +40 -0
- package/ui/inbox.js +535 -0
- package/ui/index.html +103 -0
- package/ui/machines.js +261 -0
- package/ui/manifest.webmanifest +16 -0
- package/ui/mosaic.js +189 -0
- package/ui/nav.js +141 -0
- package/ui/newteam.js +223 -0
- package/ui/org.js +653 -0
- package/ui/overlays.css +126 -0
- package/ui/palette.js +179 -0
- package/ui/people.js +370 -0
- package/ui/permissions.js +202 -0
- package/ui/qr.js +158 -0
- package/ui/router.js +171 -0
- package/ui/routes.js +46 -0
- package/ui/screen-boards.css +241 -0
- package/ui/screen-inbox.css +201 -0
- package/ui/screen-machines.css +76 -0
- package/ui/screen-mosaic.css +26 -0
- package/ui/screen-newteam.css +90 -0
- package/ui/screen-org.css +113 -0
- package/ui/screen-session.css +99 -0
- package/ui/screen-signin.css +28 -0
- package/ui/screen-team.css +80 -0
- package/ui/screen-teams.css +41 -0
- package/ui/session.js +42 -0
- package/ui/shell.css +122 -0
- package/ui/signin.js +120 -0
- package/ui/squads.js +370 -0
- package/ui/state.js +59 -0
- package/ui/stream.js +268 -0
- package/ui/styles.css +343 -0
- package/ui/team.js +115 -0
- package/ui/teams.js +58 -0
- package/ui/terminal.js +261 -0
- package/ui/theme.js +32 -0
- package/ui/timeline.js +163 -0
- package/ui/topbar.js +205 -0
- package/ui/voice-parse.js +98 -0
- package/ui/voice.js +320 -0
- package/vendor/InterVariable.woff2 +0 -0
- package/vendor/LICENSE-inter +92 -0
- package/vendor/LICENSE-xterm +21 -0
- package/vendor/README.md +8 -0
- package/vendor/addon-fit.js +2 -0
- package/vendor/xterm.css +218 -0
- package/vendor/xterm.js +2 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createAccounts } from './accounts.js'
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { randomBytes, scrypt, timingSafeEqual } from 'node:crypto'
|
|
2
|
+
import { ApiError } from '../platform/index.js'
|
|
3
|
+
|
|
4
|
+
// Asynchronous, so nobody waits while a password is checked; and only so many at
|
|
5
|
+
// once, because each one takes a lot of memory and time on purpose.
|
|
6
|
+
const N = 2 ** 15, R = 8, P = 1
|
|
7
|
+
const SIZE = 32
|
|
8
|
+
const AT_ONCE = 16
|
|
9
|
+
let running = 0
|
|
10
|
+
|
|
11
|
+
function derive(password, salt, { n = N, r = R, p = P } = {}) {
|
|
12
|
+
if (running >= AT_ONCE) throw new ApiError(503, 'Service Unavailable: too many sign-ins at once; retry')
|
|
13
|
+
running++
|
|
14
|
+
return new Promise((resolve, reject) => {
|
|
15
|
+
scrypt(password, salt, SIZE, { N: n, r, p, maxmem: 256 * 1024 * 1024 }, (err, key) => {
|
|
16
|
+
running--
|
|
17
|
+
if (err) reject(err); else resolve(key)
|
|
18
|
+
})
|
|
19
|
+
})
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export async function hashPassword(password) {
|
|
23
|
+
const salt = randomBytes(16)
|
|
24
|
+
const key = await derive(password, salt)
|
|
25
|
+
return `scrypt$${N}$${R}$${P}$${salt.toString('base64url')}$${key.toString('base64url')}`
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export async function passwordMatches(password, stored) {
|
|
29
|
+
const [kind, n, r, p, salt, key] = String(stored).split('$')
|
|
30
|
+
if (kind !== 'scrypt') return false
|
|
31
|
+
const expected = Buffer.from(key, 'base64url')
|
|
32
|
+
return timingSafeEqual(await derive(password, Buffer.from(salt, 'base64url'), { n: Number(n), r: Number(r), p: Number(p) }), expected)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// For an address nobody has: the same work, so the time doesn't say whether it exists.
|
|
36
|
+
export const NOBODY = await hashPassword(randomBytes(16).toString('hex'))
|
|
37
|
+
|
|
38
|
+
export function checkNewPassword(password) {
|
|
39
|
+
if (typeof password !== 'string' || password.length < 12) throw new ApiError(400, 'Bad Request: the password needs at least 12 characters')
|
|
40
|
+
if (password.length > 200) throw new ApiError(400, 'Bad Request: the password can have at most 200 characters')
|
|
41
|
+
}
|
package/accounts/totp.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { createCipheriv, createDecipheriv, createHmac, randomBytes } from 'node:crypto'
|
|
2
|
+
|
|
3
|
+
// Codes that change every 30 seconds (RFC 6238, as every authenticator app does it).
|
|
4
|
+
const B32 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567'
|
|
5
|
+
const STEP_MS = 30_000
|
|
6
|
+
|
|
7
|
+
export function newTotpSecret() {
|
|
8
|
+
let bits = ''
|
|
9
|
+
for (const b of randomBytes(20)) bits += b.toString(2).padStart(8, '0')
|
|
10
|
+
return bits.match(/.{5}/g).map(x => B32[parseInt(x, 2)]).join('')
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function fromBase32(text) {
|
|
14
|
+
let bits = ''
|
|
15
|
+
for (const c of text) bits += B32.indexOf(c).toString(2).padStart(5, '0')
|
|
16
|
+
return Buffer.from(bits.match(/.{8}/g).map(x => parseInt(x, 2)))
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function totpCode(secret, step) {
|
|
20
|
+
const counter = Buffer.alloc(8)
|
|
21
|
+
counter.writeBigUInt64BE(BigInt(step))
|
|
22
|
+
const mac = createHmac('sha1', fromBase32(secret)).update(counter).digest()
|
|
23
|
+
const at = mac[mac.length - 1] & 15
|
|
24
|
+
return String((mac.readUInt32BE(at) & 0x7fffffff) % 1_000_000).padStart(6, '0')
|
|
25
|
+
}
|
|
26
|
+
export const totpStep = (at = Date.now()) => Math.floor(at / STEP_MS)
|
|
27
|
+
|
|
28
|
+
// The step a code is good for (a clock half a minute off is fine), or null.
|
|
29
|
+
// One already used doesn't count again: someone looking over a shoulder is too late.
|
|
30
|
+
export function checkTotp(secret, code, lastStep, at = Date.now()) {
|
|
31
|
+
if (!/^\d{6}$/.test(String(code))) return null
|
|
32
|
+
const now = totpStep(at)
|
|
33
|
+
for (const step of [now - 1, now, now + 1]) {
|
|
34
|
+
if (step > (lastStep ?? 0) && totpCode(secret, step) === code) return step
|
|
35
|
+
}
|
|
36
|
+
return null
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// The secret at rest: encrypted with a key that is not in the database, and
|
|
40
|
+
// tied to its user, so a copy of the database alone gives no codes.
|
|
41
|
+
export function sealSecret(key, userId, secret) {
|
|
42
|
+
const iv = randomBytes(12)
|
|
43
|
+
const c = createCipheriv('aes-256-gcm', key, iv)
|
|
44
|
+
c.setAAD(Buffer.from(userId))
|
|
45
|
+
const body = Buffer.concat([c.update(secret, 'utf8'), c.final()])
|
|
46
|
+
return [iv, c.getAuthTag(), body].map(x => x.toString('base64url')).join('.')
|
|
47
|
+
}
|
|
48
|
+
export function openSecret(key, userId, sealed) {
|
|
49
|
+
const [iv, tag, body] = String(sealed).split('.').map(x => Buffer.from(x, 'base64url'))
|
|
50
|
+
const d = createDecipheriv('aes-256-gcm', key, iv)
|
|
51
|
+
d.setAAD(Buffer.from(userId))
|
|
52
|
+
d.setAuthTag(tag)
|
|
53
|
+
return Buffer.concat([d.update(body), d.final()]).toString('utf8')
|
|
54
|
+
}
|