001    /* MessageProp.java -- GSS-API message property.
002       Copyright (C) 2004 Free Software Foundation, Inc.
003    
004    This file is part of GNU Classpath.
005    
006    GNU Classpath is free software; you can redistribute it and/or modify
007    it under the terms of the GNU General Public License as published by
008    the Free Software Foundation; either version 2, or (at your option)
009    any later version.
010    
011    GNU Classpath is distributed in the hope that it will be useful, but
012    WITHOUT ANY WARRANTY; without even the implied warranty of
013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014    General Public License for more details.
015    
016    You should have received a copy of the GNU General Public License
017    along with GNU Classpath; see the file COPYING.  If not, write to the
018    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
019    02110-1301 USA.
020    
021    Linking this library statically or dynamically with other modules is
022    making a combined work based on this library.  Thus, the terms and
023    conditions of the GNU General Public License cover the whole
024    combination.
025    
026    As a special exception, the copyright holders of this library give you
027    permission to link this library with independent modules to produce an
028    executable, regardless of the license terms of these independent
029    modules, and to copy and distribute the resulting executable under
030    terms of your choice, provided that you also meet, for each linked
031    independent module, the terms and conditions of the license of that
032    module.  An independent module is a module which is not derived from
033    or based on this library.  If you modify this library, you may extend
034    this exception to your version of the library, but you are not
035    obligated to do so.  If you do not wish to do so, delete this
036    exception statement from your version.
037    
038       The documentation comments of this class are derived from the text
039       of RFC 2853:  Generic Security Service API Version 2: Java Bindings.
040       That document is covered under the following license notice:
041    
042    Copyright (C) The Internet Society (2000).  All Rights Reserved.
043    
044    This document and translations of it may be copied and furnished to
045    others, and derivative works that comment on or otherwise explain it
046    or assist in its implementation may be prepared, copied, published and
047    distributed, in whole or in part, without restriction of any kind,
048    provided that the above copyright notice and this paragraph are
049    included on all such copies and derivative works.  However, this
050    document itself may not be modified in any way, such as by removing
051    the copyright notice or references to the Internet Society or other
052    Internet organizations, except as needed for the purpose of developing
053    Internet standards in which case the procedures for copyrights defined
054    in the Internet Standards process must be followed, or as required to
055    translate it into languages other than English.
056    
057    The limited permissions granted above are perpetual and will not be
058    revoked by the Internet Society or its successors or assigns.
059    
060    This document and the information contained herein is provided on an
061    "AS IS" basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING
062    TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT
063    NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION HEREIN
064    WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF
065    MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. */
066    
067    
068    package org.ietf.jgss;
069    
070    /**
071     * <p>This is a utility class used within the per-message {@link
072     * GSSContext} methods to convey per-message properties.</p>
073     *
074     * <p>When used with the GSSContext interface's {@link
075     * GSSContext#wrap(byte[],int,int,org.ietf.jgss.MessageProp)} and {@link
076     * GSSContext#getMIC(byte[],int,int,org.ietf.jgss.MessageProp)} methods, an
077     * instance of this class is used to indicate the desired QOP and to
078     * request if confidentiality services are to be applied to caller
079     * supplied data (wrap only).  To request default QOP, the value of 0
080     * should be used for QOP.</p>
081     *
082     * <p>When used with the {@link
083     * GSSContext#unwrap(byte[],int,int,org.ietf.jgss.MessageProp)} and {@link
084     * GSSContext#verifyMIC(byte[],int,int,byte[],int,int,org.ietf.jgss.MessageProp)}
085     * methods of the GSSContext interface, an instance of this class will be
086     * used to indicate the applied QOP and confidentiality services over the
087     * supplied message. In the case of verifyMIC, the confidentiality state
088     * will always be "false".  Upon return from these methods, this object will
089     * also contain any supplementary status values applicable to the processed
090     * token.  The supplementary status values can indicate old tokens, out
091     * of sequence tokens, gap tokens or duplicate tokens.</p>
092     */
093    public class MessageProp
094    {
095    
096      // Fields.
097      // -------------------------------------------------------------------------
098    
099      private int qopVal;
100      private boolean privState;
101      private boolean duplicate;
102      private boolean old;
103      private boolean unseq;
104      private boolean gap;
105      private int minorStatus;
106      private String minorString;
107    
108      // Constructors.
109      // -------------------------------------------------------------------------
110    
111      /**
112       * <p>Constructor which sets QOP to 0 indicating that the default QOP is
113       * requested.</p>
114       *
115       * @param privState The desired privacy state. "true" for privacy and
116       *                  "false" for integrity only.
117       */
118      public MessageProp(boolean privState)
119      {
120        this(0, privState);
121      }
122    
123      /**
124       * <p>Constructor which sets the values for the qop and privacy state.</p>
125       *
126       * @param qop       The desired QOP.  Use 0 to request a default QOP.
127       * @param privState The desired privacy state. "true" for privacy and
128       *                  "false" for integrity only.
129       */
130      public MessageProp(int qop, boolean privState)
131      {
132        this.qopVal = qop;
133        this.privState = privState;
134      }
135    
136      // Instance methods.
137      // -------------------------------------------------------------------------
138    
139      /**
140       * Retrieves the QOP value.
141       *
142       * @return The QOP value.
143       */
144      public int getQOP()
145      {
146        return qopVal;
147      }
148    
149      /**
150       * Retrieves the privacy state.
151       *
152       * @return The privacy state.
153       */
154      public boolean getPrivacy()
155      {
156        return privState;
157      }
158    
159      /**
160       * Retrieves the minor status that the underlying mechanism might have
161       * set.
162       *
163       * @return The minor status.
164       */
165      public int getMinorStatus()
166      {
167        return minorStatus;
168      }
169    
170      /**
171       * Returns a string explaining the mechanism specific error code.
172       * <code>null</code> will be returned when no mechanism error code has
173       * been set.
174       *
175       * @return The minor status string.
176       */
177      public String getMinorString()
178      {
179        return minorString;
180      }
181    
182      /**
183       * Sets the QOP value.
184       *
185       * @param qopVal The QOP value to be set.  Use 0 to request a default
186       *               QOP value.
187       */
188      public void setQOP(int qopVal)
189      {
190        this.qopVal = qopVal;
191      }
192    
193      /**
194       * Sets the privacy state.
195       *
196       * @param privState The privacy state to set.
197       */
198      public void setPrivacy(boolean privState)
199      {
200        this.privState = privState;
201      }
202    
203      /**
204       * Returns "true" if this is a duplicate of an earlier token.
205       *
206       * @return True if this is a duplicate of an earlier token.
207       */
208      public boolean isDuplicateToken()
209      {
210        return duplicate;
211      }
212    
213      /**
214       * Returns "true" if the token's validity period has expired.
215       *
216       * @return True if the token's validity period has expired.
217       */
218      public boolean isOldToken()
219      {
220        return old;
221      }
222    
223      /**
224       * Returns "true" if a later token has already been processed.
225       *
226       * @return True if a later token has already been processed.
227       */
228      public boolean isUnseqToken()
229      {
230        return unseq;
231      }
232    
233      /**
234       * Returns "true" if an expected per-message token was not received.
235       *
236       * @return True if an expected per-message token was not received.
237       */
238      public boolean isGapToken()
239      {
240        return gap;
241      }
242    
243      /**
244       * This method sets the state for the supplementary information flags
245       * and the minor status in MessageProp.  It is not used by the
246       * application but by the GSS implementation to return this information
247       * to the caller of a per-message context method.
248       *
249       * @param duplicate   True if the token was a duplicate of an earlier
250       *                    token, false otherwise.
251       * @param old         True if the token's validity period has expired,
252       *                    false otherwise.
253       * @param unseq       True if a later token has already been processed,
254       *                    false otherwise.
255       * @param gap         True if one or more predecessor tokens have not yet
256       *                    been successfully processed, false otherwise.
257       * @param minorStatus The integer minor status code that the underlying
258       *                    mechanism wants to set.
259       * @param minorString The textual representation of the minorStatus
260       *                    value.
261       */
262      public void setSupplementaryStates(boolean duplicate, boolean old,
263                                         boolean unseq, boolean gap,
264                                         int minorStatus, String minorString)
265      {
266        this.duplicate = duplicate;
267        this.old = old;
268        this.unseq = unseq;
269        this.gap = gap;
270        this.minorStatus = minorStatus;
271        this.minorString = minorString;
272      }
273    }