1. /*
  2. * @(#)MessageProp.java 1.8 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package org.ietf.jgss;
  8. /**
  9. * This is a utility class used within the per-message GSSContext
  10. * methods to convey per-message properties.<p>
  11. *
  12. * When used with the GSSContext interface's wrap and getMIC methods, an
  13. * instance of this class is used to indicate the desired
  14. * Quality-of-Protection (QOP) and to request if confidentiality services
  15. * are to be applied to caller supplied data (wrap only). To request
  16. * default QOP, the value of 0 should be used for QOP.<p>
  17. *
  18. * When used with the unwrap and verifyMIC methods of the GSSContext
  19. * interface, an instance of this class will be used to indicate the
  20. * applied QOP and confidentiality services over the supplied message.
  21. * In the case of verifyMIC, the confidentiality state will always be
  22. * <code>false</code>. Upon return from these methods, this object will also
  23. * contain any supplementary status values applicable to the processed
  24. * token. The supplementary status values can indicate old tokens, out
  25. * of sequence tokens, gap tokens or duplicate tokens.<p>
  26. *
  27. * @see GSSContext#wrap
  28. * @see GSSContext#unwrap
  29. * @see GSSContext#getMIC
  30. * @see GSSContext#verifyMIC
  31. *
  32. * @author Mayank Upadhyay
  33. * @version 1.8, 01/23/03
  34. * @since 1.4
  35. */
  36. public class MessageProp {
  37. private boolean privacyState;
  38. private int qop;
  39. private boolean dupToken;
  40. private boolean oldToken;
  41. private boolean unseqToken;
  42. private boolean gapToken;
  43. private int minorStatus;
  44. private String minorString;
  45. /**
  46. * Constructor which sets the desired privacy state. The QOP value used
  47. * is 0.
  48. *
  49. * @param privState the privacy (i.e. confidentiality) state
  50. */
  51. public MessageProp(boolean privState) {
  52. this(0, privState);
  53. }
  54. /**
  55. * Constructor which sets the values for the qop and privacy state.
  56. *
  57. * @param qop the QOP value
  58. * @param privState the privacy (i.e. confidentiality) state
  59. */
  60. public MessageProp(int qop, boolean privState) {
  61. this.qop = qop;
  62. this.privacyState = privState;
  63. resetStatusValues();
  64. }
  65. /**
  66. * Retrieves the QOP value.
  67. *
  68. * @return an int representing the QOP value
  69. * @see #setQOP
  70. */
  71. public int getQOP() {
  72. return qop;
  73. }
  74. /**
  75. * Retrieves the privacy state.
  76. *
  77. * @return true if the privacy (i.e., confidentiality) state is true,
  78. * false otherwise.
  79. * @see #setPrivacy
  80. */
  81. public boolean getPrivacy() {
  82. return (privacyState);
  83. }
  84. /**
  85. * Sets the QOP value.
  86. *
  87. * @param qop the int value to set the QOP to
  88. * @see #getQOP
  89. */
  90. public void setQOP(int qop) {
  91. this.qop = qop;
  92. }
  93. /**
  94. * Sets the privacy state.
  95. *
  96. * @param privState true is the privacy (i.e., confidentiality) state
  97. * is true, false otherwise.
  98. * @see #getPrivacy
  99. */
  100. public void setPrivacy(boolean privState) {
  101. this.privacyState = privState;
  102. }
  103. /**
  104. * Tests if this is a duplicate of an earlier token.
  105. *
  106. * @return true if this is a duplicate, false otherwise.
  107. */
  108. public boolean isDuplicateToken() {
  109. return dupToken;
  110. }
  111. /**
  112. * Tests if this token's validity period has expired, i.e., the token
  113. * is too old to be checked for duplication.
  114. *
  115. * @return true if the token's validity period has expired, false
  116. * otherwise.
  117. */
  118. public boolean isOldToken() {
  119. return oldToken;
  120. }
  121. /**
  122. * Tests if a later token had already been processed.
  123. *
  124. * @return true if a later token had already been processed, false otherwise.
  125. */
  126. public boolean isUnseqToken() {
  127. return unseqToken;
  128. }
  129. /**
  130. * Tests if an expected token was not received, i.e., one or more
  131. * predecessor tokens have not yet been successfully processed.
  132. *
  133. * @return true if an expected per-message token was not received,
  134. * false otherwise.
  135. */
  136. public boolean isGapToken() {
  137. return gapToken;
  138. }
  139. /**
  140. * Retrieves the minor status code that the underlying mechanism might
  141. * have set for this per-message operation.
  142. *
  143. * @return the int minor status
  144. */
  145. public int getMinorStatus(){
  146. return minorStatus;
  147. }
  148. /**
  149. * Retrieves a string explaining the minor status code.
  150. *
  151. * @return a String corresponding to the minor status
  152. * code. <code>null</code> will be returned when no minor status code
  153. * has been set.
  154. */
  155. public String getMinorString(){
  156. return minorString;
  157. }
  158. /**
  159. * This method sets the state for the supplementary information flags
  160. * and the minor status in MessageProp. It is not used by the
  161. * application but by the GSS implementation to return this information
  162. * to the caller of a per-message context method.
  163. *
  164. * @param duplicate true if the token was a duplicate of an earlier
  165. * token, false otherwise
  166. * @param old true if the token's validity period has expired, false
  167. * otherwise
  168. * @param unseq true if a later token has already been processed, false
  169. * otherwise
  170. * @param gap true if one or more predecessor tokens have not yet been
  171. * successfully processed, false otherwise
  172. * @param minorStatus the int minor status code for the per-message
  173. * operation
  174. * @param minorString the textual representation of the minorStatus value
  175. */
  176. public void setSupplementaryStates(boolean duplicate,
  177. boolean old, boolean unseq, boolean gap,
  178. int minorStatus, String minorString) {
  179. this.dupToken = duplicate;
  180. this.oldToken = old;
  181. this.unseqToken = unseq;
  182. this.gapToken = gap;
  183. this.minorStatus = minorStatus;
  184. this.minorString = minorString;
  185. }
  186. /**
  187. * Resets the supplementary status values to false.
  188. */
  189. private void resetStatusValues() {
  190. dupToken = false;
  191. oldToken = false;
  192. unseqToken = false;
  193. gapToken = false;
  194. minorStatus = 0;
  195. minorString = null;
  196. }
  197. }