sideora 0.0.1-alpha.0 → 0.1.0-alpha.2

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.
Files changed (221) hide show
  1. package/LICENSE.md +9 -0
  2. package/README.md +57 -6
  3. package/assets/sounds/freesound_community-mail-40275.mp3 +0 -0
  4. package/assets/sounds/mixkit-clear-announce-tones-2861.wav +0 -0
  5. package/assets/sounds/mixkit-happy-bells-notification-937.wav +0 -0
  6. package/assets/sounds/mixkit-musical-alert-notification-2309.wav +0 -0
  7. package/assets/sounds/nice-chime.mp3 +0 -0
  8. package/bin/sideora.js +2430 -12
  9. package/extension/dist/assets/background.ts-NW8YqAlO.js +1 -0
  10. package/extension/dist/assets/fillCode-Ci8IkBvY.js +1 -0
  11. package/extension/dist/assets/index.html-DrrPha1M.js +2 -0
  12. package/extension/dist/assets/modulepreload-polyfill-DcjICKwh.js +1 -0
  13. package/extension/dist/assets/shell-82MNMljp.css +1 -0
  14. package/extension/dist/assets/shell-QYBN1bx1.js +1 -0
  15. package/extension/dist/icons/icon-128.png +0 -0
  16. package/extension/dist/icons/icon-16.png +0 -0
  17. package/extension/dist/icons/icon-32.png +0 -0
  18. package/extension/dist/icons/icon-48.png +0 -0
  19. package/extension/dist/manifest.json +40 -0
  20. package/extension/dist/service-worker-loader.js +1 -0
  21. package/extension/dist/src/newtab/index.html +14 -0
  22. package/extension/dist/src/panel/index.html +15 -0
  23. package/extension/dist-web/assets/abnfDiagram-WEYOIA3C-CoXOc872.js +1 -0
  24. package/extension/dist-web/assets/apple-touch-icon-DSgRQASq.png +0 -0
  25. package/extension/dist-web/assets/architecture-WOLXFQ4H-BkJ4AerO.js +1 -0
  26. package/extension/dist-web/assets/architectureDiagram-ZHVYKT53-aPkSDlxA.js +36 -0
  27. package/extension/dist-web/assets/blockDiagram-RJAE7QA3-CH1G4NBZ.js +140 -0
  28. package/extension/dist-web/assets/c4Diagram-XDPPPE54-Baum1zDu.js +38 -0
  29. package/extension/dist-web/assets/channel-PsQg-mnK.js +1 -0
  30. package/extension/dist-web/assets/chunk-2E7WHVMD-CKvLrWRa.js +88 -0
  31. package/extension/dist-web/assets/chunk-2Q5K7J3B-C1jixKkw.js +1 -0
  32. package/extension/dist-web/assets/chunk-4EMNKR2T-6fjnroCZ.js +1 -0
  33. package/extension/dist-web/assets/chunk-55XCU76K-Ygs3sNpi.js +1 -0
  34. package/extension/dist-web/assets/chunk-5VM5RSS4-ZNzvKenW.js +15 -0
  35. package/extension/dist-web/assets/chunk-7S6XSTFO-iX5xYzfP.js +2 -0
  36. package/extension/dist-web/assets/chunk-AQDTSKZB-D9zwhFI8.js +72 -0
  37. package/extension/dist-web/assets/chunk-DSNLSHJZ-siGS-4qu.js +129 -0
  38. package/extension/dist-web/assets/chunk-DUW6YSOI-Dgx8z5s3.js +1 -0
  39. package/extension/dist-web/assets/chunk-HAGFOTED-_3dtnWXn.js +62 -0
  40. package/extension/dist-web/assets/chunk-HNE4Q36P-BPzRHi72.js +1 -0
  41. package/extension/dist-web/assets/chunk-J5ZVWO5B-oDCd-gWO.js +1 -0
  42. package/extension/dist-web/assets/chunk-JWPE2WC7-DVXcaiue.js +1 -0
  43. package/extension/dist-web/assets/chunk-NGNAAXSQ-DI_UYJZ4.js +136 -0
  44. package/extension/dist-web/assets/chunk-NQOKRVIF-AXbmOBjs.js +213 -0
  45. package/extension/dist-web/assets/chunk-UHW7PFBP-B3xrZ8sD.js +1 -0
  46. package/extension/dist-web/assets/chunk-VQ5W62QI-D_k7Pa6b.js +1 -0
  47. package/extension/dist-web/assets/chunk-WQQL4CDK-BBIrWwoZ.js +10 -0
  48. package/extension/dist-web/assets/chunk-XXDRQBXY-i7MKP1NY.js +1 -0
  49. package/extension/dist-web/assets/chunk-Y2CYZVJY-DsF7k-Jl.js +1 -0
  50. package/extension/dist-web/assets/chunk-YZO67HFG-Z7qp5QAI.js +1 -0
  51. package/extension/dist-web/assets/chunk-ZAUX2LTX-CSt3c0Rb.js +1 -0
  52. package/extension/dist-web/assets/chunk-ZCHMQSOR-g8XRABGK.js +2 -0
  53. package/extension/dist-web/assets/classDiagram-v2-4MYWR3UA-BL706wzc.js +217 -0
  54. package/extension/dist-web/assets/cose-bilkent-JH36ORCC-C6J2IoHg.js +1 -0
  55. package/extension/dist-web/assets/cynefin-EF2NZ3EQ-DLhQOiAy.js +1 -0
  56. package/extension/dist-web/assets/cynefinDiagram-WF24UDRP-Cv9Lx6_l.js +62 -0
  57. package/extension/dist-web/assets/cytoscape.esm-nTrd5EVq.js +321 -0
  58. package/extension/dist-web/assets/d3-scale-CElPUUud.js +1 -0
  59. package/extension/dist-web/assets/d3-selection-COWvaQNI.js +1 -0
  60. package/extension/dist-web/assets/dagre-NK4GIZVX-ngM-w2EC.js +4 -0
  61. package/extension/dist-web/assets/diagram-CBK3MWTC-kp8sayNG.js +24 -0
  62. package/extension/dist-web/assets/diagram-I5XIIV2D-BZ_Dgs6K.js +24 -0
  63. package/extension/dist-web/assets/diagram-ODIL2UCW-DWhUyArG.js +30 -0
  64. package/extension/dist-web/assets/diagram-PFBEJUXE-CBAdEK7l.js +3 -0
  65. package/extension/dist-web/assets/diagram-RJA3I4VV-kOdIr_3K.js +41 -0
  66. package/extension/dist-web/assets/diagram-TYUNFSNR-BrWGa0x5.js +200 -0
  67. package/extension/dist-web/assets/dist-DdXDFcej.js +1 -0
  68. package/extension/dist-web/assets/docx-preview-D1zbEiLy.js +20 -0
  69. package/extension/dist-web/assets/earth-Ce3xs8Cb.webp +0 -0
  70. package/extension/dist-web/assets/ebnfDiagram-V4P3TTPT-0r3weWmj.js +1 -0
  71. package/extension/dist-web/assets/elk-QONTBCTQ-D3oElRZ3.js +27 -0
  72. package/extension/dist-web/assets/erDiagram-KYQIGQAA-B9oU7_j_.js +99 -0
  73. package/extension/dist-web/assets/eventmodeling-K75KTNOO-CMKgc1nP.js +1 -0
  74. package/extension/dist-web/assets/favicon-D_X6tUVf.svg +5 -0
  75. package/extension/dist-web/assets/flowDiagram-IUGLLWBU-yRwks0Mw.js +1 -0
  76. package/extension/dist-web/assets/ganttDiagram-R7GPNTJY-cJqD1qwQ.js +292 -0
  77. package/extension/dist-web/assets/gitGraph-VSP46ZUC-CuBQqkbr.js +1 -0
  78. package/extension/dist-web/assets/gitGraphDiagram-PDYL7XHY-D7bHnQXC.js +106 -0
  79. package/extension/dist-web/assets/graphlib-DS17s2tU.js +1 -0
  80. package/extension/dist-web/assets/home-CV7-8Trs.js +1 -0
  81. package/extension/dist-web/assets/index-CQvw7Wy_.js +7 -0
  82. package/extension/dist-web/assets/index-CVKnZ21i.css +1 -0
  83. package/extension/dist-web/assets/info-OHQRW6UA-B8kyzV4O.js +1 -0
  84. package/extension/dist-web/assets/infoDiagram-MVDRKAX5-CEm6lezX.js +2 -0
  85. package/extension/dist-web/assets/ishikawaDiagram-HPEHV2GE-Ce3uv2wr.js +70 -0
  86. package/extension/dist-web/assets/journeyDiagram-BOSHW7O7-QgdahHCP.js +139 -0
  87. package/extension/dist-web/assets/jszip.min-3XXygzvy.js +2 -0
  88. package/extension/dist-web/assets/kanban-definition-FNSA4HC5-DPuTtWgR.js +89 -0
  89. package/extension/dist-web/assets/katex-MEuSR36T.js +257 -0
  90. package/extension/dist-web/assets/mermaid-parser.core-h7U7YGn_.js +7 -0
  91. package/extension/dist-web/assets/mermaid.core-DkGhophj.js +44 -0
  92. package/extension/dist-web/assets/mindmap-definition-6OY57UG3-D7VQxbda.js +98 -0
  93. package/extension/dist-web/assets/mount-CBzzf6KQ.js +195 -0
  94. package/extension/dist-web/assets/mount-DtvYnQXt.css +1 -0
  95. package/extension/dist-web/assets/officeparser.browser.slim-kEjhTrQ1.js +1989 -0
  96. package/extension/dist-web/assets/packet-JDAUHWVQ-oafHgw6X.js +1 -0
  97. package/extension/dist-web/assets/pegDiagram-ECIUJNBX-C3zo1naj.js +1 -0
  98. package/extension/dist-web/assets/peoria-B5TBlKDG.jpg +0 -0
  99. package/extension/dist-web/assets/peoria-thumb-CN8upAdZ.jpg +0 -0
  100. package/extension/dist-web/assets/pie-XZMESJXO-DXzeBQqF.js +1 -0
  101. package/extension/dist-web/assets/pieDiagram-GNMPY74T-S5NzPthl.js +39 -0
  102. package/extension/dist-web/assets/quadrantDiagram-D57K4MC3-C9glHQmk.js +7 -0
  103. package/extension/dist-web/assets/radar-ABXABTNO-CWTNqtbu.js +1 -0
  104. package/extension/dist-web/assets/railroad-I3PHUGI6-BTpD5_Bu.js +1 -0
  105. package/extension/dist-web/assets/railroad-abnf-LNEFI6M7-bWyxoXQG.js +1 -0
  106. package/extension/dist-web/assets/railroad-ebnf-DWYD2UWJ-ri5733DQ.js +1 -0
  107. package/extension/dist-web/assets/railroad-peg-JR7BVNR7-CmGfTubP.js +1 -0
  108. package/extension/dist-web/assets/railroadDiagram-Y72NRBL7-DTfe6Dh1.js +1 -0
  109. package/extension/dist-web/assets/requirementDiagram-EQYSW5RA-DQDzcS3L.js +84 -0
  110. package/extension/dist-web/assets/rolldown-runtime-COiEfhsA.js +1 -0
  111. package/extension/dist-web/assets/rough.esm-Dy-Kn_BL.js +1 -0
  112. package/extension/dist-web/assets/sankeyDiagram-SY24JHO5-DyMKWxdB.js +40 -0
  113. package/extension/dist-web/assets/sequenceDiagram-BLEHNHQU-dIkB1mCn.js +169 -0
  114. package/extension/dist-web/assets/sizeCapture-INFHLROL-3uHXrFqA.js +1 -0
  115. package/extension/dist-web/assets/stateDiagram-v2-A6IESKWZ-Bj_vxEVF.js +291 -0
  116. package/extension/dist-web/assets/swimlanes-B3ENRKFQ-BSkWEwHR.js +1 -0
  117. package/extension/dist-web/assets/swimlanesDiagram-AYQRV4AK-BTzSDlSM.js +8 -0
  118. package/extension/dist-web/assets/timeline-definition-JXYKGLGB-TwfWS0pw.js +120 -0
  119. package/extension/dist-web/assets/treeView-D4JQ5SDB-BzA_8YYb.js +1 -0
  120. package/extension/dist-web/assets/treemap-SAJKECNS-BI9d6--2.js +1 -0
  121. package/extension/dist-web/assets/usecaseDiagram-WPOLBNNX-BOVbAUPk.js +328 -0
  122. package/extension/dist-web/assets/vennDiagram-Q3Y3IDCW-X2kYAWaj.js +34 -0
  123. package/extension/dist-web/assets/wardley-7MLQ67FV-CItxqJ8G.js +1 -0
  124. package/extension/dist-web/assets/wardleyDiagram-IVAIDKWA-BnUXvKD_.js +78 -0
  125. package/extension/dist-web/assets/xychartDiagram-4URNHDU4-ysvBXvyE.js +7 -0
  126. package/extension/dist-web/icon-192.png +0 -0
  127. package/extension/dist-web/icon-512.png +0 -0
  128. package/extension/dist-web/index.html +25 -0
  129. package/extension/dist-web/manifest.webmanifest +14 -0
  130. package/package.json +64 -12
  131. package/plugin/.claude-plugin/icon.png +0 -0
  132. package/plugin/.claude-plugin/plugin.json +6 -0
  133. package/plugin/.mcp.json +8 -0
  134. package/plugin/README.md +72 -0
  135. package/plugin/mcp-launcher.mjs +48 -0
  136. package/src/account-probe.js +45 -0
  137. package/src/accounts.js +687 -0
  138. package/src/ai.js +269 -0
  139. package/src/assistant-runs.js +32 -0
  140. package/src/attached-mail.js +76 -0
  141. package/src/auth-gate.js +70 -0
  142. package/src/backup-cli.js +158 -0
  143. package/src/backup.js +329 -0
  144. package/src/bimi.js +233 -0
  145. package/src/bridge.js +101 -0
  146. package/src/calendar-alerts.js +56 -0
  147. package/src/chats.js +27 -0
  148. package/src/compose-editor.js +58 -0
  149. package/src/config.js +420 -0
  150. package/src/connections.d.ts +24 -0
  151. package/src/connections.js +37 -0
  152. package/src/core/agent.js +92 -0
  153. package/src/core/assistant.d.ts +13 -0
  154. package/src/core/assistant.js +790 -0
  155. package/src/core/chats.js +323 -0
  156. package/src/core/markdown.d.ts +8 -0
  157. package/src/core/markdown.js +239 -0
  158. package/src/core/notes.js +445 -0
  159. package/src/core/otp.js +152 -0
  160. package/src/core/rules.js +196 -0
  161. package/src/core/runs.d.ts +9 -0
  162. package/src/core/runs.js +211 -0
  163. package/src/core/thread.js +526 -0
  164. package/src/core/write.js +247 -0
  165. package/src/core-db.js +131 -0
  166. package/src/core.js +174 -0
  167. package/src/credentials.js +320 -0
  168. package/src/daemon.js +564 -0
  169. package/src/events.js +213 -0
  170. package/src/extension-id.d.ts +2 -0
  171. package/src/extension-id.js +5 -0
  172. package/src/file-lock.js +27 -0
  173. package/src/files-index.js +154 -0
  174. package/src/google-contacts.js +315 -0
  175. package/src/google-signin.js +306 -0
  176. package/src/host/assistant-html.js +44 -0
  177. package/src/host/chats-files.js +137 -0
  178. package/src/host/file-prep.js +122 -0
  179. package/src/host/notes-files.js +158 -0
  180. package/src/host/office-text.js +224 -0
  181. package/src/host/office-worker.js +8 -0
  182. package/src/host/rules-file.js +20 -0
  183. package/src/host/secrets-file.js +91 -0
  184. package/src/host/systemd.js +90 -0
  185. package/src/hub.js +245 -0
  186. package/src/identity.js +316 -0
  187. package/src/labels.js +5 -0
  188. package/src/mail-port.d.ts +79 -0
  189. package/src/mail-port.js +148 -0
  190. package/src/mcp-server.js +747 -0
  191. package/src/microsoft-app.js +20 -0
  192. package/src/microsoft-signin.js +194 -0
  193. package/src/migrate.js +327 -0
  194. package/src/notes-html.js +450 -0
  195. package/src/notes.js +19 -0
  196. package/src/notify.js +105 -0
  197. package/src/onepassword.js +223 -0
  198. package/src/op-registry.d.ts +14 -0
  199. package/src/op-registry.js +150 -0
  200. package/src/ops.js +1251 -0
  201. package/src/otp.js +6 -0
  202. package/src/panel-ops.js +273 -0
  203. package/src/pictures.js +735 -0
  204. package/src/postinstall.js +25 -0
  205. package/src/relay-passkey.js +122 -0
  206. package/src/relay-request.js +155 -0
  207. package/src/relay-seal.js +56 -0
  208. package/src/relay-settings.js +139 -0
  209. package/src/relay.js +876 -0
  210. package/src/render.js +82 -0
  211. package/src/rules-store.js +8 -0
  212. package/src/safe-fetch.js +215 -0
  213. package/src/sender-auth.js +270 -0
  214. package/src/site-match.js +77 -0
  215. package/src/tui-agenda.js +266 -0
  216. package/src/tui.js +670 -0
  217. package/src/vmc.js +376 -0
  218. package/src/wake.js +96 -0
  219. package/src/web-access.js +185 -0
  220. package/src/web-server.js +241 -0
  221. package/src/web-service.js +152 -0
