@pithy-sh/payments 0.1.1 → 0.1.3
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/dist/admin/coverage.d.ts +35 -0
- package/dist/admin/coverage.d.ts.map +1 -0
- package/dist/admin/coverage.js +56 -0
- package/dist/admin/read.d.ts +222 -0
- package/dist/admin/read.d.ts.map +1 -0
- package/dist/admin/read.js +159 -0
- package/dist/audit/actions.d.ts +211 -0
- package/dist/audit/actions.d.ts.map +1 -0
- package/dist/audit/actions.js +211 -0
- package/dist/capability.d.ts +72 -0
- package/dist/capability.d.ts.map +1 -0
- package/dist/capability.js +228 -0
- package/dist/client/api.d.ts +435 -0
- package/dist/client/api.d.ts.map +1 -0
- package/dist/client/api.js +415 -0
- package/dist/client/checkout.d.ts +144 -0
- package/dist/client/checkout.d.ts.map +1 -0
- package/dist/client/checkout.js +173 -0
- package/dist/client/fixtures/price-preview-de.js +89 -0
- package/dist/client/fixtures/price-preview-gb.js +89 -0
- package/dist/client/fixtures/price-preview-jp-yen.js +89 -0
- package/dist/client/fixtures/price-preview-us-country-only.js +89 -0
- package/dist/client/fixtures/price-preview-us-new-york.js +89 -0
- package/dist/client/fixtures/pricePreview.d.ts +54 -0
- package/dist/client/fixtures/pricePreview.d.ts.map +1 -0
- package/dist/client/fixtures/pricePreview.js +61 -0
- package/dist/client/hooks.d.ts +235 -0
- package/dist/client/hooks.d.ts.map +1 -0
- package/dist/client/hooks.js +428 -0
- package/dist/client/paddle.d.ts +433 -0
- package/dist/client/paddle.d.ts.map +1 -0
- package/dist/client/paddle.js +391 -0
- package/dist/client/paddleCache.d.ts +123 -0
- package/dist/client/paddleCache.d.ts.map +1 -0
- package/dist/client/paddleCache.js +159 -0
- package/dist/client/paddlePrices.d.ts +94 -0
- package/dist/client/paddlePrices.d.ts.map +1 -0
- package/dist/client/paddlePrices.js +55 -0
- package/dist/client/paddlePricesTag.d.ts +127 -0
- package/dist/client/paddlePricesTag.d.ts.map +1 -0
- package/dist/client/paddlePricesTag.js +207 -0
- package/dist/client/projection.d.ts +128 -0
- package/dist/client/projection.d.ts.map +1 -0
- package/dist/client/projection.js +0 -0
- package/dist/client/test-utils/cacheStore.d.ts +18 -0
- package/dist/client/test-utils/cacheStore.d.ts.map +1 -0
- package/dist/client/test-utils/cacheStore.js +42 -0
- package/dist/client/wholeUnits.d.ts +18 -0
- package/dist/client/wholeUnits.d.ts.map +1 -0
- package/dist/client/wholeUnits.js +120 -0
- package/dist/config/config.d.ts +238 -0
- package/dist/config/config.d.ts.map +1 -0
- package/dist/config/config.js +249 -0
- package/dist/data/discount.d.ts +127 -0
- package/dist/data/discount.d.ts.map +1 -0
- package/dist/data/discount.js +91 -0
- package/dist/data/entitlement.d.ts +43 -0
- package/dist/data/entitlement.d.ts.map +1 -0
- package/dist/data/entitlement.js +43 -0
- package/dist/data/money.d.ts +15 -0
- package/dist/data/money.d.ts.map +1 -0
- package/dist/data/money.js +76 -0
- package/dist/data/pause.d.ts +133 -0
- package/dist/data/pause.d.ts.map +1 -0
- package/dist/data/pause.js +63 -0
- package/dist/data/providerAccount.d.ts +40 -0
- package/dist/data/providerAccount.d.ts.map +1 -0
- package/dist/data/providerAccount.js +34 -0
- package/dist/data/purchase.d.ts +107 -0
- package/dist/data/purchase.d.ts.map +1 -0
- package/dist/data/purchase.js +77 -0
- package/dist/data/rail.d.ts +74 -0
- package/dist/data/rail.d.ts.map +1 -0
- package/dist/data/rail.js +74 -0
- package/dist/data/reconcileRun.d.ts +120 -0
- package/dist/data/reconcileRun.d.ts.map +1 -0
- package/dist/data/reconcileRun.js +120 -0
- package/dist/data/renderMoney.d.ts +85 -0
- package/dist/data/renderMoney.d.ts.map +1 -0
- package/dist/data/renderMoney.js +146 -0
- package/dist/data/status.d.ts +58 -0
- package/dist/data/status.d.ts.map +1 -0
- package/dist/data/status.js +68 -0
- package/dist/data/subject.d.ts +111 -0
- package/dist/data/subject.d.ts.map +1 -0
- package/dist/data/subject.js +125 -0
- package/dist/data/subscription.d.ts +624 -0
- package/dist/data/subscription.d.ts.map +1 -0
- package/dist/data/subscription.js +497 -0
- package/dist/data/syncCursor.d.ts +33 -0
- package/dist/data/syncCursor.d.ts.map +1 -0
- package/dist/data/syncCursor.js +29 -0
- package/dist/data/tables.d.ts +37 -0
- package/dist/data/tables.d.ts.map +1 -0
- package/dist/data/tables.js +44 -0
- package/dist/data/webhookEvent.d.ts +134 -0
- package/dist/data/webhookEvent.d.ts.map +1 -0
- package/dist/data/webhookEvent.js +128 -0
- package/dist/entitlement/manual.d.ts +101 -0
- package/dist/entitlement/manual.d.ts.map +1 -0
- package/dist/entitlement/manual.js +84 -0
- package/dist/entitlement/resolver.d.ts +60 -0
- package/dist/entitlement/resolver.d.ts.map +1 -0
- package/dist/entitlement/resolver.js +101 -0
- package/dist/entitlement/subjectSeam.d.ts +102 -0
- package/dist/entitlement/subjectSeam.d.ts.map +1 -0
- package/dist/entitlement/subjectSeam.js +85 -0
- package/dist/error/errors.d.ts +247 -0
- package/dist/error/errors.d.ts.map +1 -0
- package/dist/error/errors.js +326 -0
- package/dist/grants/apply.d.ts +74 -0
- package/dist/grants/apply.d.ts.map +1 -0
- package/dist/grants/apply.js +148 -0
- package/dist/grants/clawback.d.ts +43 -0
- package/dist/grants/clawback.d.ts.map +1 -0
- package/dist/grants/clawback.js +71 -0
- package/dist/grants/ledgerSeam.d.ts +89 -0
- package/dist/grants/ledgerSeam.d.ts.map +1 -0
- package/dist/grants/ledgerSeam.js +66 -0
- package/dist/http/dispatch.d.ts +35 -0
- package/dist/http/dispatch.d.ts.map +1 -0
- package/dist/http/dispatch.js +40 -0
- package/dist/http/guards.d.ts +43 -0
- package/dist/http/guards.d.ts.map +1 -0
- package/dist/http/guards.js +52 -0
- package/dist/http/manifestConfig.d.ts +38 -0
- package/dist/http/manifestConfig.d.ts.map +1 -0
- package/dist/http/manifestConfig.js +49 -0
- package/dist/http/responses.d.ts +1455 -0
- package/dist/http/responses.d.ts.map +1 -0
- package/dist/http/responses.js +728 -0
- package/dist/http/routes.d.ts +315 -0
- package/dist/http/routes.d.ts.map +1 -0
- package/dist/http/routes.js +1966 -0
- package/dist/http/schemas.d.ts +404 -0
- package/dist/http/schemas.d.ts.map +1 -0
- package/dist/http/schemas.js +359 -0
- package/dist/http/scopes.d.ts +160 -0
- package/dist/http/scopes.d.ts.map +1 -0
- package/dist/http/scopes.js +240 -0
- package/dist/http/view.d.ts +96 -0
- package/dist/http/view.d.ts.map +1 -0
- package/dist/http/view.js +170 -0
- package/dist/http/webhookGuard.d.ts +109 -0
- package/dist/http/webhookGuard.d.ts.map +1 -0
- package/dist/http/webhookGuard.js +206 -0
- package/dist/index.d.ts +64 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +43 -0
- package/dist/migrations/0001_purchases.d.ts +35 -0
- package/dist/migrations/0001_purchases.d.ts.map +1 -0
- package/dist/migrations/0001_purchases.js +80 -0
- package/dist/pricing/location.d.ts +138 -0
- package/dist/pricing/location.d.ts.map +1 -0
- package/dist/pricing/location.js +81 -0
- package/dist/pricing/visitor.d.ts +56 -0
- package/dist/pricing/visitor.d.ts.map +1 -0
- package/dist/pricing/visitor.js +35 -0
- package/dist/projection/event.d.ts +66 -0
- package/dist/projection/event.d.ts.map +1 -0
- package/dist/projection/event.js +45 -0
- package/dist/projection/orphans.d.ts +114 -0
- package/dist/projection/orphans.d.ts.map +1 -0
- package/dist/projection/orphans.js +162 -0
- package/dist/projection/owner.d.ts +121 -0
- package/dist/projection/owner.d.ts.map +1 -0
- package/dist/projection/owner.js +114 -0
- package/dist/projection/resolve.d.ts +30 -0
- package/dist/projection/resolve.d.ts.map +1 -0
- package/dist/projection/resolve.js +42 -0
- package/dist/projection/writer.d.ts +103 -0
- package/dist/projection/writer.d.ts.map +1 -0
- package/dist/projection/writer.js +280 -0
- package/dist/provision/resolvePaymentsConfig.d.ts +48 -0
- package/dist/provision/resolvePaymentsConfig.d.ts.map +1 -0
- package/dist/provision/resolvePaymentsConfig.js +41 -0
- package/dist/rails/apple/certs.d.ts +7 -0
- package/dist/rails/apple/certs.d.ts.map +1 -0
- package/dist/rails/apple/certs.js +8 -0
- package/dist/rails/apple/der.d.ts +107 -0
- package/dist/rails/apple/der.d.ts.map +1 -0
- package/dist/rails/apple/der.js +217 -0
- package/dist/rails/apple/fixtures/chain.d.ts +117 -0
- package/dist/rails/apple/fixtures/chain.d.ts.map +1 -0
- package/dist/rails/apple/fixtures/chain.js +289 -0
- package/dist/rails/apple/http.d.ts +74 -0
- package/dist/rails/apple/http.d.ts.map +1 -0
- package/dist/rails/apple/http.js +32 -0
- package/dist/rails/apple/jws.d.ts +17 -0
- package/dist/rails/apple/jws.d.ts.map +1 -0
- package/dist/rails/apple/jws.js +75 -0
- package/dist/rails/apple/notification.d.ts +116 -0
- package/dist/rails/apple/notification.d.ts.map +1 -0
- package/dist/rails/apple/notification.js +199 -0
- package/dist/rails/apple/rail.d.ts +25 -0
- package/dist/rails/apple/rail.d.ts.map +1 -0
- package/dist/rails/apple/rail.js +68 -0
- package/dist/rails/apple/serverApi.d.ts +120 -0
- package/dist/rails/apple/serverApi.d.ts.map +1 -0
- package/dist/rails/apple/serverApi.js +244 -0
- package/dist/rails/apple/verify.d.ts +36 -0
- package/dist/rails/apple/verify.d.ts.map +1 -0
- package/dist/rails/apple/verify.js +46 -0
- package/dist/rails/apple/x509.d.ts +85 -0
- package/dist/rails/apple/x509.d.ts.map +1 -0
- package/dist/rails/apple/x509.js +273 -0
- package/dist/rails/contract.d.ts +871 -0
- package/dist/rails/contract.d.ts.map +1 -0
- package/dist/rails/contract.js +60 -0
- package/dist/rails/google/fixtures/push.d.ts +71 -0
- package/dist/rails/google/fixtures/push.d.ts.map +1 -0
- package/dist/rails/google/fixtures/push.js +107 -0
- package/dist/rails/google/http.d.ts +77 -0
- package/dist/rails/google/http.d.ts.map +1 -0
- package/dist/rails/google/http.js +39 -0
- package/dist/rails/google/jwt.d.ts +53 -0
- package/dist/rails/google/jwt.d.ts.map +1 -0
- package/dist/rails/google/jwt.js +94 -0
- package/dist/rails/google/oidc.d.ts +112 -0
- package/dist/rails/google/oidc.d.ts.map +1 -0
- package/dist/rails/google/oidc.js +179 -0
- package/dist/rails/google/playApi.d.ts +188 -0
- package/dist/rails/google/playApi.d.ts.map +1 -0
- package/dist/rails/google/playApi.js +350 -0
- package/dist/rails/google/rail.d.ts +57 -0
- package/dist/rails/google/rail.d.ts.map +1 -0
- package/dist/rails/google/rail.js +70 -0
- package/dist/rails/google/rtdn.d.ts +105 -0
- package/dist/rails/google/rtdn.d.ts.map +1 -0
- package/dist/rails/google/rtdn.js +179 -0
- package/dist/rails/google/verify.d.ts +20 -0
- package/dist/rails/google/verify.d.ts.map +1 -0
- package/dist/rails/google/verify.js +76 -0
- package/dist/rails/lemonSqueezy/api.d.ts +92 -0
- package/dist/rails/lemonSqueezy/api.d.ts.map +1 -0
- package/dist/rails/lemonSqueezy/api.js +121 -0
- package/dist/rails/lemonSqueezy/checkout.d.ts +52 -0
- package/dist/rails/lemonSqueezy/checkout.d.ts.map +1 -0
- package/dist/rails/lemonSqueezy/checkout.js +84 -0
- package/dist/rails/lemonSqueezy/discounts.d.ts +50 -0
- package/dist/rails/lemonSqueezy/discounts.d.ts.map +1 -0
- package/dist/rails/lemonSqueezy/discounts.js +75 -0
- package/dist/rails/lemonSqueezy/fixtures/events.d.ts +56 -0
- package/dist/rails/lemonSqueezy/fixtures/events.d.ts.map +1 -0
- package/dist/rails/lemonSqueezy/fixtures/events.js +144 -0
- package/dist/rails/lemonSqueezy/objects.d.ts +229 -0
- package/dist/rails/lemonSqueezy/objects.d.ts.map +1 -0
- package/dist/rails/lemonSqueezy/objects.js +379 -0
- package/dist/rails/lemonSqueezy/portal.d.ts +35 -0
- package/dist/rails/lemonSqueezy/portal.d.ts.map +1 -0
- package/dist/rails/lemonSqueezy/portal.js +18 -0
- package/dist/rails/lemonSqueezy/pricing.d.ts +25 -0
- package/dist/rails/lemonSqueezy/pricing.d.ts.map +1 -0
- package/dist/rails/lemonSqueezy/pricing.js +54 -0
- package/dist/rails/lemonSqueezy/rail.d.ts +41 -0
- package/dist/rails/lemonSqueezy/rail.d.ts.map +1 -0
- package/dist/rails/lemonSqueezy/rail.js +67 -0
- package/dist/rails/lemonSqueezy/read.d.ts +28 -0
- package/dist/rails/lemonSqueezy/read.d.ts.map +1 -0
- package/dist/rails/lemonSqueezy/read.js +37 -0
- package/dist/rails/lemonSqueezy/refresh.d.ts +42 -0
- package/dist/rails/lemonSqueezy/refresh.d.ts.map +1 -0
- package/dist/rails/lemonSqueezy/refresh.js +40 -0
- package/dist/rails/lemonSqueezy/signature.d.ts +56 -0
- package/dist/rails/lemonSqueezy/signature.d.ts.map +1 -0
- package/dist/rails/lemonSqueezy/signature.js +92 -0
- package/dist/rails/lemonSqueezy/verify.d.ts +33 -0
- package/dist/rails/lemonSqueezy/verify.d.ts.map +1 -0
- package/dist/rails/lemonSqueezy/verify.js +41 -0
- package/dist/rails/lemonSqueezy/webhook.d.ts +53 -0
- package/dist/rails/lemonSqueezy/webhook.d.ts.map +1 -0
- package/dist/rails/lemonSqueezy/webhook.js +179 -0
- package/dist/rails/paddle/adjustments.d.ts +60 -0
- package/dist/rails/paddle/adjustments.d.ts.map +1 -0
- package/dist/rails/paddle/adjustments.js +66 -0
- package/dist/rails/paddle/api.d.ts +138 -0
- package/dist/rails/paddle/api.d.ts.map +1 -0
- package/dist/rails/paddle/api.js +152 -0
- package/dist/rails/paddle/checkout.d.ts +69 -0
- package/dist/rails/paddle/checkout.d.ts.map +1 -0
- package/dist/rails/paddle/checkout.js +100 -0
- package/dist/rails/paddle/discounts.d.ts +67 -0
- package/dist/rails/paddle/discounts.d.ts.map +1 -0
- package/dist/rails/paddle/discounts.js +73 -0
- package/dist/rails/paddle/events.d.ts +140 -0
- package/dist/rails/paddle/events.d.ts.map +1 -0
- package/dist/rails/paddle/events.js +183 -0
- package/dist/rails/paddle/fixtures/browserForged.d.ts +42 -0
- package/dist/rails/paddle/fixtures/browserForged.d.ts.map +1 -0
- package/dist/rails/paddle/fixtures/browserForged.js +52 -0
- package/dist/rails/paddle/fixtures/pausedSubscription.d.ts +78 -0
- package/dist/rails/paddle/fixtures/pausedSubscription.d.ts.map +1 -0
- package/dist/rails/paddle/fixtures/pausedSubscription.js +76 -0
- package/dist/rails/paddle/objects.d.ts +519 -0
- package/dist/rails/paddle/objects.d.ts.map +1 -0
- package/dist/rails/paddle/objects.js +588 -0
- package/dist/rails/paddle/portal.d.ts +45 -0
- package/dist/rails/paddle/portal.d.ts.map +1 -0
- package/dist/rails/paddle/portal.js +42 -0
- package/dist/rails/paddle/rail.d.ts +55 -0
- package/dist/rails/paddle/rail.d.ts.map +1 -0
- package/dist/rails/paddle/rail.js +117 -0
- package/dist/rails/paddle/read.d.ts +53 -0
- package/dist/rails/paddle/read.d.ts.map +1 -0
- package/dist/rails/paddle/read.js +66 -0
- package/dist/rails/paddle/recorded.d.ts +49 -0
- package/dist/rails/paddle/recorded.d.ts.map +1 -0
- package/dist/rails/paddle/recorded.js +79 -0
- package/dist/rails/paddle/refresh.d.ts +54 -0
- package/dist/rails/paddle/refresh.d.ts.map +1 -0
- package/dist/rails/paddle/refresh.js +94 -0
- package/dist/rails/paddle/refund.d.ts +82 -0
- package/dist/rails/paddle/refund.d.ts.map +1 -0
- package/dist/rails/paddle/refund.js +175 -0
- package/dist/rails/paddle/signature.d.ts +83 -0
- package/dist/rails/paddle/signature.d.ts.map +1 -0
- package/dist/rails/paddle/signature.js +163 -0
- package/dist/rails/paddle/subscription.d.ts +137 -0
- package/dist/rails/paddle/subscription.d.ts.map +1 -0
- package/dist/rails/paddle/subscription.js +538 -0
- package/dist/rails/paddle/verify.d.ts +46 -0
- package/dist/rails/paddle/verify.d.ts.map +1 -0
- package/dist/rails/paddle/verify.js +43 -0
- package/dist/rails/paddle/webhook.d.ts +98 -0
- package/dist/rails/paddle/webhook.d.ts.map +1 -0
- package/dist/rails/paddle/webhook.js +181 -0
- package/dist/rails/providers.d.ts +73 -0
- package/dist/rails/providers.d.ts.map +1 -0
- package/dist/rails/providers.js +62 -0
- package/dist/rails/stripe/api.d.ts +118 -0
- package/dist/rails/stripe/api.d.ts.map +1 -0
- package/dist/rails/stripe/api.js +153 -0
- package/dist/rails/stripe/checkout.d.ts +60 -0
- package/dist/rails/stripe/checkout.d.ts.map +1 -0
- package/dist/rails/stripe/checkout.js +86 -0
- package/dist/rails/stripe/discounts.d.ts +50 -0
- package/dist/rails/stripe/discounts.d.ts.map +1 -0
- package/dist/rails/stripe/discounts.js +87 -0
- package/dist/rails/stripe/fixtures/events.d.ts +64 -0
- package/dist/rails/stripe/fixtures/events.d.ts.map +1 -0
- package/dist/rails/stripe/fixtures/events.js +67 -0
- package/dist/rails/stripe/objects.d.ts +237 -0
- package/dist/rails/stripe/objects.d.ts.map +1 -0
- package/dist/rails/stripe/objects.js +389 -0
- package/dist/rails/stripe/portal.d.ts +29 -0
- package/dist/rails/stripe/portal.d.ts.map +1 -0
- package/dist/rails/stripe/portal.js +41 -0
- package/dist/rails/stripe/pricing.d.ts +25 -0
- package/dist/rails/stripe/pricing.d.ts.map +1 -0
- package/dist/rails/stripe/pricing.js +68 -0
- package/dist/rails/stripe/rail.d.ts +28 -0
- package/dist/rails/stripe/rail.d.ts.map +1 -0
- package/dist/rails/stripe/rail.js +81 -0
- package/dist/rails/stripe/refresh.d.ts +33 -0
- package/dist/rails/stripe/refresh.d.ts.map +1 -0
- package/dist/rails/stripe/refresh.js +21 -0
- package/dist/rails/stripe/signature.d.ts +71 -0
- package/dist/rails/stripe/signature.d.ts.map +1 -0
- package/dist/rails/stripe/signature.js +92 -0
- package/dist/rails/stripe/verify.d.ts +15 -0
- package/dist/rails/stripe/verify.d.ts.map +1 -0
- package/dist/rails/stripe/verify.js +63 -0
- package/dist/rails/stripe/webhook.d.ts +26 -0
- package/dist/rails/stripe/webhook.d.ts.map +1 -0
- package/dist/rails/stripe/webhook.js +31 -0
- package/dist/secret/registry.d.ts +192 -0
- package/dist/secret/registry.d.ts.map +1 -0
- package/dist/secret/registry.js +154 -0
- package/dist/seeds/example.d.ts +3 -0
- package/dist/seeds/example.d.ts.map +1 -0
- package/dist/seeds/example.js +171 -0
- package/dist/version.generated.d.ts +5 -0
- package/dist/version.generated.d.ts.map +1 -0
- package/dist/version.generated.js +7 -0
- package/dist/workflows/paddleSweep.d.ts +175 -0
- package/dist/workflows/paddleSweep.d.ts.map +1 -0
- package/dist/workflows/paddleSweep.js +433 -0
- package/dist/workflows/railAccess.d.ts +48 -0
- package/dist/workflows/railAccess.d.ts.map +1 -0
- package/dist/workflows/railAccess.js +36 -0
- package/dist/workflows/reconcile.d.ts +161 -0
- package/dist/workflows/reconcile.d.ts.map +1 -0
- package/dist/workflows/reconcile.js +352 -0
- package/dist/workflows/report.d.ts +28 -0
- package/dist/workflows/report.d.ts.map +1 -0
- package/dist/workflows/report.js +54 -0
- package/dist/workflows/retryPolicy.d.ts +29 -0
- package/dist/workflows/retryPolicy.d.ts.map +1 -0
- package/dist/workflows/retryPolicy.js +37 -0
- package/dist/workflows/specs.d.ts +102 -0
- package/dist/workflows/specs.d.ts.map +1 -0
- package/dist/workflows/specs.js +84 -0
- package/dist/workflows/worker.d.ts +62 -0
- package/dist/workflows/worker.d.ts.map +1 -0
- package/dist/workflows/worker.js +92 -0
- package/dist/workflows/workerConfig.d.ts +46 -0
- package/dist/workflows/workerConfig.d.ts.map +1 -0
- package/dist/workflows/workerConfig.js +38 -0
- package/package.json +22 -13
- package/pithy.manifest.json +19 -13
- package/src/version.generated.ts +1 -1
- package/src/client/paddlePrices.iife.ts +0 -43
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { PaymentsInvalidReceiptError } from "../../error/errors.js";
|
|
2
|
+
//#region src/rails/apple/der.ts
|
|
3
|
+
/**
|
|
4
|
+
* The byte encodings Apple's signed data is built from: base64 and base64url, and just enough ASN.1 DER
|
|
5
|
+
* to walk an X.509 certificate.
|
|
6
|
+
*
|
|
7
|
+
* **Why this exists at all.** Verifying an App Store Server Notification means verifying a JWS against a
|
|
8
|
+
* certificate chain, and there is no certificate parser in the Workers runtime — `crypto.subtle` imports a
|
|
9
|
+
* SubjectPublicKeyInfo but will not open a certificate to find one. Node's `X509Certificate` is not
|
|
10
|
+
* available here. So the parts of DER the chain needs are read directly, and nothing more: this is a
|
|
11
|
+
* reader, never a general ASN.1 library, and it has no encoder.
|
|
12
|
+
*
|
|
13
|
+
* **Every parse is hostile-input parsing.** These bytes arrive in an unauthenticated HTTP request, which
|
|
14
|
+
* is the whole point of verifying them, so every length is checked against the buffer it claims to live in
|
|
15
|
+
* before it is trusted. A length that overruns its buffer or its parent is refused rather than clamped —
|
|
16
|
+
* clamping would let a crafted certificate present bytes that were never inside it. Indefinite lengths are
|
|
17
|
+
* refused outright: DER forbids them, and honoring BER's end-of-contents marker is how a parser is made
|
|
18
|
+
* to disagree with the verifier about where a structure ends.
|
|
19
|
+
*
|
|
20
|
+
* Failures throw `payments/invalid_receipt` — malformed, not merely unverified. A caller on the webhook
|
|
21
|
+
* path maps that to `payments/webhook_unverified`, so one implementation serves both paths with the right
|
|
22
|
+
* code on each.
|
|
23
|
+
*/
|
|
24
|
+
/** DER tag for a constructed SEQUENCE. */
|
|
25
|
+
const ASN1_SEQUENCE = 48;
|
|
26
|
+
/** DER tag for an INTEGER. */
|
|
27
|
+
const ASN1_INTEGER = 2;
|
|
28
|
+
/** DER tag for a BIT STRING. */
|
|
29
|
+
const ASN1_BIT_STRING = 3;
|
|
30
|
+
/** DER tag for an OBJECT IDENTIFIER. */
|
|
31
|
+
const ASN1_OID = 6;
|
|
32
|
+
/** DER tag for a UTCTime. */
|
|
33
|
+
const ASN1_UTC_TIME = 23;
|
|
34
|
+
/** DER tag for a GeneralizedTime. */
|
|
35
|
+
const ASN1_GENERALIZED_TIME = 24;
|
|
36
|
+
/** DER tag for a BOOLEAN — how an extension states `critical`, and how basicConstraints states `cA`. */
|
|
37
|
+
const ASN1_BOOLEAN = 1;
|
|
38
|
+
/** DER tag for an OCTET STRING — an X.509 extension's value is one, wrapping the extension's own DER. */
|
|
39
|
+
const ASN1_OCTET_STRING = 4;
|
|
40
|
+
/** The bit in a tag byte that marks a node constructed (its contents are further nodes). */
|
|
41
|
+
const ASN1_CONSTRUCTED = 32;
|
|
42
|
+
/** A structural refusal. The detail names the position, because a chain has several places to fail. */
|
|
43
|
+
function malformed(detail) {
|
|
44
|
+
return new PaymentsInvalidReceiptError({
|
|
45
|
+
message: "That purchase could not be read.",
|
|
46
|
+
action: "Submit the transaction exactly as the store SDK returned it.",
|
|
47
|
+
detail
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Read one DER node at `offset`. Returns the node and the offset just past it, so a caller walks a
|
|
52
|
+
* sequence by feeding the returned `end` back in.
|
|
53
|
+
*/
|
|
54
|
+
function readAsn1(bytes, offset = 0) {
|
|
55
|
+
if (offset + 2 > bytes.length) throw malformed(`DER: truncated header at offset ${offset}.`);
|
|
56
|
+
const tag = bytes[offset];
|
|
57
|
+
const first = bytes[offset + 1];
|
|
58
|
+
let length;
|
|
59
|
+
let contentsAt;
|
|
60
|
+
if (first < 128) {
|
|
61
|
+
length = first;
|
|
62
|
+
contentsAt = offset + 2;
|
|
63
|
+
} else {
|
|
64
|
+
const lengthBytes = first & 127;
|
|
65
|
+
if (lengthBytes === 0) throw malformed(`DER: indefinite length at offset ${offset}.`);
|
|
66
|
+
if (lengthBytes > 4) throw malformed(`DER: length of ${lengthBytes} bytes at offset ${offset} is too wide.`);
|
|
67
|
+
if (offset + 2 + lengthBytes > bytes.length) throw malformed(`DER: truncated length at offset ${offset}.`);
|
|
68
|
+
length = 0;
|
|
69
|
+
for (let i = 0; i < lengthBytes; i += 1) length = length * 256 + bytes[offset + 2 + i];
|
|
70
|
+
contentsAt = offset + 2 + lengthBytes;
|
|
71
|
+
}
|
|
72
|
+
const end = contentsAt + length;
|
|
73
|
+
if (end > bytes.length) throw malformed(`DER: node at offset ${offset} claims ${length} bytes, ${bytes.length - contentsAt} remain.`);
|
|
74
|
+
return {
|
|
75
|
+
node: {
|
|
76
|
+
tag,
|
|
77
|
+
der: bytes.subarray(offset, end),
|
|
78
|
+
value: bytes.subarray(contentsAt, end)
|
|
79
|
+
},
|
|
80
|
+
end
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* The members of a constructed node, in order. Each member is read from the parent's contents, so a member
|
|
85
|
+
* that overruns the parent is refused — the check the parent's own length would otherwise not enforce.
|
|
86
|
+
*/
|
|
87
|
+
function asn1Children(node) {
|
|
88
|
+
if ((node.tag & ASN1_CONSTRUCTED) === 0) throw malformed(`DER: tag 0x${node.tag.toString(16)} is not constructed.`);
|
|
89
|
+
const children = [];
|
|
90
|
+
let offset = 0;
|
|
91
|
+
while (offset < node.value.length) {
|
|
92
|
+
const { node: child, end } = readAsn1(node.value, offset);
|
|
93
|
+
children.push(child);
|
|
94
|
+
offset = end;
|
|
95
|
+
}
|
|
96
|
+
return children;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* An OBJECT IDENTIFIER as dotted decimal. Algorithm and curve identities are compared as strings rather
|
|
100
|
+
* than as byte patterns, so the comparison sites read as the names they mean.
|
|
101
|
+
*/
|
|
102
|
+
function readOid(node) {
|
|
103
|
+
if (node.tag !== 6) throw malformed(`DER: expected an OBJECT IDENTIFIER, found tag 0x${node.tag.toString(16)}.`);
|
|
104
|
+
if (node.value.length === 0) throw malformed("DER: empty OBJECT IDENTIFIER.");
|
|
105
|
+
const first = node.value[0];
|
|
106
|
+
const arcs = [Math.min(Math.floor(first / 40), 2)];
|
|
107
|
+
arcs.push(first - arcs[0] * 40);
|
|
108
|
+
let current = 0;
|
|
109
|
+
for (let i = 1; i < node.value.length; i += 1) {
|
|
110
|
+
const byte = node.value[i];
|
|
111
|
+
current = current * 128 + (byte & 127);
|
|
112
|
+
if ((byte & 128) === 0) {
|
|
113
|
+
arcs.push(current);
|
|
114
|
+
current = 0;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return arcs.join(".");
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* An X.509 ECDSA signature (`SEQUENCE { INTEGER r, INTEGER s }`) as the fixed-width `r || s` WebCrypto
|
|
121
|
+
* verifies. `size` is the curve's coordinate size — 32 bytes for P-256, 48 for P-384.
|
|
122
|
+
*
|
|
123
|
+
* The two encodings differ in exactly the way that trips people up. DER writes each integer with the
|
|
124
|
+
* fewest bytes that keep it positive, so a coordinate whose top bit is set gains a leading zero and a
|
|
125
|
+
* small one loses leading bytes. WebCrypto wants both coordinates at full width. So the padding byte is
|
|
126
|
+
* stripped and the remainder right-aligned; a value still wider than the curve after stripping is refused
|
|
127
|
+
* rather than truncated, because truncating a signature makes a forgery verify.
|
|
128
|
+
*/
|
|
129
|
+
function derSignatureToRaw(der, size) {
|
|
130
|
+
const { node } = readAsn1(der);
|
|
131
|
+
if (node.tag !== 48) throw malformed("DER: an ECDSA signature must be a SEQUENCE.");
|
|
132
|
+
const parts = asn1Children(node);
|
|
133
|
+
if (parts.length !== 2) throw malformed(`DER: an ECDSA signature has two integers, found ${parts.length}.`);
|
|
134
|
+
const raw = new Uint8Array(size * 2);
|
|
135
|
+
for (const [index, part] of parts.entries()) {
|
|
136
|
+
if (part.tag !== 2) throw malformed("DER: an ECDSA signature's members must be INTEGERs.");
|
|
137
|
+
let value = part.value;
|
|
138
|
+
while (value.length > 0 && value[0] === 0) value = value.subarray(1);
|
|
139
|
+
if (value.length > size) throw malformed(`DER: ECDSA coordinate is ${value.length} bytes, the curve is ${size}.`);
|
|
140
|
+
raw.set(value, index * size + (size - value.length));
|
|
141
|
+
}
|
|
142
|
+
return raw;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* A DER BOOLEAN. DER admits exactly two encodings — `0x00` false, `0xff` true — and anything else is
|
|
146
|
+
* refused rather than coerced. A parser that read any non-zero byte as true would disagree with an encoder
|
|
147
|
+
* that wrote `0x01`, and for `basicConstraints.cA` that disagreement is the difference between a
|
|
148
|
+
* certificate authority and a leaf.
|
|
149
|
+
*/
|
|
150
|
+
function readBoolean(node) {
|
|
151
|
+
if (node.tag !== 1) throw malformed(`DER: expected a BOOLEAN, found tag 0x${node.tag.toString(16)}.`);
|
|
152
|
+
if (node.value.length !== 1) throw malformed(`DER: a BOOLEAN is one byte, found ${node.value.length}.`);
|
|
153
|
+
const byte = node.value[0];
|
|
154
|
+
if (byte === 0) return false;
|
|
155
|
+
if (byte === 255) return true;
|
|
156
|
+
throw malformed(`DER: 0x${byte.toString(16)} is not a DER BOOLEAN; only 0x00 and 0xff are.`);
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* A non-negative INTEGER, as a number. Only used for small constrained values (`pathLenConstraint`), so a
|
|
160
|
+
* value wider than is plausible is refused rather than silently losing precision past 2^53.
|
|
161
|
+
*/
|
|
162
|
+
function readInteger(node) {
|
|
163
|
+
if (node.tag !== 2) throw malformed(`DER: expected an INTEGER, found tag 0x${node.tag.toString(16)}.`);
|
|
164
|
+
if (node.value.length === 0) throw malformed("DER: empty INTEGER.");
|
|
165
|
+
if (node.value[0] & 128) throw malformed("DER: a negative INTEGER is not accepted here.");
|
|
166
|
+
if (node.value.length > 4) throw malformed(`DER: INTEGER of ${node.value.length} bytes is wider than expected.`);
|
|
167
|
+
let value = 0;
|
|
168
|
+
for (const byte of node.value) value = value * 256 + byte;
|
|
169
|
+
return value;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* A BIT STRING's bits, most-significant first, as booleans. The first contents byte counts the unused
|
|
173
|
+
* trailing bits of the last byte, and those are dropped — a `keyUsage` with padding read as data would
|
|
174
|
+
* report permissions the certificate never granted.
|
|
175
|
+
*/
|
|
176
|
+
function readBits(node) {
|
|
177
|
+
if (node.tag !== 3) throw malformed(`DER: expected a BIT STRING, found tag 0x${node.tag.toString(16)}.`);
|
|
178
|
+
if (node.value.length === 0) throw malformed("DER: empty BIT STRING.");
|
|
179
|
+
const unused = node.value[0];
|
|
180
|
+
if (unused > 7) throw malformed(`DER: a BIT STRING cannot have ${unused} unused bits.`);
|
|
181
|
+
const bytes = node.value.subarray(1);
|
|
182
|
+
if (bytes.length === 0) return [];
|
|
183
|
+
const bits = [];
|
|
184
|
+
for (const [index, byte] of bytes.entries()) {
|
|
185
|
+
const width = index === bytes.length - 1 ? 8 - unused : 8;
|
|
186
|
+
for (let bit = 0; bit < width; bit += 1) bits.push((byte & 128 >> bit) !== 0);
|
|
187
|
+
}
|
|
188
|
+
return bits;
|
|
189
|
+
}
|
|
190
|
+
/** Bytes from a base64 string, standard alphabet — how a JWS header's `x5c` carries a certificate. */
|
|
191
|
+
function decodeBase64(encoded) {
|
|
192
|
+
if (encoded.length === 0) throw malformed("base64: empty value.");
|
|
193
|
+
let binary;
|
|
194
|
+
try {
|
|
195
|
+
binary = atob(encoded);
|
|
196
|
+
} catch (cause) {
|
|
197
|
+
throw new PaymentsInvalidReceiptError({ detail: "base64: value is not valid base64." }, { cause });
|
|
198
|
+
}
|
|
199
|
+
return Uint8Array.from(binary, (character) => character.charCodeAt(0));
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Bytes from a base64url string — how a JWS carries its header, payload, and signature. The URL alphabet
|
|
203
|
+
* substitutes `-` and `_`, and drops the padding, so both are restored before decoding.
|
|
204
|
+
*/
|
|
205
|
+
function decodeBase64Url(encoded) {
|
|
206
|
+
if (encoded.length === 0) throw malformed("base64url: empty value.");
|
|
207
|
+
const standard = encoded.replaceAll("-", "+").replaceAll("_", "/");
|
|
208
|
+
return decodeBase64(standard.padEnd(standard.length + (4 - standard.length % 4) % 4, "="));
|
|
209
|
+
}
|
|
210
|
+
/** Whether two byte strings have identical contents. Used to match a pinned root and to link a chain. */
|
|
211
|
+
function bytesEqual(left, right) {
|
|
212
|
+
if (left.length !== right.length) return false;
|
|
213
|
+
for (let i = 0; i < left.length; i += 1) if (left[i] !== right[i]) return false;
|
|
214
|
+
return true;
|
|
215
|
+
}
|
|
216
|
+
//#endregion
|
|
217
|
+
export { ASN1_BIT_STRING, ASN1_BOOLEAN, ASN1_GENERALIZED_TIME, ASN1_INTEGER, ASN1_OCTET_STRING, ASN1_OID, ASN1_SEQUENCE, ASN1_UTC_TIME, asn1Children, bytesEqual, decodeBase64, decodeBase64Url, derSignatureToRaw, readAsn1, readBits, readBoolean, readInteger, readOid };
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test material: a real X.509 certificate chain and real JWS signatures, minted at test time.
|
|
3
|
+
*
|
|
4
|
+
* Verifying Apple's signature is the security boundary on the webhook route, so its tests must exercise
|
|
5
|
+
* genuine cryptography — a stubbed verifier proves nothing about the one thing that matters. No test may
|
|
6
|
+
* reach a live store either. So the tests mint their own chain here with WebCrypto and sign real
|
|
7
|
+
* certificates with it: leaf ← intermediate ← root, the shape Apple's `x5c` carries, with the root pinned
|
|
8
|
+
* into the verifier the way `APPLE_ROOT_CERTIFICATES` is pinned in production.
|
|
9
|
+
*
|
|
10
|
+
* That makes the negative cases real too. A chain rooted elsewhere is a second minted root the verifier was
|
|
11
|
+
* never given. An expired leaf is a leaf minted with a past `notAfter`. A tampered body is a byte changed
|
|
12
|
+
* after signing. None of them is a mock refusing on command.
|
|
13
|
+
*
|
|
14
|
+
* This file is a DER **encoder** and the only one in the package — the shipped code reads certificates and
|
|
15
|
+
* never writes them, and that asymmetry is deliberate. It lives under `fixtures/` for the same reason the
|
|
16
|
+
* recorded notification payloads do: it is test input, not product.
|
|
17
|
+
*/
|
|
18
|
+
/** The curves the minter and Apple's own chain use: P-256 for a leaf, P-384 for a CA. */
|
|
19
|
+
export type TestCurve = "P-256" | "P-384";
|
|
20
|
+
/** A minted chain, in the order a JWS `x5c` header carries it. */
|
|
21
|
+
export interface MintedChain {
|
|
22
|
+
/** base64 DER, leaf first, root last. */
|
|
23
|
+
x5c: string[];
|
|
24
|
+
/** The leaf's private key — what signs a JWS. */
|
|
25
|
+
leafKey: CryptoKey;
|
|
26
|
+
/** base64 DER of the root, for pinning into the verifier under test. */
|
|
27
|
+
root: string;
|
|
28
|
+
}
|
|
29
|
+
/** How a caller bends the chain: shift a validity window, or change a curve. */
|
|
30
|
+
export interface MintChainOptions {
|
|
31
|
+
/** The leaf's validity window. Defaults to a year either side of now. */
|
|
32
|
+
leafNotBefore?: Date;
|
|
33
|
+
leafNotAfter?: Date;
|
|
34
|
+
/** The intermediate's validity window. Defaults to the same. */
|
|
35
|
+
intermediateNotBefore?: Date;
|
|
36
|
+
intermediateNotAfter?: Date;
|
|
37
|
+
/** The leaf's curve. P-256 is what ES256 requires; P-384 is how algorithm confusion is tested. */
|
|
38
|
+
leafCurve?: TestCurve;
|
|
39
|
+
/** A distinguishing name, so two chains minted in one test are told apart. */
|
|
40
|
+
label?: string;
|
|
41
|
+
/**
|
|
42
|
+
* Mint the intermediate without `basicConstraints` CA:TRUE — as an ordinary leaf certificate would be.
|
|
43
|
+
* This is the shape of the attack the CA check exists to refuse: any certificate Apple issued, used to
|
|
44
|
+
* sign a certificate of the attacker's own.
|
|
45
|
+
*/
|
|
46
|
+
intermediateNotCa?: boolean;
|
|
47
|
+
/** Mint the intermediate with `keyUsage` present but `keyCertSign` cleared. */
|
|
48
|
+
intermediateWithoutKeyCertSign?: boolean;
|
|
49
|
+
/** `pathLenConstraint` on the intermediate, so a chain deeper than it permits can be minted. */
|
|
50
|
+
intermediatePathLen?: number;
|
|
51
|
+
/** Omit Apple's receipt-signer marker from the leaf. */
|
|
52
|
+
leafWithoutSignerOid?: boolean;
|
|
53
|
+
/** Omit Apple's WWDR marker from the intermediate. */
|
|
54
|
+
intermediateWithoutWwdrOid?: boolean;
|
|
55
|
+
/** Mint a fourth certificate between the leaf and the intermediate, for the depth cases. */
|
|
56
|
+
extraIntermediate?: boolean;
|
|
57
|
+
}
|
|
58
|
+
/** base64url without padding — how every segment of a JWS is encoded. */
|
|
59
|
+
export declare function base64Url(bytes: Uint8Array): string;
|
|
60
|
+
/**
|
|
61
|
+
* Mint a three-certificate chain shaped like Apple's: P-256 leaf ← P-384 intermediate ← P-384 root.
|
|
62
|
+
*
|
|
63
|
+
* The default mint is a chain the verifier accepts, which means it carries what a real Apple chain carries:
|
|
64
|
+
* `basicConstraints` CA:TRUE on the root and intermediate, `keyUsage` with `keyCertSign` on both, and Apple's
|
|
65
|
+
* two marker OIDs. Every `MintChainOptions` flag that removes one of those exists so a test can prove the
|
|
66
|
+
* corresponding refusal is real rather than assumed.
|
|
67
|
+
*/
|
|
68
|
+
export declare function mintChain(options?: MintChainOptions): Promise<MintedChain>;
|
|
69
|
+
/**
|
|
70
|
+
* Sign a compact JWS the way Apple does: an `ES256` header carrying the chain in `x5c`, the payload, and a
|
|
71
|
+
* P-256 signature over `header.payload`.
|
|
72
|
+
*
|
|
73
|
+
* `header` overrides let a test present a header Apple never would — `alg: "none"`, a missing `x5c`, an
|
|
74
|
+
* `HS256` claim over an EC signature — which is how algorithm confusion is proved rejected rather than
|
|
75
|
+
* assumed impossible.
|
|
76
|
+
*/
|
|
77
|
+
export declare function signJws(payload: unknown, chain: MintedChain, header?: Record<string, unknown>, hash?: "SHA-256" | "SHA-384"): Promise<string>;
|
|
78
|
+
/** A compact JWS with its payload swapped for another, keeping the original signature. The tamper case. */
|
|
79
|
+
export declare function tamperPayload(jws: string, payload: unknown): string;
|
|
80
|
+
/**
|
|
81
|
+
* A recorded notification, as the `*.json` files beside this module store one.
|
|
82
|
+
*
|
|
83
|
+
* The files hold **decoded** payloads, and this is why: Apple nests three independently-signed JWS inside
|
|
84
|
+
* one notification, and a recorded signature can only ever be verified against Apple's real chain, which no
|
|
85
|
+
* test may reach. So the recording keeps the payloads — redacted, but faithful to Apple's published
|
|
86
|
+
* `responseBodyV2DecodedPayload`, `JWSTransactionDecodedPayload`, and `JWSRenewalInfoDecodedPayload` shapes
|
|
87
|
+
* — and {@link signNotification} re-signs them with the minted chain. The shapes are the fixture; the
|
|
88
|
+
* signatures are the test's own.
|
|
89
|
+
*/
|
|
90
|
+
export interface NotificationFixture {
|
|
91
|
+
/** The notification payload, without the nested JWS fields — those are produced from the two below. */
|
|
92
|
+
notification: Record<string, unknown> & {
|
|
93
|
+
data?: Record<string, unknown>;
|
|
94
|
+
};
|
|
95
|
+
/** The transaction payload, signed into `data.signedTransactionInfo`. Absent for a state-free type. */
|
|
96
|
+
transaction?: Record<string, unknown>;
|
|
97
|
+
/** The renewal payload, signed into `data.signedRenewalInfo`. Absent for a one-time purchase. */
|
|
98
|
+
renewalInfo?: Record<string, unknown>;
|
|
99
|
+
}
|
|
100
|
+
/** Sign a recorded notification into the nested-JWS form Apple actually delivers. */
|
|
101
|
+
export declare function signNotification(fixture: NotificationFixture, chain: MintedChain): Promise<string>;
|
|
102
|
+
/** A minted App Store Connect API key: the PKCS#8 PEM a `.p8` holds, and the public half to verify against. */
|
|
103
|
+
export interface MintedAppStoreKey {
|
|
104
|
+
/** The private key in the exact PEM armour App Store Connect issues. */
|
|
105
|
+
pem: string;
|
|
106
|
+
/** The public half, so a test can verify a minted token rather than trust its shape. */
|
|
107
|
+
publicKey: CryptoKey;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Mint an App Store Connect API key.
|
|
111
|
+
*
|
|
112
|
+
* A real P-256 pair exported as PKCS#8 PEM, because that is exactly what a downloaded `.p8` is — so a suite
|
|
113
|
+
* that mints a token with it and verifies it against the public half has proved Apple would have accepted
|
|
114
|
+
* the token, rather than proved the string has three dots in it.
|
|
115
|
+
*/
|
|
116
|
+
export declare function mintAppStoreKey(): Promise<MintedAppStoreKey>;
|
|
117
|
+
//# sourceMappingURL=chain.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chain.d.ts","sourceRoot":"","sources":["../../../../src/rails/apple/fixtures/chain.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;GAgBG;AAEH,yFAAyF;AACzF,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,OAAO,CAAC;AAW1C,kEAAkE;AAClE,MAAM,WAAW,WAAW;IAC1B,yCAAyC;IACzC,GAAG,EAAE,MAAM,EAAE,CAAC;IACd,iDAAiD;IACjD,OAAO,EAAE,SAAS,CAAC;IACnB,wEAAwE;IACxE,IAAI,EAAE,MAAM,CAAC;CACd;AAED,gFAAgF;AAChF,MAAM,WAAW,gBAAgB;IAC/B,yEAAyE;IACzE,aAAa,CAAC,EAAE,IAAI,CAAC;IACrB,YAAY,CAAC,EAAE,IAAI,CAAC;IACpB,gEAAgE;IAChE,qBAAqB,CAAC,EAAE,IAAI,CAAC;IAC7B,oBAAoB,CAAC,EAAE,IAAI,CAAC;IAC5B,kGAAkG;IAClG,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,8EAA8E;IAC9E,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,+EAA+E;IAC/E,8BAA8B,CAAC,EAAE,OAAO,CAAC;IACzC,gGAAgG;IAChG,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,wDAAwD;IACxD,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,sDAAsD;IACtD,0BAA0B,CAAC,EAAE,OAAO,CAAC;IACrC,4FAA4F;IAC5F,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AA0HD,yEAAyE;AACzE,wBAAgB,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAEnD;AAiDD;;;;;;;GAOG;AACH,wBAAsB,SAAS,CAAC,OAAO,GAAE,gBAAqB,GAAG,OAAO,CAAC,WAAW,CAAC,CAqEpF;AAED;;;;;;;GAOG;AACH,wBAAsB,OAAO,CAC3B,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,WAAW,EAClB,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,EACpC,IAAI,GAAE,SAAS,GAAG,SAAqB,GACtC,OAAO,CAAC,MAAM,CAAC,CAQjB;AAED,2GAA2G;AAC3G,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAGnE;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,mBAAmB;IAClC,uGAAuG;IACvG,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,CAAC;IAC3E,uGAAuG;IACvG,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACtC,iGAAiG;IACjG,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACvC;AAED,qFAAqF;AACrF,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,mBAAmB,EAAE,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAUxG;AAED,+GAA+G;AAC/G,MAAM,WAAW,iBAAiB;IAChC,wEAAwE;IACxE,GAAG,EAAE,MAAM,CAAC;IACZ,wFAAwF;IACxF,SAAS,EAAE,SAAS,CAAC;CACtB;AAED;;;;;;GAMG;AACH,wBAAsB,eAAe,IAAI,OAAO,CAAC,iBAAiB,CAAC,CAWlE"}
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
//#region src/rails/apple/fixtures/chain.ts
|
|
2
|
+
const OID_COMMON_NAME = "2.5.4.3";
|
|
3
|
+
const OID_ECDSA_SHA256 = "1.2.840.10045.4.3.2";
|
|
4
|
+
const OID_ECDSA_SHA384 = "1.2.840.10045.4.3.3";
|
|
5
|
+
const OID_BASIC_CONSTRAINTS = "2.5.29.19";
|
|
6
|
+
const OID_KEY_USAGE = "2.5.29.15";
|
|
7
|
+
/** Apple's published marker OIDs — the same two `x509.ts` requires. */
|
|
8
|
+
const OID_APPLE_RECEIPT_SIGNER = "1.2.840.113635.100.6.11.1";
|
|
9
|
+
const OID_APPLE_WWDR = "1.2.840.113635.100.6.2.1";
|
|
10
|
+
/** Tag-length-value. Long-form length whenever the contents need it, exactly as DER requires. */
|
|
11
|
+
function tlv(tag, contents) {
|
|
12
|
+
if (contents.length < 128) return new Uint8Array([
|
|
13
|
+
tag,
|
|
14
|
+
contents.length,
|
|
15
|
+
...contents
|
|
16
|
+
]);
|
|
17
|
+
const lengthBytes = [];
|
|
18
|
+
let remaining = contents.length;
|
|
19
|
+
while (remaining > 0) {
|
|
20
|
+
lengthBytes.unshift(remaining & 255);
|
|
21
|
+
remaining = Math.floor(remaining / 256);
|
|
22
|
+
}
|
|
23
|
+
return new Uint8Array([
|
|
24
|
+
tag,
|
|
25
|
+
128 | lengthBytes.length,
|
|
26
|
+
...lengthBytes,
|
|
27
|
+
...contents
|
|
28
|
+
]);
|
|
29
|
+
}
|
|
30
|
+
function concat(...parts) {
|
|
31
|
+
const total = parts.reduce((sum, part) => sum + part.length, 0);
|
|
32
|
+
const out = new Uint8Array(total);
|
|
33
|
+
let offset = 0;
|
|
34
|
+
for (const part of parts) {
|
|
35
|
+
out.set(part, offset);
|
|
36
|
+
offset += part.length;
|
|
37
|
+
}
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
const sequence = (...parts) => tlv(48, concat(...parts));
|
|
41
|
+
const set = (...parts) => tlv(49, concat(...parts));
|
|
42
|
+
const utf8String = (text) => tlv(12, new TextEncoder().encode(text));
|
|
43
|
+
const bitString = (bytes) => tlv(3, concat(new Uint8Array([0]), bytes));
|
|
44
|
+
const explicit = (index, contents) => tlv(160 | index, contents);
|
|
45
|
+
const octetString = (bytes) => tlv(4, bytes);
|
|
46
|
+
/** DER admits only 0x00 and 0xff for a BOOLEAN, and the reader under test enforces exactly that. */
|
|
47
|
+
const boolean = (value) => tlv(1, new Uint8Array([value ? 255 : 0]));
|
|
48
|
+
/** `Extension ::= SEQUENCE { extnID, critical DEFAULT FALSE, extnValue OCTET STRING }`. */
|
|
49
|
+
function extension(id, value, critical = false) {
|
|
50
|
+
const parts = critical ? [
|
|
51
|
+
oid(id),
|
|
52
|
+
boolean(true),
|
|
53
|
+
octetString(value)
|
|
54
|
+
] : [oid(id), octetString(value)];
|
|
55
|
+
return sequence(...parts);
|
|
56
|
+
}
|
|
57
|
+
/** `BasicConstraints ::= SEQUENCE { cA BOOLEAN DEFAULT FALSE, pathLenConstraint INTEGER OPTIONAL }`. */
|
|
58
|
+
function basicConstraints(ca, pathLen) {
|
|
59
|
+
const members = [];
|
|
60
|
+
if (ca) members.push(boolean(true));
|
|
61
|
+
if (pathLen !== void 0) members.push(integer(pathLen));
|
|
62
|
+
return extension(OID_BASIC_CONSTRAINTS, sequence(...members), true);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* `keyUsage`, as the bits a CA needs. `digitalSignature` is bit 0 and `keyCertSign` bit 5, so a CA's byte is
|
|
66
|
+
* `0b00000100` with two unused trailing bits and a leaf's is `0b10000000` with seven.
|
|
67
|
+
*/
|
|
68
|
+
function keyUsage(keyCertSign) {
|
|
69
|
+
const bytes = keyCertSign ? new Uint8Array([2, 4]) : new Uint8Array([7, 128]);
|
|
70
|
+
return extension(OID_KEY_USAGE, tlv(3, bytes), true);
|
|
71
|
+
}
|
|
72
|
+
/** A positive INTEGER, with DER's leading zero when the high bit would read as a sign. */
|
|
73
|
+
function integer(value) {
|
|
74
|
+
const bytes = [];
|
|
75
|
+
let remaining = value;
|
|
76
|
+
do {
|
|
77
|
+
bytes.unshift(remaining & 255);
|
|
78
|
+
remaining = Math.floor(remaining / 256);
|
|
79
|
+
} while (remaining > 0);
|
|
80
|
+
if (bytes[0] & 128) bytes.unshift(0);
|
|
81
|
+
return tlv(2, new Uint8Array(bytes));
|
|
82
|
+
}
|
|
83
|
+
function oid(dotted) {
|
|
84
|
+
const arcs = dotted.split(".").map(Number);
|
|
85
|
+
const bytes = [40 * arcs[0] + arcs[1]];
|
|
86
|
+
for (const arc of arcs.slice(2)) {
|
|
87
|
+
const base128 = [arc & 127];
|
|
88
|
+
let remaining = Math.floor(arc / 128);
|
|
89
|
+
while (remaining > 0) {
|
|
90
|
+
base128.unshift(remaining & 127 | 128);
|
|
91
|
+
remaining = Math.floor(remaining / 128);
|
|
92
|
+
}
|
|
93
|
+
bytes.push(...base128);
|
|
94
|
+
}
|
|
95
|
+
return tlv(6, new Uint8Array(bytes));
|
|
96
|
+
}
|
|
97
|
+
/** UTCTime, `YYMMDDHHMMSSZ` — the encoding X.509 uses for any year before 2050. */
|
|
98
|
+
function utcTime(when) {
|
|
99
|
+
const iso = when.toISOString();
|
|
100
|
+
const text = `${iso.slice(2, 4)}${iso.slice(5, 7)}${iso.slice(8, 10)}${iso.slice(11, 13)}${iso.slice(14, 16)}${iso.slice(17, 19)}Z`;
|
|
101
|
+
return tlv(23, new TextEncoder().encode(text));
|
|
102
|
+
}
|
|
103
|
+
/** A Name carrying one common name — enough to link a chain, which matches issuer against subject. */
|
|
104
|
+
const name = (commonName) => sequence(set(sequence(oid(OID_COMMON_NAME), utf8String(commonName))));
|
|
105
|
+
/** WebCrypto's fixed-width `r || s` as the `SEQUENCE { INTEGER r, INTEGER s }` X.509 carries. */
|
|
106
|
+
function rawSignatureToDer(raw) {
|
|
107
|
+
const half = raw.length / 2;
|
|
108
|
+
const parts = [raw.subarray(0, half), raw.subarray(half)].map((coordinate) => {
|
|
109
|
+
let value = coordinate;
|
|
110
|
+
while (value.length > 1 && value[0] === 0) value = value.subarray(1);
|
|
111
|
+
return tlv(2, value[0] & 128 ? concat(new Uint8Array([0]), value) : value);
|
|
112
|
+
});
|
|
113
|
+
return sequence(...parts);
|
|
114
|
+
}
|
|
115
|
+
function bytesToBase64(bytes) {
|
|
116
|
+
let binary = "";
|
|
117
|
+
for (const byte of bytes) binary += String.fromCharCode(byte);
|
|
118
|
+
return btoa(binary);
|
|
119
|
+
}
|
|
120
|
+
/** base64url without padding — how every segment of a JWS is encoded. */
|
|
121
|
+
function base64Url(bytes) {
|
|
122
|
+
return bytesToBase64(bytes).replaceAll("+", "-").replaceAll("/", "_").replaceAll("=", "");
|
|
123
|
+
}
|
|
124
|
+
async function generateKeyPair(curve) {
|
|
125
|
+
return await crypto.subtle.generateKey({
|
|
126
|
+
name: "ECDSA",
|
|
127
|
+
namedCurve: curve
|
|
128
|
+
}, true, ["sign", "verify"]);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Mint one certificate. `issuer` is undefined for a self-signed root, in which case the certificate names
|
|
132
|
+
* and signs itself the way a real root does.
|
|
133
|
+
*/
|
|
134
|
+
async function mintCertificate(options) {
|
|
135
|
+
const { publicKey, privateKey } = await generateKeyPair(options.curve);
|
|
136
|
+
const spki = new Uint8Array(await crypto.subtle.exportKey("spki", publicKey));
|
|
137
|
+
const subject = name(options.commonName);
|
|
138
|
+
const algorithm = sequence(oid(options.issuerHash === "SHA-384" ? OID_ECDSA_SHA384 : OID_ECDSA_SHA256));
|
|
139
|
+
const extensions = options.extensions ?? [];
|
|
140
|
+
const tbs = sequence(explicit(0, integer(2)), integer(options.serial), algorithm, options.issuer?.subject ?? subject, sequence(utcTime(options.notBefore), utcTime(options.notAfter)), subject, spki, ...extensions.length > 0 ? [explicit(3, sequence(...extensions))] : []);
|
|
141
|
+
const signingKey = options.issuer?.privateKey ?? privateKey;
|
|
142
|
+
const raw = new Uint8Array(await crypto.subtle.sign({
|
|
143
|
+
name: "ECDSA",
|
|
144
|
+
hash: options.issuerHash
|
|
145
|
+
}, signingKey, tbs));
|
|
146
|
+
return {
|
|
147
|
+
der: sequence(tbs, algorithm, bitString(rawSignatureToDer(raw))),
|
|
148
|
+
publicKey,
|
|
149
|
+
privateKey,
|
|
150
|
+
subject
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Mint a three-certificate chain shaped like Apple's: P-256 leaf ← P-384 intermediate ← P-384 root.
|
|
155
|
+
*
|
|
156
|
+
* The default mint is a chain the verifier accepts, which means it carries what a real Apple chain carries:
|
|
157
|
+
* `basicConstraints` CA:TRUE on the root and intermediate, `keyUsage` with `keyCertSign` on both, and Apple's
|
|
158
|
+
* two marker OIDs. Every `MintChainOptions` flag that removes one of those exists so a test can prove the
|
|
159
|
+
* corresponding refusal is real rather than assumed.
|
|
160
|
+
*/
|
|
161
|
+
async function mintChain(options = {}) {
|
|
162
|
+
const year = 31536e6;
|
|
163
|
+
const now = Date.now();
|
|
164
|
+
const label = options.label ?? "pithy";
|
|
165
|
+
const root = await mintCertificate({
|
|
166
|
+
commonName: `${label} test root`,
|
|
167
|
+
curve: "P-384",
|
|
168
|
+
notBefore: /* @__PURE__ */ new Date(now - year),
|
|
169
|
+
notAfter: new Date(now + year),
|
|
170
|
+
issuerHash: "SHA-384",
|
|
171
|
+
serial: 1,
|
|
172
|
+
extensions: [basicConstraints(true), keyUsage(true)]
|
|
173
|
+
});
|
|
174
|
+
const intermediateExtensions = [];
|
|
175
|
+
if (!options.intermediateNotCa) intermediateExtensions.push(basicConstraints(true, options.intermediatePathLen));
|
|
176
|
+
intermediateExtensions.push(keyUsage(!options.intermediateWithoutKeyCertSign));
|
|
177
|
+
if (!options.intermediateWithoutWwdrOid) intermediateExtensions.push(extension(OID_APPLE_WWDR, sequence()));
|
|
178
|
+
const intermediate = await mintCertificate({
|
|
179
|
+
commonName: `${label} test intermediate`,
|
|
180
|
+
curve: "P-384",
|
|
181
|
+
notBefore: options.intermediateNotBefore ?? /* @__PURE__ */ new Date(now - year),
|
|
182
|
+
notAfter: options.intermediateNotAfter ?? new Date(now + year),
|
|
183
|
+
issuer: root,
|
|
184
|
+
issuerHash: "SHA-384",
|
|
185
|
+
serial: 2,
|
|
186
|
+
extensions: intermediateExtensions
|
|
187
|
+
});
|
|
188
|
+
const extra = options.extraIntermediate ? await mintCertificate({
|
|
189
|
+
commonName: `${label} test sub-intermediate`,
|
|
190
|
+
curve: "P-384",
|
|
191
|
+
notBefore: /* @__PURE__ */ new Date(now - year),
|
|
192
|
+
notAfter: new Date(now + year),
|
|
193
|
+
issuer: intermediate,
|
|
194
|
+
issuerHash: "SHA-384",
|
|
195
|
+
serial: 4,
|
|
196
|
+
extensions: [
|
|
197
|
+
basicConstraints(true),
|
|
198
|
+
keyUsage(true),
|
|
199
|
+
extension(OID_APPLE_WWDR, sequence())
|
|
200
|
+
]
|
|
201
|
+
}) : void 0;
|
|
202
|
+
const leafExtensions = [keyUsage(false)];
|
|
203
|
+
if (!options.leafWithoutSignerOid) leafExtensions.push(extension(OID_APPLE_RECEIPT_SIGNER, sequence()));
|
|
204
|
+
const leaf = await mintCertificate({
|
|
205
|
+
commonName: `${label} test leaf`,
|
|
206
|
+
curve: options.leafCurve ?? "P-256",
|
|
207
|
+
notBefore: options.leafNotBefore ?? /* @__PURE__ */ new Date(now - year),
|
|
208
|
+
notAfter: options.leafNotAfter ?? new Date(now + year),
|
|
209
|
+
issuer: extra ?? intermediate,
|
|
210
|
+
issuerHash: "SHA-384",
|
|
211
|
+
serial: 3,
|
|
212
|
+
extensions: leafExtensions
|
|
213
|
+
});
|
|
214
|
+
return {
|
|
215
|
+
x5c: (extra ? [
|
|
216
|
+
leaf.der,
|
|
217
|
+
extra.der,
|
|
218
|
+
intermediate.der,
|
|
219
|
+
root.der
|
|
220
|
+
] : [
|
|
221
|
+
leaf.der,
|
|
222
|
+
intermediate.der,
|
|
223
|
+
root.der
|
|
224
|
+
]).map(bytesToBase64),
|
|
225
|
+
leafKey: leaf.privateKey,
|
|
226
|
+
root: bytesToBase64(root.der)
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Sign a compact JWS the way Apple does: an `ES256` header carrying the chain in `x5c`, the payload, and a
|
|
231
|
+
* P-256 signature over `header.payload`.
|
|
232
|
+
*
|
|
233
|
+
* `header` overrides let a test present a header Apple never would — `alg: "none"`, a missing `x5c`, an
|
|
234
|
+
* `HS256` claim over an EC signature — which is how algorithm confusion is proved rejected rather than
|
|
235
|
+
* assumed impossible.
|
|
236
|
+
*/
|
|
237
|
+
async function signJws(payload, chain, header = {}, hash = "SHA-256") {
|
|
238
|
+
const encoder = new TextEncoder();
|
|
239
|
+
const head = base64Url(encoder.encode(JSON.stringify({
|
|
240
|
+
alg: "ES256",
|
|
241
|
+
x5c: chain.x5c,
|
|
242
|
+
...header
|
|
243
|
+
})));
|
|
244
|
+
const body = base64Url(encoder.encode(JSON.stringify(payload)));
|
|
245
|
+
return `${head}.${body}.${base64Url(new Uint8Array(await crypto.subtle.sign({
|
|
246
|
+
name: "ECDSA",
|
|
247
|
+
hash
|
|
248
|
+
}, chain.leafKey, encoder.encode(`${head}.${body}`))))}`;
|
|
249
|
+
}
|
|
250
|
+
/** A compact JWS with its payload swapped for another, keeping the original signature. The tamper case. */
|
|
251
|
+
function tamperPayload(jws, payload) {
|
|
252
|
+
const [head, , signature] = jws.split(".");
|
|
253
|
+
return `${head}.${base64Url(new TextEncoder().encode(JSON.stringify(payload)))}.${signature}`;
|
|
254
|
+
}
|
|
255
|
+
/** Sign a recorded notification into the nested-JWS form Apple actually delivers. */
|
|
256
|
+
async function signNotification(fixture, chain) {
|
|
257
|
+
const data = fixture.notification.data;
|
|
258
|
+
const signedData = data ? {
|
|
259
|
+
...data,
|
|
260
|
+
...fixture.transaction ? { signedTransactionInfo: await signJws(fixture.transaction, chain) } : {},
|
|
261
|
+
...fixture.renewalInfo ? { signedRenewalInfo: await signJws(fixture.renewalInfo, chain) } : {}
|
|
262
|
+
} : void 0;
|
|
263
|
+
return signJws({
|
|
264
|
+
...fixture.notification,
|
|
265
|
+
...signedData ? { data: signedData } : {}
|
|
266
|
+
}, chain);
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Mint an App Store Connect API key.
|
|
270
|
+
*
|
|
271
|
+
* A real P-256 pair exported as PKCS#8 PEM, because that is exactly what a downloaded `.p8` is — so a suite
|
|
272
|
+
* that mints a token with it and verifies it against the public half has proved Apple would have accepted
|
|
273
|
+
* the token, rather than proved the string has three dots in it.
|
|
274
|
+
*/
|
|
275
|
+
async function mintAppStoreKey() {
|
|
276
|
+
const pair = await crypto.subtle.generateKey({
|
|
277
|
+
name: "ECDSA",
|
|
278
|
+
namedCurve: "P-256"
|
|
279
|
+
}, true, ["sign", "verify"]);
|
|
280
|
+
const pkcs8 = new Uint8Array(await crypto.subtle.exportKey("pkcs8", pair.privateKey));
|
|
281
|
+
let binary = "";
|
|
282
|
+
for (const byte of pkcs8) binary += String.fromCharCode(byte);
|
|
283
|
+
return {
|
|
284
|
+
pem: `-----BEGIN PRIVATE KEY-----\n${(btoa(binary).match(/.{1,64}/g) ?? []).join("\n")}\n-----END PRIVATE KEY-----\n`,
|
|
285
|
+
publicKey: pair.publicKey
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
//#endregion
|
|
289
|
+
export { base64Url, mintAppStoreKey, mintChain, signJws, signNotification, tamperPayload };
|