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

Change expiration for JWT authentification of engine port to 60 seconds #4168

Merged
merged 3 commits into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 22.7.0

### Additions and Improvements
- Engine API: Change expiration time for JWT tokens to 60s [#4168](https://github.com/hyperledger/besu/pull/4168)

### Bug Fixes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
public class EngineAuthService implements AuthenticationService {

private static final Logger LOG = LoggerFactory.getLogger(EngineAuthService.class);
private static final int JWT_EXPIRATION_TIME = 60;

private final JWTAuth jwtAuthProvider;

public EngineAuthService(final Vertx vertx, final Optional<File> signingKey, final Path datadir) {
Expand Down Expand Up @@ -167,6 +169,6 @@ public boolean isPermitted(
private boolean issuedRecently(final long iat) {
long iatSecondsSinceEpoch = iat;
long nowSecondsSinceEpoch = System.currentTimeMillis() / 1000;
return (Math.abs((nowSecondsSinceEpoch - iatSecondsSinceEpoch)) <= 5);
return (Math.abs((nowSecondsSinceEpoch - iatSecondsSinceEpoch)) <= JWT_EXPIRATION_TIME);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,10 @@ public void denyExpired() throws IOException, URISyntaxException {
assertThat(auth).isNotNull();
JWTAuth jwtAuth = auth.getJwtAuthProvider();
String token =
jwtAuth.generateToken(new JsonObject().put("iat", (System.currentTimeMillis() / 1000) - 6));
jwtAuth.generateToken(
new JsonObject().put("iat", (System.currentTimeMillis() / 1000) - 61));

Handler<Optional<User>> authHandler =
new Handler<Optional<User>>() {
@Override
public void handle(final Optional<User> event) {
assertThat(event).isEmpty();
}
};
Handler<Optional<User>> authHandler = event -> assertThat(event).isEmpty();
auth.authenticate(token, authHandler);
}
}