Skip to content

Commit

Permalink
Merge pull request #575 from Vorimo/timing-references-alignment
Browse files Browse the repository at this point in the history
Time properties renamed
  • Loading branch information
pmlopes authored Jul 19, 2022
2 parents 5fb2006 + db45112 commit c9da04a
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.impl.JsonUtil;
import java.time.Instant;
import java.time.format.DateTimeFormatter;

import java.util.Base64;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class JWTOptions {
private String algorithm = "HS256";
private JsonObject header = EMPTY;
private boolean noTimestamp;
private int expiresInSeconds;
private int expires;
private List<String> audience;
private String issuer;
private String subject;
Expand All @@ -33,7 +33,7 @@ public JWTOptions(JWTOptions other) {
this.algorithm = other.algorithm;
this.header = other.header;
this.noTimestamp = other.noTimestamp;
this.expiresInSeconds = other.expiresInSeconds;
this.expires = other.expires;
this.audience = other.audience;
this.issuer = other.issuer;
this.subject = other.subject;
Expand Down Expand Up @@ -97,16 +97,16 @@ public JWTOptions setNoTimestamp(boolean noTimestamp) {
}

public int getExpiresInSeconds() {
return expiresInSeconds;
return expires;
}

public JWTOptions setExpiresInSeconds(int expiresInSeconds) {
this.expiresInSeconds = expiresInSeconds;
public JWTOptions setExpiresInSeconds(int expires) {
this.expires = expires;
return this;
}

public JWTOptions setExpiresInMinutes(int expiresInMinutes) {
this.expiresInSeconds = expiresInMinutes * 60;
this.expires = expiresInMinutes * 60;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public class OAuth2Options {
// JWK path RFC7517
private String jwkPath;
//seconds of JWKs lifetime
private long jwkMaxAgeInSeconds;
private long jwkMaxAge;
// OpenID non standard
private String tenant;

Expand Down Expand Up @@ -146,7 +146,7 @@ public OAuth2Options(OAuth2Options other) {
headers = null;
}
jwkPath = other.getJwkPath();
jwkMaxAgeInSeconds = other.getJwkMaxAgeInSeconds();
jwkMaxAge = other.getJwkMaxAgeInSeconds();
httpClientOptions = other.getHttpClientOptions();
userAgent = other.getUserAgent();
supportedGrantTypes = other.getSupportedGrantTypes();
Expand All @@ -163,7 +163,7 @@ private void init() {
revocationPath = REVOCATION_PATH;
scopeSeparator = SCOPE_SEPARATOR;
jwtOptions = JWT_OPTIONS;
jwkMaxAgeInSeconds = JWK_DEFAULT_AGE;
jwkMaxAge = JWK_DEFAULT_AGE;
}

/**
Expand Down Expand Up @@ -557,7 +557,7 @@ public OAuth2Options setTenant(String tenant) {

@Deprecated
public boolean isRotateJWKs() {
return jwkMaxAgeInSeconds != -1L;
return jwkMaxAge != -1L;
}

/**
Expand Down Expand Up @@ -704,7 +704,7 @@ public OAuth2Options setHttpClientOptions(HttpClientOptions httpClientOptions) {
}

public long getJwkMaxAgeInSeconds() {
return jwkMaxAgeInSeconds;
return jwkMaxAge;
}

/**
Expand All @@ -713,6 +713,6 @@ public long getJwkMaxAgeInSeconds() {
* @param jwkMaxAgeInSeconds timeout of JWKs rotation
*/
public void setJwkMaxAgeInSeconds(long jwkMaxAgeInSeconds) {
this.jwkMaxAgeInSeconds = jwkMaxAgeInSeconds;
this.jwkMaxAge = jwkMaxAgeInSeconds;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.impl.JsonUtil;
import java.time.Instant;
import java.time.format.DateTimeFormatter;

import java.util.Base64;

/**
Expand Down Expand Up @@ -82,7 +81,7 @@ public static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json,
break;
case "timeout":
if (member.getValue() instanceof Number) {
obj.setTimeout(((Number)member.getValue()).longValue());
obj.setTimeoutInMilliseconds(((Number)member.getValue()).longValue());
}
break;
case "transports":
Expand Down Expand Up @@ -128,8 +127,8 @@ public static void toJson(WebAuthnOptions obj, java.util.Map<String, Object> jso
json.put("relyingParty", obj.getRelyingParty().toJson());
}
json.put("requireResidentKey", obj.getRequireResidentKey());
if (obj.getTimeout() != null) {
json.put("timeout", obj.getTimeout());
if (obj.getTimeoutInMilliseconds() != null) {
json.put("timeout", obj.getTimeoutInMilliseconds());
}
if (obj.getTransports() != null) {
JsonArray array = new JsonArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,17 +361,17 @@ public WebAuthnOptions setUserVerification(UserVerification userVerification) {
return this;
}

public Long getTimeout() {
public Long getTimeoutInMilliseconds() {
return timeout;
}

public WebAuthnOptions setTimeout(Long timeout) {
if (timeout != null) {
if (timeout < 0) {
public WebAuthnOptions setTimeoutInMilliseconds(Long timeoutInMilliseconds) {
if (timeoutInMilliseconds != null) {
if (timeoutInMilliseconds < 0) {
throw new IllegalArgumentException("Timeout must be >= 0");
}
}
this.timeout = timeout;
this.timeout = timeoutInMilliseconds;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public Future<JsonObject> createCredentialsOptions(JsonObject user) {
.put("type", "public-key"));
}
// optional timeout
putOpt(json, "timeout", options.getTimeout());
putOpt(json, "timeout", options.getTimeoutInMilliseconds());
// optional excluded credentials
if (!authenticators.isEmpty()) {
JsonArray transports = new JsonArray();
Expand Down Expand Up @@ -231,7 +231,7 @@ public Future<JsonObject> getCredentialsOptions(String name) {
// https://w3c.github.io/webauthn/#dictionary-assertion-options
JsonObject json = new JsonObject()
.put("challenge", randomBase64URLBuffer(options.getChallengeLength()));
putOpt(json, "timeout", options.getTimeout());
putOpt(json, "timeout", options.getTimeoutInMilliseconds());
putOpt(json, "rpId", options.getRelyingParty().getId());
putOpt(json, "userVerification", options.getUserVerification());
putOpt(json, "extensions", options.getExtensions());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public AttestationCertificates validate(WebAuthnOptions options, MetaData metada
// 6. Verify the timestamp
long timestampMs = token.getJsonObject("payload").getLong("timestampMs", 0L);
long now = System.currentTimeMillis();
if (timestampMs > now || (timestampMs + options.getTimeout()) < now) {
if (timestampMs > now || (timestampMs + options.getTimeoutInMilliseconds()) < now) {
throw new AttestationException("timestampMs is invalid!");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public void testSafetyNetAttestation(TestContext should) {
WebAuthn webAuthN = WebAuthn.create(
rule.vertx(),
new WebAuthnOptions().setRelyingParty(new RelyingParty().setName("FIDO Examples Corporation"))
.setTimeout(System.currentTimeMillis()))
.setTimeoutInMilliseconds(System.currentTimeMillis()))
.authenticatorFetcher(database::fetch)
.authenticatorUpdater(database::store);

Expand Down

0 comments on commit c9da04a

Please sign in to comment.