Elffuss BraidHub

kikocis/EDC public

docs: add decision record about customizable JWSSigners (#4396)

Changeset49f52aca5a72c16f69cfd9f35ea85dfef34c112b50519c8b659e922ab616abc9
AuthorPaul Latzelsperger <43503240+paullatzelsperger@users.noreply.github.com> · 2024-08-07 10:57 +02:00
CommitterGitHub <noreply@github.com> · 2024-08-07 10:57 +02:00
Parentsfa9ee1399716

Browse the files at this changeset

2 files changed

added docs/developer/decision-records/2024-08-05-custom-jwssigners/README.md +52 −0
@@ -0,0 +1,52 @@
1+# Allowing custom `JWSSigner` implementations
2+
3+## Decision
4+
5+To allow custom `JWSSigner` implementations, the `TokenGenerationService` needs to be refactored, in particular the way
6+how `PrivateKey` objects are handled.
7+
8+## Rationale
9+
10+In the current EDC implementation, the private key is always resolved from the vault, and a `JWSSigner` implementation
11+is instantiated based on the algorithm of the key.
12+
13+Some High-Security Modules (HSMs) have a feature where the signing of content can be done with a remote call while
14+the private key material does not leave the HSM itself.
15+
16+To support this feature in EDC, the `TokenGenerationService` and its implementation, the `JwtGenerationService` must be
17+refactored to accommodate the custom `JWSSigner`.
18+
19+## Approach
20+
21+- refactor the `generate()` method: instead of taking a `Supplier<PrivateKey`, the `TokenGenerationService` will take a
22+ plain String containing the private key ID.
23+- a new interface `JwsSignerProvider` is added in its own SPI module `jwt-signer-spi`:
24+ ```java
25+ public interface JwsSignerProvider extends Function<String, JWSSigner> {
26+ // marker interface
27+ }
28+ ```
29+ Note that this will expose Nimbus classes in the SPI module!
30+- the `JwtGenerationService` takes in its constructor a `JwsSignerProvider`, which is then used upon token generation to
31+ get a `JWSSigner` for a particular private key ID.
32+ ```java
33+ @Override
34+ public Result<TokenRepresentation> generate(String privateKeyId, @NotNull TokenDecorator... decorators) {
35+ var tokenSigner = jwsGeneratorFunction.apply(privateKeyId);
36+ if (tokenSigner == null) {
37+ return Result.failure("JWSSigner cannot be generated for private key '%s'".formatted(privateKeyId));
38+ }
39+ //...
40+ }
41+ ```
42+- The default implementation will simply resolve the private key from
43+ the vault and create a `JWSSigner` for it:
44+ ```java
45+ @Provider(isDefault = true)
46+ public JwsSignerProvider defaultSignerProvider() {
47+ return privateKeyId -> {
48+ var pk = privateKeyResolver.resolvePrivateKey(privateKeyId).orElseThrow(/*exception*/);
49+ return CryptoConverter.createSignerFor(pk);
50+ };
51+ }
52+ ```
No newline at the end of the file
modified docs/developer/decision-records/README.md +1 −0
@@ -58,3 +58,4 @@
5858 - [2024-05-24 Dataplane Selection Improvements](./2024-05-24-dataplane-selection-improvements/)
5959 - [2024-06-24 Api Authentication Configuration](./2024-06-24-api-authentication-configuration/)
6060 - [2024-07-03 Additional CatalogRequest scope parameter](./2024-07-03-additional-catalogrequest-param/)
61+- [2024-08-05 Custom JWSSigner Implementations](./2024-08-05-custom-jwssigners/)