-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: abstract jwk to its own module
- Loading branch information
Showing
13 changed files
with
133 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
...les/openid-federation-common/src/commonMain/kotlin/com/sphereon/oid/fed/common/jwk/Jwk.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.sphereon.oid.fed.common.jwk | ||
|
||
import com.sphereon.oid.fed.openapi.models.Jwk | ||
|
||
expect fun generateKeyPair(): Jwk |
3 changes: 0 additions & 3 deletions
3
...openid-federation-common/src/commonMain/kotlin/com/sphereon/oid/fed/common/jwt/JoseJwt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,7 @@ | ||
package com.sphereon.oid.fed.common.jwt | ||
|
||
import com.sphereon.oid.fed.openapi.models.JwtWithPrivateKey | ||
|
||
expect class JwtHeader | ||
expect class JwtPayload | ||
|
||
expect fun sign(payload: JwtPayload, header: JwtHeader, opts: Map<String, Any>): String | ||
expect fun verify(jwt: String, key: Any, opts: Map<String, Any>): Boolean | ||
expect fun generateKeyPair(): JwtWithPrivateKey |
20 changes: 20 additions & 0 deletions
20
modules/openid-federation-common/src/jsMain/kotlin/com.sphereon.oid.fed.common.jwk/Jwk.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.sphereon.oid.fed.common.jwk | ||
|
||
import com.sphereon.oid.fed.common.jwt.Jose | ||
import com.sphereon.oid.fed.openapi.models.Jwk | ||
|
||
@ExperimentalJsExport | ||
@JsExport | ||
actual fun generateKeyPair(): Jwk { | ||
val key = Jose.generateKeyPair("EC") | ||
return Jwk( | ||
d = key.d, | ||
alg = key.alg, | ||
crv = key.crv, | ||
x = key.x, | ||
y = key.y, | ||
kid = key.kid, | ||
kty = key.kty, | ||
use = key.use, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...es/openid-federation-common/src/jvmMain/kotlin/com/sphereon/oid/fed/common/jwk/Jwk.jvm.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.sphereon.oid.fed.common.jwk | ||
|
||
import com.nimbusds.jose.Algorithm | ||
import com.nimbusds.jose.jwk.Curve | ||
import com.nimbusds.jose.jwk.ECKey | ||
import com.nimbusds.jose.jwk.gen.ECKeyGenerator | ||
import com.sphereon.oid.fed.openapi.models.Jwk | ||
import java.util.* | ||
|
||
actual fun generateKeyPair(): Jwk { | ||
try { | ||
val ecKey: ECKey = ECKeyGenerator(Curve.P_256) | ||
.keyIDFromThumbprint(true) | ||
.algorithm(Algorithm("EC")) | ||
.issueTime(Date()) | ||
.generate() | ||
|
||
return Jwk( | ||
d = ecKey.d.toString(), | ||
alg = ecKey.algorithm.name, | ||
crv = ecKey.curve.name, | ||
kid = ecKey.keyID, | ||
kty = ecKey.keyType.value, | ||
use = ecKey.keyUse?.value ?: "sig", | ||
x = ecKey.x.toString(), | ||
y = ecKey.y.toString() | ||
) | ||
|
||
} catch (e: Exception) { | ||
throw Exception("Couldn't generate the EC Key Pair: ${e.message}", e) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
modules/persistence/src/commonMain/resources/db/migration/2.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
CREATE TABLE jwk ( | ||
id SERIAL PRIMARY KEY, | ||
uuid UUID DEFAULT gen_random_uuid(), | ||
account_id INT NOT NULL, | ||
kty VARCHAR(10) NOT NULL, | ||
crv VARCHAR(10), | ||
kid VARCHAR(255) UNIQUE, | ||
x TEXT, | ||
y TEXT, | ||
d TEXT, | ||
n TEXT, | ||
e TEXT, | ||
p TEXT, | ||
q TEXT, | ||
dp TEXT, | ||
dq TEXT, | ||
qi TEXT, | ||
x5u TEXT, | ||
x5c TEXT, | ||
x5t TEXT, | ||
x5t_s256 TEXT, | ||
alg VARCHAR(10), | ||
use VARCHAR(10) NULL, | ||
revoked_at TIMESTAMP, | ||
revoked_reason TEXT, | ||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, | ||
CONSTRAINT FK_AccountJwk FOREIGN KEY (account_id) REFERENCES account (id) | ||
); | ||
|
||
CREATE INDEX jwk_account_id_index ON jwk (account_id); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.