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
- 36984386Preserve state transitions when their notes are editedmre
- d75cb946Log E30 startmre
- 0bf3fefaMission 030: edited state note labelmre
- 691565c6Log neutral-ticket rule checkmre
- bc3bdecerecords: day38b live, #94 purgedmre
- f6c5aa0dMerge main (records)mre
- e23d42acconnect gate: wait for hydration before clicking Disconnectmre
- a5d45d00records: D38 cause, GOmre
- 19eeb938records: D38 gates, two day38b failuresmre
- f8e42a85Re-vendor tickets to Hybriel set day38b (1e554d7)mre
- 51645016Merge purge-94 (#94, identity rule)mre
- 94d6ca2arecords: D38 startedmre
- 9df09aacmission 029: day38b re-vendor + deploymre
- d2834f65records: #94 backup planmre
- 4467d8cbrecords: #94 purge readymre
- aa2d124eREADME: the #94 purge gatemre
- e843ff7cOne-time purge of miserit-anthar#94 (#94, identity rule): idempotent step in lib/migrate.hl, fixture gate tests/purge94.mjsmre
- 506a4efdmission 028: #94, identity rulemre
- 78c7f48eRefine mpackdb holdmre
- 3d7d89c8Record mpackdb hold until day38mre