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.Config;
0N/Aimport sun.security.krb5.KrbException;
0N/Aimport sun.security.krb5.Asn1Exception;
0N/Aimport sun.security.krb5.internal.util.KerberosFlags;
0N/Aimport sun.security.util.*;
0N/Aimport java.io.IOException;
0N/A
0N/A/**
0N/A * Implements the ASN.1 KDCOptions type.
0N/A *
0N/A * <xmp>
0N/A * KDCOptions ::= KerberosFlags
0N/A * -- reserved(0),
0N/A * -- forwardable(1),
0N/A * -- forwarded(2),
0N/A * -- proxiable(3),
0N/A * -- proxy(4),
0N/A * -- allow-postdate(5),
0N/A * -- postdated(6),
0N/A * -- unused7(7),
0N/A * -- renewable(8),
0N/A * -- unused9(9),
0N/A * -- unused10(10),
0N/A * -- opt-hardware-auth(11),
0N/A * -- unused12(12),
0N/A * -- unused13(13),
0N/A * -- 15 is reserved for canonicalize
0N/A * -- unused15(15),
0N/A * -- 26 was unused in 1510
0N/A * -- disable-transited-check(26),
0N/A * -- renewable-ok(27),
0N/A * -- enc-tkt-in-skey(28),
0N/A * -- renew(30),
0N/A * -- validate(31)
0N/A *
0N/A * KerberosFlags ::= BIT STRING (SIZE (32..MAX))
0N/A * -- minimum number of bits shall be sent,
0N/A * -- but no fewer than 32
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 * <p>
0N/A * This class appears as data field in the initial request(KRB_AS_REQ)
0N/A * or subsequent request(KRB_TGS_REQ) to the KDC and indicates the flags
0N/A * that the client wants to set on the tickets.
0N/A *
0N/A * The optional bits are:
0N/A * <UL>
0N/A * <LI>KDCOptions.RESERVED
0N/A * <LI>KDCOptions.FORWARDABLE
0N/A * <LI>KDCOptions.FORWARDED
0N/A * <LI>KDCOptions.PROXIABLE
0N/A * <LI>KDCOptions.PROXY
0N/A * <LI>KDCOptions.ALLOW_POSTDATE
0N/A * <LI>KDCOptions.POSTDATED
0N/A * <LI>KDCOptions.RENEWABLE
0N/A * <LI>KDCOptions.RENEWABLE_OK
0N/A * <LI>KDCOptions.ENC_TKT_IN_SKEY
0N/A * <LI>KDCOptions.RENEW
0N/A * <LI>KDCOptions.VALIDATE
0N/A * </UL>
0N/A * <p> Various checks must be made before honoring an option. The restrictions
0N/A * on the use of some options are as follows:
0N/A * <ol>
0N/A * <li> FORWARDABLE, FORWARDED, PROXIABLE, RENEWABLE options may be set in
0N/A * subsequent request only if the ticket_granting ticket on which it is based has
0N/A * the same options (FORWARDABLE, FORWARDED, PROXIABLE, RENEWABLE) set.
0N/A * <li> ALLOW_POSTDATE may be set in subsequent request only if the
0N/A * ticket-granting ticket on which it is based also has its MAY_POSTDATE flag set.
0N/A * <li> POSTDATED may be set in subsequent request only if the
0N/A * ticket-granting ticket on which it is based also has its MAY_POSTDATE flag set.
0N/A * <li> RENEWABLE or RENEW may be set in subsequent request only if the
0N/A * ticket-granting ticket on which it is based also has its RENEWABLE flag set.
0N/A * <li> POXY may be set in subsequent request only if the ticket-granting ticket
0N/A * on which it is based also has its PROXIABLE flag set, and the address(es) of
0N/A * the host from which the resulting ticket is to be valid should be included
0N/A * in the addresses field of the request.
0N/A * <li>FORWARDED, PROXY, ENC_TKT_IN_SKEY, RENEW, VALIDATE are used only in
0N/A * subsequent requests.
0N/A * </ol><p>
0N/A */
0N/A
0N/Apublic class KDCOptions extends KerberosFlags {
0N/A
0N/A public final int KDC_OPT_PROXIABLE = 0x10000000;
0N/A public final int KDC_OPT_RENEWABLE_OK = 0x00000010;
0N/A public final int KDC_OPT_FORWARDABLE = 0x40000000;
0N/A
0N/A
0N/A // KDC Options
0N/A
0N/A public static final int RESERVED = 0;
0N/A public static final int FORWARDABLE = 1;
0N/A public static final int FORWARDED = 2;
0N/A public static final int PROXIABLE = 3;
0N/A public static final int PROXY = 4;
0N/A public static final int ALLOW_POSTDATE = 5;
0N/A public static final int POSTDATED = 6;
0N/A public static final int UNUSED7 = 7;
0N/A public static final int RENEWABLE = 8;
0N/A public static final int UNUSED9 = 9;
0N/A public static final int UNUSED10 = 10;
0N/A public static final int UNUSED11 = 11;
0N/A public static final int RENEWABLE_OK = 27;
0N/A public static final int ENC_TKT_IN_SKEY = 28;
0N/A public static final int RENEW = 30;
0N/A public static final int VALIDATE = 31;
0N/A
0N/A private boolean DEBUG = Krb5.DEBUG;
0N/A
0N/A public KDCOptions() {
0N/A super(Krb5.KDC_OPTS_MAX + 1);
0N/A setDefault();
0N/A }
0N/A
0N/A public KDCOptions(int size, byte[] data) throws Asn1Exception {
0N/A super(size, data);
0N/A if ((size > data.length * BITS_PER_UNIT) || (size > Krb5.KDC_OPTS_MAX + 1))
0N/A throw new Asn1Exception(Krb5.BITSTRING_BAD_LENGTH);
0N/A }
0N/A
0N/A /**
0N/A * Constructs a KDCOptions from the specified bit settings.
0N/A *
0N/A * @param data the bits to be set for the KDCOptions.
0N/A * @exception Asn1Exception if an error occurs while decoding an ASN1
0N/A * encoded data.
0N/A *
0N/A */
0N/A public KDCOptions(boolean[] data) throws Asn1Exception {
0N/A super(data);
0N/A if (data.length > Krb5.KDC_OPTS_MAX + 1) {
0N/A throw new Asn1Exception(Krb5.BITSTRING_BAD_LENGTH);
0N/A }
0N/A }
0N/A
0N/A public KDCOptions(DerValue encoding) throws Asn1Exception, IOException {
0N/A this(encoding.getUnalignedBitString(true).toBooleanArray());
0N/A }
0N/A
0N/A /**
0N/A * Constructs a KDCOptions from the passed bit settings.
0N/A *
0N/A * @param options the bits to be set for the KDCOptions.
0N/A *
0N/A */
0N/A public KDCOptions(byte[] options) {
0N/A super(options.length * BITS_PER_UNIT, options);
0N/A }
0N/A
0N/A /**
0N/A * Parse (unmarshal) a KDCOptions from a DER input stream. This form
0N/A * parsing might be used when expanding a value which is part of
0N/A * a constructed sequence and uses explicitly tagged type.
0N/A *
0N/A * @param data the Der input stream value, which contains one or more
0N/A * marshaled value.
0N/A * @param explicitTag tag number.
0N/A * @param optional indicate if this data field is optional
0N/A * @return an instance of KDCOptions.
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 */
0N/A
0N/A public static KDCOptions parse(DerInputStream data, byte explicitTag, boolean optional) throws Asn1Exception, IOException {
0N/A if ((optional) && (((byte)data.peekByte() & (byte)0x1F) != explicitTag))
0N/A return null;
0N/A DerValue der = data.getDerValue();
0N/A if (explicitTag != (der.getTag() & (byte)0x1F)) {
0N/A throw new Asn1Exception(Krb5.ASN1_BAD_ID);
0N/A } else {
0N/A DerValue subDer = der.getData().getDerValue();
0N/A return new KDCOptions(subDer);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Sets the value(true/false) for one of the <code>KDCOptions</code>.
0N/A *
0N/A * @param option an option bit.
0N/A * @param value true if the option is selected, false if the option is not selected.
0N/A * @exception ArrayIndexOutOfBoundsException if array index out of bound occurs.
0N/A * @see sun.security.krb5.internal.Krb5
0N/A */
0N/A public void set(int option, boolean value) throws ArrayIndexOutOfBoundsException {
0N/A super.set(option, value);
0N/A }
0N/A
0N/A /**
0N/A * Gets the value(true/false) for one of the <code>KDCOptions</code>.
0N/A *
0N/A * @param option an option bit.
0N/A * @return value true if the option is selected, false if the option is not selected.
0N/A * @exception ArrayIndexOutOfBoundsException if array index out of bound occurs.
0N/A * @see sun.security.krb5.internal.Krb5
0N/A */
0N/A
0N/A public boolean get(int option) throws ArrayIndexOutOfBoundsException {
0N/A return super.get(option);
0N/A }
0N/A
0N/A
0N/A private void setDefault() {
0N/A try {
0N/A
0N/A Config config = Config.getInstance();
0N/A
0N/A /*
0N/A * First see if the IBM hex format is being used.
0N/A * If not, try the Sun's string (boolean) format.
0N/A */
0N/A
0N/A int options =config.getDefaultIntValue("kdc_default_options",
0N/A "libdefaults");
0N/A
0N/A if ((options & RENEWABLE_OK) == RENEWABLE_OK) {
0N/A set(RENEWABLE_OK, true);
0N/A } else {
0N/A if (config.getDefaultBooleanValue("renewable", "libdefaults")) {
0N/A set(RENEWABLE_OK, true);
0N/A }
0N/A }
0N/A if ((options & PROXIABLE) == PROXIABLE) {
0N/A set(PROXIABLE, true);
0N/A } else {
0N/A if (config.getDefaultBooleanValue("proxiable", "libdefaults")) {
0N/A set(PROXIABLE, true);
0N/A }
0N/A }
0N/A
0N/A if ((options & FORWARDABLE) == FORWARDABLE) {
0N/A set(FORWARDABLE, true);
0N/A } else {
0N/A if (config.getDefaultBooleanValue("forwardable", "libdefaults")) {
0N/A set(FORWARDABLE, true);
0N/A }
0N/A }
0N/A } catch (KrbException e) {
0N/A if (DEBUG) {
0N/A System.out.println("Exception in getting default values for " +
0N/A "KDC Options from the configuration ");
0N/A e.printStackTrace();
0N/A
0N/A }
0N/A }
0N/A }
0N/A}