Search in sources :

Example 1 with ReplayCache

use of sun.security.krb5.internal.ReplayCache in project jdk8u_jdk by JetBrains.

the class ReplayCacheExpunge method main.

public static void main(String[] args) throws Exception {
    // Make sure clockskew is default value
    System.setProperty("java.security.krb5.conf", "nothing");
    int count = Integer.parseInt(args[0]);
    ReplayCache cache = ReplayCache.getInstance("dfl:./");
    AuthTimeWithHash a1 = new AuthTimeWithHash(client, server, time(-400), 0, hash("1"));
    AuthTimeWithHash a2 = new AuthTimeWithHash(client, server, time(0), 0, hash("4"));
    KerberosTime now = new KerberosTime(time(0) * 1000L);
    KerberosTime then = new KerberosTime(time(-300) * 1000L);
    // Once upon a time, we added a lot of events
    for (int i = 0; i < count; i++) {
        a1 = new AuthTimeWithHash(client, server, time(-400), 0, hash(""));
        cache.checkAndStore(then, a1);
    }
    // Now, we add a new one. If some conditions hold, the old ones
    // will be expunged.
    cache.checkAndStore(now, a2);
    // and adding an old one will not trigger any error
    cache.checkAndStore(now, a1);
}
Also used : AuthTimeWithHash(sun.security.krb5.internal.rcache.AuthTimeWithHash) ReplayCache(sun.security.krb5.internal.ReplayCache) KerberosTime(sun.security.krb5.internal.KerberosTime)

Example 2 with ReplayCache

use of sun.security.krb5.internal.ReplayCache in project jdk8u_jdk by JetBrains.

the class ReplayCachePrecise method main.

public static void main(String[] args) throws Exception {
    AuthTimeWithHash a1 = new AuthTimeWithHash(client, server, time(0), 0, "1111111111111111");
    AuthTimeWithHash a2 = new AuthTimeWithHash(client, server, time(0), 0, "2222222222222222");
    KerberosTime now = new KerberosTime(time(0) * 1000L);
    // When all new styles, must exact match
    ReplayCache cache = ReplayCache.getInstance("dfl:./c1");
    cache.checkAndStore(now, a1);
    cache.checkAndStore(now, a2);
    // When only old style in cache, partial match
    cache = ReplayCache.getInstance("dfl:./c2");
    cache.checkAndStore(now, a1);
    // A small surgery to remove the new style from the cache file
    SeekableByteChannel ch = Files.newByteChannel(Paths.get("c2"), StandardOpenOption.WRITE, StandardOpenOption.READ);
    ch.position(6);
    ch.write(ByteBuffer.wrap(a1.encode(false)));
    ch.truncate(ch.position());
    ch.close();
    try {
        cache.checkAndStore(now, a2);
        throw new Exception();
    } catch (KrbException ke) {
        // Correct
        System.out.println(ke);
    }
}
Also used : AuthTimeWithHash(sun.security.krb5.internal.rcache.AuthTimeWithHash) SeekableByteChannel(java.nio.channels.SeekableByteChannel) ReplayCache(sun.security.krb5.internal.ReplayCache) KrbException(sun.security.krb5.KrbException) KerberosTime(sun.security.krb5.internal.KerberosTime) KrbException(sun.security.krb5.KrbException)

Aggregations

KerberosTime (sun.security.krb5.internal.KerberosTime)2 ReplayCache (sun.security.krb5.internal.ReplayCache)2 AuthTimeWithHash (sun.security.krb5.internal.rcache.AuthTimeWithHash)2 SeekableByteChannel (java.nio.channels.SeekableByteChannel)1 KrbException (sun.security.krb5.KrbException)1