@venizia/ignis 0.4.8-9 → 0.5.0-0
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/esm/base/applications/base.js +5 -2
- package/dist/esm/base/applications/base.js.map +1 -1
- package/dist/esm/base/middlewares/request-spy/request-spy.middleware.js +1 -1
- package/dist/esm/base/middlewares/request-spy/request-spy.middleware.js.map +1 -1
- package/dist/esm/components/api-reference/common/keys.d.ts +2 -1
- package/dist/esm/components/api-reference/common/keys.js +4 -1
- package/dist/esm/components/api-reference/common/keys.js.map +1 -1
- package/dist/esm/components/api-reference/common/types.d.ts +7 -4
- package/dist/esm/components/api-reference/common/types.js.map +1 -1
- package/dist/esm/components/api-reference/component.js +8 -3
- package/dist/esm/components/api-reference/component.js.map +1 -1
- package/dist/esm/components/auth/authenticate/component.js +13 -18
- package/dist/esm/components/auth/authenticate/component.js.map +1 -1
- package/dist/esm/components/auth/authenticate/controllers/factory.d.ts +3 -3
- package/dist/esm/components/auth/authenticate/controllers/factory.js +1 -1
- package/dist/esm/components/auth/authenticate/controllers/factory.js.map +1 -1
- package/dist/esm/components/auth/authenticate/controllers/jwks/controller.js.map +1 -1
- package/dist/esm/components/auth/authenticate/controllers/jwks/definitions.d.ts +2 -2
- package/dist/esm/components/auth/authenticate/controllers/service-certs/controller.js.map +1 -1
- package/dist/esm/components/auth/authenticate/controllers/service-certs/definitions.d.ts +2 -2
- package/dist/esm/components/auth/authenticate/services/basic/service.js +1 -1
- package/dist/esm/components/auth/authenticate/services/basic/service.js.map +1 -1
- package/dist/esm/components/auth/authenticate/services/bearer/abstract.service.d.ts +5 -3
- package/dist/esm/components/auth/authenticate/services/bearer/abstract.service.js +19 -2
- package/dist/esm/components/auth/authenticate/services/bearer/abstract.service.js.map +1 -1
- package/dist/esm/components/auth/authenticate/services/bearer/jwks/issuer.service.d.ts +3 -3
- package/dist/esm/components/auth/authenticate/services/bearer/jwks/issuer.service.js +1 -1
- package/dist/esm/components/auth/authenticate/services/bearer/jwks/issuer.service.js.map +1 -1
- package/dist/esm/components/auth/authenticate/services/bearer/jwks/verifier.service.d.ts +3 -3
- package/dist/esm/components/auth/authenticate/services/bearer/jwks/verifier.service.js +2 -2
- package/dist/esm/components/auth/authenticate/services/bearer/jwks/verifier.service.js.map +1 -1
- package/dist/esm/components/auth/authenticate/services/bearer/jws.service.d.ts +3 -3
- package/dist/esm/components/auth/authenticate/services/bearer/jws.service.js +1 -1
- package/dist/esm/components/auth/authenticate/services/bearer/jws.service.js.map +1 -1
- package/dist/esm/components/auth/authenticate/services/jwks-url-policy.d.ts +10 -22
- package/dist/esm/components/auth/authenticate/services/jwks-url-policy.js +16 -112
- package/dist/esm/components/auth/authenticate/services/jwks-url-policy.js.map +1 -1
- package/dist/esm/components/auth/authenticate/services/service/signer.service.d.ts +11 -0
- package/dist/esm/components/auth/authenticate/services/service/signer.service.js +18 -0
- package/dist/esm/components/auth/authenticate/services/service/signer.service.js.map +1 -1
- package/dist/esm/components/auth/authenticate/services/service/verifier.service.js +1 -1
- package/dist/esm/components/auth/authenticate/services/service/verifier.service.js.map +1 -1
- package/dist/esm/components/auth/authenticate/strategies/basic.strategy.js.map +1 -1
- package/dist/esm/components/auth/authenticate/strategies/jwks/issuer.js.map +1 -1
- package/dist/esm/components/auth/authenticate/strategies/jwks/verifier.js.map +1 -1
- package/dist/esm/components/auth/authenticate/strategies/jws.strategy.js.map +1 -1
- package/dist/esm/components/auth/authenticate/strategies/service.strategy.js.map +1 -1
- package/dist/esm/components/auth/authorize/adapters/common/types.d.ts +1 -2
- package/dist/esm/components/auth/authorize/adapters/common/types.js.map +1 -1
- package/dist/esm/components/auth/authorize/component.js.map +1 -1
- package/dist/esm/components/controller/grpc/common/types.d.ts +1 -1
- package/dist/esm/components/controller/grpc/common/types.js +4 -1
- package/dist/esm/components/controller/grpc/common/types.js.map +1 -1
- package/dist/esm/components/controller/grpc/grpc.component.js.map +1 -1
- package/dist/esm/components/health-check/common/keys.d.ts +4 -2
- package/dist/esm/components/health-check/common/keys.js +7 -2
- package/dist/esm/components/health-check/common/keys.js.map +1 -1
- package/dist/esm/components/health-check/common/types.d.ts +1 -1
- package/dist/esm/components/health-check/common/types.js.map +1 -1
- package/dist/esm/components/health-check/component.js +1 -3
- package/dist/esm/components/health-check/component.js.map +1 -1
- package/dist/esm/components/mail/common/constants.d.ts +32 -14
- package/dist/esm/components/mail/common/constants.js +25 -32
- package/dist/esm/components/mail/common/constants.js.map +1 -1
- package/dist/esm/components/mail/common/errors.d.ts +19 -1
- package/dist/esm/components/mail/common/errors.js +13 -1
- package/dist/esm/components/mail/common/errors.js.map +1 -1
- package/dist/esm/components/mail/common/keys.d.ts +14 -11
- package/dist/esm/components/mail/common/keys.js +34 -11
- package/dist/esm/components/mail/common/keys.js.map +1 -1
- package/dist/esm/components/mail/common/types/message.d.ts +7 -4
- package/dist/esm/components/mail/common/types/message.js.map +1 -1
- package/dist/esm/components/mail/common/types/options.d.ts +54 -10
- package/dist/esm/components/mail/common/types/options.js.map +1 -1
- package/dist/esm/components/mail/common/types/queue.d.ts +25 -12
- package/dist/esm/components/mail/common/types/queue.js.map +1 -1
- package/dist/esm/components/mail/common/types/template.d.ts +8 -4
- package/dist/esm/components/mail/common/types/template.js.map +1 -1
- package/dist/esm/components/mail/common/types/verification.d.ts +1 -0
- package/dist/esm/components/mail/common/types/verification.js.map +1 -1
- package/dist/esm/components/mail/component.js +11 -2
- package/dist/esm/components/mail/component.js.map +1 -1
- package/dist/esm/components/mail/helpers/executors/bull-mq-executor.helper.d.ts +3 -1
- package/dist/esm/components/mail/helpers/executors/bull-mq-executor.helper.js +27 -33
- package/dist/esm/components/mail/helpers/executors/bull-mq-executor.helper.js.map +1 -1
- package/dist/esm/components/mail/helpers/executors/internal-queue-executor.helper.d.ts +2 -0
- package/dist/esm/components/mail/helpers/executors/internal-queue-executor.helper.js +17 -10
- package/dist/esm/components/mail/helpers/executors/internal-queue-executor.helper.js.map +1 -1
- package/dist/esm/components/mail/helpers/transporters/amazon-ses-transporter.helper.js +11 -6
- package/dist/esm/components/mail/helpers/transporters/amazon-ses-transporter.helper.js.map +1 -1
- package/dist/esm/components/mail/helpers/transporters/mailgun-transporter.helper.d.ts +2 -3
- package/dist/esm/components/mail/helpers/transporters/mailgun-transporter.helper.js +15 -6
- package/dist/esm/components/mail/helpers/transporters/mailgun-transporter.helper.js.map +1 -1
- package/dist/esm/components/mail/helpers/transporters/nodemail-transporter.helper.d.ts +2 -3
- package/dist/esm/components/mail/helpers/transporters/nodemail-transporter.helper.js +2 -2
- package/dist/esm/components/mail/helpers/transporters/nodemail-transporter.helper.js.map +1 -1
- package/dist/esm/components/mail/providers/mail-queue-executor.provider.d.ts +2 -2
- package/dist/esm/components/mail/providers/mail-queue-executor.provider.js +7 -9
- package/dist/esm/components/mail/providers/mail-queue-executor.provider.js.map +1 -1
- package/dist/esm/components/mail/providers/mail-transporter.provider.js +7 -7
- package/dist/esm/components/mail/providers/mail-transporter.provider.js.map +1 -1
- package/dist/esm/components/mail/services/generators/numeric-code.d.ts +1 -6
- package/dist/esm/components/mail/services/generators/numeric-code.js +3 -31
- package/dist/esm/components/mail/services/generators/numeric-code.js.map +1 -1
- package/dist/esm/components/mail/services/generators/random-token.d.ts +4 -1
- package/dist/esm/components/mail/services/generators/random-token.js +9 -6
- package/dist/esm/components/mail/services/generators/random-token.js.map +1 -1
- package/dist/esm/components/mail/services/mail.service.d.ts +1 -2
- package/dist/esm/components/mail/services/mail.service.js +22 -19
- package/dist/esm/components/mail/services/mail.service.js.map +1 -1
- package/dist/esm/components/mail/services/template.service.d.ts +8 -6
- package/dist/esm/components/mail/services/template.service.js +34 -33
- package/dist/esm/components/mail/services/template.service.js.map +1 -1
- package/dist/esm/components/mail/utilities/attachment.utility.js +8 -6
- package/dist/esm/components/mail/utilities/attachment.utility.js.map +1 -1
- package/dist/esm/components/mail/utilities/header.utility.d.ts +14 -0
- package/dist/esm/components/mail/utilities/header.utility.js +44 -0
- package/dist/esm/components/mail/utilities/header.utility.js.map +1 -0
- package/dist/esm/components/mail/utilities/index.d.ts +2 -0
- package/dist/esm/components/mail/utilities/index.js +2 -0
- package/dist/esm/components/mail/utilities/index.js.map +1 -1
- package/dist/esm/components/mail/utilities/mime.utility.d.ts +5 -1
- package/dist/esm/components/mail/utilities/mime.utility.js +12 -58
- package/dist/esm/components/mail/utilities/mime.utility.js.map +1 -1
- package/dist/esm/components/mail/utilities/template-renderer.utility.d.ts +31 -0
- package/dist/esm/components/mail/utilities/template-renderer.utility.js +184 -0
- package/dist/esm/components/mail/utilities/template-renderer.utility.js.map +1 -0
- package/dist/esm/components/mail/utilities/type.utility.d.ts +2 -3
- package/dist/esm/components/mail/utilities/type.utility.js +6 -7
- package/dist/esm/components/mail/utilities/type.utility.js.map +1 -1
- package/dist/esm/components/request-tracker/component.d.ts +2 -1
- package/dist/esm/components/request-tracker/component.js +5 -5
- package/dist/esm/components/request-tracker/component.js.map +1 -1
- package/dist/esm/components/server-info/common/keys.d.ts +2 -1
- package/dist/esm/components/server-info/common/keys.js +4 -1
- package/dist/esm/components/server-info/common/keys.js.map +1 -1
- package/dist/esm/components/server-info/common/types.d.ts +1 -1
- package/dist/esm/components/server-info/common/types.js.map +1 -1
- package/dist/esm/components/server-info/component.js +1 -3
- package/dist/esm/components/server-info/component.js.map +1 -1
- package/dist/esm/components/socket-io/common/keys.d.ts +9 -6
- package/dist/esm/components/socket-io/common/keys.js +19 -6
- package/dist/esm/components/socket-io/common/keys.js.map +1 -1
- package/dist/esm/components/socket-io/component.js +1 -1
- package/dist/esm/components/socket-io/component.js.map +1 -1
- package/dist/esm/components/socket-io/handlers/bun.handler.d.ts +13 -3
- package/dist/esm/components/socket-io/handlers/bun.handler.js.map +1 -1
- package/dist/esm/components/static-asset/common/constants.d.ts +51 -24
- package/dist/esm/components/static-asset/common/constants.js +75 -47
- package/dist/esm/components/static-asset/common/constants.js.map +1 -1
- package/dist/esm/components/static-asset/common/errors.d.ts +30 -35
- package/dist/esm/components/static-asset/common/errors.js +31 -33
- package/dist/esm/components/static-asset/common/errors.js.map +1 -1
- package/dist/esm/components/static-asset/common/index.d.ts +1 -1
- package/dist/esm/components/static-asset/common/index.js +1 -1
- package/dist/esm/components/static-asset/common/index.js.map +1 -1
- package/dist/esm/components/static-asset/common/keys.d.ts +14 -2
- package/dist/esm/components/static-asset/common/keys.js +17 -2
- package/dist/esm/components/static-asset/common/keys.js.map +1 -1
- package/dist/esm/components/static-asset/common/types.d.ts +267 -147
- package/dist/esm/components/static-asset/common/types.js.map +1 -1
- package/dist/esm/components/static-asset/common/validation.d.ts +10 -0
- package/dist/esm/components/static-asset/common/validation.js +8 -0
- package/dist/esm/components/static-asset/common/validation.js.map +1 -0
- package/dist/esm/components/static-asset/component.d.ts +4 -2
- package/dist/esm/components/static-asset/component.js +27 -31
- package/dist/esm/components/static-asset/component.js.map +1 -1
- package/dist/esm/components/static-asset/controller/factory.d.ts +37 -79
- package/dist/esm/components/static-asset/controller/factory.js +26 -917
- package/dist/esm/components/static-asset/controller/factory.js.map +1 -1
- package/dist/esm/components/static-asset/controller/index.d.ts +1 -0
- package/dist/esm/components/static-asset/controller/index.js +1 -0
- package/dist/esm/components/static-asset/controller/index.js.map +1 -1
- package/dist/esm/components/static-asset/controller/routes/context.d.ts +62 -0
- package/dist/esm/components/static-asset/controller/routes/context.js +45 -0
- package/dist/esm/components/static-asset/controller/routes/context.js.map +1 -0
- package/dist/esm/components/static-asset/controller/routes/definition.d.ts +40 -0
- package/dist/esm/components/static-asset/controller/routes/definition.js +83 -0
- package/dist/esm/components/static-asset/controller/routes/definition.js.map +1 -0
- package/dist/esm/components/static-asset/controller/routes/direct-upload.d.ts +3 -0
- package/dist/esm/components/static-asset/controller/routes/direct-upload.js +153 -0
- package/dist/esm/components/static-asset/controller/routes/direct-upload.js.map +1 -0
- package/dist/esm/components/static-asset/controller/routes/labels.d.ts +16 -0
- package/dist/esm/components/static-asset/controller/routes/labels.js +19 -0
- package/dist/esm/components/static-asset/controller/routes/labels.js.map +1 -0
- package/dist/esm/components/static-asset/controller/routes/objects.d.ts +7 -0
- package/dist/esm/components/static-asset/controller/routes/objects.js +193 -0
- package/dist/esm/components/static-asset/controller/routes/objects.js.map +1 -0
- package/dist/esm/components/static-asset/controller/routes/serve.d.ts +29 -0
- package/dist/esm/components/static-asset/controller/routes/serve.js +152 -0
- package/dist/esm/components/static-asset/controller/routes/serve.js.map +1 -0
- package/dist/esm/components/static-asset/controller/routes/table.d.ts +12 -0
- package/dist/esm/components/static-asset/controller/routes/table.js +52 -0
- package/dist/esm/components/static-asset/controller/routes/table.js.map +1 -0
- package/dist/esm/components/static-asset/controller/routes/upload.d.ts +10 -0
- package/dist/esm/components/static-asset/controller/routes/upload.js +175 -0
- package/dist/esm/components/static-asset/controller/routes/upload.js.map +1 -0
- package/dist/esm/components/static-asset/index.d.ts +2 -1
- package/dist/esm/components/static-asset/index.js +2 -1
- package/dist/esm/components/static-asset/index.js.map +1 -1
- package/dist/esm/components/static-asset/models/base.model.d.ts +4 -4
- package/dist/esm/components/static-asset/models/base.model.js.map +1 -1
- package/dist/esm/components/static-asset/services/commitment.service.d.ts +103 -0
- package/dist/esm/components/static-asset/services/commitment.service.js +252 -0
- package/dist/esm/components/static-asset/services/commitment.service.js.map +1 -0
- package/dist/esm/components/static-asset/services/index.d.ts +3 -0
- package/dist/esm/components/static-asset/services/index.js +3 -0
- package/dist/esm/components/static-asset/services/index.js.map +1 -0
- package/dist/esm/components/static-asset/services/policy.service.d.ts +45 -0
- package/dist/esm/components/static-asset/services/policy.service.js +104 -0
- package/dist/esm/components/static-asset/services/policy.service.js.map +1 -0
- package/dist/esm/components/static-asset/utilities/commit-token.utility.d.ts +28 -0
- package/dist/esm/components/static-asset/utilities/commit-token.utility.js +112 -0
- package/dist/esm/components/static-asset/utilities/commit-token.utility.js.map +1 -0
- package/dist/esm/components/static-asset/utilities/entry.utility.d.ts +69 -0
- package/dist/esm/components/static-asset/utilities/entry.utility.js +160 -0
- package/dist/esm/components/static-asset/utilities/entry.utility.js.map +1 -0
- package/dist/esm/components/static-asset/utilities/index.d.ts +6 -0
- package/dist/esm/components/static-asset/utilities/index.js +6 -0
- package/dist/esm/components/static-asset/utilities/index.js.map +1 -0
- package/dist/esm/components/static-asset/{ingest.d.ts → utilities/ingest.utility.d.ts} +8 -8
- package/dist/esm/components/static-asset/{ingest.js → utilities/ingest.utility.js} +21 -23
- package/dist/esm/components/static-asset/utilities/ingest.utility.js.map +1 -0
- package/dist/esm/components/static-asset/{controller/key-scope.d.ts → utilities/key-scope.utility.d.ts} +21 -2
- package/dist/esm/components/static-asset/utilities/key-scope.utility.js +74 -0
- package/dist/esm/components/static-asset/utilities/key-scope.utility.js.map +1 -0
- package/dist/esm/components/static-asset/{controller/meta-link.d.ts → utilities/meta-link.utility.d.ts} +9 -9
- package/dist/esm/components/static-asset/{controller/meta-link.js → utilities/meta-link.utility.js} +10 -10
- package/dist/esm/components/static-asset/utilities/meta-link.utility.js.map +1 -0
- package/dist/esm/components/static-asset/utilities/object-link.utility.d.ts +16 -0
- package/dist/esm/components/static-asset/utilities/object-link.utility.js +20 -0
- package/dist/esm/components/static-asset/utilities/object-link.utility.js.map +1 -0
- package/dist/esm/components/static-asset/utilities/pinned-file.utility.d.ts +39 -0
- package/dist/esm/components/static-asset/utilities/pinned-file.utility.js +53 -0
- package/dist/esm/components/static-asset/utilities/pinned-file.utility.js.map +1 -0
- package/dist/esm/components/static-asset/utilities/route-options.utility.d.ts +43 -0
- package/dist/esm/components/static-asset/utilities/route-options.utility.js +71 -0
- package/dist/esm/components/static-asset/utilities/route-options.utility.js.map +1 -0
- package/dist/esm/components/static-asset/utilities/toggle.utility.d.ts +5 -0
- package/dist/esm/components/static-asset/utilities/toggle.utility.js +5 -0
- package/dist/esm/components/static-asset/utilities/toggle.utility.js.map +1 -0
- package/dist/esm/components/websocket/common/keys.d.ts +12 -10
- package/dist/esm/components/websocket/common/keys.js +31 -10
- package/dist/esm/components/websocket/common/keys.js.map +1 -1
- package/dist/esm/components/websocket/component.js.map +1 -1
- package/dist/esm/testing/assert-application-boots.d.ts +2 -2
- package/dist/esm/testing/assert-application-boots.js +6 -2
- package/dist/esm/testing/assert-application-boots.js.map +1 -1
- package/dist/presets/app/preset.json +4 -4
- package/dist/presets/lib/preset.json +3 -3
- package/dist/presets/shared/preset.json +1 -1
- package/package.json +8 -8
- package/dist/esm/components/static-asset/common/commit-token.d.ts +0 -28
- package/dist/esm/components/static-asset/common/commit-token.js +0 -48
- package/dist/esm/components/static-asset/common/commit-token.js.map +0 -1
- package/dist/esm/components/static-asset/controller/base.definition.d.ts +0 -30
- package/dist/esm/components/static-asset/controller/base.definition.js +0 -307
- package/dist/esm/components/static-asset/controller/base.definition.js.map +0 -1
- package/dist/esm/components/static-asset/controller/key-scope.js +0 -41
- package/dist/esm/components/static-asset/controller/key-scope.js.map +0 -1
- package/dist/esm/components/static-asset/controller/meta-link.js.map +0 -1
- package/dist/esm/components/static-asset/controller/route-options.d.ts +0 -29
- package/dist/esm/components/static-asset/controller/route-options.js +0 -47
- package/dist/esm/components/static-asset/controller/route-options.js.map +0 -1
- package/dist/esm/components/static-asset/ingest.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"issuer.service.js","sourceRoot":"","sources":["../../../../../../../../src/components/auth/authenticate/services/bearer/jwks/issuer.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,EAAE,IAAI,EAAuC,MAAM,+BAA+B,CAAC;AAC1F,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EACL,uBAAuB,EAIvB,MAAM,EACN,cAAc,EACd,cAAc,GAEf,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,wBAAwB,EAAE,MAAM,oBA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,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;aAC1E,WAAW,EAAE;aACb,iBAAiB,CAAC,GAAG,GAAG,SAAS,CAAC;aAClC,YAAY,CAAC,GAAG,CAAC,CAAC;QAErB,OAAO,IAAI,CAAC,eAAe,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IAC1F,CAAC;IAEkB,aAAa;QAC9B,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YACrB,MAAM,QAAQ,CAAC,EAAE,OAAO,EAAE,qCAAqC,EAAE,CAAC,CAAC;QACrE,CAAC;QAED,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAEkB,wBAAwB;QACzC,OAAO,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC;IACxC,CAAC;IAED,OAAO;QACL,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;YACf,MAAM,QAAQ,CAAC;gBACb,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,mBAAmB;gBACrD,OAAO,EAAE,iFAAiF;aAC3F,CAAC,CAAC;QACL,CAAC;QAED,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED,KAAK,CAAC,YAAY;QAChB,MAAM,IAAI,CAAC,iBAAiB,EAAE,CAAC;QAE/B,OAAO,IAAI,CAAC,IAAK,CAAC;IACpB,CAAC;CACF,CAAA;AArOY,sBAAsB;IAM9B,WAAA,MAAM,CAAC,EAAE,GAAG,EAAE,uBAAuB,CAAC,YAAY,EAAE,CAAC,CAAA;;GAN7C,sBAAsB,CAqOlC","sourcesContent":["import { HTTP, type TNullable, type ValueOrPromise } from '@venizia/ignis-helpers/common';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport {\n AuthenticateBindingKeys,\n type IJWKSIssuerOptions,\n type IJWTIssueClaims,\n type IJWTTokenPayload,\n inject,\n JWKSKeyDrivers,\n JWKSKeyFormats,\n type TGetTokenExpiresFn,\n} from '@venizia/ignis-kernel';\nimport { type Env } from 'hono';\nimport type { CryptoKey, JWK } from 'jose';\nimport { readFile } from 'node:fs/promises';\nimport { JoseLoader } from '../../jose-loader';\nimport { AbstractJWKSTokenService } from './abstract.service';\n\n/** Signs tokens with a private key loaded from `IJWKSIssuerOptions` and exposes the matching public keys as a JWKS via `getJWKSAsync()`. */\nexport class JWKSIssuerTokenService<E extends Env = Env> extends AbstractJWKSTokenService<E> {\n protected privateKey: TNullable<CryptoKey | Uint8Array> = null;\n protected publicKey: TNullable<CryptoKey | Uint8Array> = null;\n protected jwks: { keys: JWK[] } | null = null;\n\n constructor(\n @inject({ key: AuthenticateBindingKeys.JWKS_OPTIONS })\n protected options: IJWKSIssuerOptions,\n ) {\n super({ scope: JWKSIssuerTokenService.name });\n\n this.configureClaims({ options: this.options, pinnedAlgorithms: [this.options.algorithm] });\n this.configurePayloadEncryption({\n aesAlgorithm: this.options.aesAlgorithm,\n applicationSecret: this.options.applicationSecret,\n fieldCodecs: this.options.fieldCodecs,\n });\n }\n\n protected override async initialize(): Promise<void> {\n const { keys, algorithm } = this.options;\n\n const raw = await this.resolveKeyContent({ keys });\n const built = await this.parseKeyMaterial({ raw, algorithm, keys });\n\n this.privateKey = built.priv;\n this.publicKey = built.pub;\n\n const { exportJWK } = await JoseLoader.load();\n const publicJWK = await exportJWK(this.publicKey!);\n\n // Belt and braces. `assertPublicJWK` already refused a private JWK on the way IN, but this is\n // the exact object an unauthenticated `/certs` serves - the last place to notice a signing key\n // about to be published, whatever route the material took to get here.\n this.assertPublicJWK({ jwk: publicJWK });\n\n publicJWK.kid = this.options.kid;\n publicJWK.alg = algorithm;\n publicJWK.use = 'sig';\n\n this.jwks = { keys: [publicJWK] };\n\n this.initialized = true;\n\n this.logger\n .for(this.initialize.name)\n .info(\n 'JWKS issuer initialized | driver: %s | format: %s | kid: %s',\n keys.driver,\n keys.format,\n this.options.kid,\n );\n }\n\n protected async resolveKeyContent(opts: { keys: IJWKSIssuerOptions['keys'] }) {\n const { keys } = opts;\n\n switch (keys.driver) {\n case JWKSKeyDrivers.FILE: {\n const [priv, pub] = await Promise.all([\n readFile(keys.private, 'utf-8'),\n readFile(keys.public, 'utf-8'),\n ]);\n\n return { priv, pub };\n }\n case JWKSKeyDrivers.TEXT: {\n return {\n priv: keys.private,\n pub: keys.public,\n };\n }\n default: {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[JWKSIssuerTokenService] Unknown key driver: ${keys.driver}`,\n });\n }\n }\n }\n\n /**\n * Refuses a JWK carrying private material where a PUBLIC key is expected.\n *\n * The `pem` format cannot reach this state - `importSPKI` rejects a private PEM outright. The\n * `jwk` format can: `importJWK` imports whatever it is handed, and a private JWK marked\n * `\"ext\": true` yields an EXTRACTABLE key, so `exportJWK` then carries `d` straight into the\n * document `/certs` serves without authentication. Measured on jose 6.2.3: with `ext: true` the\n * round trip returns `d`; without it, export throws. So the only thing standing between a\n * mis-pasted key and a published signing key was an optional flag on attacker-irrelevant input.\n *\n * Named members, not a blanket scan: `d` covers EC/OKP and RSA's private exponent, and the CRT\n * members are the rest of an RSA private key.\n */\n protected assertPublicJWK(opts: { jwk: JWK }): void {\n const PRIVATE_MEMBERS = ['d', 'p', 'q', 'dp', 'dq', 'qi', 'k'] as const;\n\n const present = PRIVATE_MEMBERS.filter((member) => opts.jwk[member] !== undefined);\n\n if (present.length === 0) {\n return;\n }\n\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[JWKSIssuerTokenService] The public key material carries PRIVATE members (${present.join(', ')}) | this key would be published at the JWKS endpoint | pass the public half in keys.public`,\n });\n }\n\n protected async parseKeyMaterial(opts: {\n raw: { priv: string; pub: string };\n algorithm: IJWKSIssuerOptions['algorithm'];\n keys: IJWKSIssuerOptions['keys'];\n }) {\n const { raw, algorithm, keys } = opts;\n\n if (!raw.priv) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: '[JWKSIssuerTokenService] Invalid raw.priv key!',\n });\n }\n\n if (!raw.pub) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: '[JWKSIssuerTokenService] Invalid raw.pub key!',\n });\n }\n\n const { importJWK, importPKCS8, importSPKI } = await JoseLoader.load();\n\n switch (keys.format) {\n case JWKSKeyFormats.PEM: {\n const priv = await importPKCS8(raw.priv, algorithm);\n const pub = await importSPKI(raw.pub, algorithm);\n\n return { priv, pub };\n }\n case JWKSKeyFormats.JWK: {\n try {\n const parsed = {\n priv: JSON.parse(raw.priv) as JWK,\n pub: JSON.parse(raw.pub) as JWK,\n };\n\n this.assertPublicJWK({ jwk: parsed.pub });\n\n const priv = await importJWK(parsed.priv, algorithm);\n const pub = await importJWK(parsed.pub, algorithm);\n\n return { priv, pub };\n } catch (error) {\n this.logger\n .for(this.parseKeyMaterial.name)\n .error('Invalid JWK key material | Error: %s', error);\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: '[JWKSIssuerTokenService] Invalid JWK key material',\n });\n }\n }\n default: {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[JWKSIssuerTokenService] Unknown key format: ${keys.format}`,\n });\n }\n }\n }\n\n protected override async doVerify(token: string): Promise<IJWTTokenPayload> {\n await this.ensureInitialized();\n const { jwtVerify } = await JoseLoader.load();\n const result = await jwtVerify<IJWTTokenPayload>(token, this.publicKey!, this.verifyOptions!);\n\n return this.decryptPayload({ result });\n }\n\n override async getSigner(opts: {\n payload: IJWTTokenPayload;\n getTokenExpiresFn: TGetTokenExpiresFn;\n claims?: IJWTIssueClaims;\n }) {\n await this.ensureInitialized();\n const { SignJWT } = await JoseLoader.load();\n\n const now = Math.floor(Date.now() / 1000);\n const expiresIn = await opts.getTokenExpiresFn();\n\n const encryptedPayload = await this.encryptPayload(opts.payload);\n\n const signer = new SignJWT({ ...encryptedPayload })\n .setProtectedHeader({ alg: this.options.algorithm, kid: this.options.kid })\n .setIssuedAt()\n .setExpirationTime(now + expiresIn)\n .setNotBefore(now);\n\n return this.applySignClaims({ signer, payload: encryptedPayload, claims: opts.claims });\n }\n\n protected override getSigningKey(): ValueOrPromise<Uint8Array | CryptoKey> {\n if (!this.privateKey) {\n throw getError({ message: '[getSigningKey] Invalid privateKey!' });\n }\n\n return this.privateKey;\n }\n\n protected override getDefaultTokenExpiresFn(): TGetTokenExpiresFn {\n return this.options.getTokenExpiresFn;\n }\n\n getJWKS(): { keys: JWK[] } {\n if (!this.jwks) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: '[JWKSIssuerTokenService] JWKS not initialized yet. Call getJWKSAsync() instead.',\n });\n }\n\n return this.jwks;\n }\n\n async getJWKSAsync(): Promise<{ keys: JWK[] }> {\n await this.ensureInitialized();\n\n return this.jwks!;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"issuer.service.js","sourceRoot":"","sources":["../../../../../../../../src/components/auth/authenticate/services/bearer/jwks/issuer.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,EAAE,IAAI,EAAuC,MAAM,+BAA+B,CAAC;AAC1F,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EACL,uBAAuB,EAIvB,MAAM,EACN,cAAc,EACd,cAAc,GAGf,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAE9D,4IAA4I;AAC5I,IAAa,sBAAsB,8BAAnC,MAAa,sBAA4C,SAAQ,wBAA2B;IAK1F,YAEE,OAAuF;QAEvF,KAAK,CAAC,EAAE,KAAK,EAAE,wBAAsB,CAAC,IAAI,EAAE,CAAC,CAAC;QAFpC,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,MAAM,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IAC1F,CAAC;IAEkB,aAAa;QAC9B,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YACrB,MAAM,QAAQ,CAAC,EAAE,OAAO,EAAE,qCAAqC,EAAE,CAAC,CAAC;QACrE,CAAC;QAED,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAEkB,wBAAwB;QACzC,OAAO,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC;IACxC,CAAC;IAED,OAAO;QACL,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;YACf,MAAM,QAAQ,CAAC;gBACb,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,mBAAmB;gBACrD,OAAO,EAAE,iFAAiF;aAC3F,CAAC,CAAC;QACL,CAAC;QAED,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED,KAAK,CAAC,YAAY;QAChB,MAAM,IAAI,CAAC,iBAAiB,EAAE,CAAC;QAE/B,OAAO,IAAI,CAAC,IAAK,CAAC;IACpB,CAAC;CACF,CAAA;AArOY,sBAAsB;IAM9B,WAAA,MAAM,CAAC,EAAE,GAAG,EAAE,uBAAuB,CAAC,mBAAmB,EAAE,CAAC,CAAA;;GANpD,sBAAsB,CAqOlC","sourcesContent":["import { HTTP, type TNullable, type ValueOrPromise } from '@venizia/ignis-helpers/common';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport {\n AuthenticateBindingKeys,\n type IJWKSIssuerOptions,\n type IJWTIssueClaims,\n type IJWTTokenPayload,\n inject,\n JWKSKeyDrivers,\n JWKSKeyFormats,\n type TBindingKeyValue,\n type TGetTokenExpiresFn,\n} from '@venizia/ignis-kernel';\nimport { type Env } from 'hono';\nimport type { CryptoKey, JWK } from 'jose';\nimport { readFile } from 'node:fs/promises';\nimport { JoseLoader } from '../../jose-loader';\nimport { AbstractJWKSTokenService } from './abstract.service';\n\n/** Signs tokens with a private key loaded from `IJWKSIssuerOptions` and exposes the matching public keys as a JWKS via `getJWKSAsync()`. */\nexport class JWKSIssuerTokenService<E extends Env = Env> extends AbstractJWKSTokenService<E> {\n protected privateKey: TNullable<CryptoKey | Uint8Array> = null;\n protected publicKey: TNullable<CryptoKey | Uint8Array> = null;\n protected jwks: { keys: JWK[] } | null = null;\n\n constructor(\n @inject({ key: AuthenticateBindingKeys.JWKS_ISSUER_OPTIONS })\n protected options: TBindingKeyValue<typeof AuthenticateBindingKeys.JWKS_ISSUER_OPTIONS>,\n ) {\n super({ scope: JWKSIssuerTokenService.name });\n\n this.configureClaims({ options: this.options, pinnedAlgorithms: [this.options.algorithm] });\n this.configurePayloadEncryption({\n aesAlgorithm: this.options.aesAlgorithm,\n applicationSecret: this.options.applicationSecret,\n fieldCodecs: this.options.fieldCodecs,\n });\n }\n\n protected override async initialize(): Promise<void> {\n const { keys, algorithm } = this.options;\n\n const raw = await this.resolveKeyContent({ keys });\n const built = await this.parseKeyMaterial({ raw, algorithm, keys });\n\n this.privateKey = built.priv;\n this.publicKey = built.pub;\n\n const { exportJWK } = await JoseLoader.load();\n const publicJWK = await exportJWK(this.publicKey!);\n\n // Belt and braces. `assertPublicJWK` already refused a private JWK on the way IN, but this is\n // the exact object an unauthenticated `/certs` serves - the last place to notice a signing key\n // about to be published, whatever route the material took to get here.\n this.assertPublicJWK({ jwk: publicJWK });\n\n publicJWK.kid = this.options.kid;\n publicJWK.alg = algorithm;\n publicJWK.use = 'sig';\n\n this.jwks = { keys: [publicJWK] };\n\n this.initialized = true;\n\n this.logger\n .for(this.initialize.name)\n .info(\n 'JWKS issuer initialized | driver: %s | format: %s | kid: %s',\n keys.driver,\n keys.format,\n this.options.kid,\n );\n }\n\n protected async resolveKeyContent(opts: { keys: IJWKSIssuerOptions['keys'] }) {\n const { keys } = opts;\n\n switch (keys.driver) {\n case JWKSKeyDrivers.FILE: {\n const [priv, pub] = await Promise.all([\n readFile(keys.private, 'utf-8'),\n readFile(keys.public, 'utf-8'),\n ]);\n\n return { priv, pub };\n }\n case JWKSKeyDrivers.TEXT: {\n return {\n priv: keys.private,\n pub: keys.public,\n };\n }\n default: {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[JWKSIssuerTokenService] Unknown key driver: ${keys.driver}`,\n });\n }\n }\n }\n\n /**\n * Refuses a JWK carrying private material where a PUBLIC key is expected.\n *\n * The `pem` format cannot reach this state - `importSPKI` rejects a private PEM outright. The\n * `jwk` format can: `importJWK` imports whatever it is handed, and a private JWK marked\n * `\"ext\": true` yields an EXTRACTABLE key, so `exportJWK` then carries `d` straight into the\n * document `/certs` serves without authentication. Measured on jose 6.2.3: with `ext: true` the\n * round trip returns `d`; without it, export throws. So the only thing standing between a\n * mis-pasted key and a published signing key was an optional flag on attacker-irrelevant input.\n *\n * Named members, not a blanket scan: `d` covers EC/OKP and RSA's private exponent, and the CRT\n * members are the rest of an RSA private key.\n */\n protected assertPublicJWK(opts: { jwk: JWK }): void {\n const PRIVATE_MEMBERS = ['d', 'p', 'q', 'dp', 'dq', 'qi', 'k'] as const;\n\n const present = PRIVATE_MEMBERS.filter((member) => opts.jwk[member] !== undefined);\n\n if (present.length === 0) {\n return;\n }\n\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[JWKSIssuerTokenService] The public key material carries PRIVATE members (${present.join(', ')}) | this key would be published at the JWKS endpoint | pass the public half in keys.public`,\n });\n }\n\n protected async parseKeyMaterial(opts: {\n raw: { priv: string; pub: string };\n algorithm: IJWKSIssuerOptions['algorithm'];\n keys: IJWKSIssuerOptions['keys'];\n }) {\n const { raw, algorithm, keys } = opts;\n\n if (!raw.priv) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: '[JWKSIssuerTokenService] Invalid raw.priv key!',\n });\n }\n\n if (!raw.pub) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: '[JWKSIssuerTokenService] Invalid raw.pub key!',\n });\n }\n\n const { importJWK, importPKCS8, importSPKI } = await JoseLoader.load();\n\n switch (keys.format) {\n case JWKSKeyFormats.PEM: {\n const priv = await importPKCS8(raw.priv, algorithm);\n const pub = await importSPKI(raw.pub, algorithm);\n\n return { priv, pub };\n }\n case JWKSKeyFormats.JWK: {\n try {\n const parsed = {\n priv: JSON.parse(raw.priv) as JWK,\n pub: JSON.parse(raw.pub) as JWK,\n };\n\n this.assertPublicJWK({ jwk: parsed.pub });\n\n const priv = await importJWK(parsed.priv, algorithm);\n const pub = await importJWK(parsed.pub, algorithm);\n\n return { priv, pub };\n } catch (error) {\n this.logger\n .for(this.parseKeyMaterial.name)\n .error('Invalid JWK key material | Error: %s', error);\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: '[JWKSIssuerTokenService] Invalid JWK key material',\n });\n }\n }\n default: {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[JWKSIssuerTokenService] Unknown key format: ${keys.format}`,\n });\n }\n }\n }\n\n protected override async doVerify(token: string): Promise<IJWTTokenPayload> {\n await this.ensureInitialized();\n const { jwtVerify } = await JoseLoader.load();\n const result = await jwtVerify<IJWTTokenPayload>(token, this.publicKey!, this.verifyOptions!);\n\n return this.decryptPayload({ result });\n }\n\n override async getSigner(opts: {\n payload: IJWTTokenPayload;\n getTokenExpiresFn: TGetTokenExpiresFn;\n claims?: IJWTIssueClaims;\n }) {\n await this.ensureInitialized();\n const { SignJWT } = await JoseLoader.load();\n\n const now = Math.floor(Date.now() / 1000);\n const expiresIn = await opts.getTokenExpiresFn();\n\n const encryptedPayload = await this.encryptPayload(opts.payload);\n\n const signer = new SignJWT({ ...encryptedPayload })\n .setProtectedHeader({ alg: this.options.algorithm, kid: this.options.kid })\n .setIssuedAt()\n .setExpirationTime(now + expiresIn)\n .setNotBefore(now);\n\n return this.applySignClaims({ signer, payload: encryptedPayload, claims: opts.claims });\n }\n\n protected override getSigningKey(): ValueOrPromise<Uint8Array | CryptoKey> {\n if (!this.privateKey) {\n throw getError({ message: '[getSigningKey] Invalid privateKey!' });\n }\n\n return this.privateKey;\n }\n\n protected override getDefaultTokenExpiresFn(): TGetTokenExpiresFn {\n return this.options.getTokenExpiresFn;\n }\n\n getJWKS(): { keys: JWK[] } {\n if (!this.jwks) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: '[JWKSIssuerTokenService] JWKS not initialized yet. Call getJWKSAsync() instead.',\n });\n }\n\n return this.jwks;\n }\n\n async getJWKSAsync(): Promise<{ keys: JWK[] }> {\n await this.ensureInitialized();\n\n return this.jwks!;\n }\n}\n"]}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { AuthenticateBindingKeys, type IJWTTokenPayload, type TBindingKeyValue, type TGetTokenExpiresFn } from '@venizia/ignis-kernel';
|
|
2
2
|
import { type Env } from 'hono';
|
|
3
3
|
import type { createRemoteJWKSet, SignJWT } from 'jose';
|
|
4
4
|
import { AbstractJWKSTokenService } from './abstract.service.js';
|
|
5
5
|
/** Verifies tokens against a remote JWKS fetched from `jwksUrl`. The key set is cached for `cacheTtlMs` (default 43_200_000 ms) with a `cooldownMs` refetch cooldown (default 30_000 ms). */
|
|
6
6
|
export declare class JWKSVerifierTokenService<E extends Env = Env> extends AbstractJWKSTokenService<E> {
|
|
7
|
-
protected options:
|
|
7
|
+
protected options: TBindingKeyValue<typeof AuthenticateBindingKeys.JWKS_VERIFIER_OPTIONS>;
|
|
8
8
|
protected jwksVerifier: ReturnType<typeof createRemoteJWKSet> | null;
|
|
9
|
-
constructor(options:
|
|
9
|
+
constructor(options: TBindingKeyValue<typeof AuthenticateBindingKeys.JWKS_VERIFIER_OPTIONS>);
|
|
10
10
|
protected initialize(): Promise<void>;
|
|
11
11
|
protected doVerify(token: string): Promise<IJWTTokenPayload>;
|
|
12
12
|
getSigner(_opts: {
|
|
@@ -36,7 +36,7 @@ let JWKSVerifierTokenService = JWKSVerifierTokenService_1 = class JWKSVerifierTo
|
|
|
36
36
|
scope: JWKSVerifierTokenService_1.name,
|
|
37
37
|
label: 'jwksUrl',
|
|
38
38
|
url: this.options.jwksUrl,
|
|
39
|
-
|
|
39
|
+
trusted: this.options.jwks?.trusted,
|
|
40
40
|
});
|
|
41
41
|
this.jwksVerifier = createRemoteJWKSet(jwksUrl, {
|
|
42
42
|
cacheMaxAge: this.options.cacheTtlMs ?? 43_200_000,
|
|
@@ -73,7 +73,7 @@ let JWKSVerifierTokenService = JWKSVerifierTokenService_1 = class JWKSVerifierTo
|
|
|
73
73
|
}
|
|
74
74
|
};
|
|
75
75
|
JWKSVerifierTokenService = JWKSVerifierTokenService_1 = __decorate([
|
|
76
|
-
__param(0, inject({ key: AuthenticateBindingKeys.
|
|
76
|
+
__param(0, inject({ key: AuthenticateBindingKeys.JWKS_VERIFIER_OPTIONS })),
|
|
77
77
|
__metadata("design:paramtypes", [Object])
|
|
78
78
|
], JWKSVerifierTokenService);
|
|
79
79
|
export { JWKSVerifierTokenService };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verifier.service.js","sourceRoot":"","sources":["../../../../../../../../src/components/auth/authenticate/services/bearer/jwks/verifier.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EACL,uBAAuB,
|
|
1
|
+
{"version":3,"file":"verifier.service.js","sourceRoot":"","sources":["../../../../../../../../src/components/auth/authenticate/services/bearer/jwks/verifier.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EACL,uBAAuB,EAEvB,MAAM,G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Error } from '@venizia/ignis-helpers/core';\nimport {\n AuthenticateBindingKeys,\n type IJWTTokenPayload,\n inject,\n type TBindingKeyValue,\n type TGetTokenExpiresFn,\n} from '@venizia/ignis-kernel';\nimport { type Env } from 'hono';\nimport type { createRemoteJWKSet, SignJWT } from 'jose';\nimport { JoseLoader } from '../../jose-loader';\nimport { JWKSUrlPolicy } from '../../jwks-url-policy';\nimport { AbstractJWKSTokenService } from './abstract.service';\n\n/** Verifies tokens against a remote JWKS fetched from `jwksUrl`. The key set is cached for `cacheTtlMs` (default 43_200_000 ms) with a `cooldownMs` refetch cooldown (default 30_000 ms). */\nexport class JWKSVerifierTokenService<E extends Env = Env> extends AbstractJWKSTokenService<E> {\n protected jwksVerifier: ReturnType<typeof createRemoteJWKSet> | null = null;\n\n constructor(\n @inject({ key: AuthenticateBindingKeys.JWKS_VERIFIER_OPTIONS })\n protected options: TBindingKeyValue<typeof AuthenticateBindingKeys.JWKS_VERIFIER_OPTIONS>,\n ) {\n super({ scope: JWKSVerifierTokenService.name });\n this.configureClaims({ options: this.options });\n this.configurePayloadEncryption({\n aesAlgorithm: this.options.aesAlgorithm,\n applicationSecret: this.options.applicationSecret,\n fieldCodecs: this.options.fieldCodecs,\n });\n }\n\n protected override async initialize(): Promise<void> {\n const { createRemoteJWKSet } = await JoseLoader.load();\n const jwksUrl = JWKSUrlPolicy.assertUrl({\n scope: JWKSVerifierTokenService.name,\n label: 'jwksUrl',\n url: this.options.jwksUrl,\n trusted: this.options.jwks?.trusted,\n });\n this.jwksVerifier = createRemoteJWKSet(jwksUrl, {\n cacheMaxAge: this.options.cacheTtlMs ?? 43_200_000,\n cooldownDuration: this.options.cooldownMs ?? 30_000,\n });\n\n this.initialized = true;\n\n this.logger\n .for(this.initialize.name)\n .info('JWKS verifier initialized | origin: %s', jwksUrl.origin);\n }\n\n protected override async doVerify(token: string): Promise<IJWTTokenPayload> {\n await this.ensureInitialized();\n const { jwtVerify } = await JoseLoader.load();\n const result = await jwtVerify<IJWTTokenPayload>(\n token,\n this.jwksVerifier!,\n this.verifyOptions!,\n );\n\n return this.decryptPayload({ result });\n }\n\n override async getSigner(_opts: {\n payload: IJWTTokenPayload;\n getTokenExpiresFn: TGetTokenExpiresFn;\n }): Promise<SignJWT> {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: '[JWKSVerifierTokenService] Verifier mode cannot sign tokens',\n });\n }\n\n protected override getSigningKey(): never {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: '[JWKSVerifierTokenService] Verifier mode cannot sign tokens',\n });\n }\n\n protected override getDefaultTokenExpiresFn(): never {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: '[JWKSVerifierTokenService] Verifier mode has no token expiry',\n });\n }\n}\n"]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { type ValueOrPromise } from '@venizia/ignis-helpers/common';
|
|
2
|
-
import {
|
|
2
|
+
import { AuthenticateBindingKeys, type IJWTIssueClaims, type IJWTTokenPayload, type TBindingKeyValue, type TGetTokenExpiresFn } from '@venizia/ignis-kernel';
|
|
3
3
|
import { type Env } from 'hono';
|
|
4
4
|
import { AbstractBearerTokenService } from './abstract.service.js';
|
|
5
5
|
/** Symmetric JWT (JWS) token service with optional AES-encrypted payloads. */
|
|
6
6
|
export declare class JWSTokenService<E extends Env = Env> extends AbstractBearerTokenService<E> {
|
|
7
|
-
protected options:
|
|
7
|
+
protected options: TBindingKeyValue<typeof AuthenticateBindingKeys.JWS_OPTIONS>;
|
|
8
8
|
/** The shortest `jwtSecret` accepted, in bytes: an HMAC key is as strong as it is long, and 32 bytes is the size of a SHA-256 output. */
|
|
9
9
|
static readonly MIN_SECRET_BYTES = 32;
|
|
10
10
|
protected jwtSecret: Uint8Array;
|
|
@@ -17,7 +17,7 @@ export declare class JWSTokenService<E extends Env = Env> extends AbstractBearer
|
|
|
17
17
|
scope: string;
|
|
18
18
|
secret: string;
|
|
19
19
|
}): void;
|
|
20
|
-
constructor(options:
|
|
20
|
+
constructor(options: TBindingKeyValue<typeof AuthenticateBindingKeys.JWS_OPTIONS>);
|
|
21
21
|
protected doVerify(token: string): Promise<IJWTTokenPayload>;
|
|
22
22
|
getSigner(opts: {
|
|
23
23
|
payload: IJWTTokenPayload;
|
|
@@ -92,7 +92,7 @@ let JWSTokenService = class JWSTokenService extends AbstractBearerTokenService {
|
|
|
92
92
|
}
|
|
93
93
|
};
|
|
94
94
|
JWSTokenService = JWSTokenService_1 = __decorate([
|
|
95
|
-
__param(0, inject({ key: AuthenticateBindingKeys.
|
|
95
|
+
__param(0, inject({ key: AuthenticateBindingKeys.JWS_OPTIONS })),
|
|
96
96
|
__metadata("design:paramtypes", [Object])
|
|
97
97
|
], JWSTokenService);
|
|
98
98
|
export { JWSTokenService };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jws.service.js","sourceRoot":"","sources":["../../../../../../../src/components/auth/authenticate/services/bearer/jws.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,EAAE,IAAI,EAAuB,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EACL,uBAAuB,
|
|
1
|
+
{"version":3,"file":"jws.service.js","sourceRoot":"","sources":["../../../../../../../src/components/auth/authenticate/services/bearer/jws.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,EAAE,IAAI,EAAuB,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EACL,uBAAuB,EAGvB,MAAM,GAGP,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,0BAA0B,EAAE,MAAM,oBAAoB,CAAC;AAEhE,8EAA8E;AAC9E,IAAa,eAAe,GAA5B,MAAa,eAAqC,SAAQ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CAAC,GAAG,GAAG,SAAS,CAAC;aAClC,YAAY,CAAC,GAAG,CAAC,CAAC;QAErB,OAAO,IAAI,CAAC,eAAe,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IAC1F,CAAC;IAEkB,aAAa;QAC9B,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YACpB,MAAM,QAAQ,CAAC,EAAE,OAAO,EAAE,oCAAoC,EAAE,CAAC,CAAC;QACpE,CAAC;QAED,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAEkB,wBAAwB;QACzC,OAAO,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC;IACxC,CAAC;;AArGU,eAAe;IAyBvB,WAAA,MAAM,CAAC,EAAE,GAAG,EAAE,uBAAuB,CAAC,WAAW,EAAE,CAAC,CAAA;;GAzB5C,eAAe,CAsG3B","sourcesContent":["import { HTTP, type ValueOrPromise } from '@venizia/ignis-helpers/common';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport {\n AuthenticateBindingKeys,\n type IJWTIssueClaims,\n type IJWTTokenPayload,\n inject,\n type TBindingKeyValue,\n type TGetTokenExpiresFn,\n} from '@venizia/ignis-kernel';\nimport { type Env } from 'hono';\nimport { JoseLoader } from '../jose-loader';\nimport { AbstractBearerTokenService } from './abstract.service';\n\n/** Symmetric JWT (JWS) token service with optional AES-encrypted payloads. */\nexport class JWSTokenService<E extends Env = Env> extends AbstractBearerTokenService<E> {\n /** The shortest `jwtSecret` accepted, in bytes: an HMAC key is as strong as it is long, and 32 bytes is the size of a SHA-256 output. */\n static readonly MIN_SECRET_BYTES = 32;\n\n protected jwtSecret: Uint8Array;\n\n /**\n * Refuses a `jwtSecret` shorter than {@link JWSTokenService.MIN_SECRET_BYTES} (counted in UTF-8 bytes, not\n * characters), saying how to make one. The secret is never echoed. The component calls it at boot and the\n * service when it is built.\n */\n static assertSecretStrength(opts: { scope: string; secret: string }): void {\n const bytes = new TextEncoder().encode(opts.secret).length;\n\n if (bytes >= JWSTokenService.MIN_SECRET_BYTES) {\n return;\n }\n\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${opts.scope}] jwtSecret is too short: ${bytes} bytes, at least ${JWSTokenService.MIN_SECRET_BYTES} are required | Generate one with: openssl rand -base64 48`,\n });\n }\n\n constructor(\n @inject({ key: AuthenticateBindingKeys.JWS_OPTIONS })\n protected options: TBindingKeyValue<typeof AuthenticateBindingKeys.JWS_OPTIONS>,\n ) {\n super({ scope: JWSTokenService.name });\n\n const { aesAlgorithm, jwtSecret, applicationSecret, getTokenExpiresFn } = options ?? {};\n\n if (!jwtSecret) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: '[JWSTokenService] Invalid jwtSecret',\n });\n }\n\n if (!getTokenExpiresFn) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: '[JWSTokenService] Invalid getTokenExpiresFn',\n });\n }\n\n this.configureClaims({\n options,\n pinnedAlgorithms: [options.headerAlgorithm ?? 'HS256'],\n });\n JWSTokenService.assertSecretStrength({ scope: JWSTokenService.name, secret: jwtSecret });\n\n this.configurePayloadEncryption({\n aesAlgorithm,\n applicationSecret,\n fieldCodecs: options.fieldCodecs,\n });\n this.jwtSecret = new TextEncoder().encode(this.options.jwtSecret);\n }\n\n protected override async doVerify(token: string): Promise<IJWTTokenPayload> {\n const { jwtVerify } = await JoseLoader.load();\n const decodedToken = await jwtVerify<IJWTTokenPayload>(\n token,\n this.jwtSecret,\n this.verifyOptions!,\n );\n\n return this.decryptPayload({ result: decodedToken });\n }\n\n override async getSigner(opts: {\n payload: IJWTTokenPayload;\n getTokenExpiresFn: TGetTokenExpiresFn;\n claims?: IJWTIssueClaims;\n }) {\n const { SignJWT } = await JoseLoader.load();\n const now = Math.floor(Date.now() / 1000);\n const expiresIn = await opts.getTokenExpiresFn();\n\n const encryptedPayload = await this.encryptPayload(opts.payload);\n\n const signer = new SignJWT(Object.assign({}, encryptedPayload))\n .setProtectedHeader({ alg: this.options.headerAlgorithm ?? 'HS256' })\n .setIssuedAt()\n .setExpirationTime(now + expiresIn)\n .setNotBefore(now);\n\n return this.applySignClaims({ signer, payload: encryptedPayload, claims: opts.claims });\n }\n\n protected override getSigningKey(): ValueOrPromise<Uint8Array> {\n if (!this.jwtSecret) {\n throw getError({ message: '[getSigningKey] Invalid jwtSecret!' });\n }\n\n return this.jwtSecret;\n }\n\n protected override getDefaultTokenExpiresFn(): TGetTokenExpiresFn {\n return this.options.getTokenExpiresFn;\n }\n}\n"]}
|
|
@@ -1,42 +1,30 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Where a JWKS may be fetched from. A key set read over plain `http:` can be replaced on the way, and
|
|
3
3
|
* whoever replaces it signs tokens that verify, so a JWKS URL is `https:` unless its host is loopback or
|
|
4
|
-
* is listed in `jwks.
|
|
4
|
+
* its origin is listed in `jwks.trusted`. The one policy serves the JWKS verifier and the service-assertion
|
|
5
5
|
* callers: both fetch a key set to decide who may call.
|
|
6
6
|
*
|
|
7
|
-
* The opt-in is an EXACT
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* the URL parser, so the two sides are compared in the form the parser gives them: `http://2130706433` is
|
|
11
|
-
* `127.0.0.1`, and `http://[::ffff:10.0.0.5]` is `[::ffff:a00:5]`, which is not `10.0.0.5`.
|
|
7
|
+
* The opt-in is an EXACT origin, never a pattern or a range, in the form the URL parser writes it
|
|
8
|
+
* (`http://identity-service`, `http://10.0.0.5:8080`, `http://[fd00::1]:8443`). The shape check is the url guard's own
|
|
9
|
+
* (`UrlPolicy.resolveTrustedOrigins`), so a JWKS entry and a `policy.hosts.trusted` entry follow one rule.
|
|
12
10
|
*/
|
|
13
11
|
export declare class JWKSUrlPolicy {
|
|
14
|
-
/**
|
|
15
|
-
|
|
16
|
-
* in the form a URL is matched in: the host as the URL parser writes it (lower case), then `:port` when there is one.
|
|
17
|
-
* An entry is valid only when `new URL('http://' + entry)` gives the same host back, and the same port.
|
|
18
|
-
*/
|
|
19
|
-
static resolveHttpHosts(opts: {
|
|
12
|
+
/** Refuses a `jwks.trusted` list that is not exactly a list of origins, and answers the origins as a set. */
|
|
13
|
+
static resolveTrustedOrigins(opts: {
|
|
20
14
|
scope: string;
|
|
21
|
-
|
|
15
|
+
trusted?: unknown;
|
|
22
16
|
}): ReadonlySet<string>;
|
|
23
|
-
/** The canonical form of one entry, or `undefined` when it is not exactly a host with an optional port. */
|
|
24
|
-
private static canonicalEntry;
|
|
25
|
-
/** Whether a name is within the DNS limits: 253 characters, and 63 for each label. */
|
|
26
|
-
private static isWithinLimits;
|
|
27
|
-
/** `http://<authority>` through the URL parser, or `undefined` when it refuses it. */
|
|
28
|
-
private static parseHttp;
|
|
29
17
|
/** Whether the URL parser's hostname is a loopback one: `localhost`, `127.0.0.0/8` or `::1`. */
|
|
30
18
|
static isLoopback(hostname: string): boolean;
|
|
31
19
|
/**
|
|
32
|
-
* Parses a JWKS URL and refuses it unless it is `https:`, or `http:` to a loopback host or
|
|
33
|
-
* `jwks.
|
|
20
|
+
* Parses a JWKS URL and refuses it unless it is `https:`, or `http:` to a loopback host or an origin listed in
|
|
21
|
+
* `jwks.trusted`. Only the host name goes into the message: a URL may carry credentials.
|
|
34
22
|
*/
|
|
35
23
|
static assertUrl(opts: {
|
|
36
24
|
scope: string;
|
|
37
25
|
label: string;
|
|
38
26
|
url: string;
|
|
39
|
-
|
|
27
|
+
trusted?: unknown;
|
|
40
28
|
}): URL;
|
|
41
29
|
}
|
|
42
30
|
//# sourceMappingURL=jwks-url-policy.d.ts.map
|
|
@@ -1,120 +1,27 @@
|
|
|
1
1
|
import { HTTP } from '@venizia/ignis-helpers/common';
|
|
2
|
-
import { getError } from '@venizia/ignis-helpers/core';
|
|
3
|
-
/** One host name: labels of letters, digits and hyphens joined by single dots - no empty label, no wildcard. */
|
|
4
|
-
const HOST_NAME_PATTERN = /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)*$/;
|
|
5
|
-
/** An IPv4 address, in any spelling a caller might write; the URL parser decides whether it is the address it looks like. */
|
|
6
|
-
const IPV4_PATTERN = /^\d{1,3}(?:\.\d{1,3}){3}$/;
|
|
7
|
-
/**
|
|
8
|
-
* An entry of `jwks.hosts.http`: a host (a name, an IPv4 address, or an IPv6 address in brackets) and an optional
|
|
9
|
-
* `:port`. Nothing else: no scheme, path, userinfo or wildcard.
|
|
10
|
-
*/
|
|
11
|
-
const ENTRY_PATTERN = /^(?<host>\[[0-9a-f:.]+\]|[a-z0-9][a-z0-9.-]*)(?::(?<port>[0-9]{1,5}))?$/;
|
|
12
|
-
/** The port of an `http:` URL that names none. */
|
|
13
|
-
const DEFAULT_HTTP_PORT = '80';
|
|
14
|
-
/** The longest label and the longest name DNS has (RFC 1035): a longer entry is not a host name. */
|
|
15
|
-
const MAX_LABEL_LENGTH = 63;
|
|
16
|
-
const MAX_NAME_LENGTH = 253;
|
|
17
|
-
/** The addresses that mean "any local address", not a host: as the URL parser writes them. */
|
|
18
|
-
const UNSPECIFIED_HOSTS = new Set(['0.0.0.0', '[::]']);
|
|
19
|
-
/** `127.0.0.0/8`, as the URL parser writes an IPv4 host. */
|
|
20
|
-
const LOOPBACK_IPV4_PATTERN = /^127(?:\.\d{1,3}){3}$/;
|
|
21
|
-
const LOOPBACK_HOSTS = new Set(['localhost', '[::1]']);
|
|
2
|
+
import { getError, UrlPolicy } from '@venizia/ignis-helpers/core';
|
|
22
3
|
/**
|
|
23
4
|
* Where a JWKS may be fetched from. A key set read over plain `http:` can be replaced on the way, and
|
|
24
5
|
* whoever replaces it signs tokens that verify, so a JWKS URL is `https:` unless its host is loopback or
|
|
25
|
-
* is listed in `jwks.
|
|
6
|
+
* its origin is listed in `jwks.trusted`. The one policy serves the JWKS verifier and the service-assertion
|
|
26
7
|
* callers: both fetch a key set to decide who may call.
|
|
27
8
|
*
|
|
28
|
-
* The opt-in is an EXACT
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* the URL parser, so the two sides are compared in the form the parser gives them: `http://2130706433` is
|
|
32
|
-
* `127.0.0.1`, and `http://[::ffff:10.0.0.5]` is `[::ffff:a00:5]`, which is not `10.0.0.5`.
|
|
9
|
+
* The opt-in is an EXACT origin, never a pattern or a range, in the form the URL parser writes it
|
|
10
|
+
* (`http://identity-service`, `http://10.0.0.5:8080`, `http://[fd00::1]:8443`). The shape check is the url guard's own
|
|
11
|
+
* (`UrlPolicy.resolveTrustedOrigins`), so a JWKS entry and a `policy.hosts.trusted` entry follow one rule.
|
|
33
12
|
*/
|
|
34
13
|
export class JWKSUrlPolicy {
|
|
35
|
-
/**
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
* An entry is valid only when `new URL('http://' + entry)` gives the same host back, and the same port.
|
|
39
|
-
*/
|
|
40
|
-
static resolveHttpHosts(opts) {
|
|
41
|
-
const { scope, hosts } = opts;
|
|
42
|
-
if (hosts === undefined) {
|
|
43
|
-
return new Set();
|
|
44
|
-
}
|
|
45
|
-
if (!Array.isArray(hosts)) {
|
|
46
|
-
throw getError({
|
|
47
|
-
statusCode: HTTP.ResultCodes.RS_5.InternalServerError,
|
|
48
|
-
message: `[${scope}] jwks.hosts.http must be a list of hosts`,
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
const resolved = new Set();
|
|
52
|
-
for (const entry of hosts) {
|
|
53
|
-
const canonical = typeof entry === 'string' ? JWKSUrlPolicy.canonicalEntry({ entry }) : undefined;
|
|
54
|
-
if (canonical === undefined) {
|
|
55
|
-
throw getError({
|
|
56
|
-
statusCode: HTTP.ResultCodes.RS_5.InternalServerError,
|
|
57
|
-
message: `[${scope}] jwks.hosts.http holds ${JSON.stringify(entry)} | list exact hosts only: a name, an IPv4 address or an IPv6 address in brackets, with an optional :port, for example 'identity-service', '10.0.0.5:8080' or '[fd00::1]:8443' - no scheme, path, credentials, wildcard or range`,
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
resolved.add(canonical);
|
|
61
|
-
}
|
|
62
|
-
return resolved;
|
|
63
|
-
}
|
|
64
|
-
/** The canonical form of one entry, or `undefined` when it is not exactly a host with an optional port. */
|
|
65
|
-
static canonicalEntry(opts) {
|
|
66
|
-
// Not trimmed: an entry with a space, a tab or a newline around it is a typo, and is refused rather than corrected.
|
|
67
|
-
const matched = ENTRY_PATTERN.exec(opts.entry.toLowerCase());
|
|
68
|
-
const { host, port } = matched?.groups ?? {};
|
|
69
|
-
if (host === undefined) {
|
|
70
|
-
return undefined;
|
|
71
|
-
}
|
|
72
|
-
// A name has labels of its own shape; an IPv4 or an IPv6 address is judged by the parser alone, below.
|
|
73
|
-
const isAddress = host.startsWith('[') || IPV4_PATTERN.test(host);
|
|
74
|
-
if (!isAddress &&
|
|
75
|
-
!(HOST_NAME_PATTERN.test(host) && JWKSUrlPolicy.isWithinLimits({ name: host }))) {
|
|
76
|
-
return undefined;
|
|
77
|
-
}
|
|
78
|
-
const parsed = JWKSUrlPolicy.parseHttp({
|
|
79
|
-
authority: port === undefined ? host : `${host}:${port}`,
|
|
80
|
-
});
|
|
81
|
-
// The host must be what the parser makes of it: `2130706433`, `0x7f000001`, `1.2.3`, `010.0.0.5` and
|
|
82
|
-
// `[::ffff:10.0.0.5]` are spellings the parser rewrites, so none of them is the host it looks like.
|
|
83
|
-
if (parsed === undefined || parsed.hostname !== host || UNSPECIFIED_HOSTS.has(host)) {
|
|
84
|
-
return undefined;
|
|
85
|
-
}
|
|
86
|
-
if (port === undefined) {
|
|
87
|
-
return host;
|
|
88
|
-
}
|
|
89
|
-
// The parser drops the default port, so `:80` reads back as no port; a port is valid only as the parser keeps it.
|
|
90
|
-
const kept = parsed.port === '' ? DEFAULT_HTTP_PORT : parsed.port;
|
|
91
|
-
if (kept !== port || Number(port) < 1) {
|
|
92
|
-
return undefined;
|
|
93
|
-
}
|
|
94
|
-
return `${host}:${port}`;
|
|
95
|
-
}
|
|
96
|
-
/** Whether a name is within the DNS limits: 253 characters, and 63 for each label. */
|
|
97
|
-
static isWithinLimits(opts) {
|
|
98
|
-
return (opts.name.length <= MAX_NAME_LENGTH &&
|
|
99
|
-
opts.name.split('.').every((label) => label.length <= MAX_LABEL_LENGTH));
|
|
100
|
-
}
|
|
101
|
-
/** `http://<authority>` through the URL parser, or `undefined` when it refuses it. */
|
|
102
|
-
static parseHttp(opts) {
|
|
103
|
-
try {
|
|
104
|
-
return new URL(`http://${opts.authority}`);
|
|
105
|
-
// eslint-disable-next-line venizia/no-silent-catch -- an authority the parser refuses is not a host: the caller refuses the entry
|
|
106
|
-
}
|
|
107
|
-
catch {
|
|
108
|
-
return undefined;
|
|
109
|
-
}
|
|
14
|
+
/** Refuses a `jwks.trusted` list that is not exactly a list of origins, and answers the origins as a set. */
|
|
15
|
+
static resolveTrustedOrigins(opts) {
|
|
16
|
+
return UrlPolicy.resolveTrustedOrigins({ ...opts, label: 'jwks.trusted' });
|
|
110
17
|
}
|
|
111
18
|
/** Whether the URL parser's hostname is a loopback one: `localhost`, `127.0.0.0/8` or `::1`. */
|
|
112
19
|
static isLoopback(hostname) {
|
|
113
|
-
return
|
|
20
|
+
return UrlPolicy.isLoopbackHost({ hostname });
|
|
114
21
|
}
|
|
115
22
|
/**
|
|
116
|
-
* Parses a JWKS URL and refuses it unless it is `https:`, or `http:` to a loopback host or
|
|
117
|
-
* `jwks.
|
|
23
|
+
* Parses a JWKS URL and refuses it unless it is `https:`, or `http:` to a loopback host or an origin listed in
|
|
24
|
+
* `jwks.trusted`. Only the host name goes into the message: a URL may carry credentials.
|
|
118
25
|
*/
|
|
119
26
|
static assertUrl(opts) {
|
|
120
27
|
const { scope, label, url } = opts;
|
|
@@ -129,6 +36,8 @@ export class JWKSUrlPolicy {
|
|
|
129
36
|
message: `[${scope}] ${label} is not a valid URL`,
|
|
130
37
|
});
|
|
131
38
|
}
|
|
39
|
+
// Before the https early return: a bad `jwks.trusted` refuses the boot whatever the URL is.
|
|
40
|
+
const trusted = JWKSUrlPolicy.resolveTrustedOrigins({ scope, trusted: opts.trusted });
|
|
132
41
|
if (parsed.protocol === 'https:') {
|
|
133
42
|
return parsed;
|
|
134
43
|
}
|
|
@@ -138,24 +47,19 @@ export class JWKSUrlPolicy {
|
|
|
138
47
|
message: `[${scope}] ${label} must use https | scheme: ${parsed.protocol}`,
|
|
139
48
|
});
|
|
140
49
|
}
|
|
141
|
-
|
|
142
|
-
// Nothing listens on port 0: a URL that names it is a mistake, and no entry without a port should cover it.
|
|
50
|
+
// Nothing listens on port 0: a URL that names it is a mistake, and no origin should cover it.
|
|
143
51
|
if (parsed.port === '0') {
|
|
144
52
|
throw getError({
|
|
145
53
|
statusCode: HTTP.ResultCodes.RS_5.InternalServerError,
|
|
146
54
|
message: `[${scope}] ${label} uses port 0 | the host is '${parsed.hostname}'`,
|
|
147
55
|
});
|
|
148
56
|
}
|
|
149
|
-
|
|
150
|
-
const port = parsed.port === '' ? DEFAULT_HTTP_PORT : parsed.port;
|
|
151
|
-
if (JWKSUrlPolicy.isLoopback(parsed.hostname) ||
|
|
152
|
-
allowed.has(parsed.hostname) ||
|
|
153
|
-
allowed.has(`${parsed.hostname}:${port}`)) {
|
|
57
|
+
if (JWKSUrlPolicy.isLoopback(parsed.hostname) || trusted.has(parsed.origin)) {
|
|
154
58
|
return parsed;
|
|
155
59
|
}
|
|
156
60
|
throw getError({
|
|
157
61
|
statusCode: HTTP.ResultCodes.RS_5.InternalServerError,
|
|
158
|
-
message: `[${scope}] ${label} uses http: and the
|
|
62
|
+
message: `[${scope}] ${label} uses http: and the origin '${parsed.origin}' is not trusted | use https, or list the origin in jwks.trusted`,
|
|
159
63
|
});
|
|
160
64
|
}
|
|
161
65
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jwks-url-policy.js","sourceRoot":"","sources":["../../../../../../src/components/auth/authenticate/services/jwks-url-policy.ts"],"names":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GAAG;aAC9E,CAAC,CAAC;QACL,CAAC;QAED,wHAAwH;QACxH,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC;QAElE,IACE,aAAa,CAAC,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC;YACzC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC;YAC5B,OAAO,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,QAAQ,IAAI,IAAI,EAAE,CAAC,EACzC,CAAC;YACD,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,MAAM,QAAQ,CAAC;YACb,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,mBAAmB;YACrD,OAAO,EAAE,IAAI,KAAK,KAAK,KAAK,6BAA6B,MAAM,CAAC,QAAQ,mEAAmE;SAC5I,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { HTTP } from '@venizia/ignis-helpers/common';\nimport { getError } from '@venizia/ignis-helpers/core';\n\n/** One host name: labels of letters, digits and hyphens joined by single dots - no empty label, no wildcard. */\nconst HOST_NAME_PATTERN = /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?(?:\\.[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)*$/;\n\n/** An IPv4 address, in any spelling a caller might write; the URL parser decides whether it is the address it looks like. */\nconst IPV4_PATTERN = /^\\d{1,3}(?:\\.\\d{1,3}){3}$/;\n\n/**\n * An entry of `jwks.hosts.http`: a host (a name, an IPv4 address, or an IPv6 address in brackets) and an optional\n * `:port`. Nothing else: no scheme, path, userinfo or wildcard.\n */\nconst ENTRY_PATTERN = /^(?<host>\\[[0-9a-f:.]+\\]|[a-z0-9][a-z0-9.-]*)(?::(?<port>[0-9]{1,5}))?$/;\n\n/** The port of an `http:` URL that names none. */\nconst DEFAULT_HTTP_PORT = '80';\n\n/** The longest label and the longest name DNS has (RFC 1035): a longer entry is not a host name. */\nconst MAX_LABEL_LENGTH = 63;\nconst MAX_NAME_LENGTH = 253;\n\n/** The addresses that mean \"any local address\", not a host: as the URL parser writes them. */\nconst UNSPECIFIED_HOSTS: ReadonlySet<string> = new Set(['0.0.0.0', '[::]']);\n\n/** `127.0.0.0/8`, as the URL parser writes an IPv4 host. */\nconst LOOPBACK_IPV4_PATTERN = /^127(?:\\.\\d{1,3}){3}$/;\n\nconst LOOPBACK_HOSTS: ReadonlySet<string> = new Set(['localhost', '[::1]']);\n\n/**\n * Where a JWKS may be fetched from. A key set read over plain `http:` can be replaced on the way, and\n * whoever replaces it signs tokens that verify, so a JWKS URL is `https:` unless its host is loopback or\n * is listed in `jwks.hosts.http`. The one policy serves the JWKS verifier and the service-assertion\n * callers: both fetch a key set to decide who may call.\n *\n * The opt-in is an EXACT entry, never a pattern or a range: a host name, an IPv4 address, or an IPv6 address in\n * brackets, each optionally with a port (`identity-service`, `10.0.0.5:8080`, `[fd00::1]:8443`). An entry without a\n * port covers every port of that host; an entry with one covers that port only. An entry and a URL are both read by\n * the URL parser, so the two sides are compared in the form the parser gives them: `http://2130706433` is\n * `127.0.0.1`, and `http://[::ffff:10.0.0.5]` is `[::ffff:a00:5]`, which is not `10.0.0.5`.\n */\nexport class JWKSUrlPolicy {\n /**\n * Refuses an entry of `jwks.hosts.http` that is not exactly a host with an optional port, and answers the entries\n * in the form a URL is matched in: the host as the URL parser writes it (lower case), then `:port` when there is one.\n * An entry is valid only when `new URL('http://' + entry)` gives the same host back, and the same port.\n */\n static resolveHttpHosts(opts: { scope: string; hosts?: unknown }): ReadonlySet<string> {\n const { scope, hosts } = opts;\n\n if (hosts === undefined) {\n return new Set();\n }\n\n if (!Array.isArray(hosts)) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${scope}] jwks.hosts.http must be a list of hosts`,\n });\n }\n\n const resolved = new Set<string>();\n\n for (const entry of hosts) {\n const canonical =\n typeof entry === 'string' ? JWKSUrlPolicy.canonicalEntry({ entry }) : undefined;\n\n if (canonical === undefined) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${scope}] jwks.hosts.http holds ${JSON.stringify(entry)} | list exact hosts only: a name, an IPv4 address or an IPv6 address in brackets, with an optional :port, for example 'identity-service', '10.0.0.5:8080' or '[fd00::1]:8443' - no scheme, path, credentials, wildcard or range`,\n });\n }\n\n resolved.add(canonical);\n }\n\n return resolved;\n }\n\n /** The canonical form of one entry, or `undefined` when it is not exactly a host with an optional port. */\n private static canonicalEntry(opts: { entry: string }): string | undefined {\n // Not trimmed: an entry with a space, a tab or a newline around it is a typo, and is refused rather than corrected.\n const matched = ENTRY_PATTERN.exec(opts.entry.toLowerCase());\n const { host, port } = matched?.groups ?? {};\n\n if (host === undefined) {\n return undefined;\n }\n\n // A name has labels of its own shape; an IPv4 or an IPv6 address is judged by the parser alone, below.\n const isAddress = host.startsWith('[') || IPV4_PATTERN.test(host);\n\n if (\n !isAddress &&\n !(HOST_NAME_PATTERN.test(host) && JWKSUrlPolicy.isWithinLimits({ name: host }))\n ) {\n return undefined;\n }\n\n const parsed = JWKSUrlPolicy.parseHttp({\n authority: port === undefined ? host : `${host}:${port}`,\n });\n\n // The host must be what the parser makes of it: `2130706433`, `0x7f000001`, `1.2.3`, `010.0.0.5` and\n // `[::ffff:10.0.0.5]` are spellings the parser rewrites, so none of them is the host it looks like.\n if (parsed === undefined || parsed.hostname !== host || UNSPECIFIED_HOSTS.has(host)) {\n return undefined;\n }\n\n if (port === undefined) {\n return host;\n }\n\n // The parser drops the default port, so `:80` reads back as no port; a port is valid only as the parser keeps it.\n const kept = parsed.port === '' ? DEFAULT_HTTP_PORT : parsed.port;\n\n if (kept !== port || Number(port) < 1) {\n return undefined;\n }\n\n return `${host}:${port}`;\n }\n\n /** Whether a name is within the DNS limits: 253 characters, and 63 for each label. */\n private static isWithinLimits(opts: { name: string }): boolean {\n return (\n opts.name.length <= MAX_NAME_LENGTH &&\n opts.name.split('.').every((label) => label.length <= MAX_LABEL_LENGTH)\n );\n }\n\n /** `http://<authority>` through the URL parser, or `undefined` when it refuses it. */\n private static parseHttp(opts: { authority: string }): URL | undefined {\n try {\n return new URL(`http://${opts.authority}`);\n // eslint-disable-next-line venizia/no-silent-catch -- an authority the parser refuses is not a host: the caller refuses the entry\n } catch {\n return undefined;\n }\n }\n\n /** Whether the URL parser's hostname is a loopback one: `localhost`, `127.0.0.0/8` or `::1`. */\n static isLoopback(hostname: string): boolean {\n return LOOPBACK_HOSTS.has(hostname) || LOOPBACK_IPV4_PATTERN.test(hostname);\n }\n\n /**\n * Parses a JWKS URL and refuses it unless it is `https:`, or `http:` to a loopback host or a host listed in\n * `jwks.hosts.http`. Only the host name goes into the message: a URL may carry credentials.\n */\n static assertUrl(opts: { scope: string; label: string; url: string; hosts?: unknown }): URL {\n const { scope, label, url } = opts;\n\n let parsed: URL;\n\n try {\n parsed = new URL(url);\n // eslint-disable-next-line venizia/no-silent-catch -- the refusal below names the key and withholds the URL, which may carry credentials\n } catch {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${scope}] ${label} is not a valid URL`,\n });\n }\n\n if (parsed.protocol === 'https:') {\n return parsed;\n }\n\n if (parsed.protocol !== 'http:') {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${scope}] ${label} must use https | scheme: ${parsed.protocol}`,\n });\n }\n\n const allowed = JWKSUrlPolicy.resolveHttpHosts({ scope, hosts: opts.hosts });\n\n // Nothing listens on port 0: a URL that names it is a mistake, and no entry without a port should cover it.\n if (parsed.port === '0') {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${scope}] ${label} uses port 0 | the host is '${parsed.hostname}'`,\n });\n }\n\n // An entry without a port covers every port; one with a port covers that port only (an `http:` URL with none is on 80).\n const port = parsed.port === '' ? DEFAULT_HTTP_PORT : parsed.port;\n\n if (\n JWKSUrlPolicy.isLoopback(parsed.hostname) ||\n allowed.has(parsed.hostname) ||\n allowed.has(`${parsed.hostname}:${port}`)\n ) {\n return parsed;\n }\n\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${scope}] ${label} uses http: and the host '${parsed.hostname}' is not allowed | use https, or list the host in jwks.hosts.http`,\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"jwks-url-policy.js","sourceRoot":"","sources":["../../../../../../src/components/auth/authenticate/services/jwks-url-policy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAElE;;;;;;;;;GASG;AACH,MAAM,OAAO,aAAa;IACxB,6GAA6G;IAC7G,MAAM,CAAC,qBAAqB,CAAC,IAA0C;QACrE,OAAO,SAAS,CAAC,qBAAqB,CAAC,EAAE,GAAG,IAAI,EAAE,KAAK,EAAE,cAAc,EAAE,CAAC,CAAC;IAC7E,CAAC;IAED,gGAAgG;IAChG,MAAM,CAAC,UAAU,CAAC,QAAgB;QAChC,OAAO,SAAS,CAAC,cAAc,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC;IAChD,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,SAAS,CAAC,IAAsE;QACrF,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;QAEnC,IAAI,MAAW,CAAC;QAEhB,IAAI,CAAC;YACH,MAAM,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;YACtB,yIAAyI;QAC3I,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,QAAQ,CAAC;gBACb,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,mBAAmB;gBACrD,OAAO,EAAE,IAAI,KAAK,KAAK,KAAK,qBAAqB;aAClD,CAAC,CAAC;QACL,CAAC;QAED,4FAA4F;QAC5F,MAAM,OAAO,GAAG,aAAa,CAAC,qBAAqB,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;QAEtF,IAAI,MAAM,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;YACjC,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,IAAI,MAAM,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;YAChC,MAAM,QAAQ,CAAC;gBACb,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,mBAAmB;gBACrD,OAAO,EAAE,IAAI,KAAK,KAAK,KAAK,6BAA6B,MAAM,CAAC,QAAQ,EAAE;aAC3E,CAAC,CAAC;QACL,CAAC;QAED,8FAA8F;QAC9F,IAAI,MAAM,CAAC,IAAI,KAAK,GAAG,EAAE,CAAC;YACxB,MAAM,QAAQ,CAAC;gBACb,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,mBAAmB;gBACrD,OAAO,EAAE,IAAI,KAAK,KAAK,KAAK,+BAA+B,MAAM,CAAC,QAAQ,GAAG;aAC9E,CAAC,CAAC;QACL,CAAC;QAED,IAAI,aAAa,CAAC,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;YAC5E,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,MAAM,QAAQ,CAAC;YACb,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,mBAAmB;YACrD,OAAO,EAAE,IAAI,KAAK,KAAK,KAAK,+BAA+B,MAAM,CAAC,MAAM,kEAAkE;SAC3I,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { HTTP } from '@venizia/ignis-helpers/common';\nimport { getError, UrlPolicy } from '@venizia/ignis-helpers/core';\n\n/**\n * Where a JWKS may be fetched from. A key set read over plain `http:` can be replaced on the way, and\n * whoever replaces it signs tokens that verify, so a JWKS URL is `https:` unless its host is loopback or\n * its origin is listed in `jwks.trusted`. The one policy serves the JWKS verifier and the service-assertion\n * callers: both fetch a key set to decide who may call.\n *\n * The opt-in is an EXACT origin, never a pattern or a range, in the form the URL parser writes it\n * (`http://identity-service`, `http://10.0.0.5:8080`, `http://[fd00::1]:8443`). The shape check is the url guard's own\n * (`UrlPolicy.resolveTrustedOrigins`), so a JWKS entry and a `policy.hosts.trusted` entry follow one rule.\n */\nexport class JWKSUrlPolicy {\n /** Refuses a `jwks.trusted` list that is not exactly a list of origins, and answers the origins as a set. */\n static resolveTrustedOrigins(opts: { scope: string; trusted?: unknown }): ReadonlySet<string> {\n return UrlPolicy.resolveTrustedOrigins({ ...opts, label: 'jwks.trusted' });\n }\n\n /** Whether the URL parser's hostname is a loopback one: `localhost`, `127.0.0.0/8` or `::1`. */\n static isLoopback(hostname: string): boolean {\n return UrlPolicy.isLoopbackHost({ hostname });\n }\n\n /**\n * Parses a JWKS URL and refuses it unless it is `https:`, or `http:` to a loopback host or an origin listed in\n * `jwks.trusted`. Only the host name goes into the message: a URL may carry credentials.\n */\n static assertUrl(opts: { scope: string; label: string; url: string; trusted?: unknown }): URL {\n const { scope, label, url } = opts;\n\n let parsed: URL;\n\n try {\n parsed = new URL(url);\n // eslint-disable-next-line venizia/no-silent-catch -- the refusal below names the key and withholds the URL, which may carry credentials\n } catch {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${scope}] ${label} is not a valid URL`,\n });\n }\n\n // Before the https early return: a bad `jwks.trusted` refuses the boot whatever the URL is.\n const trusted = JWKSUrlPolicy.resolveTrustedOrigins({ scope, trusted: opts.trusted });\n\n if (parsed.protocol === 'https:') {\n return parsed;\n }\n\n if (parsed.protocol !== 'http:') {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${scope}] ${label} must use https | scheme: ${parsed.protocol}`,\n });\n }\n\n // Nothing listens on port 0: a URL that names it is a mistake, and no origin should cover it.\n if (parsed.port === '0') {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${scope}] ${label} uses port 0 | the host is '${parsed.hostname}'`,\n });\n }\n\n if (JWKSUrlPolicy.isLoopback(parsed.hostname) || trusted.has(parsed.origin)) {\n return parsed;\n }\n\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${scope}] ${label} uses http: and the origin '${parsed.origin}' is not trusted | use https, or list the origin in jwks.trusted`,\n });\n }\n}\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { BaseService } from '@venizia/ignis-kernel';
|
|
2
2
|
import type { IServiceAuthOptions } from '@venizia/ignis-kernel';
|
|
3
|
+
import { type IFetcherHooks } from '@venizia/ignis-helpers/core';
|
|
3
4
|
import type { JWK } from 'jose';
|
|
4
5
|
/**
|
|
5
6
|
* Mints the outgoing assertion, and publishes the public half for callees to verify against.
|
|
@@ -16,6 +17,16 @@ export declare class ServiceAssertionSignerService extends BaseService {
|
|
|
16
17
|
isEnabled(): boolean;
|
|
17
18
|
/** `<name>_<rest path without its slash>`, so a rotated mount changes the kid rather than colliding. */
|
|
18
19
|
getKeyId(): string;
|
|
20
|
+
/**
|
|
21
|
+
* The `onRequest` hook of a fetcher that calls `audience`: before EVERY send - each retry attempt included, so the
|
|
22
|
+
* `jti` is fresh - it signs the method and the percent-encoded path of the request and sets the assertion header.
|
|
23
|
+
* `Authorization` is left alone, so the end user's token still travels on the same request.
|
|
24
|
+
*
|
|
25
|
+
* `new NativeFetcher({ name, hooks: { onRequest: signer.createRequestHook({ audience: 'pricing' }) } })`
|
|
26
|
+
*/
|
|
27
|
+
createRequestHook(opts: {
|
|
28
|
+
audience: string;
|
|
29
|
+
}): NonNullable<IFetcherHooks['onRequest']>;
|
|
19
30
|
/**
|
|
20
31
|
* One assertion, bound to this exact call.
|
|
21
32
|
*
|
|
@@ -40,6 +40,24 @@ let ServiceAssertionSignerService = ServiceAssertionSignerService_1 = class Serv
|
|
|
40
40
|
const restPath = this.options.rest?.path ?? ServiceAssertion.DEFAULT_REST_PATH;
|
|
41
41
|
return this.options.keys?.kid ?? `${this.options.name}_${restPath.replace(/^\//, '')}`;
|
|
42
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* The `onRequest` hook of a fetcher that calls `audience`: before EVERY send - each retry attempt included, so the
|
|
45
|
+
* `jti` is fresh - it signs the method and the percent-encoded path of the request and sets the assertion header.
|
|
46
|
+
* `Authorization` is left alone, so the end user's token still travels on the same request.
|
|
47
|
+
*
|
|
48
|
+
* `new NativeFetcher({ name, hooks: { onRequest: signer.createRequestHook({ audience: 'pricing' }) } })`
|
|
49
|
+
*/
|
|
50
|
+
createRequestHook(opts) {
|
|
51
|
+
const { audience } = opts;
|
|
52
|
+
return async (request) => {
|
|
53
|
+
const assertion = await this.sign({
|
|
54
|
+
method: request.method,
|
|
55
|
+
path: new URL(request.url).pathname,
|
|
56
|
+
audience,
|
|
57
|
+
});
|
|
58
|
+
request.headers.set(ServiceAssertion.HEADER, assertion);
|
|
59
|
+
};
|
|
60
|
+
}
|
|
43
61
|
/**
|
|
44
62
|
* One assertion, bound to this exact call.
|
|
45
63
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signer.service.js","sourceRoot":"","sources":["../../../../../../../src/components/auth/authenticate/services/service/signer.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,uBAAuB,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE/F,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAC3E,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AAErD,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,M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,CAAC,IAAI,eAAe,cAAc,CAAC,GAAG,oCAAoC,MAAM,EAAE;aAC7H,CAAC,CAAC;QACL,CAAC;QAED,IAAI,MAAM,KAAK,cAAc,CAAC,IAAI,EAAE,CAAC;YACnC,OAAO,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACxC,CAAC;QAED,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAEO,aAAa;QACnB,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;YACtB,OAAO;QACT,CAAC;QAED,MAAM,QAAQ,CAAC;YACb,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,mBAAmB;YACrD,OAAO,EAAE,IAAI,+BAA6B,CAAC,IAAI,iFAAiF;SACjI,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AAvIY,6BAA6B;IASrC,WAAA,MAAM,CAAC,EAAE,GAAG,EAAE,uBAAuB,CAAC,eAAe,EAAE,CAAC,CAAA;;GAThD,6BAA6B,CAuIzC","sourcesContent":["import { inject } from '@/base/metadata';\nimport { AuthenticateBindingKeys, BaseService, ServiceAssertion } from '@venizia/ignis-kernel';\nimport type { IServiceAuthOptions } from '@venizia/ignis-kernel';\nimport { getError, RequestIdGenerator } from '@venizia/ignis-helpers/core';\nimport { HTTP } from '@venizia/ignis-helpers/common';\nimport type { CryptoKey, JWK } from 'jose';\nimport { readFile } from 'node:fs/promises';\nimport { JWKSKeyDrivers, JWKSKeyFormats } from '@venizia/ignis-kernel';\nimport { JoseLoader } from '../jose-loader';\n\n/**\n * Mints the outgoing assertion, and publishes the public half for callees to verify against.\n *\n * Only a service that CALLS OUT needs this. `isEnabled()` is false when the application configured\n * no keys, and the component then mounts no certs route.\n */\nexport class ServiceAssertionSignerService extends BaseService {\n private readonly requestIdGenerator = new RequestIdGenerator({\n scope: ServiceAssertionSignerService.name,\n });\n\n private privateKey?: CryptoKey;\n private jwks?: { keys: JWK[] };\n\n constructor(\n @inject({ key: AuthenticateBindingKeys.SERVICE_OPTIONS })\n private readonly options: IServiceAuthOptions,\n ) {\n super({ scope: ServiceAssertionSignerService.name });\n }\n\n isEnabled(): boolean {\n return Boolean(this.options.keys);\n }\n\n /** `<name>_<rest path without its slash>`, so a rotated mount changes the kid rather than colliding. */\n getKeyId(): string {\n const restPath = this.options.rest?.path ?? ServiceAssertion.DEFAULT_REST_PATH;\n\n return this.options.keys?.kid ?? `${this.options.name}_${restPath.replace(/^\\//, '')}`;\n }\n\n /**\n * One assertion, bound to this exact call.\n *\n * `path` must be the percent-ENCODED pathname - `new URL(target).pathname`. The verifier compares\n * against the same shape, and a decoded path here would fail every route carrying a space or a\n * non-ASCII slug.\n */\n async sign(opts: { method: string; path: string; audience: string }): Promise<string> {\n const { method, path, audience } = opts;\n\n this.assertEnabled();\n\n const { SignJWT } = await JoseLoader.load();\n const now = Math.floor(Date.now() / 1000);\n const lifetime =\n this.options.signLifetimeSeconds ?? ServiceAssertion.DEFAULT_SIGN_LIFETIME_SECONDS;\n\n const assertion = new SignJWT({ htm: method.toUpperCase(), htu: path })\n .setProtectedHeader({\n alg: ServiceAssertion.ALGORITHM,\n kid: this.getKeyId(),\n typ: ServiceAssertion.TYP,\n })\n .setIssuer(this.options.name)\n .setSubject(this.options.name)\n .setAudience(audience)\n .setJti(this.requestIdGenerator.nextId())\n .setIssuedAt(now)\n .setExpirationTime(now + lifetime);\n\n const privateKey = await this.resolvePrivateKey();\n\n return assertion.sign(privateKey);\n }\n\n /**\n * The document `/svc-certs` serves, built from the PUBLIC key only.\n *\n * `importSPKI` refuses a private PEM outright, which is what makes the private half unreachable\n * from here by construction rather than by care. The JWK format is deliberately NOT accepted for\n * this path: `importJWK` imports whatever it is handed, and a private JWK marked `\"ext\": true`\n * round-trips its `d` straight into this document. See `JWKSIssuerTokenService.assertPublicJWK`.\n */\n async getPublicJWKS(): Promise<{ keys: JWK[] }> {\n if (this.jwks) {\n return this.jwks;\n }\n\n this.assertEnabled();\n\n const { exportJWK, importSPKI } = await JoseLoader.load();\n const raw = await this.readKey({ source: this.options.keys!.public });\n const publicKey = await importSPKI(raw, ServiceAssertion.ALGORITHM);\n const jwk = await exportJWK(publicKey);\n\n if (jwk.d !== undefined) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${ServiceAssertionSignerService.name}] The public key material carries a private exponent | this key would be published at the certs endpoint`,\n });\n }\n\n this.jwks = {\n keys: [{ ...jwk, kid: this.getKeyId(), alg: ServiceAssertion.ALGORITHM, use: 'sig' }],\n };\n\n return this.jwks;\n }\n\n private async resolvePrivateKey(): Promise<CryptoKey> {\n if (this.privateKey) {\n return this.privateKey;\n }\n\n const { importPKCS8 } = await JoseLoader.load();\n const raw = await this.readKey({ source: this.options.keys!.private });\n const result = await importPKCS8(raw, ServiceAssertion.ALGORITHM);\n this.privateKey = result;\n\n return this.privateKey;\n }\n\n private async readKey(opts: { source: string }): Promise<string> {\n const { format, driver } = this.options.keys!;\n\n if (format !== JWKSKeyFormats.PEM) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${ServiceAssertionSignerService.name}] Only the '${JWKSKeyFormats.PEM}' key format is supported | got: ${format}`,\n });\n }\n\n if (driver === JWKSKeyDrivers.FILE) {\n return readFile(opts.source, 'utf-8');\n }\n\n return opts.source;\n }\n\n private assertEnabled(): void {\n if (this.options.keys) {\n return;\n }\n\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${ServiceAssertionSignerService.name}] This service has no signing keys | it can verify assertions but not mint them`,\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"signer.service.js","sourceRoot":"","sources":["../../../../../../../src/components/auth/authenticate/services/service/signer.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,uBAAuB,EAAE,WAAW,EAAE,gBAAgB,EAAE,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BAA6B;IASrC,WAAA,MAAM,CAAC,EAAE,GAAG,EAAE,uBAAuB,CAAC,eAAe,EAAE,CAAC,CAAA;;GAThD,6BAA6B,CA4JzC","sourcesContent":["import { inject } from '@/base/metadata';\nimport { AuthenticateBindingKeys, BaseService, ServiceAssertion } from '@venizia/ignis-kernel';\nimport type { IServiceAuthOptions } from '@venizia/ignis-kernel';\nimport { getError, RequestIdGenerator, type IFetcherHooks } from '@venizia/ignis-helpers/core';\nimport { HTTP } from '@venizia/ignis-helpers/common';\nimport type { CryptoKey, JWK } from 'jose';\nimport { readFile } from 'node:fs/promises';\nimport { JWKSKeyDrivers, JWKSKeyFormats } from '@venizia/ignis-kernel';\nimport { JoseLoader } from '../jose-loader';\n\n/**\n * Mints the outgoing assertion, and publishes the public half for callees to verify against.\n *\n * Only a service that CALLS OUT needs this. `isEnabled()` is false when the application configured\n * no keys, and the component then mounts no certs route.\n */\nexport class ServiceAssertionSignerService extends BaseService {\n private readonly requestIdGenerator = new RequestIdGenerator({\n scope: ServiceAssertionSignerService.name,\n });\n\n private privateKey?: CryptoKey;\n private jwks?: { keys: JWK[] };\n\n constructor(\n @inject({ key: AuthenticateBindingKeys.SERVICE_OPTIONS })\n private readonly options: IServiceAuthOptions,\n ) {\n super({ scope: ServiceAssertionSignerService.name });\n }\n\n isEnabled(): boolean {\n return Boolean(this.options.keys);\n }\n\n /** `<name>_<rest path without its slash>`, so a rotated mount changes the kid rather than colliding. */\n getKeyId(): string {\n const restPath = this.options.rest?.path ?? ServiceAssertion.DEFAULT_REST_PATH;\n\n return this.options.keys?.kid ?? `${this.options.name}_${restPath.replace(/^\\//, '')}`;\n }\n\n /**\n * The `onRequest` hook of a fetcher that calls `audience`: before EVERY send - each retry attempt included, so the\n * `jti` is fresh - it signs the method and the percent-encoded path of the request and sets the assertion header.\n * `Authorization` is left alone, so the end user's token still travels on the same request.\n *\n * `new NativeFetcher({ name, hooks: { onRequest: signer.createRequestHook({ audience: 'pricing' }) } })`\n */\n createRequestHook(opts: { audience: string }): NonNullable<IFetcherHooks['onRequest']> {\n const { audience } = opts;\n\n return async (request) => {\n const assertion = await this.sign({\n method: request.method,\n path: new URL(request.url).pathname,\n audience,\n });\n\n request.headers.set(ServiceAssertion.HEADER, assertion);\n };\n }\n\n /**\n * One assertion, bound to this exact call.\n *\n * `path` must be the percent-ENCODED pathname - `new URL(target).pathname`. The verifier compares\n * against the same shape, and a decoded path here would fail every route carrying a space or a\n * non-ASCII slug.\n */\n async sign(opts: { method: string; path: string; audience: string }): Promise<string> {\n const { method, path, audience } = opts;\n\n this.assertEnabled();\n\n const { SignJWT } = await JoseLoader.load();\n const now = Math.floor(Date.now() / 1000);\n const lifetime =\n this.options.signLifetimeSeconds ?? ServiceAssertion.DEFAULT_SIGN_LIFETIME_SECONDS;\n\n const assertion = new SignJWT({ htm: method.toUpperCase(), htu: path })\n .setProtectedHeader({\n alg: ServiceAssertion.ALGORITHM,\n kid: this.getKeyId(),\n typ: ServiceAssertion.TYP,\n })\n .setIssuer(this.options.name)\n .setSubject(this.options.name)\n .setAudience(audience)\n .setJti(this.requestIdGenerator.nextId())\n .setIssuedAt(now)\n .setExpirationTime(now + lifetime);\n\n const privateKey = await this.resolvePrivateKey();\n\n return assertion.sign(privateKey);\n }\n\n /**\n * The document `/svc-certs` serves, built from the PUBLIC key only.\n *\n * `importSPKI` refuses a private PEM outright, which is what makes the private half unreachable\n * from here by construction rather than by care. The JWK format is deliberately NOT accepted for\n * this path: `importJWK` imports whatever it is handed, and a private JWK marked `\"ext\": true`\n * round-trips its `d` straight into this document. See `JWKSIssuerTokenService.assertPublicJWK`.\n */\n async getPublicJWKS(): Promise<{ keys: JWK[] }> {\n if (this.jwks) {\n return this.jwks;\n }\n\n this.assertEnabled();\n\n const { exportJWK, importSPKI } = await JoseLoader.load();\n const raw = await this.readKey({ source: this.options.keys!.public });\n const publicKey = await importSPKI(raw, ServiceAssertion.ALGORITHM);\n const jwk = await exportJWK(publicKey);\n\n if (jwk.d !== undefined) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${ServiceAssertionSignerService.name}] The public key material carries a private exponent | this key would be published at the certs endpoint`,\n });\n }\n\n this.jwks = {\n keys: [{ ...jwk, kid: this.getKeyId(), alg: ServiceAssertion.ALGORITHM, use: 'sig' }],\n };\n\n return this.jwks;\n }\n\n private async resolvePrivateKey(): Promise<CryptoKey> {\n if (this.privateKey) {\n return this.privateKey;\n }\n\n const { importPKCS8 } = await JoseLoader.load();\n const raw = await this.readKey({ source: this.options.keys!.private });\n const result = await importPKCS8(raw, ServiceAssertion.ALGORITHM);\n this.privateKey = result;\n\n return this.privateKey;\n }\n\n private async readKey(opts: { source: string }): Promise<string> {\n const { format, driver } = this.options.keys!;\n\n if (format !== JWKSKeyFormats.PEM) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${ServiceAssertionSignerService.name}] Only the '${JWKSKeyFormats.PEM}' key format is supported | got: ${format}`,\n });\n }\n\n if (driver === JWKSKeyDrivers.FILE) {\n return readFile(opts.source, 'utf-8');\n }\n\n return opts.source;\n }\n\n private assertEnabled(): void {\n if (this.options.keys) {\n return;\n }\n\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${ServiceAssertionSignerService.name}] This service has no signing keys | it can verify assertions but not mint them`,\n });\n }\n}\n"]}
|
|
@@ -96,7 +96,7 @@ let ServiceAssertionVerifierService = ServiceAssertionVerifierService_1 = class
|
|
|
96
96
|
scope: ServiceAssertionVerifierService_1.name,
|
|
97
97
|
label: 'the caller jwksUrl',
|
|
98
98
|
url: jwksUrl,
|
|
99
|
-
|
|
99
|
+
trusted: this.options.jwks?.trusted,
|
|
100
100
|
}), {
|
|
101
101
|
cacheMaxAge: this.options.jwks?.cacheMaxAgeMs ?? ServiceAssertion.DEFAULT_JWKS_CACHE_MAX_AGE_MS,
|
|
102
102
|
cooldownDuration: this.options.jwks?.cooldownMs ?? ServiceAssertion.DEFAULT_JWKS_COOLDOWN_MS,
|