Path: blob/master/src/java.security.jgss/share/classes/org/ietf/jgss/MessageProp.java
41155 views
/*1* Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.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 org.ietf.jgss;2627/**28* This is a utility class used within the per-message GSSContext29* methods to convey per-message properties.<p>30*31* When used with the GSSContext interface's wrap and getMIC methods, an32* instance of this class is used to indicate the desired33* Quality-of-Protection (QOP) and to request if confidentiality services34* are to be applied to caller supplied data (wrap only). To request35* default QOP, the value of 0 should be used for QOP.<p>36*37* When used with the unwrap and verifyMIC methods of the GSSContext38* interface, an instance of this class will be used to indicate the39* applied QOP and confidentiality services over the supplied message.40* In the case of verifyMIC, the confidentiality state will always be41* <code>false</code>. Upon return from these methods, this object will also42* contain any supplementary status values applicable to the processed43* token. The supplementary status values can indicate old tokens, out44* of sequence tokens, gap tokens or duplicate tokens.45*46* @see GSSContext#wrap47* @see GSSContext#unwrap48* @see GSSContext#getMIC49* @see GSSContext#verifyMIC50*51* @author Mayank Upadhyay52* @since 1.453*/54public class MessageProp {5556private boolean privacyState;57private int qop;58private boolean dupToken;59private boolean oldToken;60private boolean unseqToken;61private boolean gapToken;62private int minorStatus;63private String minorString;6465/**66* Constructor which sets the desired privacy state. The QOP value used67* is 0.68*69* @param privState the privacy (i.e. confidentiality) state70*/71public MessageProp(boolean privState) {72this(0, privState);73}7475/**76* Constructor which sets the values for the qop and privacy state.77*78* @param qop the QOP value79* @param privState the privacy (i.e. confidentiality) state80*/81public MessageProp(int qop, boolean privState) {82this.qop = qop;83this.privacyState = privState;84resetStatusValues();85}8687/**88* Retrieves the QOP value.89*90* @return an int representing the QOP value91* @see #setQOP92*/93public int getQOP() {94return qop;95}9697/**98* Retrieves the privacy state.99*100* @return true if the privacy (i.e., confidentiality) state is true,101* false otherwise.102* @see #setPrivacy103*/104public boolean getPrivacy() {105106return (privacyState);107}108109/**110* Sets the QOP value.111*112* @param qop the int value to set the QOP to113* @see #getQOP114*/115public void setQOP(int qop) {116this.qop = qop;117}118119120/**121* Sets the privacy state.122*123* @param privState true is the privacy (i.e., confidentiality) state124* is true, false otherwise.125* @see #getPrivacy126*/127public void setPrivacy(boolean privState) {128129this.privacyState = privState;130}131132133/**134* Tests if this is a duplicate of an earlier token.135*136* @return true if this is a duplicate, false otherwise.137*/138public boolean isDuplicateToken() {139return dupToken;140}141142/**143* Tests if this token's validity period has expired, i.e., the token144* is too old to be checked for duplication.145*146* @return true if the token's validity period has expired, false147* otherwise.148*/149public boolean isOldToken() {150return oldToken;151}152153/**154* Tests if a later token had already been processed.155*156* @return true if a later token had already been processed, false otherwise.157*/158public boolean isUnseqToken() {159return unseqToken;160}161162/**163* Tests if an expected token was not received, i.e., one or more164* predecessor tokens have not yet been successfully processed.165*166* @return true if an expected per-message token was not received,167* false otherwise.168*/169public boolean isGapToken() {170return gapToken;171}172173/**174* Retrieves the minor status code that the underlying mechanism might175* have set for this per-message operation.176*177* @return the int minor status178*/179public int getMinorStatus(){180return minorStatus;181}182183/**184* Retrieves a string explaining the minor status code.185*186* @return a String corresponding to the minor status187* code. <code>null</code> will be returned when no minor status code188* has been set.189*/190public String getMinorString(){191return minorString;192}193194/**195* This method sets the state for the supplementary information flags196* and the minor status in MessageProp. It is not used by the197* application but by the GSS implementation to return this information198* to the caller of a per-message context method.199*200* @param duplicate true if the token was a duplicate of an earlier201* token, false otherwise202* @param old true if the token's validity period has expired, false203* otherwise204* @param unseq true if a later token has already been processed, false205* otherwise206* @param gap true if one or more predecessor tokens have not yet been207* successfully processed, false otherwise208* @param minorStatus the int minor status code for the per-message209* operation210* @param minorString the textual representation of the minorStatus value211*/212public void setSupplementaryStates(boolean duplicate,213boolean old, boolean unseq, boolean gap,214int minorStatus, String minorString) {215this.dupToken = duplicate;216this.oldToken = old;217this.unseqToken = unseq;218this.gapToken = gap;219this.minorStatus = minorStatus;220this.minorString = minorString;221}222223/**224* Resets the supplementary status values to false.225*/226private void resetStatusValues() {227dupToken = false;228oldToken = false;229unseqToken = false;230gapToken = false;231minorStatus = 0;232minorString = null;233}234}235236237