tickets
All repositories: gitoria
2.0 KB
// The per-chat push destination and encrypted HMAC secret. Never returned through the API.import { env } from 'hl:proc'import { hkdfExtract, randomBytes, fromBase64, base64urlEncode, base64urlDecode, aes128gcmEncrypt, aes128gcmDecrypt } from 'hl:crypto'static pushUrlError = (url) => {if (url == '') { return null }if (hlTypeName(url) != 'String' || url.length > 500 || url.includes('?') || url.includes('#') || url.includes('@') || url.includes('\\')) { return 'invalid pushUrl' }allowed = env('TICKETS_PUSH_ALLOWED')if (allowed == null || allowed == '') { return 'pushUrl is not allowed' }for (entry of allowed.split(',')) {let base = entry.trim()while (base.endsWith('/')) { base = base.slice(0, base.length - 1) }prefix = base + '/api/push/'if ((base.startsWith('http://') || base.startsWith('https://')) && url.startsWith(prefix)) {chat = url.slice(prefix.length)if (chat == '') { return 'pushUrl needs a chat id' }let i = 0while (i < chat.length) {if (!'0123456789-'.includes(chat[i])) { return 'pushUrl chat id must contain only digits and hyphens' }i = i + 1}return null}}return 'pushUrl is not allowed'}static pushKey = () => {master = env('TICKETS_PUSH_KEY')if (master == null || master.length < 32) { return null }return hkdfExtract(toBytes(master), toBytes('tickets subscription secrets v1')).slice(0, 16)}static sealPushSecret = (secret, url) => {key = pushKey()if (key == null) { return null }nonce = fromBase64(randomBytes(12, 'base64'))cipher = aes128gcmEncrypt(key, nonce, toBytes(secret), toBytes(url))return { nonce = base64urlEncode(nonce) cipher = base64urlEncode(cipher) }}static pushSecret = (s) => {key = pushKey()if (key == null || s.secret == null) { return null }nonce = base64urlDecode(s.secret.nonce)cipher = base64urlDecode(s.secret.cipher)if (nonce == null || nonce.length != 12 || cipher == null) { return null }plain = aes128gcmDecrypt(key, nonce, cipher, toBytes(s.pushUrl))return plain == null ? null : plain.toString()}
Branches
Latest commits
- 11dc8dea|||PR Document offline shell and keyed ordering framework gapsmre
- ed091d44Merge branch 'records' into mainTickets
- 180c0cdb|||PR records: ticket move live (M32), hybriel#439mre
- 497cae7bMerge branch 'm32-move' into mainTickets
- 772e0696|||PR Allow project admins to move tickets between their projectsmre
- be92a560Merge branch 'records' into mainTickets
- 0daf2ea8|||PR records: PR-only workflow, #50 donemre
- 0185d0b6Log PR 1 deploymre
- f5bf16e2Mission 031: deploy PR 1mre
- c69cd5f3Merge branch 'pr-flow' into mainTickets
- cc56798cLog gitoria PR-only requestmre
- d876d0b2|||PR README: changes land as PRsmre
- fd83ac1fconductor: caramboleyo is the user, not owner/creatorApollo
- 3b858c91Log backup hard-link fixmre
- 7f6b37a0deploy.sh backup: tar --hard-dereference (hard links broke mpackdb sidecars on restore)mre
- e93711d9Log E30 livemre
- 59c02e4dMerge e30: preserve edited state note labels in Markdownmre
- 30970796Log E30 deploy GOmre
- 7c8e6d83Limit edited state note fix to Markdown renderingmre
- 910536d0Log E30 reviewmre