Search in sources :

Example 1 with ChannelBinding

use of org.ietf.jgss.ChannelBinding in project jdk8u_jdk by JetBrains.

the class NoAddresses method main.

public static void main(String[] args) throws Exception {
    OneKDC kdc = new OneKDC(null);
    kdc.writeJAASConf();
    KDC.saveConfig(OneKDC.KRB5_CONF, kdc, "noaddresses = false", "default_keytab_name = " + OneKDC.KTAB);
    Config.refresh();
    Context c = Context.fromJAAS("client");
    Context s = Context.fromJAAS("server");
    c.startAsClient(OneKDC.SERVER, GSSUtil.GSS_KRB5_MECH_OID);
    s.startAsServer(GSSUtil.GSS_KRB5_MECH_OID);
    InetAddress initiator = InetAddress.getLocalHost();
    InetAddress acceptor = InetAddress.getLocalHost();
    switch(args[0]) {
        case "1":
            // no initiator host address available, should be OK
            break;
        case "2":
            // correct initiator host address, still fine
            c.x().setChannelBinding(new ChannelBinding(initiator, acceptor, null));
            s.x().setChannelBinding(new ChannelBinding(initiator, acceptor, null));
            break;
        case "3":
            // incorrect initiator host address, fail
            initiator = InetAddress.getByAddress(new byte[] { 1, 1, 1, 1 });
            c.x().setChannelBinding(new ChannelBinding(initiator, acceptor, null));
            s.x().setChannelBinding(new ChannelBinding(initiator, acceptor, null));
            break;
    }
    Context.handshake(c, s);
}
Also used : InetAddress(java.net.InetAddress) ChannelBinding(org.ietf.jgss.ChannelBinding)

Example 2 with ChannelBinding

use of org.ietf.jgss.ChannelBinding in project jdk8u_jdk by JetBrains.

the class IgnoreChannelBinding method main.

public static void main(String[] args) throws Exception {
    new OneKDC(null).writeJAASConf();
    Context c = Context.fromJAAS("client");
    Context s = Context.fromJAAS("server");
    // All silent
    c.startAsClient(OneKDC.SERVER, GSSUtil.GSS_KRB5_MECH_OID);
    s.startAsServer(GSSUtil.GSS_KRB5_MECH_OID);
    Context.handshake(c, s);
    // Initiator req, acceptor ignore
    c.startAsClient(OneKDC.SERVER, GSSUtil.GSS_KRB5_MECH_OID);
    c.x().setChannelBinding(new ChannelBinding(InetAddress.getByName("client.rabbit.hole"), InetAddress.getByName("host.rabbit.hole"), new byte[0]));
    s.startAsServer(GSSUtil.GSS_KRB5_MECH_OID);
    Context.handshake(c, s);
    // Both req, and match
    c.startAsClient(OneKDC.SERVER, GSSUtil.GSS_KRB5_MECH_OID);
    c.x().setChannelBinding(new ChannelBinding(InetAddress.getByName("client.rabbit.hole"), InetAddress.getByName("host.rabbit.hole"), new byte[0]));
    s.startAsServer(GSSUtil.GSS_KRB5_MECH_OID);
    s.x().setChannelBinding(new ChannelBinding(InetAddress.getByName("client.rabbit.hole"), InetAddress.getByName("host.rabbit.hole"), new byte[0]));
    Context.handshake(c, s);
    // Both req, NOT match
    c.startAsClient(OneKDC.SERVER, GSSUtil.GSS_KRB5_MECH_OID);
    c.x().setChannelBinding(new ChannelBinding(InetAddress.getByName("client.rabbit.hole"), InetAddress.getByName("host.rabbit.hole"), new byte[0]));
    s.startAsServer(GSSUtil.GSS_KRB5_MECH_OID);
    s.x().setChannelBinding(new ChannelBinding(InetAddress.getByName("client.rabbit.hole"), InetAddress.getByName("host.rabbit.hole"), // 0 -> 1
    new byte[1]));
    try {
        Context.handshake(c, s);
        throw new Exception("Acceptor should reject initiator");
    } catch (GSSException ge) {
    // Expected bahavior
    }
    // Acceptor req, reject
    c.startAsClient(OneKDC.SERVER, GSSUtil.GSS_KRB5_MECH_OID);
    s.startAsServer(GSSUtil.GSS_KRB5_MECH_OID);
    s.x().setChannelBinding(new ChannelBinding(InetAddress.getByName("client.rabbit.hole"), InetAddress.getByName("host.rabbit.hole"), new byte[0]));
    try {
        Context.handshake(c, s);
        throw new Exception("Acceptor should reject initiator");
    } catch (GSSException ge) {
        // Expected bahavior
        if (ge.getMajor() != GSSException.BAD_BINDINGS) {
            throw ge;
        }
    }
}
Also used : GSSException(org.ietf.jgss.GSSException) GSSException(org.ietf.jgss.GSSException) ChannelBinding(org.ietf.jgss.ChannelBinding)

Aggregations

ChannelBinding (org.ietf.jgss.ChannelBinding)2 InetAddress (java.net.InetAddress)1 GSSException (org.ietf.jgss.GSSException)1