0N/A/*
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/A/*
0N/A *
0N/A * (C) Copyright IBM Corp. 1999 All Rights Reserved.
0N/A * Copyright 1997 The Open Group Research Institute. All rights reserved.
0N/A */
0N/A
0N/Apackage sun.security.krb5.internal;
0N/A
0N/Aimport sun.security.krb5.*;
0N/Aimport sun.security.util.*;
0N/Aimport java.util.Vector;
0N/Aimport java.io.IOException;
0N/A
0N/A/**
0N/A * Implements the ASN.1 KrbCredInfo type.
0N/A *
0N/A * <xmp>
0N/A * KrbCredInfo ::= SEQUENCE {
0N/A * key [0] EncryptionKey,
0N/A * prealm [1] Realm OPTIONAL,
0N/A * pname [2] PrincipalName OPTIONAL,
0N/A * flags [3] TicketFlags OPTIONAL,
0N/A * authtime [4] KerberosTime OPTIONAL,
0N/A * starttime [5] KerberosTime OPTIONAL,
0N/A * endtime [6] KerberosTime OPTIONAL,
0N/A * renew-till [7] KerberosTime OPTIONAL,
0N/A * srealm [8] Realm OPTIONAL,
0N/A * sname [9] PrincipalName OPTIONAL,
0N/A * caddr [10] HostAddresses OPTIONAL
0N/A * }
0N/A * </xmp>
0N/A *
0N/A * <p>
0N/A * This definition reflects the Network Working Group RFC 4120
0N/A * specification available at
0N/A * <a href="http://www.ietf.org/rfc/rfc4120.txt">
0N/A * http://www.ietf.org/rfc/rfc4120.txt</a>.
0N/A */
0N/A
0N/Apublic class KrbCredInfo {
0N/A public EncryptionKey key;
0N/A public Realm prealm; //optional
0N/A public PrincipalName pname; //optional
0N/A public TicketFlags flags; //optional
0N/A public KerberosTime authtime; //optional
0N/A public KerberosTime starttime; //optional
0N/A public KerberosTime endtime; //optional
0N/A public KerberosTime renewTill; //optional
0N/A public Realm srealm; //optional
0N/A public PrincipalName sname; //optional
0N/A public HostAddresses caddr; //optional
0N/A
0N/A private KrbCredInfo() {
0N/A }
0N/A
0N/A public KrbCredInfo(
0N/A EncryptionKey new_key,
0N/A Realm new_prealm,
0N/A PrincipalName new_pname,
0N/A TicketFlags new_flags,
0N/A KerberosTime new_authtime,
0N/A KerberosTime new_starttime,
0N/A KerberosTime new_endtime,
0N/A KerberosTime new_renewTill,
0N/A Realm new_srealm,
0N/A PrincipalName new_sname,
0N/A HostAddresses new_caddr
0N/A ) {
0N/A key = new_key;
0N/A prealm = new_prealm;
0N/A pname = new_pname;
0N/A flags = new_flags;
0N/A authtime = new_authtime;
0N/A starttime = new_starttime;
0N/A endtime = new_endtime;
0N/A renewTill = new_renewTill;
0N/A srealm = new_srealm;
0N/A sname = new_sname;
0N/A caddr = new_caddr;
0N/A }
0N/A
0N/A /**
0N/A * Constructs a KrbCredInfo object.
0N/A * @param encoding a Der-encoded data.
0N/A * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
0N/A * @exception IOException if an I/O error occurs while reading encoded data.
0N/A * @exception RealmException if an error occurs while parsing a Realm object.
0N/A */
0N/A public KrbCredInfo(DerValue encoding)
50N/A throws Asn1Exception, IOException, RealmException{
0N/A if (encoding.getTag() != DerValue.tag_Sequence) {
0N/A throw new Asn1Exception(Krb5.ASN1_BAD_ID);
0N/A }
0N/A prealm = null;
0N/A pname = null;
0N/A flags = null;
0N/A authtime = null;
0N/A starttime = null;
0N/A endtime = null;
0N/A renewTill = null;
0N/A srealm = null;
0N/A sname = null;
0N/A caddr = null;
0N/A key = EncryptionKey.parse(encoding.getData(), (byte)0x00, false);
0N/A if (encoding.getData().available() > 0)
0N/A prealm = Realm.parse(encoding.getData(), (byte)0x01, true);
0N/A if (encoding.getData().available() > 0)
0N/A pname = PrincipalName.parse(encoding.getData(), (byte)0x02, true);
0N/A if (encoding.getData().available() > 0)
0N/A flags = TicketFlags.parse(encoding.getData(), (byte)0x03, true);
0N/A if (encoding.getData().available() > 0)
0N/A authtime = KerberosTime.parse(encoding.getData(), (byte)0x04, true);
0N/A if (encoding.getData().available() > 0)
0N/A starttime = KerberosTime.parse(encoding.getData(), (byte)0x05, true);
0N/A if (encoding.getData().available() > 0)
0N/A endtime = KerberosTime.parse(encoding.getData(), (byte)0x06, true);
0N/A if (encoding.getData().available() > 0)
0N/A renewTill = KerberosTime.parse(encoding.getData(), (byte)0x07, true);
0N/A if (encoding.getData().available() > 0)
0N/A srealm = Realm.parse(encoding.getData(), (byte)0x08, true);
0N/A if (encoding.getData().available() > 0)
0N/A sname = PrincipalName.parse(encoding.getData(), (byte)0x09, true);
0N/A if (encoding.getData().available() > 0)
0N/A caddr = HostAddresses.parse(encoding.getData(), (byte)0x0A, true);
0N/A if (encoding.getData().available() > 0)
0N/A throw new Asn1Exception(Krb5.ASN1_BAD_ID);
0N/A }
0N/A
0N/A /**
0N/A * Encodes an KrbCredInfo object.
0N/A * @return the byte array of encoded KrbCredInfo object.
0N/A * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
0N/A * @exception IOException if an I/O error occurs while reading encoded data.
0N/A */
0N/A public byte[] asn1Encode() throws Asn1Exception, IOException {
3388N/A Vector<DerValue> v = new Vector<>();
0N/A v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), key.asn1Encode()));
0N/A if (prealm != null)
50N/A v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), prealm.asn1Encode()));
0N/A if (pname != null)
50N/A v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x02), pname.asn1Encode()));
0N/A if (flags != null)
50N/A v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x03), flags.asn1Encode()));
0N/A if (authtime != null)
50N/A v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x04), authtime.asn1Encode()));
0N/A if (starttime != null)
50N/A v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x05), starttime.asn1Encode()));
0N/A if (endtime != null)
50N/A v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x06), endtime.asn1Encode()));
0N/A if (renewTill != null)
50N/A v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x07), renewTill.asn1Encode()));
0N/A if (srealm != null)
50N/A v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x08), srealm.asn1Encode()));
0N/A if (sname != null)
50N/A v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x09), sname.asn1Encode()));
0N/A if (caddr != null)
50N/A v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x0A), caddr.asn1Encode()));
0N/A DerValue der[] = new DerValue[v.size()];
0N/A v.copyInto(der);
0N/A DerOutputStream out = new DerOutputStream();
0N/A out.putSequence(der);
0N/A return out.toByteArray();
0N/A }
0N/A
0N/A public Object clone() {
0N/A KrbCredInfo kcred = new KrbCredInfo();
0N/A kcred.key = (EncryptionKey)key.clone();
0N/A // optional fields
0N/A if (prealm != null)
0N/A kcred.prealm = (Realm)prealm.clone();
0N/A if (pname != null)
0N/A kcred.pname = (PrincipalName)pname.clone();
0N/A if (flags != null)
0N/A kcred.flags = (TicketFlags)flags.clone();
0N/A if (authtime != null)
0N/A kcred.authtime = (KerberosTime)authtime.clone();
0N/A if (starttime != null)
0N/A kcred.starttime = (KerberosTime)starttime.clone();
0N/A if (endtime != null)
0N/A kcred.endtime = (KerberosTime)endtime.clone();
0N/A if (renewTill != null)
0N/A kcred.renewTill = (KerberosTime)renewTill.clone();
0N/A if (srealm != null)
0N/A kcred.srealm = (Realm)srealm.clone();
0N/A if (sname != null)
0N/A kcred.sname = (PrincipalName)sname.clone();
0N/A if (caddr != null)
0N/A kcred.caddr = (HostAddresses)caddr.clone();
0N/A return kcred;
0N/A }
0N/A
0N/A}