001/* MessageProp.java -- GSS-API message property. 002 Copyright (C) 2004 Free Software Foundation, Inc. 003 004This file is part of GNU Classpath. 005 006GNU Classpath is free software; you can redistribute it and/or modify 007it under the terms of the GNU General Public License as published by 008the Free Software Foundation; either version 2, or (at your option) 009any later version. 010 011GNU Classpath is distributed in the hope that it will be useful, but 012WITHOUT ANY WARRANTY; without even the implied warranty of 013MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014General Public License for more details. 015 016You should have received a copy of the GNU General Public License 017along with GNU Classpath; see the file COPYING. If not, write to the 018Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 01902110-1301 USA. 020 021Linking this library statically or dynamically with other modules is 022making a combined work based on this library. Thus, the terms and 023conditions of the GNU General Public License cover the whole 024combination. 025 026As a special exception, the copyright holders of this library give you 027permission to link this library with independent modules to produce an 028executable, regardless of the license terms of these independent 029modules, and to copy and distribute the resulting executable under 030terms of your choice, provided that you also meet, for each linked 031independent module, the terms and conditions of the license of that 032module. An independent module is a module which is not derived from 033or based on this library. If you modify this library, you may extend 034this exception to your version of the library, but you are not 035obligated to do so. If you do not wish to do so, delete this 036exception 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 042Copyright (C) The Internet Society (2000). All Rights Reserved. 043 044This document and translations of it may be copied and furnished to 045others, and derivative works that comment on or otherwise explain it 046or assist in its implementation may be prepared, copied, published and 047distributed, in whole or in part, without restriction of any kind, 048provided that the above copyright notice and this paragraph are 049included on all such copies and derivative works. However, this 050document itself may not be modified in any way, such as by removing 051the copyright notice or references to the Internet Society or other 052Internet organizations, except as needed for the purpose of developing 053Internet standards in which case the procedures for copyrights defined 054in the Internet Standards process must be followed, or as required to 055translate it into languages other than English. 056 057The limited permissions granted above are perpetual and will not be 058revoked by the Internet Society or its successors or assigns. 059 060This document and the information contained herein is provided on an 061"AS IS" basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING 062TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT 063NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION HEREIN 064WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF 065MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. */ 066 067 068package 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 */ 093public 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}