Path: blob/master/src/java.security.jgss/share/classes/sun/security/krb5/internal/PaPacOptions.java
41161 views
/*1* Copyright (c) 2019, Red Hat, Inc.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.security.krb5.internal;2627import java.io.IOException;28import sun.security.krb5.Asn1Exception;29import sun.security.krb5.internal.util.KerberosFlags;30import sun.security.util.DerOutputStream;31import sun.security.util.DerValue;3233/**34* Implements the ASN.1 PA-PAC-OPTIONS type.35*36* <pre>{@code37* PA-PAC-OPTIONS ::= SEQUENCE {38* KerberosFlags39* -- Claims (0)40* -- Branch Aware (1)41* -- Forward to Full DC (2)42* }43* Note: KerberosFlags ::= BIT STRING (SIZE (32..MAX))44* -- minimum number of bits shall be sent, but no fewer than 3245*46* PA-PAC-OPTIONS ::= KerberosFlags47* -- resource-based constrained delegation (3)48* }</pre>49*50* This definition reflects MS-KILE (section 2.2.10)51* and MS-SFU (section 2.2.5).52*/5354public class PaPacOptions {5556private static final int CLAIMS = 0;57private static final int BRANCH_AWARE = 1;58private static final int FORWARD_TO_FULL_DC = 2;59private static final int RESOURCE_BASED_CONSTRAINED_DELEGATION = 3;6061private KerberosFlags flags;6263public PaPacOptions() {64this.flags = new KerberosFlags(Krb5.AP_OPTS_MAX + 1);65}6667/**68* Constructs a PA-PAC-OPTIONS object from a DER encoding.69* @param encoding the ASN.1 encoded input70* @throws Asn1Exception if invalid DER71* @throws IOException if there is an error reading the DER value72*/73public PaPacOptions(DerValue encoding) throws Asn1Exception, IOException {74if (encoding.getTag() != DerValue.tag_Sequence) {75throw new Asn1Exception(Krb5.ASN1_BAD_ID);76}7778DerValue der = encoding.getData().getDerValue();79if ((der.getTag() & 0x1F) == 0x00) {80flags = new KDCOptions(81der.getData().getDerValue());82} else {83throw new Asn1Exception(Krb5.ASN1_BAD_ID);84}85}8687/**88* Setter for the claims flag89* @param value whether the claims flag is set or not90* @return the same PaPacOptions instance91*/92public PaPacOptions setClaims(boolean value) {93flags.set(CLAIMS, value);94return this;95}9697/**98* Getter for the claims flag99* @return the claims flag value100*/101public boolean getClaims() {102return flags.get(CLAIMS);103}104105/**106* Setter for the branch-aware flag107* @param value whether the branch-aware flag is set or not108* @return the same PaPacOptions instance109*/110public PaPacOptions setBranchAware(boolean value) {111flags.set(BRANCH_AWARE, value);112return this;113}114115/**116* Getter for the branch-aware flag117* @return the branch-aware flag value118*/119public boolean getBranchAware() {120return flags.get(BRANCH_AWARE);121}122123/**124* Setter for the forward-to-full-DC flag125* @param value whether the forward-to-full-DC flag is set or not126* @return the same PaPacOptions instance127*/128public PaPacOptions setForwardToFullDC(boolean value) {129flags.set(FORWARD_TO_FULL_DC, value);130return this;131}132133/**134* Getter for the forward-to-full-DC flag135* @return the forward-to-full-DC flag value136*/137public boolean getForwardToFullDC() {138return flags.get(FORWARD_TO_FULL_DC);139}140141/**142* Setter for the resource-based-constrained-delegation flag143* @param value whether the resource-based-constrained-delegation144* is set or not145* @return the same PaPacOptions instance146*/147public PaPacOptions setResourceBasedConstrainedDelegation(boolean value) {148flags.set(RESOURCE_BASED_CONSTRAINED_DELEGATION, value);149return this;150}151152/**153* Getter for the resource-based-constrained-delegation flag154* @return the resource-based-constrained-delegation flag value155*/156public boolean getResourceBasedConstrainedDelegation() {157return flags.get(RESOURCE_BASED_CONSTRAINED_DELEGATION);158}159160/**161* Encodes this PaPacOptions instance.162* @return an ASN.1 encoded PaPacOptions byte array163* @throws IOException if an I/O error occurs while encoding this164* PaPacOptions instance165*/166public byte[] asn1Encode() throws IOException {167byte[] bytes = null;168try(DerOutputStream temp = new DerOutputStream()) {169temp.write(170DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00),171flags.asn1Encode());172bytes = temp.toByteArray();173}174try(DerOutputStream temp = new DerOutputStream()) {175temp.write(DerValue.tag_Sequence, bytes);176return temp.toByteArray();177}178}179180@Override181public String toString() {182return flags.toString();183}184}185186187