Skip to content

Commit 35bfd06

Browse files
committed
fix actframework#513 DefaultSessionCodec.processExpiration error and actframework#512 JWT: sometimes JWT deserialization failed
1 parent a1b1035 commit 35bfd06

3 files changed

Lines changed: 14 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* EntityMetaInfo and scanner - support JPA plugin
66
* Update to act-asm-5.0.3 for precise line number in error reporting
77
* Improve built-in service performance by make them as nonblock when possible
8+
* `DefaultSessionCodec.processExpiration` error #513
9+
* JWT: sometimes JWT deserialization failed #512
810
* Command line param binding failed for `char[]` #511
911
* `NullPointerException` after app reloaded from an ASM error in dev mode #509
1012
* Error page not displayed if asm error raised during scanning phase #508

src/main/java/act/crypto/HMAC.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ public String toString(JWT.Token token) {
8282
token.header(JWT.Header.ALGO, algoName);
8383
String headers = token.headerJsonString();
8484
String payloads = token.payloadJsonString();
85-
String encodedHeaders = Codec.encodeUrlSafeBase64(headers);
86-
String encodedPayloads = Codec.encodeUrlSafeBase64(payloads);
85+
String encodedHeaders = encodePart(headers);
86+
String encodedPayloads = encodePart(payloads);
8787
StringBuilder buf = new StringBuilder(encodedHeaders)
8888
.append(".")
8989
.append(encodedPayloads);
@@ -97,15 +97,15 @@ public String hash(String text) {
9797

9898
public String hash(byte[] bytes) {
9999
byte[] hashed = mac.doFinal(bytes);
100-
return Codec.encodeUrlSafeBase64(hashed);
100+
return encodePart(hashed);
101101
}
102102

103103
public boolean verifyHash(String content, String hash) {
104104
byte[] myHash = mac.doFinal(content.getBytes(UTF_8));
105105
int len = hash.length();
106106
int padding = 4 - len % 4;
107107
if (padding > 0) {
108-
hash = S.concat(hash, S.times('.', padding));
108+
hash = S.concat(hash, S.times(Codec.URL_SAFE_BASE64_PADDING_CHAR, padding));
109109
}
110110
return MessageDigest.isEqual(myHash, Codec.decodeUrlSafeBase64(hash));
111111
}
@@ -124,6 +124,13 @@ public boolean verifyArgo(String algoName) {
124124
}
125125
}
126126

127+
private static String encodePart(String part) {
128+
return Codec.encodeUrlSafeBase64(part);
129+
}
130+
private static String encodePart(byte[] part) {
131+
return Codec.encodeUrlSafeBase64(part);
132+
}
133+
127134
public static void main(String[] args) {
128135
HMAC hmac = new HMAC("secret", "SHA256");
129136
System.out.println(hmac.hash("Hello World"));

src/main/java/act/session/DefaultSessionCodec.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ private String dissolveIntoCookieContent(H.KV<?> kv, boolean isSession) {
208208

209209
static H.Session processExpiration(H.Session session, long now, boolean newSession, boolean sessionWillExpire, int ttl, String pingPath, H.Request request) {
210210
if (!sessionWillExpire) return session;
211-
long expiration = now + ttl;
211+
long expiration = now + ttl * 1000;
212212
if (newSession) {
213213
// no previous cookie to restore; but we need to set the timestamp in the new cookie
214214
// note we use `load` API instead of `put` because we don't want to set the dirty flag

0 commit comments

Comments
 (0)