0N/A/*
2362N/A * Copyright (c) 2000, 2006, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage sun.security.jgss.krb5;
0N/A
0N/Aimport org.ietf.jgss.*;
0N/Aimport java.io.InputStream;
0N/Aimport java.io.OutputStream;
0N/Aimport java.io.IOException;
0N/Aimport java.io.ByteArrayInputStream;
0N/Aimport java.io.ByteArrayOutputStream;
0N/A
0N/Aclass MicToken extends MessageToken {
0N/A
0N/A public MicToken(Krb5Context context,
0N/A byte[] tokenBytes, int tokenOffset, int tokenLen,
0N/A MessageProp prop) throws GSSException {
0N/A super(Krb5Token.MIC_ID, context,
0N/A tokenBytes, tokenOffset, tokenLen, prop);
0N/A }
0N/A
0N/A public MicToken(Krb5Context context,
0N/A InputStream is, MessageProp prop)
0N/A throws GSSException {
0N/A super(Krb5Token.MIC_ID, context, is, prop);
0N/A }
0N/A
0N/A public void verify(byte[] data, int offset, int len) throws GSSException {
0N/A if (!verifySignAndSeqNumber(null, data, offset, len, null))
0N/A throw new GSSException(GSSException.BAD_MIC, -1,
0N/A "Corrupt checksum or sequence number in MIC token");
0N/A }
0N/A
0N/A public void verify(InputStream data) throws GSSException {
0N/A byte[] dataBytes = null;
0N/A try {
0N/A dataBytes = new byte[data.available()];
0N/A data.read(dataBytes);
0N/A } catch (IOException e) {
0N/A // Error reading application data
0N/A throw new GSSException(GSSException.BAD_MIC, -1,
0N/A "Corrupt checksum or sequence number in MIC token");
0N/A }
0N/A verify(dataBytes, 0, dataBytes.length);
0N/A }
0N/A
0N/A public MicToken(Krb5Context context, MessageProp prop,
0N/A byte[] data, int pos, int len)
0N/A throws GSSException {
0N/A super(Krb5Token.MIC_ID, context);
0N/A
0N/A // debug("Application data to MicToken verify is [" +
0N/A // getHexBytes(data, pos, len) + "]\n");
0N/A if (prop == null) prop = new MessageProp(0, false);
0N/A genSignAndSeqNumber(prop, null, data, pos, len, null);
0N/A }
0N/A
0N/A public MicToken(Krb5Context context, MessageProp prop,
0N/A InputStream data)
0N/A throws GSSException, IOException {
0N/A super(Krb5Token.MIC_ID, context);
0N/A byte[] dataBytes = new byte[data.available()];
0N/A data.read(dataBytes);
0N/A
0N/A //debug("Application data to MicToken cons is [" +
0N/A // getHexBytes(dataBytes) + "]\n");
0N/A if (prop == null) prop = new MessageProp(0, false);
0N/A genSignAndSeqNumber(prop, null, dataBytes, 0, dataBytes.length, null);
0N/A }
0N/A
0N/A protected int getSealAlg(boolean confRequested, int qop) {
0N/A return (SEAL_ALG_NONE);
0N/A }
0N/A
0N/A public int encode(byte[] outToken, int offset)
0N/A throws IOException, GSSException {
0N/A // Token is small
0N/A ByteArrayOutputStream bos = new ByteArrayOutputStream();
0N/A super.encode(bos);
0N/A byte[] token = bos.toByteArray();
0N/A System.arraycopy(token, 0, outToken, offset, token.length);
0N/A return token.length;
0N/A }
0N/A
0N/A public byte[] encode() throws IOException, GSSException{
0N/A // XXX Fine tune this initial size
0N/A ByteArrayOutputStream bos = new ByteArrayOutputStream(50);
0N/A encode(bos);
0N/A return bos.toByteArray();
0N/A }
0N/A
0N/A}