Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Implemented KMS, JWKS generation and JWT sign #14

Merged
merged 16 commits into from
Aug 16, 2024

Conversation

zoemaas
Copy link
Contributor

@zoemaas zoemaas commented Jul 12, 2024

No description provided.

@zoemaas zoemaas marked this pull request as ready for review July 18, 2024 08:59
@nklomp
Copy link
Contributor

nklomp commented Jul 23, 2024

You cannot just invent your own kid with a uuid

opts: Map<String, Any>
): String {
val rsaJWK = opts["key"] as RSAKey? ?: RSAKeyGenerator(2048)
.keyID(UUID.randomUUID().toString())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nklomp made a comment about not being possible to generate a random kid with uuid

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made header the second parameter of the sign function, the key should be passed in for both js and jvm now.

Copy link
Contributor

@nklomp nklomp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See remarks

opts: Map<String, Any>
): String {
val privateKey = opts["privateKey"] ?: throw IllegalArgumentException("JWK private key is required")
val header = opts["jwtHeader"] as String? ?: "{\"typ\":\"JWT\",\"alg\":\"RS256\",\"kid\":\"${Uuid.v4()}\"}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should not just create a header, let alone use a random kid value.
Although "kid" is officially not defined, normally they are the JWK thumbprint in case a JWK is used, or a DID VM in case DIDs are used.
So please make a header a first class citizen like the payload. Require it to be passed in. 2nd don't create random kids.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made header the second parameter of the sign function, the key should be passed in for both js and jvm now.

@@ -0,0 +1,4 @@
package com.sphereon.oid.fed.common.jwt

expect fun sign(payload: String, header: String, opts: Map<String, Any>): String
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not like this whole signature.
First of all, opts: Map<String, Any>, with this you are putting the platform differences with the implementer. Please create a static options data class with options that work for all platforms. Do the mapping in the platform implementation. If there are options available on one platform that are not available on the other we should think hard if we really need to expose them or if we can omit them or set a default value that works for us.

Then payload: String, header: String is also not very clear. Make it at least
jwtHeader:String, jwtPayload:String or better, create a little data class
data class UnsignedJWT(val header:String, val payload,String) and use that as parameter.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the discussion in slack about the opts. They are they are there for external implementors. Not for platform specifics.

Regarding the header and payload. How did that ever change to string. That doesn't make any sense. These should be objects, that are translated into strings in this exact function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes implemented

Zoe Maas and others added 4 commits August 2, 2024 16:21
* fix: add missing repositories for windows

* fix: update ci docker compose command
* chore: Removed redundant HTTPCache

* chore: Uncommented ios targets back

* refactor: refactored serializeNullable()

* refactor: refactored deserialize()

* refactor: refactored OutgoingEntityStatementContent.bytes()

* refactor: refactored the tests to use assertEquals()

* refactor: Changed the response body to jwt string

* refactor: Removed unnecessary converter

* feat: implement jwk persistence

* fix: remove unused statement

* fix: github CI

* feat/OIDF-51 - Implement Persistence Module (#21)

* merge oidf-7

* fix: models package

* fix: openapi TrustMarkOwner property

* fix: create account method return type

* fix: rename file for consistency

* feat: implement migration

* fix: repository dependency

* fix: add missing trailing new line

* feat: implement services module

* fix: package path

* fix: remove unused file

* fix: add missing entity to openapi spec

* feat: persist generated keys

* fix: typo

* fix: missing deps

* fix: ci docker command

* fix: dependency

* fix: remove unnecessary statement

* feat: abstract jwk to its own module

* feat: encrypt private keys when saving to database

* feat: add note to README regarding usage of Local KMS in prod envs

* fix: adapt key encryption test cases for when APP_KEY is null

* fix: adjust function name

* fix: add kotlin-js-store to gitignore

* fix: clean common gradle file

* fix: disable android build

* fix: remove js implementation from services

* feat: implement Subordinate repository (#29)

* feat: implement federation server structure (#28)

* feat: implement federation server structure

* feat: implement Subordinate repository

* fix: remove unused files

* feat: implement federation list endpoint

---------

Co-authored-by: Zoe Maas <[email protected]>
@jcmelati jcmelati merged commit f3672af into develop Aug 16, 2024
1 check passed
@jcmelati jcmelati deleted the feature/OIDF-42 branch August 22, 2024 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants