KEYCLOAK-4176
This commit is contained in:
parent
8a02ef1859
commit
426e55664f
2 changed files with 5 additions and 5 deletions
|
@ -25,6 +25,7 @@ import org.keycloak.jose.jws.JWSInput;
|
|||
import javax.crypto.Mac;
|
||||
import javax.crypto.SecretKey;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
/**
|
||||
|
@ -81,8 +82,7 @@ public class HMACProvider implements SignatureProvider {
|
|||
public static boolean verify(JWSInput input, SecretKey key) {
|
||||
try {
|
||||
byte[] signature = sign(input.getEncodedSignatureInput().getBytes("UTF-8"), input.getHeader().getAlgorithm(), key);
|
||||
String x = Base64Url.encode(signature);
|
||||
return x.equals(input.getEncodedSignature());
|
||||
return MessageDigest.isEqual(signature, Base64Url.decode(input.getEncodedSignature()));
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
@ -92,8 +92,7 @@ public class HMACProvider implements SignatureProvider {
|
|||
public static boolean verify(JWSInput input, byte[] sharedSecret) {
|
||||
try {
|
||||
byte[] signature = sign(input.getEncodedSignatureInput().getBytes("UTF-8"), input.getHeader().getAlgorithm(), sharedSecret);
|
||||
String x = Base64Url.encode(signature);
|
||||
return x.equals(input.getEncodedSignature());
|
||||
return MessageDigest.isEqual(signature, Base64Url.decode(input.getEncodedSignature()));
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ import org.keycloak.models.RealmModel;
|
|||
import org.keycloak.models.RoleModel;
|
||||
import org.keycloak.models.utils.KeycloakModelUtils;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -252,7 +253,7 @@ public class ClientSessionCode {
|
|||
|
||||
clientSession.removeNote(ACTIVE_CODE);
|
||||
|
||||
return code.equals(activeCode);
|
||||
return MessageDigest.isEqual(code.getBytes(), activeCode.getBytes());
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue