-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EPA-158: Pick right OpenID Provider JWKS for IdToken verification
- Loading branch information
1 parent
de9d44f
commit de1e3b0
Showing
19 changed files
with
581 additions
and
13 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
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
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
17 changes: 17 additions & 0 deletions
17
ehealthid/src/main/java/com/oviva/ehealthid/fedclient/api/ExtendedJWKSet.java
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,17 @@ | ||
package com.oviva.ehealthid.fedclient.api; | ||
|
||
import com.nimbusds.jose.jwk.JWK; | ||
import com.nimbusds.jose.jwk.JWKSet; | ||
import java.util.List; | ||
|
||
// slight variation of a JWKSet :/ | ||
// https://openid.net/specs/openid-connect-federation-1_0-21.html#name-openid-connect-and-oauth2-m | ||
public record ExtendedJWKSet(long exp, String iss, List<JWK> keys) { | ||
|
||
public JWKSet toJWKSet() { | ||
if (keys == null) { | ||
return new JWKSet(); | ||
} | ||
return new JWKSet(keys); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
ehealthid/src/main/java/com/oviva/ehealthid/fedclient/api/ExtendedJWKSetJWS.java
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,43 @@ | ||
package com.oviva.ehealthid.fedclient.api; | ||
|
||
import com.nimbusds.jose.JWSObject; | ||
import com.nimbusds.jose.jwk.JWKSet; | ||
import com.oviva.ehealthid.crypto.JwsVerifier; | ||
import com.oviva.ehealthid.fedclient.FederationExceptions; | ||
import com.oviva.ehealthid.util.JsonCodec; | ||
import com.oviva.ehealthid.util.JsonPayloadTransformer; | ||
import java.text.ParseException; | ||
import java.time.Instant; | ||
|
||
public record ExtendedJWKSetJWS(JWSObject jws, ExtendedJWKSet body) implements TemporalValid { | ||
|
||
public static final String JWKS_TYPE = "jwk-set+json"; | ||
|
||
public static ExtendedJWKSetJWS parse(String wire) { | ||
try { | ||
|
||
var jws = JWSObject.parse(wire); | ||
|
||
if (!JWKS_TYPE.equals(jws.getHeader().getType().getType())) { | ||
throw FederationExceptions.notASignedJwks(jws.getHeader().getType().getType()); | ||
} | ||
|
||
var es = | ||
jws.getPayload() | ||
.toType(new JsonPayloadTransformer<>(ExtendedJWKSet.class, JsonCodec::readValue)); | ||
return new ExtendedJWKSetJWS(jws, es); | ||
} catch (ParseException e) { | ||
throw FederationExceptions.badSignedJwks(e); | ||
} | ||
} | ||
|
||
public boolean verifySignature(JWKSet jwks) { | ||
return JwsVerifier.verify(jwks, jws); | ||
} | ||
|
||
@Override | ||
public boolean isValidAt(Instant pointInTime) { | ||
var epoch = pointInTime.getEpochSecond(); | ||
return body.exp() == 0 || epoch < body.exp(); | ||
} | ||
} |
Oops, something went wrong.