--- old/src/java.security.jgss/share/classes/sun/security/krb5/internal/rcache/AuthTimeWithHash.java 2016-10-25 09:03:38.000000000 +0800 +++ new/src/java.security.jgss/share/classes/sun/security/krb5/internal/rcache/AuthTimeWithHash.java 2016-10-25 09:03:38.000000000 +0800 @@ -25,6 +25,8 @@ package sun.security.krb5.internal.rcache; +import sun.security.action.GetPropertyAction; + import java.util.Objects; /** @@ -34,14 +36,32 @@ public class AuthTimeWithHash extends AuthTime implements Comparable { + // The hash algorithm can be "HASH" or "SHA256". + public static String DEFAULT_HASH_ALG = GetPropertyAction + .privilegedGetProperty("jdk.krb5.rcache.hashalg", "HASH"); + + public static String realAlg(String alg) { + if (alg.equals("HASH")) { + return "MD5"; + } else if (alg.equals("SHA")) { + return "SHA-1"; + } else if (alg.startsWith("SHA") && !alg.startsWith("SHA-")) { + return "SHA-" + alg.substring(3); + } else { + return alg; + } + } + + final String hashAlg; final String hash; /** * Constructs a new AuthTimeWithHash. */ public AuthTimeWithHash(String client, String server, - int ctime, int cusec, String hash) { + int ctime, int cusec, String hashAlg, String hash) { super(client, server, ctime, cusec); + this.hashAlg = hashAlg; this.hash = hash; } @@ -56,6 +76,7 @@ if (!(o instanceof AuthTimeWithHash)) return false; AuthTimeWithHash that = (AuthTimeWithHash)o; return Objects.equals(hash, that.hash) + && Objects.equals(hashAlg, that.hashAlg) && Objects.equals(client, that.client) && Objects.equals(server, that.server) && ctime == that.ctime @@ -91,6 +112,19 @@ /** * Compares with a possibly old style object. Used * in DflCache$Storage#loadAndCheck. + * @return true if all AuthTime fields are the same but different hash + */ + public boolean sameTimeDiffHash(AuthTimeWithHash old) { + if (!this.isSameIgnoresHash(old)) { + return false; + } + return this.hashAlg.equals(old.hashAlg) && + !this.hash.equals(old.hash); + } + + /** + * Compares with a possibly old style object. Used + * in DflCache$Storage#loadAndCheck. * @return true if all AuthTime fields are the same */ public boolean isSameIgnoresHash(AuthTime old) { @@ -112,7 +146,7 @@ String sstring; if (withHash) { cstring = ""; - sstring = String.format("HASH:%s %d:%s %d:%s", hash, + sstring = String.format("%s:%s %d:%s %d:%s", hashAlg, hash, client.length(), client, server.length(), server); } else {