Search in sources :

Example 1 with GSSHeader

use of sun.security.jgss.GSSHeader in project jdk8u_jdk by JetBrains.

the class NativeGSSContext method getMechFromSpNegoToken.

// Retrieve the (preferred) mech out of SPNEGO tokens, i.e.
// NegTokenInit & NegTokenTarg
private static Oid getMechFromSpNegoToken(byte[] token, boolean isInitiator) throws GSSException {
    Oid mech = null;
    if (isInitiator) {
        GSSHeader header = null;
        try {
            header = new GSSHeader(new ByteArrayInputStream(token));
        } catch (IOException ioe) {
            throw new GSSExceptionImpl(GSSException.FAILURE, ioe);
        }
        int negTokenLen = header.getMechTokenLength();
        byte[] negToken = new byte[negTokenLen];
        System.arraycopy(token, token.length - negTokenLen, negToken, 0, negToken.length);
        NegTokenInit ntok = new NegTokenInit(negToken);
        if (ntok.getMechToken() != null) {
            Oid[] mechList = ntok.getMechTypeList();
            mech = mechList[0];
        }
    } else {
        NegTokenTarg ntok = new NegTokenTarg(token);
        mech = ntok.getSupportedMech();
    }
    return mech;
}
Also used : NegTokenTarg(sun.security.jgss.spnego.NegTokenTarg) NegTokenInit(sun.security.jgss.spnego.NegTokenInit) GSSExceptionImpl(sun.security.jgss.GSSExceptionImpl) GSSHeader(sun.security.jgss.GSSHeader)

Example 2 with GSSHeader

use of sun.security.jgss.GSSHeader in project jdk8u_jdk by JetBrains.

the class NativeGSSContext method retrieveToken.

private byte[] retrieveToken(InputStream is, int mechTokenLen) throws GSSException {
    try {
        byte[] result = null;
        if (mechTokenLen != -1) {
            // Need to add back the GSS header for a complete GSS token
            SunNativeProvider.debug("Precomputed mechToken length: " + mechTokenLen);
            GSSHeader gssHeader = new GSSHeader(new ObjectIdentifier(cStub.getMech().toString()), mechTokenLen);
            ByteArrayOutputStream baos = new ByteArrayOutputStream(600);
            byte[] mechToken = new byte[mechTokenLen];
            int len = is.read(mechToken);
            assert (mechTokenLen == len);
            gssHeader.encode(baos);
            baos.write(mechToken);
            result = baos.toByteArray();
        } else {
            // Must be unparsed GSS token or SPNEGO's NegTokenTarg token
            assert (mechTokenLen == -1);
            DerValue dv = new DerValue(is);
            result = dv.toByteArray();
        }
        SunNativeProvider.debug("Complete Token length: " + result.length);
        return result;
    } catch (IOException ioe) {
        throw new GSSExceptionImpl(GSSException.FAILURE, ioe);
    }
}
Also used : DerValue(sun.security.util.DerValue) GSSExceptionImpl(sun.security.jgss.GSSExceptionImpl) GSSHeader(sun.security.jgss.GSSHeader) ObjectIdentifier(sun.security.util.ObjectIdentifier)

Aggregations

GSSExceptionImpl (sun.security.jgss.GSSExceptionImpl)2 GSSHeader (sun.security.jgss.GSSHeader)2 NegTokenInit (sun.security.jgss.spnego.NegTokenInit)1 NegTokenTarg (sun.security.jgss.spnego.NegTokenTarg)1 DerValue (sun.security.util.DerValue)1 ObjectIdentifier (sun.security.util.ObjectIdentifier)1