31
32 import java.nio.ByteBuffer;
33 import java.nio.channels.SeekableByteChannel;
34 import java.nio.file.Files;
35 import java.nio.file.Paths;
36 import java.nio.file.StandardOpenOption;
37 import java.util.Random;
38 import sun.security.krb5.KrbException;
39 import sun.security.krb5.internal.KerberosTime;
40 import sun.security.krb5.internal.ReplayCache;
41 import sun.security.krb5.internal.rcache.AuthTimeWithHash;
42
43 public class ReplayCachePrecise {
44 static final String client = "dummy@REALM";
45 static final String server = "server/localhost@REALM";
46 static final Random rand = new Random();
47
48 public static void main(String[] args) throws Exception {
49
50 AuthTimeWithHash a1 = new AuthTimeWithHash(client, server, time(0), 0,
51 "1111111111111111");
52 AuthTimeWithHash a2 = new AuthTimeWithHash(client, server, time(0), 0,
53 "2222222222222222");
54 KerberosTime now = new KerberosTime(time(0)*1000L);
55
56 // When all new styles, must exact match
57 ReplayCache cache = ReplayCache.getInstance("dfl:./c1");
58 cache.checkAndStore(now, a1);
59 cache.checkAndStore(now, a2);
60
61 // When only old style in cache, partial match
62 cache = ReplayCache.getInstance("dfl:./c2");
63 cache.checkAndStore(now, a1);
64 // A small surgery to remove the new style from the cache file
65 SeekableByteChannel ch = Files.newByteChannel(Paths.get("c2"),
66 StandardOpenOption.WRITE,
67 StandardOpenOption.READ);
68 ch.position(6);
69 ch.write(ByteBuffer.wrap(a1.encode(false)));
70 ch.truncate(ch.position());
71 ch.close();
72 try {
73 cache.checkAndStore(now, a2);
|
31
32 import java.nio.ByteBuffer;
33 import java.nio.channels.SeekableByteChannel;
34 import java.nio.file.Files;
35 import java.nio.file.Paths;
36 import java.nio.file.StandardOpenOption;
37 import java.util.Random;
38 import sun.security.krb5.KrbException;
39 import sun.security.krb5.internal.KerberosTime;
40 import sun.security.krb5.internal.ReplayCache;
41 import sun.security.krb5.internal.rcache.AuthTimeWithHash;
42
43 public class ReplayCachePrecise {
44 static final String client = "dummy@REALM";
45 static final String server = "server/localhost@REALM";
46 static final Random rand = new Random();
47
48 public static void main(String[] args) throws Exception {
49
50 AuthTimeWithHash a1 = new AuthTimeWithHash(client, server, time(0), 0,
51 "HASH", "1111111111111111");
52 AuthTimeWithHash a2 = new AuthTimeWithHash(client, server, time(0), 0,
53 "HASH", "2222222222222222");
54 KerberosTime now = new KerberosTime(time(0)*1000L);
55
56 // When all new styles, must exact match
57 ReplayCache cache = ReplayCache.getInstance("dfl:./c1");
58 cache.checkAndStore(now, a1);
59 cache.checkAndStore(now, a2);
60
61 // When only old style in cache, partial match
62 cache = ReplayCache.getInstance("dfl:./c2");
63 cache.checkAndStore(now, a1);
64 // A small surgery to remove the new style from the cache file
65 SeekableByteChannel ch = Files.newByteChannel(Paths.get("c2"),
66 StandardOpenOption.WRITE,
67 StandardOpenOption.READ);
68 ch.position(6);
69 ch.write(ByteBuffer.wrap(a1.encode(false)));
70 ch.truncate(ch.position());
71 ch.close();
72 try {
73 cache.checkAndStore(now, a2);
|