package/src/vmc.js ADDED
@@ -0,0 +1,376 @@
1
+ // Mark certificates: the certificate a BIMI record's a= names. A Verified Mark
2
+ // Certificate (VMC) says a trademark office registered this logo for the
3
+ // organisation that holds the domain; a Common Mark Certificate (CMC) is
4
+ // accepted too, though it proves less: a mark in prior use (shown on the
5
+ // organisation's site for a year), or a government's mark, with no
6
+ // registration behind it. Both are issued under the same roots, with the
7
+ // same key usage, and a CA checked who the organisation is. A logo that
8
+ // comes with a valid one is shown for any sender whose mail passed DMARC for
9
+ // that domain (sender-auth.js); without one, only for domains the person
10
+ // already corresponds with (pictures.js).
11
+ //
12
+ // Checked here, with node:crypto and a little DER reading:
13
+ // - the chain: leaf → the certificate(s) the PEM brings → one of the pinned
14
+ // mark-certificate roots below (each signature verified; the root the PEM
15
+ // brings along is not used, only the pinned one with the same key);
16
+ // - every certificate in the chain, pinned root included, within its dates
17
+ // now; the earliest end date of them all is when the result stops counting;
18
+ // - the path: each CA above the leaf a CA (basicConstraints), its
19
+ // pathLenConstraint respected; a certificate with nameConstraints anywhere
20
+ // in the chain is refused (not applied: refused), and so is one with a
21
+ // critical extension not read here;
22
+ // - the leaf: not a CA, extended key usage BIMI (1.3.6.1.5.5.7.3.31), and a
23
+ // subjectAltName dNSName equal to the BIMI domain or the sender's domain;
24
+ // - the logo: the subject's own logo in the certificate (logotype extension
25
+ // 1.3.6.1.5.5.7.1.12, subjectLogo [2]: data:image/svg+xml;base64 of a
26
+ // gzipped SVG; never a community or issuer logo), not l=. It is then
27
+ // cleaned like any other SVG (bimi.js).
28
+ // Not checked: revocation (no CRL, no OCSP), Certificate Transparency.
29
+
30
+ import { X509Certificate } from 'node:crypto';
31
+ import zlib from 'node:zlib';
32
+ import { sanitizeSvg, MAX_SVG } from './bimi.js';
33
+
34
+ export const MAX_PEM = 64 * 1024;
35
+ const EKU_BIMI = '1.3.6.1.5.5.7.3.31';
36
+
37
+ // The roots mark certificates chain to, each from its issuer's own repository (the URL its certificates' AIA name),
38
+ // with its SHA-256 fingerprint; checked against the copies inside real VMCs (test/fixtures/vmc).
39
+ // DigiCert (VMC and CMC): https://cacerts.digicert.com/DigiCertVerifiedMarkRootCA.crt
40
+ // GlobalSign (VMC and CMC): https://secure.globalsign.com/cacert/gsverifiedmarkrootr42.crt
41
+ // SSL.com, also Sectigo's and Entrust's current VMCs: http://cert.ssl.com/SSL.com-VMC-Root-2024-RSA.cer and -ECC.cer
42
+ // Entrust's older root (Entrust Verified Mark Root Certification Authority - VMCR1) is not here: its repository
43
+ // refused to hand it over, and Entrust now issues through Sectigo, under SSL.com's root.
44
+ export const ROOTS = [
45
+ {
46
+ name: 'DigiCert Verified Mark Root CA',
47
+ sha256: '50:43:86:C9:EE:89:32:FE:CC:95:FA:DE:42:7F:69:C3:E2:53:4B:73:10:48:9E:30:0F:EE:44:8E:33:C4:6B:42',
48
+ source: 'https://cacerts.digicert.com/DigiCertVerifiedMarkRootCA.crt',
49
+ pem: `-----BEGIN CERTIFICATE-----
50
+ MIIF3jCCA8agAwIBAgIQBsFnz+v0jTXWJBAYXhHF6zANBgkqhkiG9w0BAQsFADCB
51
+ iDELMAkGA1UEBhMCVVMxDTALBgNVBAgTBFV0YWgxDTALBgNVBAcTBExlaGkxFzAV
52
+ BgNVBAoTDkRpZ2lDZXJ0LCBJbmMuMRkwFwYDVQQLExB3d3cuZGlnaWNlcnQuY29t
53
+ MScwJQYDVQQDEx5EaWdpQ2VydCBWZXJpZmllZCBNYXJrIFJvb3QgQ0EwHhcNMTkw
54
+ OTIzMTIxMjA2WhcNNDkwOTIzMTIxMjA2WjCBiDELMAkGA1UEBhMCVVMxDTALBgNV
55
+ BAgTBFV0YWgxDTALBgNVBAcTBExlaGkxFzAVBgNVBAoTDkRpZ2lDZXJ0LCBJbmMu
56
+ MRkwFwYDVQQLExB3d3cuZGlnaWNlcnQuY29tMScwJQYDVQQDEx5EaWdpQ2VydCBW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dA6UFIHdMSIzLHZylzjuwciI706x83Ib17DMKO
73
+ cpO2QVB7Beqv240TWxKxH21pFZsl44OgI+HcAPDbfJe3PEzwEZKNcKRkMWa/FFu2
74
+ ckQxpTcfZABrarnuRLcSINiodSW7VfxctzegXWM4WmQeutPBOicceV3J4ZVkhthB
75
+ m784vES1DIuDTqT9/iqStBGN8eOGx9qKvjaXT8SdcrP58FpXrtm/xKgtILptxfVT
76
+ 042oogQfb2cNahKRSvs0xH3jyhO944t0zMH/bEpRdU36wR1/Fo56zXy2Zv4czMwg
77
+ 3Hg7mbAalJvcnBvH+NHPgucQI432XX11K29vz7HuNC7P9yKhxns+MbOQDMDPOhtS
78
+ LUpBmzRNG4+2BZJZyKGqYd+STHisEGYeYCi3MVrwSe2UqcDi9f2UAWVbkDE/YB6/
79
+ e7+C7o6UWkXSU7dzR7FwFsfBHi6EqgIb2e9pINAxdvlc/3E19Ld/GJEtlw7nSdzp
80
+ 71eMp5Z48iY54fV2lM/rXogS1R4r3p2oPe9efG0XaJMd0v1gom5Da/khJA7+wjRB
81
+ 0wberd/tg3N0dJsSSznZjwYB
82
+ -----END CERTIFICATE-----`
83
+ },
84
+ {
85
+ name: 'GlobalSign Verified Mark Root R42',
86
+ sha256: 'CD:12:2C:B8:77:C6:92:8B:90:17:B0:F0:B8:0D:BD:50:81:96:30:0B:BD:03:CD:73:56:C3:BE:EF:52:4E:7E:0B',
87
+ source: 'https://secure.globalsign.com/cacert/gsverifiedmarkrootr42.crt',
88
+ pem: `-----BEGIN CERTIFICATE-----
89
+ MIIFdDCCA1ygAwIBAgIQf+UwA4GYp199F8APJCyr8zANBgkqhkiG9w0BAQwFADBU
90
+ MQswCQYDVQQGEwJCRTEZMBcGA1UEChMQR2xvYmFsU2lnbiBudi1zYTEqMCgGA1UE
91
+ AxMhR2xvYmFsU2lnbiBWZXJpZmllZCBNYXJrIFJvb3QgUjQyMB4XDTIzMTExNTAz
92
+ NDA1MloXDTQyMTExNTAwMDAwMFowVDELMA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nZ6
108
+ t8OZEu3nr6DHAuImAonIqO8HcBcgwydDIAeD7GOafOZ47mRkYOFIa+tkJ21pfmJv
109
+ KUt3ASW1uLAHCJNYHVLXs7txnq1mRKuwyuaeb6JdTazzjXgNDLZQgvOfM7mkDf6f
110
+ S2Z+dbKOZBYwo6zspqoQc1s6k0Xg9h7oEiJCC+3FUfJQSYyi2bynZSEn2c67OSFT
111
+ fqXVr9nhlaawLGEKUaFlYeQspUO5MUFYmGWqnf38M8ZM0rPx5R00jZ/E5sKcSqFH
112
+ CaVghDPiVv9Jzs8gNllwDbi7rXwMstaKATJJXiWgSdsxrfQr7+FRyXQJmRVXKxZ6
113
+ 6uNe1ZgAzgNbjCvGmwF1StBtr1DrdOSk7sOMBMuJftB2g9/K67VUfz+jkylIbv5y
114
+ bvnCqBoAvq2DSQ76O5WyWiTBkPYp2Fh/WMHkXVIQpT6Q7FMTiGxtAxv69sq1CeJ9
115
+ i9g/iAJBdToQwJwH80Ah3hSPg1DQ8LTIjTtOxxkJ6Aeh/XU1/w9lW91XGLgXye1U
116
+ fjUIWKsoe1rE2RK+RSP6BZWcRNhJOyqi40gdTRLJkbc0Itq/62NFV4mIWcWKafhb
117
+ 4ZOU1rvk1woeteJJZHd7cLakW6ONJAEtWGe43ZVx/lqFXQH4kOMPuR/7h2G1Aie6
118
+ Fk6hsIjUv20=
119
+ -----END CERTIFICATE-----`
120
+ },
121
+ {
122
+ name: 'SSL.com VMC RSA Root CA 2024',
123
+ sha256: '8F:9D:1B:76:98:88:67:82:A5:99:B4:85:10:65:1C:66:A1:AA:0C:5C:A3:19:20:97:BD:C6:85:34:15:4B:D3:0D',
124
+ source: 'http://cert.ssl.com/SSL.com-VMC-Root-2024-RSA.cer',
125
+ pem: `-----BEGIN CERTIFICATE-----
126
+ MIIFiTCCA3GgAwIBAgIQcJRvrr6zzODYb7h2d4BhyzANBgkqhkiG9w0BAQsFADBO
127
+ MQswCQYDVQQGEwJVUzEYMBYGA1UECgwPU1NMIENvcn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oAUwTWi9FnZB3aX/croa3fWJq56WvswHQYDVR0OBBYEFME1ovRZ2Qd2l/3K
144
+ 6Gt31iauelr7MA4GA1UdDwEB/wQEAwIBhjANBgkqhkiG9w0BAQsFAAOCAgEAIet3
145
+ +K2+sef6SZBE+5cFsnKYtagi50I1iECJQziusyw1wK9Keman4TZshwio4Z/nvaq2
146
+ ed3s3YYFL6BGksJTJPImrEaQI3aqHa16AEzw6F2k3gz78wbcpjygGJMekVrhyF5l
147
+ E+ErRcY9JGo1IGscBYlZcXkHJThNO9gEyoH+os73KIsY4120CBe3jbfOhRpDZioF
148
+ wUxepdzEzx8ZRXGsz58m+0NS0cBcvkqpIpnI2TFDT/lK0s2ys65h2YLhDsUnhtJ2
149
+ Kd8boP+ImazgpfpjgVEeCCpoPzWmmlMzxr083f0Mya4uSPidk/FkVYo3l+NAUcfH
150
+ WcfH6ca7Xrm5DXsOaP0cDWaYphbEKVVi164V03fNClW3p7xzLCDUfzdAaQs1JY1G
151
+ h0GgH4dNdp+BgGjjUPZ86IZhCuOq0rm3czfxb25l6WuAf7A0gq4oVgMNbbIepap8
152
+ YRbbU3nGl4A+s6qjtIhy6QGVWYqwQVElP7ba1sbhqLu5Uu/QyI/B5uEBO3oTvNgc
153
+ pld8jFKTqIO9yFgzvIO6XhfwW5VvLHozlzb7fM8hPKnrdd5HT3XnFTkKl/y4zLrw
154
+ OnvNhh5QMQe+HEnpScufX/cFPh568bVicV061IvLoGr84rlgxO+RjWuILOiXCVi0
155
+ 7JsQLmpgD+ebpTit7HrVpCJa1SZXeHlzkc/yI74=
156
+ -----END CERTIFICATE-----`
157
+ },
158
+ {
159
+ name: 'SSL.com VMC ECC Root CA 2024',
160
+ sha256: '1B:82:E7:F4:91:0B:51:E3:E8:02:A4:93:AC:DC:17:FF:58:EA:C8:B9:EB:7C:09:B5:2A:C6:CD:2E:FB:83:59:8C',
161
+ source: 'http://cert.ssl.com/SSL.com-VMC-Root-2024-ECC.cer',
162
+ pem: `-----BEGIN CERTIFICATE-----
163
+ MIICOjCCAcCgAwIBAgIQEUfBai0/SvdnXWXlwaytjjAKBggqhkjOPQQDAzBOMQsw
164
+ CQYDVQQGEwJVUzEYMBYGA1UECgwPU1NMIENvcnBvcmF0aW9uMSUwIwYDVQQDDBxT
165
+ U0wuY29tIFZNQyBFQ0MgUm9vdCBDQSAyMDI0MB4XDTI0MDIxOTE2MjUzMFoXDTQ4
166
+ MDIxMzE2MjUyOVowTjELMAkGA1UEBhMCVVMxGDAWBgNVBAoMD1NTTCBDb3Jwb3Jh
167
+ dGlvbjElMCMGA1UEAwwcU1NMLmNvbSBWTUMgRUNDIFJvb3QgQ0EgMjAyNDB2MBAG
168
+ ByqGSM49AgEGBSuBBAAiA2IABAlYNKIok2H2MoERpO66/tfLns/aRbbVN8HhNGbe
169
+ znXOJhQozKiHoCOCN7bCCuMdpAXVosUptXs+8Sksd8Hluh91J1W1QQVi9KyFSwgM
170
+ VTAynuA64X9MbrQNwkZaCQXPtKNjMGEwDwYDVR0TAQH/BAUwAwEB/zAfBgNVHSME
171
+ GDAWgBQl8MYq5N4ipgAt8VK4J42gUeKgpTAdBgNVHQ4EFgQUJfDGKuTeIqYALfFS
172
+ uCeNoFHioKUwDgYDVR0PAQH/BAQDAgGGMAoGCCqGSM49BAMDA2gAMGUCMHkYwAy0
173
+ rQ/BXQCanvUeTylOOCbaIO+rbFxOY8KF+AHmv0MJI7t++BnWUE1XwYABXAIxAKbi
174
+ 1Mpz6UpoC5yWsed9Z1rhT+pMwzPwNrdsRMLAesSq2Jbv0UGQ/1uJcM/6OtDFgQ==
175
+ -----END CERTIFICATE-----`
176
+ }
177
+ ];
178
+
179
+ let pinned = null;
180
+ /** The pinned roots, parsed once; one whose fingerprint is not the one written beside it is left out. */
181
+ function pinnedRoots() {
182
+ if (pinned) return pinned;
183
+ pinned = ROOTS.map((r) => { const c = new X509Certificate(r.pem); return c.fingerprint256 === r.sha256 ? c : null; }).filter(Boolean);
184
+ return pinned;
185
+ }
186
+
187
+ export class VmcRefused extends Error {
188
+ constructor(message) { super(message); this.name = 'VmcRefused'; }
189
+ }
190
+
191
+ /** The certificates of a PEM file, in order. */
192
+ export function pemCertificates(text) {
193
+ const blocks = String(text ?? '').match(/-----BEGIN CERTIFICATE-----[A-Za-z0-9+/=\s]+?-----END CERTIFICATE-----/g) || [];
194
+ if (!blocks.length || blocks.length > 6) throw new VmcRefused('not a certificate file');
195
+ return blocks.map((b) => { try { return new X509Certificate(b); } catch { throw new VmcRefused('a certificate that does not parse'); } });
196
+ }
197
+
198
+ const dateOf = (c, k) => c[`${k}Date`] instanceof Date ? c[`${k}Date`] : new Date(c[k]);
199
+ const within = (c, now) => dateOf(c, 'validFrom') <= now && now <= dateOf(c, 'validTo');
200
+ const issued = (child, parent) => { try { return child.checkIssued(parent) && child.verify(parent.publicKey); } catch { return false; } };
201
+ const dnsNames = (c) => String(c.subjectAltName || '').split(/,\s*/).filter((s) => s.startsWith('DNS:')).map((s) => s.slice(4).trim().toLowerCase());
202
+
203
+ // --- DER, as much as the logotype needs -------------------------------------------------
204
+
205
+ function tlv(buf, pos, end) {
206
+ if (pos + 2 > end) throw new VmcRefused('DER cut short');
207
+ const tag = buf[pos];
208
+ let len = buf[pos + 1];
209
+ let head = 2;
210
+ if (len & 0x80) {
211
+ const n = len & 0x7f;
212
+ if (n < 1 || n > 4 || pos + 2 + n > end) throw new VmcRefused('a DER length that does not parse');
213
+ len = 0;
214
+ for (let i = 0; i < n; i++) len = len * 256 + buf[pos + 2 + i];
215
+ head = 2 + n;
216
+ }
217
+ const start = pos + head;
218
+ if (start + len > end) throw new VmcRefused('DER cut short');
219
+ return { tag, start, end: start + len };
220
+ }
221
+ function children(buf, start, end) {
222
+ const out = [];
223
+ for (let pos = start; pos < end;) { const t = tlv(buf, pos, end); out.push(t); pos = t.end; }
224
+ return out;
225
+ }
226
+
227
+ /** An OID's content bytes → its dotted form. */
228
+ function oidText(bytes) {
229
+ const out = [];
230
+ let v = 0;
231
+ for (let i = 0; i < bytes.length; i++) {
232
+ v = v * 128 + (bytes[i] & 0x7f);
233
+ if (!(bytes[i] & 0x80)) {
234
+ if (!out.length) out.push(v < 80 ? Math.floor(v / 40) : 2, v < 80 ? v % 40 : v - 80);
235
+ else out.push(v);
236
+ v = 0;
237
+ }
238
+ }
239
+ return out.join('.');
240
+ }
241
+
242
+ /** A certificate's extensions: [{ oid, critical, value: { start, end } (the extnValue's contents) }]. */
243
+ export function extensionsOf(der) {
244
+ const cert = children(der, 0, der.length)[0];
245
+ const tbs = children(der, cert.start, cert.end)[0];
246
+ const exts = children(der, tbs.start, tbs.end).find((t) => t.tag === 0xa3);
247
+ if (!exts) return [];
248
+ const list = children(der, exts.start, exts.end)[0];
249
+ if (!list || list.tag !== 0x30) throw new VmcRefused('extensions that do not parse');
250
+ return children(der, list.start, list.end).map((ext) => {
251
+ const parts = children(der, ext.start, ext.end);
252
+ if (parts.length < 2 || parts[0].tag !== 0x06 || parts[parts.length - 1].tag !== 0x04) throw new VmcRefused('an extension that does not parse');
253
+ const critical = parts.length === 3 && parts[1].tag === 0x01 && der[parts[1].start] !== 0;
254
+ return { oid: oidText(der.subarray(parts[0].start, parts[0].end)), critical, value: parts[parts.length - 1] };
255
+ });
256
+ }
257
+
258
+ const OID = { basicConstraints: '2.5.29.19', keyUsage: '2.5.29.15', extKeyUsage: '2.5.29.37', subjectAltName: '2.5.29.17', nameConstraints: '2.5.29.30', authorityKeyId: '2.5.29.35', subjectKeyId: '2.5.29.14', logotype: '1.3.6.1.5.5.7.1.12' };
259
+ // what is read and acted on here (or by OpenSSL beneath node:crypto): a critical extension may be one of these only
260
+ const UNDERSTOOD = new Set([OID.basicConstraints, OID.keyUsage, OID.extKeyUsage, OID.subjectAltName, OID.authorityKeyId, OID.subjectKeyId, OID.logotype]);
261
+
262
+ /** basicConstraints → { ca, pathLen (null: none) }; absent → { ca: false, pathLen: null }. */
263
+ function basicConstraintsOf(der, exts) {
264
+ const bc = exts.find((e) => e.oid === OID.basicConstraints);
265
+ if (!bc) return { ca: false, pathLen: null };
266
+ const seq = children(der, bc.value.start, bc.value.end)[0];
267
+ let ca = false;
268
+ let pathLen = null;
269
+ for (const t of seq ? children(der, seq.start, seq.end) : []) {
270
+ if (t.tag === 0x01) ca = der[t.start] !== 0;
271
+ else if (t.tag === 0x02) { if (t.end - t.start > 2 || der[t.start] & 0x80) throw new VmcRefused('a path length that does not parse'); pathLen = der.readUIntBE(t.start, t.end - t.start); }
272
+ }
273
+ return { ca, pathLen };
274
+ }
275
+
276
+ /** The data: URIs (IA5String) of the subject's own logo (subjectLogo [2]) in the certificate's logotype extension. */
277
+ export function logotypeUris(der) {
278
+ const ext = extensionsOf(der).find((e) => e.oid === OID.logotype);
279
+ if (!ext) return [];
280
+ const seq = children(der, ext.value.start, ext.value.end)[0]; // LogotypeExtn ::= SEQUENCE { [0] community, [1] issuer, [2] subject, [3] other }
281
+ if (!seq || seq.tag !== 0x30) return [];
282
+ const subject = children(der, seq.start, seq.end).find((t) => t.tag === 0xa2);
283
+ if (!subject) return [];
284
+ const out = [];
285
+ const walk = (s, e, depth) => {
286
+ if (depth > 12) return;
287
+ for (const t of children(der, s, e)) {
288
+ if (t.tag === 0x16) out.push(der.subarray(t.start, t.end).toString('latin1'));
289
+ else if (t.tag & 0x20) walk(t.start, t.end, depth + 1);
290
+ }
291
+ };
292
+ walk(subject.start, subject.end, 0);
293
+ return out;
294
+ }
295
+
296
+ /** The extensions of every certificate of an accepted chain: nameConstraints refused anywhere, an unknown critical one too. */
297
+ function checkExtensions(chain) {
298
+ for (const c of chain) {
299
+ const exts = extensionsOf(c.raw);
300
+ if (exts.some((e) => e.oid === OID.nameConstraints)) throw new VmcRefused('a certificate with name constraints');
301
+ const unknown = exts.find((e) => e.critical && !UNDERSTOOD.has(e.oid));
302
+ if (unknown) throw new VmcRefused(`a critical extension not understood (${unknown.oid})`);
303
+ }
304
+ }
305
+
306
+ /** chain: [leaf, …intermediates, root]. Every one above the leaf a CA; each pathLenConstraint ≥ the CAs between it and the leaf. */
307
+ function checkPath(chain) {
308
+ for (let k = 1; k < chain.length; k++) {
309
+ const { ca, pathLen } = basicConstraintsOf(chain[k].raw, extensionsOf(chain[k].raw));
310
+ if (!ca) throw new VmcRefused('a certificate above the leaf that is not a CA');
311
+ const below = k - 1; // CA certificates between this one and the leaf
312
+ if (pathLen != null && below > pathLen) throw new VmcRefused('a path longer than a CA allows');
313
+ }
314
+ if (basicConstraintsOf(chain[0].raw, extensionsOf(chain[0].raw)).ca) throw new VmcRefused('the leaf is a CA');
315
+ }
316
+
317
+ /** The SVG a logotype data: URI holds (gzipped or not), at most MAX_SVG once inflated. */
318
+ function svgOf(uri) {
319
+ const m = /^data:image\/svg\+xml;base64,([A-Za-z0-9+/=\s]+)$/.exec(uri);
320
+ if (!m) return null;
321
+ const raw = Buffer.from(m[1].replace(/\s+/g, ''), 'base64');
322
+ let svg;
323
+ try { svg = raw[0] === 0x1f && raw[1] === 0x8b ? zlib.gunzipSync(raw, { maxOutputLength: MAX_SVG }) : raw; } catch { throw new VmcRefused('a logo that does not inflate, or too large'); }
324
+ if (svg.length > MAX_SVG) throw new VmcRefused('a logo too large');
325
+ return svg.toString('utf8');
326
+ }
327
+
328
+ /**
329
+ * A mark certificate file, checked (chain to a pinned root, dates, BIMI use,
330
+ * logo) → { svg (cleaned), names (its dNSNames), notAfter (ms) }. Which
331
+ * domain it is for is the caller's to compare with `names` (verifyMarkCertificate does).
332
+ * Throws VmcRefused (or SvgRefused) for anything that does not hold.
333
+ */
334
+ export function checkMarkCertificate(pemText, { now = new Date(), roots = pinnedRoots() } = {}) {
335
+ if (String(pemText ?? '').length > MAX_PEM) throw new VmcRefused('too large');
336
+ const certs = pemCertificates(pemText);
337
+ const leaf = certs.find((c) => !c.ca && (c.keyUsage || []).includes(EKU_BIMI));
338
+ if (!leaf) throw new VmcRefused('no mark certificate in the file');
339
+ if (!within(leaf, now)) throw new VmcRefused('the certificate is not valid now');
340
+ const names = dnsNames(leaf);
341
+ if (!names.length) throw new VmcRefused('the certificate names no domain');
342
+ // up the chain, to a pinned root
343
+ let current = leaf;
344
+ const chain = [leaf];
345
+ const used = new Set([leaf]);
346
+ for (let step = 0; step < 4; step++) {
347
+ const root = roots.find((r) => issued(current, r) && within(r, now));
348
+ if (root) {
349
+ chain.push(root);
350
+ checkExtensions(chain);
351
+ checkPath(chain);
352
+ // the result counts until the first of them ends
353
+ const notAfter = Math.min(...chain.map((c) => dateOf(c, 'validTo').getTime()));
354
+ const uris = logotypeUris(leaf.raw);
355
+ for (const uri of uris) {
356
+ const svg = svgOf(uri);
357
+ if (svg != null) return { svg: sanitizeSvg(svg), names, notAfter };
358
+ }
359
+ throw new VmcRefused('no SVG logo of the subject in the certificate');
360
+ }
361
+ const next = certs.find((c) => !used.has(c) && c.ca && within(c, now) && (!c.keyUsage || c.keyUsage.includes(EKU_BIMI)) && issued(current, c));
362
+ if (!next) throw new VmcRefused('the certificate does not chain to a mark-certificate root');
363
+ used.add(next);
364
+ chain.push(next);
365
+ current = next;
366
+ }
367
+ throw new VmcRefused('the chain is too long');
368
+ }
369
+
370
+ /** The same, for `domain` (or `orgDomain`, where the BIMI record was found): its subjectAltName must name one of them → the cleaned SVG. */
371
+ export function verifyMarkCertificate(pemText, { domain, orgDomain = domain, now = new Date(), roots } = {}) {
372
+ const r = checkMarkCertificate(pemText, { now, ...(roots ? { roots } : {}) });
373
+ const want = [String(domain).toLowerCase(), String(orgDomain).toLowerCase()];
374
+ if (!r.names.some((n) => want.includes(n))) throw new VmcRefused('the certificate is for other domains');
375
+ return r.svg;
376
+ }
package/src/wake.js ADDED
@@ -0,0 +1,96 @@
1
+ // Wake a Claude agent for a matched mail: spawn `claude -p` headless with the
2
+ // mail MCP server attached. The agent can read the full thread and create a
3
+ // reply-all DRAFT — the send button stays with the human.
4
+
5
+ import { spawn } from 'node:child_process';
6
+ import fs from 'node:fs';
7
+ import path from 'node:path';
8
+ import { LOG_DIR, MCP_CONFIG_PATH, childEnv } from './config.js';
9
+
10
+ const PROMPT_HEADER = `New mail matched the watch rule "{{rule}}".
11
+ From: {{from}} <{{fromEmail}}>
12
+ Subject: {{subject}}
13
+ Received: {{received}}
14
+ Message id: {{id}}
15
+ Account: {{account}}
16
+
17
+ Use the mail MCP tools to read this message in full (read_message), and the
18
+ rest of its thread if relevant (get_thread). Then:
19
+
20
+ 1. Write a concise action digest: what is being asked, of whom, deadlines,
21
+ step-by-step checklist if the mail contains one, and any risks/rollback
22
+ notes. Save it to {{digestDir}}/{{ts}}-digest.md.
23
+ 2. Show a macOS notification with the one-line gist:
24
+ osascript -e 'display notification "<gist>" with title "📬 {{from}}"'`;
25
+
26
+ const PROMPT_DRAFT_STEP = `
27
+ 3. If the mail asks the recipients to acknowledge or pick up a task, create a
28
+ reply-all DRAFT (draft_reply_all) acknowledging it. Do NOT send anything —
29
+ drafts only.`;
30
+
31
+ const PROMPT_FOOTER = `
32
+
33
+ Be brief and factual. Do not take any action beyond the mail tools, writing
34
+ the digest file, and the notification.`;
35
+
36
+ const READ_TOOLS = [
37
+ 'mcp__sideora__list_accounts',
38
+ 'mcp__sideora__list_unread',
39
+ 'mcp__sideora__search_mail',
40
+ 'mcp__sideora__read_message',
41
+ 'mcp__sideora__get_thread',
42
+ 'mcp__sideora__next_event',
43
+ 'mcp__sideora__save_attachments',
44
+ 'mcp__sideora__mark_read',
45
+ 'Bash(osascript:*)',
46
+ 'Write'
47
+ ];
48
+ const DRAFT_TOOLS = ['mcp__sideora__draft_reply', 'mcp__sideora__draft_reply_all', 'mcp__sideora__compose_draft', 'mcp__sideora__update_draft', 'mcp__sideora__add_attachment'];
49
+
50
+ export function wakeAgent(config, rule, item, digestDir) {
51
+ const ts = new Date().toISOString().replace(/[:.]/g, '-');
52
+ const vars = {
53
+ rule: rule.name || 'unnamed',
54
+ from: item.fromName || item.fromEmail,
55
+ fromEmail: item.fromEmail,
56
+ subject: item.subject,
57
+ received: item.received,
58
+ id: item.id,
59
+ account: item.account || '',
60
+ ts,
61
+ digestDir
62
+ };
63
+ // wake.draft: false → the agent only digests and notifies; no reply draft,
64
+ // and the draft tools are not even granted.
65
+ const draftAllowed = !(rule.wake && rule.wake.draft === false);
66
+ const defaultPrompt = PROMPT_HEADER + (draftAllowed ? PROMPT_DRAFT_STEP : '') + PROMPT_FOOTER;
67
+ const template = rule.wake && typeof rule.wake.prompt === 'string' ? rule.wake.prompt : defaultPrompt;
68
+ const prompt = template.replace(/\{\{(\w+)\}\}/g, (_, k) => String(vars[k] ?? ''));
69
+ const allowedTools = (draftAllowed ? READ_TOOLS.concat(DRAFT_TOOLS) : READ_TOOLS).join(',');
70
+
71
+ const logFile = path.join(LOG_DIR, `wake-${ts}.log`);
72
+ const out = fs.openSync(logFile, 'a');
73
+ const model = (rule.wake && rule.wake.model) || config.claudeModel || 'sonnet';
74
+
75
+ const args = [
76
+ '-p', prompt,
77
+ '--model', model,
78
+ '--mcp-config', MCP_CONFIG_PATH,
79
+ '--allowedTools', allowedTools,
80
+ // send_draft can appear mid-session when mcp.allowSend flips on; never for a woken agent
81
+ '--disallowedTools', 'mcp__sideora__send_draft'
82
+ ];
83
+
84
+ const child = spawn(config.claudePath, args, {
85
+ detached: true,
86
+ stdio: ['ignore', out, out],
87
+ cwd: digestDir,
88
+ // no password of an account (credentials.env) nor a 1Password token goes to the agent
89
+ env: childEnv({ PATH: `${process.env.PATH || ''}:/opt/homebrew/bin:/usr/local/bin` })
90
+ });
91
+ child.on('error', (e) => {
92
+ fs.appendFileSync(logFile, `\nfailed to spawn claude (${config.claudePath}): ${e.message}\n`);
93
+ });
94
+ child.unref();
95
+ return logFile;
96
+ }
@@ -0,0 +1,185 @@
1
+ // Who may use the web app (src/web-server.js): browsers paired with this Mac.
2
+ //
3
+ // Pairing starts here, on the Mac, never in the browser: `sideora web` (or
4
+ // `sideora web pair`) makes a code, good once and for ten minutes, and
5
+ // prints the link that carries it. The browser that opens the link hands the
6
+ // code over and gets a session token, which it sends with every request.
7
+ //
8
+ // Kept in $SIDEORA_HOME/web.json (mode 600): codes and tokens as SHA-256
9
+ // only, so the file opens no door. A session ends when it is forgotten here,
10
+ // or after thirty days without a request.
11
+
12
+ import crypto from 'node:crypto';
13
+ import fs from 'node:fs';
14
+ import path from 'node:path';
15
+ import { HOME_DIR } from './config.js';
16
+ import { withFileLock } from './file-lock.js';
17
+
18
+ export const WEB_ACCESS_PATH = path.join(HOME_DIR, 'web.json');
19
+ export const CODE_MS = 10 * 60 * 1000;
20
+ export const IDLE_MS = 30 * 24 * 60 * 60 * 1000;
21
+ const MAX_SESSIONS = 20;
22
+ const SEEN_EVERY_MS = 60 * 1000;
23
+
24
+ const sha = (s) => crypto.createHash('sha256').update(String(s)).digest('hex');
25
+
26
+ function read() {
27
+ try {
28
+ const doc = JSON.parse(fs.readFileSync(WEB_ACCESS_PATH, 'utf8'));
29
+ return { codes: Array.isArray(doc?.codes) ? doc.codes : [], sessions: Array.isArray(doc?.sessions) ? doc.sessions : [] };
30
+ } catch {
31
+ return { codes: [], sessions: [] };
32
+ }
33
+ }
34
+
35
+ // One change at a time, across processes (src/file-lock.js): the server noting a session was used, `web forget` in
36
+ // a terminal, a second server on the same folder.
37
+ const locked = (change) => withFileLock(WEB_ACCESS_PATH, change);
38
+
39
+ function write(doc) {
40
+ fs.mkdirSync(HOME_DIR, { recursive: true });
41
+ const tmp = `${WEB_ACCESS_PATH}.${process.pid}.${crypto.randomBytes(4).toString('hex')}.tmp`;
42
+ fs.writeFileSync(tmp, JSON.stringify(doc, null, 2) + '\n', { mode: 0o600 });
43
+ fs.renameSync(tmp, WEB_ACCESS_PATH);
44
+ }
45
+
46
+ /** What is still good at `now`: codes not past their time, sessions used within the idle time. */
47
+ function live(doc, now) {
48
+ return {
49
+ codes: doc.codes.filter((c) => typeof c?.hash === 'string' && c.expires > now),
50
+ sessions: doc.sessions.filter((s) => typeof s?.hash === 'string' && now - (s.seen || s.created || 0) < IDLE_MS)
51
+ };
52
+ }
53
+
54
+ // 0 and O, 1 and I and L left out: a code may be read aloud or typed
55
+ const ALPHABET = 'ABCDEFGHJKMNPQRSTUVWXYZ23456789';
56
+ const word = (n) => Array.from(crypto.randomBytes(n), (b) => ALPHABET[b % ALPHABET.length]).join('');
57
+ /** A code as typed or pasted: its letters and digits, upper case. */
58
+ const plain = (code) => String(code ?? '').toUpperCase().replace(/[^A-Z0-9]/g, '');
59
+
60
+ /**
61
+ * A new pairing code (XXXX-XXXX-XXXX-XXXX, about 79 bits), good once, until `expires`. `purpose`: what it lets in: a
62
+ * browser on this computer ('web') or a device through the relay ('relay'). A code is good for the one it was made for.
63
+ */
64
+ export function newPairingCode(now = Date.now(), purpose = 'web') {
65
+ const code = [word(4), word(4), word(4), word(4)].join('-');
66
+ locked(() => {
67
+ const doc = live(read(), now);
68
+ doc.codes = [...doc.codes.slice(-4), { hash: sha(plain(code)), expires: now + CODE_MS, purpose }]; // a handful at most wait at once
69
+ write(doc);
70
+ });
71
+ return { code, expires: now + CODE_MS };
72
+ }
73
+
74
+ /**
75
+ * A browser hands a code over: a session, or null (no such code, used, or past its time). `was`: the token it had
76
+ * until now, when it is paired again: that session ends, so one browser is one session. When there are too many,
77
+ * the one unused for longest goes.
78
+ */
79
+ export function pair(code, agent = '', now = Date.now(), was = '') {
80
+ const given = plain(code);
81
+ if (given.length < 16) return null;
82
+ const hash = sha(given);
83
+ return locked(() => {
84
+ const doc = live(read(), now);
85
+ // ('extension': made for the Chrome extension's own frame, through its native link to the Mac: a session that may
86
+ // change accounts, as the extension always could)
87
+ const at = doc.codes.findIndex((c) => ['web', 'extension'].includes(c.purpose ?? 'web') && c.hash.length === hash.length && crypto.timingSafeEqual(Buffer.from(c.hash), Buffer.from(hash)));
88
+ if (at < 0) return null;
89
+ const admin = doc.codes[at].purpose === 'extension';
90
+ doc.codes.splice(at, 1);
91
+ const token = crypto.randomBytes(32).toString('base64url');
92
+ const id = 'w' + crypto.randomBytes(4).toString('hex');
93
+ const old = typeof was === 'string' && was.length >= 20 && was.length <= 200 ? sha(was) : '';
94
+ const kept = doc.sessions.filter((x) => x.hash !== old).sort((a, b) => (a.seen || 0) - (b.seen || 0)).slice(-(MAX_SESSIONS - 1));
95
+ doc.sessions = [...kept, { id, hash: sha(token), created: now, seen: now, agent: String(agent || '').slice(0, 200), ...(admin ? { admin: true } : {}) }];
96
+ write(doc);
97
+ return { id, token };
98
+ });
99
+ }
100
+
101
+ /** A code's reference: enough of its hash to name it (to a page that showed it), nothing to pair with. */
102
+ export const codeRef = (code) => sha(plain(code)).slice(0, 16);
103
+ const refOk = (ref) => typeof ref === 'string' && /^[0-9a-f]{16}$/.test(ref);
104
+ /** Whether the code so named still waits to be used (not used, not past its time, not withdrawn). */
105
+ export function codeWaiting(ref, now = Date.now()) {
106
+ return refOk(ref) && live(read(), now).codes.some((c) => c.hash.startsWith(ref));
107
+ }
108
+ /** A code withdrawn before it was used (the card that showed it closed, or another made in its place). */
109
+ export function dropCode(ref, now = Date.now()) {
110
+ if (!refOk(ref)) return false;
111
+ return locked(() => {
112
+ const doc = live(read(), now);
113
+ const left = doc.codes.filter((c) => !c.hash.startsWith(ref));
114
+ if (left.length === doc.codes.length) return false;
115
+ write({ ...doc, codes: left });
116
+ return true;
117
+ });
118
+ }
119
+
120
+ /** Spend a pairing code made for something other than a session here (`purpose`: 'relay', a device paired through the relay: src/relay.js). True when it was good, and of that purpose. */
121
+ export function takeCode(code, now = Date.now(), purpose = 'relay') {
122
+ const given = plain(code);
123
+ if (given.length < 16) return false;
124
+ const hash = sha(given);
125
+ return locked(() => {
126
+ const doc = live(read(), now);
127
+ const at = doc.codes.findIndex((c) => c.purpose === purpose && c.hash.length === hash.length && crypto.timingSafeEqual(Buffer.from(c.hash), Buffer.from(hash)));
128
+ if (at < 0) return false;
129
+ doc.codes.splice(at, 1);
130
+ write(doc);
131
+ return true;
132
+ });
133
+ }
134
+
135
+ /** The session a token is of, or null. Notes that it was used (once a minute at most). */
136
+ export function sessionOf(token, now = Date.now()) {
137
+ if (typeof token !== 'string' || token.length < 20 || token.length > 200) return null;
138
+ const hash = sha(token);
139
+ const of = (doc) => doc.sessions.find((x) => x.hash.length === hash.length && crypto.timingSafeEqual(Buffer.from(x.hash), Buffer.from(hash)));
140
+ let s = of(live(read(), now));
141
+ if (!s) return null;
142
+ if (now - (s.seen || 0) > SEEN_EVERY_MS) {
143
+ // noted under the lock, on what the file holds then: a session forgotten a moment ago is not written back
144
+ try {
145
+ s = locked(() => {
146
+ const doc = live(read(), now);
147
+ const mine = of(doc);
148
+ if (mine) { mine.seen = now; write(doc); }
149
+ return mine ?? null;
150
+ });
151
+ } catch { /* busy: it is still a session, noted next time */ }
152
+ if (!s) return null;
153
+ }
154
+ return { id: s.id, created: s.created, seen: s.seen, agent: s.agent || '', ...(s.admin === true ? { admin: true } : {}) };
155
+ }
156
+
157
+ /** Where the server is listening (`sideora web` notes it as it starts, and takes it away as it stops): its port, or null. */
158
+ export const WEB_PORT_PATH = path.join(HOME_DIR, 'web.port');
159
+ export function notePort(port) {
160
+ try {
161
+ if (port == null) fs.unlinkSync(WEB_PORT_PATH);
162
+ else { fs.mkdirSync(HOME_DIR, { recursive: true }); fs.writeFileSync(WEB_PORT_PATH, String(port) + '\n', { mode: 0o600 }); }
163
+ } catch { /* not noted: `web pair` falls back on the usual port */ }
164
+ }
165
+ export function notedPort() {
166
+ try { const n = Number(fs.readFileSync(WEB_PORT_PATH, 'utf8').trim()); return Number.isInteger(n) && n > 0 && n < 65536 ? n : null; } catch { return null; }
167
+ }
168
+
169
+ /** The paired browsers: [{ id, created, seen, agent }], the last used first. Never a token. */
170
+ export function listSessions(now = Date.now()) {
171
+ return live(read(), now).sessions.map((s) => ({ id: s.id, created: s.created, seen: s.seen, agent: s.agent || '', ...(s.admin === true ? { admin: true } : {}) })).sort((a, b) => b.seen - a.seen);
172
+ }
173
+
174
+ /** Forget one session by its id, or all of them ('all'); codes waiting go with 'all'. Returns how many sessions ended. */
175
+ export function endSessions(which, now = Date.now()) {
176
+ return locked(() => {
177
+ const doc = live(read(), now);
178
+ const keep = which === 'all' ? [] : doc.sessions.filter((s) => s.id !== which);
179
+ const ended = doc.sessions.length - keep.length;
180
+ if (which === 'all') doc.codes = [];
181
+ doc.sessions = keep;
182
+ if (ended || which === 'all') write(doc);
183
+ return ended;
184
+ });
185
+ }