gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit61641dd961641dd9Complete subscriptions deployment evidencemre61641dd9/lib/subscription-push.hl

2.0 KB

  1. // The per-chat push destination and encrypted HMAC secret. Never returned through the API.
  2. import { env } from 'hl:proc'
  3. import { hkdfExtract, randomBytes, fromBase64, base64urlEncode, base64urlDecode, aes128gcmEncrypt, aes128gcmDecrypt } from 'hl:crypto'
  4. static pushUrlError = (url) => {
  5. if (url == '') { return null }
  6. if (hlTypeName(url) != 'String' || url.length > 500 || url.includes('?') || url.includes('#') || url.includes('@') || url.includes('\\')) { return 'invalid pushUrl' }
  7. allowed = env('TICKETS_PUSH_ALLOWED')
  8. if (allowed == null || allowed == '') { return 'pushUrl is not allowed' }
  9. for (entry of allowed.split(',')) {
  10. let base = entry.trim()
  11. while (base.endsWith('/')) { base = base.slice(0, base.length - 1) }
  12. prefix = base + '/api/push/'
  13. if ((base.startsWith('http://') || base.startsWith('https://')) && url.startsWith(prefix)) {
  14. chat = url.slice(prefix.length)
  15. if (chat == '') { return 'pushUrl needs a chat id' }
  16. let i = 0
  17. while (i < chat.length) {
  18. if (!'0123456789-'.includes(chat[i])) { return 'pushUrl chat id must contain only digits and hyphens' }
  19. i = i + 1
  20. }
  21. return null
  22. }
  23. }
  24. return 'pushUrl is not allowed'
  25. }
  26. static pushKey = () => {
  27. master = env('TICKETS_PUSH_KEY')
  28. if (master == null || master.length < 32) { return null }
  29. return hkdfExtract(toBytes(master), toBytes('tickets subscription secrets v1')).slice(0, 16)
  30. }
  31. static sealPushSecret = (secret, url) => {
  32. key = pushKey()
  33. if (key == null) { return null }
  34. nonce = fromBase64(randomBytes(12, 'base64'))
  35. cipher = aes128gcmEncrypt(key, nonce, toBytes(secret), toBytes(url))
  36. return { nonce = base64urlEncode(nonce) cipher = base64urlEncode(cipher) }
  37. }
  38. static pushSecret = (s) => {
  39. key = pushKey()
  40. if (key == null || s.secret == null) { return null }
  41. nonce = base64urlDecode(s.secret.nonce)
  42. cipher = base64urlDecode(s.secret.cipher)
  43. if (nonce == null || nonce.length != 12 || cipher == null) { return null }
  44. plain = aes128gcmDecrypt(key, nonce, cipher, toBytes(s.pushUrl))
  45. return plain == null ? null : plain.toString()
  46. }

Branches

Latest commits

  • 61641dd9Complete subscriptions deployment evidencemre
  • c980856cRecord successful subscriptions deployment and live checksmre
  • 4b4710adMerge branch 's51-subscriptions'mre
  • a731ef7eTickets conductor: S51 reviewed, deploy stepmre
  • b487b05aRecord verified direct push protocol handoffmre
  • 74e34cc3Verify encrypted push secrets and direct push retry semanticsmre
  • a1ac5cd0Push subscription notices directly to signed HyperConductor chat endpointsmre
  • d662ad27Remove superseded waker service for direct chat push protocolmre
  • c0ac927aTickets conductor: S51 redo for push protocolmre
  • ff2e8701Finalize subscription build verification and handoff reportmre
  • 07c6daeeTickets conductor: push allowlist URLsmre
  • 8517d14cTickets conductor: Hermes push endpointmre
  • aa4e192cTickets conductor: brief 027 push protocol changemre
  • 54bc5fe1Harden delta relevance, overflow caps and retry verificationmre
  • 8d8e2053Document subscription contract and exercise delta deliverymre
  • fd23726aAdd subscription delta API and signed wake bridgemre
  • c5d28fb5Tickets conductor: S51 startedmre
  • fd6ca1e6Tickets conductor: brief 027 waker design, push-test projectmre
  • e448e656Tickets conductor: STATUS #51mre
  • 1c10857bTickets conductor: P51 eval, brief 027mre