J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2000-2001 Sun Microsystems, Inc. All Rights Reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. Sun designates this |
| 8 | * particular file as subject to the "Classpath" exception as provided |
| 9 | * by Sun in the LICENSE file that accompanied this code. |
| 10 | * |
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | * version 2 for more details (a copy is included in the LICENSE file that |
| 15 | * accompanied this code). |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License version |
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
| 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 23 | * have any questions. |
| 24 | */ |
| 25 | |
| 26 | package org.ietf.jgss; |
| 27 | |
| 28 | /** |
| 29 | * This is a utility class used within the per-message GSSContext |
| 30 | * methods to convey per-message properties.<p> |
| 31 | * |
| 32 | * When used with the GSSContext interface's wrap and getMIC methods, an |
| 33 | * instance of this class is used to indicate the desired |
| 34 | * Quality-of-Protection (QOP) and to request if confidentiality services |
| 35 | * are to be applied to caller supplied data (wrap only). To request |
| 36 | * default QOP, the value of 0 should be used for QOP.<p> |
| 37 | * |
| 38 | * When used with the unwrap and verifyMIC methods of the GSSContext |
| 39 | * interface, an instance of this class will be used to indicate the |
| 40 | * applied QOP and confidentiality services over the supplied message. |
| 41 | * In the case of verifyMIC, the confidentiality state will always be |
| 42 | * <code>false</code>. Upon return from these methods, this object will also |
| 43 | * contain any supplementary status values applicable to the processed |
| 44 | * token. The supplementary status values can indicate old tokens, out |
| 45 | * of sequence tokens, gap tokens or duplicate tokens.<p> |
| 46 | * |
| 47 | * @see GSSContext#wrap |
| 48 | * @see GSSContext#unwrap |
| 49 | * @see GSSContext#getMIC |
| 50 | * @see GSSContext#verifyMIC |
| 51 | * |
| 52 | * @author Mayank Upadhyay |
| 53 | * @since 1.4 |
| 54 | */ |
| 55 | public class MessageProp { |
| 56 | |
| 57 | private boolean privacyState; |
| 58 | private int qop; |
| 59 | private boolean dupToken; |
| 60 | private boolean oldToken; |
| 61 | private boolean unseqToken; |
| 62 | private boolean gapToken; |
| 63 | private int minorStatus; |
| 64 | private String minorString; |
| 65 | |
| 66 | /** |
| 67 | * Constructor which sets the desired privacy state. The QOP value used |
| 68 | * is 0. |
| 69 | * |
| 70 | * @param privState the privacy (i.e. confidentiality) state |
| 71 | */ |
| 72 | public MessageProp(boolean privState) { |
| 73 | this(0, privState); |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Constructor which sets the values for the qop and privacy state. |
| 78 | * |
| 79 | * @param qop the QOP value |
| 80 | * @param privState the privacy (i.e. confidentiality) state |
| 81 | */ |
| 82 | public MessageProp(int qop, boolean privState) { |
| 83 | this.qop = qop; |
| 84 | this.privacyState = privState; |
| 85 | resetStatusValues(); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Retrieves the QOP value. |
| 90 | * |
| 91 | * @return an int representing the QOP value |
| 92 | * @see #setQOP |
| 93 | */ |
| 94 | public int getQOP() { |
| 95 | return qop; |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Retrieves the privacy state. |
| 100 | * |
| 101 | * @return true if the privacy (i.e., confidentiality) state is true, |
| 102 | * false otherwise. |
| 103 | * @see #setPrivacy |
| 104 | */ |
| 105 | public boolean getPrivacy() { |
| 106 | |
| 107 | return (privacyState); |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Sets the QOP value. |
| 112 | * |
| 113 | * @param qop the int value to set the QOP to |
| 114 | * @see #getQOP |
| 115 | */ |
| 116 | public void setQOP(int qop) { |
| 117 | this.qop = qop; |
| 118 | } |
| 119 | |
| 120 | |
| 121 | /** |
| 122 | * Sets the privacy state. |
| 123 | * |
| 124 | * @param privState true is the privacy (i.e., confidentiality) state |
| 125 | * is true, false otherwise. |
| 126 | * @see #getPrivacy |
| 127 | */ |
| 128 | public void setPrivacy(boolean privState) { |
| 129 | |
| 130 | this.privacyState = privState; |
| 131 | } |
| 132 | |
| 133 | |
| 134 | /** |
| 135 | * Tests if this is a duplicate of an earlier token. |
| 136 | * |
| 137 | * @return true if this is a duplicate, false otherwise. |
| 138 | */ |
| 139 | public boolean isDuplicateToken() { |
| 140 | return dupToken; |
| 141 | } |
| 142 | |
| 143 | /** |
| 144 | * Tests if this token's validity period has expired, i.e., the token |
| 145 | * is too old to be checked for duplication. |
| 146 | * |
| 147 | * @return true if the token's validity period has expired, false |
| 148 | * otherwise. |
| 149 | */ |
| 150 | public boolean isOldToken() { |
| 151 | return oldToken; |
| 152 | } |
| 153 | |
| 154 | /** |
| 155 | * Tests if a later token had already been processed. |
| 156 | * |
| 157 | * @return true if a later token had already been processed, false otherwise. |
| 158 | */ |
| 159 | public boolean isUnseqToken() { |
| 160 | return unseqToken; |
| 161 | } |
| 162 | |
| 163 | /** |
| 164 | * Tests if an expected token was not received, i.e., one or more |
| 165 | * predecessor tokens have not yet been successfully processed. |
| 166 | * |
| 167 | * @return true if an expected per-message token was not received, |
| 168 | * false otherwise. |
| 169 | */ |
| 170 | public boolean isGapToken() { |
| 171 | return gapToken; |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * Retrieves the minor status code that the underlying mechanism might |
| 176 | * have set for this per-message operation. |
| 177 | * |
| 178 | * @return the int minor status |
| 179 | */ |
| 180 | public int getMinorStatus(){ |
| 181 | return minorStatus; |
| 182 | } |
| 183 | |
| 184 | /** |
| 185 | * Retrieves a string explaining the minor status code. |
| 186 | * |
| 187 | * @return a String corresponding to the minor status |
| 188 | * code. <code>null</code> will be returned when no minor status code |
| 189 | * has been set. |
| 190 | */ |
| 191 | public String getMinorString(){ |
| 192 | return minorString; |
| 193 | } |
| 194 | |
| 195 | /** |
| 196 | * This method sets the state for the supplementary information flags |
| 197 | * and the minor status in MessageProp. It is not used by the |
| 198 | * application but by the GSS implementation to return this information |
| 199 | * to the caller of a per-message context method. |
| 200 | * |
| 201 | * @param duplicate true if the token was a duplicate of an earlier |
| 202 | * token, false otherwise |
| 203 | * @param old true if the token's validity period has expired, false |
| 204 | * otherwise |
| 205 | * @param unseq true if a later token has already been processed, false |
| 206 | * otherwise |
| 207 | * @param gap true if one or more predecessor tokens have not yet been |
| 208 | * successfully processed, false otherwise |
| 209 | * @param minorStatus the int minor status code for the per-message |
| 210 | * operation |
| 211 | * @param minorString the textual representation of the minorStatus value |
| 212 | */ |
| 213 | public void setSupplementaryStates(boolean duplicate, |
| 214 | boolean old, boolean unseq, boolean gap, |
| 215 | int minorStatus, String minorString) { |
| 216 | this.dupToken = duplicate; |
| 217 | this.oldToken = old; |
| 218 | this.unseqToken = unseq; |
| 219 | this.gapToken = gap; |
| 220 | this.minorStatus = minorStatus; |
| 221 | this.minorString = minorString; |
| 222 | } |
| 223 | |
| 224 | /** |
| 225 | * Resets the supplementary status values to false. |
| 226 | */ |
| 227 | private void resetStatusValues() { |
| 228 | dupToken = false; |
| 229 | oldToken = false; |
| 230 | unseqToken = false; |
| 231 | gapToken = false; |
| 232 | minorStatus = 0; |
| 233 | minorString = null; |
| 234 | } |
| 235 | } |