Search in sources :

Example 6 with GSSExceptionImpl

use of sun.security.jgss.GSSExceptionImpl 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)

Example 7 with GSSExceptionImpl

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

the class NativeGSSContext method wrap.

public void wrap(byte[] inBuf, int offset, int len, OutputStream os, MessageProp msgProp) throws GSSException {
    try {
        byte[] result = wrap(inBuf, offset, len, msgProp);
        os.write(result);
    } catch (IOException ioe) {
        throw new GSSExceptionImpl(GSSException.FAILURE, ioe);
    }
}
Also used : GSSExceptionImpl(sun.security.jgss.GSSExceptionImpl)

Example 8 with GSSExceptionImpl

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

the class NativeGSSContext method wrap.

public void wrap(InputStream inStream, OutputStream outStream, MessageProp msgProp) throws GSSException {
    try {
        byte[] data = new byte[inStream.available()];
        int length = inStream.read(data);
        byte[] token = wrap(data, 0, length, msgProp);
        outStream.write(token);
    } catch (IOException ioe) {
        throw new GSSExceptionImpl(GSSException.FAILURE, ioe);
    }
}
Also used : GSSExceptionImpl(sun.security.jgss.GSSExceptionImpl)

Example 9 with GSSExceptionImpl

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

the class GSSNameElement method export.

public byte[] export() throws GSSException {
    byte[] nameVal = cStub.exportName(pName);
    // Need to strip off the mech Oid portion of the exported
    // bytes since GSSNameImpl class will subsequently add it.
    int pos = 0;
    if ((nameVal[pos++] != 0x04) || (nameVal[pos++] != 0x01))
        throw new GSSException(GSSException.BAD_NAME);
    int mechOidLen = (((0xFF & nameVal[pos++]) << 8) | (0xFF & nameVal[pos++]));
    ObjectIdentifier temp = null;
    try {
        DerInputStream din = new DerInputStream(nameVal, pos, mechOidLen);
        temp = new ObjectIdentifier(din);
    } catch (IOException e) {
        throw new GSSExceptionImpl(GSSException.BAD_NAME, e);
    }
    Oid mech2 = new Oid(temp.toString());
    assert (mech2.equals(getMechanism()));
    pos += mechOidLen;
    int mechPortionLen = (((0xFF & nameVal[pos++]) << 24) | ((0xFF & nameVal[pos++]) << 16) | ((0xFF & nameVal[pos++]) << 8) | (0xFF & nameVal[pos++]));
    if (mechPortionLen < 0) {
        throw new GSSException(GSSException.BAD_NAME);
    }
    byte[] mechPortion = new byte[mechPortionLen];
    System.arraycopy(nameVal, pos, mechPortion, 0, mechPortionLen);
    return mechPortion;
}
Also used : DerInputStream(sun.security.util.DerInputStream) IOException(java.io.IOException) GSSExceptionImpl(sun.security.jgss.GSSExceptionImpl) ObjectIdentifier(sun.security.util.ObjectIdentifier)

Aggregations

GSSExceptionImpl (sun.security.jgss.GSSExceptionImpl)9 GSSHeader (sun.security.jgss.GSSHeader)2 ObjectIdentifier (sun.security.util.ObjectIdentifier)2 IOException (java.io.IOException)1 NegTokenInit (sun.security.jgss.spnego.NegTokenInit)1 NegTokenTarg (sun.security.jgss.spnego.NegTokenTarg)1 DerInputStream (sun.security.util.DerInputStream)1 DerValue (sun.security.util.DerValue)1