Skip to content

Commit

Permalink
[SECURITY-1849]
Browse files Browse the repository at this point in the history
  • Loading branch information
car-roll committed Jul 19, 2022
1 parent 23ea472 commit 11d1d79
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

import hudson.util.Secret;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;

import java.security.MessageDigest;

import static com.google.common.base.Preconditions.checkNotNull;
import static java.nio.charset.StandardCharsets.UTF_8;

Expand Down Expand Up @@ -71,6 +72,12 @@ public String sha1() {
public boolean matches(String digest) {
String computed = sha1();
LOGGER.trace("Signature: calculated={} provided={}", computed, digest);
return StringUtils.equals(computed, digest);
if (digest == null && computed == null) {
return true;
} else if (digest == null || computed == null) {
return false;
} else {
return MessageDigest.isEqual(computed.getBytes(UTF_8), digest.getBytes(UTF_8));
}
}
}

0 comments on commit 11d1d79

Please sign in to comment.